changeset 21102:f387e8c671a4

propagate from branch 'im.pidgin.pidgin' (head 267f2e22b77cc35309c41a034169f74faaa46e1f) to branch 'im.pidgin.cpw.khc.msnp14.soap' (head ad5838522d44d037dc333469f1ab6df844ca1875)
author Ka-Hing Cheung <khc@hxbc.us>
date Wed, 24 Oct 2007 02:48:32 +0000
parents fcce0bf2a279 (current diff) 741c3b5eac21 (diff)
children aa875e77e5ce d31843a6b3bb ca624eda4267 c5df2bf2bf8e
files libpurple/account.c libpurple/protocols/msn/msn.c libpurple/protocols/msn/nexus.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/oim.c libpurple/protocols/msn/session.c libpurple/protocols/msn/soap.c libpurple/protocols/myspace/user.h pidgin/gtkdialogs.c pidgin/gtkutils.c po/ChangeLog po/de.po
diffstat 13 files changed, 1006 insertions(+), 720 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/Makefile.am	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/Makefile.am	Wed Oct 24 02:48:32 2007 +0000
@@ -52,6 +52,8 @@
 	slpsession.h \
 	soap.c\
 	soap.h\
+	soap2.c \
+	soap2.h \
 	state.c \
 	state.h \
 	switchboard.c \
--- a/libpurple/protocols/msn/msn.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/msn.c	Wed Oct 24 02:48:32 2007 +0000
@@ -951,21 +951,17 @@
 	}else	{
 		/*send Offline Instant Message,only to MSN Passport User*/
 		MsnSession *session;
-		MsnOim *oim;
 		char *friendname;
 
 		purple_debug_info("MSNP14","prepare to send offline Message\n");
 		session = gc->proto_data;
-		/* XXX/khc: hack */
-		if (!session->oim)
-			session->oim = msn_oim_new(session);
 
-		oim = session->oim;
 		friendname = msn_encode_mime(account->username);
-		msn_oim_prep_send_msg_info(oim, purple_account_get_username(account),
-								   friendname, who,	message);
+		msn_oim_prep_send_msg_info(session->oim,
+			purple_account_get_username(account),
+			friendname, who,	message);
+		msn_oim_send_msg(session->oim);
 		g_free(friendname);
-		msn_oim_send_msg(oim);
 	}
 
 	return 1;
--- a/libpurple/protocols/msn/nexus.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/nexus.c	Wed Oct 24 02:48:32 2007 +0000
@@ -22,15 +22,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 #include "msn.h"
-#include "soap.h"
+#include "soap2.h"
 #include "nexus.h"
 #include "notification.h"
 
 #undef NEXUS_LOGIN_TWN
 
-/*Local Function Prototype*/
-static gboolean nexus_login_connect_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc);
-
 /**************************************************************************
  * Main
  **************************************************************************/
@@ -42,8 +39,6 @@
 
 	nexus = g_new0(MsnNexus, 1);
 	nexus->session = session;
-	/*we must use SSL connection to do Windows Live ID authentication*/
-	nexus->soapconn = msn_soap_new(session,nexus,1);
 
 	nexus->challenge_data = g_hash_table_new_full(g_str_hash,
 		g_str_equal, g_free, g_free);
@@ -57,193 +52,98 @@
 	if (nexus->challenge_data != NULL)
 		g_hash_table_destroy(nexus->challenge_data);
 
-	msn_soap_destroy(nexus->soapconn);
 	g_free(nexus);
 }
 
-#if 0 /* khc */
-/**************************************************************************
- * Util
- **************************************************************************/
-
-static gssize
-msn_ssl_read(MsnNexus *nexus)
-{
-	gssize len;
-	char temp_buf[4096];
-
-	if ((len = purple_ssl_read(nexus->gsc, temp_buf,
-			sizeof(temp_buf))) > 0)
-	{
-		nexus->read_buf = g_realloc(nexus->read_buf,
-			nexus->read_len + len + 1);
-		strncpy(nexus->read_buf + nexus->read_len, temp_buf, len);
-		nexus->read_len += len;
-		nexus->read_buf[nexus->read_len] = '\0';
-	}
-
-	return len;
-}
-
-static void
-nexus_write_cb(gpointer data, gint source, PurpleInputCondition cond)
-{
-	MsnNexus *nexus = data;
-	int len, total_len;
-
-	total_len = strlen(nexus->write_buf);
-
-	len = purple_ssl_write(nexus->gsc,
-		nexus->write_buf + nexus->written_len,
-		total_len - nexus->written_len);
-
-	if (len < 0 && errno == EAGAIN)
-		return;
-	else if (len <= 0) {
-		purple_input_remove(nexus->input_handler);
-		nexus->input_handler = 0;
-		/* TODO: notify of the error */
-		return;
-	}
-	nexus->written_len += len;
-
-	if (nexus->written_len < total_len)
-		return;
-
-	purple_input_remove(nexus->input_handler);
-	nexus->input_handler = 0;
-
-	g_free(nexus->write_buf);
-	nexus->write_buf = NULL;
-	nexus->written_len = 0;
-
-	nexus->written_cb(nexus, source, 0);
-}
-
-#endif
 /**************************************************************************
  * Login
  **************************************************************************/
+
 static void
-nexus_login_error_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc, PurpleSslErrorType error)
+nexus_got_response_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
 {
-	MsnSession *session;
+	MsnNexus *nexus = data;
+	MsnSession *session = nexus->session;
+	xmlnode *node;
+
+	if (resp == NULL) {
+		msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect"));
+		return;
+	}
+
+	node = msn_soap_xml_get(resp->xml,	"Body/"
+		"RequestSecurityTokenResponseCollection/RequestSecurityTokenResponse");
+
+	for (; node; node = node->next) {
+		xmlnode *token = msn_soap_xml_get(node,
+			"RequestedSecurityToken/BinarySecurityToken");
+
+		if (token) {
+			char *token_str = xmlnode_get_data(token);
+			char **elems, **cur, **tokens;
+			char *msn_twn_t, *msn_twn_p, *cert_str;
+
+			if (token_str == NULL) continue;
+
+			elems = g_strsplit(token_str, "&", 0);
 
-	session = soapconn->session;
-	g_return_if_fail(session != NULL);
+			for (cur = elems; *cur != NULL; cur++){
+				tokens = g_strsplit(*cur, "=", 2);
+				g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]);
+				/* Don't free each of the tokens, only the array. */
+				g_free(tokens);
+			}
+
+			g_free(token_str);
+			g_strfreev(elems);
+
+			msn_twn_t = g_hash_table_lookup(nexus->challenge_data, "t");
+			msn_twn_p = g_hash_table_lookup(nexus->challenge_data, "p");
+
+			/*setup the t and p parameter for session*/
+			if (session->passport_info.t != NULL){
+				g_free(session->passport_info.t);
+			}
+			session->passport_info.t = g_strdup(msn_twn_t);
 
-	soapconn->gsc = NULL;
+			if (session->passport_info.p != NULL)
+				g_free(session->passport_info.p);
+			session->passport_info.p = g_strdup(msn_twn_p);
+
+			cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
+			msn_got_login_params(session, cert_str);
 
-	msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect"));
-	/* the above line will result in nexus being destroyed, so we don't want
-	 * to destroy it here, or we'd crash */
+			purple_debug_info("MSN Nexus","Close nexus connection!\n");
+			g_free(cert_str);
+			msn_nexus_destroy(nexus);
+			session->nexus = NULL;
+
+			return;
+		}
+	}
+
+	/* we must have failed! */
+	msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication: cannot find authenticate token in server response"));
 }
 
-/*process the SOAP reply, get the Authentication Info*/
-static gboolean
-nexus_login_read_cb(MsnSoapConn *soapconn)
+/*when connect, do the SOAP Style windows Live ID authentication */
+void
+msn_nexus_connect(MsnNexus *nexus)
 {
-	MsnNexus *nexus;
-	MsnSession *session;
-
-	char *base, *c;
-	char *msn_twn_t,*msn_twn_p;
-	char *login_params;
-	char **elems, **cur, **tokens;
-	char * cert_str;
-
-	nexus = soapconn->parent;
-	g_return_val_if_fail(nexus != NULL, TRUE);
-	session = nexus->session;
-	g_return_val_if_fail(session != NULL, FALSE);
-
-	/*reply OK, we should process the SOAP body*/
-	purple_debug_info("MSN Nexus","TWN Server Windows Live ID Reply OK!\n");
-
-	//TODO: we should parse it using XML
-#ifdef NEXUS_LOGIN_TWN
-	base  = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_START_TOKEN);
-	base += strlen(TWN_START_TOKEN);
-	c     = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_END_TOKEN);
-#else
-	base  = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_LIVE_START_TOKEN);
-	base += strlen(TWN_LIVE_START_TOKEN);
-	c     = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_LIVE_END_TOKEN);
-#endif
-	login_params = g_strndup(base, c - base);
-
-	//		purple_debug_info("msn", "TWN Cert: {%s}\n", login_params);
-
-	/* Parse the challenge data. */
-	elems = g_strsplit(login_params, "&amp;", 0);
-
-	for (cur = elems; *cur != NULL; cur++){
-			tokens = g_strsplit(*cur, "=", 2);
-			g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]);
-			/* Don't free each of the tokens, only the array. */
-			g_free(tokens);
-	}
-
-	g_strfreev(elems);
-
-	msn_twn_t = (char *)g_hash_table_lookup(nexus->challenge_data, "t");
-	msn_twn_p = (char *)g_hash_table_lookup(nexus->challenge_data, "p");
-
-	/*setup the t and p parameter for session*/
-	g_free(session->passport_info.t);
-	session->passport_info.t = g_strdup(msn_twn_t);
-
-	g_free(session->passport_info.p);
-	session->passport_info.p = g_strdup(msn_twn_p);
-
-	cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
-	msn_got_login_params(session, cert_str);
-
-	purple_debug_info("MSN Nexus","Close nexus connection!\n");
-	g_free(cert_str);
-	g_free(login_params);
-	msn_nexus_destroy(nexus);
-	session->nexus = NULL;
-
-	return FALSE;
-}
-
-static void
-nexus_login_written_cb(MsnSoapConn *soapconn)
-{
-	soapconn->read_cb = nexus_login_read_cb;
-//	msn_soap_read_cb(data,source,cond);
-}
-
-
-/*when connect, do the SOAP Style windows Live ID authentication */
-gboolean
-nexus_login_connect_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc)
-{
-	MsnNexus * nexus;
-	MsnSession *session;
+	MsnSession *session = nexus->session;
 	char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf;
 	char *fs0,*fs;
 	char *username, *password;
-	char *request_str, *tail;
+	char *tail;
 #ifdef NEXUS_LOGIN_TWN
 	char *challenge_str;
 #else
 	char *rst1_str,*rst2_str,*rst3_str;
 #endif
-	
-	purple_debug_info("MSN Nexus","Starting Windows Live ID authentication\n");
-
-	g_return_val_if_fail(soapconn != NULL, FALSE);
 
-	nexus = soapconn->parent;
-	g_return_val_if_fail(nexus != NULL, TRUE);
+	MsnSoapMessage *soap;
 
-	session = soapconn->session;
-	g_return_val_if_fail(session != NULL, FALSE);
-
-	msn_soap_set_process_step(soapconn, MSN_SOAP_PROCESSING);
-
+	purple_debug_info("MSN Nexus","Starting Windows Live ID authentication\n");
 	msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE);
 
 	/*prepare the Windows Live ID authentication token*/
@@ -272,7 +172,6 @@
 		msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication Failed"));
 		g_free(username);
 		g_free(password);
-		purple_ssl_close(gsc);
 		msn_nexus_destroy(nexus);
 		session->nexus = NULL;
 		return FALSE;
@@ -314,151 +213,10 @@
 #endif
 	g_free(fs);
 
-	soapconn->login_path = g_strdup(TWN_POST_URL);
-	request_str = g_strdup_printf(
-					"POST %s HTTP/1.1\r\n"
-					"Accept: text/*\r\n"
-					"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
-					"Host: %s\r\n"
-					"Content-Length: %" G_GSIZE_FORMAT "\r\n"
-					"Connection: Keep-Alive\r\n"
-					"Cache-Control: no-cache\r\n\r\n"
-					"%s",
-					soapconn->login_path, soapconn->login_host, strlen(tail),
-					tail);
-
-#ifdef MSN_SOAP_DEBUG	
-	purple_debug_misc("MSN Nexus", "TWN Sending:\n%s\n", request_str);
-#endif
-	g_free(tail);
-	g_free(username);
-	g_free(password);
-
-	/*prepare to send the SOAP request*/
-	msn_soap_write(soapconn, request_str, nexus_login_written_cb);
+	soap = msn_soap_message_new(NULL, xmlnode_from_str(tail, -1));
+	msn_soap_message_send(nexus->session, soap, MSN_TWN_SERVER, TWN_POST_URL,
+		nexus_got_response_cb, nexus);
 
 	return TRUE;
 }
 
-#if 0 /* khc */
-static void
-nexus_connect_written_cb(gpointer data, gint source, PurpleInputCondition cond)
-{
-	MsnNexus *nexus = data;
-	int len;
-
-	char *da_login;
-	char *base, *c;
-
-	if (nexus->input_handler == 0)
-		/* TODO: Use purple_ssl_input_add()? */
-		nexus->input_handler = purple_input_add(nexus->gsc->fd,
-			PURPLE_INPUT_READ, nexus_connect_written_cb, nexus);
-
-
-	/* Get the PassportURLs line. */
-	len = msn_ssl_read(nexus);
-
-	if (len < 0 && errno == EAGAIN)
-		return;
-	else if (len < 0) {
-		purple_input_remove(nexus->input_handler);
-		nexus->input_handler = 0;
-		g_free(nexus->read_buf);
-		nexus->read_buf = NULL;
-		nexus->read_len = 0;
-		/* TODO: error handling */
-		return;
-	}
-
-	if (g_strstr_len(nexus->read_buf, nexus->read_len,
-			"\r\n\r\n") == NULL)
-		return;
-
-	purple_input_remove(nexus->input_handler);
-	nexus->input_handler = 0;
-
-	base = strstr(nexus->read_buf, "PassportURLs");
-
-	if (base == NULL)
-	{
-		g_free(nexus->read_buf);
-		nexus->read_buf = NULL;
-		nexus->read_len = 0;
-		return;
-	}
-
-	if ((da_login = strstr(base, "DALogin=")) != NULL)
-	{
-		/* skip over "DALogin=" */
-		da_login += 8;
-
-		if ((c = strchr(da_login, ',')) != NULL)
-			*c = '\0';
-
-		if ((c = strchr(da_login, '/')) != NULL)
-		{
-			nexus->login_path = g_strdup(c);
-			*c = '\0';
-		}
-
-		nexus->login_host = g_strdup(da_login);
-	}
-
-	g_free(nexus->read_buf);
-	nexus->read_buf = NULL;
-	nexus->read_len = 0;
-
-	purple_ssl_close(nexus->gsc);
-
-	/* Now begin the connection to the login server. */
-	nexus->gsc = purple_ssl_connect(nexus->session->account,
-			nexus->login_host, PURPLE_SSL_DEFAULT_PORT,
-			login_connect_cb, login_error_cb, nexus);
-}
-
-
-#endif
-
-/**************************************************************************
- * Connect
- **************************************************************************/
-
-#if 0 /* khc */
-static void
-nexus_connect_cb(gpointer data, PurpleSslConnection *gsc,
-				 PurpleInputCondition cond)
-{
-	MsnNexus *nexus;
-	MsnSession *session;
-
-	nexus = data;
-	g_return_if_fail(nexus != NULL);
-
-	session = nexus->session;
-	g_return_if_fail(session != NULL);
-
-	msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH);
-
-	nexus->write_buf = g_strdup("GET /rdr/pprdr.asp\r\n\r\n");
-	nexus->written_len = 0;
-
-	nexus->read_len = 0;
-
-	nexus->written_cb = nexus_connect_written_cb;
-
-	nexus->input_handler = purple_input_add(gsc->fd, PURPLE_INPUT_WRITE,
-		nexus_write_cb, nexus);
-
-	nexus_write_cb(nexus, gsc->fd, PURPLE_INPUT_WRITE);
-}
-
-#endif
-
-void
-msn_nexus_connect(MsnNexus *nexus)
-{
-	/*  Authenticate via Windows Live ID. */
-	msn_soap_init(nexus->soapconn, MSN_TWN_SERVER, TRUE, nexus_login_connect_cb, nexus_login_error_cb);
-	msn_soap_connect(nexus->soapconn);
-}
--- a/libpurple/protocols/msn/nexus.h	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/nexus.h	Wed Oct 24 02:48:32 2007 +0000
@@ -139,7 +139,6 @@
 struct _MsnNexus
 {
 	MsnSession *session;
-	MsnSoapConn *soapconn;
 	char * challenge_data_str;
 	GHashTable *challenge_data;
 };
--- a/libpurple/protocols/msn/notification.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/notification.c	Wed Oct 24 02:48:32 2007 +0000
@@ -1790,9 +1790,7 @@
 		return;
 
 	/*new a oim session*/
-	/* There are several things that call this */
-	if (session->oim == NULL)
-		session->oim = msn_oim_new(session);
+//	session->oim = msn_oim_new(session);
 //	msn_oim_connect(session->oim);
 
 	table = msn_message_get_hashtable_from_body(msg);
--- a/libpurple/protocols/msn/oim.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/oim.c	Wed Oct 24 02:48:32 2007 +0000
@@ -24,24 +24,31 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "msn.h"
-#include "soap.h"
+#include "soap2.h"
 #include "oim.h"
 #include "msnutils.h"
 
+typedef struct _MsnOimSendReq {
+	char *from_member;
+	char *friendname;
+	char *to_member;
+	char *oim_msg;
+} MsnOimSendReq;
+
+typedef struct {
+	MsnOim *oim;
+	char *msg_id;
+} MsnOimRecvData;
+
 /*Local Function Prototype*/
-static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid);
+static void msn_oim_post_single_get_msg(MsnOim *oim, char *msgid);
 static MsnOimSendReq *msn_oim_new_send_req(const char *from_member,
-					   const char *friendname,
-					   const char* to_member,
-					   gint send_seq,
-					   const char *msg);
-static void msn_oim_retrieve_connect_init(MsnSoapConn *soapconn);
-static void msn_oim_send_connect_init(MsnSoapConn *soapconn);
+										   const char *friendname,
+										   const char* to_member,
+										   const char *msg);
 static void msn_oim_free_send_req(MsnOimSendReq *req);
-static void msn_oim_report_to_user(MsnOim *oim, const char *msg_str);
-static void msn_oim_get_process(MsnOim *oim, const char *oim_msg);
-static gchar *msn_oim_msg_to_str(MsnOim *oim, const char *body);
-static void msn_oim_send_process(MsnOim *oim, const char *body, int len);
+static void msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str);
+static char *msn_oim_msg_to_str(MsnOim *oim, const char *body);
 
 /*new a OIM object*/
 MsnOim *
@@ -51,10 +58,7 @@
 
 	oim = g_new0(MsnOim, 1);
 	oim->session = session;
-	oim->retrieveconn = msn_soap_new(session, oim, TRUE);
-	
-	oim->oim_list = NULL;
-	oim->sendconn = msn_soap_new(session, oim, TRUE);
+	oim->oim_list	= NULL;
 	oim->run_id = rand_guid();
 	oim->challenge = NULL;
 	oim->send_queue = g_queue_new();
@@ -69,8 +73,6 @@
 	MsnOimSendReq *request;
 	
 	purple_debug_info("OIM","destroy the OIM \n");
-	msn_soap_destroy(oim->retrieveconn);
-	msn_soap_destroy(oim->sendconn);
 	g_free(oim->run_id);
 	g_free(oim->challenge);
 	
@@ -84,8 +86,7 @@
 
 static MsnOimSendReq *
 msn_oim_new_send_req(const char *from_member, const char*friendname,
-					 const char* to_member, gint send_seq,
-					 const char *msg)
+	const char* to_member, const char *msg)
 {
 	MsnOimSendReq *request;
 	
@@ -93,7 +94,6 @@
 	request->from_member	=g_strdup(from_member);
 	request->friendname		= g_strdup(friendname);
 	request->to_member		= g_strdup(to_member);
-	request->send_seq		= send_seq;
 	request->oim_msg		= g_strdup(msg);
 	return request;
 }
@@ -130,135 +130,56 @@
 	return oim_body;
 }
 
-/*oim SOAP server login error*/
-static void
-msn_oim_send_error_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc, PurpleSslErrorType error)
-{
-	MsnSession *session;
-
-	session = soapconn->session;
-	g_return_if_fail(session != NULL);
-
-	msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
-}
-
-/*msn oim SOAP server connect process*/
-static gboolean
-msn_oim_send_connect_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc)
-{
-	MsnSession * session;
-	MsnOim *oim;
-
-	oim = soapconn->parent;
-	g_return_val_if_fail(oim != NULL, TRUE);
-
-	session = oim->session;
-	g_return_val_if_fail(session != NULL, FALSE);
-
-	return TRUE;
-}
-
 /*
  * Process the send return SOAP string
  * If got SOAP Fault,get the lock key,and resend it.
  */
 static void
-msn_oim_send_process(MsnOim *oim, const char *body, int len)
+msn_oim_send_read_cb(MsnSoapMessage *request, MsnSoapMessage *response,
+	gpointer data)
 {
-	xmlnode *responseNode, *bodyNode;
-	xmlnode *faultNode = NULL, *faultCodeNode, *faultstringNode;
-	xmlnode *detailNode, *challengeNode;
-	char *fault_code, *fault_text;
-
-	responseNode = xmlnode_from_str(body,len);
+	MsnOim *oim = data;
+	xmlnode	*faultNode, *challengeNode;
+	MsnOimSendReq *msg = g_queue_pop_head(oim->send_queue);
 
-	g_return_if_fail(responseNode != NULL);
+	g_return_if_fail(msg != NULL);
 
-	if ((bodyNode = xmlnode_get_child(responseNode, "Body")))
-		faultNode = xmlnode_get_child(bodyNode, "Fault");
-
-	if (faultNode == NULL) {
-		/*Send OK! return*/
-		MsnOimSendReq *request;
+	if (response == NULL) {
+		purple_debug_info("MSNP14", "cannot send OIM: %s\n", msg->oim_msg);
+	} else {
+		faultNode = msn_soap_xml_get(response->xml, "Body/Fault");
 
-		xmlnode_free(responseNode);
-		request = g_queue_pop_head(oim->send_queue);
-		msn_oim_free_send_req(request);
-		/*send next buffered Offline Message*/
-		msn_soap_post(oim->sendconn, NULL);
+		if (faultNode == NULL) {
+			/*Send OK! return*/
+			purple_debug_info("MSNP14", "sent OIM: %s\n", msg->oim_msg);
+		} else {
+			/*get the challenge,and repost it*/
+			challengeNode = msn_soap_xml_get(faultNode,
+				"detail/LockKeyChallenge");
 
-		return;
-	}
+			if (challengeNode == NULL) {
+				purple_debug_info("MSNP14", "can't find lock key for OIM: %s\n", msg);
+			} else {
+				char buf[33];
 
-	/*get the challenge,and repost it*/
-	if (faultNode)
-		faultCodeNode = xmlnode_get_child(faultNode, "faultcode");
+				char *challenge = xmlnode_get_data(challengeNode);
+				msn_handle_chl(challenge, buf);
+
+				g_free(oim->challenge);
+				oim->challenge = g_strndup(buf, sizeof(buf));
+				g_free(challenge);
+				purple_debug_info("MSNP14","lockkey:{%s}\n",oim->challenge);
 
-	if(faultCodeNode == NULL){
-		purple_debug_info("MSN OIM", "No faultcode for failed Offline Message.\n");
-		xmlnode_free(responseNode);
-		return;
+				/*repost the send*/
+				purple_debug_info("MSNP14","resending OIM: %s\n", msg->oim_msg);
+				g_queue_push_head(oim->send_queue, msg);
+				msn_oim_send_msg(oim);
+				return;
+			}
+		}
 	}
 
-	fault_code = xmlnode_get_data(faultCodeNode);
-#if 0
-	if(!strcmp(fault_code,"q0:AuthenticationFailed")){
-		/*other Fault Reason?*/
-		goto oim_send_process_fail;
-	}
-#endif
-
-	faultstringNode = xmlnode_get_child(faultNode, "faultstring");
-	fault_text = xmlnode_get_data(faultstringNode);
-	purple_debug_info("MSN OIM", "Error sending Offline Message: %s (%s)\n",
-		fault_text ? fault_text : "(null)", fault_code ? fault_code : "(null)");
-
-	/* lock key fault reason,
-	 * compute the challenge and resend it
-	 */
-	if ((detailNode = xmlnode_get_child(faultNode, "detail"))
-			&& (challengeNode = xmlnode_get_child(detailNode, "LockKeyChallenge"))) {
-		g_free(oim->challenge);
-		oim->challenge = xmlnode_get_data(challengeNode);
-
-		purple_debug_info("MSN OIM", "Retrying Offline IM with lockkey:{%s}\n",
-			oim->challenge ? oim->challenge : "(null)");
-
-		/*repost the send*/
-		msn_oim_send_msg(oim);
-
-		/* XXX: This needs to give up eventually (1 retry, maybe?) */
-	}
-
-	g_free(fault_text);
-	g_free(fault_code);
-	xmlnode_free(responseNode);
-}
-
-static gboolean
-msn_oim_send_read_cb(MsnSoapConn *soapconn)
-{
-	MsnSession *session = soapconn->session;
-	MsnOim * oim;
-
-	if (soapconn->body == NULL)
-		return TRUE;
-
-	g_return_val_if_fail(session != NULL, FALSE);
-	oim = soapconn->session->oim;
-	g_return_val_if_fail(oim != NULL, TRUE);
-
-	purple_debug_info("MSN OIM","read buffer:{%s}\n", soapconn->body);
-	msn_oim_send_process(oim,soapconn->body,soapconn->body_len);
-
-	return TRUE;
-}
-
-static void
-msn_oim_send_written_cb(MsnSoapConn *soapconn)
-{
-	soapconn->read_cb = msn_oim_send_read_cb;
-//	msn_soap_read_cb(data,source,cond);
+	msn_oim_free_send_req(msg);
 }
 
 void
@@ -266,45 +187,36 @@
 						   const char* friendname, const char *tomember,
 						   const char * msg)
 {
-	MsnOimSendReq *request;
-
 	g_return_if_fail(oim != NULL);
 
-	request = msn_oim_new_send_req(membername,friendname,tomember,oim->send_seq,msg);
-	g_queue_push_tail(oim->send_queue,request);
+	g_queue_push_tail(oim->send_queue,
+		msn_oim_new_send_req(membername, friendname, tomember, msg));
 }
 
 /*post send single message request to oim server*/
 void 
 msn_oim_send_msg(MsnOim *oim)
 {
-	MsnSoapReq *soap_request;
 	MsnOimSendReq *oim_request;
 	char *soap_body,*mspauth;
-	gchar *msg_body;
-	char buf[33];
+	char *msg_body;
 
 	g_return_if_fail(oim != NULL);
-	oim_request = g_queue_pop_head(oim->send_queue);
+	oim_request = g_queue_peek_head(oim->send_queue);
 	g_return_if_fail(oim_request != NULL);
 
-	purple_debug_info("MSN OIM","send single OIM Message\n");
+	purple_debug_info("MSNP14","sending OIM: %s\n", oim_request->oim_msg);
 	mspauth = g_strdup_printf("t=%s&amp;p=%s",
 		oim->session->passport_info.t,
 		oim->session->passport_info.p
 		);
-	g_queue_push_head(oim->send_queue,oim_request);
 
 	/* if we got the challenge lock key, we compute it
 	 * else we go for the SOAP fault and resend it.
 	 */
-	if(oim->challenge != NULL){
-		msn_handle_chl(oim->challenge, buf);
-	}else{
-		purple_debug_info("MSN OIM","no lock key challenge,wait for SOAP Fault and Resend\n");
-		buf[0]='\0';
+	if(oim->challenge == NULL){
+		purple_debug_info("MSNP14","no lock key challenge,wait for SOAP Fault and Resend\n");
 	}
-	purple_debug_info("MSN OIM","get the lock key challenge {%s}\n",buf);
 
 	msg_body = msn_oim_msg_to_str(oim, oim_request->oim_msg);
 	soap_body = g_strdup_printf(MSN_OIM_SEND_TEMPLATE,
@@ -313,117 +225,71 @@
 					oim_request->to_member,
 					mspauth,
 					MSNP13_WLM_PRODUCT_ID,
-					buf,
-					oim_request->send_seq,
+					oim->challenge ? oim->challenge : "",
+					oim->send_seq,
 					msg_body);
 
-	soap_request = msn_soap_request_new(MSN_OIM_SEND_HOST,
-					MSN_OIM_SEND_URL,
-					MSN_OIM_SEND_SOAP_ACTION,
-					soap_body,
-					NULL,
-					msn_oim_send_read_cb,
-					msn_oim_send_written_cb,
-					msn_oim_send_connect_init);
+	msn_soap_message_send(oim->session,
+		msn_soap_message_new(MSN_OIM_SEND_SOAP_ACTION,
+			xmlnode_from_str(soap_body, -1)),
+		MSN_OIM_SEND_HOST, MSN_OIM_SEND_URL, msn_oim_send_read_cb, oim);
+
+	/*increase the offline Sequence control*/
+	if (oim->challenge != NULL) {
+		oim->send_seq++;
+	}
+
 	g_free(mspauth);
 	g_free(msg_body);
 	g_free(soap_body);
-
-	/*increase the offline Sequence control*/
-	if(oim->challenge != NULL){
-		oim->send_seq++;
-	}
-	msn_soap_post(oim->sendconn,soap_request);
 }
 
 /****************************************
  * OIM delete SOAP request
  * **************************************/
-static gboolean
-msn_oim_delete_read_cb(MsnSoapConn *soapconn)
+static void
+msn_oim_delete_read_cb(MsnSoapMessage *request, MsnSoapMessage *response,
+	gpointer data)
 {
-	if (soapconn->body == NULL)
-		return TRUE;
-	purple_debug_info("MSN OIM","OIM delete read buffer:{%s}\n",soapconn->body);
+	MsnOimRecvData *rdata = data;
 
-	msn_soap_free_read_buf(soapconn);
-	/*get next single Offline Message*/
-//	msn_soap_post(soapconn,NULL);	/* we already do this in soap.c */
-	return TRUE;
-}
+	if (response && msn_soap_xml_get(response->xml, "Body/Fault") == NULL) {
+		purple_debug_info("msnoim", "delete OIM success\n");
+		rdata->oim->oim_list = g_list_remove(rdata->oim->oim_list,
+			rdata->msg_id);
+		g_free(rdata->msg_id);
+	} else {
+		purple_debug_info("msnoim", "delete OIM failed\n");
+	}
 
-static void
-msn_oim_delete_written_cb(MsnSoapConn *soapconn)
-{
-	soapconn->read_cb = msn_oim_delete_read_cb;
+	g_free(rdata);
 }
 
 /*Post to get the Offline Instant Message*/
 static void
-msn_oim_post_delete_msg(MsnOim *oim,const char *msgid)
+msn_oim_post_delete_msg(MsnOimRecvData *rdata)
 {
-	MsnSoapReq *soap_request;
-	gchar *soap_body;
-	const char *t,*p;
+	MsnOim *oim = rdata->oim;
+	char *msgid = rdata->msg_id;
+	char *soap_body;
 
-	g_return_if_fail(oim != NULL);
-	g_return_if_fail(msgid != NULL);
-
-	purple_debug_info("MSN OIM","Delete single OIM Message {%s}\n",msgid);
-	t = oim->session->passport_info.t;
-	p = oim->session->passport_info.p;
+	purple_debug_info("MSNP14","Delete single OIM Message {%s}\n",msgid);
 
 	soap_body = g_strdup_printf(MSN_OIM_DEL_TEMPLATE,
-					t,
-					p,
-					msgid
-					);
-	soap_request = msn_soap_request_new(MSN_OIM_RETRIEVE_HOST,
-					MSN_OIM_RETRIEVE_URL,
-					MSN_OIM_DEL_SOAP_ACTION,
-					soap_body,
-					NULL,
-					msn_oim_delete_read_cb,
-					msn_oim_delete_written_cb,
-					msn_oim_retrieve_connect_init);
+		oim->session->passport_info.t, oim->session->passport_info.p, msgid);
+
+	msn_soap_message_send(oim->session,
+		msn_soap_message_new(MSN_OIM_DEL_SOAP_ACTION,
+			xmlnode_from_str(soap_body, -1)),
+		MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
+		msn_oim_delete_read_cb, rdata);
+
 	g_free(soap_body);
-	msn_soap_post(oim->retrieveconn,soap_request);
 }
 
 /****************************************
  * OIM get SOAP request
  * **************************************/
-/*oim SOAP server login error*/
-static void
-msn_oim_get_error_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc, PurpleSslErrorType error)
-{
-	MsnSession *session;
-
-	session = soapconn->session;
-	g_return_if_fail(session != NULL);
-	msn_soap_clean_unhandled_requests(soapconn);
-
-//	msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
-}
-
-/*msn oim SOAP server connect process*/
-static gboolean
-msn_oim_get_connect_cb(MsnSoapConn *soapconn, PurpleSslConnection *gsc)
-{
-	MsnSession * session;
-	MsnOim *oim;
-
-	oim = soapconn->parent;
-	g_return_val_if_fail(oim != NULL, TRUE);
-
-	session = oim->session;
-	g_return_val_if_fail(session != NULL, FALSE);
-
-	purple_debug_info("MSN OIM","Connected and ready to get OIM!\n");
-
-	return TRUE;
-}
-
 /* like purple_str_to_time, but different. The format of the timestamp
  * is like this: 5 Sep 2007 21:42:12 -0700 */
 static time_t
@@ -435,9 +301,13 @@
 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
 	};
+	time_t tval = 0;
 	struct tm t;
 	memset(&t, 0, sizeof(t));
 
+	time(&tval);
+	localtime_r(&tval, &t);
+
 	if (sscanf(timestamp, "%02d %03s %04d %02d:%02d:%02d %05s",
 					&t.tm_mday, month_str, &t.tm_year,
 					&t.tm_hour, &t.tm_min, &t.tm_sec, tz_str) == 7) {
@@ -466,14 +336,13 @@
 					tzoff *= -1;
 
 				t.tm_year -= 1900;
-				t.tm_isdst = 0;
 
 #ifdef _WIN32
 				if ((sys_tzoff = wpurple_get_tz_offset()) != -1)
 					tzoff += sys_tzoff;
 #else
 #ifdef HAVE_TM_GMTOFF
-				tzoff += t.tm_gmtoff;
+				tzoff -= t.tm_gmtoff;
 #else
 #	ifdef HAVE_TIMEZONE
 				tzset();    /* making sure */
@@ -487,13 +356,13 @@
 		}
 	}
 
-	purple_debug_info("MSN OIM:OIM", "Can't parse timestamp %s\n", timestamp);
-	return time(NULL);
+	purple_debug_info("MSNP14:OIM", "Can't parse timestamp %s\n", timestamp);
+	return tval;
 }
 
 /*Post the Offline Instant Message to User Conversation*/
 static void
-msn_oim_report_to_user(MsnOim *oim, const char *msg_str)
+msn_oim_report_to_user(MsnOimRecvData *rdata, const char *msg_str)
 {
 	MsnMessage *message;
 	char *date,*from,*decode_msg;
@@ -502,14 +371,13 @@
 	char *start,*end;
 	int has_nick = 0;
 	char *passport_str, *passport;
-	char *msg_id;
 	time_t stamp;
 
 	message = msn_message_new(MSN_MSG_UNKNOWN);
 
 	msn_message_parse_payload(message, msg_str, strlen(msg_str),
 							  MSG_OIM_LINE_DEM, MSG_OIM_BODY_DEM);
-	purple_debug_info("MSN OIM","oim body:{%s}\n",message->body);
+	purple_debug_info("MSNP14","oim body:{%s}\n",message->body);
 	decode_msg = (char *)purple_base64_decode(message->body,&body_len);
 	date =	(char *)g_hash_table_lookup(message->attr_table, "Date");
 	from =	(char *)g_hash_table_lookup(message->attr_table, "From");
@@ -519,12 +387,12 @@
 	if(has_nick){
 		tokens = g_strsplit(from , " " , 2);
 		passport_str = g_strdup(tokens[1]);
-		purple_debug_info("MSN OIM","oim Date:{%s},nickname:{%s},tokens[1]:{%s} passport{%s}\n",
+		purple_debug_info("MSNP14","oim Date:{%s},nickname:{%s},tokens[1]:{%s} passport{%s}\n",
 							date,tokens[0],tokens[1],passport_str);
 		g_strfreev(tokens);
 	}else{
 		passport_str = g_strdup(from);
-		purple_debug_info("MSN OIM","oim Date:{%s},passport{%s}\n",
+		purple_debug_info("MSNP14","oim Date:{%s},passport{%s}\n",
 					date,passport_str);
 	}
 	start = strstr(passport_str,"<");
@@ -536,66 +404,43 @@
 
 	stamp = msn_oim_parse_timestamp(date);
 
-	serv_got_im(oim->session->account->gc, passport, decode_msg, 0, stamp);
+	serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0,
+		stamp);
 
 	/*Now get the oim message ID from the oim_list.
 	 * and append to read list to prepare for deleting the Offline Message when sign out
 	 */
-	if(oim->oim_list != NULL){
-		msg_id = oim->oim_list->data;
-		msn_oim_post_delete_msg(oim,msg_id);
-		oim->oim_list = g_list_remove(oim->oim_list, oim->oim_list->data);
-		g_free(msg_id);
-	}
+	msn_oim_post_delete_msg(rdata);
 
 	g_free(passport);
+	g_free(decode_msg);
 }
 
 /* Parse the XML data,
  * prepare to report the OIM to user
  */
 static void
-msn_oim_get_process(MsnOim *oim, const char *oim_msg)
-{
-	xmlnode *oim_node,*bodyNode,*responseNode,*msgNode;
-	char *msg_str;
-
-	oim_node = xmlnode_from_str(oim_msg, strlen(oim_msg));
-	bodyNode = xmlnode_get_child(oim_node,"Body");
-	responseNode = xmlnode_get_child(bodyNode,"GetMessageResponse");
-	msgNode = xmlnode_get_child(responseNode,"GetMessageResult");
-	msg_str = xmlnode_get_data(msgNode);
-	purple_debug_info("OIM","msg:{%s}\n",msg_str);
-	msn_oim_report_to_user(oim,msg_str);
-
-	g_free(msg_str);
-	xmlnode_free(oim_node);
-}
-
-static gboolean
-msn_oim_get_read_cb(MsnSoapConn *soapconn)
+msn_oim_get_read_cb(MsnSoapMessage *request, MsnSoapMessage *response,
+	gpointer data)
 {
-	MsnOim * oim = soapconn->session->oim;
-
-	if (soapconn->body == NULL)
-		return TRUE;
+	MsnOimRecvData *rdata = data;
 
-	purple_debug_info("MSN OIM","OIM get read buffer:{%s}\n",soapconn->body);
-
-	/*we need to process the read message!*/
-	msn_oim_get_process(oim,soapconn->body);
-	msn_soap_free_read_buf(soapconn);
+	if (response != NULL) {
+		xmlnode *msg_node = msn_soap_xml_get(response->xml,
+			"Body/GetMessageResponse/GetMessageResult");
 
-	/*get next single Offline Message*/
-//	msn_soap_post(soapconn,NULL); /* we already do this in soap.c */
-	return TRUE;
-}
-
-static void
-msn_oim_get_written_cb(MsnSoapConn *soapconn)
-{
-	soapconn->read_cb = msn_oim_get_read_cb;
-//	msn_soap_read_cb(data,source,cond);
+		if (msg_node) {
+			char *msg_str = xmlnode_get_data(msg_node);
+			msn_oim_report_to_user(rdata, msg_str);
+			g_free(msg_str);
+		} else {
+			char *str = xmlnode_to_str(response->xml, NULL);
+			purple_debug_info("msnoim", "Unknown response: %s\n", str);
+			g_free(str);
+		}
+	} else {
+		purple_debug_info("msnoim", "Failed to get OIM\n");
+	}
 }
 
 /* parse the oim XML data 
@@ -604,116 +449,88 @@
 void
 msn_parse_oim_msg(MsnOim *oim,const char *xmlmsg)
 {
-	xmlnode *node, *mNode,*ENode,*INode,*rtNode,*nNode;
-	char *passport,*msgid,*nickname, *unread, *rTime = NULL;
+	xmlnode *node, *mNode;
+	xmlnode *iu_node;
 	MsnSession *session = oim->session;
 
-	purple_debug_info("MSN OIM:OIM", "%s", xmlmsg);
+	purple_debug_info("MSNP14:OIM", "%s", xmlmsg);
 
-	node = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
-	if (!node || !node->name || strcmp(node->name, "MD") != 0) {
-		if (node)
-			xmlnode_free(node);
+	node = xmlnode_from_str(xmlmsg, -1);
+	if (strcmp(node->name, "MD") != 0) {
+		purple_debug_info("msnoim", "WTF is this? %s\n", xmlmsg);
+		xmlnode_free(node);
 		return;
 	}
 
-	ENode = xmlnode_get_child(node, "E");
-	INode = xmlnode_get_child(ENode, "IU");
-	unread = xmlnode_get_data(INode);
-
-	if (unread != NULL && purple_account_get_check_mail(session->account))
-	{
-		int count = atoi(unread);
+	iu_node = msn_soap_xml_get(node, "E/IU");
 
-		if (count > 0)
-		{
-			const char *passport;
-			const char *url;
+	if (iu_node != NULL && purple_account_get_check_mail(session->account))
+	{
+		char *unread = xmlnode_get_data(iu_node);
+		const char *passport = msn_user_get_passport(session->user);
+		const char *url = session->passport_info.file;
 
-			passport = msn_user_get_passport(session->user);
-			url = session->passport_info.file;
-
-			purple_notify_emails(session->account->gc, atoi(unread), FALSE, NULL, NULL,
-					&passport, &url, NULL, NULL);
-		}
+		/* XXX/khc: pretty sure this is wrong */
+		purple_notify_emails(session->account->gc, atoi(unread), FALSE, NULL,
+			NULL, &passport, &url, NULL, NULL);
+		g_free(unread);
 	}
 
 	for(mNode = xmlnode_get_child(node, "M"); mNode;
 					mNode = xmlnode_get_next_twin(mNode)){
-		/*email Node*/
-		ENode = xmlnode_get_child(mNode,"E");
-		passport = xmlnode_get_data(ENode);
-		/*Index */
-		INode = xmlnode_get_child(mNode,"I");
-		msgid = xmlnode_get_data(INode);
-		/*Nickname*/
-		nNode = xmlnode_get_child(mNode,"N");
-		nickname = xmlnode_get_data(nNode);
-		/*receive time*/
-		rtNode = xmlnode_get_child(mNode,"RT");
-		if(rtNode != NULL)
-			rTime = xmlnode_get_data(rtNode);
-/*		purple_debug_info("MSN OIM","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */
+		char *passport, *msgid, *nickname, *rtime = NULL;
+		xmlnode *e_node, *i_node, *n_node, *rt_node;
+
+		e_node = xmlnode_get_child(mNode, "E");
+		passport = xmlnode_get_data(e_node);
+
+		i_node = xmlnode_get_child(mNode, "I");
+		msgid = xmlnode_get_data(i_node);
+
+		n_node = xmlnode_get_child(mNode, "N");
+		nickname = xmlnode_get_data(n_node);
 
-		oim->oim_list = g_list_append(oim->oim_list,strdup(msgid));
-		msn_oim_post_single_get_msg(oim,msgid);
+		rt_node = xmlnode_get_child(mNode, "RT");
+		if (rt_node != NULL) {
+			rtime = xmlnode_get_data(rt_node);
+		}
+/*		purple_debug_info("msnoim","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */
+
+		if (!g_list_find_custom(oim->oim_list, msgid, (GCompareFunc)strcmp)) {
+			oim->oim_list = g_list_append(oim->oim_list, msgid);
+			msn_oim_post_single_get_msg(oim, msgid);
+			msgid = NULL;
+		}
+
 		g_free(passport);
 		g_free(msgid);
-		g_free(rTime);
-		rTime = NULL;
+		g_free(rtime);
 		g_free(nickname);
 	}
-	g_free(unread);
+
 	xmlnode_free(node);
 }
 
 /*Post to get the Offline Instant Message*/
 static void
-msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid)
+msn_oim_post_single_get_msg(MsnOim *oim, char *msgid)
 {
-	MsnSoapReq *soap_request;
-	gchar *soap_body;
-	const char *t,*p;
+	char *soap_body;
+	MsnOimRecvData *data = g_new0(MsnOimRecvData, 1);
 
-	purple_debug_info("MSN OIM","Get single OIM Message\n");
-	t = oim->session->passport_info.t;
-	p = oim->session->passport_info.p;
+	purple_debug_info("MSNP14","Get single OIM Message\n");
+
+	data->oim = oim;
+	data->msg_id = msgid;
 
 	soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE,
-					t,
-					p,
-					msgid
-					);
-	soap_request = msn_soap_request_new(MSN_OIM_RETRIEVE_HOST,
-					MSN_OIM_RETRIEVE_URL,
-					MSN_OIM_GET_SOAP_ACTION,
-					soap_body,
-					NULL,
-					msn_oim_get_read_cb,
-					msn_oim_get_written_cb,
-					msn_oim_retrieve_connect_init);
-	g_free(soap_body);
-	msn_soap_post(oim->retrieveconn,soap_request);
-}
+		oim->session->passport_info.t, oim->session->passport_info.p, msgid);
 
-/*msn oim retrieve server connect init */
-static void
-msn_oim_retrieve_connect_init(MsnSoapConn *soapconn)
-{
-	purple_debug_info("MSN OIM","Initializing OIM retrieve connection\n");
-	msn_soap_init(soapconn, MSN_OIM_RETRIEVE_HOST, TRUE,
-		      msn_oim_get_connect_cb,
-		      msn_oim_get_error_cb);
-}
+	msn_soap_message_send(oim->session,
+		msn_soap_message_new(MSN_OIM_GET_SOAP_ACTION,
+			xmlnode_from_str(soap_body, -1)),
+		MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
+		msn_oim_get_read_cb, data);
 
-/*Msn OIM Send Server Connect Init Function*/
-static void
-msn_oim_send_connect_init(MsnSoapConn *sendconn)
-{
-	purple_debug_info("MSN OIM","Initializing OIM send connection\n");
-	msn_soap_init(sendconn, MSN_OIM_SEND_HOST, TRUE,
-		      msn_oim_send_connect_cb,
-		      msn_oim_send_error_cb);
+	g_free(soap_body);
 }
-
-/* EOF oim.c*/
--- a/libpurple/protocols/msn/oim.h	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/oim.h	Wed Oct 24 02:48:32 2007 +0000
@@ -95,17 +95,6 @@
 	"</soap:Body>"\
 "</soap:Envelope>"
 
-typedef struct _MsnOimSendReq MsnOimSendReq;
-
-struct _MsnOimSendReq
-{
-	char *from_member;
-	char *friendname;
-	char *to_member;
-	char *oim_msg;
-	gint send_seq;
-};
-
 typedef struct _MsnOim MsnOim;
 
 struct _MsnOim
@@ -127,7 +116,6 @@
  * **************************************************/
 MsnOim * msn_oim_new(MsnSession *session);
 void msn_oim_destroy(MsnOim *oim);
-void msn_oim_connect(MsnOim *oim);
 
 void msn_parse_oim_msg(MsnOim *oim,const char *xmlmsg);
 
@@ -138,11 +126,5 @@
 
 void msn_oim_send_msg(MsnOim *oim);
 
-/*get the OIM message*/
-void msn_oim_get_msg(MsnOim *oim);
-
-/*report the oim message to the conversation*/
-void msn_oim_report_user(MsnOim *oim,const char *passport,char *msg);
-
 #endif/* _MSN_OIM_H_*/
 /*endof oim.h*/
--- a/libpurple/protocols/msn/session.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/session.c	Wed Oct 24 02:48:32 2007 +0000
@@ -24,6 +24,7 @@
 #include "msn.h"
 #include "session.h"
 #include "notification.h"
+#include "oim.h"
 
 #include "dialog.h"
 
@@ -42,6 +43,7 @@
 
 	session->user = msn_user_new(session->userlist,
 								 purple_account_get_username(account), NULL);
+	session->oim = msn_oim_new(session);
 
 	/*if you want to chat with Yahoo Messenger*/
 	//session->protocol_ver = WLM_YAHOO_PROT_VER;
@@ -99,6 +101,12 @@
 	if (session->user != NULL)
 		msn_user_destroy(session->user);
 
+	if (session->soap_table)
+		g_hash_table_destroy(session->soap_table);
+
+	if (session->soap_cleanup_handle)
+		purple_timeout_remove(session->soap_cleanup_handle);
+
 	g_free(session);
 }
 
--- a/libpurple/protocols/msn/session.h	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/session.h	Wed Oct 24 02:48:32 2007 +0000
@@ -126,6 +126,9 @@
 		char *client_ip;
 		int client_port;
 	} passport_info;
+
+	GHashTable *soap_table;
+	int soap_cleanup_handle;
 };
 
 /**
--- a/libpurple/protocols/msn/soap.c	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/soap.c	Wed Oct 24 02:48:32 2007 +0000
@@ -308,7 +308,7 @@
 }
 
 /*read the whole SOAP server response*/
-void 
+static void 
 msn_soap_read_cb(gpointer data, gint source, PurpleInputCondition cond)
 {
 	MsnSoapConn *soapconn = data;
--- a/libpurple/protocols/msn/soap.h	Tue Oct 23 21:52:55 2007 +0000
+++ b/libpurple/protocols/msn/soap.h	Wed Oct 24 02:48:32 2007 +0000
@@ -154,7 +154,6 @@
 void msn_soap_free_read_buf(MsnSoapConn *soapconn);
 void msn_soap_free_write_buf(MsnSoapConn *soapconn);
 void msn_soap_connect_cb(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond);
-void msn_soap_read_cb(gpointer data, gint source, PurpleInputCondition cond);
 
 /*clean the unhandled requests*/
 void msn_soap_clean_unhandled_requests(MsnSoapConn *soapconn);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/msn/soap2.c	Wed Oct 24 02:48:32 2007 +0000
@@ -0,0 +1,666 @@
+/**
+ * @file soap2.c
+ * 	C file for SOAP connection related process
+ *
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "soap2.h"
+
+#include "session.h"
+
+#include "debug.h"
+#include "xmlnode.h"
+
+#include <glib.h>
+#include <error.h>
+
+#define SOAP_TIMEOUT (5 * 60)
+
+typedef struct _MsnSoapRequest {
+	char *path;
+	MsnSoapMessage *message;
+	MsnSoapCallback cb;
+	gpointer cb_data;
+} MsnSoapRequest;
+
+typedef struct _MsnSoapConnection {
+	MsnSession *session;
+	char *host;
+
+	time_t last_used;
+	PurpleSslConnection *ssl;
+	gboolean connected;
+
+	guint event_handle;
+	GString *buf;
+	gsize handled_len;
+	gsize body_len;
+	int response_code;
+	gboolean headers_done;
+	gboolean close_when_done;
+
+	MsnSoapMessage *message;
+
+	GQueue *queue;
+	MsnSoapRequest *current_request;
+} MsnSoapConnection;
+
+static void msn_soap_connection_destroy_foreach_cb(gpointer item, gpointer data);
+static gboolean msn_soap_connection_run(gpointer data);
+
+static MsnSoapConnection *msn_soap_connection_new(MsnSession *session,
+	const char *host);
+static void msn_soap_connection_handle_next(MsnSoapConnection *conn);
+static void msn_soap_connection_destroy(MsnSoapConnection *conn);
+
+static void msn_soap_message_send_internal(MsnSession *session,
+	MsnSoapMessage *message, const char *host, const char *path,
+	MsnSoapCallback cb, gpointer cb_data, gboolean first);
+
+static void msn_soap_request_destroy(MsnSoapRequest *req);
+static void msn_soap_connection_sanitize(MsnSoapConnection *conn, gboolean disconnect);
+
+static gboolean
+msn_soap_cleanup_each(gpointer key, gpointer value, gpointer data)
+{
+	MsnSoapConnection *conn = value;
+	time_t *t = data;
+
+	if ((*t - conn->last_used) > SOAP_TIMEOUT * 2) {
+		purple_debug_info("soap", "cleaning up soap conn %p\n", conn);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gboolean
+msn_soap_cleanup_for_session(gpointer data)
+{
+	MsnSession *sess = data;
+	time_t t = time(NULL);
+
+	purple_debug_info("soap", "session cleanup timeout\n");
+
+	if (sess->soap_table) {
+		g_hash_table_foreach_remove(sess->soap_table, msn_soap_cleanup_each,
+			&t);
+
+		if (g_hash_table_size(sess->soap_table) == 0) {
+			purple_timeout_remove(sess->soap_cleanup_handle);
+			sess->soap_cleanup_handle = 0;
+		}
+	}
+
+	return TRUE;
+}
+
+static MsnSoapConnection *
+msn_soap_get_connection(MsnSession *session, const char *host)
+{
+	MsnSoapConnection *conn = NULL;
+
+	if (session->soap_table) {
+		conn = g_hash_table_lookup(session->soap_table, host);
+	} else {
+		session->soap_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+			NULL, (GDestroyNotify)msn_soap_connection_destroy);
+	}
+
+	if (session->soap_cleanup_handle == 0)
+		session->soap_cleanup_handle = purple_timeout_add(SOAP_TIMEOUT * 1000,
+			msn_soap_cleanup_for_session, session);
+
+	if (conn == NULL) {
+		conn = msn_soap_connection_new(session, host);
+		g_hash_table_insert(session->soap_table, conn->host, conn);
+	}
+
+	conn->last_used = time(NULL);
+
+	return conn;
+}
+
+static MsnSoapConnection *
+msn_soap_connection_new(MsnSession *session, const char *host)
+{
+	MsnSoapConnection *conn = g_new0(MsnSoapConnection, 1);
+	conn->session = session;
+	conn->host = g_strdup(host);
+	conn->queue = g_queue_new();
+	return conn;
+}
+
+static void
+msn_soap_connected_cb(gpointer data, PurpleSslConnection *ssl,
+		PurpleInputCondition cond)
+{
+	MsnSoapConnection *conn = data;
+
+	conn->connected = TRUE;
+
+	if (conn->event_handle == 0)
+		conn->event_handle = g_idle_add(msn_soap_connection_run, conn);
+}
+
+static void
+msn_soap_error_cb(PurpleSslConnection *ssl, PurpleSslErrorType error,
+		gpointer data)
+{
+	MsnSoapConnection *conn = data;
+
+	g_hash_table_remove(conn->session->soap_table, conn->host);
+}
+
+static gboolean
+msn_soap_handle_redirect(MsnSoapConnection *conn, const char *url)
+{
+	char *c;
+
+	/* Skip the http:// */
+	if ((c = strchr(url, '/')) != NULL)
+		url += 2;
+
+	if ((c = strchr(url, '/')) != NULL) {
+		char *host, *path;
+
+		host = g_strndup(url, c - url);
+		path = g_strdup(c);
+
+		msn_soap_message_send_internal(conn->session,
+			conn->current_request->message,	host, path,
+			conn->current_request->cb, conn->current_request->cb_data, TRUE);
+
+		msn_soap_request_destroy(conn->current_request);
+		conn->current_request = NULL;
+
+		g_free(host);
+		g_free(path);
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gboolean
+msn_soap_handle_body(MsnSoapConnection *conn, MsnSoapMessage *response)
+{
+	xmlnode *body = xmlnode_get_child(response->xml, "Body");
+
+	if (body) {
+		MsnSoapRequest *request;
+
+		if (strcmp(body->name, "Fault") == 0) {
+			xmlnode *fault = xmlnode_get_child(body, "faultcode");
+
+			if (fault != NULL) {
+				char *faultdata = xmlnode_get_data(fault);
+
+				if (strcmp(faultdata, "psf:Redirect") == 0) {
+					xmlnode *url = xmlnode_get_child(body, "redirectUrl");
+
+					if (url) {
+						char *urldata = xmlnode_get_data(url);
+						msn_soap_handle_redirect(conn, urldata);
+						g_free(urldata);
+					}
+
+					g_free(faultdata);
+					return TRUE;
+				} else if (strcmp(faultdata, "wsse:FailedAuthentication") == 0) {
+					xmlnode *reason = xmlnode_get_child(body, "faultstring");
+					char *reasondata = xmlnode_get_data(reason);
+
+					msn_soap_connection_sanitize(conn, TRUE);
+					msn_session_set_error(conn->session, MSN_ERROR_AUTH,
+						reasondata);
+
+					g_free(reasondata);
+					g_free(faultdata);
+					return FALSE;
+				}
+
+				g_free(faultdata);
+			}
+		}
+
+		request = conn->current_request;
+		conn->current_request = NULL;
+		request->cb(request->message, response,
+			request->cb_data);
+		msn_soap_request_destroy(request);
+	}
+
+	return TRUE;
+}
+
+static void
+msn_soap_read_cb(gpointer data, gint fd, PurpleInputCondition cond)
+{
+    MsnSoapConnection *conn = data;
+	int count;
+	char buf[8192];
+	char *linebreak;
+	char *cursor;
+	gboolean handled = FALSE;
+
+	g_return_if_fail(cond == PURPLE_INPUT_READ);
+
+	count = purple_ssl_read(conn->ssl, buf, sizeof(buf));
+	purple_debug_info("soap", "read %d bytes\n", count);
+	if (count < 0 && errno == EAGAIN)
+		return;
+	else if (count <= 0) {
+		purple_debug_info("soap", "read: %s\n", strerror(errno));
+		purple_ssl_close(conn->ssl);
+		conn->ssl = NULL;
+		msn_soap_connection_handle_next(conn);
+		return;
+	}
+
+	if (conn->message == NULL) {
+		conn->message = msn_soap_message_new(NULL, NULL);
+	}
+
+	if (conn->buf == NULL) {
+		conn->buf = g_string_new_len(buf, count);
+	} else {
+		g_string_append_len(conn->buf, buf, count);
+	}
+
+	purple_debug_info("soap", "current %s\n", conn->buf->str);
+
+	cursor = conn->buf->str + conn->handled_len;
+
+	if (!conn->headers_done) {
+		while ((linebreak = strstr(cursor, "\r\n"))	!= NULL) {
+			conn->handled_len = linebreak - conn->buf->str + 2;
+
+			if (conn->response_code == 0) {
+				if (sscanf(cursor, "HTTP/1.1 %d", &conn->response_code) != 1) {
+					/* something horribly wrong */
+					purple_ssl_close(conn->ssl);
+					conn->ssl = NULL;
+					msn_soap_connection_handle_next(conn);
+					handled = TRUE;
+					break;
+				} else if (conn->response_code == 503) {
+					msn_soap_connection_sanitize(conn, TRUE);
+					msn_session_set_error(conn->session, MSN_ERROR_SERV_UNAVAILABLE, NULL);
+					return;
+				}
+			} else if (cursor == linebreak) {
+				/* blank line */
+				conn->headers_done = TRUE;
+				cursor = conn->buf->str + conn->handled_len;
+				break;
+			} else {
+				char *line = g_strndup(cursor, linebreak - cursor);
+				char *sep = strstr(line, ": ");
+				char *key = line;
+				char *value;
+
+				if (sep == NULL) {
+					purple_debug_info("soap", "ignoring malformed line: %s\n", line);
+					g_free(line);
+					goto loop_end;
+				}
+
+				value = sep + 2;
+				*sep = '\0';
+				msn_soap_message_add_header(conn->message, key, value);
+				purple_debug_info("soap", "header %s: %s\n", key, value);
+
+				if ((conn->response_code == 301 || conn->response_code == 300)
+					&& strcmp(key, "Location") == 0) {
+
+					msn_soap_handle_redirect(conn, value);
+
+					handled = TRUE;
+					g_free(line);
+					break;
+				} else if (conn->response_code == 401 &&
+					strcmp(key, "WWW-Authenticate") == 0) {
+					char *error = strstr(value, "cbtxt=");
+
+					if (error) {
+						error += strlen("cbtxt=");
+					}
+
+					msn_soap_connection_sanitize(conn, TRUE);
+					msn_session_set_error(conn->session, MSN_ERROR_AUTH,
+						error ? purple_url_decode(error) : NULL);
+
+					g_free(line);
+					return;
+				} else if (strcmp(key, "Content-Length") == 0) {
+					conn->body_len = atoi(value);
+				} else if (strcmp(key, "Connection") == 0) {
+					if (strcmp(value, "close") == 0) {
+						conn->close_when_done = TRUE;
+					}
+				}
+				g_free(line);
+			}
+
+		loop_end:
+			cursor = conn->buf->str + conn->handled_len;
+		}
+	}
+
+	if (!handled && conn->headers_done) {
+		if (conn->buf->len - conn->handled_len >= 
+			conn->body_len) {
+			xmlnode *node = xmlnode_from_str(cursor, conn->body_len);
+
+			if (node == NULL) {
+				purple_debug_info("soap", "Malformed SOAP response: %s\n",
+					cursor);
+			} else {
+				MsnSoapMessage *message = conn->message;
+				conn->message = NULL;
+				message->xml = node;
+
+				if (!msn_soap_handle_body(conn, message))
+					return;
+			}
+
+			msn_soap_connection_handle_next(conn);
+		}
+
+		return;
+	}
+
+	if (handled) {
+		msn_soap_connection_handle_next(conn);
+	}
+}
+
+static void
+msn_soap_write_cb(gpointer data, gint fd, PurpleInputCondition cond)
+{
+	MsnSoapConnection *conn = data;
+	int written;
+
+	g_return_if_fail(cond == PURPLE_INPUT_WRITE);
+
+	written = purple_ssl_write(conn->ssl, conn->buf->str + conn->handled_len,
+		conn->buf->len - conn->handled_len);
+
+	if (written < 0 && errno == EAGAIN)
+		return;
+	else if (written <= 0) {
+		purple_ssl_close(conn->ssl);
+		conn->ssl = NULL;
+		msn_soap_connection_handle_next(conn);
+		return;
+	}
+
+	conn->handled_len += written;
+
+	if (conn->handled_len < conn->buf->len)
+		return;
+
+	/* we are done! */
+	g_string_free(conn->buf, TRUE);
+	conn->buf = NULL;
+	conn->handled_len = 0;
+	conn->body_len = 0;
+	conn->response_code = 0;
+	conn->headers_done = FALSE;
+	conn->close_when_done = FALSE;
+
+	purple_input_remove(conn->event_handle);
+	conn->event_handle = purple_input_add(conn->ssl->fd, PURPLE_INPUT_READ,
+		msn_soap_read_cb, conn);
+}
+
+static gboolean
+msn_soap_connection_run(gpointer data)
+{
+	MsnSoapConnection *conn = data;
+	MsnSoapRequest *req = g_queue_peek_head(conn->queue);
+
+	conn->event_handle = 0;
+
+	if (req) {
+		if (conn->ssl == NULL) {
+			conn->ssl = purple_ssl_connect(conn->session->account, conn->host,
+				443, msn_soap_connected_cb, msn_soap_error_cb, conn);
+		} else if (conn->connected) {
+			int len = -1;
+			char *body = xmlnode_to_str(req->message->xml, &len);
+			GSList *iter;
+			char *authstr = NULL;
+
+			g_queue_pop_head(conn->queue);
+
+			conn->buf = g_string_new("");
+
+			if (conn->session->passport_info.mspauth)
+				authstr = g_strdup_printf("Cookie: MSPAuth=%s\r\n",
+					conn->session->passport_info.mspauth);
+
+
+			g_string_append_printf(conn->buf,
+				"POST %s HTTP/1.1\r\n"
+				"SOAPAction: %s\r\n"
+				"Content-Type:text/xml; charset=utf-8\r\n"
+				"%s"
+				"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
+				"Accept: */*\r\n"
+				"Host: %s\r\n"
+				"Content-Length: %d\r\n"
+				"Connection: Keep-Alive\r\n"
+				"Cache-Control: no-cache\r\n",
+				req->path, req->message->action ? req->message->action : "",
+				authstr ? authstr : "",	conn->host, len);
+
+			for (iter = req->message->headers; iter; iter = iter->next) {
+				g_string_append(conn->buf, (char *)iter->data);
+				g_string_append(conn->buf, "\r\n");
+			}
+
+			g_string_append(conn->buf, "\r\n");
+			g_string_append(conn->buf, body);
+
+			purple_debug_info("soap", "%s\n", conn->buf->str);
+
+			conn->handled_len = 0;
+			conn->current_request = req;
+
+			conn->event_handle = purple_input_add(conn->ssl->fd,
+				PURPLE_INPUT_WRITE, msn_soap_write_cb, conn);
+			msn_soap_write_cb(conn, conn->ssl->fd, PURPLE_INPUT_WRITE);
+
+			g_free(authstr);
+			g_free(body);
+		}		
+	}
+
+	return FALSE;
+}
+
+void
+msn_soap_message_send(MsnSession *session, MsnSoapMessage *message,
+	const char *host, const char *path,
+	MsnSoapCallback cb, gpointer cb_data)
+{
+	msn_soap_message_send_internal(session, message, host, path, cb, cb_data,
+		FALSE);
+}
+
+static void
+msn_soap_message_send_internal(MsnSession *session,
+	MsnSoapMessage *message, const char *host, const char *path,
+	MsnSoapCallback cb, gpointer cb_data, gboolean first)
+{
+	MsnSoapConnection *conn = msn_soap_get_connection(session, host);
+	MsnSoapRequest *req = g_new0(MsnSoapRequest, 1);
+
+	req->path = g_strdup(path);
+	req->message = message;
+	req->cb = cb;
+	req->cb_data = cb_data;
+
+	if (first) {
+		g_queue_push_head(conn->queue, req);
+	} else {
+		g_queue_push_tail(conn->queue, req);
+	}
+
+	if (conn->event_handle == 0)
+		conn->event_handle = purple_timeout_add(0, msn_soap_connection_run,
+			conn);
+}
+
+static void
+msn_soap_connection_sanitize(MsnSoapConnection *conn, gboolean disconnect)
+{
+	if (conn->event_handle) {
+		purple_input_remove(conn->event_handle);
+		conn->event_handle = 0;
+	}
+
+	if (conn->message) {
+		msn_soap_message_destroy(conn->message);
+		conn->message = NULL;
+	}
+
+	if (conn->buf) {
+		g_string_free(conn->buf, TRUE);
+		conn->buf = NULL;
+	}
+
+	if (conn->ssl && (disconnect || conn->close_when_done)) {
+		purple_ssl_close(conn->ssl);
+		conn->ssl = NULL;
+	}
+
+	if (conn->current_request) {
+		msn_soap_request_destroy(conn->current_request);
+		conn->current_request = NULL;
+	}
+}
+
+static void
+msn_soap_connection_handle_next(MsnSoapConnection *conn)
+{
+	msn_soap_connection_sanitize(conn, FALSE);
+
+	conn->event_handle = purple_timeout_add(0, msn_soap_connection_run,	conn);
+
+	if (conn->current_request) {
+		MsnSoapRequest *req = conn->current_request;
+		conn->current_request = NULL;
+		msn_soap_connection_destroy_foreach_cb(req, conn);
+	}
+}
+
+static void
+msn_soap_connection_destroy_foreach_cb(gpointer item, gpointer data)
+{
+	MsnSoapRequest *req = item;
+
+	if (req->cb)
+		req->cb(req->message, NULL, req->cb_data);
+
+	msn_soap_request_destroy(req);
+}
+
+static void
+msn_soap_connection_destroy(MsnSoapConnection *conn)
+{
+	if (conn->current_request) {
+		MsnSoapRequest *req = conn->current_request;
+		conn->current_request = NULL;
+		msn_soap_connection_destroy_foreach_cb(req, conn);
+	}
+
+	msn_soap_connection_sanitize(conn, TRUE);
+	g_queue_foreach(conn->queue, msn_soap_connection_destroy_foreach_cb, conn);
+	g_queue_free(conn->queue);
+
+	g_free(conn->host);
+	g_free(conn);
+}
+
+MsnSoapMessage *
+msn_soap_message_new(const char *action, xmlnode *xml)
+{
+	MsnSoapMessage *message = g_new0(MsnSoapMessage, 1);
+
+	message->action = g_strdup(action);
+	message->xml = xml;
+
+	return message;
+}
+
+void
+msn_soap_message_destroy(MsnSoapMessage *message)
+{
+	if (message) {
+		g_slist_foreach(message->headers, (GFunc)g_free, NULL);
+		g_slist_free(message->headers);
+		g_free(message->action);
+		if (message->xml)
+			xmlnode_free(message->xml);
+		g_free(message);
+	}
+}
+
+void
+msn_soap_message_add_header(MsnSoapMessage *req,
+		const char *name, const char *value)
+{
+	char *header = g_strdup_printf("%s: %s\r\n", name, value);
+
+	req->headers = g_slist_prepend(req->headers, header);
+}
+
+static void
+msn_soap_request_destroy(MsnSoapRequest *req)
+{
+	g_free(req->path);
+	msn_soap_message_destroy(req->message);
+	g_free(req);
+}
+
+xmlnode *
+msn_soap_xml_get(xmlnode *parent, const char *node)
+{
+	xmlnode *ret;
+	char **tokens = g_strsplit(node, "/", -1);
+	int i;
+
+	for (i = 0; tokens[i]; i++) {
+		if ((ret = xmlnode_get_child(parent, tokens[i])) != NULL)
+			parent = ret;
+		else
+			break;
+	}
+
+	g_strfreev(tokens);
+	return ret;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/msn/soap2.h	Wed Oct 24 02:48:32 2007 +0000
@@ -0,0 +1,58 @@
+/**
+ * @file soap2.h
+ * 	header file for SOAP connection related process
+ *
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _MSN_SOAP2_H
+#define _MSN_SOAP2_H
+
+#include "session.h"
+#include "sslconn.h"
+#include "xmlnode.h"
+
+#include <glib.h>
+
+typedef struct _MsnSoapMessage MsnSoapMessage;
+typedef void (*MsnSoapCallback)(MsnSoapMessage *request,
+	MsnSoapMessage *response, gpointer cb_data);
+
+struct _MsnSoapMessage {
+	char *action;
+	xmlnode *xml;
+	GSList *headers;
+};
+
+MsnSoapMessage *msn_soap_message_new(const char *action, xmlnode *xml);
+
+void msn_soap_message_add_header(MsnSoapMessage *req,
+	const char *name, const char *value);
+
+void msn_soap_message_send(MsnSession *session,
+	MsnSoapMessage *message, const char *host, const char *path,
+	MsnSoapCallback cb, gpointer cb_data);
+
+void msn_soap_message_destroy(MsnSoapMessage *message);
+
+xmlnode *msn_soap_xml_get(xmlnode *parent, const char *node);
+
+#endif