Changeset e3413cc for protocols


Ignore:
Timestamp:
2010-03-30T01:30:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7815a2b
Parents:
c4bc92a
Message:

Added local_display_name setting for MSN accounts and some hopefully clever
enough handling for it. Should solve problems with MSN servers forgetting/
overriding display names set by the user.

Location:
protocols/msn
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rc4bc92a re3413cc  
    3131GSList *msn_switchboards;
    3232
    33 static char *msn_set_display_name( set_t *set, char *value );
     33static char *set_eval_display_name( set_t *set, char *value );
    3434
    3535static void msn_init( account_t *acc )
    3636{
    37         set_t *s;
    38        
    39         s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc );
    40         s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
    41 
    42         s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
     37        set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
     38        set_add( &acc->set, "local_display_name", "false", set_eval_bool, acc );
     39        set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
    4340}
    4441
     
    167164static void msn_set_my_name( struct im_connection *ic, char *info )
    168165{
    169         msn_set_display_name( set_find( &ic->acc->set, "display_name" ), info );
     166        msn_set_display_name( ic, info );
    170167}
    171168
     
    283280}
    284281
    285 static char *msn_set_display_name( set_t *set, char *value )
     282static char *set_eval_display_name( set_t *set, char *value )
    286283{
    287284        account_t *acc = set->data;
    288285        struct im_connection *ic = acc->ic;
    289         struct msn_data *md;
    290         char buf[1024], *fn;
    291        
    292         /* Double-check. */
     286       
     287        /* Allow any name if we're offline. */
    293288        if( ic == NULL )
    294                 return NULL;
    295        
    296         md = ic->proto_data;
     289                return value;
    297290       
    298291        if( strlen( value ) > 129 )
     
    301294                return NULL;
    302295        }
    303        
    304         fn = msn_http_encode( value );
    305        
    306         g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );
    307         msn_write( ic, buf, strlen( buf ) );
    308         g_free( fn );
    309296       
    310297        /* Returning NULL would be better, because the server still has to
    311298           confirm the name change. However, it looks a bit confusing to the
    312299           user. */
    313         return value;
     300        return msn_set_display_name( ic, value ) ? value : NULL;
    314301}
    315302
  • protocols/msn/msn.h

    rc4bc92a re3413cc  
    161161char *msn_http_encode( const char *input );
    162162void msn_msgq_purge( struct im_connection *ic, GSList **list );
     163gboolean msn_set_display_name( struct im_connection *ic, const char *rawname );
    163164
    164165/* tables.c */
  • protocols/msn/msn_util.c

    rc4bc92a re3413cc  
    3838                imcb_error( ic, "Short write() to main server" );
    3939                imc_logout( ic, TRUE );
    40                 return( 0 );
    41         }
    42        
    43         return( 1 );
     40                return 0;
     41        }
     42       
     43        return 1;
    4444}
    4545
     
    377377        g_string_free( ret, TRUE );
    378378}
     379
     380gboolean msn_set_display_name( struct im_connection *ic, const char *rawname )
     381{
     382        char *fn = msn_http_encode( rawname );
     383        struct msn_data *md = ic->proto_data;
     384        char buf[1024];
     385       
     386        g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );
     387        g_free( fn );
     388       
     389        return msn_write( ic, buf, strlen( buf ) ) != 0;
     390}
  • protocols/msn/ns.c

    rc4bc92a re3413cc  
    3535
    3636static void msn_auth_got_passport_token( struct msn_auth_data *mad );
     37static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name );
    3738
    3839gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond )
     
    231232                else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 )
    232233                {
    233                         set_t *s;
    234                        
    235234                        if( num_parts == 7 )
    236                         {
    237                                 http_decode( cmd[4] );
    238                                
    239                                 strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
    240                                 ic->displayname[sizeof(ic->displayname)-1] = 0;
    241                                
    242                                 if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
    243                                 {
    244                                         g_free( s->value );
    245                                         s->value = g_strdup( cmd[4] );
    246                                 }
    247                         }
     235                                msn_ns_got_display_name( ic, cmd[4] );
    248236                        else
    249                         {
    250237                                imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
    251                         }
    252238                       
    253239                        imcb_log( ic, "Authenticated, getting buddy list" );
     
    567553                return( 0 );
    568554        }
     555#if 0
     556        /* Discard this one completely for now since I don't care about the ack
     557           and since MSN servers can apparently screw up the formatting. */
    569558        else if( strcmp( cmd[0], "REA" ) == 0 )
    570559        {
     
    597586                }
    598587        }
     588#endif
    599589        else if( strcmp( cmd[0], "IPG" ) == 0 )
    600590        {
     
    746736        }
    747737}
     738
     739static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name )
     740{
     741        set_t *s;
     742       
     743        if( ( s = set_find( &ic->acc->set, "display_name" ) ) == NULL )
     744                return FALSE; /* Shouldn't happen.. */
     745       
     746        http_decode( name );
     747       
     748        if( s->value && strcmp( s->value, name ) == 0 )
     749        {
     750                return TRUE;
     751                /* The names match, nothing to worry about. */
     752        }
     753        else if( s->value != NULL &&
     754                 ( strcmp( name, ic->acc->user ) == 0 ||
     755                   set_getbool( &ic->acc->set, "local_display_name" ) ) )
     756        {
     757                /* The server thinks our display name is our e-mail address
     758                   which is probably wrong, or the user *wants* us to do this:
     759                   Always use the locally set display_name. */
     760                return msn_set_display_name( ic, s->value );
     761        }
     762        else
     763        {
     764                if( s->value && *s->value )
     765                        imcb_log( ic, "BitlBee thinks your display name is `%s' but "
     766                                      "the MSN server says it's `%s'. Using the MSN "
     767                                      "server's name. Set local_display_name to true "
     768                                      "to use the local name.", s->value, name );
     769               
     770                g_free( s->value );
     771                s->value = g_strdup( name );
     772                return TRUE;
     773        }
     774}
Note: See TracChangeset for help on using the changeset viewer.