Mercurial > pidgin
comparison libpurple/protocols/jabber/iq.c @ 24952:bcad7dc4b453
propagate from branch 'im.pidgin.pidgin' (head 633ffe234af48ead3631ae62e23840b4438fcf5f)
to branch 'im.pidgin.maiku.vv' (head 5585b8e919d9adb0eb491c714768027e81f1918c)
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Thu, 06 Nov 2008 03:20:05 +0000 |
parents | 8bfa1f01f035 040c66dffbf0 |
children | 88f183f7dfc7 |
comparison
equal
deleted
inserted
replaced
24951:94224a5563db | 24952:bcad7dc4b453 |
---|---|
104 iq->callback_data = data; | 104 iq->callback_data = data; |
105 } | 105 } |
106 | 106 |
107 void jabber_iq_set_id(JabberIq *iq, const char *id) | 107 void jabber_iq_set_id(JabberIq *iq, const char *id) |
108 { | 108 { |
109 if(iq->id) | 109 g_free(iq->id); |
110 g_free(iq->id); | |
111 | 110 |
112 if(id) { | 111 if(id) { |
113 xmlnode_set_attrib(iq->node, "id", id); | 112 xmlnode_set_attrib(iq->node, "id", id); |
114 iq->id = g_strdup(id); | 113 iq->id = g_strdup(id); |
115 } else { | 114 } else { |
319 query = xmlnode_get_child(packet, "query"); | 318 query = xmlnode_get_child(packet, "query"); |
320 type = xmlnode_get_attrib(packet, "type"); | 319 type = xmlnode_get_attrib(packet, "type"); |
321 from = xmlnode_get_attrib(packet, "from"); | 320 from = xmlnode_get_attrib(packet, "from"); |
322 id = xmlnode_get_attrib(packet, "id"); | 321 id = xmlnode_get_attrib(packet, "id"); |
323 | 322 |
323 if(type == NULL || !(!strcmp(type, "get") || !strcmp(type, "set") | |
324 || !strcmp(type, "result") || !strcmp(type, "error"))) { | |
325 purple_debug_error("jabber", "IQ with invalid type ('%s') - ignoring.\n", | |
326 type ? type : "(null)"); | |
327 return; | |
328 } | |
329 | |
330 /* All IQs must have an ID, so send an error for a set/get that doesn't */ | |
331 if(!id || !*id) { | |
332 | |
333 if(!strcmp(type, "set") || !strcmp(type, "get")) { | |
334 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); | |
335 | |
336 xmlnode_free(iq->node); | |
337 iq->node = xmlnode_copy(packet); | |
338 xmlnode_set_attrib(iq->node, "to", from); | |
339 xmlnode_remove_attrib(iq->node, "from"); | |
340 xmlnode_set_attrib(iq->node, "type", "error"); | |
341 /* This id is clearly not useful, but we must put something there for a valid stanza */ | |
342 iq->id = jabber_get_next_id(js); | |
343 xmlnode_set_attrib(iq->node, "id", iq->id); | |
344 error = xmlnode_new_child(iq->node, "error"); | |
345 xmlnode_set_attrib(error, "type", "modify"); | |
346 x = xmlnode_new_child(error, "bad-request"); | |
347 xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
348 | |
349 jabber_iq_send(iq); | |
350 } else | |
351 purple_debug_error("jabber", "IQ of type '%s' missing id - ignoring.\n", type); | |
352 | |
353 return; | |
354 } | |
355 | |
324 /* First, lets see if a special callback got registered */ | 356 /* First, lets see if a special callback got registered */ |
325 | 357 |
326 if(type && (!strcmp(type, "result") || !strcmp(type, "error"))) { | 358 if(!strcmp(type, "result") || !strcmp(type, "error")) { |
327 if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { | 359 if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { |
328 jcd->callback(js, packet, jcd->data); | 360 jcd->callback(js, packet, jcd->data); |
329 jabber_iq_remove_callback_by_id(js, id); | 361 jabber_iq_remove_callback_by_id(js, id); |
330 return; | 362 return; |
331 } | 363 } |
332 } | 364 } |
333 | 365 |
334 /* Apparently not, so lets see if we have a pre-defined handler */ | 366 /* Apparently not, so lets see if we have a pre-defined handler */ |
335 | 367 |
336 if(type && query && (xmlns = xmlnode_get_namespace(query))) { | 368 if(query && (xmlns = xmlnode_get_namespace(query))) { |
337 if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { | 369 if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { |
338 jih(js, packet); | 370 jih(js, packet); |
339 return; | 371 return; |
340 } | 372 } |
341 } | 373 } |
352 | 384 |
353 if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { | 385 if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { |
354 jabber_gmail_poke(js, packet); | 386 jabber_gmail_poke(js, packet); |
355 return; | 387 return; |
356 } | 388 } |
357 | 389 |
358 purple_debug_info("jabber", "jabber_iq_parse\n"); | 390 purple_debug_info("jabber", "jabber_iq_parse\n"); |
359 | 391 |
360 if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { | 392 if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { |
361 jabber_ping_parse(js, packet); | 393 jabber_ping_parse(js, packet); |
362 return; | 394 return; |
373 return; | 405 return; |
374 } | 406 } |
375 #endif | 407 #endif |
376 | 408 |
377 /* If we get here, send the default error reply mandated by XMPP-CORE */ | 409 /* If we get here, send the default error reply mandated by XMPP-CORE */ |
378 if(type && (!strcmp(type, "set") || !strcmp(type, "get"))) { | 410 if(!strcmp(type, "set") || !strcmp(type, "get")) { |
379 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); | 411 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
380 | 412 |
381 xmlnode_free(iq->node); | 413 xmlnode_free(iq->node); |
382 iq->node = xmlnode_copy(packet); | 414 iq->node = xmlnode_copy(packet); |
383 xmlnode_set_attrib(iq->node, "to", from); | 415 xmlnode_set_attrib(iq->node, "to", from); |