changeset 30748:ea96292336f0

Save and cancel-on-exit any URL requests, instead of checking the connection for validity when it might be gone.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 31 Jul 2010 20:47:31 +0000
parents 30f16cb2f736
children 76049fde7ad2
files libpurple/protocols/msn/msn.c libpurple/protocols/msn/session.c libpurple/protocols/msn/session.h
diffstat 3 files changed, 27 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Fri Jul 30 07:28:00 2010 +0000
+++ b/libpurple/protocols/msn/msn.c	Sat Jul 31 20:47:31 2010 +0000
@@ -2204,6 +2204,7 @@
 		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 @@
 
 	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 @@
 	/* 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 @@
 	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 @@
 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 @@
 
 	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);
 }
--- a/libpurple/protocols/msn/session.c	Fri Jul 30 07:28:00 2010 +0000
+++ b/libpurple/protocols/msn/session.c	Sat Jul 31 20:47:31 2010 +0000
@@ -57,6 +57,11 @@
 
 	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);
 
--- a/libpurple/protocols/msn/session.h	Fri Jul 30 07:28:00 2010 +0000
+++ b/libpurple/protocols/msn/session.h	Sat Jul 31 20:47:31 2010 +0000
@@ -122,6 +122,8 @@
 
 	GHashTable *soap_table;
 	guint soap_cleanup_handle;
+
+	GSList *url_datas; /**< PurpleUtilFetchUrlData to be cancelled on exit */
 };
 
 /**