|
From: <svn...@op...> - 2010-01-04 20:15:33
|
Author: dgollub Date: Mon Jan 4 21:15:22 2010 New Revision: 5966 URL: http://www.opensync.org/changeset/5966 Log: Fix issue in osync_xmlfield_new_xmlfield() when the first child pointer get always overwritten. This requires that the previous pointer (in this case the last child in the siblings-list) get retrieved via a new function: osync_xmlfield_get_last_child() see #1183 Modified: trunk/opensync/xmlformat/opensync_xmlfield.c trunk/opensync/xmlformat/opensync_xmlfield_internals.h Modified: trunk/opensync/xmlformat/opensync_xmlfield.c ============================================================================== --- trunk/opensync/xmlformat/opensync_xmlfield.c Mon Nov 30 20:34:22 2009 (r5965) +++ trunk/opensync/xmlformat/opensync_xmlfield.c Mon Jan 4 21:15:22 2010 (r5966) @@ -62,10 +62,15 @@ node->_private = xmlfield; if (parent) { - xmlfield->prev = parent->child; - if (xmlfield->prev) + xmlfield->prev = osync_xmlfield_get_last_child(parent); + + if (xmlfield->prev) { + osync_assert(xmlfield->prev->next == NULL); xmlfield->prev->next = xmlfield; - parent->child = xmlfield; + } + + if (parent->child == NULL) + parent->child = xmlfield; } @@ -297,6 +302,20 @@ return xmlfield->child; } +OSyncXMLField *osync_xmlfield_get_last_child(OSyncXMLField *xmlfield) +{ + OSyncXMLField *last = NULL; + osync_return_val_if_fail(xmlfield, NULL); + osync_return_val_if_fail(xmlfield->child, NULL); + + last = xmlfield->child; + + while (last->next) + last = last->next; + + return last; +} + const char *osync_xmlfield_get_value(OSyncXMLField *xmlfield) { osync_return_val_if_fail(xmlfield, ""); Modified: trunk/opensync/xmlformat/opensync_xmlfield_internals.h ============================================================================== --- trunk/opensync/xmlformat/opensync_xmlfield_internals.h Mon Nov 30 20:34:22 2009 (r5965) +++ trunk/opensync/xmlformat/opensync_xmlfield_internals.h Mon Jan 4 21:15:22 2010 (r5966) @@ -72,6 +72,13 @@ */ int osync_xmlfield_key_compare_stdlib(const void *key1, const void *key2); +/** + * @brief Get the last child xmlfield + * @param xmlfield Pointer to the xmlfield object + * @return A pointer to the last child xmlfield or NULL if there is no child xmlfield + */ +OSYNC_TEST_EXPORT OSyncXMLField *osync_xmlfield_get_last_child(OSyncXMLField *xmlfield); + /*@}*/ #endif /*OPENSYNC_XMLFIELD_INTERNALS_H_*/ |