Mercurial > pidgin.yaz
diff libpurple/protocols/jabber/jabber.c @ 27755:9a60b9fab0ea
propagate from branch 'im.pidgin.pidgin' (head d50f362e369f486aaf9a95a0d79ec0632743f07d)
to branch 'im.pidgin.pidgin.yaz' (head 85b37cd20a00067af5a2da2760336b0c1016ef47)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 07 Jan 2008 03:40:27 +0000 |
parents | e13759a83714 af0426c34c27 |
children | 4426e530c156 |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Mon Dec 17 08:20:42 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.c Mon Jan 07 03:40:27 2008 +0000 @@ -389,9 +389,32 @@ g_free(txt); g_free(utf); } +static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) +{ + purple_timeout_remove(GPOINTER_TO_INT(timeout)); + js->keepalive_timeout = -1; +} + +static gboolean jabber_pong_timeout(PurpleConnection *gc) +{ + JabberStream *js = gc->proto_data; + purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, + _("Ping timeout")); + js->keepalive_timeout = -1; + return FALSE; +} + void jabber_keepalive(PurpleConnection *gc) { - jabber_send_raw(gc->proto_data, "\t", -1); + JabberStream *js = gc->proto_data; + 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(20, (GSourceFunc)(jabber_pong_timeout), gc); + jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(js->keepalive_timeout)); + jabber_iq_send(iq); } static void @@ -592,7 +615,8 @@ js->user = jabber_id_new(purple_account_get_username(account)); js->next_id = g_random_int(); js->write_buffer = purple_circ_buffer_new(512); - js->old_length = -1; + js->old_length = 0; + js->keepalive_timeout = -1; if(!js->user) { purple_connection_error_reason (gc, @@ -1077,7 +1101,7 @@ g_free, g_free); js->user = jabber_id_new(purple_account_get_username(account)); js->next_id = g_random_int(); - js->old_length = -1; + js->old_length = 0; if(!js->user) { purple_connection_error_reason (gc, @@ -1292,6 +1316,9 @@ g_free(js->old_uri); g_free(js->old_track); + if (js->keepalive_timeout != -1) + purple_timeout_remove(js->keepalive_timeout); + g_free(js); gc->proto_data = NULL; @@ -1497,10 +1524,16 @@ } else purple_notify_user_info_add_pair(user_info, _("Mood"), mood); } - if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { + if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { PurpleStatus *tune = purple_presence_get_status(presence, "tune"); const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE); - purple_notify_user_info_add_pair(user_info, _("Current media"), title); + const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST); + const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM); + char *playing = purple_util_format_song_info(title, artist, album, NULL); + if (playing) { + purple_notify_user_info_add_pair(user_info, _("Now Listening"), playing); + g_free(playing); + } } }