Ignore:
Timestamp:
2006-07-02T23:20:27Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
5b52a48
Parents:
96863f6
Message:

Added display_name setting for MSN connections. (Should replace the nick
command later.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    r96863f6 r911f2eb  
    2626#include "nogaim.h"
    2727#include "msn.h"
     28
     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}
    2838
    2939static void msn_login( account_t *acc )
     
    210220static void msn_set_info( struct gaim_connection *gc, char *info )
    211221{
    212         int i;
    213         char buf[1024], *fn, *s;
    214         struct msn_data *md = gc->proto_data;
    215        
    216         if( strlen( info ) > 129 )
    217         {
    218                 do_error_dialog( gc, "Maximum name length exceeded", "MSN" );
    219                 return;
    220         }
    221        
    222         /* Of course we could use http_encode() here, but when we encode
    223            every character, the server is less likely to complain about the
    224            chosen name. However, the MSN server doesn't seem to like escaped
    225            non-ASCII chars, so we keep those unescaped. */
    226         s = fn = g_new0( char, strlen( info ) * 3 + 1 );
    227         for( i = 0; info[i]; i ++ )
    228                 if( info[i] & 128 )
    229                 {
    230                         *s = info[i];
    231                         s ++;
    232                 }
    233                 else
    234                 {
    235                         g_snprintf( s, 4, "%%%02X", info[i] );
    236                         s += 3;
    237                 }
    238        
    239         g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
    240         msn_write( gc, buf, strlen( buf ) );
    241         g_free( fn );
     222        msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info );
    242223}
    243224
     
    378359}
    379360
     361static char *msn_set_display_name( set_t *set, char *value )
     362{
     363        account_t *acc = set->data;
     364        struct gaim_connection *gc = acc->gc;
     365        struct msn_data *md;
     366        char buf[1024], *fn, *s;
     367        int i;
     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        /* Of course we could use http_encode() here, but when we encode
     382           every character, the server is less likely to complain about the
     383           chosen name. However, the MSN server doesn't seem to like escaped
     384           non-ASCII chars, so we keep those unescaped. */
     385        s = fn = g_new0( char, strlen( value ) * 3 + 1 );
     386        for( i = 0; value[i]; i ++ )
     387                if( value[i] & 128 )
     388                {
     389                        *s = value[i];
     390                        s ++;
     391                }
     392                else
     393                {
     394                        g_snprintf( s, 4, "%%%02X", value[i] );
     395                        s += 3;
     396                }
     397       
     398        g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn );
     399        msn_write( gc, buf, strlen( buf ) );
     400        g_free( fn );
     401       
     402        /* Returning NULL would be better, because the server still has to
     403           confirm the name change. However, it looks a bit confusing to the
     404           user. */
     405        return value;
     406}
     407
    380408void msn_init()
    381409{
    382410        struct prpl *ret = g_new0(struct prpl, 1);
     411       
    383412        ret->name = "msn";
    384413        ret->login = msn_login;
     414        ret->acc_init = msn_acc_init;
    385415        ret->close = msn_close;
    386416        ret->send_im = msn_send_im;
Note: See TracChangeset for help on using the changeset viewer.