Results 1 to 2 of 2

Thread: Interpretting .pac script using QScriptEngine()

  1. #1
    Join Date
    Jul 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Interpretting .pac script using QScriptEngine()

    Hi,

    I'm trying to interpret .pac script using QScriptEngine(). .pac is nothing but a javascript which is used by web browser/http client to get proxy details.

    Here is my code:

    main()
    {
    QScriptEngine engine;
    QString str, str1, str2; int i=0;
    QFile scriptFile("proxy.pac");
    bool bRes = scriptFile.open(QIODevice::ReadOnly|QIODevice::Tex t);
    str = scriptFile.readAll();// has entire code

    bRes = engine.canEvaluate(str);
    QScriptValue ctor = engine.evaluate(str);
    scriptFile.close();

    ctor = engine.evaluate("FindProxyForURL(\"/mail\", \"www.google.com\")");
    bRes = ctor.isError(); // returns true

    str1 = ctor.toString(); // returns {"ReferenceError: dnsResolve is not defined"}
    }

    Output: Please refer comments in the above code.
    It looks QScriptEngine does not have dnsResolve() method.

    Simple .pac script will look like this,

    function FindProxyForURL(url, host)
    {
    url = url.toLowerCase();
    host = host.toLowerCase();
    hostIP = dnsResolve(host);
    if (hostIP == false)
    var hostIP = "1.2.3.4";
    if (shExpMatch(host, "myhost.mycompany.com") {
    alert("AutoCache Running Info \nPAC File:" + pacname);
    }
    if (isInNet(hostIP, "221.11.22.33", "255.255.255.0")
    return "DIRECT1";
    if (shExpMatch(host, "techdomain.myhost.abcorg.com"))
    return SECONDARYPROXY;
    return MAINPROXY;
    }

    And this javascript uses mainly below mentioned functions,
    dnsResolve()
    isInNet()
    shExpMatch()
    isResolvable()
    isPlainHostName()
    dnsDomainIs()

    more info about .pac: http://en.wikipedia.org/wiki/Proxy_auto-config


    I'm sure some you have faced this problem and overcome this, if so, could you please help in this?

    Thanks in advance...

    Saravanan

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interpretting .pac script using QScriptEngine()

    Implement your own resolver function based on what Qt offers or even ignore the pac file and do the whole resolving in a native function.

Similar Threads

  1. Interpretting javascript using QScriptEngine
    By Saranakumardb in forum Qt Programming
    Replies: 8
    Last Post: 31st July 2008, 18:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.