Changeset a1f17d4 for commands.c


Ignore:
Timestamp:
2005-12-08T14:14:28Z (18 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
7989fcf3
Parents:
1ee6c18
Message:

Simplify storage API a bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r1ee6c18 ra1f17d4  
    116116        }
    117117
    118         if( !global.storage->exists( irc->nick ))
    119         {
    120                 setpassnc( irc, cmd[1] );
    121                 root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 );
    122                 irc->status = USTATUS_IDENTIFIED;
    123         }
    124         else
    125         {
    126                 irc_usermsg( irc, "Nick is already registered" );
     118        setpassnc( irc, cmd[1] );
     119        switch( global.storage->save( irc, FALSE )) {
     120                case STORAGE_ALREADY_EXISTS:
     121                        irc_usermsg( irc, "Nick is already registered" );
     122                        break;
     123                       
     124                case STORAGE_OK:
     125                        irc->status = USTATUS_IDENTIFIED;
     126                        break;
     127
     128                default:
     129                        irc_usermsg( irc, "Error registering" );
     130                        break;
    127131        }
    128132       
     
    132136int cmd_drop( irc_t *irc, char **cmd )
    133137{
    134         if( ! global.storage->exists (irc->nick) )
    135         {
     138        storage_status_t status;
     139       
     140        status = global.storage->remove (irc->nick, cmd[1]);
     141        switch (status) {
     142        case STORAGE_NO_SUCH_USER:
    136143                irc_usermsg( irc, "That account does not exist" );
    137144                return( 0 );
    138         }
    139 
    140         if ( global.storage->check_pass (irc->nick, cmd[1]) )
    141         {
     145        case STORAGE_INVALID_PASSWORD:
    142146                irc_usermsg( irc, "Password invalid" );
    143147                return( 0 );
    144         }
    145        
    146         global.storage->remove (irc->nick);
    147        
    148         setpassnc( irc, NULL );
    149         irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick );
    150        
    151         return( 0 );
     148        case STORAGE_OK:
     149                setpassnc( irc, NULL );
     150                irc_usermsg( irc, "Account `%s' removed", irc->nick );
     151                return( 0 );
     152        default:
     153                irc_usermsg( irc, "Error: '%d'", status );
     154                return( 0 );
     155        }
    152156}
    153157
     
    614618int cmd_save( irc_t *irc, char **cmd )
    615619{
    616         if( global.storage->save( irc ) )
     620        if( global.storage->save( irc, TRUE ) )
    617621                irc_usermsg( irc, "Configuration saved" );
    618622        else
Note: See TracChangeset for help on using the changeset viewer.