comparison src/noffle.c @ 114:af7bea7515b2 noffle

[svn] --post simplification.
author bears
date Sat, 24 Jun 2000 21:36:38 +0100
parents 38b0a1532a37
children d45b0abe7c79
comparison
equal deleted inserted replaced
113:70bd4379b233 114:af7bea7515b2
8 not as server. If noffle runs as server, locking is performed while 8 not as server. If noffle runs as server, locking is performed while
9 executing NNTP commands, but temporarily released if no new command is 9 executing NNTP commands, but temporarily released if no new command is
10 received for some seconds (to allow multiple clients connect at the same 10 received for some seconds (to allow multiple clients connect at the same
11 time). 11 time).
12 12
13 $Id: noffle.c 135 2000-06-05 08:57:05Z bears $ 13 $Id: noffle.c 158 2000-06-24 20:36:38Z bears $
14 */ 14 */
15 15
16 #if HAVE_CONFIG_H 16 #if HAVE_CONFIG_H
17 #include <config.h> 17 #include <config.h>
18 #endif 18 #endif
19 19
20 #include <ctype.h> 20 #include <ctype.h>
21 #include <errno.h> 21 #include <errno.h>
22 #include <getopt.h> 22 #include <getopt.h>
23 #include <signal.h> 23 #include <signal.h>
24 #include <sys/time.h>
24 #include <sys/resource.h> 25 #include <sys/resource.h>
25 #include <syslog.h> 26 #include <syslog.h>
26 #include <unistd.h> 27 #include <unistd.h>
27 #include "client.h" 28 #include "client.h"
28 #include "common.h" 29 #include "common.h"
174 Fetch_close(); 175 Fetch_close();
175 } 176 }
176 } 177 }
177 178
178 static Bool 179 static Bool
179 doPost( Bool localOnly ) 180 doPost()
180 { 181 {
181 Str line; 182 Str line;
182 DynStr *s; 183 DynStr *s;
183 Bool res; 184 Bool res;
184 185
191 if ( ! Post_open( DynStr_str( s ) ) ) 192 if ( ! Post_open( DynStr_str( s ) ) )
192 { 193 {
193 fprintf( stderr, "Post failed: Malformed article.\n" ); 194 fprintf( stderr, "Post failed: Malformed article.\n" );
194 res = FALSE; 195 res = FALSE;
195 } 196 }
196 else if ( ! Post_post( localOnly ) ) 197 else if ( ! Post_post() )
197 { 198 {
198 fprintf( stderr, "Post failed: Can't post to group.\n" ); 199 fprintf( stderr, "Post failed: Can't post to group.\n" );
199 res = FALSE; 200 res = FALSE;
200 } 201 }
201 Post_close(); 202 Post_close();
526 " -l | --list List groups on fetch list\n" 527 " -l | --list List groups on fetch list\n"
527 " -m | --modify desc <grp> <desc> Modify a group description\n" 528 " -m | --modify desc <grp> <desc> Modify a group description\n"
528 " -m | --modify post <grp> (y|n) Modify posting status of a local group\n" 529 " -m | --modify post <grp> (y|n) Modify posting status of a local group\n"
529 " -n | --online Switch to online mode\n" 530 " -n | --online Switch to online mode\n"
530 " -o | --offline Switch to offline mode\n" 531 " -o | --offline Switch to offline mode\n"
531 " -p | --post all Post article on stdin to all groups\n" 532 " -p | --post Post article on stdin\n"
532 " -p | --post local Post article on stdin to local groups\n"
533 " -q | --query groups Get group list from server\n" 533 " -q | --query groups Get group list from server\n"
534 " -q | --query desc Get group descriptions from server\n" 534 " -q | --query desc Get group descriptions from server\n"
535 " -q | --query times Get group creation times from server\n" 535 " -q | --query times Get group creation times from server\n"
536 " -r | --server Run as server on stdin/stdout\n" 536 " -r | --server Run as server on stdin/stdout\n"
537 " -R | --requested List articles marked for download\n" 537 " -R | --requested List articles marked for download\n"
648 { "help", no_argument, NULL, 'h' }, 648 { "help", no_argument, NULL, 'h' },
649 { "list", no_argument, NULL, 'l' }, 649 { "list", no_argument, NULL, 'l' },
650 { "modify", required_argument, NULL, 'm' }, 650 { "modify", required_argument, NULL, 'm' },
651 { "offline", no_argument, NULL, 'o' }, 651 { "offline", no_argument, NULL, 'o' },
652 { "online", no_argument, NULL, 'n' }, 652 { "online", no_argument, NULL, 'n' },
653 { "post", required_argument, NULL, 'p' }, 653 { "post", no_argument, NULL, 'p' },
654 { "query", required_argument, NULL, 'q' }, 654 { "query", required_argument, NULL, 'q' },
655 { "server", no_argument, NULL, 'r' }, 655 { "server", no_argument, NULL, 'r' },
656 { "requested", no_argument, NULL, 'R' }, 656 { "requested", no_argument, NULL, 'R' },
657 { "subscribe-over", required_argument, NULL, 's' }, 657 { "subscribe-over", required_argument, NULL, 's' },
658 { "subscribe-full", required_argument, NULL, 'S' }, 658 { "subscribe-full", required_argument, NULL, 'S' },
667 signal( SIGFPE, logSignal ); 667 signal( SIGFPE, logSignal );
668 signal( SIGILL, logSignal ); 668 signal( SIGILL, logSignal );
669 signal( SIGINT, logSignal ); 669 signal( SIGINT, logSignal );
670 signal( SIGTERM, logSignal ); 670 signal( SIGTERM, logSignal );
671 signal( SIGPIPE, logSignal ); 671 signal( SIGPIPE, logSignal );
672 c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onp:q:rRs:S:t:u:v", 672 c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onpq:rRs:S:t:u:v",
673 longOptions, NULL ); 673 longOptions, NULL );
674 if ( ! initNoffle( c != 'r' ) ) 674 if ( ! initNoffle( c != 'r' ) )
675 return EXIT_FAILURE; 675 return EXIT_FAILURE;
676 result = EXIT_SUCCESS; 676 result = EXIT_SUCCESS;
677 switch ( c ) 677 switch ( c )
755 fprintf( stderr, "NOFFLE is already offline\n" ); 755 fprintf( stderr, "NOFFLE is already offline\n" );
756 else 756 else
757 Online_set( FALSE ); 757 Online_set( FALSE );
758 break; 758 break;
759 case 'p': 759 case 'p':
760 if ( ! optarg ) 760 if ( ! doPost() )
761 { 761 result = EXIT_FAILURE;
762 fprintf( stderr, "Option -p needs argument.\n" );
763 result = EXIT_FAILURE;
764 }
765 else
766 {
767 Bool local;
768
769 local = FALSE;
770 if ( strcmp( optarg, "local" ) == 0 )
771 local = TRUE;
772 else if ( strcmp( optarg, "all" ) != 0 )
773 {
774 fprintf( stderr, "Unknown argument -p %s\n", optarg );
775 result = EXIT_FAILURE;
776 }
777 if ( ! doPost( local ) )
778 result = EXIT_FAILURE;
779 }
780 break; 762 break;
781 case 'q': 763 case 'q':
782 if ( ! optarg ) 764 if ( ! optarg )
783 { 765 {
784 fprintf( stderr, "Option -q needs argument.\n" ); 766 fprintf( stderr, "Option -q needs argument.\n" );