Removed back AppConfiguration class. Postponed its implementation.
[vlp.git] / src / kernel / kernel.cpp
index 7e83ebc5ebfcdbb376b871811848bca9d2ee3125..3126480c8cf1f07f052f0feb639e101e15ace3db 100644 (file)
@@ -72,7 +72,6 @@
 #include <netinet/in.h>
 
 #include <libconfig.h>
-#include "AppConfiguration.h"
 
 #define GPATH "loggr"
 #define IPATH "logi"
@@ -297,8 +296,6 @@ 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) {
@@ -306,20 +303,29 @@ void QKernel::LoadConfig(char * fname)
     exit(3);
   }
   /* File exists, so file has been locked. Release it. */
-  fclose(file);
+  
+  config_init(&cfg);
   
   /* Read the file. If there is an error, report it and exit. */
-  if(!config_read_file(&cfg, fname)) 
+  if(!config_read(&cfg, file)) 
   {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, line %d\n",
+        config_error_text(&cfg),
+        config_error_file(&cfg),
+        config_error_line(&cfg));
     config_destroy(&cfg);
+    fclose(file);
     exit(3);/* from original code. */
   }
 
   if(!config_lookup_int(&cfg, "node_number", &NodeNumber))
   {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
+        "Warning",
+        fname,
+        "node_number");
     config_destroy(&cfg);
+    fclose(file);
     exit(3);
   }
   
@@ -327,34 +333,45 @@ void QKernel::LoadConfig(char * fname)
     ConType = (strcmp(str, "explicit") == 0) ? 1 : 2;
   }
   else {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
+        "Warning",
+        fname,
+        "type");
   }
   
   
   if(config_lookup_string(&cfg, "host", &str)) {
-    char host[255];
-    strcpy(host, str);//FIXME: buffer overflow
-    ConnectList.append(new ConnectEntry(host));
+    ConnectList.append(new ConnectEntry((char*)str));
   }
   else {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
+        "Warning",
+        fname,
+        "host");
   }
   
   if(config_lookup_string(&cfg, "progdir", &str)){
-    strcpy(progdir, str);//FIXME: buffer overflow
+    strncpy(progdir, str, 256);
   }
   else {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
+        "Warning",
+        fname,
+        "progdir");
   }
   
   if(config_lookup_string(&cfg, "homedir", &str)){
-    strcpy(HomeDir, str);//FIXME: buffer overflow
+    strncpy(HomeDir, str, 255);
   }
   else {
-    AppConfiguration::error(&cfg);
+    fprintf(stderr, "%s! In file %s, '%s' was not found.\n",
+        "Warning",
+        fname,
+        "homedir");
   }
   
   config_destroy(&cfg);
+  fclose(file);
 }
 /* +++++++++++++++++++++++++++++++++++++++++++++++ */