- Timestamp:
- 2008-04-02T14:22:57Z (16 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
conf.c
r875ad42 r85d7b85 34 34 #include "ipc.h" 35 35 36 #include "protocols/proxy.h" 37 38 char *CONF_FILE; 36 #include "proxy.h" 39 37 40 38 static int conf_loadini( conf_t *conf, char *file ); … … 43 41 { 44 42 conf_t *conf; 45 int opt, i ;43 int opt, i, config_missing = 0; 46 44 47 45 conf = g_new0( conf_t, 1 ); 48 46 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" ); 55 49 conf->nofork = 0; 56 50 conf->verbose = 0; 57 conf->primary_storage = "text"; 51 conf->primary_storage = g_strdup( "xml" ); 52 conf->migrate_storage = g_strsplit( "text", ",", -1 ); 58 53 conf->runmode = RUNMODE_INETD; 59 54 conf->authmode = AUTHMODE_OPEN; … … 62 57 conf->configdir = g_strdup( CONFIG ); 63 58 conf->plugindir = g_strdup( PLUGINDIR ); 64 conf->pidfile = g_strdup( "/var/run/bitlbee.pid");59 conf->pidfile = g_strdup( PIDFILE ); 65 60 conf->motdfile = g_strdup( ETCDIR "/motd.txt" ); 66 61 conf->ping_interval = 180; 67 62 conf->ping_timeout = 300; 63 conf->user = NULL; 68 64 proxytype = 0; 69 65 70 i = conf_loadini( conf, CONF_FILE);66 i = conf_loadini( conf, global.conf_file ); 71 67 if( i == 0 ) 72 68 { 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; 75 71 } 76 72 else if( i == -1 ) 77 73 { 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 ) 82 80 /* ^^^^ Just to make sure we skip this step from the REHASH handler. */ 83 81 { … … 88 86 else if( opt == 'p' ) 89 87 { 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 ); 96 90 } 97 91 else if( opt == 'P' ) … … 112 106 else if( opt == 'c' ) 113 107 { 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 ); 118 112 g_free( conf ); 119 113 /* Re-evaluate arguments. Don't use this option twice, … … 121 115 works with all libcs BTW.. */ 122 116 optind = 1; 123 return ( conf_load( argc, argv ));117 return conf_load( argc, argv ); 124 118 } 125 119 } … … 131 125 else if( opt == 'h' ) 132 126 { 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" 134 128 " [-c <file>] [-d <dir>] [-h]\n" 135 129 "\n" … … 139 133 " -D Daemon mode. (Still EXPERIMENTAL!)\n" 140 134 " -F Forking daemon. (one process per client)\n" 135 " -u Run daemon as specified user.\n" 141 136 " -P Specify PID-file (not for inetd mode)\n" 142 137 " -i Specify the interface (by IP address) to listen on.\n" … … 148 143 " -d Specify alternative user configuration directory\n" 149 144 " -h Show this help page.\n" ); 150 return ( NULL );145 return NULL; 151 146 } 152 147 else if( opt == 'R' ) … … 158 153 ipc_master_set_statefile( optarg ); 159 154 } 155 else if( opt == 'u' ) 156 { 157 g_free( conf->user ); 158 conf->user = g_strdup( optarg ); 159 } 160 160 } 161 161 … … 169 169 } 170 170 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; 172 175 } 173 176 … … 178 181 179 182 ini = ini_open( file ); 180 if( ini == NULL ) return ( -1 );183 if( ini == NULL ) return -1; 181 184 while( ini_read( ini ) ) 182 185 { … … 199 202 else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 ) 200 203 { 204 g_free( conf->iface ); 201 205 conf->iface = g_strdup( ini->value ); 202 206 } 203 207 else if( g_strcasecmp( ini->key, "daemonport" ) == 0 ) 204 208 { 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 ); 211 211 } 212 212 else if( g_strcasecmp( ini->key, "authmode" ) == 0 ) … … 221 221 else if( g_strcasecmp( ini->key, "authpassword" ) == 0 ) 222 222 { 223 g_free( conf->auth_pass ); 223 224 conf->auth_pass = g_strdup( ini->value ); 224 225 } 225 226 else if( g_strcasecmp( ini->key, "operpassword" ) == 0 ) 226 227 { 228 g_free( conf->oper_pass ); 227 229 conf->oper_pass = g_strdup( ini->value ); 228 230 } 229 231 else if( g_strcasecmp( ini->key, "hostname" ) == 0 ) 230 232 { 233 g_free( conf->hostname ); 231 234 conf->hostname = g_strdup( ini->value ); 232 235 } … … 249 252 { 250 253 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 ); 252 255 } 253 256 else if( g_strcasecmp( ini->key, "pinginterval" ) == 0 ) … … 256 259 { 257 260 fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value ); 258 return ( 0 );261 return 0; 259 262 } 260 263 conf->ping_interval = i; … … 265 268 { 266 269 fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value ); 267 return ( 0 );270 return 0; 268 271 } 269 272 conf->ping_timeout = i; … … 277 280 fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value ); 278 281 g_free( url ); 279 return ( 0 );282 return 0; 280 283 } 281 284 … … 293 296 g_free( url ); 294 297 } 298 else if( g_strcasecmp( ini->key, "user" ) == 0 ) 299 { 300 g_free( conf->user ); 301 conf->user = g_strdup( ini->value ); 302 } 295 303 else 296 304 { 297 305 fprintf( stderr, "Error: Unknown setting `%s` in configuration file.\n", ini->key ); 298 return ( 0 );306 return 0; 299 307 /* For now just ignore unknown keys... */ 300 308 } … … 304 312 fprintf( stderr, "Error: Unknown section [%s] in configuration file. " 305 313 "BitlBee configuration must be put in a [settings] section!\n", ini->section ); 306 return ( 0 );314 return 0; 307 315 } 308 316 } 309 317 ini_close( ini ); 310 318 311 return ( 1 );319 return 1; 312 320 } 313 321 … … 316 324 ini_t *ini; 317 325 318 ini = ini_open( CONF_FILE);326 ini = ini_open( global.conf_file ); 319 327 if( ini == NULL ) return; 320 328 while( ini_read( ini ) ) … … 322 330 if( g_strcasecmp( ini->section, "defaults" ) == 0 ) 323 331 { 324 set_t *s = set_find( irc, ini->key );332 set_t *s = set_find( &irc->set, ini->key ); 325 333 326 334 if( s )
Note: See TracChangeset
for help on using the changeset viewer.