comparison src/database.c @ 61:adf0af5152f7 noffle

[svn] Renamed some variables and function names, because they caused compiler warnings because of shadowing global variables from system include files (index, stat, serv).
author enz
date Fri, 12 May 2000 18:19:38 +0100
parents 125d79c9e586
children be450ac830b2
comparison
equal deleted inserted replaced
60:defaa632baae 61:adf0af5152f7
1 /* 1 /*
2 database.c 2 database.c
3 3
4 $Id: database.c 60 2000-05-09 22:28:38Z uh1763 $ 4 $Id: database.c 67 2000-05-12 17:19:38Z enz $
5 5
6 Uses GNU gdbm library. Using Berkeley db (included in libc6) was 6 Uses GNU gdbm library. Using Berkeley db (included in libc6) was
7 cumbersome. It is based on Berkeley db 1.85, which has severe bugs 7 cumbersome. It is based on Berkeley db 1.85, which has severe bugs
8 (e.g. it is not recommended to delete or overwrite entries with 8 (e.g. it is not recommended to delete or overwrite entries with
9 overflow pages). 9 overflow pages).
39 39
40 /* Msg Id of presently loaded article, empty if none loaded */ 40 /* Msg Id of presently loaded article, empty if none loaded */
41 Str msgId; 41 Str msgId;
42 42
43 /* Status of loaded article */ 43 /* Status of loaded article */
44 int stat; /* Flags */ 44 int status; /* Flags */
45 time_t lastAccess; 45 time_t lastAccess;
46 46
47 /* Overview of loaded article */ 47 /* Overview of loaded article */
48 Str subj; 48 Str subj;
49 Str from; 49 Str from;
133 return FALSE; 133 return FALSE;
134 } 134 }
135 135
136 Utl_cpyStr( db.msgId, msgId ); 136 Utl_cpyStr( db.msgId, msgId );
137 p = Utl_getLn( t, (char *)dptr ); 137 p = Utl_getLn( t, (char *)dptr );
138 if ( ! p || sscanf( t, "%x", &db.stat ) != 1 ) 138 if ( ! p || sscanf( t, "%x", &db.status ) != 1 )
139 { 139 {
140 Log_err( "Entry in database '%s' is corrupt (status)", msgId ); 140 Log_err( "Entry in database '%s' is corrupt (status)", msgId );
141 return FALSE; 141 return FALSE;
142 } 142 }
143 p = Utl_getLn( t, p ); 143 p = Utl_getLn( t, p );
181 datum key, val; 181 datum key, val;
182 182
183 if ( strcmp( db.msgId, "" ) == 0 ) 183 if ( strcmp( db.msgId, "" ) == 0 )
184 return FALSE; 184 return FALSE;
185 s = new_DynStr( 5000 ); 185 s = new_DynStr( 5000 );
186 snprintf( t, MAXCHAR, "%x", db.stat ); 186 snprintf( t, MAXCHAR, "%x", db.status );
187 DynStr_appLn( s, t ); 187 DynStr_appLn( s, t );
188 snprintf( t, MAXCHAR, "%lu", db.lastAccess ); 188 snprintf( t, MAXCHAR, "%lu", db.lastAccess );
189 DynStr_appLn( s, t ); 189 DynStr_appLn( s, t );
190 DynStr_appLn( s, db.subj ); 190 DynStr_appLn( s, db.subj );
191 DynStr_appLn( s, db.from ); 191 DynStr_appLn( s, db.from );
224 msgId = Ov_msgId( ov ); 224 msgId = Ov_msgId( ov );
225 Log_dbg( "Preparing entry %s", msgId ); 225 Log_dbg( "Preparing entry %s", msgId );
226 if ( Db_contains( msgId ) ) 226 if ( Db_contains( msgId ) )
227 Log_err( "Preparing article twice: %s", msgId ); 227 Log_err( "Preparing article twice: %s", msgId );
228 228
229 db.stat = DB_NOT_DOWNLOADED; 229 db.status = DB_NOT_DOWNLOADED;
230 db.lastAccess = time( NULL ); 230 db.lastAccess = time( NULL );
231 231
232 Utl_cpyStr( db.msgId, msgId ); 232 Utl_cpyStr( db.msgId, msgId );
233 Utl_cpyStr( db.subj, Ov_subj( ov ) ); 233 Utl_cpyStr( db.subj, Ov_subj( ov ) );
234 Utl_cpyStr( db.from, Ov_from( ov ) ); 234 Utl_cpyStr( db.from, Ov_from( ov ) );
255 if ( ! loadArt( msgId ) ) 255 if ( ! loadArt( msgId ) )
256 { 256 {
257 Log_err( "Cannot find info about '%s' in database", msgId ); 257 Log_err( "Cannot find info about '%s' in database", msgId );
258 return FALSE; 258 return FALSE;
259 } 259 }
260 if ( ! ( db.stat & DB_NOT_DOWNLOADED ) ) 260 if ( ! ( db.status & DB_NOT_DOWNLOADED ) )
261 { 261 {
262 Log_err( "Trying to store already retrieved article '%s'", msgId ); 262 Log_err( "Trying to store already retrieved article '%s'", msgId );
263 return FALSE; 263 return FALSE;
264 } 264 }
265 db.stat &= ~DB_NOT_DOWNLOADED; 265 db.status &= ~DB_NOT_DOWNLOADED;
266 db.stat &= ~DB_RETRIEVING_FAILED; 266 db.status &= ~DB_RETRIEVING_FAILED;
267 db.lastAccess = time( NULL ); 267 db.lastAccess = time( NULL );
268 268
269 DynStr_clear( db.txt ); 269 DynStr_clear( db.txt );
270 270
271 /* Read header */ 271 /* Read header */
283 if ( Prt_getField( field, value, lineEx ) ) 283 if ( Prt_getField( field, value, lineEx ) )
284 { 284 {
285 if ( strcmp( field, "x-noffle-status" ) == 0 ) 285 if ( strcmp( field, "x-noffle-status" ) == 0 )
286 { 286 {
287 if ( strstr( value, "NOT_DOWNLOADED" ) != 0 ) 287 if ( strstr( value, "NOT_DOWNLOADED" ) != 0 )
288 db.stat |= DB_NOT_DOWNLOADED; 288 db.status |= DB_NOT_DOWNLOADED;
289 } 289 }
290 else if ( strcmp( field, "message-id" ) != 0 290 else if ( strcmp( field, "message-id" ) != 0
291 && strcmp( field, "xref" ) != 0 291 && strcmp( field, "xref" ) != 0
292 && strcmp( field, "references" ) != 0 292 && strcmp( field, "references" ) != 0
293 && strcmp( field, "subject" ) != 0 293 && strcmp( field, "subject" ) != 0
300 } 300 }
301 } 301 }
302 302
303 /* Read body */ 303 /* Read body */
304 while ( ( artTxt = Utl_getLn( line, artTxt ) ) ) 304 while ( ( artTxt = Utl_getLn( line, artTxt ) ) )
305 if ( ! ( db.stat & DB_NOT_DOWNLOADED ) ) 305 if ( ! ( db.status & DB_NOT_DOWNLOADED ) )
306 DynStr_appLn( db.txt, line ); 306 DynStr_appLn( db.txt, line );
307 307
308 return saveArt(); 308 return saveArt();
309 } 309 }
310 310
311 void 311 void
312 Db_setStat( const char *msgId, int stat ) 312 Db_setStatus( const char *msgId, int status )
313 { 313 {
314 if ( loadArt( msgId ) ) 314 if ( loadArt( msgId ) )
315 { 315 {
316 db.stat = stat; 316 db.status = status;
317 saveArt(); 317 saveArt();
318 } 318 }
319 } 319 }
320 320
321 void 321 void
408 Db_header( const char *msgId ) 408 Db_header( const char *msgId )
409 { 409 {
410 static DynStr *s = NULL; 410 static DynStr *s = NULL;
411 411
412 Str date, t; 412 Str date, t;
413 int stat; 413 int status;
414 const char *p; 414 const char *p;
415 415
416 if ( s == NULL ) 416 if ( s == NULL )
417 s = new_DynStr( 5000 ); 417 s = new_DynStr( 5000 );
418 else 418 else
420 ASSERT( db.dbf ); 420 ASSERT( db.dbf );
421 if ( ! loadArt( msgId ) ) 421 if ( ! loadArt( msgId ) )
422 return NULL; 422 return NULL;
423 strftime( date, MAXCHAR, "%Y-%m-%d %H:%M:%S", 423 strftime( date, MAXCHAR, "%Y-%m-%d %H:%M:%S",
424 localtime( &db.lastAccess ) ); 424 localtime( &db.lastAccess ) );
425 stat = db.stat; 425 status = db.status;
426 snprintf( t, MAXCHAR, 426 snprintf( t, MAXCHAR,
427 "Message-ID: %s\n" 427 "Message-ID: %s\n"
428 "X-NOFFLE-Status:%s%s%s\n" 428 "X-NOFFLE-Status:%s%s%s\n"
429 "X-NOFFLE-LastAccess: %s\n", 429 "X-NOFFLE-LastAccess: %s\n",
430 msgId, 430 msgId,
431 stat & DB_INTERESTING ? " INTERESTING" : "", 431 status & DB_INTERESTING ? " INTERESTING" : "",
432 stat & DB_NOT_DOWNLOADED ? " NOT_DOWNLOADED" : "", 432 status & DB_NOT_DOWNLOADED ? " NOT_DOWNLOADED" : "",
433 stat & DB_RETRIEVING_FAILED ? " RETRIEVING_FAILED" : "", 433 status & DB_RETRIEVING_FAILED ? " RETRIEVING_FAILED" : "",
434 date ); 434 date );
435 DynStr_app( s, t ); 435 DynStr_app( s, t );
436 appendLongHeader( s, "Subject:", db.subj ); 436 appendLongHeader( s, "Subject:", db.subj );
437 appendLongHeader( s, "From:", db.from ); 437 appendLongHeader( s, "From:", db.from );
438 appendLongHeader( s, "Date:", db.date ); 438 appendLongHeader( s, "Date:", db.date );
464 return ""; 464 return "";
465 return ( p + 2 ); 465 return ( p + 2 );
466 } 466 }
467 467
468 int 468 int
469 Db_stat( const char *msgId ) 469 Db_status( const char *msgId )
470 { 470 {
471 if ( ! loadArt( msgId ) ) 471 if ( ! loadArt( msgId ) )
472 return 0; 472 return 0;
473 return db.stat; 473 return db.status;
474 } 474 }
475 475
476 time_t 476 time_t
477 Db_lastAccess( const char *msgId ) 477 Db_lastAccess( const char *msgId )
478 { 478 {