Mercurial > pidgin.yaz
changeset 8135:8f4ce853e685
[gaim-migrate @ 8840]
created a convenience function, and used it. a lot.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 17 Jan 2004 19:36:29 +0000 |
parents | ea3eb461efc0 |
children | fab67640b59f |
files | src/blist.c src/protocols/jabber/auth.c src/protocols/jabber/buddy.c src/protocols/jabber/chat.c src/protocols/jabber/iq.c src/protocols/jabber/jabber.c src/protocols/jabber/message.c src/protocols/jabber/presence.c src/protocols/jabber/roster.c src/protocols/jabber/si.c src/protocols/jabber/xdata.c src/xmlnode.c src/xmlnode.h |
diffstat | 13 files changed, 255 insertions(+), 231 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/blist.c Sat Jan 17 19:36:29 2004 +0000 @@ -1979,9 +1979,7 @@ gaim_blist_add_buddy(buddy, contact, group, gaim_blist_get_last_child((GaimBlistNode*)contact)); - for(x = bnode->child; x; x = x->next) { - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) - continue; + for(x = xmlnode_get_child(bnode, "setting"); x; x = xmlnode_get_next_twin(x)) { parse_setting((GaimBlistNode*)buddy, x); } @@ -2004,7 +2002,7 @@ } for(x = cnode->child; x; x = x->next) { - if(x->type != NODE_TYPE_TAG) + if(x->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(x->name, "buddy")) parse_buddy(group, contact, x); @@ -2043,11 +2041,9 @@ components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - for(x = cnode->child; x; x = x->next) { + for(x = xmlnode_get_child(cnode, "component"); x; x = xmlnode_get_next_twin(x)) { const char *name; char *value; - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "component")) - continue; name = xmlnode_get_attrib(x, "name"); value = xmlnode_get_data(x); @@ -2058,9 +2054,7 @@ gaim_blist_add_chat(chat, group, gaim_blist_get_last_child((GaimBlistNode*)group)); - for(x = cnode->child; x; x = x->next) { - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) - continue; + for(x = xmlnode_get_child(cnode, "setting"); x; x = xmlnode_get_next_twin(x)) { parse_setting((GaimBlistNode*)chat, x); } @@ -2083,7 +2077,7 @@ gaim_blist_get_last_sibling(gaimbuddylist->root)); for(cnode = groupnode->child; cnode; cnode = cnode->next) { - if(cnode->type != NODE_TYPE_TAG) + if(cnode->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(cnode->name, "setting")) parse_setting((GaimBlistNode*)group, cnode); @@ -2122,11 +2116,8 @@ blist = xmlnode_get_child(gaim, "blist"); if(blist) { xmlnode *groupnode; - for(groupnode = blist->child; groupnode; groupnode = groupnode->next) { - if(groupnode->type != NODE_TYPE_TAG || - strcmp(groupnode->name, "group")) - continue; - + for(groupnode = xmlnode_get_child(blist, "group"); groupnode; + groupnode = xmlnode_get_next_twin(groupnode)) { parse_group(groupnode); } } @@ -2156,7 +2147,7 @@ for(x = anode->child; x; x = x->next) { char *name; - if(x->type != NODE_TYPE_TAG) + if(x->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(x->name, "permit")) {
--- a/src/protocols/jabber/auth.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/auth.c Sat Jan 17 19:36:29 2004 +0000 @@ -66,16 +66,15 @@ return; } - for(mechnode = mechs->child; mechnode; mechnode = mechnode->next) + for(mechnode = xmlnode_get_child(mechs, "mechanism"); mechnode; + mechnode = xmlnode_get_next_twin(mechnode)) { - if(mechnode->type == NODE_TYPE_TAG) { - char *mech_name = xmlnode_get_data(mechnode); - if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) - digest_md5 = TRUE; - else if(mech_name && !strcmp(mech_name, "PLAIN")) - plain = TRUE; - g_free(mech_name); - } + char *mech_name = xmlnode_get_data(mechnode); + if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) + digest_md5 = TRUE; + else if(mech_name && !strcmp(mech_name, "PLAIN")) + plain = TRUE; + g_free(mech_name); } auth = xmlnode_new("auth");
--- a/src/protocols/jabber/buddy.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/buddy.c Sat Jan 17 19:36:29 2004 +0000 @@ -594,7 +594,7 @@ xmlnode *child2; char *text; - if(child->type != NODE_TYPE_TAG) + if(child->type != XMLNODE_TYPE_TAG) continue; text = xmlnode_get_data(child); @@ -606,7 +606,7 @@ { char *text2; - if(child2->type != NODE_TYPE_TAG) + if(child2->type != XMLNODE_TYPE_TAG) continue; text2 = xmlnode_get_data(child2); @@ -645,7 +645,7 @@ { char *text2; - if(child2->type != NODE_TYPE_TAG) + if(child2->type != XMLNODE_TYPE_TAG) continue; text2 = xmlnode_get_data(child2); @@ -722,7 +722,7 @@ { char *text2; - if(child2->type != NODE_TYPE_TAG) + if(child2->type != XMLNODE_TYPE_TAG) continue; text2 = xmlnode_get_data(child2);
--- a/src/protocols/jabber/chat.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/chat.c Sat Jan 17 19:36:29 2004 +0000 @@ -310,11 +310,8 @@ if(!(query = xmlnode_get_child(packet, "query"))) return; - for(x = query->child; x; x = x->next) { + for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { const char *xmlns; - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "x")) - continue; - if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) continue; @@ -462,10 +459,8 @@ if(!(query = xmlnode_get_child(packet, "query"))) return; - for(x = query->child; x; x = x->next) { + for(x = xmlnode_get_child(query, "x"); x; x = xmlnode_get_next_twin(x)) { const char *xmlns; - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "x")) - continue; if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) continue; @@ -632,16 +627,12 @@ return; } - for(item = query->child; item; item = item->next) { + for(item = xmlnode_get_child(query, "item"); item; + item = xmlnode_get_next_twin(item)) { const char *name; GaimRoomlistRoom *room; JabberID *jid; - if(item->type != NODE_TYPE_TAG) - continue; - if(strcmp(item->name, "item")) - continue; - if(!(jid = jabber_id_new(xmlnode_get_attrib(item, "jid")))) continue; name = xmlnode_get_attrib(item, "name");
--- a/src/protocols/jabber/iq.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/iq.c Sat Jan 17 19:36:29 2004 +0000 @@ -296,7 +296,7 @@ jabber_id_free(jid); for(child = query->child; child; child = child->next) { - if(child->type != NODE_TYPE_TAG) + if(child->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(child->name, "identity")) { @@ -365,14 +365,11 @@ query = xmlnode_get_child(packet, "query"); - for(child = query->child; child; child = child->next) { + for(child = xmlnode_get_child(query, "item"); child; + child = xmlnode_get_next_twin(child)) { JabberIq *iq; const char *jid; - if(child->type != NODE_TYPE_TAG) - continue; - if(strcmp(child->name, "item")) - continue; if(!(jid = xmlnode_get_attrib(child, "jid"))) continue; @@ -399,10 +396,12 @@ JabberCallbackData *jcd; xmlnode *query; const char *xmlns; - const char *type, *id; + const char *type, *id, *from; + JabberIq *iq; query = xmlnode_get_child(packet, "query"); type = xmlnode_get_attrib(packet, "type"); + from = xmlnode_get_attrib(packet, "from"); if(type && query && (xmlns = xmlnode_get_attrib(query, "xmlns"))) { if(!strcmp(type, "set")) { @@ -453,6 +452,24 @@ && *id && (jcd = g_hash_table_lookup(js->callbacks, id))) { jcd->callback(js, packet, jcd->data); g_hash_table_remove(js->callbacks, id); + return; + } + + /* Default error reply mandated by XMPP-CORE */ + + iq = jabber_iq_new(js, JABBER_IQ_ERROR); + xmlnode_set_attrib(iq->node, "id", id); + xmlnode_set_attrib(iq->node, "to", from); + + for(query = packet->child; query; query = query->next) { + switch(query->type) { + case XMLNODE_TYPE_TAG: + break; + case XMLNODE_TYPE_ATTRIB: + break; + case XMLNODE_TYPE_DATA: + break; + } } }
--- a/src/protocols/jabber/jabber.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/jabber.c Sat Jan 17 19:36:29 2004 +0000 @@ -584,11 +584,8 @@ return; } - for(x = packet->child; x; x = x->next) { + for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { const char *xmlns; - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "x")) - continue; - if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) continue;
--- a/src/protocols/jabber/message.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/message.c Sat Jan 17 19:36:29 2004 +0000 @@ -259,7 +259,7 @@ jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); for(child = packet->child; child; child = child->next) { - if(child->type != NODE_TYPE_TAG) + if(child->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(child->name, "subject")) {
--- a/src/protocols/jabber/presence.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/presence.c Sat Jan 17 19:36:29 2004 +0000 @@ -218,7 +218,7 @@ for(y = packet->child; y; y = y->next) { - if(y->type != NODE_TYPE_TAG) + if(y->type != XMLNODE_TYPE_TAG) continue; if(!strcmp(y->name, "status")) { @@ -315,11 +315,9 @@ jabber_buddy_remove_resource(jb, jid->resource); if(chat->muc) { xmlnode *x; - for(x = packet->child; x; x = x->next) { + for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { const char *xmlns, *nick, *code; xmlnode *stat, *item; - if(x->type != NODE_TYPE_TAG || strcmp(x->name, "x")) - continue; if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || strcmp(xmlns, "http://jabber.org/protocol/muc#user")) continue;
--- a/src/protocols/jabber/roster.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/roster.c Sat Jan 17 19:36:29 2004 +0000 @@ -147,14 +147,11 @@ js->roster_parsed = TRUE; - for(item = query->child; item; item = item->next) + for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) { const char *jid, *name, *subscription, *ask; JabberBuddy *jb; - if(item->type != NODE_TYPE_TAG || strcmp(item->name, "item")) - continue; - subscription = xmlnode_get_attrib(item, "subscription"); jid = xmlnode_get_attrib(item, "jid"); name = xmlnode_get_attrib(item, "name"); @@ -186,10 +183,8 @@ } else { GSList *groups = NULL; - for(group = item->child; group; group = group->next) { + for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) { char *group_name; - if(group->type != NODE_TYPE_TAG || strcmp(group->name, "group")) - continue; if(!(group_name = xmlnode_get_data(group))) group_name = g_strdup("");
--- a/src/protocols/jabber/si.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/si.c Sat Jan 17 19:36:29 2004 +0000 @@ -82,18 +82,15 @@ if(!(feature = xmlnode_get_child(si, "feature"))) return; - for(x = feature->child; x; x = x->next) { + for(x = xmlnode_get_child(feature, "x"); x; x = xmlnode_get_next_twin(x)) { const char *xmlns; - if(x->type != NODE_TYPE_TAG) - continue; if(!(xmlns = xmlnode_get_attrib(x, "xmlns"))) continue; if(strcmp(xmlns, "jabber:x:data")) continue; - for(field = x->child; field; field = field->next) { + for(field = xmlnode_get_child(x, "field"); field; + field = xmlnode_get_next_twin(field)) { const char *var; - if(field->type != NODE_TYPE_TAG) - continue; if(!(var = xmlnode_get_attrib(field, "var"))) continue; if(!strcmp(var, "stream-method")) {
--- a/src/protocols/jabber/xdata.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/protocols/jabber/xdata.c Sat Jan 17 19:36:29 2004 +0000 @@ -165,163 +165,157 @@ group = gaim_request_field_group_new(NULL); gaim_request_fields_add_group(fields, group); - for(fn = packet->child; fn; fn = fn->next) { - if(fn->type == NODE_TYPE_TAG && !strcmp(fn->name, "field")) { - xmlnode *valuenode; - const char *type = xmlnode_get_attrib(fn, "type"); - const char *label = xmlnode_get_attrib(fn, "label"); - const char *var = xmlnode_get_attrib(fn, "var"); - char *value = NULL; + for(fn = xmlnode_get_child(packet, "field"); fn; fn = xmlnode_get_next_twin(fn)) { + xmlnode *valuenode; + const char *type = xmlnode_get_attrib(fn, "type"); + const char *label = xmlnode_get_attrib(fn, "label"); + const char *var = xmlnode_get_attrib(fn, "var"); + char *value = NULL; + + if(!type) + continue; + + if(!var && strcmp(type, "fixed")) + continue; + if(!label) + label = var; + + if((valuenode = xmlnode_get_child(fn, "value"))) + value = xmlnode_get_data(valuenode); + + + /* XXX: handle <required/> */ + + if(!strcmp(type, "text-private")) { + if((valuenode = xmlnode_get_child(fn, "value"))) + value = xmlnode_get_data(valuenode); + + field = gaim_request_field_string_new(var, label, + value ? value : "", FALSE); + gaim_request_field_string_set_masked(field, TRUE); + gaim_request_field_group_add_field(group, field); + + g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); + + if(value) + g_free(value); + } else if(!strcmp(type, "text-multi") || !strcmp(type, "jid-multi")) { + GString *str = g_string_new(""); + + for(valuenode = xmlnode_get_child(fn, "value"); valuenode; + valuenode = xmlnode_get_next_twin(valuenode)) { + + if(!(value = xmlnode_get_data(valuenode))) + continue; + + g_string_append_printf(str, "%s\n", value); + g_free(value); + } + + field = gaim_request_field_string_new(var, label, + str->str, TRUE); + gaim_request_field_group_add_field(group, field); - if(!type) - continue; + g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI)); + + g_string_free(str, TRUE); + } else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) { + xmlnode *optnode; + GList *selected = NULL; + + field = gaim_request_field_list_new(var, label); + + if(!strcmp(type, "list-multi")) { + gaim_request_field_list_set_multi_select(field, TRUE); + g_hash_table_replace(data->fields, g_strdup(var), + GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI)); + } else { + g_hash_table_replace(data->fields, g_strdup(var), + GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE)); + } + + for(valuenode = xmlnode_get_child(fn, "value"); valuenode; + valuenode = xmlnode_get_next_twin(valuenode)) { + selected = g_list_prepend(selected, xmlnode_get_data(valuenode)); + } - if(!var && strcmp(type, "fixed")) - continue; - if(!label) - label = var; + for(optnode = xmlnode_get_child(fn, "option"); optnode; + optnode = xmlnode_get_next_twin(optnode)) { + const char *lbl; + + if(!(valuenode = xmlnode_get_child(optnode, "value"))) + continue; + + if(!(value = xmlnode_get_data(valuenode))) + continue; + + if(!(lbl = xmlnode_get_attrib(optnode, "label"))) + label = value; + + data->values = g_slist_prepend(data->values, value); + + gaim_request_field_list_add(field, lbl, value); + if(g_list_find_custom(selected, value, (GCompareFunc)strcmp)) + gaim_request_field_list_add_selected(field, lbl); + } + gaim_request_field_group_add_field(group, field); + + while(selected) { + g_free(selected->data); + selected = g_list_delete_link(selected, selected); + } + + } else if(!strcmp(type, "boolean")) { + gboolean def = FALSE; if((valuenode = xmlnode_get_child(fn, "value"))) value = xmlnode_get_data(valuenode); - - /* XXX: handle <required/> */ - - if(!strcmp(type, "text-private")) { - if((valuenode = xmlnode_get_child(fn, "value"))) - value = xmlnode_get_data(valuenode); - - field = gaim_request_field_string_new(var, label, - value ? value : "", FALSE); - gaim_request_field_string_set_masked(field, TRUE); - gaim_request_field_group_add_field(group, field); - - g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); + if(value && (!strcasecmp(value, "yes") || + !strcasecmp(value, "true") || !strcasecmp(value, "1"))) + def = TRUE; - if(value) - g_free(value); - } else if(!strcmp(type, "text-multi") || !strcmp(type, "jid-multi")) { - GString *str = g_string_new(""); + field = gaim_request_field_bool_new(var, label, def); + gaim_request_field_group_add_field(group, field); - for(valuenode = fn->child; valuenode; valuenode = valuenode->next) { - if(valuenode->type != NODE_TYPE_TAG || strcmp(valuenode->name, "value")) - continue; - - if(!(value = xmlnode_get_data(valuenode))) - continue; - - g_string_append_printf(str, "%s\n", value); - g_free(value); - } + g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN)); - field = gaim_request_field_string_new(var, label, - str->str, TRUE); - gaim_request_field_group_add_field(group, field); - - g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_MULTI)); - - g_string_free(str, TRUE); - } else if(!strcmp(type, "list-single") || !strcmp(type, "list-multi")) { - xmlnode *optnode; - GList *selected = NULL; - - field = gaim_request_field_list_new(var, label); + if(value) + g_free(value); + } else if(!strcmp(type, "fixed") && value) { + if((valuenode = xmlnode_get_child(fn, "value"))) + value = xmlnode_get_data(valuenode); - if(!strcmp(type, "list-multi")) { - gaim_request_field_list_set_multi_select(field, TRUE); - g_hash_table_replace(data->fields, g_strdup(var), - GINT_TO_POINTER(JABBER_X_DATA_LIST_MULTI)); - } else { - g_hash_table_replace(data->fields, g_strdup(var), - GINT_TO_POINTER(JABBER_X_DATA_LIST_SINGLE)); - } - - for(valuenode = fn->child; valuenode; valuenode = valuenode->next) { - if(valuenode->type != NODE_TYPE_TAG || strcmp(valuenode->name, "value")) - continue; - selected = g_list_prepend(selected, xmlnode_get_data(valuenode)); - } - - for(optnode = fn->child; optnode; optnode = optnode->next) { - const char *lbl; - - if(optnode->type != NODE_TYPE_TAG || strcmp(optnode->name, "option")) - continue; - - if(!(valuenode = xmlnode_get_child(optnode, "value"))) - continue; + field = gaim_request_field_label_new("", value); + gaim_request_field_group_add_field(group, field); - if(!(value = xmlnode_get_data(valuenode))) - continue; - - if(!(lbl = xmlnode_get_attrib(optnode, "label"))) - label = value; - - data->values = g_slist_prepend(data->values, value); - - gaim_request_field_list_add(field, lbl, value); - if(g_list_find_custom(selected, value, (GCompareFunc)strcmp)) - gaim_request_field_list_add_selected(field, lbl); - } - gaim_request_field_group_add_field(group, field); + if(value) + g_free(value); + } else if(!strcmp(type, "hidden")) { + if((valuenode = xmlnode_get_child(fn, "value"))) + value = xmlnode_get_data(valuenode); - while(selected) { - g_free(selected->data); - selected = g_list_delete_link(selected, selected); - } - - } else if(!strcmp(type, "boolean")) { - gboolean def = FALSE; + field = gaim_request_field_string_new(var, "", value ? value : "", + FALSE); + gaim_request_field_set_visible(field, FALSE); + gaim_request_field_group_add_field(group, field); - if((valuenode = xmlnode_get_child(fn, "value"))) - value = xmlnode_get_data(valuenode); - - if(value && (!strcasecmp(value, "yes") || - !strcasecmp(value, "true") || !strcasecmp(value, "1"))) - def = TRUE; - - field = gaim_request_field_bool_new(var, label, def); - gaim_request_field_group_add_field(group, field); - - g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_BOOLEAN)); + g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); - if(value) - g_free(value); - } else if(!strcmp(type, "fixed") && value) { - if((valuenode = xmlnode_get_child(fn, "value"))) - value = xmlnode_get_data(valuenode); - - field = gaim_request_field_label_new("", value); - gaim_request_field_group_add_field(group, field); - - if(value) - g_free(value); - } else if(!strcmp(type, "hidden")) { - if((valuenode = xmlnode_get_child(fn, "value"))) - value = xmlnode_get_data(valuenode); + if(value) + g_free(value); + } else { /* text-single, jid-single, and the default */ + if((valuenode = xmlnode_get_child(fn, "value"))) + value = xmlnode_get_data(valuenode); - field = gaim_request_field_string_new(var, "", value ? value : "", - FALSE); - gaim_request_field_set_visible(field, FALSE); - gaim_request_field_group_add_field(group, field); - - g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); + field = gaim_request_field_string_new(var, label, + value ? value : "", FALSE); + gaim_request_field_group_add_field(group, field); - if(value) - g_free(value); - } else { /* text-single, jid-single, and the default */ - if((valuenode = xmlnode_get_child(fn, "value"))) - value = xmlnode_get_data(valuenode); + g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); - field = gaim_request_field_string_new(var, label, - value ? value : "", FALSE); - gaim_request_field_group_add_field(group, field); - - g_hash_table_replace(data->fields, g_strdup(var), GINT_TO_POINTER(JABBER_X_DATA_TEXT_SINGLE)); - - if(value) - g_free(value); - } + if(value) + g_free(value); } }
--- a/src/xmlnode.c Sat Jan 17 19:21:39 2004 +0000 +++ b/src/xmlnode.c Sat Jan 17 19:36:29 2004 +0000 @@ -35,7 +35,7 @@ #include "xmlnode.h" static xmlnode* -new_node(const char *name, NodeType type) +new_node(const char *name, XMLNodeType type) { xmlnode *node = g_new0(xmlnode, 1); if(name) @@ -50,7 +50,7 @@ { g_return_val_if_fail(name != NULL, NULL); - return new_node(name, NODE_TYPE_TAG); + return new_node(name, XMLNODE_TYPE_TAG); } xmlnode *xmlnode_new_child(xmlnode *parent, const char *name) @@ -60,7 +60,7 @@ g_return_val_if_fail(parent != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); - node = new_node(name, NODE_TYPE_TAG); + node = new_node(name, XMLNODE_TYPE_TAG); xmlnode_insert_child(parent, node); @@ -96,7 +96,7 @@ real_size = size == -1 ? strlen(data) : size; - node = new_node(NULL, NODE_TYPE_DATA); + node = new_node(NULL, XMLNODE_TYPE_DATA); node->data = g_memdup(data, real_size); node->data_sz = real_size; @@ -114,7 +114,7 @@ for(attr_node = node->child; attr_node; attr_node = attr_node->next) { - if(attr_node->type == NODE_TYPE_ATTRIB && + if(attr_node->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr_node->name, attr)) { if(node->child == attr_node) { node->child = attr_node->next; @@ -139,7 +139,7 @@ xmlnode_remove_attrib(node, attr); - attrib_node = new_node(attr, NODE_TYPE_ATTRIB); + attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); attrib_node->data = g_strdup(value); @@ -154,7 +154,7 @@ g_return_val_if_fail(node != NULL, NULL); for(x = node->child; x; x = x->next) { - if(x->type == NODE_TYPE_ATTRIB && !strcmp(attr, x->name)) { + if(x->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr, x->name)) { return x->data; } } @@ -196,7 +196,7 @@ child_name = names[1]; for(x = parent->child; x; x = x->next) { - if(x->type == NODE_TYPE_TAG && name && !strcmp(parent_name, x->name)) { + if(x->type == XMLNODE_TYPE_TAG && name && !strcmp(parent_name, x->name)) { ret = x; break; } @@ -220,7 +220,7 @@ for(c = node->child; c; c = c->next) { - if(c->type == NODE_TYPE_DATA) { + if(c->type == XMLNODE_TYPE_DATA) { if(!str) str = g_string_new(""); str = g_string_append_len(str, c->data, c->data_sz); @@ -249,13 +249,13 @@ for(c = node->child; c; c = c->next) { - if(c->type == NODE_TYPE_ATTRIB) { + if(c->type == XMLNODE_TYPE_ATTRIB) { esc = g_markup_escape_text(c->name, -1); esc2 = g_markup_escape_text(c->data, -1); g_string_append_printf(text, " %s='%s'", esc, esc2); g_free(esc); g_free(esc2); - } else if(c->type == NODE_TYPE_TAG || c->type == NODE_TYPE_DATA) { + } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { need_end = TRUE; } } @@ -265,12 +265,12 @@ for(c = node->child; c; c = c->next) { - if(c->type == NODE_TYPE_TAG) { + if(c->type == XMLNODE_TYPE_TAG) { int esc_len; esc = xmlnode_to_str(c, &esc_len); text = g_string_append_len(text, esc, esc_len); g_free(esc); - } else if(c->type == NODE_TYPE_DATA) { + } else if(c->type == XMLNODE_TYPE_DATA) { esc = g_markup_escape_text(c->data, c->data_sz); text = g_string_append(text, esc); g_free(esc); @@ -380,3 +380,47 @@ g_free(xpd); return ret; } + +xmlnode *xmlnode_copy(xmlnode *src) +{ + xmlnode *ret; + xmlnode *child; + xmlnode *sibling = NULL; + + if(!src) + return NULL; + + ret = new_node(src->name, src->type); + if(src->data) { + ret->data = g_memdup(src->data, src->data_sz); + ret->data_sz = src->data_sz; + } + + for(child = src->child; child; child = child->next) { + if(sibling) { + sibling->next = xmlnode_copy(child); + sibling = sibling->next; + } else { + ret->child = xmlnode_copy(child); + sibling = ret->child; + } + sibling->parent = ret; + } + + return ret; +} + +xmlnode *xmlnode_get_next_twin(xmlnode *node) { + xmlnode *sibling; + + g_return_val_if_fail(node != NULL, NULL); + g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); + + for(sibling = node->next; sibling; sibling = sibling->next) { + if(sibling->type == XMLNODE_TYPE_TAG && !strcmp(node->name, sibling->name)) + return sibling; + } + + return NULL; +} +
--- a/src/xmlnode.h Sat Jan 17 19:21:39 2004 +0000 +++ b/src/xmlnode.h Sat Jan 17 19:36:29 2004 +0000 @@ -24,17 +24,17 @@ #ifndef _GAIM_XMLNODE_H_ #define _GAIM_XMLNODE_H_ -typedef enum _NodeType +typedef enum _XMLNodeType { - NODE_TYPE_TAG, - NODE_TYPE_ATTRIB, - NODE_TYPE_DATA -} NodeType; + XMLNODE_TYPE_TAG, + XMLNODE_TYPE_ATTRIB, + XMLNODE_TYPE_DATA +} XMLNodeType; typedef struct _xmlnode { char *name; - NodeType type; + XMLNodeType type; char *data; size_t data_sz; struct _xmlnode *parent; @@ -46,6 +46,7 @@ xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); void xmlnode_insert_child(xmlnode *parent, xmlnode *child); xmlnode *xmlnode_get_child(xmlnode *parent, const char *name); +xmlnode *xmlnode_get_next_twin(xmlnode *node); void xmlnode_insert_data(xmlnode *parent, const char *data, size_t size); char *xmlnode_get_data(xmlnode *node); void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value);