using System; using System.Collections; namespace Unosquare.Swan.Networking.Ldap { /// /// Represents an Ldap Search request. /// /// internal sealed class LdapSearchRequest : LdapMessage { /// /// Initializes a new instance of the class. /// /// The base distinguished name to search from. /// The scope of the entries to search. The following /// are the valid options:. /// /// The search filter specifying the search criteria. /// The names of attributes to retrieve. /// operation exceeds the time limit. /// Specifies when aliases should be dereferenced. /// Must be one of the constants defined in /// LdapConstraints, which are DEREF_NEVER, /// DEREF_FINDING, DEREF_SEARCHING, or DEREF_ALWAYS. /// The maximum number of search results to return /// for a search request. /// The search operation will be terminated by the server /// with an LdapException.SIZE_LIMIT_EXCEEDED if the /// number of results exceed the maximum. /// The maximum time in seconds that the server /// should spend returning search results. This is a /// server-enforced limit. A value of 0 means /// no time limit. /// If true, returns the names but not the values of /// the attributes found. If false, returns the /// names and values for attributes found. /// Any controls that apply to the search request. /// or null if none. /// public LdapSearchRequest( String ldapBase, LdapScope scope, String filter, String[] attrs, Int32 dereference, Int32 maxResults, Int32 serverTimeLimit, Boolean typesOnly, LdapControl[] cont) : base( LdapOperation.SearchRequest, new RfcSearchRequest(ldapBase, scope, dereference, maxResults, serverTimeLimit, typesOnly, filter, attrs), cont) { } /// /// Retrieves an Iterator object representing the parsed filter for /// this search request. /// The first object returned from the Iterator is an Integer indicating /// the type of filter component. One or more values follow the component /// type as subsequent items in the Iterator. The pattern of Integer /// component type followed by values continues until the end of the /// filter. /// Values returned as a byte array may represent UTF-8 characters or may /// be binary values. The possible Integer components of a search filter /// and the associated values that follow are:. /// /// /// /// The search filter. /// public IEnumerator SearchFilter => this.RfcFilter.GetFilterIterator(); /// /// Retrieves the Base DN for a search request. /// /// /// the base DN for a search request. /// public String DN => this.Asn1Object.RequestDn; /// /// Retrieves the scope of a search request. /// /// /// The scope. /// public Int32 Scope => ((Asn1Enumerated)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(1)).IntValue(); /// /// Retrieves the behaviour of dereferencing aliases on a search request. /// /// /// The dereference. /// public Int32 Dereference => ((Asn1Enumerated)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(2)).IntValue(); /// /// Retrieves the maximum number of entries to be returned on a search. /// /// /// The maximum results. /// public Int32 MaxResults => ((Asn1Integer)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(3)).IntValue(); /// /// Retrieves the server time limit for a search request. /// /// /// The server time limit. /// public Int32 ServerTimeLimit => ((Asn1Integer)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(4)).IntValue(); /// /// Retrieves whether attribute values or only attribute types(names) should /// be returned in a search request. /// /// /// true if [types only]; otherwise, false. /// public Boolean TypesOnly => ((Asn1Boolean)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(5)).BooleanValue(); /// /// Retrieves an array of attribute names to request for in a search. /// /// /// The attributes. /// public String[] Attributes { get { RfcAttributeDescriptionList attrs = (RfcAttributeDescriptionList)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(7); String[] values = new String[attrs.Size()]; for(Int32 i = 0; i < values.Length; i++) { values[i] = ((Asn1OctetString)attrs.Get(i)).StringValue(); } return values; } } /// /// Creates a string representation of the filter in this search request. /// /// /// The string filter. /// public String StringFilter => this.RfcFilter.FilterToString(); /// /// Retrieves an SearchFilter object representing a filter for a search request. /// /// /// The RFC filter. /// private RfcFilter RfcFilter => (RfcFilter)((RfcSearchRequest)this.Asn1Object.Get(1)).Get(6); } }