Changeset 9df916f for commands.c


Ignore:
Timestamp:
2005-12-09T20:48:45Z (18 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
34759e6
Parents:
c2295f7 (diff), 87c24ba (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 my storage abstraction changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rc2295f7 r9df916f  
    8686int cmd_identify( irc_t *irc, char **cmd )
    8787{
    88         int checkie = bitlbee_load( irc, cmd[1] );
    89        
    90         if( checkie == -1 )
    91         {
     88        storage_status_t status = global.storage->load( irc->nick, cmd[1], irc );
     89       
     90        switch (status) {
     91        case STORAGE_INVALID_PASSWORD:
    9292                irc_usermsg( irc, "Incorrect password" );
    93         }
    94         else if( checkie == 0 )
    95         {
     93                break;
     94        case STORAGE_NO_SUCH_USER:
    9695                irc_usermsg( irc, "The nick is (probably) not registered" );
    97         }
    98         else if( checkie == 1 )
    99         {
     96                break;
     97        case STORAGE_OK:
    10098                irc_usermsg( irc, "Password accepted" );
    101         }
    102         else
    103         {
     99                break;
     100        default:
    104101                irc_usermsg( irc, "Something very weird happened" );
     102                break;
    105103        }
    106104       
     
    110108int cmd_register( irc_t *irc, char **cmd )
    111109{
    112         int checkie;
    113         char path[512];
    114        
    115110        if( global.conf->authmode == AUTHMODE_REGISTERED )
    116111        {
     
    118113                return( 0 );
    119114        }
    120        
    121         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    122         checkie = access( path, F_OK );
    123        
    124         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    125         checkie += access( path, F_OK );
    126        
    127         if( checkie == -2 )
    128         {
    129                 setpassnc( irc, cmd[1] );
    130                 root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 );
    131                 irc->status = USTATUS_IDENTIFIED;
    132         }
    133         else
    134         {
    135                 irc_usermsg( irc, "Nick is already registered" );
     115
     116        irc_setpass( irc, cmd[1] );
     117        switch( global.storage->save( irc, FALSE )) {
     118                case STORAGE_ALREADY_EXISTS:
     119                        irc_usermsg( irc, "Nick is already registered" );
     120                        break;
     121                       
     122                case STORAGE_OK:
     123                        irc->status = USTATUS_IDENTIFIED;
     124                        break;
     125
     126                default:
     127                        irc_usermsg( irc, "Error registering" );
     128                        break;
    136129        }
    137130       
     
    141134int cmd_drop( irc_t *irc, char **cmd )
    142135{
    143         char s[512];
    144         FILE *fp;
    145        
    146         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    147         fp = fopen( s, "r" );
    148         if( !fp )
    149         {
     136        storage_status_t status;
     137       
     138        status = global.storage->remove (irc->nick, cmd[1]);
     139        switch (status) {
     140        case STORAGE_NO_SUCH_USER:
    150141                irc_usermsg( irc, "That account does not exist" );
    151142                return( 0 );
    152         }
    153        
    154         fscanf( fp, "%32[^\n]s", s );
    155         fclose( fp );
    156         if( setpass( irc, cmd[1], s ) < 0 )
    157         {
    158                 irc_usermsg( irc, "Incorrect password" );
    159                 return( 0 );
    160         }
    161        
    162         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    163         unlink( s );
    164        
    165         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    166         unlink( s );
    167        
    168         setpassnc( irc, NULL );
    169         irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick );
    170        
    171         return( 0 );
     143        case STORAGE_INVALID_PASSWORD:
     144                irc_usermsg( irc, "Password invalid" );
     145                return( 0 );
     146        case STORAGE_OK:
     147                irc_setpass( irc, NULL );
     148                irc_usermsg( irc, "Account `%s' removed", irc->nick );
     149                return( 0 );
     150        default:
     151                irc_usermsg( irc, "Error: '%d'", status );
     152                return( 0 );
     153        }
    172154}
    173155
     
    634616int cmd_save( irc_t *irc, char **cmd )
    635617{
    636         if( bitlbee_save( irc ) )
     618        if( global.storage->save( irc, TRUE ) == STORAGE_OK )
    637619                irc_usermsg( irc, "Configuration saved" );
    638620        else
Note: See TracChangeset for help on using the changeset viewer.