/pidgin/main: 26b4c9a54166: HTTP: Use PurpleHttpConnectionSet in...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Aug 3 13:21:04 EDT 2013


Changeset: 26b4c9a54166a757009e2bc6d8cb2d63cf1518f8
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-08-03 19:20 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/26b4c9a54166

Description:

HTTP: Use PurpleHttpConnectionSet instead of GSLists of PurpleHttpConnection structs

diffstat:

 libpurple/protocols/jabber/bosh.c         |   6 +--
 libpurple/protocols/jabber/jabber.c       |   6 +--
 libpurple/protocols/jabber/jabber.h       |   7 +---
 libpurple/protocols/jabber/useravatar.c   |   6 ++--
 libpurple/protocols/msn/httpconn.c        |   6 +--
 libpurple/protocols/msn/msn.c             |  20 ++++---------
 libpurple/protocols/msn/session.c         |   7 ++--
 libpurple/protocols/msn/session.h         |   4 ++-
 libpurple/protocols/msn/slp.c             |   8 ++---
 libpurple/protocols/mxit/login.c          |  22 ++++----------
 libpurple/protocols/mxit/markup.c         |  12 ++-----
 libpurple/protocols/mxit/mxit.h           |   3 +-
 libpurple/protocols/mxit/protocol.c       |  23 +++++----------
 libpurple/protocols/yahoo/libymsg.c       |  46 +++++++++---------------------
 libpurple/protocols/yahoo/libymsg.h       |   5 ++-
 libpurple/protocols/yahoo/yahoo_aliases.c |  25 ++++------------
 libpurple/protocols/yahoo/yahoo_picture.c |   9 +----
 libpurple/protocols/yahoo/yahoo_profile.c |  17 ++++-------
 18 files changed, 78 insertions(+), 154 deletions(-)

diffs (truncated from 816 to 300 lines):

diff --git a/libpurple/protocols/jabber/bosh.c b/libpurple/protocols/jabber/bosh.c
--- a/libpurple/protocols/jabber/bosh.c
+++ b/libpurple/protocols/jabber/bosh.c
@@ -152,10 +152,8 @@ jabber_bosh_connection_destroy(PurpleJab
 	if (conn->send_timer)
 		purple_timeout_remove(conn->send_timer);
 
-	if (conn->sc_req != NULL) {
-		purple_http_conn_cancel(conn->sc_req);
-		conn->sc_req = NULL;
-	}
+	purple_http_conn_cancel(conn->sc_req);
+	conn->sc_req = NULL;
 
 	purple_http_keepalive_pool_unref(conn->kapool);
 	conn->kapool = NULL;
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -931,6 +931,7 @@ jabber_stream_new(PurpleAccount *account
 	purple_connection_set_protocol_data(gc, js);
 	js->gc = gc;
 	js->fd = -1;
+	js->http_conns = purple_http_connection_set_new();
 
 	user = g_strdup(purple_account_get_username(account));
 	/* jabber_id_new doesn't accept "user at domain/" as valid */
@@ -1633,10 +1634,7 @@ void jabber_close(PurpleConnection *gc)
 		js->bs_proxies = g_list_delete_link(js->bs_proxies, js->bs_proxies);
 	}
 
-	while(js->http_conns) {
-		purple_http_conn_cancel(js->http_conns->data);
-		js->http_conns = g_slist_delete_link(js->http_conns, js->http_conns);
-	}
+	purple_http_connection_set_destroy(js->http_conns);
 
 	g_free(js->stream_id);
 	if(js->user)
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -60,6 +60,7 @@ typedef struct _JabberStream JabberStrea
 #include "connection.h"
 #include "dnsquery.h"
 #include "dnssrv.h"
+#include "http.h"
 #include "media.h"
 #include "mediamanager.h"
 #include "roomlist.h"
@@ -263,11 +264,7 @@ struct _JabberStream
 
 	PurpleJabberBOSHConnection *bosh;
 
-	/**
-	 * This linked list contains PurpleHttpConnection structs
-	 * for when we lookup buddy icons from a url
-	 */
-	GSList *http_conns;
+	PurpleHttpConnectionSet *http_conns;
 
 	/* keep a hash table of JingleSessions */
 	GHashTable *sessions;
diff --git a/libpurple/protocols/jabber/useravatar.c b/libpurple/protocols/jabber/useravatar.c
--- a/libpurple/protocols/jabber/useravatar.c
+++ b/libpurple/protocols/jabber/useravatar.c
@@ -381,18 +381,18 @@ update_buddy_metadata(JabberStream *js, 
 				                        do_buddy_avatar_update_data);
 			} else {
 				PurpleHttpRequest *req;
-				PurpleHttpConnection *http_conn;
 				JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1);
 				info->js = js;
 
 				req = purple_http_request_new(url);
 				purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES);
-				http_conn = purple_http_request(js->gc, req, do_buddy_avatar_update_fromurl, info);
+				purple_http_connection_set_add(js->http_conns,
+					purple_http_request(js->gc, req,
+					do_buddy_avatar_update_fromurl, info));
 				purple_http_request_unref(req);
 
 				info->from = g_strdup(from);
 				info->id = g_strdup(id);
-				js->http_conns = g_slist_prepend(js->http_conns, http_conn);
 			}
 		}
 	}
diff --git a/libpurple/protocols/msn/httpconn.c b/libpurple/protocols/msn/httpconn.c
--- a/libpurple/protocols/msn/httpconn.c
+++ b/libpurple/protocols/msn/httpconn.c
@@ -207,10 +207,8 @@ msn_httpconn_disconnect(MsnHttpConn *htt
 		httpconn->finish_timer = 0;
 	}
 
-	if (httpconn->current_request != NULL) {
-		purple_http_conn_cancel(httpconn->current_request);
-		httpconn->current_request = NULL;
-	}
+	purple_http_conn_cancel(httpconn->current_request);
+	httpconn->current_request = NULL;
 
 	g_free(httpconn->host_dest);
 	httpconn->host_dest = NULL;
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -2338,7 +2338,6 @@ msn_got_info(PurpleHttpConnection *http_
 #endif
 
 	session = purple_connection_get_protocol_data(info_data->gc);
-	session->http_reqs = g_slist_remove(session->http_reqs, http_conn);
 
 	user_info = purple_notify_user_info_new();
 	has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data);
@@ -2728,14 +2727,13 @@ msn_got_info(PurpleHttpConnection *http_
 	if (photo_url_text)
 	{
 		PurpleHttpRequest *req;
-		PurpleHttpConnection *hc;
 
 		req = purple_http_request_new(photo_url_text);
 		purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES);
-		hc = purple_http_request(info_data->gc, req, msn_got_photo, info2_data);
+		purple_http_connection_set_add(session->http_reqs,
+			purple_http_request(info_data->gc, req, msn_got_photo,
+				info2_data));
 		purple_http_request_unref(req);
-
-		session->http_reqs = g_slist_prepend(session->http_reqs, hc);
 	}
 	else
 	{
@@ -2758,11 +2756,6 @@ msn_got_photo(PurpleHttpConnection *http
 	PurpleNotifyUserInfo *user_info = info2_data->user_info;
 	char *photo_url_text = info2_data->photo_url_text;
 
-	if (http_conn) {
-		MsnSession *session = purple_connection_get_protocol_data(info_data->gc);
-		session->http_reqs = g_slist_remove(session->http_reqs, http_conn);
-	}
-
 	/* Try to put the photo in there too, if there's one and is readable */
 	if (response && purple_http_response_is_successfull(response))
 	{
@@ -2797,7 +2790,6 @@ msn_got_photo(PurpleHttpConnection *http
 static void
 msn_get_info(PurpleConnection *gc, const char *name)
 {
-	PurpleHttpConnection *hc;
 	MsnSession *session = purple_connection_get_protocol_data(gc);
 	MsnGetInfoData *data;
 
@@ -2805,9 +2797,9 @@ msn_get_info(PurpleConnection *gc, const
 	data->gc   = gc;
 	data->name = g_strdup(name);
 
-	hc = purple_http_get_printf(gc, msn_got_info, data,
-		"%s%s", PROFILE_URL, name);
-	session->http_reqs = g_slist_prepend(session->http_reqs, hc);
+	purple_http_connection_set_add(session->http_reqs,
+		purple_http_get_printf(gc, msn_got_info, data, "%s%s",
+			PROFILE_URL, name));
 }
 
 static gboolean msn_load(PurplePlugin *plugin)
diff --git a/libpurple/protocols/msn/session.c b/libpurple/protocols/msn/session.c
--- a/libpurple/protocols/msn/session.c
+++ b/libpurple/protocols/msn/session.c
@@ -41,6 +41,8 @@ msn_session_new(PurpleAccount *account)
 
 	session = g_new0(MsnSession, 1);
 
+	session->http_reqs = purple_http_connection_set_new();
+
 	session->account = account;
 	session->notification = msn_notification_new(session);
 	session->userlist = msn_userlist_new(session);
@@ -67,10 +69,7 @@ msn_session_destroy(MsnSession *session)
 
 	session->destroying = TRUE;
 
-	while (session->http_reqs) {
-		purple_http_conn_cancel(session->http_reqs->data);
-		session->http_reqs = g_slist_delete_link(session->http_reqs, session->http_reqs);
-	}
+	purple_http_connection_set_destroy(session->http_reqs);
 
 	if (session->connected)
 		msn_session_disconnect(session);
diff --git a/libpurple/protocols/msn/session.h b/libpurple/protocols/msn/session.h
--- a/libpurple/protocols/msn/session.h
+++ b/libpurple/protocols/msn/session.h
@@ -63,6 +63,8 @@ typedef enum
 
 #define MSN_LOGIN_FQY_TIMEOUT 30
 
+#include "http.h"
+
 #include "nexus.h"
 #include "notification.h"
 #include "oim.h"
@@ -120,7 +122,7 @@ struct _MsnSession
 	MsnSoapService *soap;
 	char *guid;
 
-	GSList *http_reqs; /**< PurpleHttpConnection to be cancelled on exit */
+	PurpleHttpConnectionSet *http_reqs;
 };
 
 /**
diff --git a/libpurple/protocols/msn/slp.c b/libpurple/protocols/msn/slp.c
--- a/libpurple/protocols/msn/slp.c
+++ b/libpurple/protocols/msn/slp.c
@@ -177,8 +177,6 @@ fetched_user_display(PurpleHttpConnectio
 	MsnFetchUserDisplayData *data = _data;
 	MsnSession *session = data->session;
 
-	session->http_reqs = g_slist_remove(session->http_reqs, http_conn);
-
 	if (purple_http_response_is_successfull(response)) {
 		size_t len;
 		const gchar *icon_data;
@@ -254,7 +252,6 @@ msn_request_user_display(MsnUser *user)
 		const char *url = msn_object_get_url1(obj);
 		if (url) {
 			PurpleHttpRequest *req;
-			PurpleHttpConnection *hc;
 			MsnFetchUserDisplayData *data = g_new0(MsnFetchUserDisplayData, 1);
 			data->session = session;
 			data->remote_user = user->passport;
@@ -262,9 +259,10 @@ msn_request_user_display(MsnUser *user)
 
 			req = purple_http_request_new(url);
 			purple_http_request_set_max_len(req, 200*1024);
-			hc = purple_http_request(NULL, req, fetched_user_display, data);
+			purple_http_connection_set_add(session->http_reqs,
+				purple_http_request(NULL, req,
+					fetched_user_display, data));
 			purple_http_request_unref(req);
-			session->http_reqs = g_slist_prepend(session->http_reqs, hc);
 		} else {
 			msn_slplink_request_object(slplink, info, got_user_display,
 			                           end_user_display, obj);
diff --git a/libpurple/protocols/mxit/login.c b/libpurple/protocols/mxit/login.c
--- a/libpurple/protocols/mxit/login.c
+++ b/libpurple/protocols/mxit/login.c
@@ -91,6 +91,7 @@ static struct MXitSession* mxit_create_o
 	session->rx_state = RX_STATE_RLEN;
 	session->http_interval = MXIT_HTTP_POLL_MIN;
 	session->http_last_poll = mxit_now_milli();
+	session->async_http_reqs = purple_http_connection_set_new();
 
 	return session;
 }
@@ -391,9 +392,6 @@ mxit_cb_clientinfo2(PurpleHttpConnection
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_clientinfo_cb2\n" );
 
-	/* remove request from the async outstanding calls list */
-	session->async_http_reqs = g_slist_remove(session->async_http_reqs, http_conn);
-
 	if (!purple_http_response_is_successfull(response)) {
 		/* no reply from the WAP site */
 		purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Error contacting the MXit WAP site. Please try again later." ) );
@@ -518,7 +516,6 @@ static void free_logindata( struct login
 static void mxit_cb_captcha_ok( PurpleConnection* gc, PurpleRequestFields* fields )
 {
 	PurpleHttpRequest *req;
-	PurpleHttpConnection *hc;
 	struct MXitSession*		session	= purple_connection_get_protocol_data( gc );
 	PurpleRequestField*		field;
 	const char*				captcha_resp;
@@ -571,11 +568,10 @@ static void mxit_cb_captcha_ok( PurpleCo
 		MXIT_CP_OS, MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH,
 		time(NULL));
 	purple_http_request_header_set(req, "User-Agent", MXIT_HTTP_USERAGENT);
-	hc = purple_http_request(session->con, req, mxit_cb_clientinfo2,
-		session);
+	purple_http_connection_set_add(session->async_http_reqs,
+		purple_http_request(session->con, req, mxit_cb_clientinfo2,
+			session));
 	purple_http_request_unref(req);
-	session->async_http_reqs =
-		g_slist_prepend(session->async_http_reqs, hc);
 
 	/* free up the login resources */
 	free_logindata( session->logindata );
@@ -630,10 +626,6 @@ mxit_cb_clientinfo1(PurpleHttpConnection
 		purple_http_response_get_data(response, NULL));
 #endif
 
-	/* remove request from the async outstanding calls list */
-	session->async_http_reqs = g_slist_remove(session->async_http_reqs,
-		http_conn);
-
 	if (!purple_http_response_is_successfull(response)) {
 		/* no reply from the WAP site */
 		purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Error contacting the MXit WAP site. Please try again later." ) );
@@ -729,7 +721,6 @@ static void



More information about the Commits mailing list