Changeset a1f17d4
- Timestamp:
- 2005-12-08T14:14:28Z (19 years ago)
- Branches:
- master
- Children:
- 7989fcf3
- Parents:
- 1ee6c18
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r1ee6c18 ra1f17d4 116 116 } 117 117 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; 127 131 } 128 132 … … 132 136 int cmd_drop( irc_t *irc, char **cmd ) 133 137 { 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: 136 143 irc_usermsg( irc, "That account does not exist" ); 137 144 return( 0 ); 138 } 139 140 if ( global.storage->check_pass (irc->nick, cmd[1]) ) 141 { 145 case STORAGE_INVALID_PASSWORD: 142 146 irc_usermsg( irc, "Password invalid" ); 143 147 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 } 152 156 } 153 157 … … 614 618 int cmd_save( irc_t *irc, char **cmd ) 615 619 { 616 if( global.storage->save( irc ) )620 if( global.storage->save( irc, TRUE ) ) 617 621 irc_usermsg( irc, "Configuration saved" ); 618 622 else -
irc.c
r1ee6c18 ra1f17d4 154 154 155 155 if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 156 if( !global.storage->save( irc ) )156 if( !global.storage->save( irc, TRUE ) ) 157 157 irc_usermsg( irc, "Error while saving settings!" ); 158 158 -
storage.h
r1ee6c18 ra1f17d4 27 27 #define __STORAGE_H__ 28 28 29 typedef enum { 30 STORAGE_OK = 0, 31 STORAGE_NO_SUCH_USER, 32 STORAGE_INVALID_PASSWORD, 33 STORAGE_ALREADY_EXISTS, 34 STORAGE_OTHER_ERROR /* Error that isn't caused by user input, such as 35 a database that is unreachable. log() will be 36 used for the exact error message */ 37 } storage_status_t; 38 29 39 typedef struct { 30 40 const char *name; … … 33 43 void (*init) (void); 34 44 35 int (*load) (const char *nick, const char *password, irc_t * irc); 36 int (*exists) (const char *nick); 37 int (*save) (irc_t *irc); 38 int (*remove) (const char *nick); 39 int (*check_pass) (const char *nick, const char *pass); 45 storage_status_t (*load) (const char *nick, const char *password, irc_t * irc); 46 storage_status_t (*save) (irc_t *irc, int overwrite); 47 storage_status_t (*remove) (const char *nick, const char *password); 40 48 41 49 /* May be NULL if not supported by backend */ 42 int (*rename) (const char *onick, const char *nnick, const char *password);50 storage_status_t (*rename) (const char *onick, const char *nnick, const char *password); 43 51 } storage_t; 44 52 -
storage_text.c
r1ee6c18 ra1f17d4 36 36 } 37 37 38 static int text_load ( const char *my_nick, const char* password, irc_t *irc )38 static storage_status_t text_load ( const char *my_nick, const char* password, irc_t *irc ) 39 39 { 40 40 char s[512]; … … 50 50 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".accounts" ); 51 51 fp = fopen( s, "r" ); 52 if( !fp ) return ( 0 );52 if( !fp ) return STORAGE_NO_SUCH_USER; 53 53 54 54 fscanf( fp, "%32[^\n]s", s ); … … 56 56 { 57 57 fclose( fp ); 58 return ( -1 );58 return STORAGE_INVALID_PASSWORD; 59 59 } 60 60 … … 74 74 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".nicks" ); 75 75 fp = fopen( s, "r" ); 76 if( !fp ) return ( 0 );76 if( !fp ) return STORAGE_NO_SUCH_USER; 77 77 while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 ) 78 78 { … … 88 88 } 89 89 90 return ( 1 );91 } 92 93 static int text_save( irc_t *irc)90 return STORAGE_OK; 91 } 92 93 static storage_status_t text_save( irc_t *irc, int overwrite ) 94 94 { 95 95 char s[512]; … … 102 102 FILE *fp; 103 103 char *hash; 104 105 if (!overwrite) { 106 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); 107 if (access( path, F_OK ) != -1) 108 return STORAGE_ALREADY_EXISTS; 109 110 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" ); 111 if (access( path, F_OK ) != -1) 112 return STORAGE_ALREADY_EXISTS; 113 } 104 114 105 115 /*\ … … 127 137 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks~" ); 128 138 fp = fopen( path, "w" ); 129 if( !fp ) return ( 0 );139 if( !fp ) return STORAGE_OTHER_ERROR; 130 140 for( n = irc->nicks; n; n = n->next ) 131 141 { … … 138 148 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); 139 149 fclose( fp ); 140 return ( 0 );150 return STORAGE_OTHER_ERROR; 141 151 } 142 152 } … … 144 154 { 145 155 irc_usermsg( irc, "fclose() reported an error. Disk full?" ); 146 return ( 0 );156 return STORAGE_OTHER_ERROR; 147 157 } 148 158 … … 153 163 { 154 164 irc_usermsg( irc, "Error while removing old .nicks file" ); 155 return ( 0 );165 return STORAGE_OTHER_ERROR; 156 166 } 157 167 } … … 159 169 { 160 170 irc_usermsg( irc, "Error while renaming new .nicks file" ); 161 return ( 0 );171 return STORAGE_OTHER_ERROR; 162 172 } 163 173 164 174 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts~" ); 165 175 fp = fopen( path, "w" ); 166 if( !fp ) return ( 0 );176 if( !fp ) return STORAGE_OTHER_ERROR; 167 177 if( fprintf( fp, "%s", hash ) != strlen( hash ) ) 168 178 { 169 179 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); 170 180 fclose( fp ); 171 return ( 0 );181 return STORAGE_OTHER_ERROR; 172 182 } 173 183 g_free( hash ); … … 188 198 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); 189 199 fclose( fp ); 190 return ( 0 );200 return STORAGE_OTHER_ERROR; 191 201 } 192 202 } … … 206 216 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); 207 217 fclose( fp ); 208 return ( 0 );218 return STORAGE_OTHER_ERROR; 209 219 } 210 220 } … … 223 233 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" ); 224 234 fclose( fp ); 225 return ( 0 );235 return STORAGE_OTHER_ERROR; 226 236 } 227 237 } … … 231 241 { 232 242 irc_usermsg( irc, "fclose() reported an error. Disk full?" ); 233 return ( 0 );243 return STORAGE_OTHER_ERROR; 234 244 } 235 245 … … 240 250 { 241 251 irc_usermsg( irc, "Error while removing old .accounts file" ); 242 return ( 0 );252 return STORAGE_OTHER_ERROR; 243 253 } 244 254 } … … 246 256 { 247 257 irc_usermsg( irc, "Error while renaming new .accounts file" ); 248 return ( 0 );258 return STORAGE_OTHER_ERROR; 249 259 } 250 260 251 261 umask( ou ); 252 262 253 return( 1 ); 254 } 255 256 static int text_exists( const char *nick ) 257 { 258 char path[512]; 259 int checkie; 260 261 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" ); 262 checkie = access( path, F_OK ); 263 264 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" ); 265 checkie += access( path, F_OK ); 266 267 return ( checkie != -2 ); 268 } 269 270 static int text_remove( const char *nick ) 263 return STORAGE_OK; 264 } 265 266 static storage_status_t text_remove( const char *nick, const char *password ) 271 267 { 272 268 char s[512]; 269 FILE *fp; 270 271 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" ); 272 fp = fopen( s, "r" ); 273 if (!fp) 274 return STORAGE_NO_SUCH_USER; 275 276 fscanf( fp, "%32[^\n]s", s ); 277 fclose( fp ); 278 279 /*FIXME Test if password is correct */ 273 280 274 281 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" ); 275 282 if (unlink( s ) == -1) 276 return ( 1 );283 return STORAGE_OTHER_ERROR; 277 284 278 285 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" ); 279 286 if (unlink( s ) == -1) 280 return( 1 ); 281 282 return( 0 ); 283 } 284 285 static int text_check_pass( const char *nick, const char *password ) 286 { 287 char s[512]; 288 FILE *fp; 289 290 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" ); 291 fp = fopen( s, "r" ); 292 293 fscanf( fp, "%32[^\n]s", s ); 294 fclose( fp ); 295 296 /* FIXME */ 297 return( 0 ); 287 return STORAGE_OTHER_ERROR; 288 289 return STORAGE_OK; 298 290 } 299 291 … … 301 293 .name = "text", 302 294 .init = text_init, 303 .exists = text_exists,304 .check_pass = text_check_pass,305 295 .remove = text_remove, 306 296 .load = text_load,
Note: See TracChangeset
for help on using the changeset viewer.