| 1 | package com.github.markusbernhardt.proxy.selector.pac; |
| 2 | |
| 3 | /*************************************************************************** |
| 4 | * Defines the public interface for PAC scripts. |
| 5 | * |
| 6 | * @author Markus Bernhardt, Copyright 2016 |
| 7 | * @author Bernd Rosstauscher, Copyright 2009 |
| 8 | ***************************************************************************/ |
| 9 | public interface ScriptMethods { |
| 10 | |
| 11 | public boolean isPlainHostName(String host); |
| 12 | |
| 13 | /************************************************************************* |
| 14 | * Tests if an URL is in a given domain. |
| 15 | * |
| 16 | * @param host |
| 17 | * is the host name from the URL. |
| 18 | * @param domain |
| 19 | * is the domain name to test the host name against. |
| 20 | * @return true if the domain of host name matches. |
| 21 | ************************************************************************/ |
| 22 | |
| 23 | public boolean dnsDomainIs(String host, String domain); |
| 24 | |
| 25 | /************************************************************************* |
| 26 | * Is true if the host name matches exactly the specified host name, or if |
| 27 | * there is no domain name part in the host name, but the unqualified host |
| 28 | * name matches. |
| 29 | * |
| 30 | * @param host |
| 31 | * the host name from the URL. |
| 32 | * @param domain |
| 33 | * fully qualified host name with domain to match against. |
| 34 | * @return true if matches else false. |
| 35 | ************************************************************************/ |
| 36 | |
| 37 | public boolean localHostOrDomainIs(String host, String domain); |
| 38 | |
| 39 | /************************************************************************* |
| 40 | * Tries to resolve the host name. Returns true if succeeds. |
| 41 | * |
| 42 | * @param host |
| 43 | * is the host name from the URL. |
| 44 | * @return true if resolvable else false. |
| 45 | ************************************************************************/ |
| 46 | |
| 47 | public boolean isResolvable(String host); |
| 48 | |
| 49 | /************************************************************************* |
| 50 | * Tries to resolve the host name. Returns true if succeeds to resolve the |
| 51 | * host to an IPv4 or IPv6 address. |
| 52 | * |
| 53 | * @param host |
| 54 | * is the host name from the URL. |
| 55 | * @return true if resolvable else false. |
| 56 | ************************************************************************/ |
| 57 | |
| 58 | public boolean isResolvableEx(String host); |
| 59 | |
| 60 | /************************************************************************* |
| 61 | * Returns true if the IP address of the host matches the specified IP |
| 62 | * address pattern. Pattern and mask specification is done the same way as |
| 63 | * for SOCKS configuration. |
| 64 | * |
| 65 | * Example: isInNet(host, "198.95.0.0", "255.255.0.0") is true if the IP |
| 66 | * address of the host matches 198.95.*.*. |
| 67 | * |
| 68 | * @param host |
| 69 | * a DNS host name, or IP address. If a host name is passed, it |
| 70 | * will be resolved into an IP address by this function. |
| 71 | * @param pattern |
| 72 | * an IP address pattern in the dot-separated format. |
| 73 | * @param mask |
| 74 | * mask for the IP address pattern informing which parts of the |
| 75 | * IP address should be matched against. 0 means ignore, 255 |
| 76 | * means match. |
| 77 | * @return true if it matches else false. |
| 78 | ************************************************************************/ |
| 79 | |
| 80 | public boolean isInNet(String host, String pattern, String mask); |
| 81 | |
| 82 | /************************************************************************* |
| 83 | * Extension of the isInNet method to support IPv6. |
| 84 | * |
| 85 | * @param ipAddress |
| 86 | * an IP4 or IP6 address |
| 87 | * @param ipPrefix |
| 88 | * A string containing colon delimited IP prefix with top n bits |
| 89 | * specified in the bit field (i.e. 3ffe:8311:ffff::/48 or |
| 90 | * 123.112.0.0/16). |
| 91 | * @return true if the host is in the given subnet, else false. |
| 92 | ************************************************************************/ |
| 93 | |
| 94 | public boolean isInNetEx(String ipAddress, String ipPrefix); |
| 95 | |
| 96 | /************************************************************************* |
| 97 | * Resolves the given DNS host name into an IP address, and returns it in |
| 98 | * the dot separated format as a string. |
| 99 | * |
| 100 | * @param host |
| 101 | * the host to resolve. |
| 102 | * @return the resolved IP, empty string if not resolvable. |
| 103 | ************************************************************************/ |
| 104 | |
| 105 | public String dnsResolve(String host); |
| 106 | |
| 107 | /************************************************************************* |
| 108 | * @param host |
| 109 | * the host to resolve |
| 110 | * @return a semicolon separated list of IP6 and IP4 addresses the host name |
| 111 | * resolves to, empty string if not resolvable. |
| 112 | ************************************************************************/ |
| 113 | |
| 114 | public String dnsResolveEx(String host); |
| 115 | |
| 116 | /************************************************************************* |
| 117 | * Returns the IP address of the host that the process is running on, as a |
| 118 | * string in the dot-separated integer format. |
| 119 | * |
| 120 | * @return an IP as string. |
| 121 | ************************************************************************/ |
| 122 | |
| 123 | public String myIpAddress(); |
| 124 | |
| 125 | /************************************************************************* |
| 126 | * Returns a list of IP4 and IP6 addresses of the host that the process is |
| 127 | * running on. The list is separated with semicolons. |
| 128 | * |
| 129 | * @return the list, empty string if not available. |
| 130 | ************************************************************************/ |
| 131 | |
| 132 | public String myIpAddressEx(); |
| 133 | |
| 134 | /************************************************************************* |
| 135 | * Returns the number of DNS domain levels (number of dots) in the host |
| 136 | * name. |
| 137 | * |
| 138 | * @param host |
| 139 | * is the host name from the URL. |
| 140 | * @return number of DNS domain levels. |
| 141 | ************************************************************************/ |
| 142 | |
| 143 | public int dnsDomainLevels(String host); |
| 144 | |
| 145 | /************************************************************************* |
| 146 | * Returns true if the string matches the specified shell expression. |
| 147 | * Actually, currently the patterns are shell expressions, not regular |
| 148 | * expressions. |
| 149 | * |
| 150 | * @param str |
| 151 | * is any string to compare (e.g. the URL, or the host name). |
| 152 | * @param shexp |
| 153 | * is a shell expression to compare against. |
| 154 | * @return true if the string matches, else false. |
| 155 | ************************************************************************/ |
| 156 | |
| 157 | public boolean shExpMatch(String str, String shexp); |
| 158 | |
| 159 | /************************************************************************* |
| 160 | * Only the first parameter is mandatory. Either the second, the third, or |
| 161 | * both may be left out. If only one parameter is present, the function |
| 162 | * yields a true value on the weekday that the parameter represents. If the |
| 163 | * string "GMT" is specified as a second parameter, times are taken to be in |
| 164 | * GMT, otherwise in local time zone. If both wd1 and wd2 are defined, the |
| 165 | * condition is true if the current weekday is in between those two |
| 166 | * weekdays. Bounds are inclusive. If the "GMT" parameter is specified, |
| 167 | * times are taken to be in GMT, otherwise the local time zone is used. |
| 168 | * |
| 169 | * @param wd1 |
| 170 | * weekday 1 is one of SUN MON TUE WED THU FRI SAT |
| 171 | * @param wd2 |
| 172 | * weekday 2 is one of SUN MON TUE WED THU FRI SAT |
| 173 | * @param gmt |
| 174 | * "GMT" for gmt time format else "undefined" |
| 175 | * @return true if current day matches the criteria. |
| 176 | ************************************************************************/ |
| 177 | |
| 178 | public boolean weekdayRange(String wd1, String wd2, String gmt); |
| 179 | |
| 180 | /************************************************************************* |
| 181 | * Only the first parameter is mandatory. All other parameters can be left |
| 182 | * out therefore the meaning of the parameters changes. The method |
| 183 | * definition shows the version with the most possible parameters filled. |
| 184 | * The real meaning of the parameters is guessed from it's value. If "from" |
| 185 | * and "to" are specified then the bounds are inclusive. If the "GMT" |
| 186 | * parameter is specified, times are taken to be in GMT, otherwise the local |
| 187 | * time zone is used. |
| 188 | * |
| 189 | * @param day1 |
| 190 | * is the day of month between 1 and 31 (as an integer). |
| 191 | * @param month1 |
| 192 | * one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC |
| 193 | * @param year1 |
| 194 | * is the full year number, for example 1995 (but not 95). |
| 195 | * Integer. |
| 196 | * @param day2 |
| 197 | * is the day of month between 1 and 31 (as an integer). |
| 198 | * @param month2 |
| 199 | * one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC |
| 200 | * @param year2 |
| 201 | * is the full year number, for example 1995 (but not 95). |
| 202 | * Integer. |
| 203 | * @param gmt |
| 204 | * "GMT" for gmt time format else "undefined" |
| 205 | * @return true if the current date matches the given range. |
| 206 | ************************************************************************/ |
| 207 | |
| 208 | public boolean dateRange(Object day1, Object month1, Object year1, Object day2, Object month2, Object year2, |
| 209 | Object gmt); |
| 210 | |
| 211 | /************************************************************************* |
| 212 | * Some parameters can be left out therefore the meaning of the parameters |
| 213 | * changes. The method definition shows the version with the most possible |
| 214 | * parameters filled. The real meaning of the parameters is guessed from |
| 215 | * it's value. If "from" and "to" are specified then the bounds are |
| 216 | * inclusive. If the "GMT" parameter is specified, times are taken to be in |
| 217 | * GMT, otherwise the local time zone is used.<br> |
| 218 | * |
| 219 | * <pre> |
| 220 | * timeRange(hour) |
| 221 | * timeRange(hour1, hour2) |
| 222 | * timeRange(hour1, min1, hour2, min2) |
| 223 | * timeRange(hour1, min1, sec1, hour2, min2, sec2) |
| 224 | * timeRange(hour1, min1, sec1, hour2, min2, sec2, gmt) |
| 225 | * </pre> |
| 226 | * |
| 227 | * @param hour1 |
| 228 | * is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.) |
| 229 | * @param min1 |
| 230 | * minutes from 0 to 59. |
| 231 | * @param sec1 |
| 232 | * seconds from 0 to 59. |
| 233 | * @param hour2 |
| 234 | * is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.) |
| 235 | * @param min2 |
| 236 | * minutes from 0 to 59. |
| 237 | * @param sec2 |
| 238 | * seconds from 0 to 59. |
| 239 | * @param gmt |
| 240 | * "GMT" for gmt time format else "undefined" |
| 241 | * @return true if the current time matches the given range. |
| 242 | ************************************************************************/ |
| 243 | |
| 244 | public boolean timeRange(Object hour1, Object min1, Object sec1, Object hour2, Object min2, Object sec2, |
| 245 | Object gmt); |
| 246 | |
| 247 | /************************************************************************* |
| 248 | * Sorts a list of IP4 and IP6 addresses. Separated by semicolon. Dual |
| 249 | * addresses first, then IPv6 and last IPv4. |
| 250 | * |
| 251 | * @param ipAddressList |
| 252 | * the address list. |
| 253 | * @return the sorted list, empty string if sort is not possible |
| 254 | ************************************************************************/ |
| 255 | |
| 256 | public String sortIpAddressList(String ipAddressList); |
| 257 | |
| 258 | /************************************************************************* |
| 259 | * Gets the version of the PAC extension that is available. |
| 260 | * |
| 261 | * @return the extension version, currently 1.0 |
| 262 | ************************************************************************/ |
| 263 | |
| 264 | public String getClientVersion(); |
| 265 | |
| 266 | } |