Class PacScriptMethods

  • All Implemented Interfaces:
    ScriptMethods

    public class PacScriptMethods
    extends java.lang.Object
    implements ScriptMethods
    Implementation of PAC JavaScript functions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String OVERRIDE_LOCAL_IP  
    • Constructor Summary

      Constructors 
      Constructor Description
      PacScriptMethods()
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean dateRange​(java.lang.Object day1, java.lang.Object month1, java.lang.Object year1, java.lang.Object day2, java.lang.Object month2, java.lang.Object year2, java.lang.Object gmt)
      Only the first parameter is mandatory.
      boolean dnsDomainIs​(java.lang.String host, java.lang.String domain)
      Tests if an URL is in a given domain.
      int dnsDomainLevels​(java.lang.String host)
      Returns the number of DNS domain levels (number of dots) in the host name.
      java.lang.String dnsResolve​(java.lang.String host)
      Resolves the given DNS host name into an IP address, and returns it in the dot separated format as a string.
      java.lang.String dnsResolveEx​(java.lang.String host)
      dnsResolveEx
      java.lang.String getClientVersion()
      getClientVersion
      boolean isInNet​(java.lang.String host, java.lang.String pattern, java.lang.String mask)
      Returns true if the IP address of the host matches the specified IP address pattern.
      boolean isInNetEx​(java.lang.String ipAddress, java.lang.String ipPrefix)
      isInNetEx
      boolean isPlainHostName​(java.lang.String host)
      isPlainHostName
      boolean isResolvable​(java.lang.String host)
      Tries to resolve the host name.
      boolean isResolvableEx​(java.lang.String host)
      isResolvableEx
      boolean localHostOrDomainIs​(java.lang.String host, java.lang.String domain)
      Is true if the host name matches exactly the specified host name, or if there is no domain name part in the host name, but the unqualified host name matches.
      java.lang.String myIpAddress()
      Returns the IP address of the host that the process is running on, as a string in the dot-separated integer format.
      java.lang.String myIpAddressEx()
      myIpAddressEx
      void setCurrentTime​(java.util.Calendar cal)
      Sets a calendar with the current time.
      boolean shExpMatch​(java.lang.String str, java.lang.String shexp)
      Returns true if the string matches the specified shell expression.
      java.lang.String sortIpAddressList​(java.lang.String ipAddressList)
      sortIpAddressList
      boolean timeRange​(java.lang.Object hour1, java.lang.Object min1, java.lang.Object sec1, java.lang.Object hour2, java.lang.Object min2, java.lang.Object sec2, java.lang.Object gmt)
      Some parameters can be left out therefore the meaning of the parameters changes.
      boolean weekdayRange​(java.lang.String wd1, java.lang.String wd2, java.lang.String gmt)
      Only the first parameter is mandatory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OVERRIDE_LOCAL_IP

        public static final java.lang.String OVERRIDE_LOCAL_IP
        See Also:
        Constant Field Values
    • Constructor Detail

      • PacScriptMethods

        public PacScriptMethods()
        Constructor
    • Method Detail

      • isPlainHostName

        public boolean isPlainHostName​(java.lang.String host)
        isPlainHostName
        Specified by:
        isPlainHostName in interface ScriptMethods
        See Also:
        com.btr.proxy.selector.pac.ScriptMethods#isPlainHostName(java.lang.String)
      • dnsDomainIs

        public boolean dnsDomainIs​(java.lang.String host,
                                   java.lang.String domain)
        Tests if an URL is in a given domain.
        Specified by:
        dnsDomainIs in interface ScriptMethods
        Parameters:
        host - is the host name from the URL.
        domain - is the domain name to test the host name against.
        Returns:
        true if the domain of host name matches.
      • localHostOrDomainIs

        public boolean localHostOrDomainIs​(java.lang.String host,
                                           java.lang.String domain)
        Is true if the host name matches exactly the specified host name, or if there is no domain name part in the host name, but the unqualified host name matches.
        Specified by:
        localHostOrDomainIs in interface ScriptMethods
        Parameters:
        host - the host name from the URL.
        domain - fully qualified host name with domain to match against.
        Returns:
        true if matches else false.
      • isResolvable

        public boolean isResolvable​(java.lang.String host)
        Tries to resolve the host name. Returns true if succeeds.
        Specified by:
        isResolvable in interface ScriptMethods
        Parameters:
        host - is the host name from the URL.
        Returns:
        true if resolvable else false.
      • isInNet

        public boolean isInNet​(java.lang.String host,
                               java.lang.String pattern,
                               java.lang.String mask)
        Returns true if the IP address of the host matches the specified IP address pattern. Pattern and mask specification is done the same way as for SOCKS configuration. Example: isInNet(host, "198.95.0.0", "255.255.0.0") is true if the IP address of the host matches 198.95.*.*.
        Specified by:
        isInNet in interface ScriptMethods
        Parameters:
        host - a DNS host name, or IP address. If a host name is passed, it will be resolved into an IP address by this function.
        pattern - an IP address pattern in the dot-separated format.
        mask - mask for the IP address pattern informing which parts of the IP address should be matched against. 0 means ignore, 255 means match.
        Returns:
        true if it matches else false.
      • dnsResolve

        public java.lang.String dnsResolve​(java.lang.String host)
        Resolves the given DNS host name into an IP address, and returns it in the dot separated format as a string.
        Specified by:
        dnsResolve in interface ScriptMethods
        Parameters:
        host - the host to resolve.
        Returns:
        the resolved IP, empty string if not resolvable.
      • myIpAddress

        public java.lang.String myIpAddress()
        Returns the IP address of the host that the process is running on, as a string in the dot-separated integer format.
        Specified by:
        myIpAddress in interface ScriptMethods
        Returns:
        an IP as string.
      • dnsDomainLevels

        public int dnsDomainLevels​(java.lang.String host)
        Returns the number of DNS domain levels (number of dots) in the host name.
        Specified by:
        dnsDomainLevels in interface ScriptMethods
        Parameters:
        host - is the host name from the URL.
        Returns:
        number of DNS domain levels.
      • shExpMatch

        public boolean shExpMatch​(java.lang.String str,
                                  java.lang.String shexp)
        Returns true if the string matches the specified shell expression. Actually, currently the patterns are shell expressions, not regular expressions.
        Specified by:
        shExpMatch in interface ScriptMethods
        Parameters:
        str - is any string to compare (e.g. the URL, or the host name).
        shexp - is a shell expression to compare against.
        Returns:
        true if the string matches, else false.
      • weekdayRange

        public boolean weekdayRange​(java.lang.String wd1,
                                    java.lang.String wd2,
                                    java.lang.String gmt)
        Only the first parameter is mandatory. Either the second, the third, or both may be left out. If only one parameter is present, the function yields a true value on the weekday that the parameter represents. If the string "GMT" is specified as a second parameter, times are taken to be in GMT, otherwise in local time zone. If both wd1 and wd2 are defined, the condition is true if the current weekday is in between those two weekdays. Bounds are inclusive. If the "GMT" parameter is specified, times are taken to be in GMT, otherwise the local time zone is used.
        Specified by:
        weekdayRange in interface ScriptMethods
        Parameters:
        wd1 - weekday 1 is one of SUN MON TUE WED THU FRI SAT
        wd2 - weekday 2 is one of SUN MON TUE WED THU FRI SAT
        gmt - "GMT" for gmt time format else "undefined"
        Returns:
        true if current day matches the criteria.
      • setCurrentTime

        public void setCurrentTime​(java.util.Calendar cal)
        Sets a calendar with the current time. If this is set all date and time based methods will use this calendar to determine the current time instead of the real time. This is only be used by unit tests and is not part of the public API.
        Parameters:
        cal - a Calendar to set.
      • dateRange

        public boolean dateRange​(java.lang.Object day1,
                                 java.lang.Object month1,
                                 java.lang.Object year1,
                                 java.lang.Object day2,
                                 java.lang.Object month2,
                                 java.lang.Object year2,
                                 java.lang.Object gmt)
        Only the first parameter is mandatory. All other parameters can be left out therefore the meaning of the parameters changes. The method definition shows the version with the most possible parameters filled. The real meaning of the parameters is guessed from it's value. If "from" and "to" are specified then the bounds are inclusive. If the "GMT" parameter is specified, times are taken to be in GMT, otherwise the local time zone is used.
        Specified by:
        dateRange in interface ScriptMethods
        Parameters:
        day1 - is the day of month between 1 and 31 (as an integer).
        month1 - one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
        year1 - is the full year number, for example 1995 (but not 95). Integer.
        day2 - is the day of month between 1 and 31 (as an integer).
        month2 - one of JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
        year2 - is the full year number, for example 1995 (but not 95). Integer.
        gmt - "GMT" for gmt time format else "undefined"
        Returns:
        true if the current date matches the given range.
      • timeRange

        public boolean timeRange​(java.lang.Object hour1,
                                 java.lang.Object min1,
                                 java.lang.Object sec1,
                                 java.lang.Object hour2,
                                 java.lang.Object min2,
                                 java.lang.Object sec2,
                                 java.lang.Object gmt)
        Some parameters can be left out therefore the meaning of the parameters changes. The method definition shows the version with the most possible parameters filled. The real meaning of the parameters is guessed from it's value. If "from" and "to" are specified then the bounds are inclusive. If the "GMT" parameter is specified, times are taken to be in GMT, otherwise the local time zone is used.
         timeRange(hour)
         timeRange(hour1, hour2)
         timeRange(hour1, min1, hour2, min2)
         timeRange(hour1, min1, sec1, hour2, min2, sec2)
         timeRange(hour1, min1, sec1, hour2, min2, sec2, gmt)
         
        Specified by:
        timeRange in interface ScriptMethods
        Parameters:
        hour1 - is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.)
        min1 - minutes from 0 to 59.
        sec1 - seconds from 0 to 59.
        hour2 - is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.)
        min2 - minutes from 0 to 59.
        sec2 - seconds from 0 to 59.
        gmt - "GMT" for gmt time format else "undefined"
        Returns:
        true if the current time matches the given range.
      • isResolvableEx

        public boolean isResolvableEx​(java.lang.String host)
        isResolvableEx
        Specified by:
        isResolvableEx in interface ScriptMethods
        Parameters:
        host - is the host name from the URL.
        Returns:
        true if resolvable else false.
      • isInNetEx

        public boolean isInNetEx​(java.lang.String ipAddress,
                                 java.lang.String ipPrefix)
        isInNetEx
        Specified by:
        isInNetEx in interface ScriptMethods
        Parameters:
        ipAddress - an IP4 or IP6 address
        ipPrefix - A string containing colon delimited IP prefix with top n bits specified in the bit field (i.e. 3ffe:8311:ffff::/48 or 123.112.0.0/16).
        Returns:
        true if the host is in the given subnet, else false.
        See Also:
        com.btr.proxy.selector.pac.ScriptMethods#isInNetEx(java.lang.String, java.lang.String)
      • dnsResolveEx

        public java.lang.String dnsResolveEx​(java.lang.String host)
        dnsResolveEx
        Specified by:
        dnsResolveEx in interface ScriptMethods
        Parameters:
        host - the host to resolve
        Returns:
        a semicolon separated list of IP6 and IP4 addresses the host name resolves to, empty string if not resolvable.
      • myIpAddressEx

        public java.lang.String myIpAddressEx()
        myIpAddressEx
        Specified by:
        myIpAddressEx in interface ScriptMethods
        Returns:
        the list, empty string if not available.
        See Also:
        com.btr.proxy.selector.pac.ScriptMethods#myIpAddressEx()
      • sortIpAddressList

        public java.lang.String sortIpAddressList​(java.lang.String ipAddressList)
        sortIpAddressList
        Specified by:
        sortIpAddressList in interface ScriptMethods
        Parameters:
        ipAddressList - the address list.
        Returns:
        the sorted list, empty string if sort is not possible
      • getClientVersion

        public java.lang.String getClientVersion()
        getClientVersion
        Specified by:
        getClientVersion in interface ScriptMethods
        Returns:
        the extension version, currently 1.0