From: <svn...@op...> - 2009-09-17 18:33:18
|
Author: dgollub Date: Thu Sep 17 20:33:01 2009 New Revision: 5787 URL: http://www.opensync.org/changeset/5787 Log: Ported xmlformat plugin to latest format plugin API changes Modified: format-plugins/xmlformat/trunk/src/xmlformat-doc.c format-plugins/xmlformat/trunk/src/xmlformat.c format-plugins/xmlformat/trunk/src/xmlformat.h format-plugins/xmlformat/trunk/tests/check_merger.c format-plugins/xmlformat/trunk/tests/check_xmlformat.c Modified: format-plugins/xmlformat/trunk/src/xmlformat-doc.c ============================================================================== --- format-plugins/xmlformat/trunk/src/xmlformat-doc.c Thu Sep 17 20:29:33 2009 (r5786) +++ format-plugins/xmlformat/trunk/src/xmlformat-doc.c Thu Sep 17 20:33:01 2009 (r5787) @@ -85,7 +85,7 @@ static osync_bool from_xml(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, void *userdata, OSyncError **error) { *free_input = TRUE; - return osync_xmlformat_assemble((OSyncXMLFormat *)input, output, outpsize); + return osync_xmlformat_assemble((OSyncXMLFormat *)input, output, outpsize, error); } static osync_bool to_xml(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, void *userdata, OSyncError **error) @@ -98,9 +98,10 @@ return TRUE; } -static void destroy(char *input, unsigned int inpsize, void *user_data) +static osync_bool destroy(char *input, unsigned int inpsize, void *user_data, OSyncError **error) { free(input); + return TRUE; } static osync_bool register_format(OSyncFormatEnv *env, const char *name, const char *objtype) Modified: format-plugins/xmlformat/trunk/src/xmlformat.c ============================================================================== --- format-plugins/xmlformat/trunk/src/xmlformat.c Thu Sep 17 20:29:33 2009 (r5786) +++ format-plugins/xmlformat/trunk/src/xmlformat.c Thu Sep 17 20:33:01 2009 (r5787) @@ -24,9 +24,10 @@ #include "xmlformat.h" -void destroy_xmlformat(char *input, unsigned int inpsize, void *userdata) +osync_bool destroy_xmlformat(char *input, unsigned int inpsize, void *userdata, OSyncError **error) { osync_xmlformat_unref((OSyncXMLFormat *)input); + return TRUE; } static osync_bool duplicate_xmlformat(const char *uid, const char *input, unsigned int insize, char **newuid, char **output, unsigned int *outsize, osync_bool *dirty, void *userdata, OSyncError **error) @@ -37,19 +38,22 @@ osync_trace(TRACE_ENTRY, "%s(%s, %p, %i, %p, %p, %p, %p, %p)", __func__, uid, input, insize, newuid, output, outsize, dirty, error); - osync_xmlformat_assemble((OSyncXMLFormat *) input, &buffer, &size); + if (!osync_xmlformat_assemble((OSyncXMLFormat *) input, &buffer, &size, error)) + goto error; xmlformat = osync_xmlformat_parse(buffer, size, error); - if (!xmlformat) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - return FALSE; - } + if (!xmlformat) + goto error; *dirty = TRUE; *newuid = g_strdup_printf ("%s-dupe", uid); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; + +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } @@ -69,7 +73,7 @@ osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; } -char *print_xmlformat(const char *data, unsigned int size, void *userdata) +char *print_xmlformat(const char *data, unsigned int size, void *userdata, OSyncError **error) { char *buffer; unsigned int i; @@ -77,10 +81,13 @@ osync_assert(data); osync_assert(size > 0); - if(!osync_xmlformat_assemble((OSyncXMLFormat *)data, &buffer, &i)) - return NULL; + if(!osync_xmlformat_assemble((OSyncXMLFormat *)data, &buffer, &i, error)) + goto error; return buffer; + +error: + return NULL; } osync_bool marshal_xmlformat(const char *input, unsigned int inpsize, OSyncMarshal *marshal, void *userdata, OSyncError **error) @@ -88,7 +95,7 @@ char *buffer; unsigned int size; - if (!osync_xmlformat_assemble((OSyncXMLFormat *)input, &buffer, &size)) + if (!osync_xmlformat_assemble((OSyncXMLFormat *)input, &buffer, &size, error)) goto error; if (!osync_marshal_write_buffer(marshal, buffer, (int)size, error)) @@ -118,7 +125,8 @@ * Demarshal the entire XMLFormat struct, including the sorte * attribute to keep this information. */ - osync_xmlformat_sort(xmlformat); + if (!osync_xmlformat_sort(xmlformat, error)) + goto error; g_free(buffer); @@ -132,7 +140,7 @@ } -OSyncConvCmpResult compare_contact(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata) +OSyncConvCmpResult compare_contact(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata, OSyncError **error) { char* keys_content[] = {"Content", NULL}; char* keys_name[] = {"FirstName", "LastName", NULL}; @@ -155,15 +163,19 @@ return ret; } -static void create_contact(char **data, unsigned int *size, void *userdata) +static osync_bool create_contact(char **data, unsigned int *size, void *userdata, OSyncError **error) { - OSyncError *error = NULL; - *data = (char *)osync_xmlformat_new("contact", &error); + *data = (char *)osync_xmlformat_new("contact", error); if (!*data) - osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(&error)); + goto error; + + return TRUE; +error: + osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } -static OSyncConvCmpResult compare_event(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata) +static OSyncConvCmpResult compare_event(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata, OSyncError **error) { char* keys_content[] = {"Content", NULL}; OSyncXMLPoints points[] = { @@ -190,15 +202,20 @@ return ret; } -void create_event(char **data, unsigned int *size, void *userdata) +osync_bool create_event(char **data, unsigned int *size, void *userdata, OSyncError **error) { - OSyncError *error = NULL; - *data = (char *)osync_xmlformat_new("event", &error); + *data = (char *)osync_xmlformat_new("event", error); if (!*data) - osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(&error)); + goto error; + + return TRUE; + +error: + osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } -static OSyncConvCmpResult compare_todo(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata) +static OSyncConvCmpResult compare_todo(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata, OSyncError **error) { char* keys_content[] = {"Content", NULL}; OSyncXMLPoints points[] = { @@ -225,15 +242,20 @@ return ret; } -static void create_todo(char **data, unsigned int *size, void *userdata) +static osync_bool create_todo(char **data, unsigned int *size, void *userdata, OSyncError **error) { - OSyncError *error = NULL; - *data = (char *)osync_xmlformat_new("todo", &error); + *data = (char *)osync_xmlformat_new("todo", error); if (!*data) - osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(&error)); + goto error; + + return TRUE; + +error: + osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } -static OSyncConvCmpResult compare_note(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata) +static OSyncConvCmpResult compare_note(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata, OSyncError **error) { char* keys_content[] = {"Content", NULL}; OSyncXMLPoints points[] = { @@ -258,12 +280,17 @@ return ret; } -static void create_note(char **data, unsigned int *size, void *userdata) +static osync_bool create_note(char **data, unsigned int *size, void *userdata, OSyncError **error) { - OSyncError *error = NULL; - *data = (char *)osync_xmlformat_new("note", &error); + *data = (char *)osync_xmlformat_new("note", error); if (!*data) - osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(&error)); + goto error; + + return TRUE; + +error: + osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } static time_t get_revision(const char *data, unsigned int size, const char *attribute, OSyncError **error) @@ -338,17 +365,19 @@ return ret; } -static void finalize(void *userdata) +static osync_bool finalize(void *userdata, OSyncError **error) { XMLFormat *xmlformat_data = (XMLFormat *) userdata; if (!userdata) - return; + return TRUE; if (xmlformat_data->xmlformat_schema) osync_xmlformat_schema_unref(xmlformat_data->xmlformat_schema); osync_free(xmlformat_data); + + return TRUE; } static void *initialize(const char *objtype, OSyncError **error) @@ -368,7 +397,7 @@ return (void *) userdata; error_and_free: - finalize(userdata); + finalize(userdata, NULL); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; Modified: format-plugins/xmlformat/trunk/src/xmlformat.h ============================================================================== --- format-plugins/xmlformat/trunk/src/xmlformat.h Thu Sep 17 20:29:33 2009 (r5786) +++ format-plugins/xmlformat/trunk/src/xmlformat.h Thu Sep 17 20:33:01 2009 (r5787) @@ -61,9 +61,9 @@ } XMLFormat; -void destroy_xmlformat(char *input, unsigned int inpsize, void *userdata); +osync_bool destroy_xmlformat(char *input, unsigned int inpsize, void *userdata, OSyncError **errror); osync_bool copy_xmlformat(const char *input, unsigned int inpsize, char **output, unsigned int *outpsize, void *userdata, OSyncError **error); -char *print_xmlformat(const char *data, unsigned int size, void *userdata); +char *print_xmlformat(const char *data, unsigned int size, void *userdata, OSyncError **error); int xmlformat_get_points(OSyncXMLPoints points[], int* cur_pos, int basic_points, const char* fieldname); @@ -75,7 +75,7 @@ osync_bool marshal_xmlformat(const char *input, unsigned int inpsize, OSyncMarshal *marshal, void *userdata, OSyncError **error); osync_bool demarshal_xmlformat(OSyncMarshal *marshal, char **output, unsigned int *outpsize, void *userdata, OSyncError **error); -OSyncConvCmpResult compare_contact(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata); +OSyncConvCmpResult compare_contact(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *userdata, OSyncError **error); #endif /* XMLFORMAT_H_ */ Modified: format-plugins/xmlformat/trunk/tests/check_merger.c ============================================================================== --- format-plugins/xmlformat/trunk/tests/check_merger.c Thu Sep 17 20:29:33 2009 (r5786) +++ format-plugins/xmlformat/trunk/tests/check_merger.c Thu Sep 17 20:33:01 2009 (r5787) @@ -59,14 +59,16 @@ fail_unless(xmlformat != NULL, NULL); fail_unless(error == NULL, NULL); g_free(buffer); - osync_xmlformat_sort(xmlformat); + osync_xmlformat_sort(xmlformat, &error); + fail_unless(error == NULL, NULL); fail_unless(osync_file_read("contact-full.xml", &buffer, &size, &error), NULL); xmlformat_entire = osync_xmlformat_parse(buffer, size, &error); fail_unless(xmlformat_entire != NULL, NULL); fail_unless(error == NULL, NULL); g_free(buffer); - osync_xmlformat_sort(xmlformat_entire); + osync_xmlformat_sort(xmlformat_entire, &error); + fail_unless(error == NULL, NULL); #if 0 fail_unless(osync_file_read("capabilities.xml", &buffer, &size, &error), NULL); @@ -102,14 +104,16 @@ fail_unless(xmlformat != NULL, NULL); fail_unless(error == NULL, NULL); g_free(buffer); - osync_xmlformat_sort(xmlformat); + osync_xmlformat_sort(xmlformat, &error); + fail_unless(error == NULL, NULL); fail_unless(osync_file_read("contact-full.xml", &buffer, &size, &error), NULL); xmlformat_entire = osync_xmlformat_parse(buffer, size, &error); fail_unless(xmlformat_entire != NULL, NULL); fail_unless(error == NULL, NULL); g_free(buffer); - osync_xmlformat_sort(xmlformat_entire); + osync_xmlformat_sort(xmlformat_entire, &error); + fail_unless(error == NULL, NULL); //osync_xmlformat_assemble(xmlformat, &buffer, &size); printf("\n%s", buffer); g_free(buffer); //osync_xmlformat_assemble(xmlformat_entire, &buffer, &size); printf("\n%s", buffer); g_free(buffer); Modified: format-plugins/xmlformat/trunk/tests/check_xmlformat.c ============================================================================== --- format-plugins/xmlformat/trunk/tests/check_xmlformat.c Thu Sep 17 20:29:33 2009 (r5786) +++ format-plugins/xmlformat/trunk/tests/check_xmlformat.c Thu Sep 17 20:33:01 2009 (r5787) @@ -32,7 +32,8 @@ fail_unless(xmlformat != NULL, NULL); fail_unless(error == NULL, NULL); - fail_unless((print_buffer = print_xmlformat((char *)xmlformat, osync_xmlformat_size(), NULL)) != NULL, NULL); + fail_unless((print_buffer = print_xmlformat((char *)xmlformat, osync_xmlformat_size(), NULL, &error)) != NULL, NULL); + fail_unless(error == NULL, NULL); osync_free(print_buffer); @@ -56,7 +57,8 @@ fail_unless(xmlformat != NULL, NULL); fail_unless(error == NULL, NULL); - destroy_xmlformat((char *)xmlformat, osync_xmlformat_size(), NULL); + fail_unless(destroy_xmlformat((char *)xmlformat, osync_xmlformat_size(), NULL, &error), NULL); + fail_unless(error == NULL, NULL); osync_xmlformat_unref(xmlformat); @@ -275,12 +277,14 @@ g_free(buffer1); result = compare_contact((char*)xmlformat1, osync_xmlformat_size(), - (char*)xmlformat2, osync_xmlformat_size(), NULL); + (char*)xmlformat2, osync_xmlformat_size(), NULL, &error); fail_unless(result == OSYNC_CONV_DATA_SAME, NULL); + fail_unless(error == NULL, NULL); result = compare_contact((char*)xmlformat2, osync_xmlformat_size(), - (char*)xmlformat1, osync_xmlformat_size(), NULL); + (char*)xmlformat1, osync_xmlformat_size(), NULL, &error); fail_unless(result == OSYNC_CONV_DATA_SAME, NULL); + fail_unless(error == NULL, NULL); osync_xmlformat_unref((OSyncXMLFormat*)xmlformat1); |