vector<url> get_config(const url &dst) throw (runtime_error) { map<string,string>::const_iterator it = _data.find("PROXY_ENABLED"); vector<url> response; if (it != _data.end() && it->second == "no") { response.push_back(url("direct://")); return response; } string key; string proxy; // If the URL is an ftp url, try to read the ftp proxy if (dst.get_scheme() == "ftp") key = "FTP_PROXY"; else if (dst.get_scheme() == "http") key = "HTTP_PROXY"; else if (dst.get_scheme() == "https") key = "HTTPS_PROXY"; it = _data.find(key); if (it != _data.end()) proxy = it->second; if (proxy.empty()) throw runtime_error("Unable to read configuration"); response.push_back(url(proxy)); return response; }
vector<url> get_config(const url &dest) throw (runtime_error) { // Check for changes in the config fd_set rfds; struct timeval timeout = { 0, 0 }; vector<url> response; FD_ZERO(&rfds); FD_SET(fileno(this->read), &rfds); if (select(fileno(this->read)+1, &rfds, NULL, NULL, &timeout) > 0) this->read_data(); // Mode is wpad:// or pac+http://... if (this->data[PROXY_MODE] == "auto") { string pac = this->data[PROXY_AUTOCONFIG_URL]; response.push_back(url::is_valid(pac) ? url(string("pac+") + pac) : url("wpad://")); return response; } // Mode is http://... or socks://... else if (this->data[PROXY_MODE] == "manual") { bool auth = this->data[PROXY_USE_AUTHENTICATION] == "true"; string username = url::encode(this->data[PROXY_AUTH_USER], URL_ALLOWED_IN_USERINFO_ELEMENT); string password = url::encode(this->data[PROXY_AUTH_PASSWORD], URL_ALLOWED_IN_USERINFO_ELEMENT); // Get the per-scheme proxy settings if (dest.get_scheme() == "http") store_response("http", this->data[PROXY_HTTP_HOST], this->data[PROXY_HTTP_PORT], auth, username, password, response); else if (dest.get_scheme() == "https") // It is expected that the configured server is an // HTTP server that support CONNECT method. store_response("http", this->data[PROXY_SECURE_HOST], this->data[PROXY_SECURE_PORT], auth, username, password, response); else if (dest.get_scheme() == "ftp") // It is expected that the configured server is an // HTTP server that handles proxying FTP URLs // (e.g. request with header "Host: ftp://ftp.host.org") store_response("http", this->data[PROXY_FTP_HOST], this->data[PROXY_FTP_PORT], auth, username, password, response); store_response("socks", this->data[PROXY_SOCKS_HOST], this->data[PROXY_SOCKS_PORT], auth, username, password, response); // In case nothing matched, try HTTP Connect and fallback to direct. // If there is not secure HTTP proxy, this will only add direct:// to // the response if (response.size() == 0 && dest.get_scheme() != "http") { store_response("http", this->data[PROXY_SECURE_HOST], this->data[PROXY_SECURE_PORT], auth, username, password, response); response.push_back(url("direct://")); } } return response; }