#include "socu.h"
#include <netinet/in.h>
+#include <libconfig.h>
+#include "AppConfiguration.h"
+
#define GPATH "loggr"
#define IPATH "logi"
#define NPATH "logn"
bool info_messages;
- void LoadConfig();
+ void LoadConfig(char *);
void RunGraphModule(char*);
void RunNetModule();
InterpEntry *findINTbySocket(int);
freeINTid = 1;
ActiveConnections = 0;
strcpy(LockPasswd,"");
- LoadConfig();
+ LoadConfig("vlp.cfg");
RunNetModule();
Net_Notify = new QSocketNotifier(net_sock,QSocketNotifier::Read,this);
/* ########### load configuration from file ############# */
-void QKernel::LoadConfig()
+void QKernel::LoadConfig(char * fname)
{
-QFile f("vlp.cfg");
- QString line;
- QString val;
- int br=0;
+ config_t cfg;
+ const char *str;
- if (!f.exists())
- {
- WriteMessage("Cannot load configuration file!");sleep(2);exit(3);
+ config_init(&cfg);
+
+ /* Hack for checking if file exists without using external libs.*/
+ FILE * file = fopen(fname, "r");
+ if (!file) {
+ fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname);
+ exit(3);
}
- f.open(IO_ReadOnly);
- br = f.readLine(line,256);
- while (br>0)
- {
- QStringList l = QStringList::split("=",line,FALSE);
- QStringList::Iterator it = l.begin();
- line = *it;
- ++it;
- val = *it;
- val = val.stripWhiteSpace();
- if (line == "node_number") {NodeNumber = val.toInt();};
- if (line == "type") {if (val=="explicit") ConType=1; else
- ConType = 2; };
- if (line == "host" ) {ConnectList.append(new ConnectEntry((char*)val.ascii()));};
- if (line == "progdir") { strcpy(progdir,val.ascii());};
- if (line == "homedir") { strcpy(HomeDir,val.ascii());};
- br = f.readLine(line,256);
- }
- f.close();
+ /* 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);
+ }
+
+ if(config_lookup_string(&cfg, "type", &str)){
+ ConType = (strcmp(str, "explicit") == 0) ? 1 : 2;
+ }
+ else {
+ AppConfiguration::error(&cfg);
+ }
+
+
+ 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);
+ }
+
+ if(config_lookup_string(&cfg, "progdir", &str)){
+ strcpy(progdir, str);//FIXME: buffer overflow
+ }
+ else {
+ AppConfiguration::error(&cfg);
+ }
+
+ if(config_lookup_string(&cfg, "homedir", &str)){
+ strcpy(HomeDir, str);//FIXME: buffer overflow
+ }
+ else {
+ AppConfiguration::error(&cfg);
+ }
+
+ config_destroy(&cfg);
}
/* +++++++++++++++++++++++++++++++++++++++++++++++ */