libpurple/protocols/jabber/ping.c

Wed, 13 May 2009 20:29:03 +0000

author
Marcus Lundblad <malu@pidgin.im>
date
Wed, 13 May 2009 20:29:03 +0000
changeset 27110
05ca719b901b
parent 26983
84be4c9b3ef9
child 27143
977add4a215e
permissions
-rw-r--r--

Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.

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 {
26983
84be4c9b3ef9 Don't breaking if the user runs `/ping <user's server>` a bunch.
Paul Aurich <darkrain42@pidgin.im>
parents: 26982
diff changeset
33 if (js->keepalive_timeout >= 0) {
84be4c9b3ef9 Don't breaking if the user runs `/ping <user's server>` a bunch.
Paul Aurich <darkrain42@pidgin.im>
parents: 26982
diff changeset
34 purple_timeout_remove(js->keepalive_timeout);
84be4c9b3ef9 Don't breaking if the user runs `/ping <user's server>` a bunch.
Paul Aurich <darkrain42@pidgin.im>
parents: 26982
diff changeset
35 js->keepalive_timeout = -1;
84be4c9b3ef9 Don't breaking if the user runs `/ping <user's server>` a bunch.
Paul Aurich <darkrain42@pidgin.im>
parents: 26982
diff changeset
36 }
25555
dd0cb987435f Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents: 25554
diff changeset
37 }
dd0cb987435f Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents: 25554
diff changeset
38
17769
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
39 void
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 25814
diff changeset
40 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
41 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
42 {
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 25814
diff changeset
43 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
44 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
45
25818
d087a2754595 Avoid assertion failures on NULL 'from' attributes
Paul Aurich <darkrain42@pidgin.im>
parents: 25817
diff changeset
46 if (from)
d087a2754595 Avoid assertion failures on NULL 'from' attributes
Paul Aurich <darkrain42@pidgin.im>
parents: 25817
diff changeset
47 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
48 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
49
25554
53e161fc0658 Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents: 18911
diff changeset
50 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
51 } 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
52 /* XXX: error */
53e161fc0658 Jabber IQ handlers should handle non-query child nodes
Paul Aurich <darkrain42@pidgin.im>
parents: 18911
diff changeset
53 }
17769
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
54 }
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
55
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 25824
diff changeset
56 static void jabber_ping_result_cb(JabberStream *js, const char *from,
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 25824
diff changeset
57 JabberIqType type, const char *id,
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 25824
diff changeset
58 xmlnode *packet, gpointer data)
17769
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
59 {
26798
0da78f253fd8 Send XMPP keepalive pings to our server, not our bare JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 26687
diff changeset
60 if (purple_strequal(from, js->user->domain))
0da78f253fd8 Send XMPP keepalive pings to our server, not our bare JID.
Paul Aurich <darkrain42@pidgin.im>
parents: 26687
diff changeset
61 /* If the pong is from the server, assume it's a result of 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
62 * 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
63 jabber_keepalive_pong_cb(js);
26982
78e4765d75d7 I gave this way too long to stop getting on my nerves.
Paul Aurich <darkrain42@pidgin.im>
parents: 26798
diff changeset
64 else {
78e4765d75d7 I gave this way too long to stop getting on my nerves.
Paul Aurich <darkrain42@pidgin.im>
parents: 26798
diff changeset
65 if (type == JABBER_IQ_RESULT)
78e4765d75d7 I gave this way too long to stop getting on my nerves.
Paul Aurich <darkrain42@pidgin.im>
parents: 26798
diff changeset
66 purple_debug_info("jabber", "PONG!\n");
78e4765d75d7 I gave this way too long to stop getting on my nerves.
Paul Aurich <darkrain42@pidgin.im>
parents: 26798
diff changeset
67 else
78e4765d75d7 I gave this way too long to stop getting on my nerves.
Paul Aurich <darkrain42@pidgin.im>
parents: 26798
diff changeset
68 purple_debug_info("jabber", "ping not supported\n");
17769
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
69 }
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
25555
dd0cb987435f Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents: 25554
diff changeset
72 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
73 {
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
74 JabberIq *iq;
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
75 xmlnode *ping;
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
76
25555
dd0cb987435f Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
Paul Aurich <darkrain42@pidgin.im>
parents: 25554
diff changeset
77 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
78 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
79 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
80
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
81 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
82 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
83
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
84 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
85 jabber_iq_send(iq);
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
86
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
87 return TRUE;
69d98a4da006 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
diff changeset
88 }

mercurial