Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • conf.c

    r8961950 rcd63d58  
    3636#include "proxy.h"
    3737
    38 char *CONF_FILE;
    39 
    4038static int conf_loadini( conf_t *conf, char *file );
    4139
     
    4341{
    4442        conf_t *conf;
    45         int opt, i;
     43        int opt, i, config_missing = 0;
    4644       
    4745        conf = g_new0( conf_t, 1 );
    4846       
    49         conf->iface = NULL;
     47        conf->iface_in = NULL;
     48        conf->iface_out = NULL;
    5049        conf->port = g_strdup( "6667" );
    5150        conf->nofork = 0;
     
    6160        conf->pidfile = g_strdup( PIDFILE );
    6261        conf->motdfile = g_strdup( ETCDIR "/motd.txt" );
    63         conf->welcomefile = g_strdup( ETCDIR "/welcome.txt" );
    6462        conf->ping_interval = 180;
    6563        conf->ping_timeout = 300;
     
    6765        proxytype = 0;
    6866       
    69         i = conf_loadini( conf, CONF_FILE );
     67        i = conf_loadini( conf, global.conf_file );
    7068        if( i == 0 )
    7169        {
    72                 fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", CONF_FILE );
    73                 return( NULL );
     70                fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", global.conf_file );
     71                return NULL;
    7472        }
    7573        else if( i == -1 )
    7674        {
    77                 fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", CONF_FILE );
    78         }
    79        
    80         while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 )
     75                config_missing ++;
     76                /* Whine after parsing the options if there was no -c pointing
     77                   at a *valid* configuration file. */
     78        }
     79       
     80        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:" ) ) >= 0 )
    8181        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    8282        {
    8383                if( opt == 'i' )
    8484                {
    85                         conf->iface = g_strdup( optarg );
     85                        conf->iface_in = g_strdup( optarg );
    8686                }
    8787                else if( opt == 'p' )
     
    107107                else if( opt == 'c' )
    108108                {
    109                         if( strcmp( CONF_FILE, optarg ) != 0 )
    110                         {
    111                                 g_free( CONF_FILE );
    112                                 CONF_FILE = g_strdup( optarg );
     109                        if( strcmp( global.conf_file, optarg ) != 0 )
     110                        {
     111                                g_free( global.conf_file );
     112                                global.conf_file = g_strdup( optarg );
    113113                                g_free( conf );
    114114                                /* Re-evaluate arguments. Don't use this option twice,
     
    116116                                   works with all libcs BTW.. */
    117117                                optind = 1;
    118                                 return( conf_load( argc, argv ) );
     118                                return conf_load( argc, argv );
    119119                        }
    120120                }
     
    132132                                "\n"
    133133                                "  -I  Classic/InetD mode. (Default)\n"
    134                                 "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
     134                                "  -D  Daemon mode. (one process serves all)\n"
    135135                                "  -F  Forking daemon. (one process per client)\n"
    136136                                "  -u  Run daemon as specified user.\n"
     
    144144                                "  -d  Specify alternative user configuration directory\n"
    145145                                "  -h  Show this help page.\n" );
    146                         return( NULL );
    147                 }
    148                 else if( opt == 'R' )
    149                 {
    150                         /* We can't load the statefile yet (and should make very sure we do this
    151                            only once), so set the filename here and load the state information
    152                            when initializing ForkDaemon. (This option only makes sense in that
    153                            mode anyway!) */
    154                         ipc_master_set_statefile( optarg );
     146                        return NULL;
    155147                }
    156148                else if( opt == 'u' )
     
    170162        }
    171163       
    172         return( conf );
     164        if( config_missing )
     165                fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", global.conf_file );
     166       
     167        return conf;
    173168}
    174169
     
    179174       
    180175        ini = ini_open( file );
    181         if( ini == NULL ) return( -1 );
     176        if( ini == NULL ) return -1;
    182177        while( ini_read( ini ) )
    183178        {
     
    200195                        else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
    201196                        {
    202                                 g_free( conf->iface );
    203                                 conf->iface = g_strdup( ini->value );
     197                                g_free( conf->iface_in );
     198                                conf->iface_in = g_strdup( ini->value );
    204199                        }
    205200                        else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
     
    207202                                g_free( conf->port );
    208203                                conf->port = g_strdup( ini->value );
     204                        }
     205                        else if( g_strcasecmp( ini->key, "clientinterface" ) == 0 )
     206                        {
     207                                g_free( conf->iface_out );
     208                                conf->iface_out = g_strdup( ini->value );
    209209                        }
    210210                        else if( g_strcasecmp( ini->key, "authmode" ) == 0 )
     
    242242                                conf->motdfile = g_strdup( ini->value );
    243243                        }
    244                         else if( g_strcasecmp( ini->key, "welcomefile" ) == 0 )
    245                         {
    246                                 g_free( conf->welcomefile );
    247                                 conf->welcomefile = g_strdup( ini->value );
    248                         }
    249244                        else if( g_strcasecmp( ini->key, "account_storage" ) == 0 )
    250245                        {
     
    255250                        {
    256251                                g_strfreev( conf->migrate_storage );
    257                                 conf->migrate_storage = g_strsplit( ini->value, " \t,;", -1 );
     252                                conf->migrate_storage = g_strsplit_set( ini->value, " \t,;", -1 );
    258253                        }
    259254                        else if( g_strcasecmp( ini->key, "pinginterval" ) == 0 )
     
    262257                                {
    263258                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    264                                         return( 0 );
     259                                        return 0;
    265260                                }
    266261                                conf->ping_interval = i;
     
    271266                                {
    272267                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    273                                         return( 0 );
     268                                        return 0;
    274269                                }
    275270                                conf->ping_timeout = i;
     
    283278                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    284279                                        g_free( url );
    285                                         return( 0 );
     280                                        return 0;
    286281                                }
    287282                               
     
    307302                        {
    308303                                fprintf( stderr, "Error: Unknown setting `%s` in configuration file.\n", ini->key );
    309                                 return( 0 );
     304                                return 0;
    310305                                /* For now just ignore unknown keys... */
    311306                        }
     
    315310                        fprintf( stderr, "Error: Unknown section [%s] in configuration file. "
    316311                                         "BitlBee configuration must be put in a [settings] section!\n", ini->section );
    317                         return( 0 );
     312                        return 0;
    318313                }
    319314        }
    320315        ini_close( ini );
    321316       
    322         return( 1 );
     317        return 1;
    323318}
    324319
     
    327322        ini_t *ini;
    328323       
    329         ini = ini_open( CONF_FILE );
     324        ini = ini_open( global.conf_file );
    330325        if( ini == NULL ) return;
    331326        while( ini_read( ini ) )
Note: See TracChangeset for help on using the changeset viewer.