Changeset 3452

Show
Ignore:
Timestamp:
07/14/08 16:24:09 (2 months ago)
Author:
bricks
Message:

added internal function to pass schema dir for unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/opensync/xmlformat/opensync_xmlformat_schema.c

    r3431 r3452  
    7070         
    7171        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        } 
    7276        osyncschema->schema = xmlSchemaParse(xmlSchemaParserCtxt); 
    7377        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        } 
    7482 
    7583        osyncschema->context = xmlSchemaNewValidCtxt(osyncschema->schema); 
    7684        if (osyncschema->context == NULL) { 
    7785                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; 
    8288        } 
     89        osync_trace(TRACE_EXIT, "%s", __func__ ); 
    8390        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 /*@{*/ 
     91error: 
     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
    9597 
    9698/** 
     
    100102 * objtype as a xmlformat prior the returned pointer to a OSyncXMLFormatSchema instance is the same as before. 
    101103 * 
    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.   
    103106 * @param error The error which will hold the info in case of an error 
    104107 * @return Pointer to a instance of OSyncXMLFormatSchema 
    105108 */ 
    106109 
    107 OSyncXMLFormatSchema * osync_xmlformat_schema_get_instance(OSyncXMLFormat * xmlformat, OSyncError **error) { 
    108         static GList * schemas = NULL; 
     110OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error) { 
     111        static GList *schemas = NULL; 
    109112        static GStaticMutex mutex = G_STATIC_MUTEX_INIT; 
    110         OSyncXMLFormatSchema * osyncschema = NULL; 
     113        OSyncXMLFormatSchema *osyncschema = NULL; 
    111114        GList * entry; 
    112         const char * objtype; 
     115        const char *objtype; 
    113116         
    114117        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, xmlformat, error); 
     
    129132        } 
    130133        if ( osyncschema == NULL ) { 
    131                 osyncschema = osync_xmlformat_schema_new(xmlformat, NULL, error); 
     134                osyncschema = osync_xmlformat_schema_new(xmlformat, schemadir, error); 
    132135                if ( osyncschema != NULL ) { 
    133136                        schemas = g_list_append(schemas, osyncschema); 
     
    136139        // release mutex 
    137140        g_static_mutex_unlock(&mutex); 
     141        osync_trace(TRACE_EXIT, "%s, (%p)", __func__, osyncschema ); 
    138142        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 
     166OSyncXMLFormatSchema * osync_xmlformat_schema_get_instance(OSyncXMLFormat *xmlformat, OSyncError **error) { 
     167        return osync_xmlformat_schema_get_instance_with_path(xmlformat, NULL, error);    
    139168} 
    140169 
     
    147176 */ 
    148177 
    149 osync_bool osync_xmlformat_schema_validate(OSyncXMLFormatSchema * schema, OSyncXMLFormat * xmlformat, OSyncError **error) 
     178osync_bool osync_xmlformat_schema_validate(OSyncXMLFormatSchema *schema, OSyncXMLFormat *xmlformat, OSyncError **error) 
    150179{ 
    151180        osync_assert(xmlformat); 
  • trunk/opensync/xmlformat/opensync_xmlformat_schema_internals.h

    r3431 r3452  
    4343}; 
    4444 
    45 OSyncXMLFormatSchema *osync_xmlformat_schema_new(OSyncXMLFormat *xmlformat, const char *path, OSyncError **error);  
     45OSyncXMLFormatSchema *osync_xmlformat_schema_new(OSyncXMLFormat *xmlformat, const char *path, OSyncError **error); 
     46OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error);  
    4647 
    4748#endif /* OPENSYNC_XMLFORMAT_SCHEMA_INTERNALS_H_ */