summaryrefslogtreecommitdiff
path: root/client/Config.cpp
diff options
context:
space:
mode:
authorAlex <b0ris@b0ris-satellite.localdomain>2011-11-04 03:02:16 +0200
committerAlex <b0ris@b0ris-satellite.localdomain>2011-11-04 03:02:16 +0200
commitb7e0b79e7ce53bf467b1bcb8d60e86fac509f776 (patch)
tree8c239c3b5a0f6833ae75618fd15414682631a019 /client/Config.cpp
parentfb6fef711742bf92f4812ea70423f19443049df0 (diff)
config.cfg parser
Diffstat (limited to 'client/Config.cpp')
-rw-r--r--client/Config.cpp98
1 files changed, 94 insertions, 4 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
index b3c66a4..429d615 100644
--- a/client/Config.cpp
+++ b/client/Config.cpp
@@ -1,13 +1,12 @@
#include <algorithm>
#include <fstream>
-#include "client.h"
+#include <sstream>
+#include <stdlib.h>
#include "Config.h"
-#include "Proxy.h"
using namespace std;
-
Config* Config::self = NULL;
Config *Config::CurrentConfig()
@@ -19,6 +18,74 @@ Config *Config::CurrentConfig()
Config::Config(): StaticProxySpeedLow(50), configValid(0)
{
+ Logger::Info("Parsing config.cfg to determine initial configuration\n");
+ ifstream configFile("config.cfg", std::ios::in);
+ if (!configFile)
+ {
+ Logger::Fatal("Can't open file: config.cfg\n");
+ return;
+ }
+
+ const int str_size = 512;
+ char str[str_size] = {0};
+ while (!configFile.eof())
+ {
+ configFile.getline(str, str_size, ';');
+ configFile.ignore(2, '\n');
+ if (configFile.eof())
+ break;
+ string entry = str;
+ size_t eqpos = entry.find('=');
+ if (eqpos == string::npos)
+ {
+ Logger::Warn("No '=' at the config line: %s\n", entry.c_str());
+ continue;
+ }
+ string key = entry.substr(0, eqpos);
+ string value = entry.substr(eqpos+1);
+ Logger::Trace("Found option: %s = %s\n", key.c_str(), value.c_str());
+ if (key.compare("config_update_interval") == 0)
+ {
+ updateInterval = atoi(value.c_str());
+ }
+ else if (key.compare("client_update_interval") == 0)
+ {
+ ClientUpdateInterval = atoi(value.c_str());
+ }
+ else if (key.compare("server") == 0)
+ {
+ ServerEntry server(value);
+ servers.push_back(server);
+ }
+ else if (key.compare("welcome_msg") == 0)
+ {
+ WelcomeMsg = value;
+ }
+ else if (key.compare("config_downloaded_msg") == 0)
+ {
+ ConfigLoadedMsg = value;
+ }
+ else if (key.compare("top_panel_text") == 0)
+ {
+ TopPanelText = value;
+ }
+ else if (key.compare("bottom_panel_text") == 0)
+ {
+ BottomPanelText = value;
+ }
+ else if (key.compare("speed_visibility") == 0)
+ {
+ IsSpeedVisible = false;
+ if (value.compare("true"))
+ {
+ IsSpeedVisible = true;
+ }
+ }
+ else
+ {
+ Logger::Warn("Unrecognized config option: %s\n", key.c_str());
+ }
+ }
}
void Config::AcquireConfig()
@@ -138,7 +205,6 @@ vector<ProxyEntryStatic> Config::GetStaticProxyGuiLine(unsigned line)
swap(staticProxyLine[j], staticProxyLine[j-1]);
}
}
-
return staticProxyLine;
}
@@ -207,4 +273,28 @@ int Config::ReadStaticProxy()
}
proxyFile.close();
return 0;
+}
+
+
+/***
+ * Nested class section
+ */
+Config::ServerEntry::ServerEntry(): host("127.0.0.1"), timeout(120), retry(60)
+{
+}
+
+Config::ServerEntry::ServerEntry(string entry)
+{
+ ServerEntry();
+
+ /* processing string: "8.8.8.8 600 60" */
+ size_t start = 0, end = 0;
+ end = entry.find(' ');
+ host = entry.substr(start, end);
+ start = end+1;
+ end = entry.find(' ');
+ timeout = atoi(entry.substr(start, end).c_str());
+ start = end+1;
+ end = entry.find(' ');
+ retry = atoi(entry.substr(start, end).c_str());
} \ No newline at end of file