Mercurial > noffle
comparison src/client.c @ 88:1fcdced0246e noffle
[svn] Move posting code to post.c, add command line posting
author | bears |
---|---|
date | Thu, 18 May 2000 13:17:23 +0100 |
parents | c7df2cc65cc1 |
children | c3312022e657 |
comparison
equal
deleted
inserted
replaced
87:bf8c97460fd7 | 88:1fcdced0246e |
---|---|
1 /* | 1 /* |
2 client.c | 2 client.c |
3 | 3 |
4 $Id: client.c 80 2000-05-13 15:36:35Z bears $ | 4 $Id: client.c 100 2000-05-18 12:17:23Z bears $ |
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 |
357 } | 357 } |
358 return FALSE; | 358 return FALSE; |
359 } | 359 } |
360 | 360 |
361 static Bool | 361 static Bool |
362 isGetGroup( const char *name ) | |
363 { | |
364 GroupEnum *ge; | |
365 Bool emptyList; | |
366 const char *pattern; | |
367 | |
368 emptyList = TRUE; | |
369 ge = new_GetGrEn( client.serv ); | |
370 while ( ( pattern = GrEn_next( ge ) ) != NULL ) | |
371 { | |
372 emptyList = FALSE; | |
373 if ( Wld_match( name, pattern ) ) | |
374 { | |
375 del_GrEn( ge ); | |
376 return TRUE; | |
377 } | |
378 } | |
379 | |
380 del_GrEn( ge ); | |
381 return emptyList; | |
382 } | |
383 | |
384 static Bool | |
385 isOmitGroup( const char *name ) | |
386 { | |
387 GroupEnum *ge; | |
388 const char *pattern; | |
389 | |
390 ge = new_OmitGrEn( client.serv ); | |
391 while ( ( pattern = GrEn_next( ge ) ) != NULL ) | |
392 if ( Wld_match( name, pattern ) ) | |
393 { | |
394 del_GrEn( ge ); | |
395 return TRUE; | |
396 } | |
397 | |
398 del_GrEn( ge ); | |
399 return FALSE; | |
400 } | |
401 | |
402 static Bool | |
362 isForbiddenGroupName( const char *name ) | 403 isForbiddenGroupName( const char *name ) |
363 { | 404 { |
364 size_t i; | 405 size_t i; |
365 | 406 |
366 for ( i = 0; | 407 for ( i = 0; |
376 | 417 |
377 return FALSE; | 418 return FALSE; |
378 } | 419 } |
379 | 420 |
380 static void | 421 static void |
381 processGrps( void ) | 422 processGrps( Bool noServerPattern ) |
382 { | 423 { |
383 char postAllow; | 424 char postAllow; |
384 Bool err; | 425 Bool err; |
385 int first, last; | 426 int first, last; |
386 Str grp, line, file; | 427 Str grp, line, file; |
396 if ( isForbiddenGroupName( grp ) ) | 437 if ( isForbiddenGroupName( grp ) ) |
397 { | 438 { |
398 Log_inf( "Group %s forbidden", grp ); | 439 Log_inf( "Group %s forbidden", grp ); |
399 continue; | 440 continue; |
400 } | 441 } |
442 if ( noServerPattern && ! isGetGroup( grp ) ) | |
443 continue; | |
444 if ( isOmitGroup( grp ) ) | |
445 continue; | |
401 if ( ! Grp_exists( grp ) ) | 446 if ( ! Grp_exists( grp ) ) |
402 { | 447 { |
403 Log_inf( "Registering new group '%s'", grp ); | 448 Log_inf( "Registering new group '%s'", grp ); |
404 Grp_create( grp ); | 449 Grp_create( grp ); |
405 /* Start local numbering with remote first number to avoid | 450 /* Start local numbering with remote first number to avoid |
443 fclose( client.in ); | 488 fclose( client.in ); |
444 fclose( client.out ); | 489 fclose( client.out ); |
445 client.in = client.out = NULL; | 490 client.in = client.out = NULL; |
446 } | 491 } |
447 | 492 |
493 static Bool | |
494 doGetGrps( const char *pattern, Bool *noServerPattern ) | |
495 { | |
496 Str cmd; | |
497 int stat; | |
498 | |
499 Utl_cpyStr( cmd, "LIST ACTIVE" ); | |
500 if ( pattern[ 0 ] != '\0' ) | |
501 { | |
502 Utl_catStr( cmd, " " ); | |
503 Utl_catStr( cmd, pattern ); | |
504 } | |
505 | |
506 *noServerPattern = FALSE; | |
507 if ( ! putCmd( cmd ) ) | |
508 return FALSE; | |
509 stat = getStat(); | |
510 if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) | |
511 { | |
512 *noServerPattern = TRUE; | |
513 if ( ! putCmd( "LIST ACTIVE" ) ) | |
514 return FALSE; | |
515 stat = getStat(); | |
516 } | |
517 if ( stat != STAT_GRPS_FOLLOW ) | |
518 { | |
519 Log_err( "%s failed: %s", cmd, client.lastStat ); | |
520 return FALSE; | |
521 } | |
522 processGrps( *noServerPattern ); | |
523 return TRUE; | |
524 } | |
525 | |
448 Bool | 526 Bool |
449 Client_getGrps( void ) | 527 Client_getGrps( void ) |
450 { | 528 { |
451 if ( ! putCmd( "LIST ACTIVE" ) ) | 529 GroupEnum *ge; |
452 return FALSE; | 530 const char *pattern; |
453 if ( getStat() != STAT_GRPS_FOLLOW ) | 531 Bool doneOne, noServerPattern, res; |
454 { | 532 |
455 Log_err( "LIST ACTIVE command failed: %s", client.lastStat ); | 533 Log_inf( "Getting groups" ); |
456 return FALSE; | 534 |
457 } | 535 doneOne = FALSE; |
458 processGrps(); | 536 res = TRUE; |
537 ge = new_GetGrEn( client.serv ); | |
538 while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) | |
539 { | |
540 res = doGetGrps( pattern, &noServerPattern ); | |
541 doneOne = TRUE; | |
542 if ( noServerPattern ) | |
543 break; | |
544 } | |
545 | |
546 if ( ! doneOne ) | |
547 res = doGetGrps( "", &noServerPattern ); | |
548 | |
549 del_GrEn( ge ); | |
550 return res; | |
551 } | |
552 | |
553 static Bool | |
554 doGetDsc( const char *pattern, Bool *noServerPattern ) | |
555 { | |
556 Bool err; | |
557 Str name, line, dsc, cmd; | |
558 int stat; | |
559 | |
560 Utl_cpyStr( cmd, "LIST NEWSGROUPS" ); | |
561 if ( pattern[ 0 ] != '\0' ) | |
562 { | |
563 Utl_catStr( cmd, " " ); | |
564 Utl_catStr( cmd, pattern ); | |
565 } | |
566 | |
567 *noServerPattern = FALSE; | |
568 if ( ! putCmd( cmd ) ) | |
569 return FALSE; | |
570 stat = getStat(); | |
571 if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) | |
572 { | |
573 *noServerPattern = TRUE; | |
574 if ( !putCmd( "LIST NEWSGROUPS" ) ) | |
575 return FALSE; | |
576 stat = getStat(); | |
577 } | |
578 if ( stat != STAT_GRPS_FOLLOW ) | |
579 { | |
580 Log_err( "%s failed: %s", cmd, client.lastStat ); | |
581 return FALSE; | |
582 } | |
583 while ( getTxtLn( line, &err ) && ! err ) | |
584 { | |
585 if ( sscanf( line, "%s", name ) != 1 ) | |
586 { | |
587 Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line ); | |
588 continue; | |
589 } | |
590 if ( *noServerPattern && ! isGetGroup( name ) ) | |
591 continue; | |
592 strcpy( dsc, Utl_restOfLn( line, 1 ) ); | |
593 if ( Grp_exists( name ) ) | |
594 { | |
595 Log_dbg( "Description of %s: %s", name, dsc ); | |
596 Grp_setDsc( name, dsc ); | |
597 } | |
598 } | |
459 return TRUE; | 599 return TRUE; |
460 } | 600 } |
461 | 601 |
462 Bool | 602 Bool |
463 Client_getDsc( void ) | 603 Client_getDsc( void ) |
464 { | 604 { |
605 GroupEnum *ge; | |
606 const char *pattern; | |
607 Bool doneOne, noServerPattern, res; | |
608 | |
609 Log_inf( "Querying group descriptions" ); | |
610 | |
611 doneOne = FALSE; | |
612 res = TRUE; | |
613 ge = new_GetGrEn( client.serv ); | |
614 while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) | |
615 { | |
616 res = doGetDsc( pattern, &noServerPattern ); | |
617 doneOne = TRUE; | |
618 if ( noServerPattern ) | |
619 break; | |
620 } | |
621 | |
622 if ( ! doneOne ) | |
623 res = doGetDsc( "", &noServerPattern ); | |
624 | |
625 del_GrEn( ge ); | |
626 return res; | |
627 } | |
628 | |
629 static Bool | |
630 doGetCreationTimes( const char *pattern, Bool *noServerPattern ) | |
631 { | |
465 Bool err; | 632 Bool err; |
466 Str name, line, dsc; | 633 Str name, line, cmd; |
467 | 634 time_t t; |
468 Log_inf( "Querying group descriptions" ); | 635 int stat; |
469 if ( ! putCmd( "LIST NEWSGROUPS" ) ) | 636 |
470 return FALSE; | 637 Utl_cpyStr( cmd, "LIST ACTIVE.TIMES" ); |
471 if ( getStat() != STAT_GRPS_FOLLOW ) | 638 if ( pattern[ 0 ] != '\0' ) |
472 { | 639 { |
473 Log_err( "LIST NEWSGROUPS failed: %s", client.lastStat ); | 640 Utl_catStr( cmd, " " ); |
641 Utl_catStr( cmd, pattern ); | |
642 } | |
643 | |
644 *noServerPattern = FALSE; | |
645 if ( ! putCmd( cmd ) ) | |
646 return FALSE; | |
647 stat = getStat(); | |
648 if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) | |
649 { | |
650 *noServerPattern= TRUE; | |
651 if ( ! putCmd( "LIST ACTIVE.TIMES" ) ) | |
652 return FALSE; | |
653 stat = getStat(); | |
654 } | |
655 if ( stat != STAT_GRPS_FOLLOW ) | |
656 { | |
657 Log_err( "%s failed: %s", cmd, client.lastStat ); | |
474 return FALSE; | 658 return FALSE; |
475 } | 659 } |
476 while ( getTxtLn( line, &err ) && ! err ) | 660 while ( getTxtLn( line, &err ) && ! err ) |
477 { | 661 { |
478 if ( sscanf( line, "%s", name ) != 1 ) | 662 if ( sscanf( line, "%s %ld", name, &t ) != 2 ) |
479 { | 663 { |
480 Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line ); | 664 Log_err( "Unknown reply to LIST ACTIVE.TIMES: %s", line ); |
481 continue; | 665 continue; |
482 } | 666 } |
483 strcpy( dsc, Utl_restOfLn( line, 1 ) ); | 667 if ( *noServerPattern && ! isGetGroup( name ) ) |
668 continue; | |
484 if ( Grp_exists( name ) ) | 669 if ( Grp_exists( name ) ) |
485 { | 670 { |
486 Log_dbg( "Description of %s: %s", name, dsc ); | 671 Log_inf( "Creation time of %s: %ld", name, t ); |
487 Grp_setDsc( name, dsc ); | 672 Grp_setCreated( name, t ); |
488 } | 673 } |
489 } | 674 } |
490 return TRUE; | 675 return TRUE; |
491 } | 676 } |
492 | 677 |
493 Bool | 678 Bool |
494 Client_getCreationTimes( void ) | 679 Client_getCreationTimes( void ) |
495 { | 680 { |
496 Bool err; | 681 GroupEnum *ge; |
497 Str name, line; | 682 const char *pattern; |
498 time_t t; | 683 Bool doneOne, noServerPattern, res; |
499 | 684 |
500 Log_inf( "Querying group creation times" ); | 685 Log_inf( "Querying group creation times" ); |
501 if ( ! putCmd( "LIST ACTIVE.TIMES" ) ) | 686 |
502 return FALSE; | 687 doneOne = FALSE; |
503 if ( getStat() != STAT_GRPS_FOLLOW ) | 688 res = TRUE; |
504 { | 689 ge = new_GetGrEn( client.serv ); |
505 Log_err( "LIST ACTIVE.TIMES failes: %s", client.lastStat ); | 690 while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) |
506 return FALSE; | 691 { |
507 } | 692 res = doGetCreationTimes( pattern, &noServerPattern ); |
508 while ( getTxtLn( line, &err ) && ! err ) | 693 doneOne = TRUE; |
509 { | 694 if ( noServerPattern ) |
510 if ( sscanf( line, "%s %ld", name, &t ) != 2 ) | 695 break; |
511 { | 696 } |
512 Log_err( "Unknown reply to LIST ACTIVE.TIMES: %s", line ); | 697 |
513 continue; | 698 if ( ! doneOne ) |
514 } | 699 res = doGetCreationTimes( "", &noServerPattern ); |
515 if ( Grp_exists( name ) ) | 700 |
516 { | 701 del_GrEn( ge ); |
517 Log_inf( "Creation time of %s: %ld", name, t ); | 702 return res; |
518 Grp_setCreated( name, t ); | |
519 } | |
520 } | |
521 return TRUE; | |
522 } | 703 } |
523 | 704 |
524 Bool | 705 Bool |
525 Client_getNewgrps( const time_t *lastTime ) | 706 Client_getNewgrps( const time_t *lastTime ) |
526 { | 707 { |
533 Do not use century for working with old server software until 2000. | 714 Do not use century for working with old server software until 2000. |
534 According to newest IETF draft, this is still valid after 2000. | 715 According to newest IETF draft, this is still valid after 2000. |
535 (directly using %y in fmt string causes a Y2K compiler warning) | 716 (directly using %y in fmt string causes a Y2K compiler warning) |
536 */ | 717 */ |
537 p = s + 2; | 718 p = s + 2; |
538 if ( ! putCmd( "NEWGROUPS %s", p ) ) | 719 if ( ! putCmd( "NEWGROUPS %s GMT", p ) ) |
539 return FALSE; | 720 return FALSE; |
540 if ( getStat() != STAT_NEW_GRP_FOLLOW ) | 721 if ( getStat() != STAT_NEW_GRP_FOLLOW ) |
541 { | 722 { |
542 Log_err( "NEWGROUPS command failed: %s", client.lastStat ); | 723 Log_err( "NEWGROUPS command failed: %s", client.lastStat ); |
543 return FALSE; | 724 return FALSE; |
544 } | 725 } |
545 processGrps(); | 726 processGrps( TRUE ); |
546 return TRUE; | 727 return TRUE; |
547 } | 728 } |
548 | 729 |
549 static const char * | 730 static const char * |
550 readField( Str result, const char *p ) | 731 readField( Str result, const char *p ) |
743 while ( getTxtLn( line, &err ) && ! err ) | 924 while ( getTxtLn( line, &err ) && ! err ) |
744 { | 925 { |
745 if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref, | 926 if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref, |
746 &bytes, &lines ) ) | 927 &bytes, &lines ) ) |
747 Log_err( "Bad overview line: %s", line ); | 928 Log_err( "Bad overview line: %s", line ); |
929 else if ( Cont_find( msgId ) >= 0 ) | |
930 Log_inf( "Already have '%s'", msgId ); | |
748 else | 931 else |
749 { | 932 { |
750 ov = new_Over( subj, from, date, msgId, ref, bytes, lines ); | 933 ov = new_Over( subj, from, date, msgId, ref, bytes, lines ); |
751 Cont_app( ov ); | 934 Cont_app( ov ); |
752 prepareEntry( ov ); | 935 prepareEntry( ov ); |