Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / protocols / jabber / ping.c
blob7cb2b9702428c28807b6a02a8ca006cd6ea29e10
1 /*
2 * purple - Jabber Protocol Plugin
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 #include "internal.h"
27 #include "debug.h"
29 #include "jabber.h"
30 #include "ping.h"
31 #include "iq.h"
33 static void jabber_keepalive_pong_cb(JabberStream *js, const char *from,
34 JabberIqType type, const char *id,
35 PurpleXmlNode *packet, gpointer data)
37 if (js->keepalive_timeout != 0) {
38 g_source_remove(js->keepalive_timeout);
39 js->keepalive_timeout = 0;
43 void
44 jabber_ping_parse(JabberStream *js, const char *from,
45 JabberIqType type, const char *id, PurpleXmlNode *ping)
47 if (type == JABBER_IQ_GET) {
48 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT);
50 if (from)
51 purple_xmlnode_set_attrib(iq->node, "to", from);
52 purple_xmlnode_set_attrib(iq->node, "id", id);
54 jabber_iq_send(iq);
55 } else if (type == JABBER_IQ_SET) {
56 /* XXX: error */
60 static void jabber_ping_result_cb(JabberStream *js, const char *from,
61 JabberIqType type, const char *id,
62 PurpleXmlNode *packet, gpointer data)
64 if (type == JABBER_IQ_RESULT)
65 purple_debug_info("jabber", "PONG!\n");
66 else
67 purple_debug_info("jabber", "ping not supported\n");
70 void jabber_keepalive_ping(JabberStream *js)
72 JabberIq *iq;
73 PurpleXmlNode *ping;
75 iq = jabber_iq_new(js, JABBER_IQ_GET);
76 ping = purple_xmlnode_new_child(iq->node, "ping");
77 purple_xmlnode_set_namespace(ping, NS_PING);
79 jabber_iq_set_callback(iq, jabber_keepalive_pong_cb, NULL);
80 jabber_iq_send(iq);
83 gboolean jabber_ping_jid(JabberStream *js, const char *jid)
85 JabberIq *iq;
86 PurpleXmlNode *ping;
88 iq = jabber_iq_new(js, JABBER_IQ_GET);
89 if (jid)
90 purple_xmlnode_set_attrib(iq->node, "to", jid);
92 ping = purple_xmlnode_new_child(iq->node, "ping");
93 purple_xmlnode_set_namespace(ping, NS_PING);
95 jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL);
96 jabber_iq_send(iq);
98 return TRUE;