Debian Codegraph @

src/main/java/com/github/markusbernhardt/proxy/selector/pac/PacScriptMethods.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.selector.pac;
2
3 import java.io.IOException;
4 import java.math.BigInteger;
5 import java.net.Inet4Address;
6 import java.net.Inet6Address;
7 import java.net.InetAddress;
8 import java.net.NetworkInterface;
9 import java.net.UnknownHostException;
10 import java.util.Arrays;
11 import java.util.Calendar;
12 import java.util.Collections;
13 import java.util.Comparator;
14 import java.util.Date;
15 import java.util.Enumeration;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.StringTokenizer;
20 import java.util.TimeZone;
21 import java.util.TreeMap;
22
23 import com.github.markusbernhardt.proxy.util.Logger;
24 import com.github.markusbernhardt.proxy.util.Logger.LogLevel;
25
26 /***************************************************************************
27 * Implementation of PAC JavaScript functions.
28 *
29 * @author Markus Bernhardt, Copyright 2016
30 * @author Bernd Rosstauscher, Copyright 2009
31 ***************************************************************************
32 */
33 public class PacScriptMethods implements ScriptMethods {
34
35 // TODO 30.03.2015 bros Test for IP6 compatibility
36
37 public static final String OVERRIDE_LOCAL_IP = "com.btr.proxy.pac.overrideLocalIP";
38
39 private final static String GMT = "GMT";
40
41 private final static List<String> DAYS = Collections
42 .unmodifiableList(Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"));
43
44 private final static List<String> MONTH = Collections.unmodifiableList(
45 Arrays.asList("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"));
46
47 private Calendar currentTime;
48
49 /*************************************************************************
50 * Constructor
51 ************************************************************************/
52
53 public PacScriptMethods() {
54 super();
55 }
56
57 /*************************************************************************
58 * isPlainHostName
59 *
60 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#isPlainHostName(java.lang.String)
61 ************************************************************************/
62
63 public boolean isPlainHostName(String host) {
64 return host.indexOf(".") < 0;
65 }
66
67 /*************************************************************************
68 * Tests if an URL is in a given domain.
69 *
70 * @param host
71 * is the host name from the URL.
72 * @param domain
73 * is the domain name to test the host name against.
74 * @return true if the domain of host name matches.
75 ************************************************************************/
76
77 public boolean dnsDomainIs(String host, String domain) {
78 return host.endsWith(domain);
79 }
80
81 /*************************************************************************
82 * Is true if the host name matches exactly the specified host name, or if
83 * there is no domain name part in the host name, but the unqualified host
84 * name matches.
85 *
86 * @param host
87 * the host name from the URL.
88 * @param domain
89 * fully qualified host name with domain to match against.
90 * @return true if matches else false.
91 ************************************************************************/
92
93 public boolean localHostOrDomainIs(String host, String domain) {
94 return domain.startsWith(host);
95 }
96
97 /*************************************************************************
98 * Tries to resolve the host name. Returns true if succeeds.
99 *
100 * @param host
101 * is the host name from the URL.
102 * @return true if resolvable else false.
103 ************************************************************************/
104
105 public boolean isResolvable(String host) {
106 try {
107 InetAddress.getByName(host).getHostAddress();
108 return true;
109 } catch (UnknownHostException ex) {
110 Logger.log(JavaxPacScriptParser.class, LogLevel.DEBUG, "Hostname not resolveable {0}.", host);
111 }
112 return false;
113 }
114
115 /*************************************************************************
116 * Returns true if the IP address of the host matches the specified IP
117 * address pattern. Pattern and mask specification is done the same way as
118 * for SOCKS configuration.
119 *
120 * Example: isInNet(host, "198.95.0.0", "255.255.0.0") is true if the IP
121 * address of the host matches 198.95.*.*.
122 *
123 * @param host
124 * a DNS host name, or IP address. If a host name is passed, it
125 * will be resolved into an IP address by this function.
126 * @param pattern
127 * an IP address pattern in the dot-separated format.
128 * @param mask
129 * mask for the IP address pattern informing which parts of the
130 * IP address should be matched against. 0 means ignore, 255
131 * means match.
132 * @return true if it matches else false.
133 ************************************************************************/
134
135 public boolean isInNet(String host, String pattern, String mask) {
136 host = dnsResolve(host);
137 if (host == null || host.length() == 0) {
138 return false;
139 }
140 long lhost = parseIpAddressToLong(host);
141 long lpattern = parseIpAddressToLong(pattern);
142 long lmask = parseIpAddressToLong(mask);
143 return (lhost & lmask) == lpattern;
144 }
145
146 /*************************************************************************
147 * Convert a string representation of a IP to a long.
148 *
149 * @param address
150 * to convert.
151 * @return the address as long.
152 ************************************************************************/
153
154 private long parseIpAddressToLong(String address) {
155 long result = 0;
156 String[] parts = address.split("\\.");
157 long shift = 24;
158 for (String part : parts) {
159 long lpart = Long.parseLong(part);
160
161 result |= (lpart << shift);
162 shift -= 8;
163 }
164 return result;
165 }
166
167 /*************************************************************************
168 * Resolves the given DNS host name into an IP address, and returns it in
169 * the dot separated format as a string.
170 *
171 * @param host
172 * the host to resolve.
173 * @return the resolved IP, empty string if not resolvable.
174 ************************************************************************/
175
176 public String dnsResolve(String host) {
177 try {
178 InetAddress ina = InetAddress.getByName(host);
179 return ina.getHostAddress();
180 } catch (UnknownHostException e) {
181 Logger.log(JavaxPacScriptParser.class, LogLevel.DEBUG, "DNS name not resolvable {0}.", host);
182 }
183 return "";
184 }
185
186 /*************************************************************************
187 * Returns the IP address of the host that the process is running on, as a
188 * string in the dot-separated integer format.
189 *
190 * @return an IP as string.
191 ************************************************************************/
192
193 public String myIpAddress() {
194 return getLocalAddressOfType(Inet4Address.class);
195 }
196
197 /*************************************************************************
198 * Get the current IP address of the computer. This will return the first
199 * address of the first network interface that is a "real" IP address of the
200 * given type.
201 *
202 * @param cl
203 * the type of address we are searching for.
204 * @return the address as string or "" if not found.
205 ************************************************************************/
206
207 private String getLocalAddressOfType(Class<? extends InetAddress> cl) {
208 try {
209 String overrideIP = System.getProperty(OVERRIDE_LOCAL_IP);
210 if (overrideIP != null && overrideIP.trim().length() > 0) {
211 return overrideIP.trim();
212 }
213 Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
214 while (interfaces.hasMoreElements()) {
215 NetworkInterface current = interfaces.nextElement();
216 if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
217 continue;
218 }
219 Enumeration<InetAddress> addresses = current.getInetAddresses();
220 while (addresses.hasMoreElements()) {
221 InetAddress adr = addresses.nextElement();
222 if (cl.isInstance(adr)) {
223 Logger.log(JavaxPacScriptParser.class, LogLevel.TRACE, "Local address resolved to {0}", adr);
224 return adr.getHostAddress();
225 }
226 }
227 }
228 return "";
229 } catch (IOException e) {
230 Logger.log(JavaxPacScriptParser.class, LogLevel.DEBUG, "Local address not resolvable.");
231 return "";
232 }
233 }
234
235 /*************************************************************************
236 * Returns the number of DNS domain levels (number of dots) in the host
237 * name.
238 *
239 * @param host
240 * is the host name from the URL.
241 * @return number of DNS domain levels.
242 ************************************************************************/
243
244 public int dnsDomainLevels(String host) {
245 int count = 0;
246 int startPos = 0;
247 while ((startPos = host.indexOf(".", startPos + 1)) > -1) {
248 count++;
249 }
250 return count;
251 }
252
253 /*************************************************************************
254 * Returns true if the string matches the specified shell expression.
255 * Actually, currently the patterns are shell expressions, not regular
256 * expressions.
257 *
258 * @param str
259 * is any string to compare (e.g. the URL, or the host name).
260 * @param shexp
261 * is a shell expression to compare against.
262 * @return true if the string matches, else false.
263 ************************************************************************/
264
265 public boolean shExpMatch(String str, String shexp) {
266 StringTokenizer tokenizer = new StringTokenizer(shexp, "*");
267 int startPos = 0;
268 while (tokenizer.hasMoreTokens()) {
269 String token = tokenizer.nextToken();
270 int temp = str.indexOf(token, startPos);
271
272 // Must start with first token
273 if (startPos == 0 && !shexp.startsWith("*") && temp != 0) {
274 return false;
275 }
276 // Last one ends with last token
277 if (!tokenizer.hasMoreTokens() && !shexp.endsWith("*") && !str.endsWith(token)) {
278 return false;
279 }
280
281 if (temp == -1) {
282 return false;
283 } else {
284 startPos = temp + token.length();
285 }
286 }
287
288 return true;
289 }
290
291 /*************************************************************************
292 * Only the first parameter is mandatory. Either the second, the third, or
293 * both may be left out. If only one parameter is present, the function
294 * yields a true value on the weekday that the parameter represents. If the
295 * string "GMT" is specified as a second parameter, times are taken to be in
296 * GMT, otherwise in local time zone. If both wd1 and wd2 are defined, the
297 * condition is true if the current weekday is in between those two
298 * weekdays. Bounds are inclusive. If the "GMT" parameter is specified,
299 * times are taken to be in GMT, otherwise the local time zone is used.
300 *
301 * @param wd1
302 * weekday 1 is one of SUN MON TUE WED THU FRI SAT
303 * @param wd2
304 * weekday 2 is one of SUN MON TUE WED THU FRI SAT
305 * @param gmt
306 * "GMT" for gmt time format else "undefined"
307 * @return true if current day matches the criteria.
308 ************************************************************************/
309
310 public boolean weekdayRange(String wd1, String wd2, String gmt) {
311 boolean useGmt = GMT.equalsIgnoreCase(wd2) || GMT.equalsIgnoreCase(gmt);
312 Calendar cal = getCurrentTime(useGmt);
313
314 int currentDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
315 int from = DAYS.indexOf(wd1 == null ? null : wd1.toUpperCase());
316 int to = DAYS.indexOf(wd2 == null ? null : wd2.toUpperCase());
317 if (to == -1) {
318 to = from;
319 }
320
321 if (to < from) {
322 return currentDay >= from || currentDay <= to;
323 } else {
324 return currentDay >= from && currentDay <= to;
325 }
326 }
327
328 /*************************************************************************
329 * Sets a calendar with the current time. If this is set all date and time
330 * based methods will use this calendar to determine the current time
331 * instead of the real time. This is only be used by unit tests and is not
332 * part of the public API.
333 *
334 * @param cal
335 * a Calendar to set.
336 ************************************************************************/
337
338 public void setCurrentTime(Calendar cal) {
339 this.currentTime = cal;
340 }
341
342 /*************************************************************************
343 * Gets a calendar set to the current time. This is used by the date and
344 * time based methods.
345 *
346 * @param useGmt
347 * flag to indicate if the calendar is to be created in GMT time
348 * or local time.
349 * @return a Calendar set to the current time.
350 ************************************************************************/
351
352 private Calendar getCurrentTime(boolean useGmt) {
353 if (this.currentTime != null) { // Only used for unit tests
354 return (Calendar) this.currentTime.clone();
355 }
356 return Calendar.getInstance(useGmt ? TimeZone.getTimeZone(GMT) : TimeZone.getDefault());
357 }
358
359 /*************************************************************************
360 * Only the first parameter is mandatory. All other parameters can be left
361 * out therefore the meaning of the parameters changes. The method
362 * definition shows the version with the most possible parameters filled.
363 * The real meaning of the parameters is guessed from it's value. If "from"
364 * and "to" are specified then the bounds are inclusive. If the "GMT"
365 * parameter is specified, times are taken to be in GMT, otherwise the local
366 * time zone is used.
367 *
368 * @param day1
369 * is the day of month between 1 and 31 (as an integer).
370 * @param month1
371 * one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
372 * @param year1
373 * is the full year number, for example 1995 (but not 95).
374 * Integer.
375 * @param day2
376 * is the day of month between 1 and 31 (as an integer).
377 * @param month2
378 * one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
379 * @param year2
380 * is the full year number, for example 1995 (but not 95).
381 * Integer.
382 * @param gmt
383 * "GMT" for gmt time format else "undefined"
384 * @return true if the current date matches the given range.
385 ************************************************************************/
386
387 public boolean dateRange(Object day1, Object month1, Object year1, Object day2, Object month2, Object year2,
388 Object gmt) {
389
390 // Guess the parameter meanings.
391 Map<String, Integer> params = new HashMap<String, Integer>();
392 parseDateParam(params, day1);
393 parseDateParam(params, month1);
394 parseDateParam(params, year1);
395 parseDateParam(params, day2);
396 parseDateParam(params, month2);
397 parseDateParam(params, year2);
398 parseDateParam(params, gmt);
399
400 // Get current date
401 boolean useGmt = params.get("gmt") != null;
402 Calendar cal = getCurrentTime(useGmt);
403 Date current = cal.getTime();
404
405 // Build the "from" date
406 if (params.get("day1") != null) {
407 cal.set(Calendar.DAY_OF_MONTH, params.get("day1"));
408 }
409 if (params.get("month1") != null) {
410 cal.set(Calendar.MONTH, params.get("month1"));
411 }
412 if (params.get("year1") != null) {
413 cal.set(Calendar.YEAR, params.get("year1"));
414 }
415 Date from = cal.getTime();
416
417 // Build the "to" date
418 Date to;
419 if (params.get("day2") != null) {
420 cal.set(Calendar.DAY_OF_MONTH, params.get("day2"));
421 }
422 if (params.get("month2") != null) {
423 cal.set(Calendar.MONTH, params.get("month2"));
424 }
425 if (params.get("year2") != null) {
426 cal.set(Calendar.YEAR, params.get("year2"));
427 }
428 to = cal.getTime();
429
430 // Need to increment to the next month?
431 if (to.before(from)) {
432 cal.add(Calendar.MONTH, +1);
433 to = cal.getTime();
434 }
435 // Need to increment to the next year?
436 if (to.before(from)) {
437 cal.add(Calendar.YEAR, +1);
438 cal.add(Calendar.MONTH, -1);
439 to = cal.getTime();
440 }
441
442 return current.compareTo(from) >= 0 && current.compareTo(to) <= 0;
443 }
444
445 /*************************************************************************
446 * Try to guess the type of the given parameter and put it into the params
447 * map.
448 *
449 * @param params
450 * a map to put the parsed parameters into.
451 * @param value
452 * to parse and specify the type for.
453 ************************************************************************/
454
455 private void parseDateParam(Map<String, Integer> params, Object value) {
456 if (value instanceof Number) {
457 int n = ((Number) value).intValue();
458 if (n <= 31) {
459 // Its a day
460 if (params.get("day1") == null) {
461 params.put("day1", n);
462 } else {
463 params.put("day2", n);
464 }
465 } else {
466 // Its a year
467 if (params.get("year1") == null) {
468 params.put("year1", n);
469 } else {
470 params.put("year2", n);
471 }
472 }
473 }
474
475 if (value instanceof String) {
476 int n = MONTH.indexOf(((String) value).toUpperCase());
477 if (n > -1) {
478 // Its a month
479 if (params.get("month1") == null) {
480 params.put("month1", n);
481 } else {
482 params.put("month2", n);
483 }
484 }
485 }
486
487 if (GMT.equalsIgnoreCase(String.valueOf(value))) {
488 params.put("gmt", 1);
489 }
490 }
491
492 /*************************************************************************
493 * Some parameters can be left out therefore the meaning of the parameters
494 * changes. The method definition shows the version with the most possible
495 * parameters filled. The real meaning of the parameters is guessed from
496 * it's value. If "from" and "to" are specified then the bounds are
497 * inclusive. If the "GMT" parameter is specified, times are taken to be in
498 * GMT, otherwise the local time zone is used.<br>
499 *
500 * <pre>
501 * timeRange(hour)
502 * timeRange(hour1, hour2)
503 * timeRange(hour1, min1, hour2, min2)
504 * timeRange(hour1, min1, sec1, hour2, min2, sec2)
505 * timeRange(hour1, min1, sec1, hour2, min2, sec2, gmt)
506 * </pre>
507 *
508 * @param hour1
509 * is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.)
510 * @param min1
511 * minutes from 0 to 59.
512 * @param sec1
513 * seconds from 0 to 59.
514 * @param hour2
515 * is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.)
516 * @param min2
517 * minutes from 0 to 59.
518 * @param sec2
519 * seconds from 0 to 59.
520 * @param gmt
521 * "GMT" for gmt time format else "undefined"
522 * @return true if the current time matches the given range.
523 ************************************************************************/
524
525 public boolean timeRange(Object hour1, Object min1, Object sec1, Object hour2, Object min2, Object sec2,
526 Object gmt) {
527 boolean useGmt = GMT.equalsIgnoreCase(String.valueOf(min1)) || GMT.equalsIgnoreCase(String.valueOf(sec1))
528 || GMT.equalsIgnoreCase(String.valueOf(min2)) || GMT.equalsIgnoreCase(String.valueOf(gmt));
529
530 Calendar cal = getCurrentTime(useGmt);
531 cal.set(Calendar.MILLISECOND, 0);
532 Date current = cal.getTime();
533 Date from;
534 Date to;
535 if (sec2 instanceof Number) {
536 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour1).intValue());
537 cal.set(Calendar.MINUTE, ((Number) min1).intValue());
538 cal.set(Calendar.SECOND, ((Number) sec1).intValue());
539 from = cal.getTime();
540
541 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour2).intValue());
542 cal.set(Calendar.MINUTE, ((Number) min2).intValue());
543 cal.set(Calendar.SECOND, ((Number) sec2).intValue());
544 to = cal.getTime();
545 } else if (hour2 instanceof Number) {
546 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour1).intValue());
547 cal.set(Calendar.MINUTE, ((Number) min1).intValue());
548 cal.set(Calendar.SECOND, 0);
549 from = cal.getTime();
550
551 cal.set(Calendar.HOUR_OF_DAY, ((Number) sec1).intValue());
552 cal.set(Calendar.MINUTE, ((Number) hour2).intValue());
553 cal.set(Calendar.SECOND, 59);
554 to = cal.getTime();
555 } else if (min1 instanceof Number) {
556 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour1).intValue());
557 cal.set(Calendar.MINUTE, 0);
558 cal.set(Calendar.SECOND, 0);
559 from = cal.getTime();
560
561 cal.set(Calendar.HOUR_OF_DAY, ((Number) min1).intValue());
562 cal.set(Calendar.MINUTE, 59);
563 cal.set(Calendar.SECOND, 59);
564 to = cal.getTime();
565 } else {
566 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour1).intValue());
567 cal.set(Calendar.MINUTE, 0);
568 cal.set(Calendar.SECOND, 0);
569 from = cal.getTime();
570
571 cal.set(Calendar.HOUR_OF_DAY, ((Number) hour1).intValue());
572 cal.set(Calendar.MINUTE, 59);
573 cal.set(Calendar.SECOND, 59);
574 to = cal.getTime();
575 }
576
577 if (to.before(from)) {
578 cal.setTime(to);
579 cal.add(Calendar.DATE, +1);
580 to = cal.getTime();
581 }
582
583 return current.compareTo(from) >= 0 && current.compareTo(to) <= 0;
584 }
585
586 // Microsoft PAC extensions for IPv6 support.
587
588 /*************************************************************************
589 * isResolvableEx
590 *
591 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#isResolvableEx(java.lang.String)
592 ************************************************************************/
593
594 public boolean isResolvableEx(String host) {
595 return isResolvable(host);
596 }
597
598 // constants
599 private static final BigInteger HIGH_32_INT = new BigInteger(new byte[] { -1, -1, -1, -1 });
600 private static final BigInteger HIGH_128_INT = new BigInteger(
601 new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 });
602
603 /*************************************************************************
604 * isInNetEx Implementation from
605 * http://fhanik.blogspot.ch/2013/11/ip-magic-check-if-ipv6-address-is.html
606 *
607 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#isInNetEx(java.lang.String,
608 * java.lang.String)
609 ************************************************************************/
610
611 public boolean isInNetEx(String ipOrHost, String cidr) {
612 if (ipOrHost == null || ipOrHost.length() == 0 || cidr == null || cidr.length() == 0) {
613 return false;
614 }
615
616 try {
617 // Split CIDR, usually written like 2000::/64"
618 String[] cidrParts = cidr.split("/");
619 if (cidrParts.length != 2) {
620 return false;
621 }
622 String cidrRange = cidrParts[0];
623 int cidrBits = Integer.parseInt(cidrParts[1]);
624
625 byte[] addressBytes = InetAddress.getByName(ipOrHost).getAddress();
626 BigInteger ip = new BigInteger(addressBytes);
627 BigInteger mask = addressBytes.length == 4 ? HIGH_32_INT.shiftLeft(32 - cidrBits)
628 : HIGH_128_INT.shiftLeft(128 - cidrBits);
629
630 byte[] rangeBytes = InetAddress.getByName(cidrRange).getAddress();
631 BigInteger range = new BigInteger(rangeBytes);
632 BigInteger lowIP = range.and(mask);
633 BigInteger highIP = lowIP.add(mask.not());
634
635 return lowIP.compareTo(ip) <= 0 && highIP.compareTo(ip) >= 0;
636 } catch (UnknownHostException e) {
637 return false;
638 }
639 }
640
641 /*************************************************************************
642 * dnsResolveEx
643 *
644 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#dnsResolveEx(java.lang.String)
645 ************************************************************************/
646
647 public String dnsResolveEx(String host) {
648 StringBuilder result = new StringBuilder();
649 try {
650 InetAddress[] list = InetAddress.getAllByName(host);
651 for (InetAddress inetAddress : list) {
652 result.append(inetAddress.getHostAddress());
653 result.append("; ");
654 }
655 } catch (UnknownHostException e) {
656 Logger.log(JavaxPacScriptParser.class, LogLevel.DEBUG, "DNS name not resolvable {0}.", host);
657 }
658 return result.toString();
659 }
660
661 /*************************************************************************
662 * myIpAddressEx
663 *
664 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#myIpAddressEx()
665 ************************************************************************/
666
667 public String myIpAddressEx() {
668 return getLocalAddressOfType(Inet6Address.class);
669 }
670
671 /*************************************************************************
672 * sortIpAddressList
673 *
674 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#sortIpAddressList(java.lang.String)
675 ************************************************************************/
676
677 public String sortIpAddressList(String ipAddressList) {
678 if (ipAddressList == null || ipAddressList.trim().length() == 0) {
679 return "";
680 }
681 try {
682 String[] ipAddressToken = ipAddressList.split(";");
683 TreeMap<byte[], String> sorting = new TreeMap<byte[], String>(new Comparator<byte[]>() {
684 public int compare(byte[] b1, byte[] b2) {
685 if (b1.length != b2.length) {
686 return b2.length - b1.length;
687 }
688 return new BigInteger(b1).compareTo(new BigInteger(b2));
689 }
690 });
691
692 for (String ip : ipAddressToken) {
693 String cleanIP = ip.trim();
694 sorting.put(InetAddress.getByName(cleanIP).getAddress(), cleanIP);
695 }
696
697 StringBuilder result = new StringBuilder();
698 for (String ip : sorting.values()) {
699 if (result.length() > 0) {
700 result.append(";");
701 }
702 result.append(ip);
703 }
704 return result.toString();
705 } catch (Exception e) {
706 Logger.log(JavaxPacScriptParser.class, LogLevel.DEBUG, "Cannot sort invalid IP list: {0}.", ipAddressList);
707 return "";
708 }
709 }
710
711 /*************************************************************************
712 * getClientVersion
713 *
714 * @see com.github.markusbernhardt.proxy.selector.pac.ScriptMethods#getClientVersion()
715 ************************************************************************/
716
717 public String getClientVersion() {
718 return "1.0";
719 }
720
721 }