Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/ping.c @ 26569:bc7fac8e2f79
propagate from branch 'im.pidgin.pidgin' (head f144c6bda9daf701aa891c875fce7a4dedd611ae)
to branch 'im.pidgin.cpw.darkrain42.xmpp.bosh' (head 8b60514f2b44295e87ee3587669aec5059556149)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 05 Apr 2009 21:13:10 +0000 |
parents | ae41d8e827e3 |
children | d00a8111e479 |
comparison
equal
deleted
inserted
replaced
26545:b01e8e76c59d | 26569:bc7fac8e2f79 |
---|---|
21 */ | 21 */ |
22 | 22 |
23 #include "internal.h" | 23 #include "internal.h" |
24 | 24 |
25 #include "debug.h" | 25 #include "debug.h" |
26 #include "xmlnode.h" | |
27 | 26 |
28 #include "jabber.h" | 27 #include "jabber.h" |
29 #include "ping.h" | 28 #include "ping.h" |
30 #include "iq.h" | 29 #include "iq.h" |
31 | 30 |
32 void | 31 static void jabber_keepalive_pong_cb(JabberStream *js) |
33 jabber_ping_parse(JabberStream *js, xmlnode *packet) | |
34 { | 32 { |
35 JabberIq *iq; | 33 purple_timeout_remove(js->keepalive_timeout); |
36 | 34 js->keepalive_timeout = -1; |
37 purple_debug_info("jabber", "jabber_ping_parse\n"); | |
38 | |
39 iq = jabber_iq_new(js, JABBER_IQ_RESULT); | |
40 | |
41 xmlnode_set_attrib(iq->node, "to", xmlnode_get_attrib(packet, "from") ); | |
42 | |
43 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
44 | |
45 jabber_iq_send(iq); | |
46 } | 35 } |
47 | 36 |
48 static void jabber_ping_result_cb(JabberStream *js, xmlnode *packet, | 37 void |
49 gpointer data) | 38 jabber_ping_parse(JabberStream *js, const char *from, |
39 JabberIqType type, const char *id, xmlnode *ping) | |
50 { | 40 { |
51 const char *type = xmlnode_get_attrib(packet, "type"); | 41 if (type == JABBER_IQ_GET) { |
42 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT); | |
52 | 43 |
53 purple_debug_info("jabber", "jabber_ping_result_cb\n"); | 44 if (from) |
54 if(type && !strcmp(type, "result")) { | 45 xmlnode_set_attrib(iq->node, "to", from); |
46 xmlnode_set_attrib(iq->node, "id", id); | |
47 | |
48 jabber_iq_send(iq); | |
49 } else if (type == JABBER_IQ_SET) { | |
50 /* XXX: error */ | |
51 } | |
52 } | |
53 | |
54 static void jabber_ping_result_cb(JabberStream *js, const char *from, | |
55 JabberIqType type, const char *id, | |
56 xmlnode *packet, gpointer data) | |
57 { | |
58 char *own_bare_jid = g_strdup_printf("%s@%s", js->user->node, | |
59 js->user->domain); | |
60 | |
61 if (!from || !strcmp(from, own_bare_jid)) { | |
62 /* If the pong is from our bare JID, treat it as a return from the | |
63 * keepalive functions */ | |
64 jabber_keepalive_pong_cb(js); | |
65 } | |
66 g_free(own_bare_jid); | |
67 | |
68 if (type == JABBER_IQ_RESULT) { | |
55 purple_debug_info("jabber", "PONG!\n"); | 69 purple_debug_info("jabber", "PONG!\n"); |
56 } else { | 70 } else { |
57 purple_debug_info("jabber", "(not supported)\n"); | 71 purple_debug_info("jabber", "(not supported)\n"); |
58 } | 72 } |
59 } | 73 } |
60 | 74 |
61 gboolean jabber_ping_jid(PurpleConversation *conv, const char *jid) | 75 gboolean jabber_ping_jid(JabberStream *js, const char *jid) |
62 { | 76 { |
63 JabberIq *iq; | 77 JabberIq *iq; |
64 xmlnode *ping; | 78 xmlnode *ping; |
65 | 79 |
66 purple_debug_info("jabber", "jabber_ping_jid\n"); | 80 iq = jabber_iq_new(js, JABBER_IQ_GET); |
67 | 81 if (jid) |
68 iq = jabber_iq_new(conv->account->gc->proto_data, JABBER_IQ_GET); | 82 xmlnode_set_attrib(iq->node, "to", jid); |
69 xmlnode_set_attrib(iq->node, "to", jid); | |
70 | 83 |
71 ping = xmlnode_new_child(iq->node, "ping"); | 84 ping = xmlnode_new_child(iq->node, "ping"); |
72 xmlnode_set_namespace(ping, "urn:xmpp:ping"); | 85 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
73 | 86 |
74 jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL); | 87 jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL); |
75 jabber_iq_send(iq); | 88 jabber_iq_send(iq); |
76 | 89 |
77 | |
78 | |
79 return TRUE; | 90 return TRUE; |
80 } | 91 } |