Mercurial > noffle
comparison src/configfile.c @ 104:402300614185 noffle
[svn] Remove expire enum, add Cfg_expire(grp). Rename Cfg_autoSubscribeMode()
Cfg_defaultAutoSubscribeMode() and add Cfg_autoSubscribeMode(grp).
author | bears |
---|---|
date | Tue, 13 Jun 2000 07:34:25 +0100 |
parents | 1fcdced0246e |
children | 6f681d41734c |
comparison
equal
deleted
inserted
replaced
103:f782184db8bc | 104:402300614185 |
---|---|
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 100 2000-05-18 12:17:23Z bears $ | 9 $Id: configfile.c 143 2000-06-13 06:34:25Z 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 |
19 #include <limits.h> | 19 #include <limits.h> |
20 #include "itemlist.h" | 20 #include "itemlist.h" |
21 #include "log.h" | 21 #include "log.h" |
22 #include "util.h" | 22 #include "util.h" |
23 #include "portable.h" | 23 #include "portable.h" |
24 #include "wildmat.h" | |
24 | 25 |
25 typedef struct | 26 typedef struct |
26 { | 27 { |
27 int numGroup; | 28 int numGroup; |
28 int maxGroup; | 29 int maxGroup; |
50 { | 51 { |
51 char *pattern; | 52 char *pattern; |
52 int days; | 53 int days; |
53 } | 54 } |
54 ExpireEntry; | 55 ExpireEntry; |
56 | |
57 typedef struct | |
58 { | |
59 char *pattern; | |
60 char *mode; | |
61 } | |
62 AutoSubscribeModeEntry; | |
55 | 63 |
56 struct | 64 struct |
57 { | 65 { |
58 /* Compile time options */ | 66 /* Compile time options */ |
59 const char *spoolDir; | 67 const char *spoolDir; |
66 Bool autoSubscribe; | 74 Bool autoSubscribe; |
67 Bool autoUnsubscribe; | 75 Bool autoUnsubscribe; |
68 Bool infoAlways; | 76 Bool infoAlways; |
69 Bool replaceMsgId; | 77 Bool replaceMsgId; |
70 Bool postLocal; | 78 Bool postLocal; |
71 Str autoSubscribeMode; | 79 Str defaultAutoSubscribeMode; |
72 Str mailTo; | 80 Str mailTo; |
73 int defaultExpire; | 81 int defaultExpire; |
74 int numServ; | 82 int numServ; |
75 int maxServ; | 83 int maxServ; |
76 ServEntry *serv; | 84 ServEntry *serv; |
77 int servIdx; /* for server enumeration */ | 85 int servIdx; /* for server enumeration */ |
78 int numExpire; | 86 int numExpire; |
79 int maxExpire; | 87 int maxExpire; |
80 ExpireEntry *expire; | 88 ExpireEntry *expire; |
81 int expireIdx; | 89 int numAutoSubscribeMode; |
90 int maxAutoSubscribeMode; | |
91 AutoSubscribeModeEntry *autoSubscribeMode; | |
82 } config = | 92 } config = |
83 { | 93 { |
84 SPOOLDIR, /* spoolDir */ | 94 SPOOLDIR, /* spoolDir */ |
85 VERSION, /* version */ | 95 VERSION, /* version */ |
86 300, /* maxFetch */ | 96 300, /* maxFetch */ |
90 FALSE, /* autoSubscribe */ | 100 FALSE, /* autoSubscribe */ |
91 FALSE, /* autoUnsubscribe */ | 101 FALSE, /* autoUnsubscribe */ |
92 TRUE, /* infoAlways */ | 102 TRUE, /* infoAlways */ |
93 TRUE, /* replaceMsgId */ | 103 TRUE, /* replaceMsgId */ |
94 FALSE, /* postLocal */ | 104 FALSE, /* postLocal */ |
95 "over", /* autoSubscribeMode */ | 105 "over", /* defaultAutoSubscribeMode */ |
96 "", /* mailTo */ | 106 "", /* mailTo */ |
97 14, /* defaultExpire */ | 107 14, /* defaultExpire */ |
98 0, /* numServ */ | 108 0, /* numServ */ |
99 0, /* maxServ */ | 109 0, /* maxServ */ |
100 NULL, /* serv */ | 110 NULL, /* serv */ |
101 0, /* servIdx */ | 111 0, /* servIdx */ |
102 0, /* numExpire */ | 112 0, /* numExpire */ |
103 0, /* maxExpire */ | 113 0, /* maxExpire */ |
104 NULL, /* expire */ | 114 NULL, /* expire */ |
105 0 /* expireIdx */ | 115 0, /* numAutoSubscribeMode */ |
116 0, /* maxAutoSubscribeMode */ | |
117 NULL /* autoSubscribeMode */ | |
106 }; | 118 }; |
107 | 119 |
108 const char * Cfg_spoolDir( void ) { return config.spoolDir; } | 120 const char * Cfg_spoolDir( void ) { return config.spoolDir; } |
109 const char * Cfg_version( void ) { return config.version; } | 121 const char * Cfg_version( void ) { return config.version; } |
110 | 122 |
115 Bool Cfg_autoUnsubscribe( void ) { return config.autoUnsubscribe; } | 127 Bool Cfg_autoUnsubscribe( void ) { return config.autoUnsubscribe; } |
116 Bool Cfg_autoSubscribe( void ) { return config.autoSubscribe; } | 128 Bool Cfg_autoSubscribe( void ) { return config.autoSubscribe; } |
117 Bool Cfg_infoAlways( void ) { return config.infoAlways; } | 129 Bool Cfg_infoAlways( void ) { return config.infoAlways; } |
118 Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; } | 130 Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; } |
119 Bool Cfg_postLocal( void ) { return config.postLocal; } | 131 Bool Cfg_postLocal( void ) { return config.postLocal; } |
120 const char * Cfg_autoSubscribeMode( void ) { | 132 const char * Cfg_defaultAutoSubscribeMode( void ) { |
121 return config.autoSubscribeMode; } | 133 return config.defaultAutoSubscribeMode; } |
122 const char * Cfg_mailTo( void ) { return config.mailTo; } | 134 const char * Cfg_mailTo( void ) { return config.mailTo; } |
123 int Cfg_expire( void ) { return config.defaultExpire; } | 135 int Cfg_defaultExpire( void ) { return config.defaultExpire; } |
124 | 136 |
125 void | 137 void |
126 Cfg_beginServEnum( void ) | 138 Cfg_beginServEnum( void ) |
127 { | 139 { |
128 config.servIdx = 0; | 140 config.servIdx = 0; |
191 user[ 0 ] = '\0'; | 203 user[ 0 ] = '\0'; |
192 pass[ 0 ] = '\0'; | 204 pass[ 0 ] = '\0'; |
193 } | 205 } |
194 } | 206 } |
195 | 207 |
196 void | |
197 Cfg_beginExpireEnum( void ) | |
198 { | |
199 config.expireIdx = 0; | |
200 } | |
201 | |
202 int | 208 int |
203 Cfg_nextExpire( Str pattern ) | 209 Cfg_expire( const char *grp ) |
204 { | 210 { |
205 if ( config.expireIdx >= config.numExpire ) | 211 int i, res; |
206 return -1; | 212 |
207 strcpy( pattern, config.expire[ config.expireIdx ].pattern ); | 213 for ( i = 0; i < config.numExpire; i++ ) |
208 return config.expire[ config.expireIdx++ ].days; | 214 if ( Wld_match( grp, config.expire[ i ].pattern ) ) |
215 { | |
216 res = config.expire[ i ].days; | |
217 Log_dbg( "Custom expire period %d for group %s", res, grp ); | |
218 return res; | |
219 } | |
220 | |
221 return Cfg_defaultExpire(); | |
222 } | |
223 | |
224 const char * | |
225 Cfg_autoSubscribeMode( const char *grp ) | |
226 { | |
227 int i; | |
228 const char *res; | |
229 | |
230 for ( i = 0; i < config.numAutoSubscribeMode; i++ ) | |
231 if ( Wld_match( grp, config.autoSubscribeMode[ i ].pattern ) ) | |
232 { | |
233 res = config.autoSubscribeMode[ i ].mode; | |
234 Log_dbg( "Custom auto subscribe mode %s for group %s", res, grp ); | |
235 return res; | |
236 } | |
237 | |
238 return Cfg_defaultAutoSubscribeMode(); | |
209 } | 239 } |
210 | 240 |
211 GroupEnum * | 241 GroupEnum * |
212 new_GetGrEn( const char *name ) | 242 new_GetGrEn( const char *name ) |
213 { | 243 { |
372 { | 402 { |
373 Str dummy, pattern; | 403 Str dummy, pattern; |
374 ExpireEntry entry; | 404 ExpireEntry entry; |
375 int days; | 405 int days; |
376 | 406 |
377 /* | |
378 The line is either "expire <num>" or "expire <pat> <num>". | |
379 The former updates the overall default. | |
380 */ | |
381 if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 ) | 407 if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 ) |
382 { | 408 { |
383 logSyntaxErr( line ); | 409 logSyntaxErr( line ); |
384 return; | 410 return; |
385 } | 411 } |
400 { | 426 { |
401 if ( ! ( config.expire = realloc( config.expire, | 427 if ( ! ( config.expire = realloc( config.expire, |
402 ( config.maxExpire + 5 ) | 428 ( config.maxExpire + 5 ) |
403 * sizeof( ExpireEntry ) ) ) ) | 429 * sizeof( ExpireEntry ) ) ) ) |
404 { | 430 { |
405 Log_err( "Could not realloc exipre list" ); | 431 Log_err( "Could not realloc expire list" ); |
406 exit( EXIT_FAILURE ); | 432 exit( EXIT_FAILURE ); |
407 } | 433 } |
408 config.maxExpire += 5; | 434 config.maxExpire += 5; |
409 } | 435 } |
410 config.expire[ config.numExpire++ ] = entry; | 436 config.expire[ config.numExpire++ ] = entry; |
459 g->maxGroup += 5; | 485 g->maxGroup += 5; |
460 } | 486 } |
461 Utl_allocAndCpy( &g->groups[ g->numGroup++ ], pattern ); | 487 Utl_allocAndCpy( &g->groups[ g->numGroup++ ], pattern ); |
462 } | 488 } |
463 del_Itl( patterns) ; | 489 del_Itl( patterns) ; |
490 } | |
491 | |
492 static Bool | |
493 isValidAutoSubscribeMode( const char *mode ) | |
494 { | |
495 return strcmp( mode, "full" ) == 0 | |
496 || strcmp( mode, "thread" ) == 0 | |
497 || strcmp( mode, "over" ) == 0 | |
498 || strcmp( mode, "off" ) == 0; | |
499 } | |
500 | |
501 static void | |
502 getAutoSubscribeMode( const char *line ) | |
503 { | |
504 Str dummy, pattern, mode; | |
505 AutoSubscribeModeEntry entry; | |
506 int items; | |
507 | |
508 items = sscanf( line, "%s %s %s", dummy, pattern, mode ); | |
509 if ( items == 2 ) | |
510 { | |
511 /* Backwards compat. default-auto-subscribe-mode */ | |
512 Utl_cpyStr( mode, pattern ); | |
513 Utl_toLower( mode ); | |
514 if ( ! isValidAutoSubscribeMode( mode ) ) | |
515 { | |
516 logSyntaxErr( line ); | |
517 return; | |
518 } | |
519 strcpy( config.defaultAutoSubscribeMode, mode ); | |
520 return; | |
521 } | |
522 else if ( items != 3 ) | |
523 { | |
524 logSyntaxErr( line ); | |
525 return; | |
526 } | |
527 | |
528 Utl_toLower( mode ); | |
529 if ( ! isValidAutoSubscribeMode( mode ) ) | |
530 { | |
531 logSyntaxErr( line ); | |
532 return; | |
533 } | |
534 | |
535 Utl_toLower( pattern ); | |
536 Utl_allocAndCpy( &entry.pattern, pattern ); | |
537 Utl_allocAndCpy( &entry.mode, mode ); | |
538 | |
539 if ( config.maxAutoSubscribeMode < config.numAutoSubscribeMode + 1 ) | |
540 { | |
541 if ( ! ( config.autoSubscribeMode = | |
542 realloc( config.autoSubscribeMode, | |
543 ( config.maxAutoSubscribeMode + 5 ) | |
544 * sizeof( AutoSubscribeModeEntry ) ) ) ) | |
545 { | |
546 Log_err( "Could not realloc auto subscribe mode list" ); | |
547 exit( EXIT_FAILURE ); | |
548 } | |
549 config.maxAutoSubscribeMode += 5; | |
550 } | |
551 config.autoSubscribeMode[ config.numAutoSubscribeMode++ ] = entry; | |
464 } | 552 } |
465 | 553 |
466 void | 554 void |
467 Cfg_read( void ) | 555 Cfg_read( void ) |
468 { | 556 { |
504 getBool( &config.infoAlways, p ); | 592 getBool( &config.infoAlways, p ); |
505 else if ( strcmp( "replace-messageid", name ) == 0 ) | 593 else if ( strcmp( "replace-messageid", name ) == 0 ) |
506 getBool( &config.replaceMsgId, p ); | 594 getBool( &config.replaceMsgId, p ); |
507 else if ( strcmp( "post-locally", name ) == 0 ) | 595 else if ( strcmp( "post-locally", name ) == 0 ) |
508 getBool( &config.postLocal, p ); | 596 getBool( &config.postLocal, p ); |
509 else if ( strcmp( "auto-subscribe-mode", name ) == 0 ) | 597 else if ( strcmp( "default-auto-subscribe-mode", name ) == 0 ) |
510 { | 598 { |
511 getStr( s, p ); | 599 getStr( s, p ); |
512 Utl_toLower( s ); | 600 Utl_toLower( s ); |
513 if ( strcmp( s, "full" ) != 0 | 601 if ( ! isValidAutoSubscribeMode( s ) ) |
514 && strcmp( s, "thread" ) != 0 | 602 { |
515 && strcmp( s, "over" ) != 0 | 603 logSyntaxErr( line ); |
516 && strcmp( s, "off" ) != 0 ) | 604 return; |
517 { | 605 } |
518 Log_err( "Syntax error in config file: %s", line ); | |
519 return; | |
520 } | |
521 else | 606 else |
522 strcpy( config.autoSubscribeMode, s ); | 607 strcpy( config.defaultAutoSubscribeMode, s ); |
523 } | 608 } |
524 else if ( strcmp( "server", name ) == 0 ) | 609 else if ( strcmp( "server", name ) == 0 ) |
525 /* Server needs line not p, | 610 /* Server needs line not p, |
526 because password may contain uppercase */ | 611 because password may contain uppercase */ |
527 getServ( line ); | 612 getServ( line ); |
528 else if ( strcmp( "mail-to", name ) == 0 ) | 613 else if ( strcmp( "mail-to", name ) == 0 ) |
529 getStr( config.mailTo, p ); | 614 getStr( config.mailTo, p ); |
530 else if ( strcmp( "expire", name ) == 0 ) | 615 else if ( strcmp( "expire", name ) == 0 ) |
531 getExpire( p ); | 616 getExpire( p ); |
617 else if ( strcmp( "auto-subscribe-mode", name ) == 0 ) | |
618 getAutoSubscribeMode( p ); | |
532 else if ( strcmp( "getgroups", name ) == 0 ) | 619 else if ( strcmp( "getgroups", name ) == 0 ) |
533 getGroups( p, TRUE ); | 620 getGroups( p, TRUE ); |
534 else if ( strcmp( "omitgroups", name ) == 0 ) | 621 else if ( strcmp( "omitgroups", name ) == 0 ) |
535 getGroups( p, FALSE ); | 622 getGroups( p, FALSE ); |
536 else | 623 else |