]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/conf.c
topic no longer limited to 127 chars (now only limited by protocol)
[ngircd.git] / src / ngircd / conf.c
index d422b468cc7ae21e2f641e73a1902c02830c2f6b..0764d2c7d96d720f700860221543479f07f86567 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.78 2005/07/07 18:46:46 fw Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.81 2005/07/28 16:23:55 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -97,7 +97,8 @@ Conf_Test( void )
 
        struct passwd *pwd;
        struct group *grp;
-       int i;
+       unsigned int i;
+       char *topic;
 
        Use_Log = false;
        Set_Defaults( true );
@@ -187,7 +188,8 @@ Conf_Test( void )
                puts( "[CHANNEL]" );
                printf( "  Name = %s\n", Conf_Channel[i].name );
                printf( "  Modes = %s\n", Conf_Channel[i].modes );
-               printf( "  Topic = %s\n", Conf_Channel[i].topic );
+               topic = (char*)array_start(&Conf_Channel[i].topic);
+               printf( "  Topic = %s\n", topic ? topic : "");
                puts( "" );
        }
        
@@ -508,15 +510,14 @@ Read_Config( void )
                                else New_Server_Idx = i;
                                continue;
                        }
-                       if( strcasecmp( section, "[CHANNEL]" ) == 0 )
-                       {
-                               if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
-                               else
-                               {
+                       if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
+                               if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
+                                       Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
+                               } else {
                                        /* Initialize new channel structure */
                                        strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
                                        strcpy( Conf_Channel[Conf_Channel_Count].modes, "" );
-                                       strcpy( Conf_Channel[Conf_Channel_Count].topic, "" );
+                                       array_free(&Conf_Channel[Conf_Channel_Count].topic);
                                        Conf_Channel_Count++;
                                }
                                continue;
@@ -804,35 +805,47 @@ Handle_GLOBAL( int Line, char *Var, char *Arg )
 LOCAL void
 Handle_OPERATOR( int Line, char *Var, char *Arg )
 {
+       unsigned int opercount;
+       size_t len;
        assert( Line > 0 );
        assert( Var != NULL );
        assert( Arg != NULL );
        assert( Conf_Oper_Count > 0 );
 
-       if( strcasecmp( Var, "Name" ) == 0 )
-       {
+       if ( Conf_Oper_Count == 0 )
+               return;
+
+       opercount = Conf_Oper_Count - 1;
+
+       if( strcasecmp( Var, "Name" ) == 0 ) {
                /* Name of IRC operator */
-               if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].name, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].name )) Config_Error_TooLong( Line, Var );
+               len = strlcpy( Conf_Oper[opercount].name, Arg, sizeof( Conf_Oper[opercount].name ));
+               if (len >= sizeof( Conf_Oper[opercount].name ))
+                               Config_Error_TooLong( Line, Var );
+
                return;
        }
-       if( strcasecmp( Var, "Password" ) == 0 )
-       {
+       if( strcasecmp( Var, "Password" ) == 0 ) {
                /* Password of IRC operator */
-               if( strlcpy( Conf_Oper[Conf_Oper_Count - 1].pwd, Arg, sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) >= sizeof( Conf_Oper[Conf_Oper_Count - 1].pwd )) Config_Error_TooLong( Line, Var );
+               len = strlcpy( Conf_Oper[opercount].pwd, Arg, sizeof( Conf_Oper[opercount].pwd ));
+               if (len >= sizeof( Conf_Oper[opercount].pwd ))
+                               Config_Error_TooLong( Line, Var );
                return;
        }
-       if( strcasecmp( Var, "Mask" ) == 0 )
-       {
-               if (Conf_Oper[Conf_Oper_Count - 1].mask) return; /* Hostname already configured */
-               Conf_Oper[Conf_Oper_Count - 1].mask = strdup( Arg );
-               if (! Conf_Oper[Conf_Oper_Count - 1].mask) {
-                       Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s", NGIRCd_ConfFile, Line, strerror(errno) );
+       if( strcasecmp( Var, "Mask" ) == 0 ) {
+               if (Conf_Oper[opercount].mask) return; /* Hostname already configured */
+
+               Conf_Oper[opercount].mask = strdup( Arg );
+               if (! Conf_Oper[opercount].mask) {
+                       Config_Error( LOG_ERR, "%s, line %d: Cannot allocate memory for operator mask: %s",
+                                                               NGIRCd_ConfFile, Line, strerror(errno) );
                        return;
                }
 
                return;
        }
-       Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
+       Config_Error( LOG_ERR, "%s, line %d (section \"Operator\"): Unknown variable \"%s\"!",
+                                                               NGIRCd_ConfFile, Line, Var );
 } /* Handle_OPERATOR */
 
 
@@ -922,7 +935,7 @@ Handle_CHANNEL( int Line, char *Var, char *Arg )
        if( strcasecmp( Var, "Topic" ) == 0 )
        {
                /* Initial topic */
-               if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].topic ))
+               if (!array_copys( &Conf_Channel[Conf_Channel_Count - 1].topic, Arg))
                        Config_Error_TooLong( Line, Var );
  
                return;