diff options
Diffstat (limited to 'client/proxy.cpp')
-rw-r--r-- | client/proxy.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/client/proxy.cpp b/client/proxy.cpp new file mode 100644 index 0000000..1857231 --- /dev/null +++ b/client/proxy.cpp @@ -0,0 +1,79 @@ + +#include <stdlib.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) +{ + login.clear(); + password.clear(); + host.clear(); + + size_t lp1 = 0, lp2 = 0; + int port = 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 ProxyEntry::Parse(std::string entry) +{ + 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) +{ + +} +
\ No newline at end of file |