Tue, 03 Feb 2009 17:10:05 +0000
Jabber IQ handlers should handle non-query child nodes
Historically, all IQ stanzas had a query child; this is no longer the case
(XMPP Ping, Entity Time, etc). Instead, have the handlers use the first
child of the IQ stanza.
Also reduce some of the duplication in XMPP ping code (just use the one in
ping.c)
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
1 | /* |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
2 | * purple - Jabber Protocol Plugin |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
3 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
5 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
6 | * This program is free software; you can redistribute it and/or modify |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
7 | * it under the terms of the GNU General Public License as published by |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
8 | * the Free Software Foundation; either version 2 of the License, or |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
9 | * (at your option) any later version. |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
10 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
11 | * This program is distributed in the hope that it will be useful, |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
14 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
15 | * GNU General Public License for more details. |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
16 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
17 | * You should have received a copy of the GNU General Public License |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
18 | * along with this program; if not, write to the Free Software |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
20 | * |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
21 | */ |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
22 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
23 | #include "internal.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
24 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
25 | #include "debug.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
26 | #include "xmlnode.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
27 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
28 | #include "jabber.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
29 | #include "ping.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
30 | #include "iq.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
31 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
32 | void |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
33 | jabber_ping_parse(JabberStream *js, xmlnode *packet) |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
34 | { |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
35 | const char *type, *id, *from; |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
36 | |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
37 | type = xmlnode_get_attrib(packet, "type"); |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
38 | from = xmlnode_get_attrib(packet, "from"); |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
39 | id = xmlnode_get_attrib(packet, "id"); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
40 | |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
41 | if (!type) { |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
42 | purple_debug_warning("jabber", "jabber_ping with no type\n"); |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
43 | return; |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
44 | } |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
45 | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
46 | purple_debug_info("jabber", "jabber_ping_parse\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
47 | |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
48 | if (!strcmp(type, "get")) { |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
49 | JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
50 | |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
51 | xmlnode_set_attrib(iq->node, "to", from); |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
52 | xmlnode_set_attrib(iq->node, "id", id); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
53 | |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
54 | jabber_iq_send(iq); |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
55 | } else if (!strcmp(type, "set")) { |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
56 | /* XXX: error */ |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
57 | } |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
58 | } |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
59 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
60 | static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet, |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
61 | gpointer data) |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
62 | { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
63 | const char *type = xmlnode_get_attrib(packet, "type"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
64 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
65 | purple_debug_info("jabber", "jabber_ping_result_cb\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
66 | if(type && !strcmp(type, "result")) { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
67 | purple_debug_info("jabber", "PONG!\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
68 | } else { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
69 | purple_debug_info("jabber", "(not supported)\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
70 | } |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
71 | } |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
72 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
73 | gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid) |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
74 | { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
75 | JabberIq *iq; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
76 | xmlnode *ping; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
77 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
78 | purple_debug_info("jabber", "jabber_ping_jid\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
79 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
80 | iq = jabber_iq_new(conv->account->gc->proto_data, JABBER_IQ_GET); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
81 | xmlnode_set_attrib(iq->node, "to", jid); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
82 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
83 | ping = xmlnode_new_child(iq->node, "ping"); |
|
18911
34ae89bfee24
Updated the XEP-0199 namespace according to the XEP.
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
84 | xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
85 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
86 | jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
87 | jabber_iq_send(iq); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
88 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
89 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
90 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
91 | return TRUE; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
92 | } |