Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • account.c

    r04026d4 rc99af3a  
    3131{
    3232        account_t *a;
    33         set_t *s;
    3433       
    3534        if( irc->accounts )
    3635        {
    3736                for( a = irc->accounts; a->next; a = a->next );
    38                 a = a->next = g_new0( account_t, 1 );
     37                a = a->next = g_new0 ( account_t, 1 );
    3938        }
    4039        else
     
    4645        a->user = g_strdup( user );
    4746        a->pass = g_strdup( pass );
    48         a->auto_connect = 1;
    4947        a->irc = irc;
    5048       
    51         s = set_add( &a->set, "auto_connect", "true", set_eval_account, a );
    52         s->flags |= ACC_SET_NOSAVE;
    53        
    54         s = set_add( &a->set, "auto_reconnect", "true", set_eval_bool, a );
    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, "username", NULL, set_eval_account, a );
    60         s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
    61         set_setstr( &a->set, "username", user );
    62        
    63         a->nicks = g_hash_table_new_full( g_str_hash, g_str_equal, g_free, g_free );
    64        
    65         /* This function adds some more settings (and might want to do more
    66            things that have to be done now, although I can't think of anything. */
    67         if( prpl->acc_init )
    68                 prpl->acc_init( a );
    69        
    7049        return( a );
    71 }
    72 
    73 char *set_eval_account( set_t *set, char *value )
    74 {
    75         account_t *acc = set->data;
    76        
    77         /* Double-check: We refuse to edit on-line accounts. */
    78         if( set->flags & ACC_SET_OFFLINE_ONLY && acc->gc )
    79                 return NULL;
    80        
    81         if( strcmp( set->key, "username" ) == 0 )
    82         {
    83                 g_free( acc->user );
    84                 acc->user = g_strdup( value );
    85                 return value;
    86         }
    87         else if( strcmp( set->key, "password" ) == 0 )
    88         {
    89                 g_free( acc->pass );
    90                 acc->pass = g_strdup( value );
    91                 return NULL;    /* password shouldn't be visible in plaintext! */
    92         }
    93         else if( strcmp( set->key, "server" ) == 0 )
    94         {
    95                 g_free( acc->server );
    96                 if( *value )
    97                         acc->server = g_strdup( value );
    98                 else
    99                         acc->server = NULL;
    100                 return value;
    101         }
    102         else if( strcmp( set->key, "auto_connect" ) == 0 )
    103         {
    104                 if( !is_bool( value ) )
    105                         return NULL;
    106                
    107                 acc->auto_connect = bool2int( value );
    108                 return value;
    109         }
    110        
    111         return NULL;
    11250}
    11351
     
    11553{
    11654        account_t *a, *ret = NULL;
    117         char *handle, *s;
    11855        int nr;
    119        
    120         /* This checks if the id string ends with (...) */
    121         if( ( handle = strchr( id, '(' ) ) && ( s = strchr( handle, ')' ) ) && s[1] == 0 )
    122         {
    123                 struct prpl *proto;
    124                
    125                 *s = *handle = 0;
    126                 handle ++;
    127                
    128                 if( ( proto = find_protocol( id ) ) )
    129                 {
    130                         for( a = irc->accounts; a; a = a->next )
    131                                 if( a->prpl == proto &&
    132                                     a->prpl->handle_cmp( handle, a->user ) == 0 )
    133                                         ret = a;
    134                 }
    135                
    136                 /* Restore the string. */
    137                 handle --;
    138                 *handle = '(';
    139                 *s = ')';
    140                
    141                 if( ret )
    142                         return ret;
    143         }
    14456       
    14557        if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
     
    191103                        }
    192104                       
    193                         while( a->set )
    194                                 set_del( &a->set, a->set->key );
    195                        
    196                         g_hash_table_destroy( a->nicks );
    197                        
    198105                        g_free( a->user );
    199106                        g_free( a->pass );
     
    209116void account_on( irc_t *irc, account_t *a )
    210117{
     118        struct aim_user *u;
     119       
    211120        if( a->gc )
    212121        {
     
    217126        cancel_auto_reconnect( a );
    218127       
     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 :-/ */
    219136        a->reconnect = 0;
    220         a->prpl->login( a );
     137       
     138        a->prpl->login( u );
    221139}
    222140
Note: See TracChangeset for help on using the changeset viewer.