FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
bool FB::Npapi::NpapiBrowserHost::DetectProxySettings ( std::map< std::string, std::string > &  settingsMap,
const std::string &  url = "" 
)
virtual

Detects the proxy settings from the browser.

This will detect the proxy settings for a given URL from the web browser; in the case that The web browser itself is not being forthcoming with proxy settings (i.e. older versions of npapi browsers dont' support it) it will fall back to system proxy settings detection.

settingsMap keys:

  • type - the type of proxy, will be one of: socks, http, https, ftp
  • hostname - hostname or address of the proxy
  • port - port of the proxy
Parameters
settingsMap(out) populated with the proxy settings in a key => value format
urlthe url for which you need proxy settings. Omit for the default proxy
Since
1.6

Reimplemented from FB::BrowserHost.

Definition at line 804 of file NpapiBrowserHost.cpp.

References FB::BrowserHost::DetectProxySettings(), and FB::URI::fromString().

805 {
806  char* retVal;
807  uint32_t len;
808  NPError err = GetValueForURL(NPNURLVProxy, URL.c_str(), &retVal, &len);
809  if (err != NPERR_NO_ERROR) {
810  // Only fall back to system proxy detection if NPAPI's API isn't supported on this browser
811  if (err == NPERR_INCOMPATIBLE_VERSION_ERROR)
812  return FB::BrowserHost::DetectProxySettings(settingsMap, URL);
813  else
814  return false;
815  }
816  std::string res(retVal, len);
817  MemFree(retVal);
818 
819  if (res == "DIRECT") {
820  return false;
821  } else {
822  settingsMap.clear();
823  vector<string> params;
824  // Chrome returns the whole proxy list string,
825  // squashing any space symbols between two consecutive proxies,
826  // thus we need semicolon as a separator also:
827  split(params, res, is_any_of(" ;"));
828  vector<string> host;
829  split(host, params[1], is_any_of(":"));
830  if (params[0] == "PROXY") {
831  FB::URI uri = FB::URI::fromString(URL);
832  settingsMap["type"] = uri.protocol;
833  } else if(params[0] == "SOCKS" ||
834  params[0] == "SOCKS5") {
835  settingsMap["type"] = "socks";
836  } else {
837  settingsMap["type"] = params[0];
838  }
839  settingsMap["hostname"] = host[0];
840  settingsMap["port"] = host[1];
841  return true;
842  }
843 }
static URI fromString(const std::string &in_str)
Returns a URI object from the given string.
Definition: URI.cpp:90
virtual bool DetectProxySettings(std::map< std::string, std::string > &settingsMap, const std::string &url="")
Detects the proxy settings from the browser.
Data structure for dealing with URI strings.
Definition: URI.h:42

Here is the call graph for this function: