1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapSearchConstraints.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
34 namespace Novell
.Directory
.Ldap
38 /// Defines the options controlling search operations.
40 /// An LdapSearchConstraints object is always associated with an
41 /// LdapConnection object; its values can be changed with the
42 /// LdapConnection.setConstraints method, or overridden by passing
43 /// an LdapSearchConstraints object to the search operation.
46 /// <seealso cref="LdapConstraints">
48 /// <seealso cref="LdapConnection.Constraints">
50 public class LdapSearchConstraints
:LdapConstraints
52 private void InitBlock()
54 dereference
= DEREF_NEVER
;
56 /// <summary> Returns the number of results to block on during receipt of search
59 /// This should be 0 if intermediate reults are not needed,
60 /// and 1 if results are to be processed as they come in. A value of
61 /// indicates block until all results are received. Default:
64 /// <returns> The the number of results to block on.
67 /// <seealso cref="BatchSize">
69 /// <summary> Specifies the number of results to return in a batch.
70 /// Specifying 0 means to block until all results are received.
71 /// Specifying 1 means to return results one result at a time. Default: 1
74 /// This should be 0 if intermediate results are not needed,
75 /// and 1 if results are to be processed as they come in. The
79 /// <param name="batchSize"> The number of results to block on.
82 /// <seealso cref="BatchSize">
84 virtual public int BatchSize
93 this.batchSize
= value;
98 /// <summary> Specifies when aliases should be dereferenced.
100 /// Returns one of the following:
102 /// <li>DEREF_NEVER</li>
103 /// <li>DEREF_FINDING</li>
104 /// <li>DEREF_SEARCHING</li>
105 /// <li>DEREF_ALWAYS</li>
109 /// <returns> The setting for dereferencing aliases.
112 /// <seealso cref="Dereference">
114 /// <summary> Sets a preference indicating whether or not aliases should be
115 /// dereferenced, and if so, when.
119 /// <param name="dereference"> Specifies how aliases are dereference and can be set
120 /// to one of the following:
122 /// <li>DEREF_NEVER - do not dereference aliases</li>
123 /// <li>DEREF_FINDING - dereference aliases when finding
124 /// the base object to start the search</li>
125 /// <li>DEREF_SEARCHING - dereference aliases when
126 /// searching but not when finding the base
127 /// object to start the search</li>
128 /// <li>DEREF_ALWAYS - dereference aliases when finding
129 /// the base object and when searching</li>
133 /// <seealso cref="Dereference">
135 virtual public int Dereference
144 this.dereference
= value;
149 /// <summary> Returns the maximum number of search results to be returned for
150 /// a search operation. A value of 0 means no limit. Default: 1000
151 /// The search operation will be terminated with an
152 /// LdapException.SIZE_LIMIT_EXCEEDED if the number of results
153 /// exceed the maximum.
156 /// <returns> The value for the maximum number of results to return.
159 /// <seealso cref="MaxResults">
161 /// <seealso cref="LdapException.SIZE_LIMIT_EXCEEDED">
163 /// <summary> Sets the maximum number of search results to be returned from a
164 /// search operation. The value 0 means no limit. The default is 1000.
165 /// The search operation will be terminated with an
166 /// LdapException.SIZE_LIMIT_EXCEEDED if the number of results
167 /// exceed the maximum.
170 /// <param name="maxResults"> Maximum number of search results to return.
173 /// <seealso cref="MaxResults">
175 /// <seealso cref="LdapException.SIZE_LIMIT_EXCEEDED">
177 virtual public int MaxResults
186 this.maxResults
= value;
191 /// <summary> Returns the maximum number of seconds that the server waits when
192 /// returning search results.
193 /// The search operation will be terminated with an
194 /// LdapException.TIME_LIMIT_EXCEEDED if the operation exceeds the time
198 /// <returns> The maximum number of seconds the server waits for search'
202 /// <seealso cref="ServerTimeLimit">
204 /// <seealso cref="LdapException.TIME_LIMIT_EXCEEDED">
206 /// <summary> Sets the maximum number of seconds that the server is to wait when
207 /// returning search results.
208 /// The search operation will be terminated with an
209 /// LdapException.TIME_LIMIT_EXCEEDED if the operation exceeds the time
212 /// The parameter is only recognized on search operations.
215 /// <param name="seconds">The number of seconds to wait for search results.
218 /// <seealso cref="ServerTimeLimit">
220 /// <seealso cref="LdapException.TIME_LIMIT_EXCEEDED">
222 virtual public int ServerTimeLimit
226 return serverTimeLimit
;
231 this.serverTimeLimit
= value;
237 private int dereference
;
238 private int serverTimeLimit
= 0;
239 private int maxResults
= 1000;
240 private int batchSize
= 1;
241 new private static System
.Object nameLock
; // protect agentNum
242 private static int lSConsNum
= 0; // Debug, LdapConnection number
243 new private System
.String name
; // String name for debug
245 /// <summary> Indicates that aliases are never dereferenced.
250 /// <seealso cref="Dereference">
252 /// <seealso cref="Dereference">
254 public const int DEREF_NEVER
= 0;
256 /// <summary> Indicates that aliases are are derefrenced when
257 /// searching the entries beneath the starting point of the search,
258 /// but not when finding the starting entry.
260 /// DEREF_SEARCHING = 1
263 /// <seealso cref="Dereference">
265 /// <seealso cref="Dereference">
267 public const int DEREF_SEARCHING
= 1;
269 /// <summary> Indicates that aliases are dereferenced when
270 /// finding the starting point for the search,
271 /// but not when searching under that starting entry.
273 /// DEREF_FINDING = 2
276 /// <seealso cref="Dereference">
278 /// <seealso cref="Dereference">
280 public const int DEREF_FINDING
= 2;
282 /// <summary> Indicates that aliases are always dereferenced, both when
283 /// finding the starting point for the search, and also when
284 /// searching the entries beneath the starting entry.
289 /// <seealso cref="Dereference">
291 /// <seealso cref="Dereference">
293 public const int DEREF_ALWAYS
= 3;
295 /// <summary> Constructs an LdapSearchConstraints object with a default set
296 /// of search constraints.
298 public LdapSearchConstraints():base()
301 // Get a unique connection name for debug
304 /// <summary> Constructs an LdapSearchConstraints object initialized with values
305 /// from an existing constraints object (LdapConstraints
306 /// or LdapSearchConstraints).
308 public LdapSearchConstraints(LdapConstraints cons
):base(cons
.TimeLimit
, cons
.ReferralFollowing
, cons
.getReferralHandler(), cons
.HopLimit
)
311 LdapControl
[] lsc
= cons
.getControls();
314 LdapControl
[] generated_var
= new LdapControl
[lsc
.Length
];
315 lsc
.CopyTo(generated_var
, 0);
316 base.setControls(generated_var
);
318 System
.Collections
.Hashtable lp
= cons
.Properties
;
321 base.Properties
= (System
.Collections
.Hashtable
) lp
.Clone();
324 if (cons
is LdapSearchConstraints
)
326 LdapSearchConstraints scons
= (LdapSearchConstraints
) cons
;
327 this.serverTimeLimit
= scons
.ServerTimeLimit
;
328 this.dereference
= scons
.Dereference
;
329 this.maxResults
= scons
.MaxResults
;
330 this.batchSize
= scons
.BatchSize
;
332 // Get a unique connection name for debug
336 /// <summary> Constructs a new LdapSearchConstraints object and allows the
337 /// specification operational constraints in that object.
340 /// <param name="msLimit"> The maximum time in milliseconds to wait for results.
341 /// The default is 0, which means that there is no
342 /// maximum time limit. This limit is enforced for an
343 /// operation by the API, not by the server.
344 /// The operation will be abandoned and terminated by the
345 /// API with an LdapException.Ldap_TIMEOUT if the
346 /// operation exceeds the time limit.
349 /// <param name="serverTimeLimit">The maximum time in seconds that the server
350 /// should spend returning search results. This is a
351 /// server-enforced limit. The default of 0 means
353 /// The operation will be terminated by the server with an
354 /// LdapException.TIME_LIMIT_EXCEEDED if the search
355 /// operation exceeds the time limit.
358 /// <param name="dereference">Specifies when aliases should be dereferenced.
359 /// Must be either DEREF_NEVER, DEREF_FINDING,
360 /// DEREF_SEARCHING, or DEREF_ALWAYS from this class.
361 /// Default: DEREF_NEVER
364 /// <param name="maxResults">The maximum number of search results to return
365 /// for a search request.
366 /// The search operation will be terminated by the server
367 /// with an LdapException.SIZE_LIMIT_EXCEEDED if the
368 /// number of results exceed the maximum.
372 /// <param name="doReferrals">Determines whether to automatically follow
373 /// referrals or not. Specify true to follow
374 /// referrals automatically, and false to throw
375 /// an LdapException.REFERRAL if the server responds
377 /// It is ignored for asynchronous operations.
381 /// <param name="batchSize">The number of results to return in a batch. Specifying
382 /// 0 means to block until all results are received.
383 /// Specifying 1 means to return results one result at a
388 /// <param name="handler"> The custom authentication handler called when
389 /// LdapConnection needs to authenticate, typically on
390 /// following a referral. A null may be specified to
391 /// indicate default authentication processing, i.e.
392 /// referrals are followed with anonymous authentication.
393 /// ThE object may be an implemention of either the
394 /// the LdapBindHandler or LdapAuthHandler interface.
395 /// It is ignored for asynchronous operations.
398 /// <param name="hop_limit">The maximum number of referrals to follow in a
399 /// sequence during automatic referral following.
400 /// The default value is 10. A value of 0 means no limit.
401 /// It is ignored for asynchronous operations.
402 /// The operation will be abandoned and terminated by the
403 /// API with an LdapException.REFERRAL_LIMIT_EXCEEDED if the
404 /// number of referrals in a sequence exceeds the limit.
407 /// <seealso cref="LdapException.Ldap_TIMEOUT">
409 /// <seealso cref="LdapException.REFERRAL">
411 /// <seealso cref="LdapException.SIZE_LIMIT_EXCEEDED">
413 /// <seealso cref="LdapException.TIME_LIMIT_EXCEEDED">
415 public LdapSearchConstraints(int msLimit
, int serverTimeLimit
, int dereference
, int maxResults
, bool doReferrals
, int batchSize
, LdapReferralHandler handler
, int hop_limit
):base(msLimit
, doReferrals
, handler
, hop_limit
)
418 this.serverTimeLimit
= serverTimeLimit
;
419 this.dereference
= dereference
;
420 this.maxResults
= maxResults
;
421 this.batchSize
= batchSize
;
422 // Get a unique connection name for debug
425 static LdapSearchConstraints()
427 nameLock
= new System
.Object();