comparison src/pseudo.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 32ba1198c6fa
comparison
equal deleted inserted replaced
42:2467ff423c15 43:2842f50feb55
1 /*
2 pseudo.c
3
4 $Id: pseudo.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 "pseudo.h"
12
13 #include <stdio.h>
14 #include <time.h>
15 #include "common.h"
16 #include "configfile.h"
17 #include "content.h"
18 #include "database.h"
19 #include "group.h"
20 #include "log.h"
21 #include "protocol.h"
22 #include "util.h"
23
24 Over *
25 genOv( const char *rawSubj, const char *rawBody, const char *suffix )
26 {
27 size_t bytes, lines;
28 time_t t;
29 Str subj, date, msgId;
30
31 snprintf( subj, MAXCHAR, "[ %s ]", rawSubj );
32 time( &t );
33 Utl_rfc822Date( t, date );
34 Prt_genMsgId( msgId, "", suffix );
35 bytes = lines = 0;
36 while ( *rawBody )
37 {
38 ++bytes;
39 if ( *rawBody == '\n' )
40 ++lines;
41 ++rawBody;
42 }
43 return new_Over( subj, "news (\"[ NOFFLE ]\")" , date, msgId, "",
44 bytes, lines );
45 }
46
47 void
48 Pseudo_appGeneralInfo()
49 {
50 Cont_app( genOv( "General info", Pseudo_generalInfoBody(),
51 "NOFFLE-GENERAL-INFO" ) );
52 }
53
54 Bool
55 Pseudo_isGeneralInfo( const char *msgId )
56 {
57 return ( strstr( msgId, "NOFFLE-GENERAL-INFO" ) != NULL );
58 }
59
60 const char *
61 Pseudo_generalInfoHead()
62 {
63 static Str s;
64
65 Over *ov;
66
67 ov = genOv( "General info", Pseudo_generalInfoBody(),
68 "NOFFLE-GENERAL-INFO" );
69 if ( ov )
70 {
71 snprintf( s, MAXCHAR,
72 "Message-ID: %s\n"
73 "Subject: %s\n"
74 "From: %s\n"
75 "Date: %s\n"
76 "Bytes: %u\n"
77 "Lines: %u\n",
78 Ov_msgId( ov ),
79 Ov_subj( ov ),
80 Ov_from( ov ),
81 Ov_date( ov ),
82 Ov_bytes( ov ),
83 Ov_lines( ov ) );
84 del_Over( ov );
85 return s;
86 }
87 return NULL;
88 }
89
90 const char *
91 Pseudo_generalInfoBody( void )
92 {
93 if ( Cfg_autoSubscribe() )
94 return
95 "\n"
96 "\t[ NOFFLE INFO: General information ]\n"
97 "\n"
98 "\t[ This server is running NOFFLE, which is a NNTP server ]\n"
99 "\t[ optimized for low speed dial-up Internet connections. ]\n"
100 "\n"
101 "\t[ By reading this or any other article of this group, ]\n"
102 "\t[ NOFFLE has put it on its fetch list and will retrieve ]\n"
103 "\t[ articles next time it is online. ]\n"
104 "\n"
105 "\t[ If you have more questions about NOFFLE please talk ]\n"
106 "\t[ to your newsmaster or read the manual page for ]\n"
107 "\t[ \"noffle\". ]\n";
108 else
109 return
110 "\n"
111 "\t[ NOFFLE INFO: General information ]\n"
112 "\n"
113 "\t[ This server is running NOFFLE, which is a NNTP server ]\n"
114 "\t[ optimized for low speed dial-up Internet connections. ]\n"
115 "\n"
116 "\t[ This group is presently not on the fetch list. You can ]\n"
117 "\t[ put groups on the fetch list by running the \"noffle\" ]\n"
118 "\t[ command on the computer where this server is running. ]\n"
119 "\n"
120 "\t[ If you have more questions about NOFFLE please talk ]\n"
121 "\t[ to your newsmaster or read the manual page for ]\n"
122 "\t[ \"noffle\". ]\n";
123 }
124
125 const char *
126 Pseudo_markedBody( void )
127 {
128 return
129 "\n"
130 "\t[ NOFFLE INFO: Marked for download ]\n"
131 "\n"
132 "\t[ The body of this article has been marked for download. ]\n";
133 }
134
135 const char *
136 Pseudo_alreadyMarkedBody( void )
137 {
138 return
139 "\n"
140 "\t[ NOFFLE INFO: Already marked for download ]\n"
141 "\n"
142 "\t[ The body of this article has already been marked ]\n"
143 "\t[ for download. ]\n";
144 }
145
146 const char *
147 Pseudo_markingFailedBody( void )
148 {
149 return
150 "\n"
151 "\t[ NOFFLE ERROR: Marking for download failed ]\n"
152 "\n"
153 "\t[ Sorry, I could not mark this article for download. ]\n"
154 "\t[ Either the database is corrupted, or I was unable to ]\n"
155 "\t[ get write access to the request directory. ]\n"
156 "\t[ Please contact your newsmaster to remove this problem. ]\n";
157 }
158
159 void
160 genPseudo( const char *rawSubj, const char* rawBody )
161 {
162 Over *ov;
163 DynStr *body = 0, *artTxt = 0;
164
165 body = new_DynStr( 10000 );
166 artTxt = new_DynStr( 10000 );
167 DynStr_app( body, "\n\t[ NOFFLE INFO: " );
168 DynStr_app( body, rawSubj );
169 DynStr_app( body, " ]\n\n" );
170 DynStr_app( body, "\t[ " );
171 while( *rawBody )
172 {
173 if ( *rawBody == '\n' )
174 {
175 DynStr_app( body, " ]\n" );
176 if ( *( rawBody + 1 ) == '\n' )
177 {
178 DynStr_app( body, "\n\t[ " );
179 ++rawBody;
180 }
181 else if ( *( rawBody + 1 ) != '\0' )
182 DynStr_app( body, "\t[ " );
183 }
184 else
185 DynStr_appN( body, rawBody, 1 );
186 ++rawBody;
187 }
188 DynStr_appLn( body, "" );
189 DynStr_appLn( artTxt,
190 "Comments: Pseudo article generated by news server NOFFLE" );
191 DynStr_appLn( artTxt, "" );
192 DynStr_appDynStr( artTxt, body );
193 ov = genOv( rawSubj, DynStr_str( body ), "PSEUDO" );
194 if ( body && artTxt && ov )
195 {
196 Cont_app( ov );
197 if ( Db_prepareEntry( ov, Cont_grp(), Cont_last() ) )
198 Db_storeArt( Ov_msgId( ov ), DynStr_str( artTxt ) );
199 Cont_write();
200 Grp_setFirstLast( Cont_grp(), Cont_first(), Cont_last() );
201 }
202 del_DynStr( body );
203 del_DynStr( artTxt );
204 }
205
206 void
207 Pseudo_retrievingFailed( const char *msgId, const char *reason )
208 {
209 DynStr *artTxt = 0;
210
211 if ( ! Db_contains( msgId ) )
212 {
213 Log_err( "Article %s has no entry in database %s", msgId );
214 return;
215 }
216 artTxt = new_DynStr( 10000 );
217 DynStr_appLn( artTxt,
218 "Comments: Pseudo body generated by news server NOFFLE" );
219 DynStr_appLn( artTxt, "" );
220 DynStr_app( artTxt,
221 "\n"
222 "\t[ NOFFLE ERROR: Retrieving failed ]\n"
223 "\n"
224 "\t[ This article could not be retrieved. Maybe ]\n"
225 "\t[ it has already expired at the remote server ]\n"
226 "\t[ or it has been cancelled by its sender. See ]\n"
227 "\t[ the appended status line of the remote ]\n"
228 "\t[ server for more information. ]\n"
229 "\n"
230 "\t[ This message will disappear the next time ]\n"
231 "\t[ someone tries to read this article, so that ]\n"
232 "\t[ it can be marked for download again. ]\n" );
233 DynStr_app( artTxt, "\n\t[ Remote server status: " );
234 DynStr_app( artTxt, reason );
235 DynStr_app( artTxt, " ]\n" );
236 Db_storeArt( msgId, DynStr_str( artTxt ) );
237 del_DynStr( artTxt );
238 }
239
240 void
241 Pseudo_cntInconsistent( const char *grp, int first, int last, int next )
242 {
243 DynStr *info;
244 Str s;
245
246 info = new_DynStr( 10000 );
247 if ( info )
248 {
249 DynStr_app( info,
250 "This group's article counter is not \n"
251 "consistent Probably the remote news server\n"
252 "was changed or has reset its article counter\n"
253 "for this group. As a consequence there could\n"
254 "be some articles be duplicated in this group\n" );
255 snprintf( s, MAXCHAR, "Group: %s", grp );
256 DynStr_appLn( info, s );
257 snprintf( s, MAXCHAR, "Remote first article number: %i", first );
258 DynStr_appLn( info, s );
259 snprintf( s, MAXCHAR, "Remote last article number: %i", last );
260 DynStr_appLn( info, s );
261 snprintf( s, MAXCHAR, "Remote next article number: %i", next );
262 DynStr_appLn( info, s );
263 genPseudo( "Article counter inconsistent", DynStr_str( info ) );
264 }
265 del_DynStr( info );
266 }
267
268 void
269 Pseudo_missArts( const char *grp, int first, int next )
270 {
271 DynStr *info;
272 Str s;
273
274 info = new_DynStr( 5000 );
275 if ( info )
276 {
277 DynStr_app( info,
278 "Some articles could not be retrieved from\n"
279 "the remote server, because it had already\n"
280 "deleted them.\n"
281 "If this group is on the fetch list, then\n"
282 "contact your newsmaster to ensure that\n"
283 "\"noffle\" is fetching news more frequently.\n" );
284 snprintf( s, MAXCHAR, "Group: %s", grp );
285 DynStr_appLn( info, s );
286 snprintf( s, MAXCHAR, "Remote next article number: %i", next );
287 DynStr_appLn( info, s );
288 snprintf( s, MAXCHAR, "Remote first article number: %i", first );
289 DynStr_appLn( info, s );
290 genPseudo( "Missing articles", DynStr_str( info ) );
291 del_DynStr( info );
292 }
293 }
294
295 void
296 Pseudo_autoUnsubscribed( const char *grp, int days )
297 {
298 DynStr *info;
299 Str s;
300
301 info = new_DynStr( 10000 );
302 if ( info )
303 {
304 DynStr_app( info,
305 "NOFFLE has automatically unsubscribed this\n"
306 "group since it has not been accessed for\n"
307 "some time.\n"
308 "Re-subscribing is done either automatically\n"
309 "by NOFFLE (if configured) or by manually\n"
310 "running the 'noffle --subscribe' command\n" );
311 snprintf( s, MAXCHAR, "Group: %s", grp );
312 DynStr_appLn( info, s );
313 snprintf( s, MAXCHAR, "Days without access: %i", days );
314 DynStr_appLn( info, s );
315 genPseudo( "Auto unsubscribed", DynStr_str( info ) );
316 }
317 del_DynStr( info );
318 }
319
320 void
321 Pseudo_autoSubscribed()
322 {
323 DynStr *info;
324
325 info = new_DynStr( 10000 );
326 if ( info )
327 {
328 DynStr_app( info,
329 "NOFFLE has now automatically subscribed to\n"
330 "this group. It will fetch articles next time\n"
331 "it is online.\n" );
332 genPseudo( "Auto subscribed", DynStr_str( info ) );
333 }
334 del_DynStr( info );
335 }