Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added network server files
[palacios.git] / misc / network_servers / vtl / config.cc
diff --git a/misc/network_servers/vtl/config.cc b/misc/network_servers/vtl/config.cc
new file mode 100644 (file)
index 0000000..f54d765
--- /dev/null
@@ -0,0 +1,43 @@
+#include "config.h"
+
+
+int read_config(string conf_file_name, config_t * config) {
+  fstream conf_file(conf_file_name.c_str(), ios::in);
+  char line[MAX_CONFIG_LINE_SIZE];
+
+  if (!conf_file.is_open()) {
+    return -1;
+  }
+
+  while ((conf_file.getline(line, MAX_CONFIG_LINE_SIZE))) {
+    string conf_line = line;
+    string tag;
+    string value;
+    int offset, ltrim_index, rtrim_index;
+
+    if (conf_line[0] == '#') {
+      continue;
+    }
+
+    offset = conf_line.find(":", 0);
+    tag = conf_line.substr(0,offset);
+
+    // kill white space
+    istringstream tag_stream(tag, istringstream::in);
+    tag_stream >> tag;
+
+    if (tag.empty()) {
+      continue;
+    }
+
+    // basic whitespace trimming, we assume that the config handlers will deal with 
+    // tokenizing and further formatting
+    value = conf_line.substr(offset + 1, conf_line.length() - offset);
+    ltrim_index = value.find_first_not_of(" \t");
+    rtrim_index = value.find_last_not_of(" \t");
+    value = value.substr(ltrim_index, (rtrim_index + 1) - ltrim_index);
+
+    (*config)[tag] = value;
+  }
+  return 0;
+}