/pidgin/main: e6de87604147: HTTP: get rid of the second msn's ow...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Jul 23 14:48:43 EDT 2013


Changeset: e6de876041478acae6855daab1a0a66953990cea
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-07-23 20:48 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/e6de87604147

Description:

HTTP: get rid of the second msn's own HTTP implementation (for soap)

diffstat:

 libpurple/http.c                  |   23 +-
 libpurple/protocols/msn/contact.c |    2 +-
 libpurple/protocols/msn/nexus.c   |   16 +-
 libpurple/protocols/msn/oim.c     |    5 +-
 libpurple/protocols/msn/session.c |    8 +-
 libpurple/protocols/msn/session.h |    4 +-
 libpurple/protocols/msn/soap.c    |  844 +++++++++----------------------------
 libpurple/protocols/msn/soap.h    |   14 +-
 8 files changed, 269 insertions(+), 647 deletions(-)

diffs (truncated from 1106 to 300 lines):

diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -703,6 +703,9 @@ static void _purple_http_error(PurpleHtt
 	hc->response->error = g_strdup_vprintf(format, args);
 	va_end(args);
 
+	if (purple_debug_is_verbose())
+		purple_debug_warning("http", "error: %s\n", hc->response->error);
+
 	purple_http_conn_cancel(hc);
 }
 
@@ -1084,7 +1087,7 @@ static gboolean _purple_http_recv_loopbo
 			hc->length_expected = hc->length_got;
 		else if (hc->length_got == 0 && hc->socket->use_count > 1) {
 			purple_debug_info("http", "Keep-alive connection "
-				"expired, retrying...\n");
+				"expired (when reading), retrying...\n");
 			purple_http_conn_retry(hc);
 			return FALSE;
 		} else {
@@ -1289,6 +1292,15 @@ static void _purple_http_send(gpointer _
 		return;
 
 	if (written < 0) {
+		if (hc->request_header_written == 0 &&
+			hc->socket->use_count > 1)
+		{
+			purple_debug_info("http", "Keep-alive connection "
+				"expired (when writing), retrying...\n");
+			purple_http_conn_retry(hc);
+			return;
+		}
+
 		_purple_http_error(hc, _("Error writing to %s: %s"),
 			hc->url->host, g_strerror(errno));
 		return;
@@ -1635,7 +1647,14 @@ purple_http_conn_retry(PurpleHttpConnect
 
 void purple_http_conn_cancel_all(PurpleConnection *gc)
 {
-	GList *gc_list = g_hash_table_lookup(purple_http_hc_by_gc, gc);
+	GList *gc_list;
+
+	if (purple_debug_is_verbose()) {
+		purple_debug_misc("http", "Cancelling all running HTTP "
+			"connections\n");
+	}
+
+	gc_list = g_hash_table_lookup(purple_http_hc_by_gc, gc);
 
 	g_hash_table_insert(purple_http_cancelling_gc, gc, GINT_TO_POINTER(TRUE));
 
diff --git a/libpurple/protocols/msn/contact.c b/libpurple/protocols/msn/contact.c
--- a/libpurple/protocols/msn/contact.c
+++ b/libpurple/protocols/msn/contact.c
@@ -288,7 +288,7 @@ msn_contact_request(MsnCallbackState *st
 	xmlnode_free(state->token->child);
 	xmlnode_insert_data(state->token,
 		msn_nexus_get_token_str(state->session->nexus, MSN_AUTH_CONTACTS), -1);
-	msn_soap_message_send(state->session,
+	msn_soap_service_send_message(state->session->soap,
 		msn_soap_message_new(state->post_action, xmlnode_copy(state->body)),
 		MSN_CONTACT_SERVER, state->post_url, FALSE,
 		msn_contact_request_cb, state);
diff --git a/libpurple/protocols/msn/nexus.c b/libpurple/protocols/msn/nexus.c
--- a/libpurple/protocols/msn/nexus.c
+++ b/libpurple/protocols/msn/nexus.c
@@ -376,8 +376,6 @@ msn_nexus_connect(MsnNexus *nexus)
 	char *request;
 	int i;
 
-	MsnSoapMessage *soap;
-
 	purple_debug_info("msn", "Starting Windows Live ID authentication\n");
 	msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE);
 
@@ -409,10 +407,11 @@ msn_nexus_connect(MsnNexus *nexus)
 	g_free(password_xml);
 	g_string_free(domains, TRUE);
 
-	soap = msn_soap_message_new(NULL, xmlnode_from_str(request, -1));
+	msn_soap_service_send_message(session->soap,
+		msn_soap_message_new(NULL, xmlnode_from_str(request, -1)),
+		MSN_SSO_SERVER, SSO_POST_URL, TRUE,
+		nexus_got_response_cb, nexus);
 	g_free(request);
-	msn_soap_message_send(session, soap, MSN_SSO_SERVER, SSO_POST_URL, TRUE,
-	                      nexus_got_response_cb, nexus);
 }
 
 static void
@@ -532,7 +531,6 @@ msn_nexus_update_token(MsnNexus *nexus, 
 	guchar signature[20];
 
 	char *request;
-	MsnSoapMessage *soap;
 
 	update = g_new0(MsnNexusUpdateCallback, 1);
 	update->cb = cb;
@@ -623,10 +621,10 @@ msn_nexus_update_token(MsnNexus *nexus, 
 	g_free(signedinfo);
 	g_free(domain);
 
-	soap = msn_soap_message_new(NULL, xmlnode_from_str(request, -1));
 	g_free(request);
-	msn_soap_message_send(session, soap, MSN_SSO_SERVER, SSO_POST_URL, TRUE,
-	                      nexus_got_update_cb, ud);
+	msn_soap_service_send_message(session->soap,
+		msn_soap_message_new(NULL, xmlnode_from_str(request, -1)),
+		MSN_SSO_SERVER, SSO_POST_URL, TRUE, nexus_got_update_cb, ud);
 }
 
 GHashTable *
diff --git a/libpurple/protocols/msn/oim.c b/libpurple/protocols/msn/oim.c
--- a/libpurple/protocols/msn/oim.c
+++ b/libpurple/protocols/msn/oim.c
@@ -244,10 +244,9 @@ msn_oim_request_helper(MsnOimRequestData
 		xmlnode_insert_data(xml_p, msn_p, -1);
 	}
 
-	msn_soap_message_send(session,
+	msn_soap_service_send_message(session->soap,
 		msn_soap_message_new(data->action, xmlnode_copy(data->body)),
-		data->host, data->url, FALSE,
-		msn_oim_request_cb, data);
+		data->host, data->url, FALSE, msn_oim_request_cb, data);
 
 	return FALSE;
 }
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
@@ -55,6 +55,8 @@ msn_session_new(PurpleAccount *account)
 
 	session->guid = rand_guid();
 
+	session->soap = msn_soap_service_new(session);
+
 	return session;
 }
 
@@ -73,11 +75,7 @@ msn_session_destroy(MsnSession *session)
 	if (session->connected)
 		msn_session_disconnect(session);
 
-	if (session->soap_cleanup_handle)
-		purple_timeout_remove(session->soap_cleanup_handle);
-
-	if (session->soap_table != NULL)
-		g_hash_table_destroy(session->soap_table);
+	msn_soap_service_destroy(session->soap);
 
 	while (session->slplinks != NULL)
 		msn_slplink_unref(session->slplinks->data);
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
@@ -66,6 +66,7 @@ typedef enum
 #include "nexus.h"
 #include "notification.h"
 #include "oim.h"
+#include "soap.h"
 #include "switchboard.h"
 #include "user.h"
 #include "userlist.h"
@@ -116,8 +117,7 @@ struct _MsnSession
 		gboolean email_enabled;
 	} passport_info;
 
-	GHashTable *soap_table;
-	guint soap_cleanup_handle;
+	MsnSoapService *soap;
 	char *guid;
 
 	GSList *http_reqs; /**< PurpleHttpConnection to be cancelled on exit */
diff --git a/libpurple/protocols/msn/soap.c b/libpurple/protocols/msn/soap.c
--- a/libpurple/protocols/msn/soap.c
+++ b/libpurple/protocols/msn/soap.c
@@ -25,19 +25,60 @@
 
 #include "soap.h"
 
-#include "internal.h"
-
 #include "debug.h"
 #include "http.h"
 
-#define SOAP_TIMEOUT (5 * 60)
+typedef struct _MsnSoapRequest MsnSoapRequest;
 
 struct _MsnSoapMessage {
 	gchar *action;
 	xmlnode *xml;
-	GSList *headers;
 };
 
+struct _MsnSoapRequest {
+	MsnSoapMessage *message;
+	MsnSoapService *soaps;
+	MsnSoapCallback cb;
+	gpointer cb_data;
+	gboolean secure;
+};
+
+struct _MsnSoapService {
+	MsnSession *session;
+	PurpleHttpKeepalivePool *keepalive_pool;
+};
+
+static void
+msn_soap_service_send_message_simple(MsnSoapService *soaps,
+	MsnSoapMessage *message, const gchar *url, gboolean secure,
+	MsnSoapCallback cb, gpointer cb_data);
+
+MsnSoapMessage *
+msn_soap_message_new(const gchar *action, xmlnode *xml)
+{
+	MsnSoapMessage *msg;
+
+	g_return_val_if_fail(xml != NULL, NULL);
+
+	msg = g_new0(MsnSoapMessage, 1);
+	msg->action = g_strdup(action);
+	msg->xml = xml;
+
+	return msg;
+}
+
+static void
+msn_soap_message_free(MsnSoapMessage *msg)
+{
+	if (msg == NULL)
+		return;
+
+	g_free(msg->action);
+	if (msg->xml != NULL)
+		xmlnode_free(msg->xml);
+	g_free(msg);
+}
+
 xmlnode *
 msn_soap_message_get_xml(MsnSoapMessage *message)
 {
@@ -46,647 +87,206 @@ msn_soap_message_get_xml(MsnSoapMessage 
 	return message->xml;
 }
 
-typedef struct _MsnSoapRequest {
-	char *path;
-	MsnSoapMessage *message;
-	gboolean secure;
-	MsnSoapCallback cb;
-	gpointer cb_data;
-} MsnSoapRequest;
+static void
+msn_soap_request_free(MsnSoapRequest *sreq)
+{
+	g_return_if_fail(sreq != NULL);
 
-typedef struct _MsnSoapConnection {
-	MsnSession *session;
-	char *host;
+	msn_soap_message_free(sreq->message);
+	g_free(sreq);
+}
 
-	time_t last_used;
-	PurpleSslConnection *ssl;
-	gboolean connected;
+MsnSoapService *
+msn_soap_service_new(MsnSession *session)
+{
+	MsnSoapService *soaps;
 
-	guint event_handle;
-	guint run_timer;
-	GString *buf;
-	gsize handled_len;
-	gsize body_len;
-	int response_code;
-	gboolean headers_done;
-	gboolean close_when_done;
+	g_return_val_if_fail(session != NULL, NULL);
 
-	MsnSoapMessage *message;
+	soaps = g_new0(MsnSoapService, 1);
+	soaps->session = session;
+	soaps->keepalive_pool = purple_http_keepalive_pool_new();
+	purple_http_keepalive_pool_set_limit_per_host(soaps->keepalive_pool, 1);
 
-	GQueue *queue;
-	MsnSoapRequest *current_request;
-} MsnSoapConnection;
+	return soaps;
+}
 
-static gboolean msn_soap_connection_run(gpointer data);
+void



More information about the Commits mailing list