Mercurial > pidgin
annotate libpurple/protocols/jabber/ping.c @ 27101:ad04d94e6ddf
Remove code for obsoleted XEP-0022 (Message Events)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Thu, 11 Jun 2009 22:25:25 +0000 |
parents | 5bbdb0a93c52 |
children | cb3e89f5a2d5 |
rev | line source |
---|---|
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
1 /* |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
2 * purple - Jabber Protocol Plugin |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
3 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
5 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
9 * (at your option) any later version. |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
10 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
14 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
15 * GNU General Public License for more details. |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
16 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
18 * along with this program; if not, write to the Free Software |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
20 * |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
21 */ |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
22 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
23 #include "internal.h" |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
24 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
25 #include "debug.h" |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
26 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
27 #include "jabber.h" |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
28 #include "ping.h" |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
29 #include "iq.h" |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
30 |
26917
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
31 static void jabber_keepalive_pong_cb(JabberStream *js, const char *from, |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
32 JabberIqType type, const char *id, |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
33 xmlnode *packet, gpointer data) |
25640
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
34 { |
27069
08f5c5b12e7c
The XMPP keepalive timeout handle needs to be a guint.
Paul Aurich <paul@darkrain42.org>
parents:
26917
diff
changeset
|
35 if (js->keepalive_timeout != 0) { |
27071
5bbdb0a93c52
Re-add annoying debug output for Adium#12351 (I must be missing something, because I don't see why it's occurring)
Paul Aurich <paul@darkrain42.org>
parents:
27069
diff
changeset
|
36 purple_debug_misc("jabber", "Keepalive PONG\n"); |
26759
6faa5d5b4f44
Don't breaking if the user runs `/ping <user's server>` a bunch.
Paul Aurich <paul@darkrain42.org>
parents:
26758
diff
changeset
|
37 purple_timeout_remove(js->keepalive_timeout); |
27069
08f5c5b12e7c
The XMPP keepalive timeout handle needs to be a guint.
Paul Aurich <paul@darkrain42.org>
parents:
26917
diff
changeset
|
38 js->keepalive_timeout = 0; |
27071
5bbdb0a93c52
Re-add annoying debug output for Adium#12351 (I must be missing something, because I don't see why it's occurring)
Paul Aurich <paul@darkrain42.org>
parents:
27069
diff
changeset
|
39 } else |
5bbdb0a93c52
Re-add annoying debug output for Adium#12351 (I must be missing something, because I don't see why it's occurring)
Paul Aurich <paul@darkrain42.org>
parents:
27069
diff
changeset
|
40 purple_debug_warning("jabber", "Keepalive PONG with no outstanding timeout!\n"); |
25640
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
41 } |
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
42 |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
43 void |
25648
050052891c55
Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents:
25645
diff
changeset
|
44 jabber_ping_parse(JabberStream *js, const char *from, |
050052891c55
Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents:
25645
diff
changeset
|
45 JabberIqType type, const char *id, xmlnode *ping) |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
46 { |
25648
050052891c55
Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents:
25645
diff
changeset
|
47 if (type == JABBER_IQ_GET) { |
25639
b5052c66701c
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <paul@darkrain42.org>
parents:
18702
diff
changeset
|
48 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT); |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
49 |
25649
c8606917787a
Avoid assertion failures on NULL 'from' attributes
Paul Aurich <paul@darkrain42.org>
parents:
25648
diff
changeset
|
50 if (from) |
c8606917787a
Avoid assertion failures on NULL 'from' attributes
Paul Aurich <paul@darkrain42.org>
parents:
25648
diff
changeset
|
51 xmlnode_set_attrib(iq->node, "to", from); |
25639
b5052c66701c
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <paul@darkrain42.org>
parents:
18702
diff
changeset
|
52 xmlnode_set_attrib(iq->node, "id", id); |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
53 |
25639
b5052c66701c
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <paul@darkrain42.org>
parents:
18702
diff
changeset
|
54 jabber_iq_send(iq); |
25648
050052891c55
Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents:
25645
diff
changeset
|
55 } else if (type == JABBER_IQ_SET) { |
25639
b5052c66701c
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <paul@darkrain42.org>
parents:
18702
diff
changeset
|
56 /* XXX: error */ |
b5052c66701c
Jabber IQ handlers should handle non-query child nodes
Paul Aurich <paul@darkrain42.org>
parents:
18702
diff
changeset
|
57 } |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
58 } |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
59 |
26465
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25655
diff
changeset
|
60 static void jabber_ping_result_cb(JabberStream *js, const char *from, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25655
diff
changeset
|
61 JabberIqType type, const char *id, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25655
diff
changeset
|
62 xmlnode *packet, gpointer data) |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
63 { |
26917
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
64 if (type == JABBER_IQ_RESULT) |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
65 purple_debug_info("jabber", "PONG!\n"); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
66 else |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
67 purple_debug_info("jabber", "ping not supported\n"); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
68 } |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
69 |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
70 void jabber_keepalive_ping(JabberStream *js) |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
71 { |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
72 JabberIq *iq; |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
73 xmlnode *ping; |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
74 |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
75 iq = jabber_iq_new(js, JABBER_IQ_GET); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
76 ping = xmlnode_new_child(iq->node, "ping"); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
77 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
78 |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
79 jabber_iq_set_callback(iq, jabber_keepalive_pong_cb, NULL); |
6b0e150f2276
Stop trying to be clever with XMPP keepalive pings.
Paul Aurich <paul@darkrain42.org>
parents:
26759
diff
changeset
|
80 jabber_iq_send(iq); |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
81 } |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
82 |
25640
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
83 gboolean jabber_ping_jid(JabberStream *js, const char *jid) |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
84 { |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
85 JabberIq *iq; |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
86 xmlnode *ping; |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
87 |
25640
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
88 iq = jabber_iq_new(js, JABBER_IQ_GET); |
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
89 if (jid) |
42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <paul@darkrain42.org>
parents:
25639
diff
changeset
|
90 xmlnode_set_attrib(iq->node, "to", jid); |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
91 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
92 ping = xmlnode_new_child(iq->node, "ping"); |
18702
413103ddeaac
Updated the XEP-0199 namespace according to the XEP.
Andreas Monitzer <pidgin@monitzer.com>
parents:
17835
diff
changeset
|
93 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
17835
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
94 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
95 jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL); |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
96 jabber_iq_send(iq); |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
97 |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
98 return TRUE; |
6ab1089e2101
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff
changeset
|
99 } |