namespace Unosquare.Swan.Networking.Ldap
{
using System.Collections;
///
/// 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:.
///
- SCOPE_BASE - searches only the base DN
- SCOPE_ONE - searches only entries under the base DN
-
/// SCOPE_SUB - searches the base DN and all entries
/// within its subtree
///
/// 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,
int dereference,
int maxResults,
int serverTimeLimit,
bool 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:.
/// - AND - followed by an Iterator value
- OR - followed by an Iterator value
- NOT - followed by an Iterator value
-
/// EQUALITY_MATCH - followed by the attribute name represented as a
/// String, and by the attribute value represented as a byte array
///
-
/// GREATER_OR_EQUAL - followed by the attribute name represented as a
/// String, and by the attribute value represented as a byte array
///
-
/// LESS_OR_EQUAL - followed by the attribute name represented as a
/// String, and by the attribute value represented as a byte array
///
-
/// APPROX_MATCH - followed by the attribute name represented as a
/// String, and by the attribute value represented as a byte array
///
- PRESENT - followed by a attribute name respresented as a String
-
/// EXTENSIBLE_MATCH - followed by the name of the matching rule
/// represented as a String, by the attribute name represented
/// as a String, and by the attribute value represented as a
/// byte array.
///
-
/// SUBSTRINGS - followed by the attribute name represented as a
/// String, by one or more SUBSTRING components (INITIAL, ANY,
/// or FINAL) followed by the SUBSTRING value.
///
///
///
/// The search filter.
///
public IEnumerator SearchFilter => RfcFilter.GetFilterIterator();
///
/// Retrieves the Base DN for a search request.
///
///
/// the base DN for a search request.
///
public string DN => Asn1Object.RequestDn;
///
/// Retrieves the scope of a search request.
///
///
/// The scope.
///
public int Scope => ((Asn1Enumerated)((RfcSearchRequest)Asn1Object.Get(1)).Get(1)).IntValue();
///
/// Retrieves the behaviour of dereferencing aliases on a search request.
///
///
/// The dereference.
///
public int Dereference => ((Asn1Enumerated)((RfcSearchRequest)Asn1Object.Get(1)).Get(2)).IntValue();
///
/// Retrieves the maximum number of entries to be returned on a search.
///
///
/// The maximum results.
///
public int MaxResults => ((Asn1Integer)((RfcSearchRequest)Asn1Object.Get(1)).Get(3)).IntValue();
///
/// Retrieves the server time limit for a search request.
///
///
/// The server time limit.
///
public int ServerTimeLimit => ((Asn1Integer)((RfcSearchRequest)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 bool TypesOnly => ((Asn1Boolean)((RfcSearchRequest)Asn1Object.Get(1)).Get(5)).BooleanValue();
///
/// Retrieves an array of attribute names to request for in a search.
///
///
/// The attributes.
///
public string[] Attributes
{
get
{
var attrs = (RfcAttributeDescriptionList)((RfcSearchRequest)Asn1Object.Get(1)).Get(7);
var values = new string[attrs.Size()];
for (var 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 => RfcFilter.FilterToString();
///
/// Retrieves an SearchFilter object representing a filter for a search request.
///
///
/// The RFC filter.
///
private RfcFilter RfcFilter => (RfcFilter)((RfcSearchRequest)Asn1Object.Get(1)).Get(6);
}
}