changeset 19788:8b4653986e8e

[gaim-migrate @ 16600] change to add SOAP HTTP header retrieve Now Can do the OIM Message XML process submitted by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Sun, 30 Jul 2006 13:44:34 +0000
parents b99512bd6d85
children 7e36832172a9
files src/protocols/msn/cmdproc.c src/protocols/msn/contact.h src/protocols/msn/msg.c src/protocols/msn/msn-utils.c src/protocols/msn/notification.c src/protocols/msn/oim.c src/protocols/msn/oim.h src/protocols/msn/session.c src/protocols/msn/session.h src/protocols/msn/soap.c
diffstat 10 files changed, 251 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/cmdproc.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/cmdproc.c	Sun Jul 30 13:44:34 2006 +0000
@@ -133,7 +133,7 @@
 	}
 
 	msn_servconn_write(servconn, data, len);
-	gaim_debug_info("<<","%s\n",data);
+//	gaim_debug_info("<<","%s\n",data);
 
 	g_free(data);
 }
--- a/src/protocols/msn/contact.h	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/contact.h	Sun Jul 30 13:44:34 2006 +0000
@@ -27,6 +27,7 @@
 
 #define MSN_CONTACT_SERVER	"contacts.msn.com"
 
+/*get contact list soap request template*/
 #define MSN_GET_CONTACT_POST_URL	"/abservice/SharingService.asmx"
 #define MSN_GET_CONTACT_SOAP_ACTION "http://www.msn.com/webservices/AddressBook/FindMembership"
 #define MSN_GET_CONTACT_TEMPLATE	"<?xml version='1.0' encoding='utf-8'?>"\
@@ -56,6 +57,7 @@
 	"</soap:Body>"\
 "</soap:Envelope>"
 
+/*get addressbook soap request template*/
 #define MSN_GET_ADDRESS_SOAP_ACTION	"http://www.msn.com/webservices/AddressBook/ABFindAll"
 #define MSN_GET_ADDRESS_POST_URL	"/abservice/abservice.asmx"
 #define MSN_GET_ADDRESS_TEMPLATE	"<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
@@ -78,6 +80,7 @@
 	"</soap:Body>"\
 "</soap:Envelope>"
 
+/*Gleams SOAP request template*/
 #define MSN_GLEAMS_TEMPLATE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"\
 	"<soap:Header>"\
@@ -100,11 +103,13 @@
 	"</soap:Body>"\
 "</soap:Envelope>"
 
+/*add conatct soap request*/
 #define MSN_CONTACT_ADD_SOAP_ACTION	"http://www.msn.com/webservices/AddressBook/ABContactAdd"
 #define MSN_CONTACT_XML	"<Contact xmlns=\"http://www.msn.com/webservices/AddressBook\"><contactInfo><contactType>LivePending</contactType><passportName>%s</passportName><isMessengerUser>true</isMessengerUser></contactInfo></Contact>"
 
 #define MSN_ADD_CONTACT_TEMPLATE	"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>ContactSave</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABContactAdd xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><contacts>%s</contacts><options><EnableAllowListManagement>true</EnableAllowListManagement></options></ABContactAdd></soap:Body></soap:Envelope>"
 
+/*delete contact from contact list soap request template*/
 #define MSN_CONTACT_DEL_SOAP_ACTION	"http://www.msn.com/webservices/AddressBook/ABContactDelete"
 #define MSN_CONTACTS_DEL		"<Contact><contactId>5e8a2e64-c271-443f-ac86-2429f3ffd18a</contactId></Contact>"
 #define MSN_DEL_CONTACT_TEMPLATE	"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><soap:Header><ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ApplicationId>09607671-1C32-421F-A6A6-CBFAA51AB5F4</ApplicationId><IsMigration>false</IsMigration><PartnerScenario>Timer</PartnerScenario></ABApplicationHeader><ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\"><ManagedGroupRequest>false</ManagedGroupRequest></ABAuthHeader></soap:Header><soap:Body><ABContactDelete xmlns=\"http://www.msn.com/webservices/AddressBook\"><abId>00000000-0000-0000-0000-000000000000</abId><contacts>%s</contacts></ABContactDelete></soap:Body></soap:Envelope>"
--- a/src/protocols/msn/msg.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/msg.c	Sun Jul 30 13:44:34 2006 +0000
@@ -214,7 +214,7 @@
 	char **elems, **cur, **tokens;
 
 	g_return_if_fail(payload != NULL);
-
+	gaim_debug_info("MaYuan","payload:{%s}\n",payload);
 	tmp_base = tmp = g_malloc0(payload_len + 1);
 	memcpy(tmp_base, payload, payload_len);
 
--- a/src/protocols/msn/msn-utils.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/msn-utils.c	Sun Jul 30 13:44:34 2006 +0000
@@ -386,7 +386,7 @@
 }
 
 /*
- * handle MSN Chanllege computation
+ * Handle MSN Chanllege computation
  *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges
  */
 #define BUFSIZE	256
--- a/src/protocols/msn/notification.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/notification.c	Sun Jul 30 13:44:34 2006 +0000
@@ -390,6 +390,7 @@
 	}else{
 		g_return_if_fail(cmd->payload_cb != NULL);
 
+		gaim_debug_info("MaYuan","MSG payload:{%s}\n",cmd->payload);
 		cmd->payload_cb(cmdproc, cmd, cmd->payload, cmd->payload_len);
 	}
 }
@@ -1359,7 +1360,40 @@
 static void
 initial_mdata_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
 {
-	gaim_debug_info("MaYuan","mdata...{%s} \n",msg->body);
+	MsnSession *session;
+	xmlnode *mdNode;
+	char *end;
+	char **elems, **cur, **tokens;
+
+//	gaim_debug_info("MaYuan","mdata...{%s} \n",msg->body);
+
+	/*new a oim session*/
+	session = cmdproc->session;
+	session->oim = msn_oim_new(session);
+
+	/*parse offline message data*/
+	elems = g_strsplit(msg->body, "\r\n", 0);
+	for (cur = elems; *cur != NULL; cur++){
+		const char *key, *value;
+
+//		gaim_debug_info("MaYuan","cur:{%s}\n",*cur);
+		tokens = g_strsplit(*cur, ": ", 2);
+
+		key = tokens[0];
+		value = tokens[1];
+
+		/*if not MIME content ,then return*/
+		if ((key != NULL) && (!strcmp(key, "Mail-Data")) ){
+//			gaim_debug_info("MaYuan","data:{%s}\n",value);
+			msn_parse_oim_msg(session->oim,value);
+			g_strfreev(tokens);
+			break;
+		}
+
+		g_strfreev(tokens);
+	}
+
+	g_strfreev(elems);
 }
 
 static void
--- a/src/protocols/msn/oim.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/oim.c	Sun Jul 30 13:44:34 2006 +0000
@@ -79,7 +79,7 @@
 	g_return_if_fail(session != NULL);
 }
 
-void msn_oim_send_msg(MsnOim *oim,char * msg)
+void msn_oim_send_msg(MsnOim *oim,char *msg)
 {
 	if(msn_soap_connected(oim->sendconn) == -1){
 		msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
@@ -89,6 +89,108 @@
 	
 }
 
+static void
+msn_oim_get_read_cb(gpointer data, GaimSslConnection *gsc,
+				 GaimInputCondition cond)
+{
+	MsnSoapConn * soapconn = data;	
+	MsnOim * msnoim;
+
+	gaim_debug_info("MaYuan","read buffer:{%s}\n",soapconn->body);
+}
+
+static void
+msn_oim_get_written_cb(gpointer data, gint source, GaimInputCondition cond)
+{
+	MsnSoapConn * soapconn = data;	
+
+	soapconn->read_cb = msn_oim_get_read_cb;
+	msn_soap_read_cb(data,source,cond);
+}
+/*
+static void
+msn_oim_login_connect_cb(gpointer data, GaimSslConnection *gsc,
+				 GaimInputCondition cond)
+{
+	
+}*/
+
+static GaimConversation *
+msn_oim_get_conv(MsnOim *oim,char *passport)
+{
+	GaimAccount *account;
+	GaimConversation * conv;
+
+	g_return_val_if_fail(oim != NULL, NULL);
+	account = oim->session->account;
+
+	conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
+									passport, account);
+	if(conv == NULL){
+		conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, passport);
+	}
+	return conv;
+}
+
+void
+msn_oim_report_user(MsnOim *oim,const char *passport,char *msg)
+{
+	GaimConversation * conv;
+
+	if ((conv = msn_oim_get_conv(oim,passport)) != NULL){
+		gaim_conversation_write(conv, NULL, msg, GAIM_MESSAGE_SYSTEM, time(NULL));
+	}
+
+}
+
+void
+msn_parse_oim_msg(MsnOim *oim,char *xmlmsg)
+{
+	xmlnode *mdNode,*mNode,*INode,*nNode,*ENode,*rtNode;
+	char *passport,*rTime,*msgid,*nickname;
+
+	mdNode = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
+	for(mNode = xmlnode_get_child(mdNode, "M"); mNode;
+					mNode = xmlnode_get_next_twin(mNode)){
+		INode = xmlnode_get_child(mNode,"E");
+		passport = xmlnode_get_data(INode);
+		INode = xmlnode_get_child(mNode,"I");
+		msgid = xmlnode_get_data(INode);
+		rtNode = xmlnode_get_child(mNode,"RT");
+		rTime = xmlnode_get_data(rtNode);
+		nNode = xmlnode_get_child(mNode,"N");
+		nickname = xmlnode_get_data(nNode);
+		gaim_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);
+		msn_oim_report_user(oim,passport,"hello");
+//		msn_oim_get_msg(oim,msgid);
+	}
+}
+
+void msn_oim_get_msg(MsnOim *oim,char *msgid)
+{
+	const char *oimid ,*oimsoapbody,*t,*p;
+
+	if(msn_soap_connected(oim->retrieveconn) == -1){
+		gaim_debug_info("MaYuan","retreive OIM server not connected!\n");
+		msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
+					msn_oim_login_connect_cb,
+					msn_oim_login_error_cb);
+		return;
+	}
+
+	oim->retrieveconn->login_path = g_strdup(MSN_OIM_RETRIEVE__URL);
+	oim->retrieveconn->soap_action = g_strdup(MSN_OIM_DEL_SOAP_ACTION);
+	t = oim->session->passport_info.t;
+	p = oim->session->passport_info.p;
+
+	oimsoapbody = g_strdup_printf(MSN_OIM_GET_TEMPLATE,
+					t,
+					p,
+					msgid
+					);
+	msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_get_written_cb);
+}
+
 /*msn oim server connect*/
 void
 msn_oim_connect(MsnOim *oim)
--- a/src/protocols/msn/oim.h	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/oim.h	Sun Jul 30 13:44:34 2006 +0000
@@ -98,6 +98,8 @@
 /*function prototype*/
 MsnOim * msn_oim_new(MsnSession *session);
 void msn_oim_destroy(MsnOim *oim);
+void msn_parse_oim_msg(MsnOim *oim,char *xmlmsg);
 
+void msn_oim_get_msg(MsnOim *oim,char *msgid);
 #endif/* _MSN_OIM_H_*/
 /*endof oim.h*/
--- a/src/protocols/msn/session.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/session.c	Sun Jul 30 13:44:34 2006 +0000
@@ -91,6 +91,11 @@
 	if (session->nexus != NULL)
 		msn_nexus_destroy(session->nexus);
 
+	if (session->contact != NULL)
+		msn_contact_destroy(session->contact);
+	if (session->oim != NULL)
+		msn_oim_destroy(session->oim);
+
 	if (session->user != NULL)
 		msn_user_destroy(session->user);
 
--- a/src/protocols/msn/session.h	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/session.h	Sun Jul 30 13:44:34 2006 +0000
@@ -39,6 +39,7 @@
 #include "nexus.h"
 #include "httpconn.h"
 #include "contact.h"
+#include "oim.h"
 
 #include "userlist.h"
 #include "sync.h"
@@ -96,6 +97,7 @@
 	MsnNotification *notification;
 	MsnNexus *nexus;
 	MsnContact *contact;
+	MsnOim		*oim;
 	MsnSync *sync;
 
 	MsnUserList *userlist;
--- a/src/protocols/msn/soap.c	Sun Jul 23 12:19:10 2006 +0000
+++ b/src/protocols/msn/soap.c	Sun Jul 30 13:44:34 2006 +0000
@@ -117,7 +117,9 @@
 	msn_soap_free_write_buf(soapconn);
 
 	/*close ssl connection*/
-	gaim_ssl_close(soapconn->gsc);
+	if(soapconn->gsc != NULL){
+		gaim_ssl_close(soapconn->gsc);
+	}
 	soapconn->gsc = NULL;
 
 	g_free(soapconn);
@@ -199,41 +201,104 @@
 		return;
 	}
 
-	body_start = (char *)g_strstr_len(soapconn->read_buf, soapconn->read_len,"\r\n\r\n");
-	if(!body_start){
-		return;
+	if (strstr(soapconn->read_buf, "HTTP/1.1 302") != NULL)
+	{
+		/* Redirect. */
+		char *location, *c;
+
+		location = strstr(soapconn->read_buf, "Location: ");
+		if (location == NULL)
+		{
+			msn_soap_free_read_buf(soapconn);
+
+			return;
+		}
+		location = strchr(location, ' ') + 1;
+
+		if ((c = strchr(location, '\r')) != NULL)
+			*c = '\0';
+
+		/* Skip the http:// */
+		if ((c = strchr(location, '/')) != NULL)
+			location = c + 2;
+
+		if ((c = strchr(location, '/')) != NULL)
+		{
+			g_free(soapconn->login_path);
+			soapconn->login_path = g_strdup(c);
+
+			*c = '\0';
+		}
+
+		g_free(soapconn->login_host);
+		soapconn->login_host = g_strdup(location);
+
+		gaim_ssl_connect(session->account, soapconn->login_host,
+			GAIM_SSL_DEFAULT_PORT, msn_soap_connect_cb,
+			msn_soap_error_cb, soapconn);
 	}
-	body_start += 4;
-
-//	gaim_debug_misc("msn", "Soap Read: {%s}\n", soapconn->read_buf);
+	else if (strstr(soapconn->read_buf, "HTTP/1.1 401 Unauthorized") != NULL)
+	{
+		const char *error;
 
-	/* we read the content-length*/
-	length_start = strstr(soapconn->read_buf, "Content-Length: ");
-	length_start += strlen("Content-Length: ");
-	length_end = strstr(length_start, "\r\n");
-	body_len = g_strndup(length_start,length_end - length_start);
+		if ((error = strstr(soapconn->read_buf, "WWW-Authenticate")) != NULL)
+		{
+			if ((error = strstr(error, "cbtxt=")) != NULL)
+			{
+				const char *c;
+				char *temp;
+
+				error += strlen("cbtxt=");
+
+				if ((c = strchr(error, '\n')) == NULL)
+					c = error + strlen(error);
+
+				temp = g_strndup(error, c - error);
+				error = gaim_url_decode(temp);
+				g_free(temp);
+			}
+		}
 
-	/*setup the conn body */
-	soapconn->body		= body_start;
-	soapconn->body_len	= atoi(body_len);
-//	gaim_debug_misc("MaYuan","content length :%d",soapconn->body_len);
+		msn_session_set_error(session, MSN_ERROR_SERV_UNAVAILABLE, error);
+	}
+	else if (strstr(soapconn->read_buf, "HTTP/1.1 200 OK"))
+	{
+			/*OK! process the SOAP body*/
+			body_start = (char *)g_strstr_len(soapconn->read_buf, soapconn->read_len,"\r\n\r\n");
+			if(!body_start){
+					return;
+			}
+			body_start += 4;
+
+			//	gaim_debug_misc("msn", "Soap Read: {%s}\n", soapconn->read_buf);
 
-	if(soapconn->read_len < body_start - soapconn->read_buf + atoi(body_len)){
-			return;
-	}
+			/* we read the content-length*/
+			length_start = strstr(soapconn->read_buf, "Content-Length: ");
+			length_start += strlen("Content-Length: ");
+			length_end = strstr(length_start, "\r\n");
+			body_len = g_strndup(length_start,length_end - length_start);
 
-	g_free(body_len);
+			/*setup the conn body */
+			soapconn->body		= body_start;
+			soapconn->body_len	= atoi(body_len);
+			//	gaim_debug_misc("MaYuan","content length :%d",soapconn->body_len);
+
+			if(soapconn->read_len < body_start - soapconn->read_buf + atoi(body_len)){
+					return;
+			}
+
+			g_free(body_len);
 
 #if 1
-	/*remove the read handler*/
-	gaim_input_remove(soapconn->input_handler);
-	soapconn->input_handler = -1;
+			/*remove the read handler*/
+			gaim_input_remove(soapconn->input_handler);
+			soapconn->input_handler = -1;
 #endif
 
-	/*call the read callback*/
-	if(soapconn->read_cb != NULL){
-		soapconn->read_cb(soapconn,source,0);
-	}
+			/*call the read callback*/
+			if(soapconn->read_cb != NULL){
+					soapconn->read_cb(soapconn,source,0);
+			}
 #if 0
 	/*clear the read buffer*/
 	msn_soap_free_read_buf(soapconn);
@@ -241,9 +306,10 @@
 	/*remove the read handler*/
 	gaim_input_remove(soapconn->input_handler);
 	soapconn->input_handler = -1;
-//	gaim_ssl_close(soapconn->gsc);
-//	soapconn->gsc = NULL;
+	//	gaim_ssl_close(soapconn->gsc);
+	//	soapconn->gsc = NULL;
 #endif
+	}
 }
 
 void 
@@ -360,7 +426,7 @@
 
 	/*free read buffer*/
 	msn_soap_free_read_buf(soapconn);
-//	gaim_debug_info("MaYuan","send to contact server{%s}\n",request_str);
+	gaim_debug_info("MaYuan","send to  server{%s}\n",request_str);
 	msn_soap_write(soapconn,request_str,written_cb);
 }