diff 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
line wrap: on
line diff
--- a/src/configfile.c	Thu May 18 13:11:05 2000 +0100
+++ b/src/configfile.c	Thu May 18 13:17:23 2000 +0100
@@ -6,7 +6,7 @@
     SPOOLDIR
     VERSION
 
-  $Id: configfile.c 88 2000-05-14 16:15:08Z bears $
+  $Id: configfile.c 100 2000-05-18 12:17:23Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -15,22 +15,40 @@
 
 #include "configfile.h"
 
+#include <ctype.h>
 #include <limits.h>
+#include "itemlist.h"
 #include "log.h"
 #include "util.h"
 #include "portable.h"
 
 typedef struct
 {
-    Str name;
-    Str user;
-    Str pass;
+    int numGroup;
+    int maxGroup;
+    char **groups;
+}
+GroupEntry;
+
+struct GroupEnum
+{
+    GroupEntry *groupEntry;
+    int groupIdx;
+};
+
+typedef struct
+{
+    char *name;
+    char *user;
+    char *pass;
+    GroupEntry getgroups;
+    GroupEntry omitgroups;
 }
 ServEntry;
 
 typedef struct
 {
-    Str pattern;
+    char *pattern;
     int days;
 }
 ExpireEntry;
@@ -48,8 +66,8 @@
     Bool autoSubscribe;
     Bool autoUnsubscribe;
     Bool infoAlways;
-    Bool removeMsgId;
     Bool replaceMsgId;
+    Bool postLocal;
     Str autoSubscribeMode;
     Str mailTo;
     int defaultExpire;
@@ -72,8 +90,8 @@
     FALSE,    /* autoSubscribe */
     FALSE,    /* autoUnsubscribe */
     TRUE,     /* infoAlways */
-    FALSE,    /* removeMsgId */
     TRUE,     /* replaceMsgId */
+    FALSE,    /* postLocal */
     "over",   /* autoSubscribeMode */
     "",       /* mailTo */
     14,       /* defaultExpire */
@@ -97,8 +115,8 @@
 Bool Cfg_autoUnsubscribe( void ) { return config.autoUnsubscribe; }
 Bool Cfg_autoSubscribe( void )  { return config.autoSubscribe; }
 Bool Cfg_infoAlways( void )  { return config.infoAlways; }
-Bool Cfg_removeMsgId( void ) { return config.removeMsgId; }
 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_mailTo( void ) { return config.mailTo; }
@@ -190,6 +208,67 @@
     return config.expire[ config.expireIdx++ ].days;
 }
 
+GroupEnum *
+new_GetGrEn( const char *name )
+{
+    GroupEnum *res;
+    int servIdx;
+
+    res = (GroupEnum *) malloc( sizeof( GroupEnum ) );
+    if ( res == NULL )
+    {
+	Log_err( "Malloc of GroupEnum failed." );
+	exit( EXIT_FAILURE );
+    }
+    if ( ! searchServ( name, &servIdx ) )
+	res->groupEntry = NULL;
+    else
+	res->groupEntry = &config.serv[ servIdx ].getgroups;
+    GrEn_first( res );
+    return res;
+}
+
+GroupEnum *
+new_OmitGrEn( const char *name )
+{
+    GroupEnum *res;
+    int servIdx;
+
+    res = (GroupEnum *) malloc( sizeof( GroupEnum ) );
+    if ( res == NULL )
+    {
+	Log_err( "Malloc of GroupEnum failed." );
+	exit( EXIT_FAILURE );
+    }
+    if ( ! searchServ( name, &servIdx ) )
+	res->groupEntry = NULL;
+    else
+	res->groupEntry = &config.serv[ servIdx ].omitgroups;
+    GrEn_first( res );
+    return res;
+}
+
+void
+del_GrEn( GroupEnum *ge )
+{
+    free(ge);
+}
+
+void
+GrEn_first( GroupEnum *ge )
+{
+    ge->groupIdx = 0;
+}
+
+const char *
+GrEn_next( GroupEnum *ge )
+{
+    if ( ge->groupEntry == NULL ||
+	 ge->groupIdx >= ge->groupEntry->numGroup )
+	return NULL;
+    return ge->groupEntry->groups[ ge->groupIdx++ ];
+}
+
 static void
 logSyntaxErr( const char *line )
 {
@@ -251,25 +330,28 @@
 static void
 getServ( const char *line )
 {
-    Str dummy;
+    Str dummy, name, user, pass;
     int r, len;
     ServEntry entry;
 
-    entry.user[ 0 ] = '\0';
-    entry.pass[ 0 ] = '\0';
+    memset( &entry, 0, sizeof( entry ) );
     r = sscanf( line, "%s %s %s %s",
-                dummy, entry.name, entry.user, entry.pass );
+                dummy, name, user, pass );
     if ( r < 2 )
     {
         logSyntaxErr( line );
         return;
     }
-    len = strlen( entry.name );
+    len = strlen( name );
     /* To make server name more definit, it is made lowercase and
        port is removed, if it is the default port */
-    if ( len > 4 && strcmp( entry.name + len - 4, ":119" ) == 0 )
-        entry.name[ len - 4 ] = '\0';
-    Utl_toLower( entry.name );
+    if ( len > 4 && strcmp( name + len - 4, ":119" ) == 0 )
+        name[ len - 4 ] = '\0';
+    Utl_toLower( name );
+
+    Utl_allocAndCpy( &entry.name, name );
+    Utl_allocAndCpy( &entry.user, user );
+    Utl_allocAndCpy( &entry.pass, pass );
 
     if ( config.maxServ < config.numServ + 1 )
     {
@@ -288,7 +370,7 @@
 static void
 getExpire( const char *line )
 {
-    Str dummy;
+    Str dummy, pattern;
     ExpireEntry entry;
     int days;
 
@@ -296,7 +378,7 @@
       The line is either "expire <num>" or "expire <pat> <num>".
       The former updates the overall default.
      */
-    if ( sscanf( line, "%s %s %d", dummy, entry.pattern, &days ) != 3 )
+    if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 )
     {
 	logSyntaxErr( line );
 	return;
@@ -310,7 +392,8 @@
 	    return;
 	}
 
-	Utl_toLower( entry.pattern );
+	Utl_toLower( pattern );
+	Utl_allocAndCpy( &entry.pattern, pattern );
 	entry.days = days;
 
 	if ( config.maxExpire < config.numExpire + 1 )
@@ -328,6 +411,58 @@
     }
 }
 
+static void
+getGroups( char *line, Bool isGet )
+{
+    const char *name;
+    ItemList *patterns;
+    const char *pattern;
+
+    if ( config.numServ == 0 )
+    {
+	Log_err( "No current server in %s", line );
+	return;
+    }
+    
+    name = line;
+    /* Skip over name and terminate it */
+    while ( line[ 0 ] != '\0' && ! isspace( line[ 0 ] ) )
+	line++;
+    if ( line[ 0 ] == '\0' )
+    {
+	logSyntaxErr( name );
+	return;
+    }
+    line[ 0 ] = '\0';
+    line++;
+    
+    patterns = new_Itl( line, " ," );
+    for( pattern = Itl_first( patterns );
+	 pattern != NULL;
+	 pattern = Itl_next( patterns ) )
+    {
+	GroupEntry *g;
+
+	if ( isGet )
+	    g = &config.serv[ config.numServ - 1 ].getgroups;
+	else
+	    g = &config.serv[ config.numServ - 1 ].omitgroups;
+	if ( g->maxGroup < g->numGroup + 1 )
+	{
+	    if ( ! ( g->groups = realloc( g->groups,
+					  ( g->maxGroup + 5 )
+					  * sizeof( char * ) ) ) )
+	    {
+		Log_err( "Could not realloc group list" );
+		exit( EXIT_FAILURE );
+	    }
+	    g->maxGroup += 5;
+	}
+	Utl_allocAndCpy( &g->groups[ g->numGroup++ ], pattern );
+    }
+    del_Itl( patterns) ;
+}
+
 void
 Cfg_read( void )
 {
@@ -367,10 +502,10 @@
             getBool( &config.autoUnsubscribe, p );
         else if ( strcmp( "info-always-unread", name ) == 0 )
             getBool( &config.infoAlways, p );
-        else if ( strcmp( "remove-messageid", name ) == 0 )
-            getBool( &config.removeMsgId, p );
         else if ( strcmp( "replace-messageid", name ) == 0 )
             getBool( &config.replaceMsgId, p );
+        else if ( strcmp( "post-locally", name ) == 0 )
+            getBool( &config.postLocal, p );
         else if ( strcmp( "auto-subscribe-mode", name ) == 0 )
         {
             getStr( s, p );
@@ -394,6 +529,10 @@
             getStr( config.mailTo, p );
         else if ( strcmp( "expire", name ) == 0 )
             getExpire( p );
+        else if ( strcmp( "getgroups", name ) == 0 )
+            getGroups( p, TRUE );
+        else if ( strcmp( "omitgroups", name ) == 0 )
+            getGroups( p, FALSE );
         else
             Log_err( "Unknown config option: %s", name );
     }