diff options
author | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-11-20 03:22:49 +0200 |
---|---|---|
committer | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-11-20 03:22:49 +0200 |
commit | 5869e779ee108a63b71798b50beee13ec2480d67 (patch) | |
tree | 91bcdbe6c8cbcd7efc0e14be94f50b662f6f2e72 /client/Config.cpp | |
parent | d542d536369c8191afcc9f63171236e6ce28d398 (diff) |
Parsing firewall rules
Diffstat (limited to 'client/Config.cpp')
-rw-r--r-- | client/Config.cpp | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/client/Config.cpp b/client/Config.cpp index abf090a..a4a6c07 100644 --- a/client/Config.cpp +++ b/client/Config.cpp @@ -10,6 +10,39 @@ using namespace std; +/* + * Firewall Entry class + */ +void Config::FirewallEntry::Parse(string entry) +{ + Logger::Trace("Parsing firewall string: %s\n", entry.c_str()); + + size_t lp1 = 0, lp2 = 0; + //extract action part + lp2 = entry.find(" ", lp1); + string action = entry.substr(lp1, lp2-lp1); + if (action.compare("block") == 0) + { + block = true; + } + else if (action.compare("allow") == 0) + { + block = false; + } + else + { + Logger::Error("Unknown firewall action! Skipping.\n"); + return; + } + //extract host part + lp1 = lp2 + 1; + host.clear(); + host = entry.substr(lp1); +} + +/* + * Config class + */ Config::Config(): StaticProxySpeedLow(50) { Logger::Info("Parsing config.cfg to determine initial configuration\n"); @@ -240,9 +273,9 @@ void Config::ParseGenericProxies(string data) if (proxies.eof()) break; string entry = str; - ProxyEntryGeneric *proxy = new ProxyEntryGeneric; - proxy->Parse(entry); - genericProxy.push_back(*proxy); + ProxyEntryGeneric proxy; + proxy.Parse(entry); + genericProxy.push_back(proxy); } } @@ -261,15 +294,30 @@ void Config::ParseStaticPorxies(string data) if (proxies.eof()) break; string entry = str; - ProxyEntryStatic *proxy = new ProxyEntryStatic; - proxy->Parse(entry); - staticProxy.push_back(*proxy); + ProxyEntryStatic proxy; + proxy.Parse(entry); + staticProxy.push_back(proxy); } } void Config::ParseFirewalls(string data) { + firewalls.clear(); + stringstream rules(data, ios_base::in); + const int str_size = 512; + char str[str_size] = {0}; + while (! rules.eof()) + { + rules.getline(str, str_size, ';'); + rules.ignore(2, '\n'); + if (rules.eof()) + break; + string entry = str; + FirewallEntry rule; + rule.Parse(entry); + firewalls.push_back(rule); + } } |