Пример #1
0
// Finds proxy for the given PAC file, url and host.
//
// This function is a wrapper around functions pacparser_init,
// pacparser_parse_pac, pacparser_find_proxy and pacparser_cleanup. If you just
// want to find out proxy a given set of pac file, url and host, this is the
// function to call.
char *                                  // Proxy string or NULL if failed.
pacparser_just_find_proxy(const char *pacfile,
                         const char *url,
                         const char *host)
{
  char *proxy;
  char *out;
  int initialized_here = 0;
  char *error_prefix = "pacparser.c: pacparser_just_find_proxy:";
  if (!global) {
    if (!pacparser_init()) {
      print_error("%s %s\n", error_prefix, "Could not initialize pacparser");
      return NULL;
    }
    initialized_here = 1;
  }
  if (!pacparser_parse_pac(pacfile)) {
    print_error("%s %s %s\n", error_prefix, "Could not parse pacfile",
		  pacfile);
    if (initialized_here) pacparser_cleanup();
    return NULL;
  }
  if (!(out = pacparser_find_proxy(url, host))) {
    print_error("%s %s %s\n", error_prefix,
		  "Could not determine proxy for url", url);
    if (initialized_here) pacparser_cleanup();
    return NULL;
  }
  proxy = (char*) malloc(strlen(out) + 1);
  strcpy(proxy, out);
  if (initialized_here) pacparser_cleanup();
  return proxy;
}
Пример #2
0
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;
}