#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;
-
- if (!f.exists())
- {
- WriteMessage("Cannot load configuration file!");sleep(2);exit(3);
+ /* 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);
+
+ AppConfiguration config(fname);
+
+ NodeNumber = config.getInt("node_number");
+ if (config.error() == TRUE) {
+ config.release();
+ exit(3);
+ }
+
+ ConType = (strcmp("explicit", config.getString("type")) == 0) ? 1 : 2;
+ config.error();
+
+ char host[255];
+ strcpy(host, config.getString("host"));//FIXME: buffer overflow
+ if (config.error() == FALSE) {
+ ConnectList.append(new ConnectEntry(config.getString("host")));
+ }
+
+ strcpy(progdir, config.getString("progdir"));//FIXME: buffer overflow
+ config.error();
+
+ strcpy(HomeDir, config.getString("homedir"));//FIXME: buffer overflow
+ config.error();
+
+ config.release();
}
/* +++++++++++++++++++++++++++++++++++++++++++++++ */