pacparser is a C library to parse PAC (proxy auto-config) files. PAC files (implemented in JavaScript) are a proxy configuration method for web access. Using them, browsers can be configured to use different proxy servers for different URLs, source IP addresses, protocols etc. PAC files can also be used for a highly available proxy setup as you can specify more than one proxy server using them.
Needless to say, PAC files are now a widely accepted method for proxy configuration management and almost all popular browsers support them. The idea behind pacparser is to make it easy to add this PAC file parsing capability to other programs. The pacparser project comes as a shared C library with a clear API. You can use it to make any C or python (using ctypes) program PAC scripts intelligent. Some very useful targets could be popular web software like wget, curl and python-urllib.
Usage Examples:
Using it with python-ctypes:
>>> from ctypes import *
>>> pp=CDLL('./libpacparser.so')
>>> pp.pacparser_init()
1
>>> pp.pacparser_parse_pac('examples/wpad.dat')
1
>>> pp.pacparser_find_proxy('http://www.google.com', 'www.google.com')
136307304
>>> string_at(136307304)
'PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT'
>>> pp.pacparser_cleanup()
>>>
Using it in C:
manugarg@hobbiton:~$ cat pactest.c
#include
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;
pacparser_init();
pacparser_parse_pac(argv[1]);
proxy = pacparser_find_proxy(argv[2], argv[3]);
printf("%sn", proxy);
pacparser_cleanup();
}
manugarg@hobbiton:~$ gcc -o pactest pactest.c -lpacparser
manugarg@hobbiton:~$ ./pactest wpad.dat http://www.google.com www.google.com
PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT
Product's homepage
What's New in This Release: [ read full changelog ]
· This version adds a feature to pacparser to allow working with the proxy auto-config (PAC) script directly (in string form) instead of requiring it to be in a file.
· This release also adds a feature to pactester to read pac files from stdin directly, which will allow users to "pipe" pac files to pactester directly from the other programs like curl.
· This release also has some build fixes to make pacparser build on non-Linux GNU systems like kFreeBSD and GNU Hurd.