comparison libpurple/protocols/jabber/disco.c @ 25648:050052891c55

Pass IQ handlers type, from, id, and the child node As QuLogic pointed out in 8a80f271, it's pointless for the handlers to re-get the information from the IQ stanza. Additionally, instead of string-matching the type everywhere, pass around a JabberIqType. Last, 'child' cannot be NULL, but 'from' may be.
author Paul Aurich <paul@darkrain42.org>
date Sun, 08 Feb 2009 06:31:18 +0000
parents a73791d35fcc
children 439f07ce4c8a
comparison
equal deleted inserted replaced
25647:969c89c09ad7 25648:050052891c55
83 js->bs_proxies = g_list_remove(js->bs_proxies, sh); 83 js->bs_proxies = g_list_remove(js->bs_proxies, sh);
84 } 84 }
85 } 85 }
86 86
87 87
88 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) { 88 void jabber_disco_info_parse(JabberStream *js, const char *from,
89 const char *from = xmlnode_get_attrib(packet, "from"); 89 JabberIqType type, const char *id,
90 const char *type = xmlnode_get_attrib(packet, "type"); 90 xmlnode *in_query) {
91 91
92 if(!from || !type) 92 if(!from)
93 return; 93 return;
94 94
95 if(!strcmp(type, "get")) { 95 if(type == JABBER_IQ_GET) {
96 xmlnode *query, *identity, *feature; 96 xmlnode *query, *identity, *feature;
97 JabberIq *iq; 97 JabberIq *iq;
98 98 const char *node = xmlnode_get_attrib(in_query, "node");
99 xmlnode *in_query;
100 const char *node = NULL;
101
102 if((in_query = xmlnode_get_child(packet, "query"))) {
103 node = xmlnode_get_attrib(in_query, "node");
104 }
105
106 99
107 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, 100 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
108 "http://jabber.org/protocol/disco#info"); 101 "http://jabber.org/protocol/disco#info");
109 102
110 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); 103 jabber_iq_set_id(iq, id);
111 104
112 xmlnode_set_attrib(iq->node, "to", from); 105 xmlnode_set_attrib(iq->node, "to", from);
113 query = xmlnode_get_child(iq->node, "query"); 106 query = xmlnode_get_child(iq->node, "query");
114 107
115 if(node) 108 if(node)
198 xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas"); 191 xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas");
199 } 192 }
200 } 193 }
201 194
202 jabber_iq_send(iq); 195 jabber_iq_send(iq);
203 } else if(!strcmp(type, "result")) { 196 } else if(type == JABBER_IQ_RESULT) {
204 xmlnode *query = xmlnode_get_child(packet, "query");
205 xmlnode *child; 197 xmlnode *child;
206 JabberID *jid; 198 JabberID *jid;
207 JabberBuddy *jb; 199 JabberBuddy *jb;
208 JabberBuddyResource *jbr = NULL; 200 JabberBuddyResource *jbr = NULL;
209 JabberCapabilities capabilities = JABBER_CAP_NONE; 201 JabberCapabilities capabilities = JABBER_CAP_NONE;
216 } 208 }
217 209
218 if(jbr) 210 if(jbr)
219 capabilities = jbr->capabilities; 211 capabilities = jbr->capabilities;
220 212
221 for(child = query->child; child; child = child->next) { 213 for(child = in_query->child; child; child = child->next) {
222 if(child->type != XMLNODE_TYPE_TAG) 214 if(child->type != XMLNODE_TYPE_TAG)
223 continue; 215 continue;
224 216
225 if(!strcmp(child->name, "identity")) { 217 if(!strcmp(child->name, "identity")) {
226 const char *category = xmlnode_get_attrib(child, "category"); 218 const char *category = xmlnode_get_attrib(child, "category");
283 275
284 if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) { 276 if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) {
285 jdicd->callback(js, from, capabilities, jdicd->data); 277 jdicd->callback(js, from, capabilities, jdicd->data);
286 g_hash_table_remove(js->disco_callbacks, from); 278 g_hash_table_remove(js->disco_callbacks, from);
287 } 279 }
288 } else if(!strcmp(type, "error")) { 280 } else if(type == JABBER_IQ_ERROR) {
289 JabberID *jid; 281 JabberID *jid;
290 JabberBuddy *jb; 282 JabberBuddy *jb;
291 JabberBuddyResource *jbr = NULL; 283 JabberBuddyResource *jbr = NULL;
292 JabberCapabilities capabilities = JABBER_CAP_NONE; 284 JabberCapabilities capabilities = JABBER_CAP_NONE;
293 struct _jabber_disco_info_cb_data *jdicd; 285 struct _jabber_disco_info_cb_data *jdicd;
307 jdicd->callback(js, from, capabilities, jdicd->data); 299 jdicd->callback(js, from, capabilities, jdicd->data);
308 g_hash_table_remove(js->disco_callbacks, from); 300 g_hash_table_remove(js->disco_callbacks, from);
309 } 301 }
310 } 302 }
311 303
312 void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) { 304 void jabber_disco_items_parse(JabberStream *js, const char *from,
313 const char *from = xmlnode_get_attrib(packet, "from"); 305 JabberIqType type, const char *id,
314 const char *type = xmlnode_get_attrib(packet, "type"); 306 xmlnode *query) {
315 307 if(type == JABBER_IQ_GET) {
316 if(type && !strcmp(type, "get")) {
317 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, 308 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
318 "http://jabber.org/protocol/disco#items"); 309 "http://jabber.org/protocol/disco#items");
319 310
320 /* preserve node */ 311 /* preserve node */
321 xmlnode *iq_query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#items"); 312 xmlnode *iq_query = xmlnode_get_child(iq->node, "query");
322 if(iq_query) { 313 const char *node = xmlnode_get_attrib(query, "node");
323 xmlnode *query = xmlnode_get_child_with_namespace(packet,"query","http://jabber.org/protocol/disco#items"); 314 if(node)
324 if(query) { 315 xmlnode_set_attrib(iq_query,"node",node);
325 const char *node = xmlnode_get_attrib(query,"node"); 316
326 if(node) 317 jabber_iq_set_id(iq, id);
327 xmlnode_set_attrib(iq_query,"node",node); 318
328 } 319 if (from)
329 } 320 xmlnode_set_attrib(iq->node, "to", from);
330
331 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
332
333 xmlnode_set_attrib(iq->node, "to", from);
334 jabber_iq_send(iq); 321 jabber_iq_send(iq);
335 } 322 }
336 } 323 }
337 324
338 static void 325 static void