My favorites | Sign in
Project Logo
                
Search
for
Updated Dec 10, 2009 by manugarg
Labels: Featured, UserDoc
pacparserUsageGuide  
pacparser usage guide, how and when to call various functions

Using pacparser in C

Determining proxy string for a set of PAC file, URL and host is as easy as:

#include <pacparser.h>
char *proxystring = pacparser_just_find_proxy("examples/wpad.dat",
                                              "http://www.manugarg.com",
                                              "www.manugarg.com")

This function initializes javascript context, loads pac file, determines proxy and finally destroys javascript context.

As you can see, if you want to find out proxy string for multiple URLs, this is not the recommended method. In that case, you first

  1. initialize pac parser engine:
  2. #include <pacparser.h>
    pacparser_init()
  3. and then, parse pac file:
  4. if(!pacparser_parse_pac("examples/wpad.dat")){
      error("could not parse pac file");
    }
  5. determine proxy string for a URL:
  6. char *proxystring = pacparser_find_proxy("http://www.manugarg.com", "www.manugarg.com");
  7. do other things and find proxy for another URL:
  8. ...
    proxystring = pacparser_find_proxy("http://www.google.com", "www.google.com");
  9. do some other things and in the end shutdown pacparser engine:
  10. ...
    pacparser_cleanup()

Using pacparser in Python:

pacparser comes as a python module also. It can be imported in python programs like any other python module.

import pacparser
pacparser.init()
pacparser.parse_pac("examples/wpad.dat")
proxy = pacparser.find_proxy("http://www.manugarg.com",
                                  "www.manugarg.com")
print proxy
pacparser.cleanup()

or, simply just

import pacparser
print pacparser.just_find_proxy("examples/wpad.dat",
               "http://www.manugarg.com", "www.manugarg.com")

Functions Reference


Sign in to add a comment
Hosted by Google Code