annotate libpurple/protocols/jabber/ping.c @ 25428:e30e9779e7bf

In jabber_iq_parse, xmlnode_get_child is called for a few special cases, and then the original xmlnode is passed to the handler. That seems kind of pointless, since jabber_iq_parse has all the data. So I just passed the data necessary for each handler instead. I didn't change the query handlers since they seem to require the parent. I assume the point was to go for a unified prototype, but since these handlers are all special cases, I think it's okay to give them a special signature as well.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Thu, 05 Feb 2009 05:42:58 +0000
parents 413103ddeaac
children 36c73d036026
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "xmlnode.h"
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
27
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
28 #include "jabber.h"
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
29 #include "ping.h"
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
30 #include "iq.h"
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
31
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
32 void
25428
e30e9779e7bf In jabber_iq_parse, xmlnode_get_child is called for a few special cases,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 18702
diff changeset
33 jabber_ping_parse(JabberStream *js, const char *from, const char *id)
17835
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
34 {
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
35 JabberIq *iq;
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
36
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
37 purple_debug_info("jabber", "jabber_ping_parse\n");
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
38
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
39 iq = jabber_iq_new(js, JABBER_IQ_RESULT);
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
40
25428
e30e9779e7bf In jabber_iq_parse, xmlnode_get_child is called for a few special cases,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 18702
diff changeset
41 xmlnode_set_attrib(iq->node, "to", from);
17835
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
42
25428
e30e9779e7bf In jabber_iq_parse, xmlnode_get_child is called for a few special cases,
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 18702
diff changeset
43 jabber_iq_set_id(iq, id);
17835
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
44
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
45 jabber_iq_send(iq);
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
46 }
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
47
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
48 static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet,
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
49 gpointer data)
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
50 {
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
51 const char *type = xmlnode_get_attrib(packet, "type");
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
52
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
53 purple_debug_info("jabber", "jabber_ping_result_cb\n");
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
54 if(type && !strcmp(type, "result")) {
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
55 purple_debug_info("jabber", "PONG!\n");
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
56 } else {
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
57 purple_debug_info("jabber", "(not supported)\n");
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 }
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
60
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
61 gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid)
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
62 {
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
63 JabberIq *iq;
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
64 xmlnode *ping;
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
65
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
66 purple_debug_info("jabber", "jabber_ping_jid\n");
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
67
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
68 iq = jabber_iq_new(conv->account->gc->proto_data, JABBER_IQ_GET);
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
69 xmlnode_set_attrib(iq->node, "to", jid);
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
70
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
71 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
72 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
73
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
74 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
75 jabber_iq_send(iq);
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
76
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
77
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
78
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
79 return TRUE;
6ab1089e2101 applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
80 }