Mercurial > noffle
comparison src/fetch.c @ 43:2842f50feb55 noffle
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
control.c, control.h, database.c, database.h, dynamicstring.c,
dynamicstring.h, fetch.c, fetch.h, fetchlist.c, fetchlist.h, group.c,
group.h, itemlist.c, itemlist.h, lock.c, lock.h, log.c, log.h, noffle.c,
online.c, online.h, outgoing.c, outgoing.h, over.c, over.h, post.c, post.h,
protocol.c, protocol.h, pseudo.c, pseudo.h, request.c, request.h, server.c,
server.h, util.c, util.h, wildmat.c, wildmat.h: Moved files to the
subdirectory src/
* Makefile.am, acconfig.h, configure.in, docs/Makefile.am, src/Makefile.am,
Makefile.in, aclocal.m4, config.h.in, configure, install-sh, missing,
mkinstalldirs, stamp-h.in, docs/Makefile.in, src/Makefile.in: Added files.
They are used by aclocal, autoheader, autoconf and automake.
* src/config.c, src/config.h: Renamed to configfile.c and configfile.h,
because configure will generate a config.h file itself.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/noffle.c, src/online.c, src/outgoing.c,
src/over.c, src/pseudo.c, src/request.c, src/server.c, src/util.c:
Changed '#include "config.h"' to '#include "configfile.h"'.
* src/client.c, src/content.c, src/database.c, src/fetch.c, src/fetchlist.c,
src/group.c, src/lock.c, src/online.c, src/outgoing.c, src/post.c,
src/protocol.c, src/request.c, src/server.c: Files now #include <config.h>.
Added missing <stdio.h>. This removes the warnings about snprintf() not
being declared.
* Makefile: Removed. This is now generated by configure.
author | uh1763 |
---|---|
date | Fri, 05 May 2000 22:45:56 +0100 |
parents | |
children | 125d79c9e586 |
comparison
equal
deleted
inserted
replaced
42:2467ff423c15 | 43:2842f50feb55 |
---|---|
1 /* | |
2 fetch.c | |
3 | |
4 $Id: fetch.c 49 2000-05-05 21:45:56Z uh1763 $ | |
5 */ | |
6 | |
7 #if HAVE_CONFIG_H | |
8 #include <config.h> | |
9 #endif | |
10 | |
11 #include <stdio.h> | |
12 #include "fetch.h" | |
13 #include <errno.h> | |
14 #include <time.h> | |
15 #include <signal.h> | |
16 #include "client.h" | |
17 #include "configfile.h" | |
18 #include "content.h" | |
19 #include "dynamicstring.h" | |
20 #include "fetchlist.h" | |
21 #include "request.h" | |
22 #include "group.h" | |
23 #include "log.h" | |
24 #include "outgoing.h" | |
25 #include "protocol.h" | |
26 #include "pseudo.h" | |
27 #include "util.h" | |
28 | |
29 struct Fetch | |
30 { | |
31 Bool ready; | |
32 Str serv; | |
33 } fetch = { FALSE, "" }; | |
34 | |
35 static Bool | |
36 connectToServ( const char *name ) | |
37 { | |
38 Log_inf( "Fetch from '%s'", name ); | |
39 if ( ! Client_connect( name ) ) | |
40 { | |
41 Log_err( "Could not connect to %s", name ); | |
42 return FALSE; | |
43 } | |
44 return TRUE; | |
45 } | |
46 | |
47 void | |
48 Fetch_getNewGrps( void ) | |
49 { | |
50 time_t t; | |
51 Str file; | |
52 | |
53 ASSERT( fetch.ready ); | |
54 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() ); | |
55 if ( ! Utl_getStamp( &t, file ) ) | |
56 { | |
57 Log_err( "Cannot read %s. Please run noffle --query groups", file ); | |
58 return; | |
59 } | |
60 Log_inf( "Updating groupinfo" ); | |
61 Client_getNewgrps( &t ); | |
62 Utl_stamp( file ); | |
63 } | |
64 | |
65 void | |
66 Fetch_getNewArts( const char *name, FetchMode mode ) | |
67 { | |
68 int next, first, last, oldLast; | |
69 | |
70 if ( ! Client_changeToGrp( name ) ) | |
71 { | |
72 Log_err( "Could not change to group %s", name ); | |
73 return; | |
74 } | |
75 Cont_read( name ); | |
76 Client_rmtFirstLast( &first, &last ); | |
77 next = Grp_rmtNext( name ); | |
78 oldLast = Cont_last(); | |
79 if ( next == last + 1 ) | |
80 { | |
81 Log_inf( "No new articles in %s", name ); | |
82 Cont_write(); | |
83 Grp_setFirstLast( name, Cont_first(), Cont_last() ); | |
84 return; | |
85 } | |
86 if ( first == 0 && last == 0 ) | |
87 { | |
88 Log_inf( "No articles in %s", name ); | |
89 Cont_write(); | |
90 Grp_setFirstLast( name, Cont_first(), Cont_last() ); | |
91 return; | |
92 } | |
93 if ( next > last + 1 ) | |
94 { | |
95 Log_err( "Article number inconsistent (%s rmt=%lu-%lu, next=%lu)", | |
96 name, first, last, next ); | |
97 Pseudo_cntInconsistent( name, first, last, next ); | |
98 } | |
99 else if ( next < first ) | |
100 { | |
101 Log_inf( "Missing articles (%s first=%lu next=%lu)", | |
102 name, first, next ); | |
103 Pseudo_missArts( name, first, next ); | |
104 } | |
105 else | |
106 first = next; | |
107 if ( last - first > Cfg_maxFetch() ) | |
108 { | |
109 Log_ntc( "Cutting number of overviews to %lu", Cfg_maxFetch() ); | |
110 first = last - Cfg_maxFetch() + 1; | |
111 } | |
112 Log_inf( "Getting remote overviews %lu-%lu for group %s", | |
113 first, last, name ); | |
114 Client_getOver( first, last, mode ); | |
115 Cont_write(); | |
116 Grp_setFirstLast( name, Cont_first(), Cont_last() ); | |
117 } | |
118 | |
119 void | |
120 Fetch_updateGrps( void ) | |
121 { | |
122 FetchMode mode; | |
123 int i, size; | |
124 const char* name; | |
125 | |
126 ASSERT( fetch.ready ); | |
127 Fetchlist_read(); | |
128 size = Fetchlist_size(); | |
129 for ( i = 0; i < size; ++i ) | |
130 { | |
131 Fetchlist_element( &name, &mode, i ); | |
132 if ( strcmp( Grp_serv( name ), fetch.serv ) == 0 ) | |
133 Fetch_getNewArts( name, mode ); | |
134 } | |
135 } | |
136 | |
137 void | |
138 Fetch_getReq_( void ) | |
139 { | |
140 Str msgId; | |
141 DynStr *list; | |
142 const char *p; | |
143 int count = 0; | |
144 | |
145 ASSERT( fetch.ready ); | |
146 Log_dbg( "Retrieving articles marked for download" ); | |
147 list = new_DynStr( 10000 ); | |
148 if ( Req_first( fetch.serv, msgId ) ) | |
149 do | |
150 { | |
151 DynStr_appLn( list, msgId ); | |
152 if ( ++count % 20 == 0 ) /* Send max. 20 ARTICLE cmds at once */ | |
153 { | |
154 p = DynStr_str( list ); | |
155 Client_retrieveArtList( p ); | |
156 while ( ( p = Utl_getLn( msgId, p ) ) ) | |
157 Req_remove( fetch.serv, msgId ); | |
158 DynStr_clear( list ); | |
159 } | |
160 } | |
161 while ( Req_next( msgId ) ); | |
162 p = DynStr_str( list ); | |
163 Client_retrieveArtList( p ); | |
164 while ( ( p = Utl_getLn( msgId, p ) ) ) | |
165 Req_remove( fetch.serv, msgId ); | |
166 del_DynStr( list ); | |
167 } | |
168 | |
169 void | |
170 Fetch_postArts( void ) | |
171 { | |
172 DynStr *s; | |
173 Str msgId, cmd, errStr, sender; | |
174 int ret; | |
175 const char *txt; | |
176 FILE *f; | |
177 sig_t lastHandler; | |
178 | |
179 s = new_DynStr( 10000 ); | |
180 if ( Out_first( fetch.serv, msgId, s ) ) | |
181 { | |
182 Log_inf( "Posting articles" ); | |
183 do | |
184 { | |
185 txt = DynStr_str( s ); | |
186 Out_remove( fetch.serv, msgId ); | |
187 if ( ! Client_postArt( msgId, txt, errStr ) ) | |
188 { | |
189 Utl_cpyStr( sender, Cfg_mailTo() ); | |
190 if ( strcmp( sender, "" ) == 0 | |
191 && ! Prt_searchHeader( txt, "SENDER", sender ) | |
192 && ! Prt_searchHeader( txt, "X-NOFFLE-X-SENDER", | |
193 sender ) /* see server.c */ | |
194 && ! Prt_searchHeader( txt, "FROM", sender ) ) | |
195 Log_err( "Article %s has no From/Sender/X-Sender field", | |
196 msgId ); | |
197 else | |
198 { | |
199 Log_ntc( "Return article to '%s' by mail", sender ); | |
200 snprintf( cmd, MAXCHAR, | |
201 "mail -s '[ NOFFLE: Posting failed ]' '%s'", | |
202 sender ); | |
203 lastHandler = signal( SIGPIPE, SIG_IGN ); | |
204 f = popen( cmd, "w" ); | |
205 if ( f == NULL ) | |
206 Log_err( "Invocation of '%s' failed (%s)", cmd, | |
207 strerror( errno ) ); | |
208 else | |
209 { | |
210 fprintf( f, | |
211 "\t[ NOFFLE: POSTING OF ARTICLE FAILED ]\n" | |
212 "\n" | |
213 "\t[ The posting of your article failed. ]\n" | |
214 "\t[ Reason of failure at remote server: ]\n" | |
215 "\n" | |
216 "\t[ %s ]\n" | |
217 "\n" | |
218 "\t[ Full article text has been appended. ]\n" | |
219 "\n" | |
220 "%s" | |
221 ".\n", | |
222 errStr, txt ); | |
223 ret = pclose( f ); | |
224 if ( ret != EXIT_SUCCESS ) | |
225 Log_err( "'%s' exit value %d", cmd, ret ); | |
226 signal( SIGPIPE, lastHandler ); | |
227 } | |
228 } | |
229 } | |
230 } | |
231 while ( Out_next( msgId, s ) ); | |
232 } | |
233 del_DynStr( s ); | |
234 } | |
235 | |
236 Bool | |
237 Fetch_init( const char *serv ) | |
238 { | |
239 if ( ! connectToServ( serv ) ) | |
240 return FALSE; | |
241 Utl_cpyStr( fetch.serv, serv ); | |
242 fetch.ready = TRUE; | |
243 return TRUE; | |
244 } | |
245 | |
246 void | |
247 Fetch_close() | |
248 { | |
249 Client_disconnect(); | |
250 fetch.ready = FALSE; | |
251 Log_inf( "Fetch from '%s' finished", fetch.serv ); | |
252 } |