QString ProxyScout::handleRequest(const KURL &url) { try { QString result = m_script->evaluate(url); QStringList proxies = QStringList::split(';', result); for(QStringList::ConstIterator it = proxies.begin(); it != proxies.end(); ++it) { QString proxy = (*it).stripWhiteSpace(); if(proxy.left(5) == "PROXY") { KURL proxyURL(proxy = proxy.mid(5).stripWhiteSpace()); // If the URL is invalid or the URL is valid but in opaque // format which indicates a port number being present in // this particular case, simply calling setProtocol() on // it trashes the whole URL. int len = proxyURL.protocol().length(); if(!proxyURL.isValid() || proxy.find(":/", len) != len) proxy.prepend("http://"); BlackList::Iterator it = m_blackList.find(proxy); if(it == m_blackList.end()) return proxy; else if(std::time(0) - *it > 1800) // 30 minutes { // black listing expired m_blackList.remove(it); return proxy; } } else return "DIRECT"; } // FIXME: blacklist } catch(const Script::Error &e) { KNotifyClient::Instance notifyInstance(m_instance); KNotifyClient::event("evaluation-error", i18n("The proxy configuration script returned an error:\n%1").arg(e.message())); } return "DIRECT"; }
std::string DimdimHelpers::ParsePACFile(std::string filePath, std::string url) { // filePath is the location of PAC File in %APPDATA% // Assuming that url is of the form http://ip:port/screenshare/.... pacparser_init(); char *proxy = NULL; pacparser_parse_pac(filePath.c_str()); std::string host(url); host.assign(host.substr(7, host.length())); host.assign(host.substr(0, host.find_first_of('/'))); proxy = pacparser_find_proxy(url.c_str(), host.c_str()); std::string proxyURL(""); if(proxy) { proxyURL.assign(proxy); } pacparser_cleanup(); return proxyURL; }