示例#1
0
        protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
        {
            if (strNamespace != null)
            {
                mXmlWriter.WriteStartElement(valueElt, strNamespace);
            }
            else
            {
                mXmlWriter.WriteStartElement(valueElt);
            }

            if (value.IsBinary && value.BinaryVal != null)
            {
                mXmlWriter.WriteAttributeString("xsi", "type", DsmlConstants.XsiUri,
                                                DsmlConstants.AttrBinaryTypePrefixedValue);
                mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
            }
            else
            {
                //note that the WriteString method handles a null argument correctly
                mXmlWriter.WriteString(value.StringVal);
            }

            mXmlWriter.WriteEndElement();
        }
示例#2
0
        protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
        {
            if (strNamespace != null)
            {
                mXmlWriter.WriteStartElement(valueElt, strNamespace);
            }
            else
            {
                mXmlWriter.WriteStartElement(valueElt);
            }

            if (value.IsBinary && value.BinaryVal != null)
            {
                mXmlWriter.WriteAttributeString("xsi", "type", DsmlConstants.XsiUri,
                    DsmlConstants.AttrBinaryTypePrefixedValue);
                mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
            }
            else
            {
                //note that the WriteString method handles a null argument correctly
                mXmlWriter.WriteString(value.StringVal);
            }

            mXmlWriter.WriteEndElement();
        }
示例#3
0
 protected static ADValue StringFilterValueToADValue(string strVal)
 {
     if (strVal == null || strVal.Length == 0)
     {
         return(null);
     }
     else
     {
         ADValue aDValue  = new ADValue();
         char[]  chrArray = new char[1];
         chrArray[0] = '\\';
         string[] strArrays = strVal.Split(chrArray);
         if ((int)strArrays.Length != 1)
         {
             ArrayList    arrayLists   = new ArrayList((int)strArrays.Length);
             UTF8Encoding uTF8Encoding = new UTF8Encoding();
             aDValue.IsBinary  = true;
             aDValue.StringVal = null;
             if (strArrays[0].Length != 0)
             {
                 arrayLists.Add(uTF8Encoding.GetBytes(strArrays[0]));
             }
             for (int i = 1; i < (int)strArrays.Length; i++)
             {
                 string str      = strArrays[i].Substring(0, 2);
                 byte[] numArray = new byte[1];
                 numArray[0] = byte.Parse(str, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                 arrayLists.Add(numArray);
                 if (strArrays[i].Length > 2)
                 {
                     arrayLists.Add(uTF8Encoding.GetBytes(strArrays[i].Substring(2)));
                 }
             }
             int length = 0;
             foreach (byte[] arrayList in arrayLists)
             {
                 length = length + (int)arrayList.Length;
             }
             aDValue.BinaryVal = new byte[length];
             int num = 0;
             foreach (byte[] arrayList1 in arrayLists)
             {
                 arrayList1.CopyTo(aDValue.BinaryVal, num);
                 num = num + (int)arrayList1.Length;
             }
         }
         else
         {
             aDValue.IsBinary  = false;
             aDValue.StringVal = strVal;
             aDValue.BinaryVal = null;
         }
         return(aDValue);
     }
 }
示例#4
0
        protected static ADValue StringFilterValueToADValue(string strVal)
        {
            if ((strVal == null) || (strVal.Length == 0))
            {
                return(null);
            }
            ADValue value2 = new ADValue();

            string[] strArray = strVal.Split(new char[] { '\\' });
            if (strArray.Length == 1)
            {
                value2.IsBinary  = false;
                value2.StringVal = strVal;
                value2.BinaryVal = null;
                return(value2);
            }
            ArrayList    list     = new ArrayList(strArray.Length);
            UTF8Encoding encoding = new UTF8Encoding();

            value2.IsBinary  = true;
            value2.StringVal = null;
            if (strArray[0].Length != 0)
            {
                list.Add(encoding.GetBytes(strArray[0]));
            }
            for (int i = 1; i < strArray.Length; i++)
            {
                string s = strArray[i].Substring(0, 2);
                list.Add(new byte[] { byte.Parse(s, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture) });
                if (strArray[i].Length > 2)
                {
                    list.Add(encoding.GetBytes(strArray[i].Substring(2)));
                }
            }
            int num2 = 0;

            foreach (byte[] buffer in list)
            {
                num2 += buffer.Length;
            }
            value2.BinaryVal = new byte[num2];
            int index = 0;

            foreach (byte[] buffer2 in list)
            {
                buffer2.CopyTo(value2.BinaryVal, index);
                index += buffer2.Length;
            }
            return(value2);
        }
示例#5
0
 protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
 {
     if (strNamespace != null)
     {
         mXmlWriter.WriteStartElement(valueElt, strNamespace);
     }
     else
     {
         mXmlWriter.WriteStartElement(valueElt);
     }
     if (value.IsBinary && (value.BinaryVal != null))
     {
         mXmlWriter.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", "xsd:base64Binary");
         mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
     }
     else
     {
         mXmlWriter.WriteString(value.StringVal);
     }
     mXmlWriter.WriteEndElement();
 }
 protected void WriteValue(string valueElt, ADValue value, XmlWriter mXmlWriter, string strNamespace)
 {
     if (strNamespace != null)
     {
         mXmlWriter.WriteStartElement(valueElt, strNamespace);
     }
     else
     {
         mXmlWriter.WriteStartElement(valueElt);
     }
     if (value.IsBinary && (value.BinaryVal != null))
     {
         mXmlWriter.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", "xsd:base64Binary");
         mXmlWriter.WriteBase64(value.BinaryVal, 0, value.BinaryVal.Length);
     }
     else
     {
         mXmlWriter.WriteString(value.StringVal);
     }
     mXmlWriter.WriteEndElement();
 }
示例#7
0
        /// <summary>
        /// Converts the string representation of a filter value to the appropriate ADvalue
        /// </summary>
        /// <remarks>
        /// If at least 1 binary escaping (e.g. \20) exists in the string representation
        /// then the value is converted to binary. Any string portions are converted 
        /// to binary UTF8 encoding.
        /// </remarks>
        /// <param name="strVal"> String representation of the filter. </param>
        /// <returns>Returns a properly initialized ADValue </returns>
        protected static ADValue StringFilterValueToADValue(string strVal)
        {
            if (strVal == null || strVal.Length == 0)
            {
                return null;
            }

            ADValue val = new ADValue();

            //The idea is that if we have at least 1 escaped binary value 
            // like \20 we will convert the entire value to binary 
            // something like \30va\2c\lue will be converted as follows:
            // 30,UTF8 binary representation of "va", 2c, UTF8 bin representation of "lue"
            String[] parts = strVal.Split(new char[] { '\\' });

            if (parts.Length == 1)
            {
                //we have no binary data in the value
                val.IsBinary = false;
                val.StringVal = strVal;
                val.BinaryVal = null;
            }
            else
            {
                ArrayList binChunks = new ArrayList(parts.Length);
                UTF8Encoding utf8 = new UTF8Encoding();

                //there is at least 1 binary value
                //for something like "\30va\2c\lue" we will have 
                //parts = {"", "30va", "2c", "lue"}
                val.IsBinary = true;
                val.StringVal = null;

                if (parts[0].Length != 0)
                {
                    //parts[0] is either empty of doesn't have 2 char hex prefix
                    binChunks.Add(utf8.GetBytes(parts[0]));
                }

                for (int i = 1; i < parts.Length; i++)
                {
                    //we must have a 2 character hex prefix 
                    Debug.Assert(parts[i].Length >= 2,
                        "FilterParser.ProcessStringFilterValue: Unexpected value. " +
                        "The the value matching regular expression must be incorrect");

                    string hexPrefix = parts[i].Substring(0, 2);

                    //handle the prefix 
                    binChunks.Add(new Byte[] { Byte.Parse(hexPrefix, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture) });

                    if (parts[i].Length > 2)
                    {
                        //handle the string portion
                        binChunks.Add(utf8.GetBytes(parts[i].Substring(2)));
                    }
                }

                //now we have all the binary chunks. Put them together
                //figure out the size we need
                int lenghtNeeded = 0;
                foreach (Byte[] chunk in binChunks)
                {
                    lenghtNeeded += chunk.Length;
                }

                val.BinaryVal = new Byte[lenghtNeeded];

                //do the actual copying
                int currIdx = 0;
                foreach (Byte[] chunk in binChunks)
                {
                    chunk.CopyTo(val.BinaryVal, currIdx);
                    currIdx += chunk.Length;
                }
            }

            return val;
        }
示例#8
0
 public ADExtenMatchFilter()
 {
     this.Value        = null;
     this.DNAttributes = false;
 }
示例#9
0
		protected static ADValue StringFilterValueToADValue(string strVal)
		{
			if (strVal == null || strVal.Length == 0)
			{
				return null;
			}
			else
			{
				ADValue aDValue = new ADValue();
				char[] chrArray = new char[1];
				chrArray[0] = '\\';
				string[] strArrays = strVal.Split(chrArray);
				if ((int)strArrays.Length != 1)
				{
					ArrayList arrayLists = new ArrayList((int)strArrays.Length);
					UTF8Encoding uTF8Encoding = new UTF8Encoding();
					aDValue.IsBinary = true;
					aDValue.StringVal = null;
					if (strArrays[0].Length != 0)
					{
						arrayLists.Add(uTF8Encoding.GetBytes(strArrays[0]));
					}
					for (int i = 1; i < (int)strArrays.Length; i++)
					{
						string str = strArrays[i].Substring(0, 2);
						byte[] numArray = new byte[1];
						numArray[0] = byte.Parse(str, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
						arrayLists.Add(numArray);
						if (strArrays[i].Length > 2)
						{
							arrayLists.Add(uTF8Encoding.GetBytes(strArrays[i].Substring(2)));
						}
					}
					int length = 0;
					foreach (byte[] arrayList in arrayLists)
					{
						length = length + (int)arrayList.Length;
					}
					aDValue.BinaryVal = new byte[length];
					int num = 0;
					foreach (byte[] arrayList1 in arrayLists)
					{
						arrayList1.CopyTo(aDValue.BinaryVal, num);
						num = num + (int)arrayList1.Length;
					}
				}
				else
				{
					aDValue.IsBinary = false;
					aDValue.StringVal = strVal;
					aDValue.BinaryVal = null;
				}
				return aDValue;
			}
		}
示例#10
0
        public static ADFilter ParseFilterString(string filter)
        {
            Match match = mFilter.Match(filter);

            if (match.Success)
            {
                ADFilter filter2 = new ADFilter();
                if (match.Groups["item"].ToString().Length == 0)
                {
                    int       num;
                    ArrayList list = new ArrayList();
                    for (string str = match.Groups["filterlist"].ToString().Trim(); str.Length > 0; str = str.Substring(num).TrimStart(new char[0]))
                    {
                        if (str[0] != '(')
                        {
                            return(null);
                        }
                        num = 1;
                        int  num2 = 1;
                        bool flag = false;
                        while ((num < str.Length) && !flag)
                        {
                            if (str[num] == '(')
                            {
                                num2++;
                            }
                            if (str[num] == ')')
                            {
                                if (num2 < 1)
                                {
                                    return(null);
                                }
                                if (num2 == 1)
                                {
                                    flag = true;
                                }
                                else
                                {
                                    num2--;
                                }
                            }
                            num++;
                        }
                        if (!flag)
                        {
                            return(null);
                        }
                        list.Add(str.Substring(0, num));
                    }
                    ADFilter filter5 = null;
                    switch (match.Groups["filtercomp"].ToString())
                    {
                    case "|":
                        filter2.Type      = ADFilter.FilterType.Or;
                        filter2.Filter.Or = new ArrayList();
                        foreach (string str2 in list)
                        {
                            filter5 = ParseFilterString(str2);
                            if (filter5 == null)
                            {
                                return(null);
                            }
                            filter2.Filter.Or.Add(filter5);
                        }
                        if (filter2.Filter.Or.Count >= 1)
                        {
                            return(filter2);
                        }
                        return(null);

                    case "&":
                        filter2.Type       = ADFilter.FilterType.And;
                        filter2.Filter.And = new ArrayList();
                        foreach (string str3 in list)
                        {
                            filter5 = ParseFilterString(str3);
                            if (filter5 == null)
                            {
                                return(null);
                            }
                            filter2.Filter.And.Add(filter5);
                        }
                        if (filter2.Filter.And.Count >= 1)
                        {
                            return(filter2);
                        }
                        return(null);

                    case "!":
                        filter2.Type = ADFilter.FilterType.Not;
                        filter5      = ParseFilterString((string)list[0]);
                        if ((list.Count > 1) || (filter5 == null))
                        {
                            return(null);
                        }
                        filter2.Filter.Not = filter5;
                        return(filter2);
                    }
                    return(null);
                }
                if (match.Groups["present"].ToString().Length != 0)
                {
                    filter2.Type           = ADFilter.FilterType.Present;
                    filter2.Filter.Present = match.Groups["presentattr"].ToString();
                    return(filter2);
                }
                if (match.Groups["simple"].ToString().Length == 0)
                {
                    if (match.Groups["substr"].ToString().Length != 0)
                    {
                        filter2.Type = ADFilter.FilterType.Substrings;
                        ADSubstringFilter filter3 = new ADSubstringFilter {
                            Initial = StringFilterValueToADValue(match.Groups["initialvalue"].ToString()),
                            Final   = StringFilterValueToADValue(match.Groups["finalvalue"].ToString())
                        };
                        if (match.Groups["anyvalue"].ToString().Length != 0)
                        {
                            foreach (Capture capture in match.Groups["anyvalue"].Captures)
                            {
                                filter3.Any.Add(StringFilterValueToADValue(capture.ToString()));
                            }
                        }
                        filter3.Name = match.Groups["substrattr"].ToString();
                        filter2.Filter.Substrings = filter3;
                        return(filter2);
                    }
                    if (match.Groups["extensible"].ToString().Length != 0)
                    {
                        filter2.Type = ADFilter.FilterType.ExtensibleMatch;
                        ADExtenMatchFilter filter4 = new ADExtenMatchFilter {
                            Value        = StringFilterValueToADValue(match.Groups["extenvalue"].ToString()),
                            DNAttributes = match.Groups["dnattr"].ToString().Length != 0,
                            Name         = match.Groups["extenattr"].ToString(),
                            MatchingRule = match.Groups["matchrule"].ToString()
                        };
                        filter2.Filter.ExtensibleMatch = filter4;
                        return(filter2);
                    }
                    return(null);
                }
                ADAttribute attribute = new ADAttribute();
                if (match.Groups["simplevalue"].ToString().Length != 0)
                {
                    ADValue value2 = StringFilterValueToADValue(match.Groups["simplevalue"].ToString());
                    attribute.Values.Add(value2);
                }
                attribute.Name = match.Groups["simpleattr"].ToString();
                switch (match.Groups["filtertype"].ToString())
                {
                case "=":
                    filter2.Type = ADFilter.FilterType.EqualityMatch;
                    filter2.Filter.EqualityMatch = attribute;
                    return(filter2);

                case "~=":
                    filter2.Type = ADFilter.FilterType.ApproxMatch;
                    filter2.Filter.ApproxMatch = attribute;
                    return(filter2);

                case "<=":
                    filter2.Type = ADFilter.FilterType.LessOrEqual;
                    filter2.Filter.LessOrEqual = attribute;
                    return(filter2);

                case ">=":
                    filter2.Type = ADFilter.FilterType.GreaterOrEqual;
                    filter2.Filter.GreaterOrEqual = attribute;
                    return(filter2);
                }
            }
            return(null);
        }
示例#11
0
		public ADSubstringFilter()
		{
			this.Initial = null;
			this.Final = null;
			this.Any = new ArrayList();
		}
示例#12
0
        public static ADFilter ParseFilterString(string filter)
        {
            ADFilter aDFilter  = null;
            ADFilter aDFilter1 = null;

            try
            {
                Match match = FilterParser.mFilter.Match(filter);
                if (match.Success)
                {
                    ADFilter arrayLists = new ADFilter();
                    if (match.Groups["item"].ToString().Length == 0)
                    {
                        ArrayList arrayLists1 = new ArrayList();
                        string    str         = match.Groups["filterlist"].ToString().Trim();
                        while (str.Length > 0)
                        {
                            if (str[0] == '(')
                            {
                                int  num  = 1;
                                int  num1 = 1;
                                bool flag = false;
                                while (num < str.Length && !flag)
                                {
                                    if (str[num] == '(')
                                    {
                                        num1++;
                                    }
                                    if (str[num] == ')')
                                    {
                                        if (num1 >= 1)
                                        {
                                            if (num1 != 1)
                                            {
                                                num1--;
                                            }
                                            else
                                            {
                                                flag = true;
                                            }
                                        }
                                        else
                                        {
                                            aDFilter1 = null;
                                            return(aDFilter1);
                                        }
                                    }
                                    num++;
                                }
                                if (flag)
                                {
                                    arrayLists1.Add(str.Substring(0, num));
                                    str = str.Substring(num).TrimStart(new char[0]);
                                }
                                else
                                {
                                    aDFilter1 = null;
                                    return(aDFilter1);
                                }
                            }
                            else
                            {
                                aDFilter1 = null;
                                return(aDFilter1);
                            }
                        }
                        string str1 = match.Groups["filtercomp"].ToString();
                        string str2 = str1;
                        if (str1 != null)
                        {
                            if (str2 == "|")
                            {
                                arrayLists.Type      = ADFilter.FilterType.Or;
                                arrayLists.Filter.Or = new ArrayList();
                                foreach (string arrayList in arrayLists1)
                                {
                                    aDFilter = FilterParser.ParseFilterString(arrayList);
                                    if (aDFilter != null)
                                    {
                                        arrayLists.Filter.Or.Add(aDFilter);
                                    }
                                    else
                                    {
                                        aDFilter1 = null;
                                        return(aDFilter1);
                                    }
                                }
                                if (arrayLists.Filter.Or.Count < 1)
                                {
                                    aDFilter1 = null;
                                    return(aDFilter1);
                                }
                                else
                                {
                                    goto Label1;
                                }
                            }
                            else
                            {
                                if (str2 == "&")
                                {
                                    arrayLists.Type       = ADFilter.FilterType.And;
                                    arrayLists.Filter.And = new ArrayList();
                                    foreach (string arrayList1 in arrayLists1)
                                    {
                                        aDFilter = FilterParser.ParseFilterString(arrayList1);
                                        if (aDFilter != null)
                                        {
                                            arrayLists.Filter.And.Add(aDFilter);
                                        }
                                        else
                                        {
                                            aDFilter1 = null;
                                            return(aDFilter1);
                                        }
                                    }
                                    if (arrayLists.Filter.And.Count < 1)
                                    {
                                        aDFilter1 = null;
                                        return(aDFilter1);
                                    }
                                    else
                                    {
                                        goto Label1;
                                    }
                                }
                                else
                                {
                                    if (str2 != "!")
                                    {
                                        aDFilter1 = null;
                                        return(aDFilter1);
                                    }
                                    arrayLists.Type = ADFilter.FilterType.Not;
                                    aDFilter        = FilterParser.ParseFilterString((string)arrayLists1[0]);
                                    if (arrayLists1.Count > 1 || aDFilter == null)
                                    {
                                        aDFilter1 = null;
                                        return(aDFilter1);
                                    }
                                    else
                                    {
                                        arrayLists.Filter.Not = aDFilter;
                                        goto Label1;
                                    }
                                }
                            }
                        }
                        aDFilter1 = null;
                        return(aDFilter1);
                    }
                    else
                    {
                        if (match.Groups["present"].ToString().Length == 0)
                        {
                            if (match.Groups["simple"].ToString().Length == 0)
                            {
                                if (match.Groups["substr"].ToString().Length == 0)
                                {
                                    if (match.Groups["extensible"].ToString().Length == 0)
                                    {
                                        aDFilter1 = null;
                                        return(aDFilter1);
                                    }
                                    else
                                    {
                                        arrayLists.Type = ADFilter.FilterType.ExtensibleMatch;
                                        ADExtenMatchFilter aDExtenMatchFilter = new ADExtenMatchFilter();
                                        aDExtenMatchFilter.Value          = FilterParser.StringFilterValueToADValue(match.Groups["extenvalue"].ToString());
                                        aDExtenMatchFilter.DNAttributes   = match.Groups["dnattr"].ToString().Length != 0;
                                        aDExtenMatchFilter.Name           = match.Groups["extenattr"].ToString();
                                        aDExtenMatchFilter.MatchingRule   = match.Groups["matchrule"].ToString();
                                        arrayLists.Filter.ExtensibleMatch = aDExtenMatchFilter;
                                    }
                                }
                                else
                                {
                                    arrayLists.Type = ADFilter.FilterType.Substrings;
                                    ADSubstringFilter aDSubstringFilter = new ADSubstringFilter();
                                    aDSubstringFilter.Initial = FilterParser.StringFilterValueToADValue(match.Groups["initialvalue"].ToString());
                                    aDSubstringFilter.Final   = FilterParser.StringFilterValueToADValue(match.Groups["finalvalue"].ToString());
                                    if (match.Groups["anyvalue"].ToString().Length != 0)
                                    {
                                        foreach (Capture capture in match.Groups["anyvalue"].Captures)
                                        {
                                            aDSubstringFilter.Any.Add(FilterParser.StringFilterValueToADValue(capture.ToString()));
                                        }
                                    }
                                    aDSubstringFilter.Name       = match.Groups["substrattr"].ToString();
                                    arrayLists.Filter.Substrings = aDSubstringFilter;
                                }
                            }
                            else
                            {
                                ADAttribute aDAttribute = new ADAttribute();
                                if (match.Groups["simplevalue"].ToString().Length != 0)
                                {
                                    ADValue aDValue = FilterParser.StringFilterValueToADValue(match.Groups["simplevalue"].ToString());
                                    aDAttribute.Values.Add(aDValue);
                                }
                                aDAttribute.Name = match.Groups["simpleattr"].ToString();
                                string str3 = match.Groups["filtertype"].ToString();
                                string str4 = str3;
                                if (str3 != null)
                                {
                                    if (str4 == "=")
                                    {
                                        arrayLists.Type = ADFilter.FilterType.EqualityMatch;
                                        arrayLists.Filter.EqualityMatch = aDAttribute;
                                        goto Label1;
                                    }
                                    else
                                    {
                                        if (str4 == "~=")
                                        {
                                            arrayLists.Type = ADFilter.FilterType.ApproxMatch;
                                            arrayLists.Filter.ApproxMatch = aDAttribute;
                                            goto Label1;
                                        }
                                        else
                                        {
                                            if (str4 == "<=")
                                            {
                                                arrayLists.Type = ADFilter.FilterType.LessOrEqual;
                                                arrayLists.Filter.LessOrEqual = aDAttribute;
                                                goto Label1;
                                            }
                                            else
                                            {
                                                if (str4 != ">=")
                                                {
                                                    aDFilter1 = null;
                                                    return(aDFilter1);
                                                }
                                                arrayLists.Type = ADFilter.FilterType.GreaterOrEqual;
                                                arrayLists.Filter.GreaterOrEqual = aDAttribute;
                                                goto Label1;
                                            }
                                        }
                                    }
                                }
                                aDFilter1 = null;
                                return(aDFilter1);
                            }
                        }
                        else
                        {
                            arrayLists.Type           = ADFilter.FilterType.Present;
                            arrayLists.Filter.Present = match.Groups["presentattr"].ToString();
                        }
                    }
Label1:
                    aDFilter1 = arrayLists;
                }
                else
                {
                    aDFilter1 = null;
                }
            }
            catch (Exception regexMatchTimeoutException)
            {
                aDFilter1 = null;
            }
            return(aDFilter1);
        }
 protected static ADValue StringFilterValueToADValue(string strVal)
 {
     if ((strVal == null) || (strVal.Length == 0))
     {
         return null;
     }
     ADValue value2 = new ADValue();
     string[] strArray = strVal.Split(new char[] { '\\' });
     if (strArray.Length == 1)
     {
         value2.IsBinary = false;
         value2.StringVal = strVal;
         value2.BinaryVal = null;
         return value2;
     }
     ArrayList list = new ArrayList(strArray.Length);
     UTF8Encoding encoding = new UTF8Encoding();
     value2.IsBinary = true;
     value2.StringVal = null;
     if (strArray[0].Length != 0)
     {
         list.Add(encoding.GetBytes(strArray[0]));
     }
     for (int i = 1; i < strArray.Length; i++)
     {
         string s = strArray[i].Substring(0, 2);
         list.Add(new byte[] { byte.Parse(s, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture) });
         if (strArray[i].Length > 2)
         {
             list.Add(encoding.GetBytes(strArray[i].Substring(2)));
         }
     }
     int num2 = 0;
     foreach (byte[] buffer in list)
     {
         num2 += buffer.Length;
     }
     value2.BinaryVal = new byte[num2];
     int index = 0;
     foreach (byte[] buffer2 in list)
     {
         buffer2.CopyTo(value2.BinaryVal, index);
         index += buffer2.Length;
     }
     return value2;
 }
示例#14
0
		public ADExtenMatchFilter()
		{
			this.Value = null;
			this.DNAttributes = false;
		}
示例#15
0
        /// <summary>
        /// Converts the string representation of a filter value to the appropriate ADvalue
        /// </summary>
        /// <remarks>
        /// If at least 1 binary escaping (e.g. \20) exists in the string representation
        /// then the value is converted to binary. Any string portions are converted
        /// to binary UTF8 encoding.
        /// </remarks>
        /// <param name="strVal"> String representation of the filter. </param>
        /// <returns>Returns a properly initialized ADValue </returns>
        protected static ADValue StringFilterValueToADValue(string strVal)
        {
            if (strVal == null || strVal.Length == 0)
            {
                return(null);
            }

            ADValue val = new ADValue();

            //The idea is that if we have at least 1 escaped binary value
            // like \20 we will convert the entire value to binary
            // something like \30va\2c\lue will be converted as follows:
            // 30,UTF8 binary representation of "va", 2c, UTF8 bin representation of "lue"
            String[] parts = strVal.Split(new char[] { '\\' });

            if (parts.Length == 1)
            {
                //we have no binary data in the value
                val.IsBinary  = false;
                val.StringVal = strVal;
                val.BinaryVal = null;
            }
            else
            {
                ArrayList    binChunks = new ArrayList(parts.Length);
                UTF8Encoding utf8      = new UTF8Encoding();

                //there is at least 1 binary value
                //for something like "\30va\2c\lue" we will have
                //parts = {"", "30va", "2c", "lue"}
                val.IsBinary  = true;
                val.StringVal = null;

                if (parts[0].Length != 0)
                {
                    //parts[0] is either empty of doesn't have 2 char hex prefix
                    binChunks.Add(utf8.GetBytes(parts[0]));
                }

                for (int i = 1; i < parts.Length; i++)
                {
                    //we must have a 2 character hex prefix
                    Debug.Assert(parts[i].Length >= 2,
                                 "FilterParser.ProcessStringFilterValue: Unexpected value. " +
                                 "The the value matching regular expression must be incorrect");

                    string hexPrefix = parts[i].Substring(0, 2);

                    //handle the prefix
                    binChunks.Add(new Byte[] { Byte.Parse(hexPrefix, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture) });

                    if (parts[i].Length > 2)
                    {
                        //handle the string portion
                        binChunks.Add(utf8.GetBytes(parts[i].Substring(2)));
                    }
                }

                //now we have all the binary chunks. Put them together
                //figure out the size we need
                int lenghtNeeded = 0;
                foreach (Byte[] chunk in binChunks)
                {
                    lenghtNeeded += chunk.Length;
                }

                val.BinaryVal = new Byte[lenghtNeeded];

                //do the actual copying
                int currIdx = 0;
                foreach (Byte[] chunk in binChunks)
                {
                    chunk.CopyTo(val.BinaryVal, currIdx);
                    currIdx += chunk.Length;
                }
            }

            return(val);
        }
示例#16
0
        public static ADFilter ParseFilterString(string filter)
        {
            Debug.Assert(filter != null);

            //perfomr the matthing. On success all info we are interested in
            //will be stored in the named captures.
            try
            {
                Match m = s_mFilter.Match(filter);
                if (!m.Success)
                {
                    return(null);
                }

                ADFilter result = new ADFilter();
                if (m.Groups["item"].ToString().Length != 0)
                {
                    //we have am "item"filter which can be
                    //of type "present", "simple", "substring", or "extensible"

                    if (m.Groups["present"].ToString().Length != 0)
                    {
                        //present filter, e.g. (objectClass=*)
                        result.Type = ADFilter.FilterType.Present;

                        Debug.Assert(m.Groups["presentattr"].ToString().Length != 0);
                        result.Filter.Present = m.Groups["presentattr"].ToString();
                    }
                    else if (m.Groups["simple"].ToString().Length != 0)
                    {
                        //simple filter, e.g.  (simpleattr =|~=|>=|<= simplevalue)
                        ADAttribute simple = new ADAttribute();

                        if (m.Groups["simplevalue"].ToString().Length != 0)
                        {
                            ADValue val = StringFilterValueToADValue(m.Groups["simplevalue"].ToString());
                            simple.Values.Add(val);
                        }

                        simple.Name = m.Groups["simpleattr"].ToString();

                        //the variours types of relationships we might have
                        switch (m.Groups["filtertype"].ToString())
                        {
                        case "=":
                            result.Type = ADFilter.FilterType.EqualityMatch;
                            result.Filter.EqualityMatch = simple;
                            break;

                        case "~=":
                            result.Type = ADFilter.FilterType.ApproxMatch;
                            result.Filter.ApproxMatch = simple;
                            break;

                        case "<=":
                            result.Type = ADFilter.FilterType.LessOrEqual;
                            result.Filter.LessOrEqual = simple;
                            break;

                        case ">=":
                            result.Type = ADFilter.FilterType.GreaterOrEqual;
                            result.Filter.GreaterOrEqual = simple;
                            break;

                        default:
                            //this should not occur
                            Debug.Fail("FilterParser.ParseFilterString: Invalid simple filter");

                            //treat like a parse error
                            return(null);
                        }
                    }
                    else if (m.Groups["substr"].ToString().Length != 0)
                    {
                        //we have a substring filter. Get the various parts of it
                        result.Type = ADFilter.FilterType.Substrings;

                        ADSubstringFilter substr = new ADSubstringFilter();

                        substr.Initial = StringFilterValueToADValue(m.Groups["initialvalue"].ToString());
                        substr.Final   = StringFilterValueToADValue(m.Groups["finalvalue"].ToString());

                        if (m.Groups["anyvalue"].ToString().Length != 0)
                        {
                            foreach (Capture c in m.Groups["anyvalue"].Captures)
                            {
                                substr.Any.Add(StringFilterValueToADValue(c.ToString()));
                            }
                        }

                        substr.Name = m.Groups["substrattr"].ToString();
                        result.Filter.Substrings = substr;
                    }
                    else if (m.Groups["extensible"].ToString().Length != 0)
                    {
                        //extensible filter
                        result.Type = ADFilter.FilterType.ExtensibleMatch;

                        ADExtenMatchFilter exten = new ADExtenMatchFilter();

                        exten.Value        = StringFilterValueToADValue(m.Groups["extenvalue"].ToString());
                        exten.DNAttributes = (m.Groups["dnattr"].ToString().Length != 0);
                        exten.Name         = m.Groups["extenattr"].ToString();
                        exten.MatchingRule = m.Groups["matchrule"].ToString();

                        result.Filter.ExtensibleMatch = exten;
                    }
                    else
                    {
                        //this should not occur
                        Debug.Fail("Invalid item filter");

                        //treat like a parse error
                        return(null);
                    }
                }
                else
                {
                    //compound recursive filter

                    //extract the filter lists
                    ArrayList filters    = new ArrayList();
                    string    filterList = m.Groups["filterlist"].ToString().Trim();

                    while (filterList.Length > 0)
                    {
                        if (filterList[0] != '(')
                        {
                            //this is a parse error: invalid filter
                            return(null);
                        }

                        int  strIdx       = 1;
                        int  left         = 1; //count opening brackest
                        bool gotSubfilter = false;

                        while (strIdx < filterList.Length && !gotSubfilter)
                        {
                            if (filterList[strIdx] == '(')
                            {
                                left++;
                            }

                            if (filterList[strIdx] == ')')
                            {
                                if (left < 1)
                                {
                                    //unbalanced parenthesis
                                    return(null);
                                }
                                else if (left == 1)
                                {
                                    //the end of the subfilter
                                    gotSubfilter = true;
                                }
                                else
                                {
                                    left--;
                                }
                            }

                            strIdx++;
                        }

                        if (!gotSubfilter)
                        {
                            //the filter list did not consist entirely of subfilters
                            return(null);
                        }

                        filters.Add(filterList.Substring(0, strIdx));
                        filterList = filterList.Substring(strIdx).TrimStart();
                    }

                    ADFilter eltFilter = null;
                    switch (m.Groups["filtercomp"].ToString())
                    {
                    case "|":
                        result.Type      = ADFilter.FilterType.Or;
                        result.Filter.Or = new ArrayList();
                        foreach (String f in filters)
                        {
                            eltFilter = ParseFilterString(f);
                            if (eltFilter == null)
                            {
                                return(null);
                            }

                            result.Filter.Or.Add(eltFilter);
                        }

                        if (result.Filter.Or.Count < 1)
                        {
                            return(null);
                        }

                        break;

                    case "&":
                        result.Type       = ADFilter.FilterType.And;
                        result.Filter.And = new ArrayList();
                        foreach (String f in filters)
                        {
                            eltFilter = ParseFilterString(f);
                            if (eltFilter == null)
                            {
                                return(null);
                            }

                            result.Filter.And.Add(eltFilter);
                        }

                        if (result.Filter.And.Count < 1)
                        {
                            return(null);
                        }

                        break;

                    case "!":
                        result.Type = ADFilter.FilterType.Not;
                        eltFilter   = ParseFilterString((string)filters[0]);
                        //Note that for ease of defining the filter grammar we allow
                        //more than one filter after '!'. We catch this here
                        if (filters.Count > 1 || eltFilter == null)
                        {
                            return(null);
                        }

                        result.Filter.Not = eltFilter;
                        break;

                    default:
                        //this should not occur
                        Debug.Fail("Invalid filter composition");

                        //treat like a parse error
                        return(null);
                    }
                }

                return(result);
            }//end of try
            catch (RegexMatchTimeoutException)
            {
                Debug.WriteLine("The input filter String: {0} exceeded the regex match timeout of {1} seconds.", filter, mFilterTimeOutInSeconds);
                return(null);
            }
        }
示例#17
0
 public ADSubstringFilter()
 {
     this.Initial = null;
     this.Final   = null;
     this.Any     = new ArrayList();
 }