changeset 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 f782184db8bc
children 1a54e1702ea2
files src/configfile.c src/configfile.h
diffstat 2 files changed, 129 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/configfile.c	Tue Jun 13 07:31:43 2000 +0100
+++ b/src/configfile.c	Tue Jun 13 07:34:25 2000 +0100
@@ -6,7 +6,7 @@
     SPOOLDIR
     VERSION
 
-  $Id: configfile.c 100 2000-05-18 12:17:23Z bears $
+  $Id: configfile.c 143 2000-06-13 06:34:25Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -21,6 +21,7 @@
 #include "log.h"
 #include "util.h"
 #include "portable.h"
+#include "wildmat.h"
 
 typedef struct
 {
@@ -53,6 +54,13 @@
 }
 ExpireEntry;
 
+typedef struct
+{
+    char *pattern;
+    char *mode;
+}
+AutoSubscribeModeEntry;
+
 struct
 {
     /* Compile time options */
@@ -68,7 +76,7 @@
     Bool infoAlways;
     Bool replaceMsgId;
     Bool postLocal;
-    Str autoSubscribeMode;
+    Str defaultAutoSubscribeMode;
     Str mailTo;
     int defaultExpire;
     int numServ;
@@ -78,7 +86,9 @@
     int numExpire;
     int maxExpire;
     ExpireEntry *expire;
-    int expireIdx;
+    int numAutoSubscribeMode;
+    int maxAutoSubscribeMode;
+    AutoSubscribeModeEntry *autoSubscribeMode;
 } config =
 {
     SPOOLDIR, /* spoolDir */
@@ -92,7 +102,7 @@
     TRUE,     /* infoAlways */
     TRUE,     /* replaceMsgId */
     FALSE,    /* postLocal */
-    "over",   /* autoSubscribeMode */
+    "over",   /* defaultAutoSubscribeMode */
     "",       /* mailTo */
     14,       /* defaultExpire */
     0,        /* numServ */
@@ -102,7 +112,9 @@
     0,        /* numExpire */
     0,        /* maxExpire */
     NULL,     /* expire */
-    0         /* expireIdx */
+    0,        /* numAutoSubscribeMode */
+    0,        /* maxAutoSubscribeMode */
+    NULL      /* autoSubscribeMode */
 };
 
 const char * Cfg_spoolDir( void ) { return config.spoolDir; }
@@ -117,10 +129,10 @@
 Bool Cfg_infoAlways( void )  { return config.infoAlways; }
 Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; }
 Bool Cfg_postLocal( void ) { return config.postLocal; }
-const char * Cfg_autoSubscribeMode( void ) {
-    return config.autoSubscribeMode; }
+const char * Cfg_defaultAutoSubscribeMode( void ) {
+    return config.defaultAutoSubscribeMode; }
 const char * Cfg_mailTo( void ) { return config.mailTo; }
-int Cfg_expire( void ) { return config.defaultExpire; }
+int Cfg_defaultExpire( void ) { return config.defaultExpire; }
 
 void
 Cfg_beginServEnum( void )
@@ -193,19 +205,37 @@
     }
 }
 
-void
-Cfg_beginExpireEnum( void )
+int
+Cfg_expire( const char *grp )
 {
-    config.expireIdx = 0;
+    int i, res;
+
+    for ( i = 0; i < config.numExpire; i++ )
+	if ( Wld_match( grp, config.expire[ i ].pattern ) )
+	{
+	    res = config.expire[ i ].days;
+	    Log_dbg( "Custom expire period %d for group %s", res, grp );
+	    return res;
+	}
+
+    return Cfg_defaultExpire();
 }
 
-int
-Cfg_nextExpire( Str pattern )
+const char *
+Cfg_autoSubscribeMode( const char *grp )
 {
-    if ( config.expireIdx >= config.numExpire )
-        return -1;
-    strcpy( pattern, config.expire[ config.expireIdx ].pattern );
-    return config.expire[ config.expireIdx++ ].days;
+    int i;
+    const char *res;
+
+    for ( i = 0; i < config.numAutoSubscribeMode; i++ )
+	if ( Wld_match( grp, config.autoSubscribeMode[ i ].pattern ) )
+	{
+	    res = config.autoSubscribeMode[ i ].mode;
+	    Log_dbg( "Custom auto subscribe mode %s for group %s", res, grp );
+	    return res;
+	}
+
+    return Cfg_defaultAutoSubscribeMode();
 }
 
 GroupEnum *
@@ -374,10 +404,6 @@
     ExpireEntry entry;
     int days;
 
-    /*
-      The line is either "expire <num>" or "expire <pat> <num>".
-      The former updates the overall default.
-     */
     if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 )
     {
 	logSyntaxErr( line );
@@ -402,7 +428,7 @@
 					      ( config.maxExpire + 5 )
 					      * sizeof( ExpireEntry ) ) ) )
 	    {
-		Log_err( "Could not realloc exipre list" );
+		Log_err( "Could not realloc expire list" );
 		exit( EXIT_FAILURE );
 	    }
 	    config.maxExpire += 5;
@@ -463,6 +489,68 @@
     del_Itl( patterns) ;
 }
 
+static Bool
+isValidAutoSubscribeMode( const char *mode )
+{
+    return strcmp( mode, "full" ) == 0
+	|| strcmp( mode, "thread" ) == 0
+	|| strcmp( mode, "over" ) == 0
+	|| strcmp( mode, "off" ) == 0;
+}
+
+static void
+getAutoSubscribeMode( const char *line )
+{
+    Str dummy, pattern, mode;
+    AutoSubscribeModeEntry entry;
+    int items;
+
+    items = sscanf( line, "%s %s %s", dummy, pattern, mode );
+    if ( items == 2 )
+    {
+	/* Backwards compat. default-auto-subscribe-mode */
+	Utl_cpyStr( mode, pattern );
+	Utl_toLower( mode );
+	if ( ! isValidAutoSubscribeMode( mode ) )
+	{
+	    logSyntaxErr( line );
+	    return;
+	}
+	strcpy( config.defaultAutoSubscribeMode, mode );
+	return;
+    }
+    else if ( items != 3 )
+    {
+	logSyntaxErr( line );
+	return;
+    }
+
+    Utl_toLower( mode );
+    if ( ! isValidAutoSubscribeMode( mode ) )
+    {
+	logSyntaxErr( line );
+	return;
+    }
+
+    Utl_toLower( pattern );
+    Utl_allocAndCpy( &entry.pattern, pattern );
+    Utl_allocAndCpy( &entry.mode, mode );
+
+    if ( config.maxAutoSubscribeMode < config.numAutoSubscribeMode + 1 )
+    {
+	if ( ! ( config.autoSubscribeMode =
+		 realloc( config.autoSubscribeMode,
+			  ( config.maxAutoSubscribeMode + 5 )
+			  * sizeof( AutoSubscribeModeEntry ) ) ) )
+	{
+	    Log_err( "Could not realloc auto subscribe mode list" );
+	    exit( EXIT_FAILURE );
+	}
+	config.maxAutoSubscribeMode += 5;
+    }
+    config.autoSubscribeMode[ config.numAutoSubscribeMode++ ] = entry;
+}
+
 void
 Cfg_read( void )
 {
@@ -506,20 +594,17 @@
             getBool( &config.replaceMsgId, p );
         else if ( strcmp( "post-locally", name ) == 0 )
             getBool( &config.postLocal, p );
-        else if ( strcmp( "auto-subscribe-mode", name ) == 0 )
+        else if ( strcmp( "default-auto-subscribe-mode", name ) == 0 )
         {
             getStr( s, p );
             Utl_toLower( s );
-            if ( strcmp( s, "full" ) != 0
-                 && strcmp( s, "thread" ) != 0
-                 && strcmp( s, "over" ) != 0
-                 && strcmp( s, "off" ) != 0 )
-            {
-                Log_err( "Syntax error in config file: %s", line );
-                return;
-            }
+	    if ( ! isValidAutoSubscribeMode( s ) )
+	    {
+		logSyntaxErr( line );
+		return;
+	    }
             else
-                strcpy( config.autoSubscribeMode, s );
+                strcpy( config.defaultAutoSubscribeMode, s );
         }
         else if ( strcmp( "server", name ) == 0 )
             /* Server needs line not p,
@@ -529,6 +614,8 @@
             getStr( config.mailTo, p );
         else if ( strcmp( "expire", name ) == 0 )
             getExpire( p );
+        else if ( strcmp( "auto-subscribe-mode", name ) == 0 )
+            getAutoSubscribeMode( p );
         else if ( strcmp( "getgroups", name ) == 0 )
             getGroups( p, TRUE );
         else if ( strcmp( "omitgroups", name ) == 0 )
--- a/src/configfile.h	Tue Jun 13 07:31:43 2000 +0100
+++ b/src/configfile.h	Tue Jun 13 07:34:25 2000 +0100
@@ -3,7 +3,7 @@
 
   Common declarations and handling of the configuration file.
 
-  $Id: configfile.h 100 2000-05-18 12:17:23Z bears $
+  $Id: configfile.h 143 2000-06-13 06:34:25Z bears $
 */
 
 #ifndef CONFIGFILE_H
@@ -31,7 +31,6 @@
 
 Bool Cfg_replaceMsgId( void );
 Bool Cfg_postLocal( void );
-const char * Cfg_autoSubscribeMode( void ); /* Can be: full, thread, over */
 const char * Cfg_mailTo( void );
 
 /* Begin iteration through the server names */
@@ -47,15 +46,17 @@
 Bool Cfg_servIsPreferential( const char *name1, const char *name2 );
 void Cfg_authInfo( const char *name, Str user, Str pass );
 
-/* Begin iteration through expire entries. */
-void Cfg_beginExpireEnum( void );
-
-/* Put next expire pattern in "pattern" and return its days count.
-   Return -1 if no more expire patterns. */
-int Cfg_nextExpire( Str pattern );
+/* Return expire period for named group. */
+int Cfg_expire( const char *grp );
 
 /* Return default expire days. */
-int Cfg_expire( void );
+int Cfg_defaultExpire( void );
+
+/* Return auto subscribe mode for named group. Can be: full, thread, over */
+const char * Cfg_autoSubscribeMode( const char *grp );
+
+/* Return default auto subscribe mode. Can be: full, thread, over */
+const char * Cfg_defaultAutoSubscribeMode( void );
 
 void Cfg_read( void );