Tue, 10 Feb 2009 06:15:27 +0000
These checks are redundant; id is guaranteed to be something above
|
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 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
27 | #include "jabber.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
28 | #include "ping.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
29 | #include "iq.h" |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
30 | |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
31 | static void jabber_keepalive_pong_cb(JabberStream *js) |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
32 | { |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
33 | purple_timeout_remove(js->keepalive_timeout); |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
34 | js->keepalive_timeout = -1; |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
35 | } |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
36 | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
37 | void |
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
25814
diff
changeset
|
38 | jabber_ping_parse(JabberStream *js, const char *from, |
|
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
25814
diff
changeset
|
39 | JabberIqType type, const char *id, xmlnode *ping) |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
40 | { |
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
25814
diff
changeset
|
41 | if (type == JABBER_IQ_GET) { |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
42 | 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
|
43 | |
|
25818
d087a2754595
Avoid assertion failures on NULL 'from' attributes
Paul Aurich <darkrain42@pidgin.im>
parents:
25817
diff
changeset
|
44 | if (from) |
|
d087a2754595
Avoid assertion failures on NULL 'from' attributes
Paul Aurich <darkrain42@pidgin.im>
parents:
25817
diff
changeset
|
45 | xmlnode_set_attrib(iq->node, "to", from); |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
46 | 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
|
47 | |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
48 | jabber_iq_send(iq); |
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
25814
diff
changeset
|
49 | } else if (type == JABBER_IQ_SET) { |
|
25554
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
50 | /* XXX: error */ |
|
53e161fc0658
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents:
18911
diff
changeset
|
51 | } |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
52 | } |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
53 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
54 | static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet, |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
55 | gpointer data) |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
56 | { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
57 | const char *type = xmlnode_get_attrib(packet, "type"); |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
58 | const char *from = xmlnode_get_attrib(packet, "from"); |
|
25824
db718e690f5f
Reduce the debug log spam from the ping code and fix a logic error.
Paul Aurich <darkrain42@pidgin.im>
parents:
25818
diff
changeset
|
59 | char *own_bare_jid = g_strdup_printf("%s@%s", js->user->node, |
|
db718e690f5f
Reduce the debug log spam from the ping code and fix a logic error.
Paul Aurich <darkrain42@pidgin.im>
parents:
25818
diff
changeset
|
60 | js->user->domain); |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
61 | |
|
25824
db718e690f5f
Reduce the debug log spam from the ping code and fix a logic error.
Paul Aurich <darkrain42@pidgin.im>
parents:
25818
diff
changeset
|
62 | if (!from || !strcmp(from, own_bare_jid)) { |
|
db718e690f5f
Reduce the debug log spam from the ping code and fix a logic error.
Paul Aurich <darkrain42@pidgin.im>
parents:
25818
diff
changeset
|
63 | /* If the pong is from our bare JID, treat it as a return from the |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
64 | * keepalive functions */ |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
65 | jabber_keepalive_pong_cb(js); |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
66 | } |
|
25824
db718e690f5f
Reduce the debug log spam from the ping code and fix a logic error.
Paul Aurich <darkrain42@pidgin.im>
parents:
25818
diff
changeset
|
67 | g_free(own_bare_jid); |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
68 | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
69 | if(type && !strcmp(type, "result")) { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
70 | purple_debug_info("jabber", "PONG!\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
71 | } else { |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
72 | purple_debug_info("jabber", "(not supported)\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
73 | } |
|
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 | |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
76 | gboolean jabber_ping_jid(JabberStream *js, const char *jid) |
|
17769
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 | JabberIq *iq; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
79 | xmlnode *ping; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
80 | |
|
25555
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
81 | iq = jabber_iq_new(js, JABBER_IQ_GET); |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
82 | if (jid) |
|
dd0cb987435f
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents:
25554
diff
changeset
|
83 | xmlnode_set_attrib(iq->node, "to", jid); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
84 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
85 | 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
|
86 | 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
|
87 | |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff
changeset
|
88 | 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
|
89 | jabber_iq_send(iq); |
|
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 | } |