Mercurial > pidgin.yaz
changeset 25925:42dd7e591031
Make the XMPP keepalive use jabber_ping_jid instead of building it itself.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 03 Feb 2009 17:39:14 +0000 |
parents | b5052c66701c |
children | 865123f21a72 |
files | libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/ping.c libpurple/protocols/jabber/ping.h |
diffstat | 3 files changed, 34 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Tue Feb 03 17:10:05 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Tue Feb 03 17:39:14 2009 +0000 @@ -439,17 +439,11 @@ g_free(txt); } -static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused) -{ - purple_timeout_remove(js->keepalive_timeout); - js->keepalive_timeout = -1; -} - -static gboolean jabber_pong_timeout(PurpleConnection *gc) +static gboolean jabber_keepalive_timeout(PurpleConnection *gc) { JabberStream *js = gc->proto_data; purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - _("Ping timeout")); + _("Ping timeout")); js->keepalive_timeout = -1; return FALSE; } @@ -459,14 +453,9 @@ JabberStream *js = gc->proto_data; if (js->keepalive_timeout == -1) { - JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); - - xmlnode *ping = xmlnode_new_child(iq->node, "ping"); - xmlnode_set_namespace(ping, "urn:xmpp:ping"); - - js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); - jabber_iq_set_callback(iq, jabber_pong_cb, NULL); - jabber_iq_send(iq); + jabber_ping_jid(js, NULL); + js->keepalive_timeout = purple_timeout_add_seconds(120, + (GSourceFunc)(jabber_keepalive_timeout), gc); } } @@ -2421,10 +2410,16 @@ static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, const char *cmd, char **args, char **error, void *data) { + PurpleAccount *account; + PurpleConnection *pc; + if(!args || !args[0]) return PURPLE_CMD_RET_FAILED; - if(!jabber_ping_jid(conv, args[0])) { + account = purple_conversation_get_account(conv); + pc = purple_account_get_connection(account); + + if(!jabber_ping_jid(pc->proto_data, args[0])) { *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); return PURPLE_CMD_RET_FAILED; }
--- a/libpurple/protocols/jabber/ping.c Tue Feb 03 17:10:05 2009 +0000 +++ b/libpurple/protocols/jabber/ping.c Tue Feb 03 17:39:14 2009 +0000 @@ -23,12 +23,17 @@ #include "internal.h" #include "debug.h" -#include "xmlnode.h" #include "jabber.h" #include "ping.h" #include "iq.h" +static void jabber_keepalive_pong_cb(JabberStream *js) +{ + purple_timeout_remove(js->keepalive_timeout); + js->keepalive_timeout = -1; +} + void jabber_ping_parse(JabberStream *js, xmlnode *packet) { @@ -58,11 +63,19 @@ } static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet, - gpointer data) + gpointer data) { const char *type = xmlnode_get_attrib(packet, "type"); + const char *from = xmlnode_get_attrib(packet, "from"); purple_debug_info("jabber", "jabber_ping_result_cb\n"); + + if (!from || !strcmp(from, js->user->domain)) { + /* If the pong is from our server, treat it as a return from the + * keepalive functions */ + jabber_keepalive_pong_cb(js); + } + if(type && !strcmp(type, "result")) { purple_debug_info("jabber", "PONG!\n"); } else { @@ -70,15 +83,16 @@ } } -gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid) +gboolean jabber_ping_jid(JabberStream *js, const char *jid) { JabberIq *iq; xmlnode *ping; purple_debug_info("jabber", "jabber_ping_jid\n"); - iq = jabber_iq_new(conv->account->gc->proto_data, JABBER_IQ_GET); - xmlnode_set_attrib(iq->node, "to", jid); + iq = jabber_iq_new(js, JABBER_IQ_GET); + if (jid) + xmlnode_set_attrib(iq->node, "to", jid); ping = xmlnode_new_child(iq->node, "ping"); xmlnode_set_namespace(ping, "urn:xmpp:ping"); @@ -86,7 +100,5 @@ jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL); jabber_iq_send(iq); - - return TRUE; }
--- a/libpurple/protocols/jabber/ping.h Tue Feb 03 17:10:05 2009 +0000 +++ b/libpurple/protocols/jabber/ping.h Tue Feb 03 17:39:14 2009 +0000 @@ -23,13 +23,9 @@ #define _PURPLE_JABBER_PING_H_ #include "jabber.h" -#include "conversation.h" +#include "xmlnode.h" -void jabber_ping_parse(JabberStream *js, - xmlnode *packet); - - -gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid); - +void jabber_ping_parse(JabberStream *js, xmlnode *packet); +gboolean jabber_ping_jid(JabberStream *js, const char *jid); #endif /* _PURPLE_JABBER_PING_H_ */