Changeset 85d7b85 for conf.c


Ignore:
Timestamp:
2008-04-02T14:22:57Z (16 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
f9dbc99
Parents:
875ad42 (diff), dd34575 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • conf.c

    r875ad42 r85d7b85  
    3434#include "ipc.h"
    3535
    36 #include "protocols/proxy.h"
    37 
    38 char *CONF_FILE;
     36#include "proxy.h"
    3937
    4038static int conf_loadini( conf_t *conf, char *file );
     
    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 #ifdef IPV6
    50         conf->iface = "::";
    51 #else
    52         conf->iface = "0.0.0.0";
    53 #endif
    54         conf->port = 6667;
     47        conf->iface = NULL;
     48        conf->port = g_strdup( "6667" );
    5549        conf->nofork = 0;
    5650        conf->verbose = 0;
    57         conf->primary_storage = "text";
     51        conf->primary_storage = g_strdup( "xml" );
     52        conf->migrate_storage = g_strsplit( "text", ",", -1 );
    5853        conf->runmode = RUNMODE_INETD;
    5954        conf->authmode = AUTHMODE_OPEN;
     
    6257        conf->configdir = g_strdup( CONFIG );
    6358        conf->plugindir = g_strdup( PLUGINDIR );
    64         conf->pidfile = g_strdup( "/var/run/bitlbee.pid" );
     59        conf->pidfile = g_strdup( PIDFILE );
    6560        conf->motdfile = g_strdup( ETCDIR "/motd.txt" );
    6661        conf->ping_interval = 180;
    6762        conf->ping_timeout = 300;
     63        conf->user = NULL;
    6864        proxytype = 0;
    6965       
    70         i = conf_loadini( conf, CONF_FILE );
     66        i = conf_loadini( conf, global.conf_file );
    7167        if( i == 0 )
    7268        {
    73                 fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", CONF_FILE );
    74                 return( NULL );
     69                fprintf( stderr, "Error: Syntax error in configuration file `%s'.\n", global.conf_file );
     70                return NULL;
    7571        }
    7672        else if( i == -1 )
    7773        {
    78                 fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", CONF_FILE );
    79         }
    80        
    81         while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:" ) ) >= 0 )
     74                config_missing ++;
     75                /* Whine after parsing the options if there was no -c pointing
     76                   at a *valid* configuration file. */
     77        }
     78       
     79        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 )
    8280        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    8381        {
     
    8886                else if( opt == 'p' )
    8987                {
    90                         if( ( sscanf( optarg, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) )
    91                         {
    92                                 fprintf( stderr, "Invalid port number: %s\n", optarg );
    93                                 return( NULL );
    94                         }
    95                         conf->port = i;
     88                        g_free( conf->port );
     89                        conf->port = g_strdup( optarg );
    9690                }
    9791                else if( opt == 'P' )
     
    112106                else if( opt == 'c' )
    113107                {
    114                         if( strcmp( CONF_FILE, optarg ) != 0 )
    115                         {
    116                                 g_free( CONF_FILE );
    117                                 CONF_FILE = g_strdup( optarg );
     108                        if( strcmp( global.conf_file, optarg ) != 0 )
     109                        {
     110                                g_free( global.conf_file );
     111                                global.conf_file = g_strdup( optarg );
    118112                                g_free( conf );
    119113                                /* Re-evaluate arguments. Don't use this option twice,
     
    121115                                   works with all libcs BTW.. */
    122116                                optind = 1;
    123                                 return( conf_load( argc, argv ) );
     117                                return conf_load( argc, argv );
    124118                        }
    125119                }
     
    131125                else if( opt == 'h' )
    132126                {
    133                         printf( "Usage: bitlbee [-D [-i <interface>] [-p <port>] [-n] [-v]] [-I]\n"
     127                        printf( "Usage: bitlbee [-D/-F [-i <interface>] [-p <port>] [-n] [-v]] [-I]\n"
    134128                                "               [-c <file>] [-d <dir>] [-h]\n"
    135129                                "\n"
     
    139133                                "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
    140134                                "  -F  Forking daemon. (one process per client)\n"
     135                                "  -u  Run daemon as specified user.\n"
    141136                                "  -P  Specify PID-file (not for inetd mode)\n"
    142137                                "  -i  Specify the interface (by IP address) to listen on.\n"
     
    148143                                "  -d  Specify alternative user configuration directory\n"
    149144                                "  -h  Show this help page.\n" );
    150                         return( NULL );
     145                        return NULL;
    151146                }
    152147                else if( opt == 'R' )
     
    158153                        ipc_master_set_statefile( optarg );
    159154                }
     155                else if( opt == 'u' )
     156                {
     157                        g_free( conf->user );
     158                        conf->user = g_strdup( optarg );
     159                }
    160160        }
    161161       
     
    169169        }
    170170       
    171         return( conf );
     171        if( config_missing )
     172                fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", global.conf_file );
     173       
     174        return conf;
    172175}
    173176
     
    178181       
    179182        ini = ini_open( file );
    180         if( ini == NULL ) return( -1 );
     183        if( ini == NULL ) return -1;
    181184        while( ini_read( ini ) )
    182185        {
     
    199202                        else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
    200203                        {
     204                                g_free( conf->iface );
    201205                                conf->iface = g_strdup( ini->value );
    202206                        }
    203207                        else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
    204208                        {
    205                                 if( ( sscanf( ini->value, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) )
    206                                 {
    207                                         fprintf( stderr, "Invalid port number: %s\n", ini->value );
    208                                         return( 0 );
    209                                 }
    210                                 conf->port = i;
     209                                g_free( conf->port );
     210                                conf->port = g_strdup( ini->value );
    211211                        }
    212212                        else if( g_strcasecmp( ini->key, "authmode" ) == 0 )
     
    221221                        else if( g_strcasecmp( ini->key, "authpassword" ) == 0 )
    222222                        {
     223                                g_free( conf->auth_pass );
    223224                                conf->auth_pass = g_strdup( ini->value );
    224225                        }
    225226                        else if( g_strcasecmp( ini->key, "operpassword" ) == 0 )
    226227                        {
     228                                g_free( conf->oper_pass );
    227229                                conf->oper_pass = g_strdup( ini->value );
    228230                        }
    229231                        else if( g_strcasecmp( ini->key, "hostname" ) == 0 )
    230232                        {
     233                                g_free( conf->hostname );
    231234                                conf->hostname = g_strdup( ini->value );
    232235                        }
     
    249252                        {
    250253                                g_strfreev( conf->migrate_storage );
    251                                 conf->migrate_storage = g_strsplit( ini->value, " \t,;", -1 );
     254                                conf->migrate_storage = g_strsplit_set( ini->value, " \t,;", -1 );
    252255                        }
    253256                        else if( g_strcasecmp( ini->key, "pinginterval" ) == 0 )
     
    256259                                {
    257260                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    258                                         return( 0 );
     261                                        return 0;
    259262                                }
    260263                                conf->ping_interval = i;
     
    265268                                {
    266269                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    267                                         return( 0 );
     270                                        return 0;
    268271                                }
    269272                                conf->ping_timeout = i;
     
    277280                                        fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value );
    278281                                        g_free( url );
    279                                         return( 0 );
     282                                        return 0;
    280283                                }
    281284                               
     
    293296                                g_free( url );
    294297                        }
     298                        else if( g_strcasecmp( ini->key, "user" ) == 0 )
     299                        {
     300                                g_free( conf->user );
     301                                conf->user = g_strdup( ini->value );
     302                        }
    295303                        else
    296304                        {
    297305                                fprintf( stderr, "Error: Unknown setting `%s` in configuration file.\n", ini->key );
    298                                 return( 0 );
     306                                return 0;
    299307                                /* For now just ignore unknown keys... */
    300308                        }
     
    304312                        fprintf( stderr, "Error: Unknown section [%s] in configuration file. "
    305313                                         "BitlBee configuration must be put in a [settings] section!\n", ini->section );
    306                         return( 0 );
     314                        return 0;
    307315                }
    308316        }
    309317        ini_close( ini );
    310318       
    311         return( 1 );
     319        return 1;
    312320}
    313321
     
    316324        ini_t *ini;
    317325       
    318         ini = ini_open( CONF_FILE );
     326        ini = ini_open( global.conf_file );
    319327        if( ini == NULL ) return;
    320328        while( ini_read( ini ) )
     
    322330                if( g_strcasecmp( ini->section, "defaults" ) == 0 )
    323331                {
    324                         set_t *s = set_find( irc, ini->key );
     332                        set_t *s = set_find( &irc->set, ini->key );
    325333                       
    326334                        if( s )
Note: See TracChangeset for help on using the changeset viewer.