summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-11-20 03:22:49 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-11-20 03:22:49 +0200
commit5869e779ee108a63b71798b50beee13ec2480d67 (patch)
tree91bcdbe6c8cbcd7efc0e14be94f50b662f6f2e72
parentd542d536369c8191afcc9f63171236e6ce28d398 (diff)
Parsing firewall rules
-rw-r--r--client/Config.cpp60
-rw-r--r--client/Config.h11
-rw-r--r--client/UpdatedConfig.cpp2
3 files changed, 63 insertions, 10 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);
+ }
}
diff --git a/client/Config.h b/client/Config.h
index 091bec2..bf75930 100644
--- a/client/Config.h
+++ b/client/Config.h
@@ -22,18 +22,23 @@ public:
class FirewallEntry
{
public:
- FirewallEntry(): block(false), host("127.0.0.1")
- {
- }
+ FirewallEntry(): block(false), host("127.0.0.1") {}
+
/**
* @brief Firewall action: true - to block access to the host,
* false - to allow access to the host
*/
bool block;
+
/**
* @brief Hostname or address to allow/block access to
*/
string host;
+
+ /**
+ * @brief Extract and set instance variables from config line
+ */
+ void Parse(string entry);
};
/**
diff --git a/client/UpdatedConfig.cpp b/client/UpdatedConfig.cpp
index bcd0cd7..04b8a86 100644
--- a/client/UpdatedConfig.cpp
+++ b/client/UpdatedConfig.cpp
@@ -98,7 +98,7 @@ void UpdatedConfig::gotServerReply(SslClient::RequestType &type, QByteArray &con
goto end;
}
- Logger::Debug("data: %s\n", confdata.constData());
+ //Logger::Debug("data: %s\n", confdata.constData());
/* stop timer - working server found */
configUpdateTimer->stop();