Пример #1
0
 protected void WriteAttrib(string attrName, ADAttribute attrib, XmlWriter mXmlWriter, string strNamespace)
 {
     if (strNamespace != null)
     {
         mXmlWriter.WriteStartElement(attrName, strNamespace);
     }
     else
     {
         mXmlWriter.WriteStartElement(attrName);
     }
     mXmlWriter.WriteAttributeString("name", attrib.Name);
     foreach (ADValue value2 in attrib.Values)
     {
         this.WriteValue("value", value2, mXmlWriter, strNamespace);
     }
     mXmlWriter.WriteEndElement();
 }
 protected void WriteAttrib(string attrName, ADAttribute attrib, XmlWriter mXmlWriter, string strNamespace)
 {
     if (strNamespace != null)
     {
         mXmlWriter.WriteStartElement(attrName, strNamespace);
     }
     else
     {
         mXmlWriter.WriteStartElement(attrName);
     }
     mXmlWriter.WriteAttributeString("name", attrib.Name);
     foreach (ADValue value2 in attrib.Values)
     {
         this.WriteValue("value", value2, mXmlWriter, strNamespace);
     }
     mXmlWriter.WriteEndElement();
 }
Пример #3
0
        protected void WriteAttrib(string attrName, ADAttribute attrib, XmlWriter mXmlWriter, string strNamespace)
        {
            if (strNamespace != null)
            {
                mXmlWriter.WriteStartElement(attrName, strNamespace);
            }
            else
            {
                mXmlWriter.WriteStartElement(attrName);
            }

            mXmlWriter.WriteAttributeString(DsmlConstants.AttrDsmlAttrName, attrib.Name);

            foreach (ADValue val in attrib.Values)
            {
                WriteValue(DsmlConstants.ElementDsmlAttrValue, val, mXmlWriter, strNamespace);
            }

            mXmlWriter.WriteEndElement();
        }
Пример #4
0
        protected void WriteAttrib(string attrName, ADAttribute attrib, XmlWriter mXmlWriter, string strNamespace)
        {
            if (strNamespace != null)
            {
                mXmlWriter.WriteStartElement(attrName, strNamespace);
            }
            else
            {
                mXmlWriter.WriteStartElement(attrName);
            }

            mXmlWriter.WriteAttributeString(DsmlConstants.AttrDsmlAttrName, attrib.Name);

            foreach (ADValue val in attrib.Values)
            {
                WriteValue(DsmlConstants.ElementDsmlAttrValue, val, mXmlWriter, strNamespace);
            }

            mXmlWriter.WriteEndElement();
        }
Пример #5
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;
            }
        }
Пример #6
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);
        }
        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;
        }
Пример #8
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);
            }
        }
Пример #9
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);
        }
Пример #10
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;
		}