pacparser  1.3.7
About: pacparser is a library to parse Proxy Auto-Config (PAC) files (incl. a pactester).
  Fossies Dox: pacparser-1.3.7.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

pacparser Documentation

Some Fossies usage hints in advance:

  1. To see the Doxygen generated documentation please click on one of the items in the steelblue colored "quick index" bar above or use the side panel at the left which displays a hierarchical tree-like index structure and is adjustable in width.
  2. If you want to search for something by keyword rather than browse for it you can use the client side search facility (using Javascript and DHTML) that provides live searching, i.e. the search results are presented and adapted as you type in the Search input field at the top right.
  3. Doxygen doesn't incorporate all member files but just a definable subset (basically the main project source code files that are written in a supported language). So to search and browse all member files you may visit the Fossies
  4. pacparser-1.3.7.tar.gz contents page and use the Fossies standard member browsing features (also with source code highlighting and additionally with optional code folding).


pacparser is a library to parse proxy auto-config (PAC) files. Proxy auto-config files are a vastly used proxy configuration method these days. Web browsers can use a PAC file to determine which proxy server to use or whether to go direct for a given URL. PAC files are written in JavaScript and can be programmed to return different proxy methods (e.g., "PROXY proxy1:port; DIRECT") depending upon URL, source IP address, protocol, time of the day etc. PAC files introduce a lot of possibilities. Please look at the wikipedia entry for Proxy auto-config ( for more information.

Needless to say, PAC files are now a widely accepted method for proxy configuration management and companies all over are using them in corporate environment. Almost all popular web browsers support PAC files. The idea behind pacparser is to make it easy to add this PAC file parsing capability to any program (C and python supported right now). It comes as a shared C library and a python module which can be used to make any C or python program PAC scripts intelligent. Some very useful targets could be popular web software like wget, curl and python-urllib.


pacparser makes use of Mozilla's JavaScript interpreter SpiderMonkey to parse PAC files (which are nothing but javascripts). Apart from that, proxy auto-config standard assumes availability of some functions which are not part of standard JavaScript. pacparser uses Mozilla's PAC implementation to define all these functions except couple of dns functions which are defined by pacparser itself. As a result, pacparser is as close to standard as it gets :)


Please see 'INSTALL' in the root directory of the package.

How to use it?

Pacparser comes as a shared library ( on Unix-like systems and pacparser.dll on windows) as well as a python module. Using it is as easy compiling your C programs against it or importing pacparser module in your python programs.

Usage Examples


>>> import pacparser
>>> pacparser.init()
>>> pacparser.parse_pac('examples/wpad.dat')
>>> pacparser.find_proxy('', '')
>>> pacparser.setmyip("")
>>> pacparser.find_proxy('', '')
>>> pacparser.find_proxy('', '')
>>> pacparser.cleanup()


#include <stdio.h>

int pacparser_init();
int pacparser_parse_pac(char* pacfile);
char *pacparser_find_proxy(char *url, char *host);
void pacparser_cleanup();

int main(int argc, char* argv[])
  char *proxy;
  proxy = pacparser_find_proxy(argv[2], argv[3]);
  printf("%s\n", proxy);
manugarg@hobbiton:~$ gcc -o pactest pactest.c -lpacparser
manugarg@hobbiton:~$ ./pactest wpad.dat


pacparser has been tested to work on Linux (all architectures supported by Debian), Mac OS X and Win32 systems.


Author: Manu Garg
Copyright (C) 2007 Manu Garg. Copyright (C) 2015 Google, Inc.

int pacparser_parse_pac(const char *pacfile)
Parses the gievn pac file.
Definition: pacparser.c:398
int pacparser_init()
Initializes pac parser.
Definition: pacparser.c:288
void pacparser_cleanup()
Destroys JavaSctipt context.
Definition: pacparser.c:468
char * pacparser_find_proxy(const char *url, const char *host)
Finds proxy for the given URL and Host.
Definition: pacparser.c:409
int main(int argc, char *argv[])
Definition: pactester.c:85