Mercurial > noffle
comparison src/noffle.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 | adf0af5152f7 |
children | 0428aed4f9d0 |
comparison
equal
deleted
inserted
replaced
87:bf8c97460fd7 | 88:1fcdced0246e |
---|---|
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 67 2000-05-12 17:19:38Z enz $ | 13 $Id: noffle.c 100 2000-05-18 12:17:23Z 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 |
36 #include "itemlist.h" | 36 #include "itemlist.h" |
37 #include "log.h" | 37 #include "log.h" |
38 #include "online.h" | 38 #include "online.h" |
39 #include "outgoing.h" | 39 #include "outgoing.h" |
40 #include "over.h" | 40 #include "over.h" |
41 #include "post.h" | |
41 #include "pseudo.h" | 42 #include "pseudo.h" |
42 #include "util.h" | 43 #include "util.h" |
43 #include "server.h" | 44 #include "server.h" |
44 #include "request.h" | 45 #include "request.h" |
45 #include "lock.h" | 46 #include "lock.h" |
168 /* get requested articles */ | 169 /* get requested articles */ |
169 Fetch_getReq_(); | 170 Fetch_getReq_(); |
170 | 171 |
171 Fetch_close(); | 172 Fetch_close(); |
172 } | 173 } |
174 } | |
175 | |
176 static Bool | |
177 doPost( Bool localOnly ) | |
178 { | |
179 Str line; | |
180 DynStr *s; | |
181 Bool res; | |
182 | |
183 | |
184 s = new_DynStr( 10000 ); | |
185 while ( fgets( line, MAXCHAR, stdin ) != NULL ) | |
186 DynStr_app( s, line ); | |
187 | |
188 res = TRUE; | |
189 if ( ! Post_open( DynStr_str( s ) ) ) | |
190 { | |
191 fprintf( stderr, "Post failed: Malformed article.\n" ); | |
192 res = FALSE; | |
193 } | |
194 else if ( ! Post_post( localOnly ) ) | |
195 { | |
196 fprintf( stderr, "Post failed: Can't post to group.\n" ); | |
197 res = FALSE; | |
198 } | |
199 Post_close(); | |
200 return res; | |
173 } | 201 } |
174 | 202 |
175 static void | 203 static void |
176 doQuery( void ) | 204 doQuery( void ) |
177 { | 205 { |
496 " -l | --list List groups on fetch list\n" | 524 " -l | --list List groups on fetch list\n" |
497 " -m | --modify desc <grp> <desc> Modify a group description\n" | 525 " -m | --modify desc <grp> <desc> Modify a group description\n" |
498 " -m | --modify post <grp> (y|n) Modify posting status of a local group\n" | 526 " -m | --modify post <grp> (y|n) Modify posting status of a local group\n" |
499 " -n | --online Switch to online mode\n" | 527 " -n | --online Switch to online mode\n" |
500 " -o | --offline Switch to offline mode\n" | 528 " -o | --offline Switch to offline mode\n" |
529 " -p | --post all Post article on stdin to all groups\n" | |
530 " -p | --post local Post article on stdin to local groups\n" | |
501 " -q | --query groups Get group list from server\n" | 531 " -q | --query groups Get group list from server\n" |
502 " -q | --query desc Get group descriptions from server\n" | 532 " -q | --query desc Get group descriptions from server\n" |
503 " -q | --query times Get group creation times from server\n" | 533 " -q | --query times Get group creation times from server\n" |
504 " -r | --server Run as server on stdin/stdout\n" | 534 " -r | --server Run as server on stdin/stdout\n" |
505 " -R | --requested List articles marked for download\n" | 535 " -R | --requested List articles marked for download\n" |
617 { "help", no_argument, NULL, 'h' }, | 647 { "help", no_argument, NULL, 'h' }, |
618 { "list", no_argument, NULL, 'l' }, | 648 { "list", no_argument, NULL, 'l' }, |
619 { "modify", required_argument, NULL, 'm' }, | 649 { "modify", required_argument, NULL, 'm' }, |
620 { "offline", no_argument, NULL, 'o' }, | 650 { "offline", no_argument, NULL, 'o' }, |
621 { "online", no_argument, NULL, 'n' }, | 651 { "online", no_argument, NULL, 'n' }, |
652 { "post", required_argument, NULL, 'p' }, | |
622 { "query", required_argument, NULL, 'q' }, | 653 { "query", required_argument, NULL, 'q' }, |
623 { "server", no_argument, NULL, 'r' }, | 654 { "server", no_argument, NULL, 'r' }, |
624 { "requested", no_argument, NULL, 'R' }, | 655 { "requested", no_argument, NULL, 'R' }, |
625 { "subscribe-over", required_argument, NULL, 's' }, | 656 { "subscribe-over", required_argument, NULL, 's' }, |
626 { "subscribe-full", required_argument, NULL, 'S' }, | 657 { "subscribe-full", required_argument, NULL, 'S' }, |
635 signal( SIGFPE, logSignal ); | 666 signal( SIGFPE, logSignal ); |
636 signal( SIGILL, logSignal ); | 667 signal( SIGILL, logSignal ); |
637 signal( SIGINT, logSignal ); | 668 signal( SIGINT, logSignal ); |
638 signal( SIGTERM, logSignal ); | 669 signal( SIGTERM, logSignal ); |
639 signal( SIGPIPE, logSignal ); | 670 signal( SIGPIPE, logSignal ); |
640 c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onq:rRs:S:t:u:v", | 671 c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onp:q:rRs:S:t:u:v", |
641 longOptions, NULL ); | 672 longOptions, NULL ); |
642 if ( ! initNoffle( c != 'r' ) ) | 673 if ( ! initNoffle( c != 'r' ) ) |
643 return EXIT_FAILURE; | 674 return EXIT_FAILURE; |
644 result = EXIT_SUCCESS; | 675 result = EXIT_SUCCESS; |
645 switch ( c ) | 676 switch ( c ) |
721 case 'o': | 752 case 'o': |
722 if ( ! Online_true() ) | 753 if ( ! Online_true() ) |
723 fprintf( stderr, "NOFFLE is already offline\n" ); | 754 fprintf( stderr, "NOFFLE is already offline\n" ); |
724 else | 755 else |
725 Online_set( FALSE ); | 756 Online_set( FALSE ); |
757 break; | |
758 case 'p': | |
759 if ( ! optarg ) | |
760 { | |
761 fprintf( stderr, "Option -p needs argument.\n" ); | |
762 result = EXIT_FAILURE; | |
763 } | |
764 else | |
765 { | |
766 Bool local; | |
767 | |
768 local = FALSE; | |
769 if ( strcmp( optarg, "local" ) == 0 ) | |
770 local = TRUE; | |
771 else if ( strcmp( optarg, "all" ) != 0 ) | |
772 { | |
773 fprintf( stderr, "Unknown argument -p %s\n", optarg ); | |
774 result = EXIT_FAILURE; | |
775 } | |
776 if ( ! doPost( local ) ) | |
777 result = EXIT_FAILURE; | |
778 } | |
726 break; | 779 break; |
727 case 'q': | 780 case 'q': |
728 if ( ! optarg ) | 781 if ( ! optarg ) |
729 { | 782 { |
730 fprintf( stderr, "Option -q needs argument.\n" ); | 783 fprintf( stderr, "Option -q needs argument.\n" ); |