pidgin: 092bbcea: Only send a yahoo ping once an hour. Th...

datallah at pidgin.im datallah at pidgin.im
Mon Sep 22 22:55:25 EDT 2008


-----------------------------------------------------------------
Revision: 092bbcea7b768d21baff3362314e784b26b1ced7
Ancestor: 6597ee41c4b15c89f49616d51fd455267fad4e73
Author: datallah at pidgin.im
Date: 2008-09-23T02:50:36
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/092bbcea7b768d21baff3362314e784b26b1ced7

Modified files:
        libpurple/protocols/yahoo/yahoo.c
        libpurple/protocols/yahoo/yahoo.h
        libpurple/protocols/yahoo/yahoo_packet.h
        libpurple/protocols/yahoo/yahoochat.c

ChangeLog: 

Only send a yahoo ping once an hour.  The server doesn't like it when send it
every 30 seconds.
We also send a keepalive every 60 seconds or so like the native client does.
I think this fixes #7161

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo.c	c1b70c8ae49b010d0527cacccf74838fb9c7dfde
+++ libpurple/protocols/yahoo/yahoo.c	7e5229419ad9251d0903c281223a7b90d319ec21
@@ -55,6 +55,12 @@
 
 /* #define TRY_WEBMESSENGER_LOGIN 0 */
 
+/* One hour */
+#define PING_TIMEOUT 3600
+
+/* One minute */
+#define KEEPALIVE_TIMEOUT 60
+
 static void yahoo_add_buddy(PurpleConnection *gc, PurpleBuddy *, PurpleGroup *);
 #ifdef TRY_WEBMESSENGER_LOGIN
 static void yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
@@ -3001,6 +3007,7 @@ static void yahoo_login(PurpleAccount *a
 	yd->xfer_peer_idstring_map = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
 	yd->confs = NULL;
 	yd->conf_id = 2;
+	yd->last_keepalive = yd->last_ping = time(NULL);
 
 	yd->current_status = get_yahoo_status_from_purple_status(status);
 
@@ -3059,7 +3066,7 @@ static void yahoo_close(PurpleConnection
 	}
 	g_slist_free(yd->cookies);
 
-	yd->chat_online = 0;
+	yd->chat_online = FALSE;
 	if (yd->in_chat)
 		yahoo_c_leave(gc, 1); /* 1 = YAHOO_CHAT_ID */
 
@@ -3871,21 +3878,36 @@ static void yahoo_keepalive(PurpleConnec
 
 static void yahoo_keepalive(PurpleConnection *gc)
 {
+	struct yahoo_packet *pkt;
 	struct yahoo_data *yd = gc->proto_data;
-	struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0);
-	yahoo_packet_send_and_free(pkt, yd);
+	time_t now = time(NULL);
 
-	if (!yd->chat_online)
-		return;
+	/* We're only allowed to send a ping once an hour or the servers will boot us */
+	if ((now - yd->last_ping) >= PING_TIMEOUT) {
+		yd->last_ping = now;
 
-	if (yd->wm) {
-		ycht_chat_send_keepalive(yd->ycht);
-		return;
+		/* The native client will only send PING or CHATPING */
+		if (yd->chat_online) {
+			if (yd->wm) {
+				ycht_chat_send_keepalive(yd->ycht);
+			} else {
+				pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0);
+				yahoo_packet_hash_str(pkt, 109, purple_connection_get_display_name(gc));
+				yahoo_packet_send_and_free(pkt, yd);
+			}
+		} else {
+			pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0);
+			yahoo_packet_send_and_free(pkt, yd);
+		}
 	}
 
-	pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0);
-	yahoo_packet_hash_str(pkt, 109, purple_connection_get_display_name(gc));
-	yahoo_packet_send_and_free(pkt, yd);
+	if ((now - yd->last_keepalive) >= KEEPALIVE_TIMEOUT) {
+		yd->last_keepalive = now;
+		pkt = yahoo_packet_new(YAHOO_SERVICE_KEEPALIVE, YAHOO_STATUS_AVAILABLE, 0);
+		yahoo_packet_hash_str(pkt, 0, purple_connection_get_display_name(gc));
+		yahoo_packet_send_and_free(pkt, yd);
+	}
+
 }
 
 static void yahoo_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *g)
============================================================
--- libpurple/protocols/yahoo/yahoo.h	e0daa1b8ad392fb22b487a60b766f83c777e3783
+++ libpurple/protocols/yahoo/yahoo.h	50bc84d9e9f5c3f1da265c8ef93ed880a403a218
@@ -176,6 +176,8 @@ struct yahoo_data {
 	 * the server expects us to keep track of the group for which it is sending us contact names.
 	 */
 	char *current_list15_grp;
+	time_t last_ping;
+	time_t last_keepalive;
 };
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)
============================================================
--- libpurple/protocols/yahoo/yahoo_packet.h	16e39edd7381ec46fdf4df3c5cb222835968314c
+++ libpurple/protocols/yahoo/yahoo_packet.h	73ca2470ec14b98bfa34d11bb2634e83039c3b30
@@ -76,7 +76,7 @@ enum yahoo_service { /* these are easier
 	YAHOO_SERVICE_IGNORECONTACT,    /* > 1, 7, 13 < 1, 66, 13, 0*/
 	YAHOO_SERVICE_REJECTCONTACT,
 	YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */
-	/* YAHOO_SERVICE_??? = 0x8A, */
+	YAHOO_SERVICE_KEEPALIVE = 0x8A,
 	YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1*/
 	YAHOO_SERVICE_CHATGOTO,
 	YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */
============================================================
--- libpurple/protocols/yahoo/yahoochat.c	95a42a96af02fb94b109a493602c8be7ed44a919
+++ libpurple/protocols/yahoo/yahoochat.c	4196414d981c3f3ae81170143fb1a099a76c84f1
@@ -369,7 +369,7 @@ void yahoo_process_chat_online(PurpleCon
 	struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data;
 
 	if (pkt->status == 1) {
-		yd->chat_online = 1;
+		yd->chat_online = TRUE;
 
 		/* We need to goto a user in chat */
 		if (yd->pending_chat_goto) {
@@ -411,7 +411,7 @@ void yahoo_process_chat_logout(PurpleCon
 	}
 
 	if (pkt->status == 1) {
-		yd->chat_online = 0;
+		yd->chat_online = FALSE;
 		g_free(yd->pending_chat_room);
 		yd->pending_chat_room = NULL;
 		g_free(yd->pending_chat_id);
@@ -881,7 +881,7 @@ static void yahoo_chat_leave(PurpleConne
 	yahoo_packet_hash_str(pkt, 1, dn);
 	yahoo_packet_send_and_free(pkt, yd);
 
-	yd->chat_online = 0;
+	yd->chat_online = FALSE;
 	g_free(yd->pending_chat_room);
 	yd->pending_chat_room = NULL;
 	g_free(yd->pending_chat_id);


More information about the Commits mailing list