# HG changeset patch # User Ma Yuan # Date 1155745225 0 # Node ID 22eeb4882d777769eed0d3642d1f2d5cff2ba49c # Parent 2315ee828b7cd43ee21909d7c6e9c6c901504bb6 [gaim-migrate @ 16790] SOAP implementation rewrite. use Queue to buffer the SOAP request. Warning:Middle stage,Never Use it committed by Ma Yuan committer: Ethan Blanton diff -r 2315ee828b7c -r 22eeb4882d77 src/protocols/msn/contact.c --- a/src/protocols/msn/contact.c Tue Aug 15 16:48:32 2006 +0000 +++ b/src/protocols/msn/contact.c Wed Aug 16 16:20:25 2006 +0000 @@ -210,10 +210,14 @@ void msn_get_contact_list(MsnContact * contact) { - gaim_debug_info("MaYuan","msn_get_contact_list()...\n"); - contact->soapconn->login_path = g_strdup(MSN_GET_CONTACT_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_GET_CONTACT_SOAP_ACTION); - msn_soap_post(contact->soapconn,MSN_GET_CONTACT_TEMPLATE,msn_get_contact_written_cb); + MsnSoapReq *soap_request; + + 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); } static void @@ -424,11 +428,16 @@ void msn_get_address_book(MsnContact *contact) { + MsnSoapReq *soap_request; + gaim_debug_info("MaYuan","msn_get_address_book()...\n"); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_GET_ADDRESS_SOAP_ACTION); - msn_soap_post(contact->soapconn,MSN_GET_ADDRESS_TEMPLATE,msn_address_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,MSN_GET_ADDRESS_SOAP_ACTION, + MSN_GET_ADDRESS_TEMPLATE, + msn_get_address_cb, + msn_address_written_cb); + msn_soap_post(contact->soapconn,soap_request); } static void @@ -451,8 +460,10 @@ void msn_add_contact(MsnContact *contact,const char *passport,char *groupId) { + MsnSoapReq *soap_request; char *body = NULL; char *contact_xml = NULL; + char *soap_action; gaim_debug_info("MaYuan","msn add a contact...\n"); contact_xml = g_strdup_printf(MSN_CONTACT_XML,passport); @@ -460,17 +471,21 @@ body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,contact_xml); g_free(contact_xml); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION); + soap_action = g_strdup(MSN_CONTACT_ADD_SOAP_ACTION); }else{ body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE,groupId,contact_xml); g_free(contact_xml); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION); + soap_action = g_strdup(MSN_ADD_CONTACT_GROUP_SOAP_ACTION); } - msn_soap_post(contact->soapconn,body,msn_add_contact_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,soap_action, + body, + msn_add_contact_read_cb, + msn_add_contact_written_cb); + msn_soap_post(contact->soapconn,soap_request); + g_free(soap_action); g_free(body); } @@ -496,15 +511,20 @@ { char *body = NULL; char *contact_xml = NULL ; + MsnSoapReq *soap_request; gaim_debug_info("MaYuan","msn delete a contact,contactId:{%s}...\n",contactId); contact_xml = g_strdup_printf(MSN_CONTACTS_DEL_XML,contactId); body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,contact_xml); g_free(contact_xml); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_CONTACT_DEL_SOAP_ACTION); - msn_soap_post(contact->soapconn,body,msn_delete_contact_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,MSN_CONTACT_DEL_SOAP_ACTION, + body, + msn_delete_contact_read_cb, + msn_delete_contact_written_cb); + msn_soap_post(contact->soapconn,soap_request); + g_free(body); } @@ -528,14 +548,19 @@ void msn_block_contact(MsnContact *contact,const char* membership_id) { + MsnSoapReq *soap_request; char *body = NULL; gaim_debug_info("MaYuan","msn block a contact...\n"); body = g_strdup_printf(MSN_CONTACT_DELECT_FROM_ALLOW_TEMPLATE,membership_id); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_SHARE_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_CONTACT_BLOCK_SOAP_ACTION); - msn_soap_post(contact->soapconn,body,msn_block_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_SHARE_POST_URL,MSN_CONTACT_BLOCK_SOAP_ACTION, + body, + msn_block_read_cb, + msn_block_written_cb); + msn_soap_post(contact->soapconn,soap_request); + g_free(body); } @@ -559,15 +584,20 @@ void msn_unblock_contact(MsnContact *contact,const char* passport) { + MsnSoapReq *soap_request; char *body = NULL; gaim_debug_info("MaYuan","msn unblock a contact...\n"); body = g_strdup_printf(MSN_UNBLOCK_CONTACT_TEMPLATE,passport); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_SHARE_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_CONTACT_UNBLOCK_SOAP_ACTION); - msn_soap_post(contact->soapconn,body,msn_unblock_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_SHARE_POST_URL,MSN_CONTACT_UNBLOCK_SOAP_ACTION, + body, + msn_unblock_read_cb, + msn_unblock_written_cb); + msn_soap_post(contact->soapconn,soap_request); + g_free(body); } @@ -591,11 +621,16 @@ void msn_get_gleams(MsnContact *contact) { + MsnSoapReq *soap_request; + gaim_debug_info("MaYuan","msn get gleams info...\n"); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_GET_GLEAMS_SOAP_ACTION); - msn_soap_post(contact->soapconn,MSN_GLEAMS_TEMPLATE,msn_gleams_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,MSN_GET_GLEAMS_SOAP_ACTION, + MSN_GLEAMS_TEMPLATE, + msn_gleams_read_cb, + msn_gleams_written_cb); + msn_soap_post(contact->soapconn,soap_request); } /*************************************************************** @@ -620,8 +655,9 @@ /*add group*/ void msn_add_group(MsnSession *session,const char* group_name) { + MsnSoapReq *soap_request; + MsnContact *contact ; char *body = NULL; - MsnContact *contact ; g_return_if_fail(session != NULL); contact = session->contact; @@ -629,15 +665,18 @@ body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,group_name); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_GROUP_ADD_SOAP_ACTION); - msn_soap_post(contact->soapconn,body,msn_group_written_cb); - g_free(body); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_ADD_SOAP_ACTION, + body, + msn_group_read_cb, + msn_group_written_cb); + msn_soap_post(contact->soapconn,soap_request); } /*delete a group*/ void msn_del_group(MsnSession *session,const char *guid) { + MsnSoapReq *soap_request; MsnContact *contact; char *body = NULL; @@ -647,9 +686,13 @@ body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,guid); /*build SOAP and POST it*/ - contact->soapconn->login_path = g_strdup(MSN_ADDRESS_BOOK_POST_URL); - contact->soapconn->soap_action = g_strdup(MSN_GROUP_DEL_SOAP_ACTION); - msn_soap_post(contact->soapconn,body,msn_group_written_cb); + soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, + MSN_ADDRESS_BOOK_POST_URL,MSN_GROUP_DEL_SOAP_ACTION, + body, + msn_group_read_cb, + msn_group_written_cb); + msn_soap_post(contact->soapconn,soap_request); + g_free(body); } diff -r 2315ee828b7c -r 22eeb4882d77 src/protocols/msn/oim.c --- a/src/protocols/msn/oim.c Tue Aug 15 16:48:32 2006 +0000 +++ b/src/protocols/msn/oim.c Wed Aug 16 16:20:25 2006 +0000 @@ -109,7 +109,8 @@ void msn_oim_send_single_msg(MsnOim *oim,char * msg) { - const char *oimsoapbody,*t,*p; + MsnSoapReq *soap_request; + const char *soap_body,*t,*p; gaim_debug_info("MaYuan","send single OIM Message\n"); oim->sendconn->login_path = g_strdup(MSN_OIM_SEND_URL); @@ -128,8 +129,12 @@ msg ); #endif - msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_send_written_cb); - + soap_request = msn_soap_request_new(MSN_OIM_SEND_HOST, + MSN_OIM_SEND_URL,MSN_OIM_SEND_SOAP_ACTION, + soap_body, + msn_oim_send_read_cb, + msn_oim_send_written_cb); + msn_soap_post(oim->sendconn,soap_request); } void msn_oim_send_msg(MsnOim *oim,char *msg) @@ -234,7 +239,8 @@ static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid) { - const char *oimsoapbody,*t,*p; + MsnSoapReq *soap_request; + const char *soap_body,*t,*p; gaim_debug_info("MaYuan","Get single OIM Message\n"); oim->retrieveconn->login_path = g_strdup(MSN_OIM_RETRIEVE__URL); @@ -242,12 +248,17 @@ t = oim->session->passport_info.t; p = oim->session->passport_info.p; - oimsoapbody = g_strdup_printf(MSN_OIM_GET_TEMPLATE, + soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE, t, p, msgid ); - msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_get_written_cb); + soap_request = msn_soap_request_new(MSN_OIM_SEND_HOST, + MSN_OIM_SEND_URL,MSN_OIM_SEND_SOAP_ACTION, + soap_body, + msn_oim_get_read_cb, + msn_oim_get_written_cb); + msn_soap_post(oim->retrieveconn,soap_request); } /*MSN OIM get SOAP request*/ diff -r 2315ee828b7c -r 22eeb4882d77 src/protocols/msn/soap.c --- a/src/protocols/msn/soap.c Tue Aug 15 16:48:32 2006 +0000 +++ b/src/protocols/msn/soap.c Wed Aug 16 16:20:25 2006 +0000 @@ -41,6 +41,8 @@ soapconn->gsc = NULL; soapconn->input_handler = -1; soapconn->output_handler = -1; + + soapconn->soap_queue = g_queue_new(); return soapconn; } @@ -65,6 +67,9 @@ if(soapconn->connect_cb != NULL){ soapconn->connect_cb(data,gsc,cond); } + + /*we do the SOAP request here*/ + msn_soap_post_head_request(soapconn); } /*ssl soap error callback*/ @@ -90,6 +95,11 @@ soapconn->ssl_conn = ssl; soapconn->connect_cb = connect_cb; soapconn->error_cb = error_cb; +} + +void +msn_soap_connect(MsnSoapConn *soapconn) +{ if(soapconn->ssl_conn){ gaim_ssl_connect(soapconn->session->account, soapconn->login_host, GAIM_SSL_DEFAULT_PORT, msn_soap_connect_cb, msn_soap_error_cb, @@ -98,10 +108,24 @@ } } +void +msn_soap_close(MsnSoapConn *soapconn) +{ + if(soapconn->ssl_conn){ + if(soapconn->gsc != NULL){ + gaim_ssl_close(soapconn->gsc); + soapconn->gsc = NULL; + } + }else{ + } +} + /*destroy the soap connection*/ void msn_soap_destroy(MsnSoapConn *soapconn) { + MsnSoapReq *request; + if(soapconn->login_host) g_free(soapconn->login_host); @@ -120,11 +144,12 @@ msn_soap_free_write_buf(soapconn); /*close ssl connection*/ - if(soapconn->gsc != NULL){ - gaim_ssl_close(soapconn->gsc); + msn_soap_close(soapconn); + + while ((request = g_queue_pop_head(soapconn->soap_queue)) != NULL){ + msn_soap_request_free(request); } - soapconn->gsc = NULL; - + g_queue_free(soapconn->soap_queue); g_free(soapconn); } @@ -290,7 +315,7 @@ gaim_debug_misc("MaYuan","SOAP Read length :%d,body len:%d\n",soapconn->read_len,soapconn->body_len); if(soapconn->read_len < body_start - soapconn->read_buf + soapconn->body_len){ - return; + return; } g_free(body_len); @@ -302,8 +327,12 @@ /*call the read callback*/ if(soapconn->read_cb != NULL){ - soapconn->read_cb(soapconn,source,0); + soapconn->read_cb(soapconn,source,0); } + + /*Process the next queued SOAP request*/ + msn_soap_post_head_request(soapconn); + #if 0 /*clear the read buffer*/ msn_soap_free_read_buf(soapconn); @@ -404,16 +433,78 @@ msn_soap_write_cb(soapconn, soapconn->gsc->fd, GAIM_INPUT_WRITE); } -/*Post the soap action*/ +/* New a soap request*/ +MsnSoapReq * +msn_soap_request_new(const char *host,const char *post_url,const char *soap_action, + const char *body, + GaimInputFunction read_cb,GaimInputFunction written_cb) +{ + MsnSoapReq *request; + + request = g_new0(MsnSoapReq, 1); + request->id = 0; + + request->login_host = g_strdup(host); + request->login_path = g_strdup(post_url); + request->soap_action = g_strdup(soap_action); + request->body = g_strdup(body); + request->read_cb = read_cb; + request->written_cb = written_cb; + + return request; +} + +/*free a soap request*/ void -msn_soap_post(MsnSoapConn *soapconn,const char * body,GaimInputFunction written_cb) +msn_soap_request_free(MsnSoapReq *request) +{ + g_return_if_fail(request != NULL); + + g_free(request->login_host); + g_free(request->login_path); + g_free(request->soap_action); + g_free(request->body); + request->read_cb = NULL; + request->written_cb = NULL; + + g_free(request); +} + +void +msn_soap_post_head_request(MsnSoapConn *soapconn) +{ + 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); + } + } +} + +void +msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request) +{ + g_queue_push_tail(soapconn->soap_queue, request); + if(!msn_soap_connected(soapconn)){ + /*not connected?connect it first*/ + msn_soap_connect(soapconn); + return; + } + /*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... + */ +} + +/*Post the soap request action*/ +void +msn_soap_post_request(MsnSoapConn *soapconn,MsnSoapReq *request) { char * soap_head = NULL; - char * soap_body = NULL; char * request_str = NULL; gaim_debug_info("MaYuan","msn_soap_post()...\n"); - soap_body = g_strdup_printf(body); soap_head = g_strdup_printf( "POST %s HTTP/1.1\r\n" "SOAPAction: %s\r\n" @@ -425,21 +516,18 @@ "Content-Length: %d\r\n" "Connection: Keep-Alive\r\n" "Cache-Control: no-cache\r\n\r\n", - soapconn->login_path, - soapconn->soap_action, + request->login_path, + request->soap_action, soapconn->session->passport_info.mspauth, - soapconn->login_host, - strlen(soap_body) + request->login_host, + strlen(request->body) ); - request_str = g_strdup_printf("%s%s", soap_head,soap_body); - g_free(soapconn->login_path); - g_free(soapconn->soap_action); + request_str = g_strdup_printf("%s%s", soap_head,request->body); g_free(soap_head); - g_free(soap_body); /*free read buffer*/ msn_soap_free_read_buf(soapconn); gaim_debug_info("MaYuan","send to server{%s}\n",request_str); - msn_soap_write(soapconn,request_str,written_cb); + msn_soap_write(soapconn,request_str,request->written_cb); } diff -r 2315ee828b7c -r 22eeb4882d77 src/protocols/msn/soap.h --- a/src/protocols/msn/soap.h Tue Aug 15 16:48:32 2006 +0000 +++ b/src/protocols/msn/soap.h Wed Aug 16 16:20:25 2006 +0000 @@ -28,9 +28,26 @@ #define MSN_SOAP_READ_BUFF_SIZE 8192 +/*MSN SoapRequest structure*/ +typedef struct _MsnSoapReq MsnSoapReq; + /*MSN Https connection structure*/ typedef struct _MsnSoapConn MsnSoapConn; +struct _MsnSoapReq{ + /*request sequence*/ + int id; + + char *login_host; + char *login_path; + char *soap_action; + + char *body; + + GaimInputFunction read_cb; + GaimInputFunction written_cb; +}; + struct _MsnSoapConn{ MsnSession *session; gpointer parent; @@ -55,6 +72,10 @@ /*write handler*/ guint output_handler; + /*Queue of SOAP request to send*/ + int soap_id; + GQueue *soap_queue; + /*write buffer*/ char *write_buf; gsize written_len; @@ -71,6 +92,15 @@ }; /*Function Prototype*/ +/*Soap Request Function */ +MsnSoapReq * +msn_soap_request_new(const char *host,const char *post_url,const char *soap_action, + const char *body, + GaimInputFunction read_cb,GaimInputFunction written_cb); +void msn_soap_request_free(MsnSoapReq *request); +void msn_soap_post_request(MsnSoapConn *soapconn,MsnSoapReq *request); +void msn_soap_post_head_request(MsnSoapConn *soapconn); + /*new a soap conneciton */ MsnSoapConn *msn_soap_new(MsnSession *session,gpointer data,int sslconn); @@ -82,7 +112,7 @@ /*write to soap*/ void msn_soap_write(MsnSoapConn * soapconn, char *write_buf, GaimInputFunction written_cb); -void msn_soap_post(MsnSoapConn *soapconn,const char * body,GaimInputFunction written_cb); +void msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request); void msn_soap_free_read_buf(MsnSoapConn *soapconn); void msn_soap_free_write_buf(MsnSoapConn *soapconn);