annotate server.c @ 2:26398b4be952 noffle

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