diff options
author | Elliott Sales de Andrade <qulogic@pidgin.im> | 2009-03-13 04:32:05 +0000 |
---|---|---|
committer | Elliott Sales de Andrade <qulogic@pidgin.im> | 2009-03-13 04:32:05 +0000 |
commit | 3b7c770777adf3c7ac8476cac904a383c4de78f2 (patch) | |
tree | 38a9390cfa60733998ad00cd21f45f9648f70bd2 | |
parent | abe494ce3882c91ff234ca692d0b2694f429ddcb (diff) | |
parent | 832b349cf2ff00439333abc4b8dfcfbed51f7635 (diff) | |
download | pidgin-3b7c770777adf3c7ac8476cac904a383c4de78f2.tar.gz |
merge of 'e97f7512b037bfcaea4958fac9831505a70fe565'
and '7420fd99903a8e801f0312cb9ec979907c1eec49'
-rw-r--r-- | ChangeLog.API | 10 | ||||
-rw-r--r-- | libpurple/protocols/bonjour/parser.c | 11 | ||||
-rw-r--r-- | libpurple/protocols/jabber/parser.c | 4 | ||||
-rw-r--r-- | libpurple/xmlnode.c | 68 | ||||
-rw-r--r-- | libpurple/xmlnode.h | 20 |
5 files changed, 66 insertions, 47 deletions
diff --git a/ChangeLog.API b/ChangeLog.API index ba94d7b728..5af7616641 100644 --- a/ChangeLog.API +++ b/ChangeLog.API @@ -26,6 +26,14 @@ version 2.6.0 (??/??/2009): * purple_request_field_set_ui_data * purple_strequal * xmlnode_from_file + * xmlnode_set_attrib_full + + Changed: + * xmlnode_remove_attrib now removes all attributes with the + same name. Previously, it would remove the first one found, + which was completely non-deterministic. If you want to remove + the attribute with no namespace, then use NULL with + xmlnode_remove_with_namespace. Deprecated: * purple_buddy_get_local_alias @@ -40,6 +48,8 @@ version 2.6.0 (??/??/2009): * purple_status_set_attr_string * purple_presence_add_status * purple_presence_add_list + * xmlnode_set_attrib_with_namespace + * xmlnode_set_attrib_with_prefix pidgin: Added: diff --git a/libpurple/protocols/bonjour/parser.c b/libpurple/protocols/bonjour/parser.c index 44a8e8bd99..04d6f10681 100644 --- a/libpurple/protocols/bonjour/parser.c +++ b/libpurple/protocols/bonjour/parser.c @@ -91,14 +91,12 @@ bonjour_parser_element_start_libxml(void *user_data, xmlnode_set_namespace(node, (const char*) namespace); for(i=0; i < nb_attributes * 5; i+=5) { + const char *name = (const char *)attributes[i]; + const char *prefix = (const char *)attributes[i+1]; + const char *attrib_ns = (const char *)attributes[i+2]; char *txt; int attrib_len = attributes[i+4] - attributes[i+3]; char *attrib = g_malloc(attrib_len + 1); - char *attrib_ns = NULL; - - if (attributes[i+2]) { - attrib_ns = g_strdup((char*)attributes[i+2]); - } memcpy(attrib, attributes[i+3], attrib_len); attrib[attrib_len] = '\0'; @@ -106,9 +104,8 @@ bonjour_parser_element_start_libxml(void *user_data, txt = attrib; attrib = purple_unescape_html(txt); g_free(txt); - xmlnode_set_attrib_with_namespace(node, (const char*) attributes[i], attrib_ns, attrib); + xmlnode_set_attrib_full(node, name, attrib_ns, prefix, attrib); g_free(attrib); - g_free(attrib_ns); } bconv->current = node; diff --git a/libpurple/protocols/jabber/parser.c b/libpurple/protocols/jabber/parser.c index 4e602768ce..35186ad15e 100644 --- a/libpurple/protocols/jabber/parser.c +++ b/libpurple/protocols/jabber/parser.c @@ -86,6 +86,8 @@ jabber_parser_element_start_libxml(void *user_data, } } for(i=0; i < nb_attributes * 5; i+=5) { + const char *name = (const char *)attributes[i]; + const char *prefix = (const char *)attributes[i+1]; const char *attrib_ns = (const char *)attributes[i+2]; char *txt; int attrib_len = attributes[i+4] - attributes[i+3]; @@ -97,7 +99,7 @@ jabber_parser_element_start_libxml(void *user_data, txt = attrib; attrib = purple_unescape_html(txt); g_free(txt); - xmlnode_set_attrib_with_namespace(node, (const char*) attributes[i], attrib_ns, attrib); + xmlnode_set_attrib_full(node, name, attrib_ns, prefix, attrib); g_free(attrib); } diff --git a/libpurple/xmlnode.c b/libpurple/xmlnode.c index fc2fc37b36..be8a731a62 100644 --- a/libpurple/xmlnode.c +++ b/libpurple/xmlnode.c @@ -27,6 +27,7 @@ * libxode uses memory pools that we simply have no need for, I decided to * write my own stuff. Also, re-writing this lets me be as lightweight * as I want to be. Thank you libxode for giving me a good starting point */ +#define _PURPLE_XMLNODE_C_ #include "debug.h" #include "internal.h" @@ -126,21 +127,28 @@ xmlnode_remove_attrib(xmlnode *node, const char *attr) g_return_if_fail(node != NULL); g_return_if_fail(attr != NULL); - for(attr_node = node->child; attr_node; attr_node = attr_node->next) - { + attr_node = node->child; + while (attr_node) { if(attr_node->type == XMLNODE_TYPE_ATTRIB && purple_strequal(attr_node->name, attr)) { - if(sibling == NULL) { + if (node->lastchild == attr_node) { + node->lastchild = sibling; + } + if (sibling == NULL) { node->child = attr_node->next; + xmlnode_free(attr_node); + attr_node = node->child; } else { sibling->next = attr_node->next; + sibling = attr_node->next; + xmlnode_free(attr_node); + attr_node = sibling; } - if (node->lastchild == attr_node) { - node->lastchild = sibling; - } - xmlnode_free(attr_node); - return; + } + else + { + attr_node = attr_node->next; } sibling = attr_node; } @@ -178,51 +186,36 @@ xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) { - xmlnode *attrib_node; - - g_return_if_fail(node != NULL); - g_return_if_fail(attr != NULL); - g_return_if_fail(value != NULL); - xmlnode_remove_attrib(node, attr); - - attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); - - attrib_node->data = g_strdup(value); - - xmlnode_insert_child(node, attrib_node); + xmlnode_set_attrib_full(node, attr, NULL, NULL, value); } void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value) { - xmlnode *attrib_node; - - g_return_if_fail(node != NULL); - g_return_if_fail(attr != NULL); - g_return_if_fail(value != NULL); - - xmlnode_remove_attrib_with_namespace(node, attr, xmlns); - attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); - - attrib_node->data = g_strdup(value); - attrib_node->xmlns = g_strdup(xmlns); - - xmlnode_insert_child(node, attrib_node); + xmlnode_set_attrib_full(node, attr, xmlns, NULL, value); } void xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char *prefix, const char *value) { + xmlnode_set_attrib_full(node, attr, NULL, prefix, value); +} + +void +xmlnode_set_attrib_full(xmlnode *node, const char *attr, const char *xmlns, const char *prefix, const char *value) +{ xmlnode *attrib_node; g_return_if_fail(node != NULL); g_return_if_fail(attr != NULL); g_return_if_fail(value != NULL); + xmlnode_remove_attrib_with_namespace(node, attr, xmlns); attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); attrib_node->data = g_strdup(value); + attrib_node->xmlns = g_strdup(xmlns); attrib_node->prefix = g_strdup(prefix); xmlnode_insert_child(node, attrib_node); @@ -585,7 +578,8 @@ xmlnode_parser_element_start_libxml(void *user_data, } for(i=0; i < nb_attributes * 5; i+=5) { - const char *prefix = (const char *)attributes[i + 1]; + const char *name = (const char *)attributes[i]; + const char *prefix = (const char *)attributes[i+1]; char *txt; int attrib_len = attributes[i+4] - attributes[i+3]; char *attrib = g_malloc(attrib_len + 1); @@ -594,11 +588,7 @@ xmlnode_parser_element_start_libxml(void *user_data, txt = attrib; attrib = purple_unescape_html(txt); g_free(txt); - if (prefix && *prefix) { - xmlnode_set_attrib_with_prefix(node, (const char*) attributes[i], prefix, attrib); - } else { - xmlnode_set_attrib(node, (const char*) attributes[i], attrib); - } + xmlnode_set_attrib_full(node, name, NULL, prefix, attrib); g_free(attrib); } diff --git a/libpurple/xmlnode.h b/libpurple/xmlnode.h index bab8192d13..bfc41f2403 100644 --- a/libpurple/xmlnode.h +++ b/libpurple/xmlnode.h @@ -157,6 +157,7 @@ char *xmlnode_get_data_unescaped(xmlnode *node); */ void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); +#if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_XMLNODE_C_) /** * Sets a prefixed attribute for a node * @@ -164,6 +165,8 @@ void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); * @param attr The name of the attribute to set * @param prefix The prefix of the attribute to ste * @param value The value of the attribute + * + * @deprecated Use xmlnode_set_attrib_full instead. */ void xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char *prefix, const char *value); @@ -174,8 +177,25 @@ void xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char * @param attr The name of the attribute to set * @param xmlns The namespace of the attribute to ste * @param value The value of the attribute + * + * @deprecated Use xmlnode_set_attrib_full instead. */ void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value); +#endif /* PURPLE_DISABLE_DEPRECATED */ + +/** + * Sets a namespaced attribute for a node + * + * @param node The node to set an attribute for. + * @param attr The name of the attribute to set + * @param xmlns The namespace of the attribute to ste + * @param prefix The prefix of the attribute to ste + * @param value The value of the attribute + * + * @since 2.6.0 + */ +void xmlnode_set_attrib_full(xmlnode *node, const char *attr, const char *xmlns, + const char *prefix, const char *value); /** * Gets an attribute from a node. |