Mercurial > noffle
comparison src/server.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 | 7250be163ec4 |
comparison
equal
deleted
inserted
replaced
60:defaa632baae | 61:adf0af5152f7 |
---|---|
1 /* | 1 /* |
2 server.c | 2 server.c |
3 | 3 |
4 $Id: server.c 60 2000-05-09 22:28:38Z uh1763 $ | 4 $Id: server.c 67 2000-05-12 17:19:38Z enz $ |
5 */ | 5 */ |
6 | 6 |
7 #if HAVE_CONFIG_H | 7 #if HAVE_CONFIG_H |
8 #include <config.h> | 8 #include <config.h> |
9 #endif | 9 #endif |
53 struct | 53 struct |
54 { | 54 { |
55 Bool running; | 55 Bool running; |
56 int artPtr; | 56 int artPtr; |
57 Str grp; /* selected group, "" if none */ | 57 Str grp; /* selected group, "" if none */ |
58 } serv = { FALSE, 0, "" }; | 58 } server = { FALSE, 0, "" }; |
59 | 59 |
60 typedef struct Cmd | 60 typedef struct Cmd |
61 { | 61 { |
62 const char *name; | 62 const char *name; |
63 const char *syntax; | 63 const char *syntax; |
120 static void | 120 static void |
121 noteInterest( void ) | 121 noteInterest( void ) |
122 { | 122 { |
123 FetchMode mode; | 123 FetchMode mode; |
124 | 124 |
125 Grp_setLastAccess( serv.grp, time( NULL ) ); | 125 Grp_setLastAccess( server.grp, time( NULL ) ); |
126 if ( ! Grp_local ( serv.grp ) && Cfg_autoSubscribe() && ! Online_true() ) | 126 if ( ! Grp_local ( server.grp ) && Cfg_autoSubscribe() && ! Online_true() ) |
127 { | 127 { |
128 Fetchlist_read(); | 128 Fetchlist_read(); |
129 if ( ! Fetchlist_contains( serv.grp ) ) | 129 if ( ! Fetchlist_contains( server.grp ) ) |
130 { | 130 { |
131 if ( strcmp( Cfg_autoSubscribeMode(), "full" ) == 0 ) | 131 if ( strcmp( Cfg_autoSubscribeMode(), "full" ) == 0 ) |
132 mode = FULL; | 132 mode = FULL; |
133 else if ( strcmp( Cfg_autoSubscribeMode(), "thread" ) == 0 ) | 133 else if ( strcmp( Cfg_autoSubscribeMode(), "thread" ) == 0 ) |
134 mode = THREAD; | 134 mode = THREAD; |
135 else | 135 else |
136 mode = OVER; | 136 mode = OVER; |
137 Fetchlist_add( serv.grp, mode ); | 137 Fetchlist_add( server.grp, mode ); |
138 Fetchlist_write(); | 138 Fetchlist_write(); |
139 Pseudo_autoSubscribed(); | 139 Pseudo_autoSubscribed(); |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
208 | 208 |
209 static void | 209 static void |
210 checkNewArts( const char *grp ) | 210 checkNewArts( const char *grp ) |
211 { | 211 { |
212 if ( ! Online_true() | 212 if ( ! Online_true() |
213 || strcmp( grp, serv.grp ) == 0 | 213 || strcmp( grp, server.grp ) == 0 |
214 || Grp_local( grp ) | 214 || Grp_local( grp ) |
215 || time( NULL ) - Grp_lastAccess( serv.grp ) < 1800 ) | 215 || time( NULL ) - Grp_lastAccess( server.grp ) < 1800 ) |
216 return; | 216 return; |
217 if ( Fetch_init( Grp_serv( grp ) ) ) | 217 if ( Fetch_init( Grp_server( grp ) ) ) |
218 { | 218 { |
219 Fetch_getNewArts( grp, OVER ); | 219 Fetch_getNewArts( grp, OVER ); |
220 Fetch_close(); | 220 Fetch_close(); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 static void | 224 static void |
225 postArts( void ) | 225 postArts( void ) |
226 { | 226 { |
227 Str serv; | 227 Str s; |
228 | 228 |
229 Cfg_beginServEnum(); | 229 Cfg_beginServEnum(); |
230 while ( Cfg_nextServ( serv ) ) | 230 while ( Cfg_nextServ( s ) ) |
231 if ( Fetch_init( serv ) ) | 231 if ( Fetch_init( s ) ) |
232 { | 232 { |
233 Fetch_postArts(); | 233 Fetch_postArts(); |
234 Fetch_close(); | 234 Fetch_close(); |
235 } | 235 } |
236 } | 236 } |
261 | 261 |
262 static void | 262 static void |
263 changeToGrp( const char *grp ) | 263 changeToGrp( const char *grp ) |
264 { | 264 { |
265 checkNewArts( grp ); | 265 checkNewArts( grp ); |
266 Utl_cpyStr( serv.grp, grp ); | 266 Utl_cpyStr( server.grp, grp ); |
267 readCont( grp ); | 267 readCont( grp ); |
268 serv.artPtr = Cont_first(); | 268 server.artPtr = Cont_first(); |
269 } | 269 } |
270 | 270 |
271 static Bool | 271 static Bool |
272 doGrp( char *arg, const Cmd *cmd ) | 272 doGrp( char *arg, const Cmd *cmd ) |
273 { | 273 { |
294 } | 294 } |
295 | 295 |
296 static Bool | 296 static Bool |
297 testGrpSelected( void ) | 297 testGrpSelected( void ) |
298 { | 298 { |
299 if ( *serv.grp == '\0' ) | 299 if ( *server.grp == '\0' ) |
300 { | 300 { |
301 putStat( STAT_NO_GRP_SELECTED, "No group selected" ); | 301 putStat( STAT_NO_GRP_SELECTED, "No group selected" ); |
302 return FALSE; | 302 return FALSE; |
303 } | 303 } |
304 return TRUE; | 304 return TRUE; |
305 } | 305 } |
306 | 306 |
307 static void | 307 static void |
308 findServ( const char *msgId, Str result ) | 308 findServer( const char *msgId, Str result ) |
309 { | 309 { |
310 const char *p, *pColon, *serv; | 310 const char *p, *pColon, *srv; |
311 Str s, grp; | 311 Str s, grp; |
312 | 312 |
313 Utl_cpyStr( result, "(unknown)" ); | 313 Utl_cpyStr( result, "(unknown)" ); |
314 if ( Db_contains( msgId ) ) | 314 if ( Db_contains( msgId ) ) |
315 { | 315 { |
320 { | 320 { |
321 pColon = strstr( p, ":" ); | 321 pColon = strstr( p, ":" ); |
322 if ( pColon ) | 322 if ( pColon ) |
323 { | 323 { |
324 Utl_cpyStrN( grp, p, pColon - p ); | 324 Utl_cpyStrN( grp, p, pColon - p ); |
325 serv = Grp_serv( grp ); | 325 srv = Grp_server( grp ); |
326 if ( Cfg_servIsPreferential( serv, result ) ) | 326 if ( Cfg_servIsPreferential( srv, result ) ) |
327 Utl_cpyStr( result, serv ); | 327 Utl_cpyStr( result, srv ); |
328 } | 328 } |
329 } | 329 } |
330 while ( ( p = strtok( NULL, " \t" ) ) ); | 330 while ( ( p = strtok( NULL, " \t" ) ) ); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 static Bool | 334 static Bool |
335 retrieveArt( const char *msgId ) | 335 retrieveArt( const char *msgId ) |
336 { | 336 { |
337 Str serv; | 337 Str s; |
338 | 338 |
339 findServ( msgId, serv ); | 339 findServer( msgId, s ); |
340 if ( strcmp( serv, "(unknown)" ) == 0 | 340 if ( strcmp( s, "(unknown)" ) == 0 |
341 || strcmp( serv, GRP_LOCAL_SERVER_NAME ) == 0 ) | 341 || strcmp( s, GRP_LOCAL_SERVER_NAME ) == 0 ) |
342 return FALSE; | 342 return FALSE; |
343 if ( ! Client_connect( serv ) ) | 343 if ( ! Client_connect( s ) ) |
344 return FALSE; | 344 return FALSE; |
345 Client_retrieveArt( msgId ); | 345 Client_retrieveArt( msgId ); |
346 Client_disconnect(); | 346 Client_disconnect(); |
347 return TRUE; | 347 return TRUE; |
348 } | 348 } |
372 | 372 |
373 if ( sscanf( arg, "%d", &n ) == 1 ) | 373 if ( sscanf( arg, "%d", &n ) == 1 ) |
374 { | 374 { |
375 if ( ! checkNumb( n ) ) | 375 if ( ! checkNumb( n ) ) |
376 return FALSE; | 376 return FALSE; |
377 serv.artPtr = n; | 377 server.artPtr = n; |
378 ov = Cont_get( n ); | 378 ov = Cont_get( n ); |
379 *msgId = Ov_msgId( ov ); | 379 *msgId = Ov_msgId( ov ); |
380 *numb = n; | 380 *numb = n; |
381 } | 381 } |
382 else if ( strcmp( arg, "" ) == 0 ) | 382 else if ( strcmp( arg, "" ) == 0 ) |
383 { | 383 { |
384 if ( ! checkNumb( serv.artPtr ) ) | 384 if ( ! checkNumb( server.artPtr ) ) |
385 return FALSE; | 385 return FALSE; |
386 ov = Cont_get( serv.artPtr ); | 386 ov = Cont_get( server.artPtr ); |
387 *msgId = Ov_msgId( ov ); | 387 *msgId = Ov_msgId( ov ); |
388 *numb = serv.artPtr; | 388 *numb = server.artPtr; |
389 } | 389 } |
390 else | 390 else |
391 { | 391 { |
392 *msgId = arg; | 392 *msgId = arg; |
393 *numb = 0; | 393 *numb = 0; |
401 } | 401 } |
402 | 402 |
403 static void | 403 static void |
404 touchArticle( const char *msgId ) | 404 touchArticle( const char *msgId ) |
405 { | 405 { |
406 int stat = Db_stat( msgId ); | 406 int status = Db_status( msgId ); |
407 stat |= DB_INTERESTING; | 407 status |= DB_INTERESTING; |
408 Db_setStat( msgId, stat ); | 408 Db_setStatus( msgId, status ); |
409 Db_updateLastAccess( msgId ); | 409 Db_updateLastAccess( msgId ); |
410 } | 410 } |
411 | 411 |
412 static void | 412 static void |
413 touchReferences( const char *msgId ) | 413 touchReferences( const char *msgId ) |
439 | 439 |
440 static void | 440 static void |
441 doBodyInDb( const char *msgId ) | 441 doBodyInDb( const char *msgId ) |
442 { | 442 { |
443 int stat; | 443 int stat; |
444 Str serv; | 444 Str srv; |
445 | 445 |
446 touchArticle( msgId ); | 446 touchArticle( msgId ); |
447 touchReferences( msgId ); | 447 touchReferences( msgId ); |
448 stat = Db_stat( msgId ); | 448 stat = Db_status( msgId ); |
449 if ( Online_true() && ( stat & DB_NOT_DOWNLOADED ) ) | 449 if ( Online_true() && ( stat & DB_NOT_DOWNLOADED ) ) |
450 { | 450 { |
451 retrieveArt( msgId ); | 451 retrieveArt( msgId ); |
452 stat = Db_stat( msgId ); | 452 stat = Db_status( msgId ); |
453 } | 453 } |
454 if ( stat & DB_RETRIEVING_FAILED ) | 454 if ( stat & DB_RETRIEVING_FAILED ) |
455 { | 455 { |
456 Db_setStat( msgId, stat & ~DB_RETRIEVING_FAILED ); | 456 Db_setStatus( msgId, stat & ~DB_RETRIEVING_FAILED ); |
457 putTxtBuf( Db_body( msgId ) ); | 457 putTxtBuf( Db_body( msgId ) ); |
458 } | 458 } |
459 else if ( stat & DB_NOT_DOWNLOADED ) | 459 else if ( stat & DB_NOT_DOWNLOADED ) |
460 { | 460 { |
461 findServ( msgId, serv ); | 461 findServer( msgId, srv ); |
462 if ( Req_contains( serv, msgId ) ) | 462 if ( Req_contains( srv, msgId ) ) |
463 putTxtBuf( Pseudo_alreadyMarkedBody() ); | 463 putTxtBuf( Pseudo_alreadyMarkedBody() ); |
464 else if ( strcmp( serv, "(unknown)" ) != 0 && | 464 else if ( strcmp( srv, "(unknown)" ) != 0 && |
465 strcmp( serv, GRP_LOCAL_SERVER_NAME ) != 0 && | 465 strcmp( srv, GRP_LOCAL_SERVER_NAME ) != 0 && |
466 Req_add( serv, msgId ) ) | 466 Req_add( srv, msgId ) ) |
467 putTxtBuf( Pseudo_markedBody() ); | 467 putTxtBuf( Pseudo_markedBody() ); |
468 else | 468 else |
469 putTxtBuf( Pseudo_markingFailedBody() ); | 469 putTxtBuf( Pseudo_markingFailedBody() ); |
470 } | 470 } |
471 else | 471 else |
568 { | 568 { |
569 int n; | 569 int n; |
570 | 570 |
571 if ( testGrpSelected() ) | 571 if ( testGrpSelected() ) |
572 { | 572 { |
573 n = serv.artPtr; | 573 n = server.artPtr; |
574 if ( ! Cont_validNumb( n ) ) | 574 if ( ! Cont_validNumb( n ) ) |
575 putStat( STAT_NO_ART_SELECTED, "No article selected" ); | 575 putStat( STAT_NO_ART_SELECTED, "No article selected" ); |
576 else | 576 else |
577 { | 577 { |
578 while ( ! Cont_validNumb( --n ) && n >= Cont_first() ); | 578 while ( ! Cont_validNumb( --n ) && n >= Cont_first() ); |
580 putStat( STAT_NO_PREV_ART, "No previous article" ); | 580 putStat( STAT_NO_PREV_ART, "No previous article" ); |
581 else | 581 else |
582 { | 582 { |
583 putStat( STAT_ART_RETRIEVED, "%ld %s selected", | 583 putStat( STAT_ART_RETRIEVED, "%ld %s selected", |
584 n, Ov_msgId( Cont_get( n ) ) ); | 584 n, Ov_msgId( Cont_get( n ) ) ); |
585 serv.artPtr = n; | 585 server.artPtr = n; |
586 } | 586 } |
587 } | 587 } |
588 } | 588 } |
589 return TRUE; | 589 return TRUE; |
590 } | 590 } |
874 { | 874 { |
875 int n; | 875 int n; |
876 | 876 |
877 if ( testGrpSelected() ) | 877 if ( testGrpSelected() ) |
878 { | 878 { |
879 n = serv.artPtr; | 879 n = server.artPtr; |
880 if ( ! Cont_validNumb( n ) ) | 880 if ( ! Cont_validNumb( n ) ) |
881 putStat( STAT_NO_ART_SELECTED, "No article selected" ); | 881 putStat( STAT_NO_ART_SELECTED, "No article selected" ); |
882 else | 882 else |
883 { | 883 { |
884 while ( ! Cont_validNumb( ++n ) && n <= Cont_last() ); | 884 while ( ! Cont_validNumb( ++n ) && n <= Cont_last() ); |
886 putStat( STAT_NO_NEXT_ART, "No next article" ); | 886 putStat( STAT_NO_NEXT_ART, "No next article" ); |
887 else | 887 else |
888 { | 888 { |
889 putStat( STAT_ART_RETRIEVED, "%ld %s selected", | 889 putStat( STAT_ART_RETRIEVED, "%ld %s selected", |
890 n, Ov_msgId( Cont_get( n ) ) ); | 890 n, Ov_msgId( Cont_get( n ) ) ); |
891 serv.artPtr = n; | 891 server.artPtr = n; |
892 } | 892 } |
893 } | 893 } |
894 } | 894 } |
895 return TRUE; | 895 return TRUE; |
896 } | 896 } |
935 grp != NULL; | 935 grp != NULL; |
936 grp = Itl_next( newsgroups ) ) | 936 grp = Itl_next( newsgroups ) ) |
937 { | 937 { |
938 if ( Grp_exists( grp ) && ! Grp_local( grp ) ) | 938 if ( Grp_exists( grp ) && ! Grp_local( grp ) ) |
939 { | 939 { |
940 if ( ! Out_add( Grp_serv( grp ), msgId, art ) ) | 940 if ( ! Out_add( Grp_server( grp ), msgId, art ) ) |
941 { | 941 { |
942 Log_err( "Cannot add posted article to outgoing directory" ); | 942 Log_err( "Cannot add posted article to outgoing directory" ); |
943 err = TRUE; | 943 err = TRUE; |
944 } | 944 } |
945 break; | 945 break; |
1000 grp != NULL; | 1000 grp != NULL; |
1001 grp = Itl_next( newsgroups ) ) | 1001 grp = Itl_next( newsgroups ) ) |
1002 { | 1002 { |
1003 if ( Grp_exists( grp ) && ! Grp_local( grp ) ) | 1003 if ( Grp_exists( grp ) && ! Grp_local( grp ) ) |
1004 { | 1004 { |
1005 if ( ! Out_add( Grp_serv( grp ), msgId, art ) ) | 1005 if ( ! Out_add( Grp_server( grp ), msgId, art ) ) |
1006 { | 1006 { |
1007 Log_err( "Cannot add posted article to outgoing directory" ); | 1007 Log_err( "Cannot add posted article to outgoing directory" ); |
1008 err = TRUE; | 1008 err = TRUE; |
1009 } | 1009 } |
1010 break; | 1010 break; |
1219 Utl_cpyStr( t, s ); | 1219 Utl_cpyStr( t, s ); |
1220 p = Utl_stripWhiteSpace( t ); | 1220 p = Utl_stripWhiteSpace( t ); |
1221 r = sscanf( p, "%d-%d", first, last ); | 1221 r = sscanf( p, "%d-%d", first, last ); |
1222 if ( r < 1 ) | 1222 if ( r < 1 ) |
1223 { | 1223 { |
1224 *first = serv.artPtr; | 1224 *first = server.artPtr; |
1225 *last = serv.artPtr; | 1225 *last = server.artPtr; |
1226 } | 1226 } |
1227 else if ( r == 1 ) | 1227 else if ( r == 1 ) |
1228 { | 1228 { |
1229 if ( p[ strlen( p ) - 1 ] == '-' ) | 1229 if ( p[ strlen( p ) - 1 ] == '-' ) |
1230 *last = Cont_last(); | 1230 *last = Cont_last(); |
1331 putTxtLn( "%lu %d", n, Ov_lines( ov ) ); | 1331 putTxtLn( "%lu %d", n, Ov_lines( ov ) ); |
1332 break; | 1332 break; |
1333 case XREF: | 1333 case XREF: |
1334 msgId = Ov_msgId( ov ); | 1334 msgId = Ov_msgId( ov ); |
1335 if ( Pseudo_isGeneralInfo( msgId ) ) | 1335 if ( Pseudo_isGeneralInfo( msgId ) ) |
1336 putTxtLn( "%lu %s:%lu", n, serv.grp, n ); | 1336 putTxtLn( "%lu %s:%lu", n, server.grp, n ); |
1337 else | 1337 else |
1338 putTxtLn( "%lu %s", n, Db_xref( msgId ) ); | 1338 putTxtLn( "%lu %s", n, Db_xref( msgId ) ); |
1339 break; | 1339 break; |
1340 default: | 1340 default: |
1341 ASSERT( FALSE ); | 1341 ASSERT( FALSE ); |
1458 | 1458 |
1459 if ( ! testGrpSelected() ) | 1459 if ( ! testGrpSelected() ) |
1460 return TRUE; | 1460 return TRUE; |
1461 parseRange( arg, &first, &last, &n ); | 1461 parseRange( arg, &first, &last, &n ); |
1462 if ( n == 0 ) | 1462 if ( n == 0 ) |
1463 first = last = serv.artPtr; | 1463 first = last = server.artPtr; |
1464 putStat( STAT_OVERS_FOLLOW, "Overview %ld-%ld", first, last ); | 1464 putStat( STAT_OVERS_FOLLOW, "Overview %ld-%ld", first, last ); |
1465 for ( i = first; i <= last; ++i ) | 1465 for ( i = first; i <= last; ++i ) |
1466 if ( ( ov = Cont_get( i ) ) ) | 1466 if ( ( ov = Cont_get( i ) ) ) |
1467 putTxtLn( "%lu\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t", | 1467 putTxtLn( "%lu\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t", |
1468 Ov_numb( ov ), Ov_subj( ov ), Ov_from( ov ), | 1468 Ov_numb( ov ), Ov_subj( ov ), Ov_from( ov ), |
1524 fflush( stdout ); | 1524 fflush( stdout ); |
1525 Log_dbg( "[S FLUSH]" ); | 1525 Log_dbg( "[S FLUSH]" ); |
1526 } | 1526 } |
1527 | 1527 |
1528 static Bool | 1528 static Bool |
1529 initServ( void ) | 1529 initServer( void ) |
1530 { | 1530 { |
1531 ASSERT( ! serv.running ); | 1531 ASSERT( ! server.running ); |
1532 if ( ! Lock_openDatabases() ) | 1532 if ( ! Lock_openDatabases() ) |
1533 return FALSE; | 1533 return FALSE; |
1534 serv.running = TRUE; | 1534 server.running = TRUE; |
1535 return TRUE; | 1535 return TRUE; |
1536 } | 1536 } |
1537 | 1537 |
1538 static void | 1538 static void |
1539 closeServ( void ) | 1539 closeServer( void ) |
1540 { | 1540 { |
1541 ASSERT( serv.running ); | 1541 ASSERT( server.running ); |
1542 serv.running = FALSE; | 1542 server.running = FALSE; |
1543 Lock_closeDatabases(); | 1543 Lock_closeDatabases(); |
1544 } | 1544 } |
1545 | 1545 |
1546 void | 1546 void |
1547 Serv_run( void ) | 1547 Server_run( void ) |
1548 { | 1548 { |
1549 Bool done; | 1549 Bool done; |
1550 int r; | 1550 int r; |
1551 Str line; | 1551 Str line; |
1552 struct timeval timeOut; | 1552 struct timeval timeOut; |
1567 r = select( STDIN_FILENO + 1, &readSet, NULL, NULL, &timeOut ); | 1567 r = select( STDIN_FILENO + 1, &readSet, NULL, NULL, &timeOut ); |
1568 if ( r < 0 ) | 1568 if ( r < 0 ) |
1569 done = TRUE; | 1569 done = TRUE; |
1570 else if ( r == 0 ) | 1570 else if ( r == 0 ) |
1571 { | 1571 { |
1572 if ( serv.running ) | 1572 if ( server.running ) |
1573 closeServ(); | 1573 closeServer(); |
1574 } | 1574 } |
1575 else /* ( r > 0 ) */ | 1575 else /* ( r > 0 ) */ |
1576 { | 1576 { |
1577 if ( ! serv.running ) | 1577 if ( ! server.running ) |
1578 { | 1578 { |
1579 if ( ! initServ() ) | 1579 if ( ! initServer() ) |
1580 { | 1580 { |
1581 putFatal( "Cannot init server" ); | 1581 putFatal( "Cannot init server" ); |
1582 done = TRUE; | 1582 done = TRUE; |
1583 } | 1583 } |
1584 } | 1584 } |
1589 } | 1589 } |
1590 else if ( ! parseAndExecute( line ) ) | 1590 else if ( ! parseAndExecute( line ) ) |
1591 done = TRUE; | 1591 done = TRUE; |
1592 } | 1592 } |
1593 } | 1593 } |
1594 if ( serv.running ) | 1594 if ( server.running ) |
1595 closeServ(); | 1595 closeServer(); |
1596 } | 1596 } |