/pidgin/main: 837d3061532b: MXit: Use the accessor functions wer...
Andrew Victor
andrew.victor at mxit.com
Fri Mar 29 19:03:44 EDT 2013
Changeset: 837d3061532b4b062533278bba7a45f66f4226aa
Author: Andrew Victor <andrew.victor at mxit.com>
Date: 2013-03-30 00:55 +0200
Branch: release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/837d3061532b
Description:
MXit: Use the accessor functions were available.
(ie, try keep the code similar to the 3.0.0 branch)
diffstat:
libpurple/protocols/mxit/actions.c | 18 +++++-----
libpurple/protocols/mxit/filexfer.c | 19 ++++++-----
libpurple/protocols/mxit/login.c | 51 ++++++++++++++++++++------------
libpurple/protocols/mxit/mxit.c | 26 +++++++---------
libpurple/protocols/mxit/roster.c | 22 +++++++-------
libpurple/protocols/mxit/splashscreen.c | 2 +-
libpurple/protocols/mxit/voicevideo.c | 2 +-
7 files changed, 74 insertions(+), 66 deletions(-)
diffs (truncated from 461 to 300 lines):
diff --git a/libpurple/protocols/mxit/actions.c b/libpurple/protocols/mxit/actions.c
--- a/libpurple/protocols/mxit/actions.c
+++ b/libpurple/protocols/mxit/actions.c
@@ -43,7 +43,7 @@
*/
static void mxit_profile_cb( PurpleConnection* gc, PurpleRequestFields* fields )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
PurpleRequestField* field = NULL;
const char* name = NULL;
const char* bday = NULL;
@@ -209,7 +209,7 @@ out:
static void mxit_profile_action( PurplePluginAction* action )
{
PurpleConnection* gc = (PurpleConnection*) action->context;
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
struct MXitProfile* profile = session->profile;
PurpleRequestFields* fields = NULL;
@@ -322,7 +322,7 @@ static void mxit_profile_action( PurpleP
*/
static void mxit_change_pin_cb( PurpleConnection* gc, PurpleRequestFields* fields )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
const char* pin = NULL;
const char* pin2 = NULL;
const char* err = NULL;
@@ -384,7 +384,7 @@ out:
static void mxit_change_pin_action( PurplePluginAction* action )
{
PurpleConnection* gc = (PurpleConnection*) action->context;
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
PurpleRequestFields* fields = NULL;
PurpleRequestFieldGroup* group = NULL;
@@ -397,12 +397,12 @@ static void mxit_change_pin_action( Purp
purple_request_fields_add_group(fields, group);
/* pin */
- field = purple_request_field_string_new( "pin", _( "PIN" ), session->acc->password, FALSE );
+ field = purple_request_field_string_new( "pin", _( "PIN" ), purple_account_get_password( session->acc ), FALSE );
purple_request_field_string_set_masked( field, TRUE );
purple_request_field_group_add_field( group, field );
/* verify pin */
- field = purple_request_field_string_new( "pin2", _( "Verify PIN" ), session->acc->password, FALSE );
+ field = purple_request_field_string_new( "pin2", _( "Verify PIN" ), purple_account_get_password( session->acc ), FALSE );
purple_request_field_string_set_masked( field, TRUE );
purple_request_field_group_add_field( group, field );
@@ -420,7 +420,7 @@ static void mxit_change_pin_action( Purp
static void mxit_splash_action( PurplePluginAction* action )
{
PurpleConnection* gc = (PurpleConnection*) action->context;
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
if ( splash_current( session ) != NULL )
splash_display( session );
@@ -457,7 +457,7 @@ static void mxit_about_action( PurplePlu
static void mxit_suggested_friends_action( PurplePluginAction* action )
{
PurpleConnection* gc = (PurpleConnection*) action->context;
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
const char* profilelist[] = {
CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR,
@@ -474,7 +474,7 @@ static void mxit_suggested_friends_actio
*/
static void mxit_user_search_cb( PurpleConnection *gc, const char *input )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
const char* profilelist[] = {
CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME, CP_PROFILE_FIRSTNAME,
CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_STATUS, CP_PROFILE_AVATAR,
diff --git a/libpurple/protocols/mxit/filexfer.c b/libpurple/protocols/mxit/filexfer.c
--- a/libpurple/protocols/mxit/filexfer.c
+++ b/libpurple/protocols/mxit/filexfer.c
@@ -126,7 +126,7 @@ static void mxit_xfer_init( PurpleXfer*
if ( purple_xfer_get_size( xfer ) > CP_MAX_FILESIZE ) {
/* the file is too big */
- purple_xfer_error( xfer->type, xfer->account, xfer->who, _( "The file you are trying to send is too large!" ) );
+ purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "The file you are trying to send is too large!" ) );
purple_xfer_cancel_local( xfer );
return;
}
@@ -151,6 +151,7 @@ static void mxit_xfer_init( PurpleXfer*
*/
static void mxit_xfer_start( PurpleXfer* xfer )
{
+ goffset filesize;
unsigned char* buffer;
int size;
int wrote;
@@ -163,10 +164,12 @@ static void mxit_xfer_start( PurpleXfer*
* a buffer and copy the file data into memory and then we can send it to
* the contact. we will send the whole file with one go.
*/
- buffer = g_malloc( xfer->bytes_remaining );
- size = fread( buffer, xfer->bytes_remaining, 1, xfer->dest_fp );
+ filesize = purple_xfer_get_bytes_remaining( xfer );
+ buffer = g_malloc( filesize );
+ size = fread( buffer, filesize, 1, xfer->dest_fp );
+ // TODO: If (size != 1) -> file read error
- wrote = purple_xfer_write( xfer, buffer, xfer->bytes_remaining );
+ wrote = purple_xfer_write( xfer, buffer, filesize );
if ( wrote > 0 )
purple_xfer_set_bytes_sent( xfer, wrote );
@@ -295,7 +298,7 @@ gboolean mxit_xfer_enabled( PurpleConnec
*/
PurpleXfer* mxit_xfer_new( PurpleConnection* gc, const char* who )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
PurpleXfer* xfer = NULL;
struct mxitxfer* mx = NULL;
@@ -395,7 +398,7 @@ static PurpleXfer* find_mxit_xfer( struc
while ( item ) {
xfer = item->data;
- if ( xfer->account == session->acc ) {
+ if ( purple_xfer_get_account( xfer ) == session->acc ) {
/* transfer is associated with this MXit account */
struct mxitxfer* mx = xfer->data;
@@ -424,19 +427,17 @@ static PurpleXfer* find_mxit_xfer( struc
void mxit_xfer_rx_file( struct MXitSession* session, const char* fileid, const char* data, int datalen )
{
PurpleXfer* xfer = NULL;
- struct mxitxfer* mx = NULL;
purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_rx_file: (size=%i)\n", datalen );
/* find the file-transfer object */
xfer = find_mxit_xfer( session, fileid );
if ( xfer ) {
- mx = xfer->data;
-
/* this is the transfer we have been looking for */
purple_xfer_ref( xfer );
purple_xfer_start( xfer, -1, NULL, 0 );
fwrite( data, datalen, 1, xfer->dest_fp );
+ // TODO: Handle error from fwrite()
purple_xfer_unref( xfer );
purple_xfer_set_completed( xfer, TRUE );
purple_xfer_end( xfer );
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
@@ -49,29 +49,27 @@ static void get_clientinfo( struct MXitS
*/
static struct MXitSession* mxit_create_object( PurpleAccount* account )
{
+ PurpleConnection* con = purple_account_get_connection( account );
struct MXitSession* session = NULL;
- PurpleConnection* con = NULL;
/* currently the wapsite does not handle a '+' in front of the username (mxitid) so we just strip it */
- if ( account->username[0] == '+' ) {
- char* fixed;
+ {
+ const char* username = purple_account_get_username( account );
- /* cut off the '+' */
- fixed = g_strdup( &account->username[1] );
- purple_account_set_username( account, fixed );
- g_free( fixed );
+ if ( username[0] == '+' ) {
+ char* fixed = g_strdup( &username[1] );
+ purple_account_set_username( account, fixed );
+ g_free( fixed );
+ }
}
session = g_new0( struct MXitSession, 1 );
+ session->con = con;
+ session->acc = account;
/* configure the connection (reference: "libpurple/connection.h") */
- con = purple_account_get_connection( account );
- con->proto_data = session;
+ purple_connection_set_protocol_data( con, session );
con->flags |= PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_SUPPORT_MOODS;
- session->con = con;
-
- /* add account */
- session->acc = account;
/* configure the session (reference: "libpurple/account.h") */
g_strlcpy( session->server, purple_account_get_string( account, MXIT_CONFIG_SERVER_ADDR, DEFAULT_SERVER ), sizeof( session->server ) );
@@ -221,7 +219,7 @@ static void mxit_login_connect( struct M
*/
static void mxit_cb_register_ok( PurpleConnection *gc, PurpleRequestFields *fields )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
struct MXitProfile* profile = session->profile;
const char* str;
const char* pin;
@@ -303,7 +301,7 @@ static void mxit_cb_register_cancel( Pur
purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_register_cancel\n" );
/* disconnect */
- purple_account_disconnect( gc->account );
+ purple_account_disconnect( purple_connection_get_account( gc ) );
}
@@ -510,7 +508,7 @@ static void free_logindata( struct login
*/
static void mxit_cb_captcha_ok( PurpleConnection* gc, PurpleRequestFields* fields )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
PurpleUtilFetchUrlData* url_data;
PurpleRequestField* field;
const char* captcha_resp;
@@ -551,9 +549,22 @@ static void mxit_cb_captcha_ok( PurpleCo
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( session->acc->username ), 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 ) );
+ 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( 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 );
@@ -576,7 +587,7 @@ static void mxit_cb_captcha_ok( PurpleCo
*/
static void mxit_cb_captcha_cancel( PurpleConnection* gc, PurpleRequestFields* fields )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
/* free up the login resources */
free_logindata( session->logindata );
diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -316,9 +316,9 @@ char* mxit_status_text( PurpleBuddy* bud
return NULL;
if ( contact->statusMsg ) /* status message */
- return g_strdup( contact-> statusMsg );
+ text = g_strdup( contact-> statusMsg );
else if ( contact->mood != MXIT_MOOD_NONE ) /* mood */
- return g_strdup( mxit_convert_mood_to_name( contact->mood ) );
+ text = g_strdup( mxit_convert_mood_to_name( contact->mood ) );
return text;
}
@@ -367,7 +367,7 @@ static void mxit_tooltip( PurpleBuddy* b
*/
static void mxit_close( PurpleConnection* gc )
{
- struct MXitSession* session = (struct MXitSession*) gc->proto_data;
+ struct MXitSession* session = purple_connection_get_protocol_data( gc );
/* disable signals */
mxit_disable_signals( session );
@@ -403,7 +403,7 @@ static int mxit_send_im( PurpleConnectio
{
purple_debug_info( MXIT_PLUGIN_ID, "Sending message '%s' to buddy '%s'\n", message, who );
- mxit_send_message( gc->proto_data, who, message, TRUE, FALSE );
+ mxit_send_message( purple_connection_get_protocol_data( gc ), who, message, TRUE, FALSE );
return 1; /* echo to conversation window */
}
@@ -417,7 +417,7 @@ static int mxit_send_im( PurpleConnectio
*/
static void mxit_set_status( PurpleAccount* account, PurpleStatus* status )
{
- struct MXitSession* session = purple_account_get_connection( account )->proto_data;
More information about the Commits
mailing list