changeset 19760:cabf9165c9ce

[gaim-migrate @ 16873] change the SOAP process Framework a initial version,can work now committed by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Sat, 19 Aug 2006 05:52:13 +0000
parents d59225f62362
children 74334aadd843
files src/protocols/msn/contact.c src/protocols/msn/nexus.c src/protocols/msn/notification.c src/protocols/msn/oim.c src/protocols/msn/soap.c src/protocols/msn/soap.h
diffstat 6 files changed, 77 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/contact.c	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/contact.c	Sat Aug 19 05:52:13 2006 +0000
@@ -30,6 +30,8 @@
 #include "xmlnode.h"
 #include "group.h"
 
+void msn_contact_connect_init(MsnSoapConn *soapconn);
+
 /*new a contact*/
 MsnContact *
 msn_contact_new(MsnSession *session)
@@ -80,7 +82,7 @@
 	g_return_if_fail(session != NULL);
 
 	/*login ok!We can retrieve the contact list*/
-	msn_get_contact_list(contact);
+//	msn_get_contact_list(contact);
 }
 
 /*get MSN member role utility*/
@@ -212,12 +214,13 @@
 {
 	MsnSoapReq *soap_request;
 
+	gaim_debug_info("MaYuan","Getting Contact List...\n");
 	soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
 					MSN_GET_CONTACT_POST_URL,MSN_GET_CONTACT_SOAP_ACTION,
 					MSN_GET_CONTACT_TEMPLATE,
 					msn_get_contact_list_cb,
 					msn_get_contact_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 }
 
 static void
@@ -437,7 +440,7 @@
 					MSN_GET_ADDRESS_TEMPLATE,
 					msn_get_address_cb,
 					msn_address_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 }
 
 static void
@@ -483,7 +486,7 @@
 					body,
 					msn_add_contact_read_cb,
 					msn_add_contact_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 
 	g_free(soap_action);
 	g_free(body);
@@ -523,7 +526,7 @@
 					body,
 					msn_delete_contact_read_cb,
 					msn_delete_contact_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 
 	g_free(body);
 }
@@ -559,7 +562,7 @@
 					body,
 					msn_block_read_cb,
 					msn_block_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 
 	g_free(body);
 }
@@ -596,7 +599,7 @@
 					body,
 					msn_unblock_read_cb,
 					msn_unblock_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 
 	g_free(body);
 }
@@ -630,7 +633,7 @@
 					MSN_GLEAMS_TEMPLATE,
 					msn_gleams_read_cb,
 					msn_gleams_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 }
 
 /***************************************************************
@@ -670,7 +673,7 @@
 					body,
 					msn_group_read_cb,
 					msn_group_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 }
 
 /*delete a group*/
@@ -691,18 +694,18 @@
 					body,
 					msn_group_read_cb,
 					msn_group_written_cb);
-	msn_soap_post(contact->soapconn,soap_request);
+	msn_soap_post(contact->soapconn,soap_request,msn_contact_connect_init);
 
 	g_free(body);
 }
 
 void
-msn_contact_connect(MsnContact *contact)
+msn_contact_connect_init(MsnSoapConn *soapconn)
 {
 	/*  Authenticate via Windows Live ID. */
 	gaim_debug_info("MaYuan","msn_contact_connect...\n");
 
-	msn_soap_init(contact->soapconn,MSN_CONTACT_SERVER,1,
+	msn_soap_init(soapconn,MSN_CONTACT_SERVER,1,
 					msn_contact_login_connect_cb,
 					msn_contact_login_error_cb);
 }
--- a/src/protocols/msn/nexus.c	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/nexus.c	Sat Aug 19 05:52:13 2006 +0000
@@ -182,7 +182,6 @@
 	/*prepare the Windows Live ID authentication token*/
 	username = g_strdup(gaim_account_get_username(session->account));
 	password = g_strdup(gaim_connection_get_password(session->account->gc));
-//		g_strdup(gaim_url_encode(gaim_connection_get_password(session->account->gc)));
 
 	challenge_str = g_strdup_printf(
 		"lc=%s&amp;id=%s&amp;tw=%s&amp;fs=%s&amp;ru=%s&amp;ct=%s&amp;kpp=%s&amp;kv=%s&amp;ver=%s&amp;rn=%s&amp;tpf=%s\r\n",
@@ -235,7 +234,7 @@
 {
 	/*  Authenticate via Windows Live ID. */
 	gaim_debug_info("MaYuan","msn_nexus_connect...\n");
-
 	msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb);
+	msn_soap_connect(nexus->soapconn);
 }
 
--- a/src/protocols/msn/notification.c	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/notification.c	Sat Aug 19 05:52:13 2006 +0000
@@ -1470,7 +1470,8 @@
 
 	/*starting retrieve the contact list*/
 	session->contact = msn_contact_new(session);
-	msn_contact_connect(session->contact);
+	msn_get_contact_list(session->contact);
+//	msn_contact_connect(session->contact);
 }
 
 static void
--- a/src/protocols/msn/oim.c	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/oim.c	Sat Aug 19 05:52:13 2006 +0000
@@ -29,6 +29,8 @@
 
 /*Local Function Prototype*/
 static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid);
+void msn_oim_retrieve_connect_init(MsnSoapConn *soapconn);
+void msn_oim_send_connect_init(MsnSoapConn *soapconn);
 
 /*new a OIM object*/
 MsnOim *
@@ -134,7 +136,7 @@
 					soap_body,
 					msn_oim_send_read_cb,
 					msn_oim_send_written_cb);
-	msn_soap_post(oim->sendconn,soap_request);
+	msn_soap_post(oim->sendconn,soap_request,msn_oim_send_connect_init);
 }
 
 void msn_oim_send_msg(MsnOim *oim,char *msg)
@@ -180,8 +182,6 @@
 	g_return_if_fail(session != NULL);
 
 	gaim_debug_info("MaYuan","oim get SOAP Server connected!\n");
-	/*call to get the message*/
-	msn_oim_get_msg(oim);
 }
 
 static void
@@ -193,9 +193,9 @@
 
 	gaim_debug_info("MaYuan","OIM get read buffer:{%s}\n",soapconn->body);
 
+	/*we need to process the read message!*/
 	/*get next single Offline Message*/
-	oim->oim_list = g_list_remove(oim->oim_list, oim->oim_list->data);
-//	msn_oim_get_msg(oim);
+//	oim->oim_list = g_list_remove(oim->oim_list, oim->oim_list->data);
 }
 
 static void
@@ -228,13 +228,8 @@
 		gaim_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);
 //		msn_session_report_user(oim->session,passport,"hello");
 		oim->oim_list = g_list_append(oim->oim_list,msgid);
+		msn_oim_post_single_get_msg(oim,msgid);
 	}
-	if(msn_soap_connected(oim->retrieveconn) == -1){
-		gaim_debug_info("MaYuan","retreive OIM server not connected! We need to connect it first\n");
-		msn_oim_connect(oim);
-		return;
-	}
-	msn_oim_get_msg(oim);
 }
 
 static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid)
@@ -258,37 +253,30 @@
 					soap_body,
 					msn_oim_get_read_cb,
 					msn_oim_get_written_cb);
-	msn_soap_post(oim->retrieveconn,soap_request);
+	msn_soap_post(oim->retrieveconn,soap_request,msn_oim_retrieve_connect_init);
 }
 
-/*MSN OIM get SOAP request*/
-void msn_oim_get_msg(MsnOim *oim)
+/*msn oim retrieve server connect init */
+void
+msn_oim_retrieve_connect_init(MsnSoapConn *soapconn)
 {
-	gaim_debug_info("MaYuan","Get OIM with SOAP \n");
-//	gaim_debug_info("MaYuan","oim->oim_list:%p,data:%s \n",oim->oim_list,oim->oim_list->data);
-	if(oim->oim_list !=NULL){
-		msn_oim_post_single_get_msg(oim,oim->oim_list->data);
+	gaim_debug_info("MaYuan","msn_oim_connect...\n");
+
+	if(msn_soap_connected(soapconn) == -1){
+		msn_soap_init(soapconn,MSN_OIM_RETRIEVE_HOST,1,
+					msn_oim_get_connect_cb,
+					msn_oim_get_error_cb);
 	}
 }
 
-/*msn oim server connect*/
-void
-msn_oim_connect(MsnOim *oim)
+void msn_oim_send_connect_init(MsnSoapConn *sendconn)
 {
-	gaim_debug_info("MaYuan","msn_oim_connect...\n");
-
-	if(msn_soap_connected(oim->retrieveconn) == -1){
-		msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
-					msn_oim_get_connect_cb,
-					msn_oim_get_error_cb);
-	}
-#if 0
-	if(msn_soap_connected(oim->sendconn) == -1){
-		msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
+	gaim_debug_info("MaYuan","msn oim send connect init...\n");
+	if(msn_soap_connected(sendconn) == -1){
+		msn_soap_init(sendconn,MSN_OIM_SEND_HOST,1,
 					msn_oim_send_connect_cb,
 					msn_oim_send_error_cb);
 	}
-#endif
 }
 
 /*endof oim.c*/
--- a/src/protocols/msn/soap.c	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/soap.c	Sat Aug 19 05:52:13 2006 +0000
@@ -26,6 +26,12 @@
 #include "msn.h"
 #include "soap.h"
 
+void
+msn_soap_set_process_step(MsnSoapConn *soapconn, MsnSoapStep step)
+{
+	soapconn->step = step;
+}
+
 //msn_soap_new(MsnSession *session,gpointer data,int sslconn)
 /*new a soap connection*/
 MsnSoapConn *
@@ -42,6 +48,7 @@
 	soapconn->input_handler = -1;
 	soapconn->output_handler = -1;
 
+	msn_soap_set_process_step(soapconn,MSN_SOAP_UNCONNECTED);
 	soapconn->soap_queue = g_queue_new();
 	return soapconn;
 }
@@ -68,6 +75,7 @@
 		soapconn->connect_cb(data,gsc,cond);
 	}
 
+	msn_soap_set_process_step(soapconn,MSN_SOAP_CONNECTED);
 	/*we do the SOAP request here*/
 	msn_soap_post_head_request(soapconn);
 }
@@ -83,6 +91,7 @@
 	if(soapconn->error_cb != NULL){
 		soapconn->error_cb(gsc,error,data);
 	}
+	msn_soap_set_process_step(soapconn, MSN_SOAP_UNCONNECTED);
 }
 
 /*init the soap connection*/
@@ -97,6 +106,7 @@
 	soapconn->error_cb = error_cb;
 }
 
+/*connect the soap connection*/
 void
 msn_soap_connect(MsnSoapConn *soapconn)
 {
@@ -108,6 +118,7 @@
 	}
 }
 
+/*close the soap connection*/
 void
 msn_soap_close(MsnSoapConn *soapconn)
 {
@@ -118,6 +129,7 @@
 		}
 	}else{
 	}
+	msn_soap_set_process_step(soapconn,MSN_SOAP_UNCONNECTED);
 }
 
 /*destroy the soap connection*/
@@ -146,6 +158,7 @@
 	/*close ssl connection*/
 	msn_soap_close(soapconn);
 
+	/*process the unhandled soap request*/
 	while ((request = g_queue_pop_head(soapconn->soap_queue)) != NULL){
 		msn_soap_request_free(request);
 	}
@@ -154,15 +167,15 @@
 }
 
 /*check the soap is connected?
- * if connected return 0
+ * if connected return 1
  */
 int
 msn_soap_connected(MsnSoapConn *soapconn)
 {
 	if(soapconn->ssl_conn){
-		return (soapconn->gsc == NULL? -1 : 0);
+		return (soapconn->gsc == NULL? 0 : 1);
 	}
-	return(soapconn->fd>0? 0 : -1);
+	return(soapconn->fd>0? 1 : 0);
 }
 
 /*read and append the content to the buffer*/
@@ -475,26 +488,33 @@
 {
 	if(!g_queue_is_empty(soapconn->soap_queue)){
 		MsnSoapReq *request;
-	
 		if((request = g_queue_pop_head(soapconn->soap_queue)) != NULL){
 			msn_soap_post_request(soapconn,request);
 		}
 	}
+	msn_soap_set_process_step(soapconn,MSN_SOAP_CONNECTED_IDLE);
 }
 
 void
-msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request)
+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)){
 		/*not connected?connect it first*/
+		gaim_debug_info("Ma Yuan","soap is not connected!\n");
+		msn_soap_init_func(soapconn);
 		msn_soap_connect(soapconn);
 		return;
 	}
+	gaim_debug_info("Ma Yuan","soap  connected!\n");
 	/*if connected, what we only needed to do is to queue the request, 
 	 * when SOAP request in the queue processed done, will do this command.
 	 * we just waiting...
 	 */
+	if(soapconn->step == MSN_SOAP_CONNECTED_IDLE){
+		msn_soap_post_head_request(soapconn);
+	}
 }
 
 /*Post the soap request action*/
@@ -505,6 +525,7 @@
 	char * request_str = NULL;
 
 	gaim_debug_info("MaYuan","msn_soap_post()...\n");
+	msn_soap_set_process_step(soapconn,MSN_SOAP_PROCESSING);
 	soap_head = g_strdup_printf(
 					"POST %s HTTP/1.1\r\n"
 					"SOAPAction: %s\r\n"
--- a/src/protocols/msn/soap.h	Fri Aug 18 19:09:07 2006 +0000
+++ b/src/protocols/msn/soap.h	Sat Aug 19 05:52:13 2006 +0000
@@ -28,12 +28,22 @@
 
 #define MSN_SOAP_READ_BUFF_SIZE		8192
 
+typedef enum
+{
+	MSN_SOAP_UNCONNECTED,
+	MSN_SOAP_CONNECTED,
+	MSN_SOAP_PROCESSING,
+	MSN_SOAP_CONNECTED_IDLE
+}MsnSoapStep;
+
 /*MSN SoapRequest structure*/
 typedef struct _MsnSoapReq MsnSoapReq;
 
 /*MSN Https connection structure*/
 typedef struct _MsnSoapConn MsnSoapConn;
 
+typedef void (*MsnSoapConnectInitFunction)(MsnSoapConn *);
+
 struct _MsnSoapReq{
 	/*request sequence*/
 	int	 id;
@@ -56,6 +66,7 @@
 	char *login_path;
 	char *soap_action;
 
+	MsnSoapStep step;
 	/*ssl connection?*/
 	guint	ssl_conn;
 	/*normal connection*/
@@ -109,10 +120,11 @@
 
 /*init a soap conneciton */
 void msn_soap_init(MsnSoapConn *soapconn,char * host,int ssl,GaimSslInputFunction connect_cb,GaimSslErrorFunction error_cb);
+void msn_soap_connect(MsnSoapConn *soapconn);
 
 /*write to soap*/
 void msn_soap_write(MsnSoapConn * soapconn, char *write_buf, GaimInputFunction written_cb);
-void msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request);
+void msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request,MsnSoapConnectInitFunction msn_soap_init_func);
 
 void  msn_soap_free_read_buf(MsnSoapConn *soapconn);
 void msn_soap_free_write_buf(MsnSoapConn *soapconn);