From: <svn...@op...> - 2010-11-07 13:42:54
|
Author: bellmich Date: Sun Nov 7 14:42:44 2010 New Revision: 232 URL: http://libwbxml.opensync.org/changeset/232 Log: fixed ticket #46 Modified: wbxml2/trunk/ChangeLog wbxml2/trunk/src/wbxml_tree.c Modified: wbxml2/trunk/ChangeLog ============================================================================== --- wbxml2/trunk/ChangeLog Fri Oct 15 17:06:51 2010 (r231) +++ wbxml2/trunk/ChangeLog Sun Nov 7 14:42:44 2010 (r232) @@ -2,6 +2,8 @@ The overflow causes crashs or wrong wbxml messages. * Fixed location of variable definitions (changes from ticket #42) This fixes some compiler errors from MS VisualStudio 2008. + * Added support for recursion in wbxml_tree_node_elt_get_from_name + (ticket #46) 2010-03-29 Michael Bell <mic...@we...> * Released 0.10.8 Modified: wbxml2/trunk/src/wbxml_tree.c ============================================================================== --- wbxml2/trunk/src/wbxml_tree.c Fri Oct 15 17:06:51 2010 (r231) +++ wbxml2/trunk/src/wbxml_tree.c Sun Nov 7 14:42:44 2010 (r232) @@ -1,7 +1,7 @@ /* * libwbxml, the WBXML Library. * Copyright (C) 2002-2008 Aymerick Jehanne <aym...@je...> - * Copyright (C) 2008-2009 Michael Bell <mic...@op...> + * Copyright (C) 2008-2010 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -752,34 +752,42 @@ WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_elt_get_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs) { WBXMLTreeNode *current_node = NULL; - WB_BOOL node_found = FALSE; + WBXMLTreeNode *recurs_node = NULL; if ((node == NULL) || (name == NULL)) return NULL; - /** @todo Handle 'recurs' TRUE */ - /* Let's go through the tree */ current_node = node; while (current_node != NULL) { - /* Is this the Node we searched ? */ - if ((current_node->type == WBXML_TREE_ELEMENT_NODE) && - (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0)) + /* Is this a normal node? */ + if (current_node->type == WBXML_TREE_ELEMENT_NODE) { - node_found = TRUE; - break; - } - else { - /* Go to next Sibbling Node */ - current_node = current_node->next; + /* Is this the Node we searched ? */ + if (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0) + { + return current_node; + } + + /* Sould we start a recursive search? */ + if (recurs && current_node->children) + { + recurs_node = wbxml_tree_node_elt_get_from_name(current_node->children, name, TRUE); + /* Is this the Node we searched ? */ + if (recurs_node) + { + return recurs_node; + } + } } - } - if (node_found) - return current_node; + /* Go to next Sibbling Node */ + current_node = current_node->next; + } + /* A node with the specified name could not be found. */ return NULL; } |