annotate client.c @ 29:4d455c29bfd1 noffle

[svn] Send MODE READER for INN
author enz
date Sun, 30 Apr 2000 12:17:40 +0100
parents ab6cf19be6d3
children 45ddd5e72164
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 client.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
25
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
4 $Id: client.c 31 2000-04-29 13:37:59Z enz $
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include "client.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <arpa/inet.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <ctype.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include <netdb.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include <netinet/in.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include <signal.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include <stdarg.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include <sys/socket.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16 #include <unistd.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 "dynamicstring.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 #include "group.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 #include "over.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 #include "protocol.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 #include "pseudo.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
25 #include "request.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 struct
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
30 FILE* in; /* Receiving socket from server */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 FILE* out; /* Sending socket to server */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32 Str lastCmd; /* Last command line */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 Str lastStat; /* Response from server to last command */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34 Str grp; /* Selected group */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35 int rmtFirst; /* First article of current group at server */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 int rmtLast; /* Last article of current group at server */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 Bool auth; /* Authetication already done? */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38 Str serv; /* Remote server name */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 } client = { NULL, NULL, "", "", "", 1, 0, FALSE, "" };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42 logBreakDown( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44 Log_err( "Connection to remote server lost "
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 "(article numbers could be inconsistent)" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
46 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 getLn( Str line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51 Bool r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 r = Prt_getLn( line, client.in );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 if ( ! r )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 logBreakDown();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56 return r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 getTxtLn( Str line, Bool *err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 Bool r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 r = Prt_getTxtLn( line, err, client.in );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65 if ( *err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 logBreakDown();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 return r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 putTxtBuf( const char *buf )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73 Prt_putTxtBuf( buf, client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 fflush( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 putEndOfTxt( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 Prt_putEndOfTxt( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82 fflush( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87 putCmd( const char *fmt, ... )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 unsigned int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 va_list ap;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 va_start( ap, fmt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 vsnprintf( line, MAXCHAR, fmt, ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 va_end( ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 strcpy( client.lastCmd, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98 Log_dbg( "[S] %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 n = fprintf( client.out, "%s\r\n", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 fflush( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102 err = ( n != strlen( line ) + 2 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
103 if ( err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
104 logBreakDown();;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
105 return ! err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
106 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
107
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
108 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
109 putCmdNoFlush( const char *fmt, ... )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
110 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
111 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
112 unsigned int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
113 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
114 va_list ap;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
115
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
116 va_start( ap, fmt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
117 vsnprintf( line, MAXCHAR, fmt, ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
118 va_end( ap );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
119 strcpy( client.lastCmd, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
120 Log_dbg( "[S] %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
121 n = fprintf( client.out, "%s\r\n", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
122 err = ( n != strlen( line ) + 2 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
123 if ( err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
124 logBreakDown();;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
125 return ! err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
126 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
127
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
128 static int getStat( void );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
129
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
130 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
131 performAuth( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
132 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
133 int stat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
134 Str user, pass;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
135
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
136 Cfg_authInfo( client.serv, user, pass );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
137 if ( strcmp( user, "" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
138 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
139 Log_err( "No username for authentication set" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
140 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
141 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
142 putCmd( "AUTHINFO USER %s", user );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
143 stat = getStat();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
144 if ( stat == STAT_AUTH_ACCEPTED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
145 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
146 else if ( stat != STAT_MORE_AUTH_REQUIRED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
147 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
148 Log_err( "Username rejected. Server stat: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
149 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
150 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
151 if ( strcmp( pass, "" ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
152 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
153 Log_err( "No password for authentication set" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
154 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
155 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
156 putCmd( "AUTHINFO PASS %s", pass );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
157 stat = getStat();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
158 if ( stat != STAT_AUTH_ACCEPTED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
159 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
160 Log_err( "Password rejected. Server status: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
161 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
162 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
163 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
164 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
165
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
166 static int
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
167 getStat( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
168 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
169 int result;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
170 Str lastCmd;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
171
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
172 if ( ! getLn( client.lastStat ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
173 result = STAT_PROGRAM_FAULT;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
174 else if ( sscanf( client.lastStat, "%d", &result ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
175 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
176 Log_err( "Invalid server status: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
177 result = STAT_PROGRAM_FAULT;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
178 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
179 if ( result == STAT_AUTH_REQUIRED && ! client.auth )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
180 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
181 client.auth = TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
182 strcpy( lastCmd, client.lastCmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
183 if ( performAuth() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
184 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
185 putCmd( lastCmd );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
186 return getStat();
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 return result;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
190 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
191
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
192 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
193 connectAlarm( int sig )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
194 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
195 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
196 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
197
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
198 static sig_t
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
199 installSignalHandler( int sig, sig_t handler )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
200 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
201 struct sigaction act, oldAct;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
202
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
203 act.sa_handler = handler;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
204 sigemptyset( &act.sa_mask );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
205 act.sa_flags = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
206 if ( sig == SIGALRM )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
207 act.sa_flags |= SA_INTERRUPT;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
208 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
209 act.sa_flags |= SA_RESTART;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
210 if ( sigaction( sig, &act, &oldAct ) < 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
211 return SIG_ERR;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
212 return oldAct.sa_handler;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
213 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
214
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
215 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
216 connectWithTimeout( int sock, const struct sockaddr *servAddr,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
217 socklen_t addrLen )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
218 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
219 sig_t oldHandler;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
220 int r, to;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
221
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
222 oldHandler = installSignalHandler( SIGALRM, connectAlarm );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
223 if ( oldHandler == SIG_ERR )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
224 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
225 Log_err( "client.c:connectWithTimeout: signal failed." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
226 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
227 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
228 to = Cfg_connectTimeout();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
229 if ( alarm( to ) != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
230 Log_err( "client.c:connectWithTimeout: Alarm was already set." );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
231 r = connect( sock, servAddr, addrLen );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
232 alarm( 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
233 installSignalHandler( SIGALRM, oldHandler );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
234 return ( r >= 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
235 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
236
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
237 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
238 Client_connect( const char *serv )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
239 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
240 unsigned short int port;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
241 int sock, i;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
242 unsigned int stat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
243 struct hostent *hp;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
244 char *pStart, *pColon;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
245 Str host, s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
246 struct sockaddr_in sIn;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
247
6
6e822f4b19f9 [svn] Set Client-Authenticated flag to False on connection to server.
enz
parents: 0
diff changeset
248 client.auth = FALSE;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
249 Utl_cpyStr( s, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
250 pStart = Utl_stripWhiteSpace( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
251 pColon = strstr( pStart, ":" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
252 if ( pColon == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
253 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
254 strcpy( host, pStart );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
255 port = 119;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
256 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
257 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
258 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
259 *pColon = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
260 strcpy( host, pStart );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
261 if ( sscanf( pColon + 1, "%hi", &port ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
262 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
263 Log_err( "Syntax error in server name: '%s'", serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
264 return FALSE;;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
265 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
266 if ( port <= 0 || port > 65535 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
267 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
268 Log_err( "Invalid port number %hi. Must be in [1, 65535]", port );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
269 return FALSE;;
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 memset( (void *)&sIn, 0, sizeof( sIn ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
273 hp = gethostbyname( host );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
274 if ( hp )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
275 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
276 for ( i = 0; (hp->h_addr_list)[ i ]; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
277 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
278 sIn.sin_family = hp->h_addrtype;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
279 sIn.sin_port = htons( port );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
280 sIn.sin_addr = *( (struct in_addr *)hp->h_addr_list[ i ] );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
281 sock = socket( AF_INET, SOCK_STREAM, 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
282 if ( sock < 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
283 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
284 if ( ! connectWithTimeout( sock, (struct sockaddr *)&sIn,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
285 sizeof( sIn ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
286 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
287 close( sock );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
288 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
289 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
290 if ( ! ( client.out = fdopen( sock, "w" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
291 || ! ( client.in = fdopen( dup( sock ), "r" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
292 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
293 close( sock );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
294 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
295 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
296 stat = getStat();
25
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
297 if ( stat == STAT_READY_POST_ALLOW ||
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
298 stat == STAT_READY_NO_POST_ALLOW )
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
299 {
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
300 /* INN needs a MODE READER before it will permit POST. */
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
301 putCmd( "MODE READER" );
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
302 stat = getStat();
ab6cf19be6d3 [svn] INN needs a MODE READER before it will permit POST
enz
parents: 6
diff changeset
303 }
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
304 switch( stat ) {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
305 case STAT_READY_POST_ALLOW:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
306 case STAT_READY_NO_POST_ALLOW:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
307 Log_inf( "Connected to %s:%d",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
308 inet_ntoa( sIn.sin_addr ), port );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
309 Utl_cpyStr( client.serv, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
310 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
311 default:
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
312 Log_err( "Bad server stat %d", stat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
313 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
314 shutdown( fileno( client.out ), 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
315 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
316 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
317 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
318 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
319
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
320 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
321 processGrps( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
322 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
323 char postAllow;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
324 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
325 int first, last;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
326 Str grp, line, file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
327
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
328 while ( getTxtLn( line, &err ) && ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
329 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
330 if ( sscanf( line, "%s %i %i %c",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
331 grp, &last, &first, &postAllow ) != 4 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
332 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
333 Log_err( "Unknown reply to LIST or NEWGROUPS: %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
334 continue;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
335 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
336 if ( ! Grp_exists( grp ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
337 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
338 Log_inf( "Registering new group '%s'", grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
339 Grp_create( grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
340 /* Start local numbering with remote first number to avoid
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
341 new numbering at the readers if noffle is re-installed */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
342 if ( first != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
343 Grp_setFirstLast( grp, first, first - 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
344 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
345 Grp_setFirstLast( grp, 1, 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
346 Grp_setRmtNext( grp, first );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
347 Grp_setServ( grp, client.serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
348 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
349 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
350 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
351 if ( Cfg_servIsPreferential( client.serv, Grp_serv( grp ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
352 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
353 Log_inf( "Changing server for '%s': '%s'->'%s'",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
354 grp, Grp_serv( grp ), client.serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
355 Grp_setServ( grp, client.serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
356 Grp_setRmtNext( grp, first );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
357 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
358 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
359 Log_dbg( "Group %s is already fetched from %s",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
360 grp, Grp_serv( grp ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
361
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
362 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
363 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
364 if ( ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
365 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
366 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
367 Utl_stamp( file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
368 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
369 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
370
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
371 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
372 Client_disconnect( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
373 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
374 if ( putCmd( "QUIT" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
375 getStat();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
376 fclose( client.in );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
377 fclose( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
378 client.in = client.out = NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
379 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
380
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
381 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
382 Client_getGrps( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
383 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
384 if ( ! putCmd( "LIST ACTIVE" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
385 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
386 if ( getStat() != STAT_GRPS_FOLLOW )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
387 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
388 Log_err( "LIST ACTIVE command failed: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
389 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
390 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
391 processGrps();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
392 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
393 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
394
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
395 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
396 Client_getDsc( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
397 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
398 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
399 Str name, line, dsc;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
400
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
401 Log_inf( "Querying group descriptions" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
402 if ( ! putCmd( "LIST NEWSGROUPS" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
403 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
404 if ( getStat() != STAT_GRPS_FOLLOW )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
405 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
406 Log_err( "LIST NEWSGROUPS failed: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
407 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
408 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
409 while ( getTxtLn( line, &err ) && ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
410 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
411 if ( sscanf( line, "%s", name ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
412 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
413 Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
414 continue;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
415 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
416 strcpy( dsc, Utl_restOfLn( line, 1 ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
417 if ( Grp_exists( name ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
418 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
419 Log_dbg( "Description of %s: %s", name, dsc );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
420 Grp_setDsc( name, dsc );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
421 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
422 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
423 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
424 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
425
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
426 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
427 Client_getCreationTimes( void )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
428 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
429 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
430 Str name, line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
431 time_t t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
432
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
433 Log_inf( "Querying group creation times" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
434 if ( ! putCmd( "LIST ACTIVE.TIMES" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
435 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
436 if ( getStat() != STAT_GRPS_FOLLOW )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
437 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
438 Log_err( "LIST ACTIVE.TIMES failes: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
439 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
440 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
441 while ( getTxtLn( line, &err ) && ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
442 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
443 if ( sscanf( line, "%s %ld", name, &t ) != 2 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
444 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
445 Log_err( "Unknown reply to LIST ACTIVE.TIMES: %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
446 continue;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
447 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
448 if ( Grp_exists( name ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
449 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
450 Log_inf( "Creation time of %s: %ld", name, t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
451 Grp_setCreated( name, t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
452 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
453 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
454 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
455 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
456
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
457 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
458 Client_getNewgrps( const time_t *lastTime )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
459 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
460 Str s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
461 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
462
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
463 ASSERT( *lastTime > 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
464 strftime( s, MAXCHAR, "%Y%m%d %H%M00", gmtime( lastTime ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
465 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
466 Do not use century for working with old server software until 2000.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
467 According to newest IETF draft, this is still valid after 2000.
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
468 (directly using %y in fmt string causes a Y2K compiler warning)
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
469 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
470 p = s + 2;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
471 if ( ! putCmd( "NEWGROUPS %s", p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
472 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
473 if ( getStat() != STAT_NEW_GRP_FOLLOW )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
474 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
475 Log_err( "NEWGROUPS command failed: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
476 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
477 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
478 processGrps();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
479 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
480 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
481
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
482 static const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
483 readField( Str result, const char *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
484 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
485 size_t len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
486 char *r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
487
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
488 if ( ! p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
489 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
490 r = result;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
491 *r = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
492 len = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
493 while ( *p != '\t' && *p != '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
494 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
495 if ( ! *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
496 return p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
497 *(r++) = *(p++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
498 ++len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
499 if ( len >= MAXCHAR - 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
500 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
501 *r = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
502 Log_err( "Field in overview too long: %s", r );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
503 return ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
504 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
505 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
506 *r = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
507 return ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
508 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
509
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
510 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
511 parseOvLn( Str line, int *numb, Str subj, Str from,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
512 Str date, Str msgId, Str ref, size_t *bytes, size_t *lines )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
513 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
514 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
515 Str t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
516
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
517 p = readField( t, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
518 if ( sscanf( t, "%i", numb ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
519 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
520 p = readField( subj, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
521 p = readField( from, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
522 p = readField( date, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
523 p = readField( msgId, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
524 p = readField( ref, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
525 p = readField( t, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
526 *bytes = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
527 *lines = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
528 if ( sscanf( t, "%d", bytes ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
529 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
530 p = readField( t, p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
531 if ( sscanf( t, "%d", lines ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
532 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
533 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
534 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
535
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
536 static const char*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
537 nextXref( const char *pXref, Str grp, int *numb )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
538 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
539 Str s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
540 const char *pColon, *src;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
541 char *dst;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
542
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
543 src = pXref;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
544 while ( *src && isspace( *src ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
545 ++src;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
546 dst = s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
547 while ( *src && ! isspace( *src ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
548 *(dst++) = *(src++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
549 *dst = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
550 if ( strlen( s ) == 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
551 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
552 pColon = strstr( s, ":" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
553 if ( ! pColon || sscanf( pColon + 1, "%i", numb ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
554 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
555 Log_err( "Corrupt Xref at position '%s'", pXref );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
556 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
557 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
558 Utl_cpyStrN( grp, s, pColon - s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
559 Log_dbg( "client.c: nextXref: grp '%s' numb %lu", grp, numb );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
560 return src;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
561 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
562
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
563 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
564 needsMark( const char *ref )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
565 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
566 Bool done = FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
567 char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
568 Str msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
569 int stat, len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
570 time_t lastAccess, nowTime;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
571 double limit;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
572
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
573 nowTime = time( NULL );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
574 limit = Cfg_threadFollowTime() * 24. * 3600.;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
575 while ( ! done )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
576 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
577 p = msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
578 while ( *ref != '<' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
579 if ( *(ref++) == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
580 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
581 len = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
582 while ( *ref != '>' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
583 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
584 if ( *ref == '\0' || ++len >= MAXCHAR - 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
585 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
586 *(p++) = *(ref++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
587 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
588 *(p++) = '>';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
589 *p = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
590 if ( Db_contains( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
591 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
592 stat = Db_stat( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
593 lastAccess = Db_lastAccess( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
594 if ( ( stat & DB_INTERESTING )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
595 && difftime( nowTime, lastAccess ) <= limit )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
596 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
597 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
598 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
599 return FALSE;
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 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
603 prepareEntry( Over *ov )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
604 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
605 Str g, t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
606 const char *msgId, *p, *xref;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
607 int n;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
608
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
609 msgId = Ov_msgId( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
610 if ( Pseudo_isGeneralInfo( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
611 Log_dbg( "Skipping general info '%s'", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
612 else if ( Db_contains( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
613 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
614 xref = Db_xref( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
615 Log_dbg( "Entry '%s' already in db with Xref '%s'", msgId, xref );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
616 p = nextXref( xref, g, &n );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
617 if ( p == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
618 Log_err( "Overview with no group in Xref '%s'", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
619 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
620 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
621 if ( Cfg_servIsPreferential( client.serv, Grp_serv( g ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
622 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
623 Log_dbg( "Changing first server for '%s' from '%s' to '%s'",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
624 msgId, Grp_serv( g ), client.serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
625 snprintf( t, MAXCHAR, "%s:%i %s",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
626 client.grp, Ov_numb( ov ), xref );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
627 Db_setXref( msgId, t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
628 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
629 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
630 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
631 Log_dbg( "Adding '%s' to Xref of '%s'", g, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
632 snprintf( t, MAXCHAR, "%s %s:%i",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
633 xref, client.grp, Ov_numb( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
634 Db_setXref( msgId, t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
635 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
636 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
637 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
638 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
639 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
640 Log_dbg( "Preparing '%s' in database", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
641 Db_prepareEntry( ov, client.grp, Ov_numb( ov ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
642 }
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 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
646 Client_getOver( int rmtFirst, int rmtLast, FetchMode mode )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
647 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
648 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
649 size_t bytes, lines;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
650 int rmtNumb, oldLast, cntMarked;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
651 Over *ov;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
652 Str line, subj, from, date, msgId, ref;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
653
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
654 ASSERT( strcmp( client.grp, "" ) != 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
655 if ( ! putCmd( "XOVER %lu-%lu", rmtFirst, rmtLast ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
656 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
657 if ( getStat() != STAT_OVERS_FOLLOW )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
658 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
659 Log_err( "XOVER command failed: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
660 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
661 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
662 Log_dbg( "Requesting overview for remote %lu-%lu", rmtFirst, rmtLast );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
663 oldLast = Cont_last();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
664 cntMarked = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
665 while ( getTxtLn( line, &err ) && ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
666 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
667 if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
668 &bytes, &lines ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
669 Log_err( "Bad overview line: %s", line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
670 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
671 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
672 ov = new_Over( subj, from, date, msgId, ref, bytes, lines );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
673 Cont_app( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
674 prepareEntry( ov );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
675 if ( mode == FULL || ( mode == THREAD && needsMark( ref ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
676 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
677 Req_add( client.serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
678 ++cntMarked;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
679 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
680 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
681 Grp_setRmtNext( client.grp, rmtNumb + 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
682 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
683 if ( oldLast != Cont_last() )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
684 Log_inf( "Added %s %lu-%lu", client.grp, oldLast + 1, Cont_last() );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
685 Log_inf( "%u articles marked for download in %s", cntMarked, client.grp );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
686 return err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
687 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
688
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
689 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
690 retrievingFailed( const char* msgId, const char *reason )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
691 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
692 int stat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
693
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
694 Log_err( "Retrieving of %s failed: %s", msgId, reason );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
695 stat = Db_stat( msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
696 Pseudo_retrievingFailed( msgId, reason );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
697 Db_setStat( msgId, stat | DB_RETRIEVING_FAILED );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
698 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
699
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
700 static Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
701 retrieveAndStoreArt( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
702 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
703 Bool err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
704 DynStr *s = NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
705 Str line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
706
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
707 Log_inf( "Retrieving %s", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
708 s = new_DynStr( 5000 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
709 while ( getTxtLn( line, &err ) && ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
710 DynStr_appLn( s, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
711 if ( ! err )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
712 Db_storeArt( msgId, DynStr_str( s ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
713 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
714 retrievingFailed( msgId, "Connection broke down" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
715 del_DynStr( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
716 return ! err;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
717 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
718
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
719 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
720 Client_retrieveArt( const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
721 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
722 if ( ! Db_contains( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
723 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
724 Log_err( "Article '%s' not prepared in database. Skipping.", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
725 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
726 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
727 if ( ! ( Db_stat( msgId ) & DB_NOT_DOWNLOADED ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
728 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
729 Log_inf( "Article '%s' already retrieved. Skipping.", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
730 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
731 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
732 if ( ! putCmd( "ARTICLE %s", msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
733 retrievingFailed( msgId, "Connection broke down" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
734 else if ( getStat() != STAT_ART_FOLLOWS )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
735 retrievingFailed( msgId, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
736 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
737 retrieveAndStoreArt( msgId );
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 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
741 Client_retrieveArtList( const char *list )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
742 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
743 Str msgId;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
744 DynStr *s;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
745 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
746
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
747 Log_inf( "Retrieving article list" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
748 s = new_DynStr( strlen( list ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
749 p = list;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
750 while ( ( p = Utl_getLn( msgId, p ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
751 if ( ! Db_contains( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
752 Log_err( "Skipping retrieving of %s (not prepared in database)",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
753 msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
754 else if ( ! ( Db_stat( msgId ) & DB_NOT_DOWNLOADED ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
755 Log_inf( "Skipping %s (already retrieved)", msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
756 else if ( ! putCmdNoFlush( "ARTICLE %s", msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
757 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
758 retrievingFailed( msgId, "Connection broke down" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
759 del_DynStr( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
760 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
761 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
762 else
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
763 DynStr_appLn( s, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
764 fflush( client.out );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
765 Log_dbg( "[S FLUSH]" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
766 p = DynStr_str( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
767 while ( ( p = Utl_getLn( msgId, p ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
768 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
769 if ( getStat() != STAT_ART_FOLLOWS )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
770 retrievingFailed( msgId, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
771 else if ( ! retrieveAndStoreArt( msgId ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
772 break;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
773 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
774 del_DynStr( s );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
775 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
776
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
777 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
778 Client_changeToGrp( const char* name )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
779 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
780 unsigned int stat;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
781 int estimatedNumb, first, last;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
782
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
783 if ( ! Grp_exists( name ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
784 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
785 if ( ! putCmd( "GROUP %s", name ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
786 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
787 if ( getStat() != STAT_GRP_SELECTED )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
788 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
789 if ( sscanf( client.lastStat, "%u %i %i %i",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
790 &stat, &estimatedNumb, &first, &last ) != 4 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
791 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
792 Log_err( "Bad server response to GROUP: %s", client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
793 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
794 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
795 Utl_cpyStr( client.grp, name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
796 client.rmtFirst = first;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
797 client.rmtLast = last;
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
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
801 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
802 Client_rmtFirstLast( int *first, int *last )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
803 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
804 *first = client.rmtFirst;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
805 *last = client.rmtLast;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
806 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
807
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
808 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
809 Client_postArt( const char *msgId, const char *artTxt,
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
810 Str errStr )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
811 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
812 if ( ! putCmd( "POST" ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
813 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
814 if ( getStat() != STAT_SEND_ART )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
815 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
816 Log_err( "Posting of %s not allowed: %s", msgId, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
817 strcpy( errStr, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
818 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
819 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
820 putTxtBuf( artTxt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
821 putEndOfTxt();
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
822 if ( getStat() != STAT_POST_OK )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
823 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
824 Log_err( "Posting of %s failed: %s", msgId, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
825 strcpy( errStr, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
826 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
827 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
828 Log_inf( "Posted %s (Status: %s)", msgId, client.lastStat );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
829 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
830 }