Changeset ca7de3a


Ignore:
Timestamp:
2010-08-12T22:13:26Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
be7a180
Parents:
7f34ce2
Message:

Successful login (including contact list sync). \o/

Location:
protocols/msn
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    r7f34ce2 rca7de3a  
    6868        md->ic = ic;
    6969        md->away_state = msn_away_state_list;
     70        md->domaintree = g_tree_new( msn_domaintree_cmp );
    7071       
    7172        msn_connections = g_slist_append( msn_connections, ic );
     
    106107                g_free( md->tokens[1] );
    107108                g_free( md->lock_key );
     109               
     110                g_tree_destroy( md->domaintree );
     111                md->domaintree = NULL;
    108112               
    109113                while( md->grpq )
     
    336340static void msn_buddy_data_add( bee_user_t *bu )
    337341{
     342        struct msn_data *md = bu->ic->proto_data;
    338343        bu->data = g_new0( struct msn_buddy_data, 1 );
     344        g_tree_insert( md->domaintree, bu->handle, bu );
    339345}
    340346
    341347static void msn_buddy_data_free( bee_user_t *bu )
    342348{
     349        struct msn_data *md = bu->ic->proto_data;
     350        g_tree_remove( md->domaintree, bu->handle );
    343351        g_free( bu->data );
    344352}
  • protocols/msn/msn.h

    r7f34ce2 rca7de3a  
    8989        int groupcount;
    9090        char **grouplist;
     91        GTree *domaintree;
    9192};
    9293
     
    153154typedef enum
    154155{
    155         MSN_BUDDY_FL = 1,
     156        MSN_BUDDY_FL = 1,   /* Warning: FL,AL,BL *must* be 1,2,4. */
    156157        MSN_BUDDY_AL = 2,
    157158        MSN_BUDDY_BL = 4,
     
    187188gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond );
    188189void msn_auth_got_passport_token( struct im_connection *ic, char *token );
     190void msn_auth_got_contact_list( struct im_connection *ic );
    189191
    190192/* msn_util.c */
     
    201203gboolean msn_set_display_name( struct im_connection *ic, const char *rawname );
    202204char *msn_p11_challenge( char *challenge );
     205gint msn_domaintree_cmp( gconstpointer a_, gconstpointer b_ );
    203206
    204207/* tables.c */
  • protocols/msn/msn_util.c

    r7f34ce2 rca7de3a  
    528528        return output;
    529529}
     530
     531gint msn_domaintree_cmp( gconstpointer a_, gconstpointer b_ )
     532{
     533        const char *a = a_, *b = b_;
     534        gint ret;
     535       
     536        if( !( a = strchr( a, '@' ) ) || !( b = strchr( b, '@' ) ) ||
     537            ( ret = strcmp( a, b ) ) == 0 )
     538                ret = strcmp( a_, b_ );
     539       
     540        return ret;
     541}
  • protocols/msn/ns.c

    r7f34ce2 rca7de3a  
    2727#include "nogaim.h"
    2828#include "msn.h"
    29 #include "passport.h"
    3029#include "md5.h"
    3130#include "soap.h"
     31#include "xmltree.h"
    3232
    3333static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond );
     
    3636
    3737static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name );
     38static void msn_ns_send_adl( struct im_connection *ic );
    3839
    3940gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond )
     
    135136                int port;
    136137               
    137                 if( num_parts == 6 && strcmp( cmd[2], "NS" ) == 0 )
     138                if( num_parts >= 6 && strcmp( cmd[2], "NS" ) == 0 )
    138139                {
    139140                        b_event_remove( ic->inpa );
     
    156157                        md->fd = proxy_connect( server, port, msn_ns_connected, ic );
    157158                }
    158                 else if( num_parts == 6 && strcmp( cmd[2], "SB" ) == 0 )
     159                else if( num_parts >= 6 && strcmp( cmd[2], "SB" ) == 0 )
    159160                {
    160161                        struct msn_switchboard *sb;
     
    261262                }
    262263        }
    263         else if( strcmp( cmd[0], "SYN" ) == 0 )
    264         {
    265                 if( num_parts == 5 )
    266                 {
    267                         int i, groupcount;
    268                        
    269                         groupcount = atoi( cmd[4] );
    270                         if( groupcount > 0 )
    271                         {
    272                                 /* valgrind says this is leaking memory, I'm guessing
    273                                    that this happens during server redirects. */
    274                                 if( md->grouplist )
    275                                 {
    276                                         for( i = 0; i < md->groupcount; i ++ )
    277                                                 g_free( md->grouplist[i] );
    278                                         g_free( md->grouplist );
    279                                 }
    280                                
    281                                 md->groupcount = groupcount;
    282                                 md->grouplist = g_new0( char *, md->groupcount );
    283                         }
    284                        
    285                         md->buddycount = atoi( cmd[3] );
    286                         if( !*cmd[3] || md->buddycount == 0 )
    287                                 msn_logged_in( ic );
    288                 }
    289                 else
    290                 {
    291                         /* Hrrm... This SYN reply doesn't really look like something we expected.
    292                            Let's assume everything is okay. */
    293                        
    294                         msn_logged_in( ic );
    295                 }
    296         }
    297         else if( strcmp( cmd[0], "LST" ) == 0 )
    298         {
    299                 int list;
    300                
    301                 if( num_parts != 4 && num_parts != 5 )
    302                 {
    303                         imcb_error( ic, "Syntax error" );
    304                         imc_logout( ic, TRUE );
    305                         return( 0 );
    306                 }
    307                
    308                 http_decode( cmd[2] );
    309                 list = atoi( cmd[3] );
    310                
    311                 if( list & 1 ) /* FL */
    312                 {
    313                         char *group = NULL;
    314                         int num;
    315                        
    316                         if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 && num < md->groupcount )
    317                                 group = md->grouplist[num];
    318                        
    319                         imcb_add_buddy( ic, cmd[1], group );
    320                         imcb_rename_buddy( ic, cmd[1], cmd[2] );
    321                 }
    322                 if( list & 2 ) /* AL */
    323                 {
    324                         ic->permit = g_slist_append( ic->permit, g_strdup( cmd[1] ) );
    325                 }
    326                 if( list & 4 ) /* BL */
    327                 {
    328                         ic->deny = g_slist_append( ic->deny, g_strdup( cmd[1] ) );
    329                 }
    330                 if( list & 8 ) /* RL */
    331                 {
    332                         if( ( list & 6 ) == 0 )
    333                                 msn_buddy_ask( ic, cmd[1], cmd[2] );
    334                 }
    335                
    336                 if( --md->buddycount == 0 )
    337                 {
    338                         if( ic->flags & OPT_LOGGED_IN )
    339                         {
    340                                 imcb_log( ic, "Successfully transferred to different server" );
    341                                 g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 );
    342                                 return( msn_write( ic, buf, strlen( buf ) ) );
    343                         }
    344                         else
    345                         {
    346                                 msn_logged_in( ic );
    347                         }
    348                 }
    349         }
    350         else if( strcmp( cmd[0], "LSG" ) == 0 )
    351         {
    352                 int num;
    353                
    354                 if( num_parts != 4 )
    355                 {
    356                         imcb_error( ic, "Syntax error" );
    357                         imc_logout( ic, TRUE );
    358                         return( 0 );
    359                 }
    360                
    361                 http_decode( cmd[2] );
    362                 num = atoi( cmd[1] );
    363                
    364                 if( num < md->groupcount )
    365                         md->grouplist[num] = g_strdup( cmd[2] );
     264        else if( strcmp( cmd[0], "BLP" ) == 0 )
     265        {
     266                msn_ns_send_adl( ic );
     267        }
     268        else if( strcmp( cmd[0], "ADL" ) == 0 )
     269        {
     270                if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 )
     271                {
     272                        char buf[1024];
     273                        char *fn_raw = set_getstr( &ic->acc->set, "display_name" );
     274                        char *fn;
     275                       
     276                        if( fn_raw == NULL )
     277                                fn_raw = ic->acc->user;
     278                        fn = g_malloc( strlen( fn_raw ) * 3 + 1 );
     279                        strcpy( fn, fn_raw );
     280                        http_encode( fn );
     281                       
     282                        g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",
     283                                    ++md->trId, fn );
     284                        g_free( fn );
     285                       
     286                        msn_write( ic, buf, strlen( buf ) );
     287                }
     288        }
     289        else if( strcmp( cmd[0], "PRP" ) == 0 )
     290        {
     291                imcb_connected( ic );
    366292        }
    367293        else if( strcmp( cmd[0], "CHL" ) == 0 )
     
    393319                const struct msn_away_state *st;
    394320               
    395                 if( num_parts != 6 )
    396                 {
    397                         imcb_error( ic, "Syntax error" );
    398                         imc_logout( ic, TRUE );
    399                         return( 0 );
    400                 }
    401                
    402                 http_decode( cmd[4] );
    403                 imcb_rename_buddy( ic, cmd[3], cmd[4] );
     321                if( num_parts < 6 )
     322                {
     323                        imcb_error( ic, "Syntax error" );
     324                        imc_logout( ic, TRUE );
     325                        return( 0 );
     326                }
     327               
     328                http_decode( cmd[5] );
     329                imcb_rename_buddy( ic, cmd[3], cmd[5] );
    404330               
    405331                st = msn_away_state_by_code( cmd[2] );
     
    787713}
    788714
     715void msn_auth_got_contact_list( struct im_connection *ic )
     716{
     717        char buf[64];
     718        struct msn_data *md;
     719       
     720        /* Dead connection? */
     721        if( g_slist_find( msn_connections, ic ) == NULL )
     722                return;
     723       
     724        md = ic->proto_data;
     725       
     726       
     727        g_snprintf( buf, sizeof( buf ), "BLP %d %s\r\n", ++md->trId, "BL" );
     728        msn_write( ic, buf, strlen( buf ) );
     729}
     730
     731static gboolean msn_ns_send_adl_1( gpointer key, gpointer value, gpointer data )
     732{
     733        struct xt_node *adl = data, *d, *c;
     734        struct bee_user *bu = value;
     735        struct msn_buddy_data *bd = bu->data;
     736        char handle[strlen(bu->handle)];
     737        char *domain;
     738        char l[4];
     739       
     740        strcpy( handle, bu->handle );
     741        if( ( domain = strchr( handle, '@' ) ) == NULL ) /* WTF */
     742                return FALSE;
     743        *domain = '\0';
     744        domain ++;
     745       
     746        if( ( d = adl->children ) == NULL ||
     747            g_strcasecmp( xt_find_attr( d, "n" ), domain ) != 0 )
     748        {
     749                d = xt_new_node( "d", NULL, NULL );
     750                xt_add_attr( d, "n", domain );
     751                xt_insert_child( adl, d );
     752        }
     753       
     754        g_snprintf( l, sizeof( l ), "%d", bd->flags & 7 );
     755        c = xt_new_node( "c", NULL, NULL );
     756        xt_add_attr( c, "n", handle );
     757        xt_add_attr( c, "l", l );
     758        xt_add_attr( c, "t", "1" ); /* 1 means normal, 4 means mobile? */
     759        xt_insert_child( d, c );
     760       
     761        return FALSE;
     762}
     763
     764static void msn_ns_send_adl( struct im_connection *ic )
     765{
     766        struct xt_node *adl;
     767        struct msn_data *md;
     768        char *adls, buf[64];
     769       
     770        /* Dead connection? */
     771        if( g_slist_find( msn_connections, ic ) == NULL )
     772                return;
     773       
     774        md = ic->proto_data;
     775       
     776        adl = xt_new_node( "ml", NULL, NULL );
     777        xt_add_attr( adl, "l", "1" );
     778        g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl );
     779        adls = xt_to_string( adl );
     780       
     781        g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) );
     782        if( msn_write( ic, buf, strlen( buf ) ) )
     783                msn_write( ic, adls, strlen( adls ) );
     784       
     785        g_free( adls );
     786        xt_free_node( adl );
     787}
     788
    789789static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name )
    790790{
  • protocols/msn/soap.c

    r7f34ce2 rca7de3a  
    578578static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req )
    579579{
     580        msn_auth_got_contact_list( soap_req->ic );
    580581        return MSN_SOAP_OK;
    581582}
Note: See TracChangeset for help on using the changeset viewer.