Saranakumardb
27th August 2008, 00:01
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
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