/*------------------------------------------------------------------------ * 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 ); } }
/*------------------------------------------------------------------------ * Create a new mxit session object * * @return The MXit session object */ static struct MXitSession* mxit_create_object( PurpleAccount* account ) { PurpleConnection* con = purple_account_get_connection( account ); struct MXitSession* session = NULL; /* currently the wapsite does not handle a '+' in front of the username (mxitid) so we just strip it */ { const char* username = purple_account_get_username( account ); 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") */ purple_connection_set_protocol_data( con, session ); purple_connection_set_flags( con, PURPLE_CONNECTION_FLAG_NO_BGCOLOR | PURPLE_CONNECTION_FLAG_NO_URLDESC | PURPLE_CONNECTION_FLAG_HTML | PURPLE_CONNECTION_FLAG_SUPPORT_MOODS ); /* 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 ) ); g_strlcpy( session->http_server, purple_account_get_string( account, MXIT_CONFIG_HTTPSERVER, DEFAULT_HTTP_SERVER ), sizeof( session->http_server ) ); session->port = purple_account_get_int( account, MXIT_CONFIG_SERVER_PORT, DEFAULT_PORT ); g_strlcpy( session->distcode, purple_account_get_string( account, MXIT_CONFIG_DISTCODE, "" ), sizeof( session->distcode ) ); g_strlcpy( session->clientkey, purple_account_get_string( account, MXIT_CONFIG_CLIENTKEY, "" ), sizeof( session->clientkey ) ); g_strlcpy( session->dialcode, purple_account_get_string( account, MXIT_CONFIG_DIALCODE, "" ), sizeof( session->dialcode ) ); session->http = purple_account_get_bool( account, MXIT_CONFIG_USE_HTTP, FALSE ); session->iimages = g_hash_table_new( g_str_hash, g_str_equal ); session->rx_state = RX_STATE_RLEN; session->http_interval = MXIT_HTTP_POLL_MIN; session->http_last_poll = mxit_now_milli(); session->async_http_reqs = purple_http_connection_set_new(); return session; }
/*------------------------------------------------------------------------ * Periodic task called every KEEPALIVE_INTERVAL (30 sec) to to maintain * idle connections, timeouts and the transmission queue to the MXit server. * * @param gc The connection object */ static void mxit_keepalive( PurpleConnection *gc ) { struct MXitSession* session = purple_connection_get_protocol_data( gc ); /* if not logged in, there is nothing to do */ if ( !( session->flags & MXIT_FLAG_LOGGEDIN ) ) return; /* pinging is only for socket connections (HTTP does polling) */ if ( session->http ) return; if ( session->last_tx <= ( mxit_now_milli() - ( MXIT_PING_INTERVAL * 1000 ) ) ) { /* * this connection has been idle for too long, better ping * the server before it kills our connection. */ mxit_send_ping( session ); } }