public bool Matches(opaqueDataListOptionType that, @operator op)
        {
            if (that != null)
            {
                List <opaqueData> opaqueList = that.opaqueData;
                if (opaqueList != null)
                {
                    if (op.Equals(@operator.equals))
                    {
                        if (opaqueList.Count != opaqueDataList.Count)
                        {
                            return(false);
                        }
                        for (int i = 0; i < opaqueList.Count; i++)
                        {
                            BaseOpaqueData opaque   = new BaseOpaqueData(opaqueList[i]);
                            BaseOpaqueData myOpaque = opaqueDataList[i];
                            if (!OpaqueDataUtil.Equals(opaque, myOpaque))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    else if (op.Equals(@operator.contains))
                    {
                        if (opaqueList.Count > opaqueDataList.Count)
                        {
                            return(false);
                        }
                        for (int i = 0; i < opaqueList.Count; i++)
                        {
                            BaseOpaqueData opaque = new BaseOpaqueData(opaqueList[i]);
                            bool           found  = false;
                            for (int j = 0; j < opaqueDataList.Count; j++)
                            {
                                BaseOpaqueData myOpaque = opaqueDataList[j];
                                if (OpaqueDataUtil.Equals(opaque, myOpaque))
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    else
                    {
                        log.Warn("Unsupported expression operator: " + op);
                    }
                }
            }

            return(false);
        }
示例#2
0
        /* (non-Javadoc)
         * @see com.jagornet.dhcpv6.option.DhcpComparableOption#matches(com.jagornet.dhcp.xml.OptionExpression)
         */
        public bool Matches(optionExpression expression)
        {
            if (expression == null)
            {
                return(false);
            }
            if (expression.code != this.GetCode())
            {
                return(false);
            }
            if (ipAddress == null)
            {
                return(false);
            }

            ipAddressOptionType exprOption = (ipAddressOptionType)expression.Item;

            if (exprOption != null)
            {
                String    exprIpAddress = exprOption.ipAddress;
                @operator op            = expression.@operator;
                if (op.Equals(@operator.equals))
                {
                    return(ipAddress.Equals(exprIpAddress));
                }
                else if (op.Equals(@operator.startsWith))
                {
                    return(ipAddress.StartsWith(exprIpAddress));
                }
                else if (op.Equals(@operator.endsWith))
                {
                    return(ipAddress.EndsWith(exprIpAddress));
                }
                else if (op.Equals(@operator.contains))
                {
                    return(ipAddress.Contains(exprIpAddress));
                }
                else if (op.Equals(@operator.regExp))
                {
                    Match m = Regex.Match(ipAddress, exprIpAddress);
                    return(m.Success);
                }
                else
                {
                    log.Warn("Unsupported expression operator: " + op);
                }
            }

            return(false);
        }
示例#3
0
        /* (non-Javadoc)
         * @see com.jagornet.dhcpv6.option.DhcpComparableOption#matches(com.jagornet.dhcp.xml.OptionExpression)
         */
        public bool Matches(optionExpression expression)
        {
            if (expression == null)
            {
                return(false);
            }
            if (expression.code != this.GetCode())
            {
                return(false);
            }
            if (unsignedByteList == null)
            {
                return(false);
            }

            unsignedByteListOptionType exprOption = (unsignedByteListOptionType)expression.Item;

            if (exprOption != null)
            {
                List <short> exprUbytes = exprOption.unsignedByte;
                @operator    op         = expression.@operator;
                if (op.Equals(@operator.equals))
                {
                    return(unsignedByteList.Equals(exprUbytes));
                }
                else if (op.Equals(@operator.contains))
                {
                    foreach (var item in exprUbytes)
                    {
                        if (!unsignedByteList.Contains(item))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    log.Warn("Unsupported expression operator: " + op);
                }
            }

            return(false);
        }
        public bool Matches(optionExpression expression)
        {
            if (expression == null)
            {
                return(false);
            }
            if (expression.code != this.code)
            {
                return(false);
            }

            unsignedShortOptionType exprOption = (unsignedShortOptionType)expression.Item;

            if (exprOption != null)
            {
                int       exprUshort = exprOption.unsignedShort;
                @operator op         = expression.@operator;
                if (op.Equals(@operator.equals))
                {
                    return(unsignedShort == exprUshort);
                }
                else if (op.Equals(@operator.lessThan))
                {
                    return(unsignedShort < exprUshort);
                }
                else if (op.Equals(@operator.lessThanOrEqual))
                {
                    return(unsignedShort <= exprUshort);
                }
                else if (op.Equals(@operator.greaterThan))
                {
                    return(unsignedShort > exprUshort);
                }
                else if (op.Equals(@operator.greaterThanOrEqual))
                {
                    return(unsignedShort >= exprUshort);
                }
                else
                {
                    log.Warn("Unsupported expression operator: " + op);
                }
            }

            // then see if we have an opaque option
            opaqueDataOptionType opaqueOption = (opaqueDataOptionType)expression.Item;

            if (opaqueOption != null)
            {
                opaqueData opaque = opaqueOption.opaqueData;
                if (opaque != null)
                {
                    string ascii = opaque.asciiValue;
                    if (ascii != null)
                    {
                        try
                        {
                            // need an Integer to handle unsigned short
                            if (unsignedShort == int.Parse(ascii))
                            {
                                return(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Invalid unsigned short ASCII value for OpaqueData: " + ascii);
                        }
                    }
                    else
                    {
                        byte[] hex = opaque.hexValue;
                        if ((hex != null) &&
                            (hex.Length >= 1) && (hex.Length <= 2))
                        {
                            int hexUnsignedShort = Convert.ToInt32(Util.ToHexString(hex), 16);
                            if (unsignedShort == hexUnsignedShort)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#5
0
 public static bool Matches(BaseOpaqueData myOpaque, opaqueData that, @operator op)
 {
     if (that != null)
     {
         string expAscii = that.asciiValue;
         string myAscii  = myOpaque.GetAscii();
         if ((expAscii != null) && (myAscii != null))
         {
             if (op.Equals(@operator.equals))
             {
                 return(myAscii.equalsIgnoreCase(expAscii));
             }
             else if (op.Equals(@operator.startsWith))
             {
                 return(myAscii.startsWith(expAscii));
             }
             else if (op.Equals(@operator.contains))
             {
                 return(myAscii.@operator(expAscii));
             }
             else if (op.Equals(@operator.endsWith))
             {
                 return(myAscii.endsWith(expAscii));
             }
             else if (op.Equals(@operator.regExp))
             {
                 return(myAscii.matches(expAscii));
             }
             else
             {
                 log.error("Unsupported expression operator: " + op);
                 return(false);
             }
         }
         else if ((expAscii == null) && (myAscii == null))
         {
             byte[] expHex = that.getHexValue();
             byte[] myHex  = myOpaque.getHex();
             if ((expHex != null) && (myHex != null))
             {
                 if (op.equals(Operator.EQUALS))
                 {
                     return(Arrays.equals(myHex, expHex));
                 }
                 else if (op.equals(Operator.STARTS_WITH))
                 {
                     if (myHex.length >= expHex.length)
                     {
                         for (int i = 0; i < expHex.length; i++)
                         {
                             if (myHex[i] != expHex[i])
                             {
                                 return(false);
                             }
                         }
                         return(true);    // if we get here, it matches
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.equals(Operator.CONTAINS))
                 {
                     if (myHex.length >= expHex.length)
                     {
                         int j = 0;
                         for (int i = 0; i < myHex.length; i++)
                         {
                             if (myHex[i] == expHex[j])
                             {
                                 // found a potential match
                                 j++;
                                 boolean matches = true;
                                 for (int ii = i + 1; ii < myHex.length; ii++)
                                 {
                                     if (myHex[ii] != expHex[j++])
                                     {
                                         matches = false;
                                         break;
                                     }
                                 }
                                 if (matches)
                                 {
                                     return(true);
                                 }
                                 j = 0;    // reset to start of exp
                             }
                         }
                         return(false);    // if we get here, it didn't match
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.equals(Operator.ENDS_WITH))
                 {
                     if (myHex.length >= expHex.length)
                     {
                         for (int i = myHex.length - 1;
                              i >= myHex.length - expHex.length;
                              i--)
                         {
                             if (myHex[i] != expHex[i])
                             {
                                 return(false);
                             }
                         }
                         return(true);    // if we get here, it matches
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.equals(Operator.REG_EXP))
                 {
                     log.error("Regular expression operator not valid for hex opaque opaqueData");
                     return(false);
                 }
                 else
                 {
                     log.error("Unsupported expression operator: " + op);
                     return(false);
                 }
             }
         }
     }
     return(false);
 }
 public static bool Matches(BaseOpaqueData myOpaque, opaqueData that, @operator op)
 {
     if (that != null)
     {
         string expAscii = that.asciiValue;
         string myAscii  = myOpaque.GetAscii();
         if ((expAscii != null) && (myAscii != null))
         {
             if (op.Equals(@operator.equals))
             {
                 return(myAscii.ToUpper() == expAscii.ToUpper());
             }
             else if (op.Equals(@operator.startsWith))
             {
                 return(myAscii.StartsWith(expAscii));
             }
             else if (op.Equals(@operator.contains))
             {
                 return(myAscii.Contains(expAscii));
             }
             else if (op.Equals(@operator.endsWith))
             {
                 return(myAscii.EndsWith(expAscii));
             }
             else if (op.Equals(@operator.regExp))
             {
                 Match m = Regex.Match(myAscii, expAscii);
                 return(m.Success);
             }
             else
             {
                 log.Error("Unsupported expression operator: " + op);
                 return(false);
             }
         }
         else if ((expAscii == null) && (myAscii == null))
         {
             byte[] expHex = that.hexValue;
             byte[] myHex  = myOpaque.GetHex();
             if ((expHex != null) && (myHex != null))
             {
                 if (op.Equals(@operator.equals))
                 {
                     return(Array.Equals(myHex, expHex));
                 }
                 else if (op.Equals(@operator.startsWith))
                 {
                     if (myHex.Length >= expHex.Length)
                     {
                         for (int i = 0; i < expHex.Length; i++)
                         {
                             if (myHex[i] != expHex[i])
                             {
                                 return(false);
                             }
                         }
                         return(true);    // if we get here, it matches
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.Equals(@operator.contains))
                 {
                     if (myHex.Length >= expHex.Length)
                     {
                         int j = 0;
                         for (int i = 0; i < myHex.Length; i++)
                         {
                             if (myHex[i] == expHex[j])
                             {
                                 // found a potential match
                                 j++;
                                 bool matches = true;
                                 for (int ii = i + 1; ii < myHex.Length; ii++)
                                 {
                                     if (myHex[ii] != expHex[j++])
                                     {
                                         matches = false;
                                         break;
                                     }
                                 }
                                 if (matches)
                                 {
                                     return(true);
                                 }
                                 j = 0;    // reset to start of exp
                             }
                         }
                         return(false);    // if we get here, it didn't match
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.Equals(@operator.endsWith))
                 {
                     if (myHex.Length >= expHex.Length)
                     {
                         for (int i = myHex.Length - 1;
                              i >= myHex.Length - expHex.Length;
                              i--)
                         {
                             if (myHex[i] != expHex[i])
                             {
                                 return(false);
                             }
                         }
                         return(true);    // if we get here, it matches
                     }
                     else
                     {
                         return(false);   // exp length too long
                     }
                 }
                 else if (op.Equals(@operator.regExp))
                 {
                     log.Error("Regular expression operator not valid for hex opaque opaqueData");
                     return(false);
                 }
                 else
                 {
                     log.Error("Unsupported expression operator: " + op);
                     return(false);
                 }
             }
         }
     }
     return(false);
 }