diff options
author | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-10-23 04:10:55 +0300 |
---|---|---|
committer | Alex Borisov <borisov.alexandr@rambler.ru> | 2011-10-23 04:10:55 +0300 |
commit | 21ad7eac963bc329395fa893300fb5c8f721fd77 (patch) | |
tree | 10dda6e6170071332aab490faeeb599f10ff6e03 /client/Proxy.cpp | |
parent | 3eef0376635624c354a5e1b8a2680b74eb23a423 (diff) |
Logging facility, Config class, tray icon, custom QApplication subclass
Diffstat (limited to 'client/Proxy.cpp')
-rw-r--r-- | client/Proxy.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/client/Proxy.cpp b/client/Proxy.cpp new file mode 100644 index 0000000..46a580e --- /dev/null +++ b/client/Proxy.cpp @@ -0,0 +1,102 @@ + +#include <stdlib.h> +#include "client.h" +#include "Proxy.h" + +/************************************** + * Proxy methods + **************************************/ + +// +// Parse proxy string and set calss members according to it's contents +// Some examples: +// user:password@server.com:1234 +// server.com:1234 +void Proxy::Parse(std::string entry) +{ + Logger::Trace("Parsing proxy string: %s\n", entry.c_str()); + + login.clear(); + password.clear(); + host.clear(); + + size_t lp1 = 0, lp2 = 0; + if(entry.find('@') != std::string::npos) + { + lp2 = entry.find(':', lp1); + login = entry.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = entry.find('@', lp1); + password = entry.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = entry.find(':', lp1); + host = entry.substr(lp1, lp2-lp1); + lp1 = lp2+1; + port = atoi(entry.substr(lp1).c_str()); + } + else + { + lp2 = entry.find(':', lp1); + host = entry.substr(lp1, lp2-lp1); + lp1 = lp2+1; + port = atoi(entry.substr(lp1).c_str()); + } +} + + +/************************************** + * ProxyEntry methods + **************************************/ +void ProxyEntryGeneric::Parse(std::string entry) +{ + Logger::Trace("Parsing generic proxy string: %s\n", entry.c_str()); + + country.clear(); + state.clear(); + city.clear(); + + size_t lp1 = 0, lp2 = 0; + //extract Proxy part + lp2 = entry.find(" ", lp1); + std::string proxy = entry.substr(lp1, lp2-lp1); + Proxy::Parse(proxy); + // extract country, city and state + lp1 = lp2+2; + lp2 = entry.find('"', lp1); + country = entry.substr(lp1, lp2-lp1); + lp1 = lp2+3; + lp2 = entry.find('"', lp1); + state = entry.substr(lp1, lp2-lp1); + lp1 = lp2+3; + lp2 = entry.find('"', lp1); + city = entry.substr(lp1, lp2-lp1); +} + + +/************************************** + * StaticProxyEntry methods + **************************************/ +void ProxyEntryStatic::Parse(std::string entry) +{ + Logger::Trace("Parsing static proxy string: %s\n", entry.c_str()); + + name.clear(); + size_t lp1 = 0, lp2 = 0; + //extract Proxy part + lp2 = entry.find(" ", lp1); + std::string proxy = entry.substr(lp1, lp2-lp1); + Proxy::Parse(proxy); + + //estract name, position and speed + lp1 = lp2+2; + lp2 = entry.find('"', lp1); + name = entry.substr(lp1, lp2-lp1); + + lp1 = lp2+2; + lp2 = entry.find(" ", lp1); + position = atoi(entry.substr(lp1, lp2-lp1).c_str()); + + lp1 = lp2+1; + speed = atoi(entry.substr(lp1).c_str()); +} +
\ No newline at end of file |