comparison src/client.c @ 250:93d5d8b098da noffle

[svn] *** empty log message ***
author mirkol
date Wed, 05 Jun 2002 23:03:44 +0100
parents fbff73fe5b40
children f049f8639dc0
comparison
equal deleted inserted replaced
249:0340b9c17edc 250:93d5d8b098da
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 371 2002-02-26 17:13:31Z bears $ 4 $Id: client.c 382 2002-06-05 22:03:44Z mirkol $
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
42 used the "to." hierarchy for dark and mysterious purposes I think 42 used the "to." hierarchy for dark and mysterious purposes I think
43 are to do with newsfeeds. The recommended restrictions are documented 43 are to do with newsfeeds. The recommended restrictions are documented
44 in C.Lindsay, "News Article Format", <draft-ietf-usefor-article-03.txt>. 44 in C.Lindsay, "News Article Format", <draft-ietf-usefor-article-03.txt>.
45 */ 45 */
46 46
47 struct ForbiddenGroupName
48 {
49 const char *pattern;
50 Bool match;
51 } forbiddenGroupNames[] =
52 {
53 { "*.*", FALSE }, /* Single component */
54 { "control.*", TRUE }, /* control.* groups */
55 { "to.*", TRUE }, /* to.* groups */
56 { "*.all", TRUE }, /* 'all' as a component */
57 { "*.all.*", TRUE },
58 { "all.*", TRUE },
59 { "*.ctl", TRUE }, /* 'ctl' as a component */
60 { "*.ctl.*", TRUE },
61 { "ctl.*", TRUE }
62 };
63
64 struct 47 struct
65 { 48 {
66 FILE* in; /* Receiving socket from server */ 49 FILE* in; /* Receiving socket from server */
67 FILE* out; /* Sending socket to server */ 50 FILE* out; /* Sending socket to server */
68 Str lastCmd; /* Last command line */ 51 Str lastCmd; /* Last command line */
266 { 249 {
267 DynStr *res; 250 DynStr *res;
268 Str line; 251 Str line;
269 Bool err; 252 Bool err;
270 253
271 res = new_DynStr(2048); 254 res = new_DynStr( MAXCHAR );
272 if ( res == NULL ) 255 if ( res == NULL )
273 return NULL; 256 return NULL;
274 257
275 while ( getTxtLn( line, &err ) && ! err ) 258 while ( getTxtLn( line, &err ) && ! err )
276 DynStr_appLn( res, line ); 259 DynStr_appLn( res, line );
416 del_GrEn( ge ); 399 del_GrEn( ge );
417 return FALSE; 400 return FALSE;
418 } 401 }
419 402
420 static Bool 403 static Bool
421 isForbiddenGroupName( const char *name ) 404 processGrps( Bool noServerPattern )
422 {
423 size_t i;
424
425 for ( i = 0;
426 i < sizeof( forbiddenGroupNames ) /
427 sizeof( struct ForbiddenGroupName );
428 i++ )
429 {
430 /* Negate result of Wld_match to ensure it is 1 or 0. */
431 if ( forbiddenGroupNames[i].match !=
432 ( ! Wld_match( name, forbiddenGroupNames[i].pattern ) ) )
433 return TRUE;
434 }
435
436 return FALSE;
437 }
438
439 static void
440 processGrps( const char *lines, Bool noServerPattern )
441 { 405 {
442 char postAllow; 406 char postAllow;
407 Bool groupupdate;
408 Bool err;
443 int first, last; 409 int first, last;
444 Str grp, line, file; 410 Str grp, file;
445 Bool groupupdate; 411 Str line;
446 412
447 ASSERT( ! Lock_gotLock() ); 413 ASSERT( ! Lock_gotLock() );
448 if ( ! Lock_openDatabases() ) 414 if ( ! Lock_openDatabases() )
449 return; 415 return TRUE; /* silently ignore */
450 416
451 groupupdate = FALSE; 417 groupupdate = FALSE;
452 while ( ( lines = Utl_getLn( line, lines) ) != NULL ) 418
453 { 419 while ( getTxtLn( line, &err ) && !err )
454 if ( sscanf( line, "%s %d %d %c", 420 {
421 if ( sscanf( line, MAXCHAR_FMT " %d %d %c",
455 grp, &last, &first, &postAllow ) != 4 ) 422 grp, &last, &first, &postAllow ) != 4 )
456 { 423 {
457 Log_err( "Unknown reply to LIST or NEWGROUPS: %s", line ); 424 Log_err( "Unknown reply to LIST or NEWGROUPS: %s", line );
458 continue; 425 continue;
459 } 426 }
460 if ( ! Grp_isValidGroupName( grp ) ) 427 if ( ! Grp_isValidName( grp ) )
461 { 428 {
462 Log_inf( "Group name %s invalid", grp ); 429 Log_inf( "Group name %s invalid", grp );
463 continue; 430 continue;
464 } 431 }
465 if ( isForbiddenGroupName( grp ) ) 432 if ( Grp_isForbiddenName( grp ) )
466 { 433 {
467 Log_inf( "Group %s forbidden", grp ); 434 Log_inf( "Group %s forbidden", grp );
468 continue; 435 continue;
469 } 436 }
470 if ( noServerPattern && ! isGetGroup( grp ) ) 437 if ( noServerPattern && ! isGetGroup( grp ) )
511 { 478 {
512 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", 479 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate",
513 Cfg_spoolDir() ); 480 Cfg_spoolDir() );
514 Utl_stamp( file ); 481 Utl_stamp( file );
515 } 482 }
483
484 /* I'm absolutely not sure about this. */
485 if ( err && groupupdate )
486 Log_err( "Group list may be corrupted with bogus data." );
487
516 Lock_closeDatabases(); 488 Lock_closeDatabases();
489 return !err;
517 } 490 }
518 491
519 void 492 void
520 Client_disconnect( void ) 493 Client_disconnect( void )
521 { 494 {
529 static int 502 static int
530 doGetGrps( const char *pattern, Bool *noServerPattern ) 503 doGetGrps( const char *pattern, Bool *noServerPattern )
531 { 504 {
532 Str cmd; 505 Str cmd;
533 int stat; 506 int stat;
534 DynStr *response;
535 507
536 Utl_cpyStr( cmd, "LIST ACTIVE" ); 508 Utl_cpyStr( cmd, "LIST ACTIVE" );
537 if ( pattern[ 0 ] != '\0' ) 509 if ( pattern[ 0 ] != '\0' )
538 { 510 {
539 Utl_catStr( cmd, " " ); 511 Utl_catStr( cmd, " " );
562 { 534 {
563 Log_err( "%s failed: %s", cmd, client.lastStat ); 535 Log_err( "%s failed: %s", cmd, client.lastStat );
564 return stat; 536 return stat;
565 } 537 }
566 538
567 response = collectTxt(); 539
568 if ( response == NULL ) 540 if ( processGrps( *noServerPattern ) == FALSE )
569 return STAT_CONNECTION_LOST; 541 return STAT_CONNECTION_LOST;
570 542
571 processGrps( DynStr_str( response ), *noServerPattern );
572 del_DynStr( response );
573 return STAT_OK; 543 return STAT_OK;
574 } 544 }
575 545
576 int 546 int
577 Client_getGrps( void ) 547 Client_getGrps( void )
648 618
649 lines = DynStr_str( response ); 619 lines = DynStr_str( response );
650 result = STAT_OK; 620 result = STAT_OK;
651 while ( ( lines = Utl_getLn( line, lines) ) != NULL ) 621 while ( ( lines = Utl_getLn( line, lines) ) != NULL )
652 { 622 {
653 if ( sscanf( line, "%s", name ) != 1 ) 623 if ( sscanf( line, MAXCHAR_FMT, name ) != 1 )
654 { 624 {
655 Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line ); 625 Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line );
656 result = STAT_PROGRAM_FAULT; 626 result = STAT_PROGRAM_FAULT;
657 break; 627 break;
658 } 628 }
701 int 671 int
702 Client_getNewgrps( const time_t *lastTime ) 672 Client_getNewgrps( const time_t *lastTime )
703 { 673 {
704 Str s; 674 Str s;
705 const char *p; 675 const char *p;
706 DynStr *response;
707 int stat; 676 int stat;
708 677
709 ASSERT( *lastTime > 0 ); 678 ASSERT( *lastTime > 0 );
710 strftime( s, MAXCHAR, "%Y%m%d %H%M00", gmtime( lastTime ) ); 679 strftime( s, MAXCHAR, "%Y%m%d %H%M00", gmtime( lastTime ) );
711 /* 680 /*
721 { 690 {
722 Log_err( "NEWGROUPS command failed: %s", client.lastStat ); 691 Log_err( "NEWGROUPS command failed: %s", client.lastStat );
723 return stat; 692 return stat;
724 } 693 }
725 694
726 response = collectTxt(); 695 if( processGrps( TRUE ) == FALSE )
727 if ( response == NULL )
728 return STAT_CONNECTION_LOST; 696 return STAT_CONNECTION_LOST;
729 697
730 processGrps( DynStr_str( response ), TRUE );
731 del_DynStr( response );
732 return STAT_OK; 698 return STAT_OK;
733 } 699 }
734 700
735 static const char * 701 static const char *
736 readField( Str result, const char *p ) 702 readField( Str result, const char *p )