Changeset a1f17d4 for storage_text.c
- Timestamp:
- 2005-12-08T14:14:28Z (18 years ago)
- Branches:
- master
- Children:
- 7989fcf3
- Parents:
- 1ee6c18
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.