#include #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; }