Changeset d8d63a2 for protocols/msn


Ignore:
Timestamp:
2006-12-05T20:40:17Z (17 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
7740c4c
Parents:
f4aa393 (diff), 55078f5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

[merge] wilmer

Location:
protocols/msn
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rf4aa393 rd8d63a2  
    2727#include "msn.h"
    2828
    29 static void msn_login( struct aim_user *acct )
    30 {
    31         struct gaim_connection *gc = new_gaim_conn( acct );
     29static char *msn_set_display_name( set_t *set, char *value );
     30
     31static void msn_acc_init( account_t *acc )
     32{
     33        set_t *s;
     34       
     35        s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc );
     36        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
     37}
     38
     39static void msn_login( account_t *acc )
     40{
     41        struct gaim_connection *gc = new_gaim_conn( acc );
    3242        struct msn_data *md = g_new0( struct msn_data, 1 );
    33        
    34         set_login_progress( gc, 1, "Connecting" );
    3543       
    3644        gc->proto_data = md;
    3745        md->fd = -1;
    3846       
    39         if( strchr( acct->username, '@' ) == NULL )
     47        if( strchr( acc->user, '@' ) == NULL )
    4048        {
    4149                hide_login_progress( gc, "Invalid account name" );
     
    4452        }
    4553       
     54        set_login_progress( gc, 1, "Connecting" );
     55       
    4656        md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, gc );
    4757        if( md->fd < 0 )
     
    4959                hide_login_progress( gc, "Could not connect to server" );
    5060                signoff( gc );
    51         }
    52         else
    53         {
    54                 md->gc = gc;
    55                 md->away_state = msn_away_state_list;
    56                
    57                 msn_connections = g_slist_append( msn_connections, gc );
    58         }
     61                return;
     62        }
     63       
     64        md->gc = gc;
     65        md->away_state = msn_away_state_list;
     66       
     67        msn_connections = g_slist_append( msn_connections, gc );
    5968}
    6069
     
    212221static void msn_set_info( struct gaim_connection *gc, char *info )
    213222{
    214         int i;
    215         char buf[1024], *fn, *s;
    216         struct msn_data *md = gc->proto_data;
    217        
    218         if( strlen( info ) > 129 )
    219         {
    220                 do_error_dialog( gc, "Maximum name length exceeded", "MSN" );
    221                 return;
    222         }
    223        
    224         /* Of course we could use http_encode() here, but when we encode
    225            every character, the server is less likely to complain about the
    226            chosen name. However, the MSN server doesn't seem to like escaped
    227            non-ASCII chars, so we keep those unescaped. */
    228         s = fn = g_new0( char, strlen( info ) * 3 + 1 );
    229         for( i = 0; info[i]; i ++ )
    230                 if( info[i] & 128 )
    231                 {
    232                         *s = info[i];
    233                         s ++;
    234                 }
    235                 else
    236                 {
    237                         g_snprintf( s, 4, "%%%02X", info[i] );
    238                         s += 3;
    239                 }
    240        
    241         g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
    242         msn_write( gc, buf, strlen( buf ) );
    243         g_free( fn );
     223        msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info );
    244224}
    245225
     
    380360}
    381361
     362static char *msn_set_display_name( set_t *set, char *value )
     363{
     364        account_t *acc = set->data;
     365        struct gaim_connection *gc = acc->gc;
     366        struct msn_data *md;
     367        char buf[1024], *fn;
     368       
     369        /* Double-check. */
     370        if( gc == NULL )
     371                return NULL;
     372       
     373        md = gc->proto_data;
     374       
     375        if( strlen( value ) > 129 )
     376        {
     377                serv_got_crap( gc, "Maximum name length exceeded" );
     378                return NULL;
     379        }
     380       
     381        fn = msn_http_encode( value );
     382       
     383        g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
     384        msn_write( gc, buf, strlen( buf ) );
     385        g_free( fn );
     386       
     387        /* Returning NULL would be better, because the server still has to
     388           confirm the name change. However, it looks a bit confusing to the
     389           user. */
     390        return value;
     391}
     392
    382393void msn_init()
    383394{
    384395        struct prpl *ret = g_new0(struct prpl, 1);
     396       
    385397        ret->name = "msn";
    386398        ret->login = msn_login;
     399        ret->acc_init = msn_acc_init;
    387400        ret->close = msn_close;
    388401        ret->send_im = msn_send_im;
     
    404417        ret->rem_deny = msn_rem_deny;
    405418        ret->send_typing = msn_send_typing;
    406         ret->cmp_buddynames = g_strcasecmp;
     419        ret->handle_cmp = g_strcasecmp;
    407420
    408421        register_protocol(ret);
  • protocols/msn/msn.h

    rf4aa393 rd8d63a2  
    157157char **msn_linesplit( char *line );
    158158int msn_handler( struct msn_handler_data *h );
     159char *msn_http_encode( const char *input );
    159160
    160161/* tables.c */
  • protocols/msn/msn_util.c

    rf4aa393 rd8d63a2  
    5454{
    5555        struct msn_data *md = gc->proto_data;
    56         GSList *l, **lp = NULL;
    5756        char buf[1024], *realname;
    5857       
    59         if( strcmp( list, "AL" ) == 0 )
    60                 lp = &gc->permit;
    61         else if( strcmp( list, "BL" ) == 0 )
    62                 lp = &gc->deny;
    63        
    64         if( lp )
    65                 for( l = *lp; l; l = l->next )
    66                         if( g_strcasecmp( l->data, who ) == 0 )
    67                                 return( 1 );
    68        
    69         realname = g_new0( char, strlen( realname_ ) * 3 + 1 );
    70         strcpy( realname, realname_ );
    71         http_encode( realname );
     58        realname = msn_http_encode( realname_ );
    7259       
    7360        g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s\r\n", ++md->trId, list, who, realname );
     
    7663                g_free( realname );
    7764               
    78                 if( lp )
    79                         *lp = g_slist_append( *lp, g_strdup( who ) );
    80                
    8165                return( 1 );
    8266        }
     
    9074{
    9175        struct msn_data *md = gc->proto_data;
    92         GSList *l = NULL, **lp = NULL;
    9376        char buf[1024];
    94        
    95         if( strcmp( list, "AL" ) == 0 )
    96                 lp = &gc->permit;
    97         else if( strcmp( list, "BL" ) == 0 )
    98                 lp = &gc->deny;
    99        
    100         if( lp )
    101         {
    102                 for( l = *lp; l; l = l->next )
    103                         if( g_strcasecmp( l->data, who ) == 0 )
    104                                 break;
    105                
    106                 if( !l )
    107                         return( 1 );
    108         }
    10977       
    11078        g_snprintf( buf, sizeof( buf ), "REM %d %s %s\r\n", ++md->trId, list, who );
    11179        if( msn_write( gc, buf, strlen( buf ) ) )
    112         {
    113                 if( lp )
    114                         *lp = g_slist_remove( *lp, l->data );
    115                
    11680                return( 1 );
    117         }
    11881       
    11982        return( 0 );
     
    350313        return( 1 );
    351314}
     315
     316/* The difference between this function and the normal http_encode() function
     317   is that this one escapes every 7-bit ASCII character because this is said
     318   to avoid some lame server-side checks when setting a real-name. Also,
     319   non-ASCII characters are not escaped because MSN servers don't seem to
     320   appreciate that! */
     321char *msn_http_encode( const char *input )
     322{
     323        char *ret, *s;
     324        int i;
     325       
     326        ret = s = g_new0( char, strlen( input ) * 3 + 1 );
     327        for( i = 0; input[i]; i ++ )
     328                if( input[i] & 128 )
     329                {
     330                        *s = input[i];
     331                        s ++;
     332                }
     333                else
     334                {
     335                        g_snprintf( s, 4, "%%%02X", input[i] );
     336                        s += 3;
     337                }
     338       
     339        return ret;
     340}
  • protocols/msn/ns.c

    rf4aa393 rd8d63a2  
    223223                else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 )
    224224                {
     225                        set_t *s;
     226                       
    225227                        http_decode( cmd[4] );
    226228                       
    227229                        strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) );
    228230                        gc->displayname[sizeof(gc->displayname)-1] = 0;
     231                       
     232                        if( ( s = set_find( &gc->acc->set, "display_name" ) ) )
     233                        {
     234                                g_free( s->value );
     235                                s->value = g_strdup( cmd[4] );
     236                        }
    229237                       
    230238                        set_login_progress( gc, 1, "Authenticated, getting buddy list" );
     
    517525                if( g_strcasecmp( cmd[3], gc->username ) == 0 )
    518526                {
     527                        set_t *s;
     528                       
    519529                        http_decode( cmd[4] );
    520530                        strncpy( gc->displayname, cmd[4], sizeof( gc->displayname ) );
    521531                        gc->displayname[sizeof(gc->displayname)-1] = 0;
     532                       
     533                        if( ( s = set_find( &gc->acc->set, "display_name" ) ) )
     534                        {
     535                                g_free( s->value );
     536                                s->value = g_strdup( cmd[4] );
     537                        }
    522538                }
    523539                else
  • protocols/msn/passport.c

    rf4aa393 rd8d63a2  
    5959        rep->data = data;
    6060        rep->func = func;
     61        rep->header = header;
    6162       
    6263        server = g_strdup( prd_cached );
     
    125126static char *passport_create_header( char *cookie, char *email, char *pwd )
    126127{
    127         char *buffer = g_new0( char, 2048 );
     128        char *buffer;
    128129        char *currenttoken;
    129130        char *email_enc, *pwd_enc;
     131       
     132        currenttoken = strstr( cookie, "lc=" );
     133        if( currenttoken == NULL )
     134                return NULL;
    130135       
    131136        email_enc = g_new0( char, strlen( email ) * 3 + 1 );
     
    137142        http_encode( pwd_enc );
    138143       
    139         currenttoken = strstr( cookie, "lc=" );
    140         if( currenttoken == NULL )
    141                 return( NULL );
    142        
    143         g_snprintf( buffer, 2048,
    144                     "Authorization: Passport1.4 OrgVerb=GET,"
    145                     "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,"
    146                     "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc,
    147                     currenttoken );
     144        buffer = g_strdup_printf( "Authorization: Passport1.4 OrgVerb=GET,"
     145                                  "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,"
     146                                  "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc,
     147                                  currenttoken );
    148148       
    149149        g_free( email_enc );
    150150        g_free( pwd_enc );
    151151       
    152         return( buffer );
     152        return buffer;
    153153}
    154154
     
    212212        if( passport_get_id_real( rep->func, rep->data, rep->header ) )
    213213        {
     214                rep->header = NULL;
    214215                destroy_reply( rep );
    215216                return;
Note: See TracChangeset for help on using the changeset viewer.