#include #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()); }