void QKernel::LoadConfig(char * fname)
{
- config_t cfg;
- const char *str;
-
- config_init(&cfg);
-
/* Hack for checking if file exists without using external libs.*/
FILE * file = fopen(fname, "r");
if (!file) {
/* File exists, so file has been locked. Release it. */
fclose(file);
- /* Read the file. If there is an error, report it and exit. */
- if(!config_read_file(&cfg, fname))
- {
- AppConfiguration::error(&cfg);
- config_destroy(&cfg);
- exit(3);/* from original code. */
- }
-
- if(!config_lookup_int(&cfg, "node_number", &NodeNumber))
- {
- AppConfiguration::error(&cfg);
- config_destroy(&cfg);
- exit(3);
- }
+ AppConfiguration config(fname);
- if(config_lookup_string(&cfg, "type", &str)){
- ConType = (strcmp(str, "explicit") == 0) ? 1 : 2;
- }
- else {
- AppConfiguration::error(&cfg);
+ NodeNumber = config.getInt("node_number");
+ if (config.error() == TRUE) {
+ config.release();
+ exit(3);
}
+ ConType = (strcmp("explicit", config.getString("type")) == 0) ? 1 : 2;
+ config.error();
- if(config_lookup_string(&cfg, "host", &str)) {
- char host[255];
- strcpy(host, str);//FIXME: buffer overflow
- ConnectList.append(new ConnectEntry(host));
- }
- else {
- AppConfiguration::error(&cfg);
+ char host[255];
+ strcpy(host, config.getString("host"));//FIXME: buffer overflow
+ if (config.error() == FALSE) {
+ ConnectList.append(new ConnectEntry(config.getString("host")));
}
- if(config_lookup_string(&cfg, "progdir", &str)){
- strcpy(progdir, str);//FIXME: buffer overflow
- }
- else {
- AppConfiguration::error(&cfg);
- }
+ strcpy(progdir, config.getString("progdir"));//FIXME: buffer overflow
+ config.error();
- if(config_lookup_string(&cfg, "homedir", &str)){
- strcpy(HomeDir, str);//FIXME: buffer overflow
- }
- else {
- AppConfiguration::error(&cfg);
- }
+ strcpy(HomeDir, config.getString("homedir"));//FIXME: buffer overflow
+ config.error();
- config_destroy(&cfg);
+ config.release();
}
/* +++++++++++++++++++++++++++++++++++++++++++++++ */