/*------------------------------------------------------------------------ * The user has selected to change their PIN. * * @param gc The connection object * @param fields The fields from the request pop-up */ static void mxit_change_pin_cb( PurpleConnection* gc, PurpleRequestFields* fields ) { struct MXitSession* session = purple_connection_get_protocol_data( gc ); const char* pin = NULL; const char* pin2 = NULL; const char* err = NULL; int len; int i; PURPLE_ASSERT_CONNECTION_IS_VALID(gc); /* validate pin */ pin = purple_request_fields_get_string( fields, "pin" ); if ( !pin ) { err = _( "The PIN you entered is invalid." ); goto out; } len = strlen( pin ); if ( ( len < 4 ) || ( len > 10 ) ) { err = _( "The PIN you entered has an invalid length [4-10]." ); goto out; } for ( i = 0; i < len; i++ ) { if ( !g_ascii_isdigit( pin[i] ) ) { err = _( "The PIN is invalid. It should only consist of digits [0-9]." ); goto out; } } pin2 = purple_request_fields_get_string( fields, "pin2" ); if ( ( !pin2 ) || ( strcmp( pin, pin2 ) != 0 ) ) { err = _( "The two PINs you entered do not match." ); goto out; } out: if ( !err ) { /* update PIN in account */ purple_account_set_password( session->acc, pin, NULL, NULL ); /* update session object */ g_free( session->encpwd ); session->encpwd = mxit_encrypt_password( session ); /* send the update request to MXit */ mxit_send_extprofile_update( session, session->encpwd, 0, NULL ); } else { /* show error to user */ mxit_popup( PURPLE_NOTIFY_MSG_ERROR, _( "PIN Update Error" ), err ); } }
/*------------------------------------------------------------------------ * We now have a connection established with MXit, so we can start the * login procedure * * @param session The MXit session object */ static void mxit_connected( struct MXitSession* session ) { int state; purple_debug_info( MXIT_PLUGIN_ID, "mxit_connected\n" ); session->flags |= MXIT_FLAG_CONNECTED; purple_connection_update_progress( session->con, _( "Logging In..." ), 2, 4 ); /* create a timer to send a ping packet if the connection is idle */ session->last_tx = mxit_now_milli(); /* encrypt the user password */ session->encpwd = mxit_encrypt_password( session ); state = purple_account_get_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN ); if ( state == MXIT_STATE_LOGIN ) { /* create and send login packet */ mxit_send_login( session ); } else { if ( !session->profile ) { /* we have lost the session profile, so ask the user to enter it again */ mxit_register_view( session ); } else { /* create and send the register packet */ mxit_send_register( session ); } } /* enable signals */ mxit_enable_signals( session ); #ifdef MXIT_LINK_CLICK /* register for uri click notification */ mxit_register_uri_handler(); #endif /* start the polling if this is a HTTP connection */ if ( session->http ) { session->http_timer_id = purple_timeout_add_seconds( 2, mxit_manage_polling, session ); } /* This timer might already exist if we're registering a new account */ if ( session->q_slow_timer_id == 0 ) { /* start the tx queue manager timer */ session->q_slow_timer_id = purple_timeout_add_seconds( 2, mxit_manage_queue_slow, session ); } }