Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • account.c

    r5100caa rc99af3a  
    2828#include "account.h"
    2929
    30 char *set_eval_account( set_t *set, char *value );
    31 
    3230account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
    3331{
    3432        account_t *a;
    35         set_t *s;
    3633       
    3734        if( irc->accounts )
    3835        {
    3936                for( a = irc->accounts; a->next; a = a->next );
    40                 a = a->next = g_new0( account_t, 1 );
     37                a = a->next = g_new0 ( account_t, 1 );
    4138        }
    4239        else
     
    4845        a->user = g_strdup( user );
    4946        a->pass = g_strdup( pass );
    50         a->auto_connect = 1;
    5147        a->irc = irc;
    5248       
    53         s = set_add( &a->set, "auto_connect", NULL, set_eval_account, a );
    54         s->flags |= ACC_SET_NOSAVE;
    55        
    56         s = set_add( &a->set, "password", NULL, set_eval_account, a );
    57         s->flags |= ACC_SET_NOSAVE;
    58        
    59         s = set_add( &a->set, "server", NULL, set_eval_account, a );
    60         s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
    61        
    62         s = set_add( &a->set, "username", NULL, set_eval_account, a );
    63         s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
    64         set_setstr( &a->set, "username", user );
    65        
    6649        return( a );
    67 }
    68 
    69 char *set_eval_account( set_t *set, char *value )
    70 {
    71         account_t *acc = set->data;
    72        
    73         /* Double-check: We refuse to edit on-line accounts. */
    74         if( acc->gc )
    75                 return NULL;
    76        
    77         if( strcmp( set->key, "username" ) == 0 )
    78         {
    79                 g_free( acc->user );
    80                 acc->user = g_strdup( value );
    81                 return value;
    82         }
    83         else if( strcmp( set->key, "password" ) == 0 )
    84         {
    85                 g_free( acc->pass );
    86                 acc->pass = g_strdup( value );
    87                 return NULL;    /* password shouldn't be visible in plaintext! */
    88         }
    89         else if( strcmp( set->key, "server" ) == 0 )
    90         {
    91                 g_free( acc->server );
    92                 if( *value )
    93                         acc->server = g_strdup( value );
    94                 else
    95                         acc->server = NULL;
    96                 return value;
    97         }
    98         else if( strcmp( set->key, "auto_connect" ) == 0 )
    99         {
    100                 if( !is_bool( value ) )
    101                         return NULL;
    102                
    103                 acc->auto_connect = bool2int( value );
    104                 return value;
    105         }
    106        
    107         return NULL;
    10850}
    10951
     
    11153{
    11254        account_t *a, *ret = NULL;
    113         char *handle, *s;
    11455        int nr;
    115        
    116         /* This checks if the id string ends with (...) */
    117         if( ( handle = strchr( id, '(' ) ) && ( s = strchr( handle, ')' ) ) && s[1] == 0 )
    118         {
    119                 struct prpl *proto;
    120                
    121                 *s = *handle = 0;
    122                 handle ++;
    123                
    124                 if( ( proto = find_protocol( id ) ) )
    125                 {
    126                         for( a = irc->accounts; a; a = a->next )
    127                                 if( a->prpl == proto &&
    128                                     a->prpl->cmp_buddynames( handle, a->user ) == 0 )
    129                                         ret = a;
    130                 }
    131                
    132                 /* Restore the string. */
    133                 handle --;
    134                 *handle = '(';
    135                 *s = ')';
    136                
    137                 if( ret )
    138                         return ret;
    139         }
    14056       
    14157        if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
     
    187103                        }
    188104                       
    189                         while( a->set )
    190                                 set_del( &a->set, a->set->key );
    191                        
    192105                        g_free( a->user );
    193106                        g_free( a->pass );
     
    203116void account_on( irc_t *irc, account_t *a )
    204117{
     118        struct aim_user *u;
     119       
    205120        if( a->gc )
    206121        {
     
    211126        cancel_auto_reconnect( a );
    212127       
     128        u = g_new0 ( struct aim_user, 1 );
     129        u->irc = irc;
     130        u->prpl = a->prpl;
     131        strncpy( u->username, a->user, sizeof( u->username ) - 1 );
     132        strncpy( u->password, a->pass, sizeof( u->password ) - 1 );
     133        if( a->server) strncpy( u->proto_opt[0], a->server, sizeof( u->proto_opt[0] ) - 1 );
     134       
     135        a->gc = (struct gaim_connection *) u; /* Bit hackish :-/ */
    213136        a->reconnect = 0;
    214         a->prpl->login( a );
     137       
     138        a->prpl->login( u );
    215139}
    216140
Note: See TracChangeset for help on using the changeset viewer.