Copyright (C) 2007 Manu Garg.
pacparser-1.3.0/README.win32 0000664 0000000 0000000 00000004455 11632721722 0015327 0 ustar 00root root 0000000 0000000 This file is about the instructions to build (and use) pacparser on Windows.
For general information on pacparser, please have a look at README in the same
directory.
Building pacparser on Windows:
-----------------------------
For compiling pacparser on Windows, you'll need MinGW (www.mingw.org) tools.
Detailed Instructions:
----------------------
Set up tools:
1. Install MinGW. Download the automated installer from here:
http://sourceforge.net/projects/mingw/files/
Running this installer lets you select what component you want to install.
Apart from minimal MinGW, we'll need MinGW make. This will install all the
necessary files in C:\MinGW.
2. Add your MinGW directory's bin (C:\MinGW\bin) to your system path variable.
======== Done setting up tools ==========
3. Now download pacparser source code tarball from
http://code.google.com/p/pacparser/downloads/list and extract it somewhere,
say C:\workspace.
4. Now extract the spidermonekey source tarball, js-*.tar.gz, located at
src\spidermonkey\js-*.tar.gz inside the pacparser source directory.
5. Compile pacparser and create ditribution.
make -f Makefile.win32 dist
6. Compile pacparser python module and copy required files to a directory
(dist).
make -f Makefile.win32 pymod
make -f Makefile.win32 dist-pymod
Using pacparser on Windows:
--------------------------
* In C programs:
Make sure that you have pacparser.dll in the sytem path somewhere
(current directory would do just fine for testing purpose).
Change to your program's directory:
=> cd c:\workspace\pacparser-1.2.1\examples
Copy pacparser.dll here and compile your program:
=> gcc -o pactest pactest.c -lpacparser -L.
Run your program:
=> pactest wpad.dat http://www.google.com www.google.com
'PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT'
* In python programs:
Install pacparser python module by running install.py in the distribution
folder. You'll then be able to use pacparser python module in the following
manner:
=> C:\python25\python
>>> import pacparser
>>> pacparser.init()
>>> pacparser.parse_pac('examples/wpad.dat')
>>> pacparser.find_proxy('http://www.google.com', 'www.google.com')
'PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT'
>>> pacparser.cleanup()
pacparser-1.3.0/docs/ 0000775 0000000 0000000 00000000000 11632721722 0014426 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/docs/html/ 0000775 0000000 0000000 00000000000 11632721722 0015372 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/docs/html/pacparser_api.html 0000664 0000000 0000000 00000000442 11632721722 0021071 0 ustar 00root root 0000000 0000000
pacparser API
pacparser-1.3.0/docs/html/pacparser_api_content.html 0000664 0000000 0000000 00000000160 11632721722 0022620 0 ustar 00root root 0000000 0000000
Click on the function names in the left frame for function documentation.
pacparser-1.3.0/docs/html/pacparser_api_table.html 0000664 0000000 0000000 00000002002 11632721722 0022232 0 ustar 00root root 0000000 0000000
Pacparser API
pacparser-1.3.0/docs/html/pacparser_cleanup.3.html 0000664 0000000 0000000 00000003111 11632721722 0022104 0 ustar 00root root 0000000 0000000
"pacparser_cleanup"(3) manual page
Table of Contents
pacparser_cleanup - Destroys JavaSctipt context.
#include <pacparser.h>
void pacparser_cleanup(void);
This function should be called
once you’re done with using pacparser engine.
pacparser_version(3)
,
pacparser_init(3)
, pacparser_parse_pac_file(3)
, pacparser_parse_pac_string(3)
,
pacparser_parse_pac(3)
, pacparser_find_proxy(3)
, pacparser_just_find_proxy(3)
,
pacparser_setmyip(3)
, pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_enable_microsoft_extensions.3.html 0000664 0000000 0000000 00000003466 11632721722 0026264 0 ustar 00root root 0000000 0000000
"pacparser_enable_microsoft_extensions"(3) manual page
Table of Contents
pacparser_enable_microsoft_extensions - Enable Microsoft PAC extensions.
#include <pacparser.h>
void pacparser_enable_microsoft_extensions(void);
Enables a subset of Microsoft PAC extensions - dnsResolveEx,
myIpAddressEx, isResolvableEx. These functions are used by Google Chrome
and IE to work with IPv6. More info: http://code.google.com/p/pacparser/issues/detail?id=4.
pacparser_version(3)
, pacparser_init(3)
, pacparser_parse_pac_file(3)
,
pacparser_parse_pac_string(3)
, pacparser_parse_pac(3)
, pacparser_find_proxy(3)
,
pacparser_just_find_proxy(3)
, pacparser_cleanup(3)
, pacparser_setmyip(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_find_proxy.3.html 0000664 0000000 0000000 00000004371 11632721722 0022647 0 ustar 00root root 0000000 0000000
"pacparser_find_proxy"(3) manual page
Table of Contents
pacparser_find_proxy - Finds proxy for a given URL and Host.
#include
<pacparser.h>
char *pacparser_find_proxy
(
const char *url,
const char *host
);
- const char *url
- URL to find proxy for.
- const char *host
- Host
part of the URL.
Finds proxy for a given URL and Host. This function
should be called only after pacparser engine has been initialized (using
pacparser_init) and pac script has been parsed (using pacparser_parse_pac_file
or pacparser_parse_pac_string).
Proxy string on sucess and NULL on
error.
pacparser_version(3)
, pacparser_init(3)
, pacparser_parse_pac_file(3)
,
pacparser_parse_pac_string(3)
, pacparser_parse_pac(3)
, pacparser_just_find_proxy(3)
,
pacparser_cleanup(3)
, pacparser_setmyip(3)
, pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_init.3.html 0000664 0000000 0000000 00000003313 11632721722 0021424 0 ustar 00root root 0000000 0000000
"pacparser_init"(3) manual page
Table of Contents
pacparser_init - Initializes pac parser
#include <pacparser.h>
int pacparser_init(void);
It initializes JavaScript engine and
does few basic initializations specific to pacparser.
0 on failure
and 1 on success.
pacparser_version(3)
, pacparser_parse_pac_file(3)
,
pacparser_parse_pac_string(3)
, pacparser_parse_pac(3)
, pacparser_find_proxy(3)
,
pacparser_just_find_proxy(3)
, pacparser_cleanup(3)
, pacparser_setmyip(3)
,
pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_just_find_proxy.3.html 0000664 0000000 0000000 00000004700 11632721722 0023710 0 ustar 00root root 0000000 0000000
"pacparser_just_find_proxy"(3) manual page
Table of Contents
pacparser_just_find_proxy - Finds proxy for a given PAC file, url
and host.
#include <pacparser.h>
char *pacparser_just_find_proxy
(
const char *pacfile,
const char *url,
const char *host
);
- const char *pacfile
- PAC file.
- const char *url
- URL to find proxy
for.
- const char *host
- Host part of the URL.
This function is a
wrapper around functions pacparser_init, pacparser_parse_pac_file, 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. This function takes
care of all the initialization and cleanup.
Proxy string on success
and NULL on error.
pacparser_version(3)
, pacparser_init(3)
, pacparser_parse_pac_file(3)
,
pacparser_parse_pac_string(3)
, pacparser_parse_pac(3)
, pacparser_find_proxy(3)
,
pacparser_cleanup(3)
, pacparser_setmyip(3)
, pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_parse_pac.3.html 0000664 0000000 0000000 00000003660 11632721722 0022423 0 ustar 00root root 0000000 0000000
"pacparser_parse_pac"(3) manual page
Table of Contents
pacparser_parse_pac - Parses pac file (deprecated, use pacparser_parse_pac_file
instead)
#include <pacparser.h>
int pacparser_parse_pac(const char
*file);
- const char *file
- PAC file to parse.
Same as
pacparser_parse_pac_file. Included only for backward compatibility.
0
on failure and 1 on success.
pacparser_version(3)
, pacparser_init(3)
,
pacparser_parse_pac_file(3)
, pacparser_parse_pac_string(3)
, pacparser_find_proxy(3)
,
pacparser_just_find_proxy(3)
, pacparser_cleanup(3)
, pacparser_setmyip(3)
,
pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_parse_pac_file.3.html 0000664 0000000 0000000 00000003646 11632721722 0023426 0 ustar 00root root 0000000 0000000
"pacparser_parse_pac_file"(3) manual page
Table of Contents
pacparser_parse_pac_file - Parses the given PAC file.
#include
<pacparser.h>
int pacparser_parse_pac_file(const char *pacfile);
- const
char *pacfile
- PAC file to parse.
Reads the given PAC file and
evaluates it in the JavaScript context created by pacparser_init.
0
on failure and 1 on success.
pacparser_version(3)
, pacparser_init(3)
,
pacparser_parse_pac_string(3)
, pacparser_parse_pac(3)
, pacparser_find_proxy(3)
,
pacparser_just_find_proxy(3)
, pacparser_cleanup(3)
, pacparser_setmyip(3)
,
pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_parse_pac_string.3.html 0000664 0000000 0000000 00000003655 11632721722 0024015 0 ustar 00root root 0000000 0000000
"pacparser_parse_pac_string"(3) manual page
Table of Contents
pacparser_parse_pac_string - Parses the given PAC script string.
#include
<pacparser.h>
int pacparser_parse_pac_string(const char *string);
- const
char *string
- PAC string to parse.
Evaulates the given PAC script
string in the JavaScript context created by pacparser_init.
0 on
failure and 1 on success.
pacparser_version(3)
, pacparser_init(3)
,
pacparser_parse_pac_file(3)
, pacparser_parse_pac(3)
, pacparser_find_proxy(3)
,
pacparser_just_find_proxy(3)
, pacparser_cleanup(3)
, pacparser_setmyip(3)
,
pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pacparser_setmyip.3.html 0000664 0000000 0000000 00000003430 11632721722 0022153 0 ustar 00root root 0000000 0000000
"pacparser_setmyip"(3) manual page
Table of Contents
pacparser_setmyip - Sets my IP address.
#include <pacparser.h>
void pacparser_setmyip(const char *ip);
- const char *ip
- Custom
IP address.
Sets my IP address to a custom value. This is the
IP address returned by myIpAddress() javascript function.
pacparser_version(3)
,
pacparser_init(3)
, pacparser_parse_pac_file(3)
, pacparser_parse_pac_string(3)
,
pacparser_parse_pac(3)
, pacparser_find_proxy(3)
, pacparser_just_find_proxy(3)
,
pacparser_cleanup(3)
, pacparser_enable_microsoft_extensions(3)
Table of Contents
pacparser-1.3.0/docs/html/pactester.1.html 0000664 0000000 0000000 00000006321 11632721722 0020413 0 ustar 00root root 0000000 0000000
"pactester"("1") manual page
Table of Contents
pactester - Tool to test proxy auto-config (pac) files.
pactester
<-p pacfile> <-u url> [-h host] [-c client_ip] [-e]
pactester <-p pacfile> <-f urlslist>
[-c client_ip] [-e]
pactester is a tool to test proxy auto-config
(pac) files. It returns the proxy config string for the given URL and the
pac file. pactester uses pacparser C library for most of its functionality.
- -p pacfile
- PAC file to test. Specify "-" to read from the standard
input.
- -u url
- URL to test the PAC file for.
- -h host
- Host part of the URL. If
not specified, it’s determined from the URL.
- -c client_ip
- Client’s IP address
(as returned by the function myIpAddress() in PAC files). If not specified,
it defaults to the IP address of the machine on which this tool is running.
- -e
- Enable Microsoft PAC extensions (dnsResolveEx, myIpAddressEx, isResolvableEx).
- -f urlslist
- A file containing the list of URLs to be tested. This is good
for testing a PAC file against a set of URLs.
To find out the proxy
config string for the pac file "wpad.dat" and the URL "http://www.google.com
":
$ pactester -p wpad.dat -u http://www.google.com
For a client with IP address
10.0.12.123:
$ pactester -p wpad.dat -c 10.0.12.123 -u http://www.google.com
For a
pac file hosted at http://wpad/wpad.dat:
$ curl -s http://wpad/wpad.dat
| pactester
-p - -u http://google.com
If you have come across a bug in pactester, please
submit a bug report at http://code.google.com/p/pacparser/issues/list.
Written
by Manu Garg (http://www.manugarg.com).
Homepage: http://code.google.com/p/pacparser.
Table of Contents
pacparser-1.3.0/docs/pacparser_cleanup.3 0000664 0000000 0000000 00000001246 11632721722 0020204 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_cleanup" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_cleanup \- Destroys JavaSctipt context.
.SH "SYNOPSIS"
.ft B
#include
.sp
void pacparser_cleanup(void);
.ft R
.SH "DESCRIPTION"
This function should be called once you're done with using pacparser engine.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_enable_microsoft_extensions.3 0000664 0000000 0000000 00000001547 11632721722 0024353 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_enable_microsoft_extensions" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_enable_microsoft_extensions \- Enable Microsoft PAC extensions.
.SH "SYNOPSIS"
.ft B
#include
.sp
void pacparser_enable_microsoft_extensions(void);
.ft R
.SH "DESCRIPTION"
Enables a subset of Microsoft PAC extensions - dnsResolveEx, myIpAddressEx,
isResolvableEx. These functions are used by Google Chrome and IE to work
with IPv6. More info: http://code.google.com/p/pacparser/issues/detail?id=4.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3)
pacparser-1.3.0/docs/pacparser_find_proxy.3 0000664 0000000 0000000 00000002060 11632721722 0020731 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_find_proxy" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_find_proxy \- Finds proxy for a given URL and Host.
.SH "SYNOPSIS"
.ft B
#include
.sp
char *pacparser_find_proxy
.br
(
.br
const char *url,
.br
const char *host
.br
);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *url"
URL to find proxy for.
.TP
.B "const char *host"
Host part of the URL.
.SH "DESCRIPTION"
Finds proxy for a given URL and Host. This function should be called only
after pacparser engine has been initialized (using pacparser_init) and pac
script has been parsed (using pacparser_parse_pac_file or
pacparser_parse_pac_string).
.SH "RETURNS"
Proxy string on sucess and NULL on error.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_init.3 0000664 0000000 0000000 00000001324 11632721722 0017515 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_init" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_init \- Initializes pac parser
.SH "SYNOPSIS"
.ft B
#include
.sp
int pacparser_init(void);
.ft R
.SH "DESCRIPTION"
It initializes JavaScript engine and does few basic initializations specific
to pacparser.
.SH "RETURNS"
0 on failure and 1 on success.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_just_find_proxy.3 0000664 0000000 0000000 00000002304 11632721722 0021777 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_just_find_proxy" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_just_find_proxy \- Finds proxy for a given PAC file, url and host.
.SH "SYNOPSIS"
.ft B
#include
.sp
char *pacparser_just_find_proxy
.br
(
.br
const char *pacfile,
.br
const char *url,
.br
const char *host
.br
);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *pacfile"
PAC file.
.TP
.B "const char *url"
URL to find proxy for.
.TP
.B "const char *host"
Host part of the URL.
.SH "DESCRIPTION"
This function is a wrapper around functions pacparser_init,
pacparser_parse_pac_file, 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. This function takes care of all the initialization
and cleanup.
.SH "RETURNS"
Proxy string on success and NULL on error.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_parse_pac.3 0000664 0000000 0000000 00000001505 11632721722 0020510 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_parse_pac" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_parse_pac \- Parses pac file (deprecated, use pacparser_parse_pac_file instead)
.SH "SYNOPSIS"
.ft B
#include
.sp
int pacparser_parse_pac(const char *file);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *file"
PAC file to parse.
.SH "DESCRIPTION"
Same as pacparser_parse_pac_file. Included only for backward compatibility.
.SH "RETURNS"
0 on failure and 1 on success.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_parse_pac_file.3 0000664 0000000 0000000 00000001500 11632721722 0021502 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_parse_pac_file" 3 "20 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_parse_pac_file \- Parses the given PAC file.
.SH "SYNOPSIS"
.ft B
#include
.sp
int pacparser_parse_pac_file(const char *pacfile);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *pacfile"
PAC file to parse.
.SH "DESCRIPTION"
Reads the given PAC file and evaluates it in the JavaScript context created
by pacparser_init.
.SH "RETURNS"
0 on failure and 1 on success.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_parse_pac_string.3 0000664 0000000 0000000 00000001511 11632721722 0022073 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_parse_pac_string" 3 "20 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_parse_pac_string \- Parses the given PAC script string.
.SH "SYNOPSIS"
.ft B
#include
.sp
int pacparser_parse_pac_string(const char *string);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *string"
PAC string to parse.
.SH "DESCRIPTION"
Evaulates the given PAC script string in the JavaScript context created
by pacparser_init.
.SH "RETURNS"
0 on failure and 1 on success.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_setmyip(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pacparser_setmyip.3 0000664 0000000 0000000 00000001402 11632721722 0020241 0 ustar 00root root 0000000 0000000 .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
.\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
.TH "pacparser_setmyip" 3 "14 March 2011" "c2man pacparser.h"
.SH "NAME"
pacparser_setmyip \- Sets my IP address.
.SH "SYNOPSIS"
.ft B
#include
.sp
void pacparser_setmyip(const char *ip);
.ft R
.SH "PARAMETERS"
.TP
.B "const char *ip"
Custom IP address.
.SH "DESCRIPTION"
Sets my IP address to a custom value. This is the IP address returned by
myIpAddress() javascript function.
.SH "SEE ALSO"
pacparser_version(3),
pacparser_init(3),
pacparser_parse_pac_file(3),
pacparser_parse_pac_string(3),
pacparser_parse_pac(3),
pacparser_find_proxy(3),
pacparser_just_find_proxy(3),
pacparser_cleanup(3),
pacparser_enable_microsoft_extensions(3)
pacparser-1.3.0/docs/pactester.1 0000664 0000000 0000000 00000003372 11632721722 0016507 0 ustar 00root root 0000000 0000000 .TH "pactester" "1" "" "" ""
.SH "NAME"
pactester \- Tool to test proxy auto\-config (pac) files.
.SH "SYNOPSIS"
.B pactester <\-p pacfile> <\-u url> [\-h host] [\-c client_ip] [\-e]
.PP
.B pactester <\-p pacfile> <\-f urlslist> [\-c client_ip] [\-e]
.SH "DESCRIPTION"
pactester is a tool to test proxy auto\-config (pac) files. It returns the
proxy config string for the given URL and the pac file. pactester uses
pacparser C library for most of its functionality.
.SH "OPTIONS"
.TP
.B \-p pacfile
PAC file to test. Specify "-" to read from the standard input.
.TP
.B \-u url
URL to test the PAC file for.
.TP
.B \-h host
Host part of the URL. If not specified, it's determined from the URL.
.TP
.B \-c client_ip
Client's IP address (as returned by the function myIpAddress() in PAC files).
If not specified, it defaults to the IP address of the machine on which
this tool is running.
.TP
.B \-e
Enable Microsoft PAC extensions (dnsResolveEx, myIpAddressEx, isResolvableEx).
.TP
.B \-f urlslist
A file containing the list of URLs to be tested. This is good for testing a PAC file against a set of URLs.
.SH "EXAMPLES"
.PP
To find out the proxy config string for the pac file "wpad.dat" and the URL
"http://www.google.com":
.PP
$ pactester \-p wpad.dat \-u http://www.google.com
For a client with IP address 10.0.12.123:
.PP
$ pactester \-p wpad.dat \-c 10.0.12.123 \-u http://www.google.com
For a pac file hosted at http://wpad/wpad.dat:
.PP
$ curl \-s http://wpad/wpad.dat | pactester \-p \- \-u http://google.com
.SH "BUGS"
If you have come across a bug in pactester, please submit a bug report at
http://code.google.com/p/pacparser/issues/list.
.SH "AUTHOR"
Written by Manu Garg (http://www.manugarg.com).
.SH "RESOURCES"
Homepage: http://code.google.com/p/pacparser.
pacparser-1.3.0/examples/ 0000775 0000000 0000000 00000000000 11632721722 0015314 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/examples/fetchurl.py 0000775 0000000 0000000 00000006261 11632721722 0017512 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# Copyright (C) 2008 Manu Garg.
# Author: Manu Garg
#
# pacparser is a library that provides methods to parse proxy auto-config
# (PAC) files. Please read README file included with this package for more
# information about this library.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA
"""
This script demonstrates how python web clients can use
proxy auto-config (PAC) files for proxy configuration using pacparser.
It take a PAC file and an url as arguments, fetches the URL using the
proxy as determined by PAC file and URL and returns the retrieved webpage.
"""
__author__ = 'manugarg@gmail.com (Manu Garg)'
__copyright__ = 'Copyright (C) 2008 Manu Garg'
__license__ = 'LGPL'
import pacparser
import socket
import sys
import urllib
def fetch_url_using_pac(pac, url):
try:
proxy_string = pacparser.just_find_proxy(pac, url)
except:
sys.stderr.write('could not determine proxy using Pacfile\n')
return None
proxylist = proxy_string.split(";")
proxies = None # Dictionary to be passed to urlopen method of urllib
while proxylist:
proxy = proxylist.pop(0).strip()
if 'DIRECT' in proxy:
proxies = {}
break
if proxy[0:5].upper() == 'PROXY':
proxy = proxy[6:].strip()
if isproxyalive(proxy):
proxies = {'http': 'http://%s' % proxy}
break
try:
sys.stderr.write('trying to fetch the page using proxy %s\n' % proxy)
response = urllib.urlopen(url, proxies=proxies)
except Exception, e:
sys.stderr.write('could not fetch webpage %s using proxy %s\n' %
(url, proxies))
sys.stderr.write(str(e)+'\n')
return None
return response
def isproxyalive(proxy):
host_port = proxy.split(":")
if len(host_port) != 2:
sys.stderr.write('proxy host is not defined as host:port\n')
return False
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
try:
s.connect((host_port[0], int(host_port[1])))
except Exception, e:
sys.stderr.write('proxy %s is not accessible\n' % proxy)
sys.stderr.write(str(e)+'\n')
return False
s.close()
return True
def main():
if len(sys.argv) != 3:
print 'Not enough arguments'
print 'Usage:\n%s ' % sys.argv[0]
return None
pacfile = sys.argv[1]
url = sys.argv[2]
response = fetch_url_using_pac(pacfile, url)
if response:
print response.read()
else:
sys.stderr.write('URL %s could not be retrieved using PAC file %s.' %
(url, pacfile))
if __name__ == '__main__':
main()
pacparser-1.3.0/examples/pactest.c 0000664 0000000 0000000 00000000573 11632721722 0017130 0 ustar 00root root 0000000 0000000 #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 = NULL;
pacparser_init();
pacparser_parse_pac(argv[1]);
proxy = pacparser_find_proxy(argv[2], argv[3]);
if(proxy) printf("%s\n", proxy);
pacparser_cleanup();
}
pacparser-1.3.0/examples/pactest.py 0000775 0000000 0000000 00000000407 11632721722 0017335 0 ustar 00root root 0000000 0000000 #!/usr/bin/python2.5
import pacparser
pacparser.init()
pacparser.parse_pac("wpad.dat")
proxy = pacparser.find_proxy("http://www.manugarg.com")
print proxy
pacparser.cleanup()
# Or simply,
print pacparser.just_find_proxy("wpad.dat", "http://www2.manugarg.com")
pacparser-1.3.0/examples/wpad.dat 0000664 0000000 0000000 00000000656 11632721722 0016750 0 ustar 00root root 0000000 0000000 // Go direct for plain hostnames and any host in .manugarg.com domain except
// for www and www.manugarg.com.
// Go via proxy for all other hosts.
function FindProxyForURL(url, host)
{
if ((isPlainHostName(host) ||
dnsDomainIs(host, ".manugarg.com")) &&
!localHostOrDomainIs(host, "www.manugarg.com"))
return "DIRECT";
else
return "PROXY proxy1.manugarg.com:3128; PROXY proxy2.manugarg.com:3128; DIRECT";
}
pacparser-1.3.0/src/ 0000775 0000000 0000000 00000000000 11632721722 0014265 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/src/Makefile 0000664 0000000 0000000 00000011252 11632721722 0015726 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# Makefile for pacparser. Please read README file included with this package
# for more information about pacparser.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# This file is not part of the source code repository. It's generated by the
# packaging script.
-include version.mk
VERSION ?= $(shell hg parents | awk 'NR==1 {print $$2}')
PREFIX ?= /usr
OS_ARCH := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
LIBRARY_NAME = libpacparser
LIB_VER = 1
# This Makefile should at least work on Linux and Mac OS X. It should work on
# most other types of Unix systems too, but I have not put any conscious effort
# for that.
#
# Set variables according to Linux.
SO_SUFFIX = so
LIBRARY = $(LIBRARY_NAME).$(SO_SUFFIX).$(LIB_VER)
MKSHLIB = $(CC) -shared
LIB_OPTS = -Wl,-soname=$(LIBRARY) -Wl,-exclude-libs=libjs.a
SHFLAGS = -fPIC
SMCFLAGS = -DHAVE_VA_COPY -DVA_COPY=__va_copy
ifeq ($(OS_ARCH),Darwin)
MAC_MINOR_VERSION := $(shell sw_vers -productVersion | cut -d. -f2)
MAC_GT_5 := $(shell [ $(MAC_MINOR_VERSION) -le 5 ] && echo false)
SO_SUFFIX = dylib
LIBRARY = $(LIBRARY_NAME).$(LIB_VER).$(SO_SUFFIX)
MKSHLIB = $(CC) -dynamiclib -framework System
LIB_OPTS = -install_name $(PREFIX)/lib/$(notdir $@)
SHFLAGS =
ifeq ($(MAC_GT_5),false)
SMCFLAGS =
endif
endif
CFLAGS = -g -DXP_UNIX -Wall -DVERSION=$(VERSION)
ifndef PYTHON
PYTHON = python
endif
# Spidermonkey library.
CFLAGS += -Ispidermonkey/js/src
LDFLAGS += -lm
LIBRARY_LINK = $(LIBRARY_NAME).$(SO_SUFFIX)
PREFIX := $(DESTDIR)$(PREFIX)
LIB_PREFIX = $(PREFIX)/lib
INC_PREFIX = $(PREFIX)/include
BIN_PREFIX = $(PREFIX)/bin
MAN_PREFIX = $(PREFIX)/share/man
.PHONY: clean pymod install-pymod
all: testpactester
spidermonkey/js/src: spidermonkey/js-?.?.?.tar.gz
tar xzvf spidermonkey/js-?.?.?.tar.gz -C spidermonkey
sed -i -e 's:\(shell uname -s | sed /\\ /s//_/\):\1 | sed s,GNU.*,Linux,:g' spidermonkey/js/src/config.mk
jsapi_buildstamp: spidermonkey/js/src
cd spidermonkey && SMCFLAGS="$(SHFLAGS) $(SMCFLAGS)" $(MAKE) jsapi
touch jsapi_buildstamp
libjs.a: spidermonkey/js/src
cd spidermonkey && SMCFLAGS="$(SHFLAGS) $(SMCFLAGS)" $(MAKE) jslib
pacparser.o: pacparser.c pac_utils.h pacparser.h jsapi_buildstamp
$(CC) $(CFLAGS) $(SHFLAGS) -c pacparser.c -o pacparser.o
touch pymod/pacparser_o_buildstamp
$(LIBRARY): pacparser.o libjs.a
$(MKSHLIB) $(LIB_OPTS) -o $(LIBRARY) pacparser.o libjs.a $(LDFLAGS)
$(LIBRARY_LINK): $(LIBRARY)
ln -sf $(LIBRARY) $(LIBRARY_LINK)
pactester: pactester.c pacparser.h $(LIBRARY_LINK)
$(CC) pactester.c -o pactester -lpacparser -L. -I.
testpactester: pactester
echo "Running tests for pactester."
NO_INTERNET=$(NO_INTERNET) ../tests/runtests.sh
install: all
install -d $(LIB_PREFIX) $(INC_PREFIX) $(BIN_PREFIX)
install -m 644 $(LIBRARY) $(LIB_PREFIX)/$(LIBRARY)
ln -sf $(LIBRARY) $(LIB_PREFIX)/$(LIBRARY_LINK)
install -m 755 pactester $(BIN_PREFIX)/pactester
install -m 644 pacparser.h $(INC_PREFIX)/pacparser.h
# install pactester manpages
install -d $(MAN_PREFIX)/man1/
(test -d ../docs && install -m 644 ../docs/*.1 $(MAN_PREFIX)/man1/) || true
# install pacparser manpages
install -d $(MAN_PREFIX)/man3/
(test -d ../docs && install -m 644 ../docs/*.3 $(MAN_PREFIX)/man3/) || true
# install html docs
install -d $(PREFIX)/share/doc/pacparser/html/
(test -d ../docs/html && install -m 644 ../docs/html/* $(PREFIX)/share/doc/pacparser/html/) || true
# install examples
install -d $(PREFIX)/share/doc/pacparser/examples/
(test -d ../examples && install -m 644 ../examples/* $(PREFIX)/share/doc//pacparser/examples/) || true
# Targets to build python module
pymod: pacparser.o pacparser.h libjs.a
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py build
$(PYTHON) ../tests/runtests.py
install-pymod: pymod
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py install --root="$(DESTDIR)/" $(EXTRA_ARGS)
clean:
rm -f $(LIBRARY_LINK) $(LIBRARY) libjs.a pacparser.o pactester pymod/pacparser_o_buildstamp jsapi_buildstamp
cd pymod && python setup.py clean --all
cd spidermonkey && $(MAKE) clean
pacparser-1.3.0/src/Makefile.win32 0000664 0000000 0000000 00000004750 11632721722 0016674 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# Makefile for pacparser. Please read README file included with this package
# for more information about pacparser.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# This file is not part of the source code repository. It's generated by the
# packaging script.
-include version.mk
LIB_VER=1
CFLAGS=-g -DXP_WIN -DVERSION=$(VERSION) -Ispidermonkey/js/src -Wall
CC=gcc
.PHONY: clean pymod install-pymod
all: pacparser.dll pacparser.lib pactester
pacparser.o: pacparser.c pac_utils.h js.lib
$(CC) $(CFLAGS) -c pacparser.c -o pacparser.o
fdlibm.lib js.lib:
$(MAKE) -C spidermonkey -f Makefile.win32
copy spidermonkey\fdlibm.lib .
copy spidermonkey\js.lib .
pacparser.dll: pacparser.o fdlibm.lib js.lib
$(CC) -shared -o pacparser.dll \
-Wl,--output-def,pacparser.def \
-Wl,--out-implib,libpacparser.a \
-Wl,--export-all-symbols \
pacparser.o -ljs -L. -lws2_32
pacparser.lib: pacparser.dll pacparser.def
lib /machine:i386 /def:pacparser.def
pactester: pactester.c pacparser.h pacparser.dll
$(CC) pactester.c -o pactester -lpacparser -L. -I.
dist: pacparser.dll pactester
if exist dist rmdir /s /q dist
mkdir dist
copy pacparser.dll dist
copy pacparser.h dist
copy pactester.exe dist
if exist pacparser.lib copy pacparser.lib dist
copy ..\README dist\README.txt
copy ..\COPYING dist\COPYING.txt
copy ..\INSTALL dist\INSTALL.txt
mkdir dist\docs
copy ..\README.win32 dist\docs
if exist ..\docs\html xcopy ..\docs\html dist\docs
# Targets to build python module
pymod: pacparser.h pacparser.dll
cd pymod && setup.py dist
cd .. && tests\runtests.py
clean:
del /F pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a
$(MAKE) -C spidermonkey -f Makefile.win32 clean
cd pymod && setup.py clean
if exist dist rmdir /s /q dist
pacparser-1.3.0/src/pac_utils.h 0000664 0000000 0000000 00000020217 11632721722 0016423 0 ustar 00root root 0000000 0000000 // Copyright (C) 2007 Manu Garg.
// Author: Manu Garg
//
// pac_utils.h defines some of the functions used by PAC files. This file is
// packaged with pacparser source code and is required for compiling pacparser.
// Please read README file included with this package for more information
// about pacparser.
// Note: This file is derived from "nsProxyAutoConfig.js" file that comes with
// mozilla source code. Please check out the following for initial developer
// and contributors:
//http://lxr.mozilla.org/seamonkey/source/netwerk/base/src/nsProxyAutoConfig.js
//
// This file is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
// pacparser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA
static const char *pacUtils =
"function dnsDomainIs(host, domain) {\n"
" return (host.length >= domain.length &&\n"
" host.substring(host.length - domain.length) == domain);\n"
"}\n"
"function dnsDomainLevels(host) {\n"
" return host.split('.').length-1;\n"
"}\n"
"function convert_addr(ipchars) {\n"
" var bytes = ipchars.split('.');\n"
" var result = ((bytes[0] & 0xff) << 24) |\n"
" ((bytes[1] & 0xff) << 16) |\n"
" ((bytes[2] & 0xff) << 8) |\n"
" (bytes[3] & 0xff);\n"
" return result;\n"
"}\n"
"function isInNet(ipaddr, pattern, maskstr) {\n"
" var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/(ipaddr);\n"
" if (test == null) {\n"
" ipaddr = dnsResolve(ipaddr);\n"
" if (ipaddr == null)\n"
" return false;\n"
" } else if (test[1] > 255 || test[2] > 255 || \n"
" test[3] > 255 || test[4] > 255) {\n"
" return false; // not an IP address\n"
" }\n"
" var host = convert_addr(ipaddr);\n"
" var pat = convert_addr(pattern);\n"
" var mask = convert_addr(maskstr);\n"
" return ((host & mask) == (pat & mask));\n"
" \n"
"}\n"
"function isPlainHostName(host) {\n"
" return (host.search('\\\\.') == -1);\n"
"}\n"
"function isResolvable(host) {\n"
" var ip = dnsResolve(host);\n"
" return (ip != null);\n"
"}\n"
"if (typeof(dnsResolveEx) == \"function\") {\n"
"function isResolvableEx(host) {\n"
" var ip = dnsResolveEx(host);\n"
" return (ip != null);\n"
"}\n"
"}\n"
"function localHostOrDomainIs(host, hostdom) {\n"
" return (host == hostdom) ||\n"
" (hostdom.lastIndexOf(host + '.', 0) == 0);\n"
"}\n"
"function shExpMatch(url, pattern) {\n"
" pattern = pattern.replace(/\\./g, '\\\\.');\n"
" pattern = pattern.replace(/\\*/g, '.*');\n"
" pattern = pattern.replace(/\\?/g, '.');\n"
" var newRe = new RegExp('^'+pattern+'$');\n"
" return newRe.test(url);\n"
"}\n"
"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n"
"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n"
"function weekdayRange() {\n"
" function getDay(weekday) {\n"
" if (weekday in wdays) {\n"
" return wdays[weekday];\n"
" }\n"
" return -1;\n"
" }\n"
" var date = new Date();\n"
" var argc = arguments.length;\n"
" var wday;\n"
" if (argc < 1)\n"
" return false;\n"
" if (arguments[argc - 1] == 'GMT') {\n"
" argc--;\n"
" wday = date.getUTCDay();\n"
" } else {\n"
" wday = date.getDay();\n"
" }\n"
" var wd1 = getDay(arguments[0]);\n"
" var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n"
" return (wd1 == -1 || wd2 == -1) ? false\n"
" : (wd1 <= wday && wday <= wd2);\n"
"}\n"
"function dateRange() {\n"
" function getMonth(name) {\n"
" if (name in months) {\n"
" return months[name];\n"
" }\n"
" return -1;\n"
" }\n"
" var date = new Date();\n"
" var argc = arguments.length;\n"
" if (argc < 1) {\n"
" return false;\n"
" }\n"
" var isGMT = (arguments[argc - 1] == 'GMT');\n"
"\n"
" if (isGMT) {\n"
" argc--;\n"
" }\n"
" // function will work even without explict handling of this case\n"
" if (argc == 1) {\n"
" var tmp = parseInt(arguments[0]);\n"
" if (isNaN(tmp)) {\n"
" return ((isGMT ? date.getUTCMonth() : date.getMonth()) ==\n"
"getMonth(arguments[0]));\n"
" } else if (tmp < 32) {\n"
" return ((isGMT ? date.getUTCDate() : date.getDate()) == tmp);\n"
" } else { \n"
" return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) ==\n"
"tmp);\n"
" }\n"
" }\n"
" var year = date.getFullYear();\n"
" var date1, date2;\n"
" date1 = new Date(year, 0, 1, 0, 0, 0);\n"
" date2 = new Date(year, 11, 31, 23, 59, 59);\n"
" var adjustMonth = false;\n"
" for (var i = 0; i < (argc >> 1); i++) {\n"
" var tmp = parseInt(arguments[i]);\n"
" if (isNaN(tmp)) {\n"
" var mon = getMonth(arguments[i]);\n"
" date1.setMonth(mon);\n"
" } else if (tmp < 32) {\n"
" adjustMonth = (argc <= 2);\n"
" date1.setDate(tmp);\n"
" } else {\n"
" date1.setFullYear(tmp);\n"
" }\n"
" }\n"
" for (var i = (argc >> 1); i < argc; i++) {\n"
" var tmp = parseInt(arguments[i]);\n"
" if (isNaN(tmp)) {\n"
" var mon = getMonth(arguments[i]);\n"
" date2.setMonth(mon);\n"
" } else if (tmp < 32) {\n"
" date2.setDate(tmp);\n"
" } else {\n"
" date2.setFullYear(tmp);\n"
" }\n"
" }\n"
" if (adjustMonth) {\n"
" date1.setMonth(date.getMonth());\n"
" date2.setMonth(date.getMonth());\n"
" }\n"
" if (isGMT) {\n"
" var tmp = date;\n"
" tmp.setFullYear(date.getUTCFullYear());\n"
" tmp.setMonth(date.getUTCMonth());\n"
" tmp.setDate(date.getUTCDate());\n"
" tmp.setHours(date.getUTCHours());\n"
" tmp.setMinutes(date.getUTCMinutes());\n"
" tmp.setSeconds(date.getUTCSeconds());\n"
" date = tmp;\n"
" }\n"
" return ((date1 <= date) && (date <= date2));\n"
"}\n"
"function timeRange() {\n"
" var argc = arguments.length;\n"
" var date = new Date();\n"
" var isGMT= false;\n"
"\n"
" if (argc < 1) {\n"
" return false;\n"
" }\n"
" if (arguments[argc - 1] == 'GMT') {\n"
" isGMT = true;\n"
" argc--;\n"
" }\n"
"\n"
" var hour = isGMT ? date.getUTCHours() : date.getHours();\n"
" var date1, date2;\n"
" date1 = new Date();\n"
" date2 = new Date();\n"
"\n"
" if (argc == 1) {\n"
" return (hour == arguments[0]);\n"
" } else if (argc == 2) {\n"
" return ((arguments[0] <= hour) && (hour <= arguments[1]));\n"
" } else {\n"
" switch (argc) {\n"
" case 6:\n"
" date1.setSeconds(arguments[2]);\n"
" date2.setSeconds(arguments[5]);\n"
" case 4:\n"
" var middle = argc >> 1;\n"
" date1.setHours(arguments[0]);\n"
" date1.setMinutes(arguments[1]);\n"
" date2.setHours(arguments[middle]);\n"
" date2.setMinutes(arguments[middle + 1]);\n"
" if (middle == 2) {\n"
" date2.setSeconds(59);\n"
" }\n"
" break;\n"
" default:\n"
" throw 'timeRange: bad number of arguments'\n"
" }\n"
" }\n"
"\n"
" if (isGMT) {\n"
" date.setFullYear(date.getUTCFullYear());\n"
" date.setMonth(date.getUTCMonth());\n"
" date.setDate(date.getUTCDate());\n"
" date.setHours(date.getUTCHours());\n"
" date.setMinutes(date.getUTCMinutes());\n"
" date.setSeconds(date.getUTCSeconds());\n"
" }\n"
" return ((date1 <= date) && (date <= date2));\n"
"}\n";
pacparser-1.3.0/src/pacparser.c 0000664 0000000 0000000 00000037242 11632721722 0016421 0 ustar 00root root 0000000 0000000 // Copyright (C) 2007 Manu Garg.
// Author: Manu Garg
//
// pacparser is a library that provides methods to parse proxy auto-config
// (PAC) files. Please read README file included with this package for more
// information about this library.
//
// pacparser is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
// pacparser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include
#include
#include
#include
#include
#ifdef XP_UNIX
#include
#include // for AF_INET
#include
#endif
#ifdef _WIN32
#ifdef __MINGW32__
// MinGW enables definition of getaddrinfo et al only if WINVER >= 0x0501.
#define WINVER 0x0501
#endif
#include
#include
#endif
#include "pac_utils.h"
#include "pacparser.h"
#define MAX_IP_RESULTS 10
static char *myip = NULL;
static int define_microsoft_extensions = 0; //0: False, 1: True
static int
_debug(void) {
if(getenv("DEBUG")) return 1;
return 0;
}
// Utility function to read a file into string.
static char * // File content in string or NULL if failed.
read_file_into_str(const char *filename)
{
char *str;
int file_size;
FILE *fptr;
int records_read;
if (!(fptr = fopen(filename, "r"))) goto error1;
if ((fseek(fptr, 0L, SEEK_END) != 0)) goto error2;
if (!(file_size=ftell(fptr))) goto error2;
if ((fseek(fptr, 0L, SEEK_SET) != 0)) goto error2;
if (!(str = (char*) malloc(file_size+1))) goto error2;
if (!(records_read=fread(str, 1, file_size, fptr))) {
free(str);
goto error2;
}
str[records_read] = '\0';
fclose(fptr);
return str;
error2:
fclose(fptr);
error1:
return NULL;
}
static void
print_error(JSContext *cx, const char *message, JSErrorReport *report)
{
fprintf(stderr, "JSERROR: %s:%d:\n %s\n",
(report->filename ? report->filename : "NULL"), report->lineno,
message);
}
// DNS Resolve function; used by other routines.
// This function is used by dnsResolve, dnsResolveEx, myIpAddress,
// myIpAddressEx.
static int
resolve_host(const char *hostname, char *ipaddr_list, int max_results)
{
struct addrinfo hints;
struct addrinfo *result;
struct addrinfo *ai;
char ipaddr[INET6_ADDRSTRLEN];
int error;
// Truncate ipaddr_list to an empty string.
ipaddr_list[0] = '\0';
#ifdef _WIN32
// On windows, we need to initialize the winsock dll first.
WSADATA WsaData;
WSAStartup(MAKEWORD(2,0), &WsaData);
#endif
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(hostname, NULL, &hints, &result);
if (error) return error;
int i = 0;
for(ai = result; ai != NULL && i < max_results; ai = ai->ai_next, i++) {
getnameinfo(ai->ai_addr, ai->ai_addrlen, ipaddr, sizeof(ipaddr), NULL, 0,
NI_NUMERICHOST);
if (ipaddr_list[0] == '\0') sprintf(ipaddr_list, "%s", ipaddr);
else sprintf(ipaddr_list, "%s;%s", ipaddr_list, ipaddr);
}
freeaddrinfo(result);
#ifdef _WIN32
WSACleanup();
#endif
return 0;
}
// dnsResolve in JS context; not available in core JavaScript.
// returns javascript null if not able to resolve.
static JSBool // JS_TRUE or JS_FALSE
dns_resolve(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char* out;
char ipaddr[INET6_ADDRSTRLEN] = "";
if(resolve_host(name, ipaddr, 1)) {
*rval = JSVAL_NULL;
return JS_TRUE;
}
out = JS_malloc(cx, strlen(ipaddr) + 1);
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
// dnsResolveEx in JS context; not available in core JavaScript.
// returns javascript null if not able to resolve.
static JSBool // JS_TRUE or JS_FALSE
dns_resolve_ex(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
char* name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char* out;
char ipaddr[INET6_ADDRSTRLEN * MAX_IP_RESULTS + MAX_IP_RESULTS] = "";
if(resolve_host(name, ipaddr, MAX_IP_RESULTS)) {
*rval = JSVAL_NULL;
return JS_TRUE;
}
out = JS_malloc(cx, strlen(ipaddr) + 1);
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
// myIpAddress in JS context; not available in core JavaScript.
// returns 127.0.0.1 if not able to determine local ip.
static JSBool // JS_TRUE or JS_FALSE
my_ip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char ipaddr[INET6_ADDRSTRLEN];
char* out;
if (myip) // If my (client's) IP address is already set.
strcpy(ipaddr, myip);
else {
char name[256];
gethostname(name, sizeof(name));
if (resolve_host(name, ipaddr, 1)) {
strcpy(ipaddr, "127.0.0.1");
}
}
out = JS_malloc(cx, strlen(ipaddr) + 1);
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
// myIpAddressEx in JS context; not available in core JavaScript.
// returns 127.0.0.1 if not able to determine local ip.
static JSBool // JS_TRUE or JS_FALSE
my_ip_ex(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char ipaddr[INET6_ADDRSTRLEN * MAX_IP_RESULTS + MAX_IP_RESULTS];
char* out;
if (myip) // If my (client's) IP address is already set.
strcpy(ipaddr, myip);
else {
char name[256];
gethostname(name, sizeof(name));
if (resolve_host(name, ipaddr, MAX_IP_RESULTS)) {
strcpy(ipaddr, "127.0.0.1");
}
}
out = JS_malloc(cx, strlen(ipaddr) + 1);
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
// Define some JS context related variables.
static JSRuntime *rt = NULL;
static JSContext *cx = NULL;
static JSObject *global = NULL;
static JSClass global_class = {
"global",0,
JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,
JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub
};
// Set my (client's) IP address to a custom value.
void
pacparser_setmyip(const char *ip)
{
myip = malloc(strlen(ip) +1); // Allocate space just to be sure.
strcpy(myip, ip);
}
void
pacparser_enable_microsoft_extensions()
{
if(cx) {
fprintf(stderr, "pacparser.c: pacparser_enable_microsoft_extensions: "
"Can not enable microsoft extensions now. This function should be "
"called before pacparser_init.\n");
return;
}
define_microsoft_extensions = 1;
}
// Initialize PAC parser.
//
// - Initializes JavaScript engine,
// - Exports dns_functions (defined above) to JavaScript context.
// - Sets error reporting function to print_error,
// - Evaluates JavaScript code in pacUtils variable defined in pac_utils.h.
int // 0 (=Failure) or 1 (=Success)
pacparser_init()
{
jsval rval;
// Initialize JS engine
if (!(rt = JS_NewRuntime(8L * 1024L * 1024L)) ||
!(cx = JS_NewContext(rt, 8192)) ||
!(global = JS_NewObject(cx, &global_class, NULL, NULL)) ||
!JS_InitStandardClasses(cx, global)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not initialize"
" JavaScript runtime.");
return 0;
}
JS_SetErrorReporter(cx, print_error);
// Export our functions to Javascript engine
if (!JS_DefineFunction(cx, global, "dnsResolve", dns_resolve, 1, 0)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not define"
" dnsResolve in JS context.");
return 0;
}
if (!JS_DefineFunction(cx, global, "myIpAddress", my_ip, 0, 0)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not define"
" myIpAddress in JS context.");
return 0;
}
if (define_microsoft_extensions) {
if (!JS_DefineFunction(cx, global, "dnsResolveEx", dns_resolve_ex, 1, 0)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not define"
" dnsResolveEx in JS context.");
return 0;
}
if (!JS_DefineFunction(cx, global, "myIpAddressEx", my_ip_ex, 0, 0)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not define"
" myIpAddressEx in JS context.");
return 0;
}
}
// Evaluate pacUtils. Utility functions required to parse pac files.
if (!JS_EvaluateScript(cx, // JS engine context
global, // global object
pacUtils, // this is defined in pac_utils.h
strlen(pacUtils),
NULL, // filename (NULL in this case)
1, // line number, used for reporting.
&rval)) {
fprintf(stderr, "pacparser.c: pacparser_init: %s\n", "Could not evaluate"
" pacUtils defined in pac_utils.h.");
return 0;
}
if (_debug()) fprintf(stderr, "DEBUG: Pacparser Initalized.\n");
return 1;
}
// Parses the given PAC script string.
//
// Evaulates the given PAC script string in the JavaScript context created
// by pacparser_init.
int // 0 (=Failure) or 1 (=Success)
pacparser_parse_pac_string(const char *script)
{
jsval rval;
if (cx == NULL || global == NULL) {
fprintf(stderr, "pacparser.c: pacparser_parse_pac_string: %s\n", "Pac "
"parser is not initialized.");
return 0;
}
if (!JS_EvaluateScript(cx,
global,
script, // Script read from pacfile
strlen(script),
"PAC script",
1,
&rval)) { // If script evaluation failed
fprintf(stderr, "pacparser.c: pacparser_parse_pac_string: %s\n",
"Failed to evaluate the pac script.");
if (_debug()) fprintf(stderr, "DEBUG: Failed to parse the PAC "
"script:\n%s\n", script);
return 0;
}
if (_debug()) fprintf(stderr, "DEBUG: Parsed the PAC script.\n");
return 1;
}
// Parses the given PAC file.
//
// reads the given PAC file and evaluates it in the JavaScript context created
// by pacparser_init.
int // 0 (=Failure) or 1 (=Success)
pacparser_parse_pac_file(const char *pacfile)
{
char *script = NULL;
if ((script = read_file_into_str(pacfile)) == NULL) {
fprintf(stderr, "pacparser.c: pacparser_parse_pac: %s: %s: %s\n",
"Could not read the pacfile: ", pacfile, strerror(errno));
return 0;
}
int result = pacparser_parse_pac_string(script);
if (script != NULL) free(script);
if (_debug()) {
if(result) fprintf(stderr, "DEBUG: Parsed the PAC file: %s\n", pacfile);
else fprintf(stderr, "DEBUG: Could not parse the PAC file: %s\n", pacfile);
}
return result;
}
// Parses PAC file (same as pacparser_parse_pac_file)
//
// (Deprecated) Use pacparser_parse_pac_file instead.
int // 0 (=Failure) or 1 (=Success)
pacparser_parse_pac(const char *pacfile)
{
return pacparser_parse_pac_file(pacfile);
}
// Finds proxy for the given URL and Host.
//
// If JavaScript engine is intialized and FindProxyForURL function is defined,
// it evaluates code FindProxyForURL(url,host) in JavaScript context and
// returns the result.
char * // Proxy string or NULL if failed.
pacparser_find_proxy(const char *url, const char *host)
{
if (_debug()) fprintf(stderr, "DEBUG: Finding proxy for URL: %s and Host:"
" %s\n", url, host);
jsval rval;
char *script;
if (url == NULL || (strcmp(url, "") == 0)) {
fprintf(stderr, "pacparser.c: pacparser_find_proxy: %s\n", "URL not "
"defined");
return NULL;
}
if (host == NULL || (strcmp(host,"") == 0)) {
fprintf(stderr, "pacparser.c: pacparser_find_proxy: %s\n", "Host not "
"defined");
return NULL;
}
if (cx == NULL || global == NULL) {
fprintf(stderr, "pacparser.c: pacparser_find_proxy: %s\n",
"Pac parser is not initialized.");
return NULL;
}
// Test if FindProxyForURL is defined.
script = "typeof(FindProxyForURL);";
if (_debug()) fprintf(stderr, "DEBUG: Executing JavaScript: %s\n", script);
JS_EvaluateScript(cx, global, script, strlen(script), NULL, 1, &rval);
if (strcmp("function", JS_GetStringBytes(JS_ValueToString(cx, rval))) != 0) {
fprintf(stderr, "pacparser.c: pacparser_find_proxy: %s\n", "Javascript"
" function FindProxyForURL not defined.");
return NULL;
}
script = (char*) malloc(32 + strlen(url) + strlen(host));
script[0] = '\0';
strcat(script, "FindProxyForURL('");
strcat(script, url);
strcat(script, "', '");
strcat(script, host);
strcat(script, "')");
if (_debug()) fprintf(stderr, "DEBUG: Executing JavaScript: %s\n", script);
if (!JS_EvaluateScript(cx, global, script, strlen(script), NULL, 1, &rval)) {
fprintf(stderr, "pacparser.c: pacparser_find_proxy: %s\n",
"Problem in executing FindProxyForURL.");
return NULL;
}
return JS_GetStringBytes(JS_ValueToString(cx, rval));
}
// Destroys JavaSctipt Engine.
void
pacparser_cleanup()
{
// Reinitliaze config variables.
myip = NULL;
define_microsoft_extensions = 0;
if (cx) {
JS_DestroyContext(cx);
cx = NULL;
}
if (rt) {
JS_DestroyRuntime(rt);
rt = NULL;
}
if (!cx && !rt) JS_ShutDown();
global = NULL;
if (_debug()) fprintf(stderr, "DEBUG: Pacparser destroyed.\n");
}
// 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;
if (!global) {
if (!pacparser_init()) {
fprintf(stderr, "pacparser.c: pacparser_just_find_proxy: %s\n",
"Could not initialize pacparser");
return NULL;
}
initialized_here = 1;
}
if (!pacparser_parse_pac(pacfile)) {
fprintf(stderr, "pacparser.c: pacparser_just_find_proxy: %s %s\n",
"Could not parse pacfile", pacfile);
if (initialized_here) pacparser_cleanup();
return NULL;
}
if (!(out = pacparser_find_proxy(url, host))) {
fprintf(stderr, "pacparser.c: pacparser_just_find_proxy: %s %s\n",
"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;
}
#define QUOTEME_(x) #x
#define QUOTEME(x) QUOTEME_(x)
char* pacparser_version(void) {
#ifndef VERSION
fprintf(stderr, "WARNING: VERSION not defined.");
return "";
#endif
return QUOTEME(VERSION);
}
pacparser-1.3.0/src/pacparser.h 0000664 0000000 0000000 00000010522 11632721722 0016416 0 ustar 00root root 0000000 0000000 // Copyright (C) 2007 Manu Garg.
// Author: Manu Garg
//
// This file defines API for pacparser library.
//
// pacparser is a library that provides methods to parse proxy auto-config
// (PAC) files. Please read README file included with this package for more
// information about this library.
//
// pacparser is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
// pacparser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#ifdef __cplusplus
extern "C" {
#endif
// Returns pacparser version
// Version string is determined at the time of build. If built from a released
// package, version corresponds to the latest release (hg) tag. If built from the
// repository, it corresponds to the head revision of the repo.
// returns version string if version defined, "" otherwise.
char* pacparser_version(void);
// Initializes pac parser
// It initializes JavaScript engine and does few basic initializations specific
// to pacparser.
// returns 0 on failure and 1 on success.
int pacparser_init(void);
// Parses the given PAC file.
// Reads the given PAC file and evaluates it in the JavaScript context created
// by pacparser_init.
// returns 0 on failure and 1 on success.
int pacparser_parse_pac_file(const char *pacfile // PAC file to parse
);
// Parses the given PAC script string.
// Evaulates the given PAC script string in the JavaScript context created
// by pacparser_init.
// returns 0 on failure and 1 on success.
int pacparser_parse_pac_string(const char *string // PAC string to parse
);
// Parses pac file (deprecated, use pacparser_parse_pac_file instead)
// Same as pacparser_parse_pac_file. Included only for backward compatibility.
// returns 0 on failure and 1 on success.
int pacparser_parse_pac(const char *file // PAC file to parse
);
// Finds proxy for the given URL and Host.
// Finds proxy for the given URL and Host. This function should be called only
// after pacparser engine has been initialized (using pacparser_init) and pac
// script has been parsed (using pacparser_parse_pac_file or
// pacparser_parse_pac_string).
// returns proxy string on sucess and NULL on error.
char *pacparser_find_proxy(const char *url, // URL to find proxy for
const char *host // Host part of the URL
);
// Finds proxy for the given PAC file, URL and Host.
// This function is a wrapper around functions pacparser_init,
// pacparser_parse_pac_file, 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. This function takes care of all the initialization
// and cleanup.
// returns proxy string on success and NULL on error.
char *pacparser_just_find_proxy(const char *pacfile, // PAC file
const char *url, // URL to find proxy for
const char *host // Host part of the URL
);
// Destroys JavaSctipt context.
// This function should be called once you're done with using pacparser engine.
void pacparser_cleanup(void);
// Sets my IP address.
// Sets my IP address to a custom value. This is the IP address returned by
// myIpAddress() javascript function.
void pacparser_setmyip(const char *ip // Custom IP address.
);
// Enable Microsoft PAC extensions.
// Enables a subset of Microsoft PAC extensions - dnsResolveEx, myIpAddressEx,
// isResolvableEx. These functions are used by Google Chrome and IE to work
// with IPv6. More info: http://code.google.com/p/pacparser/issues/detail?id=4
void pacparser_enable_microsoft_extensions(void);
#ifdef __cplusplus
}
#endif
pacparser-1.3.0/src/pactester.c 0000664 0000000 0000000 00000017372 11632721722 0016435 0 ustar 00root root 0000000 0000000 // Copyright (C) 2008 Manu Garg.
// Author: Manu Garg
//
// This file implements pactester (http://code.google.com/p/pactester) using
// pacparser.
//
// pacparser is a library that provides methods to parse proxy auto-config
// (PAC) files. Please read README file included with this package for more
// information about this library.
//
// pacparser is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
// pacparser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include
#include
#include
#include
#include
void usage(const char *progname)
{
fprintf(stderr, "\nUsage: %s <-p pacfile> <-u url> [-h host] "
"[-c client_ip] [-e]", progname);
fprintf(stderr, "\n %s <-p pacfile> <-f urlslist> "
"[-c client_ip] [-e]\n", progname);
fprintf(stderr, "\nOptions:\n");
fprintf(stderr, " -p pacfile : PAC file to test (specify '-' to read "
"from standard input)\n");
fprintf(stderr, " -u url : URL to test for\n");
fprintf(stderr, " -h host : Host part of the URL\n");
fprintf(stderr, " -c client_ip : client IP address (as returned by "
"myIpAddres() function\n");
fprintf(stderr, " in PAC files), defaults to IP address "
"on which it is running.\n");
fprintf(stderr, " -e : enable microsoft extensions "
"(Ex functions)\n");
fprintf(stderr, " -f urlslist : a file containing list of URLs to be "
"tested.\n");
fprintf(stderr, " -v : print version and exit\n");
}
char *get_host_from_url(const char *url)
{
// copy url to a pointer that we'll use to seek through the string.
char *p = strdup(url);
// Move to :
while (*p != ':' && *p != '\0')
p++;
if (p[0] == '\0'|| // We reached end without hitting :
p[1] != '/' || p[2] != '/' // Next two characters are not //
) {
fprintf(stderr, "pactester.c: Not a proper URL\n");
return NULL;
}
p = p + 3; // Get past '://'
// Host part starts from here.
char *host = p;
if (*p == '\0' || *p == '/' || *p == ':') { // If host part is null.
fprintf(stderr, "pactester.c: Not a proper URL\n");
return NULL;
}
// Seek until next /, : or end of string.
while (*p != '/' && *p != ':' && *p != '\0')
p++;
*p = '\0';
return host;
}
int main(int argc, char* argv[])
{
char *pacfile=NULL, *url=NULL, *host=NULL, *urlslist=NULL, *client_ip=NULL;
int enable_microsoft_extensions=0;
signed char c;
while ((c = getopt(argc, argv, "evp:u:h:f:c:")) != -1)
switch (c)
{
case 'v':
printf("%s\n", pacparser_version());
return 0;
case 'p':
pacfile = optarg;
break;
case 'u':
url = optarg;
break;
case 'h':
host = optarg;
break;
case 'f':
urlslist = optarg;
break;
case 'c':
client_ip = optarg;
break;
case 'e':
enable_microsoft_extensions = 1;
break;
case '?':
if (optopt == 'p' || optopt == 'u' || optopt == 'h' ||
optopt == 'f' || optopt == 'c')
usage(argv[0]);
else if (isprint (optopt))
usage(argv[0]);
else
usage(argv[0]);
return 1;
default:
abort ();
}
if (!pacfile) {
fprintf(stderr, "pactester.c: You didn't specify the PAC file\n");
usage(argv[0]);
return 1;
}
if (!url && !urlslist) {
fprintf(stderr, "pactester.c: You didn't specify the URL\n");
usage(argv[0]);
return 1;
}
if(enable_microsoft_extensions)
pacparser_enable_microsoft_extensions();
// initialize pacparser
if (!pacparser_init()) {
fprintf(stderr, "pactester.c: Could not initialize pacparser\n");
return 1;
}
// Read pacfile from stdin
if (strcmp("-", pacfile) == 0) {
char *script;
int buffsize = 4096;
int maxsize = 1024 * 1024; // Limit the max script size to 1 MB
size_t script_size = 1; // For the null terminator
char buffer[buffsize];
script = (char*) malloc(sizeof(char) * buffsize);
if (script == NULL) {
perror("pactetser.c: Failed to allocate the memory for the script");
return(1);
}
script[0] = '\0'; // Null terminate to prepare for strcat
while(fgets(buffer, buffsize, stdin)) {
if (strlen(buffer) == 0) break;
char *old = script;
script_size += strlen(buffer);
if (script_size > maxsize) {
fprintf(stderr, "Input file is too big. Maximum allowed size is: %d",
maxsize);
free(script);
return 1;
}
script = realloc(script, script_size);
if (script == NULL) {
perror("pactester.c: Failed to allocate the memory for the script");
free(old);
return 1;
}
strcat(script, buffer);
}
if (ferror(stdin)) {
free(script);
perror("pactester.c: Error reading from stdin");
return 1;
}
if(!pacparser_parse_pac_string(script)) {
fprintf(stderr, "pactester.c: Could not parse the pac script: %s\n",
script);
free(script);
pacparser_cleanup();
return 1;
}
free(script);
}
else {
if(!pacparser_parse_pac_file(pacfile)) {
fprintf(stderr, "pactester.c: Could not parse the pac file: %s\n",
pacfile);
pacparser_cleanup();
return 1;
}
}
if(client_ip)
pacparser_setmyip(client_ip);
char *proxy;
if (url) {
if (!host)
host = get_host_from_url(url);
if (host) {
proxy = NULL;
proxy = pacparser_find_proxy(url, host);
if (proxy == NULL) {
fprintf(stderr, "pactester.c: %s %s.\n",
"Problem in finding proxy for", url);
pacparser_cleanup();
return 1;
}
if (proxy) printf("%s\n", proxy);
}
}
else if (urlslist) {
char line[1000]; // this limits line length to 1000.
FILE *fp;
if (!(fp = fopen(urlslist, "r"))) {
fprintf(stderr, "pactester.c: Could not open urlslist: %s", urlslist);
pacparser_cleanup();
return 1;
}
while (fgets(line, sizeof(line), fp)) {
char *url = line;
// remove spaces from the beginning.
while (*url == ' ' || *url == '\t')
url++;
// skip comment lines
if (*url == '#') {
printf("%s", url);
continue;
}
char *urlend = url;
while (*urlend != '\r' && *urlend != '\n' && *urlend != '\0' &&
*urlend != ' ' && *urlend != '\t')
urlend++; // keeping moving till you hit space
// or end of string.
*urlend = '\0';
if ( !(host = get_host_from_url(url)) )
continue;
proxy = NULL;
proxy = pacparser_find_proxy(url, host);
if (proxy == NULL) {
fprintf(stderr, "pactester.c: %s %s.\n",
"Problem in finding proxy for", url);
pacparser_cleanup();
return 1;
}
if(proxy) printf("%s : %s\n", url, proxy);
}
fclose(fp);
}
pacparser_cleanup();
return 0;
}
pacparser-1.3.0/src/pymod/ 0000775 0000000 0000000 00000000000 11632721722 0015415 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/src/pymod/Makefile.win32 0000664 0000000 0000000 00000004331 11632721722 0020017 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# Makefile for pacparser. Please read README file included with this package
# for more information about pacparser.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
CFLAGS=-g -DXP_WIN -Wall -I..
CC=gcc
ifndef PY_HOME
$(error PY_HOME is not defined. It should point to your installtion \
directory e.g. C:\Python25. To avoid this error, this file should \
be called by setup.py only, which takes care of setting that \
variable.)
endif
ifndef PY_DLL
$(error PY_DLL is not defined. It should point to python dll location e.g. \
C:\Windows\System32\Python25.dll. To avoid this error, this \
makefile should be called by setup.py only, which takes care \
of setting that variable.)
endif
CFLAGS+=-I"$(PY_HOME)\include"
.PHONY: dist clean
build: _pacparser.pyd
pacparser_py.o: pacparser_py.c
$(CC) $(CFLAGS) -c pacparser_py.c -o pacparser_py.o
python.dll:
copy $(PY_DLL) python.dll
_pacparser.pyd: pacparser_py.o python.dll ..\pacparser.dll
$(CC) -shared -o _pacparser.pyd pacparser_py.o -lpython -L. -lpacparser -L.. -lws2_32
dist: build
if exist dist rmdir /s /q dist
mkdir dist
mkdir dist\pacparser
xcopy pacparser dist\pacparser
copy _pacparser.pyd dist\pacparser
copy ..\pacparser.dll dist\pacparser
copy install_win32.py dist\install.py
copy ..\..\COPYING dist\COPYING.txt
copy ..\..\README dist\README.txt
copy ..\..\README.win32 dist\README.win32.txt
copy ..\..\INSTALL dist\INSTALL.txt
clean:
del /F pacparser_py.o _pacparser.pyd
if exist dist rmdir /s /q dist
pacparser-1.3.0/src/pymod/install_win32.py 0000664 0000000 0000000 00000000605 11632721722 0020460 0 ustar 00root root 0000000 0000000 import shutil
import sys
from distutils import sysconfig
def main():
if sys.platform == 'win32':
shutil.rmtree('%s\\pacparser' % sysconfig.get_python_lib(),
ignore_errors=True)
shutil.copytree('pacparser', '%s\\pacparser' % sysconfig.get_python_lib())
else:
print 'This script should be used only on Win32 systems.'
if __name__ == '__main__':
main()
pacparser-1.3.0/src/pymod/pacparser/ 0000775 0000000 0000000 00000000000 11632721722 0017375 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/src/pymod/pacparser/__init__.py 0000664 0000000 0000000 00000007060 11632721722 0021511 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# pacparser is a library that provides methods to parse proxy auto-config
# (PAC) files. Please read README file included with this package for more
# information about this library.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
Python module to parse pac files. Look at project's homepage
http://code.google.com/p/pacparser for more information.
"""
__author__ = 'manugarg@gmail.com (Manu Garg)'
__copyright__ = 'Copyright (C) 2008 Manu Garg'
__license__ = 'LGPL'
from pacparser import _pacparser
import os
import re
import sys
url_regex = re.compile('.*\:\/\/([^\/]+).*')
def init():
"""
Initializes pacparser engine.
"""
_pacparser.init()
def parse_pac(pacfile):
"""
(Deprecated) Same as parse_pac_file.
"""
parse_pac_file(pacfile)
def parse_pac_file(pacfile):
"""
Reads the pacfile and evaluates it in the Javascript engine created by
init().
"""
try:
f = open(pacfile)
pac_script = f.read()
except IOError:
print('Could not read the pacfile: %s\n%s' % (pacfile, sys.exc_info()[1]))
return
f.close()
_pacparser.parse_pac_string(pac_script)
def parse_pac_string(pac_script):
"""
Evaluates pac_script in the Javascript engine created by init().
"""
_pacparser.parse_pac_string(pac_script)
def find_proxy(url, host=None):
"""
Finds proxy string for the given url and host. If host is not
defined, it's extracted from the url.
"""
if host is None:
m = url_regex.match(url)
if not m:
print('URL: %s is not a valid URL' % url)
return None
if len(m.groups()) is 1:
host = m.groups()[0]
else:
print('URL: %s is not a valid URL' % url)
return None
return _pacparser.find_proxy(url, host)
def version():
"""
Returns the compiled pacparser version.
"""
return _pacparser.version()
def cleanup():
"""
Destroys pacparser engine.
"""
_pacparser.cleanup()
def just_find_proxy(pacfile, url, host=None):
"""
This function is a wrapper around init, parse_pac, find_proxy
and cleanup. This is the function to call if you want to find
proxy just for one url.
"""
if os.path.isfile(pacfile):
pass
else:
print('PAC file: %s doesn\'t exist' % pacfile)
return None
if host is None:
m = url_regex.match(url)
if not m:
print('URL: %s is not a valid URL' % url)
return None
if len(m.groups()) is 1:
host = m.groups()[0]
else:
print('URL: %s is not a valid URL' % url)
return None
init()
parse_pac(pacfile)
proxy = find_proxy(url,host)
cleanup()
return proxy
def setmyip(ip_address):
"""
Set my ip address. This is the IP address returned by myIpAddress()
"""
_pacparser.setmyip(ip_address)
def enable_microsoft_extensions():
"""
Enables Microsoft PAC extensions (dnsResolveEx, isResolvableEx,
myIpAddressEx).
"""
_pacparser.enable_microsoft_extensions()
pacparser-1.3.0/src/pymod/pacparser_py.c 0000664 0000000 0000000 00000011224 11632721722 0020251 0 ustar 00root root 0000000 0000000 // Copyright (C) 2007 Manu Garg.
// Author: Manu Garg
//
// pacparser is a library that provides methods to parse proxy auto-config
// (PAC) files. Please read README file included with this package for more
// information about this library.
//
// pacparser is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// pacparser is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include
#include "pacparser.h"
// PyMODINIT_FUNC macro is not defined on python < 2.3. Take care of that.
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
// Py_RETURN_NONE macro is not defined on python < 2.4. Take care of that.
#ifndef Py_RETURN_NONE
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
#endif
static PyObject *PacparserError;
// Initialize PAC parser.
//
// - Initializes JavaScript engine,
// - Exports dns_functions (defined above) to JavaScript context.
// - Sets error reporting function to print_error,
// - Evaluates JavaScript code in pacUtils variable defined in pac_utils.h.
static PyObject * // 0 (=Failure) or 1 (=Success)
py_pacparser_init(PyObject *self, PyObject *args)
{
if(pacparser_init())
Py_RETURN_NONE;
else
{
PyErr_SetString(PacparserError, "Could not initialize pacparser");
return NULL;
}
}
// Parses the PAC script string.
//
// Evaulates the PAC script string in the JavaScript context created by
// pacparser_init.
static PyObject * // 0 (=Failure) or 1 (=Success)
py_pacparser_parse_pac_string(PyObject *self, PyObject *args)
{
const char *pac_script;
if (!PyArg_ParseTuple(args, "s", &pac_script))
return NULL;
if (pacparser_parse_pac_string(pac_script))
Py_RETURN_NONE;
else
{
PyErr_SetString(PacparserError, "Could not parse pac script string");
return NULL;
}
}
// Finds proxy for the given URL and Host.
//
// Evaluates FindProxyForURL(url,host) in the JavaScript context and returns
// the result.
static PyObject * // Proxy string or NULL if failed.
py_pacparser_find_proxy(PyObject *self, PyObject *args)
{
char *proxy;
const char *url;
const char *host;
if (!PyArg_ParseTuple(args, "ss", &url, &host))
return NULL;
if(!(proxy = pacparser_find_proxy(url, host)))
{
PyErr_SetString(PacparserError, "Could not find proxy");
return NULL;
}
return Py_BuildValue("s", proxy);
}
// Return pacparser version.
static PyObject * // Version string.
py_pacparser_version(PyObject *self, PyObject *args)
{
return Py_BuildValue("s", pacparser_version());
}
// Destroys JavaSctipt Engine.
static PyObject *
py_pacparser_cleanup(PyObject *self, PyObject *args)
{
pacparser_cleanup();
Py_RETURN_NONE;
}
// Sets local ip to the given argument.
static PyObject *
py_pacparser_setmyip(PyObject *self, PyObject *args)
{
const char *ip;
if (!PyArg_ParseTuple(args, "s", &ip))
return NULL;
pacparser_setmyip(ip);
Py_RETURN_NONE;
}
// Enables Microsoft extensions.
static PyObject *
py_pacparser_enable_microsoft_extensions(PyObject *self, PyObject *args)
{
pacparser_enable_microsoft_extensions();
Py_RETURN_NONE;
}
static PyMethodDef PpMethods[] = {
{"init", py_pacparser_init, METH_VARARGS, "initialize pacparser"},
{"parse_pac_string", py_pacparser_parse_pac_string, METH_VARARGS,
"parses pac script string"},
{"find_proxy", py_pacparser_find_proxy, METH_VARARGS, "returns proxy string"},
{"version", py_pacparser_version, METH_VARARGS, "returns pacparser version"},
{"cleanup", py_pacparser_cleanup, METH_VARARGS, "destroy pacparser engine"},
{"setmyip", py_pacparser_setmyip, METH_VARARGS, "set my ip address"},
{"enable_microsoft_extensions", py_pacparser_enable_microsoft_extensions,
METH_VARARGS, "enable Microsoft extensions"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
init_pacparser(void)
{
PyObject *m;
m = Py_InitModule("_pacparser", PpMethods);
PacparserError = PyErr_NewException("pacparser.error", NULL, NULL);
Py_INCREF(PacparserError);
PyModule_AddObject(m, "error", PacparserError);
}
pacparser-1.3.0/src/pymod/setup.py 0000664 0000000 0000000 00000004700 11632721722 0017130 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# pacparser is a library that provides methods to parse proxy auto-config
# (PAC) files. Please read README file included with this package for more
# information about this library.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
"""
Wrapper script around python module Makefiles. This script take care of
identifying python setup and setting up some environment variables needed by
Makefiles.
"""
import sys
import os
from distutils import sysconfig
from distutils.core import setup
from distutils.core import Extension
def main():
# Use Makefile for windows. distutils doesn't work well with windows.
if sys.platform == 'win32':
pydll = ('C:\windows\system32\python%s.dll' %
sysconfig.get_config_vars('VERSION')[0])
os.system('make -f Makefile.win32 %s PY_HOME="%s" PY_DLL="%s"' %
(' '.join(sys.argv[1:]), sys.prefix, pydll))
return
pacparser_module = Extension('_pacparser',
include_dirs = ['../spidermonkey/js/src', '..'],
sources = ['pacparser_py.c'],
extra_objects = ['../pacparser.o', '../libjs.a'])
setup (name = 'pacparser',
version = '1',
description = 'Pacparser package',
author = 'Manu Garg',
author_email = 'manugarg@gmail.com',
url = 'http://code.google.com/p/pacparser',
long_description = 'python library to parse proxy auto-config (PAC) '
'files.',
license = 'LGPL',
ext_package = 'pacparser',
ext_modules = [pacparser_module],
py_modules = ['pacparser.__init__'])
if __name__ == '__main__':
main()
pacparser-1.3.0/src/spidermonkey/ 0000775 0000000 0000000 00000000000 11632721722 0016776 5 ustar 00root root 0000000 0000000 pacparser-1.3.0/src/spidermonkey/Makefile 0000664 0000000 0000000 00000002635 11632721722 0020444 0 ustar 00root root 0000000 0000000 # Copyright (C) 2007 Manu Garg.
# Author: Manu Garg
#
# Makefile for pacparser. Please read README file included with this package
# for more information about pacparser.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# pacparser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Include config.mk to get the variable $(OBJDIR).
# We need to create $(OBJDIR) first to be able to build libjs.a alone.
ifneq ($(MAKECMDGOALS),clean)
DEPTH = js/src
include js/src/config.mk
endif
jsapi: js-buildstamp
jslib: js-buildstamp
cd js/src
find . -name "libjs.a" -exec cp {} .. \;
js-buildstamp:
mkdir -p js/src/$(OBJDIR)
CFLAGS="$(SMCFLAGS)" $(MAKE) -C js/src -f Makefile.ref libjs.a
find js/src -name "jsautocfg.h" -exec cp {} js/src \;
touch js-buildstamp
clean:
rm -rf js-buildstamp
rm -rf js
pacparser-1.3.0/src/spidermonkey/Makefile.win32 0000664 0000000 0000000 00000004437 11632721722 0021407 0 ustar 00root root 0000000 0000000 # Project: fdlibm
CC = gcc.exe
FDLIBM_SRCDIR = js/src/fdlibm
FDLIBM_OBJECTS= \
$(FDLIBM_SRCDIR)/w_sqrt.o \
$(FDLIBM_SRCDIR)/e_pow.o \
$(FDLIBM_SRCDIR)/e_sqrt.o \
$(FDLIBM_SRCDIR)/k_standard.o \
$(FDLIBM_SRCDIR)/s_atan.o \
$(FDLIBM_SRCDIR)/s_finite.o \
$(FDLIBM_SRCDIR)/s_isnan.o \
$(FDLIBM_SRCDIR)/s_matherr.o \
$(FDLIBM_SRCDIR)/s_rint.o \
$(FDLIBM_SRCDIR)/s_scalbn.o \
$(FDLIBM_SRCDIR)/w_atan2.o \
$(FDLIBM_SRCDIR)/e_atan2.o \
$(FDLIBM_SRCDIR)/s_fabs.o \
$(FDLIBM_SRCDIR)/s_copysign.o \
$(FDLIBM_SRCDIR)/w_pow.o \
$(FDLIBM_SRCDIR)/s_lib_version.o
JS_SRCDIR = js/src
JS_OBJECTS = \
$(JS_SRCDIR)/jsapi.o \
$(JS_SRCDIR)/jsarena.o \
$(JS_SRCDIR)/jsarray.o \
$(JS_SRCDIR)/jsatom.o \
$(JS_SRCDIR)/jsbool.o \
$(JS_SRCDIR)/jscntxt.o \
$(JS_SRCDIR)/jsdate.o \
$(JS_SRCDIR)/jsdbgapi.o \
$(JS_SRCDIR)/jsdhash.o \
$(JS_SRCDIR)/jsdtoa.o \
$(JS_SRCDIR)/jsemit.o \
$(JS_SRCDIR)/jsexn.o \
$(JS_SRCDIR)/jsfun.o \
$(JS_SRCDIR)/jsgc.o \
$(JS_SRCDIR)/jshash.o \
$(JS_SRCDIR)/jsiter.o \
$(JS_SRCDIR)/jsinterp.o \
$(JS_SRCDIR)/jslock.o \
$(JS_SRCDIR)/jslog2.o \
$(JS_SRCDIR)/jslong.o \
$(JS_SRCDIR)/jsmath.o \
$(JS_SRCDIR)/jsnum.o \
$(JS_SRCDIR)/jsobj.o \
$(JS_SRCDIR)/jsopcode.o \
$(JS_SRCDIR)/jsparse.o \
$(JS_SRCDIR)/jsprf.o \
$(JS_SRCDIR)/jsregexp.o \
$(JS_SRCDIR)/jsscan.o \
$(JS_SRCDIR)/jsscope.o \
$(JS_SRCDIR)/jsscript.o \
$(JS_SRCDIR)/jsstr.o \
$(JS_SRCDIR)/jsutil.o \
$(JS_SRCDIR)/jsxml.o \
$(JS_SRCDIR)/jsxdrapi.o \
$(JS_SRCDIR)/prmjtime.o
CFLAGS = -D_IEEE_LIBM -DEXPORT_JS_API -DWIN32 -D_MINGW -D_WINDOWS -DXP_WIN -s
all: js.lib fdlibm.lib
.c.o: $(CC) -c $(CFLAGS) -o $@ $(FDLIBM_SRCDIR)/$*.c
.c.o: $(CC) -c $(CFLAGS) -o $@ $(JS_SRCDIR)/$*.c
js\src\jsautokw.h: js\src\jskwgen.c
$(CC) -o jskwgen js\src\jskwgen.c
jskwgen > js\src\jsautokw.h
del jskwgen.exe
fdlibm.lib: js $(FDLIBM_OBJECTS)
ar r fdlibm.lib $(FDLIBM_OBJECTS)
ranlib fdlibm.lib
js.lib: js js\src\jsautokw.h $(JS_OBJECTS)
ar r js.lib $(JS_OBJECTS)
ranlib js.lib
js: $(wildcard js*.tar.gz)
$(error JS source directory not found. Extract $(wildcard js-*.tar.gz) tarball using tool of your choice. Possible options are 7z, WinRAR, WinZip.)
clean:
del js\src\*.o
del js\src\jsautokw.h
del js\src\fdlibm\*.o
del *.lib
pacparser-1.3.0/src/spidermonkey/install_sm.sh 0000775 0000000 0000000 00000002753 11632721722 0021511 0 ustar 00root root 0000000 0000000 #!/bin/bash -ex
#
# $Id$
# Copyright 2009 Google Inc. All Rights Reserved.
# Author: manugarg@google.com (Manu Garg)
ARCH=$(uname)
if [ "$ARCH" == "Linux" ]; then
DL_EXT="so"
fi
if [ "$ARCH" == "Darwin" ]; then
DL_EXT="dylib"
fi
function install_stuff
{
if [ $(id -u) == 0 ]; then
set -e
find . -name "libjs.${DL_EXT}" -exec install -m 644 {} /usr/local/lib/ \;
mkdir -p /usr/local/include/js
install -m 644 js/src/*.{h,tbl} /usr/local/include/js/
find . -name "*.h" -exec install -m 644 {} /usr/local/include/js/ \;
exit 0
else
echo "[Warning] Not continuing. You will need root credentials to install"\
"SM library. Please run this script again with sudo."
exit 1
fi
}
cd $(dirname $0)
# If it's already built,
if find . -name "libjs.${DL_EXT}" | grep libjs.${DL_EXT}; then
install_stuff
fi
if [ ! -e js*.tar.gz ];
then
echo -e "[Warning] SpiderMonkey source code tarball not found. Trying to"\
"download from mozilla website.\n"
if ! wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz;
then
echo -e "[FATAL] Could not download SM source code. Please download it"\
"yourself, and place it in '$(dirname $0)/' directory.\n"
cd -; exit
fi
fi
if [ ! -d js/src ]; then
tar xzf js*.tar.gz
fi
echo -e "[Note] Compiling SM...\n"
sleep 1
cd js/src; make -f Makefile.ref
if find . -name "libjs.${DL_EXT}" | grep libjs.${DL_EXT}; then
echo -e "\nCompiled successfully.\n"
# Install now.
install_stuff
fi
pacparser-1.3.0/src/spidermonkey/js-1.7.0.tar.gz 0000664 0000000 0000000 00004344447 11632721722 0021226 0 ustar 00root root 0000000 0000000 <G