From d3ff62b1eeaba12131226a277b56abd15b015bda Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Thu, 20 Oct 2011 05:35:36 +0300 Subject: proxy representation classes --- client/proxy.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 client/proxy.cpp (limited to 'client/proxy.cpp') 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 +#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 -- cgit v1.2.3