changeset 19770:1aa5494587e8

[gaim-migrate @ 16973] change the soap process to below: Post one Soap request After finish one soap request,close the connection, If there are more, reconect and process it. to avoid the below problem: in one socket, If post soap request one by one, The second will always read 0 bytes. comitted by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Tue, 22 Aug 2006 06:10:01 +0000
parents bffd1b96207c
children cf0611260c6b
files src/protocols/msn/contact.c src/protocols/msn/msg.c src/protocols/msn/msg.h src/protocols/msn/notification.c src/protocols/msn/oim.c src/protocols/msn/soap.c src/protocols/msn/switchboard.c
diffstat 7 files changed, 73 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/contact.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/contact.c	Tue Aug 22 06:10:01 2006 +0000
@@ -179,8 +179,6 @@
 	}
 
 	xmlnode_free(node);
-
-	msn_get_address_book(contact);
 }
 
 static void
@@ -197,6 +195,10 @@
 
 //	gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
 	msn_parse_contact_list(contact);
+	/*free the read buffer*/
+	msn_soap_free_read_buf(soapconn);
+
+	msn_get_address_book(contact);
 }
 
 static void
@@ -420,6 +422,8 @@
 
 //	gaim_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
 	msn_parse_addressbook(contact);
+	/*free the read buffer*/
+	msn_soap_free_read_buf(soapconn);
 }
 
 /**/
--- a/src/protocols/msn/msg.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/msg.c	Tue Aug 22 06:10:01 2006 +0000
@@ -206,7 +206,8 @@
 
 void
 msn_message_parse_payload(MsnMessage *msg,
-						  const char *payload, size_t payload_len)
+						  const char *payload, size_t payload_len,
+						  const char *line_dem,const char *body_dem)
 {
 	char *tmp_base, *tmp;
 	const char *content_type;
@@ -219,7 +220,7 @@
 	memcpy(tmp_base, payload, payload_len);
 
 	/* Parse the attributes. */
-	end = strstr(tmp, "\r\n\r\n");
+	end = strstr(tmp, body_dem);
 	/* TODO? some clients use \r delimiters instead of \r\n, the official client
 	 * doesn't send such messages, but does handle receiving them. We'll just
 	 * avoid crashing for now */
@@ -229,7 +230,7 @@
 	}
 	*end = '\0';
 
-	elems = g_strsplit(tmp, "\r\n", 0);
+	elems = g_strsplit(tmp, line_dem, 0);
 
 	for (cur = elems; *cur != NULL; cur++){
 		const char *key, *value;
@@ -268,7 +269,7 @@
 	g_strfreev(elems);
 
 	/* Proceed to the end of the "\r\n\r\n" */
-	tmp = end + 4;
+	tmp = end + strlen(body_dem);
 
 	/* Now we *should* be at the body. */
 	content_type = msn_message_get_content_type(msg);
--- a/src/protocols/msn/msg.h	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/msg.h	Tue Aug 22 06:10:01 2006 +0000
@@ -34,6 +34,12 @@
 
 typedef void (*MsnMsgCb)(MsnMessage *, void *data);
 
+#define MSG_BODY_DEM	"\r\n\r\n"
+#define MSG_LINE_DEM	"\r\n"
+
+#define MSG_OIM_BODY_DEM	"\n\n"
+#define MSG_OIM_LINE_DEM	"\n"
+
 /*
 typedef enum
 {
@@ -180,7 +186,8 @@
  * @param payload_len The length of the payload.
  */
 void msn_message_parse_payload(MsnMessage *msg, const char *payload,
-							   size_t payload_len);
+							   size_t payload_len,
+						  const char *line_dem,const char *body_dem);
 
 /**
  * Destroys a message.
--- a/src/protocols/msn/notification.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/notification.c	Tue Aug 22 06:10:01 2006 +0000
@@ -373,7 +373,7 @@
 
 	msg = msn_message_new_from_cmd(cmdproc->session, cmd);
 
-	msn_message_parse_payload(msg, payload, len);
+	msn_message_parse_payload(msg, payload, len,MSG_LINE_DEM,MSG_BODY_DEM);
 #ifdef MSN_DEBUG_NS
 	msn_message_show_readable(msg, "Notification", TRUE);
 #endif
@@ -436,7 +436,7 @@
 	gaim_debug_info("MaYuan","Process UBM payload:%s\n",payload);
 	msg = msn_message_new_from_cmd(cmdproc->session, cmd);
 
-	msn_message_parse_payload(msg, payload, len);
+	msn_message_parse_payload(msg, payload, len,MSG_LINE_DEM,MSG_BODY_DEM);
 #ifdef MSN_DEBUG_NS
 	msn_message_show_readable(msg, "Notification", TRUE);
 #endif
--- a/src/protocols/msn/oim.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/oim.c	Tue Aug 22 06:10:01 2006 +0000
@@ -184,6 +184,37 @@
 	gaim_debug_info("MaYuan","oim get SOAP Server connected!\n");
 }
 
+void
+msn_oim_report_to_user(MsnOim *oim,char *msg_str)
+{
+	MsnMessage *message;
+	char * end,*endline;
+
+	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);
+	gaim_debug_info("MaYuan","oim body:{%s}\n",message->body);
+}
+
+void
+msn_oim_process(MsnOim *oim,char *oim_msg)
+{
+	xmlnode *oimNode,*bodyNode,*responseNode,*msgNode;
+	char *msg_data,*msg_str;
+
+	oimNode = xmlnode_from_str(oim_msg, strlen(oim_msg));
+	bodyNode = xmlnode_get_child(oimNode,"Body");
+//	gaim_debug_misc("xml","body{%p},name:%s\n",bodyNode,bodyNode->name);
+	responseNode = xmlnode_get_child(bodyNode,"GetMessageResponse");
+	msgNode = xmlnode_get_child(responseNode,"GetMessageResult");
+	msg_data = xmlnode_get_data(msgNode);
+	msg_str = g_strdup(msg_data);
+	gaim_debug_info("OIM","msg:{%s}\n",msg_str);
+	msn_oim_report_to_user(oim,msg_str);
+	g_free(msg_str);
+}
+
 static void
 msn_oim_get_read_cb(gpointer data, GaimSslConnection *gsc,
 				 GaimInputCondition cond)
@@ -194,9 +225,11 @@
 	gaim_debug_info("MaYuan","OIM get read buffer:{%s}\n",soapconn->body);
 
 	/*we need to process the read message!*/
+	msn_oim_process(oim,soapconn->body);
+	msn_soap_free_read_buf(soapconn);
 	/*get next single Offline Message*/
 //	oim->oim_list = g_list_remove(oim->oim_list, oim->oim_list->data);
-	msn_soap_post_head_request(soapconn);
+	msn_soap_post(soapconn,NULL,msn_oim_retrieve_connect_init);
 }
 
 static void
--- a/src/protocols/msn/soap.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/soap.c	Tue Aug 22 06:10:01 2006 +0000
@@ -345,19 +345,22 @@
 			/*remove the read handler*/
 			gaim_input_remove(soapconn->input_handler);
 			soapconn->input_handler = -1;
+			/*
+			 * close the soap connection,if more soap request came,
+			 * Just reconnect to do it,
+			 *
+			 * To solve the problem described below:
+			 * When I post the soap request in one socket one after the other,
+			 * The first read is ok, But the second soap read always got 0 bytes,
+			 * Weird!
+			 * */
+			msn_soap_close(soapconn);
 #endif
 
 			/*call the read callback*/
 			if(soapconn->read_cb != NULL){
 				soapconn->read_cb(soapconn,source,0);
 			}
-			/*clear the read buffer*/
-			msn_soap_free_read_buf(soapconn);
-#if 1
-//			msn_soap_close(soapconn);
-#endif
-			/*Process the next queued SOAP request*/
-//			msn_soap_post_head_request(soapconn);
 	}
 	return;
 }
@@ -510,9 +513,12 @@
 msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request,
 				MsnSoapConnectInitFunction msn_soap_init_func)
 {
-	g_queue_push_tail(soapconn->soap_queue, request);
-	if(!msn_soap_connected(soapconn)&&(soapconn->step == MSN_SOAP_UNCONNECTED)){
-		/*not connected?connect it first*/
+	if(request != NULL){
+		g_queue_push_tail(soapconn->soap_queue, request);
+	}
+	if(!msn_soap_connected(soapconn)&&(soapconn->step == MSN_SOAP_UNCONNECTED)
+					&&(!g_queue_is_empty(soapconn->soap_queue))){
+		/*not connected?and we have something to process connect it first*/
 		gaim_debug_info("Ma Yuan","soap is not connected!\n");
 		msn_soap_init_func(soapconn);
 		msn_soap_connect(soapconn);
--- a/src/protocols/msn/switchboard.c	Tue Aug 22 02:55:14 2006 +0000
+++ b/src/protocols/msn/switchboard.c	Tue Aug 22 06:10:01 2006 +0000
@@ -721,7 +721,8 @@
 
 	msg = msn_message_new_from_cmd(cmdproc->session, cmd);
 
-	msn_message_parse_payload(msg, payload, len);
+	msn_message_parse_payload(msg, payload, len,
+					MSG_LINE_DEM,MSG_BODY_DEM);
 #ifdef MSN_DEBUG_SB
 	msn_message_show_readable(msg, "SB RECV", FALSE);
 #endif