pidgin: 70890f22: Save and cancel-on-exit any URL requests...

qulogic at pidgin.im qulogic at pidgin.im
Sat Jul 31 19:50:50 EDT 2010


----------------------------------------------------------------------
Revision: 70890f22a16b47ce488e92c42368250c57bf0518
Parent:   870254bc565eb9ffa4f78dce9b5f8e9bd1ebb78f
Author:   qulogic at pidgin.im
Date:     07/31/10 16:47:31
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/70890f22a16b47ce488e92c42368250c57bf0518

Changelog: 

Save and cancel-on-exit any URL requests, instead of checking the
connection for validity when it might be gone.

Changes against parent 870254bc565eb9ffa4f78dce9b5f8e9bd1ebb78f

  patched  libpurple/protocols/msn/msn.c
  patched  libpurple/protocols/msn/session.c
  patched  libpurple/protocols/msn/session.h

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	6a005f8d2d4114210f8ed43face793d0733a3181
+++ libpurple/protocols/msn/msn.c	3b2fbec6c78ed81ed731ccdfb85343a0b99d7478
@@ -2204,6 +2204,7 @@ msn_got_info(PurpleUtilFetchUrlData *url
 		const gchar *url_text, size_t len, const gchar *error_message)
 {
 	MsnGetInfoData *info_data = (MsnGetInfoData *)data;
+	MsnSession *session;
 	PurpleNotifyUserInfo *user_info;
 	char *stripped, *p, *q, *tmp;
 	char *user_url = NULL;
@@ -2221,15 +2222,8 @@ msn_got_info(PurpleUtilFetchUrlData *url
 
 	purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text);
 
-	/* Make sure the connection is still valid */
-	/* TODO: Instead of this, we should be canceling this when we disconnect */
-	if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL)
-	{
-		purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n");
-		g_free(info_data->name);
-		g_free(info_data);
-		return;
-	}
+	session = purple_connection_get_protocol_data(info_data->gc);
+	session->url_datas = g_slist_remove(session->url_datas, url_data);
 
 	user_info = purple_notify_user_info_new();
 	has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data);
@@ -2614,13 +2608,14 @@ msn_got_info(PurpleUtilFetchUrlData *url
 	/* Try to put the photo in there too, if there's one */
 	if (photo_url_text)
 	{
-		purple_util_fetch_url_len(photo_url_text, FALSE, NULL, FALSE, MAX_HTTP_BUDDYICON_BYTES, msn_got_photo,
-					   info2_data);
+		url_data = purple_util_fetch_url_len(photo_url_text, FALSE, NULL, FALSE,
+		                                     MAX_HTTP_BUDDYICON_BYTES,
+		                                     msn_got_photo, info2_data);
+		session->url_datas = g_slist_prepend(session->url_datas, url_data);
 	}
 	else
 	{
-		/* Emulate a callback */
-		/* TODO: Huh? */
+		/* Finish the Get Info and show the user something */
 		msn_got_photo(NULL, info2_data, NULL, 0, NULL);
 	}
 }
@@ -2639,10 +2634,12 @@ msn_got_photo(PurpleUtilFetchUrlData *ur
 	PurpleNotifyUserInfo *user_info = info2_data->user_info;
 	char *photo_url_text = info2_data->photo_url_text;
 
-	/* Make sure the connection is still valid if we got here by fetching a photo url */
-	/* TODO: Instead of this, we should be canceling this when we disconnect */
-	if (url_text && (error_message != NULL ||
-					 g_list_find(purple_connections_get_all(), info_data->gc) == NULL))
+	if (url_data) {
+		MsnSession *session = purple_connection_get_protocol_data(info_data->gc);
+		session->url_datas = g_slist_remove(session->url_datas, url_data);
+	}
+
+	if (url_text && error_message)
 	{
 		purple_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n");
 		g_free(stripped);
@@ -2697,8 +2694,10 @@ msn_get_info(PurpleConnection *gc, const
 static void
 msn_get_info(PurpleConnection *gc, const char *name)
 {
+	MsnSession *session = purple_connection_get_protocol_data(gc);
 	MsnGetInfoData *data;
 	char *url;
+	PurpleUtilFetchUrlData *url_data;
 
 	data       = g_new0(MsnGetInfoData, 1);
 	data->gc   = gc;
@@ -2706,9 +2705,10 @@ msn_get_info(PurpleConnection *gc, const
 
 	url = g_strdup_printf("%s%s", PROFILE_URL, name);
 
-	purple_util_fetch_url(url, FALSE,
-				   "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
-				   TRUE, msn_got_info, data);
+	url_data = purple_util_fetch_url(url, FALSE,
+	                                 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
+	                                 TRUE, msn_got_info, data);
+	session->url_datas = g_slist_prepend(session->url_datas, url_data);
 
 	g_free(url);
 }
============================================================
--- libpurple/protocols/msn/session.c	5dc761eceb3f62b2d9b6ca39b778b4d2f344b1c7
+++ libpurple/protocols/msn/session.c	0d5255671b27868560123b0861a920671350e7bc
@@ -57,6 +57,11 @@ msn_session_destroy(MsnSession *session)
 
 	session->destroying = TRUE;
 
+	while (session->url_datas) {
+		purple_util_fetch_url_cancel(session->url_datas->data);
+		session->url_datas = g_slist_delete_link(session->url_datas, session->url_datas);
+	}
+
 	if (session->connected)
 		msn_session_disconnect(session);
 
============================================================
--- libpurple/protocols/msn/session.h	ab1581b4479bd685479a2ad74a281cf8427a45c9
+++ libpurple/protocols/msn/session.h	db33182d1e34e934b0a8db61bf544ea2ef168532
@@ -122,6 +122,8 @@ struct _MsnSession
 
 	GHashTable *soap_table;
 	guint soap_cleanup_handle;
+
+	GSList *url_datas; /**< PurpleUtilFetchUrlData to be cancelled on exit */
 };
 
 /**


More information about the Commits mailing list