summaryrefslogtreecommitdiff
path: root/client/Config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/Config.cpp')
-rw-r--r--client/Config.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/client/Config.cpp b/client/Config.cpp
new file mode 100644
index 0000000..472fdf4
--- /dev/null
+++ b/client/Config.cpp
@@ -0,0 +1,91 @@
+
+#include <fstream>
+#include "client.h"
+#include "Config.h"
+#include "Proxy.h"
+
+using namespace std;
+
+
+Config* Config::self = NULL;
+
+Config *Config::CurrentConfig()
+{
+ if (self == NULL)
+ self = new Config();
+ return self;
+}
+
+Config::Config(): configValid(0)
+{
+}
+
+void Config::AcquireConfig()
+{
+ configValid = false;
+ if (ReadGenericProxy())
+ return ;
+ if (ReadStaticProxy())
+ return ;
+ configValid = true;
+}
+
+bool Config::IsConfigValid()
+{
+ return configValid;
+}
+
+
+int Config::ReadGenericProxy()
+{
+ Logger::Info("Parsing generic proxy list\n");
+
+ ifstream proxyFile("./config/proxy_list.cfg", std::ios::in);
+ if (!proxyFile)
+ {
+ Logger::Error("Can't open file ./config/proxy_list.cfg");
+ return -1;
+ }
+
+ const int str_size = 512;
+ char str[str_size] = {0};
+ while (!proxyFile.eof())
+ {
+ proxyFile.getline(str, str_size, ';');
+ if (proxyFile.eof())
+ break;
+ string entry = str;
+ ProxyEntryGeneric *proxy = new ProxyEntryGeneric;
+ proxy->Parse(entry);
+ genericProxy.push_back(*proxy);
+ }
+ proxyFile.close();
+ return 0;
+}
+
+int Config::ReadStaticProxy()
+{
+ Logger::Info("Parsing static proxy list\n");
+
+ ifstream proxyFile("./config/static_proxy_list.cfg", std::ios::in);
+ if (!proxyFile)
+ {
+ Logger::Error("Can't open file ./config/static_proxy_list.cfg\n");
+ return -1;
+ }
+
+ const int str_size = 512;
+ char str[str_size] = {0};
+ while (!proxyFile.eof())
+ {
+ proxyFile.getline(str, str_size, ';');
+ if (proxyFile.eof())
+ break;
+ string entry = str;
+ ProxyEntryStatic *proxy = new ProxyEntryStatic;
+ proxy->Parse(entry);
+ staticProxy.push_back(*proxy);
+ }
+ proxyFile.close();
+ return 0;
+} \ No newline at end of file