/pidgin/main: 65f7a964bab1: HTTP: migrate purple_util_fetch_url_...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Fri Jul 5 06:10:53 EDT 2013
Changeset: 65f7a964bab1c7dddf9042d6c02000e9a5b5bcbe
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2013-07-05 12:10 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/65f7a964bab1
Description:
HTTP: migrate purple_util_fetch_url_request to new API for mxit prpl
diffstat:
libpurple/protocols/mxit/login.c | 164 ++++++++++++++++++-----------------
libpurple/protocols/mxit/markup.c | 1 -
libpurple/protocols/mxit/mxit.h | 1 -
libpurple/protocols/mxit/protocol.c | 97 +++++++++-----------
4 files changed, 128 insertions(+), 135 deletions(-)
diffs (truncated from 422 to 300 lines):
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
@@ -25,9 +25,9 @@
#include "internal.h"
#include "debug.h"
+#include "libpurple/http.h"
#include "request.h"
#include "version.h"
-#include "obsolete.h"
#include "protocol.h"
#include "mxit.h"
@@ -372,40 +372,41 @@ static void mxit_register_view( struct M
}
-/*------------------------------------------------------------------------
- * Callback function invoked once the Authorization information has been submitted
- * to the MXit WAP site.
+/**
+ * Callback function invoked once the Authorization information has been
+ * submitted to the MXit WAP site.
*
- * @param url_data libPurple internal object (see purple_util_fetch_url_request)
- * @param user_data The MXit session object
- * @param url_text The data returned from the WAP site
- * @param len The length of the data returned
- * @param error_message Descriptive error message
+ * @param http_conn See http.h.
+ * @param response See http.h.
+ * @param _session The mxit session.
*/
-static void mxit_cb_clientinfo2( PurpleUtilFetchUrlData* url_data, gpointer user_data, const gchar* url_text, gsize len, const gchar* error_message )
+static void
+mxit_cb_clientinfo2(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _session)
{
- struct MXitSession* session = (struct MXitSession*) user_data;
+ struct MXitSession *session = _session;
gchar** parts;
gchar** host;
int state;
purple_debug_info( MXIT_PLUGIN_ID, "mxit_clientinfo_cb2\n" );
-#ifdef DEBUG_PROTOCOL
- purple_debug_info( MXIT_PLUGIN_ID, "HTTP RESPONSE: '%s'\n", url_text );
-#endif
+ /* remove request from the async outstanding calls list */
+ session->async_http_reqs = g_slist_remove(session->async_http_reqs, http_conn);
- /* remove request from the async outstanding calls list */
- session->async_calls = g_slist_remove( session->async_calls, url_data );
-
- if ( !url_text ) {
+ if (!purple_http_response_is_successfull(response)) {
/* no reply from the WAP site */
purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Error contacting the MXit WAP site. Please try again later." ) );
return;
}
+#ifdef DEBUG_PROTOCOL
+ purple_debug_info(MXIT_PLUGIN_ID, "HTTP RESPONSE: '%s'\n",
+ purple_http_response_get_data(response, NULL));
+#endif
+
/* explode the response from the WAP site into an array */
- parts = g_strsplit( url_text, ";", 15 );
+ parts = g_strsplit(purple_http_response_get_data(response, NULL), ";", 15);
if ( !parts ) {
/* wapserver error */
@@ -516,13 +517,13 @@ static void free_logindata( struct login
*/
static void mxit_cb_captcha_ok( PurpleConnection* gc, PurpleRequestFields* fields )
{
+ PurpleHttpRequest *req;
+ PurpleHttpConnection *hc;
struct MXitSession* session = purple_connection_get_protocol_data( gc );
- PurpleUtilFetchUrlData* url_data;
PurpleRequestField* field;
const char* captcha_resp;
GList* entries;
GList* entry;
- char* url;
int state;
/* get the captcha response */
@@ -556,31 +557,25 @@ static void mxit_cb_captcha_ok( PurpleCo
/* get state */
state = purple_account_get_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN );
- url = g_strdup_printf( "%s?type=getpid&sessionid=%s&login=%s&ver=%i.%i.%i&clientid=%s&cat=%s&chalresp=%s&cc=%s&loc=%s&path=%i&brand=%s&model=%s&h=%i&w=%i&ts=%li",
- session->logindata->wapserver,
- session->logindata->sessionid,
- purple_url_encode( purple_account_get_username( session->acc ) ),
- PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_MICRO_VERSION,
- MXIT_CLIENT_ID,
- MXIT_CP_ARCH,
- 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( session->acc, url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, -1, 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 );
-#endif
- g_free( url );
+ req = purple_http_request_new(NULL);
+ purple_http_request_set_url_printf(req, "%s?type=getpid&sessionid=%s&"
+ "login=%s&ver=%i.%i.%i&clientid=%s&cat=%s&chalresp=%s&cc=%s&"
+ "loc=%s&path=%i&brand=%s&model=%s&h=%i&w=%i&ts=%li",
+ session->logindata->wapserver, session->logindata->sessionid,
+ purple_url_encode(purple_account_get_username(session->acc)),
+ PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION,
+ PURPLE_MICRO_VERSION, MXIT_CLIENT_ID, MXIT_CP_ARCH,
+ 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));
+ purple_http_request_header_set(req, "User-Agent", MXIT_HTTP_USERAGENT);
+ hc = purple_http_request(session->con, req, mxit_cb_clientinfo2,
+ session);
+ purple_http_request_unref(req);
+ session->async_http_reqs =
+ g_slist_prepend(session->async_http_reqs, hc);
/* free up the login resources */
free_logindata( session->logindata );
@@ -605,19 +600,20 @@ static void mxit_cb_captcha_cancel( Purp
}
-/*------------------------------------------------------------------------
+/**
* Callback function invoked once the client information has been retrieved from
- * the MXit WAP site. Display page where user can select their authorization information.
+ * the MXit WAP site. Display page where user can select their authorization
+ * information.
*
- * @param url_data libPurple internal object (see purple_util_fetch_url_request)
- * @param user_data The MXit session object
- * @param url_text The data returned from the WAP site
- * @param len The length of the data returned
- * @param error_message Descriptive error message
+ * @param http_conn See http.h.
+ * @param response See http.h.
+ * @param _session The mxit session data.
*/
-static void mxit_cb_clientinfo1( PurpleUtilFetchUrlData* url_data, gpointer user_data, const gchar* url_text, gsize len, const gchar* error_message )
+static void
+mxit_cb_clientinfo1(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _session)
{
- struct MXitSession* session = (struct MXitSession*) user_data;
+ struct MXitSession *session = _session;
struct login_data* logindata;
PurpleRequestFields* fields;
PurpleRequestFieldGroup* group = NULL;
@@ -630,20 +626,22 @@ static void mxit_cb_clientinfo1( PurpleU
purple_debug_info( MXIT_PLUGIN_ID, "mxit_clientinfo_cb1\n" );
#ifdef DEBUG_PROTOCOL
- purple_debug_info( MXIT_PLUGIN_ID, "RESPONSE: %s\n", url_text );
+ purple_debug_info( MXIT_PLUGIN_ID, "RESPONSE: %s\n",
+ purple_http_response_get_data(response, NULL));
#endif
/* remove request from the async outstanding calls list */
- session->async_calls = g_slist_remove( session->async_calls, url_data );
+ session->async_http_reqs = g_slist_remove(session->async_http_reqs,
+ http_conn);
- if ( !url_text ) {
+ if (!purple_http_response_is_successfull(response)) {
/* no reply from the WAP site */
purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Error contacting the MXit WAP site. Please try again later." ) );
return;
}
/* explode the response from the WAP site into an array */
- parts = g_strsplit( url_text, ";", 15 );
+ parts = g_strsplit(purple_http_response_get_data(response, NULL), ";", 15);
if ( ( !parts ) || ( parts[0][0] != '0' ) ) {
/* server could not find the user */
@@ -721,35 +719,39 @@ static void mxit_cb_clientinfo1( PurpleU
}
-/*------------------------------------------------------------------------
- * Initiate a request for the client information (distribution code, client key, etc)
- * required for logging in from the MXit WAP site.
+/**
+ * Initiate a request for the client information (distribution code, client
+ * key, etc) required for logging in from the MXit WAP site.
*
- * @param session The MXit session object
+ * @param session The MXit session object.
*/
-static void get_clientinfo( struct MXitSession* session )
+static void
+get_clientinfo(struct MXitSession* session)
{
- PurpleUtilFetchUrlData* url_data;
- const char* wapserver;
- char* url;
+ PurpleHttpRequest *req;
+ PurpleHttpConnection *hc;
+ const char *wapserver;
- purple_debug_info( MXIT_PLUGIN_ID, "get_clientinfo\n" );
+ purple_debug_info(MXIT_PLUGIN_ID, "get_clientinfo\n");
- purple_connection_update_progress( session->con, _( "Retrieving User Information..." ), 0, 4 );
+ purple_connection_update_progress(session->con,
+ _("Retrieving User Information..."), 0, 4);
- /* get the WAP site as was configured by the user in the advanced settings */
- wapserver = purple_account_get_string( session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE );
+ /* get the WAP site as was configured by the user in the advanced
+ * settings
+ */
+ wapserver = purple_account_get_string(session->acc,
+ MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE);
- /* 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( session->acc, url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, -1, 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 );
-#endif
- g_free( url );
+ req = purple_http_request_new(NULL);
+ purple_http_request_set_url_printf(req, "%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));
+ purple_http_request_header_set(req, "User-Agent", MXIT_HTTP_USERAGENT);
+ hc = purple_http_request(session->con, req, mxit_cb_clientinfo1, session);
+ purple_http_request_unref(req);
+ session->async_http_reqs = g_slist_prepend(session->async_http_reqs, hc);
}
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
@@ -26,7 +26,6 @@
#include "internal.h"
#include "debug.h"
#include "libpurple/http.h"
-#include "obsolete.h"
#include "protocol.h"
#include "mxit.h"
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
@@ -168,7 +168,6 @@ 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 */
GSList* async_http_reqs; /* list of current outstanding async http requests */
/* receive */
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
@@ -26,7 +26,6 @@
#include "internal.h"
#include "debug.h"
#include "version.h"
-#include "obsolete.h"
#include "protocol.h"
#include "mxit.h"
@@ -258,72 +257,70 @@ static int mxit_write_sock_packet( int f
}
-/*------------------------------------------------------------------------
+/**
* Callback called for handling a HTTP GET response
More information about the Commits
mailing list