Mercurial > pidgin
comparison libpurple/protocols/mxit/login.c @ 32672:3828a61c44da
A boring and large patch so I can merge heads.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 23 Dec 2011 08:21:58 +0000 |
parents | e8d4755ef84b |
children |
comparison
equal
deleted
inserted
replaced
32671:0e69949b3e61 | 32672:3828a61c44da |
---|---|
47 * | 47 * |
48 * @return The MXit session object | 48 * @return The MXit session object |
49 */ | 49 */ |
50 static struct MXitSession* mxit_create_object( PurpleAccount* account ) | 50 static struct MXitSession* mxit_create_object( PurpleAccount* account ) |
51 { | 51 { |
52 PurpleConnection* con = purple_account_get_connection( account ); | |
52 struct MXitSession* session = NULL; | 53 struct MXitSession* session = NULL; |
53 PurpleConnection* con = NULL; | |
54 | 54 |
55 /* currently the wapsite does not handle a '+' in front of the username (mxitid) so we just strip it */ | 55 /* currently the wapsite does not handle a '+' in front of the username (mxitid) so we just strip it */ |
56 if ( account->username[0] == '+' ) { | 56 { |
57 char* fixed; | 57 const char* username = purple_account_get_username( account ); |
58 | 58 |
59 /* cut off the '+' */ | 59 if ( username[0] == '+' ) { |
60 fixed = g_strdup( &account->username[1] ); | 60 char* fixed = g_strdup( &username[1] ); |
61 purple_account_set_username( account, fixed ); | 61 purple_account_set_username( account, fixed ); |
62 g_free( fixed ); | 62 g_free( fixed ); |
63 } | |
63 } | 64 } |
64 | 65 |
65 session = g_new0( struct MXitSession, 1 ); | 66 session = g_new0( struct MXitSession, 1 ); |
67 session->con = con; | |
68 session->acc = account; | |
66 | 69 |
67 /* configure the connection (reference: "libpurple/connection.h") */ | 70 /* configure the connection (reference: "libpurple/connection.h") */ |
68 con = purple_account_get_connection( account ); | 71 purple_connection_set_protocol_data( con, session ); |
69 con->proto_data = session; | 72 purple_connection_set_flags( con, |
70 con->flags |= PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_SUPPORT_MOODS; | 73 PURPLE_CONNECTION_NO_BGCOLOR |
71 session->con = con; | 74 | PURPLE_CONNECTION_NO_URLDESC |
72 | 75 | PURPLE_CONNECTION_HTML |
73 /* add account */ | 76 | PURPLE_CONNECTION_SUPPORT_MOODS |
74 session->acc = account; | 77 ); |
75 | 78 |
76 /* configure the session (reference: "libpurple/account.h") */ | 79 /* configure the session (reference: "libpurple/account.h") */ |
77 g_strlcpy( session->server, purple_account_get_string( account, MXIT_CONFIG_SERVER_ADDR, DEFAULT_SERVER ), sizeof( session->server ) ); | 80 g_strlcpy( session->server, purple_account_get_string( account, MXIT_CONFIG_SERVER_ADDR, DEFAULT_SERVER ), sizeof( session->server ) ); |
78 g_strlcpy( session->http_server, purple_account_get_string( account, MXIT_CONFIG_HTTPSERVER, DEFAULT_HTTP_SERVER ), sizeof( session->http_server ) ); | 81 g_strlcpy( session->http_server, purple_account_get_string( account, MXIT_CONFIG_HTTPSERVER, DEFAULT_HTTP_SERVER ), sizeof( session->http_server ) ); |
79 session->port = purple_account_get_int( account, MXIT_CONFIG_SERVER_PORT, DEFAULT_PORT ); | 82 session->port = purple_account_get_int( account, MXIT_CONFIG_SERVER_PORT, DEFAULT_PORT ); |
171 | 174 |
172 /* we now have an open and active TCP connection to the mxit server */ | 175 /* we now have an open and active TCP connection to the mxit server */ |
173 session->fd = source; | 176 session->fd = source; |
174 | 177 |
175 /* start listening on the open connection for messages from the server (reference: "libpurple/eventloop.h") */ | 178 /* start listening on the open connection for messages from the server (reference: "libpurple/eventloop.h") */ |
176 session->con->inpa = purple_input_add( session->fd, PURPLE_INPUT_READ, mxit_cb_rx, session ); | 179 session->inpa = purple_input_add( session->fd, PURPLE_INPUT_READ, mxit_cb_rx, session ); |
177 | 180 |
178 mxit_connected( session ); | 181 mxit_connected( session ); |
179 } | 182 } |
180 | 183 |
181 | 184 |
219 * @param gc The connection object | 222 * @param gc The connection object |
220 * @param fields This is the fields filled-in by the user | 223 * @param fields This is the fields filled-in by the user |
221 */ | 224 */ |
222 static void mxit_cb_register_ok( PurpleConnection *gc, PurpleRequestFields *fields ) | 225 static void mxit_cb_register_ok( PurpleConnection *gc, PurpleRequestFields *fields ) |
223 { | 226 { |
224 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 227 struct MXitSession* session = purple_connection_get_protocol_data( gc ); |
225 struct MXitProfile* profile = session->profile; | 228 struct MXitProfile* profile = session->profile; |
226 const char* str; | 229 const char* str; |
227 const char* pin; | 230 const char* pin; |
228 const char* err = NULL; | 231 const char* err = NULL; |
229 int len; | 232 int len; |
301 static void mxit_cb_register_cancel( PurpleConnection *gc, PurpleRequestFields *fields ) | 304 static void mxit_cb_register_cancel( PurpleConnection *gc, PurpleRequestFields *fields ) |
302 { | 305 { |
303 purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_register_cancel\n" ); | 306 purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_register_cancel\n" ); |
304 | 307 |
305 /* disconnect */ | 308 /* disconnect */ |
306 purple_account_disconnect( gc->account ); | 309 purple_account_disconnect( purple_connection_get_account( gc ) ); |
307 } | 310 } |
308 | 311 |
309 | 312 |
310 /*------------------------------------------------------------------------ | 313 /*------------------------------------------------------------------------ |
311 * Show a window to the user so that he can enter his information | 314 * Show a window to the user so that he can enter his information |
505 * @param gc The connection object | 508 * @param gc The connection object |
506 * @param fields The list of fields in the accepted form | 509 * @param fields The list of fields in the accepted form |
507 */ | 510 */ |
508 static void mxit_cb_captcha_ok( PurpleConnection* gc, PurpleRequestFields* fields ) | 511 static void mxit_cb_captcha_ok( PurpleConnection* gc, PurpleRequestFields* fields ) |
509 { | 512 { |
510 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 513 struct MXitSession* session = purple_connection_get_protocol_data( gc ); |
511 PurpleUtilFetchUrlData* url_data; | 514 PurpleUtilFetchUrlData* url_data; |
512 PurpleRequestField* field; | 515 PurpleRequestField* field; |
513 const char* captcha_resp; | 516 const char* captcha_resp; |
514 GList* entries; | 517 GList* entries; |
515 GList* entry; | 518 GList* entry; |
546 | 549 |
547 /* get state */ | 550 /* get state */ |
548 state = purple_account_get_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN ); | 551 state = purple_account_get_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN ); |
549 | 552 |
550 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", | 553 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", |
551 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, | 554 session->logindata->wapserver, |
552 captcha_resp, session->logindata->cc, session->logindata->locale, ( state == MXIT_STATE_REGISTER1 ) ? 0 : 1, MXIT_CP_PLATFORM, MXIT_CP_OS, | 555 session->logindata->sessionid, |
553 MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH, time( NULL ) ); | 556 purple_url_encode( purple_account_get_username( session->acc ) ), |
554 url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_clientinfo2, session ); | 557 PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_MICRO_VERSION, |
558 MXIT_CLIENT_ID, | |
559 MXIT_CP_ARCH, | |
560 captcha_resp, | |
561 session->logindata->cc, | |
562 session->logindata->locale, | |
563 ( state == MXIT_STATE_REGISTER1 ) ? 0 : 1, | |
564 MXIT_CP_PLATFORM, | |
565 MXIT_CP_OS, | |
566 MXIT_CAPTCHA_HEIGHT, | |
567 MXIT_CAPTCHA_WIDTH, | |
568 time( NULL ) | |
569 ); | |
570 /* FIXME: This should be cancelled somewhere if not needed. */ | |
571 url_data = purple_util_fetch_url_request( session->acc, url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, -1, mxit_cb_clientinfo2, session ); | |
555 | 572 |
556 #ifdef DEBUG_PROTOCOL | 573 #ifdef DEBUG_PROTOCOL |
557 purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url ); | 574 purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url ); |
558 #endif | 575 #endif |
559 g_free( url ); | 576 g_free( url ); |
569 * @param gc The connection object | 586 * @param gc The connection object |
570 * @param fields The list of fields in the cancelled form | 587 * @param fields The list of fields in the cancelled form |
571 */ | 588 */ |
572 static void mxit_cb_captcha_cancel( PurpleConnection* gc, PurpleRequestFields* fields ) | 589 static void mxit_cb_captcha_cancel( PurpleConnection* gc, PurpleRequestFields* fields ) |
573 { | 590 { |
574 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 591 struct MXitSession* session = purple_connection_get_protocol_data( gc ); |
575 | 592 |
576 /* free up the login resources */ | 593 /* free up the login resources */ |
577 free_logindata( session->logindata ); | 594 free_logindata( session->logindata ); |
578 | 595 |
579 /* we cannot continue, so we disconnect this account */ | 596 /* we cannot continue, so we disconnect this account */ |
656 country = g_strsplit( countries[i], "|", 2 ); | 673 country = g_strsplit( countries[i], "|", 2 ); |
657 if ( !country ) { | 674 if ( !country ) { |
658 /* oops, this is not good, time to bail */ | 675 /* oops, this is not good, time to bail */ |
659 break; | 676 break; |
660 } | 677 } |
661 purple_request_field_list_add( field, country[1], g_strdup( country[0] ) ); | 678 purple_request_field_list_add_icon( field, country[1], NULL, g_strdup( country[0] ) ); |
662 if ( strcmp( country[1], parts[6] ) == 0 ) { | 679 if ( strcmp( country[1], parts[6] ) == 0 ) { |
663 /* based on the user's IP, this is his current country code, so we default to it */ | 680 /* based on the user's IP, this is his current country code, so we default to it */ |
664 purple_request_field_list_add_selected( field, country[1] ); | 681 purple_request_field_list_add_selected( field, country[1] ); |
665 } | 682 } |
666 g_strfreev( country ); | 683 g_strfreev( country ); |
677 locale = g_strsplit( locales[i], "|", 2 ); | 694 locale = g_strsplit( locales[i], "|", 2 ); |
678 if ( !locale ) { | 695 if ( !locale ) { |
679 /* oops, this is not good, time to bail */ | 696 /* oops, this is not good, time to bail */ |
680 break; | 697 break; |
681 } | 698 } |
682 purple_request_field_list_add( field, locale[1], g_strdup( locale[0] ) ); | 699 purple_request_field_list_add_icon( field, locale[1], NULL, g_strdup( locale[0] ) ); |
683 g_strfreev( locale ); | 700 g_strfreev( locale ); |
684 } | 701 } |
685 purple_request_field_list_add_selected( field, "English" ); | 702 purple_request_field_list_add_selected( field, "English" ); |
686 purple_request_field_group_add_field( group, field ); | 703 purple_request_field_group_add_field( group, field ); |
687 | 704 |
713 /* get the WAP site as was configured by the user in the advanced settings */ | 730 /* get the WAP site as was configured by the user in the advanced settings */ |
714 wapserver = purple_account_get_string( session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE ); | 731 wapserver = purple_account_get_string( session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE ); |
715 | 732 |
716 /* reference: "libpurple/util.h" */ | 733 /* reference: "libpurple/util.h" */ |
717 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 ) ); | 734 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 ) ); |
718 url_data = purple_util_fetch_url_request( url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, mxit_cb_clientinfo1, session ); | 735 /* FIXME: This should be cancelled somewhere if not needed. */ |
736 url_data = purple_util_fetch_url_request( session->acc, url, TRUE, MXIT_HTTP_USERAGENT, TRUE, NULL, FALSE, -1, mxit_cb_clientinfo1, session ); | |
719 | 737 |
720 #ifdef DEBUG_PROTOCOL | 738 #ifdef DEBUG_PROTOCOL |
721 purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url ); | 739 purple_debug_info( MXIT_PLUGIN_ID, "HTTP REQUEST: '%s'\n", url ); |
722 #endif | 740 #endif |
723 g_free( url ); | 741 g_free( url ); |
762 void mxit_reconnect( struct MXitSession* session ) | 780 void mxit_reconnect( struct MXitSession* session ) |
763 { | 781 { |
764 purple_debug_info( MXIT_PLUGIN_ID, "mxit_reconnect\n" ); | 782 purple_debug_info( MXIT_PLUGIN_ID, "mxit_reconnect\n" ); |
765 | 783 |
766 /* remove the input cb function */ | 784 /* remove the input cb function */ |
767 if ( session->con->inpa ) { | 785 if ( session->inpa ) { |
768 purple_input_remove( session->con->inpa ); | 786 purple_input_remove( session->inpa ); |
769 session->con->inpa = 0; | 787 session->inpa = 0; |
770 } | 788 } |
771 | 789 |
772 /* close existing connection */ | 790 /* close existing connection */ |
773 session->flags &= ~MXIT_FLAG_CONNECTED; | 791 session->flags &= ~MXIT_FLAG_CONNECTED; |
774 purple_proxy_connect_cancel_with_handle( session->con ); | 792 purple_proxy_connect_cancel_with_handle( session->con ); |