From b9b58a5a6bfa4bdc56cc294665e13821aefc5e5b Mon Sep 17 00:00:00 2001 From: Daniel Atallah Date: Tue, 9 Oct 2007 19:28:48 +0000 Subject: I think this is the correct fix for CID 319 and 321. I added a note about two other cases where it appears that the xmlns isn't being compared correctly, but I'm afraid that fixing them will cause behavior change. --- libpurple/protocols/bonjour/parser.c | 2 +- libpurple/protocols/jabber/parser.c | 2 +- libpurple/xmlnode.c | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libpurple/protocols/bonjour/parser.c b/libpurple/protocols/bonjour/parser.c index adc2d4621a..c062dce348 100644 --- a/libpurple/protocols/bonjour/parser.c +++ b/libpurple/protocols/bonjour/parser.c @@ -64,7 +64,7 @@ bonjour_parser_element_start_libxml(void *user_data, char *attrib_ns = NULL; if (attributes[i+2]) { - attrib_ns = g_strdup((char*)attributes[i+2]);; + attrib_ns = g_strdup((char*)attributes[i+2]); } memcpy(attrib, attributes[i+3], attrib_len); diff --git a/libpurple/protocols/jabber/parser.c b/libpurple/protocols/jabber/parser.c index bd28f0f0d4..a6b65b0f04 100644 --- a/libpurple/protocols/jabber/parser.c +++ b/libpurple/protocols/jabber/parser.c @@ -80,7 +80,7 @@ jabber_parser_element_start_libxml(void *user_data, char *attrib_ns = NULL; if (attributes[i+2]) { - attrib_ns = g_strdup((char*)attributes[i+2]);; + attrib_ns = g_strdup((char*)attributes[i+2]); } memcpy(attrib, attributes[i+3], attrib_len); diff --git a/libpurple/xmlnode.c b/libpurple/xmlnode.c index 9186dce96c..56890f5e56 100644 --- a/libpurple/xmlnode.c +++ b/libpurple/xmlnode.c @@ -146,6 +146,19 @@ xmlnode_remove_attrib(xmlnode *node, const char *attr) } } +/* Compare two nullable xmlns strings. + * They are considered equal if they're both NULL or the strings are equal + */ +static gboolean _xmlnode_compare_xmlns(const char *xmlns1, const char *xmlns2) { + gboolean equal = FALSE; + + if (xmlns1 == NULL && xmlns2 == NULL) + equal = TRUE; + else if (xmlns1 != NULL && xmlns2 != NULL && !strcmp(xmlns1, xmlns2)) + equal = TRUE; + + return equal; +} void xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) @@ -159,7 +172,7 @@ xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char { if(attr_node->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr_node->name, attr) && - !strcmp(attr_node->xmlns, xmlns)) + _xmlnode_compare_xmlns(xmlns, attr_node->xmlns)) { if(node->child == attr_node) { node->child = attr_node->next; @@ -238,7 +251,8 @@ xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *x for(x = node->child; x; x = x->next) { if(x->type == XMLNODE_TYPE_ATTRIB && - !strcmp(attr, x->name) && !strcmp(x->xmlns, xmlns)) { + !strcmp(attr, x->name) && + _xmlnode_compare_xmlns(xmlns, x->xmlns)) { return x->data; } } @@ -326,6 +340,7 @@ xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const child_name = names[1]; for(x = parent->child; x; x = x->next) { + /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ const char *xmlns = NULL; if(ns) xmlns = xmlnode_get_namespace(x); @@ -673,6 +688,7 @@ xmlnode_get_next_twin(xmlnode *node) g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); for(sibling = node->next; sibling; sibling = sibling->next) { + /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ const char *xmlns = NULL; if(ns) xmlns = xmlnode_get_namespace(sibling); -- cgit v1.2.1