From: <svn...@op...> - 2009-09-16 23:03:32
|
Author: dgollub Date: Thu Sep 17 01:02:57 2009 New Revision: 5769 URL: http://www.opensync.org/changeset/5769 Log: Add OSyncError** to parameter list for * osync_xmlfield_add_key_value * osync_xmlfield_set_key_value * osync_xmlfield_sort refs #1087 Modified: trunk/opensync/xmlformat/opensync_xmlfield.c trunk/opensync/xmlformat/opensync_xmlfield.h trunk/tests/capabilities-tests/check_xmlformat.c trunk/wrapper/opensync-merger.i Modified: trunk/opensync/xmlformat/opensync_xmlfield.c ============================================================================== --- trunk/opensync/xmlformat/opensync_xmlfield.c Thu Sep 17 00:31:11 2009 (r5768) +++ trunk/opensync/xmlformat/opensync_xmlfield.c Thu Sep 17 01:02:57 2009 (r5769) @@ -393,7 +393,7 @@ return NULL; } -void osync_xmlfield_set_key_value(OSyncXMLField *xmlfield, const char *key, const char *value) +osync_bool osync_xmlfield_set_key_value(OSyncXMLField *xmlfield, const char *key, const char *value, OSyncError **error) { xmlNodePtr cur = NULL; osync_assert(xmlfield); @@ -401,7 +401,7 @@ // If value is null or empty we don't add it to a xmlfield if (!value || strlen(value) == 0) - return; + return TRUE; cur = xmlfield->node->children; for(; cur != NULL; cur = cur->next) { @@ -411,17 +411,22 @@ } } - /* TODO: error handling - API breaking? */ + /* TODO: error handling */ if(cur == NULL) cur = xmlNewTextChild(xmlfield->node, NULL, BAD_CAST key, BAD_CAST value); - /* TODO: error handing - could be NULL */ - osync_xmlfield_new_xmlfield(xmlfield, cur, NULL); + if (!osync_xmlfield_new_xmlfield(xmlfield, cur, error)) + goto error; xmlfield->sorted = FALSE; + + return TRUE; + +error: + return FALSE; } -void osync_xmlfield_add_key_value(OSyncXMLField *xmlfield, const char *key, const char *value) +osync_bool osync_xmlfield_add_key_value(OSyncXMLField *xmlfield, const char *key, const char *value, OSyncError **error) { xmlNodePtr cur; @@ -430,10 +435,16 @@ osync_assert(value); cur = xmlNewTextChild(xmlfield->node, NULL, BAD_CAST key, BAD_CAST value); - /* TODO: error handing - could be NULL */ - osync_xmlfield_new_xmlfield(xmlfield, cur, NULL); + + if (!osync_xmlfield_new_xmlfield(xmlfield, cur, error)) + goto error; xmlfield->sorted = FALSE; + + return TRUE; + +error: + return FALSE; } unsigned int osync_xmlfield_get_key_count(OSyncXMLField *xmlfield) @@ -504,7 +515,7 @@ } } -void osync_xmlfield_sort(OSyncXMLField *xmlfield) +osync_bool osync_xmlfield_sort(OSyncXMLField *xmlfield, OSyncError **error) { int index, count; void **list = NULL; @@ -524,7 +535,9 @@ goto end; } - list = g_malloc0(sizeof(xmlNodePtr) * count); + list = osync_try_malloc0(sizeof(xmlNodePtr) * count, error); + if (!list) + goto error; cur = xmlfield->node->children; for (index=0; cur != NULL; index++) { @@ -555,5 +568,10 @@ end: xmlfield->sorted = TRUE; osync_trace(TRACE_EXIT, "%s", __func__); + + return TRUE; + +error: + return FALSE; } Modified: trunk/opensync/xmlformat/opensync_xmlfield.h ============================================================================== --- trunk/opensync/xmlformat/opensync_xmlfield.h Thu Sep 17 00:31:11 2009 (r5768) +++ trunk/opensync/xmlformat/opensync_xmlfield.h Thu Sep 17 01:02:57 2009 (r5769) @@ -162,16 +162,18 @@ * @param xmlfield Pointer to the xmlfield object * @param key The key of the key/value pair * @param value The value of the key/value pair + * @return TRUE on success, FALSE on error */ -OSYNC_EXPORT void osync_xmlfield_set_key_value(OSyncXMLField *xmlfield, const char *key, const char *value); +OSYNC_EXPORT osync_bool osync_xmlfield_set_key_value(OSyncXMLField *xmlfield, const char *key, const char *value, OSyncError **error); /** * @brief Add the key/value pair to a xmlfield * @param xmlfield Pointer to the xmlfield object * @param key The key of the key/value pair * @param value The value of the key/value pair + * @return TRUE on success, FALSE on error */ -OSYNC_EXPORT void osync_xmlfield_add_key_value(OSyncXMLField *xmlfield, const char *key, const char *value); +OSYNC_EXPORT osync_bool osync_xmlfield_add_key_value(OSyncXMLField *xmlfield, const char *key, const char *value, OSyncError **error); /** * @brief Get the count of keys of a xmlfield @@ -210,8 +212,9 @@ * if the xmlfield was build in an unsorted way. Sorting is not necessary if the * xmlfield was built in a sorted way. * @param xmlfield Pointer to the xmlfield object + * @return TRUE on success, FALSE otherwise */ -OSYNC_EXPORT void osync_xmlfield_sort(OSyncXMLField *xmlfield); +OSYNC_EXPORT osync_bool osync_xmlfield_sort(OSyncXMLField *xmlfield, OSyncError **error); /*@}*/ Modified: trunk/tests/capabilities-tests/check_xmlformat.c ============================================================================== --- trunk/tests/capabilities-tests/check_xmlformat.c Thu Sep 17 00:31:11 2009 (r5768) +++ trunk/tests/capabilities-tests/check_xmlformat.c Thu Sep 17 01:02:57 2009 (r5769) @@ -157,7 +157,8 @@ OSyncXMLField *xmlfield = osync_xmlformat_get_first_field(xmlformat); for (; xmlfield != NULL; xmlfield = osync_xmlfield_get_next(xmlfield)) { - osync_xmlfield_sort(xmlfield); + fail_unless(osync_xmlfield_sort(xmlfield, &error), NULL); + fail_unless(error == NULL, NULL); } xmlfield = osync_xmlformat_get_first_field(xmlformat); @@ -233,7 +234,8 @@ OSyncXMLFormat *xmlformat = osync_xmlformat_new("top", &error); OSyncXMLField *foo = osync_xmlfield_new(xmlformat, "foo", &error); - osync_xmlfield_set_key_value(foo, "fookeyname1", "foorandomvalue"); + osync_xmlfield_set_key_value(foo, "fookeyname1", "foorandomvalue", &error); + fail_unless(error == NULL, NULL); fail_unless(osync_xmlfield_get_child(foo) != NULL); Modified: trunk/wrapper/opensync-merger.i ============================================================================== --- trunk/wrapper/opensync-merger.i Thu Sep 17 00:31:11 2009 (r5768) +++ trunk/wrapper/opensync-merger.i Thu Sep 17 01:02:57 2009 (r5769) @@ -194,12 +194,20 @@ return osync_xmlfield_get_key_value(self, key); } + /* TODO return value bool */ void set_key_value(const char *key, const char *value) { - osync_xmlfield_set_key_value(self, key, value); + OSyncError *err = NULL; + osync_xmlfield_set_key_value(self, key, value, &err); + if (raise_exception_on_error(err)) + return; } + /* TODO return value bool */ void add_key_value(const char *key, const char *value) { - osync_xmlfield_add_key_value(self, key, value); + OSyncError *err; + osync_xmlfield_add_key_value(self, key, value, &err); + if (raise_exception_on_error(err)) + return; } int get_key_count() { |