Changeset 3452
- Timestamp:
- 07/14/08 16:24:09 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/opensync/xmlformat/opensync_xmlformat_schema.c
r3431 r3452 70 70 71 71 xmlSchemaParserCtxt = xmlSchemaNewParserCtxt(schemafilepath); 72 if ( xmlSchemaParserCtxt == NULL ) { 73 osync_error_set(error, OSYNC_ERROR_GENERIC, "Creation of new XMLFormatSchema failed. Could not create schema parser context."); 74 goto error; 75 } 72 76 osyncschema->schema = xmlSchemaParse(xmlSchemaParserCtxt); 73 77 xmlSchemaFreeParserCtxt(xmlSchemaParserCtxt); 78 if ( osyncschema->schema == NULL ) { 79 osync_error_set(error, OSYNC_ERROR_GENERIC, "Creation of new XMLFormatSchema failed. Could not read schema file."); 80 goto error; 81 } 74 82 75 83 osyncschema->context = xmlSchemaNewValidCtxt(osyncschema->schema); 76 84 if (osyncschema->context == NULL) { 77 85 xmlSchemaFree(osyncschema->schema); 78 g_free(osyncschema->objtype); 79 g_free(osyncschema); 80 osyncschema = NULL; 81 osync_error_set(error, OSYNC_ERROR_GENERIC, "XMLFormat validation failed. Could not create Schema Context."); 86 osync_error_set(error, OSYNC_ERROR_GENERIC, "Creation of new XMLFormatSchema failed. Could not create schema validation context."); 87 goto error; 82 88 } 89 osync_trace(TRACE_EXIT, "%s", __func__ ); 83 90 return osyncschema; 84 } 85 86 /*@}*/ 87 88 /** 89 * @defgroup OSyncXMLFormatAPI OpenSync XMLFormat 90 * @ingroup OSyncPublic 91 * @brief The public part of the OSyncXMLFormat 92 * 93 */ 94 /*@{*/ 91 error: 92 g_free(osyncschema->objtype); 93 g_free(osyncschema); 94 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 95 return NULL; 96 } 95 97 96 98 /** … … 100 102 * objtype as a xmlformat prior the returned pointer to a OSyncXMLFormatSchema instance is the same as before. 101 103 * 102 * @param xmlformat The pointer to a xmlformat object 104 * @param xmlformat The pointer to a xmlformat object 105 * @param schemadir Path of the dir where the schema files are found. 103 106 * @param error The error which will hold the info in case of an error 104 107 * @return Pointer to a instance of OSyncXMLFormatSchema 105 108 */ 106 109 107 OSyncXMLFormatSchema * osync_xmlformat_schema_get_instance(OSyncXMLFormat * xmlformat, OSyncError **error) {108 static GList * schemas = NULL;110 OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error) { 111 static GList *schemas = NULL; 109 112 static GStaticMutex mutex = G_STATIC_MUTEX_INIT; 110 OSyncXMLFormatSchema * osyncschema = NULL;113 OSyncXMLFormatSchema *osyncschema = NULL; 111 114 GList * entry; 112 const char * objtype;115 const char *objtype; 113 116 114 117 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, xmlformat, error); … … 129 132 } 130 133 if ( osyncschema == NULL ) { 131 osyncschema = osync_xmlformat_schema_new(xmlformat, NULL, error);134 osyncschema = osync_xmlformat_schema_new(xmlformat, schemadir, error); 132 135 if ( osyncschema != NULL ) { 133 136 schemas = g_list_append(schemas, osyncschema); … … 136 139 // release mutex 137 140 g_static_mutex_unlock(&mutex); 141 osync_trace(TRACE_EXIT, "%s, (%p)", __func__, osyncschema ); 138 142 return osyncschema; 143 } 144 145 /*@}*/ 146 147 /** 148 * @defgroup OSyncXMLFormatAPI OpenSync XMLFormat 149 * @ingroup OSyncPublic 150 * @brief The public part of the OSyncXMLFormat 151 * 152 */ 153 /*@{*/ 154 155 /** 156 * @brief Get a schema for the xmlformat. 157 * 158 * This function creates only one instance of a schema for each objtype. If a xmlformat is passed as a parameter with the same 159 * objtype as a xmlformat prior the returned pointer to a OSyncXMLFormatSchema instance is the same as before. 160 * 161 * @param xmlformat The pointer to a xmlformat object 162 * @param error The error which will hold the info in case of an error 163 * @return Pointer to a instance of OSyncXMLFormatSchema 164 */ 165 166 OSyncXMLFormatSchema * osync_xmlformat_schema_get_instance(OSyncXMLFormat *xmlformat, OSyncError **error) { 167 return osync_xmlformat_schema_get_instance_with_path(xmlformat, NULL, error); 139 168 } 140 169 … … 147 176 */ 148 177 149 osync_bool osync_xmlformat_schema_validate(OSyncXMLFormatSchema * schema, OSyncXMLFormat *xmlformat, OSyncError **error)178 osync_bool osync_xmlformat_schema_validate(OSyncXMLFormatSchema *schema, OSyncXMLFormat *xmlformat, OSyncError **error) 150 179 { 151 180 osync_assert(xmlformat); trunk/opensync/xmlformat/opensync_xmlformat_schema_internals.h
r3431 r3452 43 43 }; 44 44 45 OSyncXMLFormatSchema *osync_xmlformat_schema_new(OSyncXMLFormat *xmlformat, const char *path, OSyncError **error); 45 OSyncXMLFormatSchema *osync_xmlformat_schema_new(OSyncXMLFormat *xmlformat, const char *path, OSyncError **error); 46 OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error); 46 47 47 48 #endif /* OPENSYNC_XMLFORMAT_SCHEMA_INTERNALS_H_ */
