/pidgin/main: 094a4b10e8d5: Maintain list of outstanding async c...

Pieter Loubser pieter.loubser at mxit.com
Tue Mar 5 08:36:46 EST 2013


Changeset: 094a4b10e8d5f9eabb2d1512e432b9343a3f0e8f
Author:	 Pieter Loubser <pieter.loubser at mxit.com>
Date:	 2013-03-05 15:36 +0200
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/094a4b10e8d5

Description:

Maintain list of outstanding async calls made so that it can be canceled when the account is disconnected.

CID 732140 - markup.c:634
CID 732139 - login.c:554
CID 732138 - login.c:718
CID 732137 - http.c:330

diffstat:

 libpurple/protocols/mxit/http.c     |   3 +++
 libpurple/protocols/mxit/login.c    |  10 ++++++++++
 libpurple/protocols/mxit/markup.c   |   6 ++++++
 libpurple/protocols/mxit/mxit.h     |   2 +-
 libpurple/protocols/mxit/protocol.c |  15 +++++++++------
 5 files changed, 29 insertions(+), 7 deletions(-)

diffs (141 lines):

diff --git a/libpurple/protocols/mxit/http.c b/libpurple/protocols/mxit/http.c
--- a/libpurple/protocols/mxit/http.c
+++ b/libpurple/protocols/mxit/http.c
@@ -328,5 +328,8 @@ void mxit_http_send_request( struct MXit
 
 	/* open connection to the HTTP server */
 	con = purple_proxy_connect( NULL, session->acc, host, port, mxit_cb_http_connect, req );
+	if ( !con ) {
+		purple_connection_error_reason( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Unable to connect" ) );
+	}
 }
 
diff --git a/libpurple/protocols/mxit/login.c b/libpurple/protocols/mxit/login.c
--- a/libpurple/protocols/mxit/login.c
+++ b/libpurple/protocols/mxit/login.c
@@ -389,6 +389,9 @@ static void mxit_cb_clientinfo2( PurpleU
 	purple_debug_info( MXIT_PLUGIN_ID, "HTTP RESPONSE: '%s'\n", url_text );
 #endif
 
+	/* remove request from the async outstanding calls list */
+	session->async_calls = g_slist_remove( session->async_calls, url_data );
+
 	if ( !url_text ) {
 		/* no reply from the WAP site */
 		purple_connection_error( session->con, _( "Error contacting the MXit WAP site. Please try again later." ) );
@@ -552,6 +555,8 @@ static void mxit_cb_captcha_ok( PurpleCo
 			captcha_resp, session->logindata->cc, session->logindata->locale, ( state == MXIT_STATE_REGISTER1 ) ? 0 : 1, MXIT_CP_PLATFORM, MXIT_CP_OS,
 			MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH, time( NULL ) );
 	url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_clientinfo2, session );
+	if ( url_data )
+		session->async_calls = g_slist_prepend( session->async_calls, url_data );
 
 #ifdef	DEBUG_PROTOCOL
 	purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url );
@@ -609,6 +614,9 @@ static void mxit_cb_clientinfo1( PurpleU
 	purple_debug_info( MXIT_PLUGIN_ID, "RESPONSE: %s\n", url_text );
 #endif
 
+	/* remove request from the async outstanding calls list */
+	session->async_calls = g_slist_remove( session->async_calls, url_data );
+
 	if ( !url_text ) {
 		/* no reply from the WAP site */
 		purple_connection_error( session->con, _( "Error contacting the MXit WAP site. Please try again later." ) );
@@ -716,6 +724,8 @@ static void get_clientinfo( struct MXitS
 	/* reference: "libpurple/util.h" */
 	url = g_strdup_printf( "%s/res/?type=challenge&getcountries=true&getlanguage=true&getimage=true&h=%i&w=%i&ts=%li", wapserver, MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH, time( NULL ) );
 	url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_clientinfo1, session );
+	if ( url_data )
+		session->async_calls = g_slist_prepend( session->async_calls, url_data );
 
 #ifdef	DEBUG_PROTOCOL
 	purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url );
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -487,6 +487,9 @@ static void emoticon_returned( PurpleUti
 	purple_debug_info( MXIT_PLUGIN_ID, "emoticon_returned\n" );
 #endif
 
+	/* remove request from the async outstanding calls list */
+	mx->session->async_calls = g_slist_remove( mx->session->async_calls, url_data );
+
 	if ( !url_text ) {
 		/* no reply from the WAP site */
 		purple_debug_error( MXIT_PLUGIN_ID, "Error contacting the MXit WAP site. Please try again later (emoticon).\n" );
@@ -632,6 +635,9 @@ static void emoticon_request( struct RXM
 	/* reference: "libpurple/util.h" */
 	url = g_strdup_printf( "%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver, MXIT_EMOTICON_SIZE, id, time( NULL ) );
 	url_data = purple_util_fetch_url_request( url, TRUE, NULL, TRUE, NULL, FALSE, emoticon_returned, mx );
+	if ( url_data )
+		mx->session->async_calls = g_slist_prepend( mx->session->async_calls, url_data );
+
 	g_free( url );
 }
 
diff --git a/libpurple/protocols/mxit/mxit.h b/libpurple/protocols/mxit/mxit.h
--- a/libpurple/protocols/mxit/mxit.h
+++ b/libpurple/protocols/mxit/mxit.h
@@ -141,7 +141,6 @@ struct MXitSession {
 	int					http_interval;				/* poll inverval */
 	gint64				http_last_poll;				/* the last time a poll has been sent */
 	guint				http_handler;				/* HTTP connection handler */
-	void*				http_out_req;				/* HTTP outstanding request */
 
 	/* other servers */
 	char				voip_server[HOST_NAME_MAX];	/* voice/video server */
@@ -168,6 +167,7 @@ struct MXitSession {
 	int					outack;						/* outstanding ack packet */
 	guint				q_slow_timer_id;			/* timer handle for slow tx queue */
 	guint				q_fast_timer_id;			/* timer handle for fast tx queue */
+	GSList*				async_calls;				/* list of current outstanding async calls */
 
 	/* receive */
 	char				rx_lbuf[16];				/* receive byte buffer (socket packet length) */
diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -267,7 +267,7 @@ static void mxit_cb_http_rx( PurpleUtilF
 	struct MXitSession*		session		= (struct MXitSession*) user_data;
 
 	/* clear outstanding request */
-	session->http_out_req = NULL;
+	session->async_calls = g_slist_remove( session->async_calls, url_data );
 
 	if ( ( !url_text ) || ( len == 0 ) ) {
 		/* error with request */
@@ -293,6 +293,7 @@ static void mxit_cb_http_rx( PurpleUtilF
  */
 static void mxit_write_http_get( struct MXitSession* session, struct tx_packet* packet )
 {
+	PurpleUtilFetchUrlData*	url_data;
 	char*		part	= NULL;
 	char*		url		= NULL;
 
@@ -311,7 +312,9 @@ static void mxit_write_http_get( struct 
 #endif
 
 	/* send the HTTP request */
-	session->http_out_req = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_http_rx, session );
+	url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_http_rx, session );
+	if ( url_data )
+		session->async_calls = g_slist_prepend( session->async_calls, url_data );
 
 	g_free( url );
 	if ( part )
@@ -2873,10 +2876,10 @@ void mxit_close_connection( struct MXitS
 	}
 	session->flags &= ~MXIT_FLAG_CONNECTED;
 
-	/* cancel outstanding HTTP request */
-	if ( ( session->http ) && ( session->http_out_req ) ) {
-		purple_util_fetch_url_cancel( (PurpleUtilFetchUrlData*) session->http_out_req );
-		session->http_out_req = NULL;
+	/* cancel all outstanding async calls */
+	while ( session->async_calls ) {
+		purple_util_fetch_url_cancel( session->async_calls->data );
+		session->async_calls = g_slist_delete_link(session->async_calls, session->async_calls);
 	}
 
 	/* remove the input cb function */



More information about the Commits mailing list