Mercurial > pidgin.yaz
comparison libpurple/xmlnode.c @ 25385:a6e3cb32cdd2
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
closes #7790
committer: Gary Kramlich <grim@reaperworld.com>
| author | Paul Aurich <paul@darkrain42.org> |
|---|---|
| date | Tue, 06 Jan 2009 03:39:51 +0000 |
| parents | 43b721aa4b76 |
| children | 584063555949 |
comparison
equal
deleted
inserted
replaced
| 25384:991796129108 | 25385:a6e3cb32cdd2 |
|---|---|
| 127 g_return_if_fail(attr != NULL); | 127 g_return_if_fail(attr != NULL); |
| 128 | 128 |
| 129 for(attr_node = node->child; attr_node; attr_node = attr_node->next) | 129 for(attr_node = node->child; attr_node; attr_node = attr_node->next) |
| 130 { | 130 { |
| 131 if(attr_node->type == XMLNODE_TYPE_ATTRIB && | 131 if(attr_node->type == XMLNODE_TYPE_ATTRIB && |
| 132 !strcmp(attr_node->name, attr)) | 132 purple_strequal(attr_node->name, attr)) |
| 133 { | 133 { |
| 134 if(sibling == NULL) { | 134 if(sibling == NULL) { |
| 135 node->child = attr_node->next; | 135 node->child = attr_node->next; |
| 136 } else { | 136 } else { |
| 137 sibling->next = attr_node->next; | 137 sibling->next = attr_node->next; |
| 144 } | 144 } |
| 145 sibling = attr_node; | 145 sibling = attr_node; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 /* Compare two nullable xmlns strings. | |
| 150 * They are considered equal if they're both NULL or the strings are equal | |
| 151 */ | |
| 152 static gboolean _xmlnode_compare_xmlns(const char *xmlns1, const char *xmlns2) { | |
| 153 gboolean equal = FALSE; | |
| 154 | |
| 155 if (xmlns1 == NULL && xmlns2 == NULL) | |
| 156 equal = TRUE; | |
| 157 else if (xmlns1 != NULL && xmlns2 != NULL && !strcmp(xmlns1, xmlns2)) | |
| 158 equal = TRUE; | |
| 159 | |
| 160 return equal; | |
| 161 } | |
| 162 | |
| 163 void | 149 void |
| 164 xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | 150 xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) |
| 165 { | 151 { |
| 166 xmlnode *attr_node, *sibling = NULL; | 152 xmlnode *attr_node, *sibling = NULL; |
| 167 | 153 |
| 169 g_return_if_fail(attr != NULL); | 155 g_return_if_fail(attr != NULL); |
| 170 | 156 |
| 171 for(attr_node = node->child; attr_node; attr_node = attr_node->next) | 157 for(attr_node = node->child; attr_node; attr_node = attr_node->next) |
| 172 { | 158 { |
| 173 if(attr_node->type == XMLNODE_TYPE_ATTRIB && | 159 if(attr_node->type == XMLNODE_TYPE_ATTRIB && |
| 174 !strcmp(attr_node->name, attr) && | 160 purple_strequal(attr, attr_node->name) && |
| 175 _xmlnode_compare_xmlns(xmlns, attr_node->xmlns)) | 161 purple_strequal(xmlns, attr_node->xmlns)) |
| 176 { | 162 { |
| 177 if(sibling == NULL) { | 163 if(sibling == NULL) { |
| 178 node->child = attr_node->next; | 164 node->child = attr_node->next; |
| 179 } else { | 165 } else { |
| 180 sibling->next = attr_node->next; | 166 sibling->next = attr_node->next; |
| 250 | 236 |
| 251 g_return_val_if_fail(node != NULL, NULL); | 237 g_return_val_if_fail(node != NULL, NULL); |
| 252 g_return_val_if_fail(attr != NULL, NULL); | 238 g_return_val_if_fail(attr != NULL, NULL); |
| 253 | 239 |
| 254 for(x = node->child; x; x = x->next) { | 240 for(x = node->child; x; x = x->next) { |
| 255 if(x->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr, x->name)) { | 241 if(x->type == XMLNODE_TYPE_ATTRIB && purple_strequal(attr, x->name)) { |
| 256 return x->data; | 242 return x->data; |
| 257 } | 243 } |
| 258 } | 244 } |
| 259 | 245 |
| 260 return NULL; | 246 return NULL; |
| 268 g_return_val_if_fail(node != NULL, NULL); | 254 g_return_val_if_fail(node != NULL, NULL); |
| 269 g_return_val_if_fail(attr != NULL, NULL); | 255 g_return_val_if_fail(attr != NULL, NULL); |
| 270 | 256 |
| 271 for(x = node->child; x; x = x->next) { | 257 for(x = node->child; x; x = x->next) { |
| 272 if(x->type == XMLNODE_TYPE_ATTRIB && | 258 if(x->type == XMLNODE_TYPE_ATTRIB && |
| 273 !strcmp(attr, x->name) && | 259 purple_strequal(attr, x->name) && |
| 274 _xmlnode_compare_xmlns(xmlns, x->xmlns)) { | 260 purple_strequal(xmlns, x->xmlns)) { |
| 275 return x->data; | 261 return x->data; |
| 276 } | 262 } |
| 277 } | 263 } |
| 278 | 264 |
| 279 return NULL; | 265 return NULL; |
| 380 /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ | 366 /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 381 const char *xmlns = NULL; | 367 const char *xmlns = NULL; |
| 382 if(ns) | 368 if(ns) |
| 383 xmlns = xmlnode_get_namespace(x); | 369 xmlns = xmlnode_get_namespace(x); |
| 384 | 370 |
| 385 if(x->type == XMLNODE_TYPE_TAG && name && !strcmp(parent_name, x->name) | 371 if(x->type == XMLNODE_TYPE_TAG && purple_strequal(parent_name, x->name) |
| 386 && (!ns || (xmlns && !strcmp(ns, xmlns)))) { | 372 && purple_strequal(ns, xmlns)) { |
| 387 ret = x; | 373 ret = x; |
| 388 break; | 374 break; |
| 389 } | 375 } |
| 390 } | 376 } |
| 391 | 377 |
| 469 | 455 |
| 470 if (node->namespace_map) { | 456 if (node->namespace_map) { |
| 471 g_hash_table_foreach(node->namespace_map, | 457 g_hash_table_foreach(node->namespace_map, |
| 472 (GHFunc)xmlnode_to_str_foreach_append_ns, text); | 458 (GHFunc)xmlnode_to_str_foreach_append_ns, text); |
| 473 } else if (node->xmlns) { | 459 } else if (node->xmlns) { |
| 474 if(!node->parent || !node->parent->xmlns || strcmp(node->xmlns, node->parent->xmlns)) | 460 if(!node->parent || !purple_strequal(node->xmlns, node->parent->xmlns)) |
| 475 { | 461 { |
| 476 char *xmlns = g_markup_escape_text(node->xmlns, -1); | 462 char *xmlns = g_markup_escape_text(node->xmlns, -1); |
| 477 g_string_append_printf(text, " xmlns='%s'", xmlns); | 463 g_string_append_printf(text, " xmlns='%s'", xmlns); |
| 478 g_free(xmlns); | 464 g_free(xmlns); |
| 479 } | 465 } |
| 864 /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ | 850 /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 865 const char *xmlns = NULL; | 851 const char *xmlns = NULL; |
| 866 if(ns) | 852 if(ns) |
| 867 xmlns = xmlnode_get_namespace(sibling); | 853 xmlns = xmlnode_get_namespace(sibling); |
| 868 | 854 |
| 869 if(sibling->type == XMLNODE_TYPE_TAG && !strcmp(node->name, sibling->name) && | 855 if(sibling->type == XMLNODE_TYPE_TAG && purple_strequal(node->name, sibling->name) && |
| 870 (!ns || (xmlns && !strcmp(ns, xmlns)))) | 856 purple_strequal(ns, xmlns)) |
| 871 return sibling; | 857 return sibling; |
| 872 } | 858 } |
| 873 | 859 |
| 874 return NULL; | 860 return NULL; |
| 875 } | 861 } |
