diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-05-12 00:27:11 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-05-12 00:27:11 +0100 |
commit | 3742fb6ae99c2e5e25cff272a154b9834866e8f9 (patch) | |
tree | 4cb9e08f0bf668dad9b47af15ab60c0c3cc1b179 | |
parent | f8cb76dea3554fd82c01c5cae61f35d2b6cb0936 (diff) |
Implement some kind of ignorant awareness of XML namespaces: Enough to not
break backward compatibility (hopefully) but be able to pick up inappropriate
uses of XML namespace prefixes. Main reason for this change: Fix XMPP typing
notification compatibility with GMail.
-rw-r--r-- | lib/xmltree.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/xmltree.c b/lib/xmltree.c index 67fe46e1..31f8ee9c 100644 --- a/lib/xmltree.c +++ b/lib/xmltree.c @@ -448,7 +448,11 @@ struct xt_node *xt_find_node( struct xt_node *node, const char *name ) { while( node ) { - if( g_strcasecmp( node->name, name ) == 0 ) + char *colon; + + if( g_strcasecmp( node->name, name ) == 0 || + ( ( colon = strchr( node->name, ':' ) ) && + g_strcasecmp( colon + 1, name ) == 0 ) ) break; node = node->next; @@ -460,6 +464,7 @@ struct xt_node *xt_find_node( struct xt_node *node, const char *name ) char *xt_find_attr( struct xt_node *node, const char *key ) { int i; + char *colon; if( !node ) return NULL; @@ -468,6 +473,21 @@ char *xt_find_attr( struct xt_node *node, const char *key ) if( g_strcasecmp( node->attr[i].key, key ) == 0 ) break; + /* This is an awful hack that only takes care of namespace prefixes + inside a tag. Since IMHO excessive namespace usage in XMPP is + massive overkill anyway (this code exists for almost four years + now and never really missed it): Meh. */ + if( !node->attr[i].key && strcmp( key, "xmlns" ) == 0 && + ( colon = strchr( node->name, ':' ) ) ) + { + *colon = '\0'; + for( i = 0; node->attr[i].key; i ++ ) + if( strncmp( node->attr[i].key, "xmlns:", 6 ) == 0 && + strcmp( node->attr[i].key + 6, node->name ) == 0 ) + break; + *colon = ':'; + } + return node->attr[i].value; } |