Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 25645:ced3d4ab745a
propagate from branch 'im.pidgin.pidgin' (head 8d4081da0c186c04dc75d736d688bf4f20e52676)
to branch 'im.pidgin.cpw.darkrain42.xmpp.iq-handlers' (head 9a25f2e3149558150e52b40d5c119965ed617e37)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 08 Feb 2009 03:34:25 +0000 |
parents | 256fbe98f6be 42dd7e591031 |
children | 050052891c55 |
comparison
equal
deleted
inserted
replaced
25434:2035b8164aca | 25645:ced3d4ab745a |
---|---|
437 txt = xmlnode_to_str(packet, &len); | 437 txt = xmlnode_to_str(packet, &len); |
438 jabber_send_raw(js, txt, len); | 438 jabber_send_raw(js, txt, len); |
439 g_free(txt); | 439 g_free(txt); |
440 } | 440 } |
441 | 441 |
442 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused) | 442 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) |
443 { | |
444 purple_timeout_remove(js->keepalive_timeout); | |
445 js->keepalive_timeout = -1; | |
446 } | |
447 | |
448 static gboolean jabber_pong_timeout(PurpleConnection *gc) | |
449 { | 443 { |
450 JabberStream *js = gc->proto_data; | 444 JabberStream *js = gc->proto_data; |
451 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 445 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
452 _("Ping timeout")); | 446 _("Ping timeout")); |
453 js->keepalive_timeout = -1; | 447 js->keepalive_timeout = -1; |
454 return FALSE; | 448 return FALSE; |
455 } | 449 } |
456 | 450 |
457 void jabber_keepalive(PurpleConnection *gc) | 451 void jabber_keepalive(PurpleConnection *gc) |
458 { | 452 { |
459 JabberStream *js = gc->proto_data; | 453 JabberStream *js = gc->proto_data; |
460 | 454 |
461 if (js->keepalive_timeout == -1) { | 455 if (js->keepalive_timeout == -1) { |
462 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); | 456 jabber_ping_jid(js, NULL); |
463 | 457 js->keepalive_timeout = purple_timeout_add_seconds(120, |
464 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); | 458 (GSourceFunc)(jabber_keepalive_timeout), gc); |
465 xmlnode_set_namespace(ping, "urn:xmpp:ping"); | |
466 | |
467 js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); | |
468 jabber_iq_set_callback(iq, jabber_pong_cb, NULL); | |
469 jabber_iq_send(iq); | |
470 } | 459 } |
471 } | 460 } |
472 | 461 |
473 static void | 462 static void |
474 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, | 463 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
2419 } | 2408 } |
2420 | 2409 |
2421 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, | 2410 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, |
2422 const char *cmd, char **args, char **error, void *data) | 2411 const char *cmd, char **args, char **error, void *data) |
2423 { | 2412 { |
2413 PurpleAccount *account; | |
2414 PurpleConnection *pc; | |
2415 | |
2424 if(!args || !args[0]) | 2416 if(!args || !args[0]) |
2425 return PURPLE_CMD_RET_FAILED; | 2417 return PURPLE_CMD_RET_FAILED; |
2426 | 2418 |
2427 if(!jabber_ping_jid(conv, args[0])) { | 2419 account = purple_conversation_get_account(conv); |
2420 pc = purple_account_get_connection(account); | |
2421 | |
2422 if(!jabber_ping_jid(pc->proto_data, args[0])) { | |
2428 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); | 2423 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); |
2429 return PURPLE_CMD_RET_FAILED; | 2424 return PURPLE_CMD_RET_FAILED; |
2430 } | 2425 } |
2431 | 2426 |
2432 return PURPLE_CMD_RET_OK; | 2427 return PURPLE_CMD_RET_OK; |