annotate server.c @ 37:792eb10e936d noffle

[svn] Change returned status info for STAT_POST_OK, because\n"Message queued for posting" is no longer meaningful for local groups.
author enz
date Thu, 04 May 2000 09:16:09 +0100
parents 526a4c34ee2e
children 8e972daaeab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
2 server.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
37
792eb10e936d [svn] Change returned status info for STAT_POST_OK, because\n"Message queued for posting" is no longer meaningful for local groups.
enz
parents: 26
diff changeset
4 $Id: server.c 43 2000-05-04 08:16:09Z enz $
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include "server.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8 #include <ctype.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <signal.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <stdarg.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include <sys/time.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include <sys/types.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include <time.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include <unistd.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include "client.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16 #include "common.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
17 #include "config.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
18 #include "content.h"
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
19 #include "control.h"
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 #include "database.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21 #include "dynamicstring.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 #include "fetch.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 #include "fetchlist.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 #include "group.h"
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
25 #include "itemlist.h"
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26 #include "lock.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 #include "online.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 #include "outgoing.h"
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
30 #include "post.h"
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 #include "protocol.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32 #include "pseudo.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 #include "request.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 struct
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38 Bool running;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 int artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40 Str grp; /* selected group, "" if none */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41 } serv = { FALSE, 0, "" };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 typedef struct Cmd
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 const char *name;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
46 const char *syntax;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47 /* Returns false, if quit cmd */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 Bool (*cmdProc)( char *arg, const struct Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50 Cmd;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52 static Bool doArt( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 static Bool doBody( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 static Bool doGrp( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 static Bool doHead( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56 static Bool doHelp( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 static Bool doIhave( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58 static Bool doLast( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 static Bool doList( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 static Bool doListgrp( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 static Bool doMode( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 static Bool doNewgrps( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63 static Bool doNext( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 static Bool doPost( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65 static Bool doSlave( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 static Bool doStat( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 static Bool doQuit( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 static Bool doXhdr( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69 static Bool doXpat( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70 static Bool doXOver( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 static Bool notImplemented( char *arg, const Cmd *cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 static void putStat( unsigned int stat, const char *fmt, ... );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 Cmd commands[] =
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 { "article", "ARTICLE [msg-id|n]", &doArt },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77 { "body", "BODY [msg-id|n]", &doBody },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78 { "head", "HEAD [msg-id|n]", &doHead },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 { "group", "GROUP grp", &doGrp },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80 { "help", "HELP", &doHelp },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 { "ihave", "IHAVE (ignored)", &doIhave },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82 { "last", "LAST", &doLast },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 { "list", "LIST [ACTIVE [pat]]|ACTIVE.TIMES [pat]|"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 "EXTENSIONS|NEWSGROUPS [pat]|OVERVIEW.FMT", &doList },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85 { "listgroup", "LISTGROUP grp", &doListgrp },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 { "mode", "MODE (ignored)", &doMode },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87 { "newgroups", "NEWGROUPS [xx]yymmdd hhmmss [GMT]", &doNewgrps },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 { "newnews", "NEWNEWS (not implemented)", &notImplemented },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89 { "next", "NEXT", &doNext },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 { "post", "POST", &doPost },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 { "quit", "QUIT", &doQuit },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 { "slave", "SLAVE (ignored)", &doSlave },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93 { "stat", "STAT [msg-id|n]", &doStat },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 { "xhdr", "XHDR over-field [m[-[n]]]", &doXhdr },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 { "xpat", "XPAT over-field m[-[n]] pat", &doXpat },
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 { "xover", "XOVER [m[-[n]]]", &doXOver }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 Notice interest in reading this group.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 Automatically subscribe if option set in config file.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
103 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
104 noteInterest( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
105 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
106 FetchMode mode;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
107
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
108 Grp_setLastAccess( serv.grp, time( NULL ) );
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
109 if ( ! Grp_local ( serv.grp ) && Cfg_autoSubscribe() && ! Online_true() )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
110 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
111 Fetchlist_read();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
112 if ( ! Fetchlist_contains( serv.grp ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
113 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
114 if ( strcmp( Cfg_autoSubscribeMode(), "full" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
115 mode = FULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
116 else if ( strcmp( Cfg_autoSubscribeMode(), "thread" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
117 mode = THREAD;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
118 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
119 mode = OVER;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
120 Fetchlist_add( serv.grp, mode );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
121 Fetchlist_write();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
122 Pseudo_autoSubscribed();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
123 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
124 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
125 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
126
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
127 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
128 putStat( unsigned int stat, const char *fmt, ... )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
129 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
130 Str s, line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
131 va_list ap;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
132
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
133 ASSERT( stat <= 999 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
134 va_start( ap, fmt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
135 vsnprintf( s, MAXCHAR, fmt, ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
136 va_end( ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
137 snprintf( line, MAXCHAR, "%u %s", stat, s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
138 Log_dbg( "[S] %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
139 printf( "%s\r\n", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
140 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
141
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
142 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
143 putTxtLn( const char *fmt, ... )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
144 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
145 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
146 va_list ap;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
147
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
148 va_start( ap, fmt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
149 vsnprintf( line, MAXCHAR, fmt, ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
150 va_end( ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
151 Prt_putTxtLn( line, stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
152 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
153
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
154 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
155 putTxtBuf( const char *buf )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
156 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
157 if ( buf )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
158 Prt_putTxtBuf( buf, stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
159 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
160
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
161 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
162 putEndOfTxt( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
163 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
164 Prt_putEndOfTxt( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
165 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
166
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
167 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
168 putSyntax( const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
169 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
170 putStat( STAT_SYNTAX_ERR, "Syntax error. Usage: %s", cmd->syntax );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
171 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
172
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
173 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
174 getLn( Str line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
175 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
176 return Prt_getLn( line, stdin );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
177 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
178
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
179 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
180 getTxtLn( Str line, Bool *err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
181 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
182 return Prt_getTxtLn( line, err, stdin );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
183 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
184
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
185 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
186 notImplemented( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
187 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
188 putStat( STAT_NO_PERMISSION, "Command not implemented" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
189 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
190 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
191
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
192 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
193 checkNewArts( const char *grp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
194 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
195 if ( ! Online_true()
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
196 || strcmp( grp, serv.grp ) == 0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
197 || time( NULL ) - Grp_lastAccess( serv.grp ) < 1800 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
198 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
199 if ( Fetch_init( Grp_serv( grp ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
200 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
201 Fetch_getNewArts( grp, OVER );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
202 Fetch_close();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
203 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
204 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
205
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
206 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
207 postArts()
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
208 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
209 Str serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
210
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
211 Cfg_beginServEnum();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
212 while ( Cfg_nextServ( serv ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
213 if ( Fetch_init( serv ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
214 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
215 Fetch_postArts();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
216 Fetch_close();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
217 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
218 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
219
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
220 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
221 readCont( const char *name )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
222 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
223 Fetchlist_read();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
224 Cont_read( name );
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
225 if ( ! Grp_local ( name )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
226 && ! Fetchlist_contains( name )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
227 && ! Online_true() )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
228 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
229 Pseudo_appGeneralInfo();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
230 Grp_setFirstLast( name, Cont_first(), Cont_last() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
231 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
232 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
233
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
234 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
235 changeToGrp( const char *grp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
236 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
237 checkNewArts( grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
238 Utl_cpyStr( serv.grp, grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
239 readCont( grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
240 serv.artPtr = Cont_first();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
241 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
242
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
243 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
244 doGrp( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
245 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
246 int first, last, numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
247
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
248 if ( arg[ 0 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
249 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
250 else if ( ! Grp_exists( arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
251 putStat( STAT_NO_SUCH_GRP, "No such group" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
252 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
253 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
254 changeToGrp( arg );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
255 first = Cont_first();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
256 last = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
257 numb = last - first + 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
258 if ( first > last )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
259 first = last = numb = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
260 putStat( STAT_GRP_SELECTED, "%lu %lu %lu %s selected",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
261 numb, first, last, arg );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
262 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
263 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
264 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
265
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
266 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
267 testGrpSelected( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
268 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
269 if ( *serv.grp == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
270 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
271 putStat( STAT_NO_GRP_SELECTED, "No group selected" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
272 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
273 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
274 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
275 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
276
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
277 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
278 findServ( const char *msgId, Str result )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
279 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
280 const char *p, *pColon, *serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
281 Str s, grp;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
282
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
283 Utl_cpyStr( result, "(unknown)" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
284 if ( Db_contains( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
285 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
286 Utl_cpyStr( s, Db_xref( msgId ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
287 p = strtok( s, " \t" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
288 if ( p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
289 do
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
290 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
291 pColon = strstr( p, ":" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
292 if ( pColon )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
293 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
294 Utl_cpyStrN( grp, p, pColon - p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
295 serv = Grp_serv( grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
296 if ( Cfg_servIsPreferential( serv, result ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
297 Utl_cpyStr( result, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
298 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
299 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
300 while ( ( p = strtok( NULL, " \t" ) ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
301 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
302 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
303
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
304 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
305 retrieveArt( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
306 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
307 Str serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
308
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
309 findServ( msgId, serv );
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
310 if ( strcmp( serv, "(unknown)" ) == 0 || strcmp( serv, "(local)" ) == 0 )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
311 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
312 if ( ! Client_connect( serv ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
313 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
314 Client_retrieveArt( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
315 Client_disconnect();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
316 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
317 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
318
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
319 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
320 checkNumb( int numb )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
321 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
322 if ( ! testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
323 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
324 if ( ! Cont_validNumb( numb ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
325 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
326 putStat( STAT_NO_SUCH_NUMB, "No such article" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
327 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
328 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
329 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
330 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
331
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
332 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
333 Parse arguments for ARTICLE, BODY, HEAD, STAT commands.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
334 Return message-ID and article number (0 if unknown).
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
335 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
336 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
337 whichId( const char **msgId, int *numb, char *arg )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
338 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
339 const Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
340 int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
341
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
342 if ( sscanf( arg, "%i", &n ) == 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
343 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
344 if ( ! checkNumb( n ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
345 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
346 serv.artPtr = n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
347 ov = Cont_get( n );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
348 *msgId = Ov_msgId( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
349 *numb = n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
350 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
351 else if ( strcmp( arg, "" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
352 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
353 if ( ! checkNumb( serv.artPtr ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
354 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
355 ov = Cont_get( serv.artPtr );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
356 *msgId = Ov_msgId( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
357 *numb = serv.artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
358 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
359 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
360 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
361 *msgId = arg;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
362 *numb = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
363 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
364 if ( ! Pseudo_isGeneralInfo( *msgId ) && ! Db_contains( *msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
365 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
366 putStat( STAT_NO_SUCH_NUMB, "No such article" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
367 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
368 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
369 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
370 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
371
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
372 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
373 touchArticle( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
374 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
375 int stat = Db_stat( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
376 stat |= DB_INTERESTING;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
377 Db_setStat( msgId, stat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
378 Db_updateLastAccess( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
379 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
380
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
381 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
382 touchReferences( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
383 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
384 Str s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
385 int len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
386 char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
387 const char *ref = Db_ref( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
388
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
389 while ( TRUE )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
390 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
391 p = s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
392 while ( *ref != '<' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
393 if ( *(ref++) == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
394 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
395 len = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
396 while ( *ref != '>' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
397 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
398 if ( *ref == '\0' || ++len >= MAXCHAR - 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
399 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
400 *(p++) = *(ref++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
401 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
402 *(p++) = '>';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
403 *p = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
404 if ( Db_contains( s ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
405 touchArticle( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
406 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
407 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
408
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
409 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
410 doBodyInDb( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
411 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
412 int stat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
413 Str serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
414
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
415 touchArticle( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
416 touchReferences( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
417 stat = Db_stat( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
418 if ( Online_true() && ( stat & DB_NOT_DOWNLOADED ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
419 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
420 retrieveArt( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
421 stat = Db_stat( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
422 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
423 if ( stat & DB_RETRIEVING_FAILED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
424 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
425 Db_setStat( msgId, stat & ~DB_RETRIEVING_FAILED );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
426 putTxtBuf( Db_body( msgId ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
427 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
428 else if ( stat & DB_NOT_DOWNLOADED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
429 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
430 findServ( msgId, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
431 if ( Req_contains( serv, msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
432 putTxtBuf( Pseudo_alreadyMarkedBody() );
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
433 else if ( strcmp( serv, "(unknown)" ) != 0 &&
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
434 strcmp( serv, "(local)" ) != 0 &&
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
435 Req_add( serv, msgId ) )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
436 putTxtBuf( Pseudo_markedBody() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
437 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
438 putTxtBuf( Pseudo_markingFailedBody() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
439 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
440 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
441 putTxtBuf( Db_body( msgId ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
442 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
443
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
444 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
445 doBody( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
446 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
447 const char *msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
448 int numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
449
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
450 if ( ! whichId( &msgId, &numb, arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
451 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
452 putStat( STAT_BODY_FOLLOWS, "%ld %s Body", numb, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
453 if ( Pseudo_isGeneralInfo( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
454 putTxtBuf( Pseudo_generalInfoBody() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
455 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
456 doBodyInDb( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
457 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
458 noteInterest();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
459 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
460 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
461
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
462 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
463 doHeadInDb( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
464 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
465 putTxtBuf( Db_header( msgId ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
466 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
467
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
468 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
469 doHead( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
470 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
471 const char *msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
472 int numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
473
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
474 if ( ! whichId( &msgId, &numb, arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
475 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
476 putStat( STAT_HEAD_FOLLOWS, "%ld %s Head", numb, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
477 if ( Pseudo_isGeneralInfo( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
478 putTxtBuf( Pseudo_generalInfoHead() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
479 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
480 doHeadInDb( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
481 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
482 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
483 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
484
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
485 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
486 doArtInDb( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
487 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
488 doHeadInDb( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
489 putTxtLn( "" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
490 doBodyInDb( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
491 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
492
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
493 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
494 doArt( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
495 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
496 const char *msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
497 int numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
498
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
499 if ( ! whichId( &msgId, &numb, arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
500 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
501 putStat( STAT_ART_FOLLOWS, "%ld %s Article", numb, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
502 if ( Pseudo_isGeneralInfo( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
503 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
504 putTxtBuf( Pseudo_generalInfoHead() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
505 putTxtLn( "" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
506 putTxtBuf( Pseudo_generalInfoBody() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
507 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
508 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
509 doArtInDb( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
510 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
511 noteInterest();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
512 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
513 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
514
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
515 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
516 doHelp( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
517 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
518 unsigned int i;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
519
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
520 putStat( STAT_HELP_FOLLOWS, "Help" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
521 putTxtBuf( "\nCommands:\n\n" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
522 for ( i = 0; i < sizeof( commands ) / sizeof( commands[ 0 ] ); ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
523 putTxtLn( "%s", commands[ i ].syntax );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
524 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
525 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
526 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
527
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
528 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
529 doIhave( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
530 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
531 putStat( STAT_ART_REJECTED, "Command not used" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
532 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
533 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
534
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
535 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
536 doLast( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
537 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
538 int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
539
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
540 if ( testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
541 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
542 n = serv.artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
543 if ( ! Cont_validNumb( n ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
544 putStat( STAT_NO_ART_SELECTED, "No article selected" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
545 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
546 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
547 while ( ! Cont_validNumb( --n ) && n >= Cont_first() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
548 if ( ! Cont_validNumb( n ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
549 putStat( STAT_NO_PREV_ART, "No previous article" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
550 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
551 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
552 putStat( STAT_ART_RETRIEVED, "%ld %s selected",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
553 n, Ov_msgId( Cont_get( n ) ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
554 serv.artPtr = n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
555 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
556 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
557 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
558 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
559 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
560
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
561 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
562 printGroups( const char *pat, void (*printProc)( Str, const char* ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
563 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
564 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
565 const char *g;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
566 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
567 sig_t lastHandler;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
568 int ret;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
569
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
570 putStat( STAT_GRPS_FOLLOW, "Groups" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
571 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
572 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
573 if ( Grp_exists( pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
574 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
575 (*printProc)( line, pat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
576 if ( ! Prt_putTxtLn( line, stdout ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
577 Log_err( "Writing to stdout failed." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
578 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
579 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
580 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
581 lastHandler = signal( SIGPIPE, SIG_IGN );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
582 f = popen( "sort", "w" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
583 if ( f == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
584 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
585 Log_err( "Cannot open pipe to 'sort'" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
586 if ( Grp_firstGrp( &g ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
587 do
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
588 if ( Utl_matchPattern( g, pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
589 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
590 (*printProc)( line, g );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
591 if ( ! Prt_putTxtLn( line, stdout ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
592 Log_err( "Writing to stdout failed." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
593 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
594 while ( Grp_nextGrp( &g ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
595 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
596 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
597 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
598 if ( Grp_firstGrp( &g ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
599 do
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
600 if ( Utl_matchPattern( g, pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
601 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
602 (*printProc)( line, g );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
603 if ( ! Prt_putTxtLn( line, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
604 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
605 Log_err( "Writing to 'sort' pipe failed." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
606 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
607 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
608 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
609 while ( Grp_nextGrp( &g ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
610 ret = pclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
611 if ( ret != EXIT_SUCCESS )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
612 Log_err( "sort command returned %i", ret );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
613 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
614 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
615 signal( SIGPIPE, lastHandler );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
616 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
617 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
618 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
619 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
620
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
621 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
622 printActiveTimes( Str result, const char *grp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
623 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
624 snprintf( result, MAXCHAR, "%s %ld", grp, Grp_created( grp ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
625 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
626
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
627 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
628 doListActiveTimes( const char *pat )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
629 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
630 printGroups( pat, &printActiveTimes );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
631 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
632
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
633 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
634 printActive( Str result, const char *grp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
635 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
636 snprintf( result, MAXCHAR, "%s %i %i y",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
637 grp, Grp_last( grp ), Grp_first( grp ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
638 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
639
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
640 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
641 doListActive( const char *pat )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
642 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
643 printGroups( pat, &printActive );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
644 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
645
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
646 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
647 printNewsgrp( Str result, const char *grp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
648 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
649 snprintf( result, MAXCHAR, "%s %s", grp, Grp_dsc( grp ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
650 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
651
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
652 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
653 doListNewsgrps( const char *pat )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
654 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
655 printGroups( pat, &printNewsgrp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
656 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
657
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
658 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
659 putGrp( const char *name )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
660 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
661 putTxtLn( "%s %lu %lu y", name, Grp_last( name ), Grp_first( name ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
662 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
663
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
664 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
665 doListOverFmt( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
666 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
667 putStat( STAT_GRPS_FOLLOW, "Overview format" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
668 putTxtBuf( "Subject:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
669 "From:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
670 "Date:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
671 "Message-ID:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
672 "References:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
673 "Bytes:\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
674 "Lines:\n" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
675 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
676 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
677
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
678 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
679 doListExtensions( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
680 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
681 putStat( STAT_CMD_OK, "Extensions" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
682 putTxtBuf( " LISTGROUP\n"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
683 " XOVER\n" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
684 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
685 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
686
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
687 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
688 doList( char *line, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
689 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
690 Str s, arg;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
691 const char *pat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
692
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
693 if ( sscanf( line, "%s", s ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
694 doListActive( "*" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
695 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
696 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
697 Utl_toLower( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
698 strcpy( arg, Utl_restOfLn( line, 1 ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
699 pat = Utl_stripWhiteSpace( arg );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
700 if ( pat[ 0 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
701 pat = "*";
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
702 if ( strcmp( "active", s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
703 doListActive( pat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
704 else if ( strcmp( "overview.fmt", s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
705 doListOverFmt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
706 else if ( strcmp( "newsgroups", s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
707 doListNewsgrps( pat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
708 else if ( strcmp( "active.times", s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
709 doListActiveTimes( pat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
710 else if ( strcmp( "extensions", s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
711 doListExtensions();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
712 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
713 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
714 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
715 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
716 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
717
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
718 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
719 doListgrp( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
720 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
721 const Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
722 int first, last, i;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
723
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
724 if ( ! Grp_exists( arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
725 putStat( STAT_NO_SUCH_GRP, "No such group" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
726 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
727 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
728 changeToGrp( arg );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
729 first = Cont_first();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
730 last = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
731 putStat( STAT_GRP_SELECTED, "Article list" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
732 for ( i = first; i <= last; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
733 if ( ( ov = Cont_get( i ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
734 putTxtLn( "%lu", i );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
735 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
736 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
737 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
738 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
739
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
740 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
741 doMode( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
742 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
743 putStat( STAT_READY_POST_ALLOW, "Ok" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
744 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
745 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
746
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
747 static unsigned long
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
748 getTimeInSeconds( unsigned int year, unsigned int mon, unsigned int day,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
749 unsigned int hour, unsigned int min, unsigned int sec )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
750 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
751 struct tm t = { 0 };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
752
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
753 t.tm_year = year - 1900;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
754 t.tm_mon = mon - 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
755 t.tm_mday = day;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
756 t.tm_hour = hour;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
757 t.tm_min = min;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
758 t.tm_sec = sec;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
759 return mktime( &t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
760 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
761
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
762
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
763 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
764 doNewgrps( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
765 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
766 time_t t, now, lastUpdate;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
767 unsigned int year, mon, day, hour, min, sec, cent, len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
768 const char *g;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
769 Str date, timeofday, file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
770
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
771 if ( sscanf( arg, "%s %s", date, timeofday ) != 2 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
772 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
773 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
774 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
775 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
776 len = strlen( date );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
777 switch ( len )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
778 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
779 case 6:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
780 if ( sscanf( date, "%2u%2u%2u", &year, &mon, &day ) != 3 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
781 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
782 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
783 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
784 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
785 now = time( NULL );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
786 cent = 1900;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
787 while ( now > getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
788 cent += 100;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
789 year += cent;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
790 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
791 case 8:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
792 if ( sscanf( date, "%4u%2u%2u", &year, &mon, &day ) != 3 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
793 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
794 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
795 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
796 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
797 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
798 default:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
799 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
800 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
801 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
802 if ( sscanf( timeofday, "%2u%2u%2u", &hour, &min, &sec ) != 3 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
803 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
804 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
805 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
806 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
807 if ( year < 1970 || mon == 0 || mon > 12 || day == 0 || day > 31
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
808 || hour > 23 || min > 59 || sec > 60 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
809 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
810 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
811 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
812 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
813 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
814 t = getTimeInSeconds( year, mon, day, hour, min, sec );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
815 putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", arg );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
816
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
817 if ( ! Utl_getStamp( &lastUpdate, file ) || t <= lastUpdate )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
818 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
819 if ( Grp_firstGrp( &g ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
820 do
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
821 if ( Grp_created( g ) > t )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
822 putGrp( g );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
823 while ( Grp_nextGrp( &g ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
824 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
825 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
826 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
827 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
828
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
829 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
830 doNext( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
831 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
832 int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
833
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
834 if ( testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
835 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
836 n = serv.artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
837 if ( ! Cont_validNumb( n ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
838 putStat( STAT_NO_ART_SELECTED, "No article selected" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
839 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
840 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
841 while ( ! Cont_validNumb( ++n ) && n <= Cont_last() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
842 if ( ! Cont_validNumb( n ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
843 putStat( STAT_NO_NEXT_ART, "No next article" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
844 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
845 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
846 putStat( STAT_ART_RETRIEVED, "%ld %s selected",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
847 n, Ov_msgId( Cont_get( n ) ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
848 serv.artPtr = n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
849 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
850 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
851 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
852 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
853 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
854
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
855 /* Cancel and return TRUE if need to send cancel message on to server. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
856 static Bool
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
857 controlCancel( const char *cancelId )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
858 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
859 return ( Ctrl_cancel( cancelId ) == CANCEL_NEEDS_MSG );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
860 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
861
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
862 /*
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
863 It's a control message. Currently we only know about 'cancel'
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
864 messages; others are passed on for outside groups, and logged
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
865 as ignored for local groups.
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
866 */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
867 static Bool
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
868 handleControl( ItemList *control, ItemList *newsgroups,
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
869 const char *msgId, const DynStr *art )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
870 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
871 const char *grp;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
872 const char *op;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
873 Bool err = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
874 Bool localDone = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
875
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
876 op = Itl_first( control );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
877 if ( op == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
878 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
879 Log_err( "Malformed control line." );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
880 return TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
881 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
882 else if ( strcasecmp( op, "cancel" ) == 0 )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
883 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
884 if ( controlCancel( Itl_next( control ) ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
885 localDone = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
886 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
887 return err;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
888 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
889
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
890 /* Pass on for outside groups. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
891 for( grp = Itl_first( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
892 grp != NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
893 grp = Itl_next( newsgroups ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
894 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
895 if ( Grp_exists( grp ) && ! Grp_local( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
896 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
897 if ( ! Out_add( Grp_serv( grp ), msgId, art ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
898 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
899 Log_err( "Cannot add posted article to outgoing directory" );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
900 err = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
901 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
902 break;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
903 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
904 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
905
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
906 if ( localDone )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
907 return err;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
908
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
909 /* Log 'can't do' for internal groups. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
910 for( grp = Itl_first( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
911 grp != NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
912 grp = Itl_next( newsgroups ) )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
913 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
914 if ( Grp_exists( grp ) && Grp_local( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
915 Log_inf( "Ignoring control '%s' for '%s'.", op, grp );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
916 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
917
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
918 return err;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
919 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
920
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
921 static Bool
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
922 postArticle( ItemList *newsgroups, const char *msgId, const DynStr *art )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
923 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
924 const char *grp;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
925 Bool err;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
926 Bool oneLocal;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
927
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
928 err = oneLocal = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
929
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
930 /* Run round first doing all local groups. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
931 for( grp = Itl_first( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
932 grp != NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
933 grp = Itl_next( newsgroups ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
934 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
935 if ( Grp_local( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
936 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
937 if ( ! oneLocal )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
938 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
939 if ( ! Post_open( DynStr_str( art ) ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
940 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
941 err = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
942 break;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
943 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
944 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
945 oneLocal = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
946 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
947
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
948 if ( ! Post_add( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
949 err = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
950 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
951 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
952 if ( oneLocal )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
953 Post_close();
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
954
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
955 /* Now look for a valid external group. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
956 for( grp = Itl_first( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
957 grp != NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
958 grp = Itl_next( newsgroups ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
959 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
960 if ( Grp_exists( grp ) && ! Grp_local( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
961 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
962 if ( ! Out_add( Grp_serv( grp ), msgId, art ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
963 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
964 Log_err( "Cannot add posted article to outgoing directory" );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
965 err = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
966 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
967 break;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
968 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
969 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
970
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
971 return err;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
972 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
973
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
974 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
975 doPost( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
976 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
977 Bool err, replyToFound, dateFound, inHeader;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
978 DynStr *s;
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
979 Str line, field, val, msgId, from;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
980 const char* p;
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
981 ItemList * newsgroups, *control;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
982
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
983 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
984 Get article and make following changes to the header:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
985 - add/replace/cut Message-ID depending on config options
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
986 - add Reply-To with content of From, if missing
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
987 (some providers overwrite From field)
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
988 - rename X-Sender header to X-NOFFLE-X-Sender
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
989 (some providers want to insert their own X-Sender)
12
43631b72021f [svn] Fixed bug: multiple line headers of posted articles were truncated
enz
parents: 0
diff changeset
990
43631b72021f [svn] Fixed bug: multiple line headers of posted articles were truncated
enz
parents: 0
diff changeset
991 For doing this, it is not necessary to parse multiple-line
43631b72021f [svn] Fixed bug: multiple line headers of posted articles were truncated
enz
parents: 0
diff changeset
992 headers.
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
993 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
994 putStat( STAT_SEND_ART, "Continue (end with period)" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
995 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
996 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
997 s = new_DynStr( 10000 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
998 msgId[ 0 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
999 from[ 0 ] = '\0';
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1000 newsgroups = control = NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1001 replyToFound = dateFound = FALSE;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1002 inHeader = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1003 while ( getTxtLn( line, &err ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1004 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1005 if ( inHeader )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1006 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1007 p = Utl_stripWhiteSpace( line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1008 if ( *p == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1009 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1010 inHeader = FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1011 if ( from[ 0 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1012 Log_err( "Posted message has no From field" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1013 if ( ! Cfg_removeMsgId() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1014 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1015 if ( Cfg_replaceMsgId() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1016 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1017 Prt_genMsgId( msgId, from, "NOFFLE" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1018 Log_dbg( "Replacing Message-ID with '%s'", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1019 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1020 else if ( msgId[ 0 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1021 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1022 Prt_genMsgId( msgId, from, "NOFFLE" );
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1023
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1024 Log_inf( "Adding missing Message-ID '%s'", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1025 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1026 else if ( ! Prt_isValidMsgId( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1027 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1028 Log_ntc( "Replacing invalid Message-ID with '%s'",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1029 msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1030 Prt_genMsgId( msgId, from, "NOFFLE" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1031 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1032 DynStr_app( s, "Message-ID: " );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1033 DynStr_appLn( s, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1034 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1035 if ( ! replyToFound && from[ 0 ] != '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1036 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1037 Log_dbg( "Adding Reply-To field to posted message." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1038 DynStr_app( s, "Reply-To: " );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1039 DynStr_appLn( s, from );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1040 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1041 if ( ! dateFound )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1042 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1043 time_t t;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1044
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1045 time( &t );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1046 strftime( val, MAXCHAR, "%d %b %Y %H:%M:%S %Z",
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1047 localtime( &t ) );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1048 DynStr_app( s, "Date: " );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1049 DynStr_appLn( s, val );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1050 }
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1051 DynStr_appLn( s, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1052 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1053 else if ( Prt_getField( field, val, p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1054 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1055 if ( strcmp( field, "message-id" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1056 strcpy( msgId, val );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1057 else if ( strcmp( field, "from" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1058 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1059 strcpy( from, val );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1060 DynStr_appLn( s, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1061 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1062 else if ( strcmp( field, "newsgroups" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1063 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1064 Utl_toLower( val );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1065 newsgroups = new_Itl ( val, " ," );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1066 DynStr_appLn( s, p );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1067 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1068 else if ( strcmp( field, "control" ) == 0 )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1069 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1070 control = new_Itl ( val, " " );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1071 DynStr_appLn( s, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1072 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1073 else if ( strcmp( field, "reply-to" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1074 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1075 replyToFound = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1076 DynStr_appLn( s, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1077 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1078 else if ( strcmp( field, "date" ) == 0 )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1079 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1080 dateFound = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1081 DynStr_appLn( s, p );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1082 }
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1083 else if ( strcmp( field, "x-sender" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1084 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1085 DynStr_app( s, "X-NOFFLE-X-Sender: " );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1086 DynStr_appLn( s, val );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1087 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1088 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1089 DynStr_appLn( s, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1090 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1091 else
12
43631b72021f [svn] Fixed bug: multiple line headers of posted articles were truncated
enz
parents: 0
diff changeset
1092 DynStr_appLn( s, line );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1093 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1094 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1095 DynStr_appLn( s, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1096 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1097 if ( inHeader )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1098 Log_err( "Posted message has no body" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1099 if ( ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1100 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1101 if ( newsgroups == NULL || Itl_count( newsgroups ) == 0 )
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1102 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1103 Log_err( "Posted message has no valid Newsgroups header field" );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1104 err = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1105 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1106 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1107 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1108 const char *grp;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1109 Bool knownGrp = FALSE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1110
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1111 /* Check at least one group is known. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1112 for( grp = Itl_first( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1113 grp != NULL;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1114 grp = Itl_next( newsgroups ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1115 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1116 if ( Grp_exists( grp ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1117 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1118 knownGrp = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1119 break;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1120 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1121 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1122
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1123 if ( ! knownGrp )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1124 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1125
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1126 Log_err( "No known group in Newsgroups header field" );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1127 err = TRUE;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1128 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1129 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1130 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1131 err = ( control == NULL )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1132 ? postArticle( newsgroups, msgId, s )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1133 : handleControl( control, newsgroups, msgId, s );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1134 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1135 }
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1136 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1137 if ( err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1138 putStat( STAT_POST_FAILED, "Posting failed" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1139 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1140 {
37
792eb10e936d [svn] Change returned status info for STAT_POST_OK, because\n"Message queued for posting" is no longer meaningful for local groups.
enz
parents: 26
diff changeset
1141 putStat( STAT_POST_OK, "Message posted" );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1142 if ( Online_true() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1143 postArts();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1144 }
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1145 del_Itl( newsgroups );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 12
diff changeset
1146 del_Itl( control );
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1147 del_DynStr( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1148 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1149 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1150
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1151 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1152 parseRange( const char *s, int *first, int *last, int *numb )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1153 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1154 int r, i;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1155 char* p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1156 Str t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1157
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1158 Utl_cpyStr( t, s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1159 p = Utl_stripWhiteSpace( t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1160 r = sscanf( p, "%i-%i", first, last );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1161 if ( r < 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1162 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1163 *first = serv.artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1164 *last = serv.artPtr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1165 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1166 else if ( r == 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1167 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1168 if ( p[ strlen( p ) - 1 ] == '-' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1169 *last = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1170 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1171 *last = *first;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1172 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1173 if ( *first < Cont_first() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1174 *first = Cont_first();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1175 if ( *last > Cont_last() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1176 *last = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1177 if ( *first > Cont_last() || *last < Cont_first() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1178 *last = *first - 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1179 *numb = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1180 for ( i = *first; i <= *last; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1181 if ( Cont_validNumb( i ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1182 ++(*numb);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1183 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1184
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1185 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1186 doXhdr( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1187 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1188 int first, last, i, n, numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1189 enum { SUBJ, FROM, DATE, MSG_ID, REF, BYTES, LINES } what;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1190 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1191 const Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1192 Str whatStr;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1193
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1194 if ( ! testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1195 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1196 if ( sscanf( arg, "%s", whatStr ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1197 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1198 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1199 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1200 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1201 Utl_toLower( whatStr );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1202 if ( strcmp( whatStr, "subject" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1203 what = SUBJ;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1204 else if ( strcmp( whatStr, "from" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1205 what = FROM;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1206 else if ( strcmp( whatStr, "date" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1207 what = DATE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1208 else if ( strcmp( whatStr, "message-id" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1209 what = MSG_ID;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1210 else if ( strcmp( whatStr, "references" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1211 what = REF;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1212 else if ( strcmp( whatStr, "bytes" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1213 what = BYTES;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1214 else if ( strcmp( whatStr, "lines" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1215 what = LINES;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1216 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1217 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1218 putStat( STAT_HEAD_FOLLOWS, "Unknown header (empty list follows)" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1219 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1220 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1221 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1222 p = Utl_restOfLn( arg, 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1223 parseRange( p, &first, &last, &numb );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1224 if ( numb == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1225 putStat( STAT_NO_ART_SELECTED, "No articles selected" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1226 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1227 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1228 putStat( STAT_HEAD_FOLLOWS, "%s header %lu-%lu",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1229 whatStr, first, last ) ;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1230 for ( i = first; i <= last; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1231 if ( ( ov = Cont_get( i ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1232 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1233 n = Ov_numb( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1234 switch ( what )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1235 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1236 case SUBJ:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1237 putTxtLn( "%lu %s", n, Ov_subj( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1238 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1239 case FROM:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1240 putTxtLn( "%lu %s", n, Ov_from( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1241 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1242 case DATE:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1243 putTxtLn( "%lu %s", n, Ov_date( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1244 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1245 case MSG_ID:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1246 putTxtLn( "%lu %s", n, Ov_msgId( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1247 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1248 case REF:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1249 putTxtLn( "%lu %s", n, Ov_ref( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1250 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1251 case BYTES:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1252 putTxtLn( "%lu %d", n, Ov_bytes( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1253 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1254 case LINES:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1255 putTxtLn( "%lu %d", n, Ov_lines( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1256 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1257 default:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1258 ASSERT( FALSE );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1259 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1260 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1261 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1262 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1263 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1264 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1265
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1266 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1267 doXpat( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1268 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1269 int first, last, i, n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1270 enum { SUBJ, FROM, DATE, MSG_ID, REF } what;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1271 const Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1272 Str whatStr, pat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1273
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1274 if ( ! testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1275 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1276 if ( sscanf( arg, "%s %i-%i %s", whatStr, &first, &last, pat ) != 4 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1277 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1278 if ( sscanf( arg, "%s %i- %s", whatStr, &first, pat ) == 3 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1279 last = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1280 else if ( sscanf( arg, "%s %i %s", whatStr, &first, pat ) == 3 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1281 last = first;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1282 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1283 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1284 putSyntax( cmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1285 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1286 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1287 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1288 Utl_toLower( whatStr );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1289 if ( strcmp( whatStr, "subject" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1290 what = SUBJ;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1291 else if ( strcmp( whatStr, "from" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1292 what = FROM;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1293 else if ( strcmp( whatStr, "date" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1294 what = DATE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1295 else if ( strcmp( whatStr, "message-id" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1296 what = MSG_ID;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1297 else if ( strcmp( whatStr, "references" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1298 what = REF;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1299 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1300 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1301 putStat( STAT_HEAD_FOLLOWS, "invalid header (empty list follows)" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1302 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1303 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1304 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1305 putStat( STAT_HEAD_FOLLOWS, "header" ) ;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1306 for ( i = first; i <= last; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1307 if ( ( ov = Cont_get( i ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1308 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1309 n = Ov_numb( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1310 switch ( what )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1311 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1312 case SUBJ:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1313 if ( Utl_matchPattern( Ov_subj( ov ), pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1314 putTxtLn( "%lu %s", n, Ov_subj( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1315 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1316 case FROM:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1317 if ( Utl_matchPattern( Ov_from( ov ), pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1318 putTxtLn( "%lu %s", n, Ov_from( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1319 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1320 case DATE:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1321 if ( Utl_matchPattern( Ov_date( ov ), pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1322 putTxtLn( "%lu %s", n, Ov_date( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1323 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1324 case MSG_ID:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1325 if ( Utl_matchPattern( Ov_msgId( ov ), pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1326 putTxtLn( "%lu %s", n, Ov_msgId( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1327 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1328 case REF:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1329 if ( Utl_matchPattern( Ov_ref( ov ), pat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1330 putTxtLn( "%lu %s", n, Ov_ref( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1331 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1332 default:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1333 ASSERT( FALSE );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1334 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1335 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1336 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1337 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1338 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1339
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1340 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1341 doSlave( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1342 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1343 putStat( STAT_CMD_OK, "Ok" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1344 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1345 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1346
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1347 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1348 doStat( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1349 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1350 const char *msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1351 int numb;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1352
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1353 if ( ! whichId( &msgId, &numb, arg ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1354 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1355 if ( numb > 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1356 putStat( STAT_ART_RETRIEVED, "%ld %s selected",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1357 numb, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1358 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1359 putStat( STAT_ART_RETRIEVED, "0 %s selected", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1360 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1361 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1362
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1363 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1364 doQuit( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1365 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1366 putStat( STAT_GOODBYE, "Goodbye" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1367 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1368 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1369
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1370 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1371 doXOver( char *arg, const Cmd *cmd )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1372 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1373 int first, last, i, n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1374 const Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1375
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1376 if ( ! testGrpSelected() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1377 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1378 parseRange( arg, &first, &last, &n );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1379 if ( n == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1380 putStat( STAT_NO_ART_SELECTED, "No articles selected" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1381 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1382 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1383 putStat( STAT_OVERS_FOLLOW, "Overview %ld-%ld", first, last );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1384 for ( i = first; i <= last; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1385 if ( ( ov = Cont_get( i ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1386 putTxtLn( "%lu\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1387 Ov_numb( ov ), Ov_subj( ov ), Ov_from( ov ),
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1388 Ov_date( ov ), Ov_msgId( ov ), Ov_ref( ov ),
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1389 Ov_bytes( ov ), Ov_lines( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1390 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1391 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1392 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1393 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1394
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1395 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1396 putFatal( const char *fmt, ... )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1397 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1398 va_list ap;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1399 Str s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1400
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1401 va_start( ap, fmt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1402 vsnprintf( s, MAXCHAR, fmt, ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1403 va_end( ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1404 Log_err( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1405 putStat( STAT_PROGRAM_FAULT, "%s", s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1406 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1407 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1408 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1409
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1410 /* Parse line, execute command and return FALSE, if it was the quit command. */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1411 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1412 parseAndExecute( Str line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1413 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1414 unsigned int i, n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1415 Cmd *c;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1416 Str s, arg;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1417 Bool ret;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1418
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1419 if ( sscanf( line, "%s", s ) == 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1420 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1421 Utl_toLower( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1422 strcpy( arg, Utl_restOfLn( line, 1 ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1423 n = sizeof( commands ) / sizeof( commands[ 0 ] );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1424 for ( i = 0, c = commands; i < n; ++i, ++c )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1425 if ( strcmp( c->name, s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1426 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1427 ret = c->cmdProc( Utl_stripWhiteSpace( arg ), c );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1428 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1429 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1430 return ret;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1431 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1432 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1433 putStat( STAT_NO_SUCH_CMD, "Command not recognized" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1434 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1435 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1436 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1437 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1438
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1439 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1440 putWelcome( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1441 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1442 putStat( STAT_READY_POST_ALLOW, "NNTP server NOFFLE %s",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1443 Cfg_version() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1444 fflush( stdout );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1445 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1446 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1447
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1448 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1449 initServ( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1450 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1451 ASSERT( ! serv.running );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1452 if ( ! Lock_openDatabases() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1453 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1454 serv.running = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1455 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1456 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1457
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1458 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1459 closeServ( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1460 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1461 ASSERT( serv.running );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1462 serv.running = FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1463 Lock_closeDatabases();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1464 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1465
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1466 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1467 Serv_run( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1468 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1469 Bool done;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1470 int r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1471 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1472 struct timeval timeOut;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1473 fd_set readSet;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1474
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1475 putWelcome();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1476 done = FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1477 while ( ! done )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1478 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1479 FD_ZERO( &readSet );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1480 FD_SET( STDIN_FILENO, &readSet );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1481 /* Never hold lock more than 5 seconds (empirically good value,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1482 avoids to close/open databases, if clients sends several
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1483 commands, but releases the lock often enough, for allowing
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1484 multiple persons to read news at the same time) */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1485 timeOut.tv_sec = 5;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1486 timeOut.tv_usec = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1487 r = select( STDIN_FILENO + 1, &readSet, NULL, NULL, &timeOut );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1488 if ( r < 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1489 done = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1490 else if ( r == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1491 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1492 if ( serv.running )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1493 closeServ();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1494 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1495 else /* ( r > 0 ) */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1496 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1497 if ( ! serv.running )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1498 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1499 if ( ! initServ() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1500 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1501 putFatal( "Cannot init server" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1502 done = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1503 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1504 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1505 if ( ! getLn( line ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1506 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1507 Log_inf( "Client disconnected. Terminating." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1508 done = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1509 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1510 else if ( ! parseAndExecute( line ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1511 done = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1512 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1513 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1514 if ( serv.running )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1515 closeServ();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1516 }