////////////////////////////////////////// // // // Esempio di file WPAD.dat // // // ////////////////////////////////////////// BackupRoute="PROXY "; UseDirectForLocal=true; function MakeIPs(){ } DirectIPs=new MakeIPs(); cDirectIPs=0; function MakeNames(){ this[0]="*.home.lan"; this[1]="home.it"; this[2]="home.com"; } DirectNames=new MakeNames(); cDirectNames=3; cNodes=1; function MakeProxies(){ this[0]=new Node("webproxy.home.lan:8080",0,1.000000); } Proxies = new MakeProxies(); function Node(name, hash, load){ this.name = name; this.hash = hash; this.load = load; this.score = 0; return this; } function FindProxyForURL(url, host){ var urlhash, ibest, bestscore, list, i, j; if (UseDirectForLocal && isPlainHostName(host)) return "DIRECT"; if (cDirectNames > 0) for (i = 0; i < cDirectNames; i++) if (shExpMatch(host, DirectNames[i])) return "DIRECT"; if (cDirectIPs > 0) for (i = 0; i < cDirectIPs; i += 2) if (isInNet(host, DirectIPs[i], DirectIPs[i+1])) return "DIRECT"; urlhash = HashString(url); for (i = 0; i < cNodes; i++) Proxies[i].score = Proxies[i].load * Scramble(MakeInt(urlhash ^ Proxies[i].hash)); list = ""; for (j = 0; j < cNodes; j++) { for (bestscore = -1, i = 0; i < cNodes; i++) { if (Proxies[i].score > bestscore) { bestscore = Proxies[i].score; ibest = i; } } Proxies[ibest].score = -1; list = list + "PROXY " + Proxies[ibest].name + "; "; } list = list + BackupRoute; return list; } function HashString(url){ var h = 0; var slashes = 0; for (var i = 0; i < url.length; i++) { var c = url.charAt(i); if (c == '/') slashes++; if (slashes < 3) c = c.toLowerCase(); h += (((h & 0x1fff) << 19) | ((h >> 13) & 0x7ffff)) + CharToAscii(c); h = MakeInt(h); } return h; } function Scramble(h){ h += ((h & 0xffff) * 0x1965) + ((((h >> 16) & 0xffff) * 0x1965) << 16) + (((h & 0xffff) * 0x6253) << 16); h = MakeInt(h); h += (((h & 0x7ff) << 21) | ((h >> 11) & 0x1fffff)); return MakeInt(h); } var Chars =" !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~???????????????????????? "; function CharToAscii(c){ return Chars.indexOf(c) + 32; } function MakeInt(x){ if (x < 0) { return x + 4294967296; } else if (x >= 4294967296) { return x - 4294967296; } return x; }