comparison src/configfile.c @ 88:1fcdced0246e noffle

[svn] Move posting code to post.c, add command line posting
author bears
date Thu, 18 May 2000 13:17:23 +0100
parents 1eb0cdd17c76
children 402300614185
comparison
equal deleted inserted replaced
87:bf8c97460fd7 88:1fcdced0246e
4 The following macros must be set, when compiling this file: 4 The following macros must be set, when compiling this file:
5 CONFIGFILE 5 CONFIGFILE
6 SPOOLDIR 6 SPOOLDIR
7 VERSION 7 VERSION
8 8
9 $Id: configfile.c 88 2000-05-14 16:15:08Z bears $ 9 $Id: configfile.c 100 2000-05-18 12:17:23Z bears $
10 */ 10 */
11 11
12 #if HAVE_CONFIG_H 12 #if HAVE_CONFIG_H
13 #include <config.h> 13 #include <config.h>
14 #endif 14 #endif
15 15
16 #include "configfile.h" 16 #include "configfile.h"
17 17
18 #include <ctype.h>
18 #include <limits.h> 19 #include <limits.h>
20 #include "itemlist.h"
19 #include "log.h" 21 #include "log.h"
20 #include "util.h" 22 #include "util.h"
21 #include "portable.h" 23 #include "portable.h"
22 24
23 typedef struct 25 typedef struct
24 { 26 {
25 Str name; 27 int numGroup;
26 Str user; 28 int maxGroup;
27 Str pass; 29 char **groups;
30 }
31 GroupEntry;
32
33 struct GroupEnum
34 {
35 GroupEntry *groupEntry;
36 int groupIdx;
37 };
38
39 typedef struct
40 {
41 char *name;
42 char *user;
43 char *pass;
44 GroupEntry getgroups;
45 GroupEntry omitgroups;
28 } 46 }
29 ServEntry; 47 ServEntry;
30 48
31 typedef struct 49 typedef struct
32 { 50 {
33 Str pattern; 51 char *pattern;
34 int days; 52 int days;
35 } 53 }
36 ExpireEntry; 54 ExpireEntry;
37 55
38 struct 56 struct
46 int threadFollowTime; 64 int threadFollowTime;
47 int connectTimeout; 65 int connectTimeout;
48 Bool autoSubscribe; 66 Bool autoSubscribe;
49 Bool autoUnsubscribe; 67 Bool autoUnsubscribe;
50 Bool infoAlways; 68 Bool infoAlways;
51 Bool removeMsgId;
52 Bool replaceMsgId; 69 Bool replaceMsgId;
70 Bool postLocal;
53 Str autoSubscribeMode; 71 Str autoSubscribeMode;
54 Str mailTo; 72 Str mailTo;
55 int defaultExpire; 73 int defaultExpire;
56 int numServ; 74 int numServ;
57 int maxServ; 75 int maxServ;
70 7, /* threadFollowTime */ 88 7, /* threadFollowTime */
71 30, /* connectTimeout */ 89 30, /* connectTimeout */
72 FALSE, /* autoSubscribe */ 90 FALSE, /* autoSubscribe */
73 FALSE, /* autoUnsubscribe */ 91 FALSE, /* autoUnsubscribe */
74 TRUE, /* infoAlways */ 92 TRUE, /* infoAlways */
75 FALSE, /* removeMsgId */
76 TRUE, /* replaceMsgId */ 93 TRUE, /* replaceMsgId */
94 FALSE, /* postLocal */
77 "over", /* autoSubscribeMode */ 95 "over", /* autoSubscribeMode */
78 "", /* mailTo */ 96 "", /* mailTo */
79 14, /* defaultExpire */ 97 14, /* defaultExpire */
80 0, /* numServ */ 98 0, /* numServ */
81 0, /* maxServ */ 99 0, /* maxServ */
95 int Cfg_threadFollowTime( void ) { return config.threadFollowTime; } 113 int Cfg_threadFollowTime( void ) { return config.threadFollowTime; }
96 int Cfg_connectTimeout( void ) { return config.connectTimeout; } 114 int Cfg_connectTimeout( void ) { return config.connectTimeout; }
97 Bool Cfg_autoUnsubscribe( void ) { return config.autoUnsubscribe; } 115 Bool Cfg_autoUnsubscribe( void ) { return config.autoUnsubscribe; }
98 Bool Cfg_autoSubscribe( void ) { return config.autoSubscribe; } 116 Bool Cfg_autoSubscribe( void ) { return config.autoSubscribe; }
99 Bool Cfg_infoAlways( void ) { return config.infoAlways; } 117 Bool Cfg_infoAlways( void ) { return config.infoAlways; }
100 Bool Cfg_removeMsgId( void ) { return config.removeMsgId; }
101 Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; } 118 Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; }
119 Bool Cfg_postLocal( void ) { return config.postLocal; }
102 const char * Cfg_autoSubscribeMode( void ) { 120 const char * Cfg_autoSubscribeMode( void ) {
103 return config.autoSubscribeMode; } 121 return config.autoSubscribeMode; }
104 const char * Cfg_mailTo( void ) { return config.mailTo; } 122 const char * Cfg_mailTo( void ) { return config.mailTo; }
105 int Cfg_expire( void ) { return config.defaultExpire; } 123 int Cfg_expire( void ) { return config.defaultExpire; }
106 124
188 return -1; 206 return -1;
189 strcpy( pattern, config.expire[ config.expireIdx ].pattern ); 207 strcpy( pattern, config.expire[ config.expireIdx ].pattern );
190 return config.expire[ config.expireIdx++ ].days; 208 return config.expire[ config.expireIdx++ ].days;
191 } 209 }
192 210
211 GroupEnum *
212 new_GetGrEn( const char *name )
213 {
214 GroupEnum *res;
215 int servIdx;
216
217 res = (GroupEnum *) malloc( sizeof( GroupEnum ) );
218 if ( res == NULL )
219 {
220 Log_err( "Malloc of GroupEnum failed." );
221 exit( EXIT_FAILURE );
222 }
223 if ( ! searchServ( name, &servIdx ) )
224 res->groupEntry = NULL;
225 else
226 res->groupEntry = &config.serv[ servIdx ].getgroups;
227 GrEn_first( res );
228 return res;
229 }
230
231 GroupEnum *
232 new_OmitGrEn( const char *name )
233 {
234 GroupEnum *res;
235 int servIdx;
236
237 res = (GroupEnum *) malloc( sizeof( GroupEnum ) );
238 if ( res == NULL )
239 {
240 Log_err( "Malloc of GroupEnum failed." );
241 exit( EXIT_FAILURE );
242 }
243 if ( ! searchServ( name, &servIdx ) )
244 res->groupEntry = NULL;
245 else
246 res->groupEntry = &config.serv[ servIdx ].omitgroups;
247 GrEn_first( res );
248 return res;
249 }
250
251 void
252 del_GrEn( GroupEnum *ge )
253 {
254 free(ge);
255 }
256
257 void
258 GrEn_first( GroupEnum *ge )
259 {
260 ge->groupIdx = 0;
261 }
262
263 const char *
264 GrEn_next( GroupEnum *ge )
265 {
266 if ( ge->groupEntry == NULL ||
267 ge->groupIdx >= ge->groupEntry->numGroup )
268 return NULL;
269 return ge->groupEntry->groups[ ge->groupIdx++ ];
270 }
271
193 static void 272 static void
194 logSyntaxErr( const char *line ) 273 logSyntaxErr( const char *line )
195 { 274 {
196 Log_err( "Syntax error in config file: %s", line ); 275 Log_err( "Syntax error in config file: %s", line );
197 } 276 }
249 } 328 }
250 329
251 static void 330 static void
252 getServ( const char *line ) 331 getServ( const char *line )
253 { 332 {
254 Str dummy; 333 Str dummy, name, user, pass;
255 int r, len; 334 int r, len;
256 ServEntry entry; 335 ServEntry entry;
257 336
258 entry.user[ 0 ] = '\0'; 337 memset( &entry, 0, sizeof( entry ) );
259 entry.pass[ 0 ] = '\0';
260 r = sscanf( line, "%s %s %s %s", 338 r = sscanf( line, "%s %s %s %s",
261 dummy, entry.name, entry.user, entry.pass ); 339 dummy, name, user, pass );
262 if ( r < 2 ) 340 if ( r < 2 )
263 { 341 {
264 logSyntaxErr( line ); 342 logSyntaxErr( line );
265 return; 343 return;
266 } 344 }
267 len = strlen( entry.name ); 345 len = strlen( name );
268 /* To make server name more definit, it is made lowercase and 346 /* To make server name more definit, it is made lowercase and
269 port is removed, if it is the default port */ 347 port is removed, if it is the default port */
270 if ( len > 4 && strcmp( entry.name + len - 4, ":119" ) == 0 ) 348 if ( len > 4 && strcmp( name + len - 4, ":119" ) == 0 )
271 entry.name[ len - 4 ] = '\0'; 349 name[ len - 4 ] = '\0';
272 Utl_toLower( entry.name ); 350 Utl_toLower( name );
351
352 Utl_allocAndCpy( &entry.name, name );
353 Utl_allocAndCpy( &entry.user, user );
354 Utl_allocAndCpy( &entry.pass, pass );
273 355
274 if ( config.maxServ < config.numServ + 1 ) 356 if ( config.maxServ < config.numServ + 1 )
275 { 357 {
276 if ( ! ( config.serv = realloc( config.serv, 358 if ( ! ( config.serv = realloc( config.serv,
277 ( config.maxServ + 5 ) 359 ( config.maxServ + 5 )
286 } 368 }
287 369
288 static void 370 static void
289 getExpire( const char *line ) 371 getExpire( const char *line )
290 { 372 {
291 Str dummy; 373 Str dummy, pattern;
292 ExpireEntry entry; 374 ExpireEntry entry;
293 int days; 375 int days;
294 376
295 /* 377 /*
296 The line is either "expire <num>" or "expire <pat> <num>". 378 The line is either "expire <num>" or "expire <pat> <num>".
297 The former updates the overall default. 379 The former updates the overall default.
298 */ 380 */
299 if ( sscanf( line, "%s %s %d", dummy, entry.pattern, &days ) != 3 ) 381 if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 )
300 { 382 {
301 logSyntaxErr( line ); 383 logSyntaxErr( line );
302 return; 384 return;
303 } 385 }
304 else 386 else
308 Log_err( "Expire days error in '%s': must be integer > 0", 390 Log_err( "Expire days error in '%s': must be integer > 0",
309 line, days ); 391 line, days );
310 return; 392 return;
311 } 393 }
312 394
313 Utl_toLower( entry.pattern ); 395 Utl_toLower( pattern );
396 Utl_allocAndCpy( &entry.pattern, pattern );
314 entry.days = days; 397 entry.days = days;
315 398
316 if ( config.maxExpire < config.numExpire + 1 ) 399 if ( config.maxExpire < config.numExpire + 1 )
317 { 400 {
318 if ( ! ( config.expire = realloc( config.expire, 401 if ( ! ( config.expire = realloc( config.expire,
324 } 407 }
325 config.maxExpire += 5; 408 config.maxExpire += 5;
326 } 409 }
327 config.expire[ config.numExpire++ ] = entry; 410 config.expire[ config.numExpire++ ] = entry;
328 } 411 }
412 }
413
414 static void
415 getGroups( char *line, Bool isGet )
416 {
417 const char *name;
418 ItemList *patterns;
419 const char *pattern;
420
421 if ( config.numServ == 0 )
422 {
423 Log_err( "No current server in %s", line );
424 return;
425 }
426
427 name = line;
428 /* Skip over name and terminate it */
429 while ( line[ 0 ] != '\0' && ! isspace( line[ 0 ] ) )
430 line++;
431 if ( line[ 0 ] == '\0' )
432 {
433 logSyntaxErr( name );
434 return;
435 }
436 line[ 0 ] = '\0';
437 line++;
438
439 patterns = new_Itl( line, " ," );
440 for( pattern = Itl_first( patterns );
441 pattern != NULL;
442 pattern = Itl_next( patterns ) )
443 {
444 GroupEntry *g;
445
446 if ( isGet )
447 g = &config.serv[ config.numServ - 1 ].getgroups;
448 else
449 g = &config.serv[ config.numServ - 1 ].omitgroups;
450 if ( g->maxGroup < g->numGroup + 1 )
451 {
452 if ( ! ( g->groups = realloc( g->groups,
453 ( g->maxGroup + 5 )
454 * sizeof( char * ) ) ) )
455 {
456 Log_err( "Could not realloc group list" );
457 exit( EXIT_FAILURE );
458 }
459 g->maxGroup += 5;
460 }
461 Utl_allocAndCpy( &g->groups[ g->numGroup++ ], pattern );
462 }
463 del_Itl( patterns) ;
329 } 464 }
330 465
331 void 466 void
332 Cfg_read( void ) 467 Cfg_read( void )
333 { 468 {
365 getBool( &config.autoSubscribe, p ); 500 getBool( &config.autoSubscribe, p );
366 else if ( strcmp( "auto-unsubscribe", name ) == 0 ) 501 else if ( strcmp( "auto-unsubscribe", name ) == 0 )
367 getBool( &config.autoUnsubscribe, p ); 502 getBool( &config.autoUnsubscribe, p );
368 else if ( strcmp( "info-always-unread", name ) == 0 ) 503 else if ( strcmp( "info-always-unread", name ) == 0 )
369 getBool( &config.infoAlways, p ); 504 getBool( &config.infoAlways, p );
370 else if ( strcmp( "remove-messageid", name ) == 0 )
371 getBool( &config.removeMsgId, p );
372 else if ( strcmp( "replace-messageid", name ) == 0 ) 505 else if ( strcmp( "replace-messageid", name ) == 0 )
373 getBool( &config.replaceMsgId, p ); 506 getBool( &config.replaceMsgId, p );
507 else if ( strcmp( "post-locally", name ) == 0 )
508 getBool( &config.postLocal, p );
374 else if ( strcmp( "auto-subscribe-mode", name ) == 0 ) 509 else if ( strcmp( "auto-subscribe-mode", name ) == 0 )
375 { 510 {
376 getStr( s, p ); 511 getStr( s, p );
377 Utl_toLower( s ); 512 Utl_toLower( s );
378 if ( strcmp( s, "full" ) != 0 513 if ( strcmp( s, "full" ) != 0
392 getServ( line ); 527 getServ( line );
393 else if ( strcmp( "mail-to", name ) == 0 ) 528 else if ( strcmp( "mail-to", name ) == 0 )
394 getStr( config.mailTo, p ); 529 getStr( config.mailTo, p );
395 else if ( strcmp( "expire", name ) == 0 ) 530 else if ( strcmp( "expire", name ) == 0 )
396 getExpire( p ); 531 getExpire( p );
532 else if ( strcmp( "getgroups", name ) == 0 )
533 getGroups( p, TRUE );
534 else if ( strcmp( "omitgroups", name ) == 0 )
535 getGroups( p, FALSE );
397 else 536 else
398 Log_err( "Unknown config option: %s", name ); 537 Log_err( "Unknown config option: %s", name );
399 } 538 }
400 fclose( f ); 539 fclose( f );
401 if ( ! config.numServ ) 540 if ( ! config.numServ )