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.Controls.LdapPersistSearchControl.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using Novell.Directory.Ldap;
\r
34 using Novell.Directory.Ldap.Asn1;
\r
36 namespace Novell.Directory.Ldap.Controls
\r
40 /// <summary> LdapPersistSearchControl is a Server Control that allows a client
\r
41 /// to receive notifications from the server of changes to entries within
\r
42 /// the searches result set. The client can be notified when an entry is
\r
43 /// added to the result set, when an entry is deleted from the result set,
\r
44 /// when a DN has been changed or when and attribute value has been changed.
\r
46 /// <p>Sample Code: <a href="http://developer.novell.com/ndk/doc/samplecode/
\r
47 /// jldap_sample/controls/SearchPersist.java.html">SearchPersist.java</p>
\r
49 public class LdapPersistSearchControl:LdapControl
\r
51 /// <summary> Returns the change types to be monitored as a logical OR of any or
\r
52 /// all of these values: ADD, DELETE, MODIFY, and/or MODDN.
\r
55 /// <returns> the change types to be monitored. The logical or of any of
\r
56 /// the following values: ADD, DELETE, MODIFY, and/or MODDN.
\r
58 /// <summary> Sets the change types to be monitored.
\r
60 /// types The change types to be monitored as a logical OR of any or all
\r
61 /// of these types: ADD, DELETE, MODIFY, and/or MODDN. Can also be set
\r
62 /// to the value ANY which is defined as the logical OR of all of the
\r
63 /// preceding values.
\r
65 virtual public int ChangeTypes
\r
69 return m_changeTypes;
\r
74 m_changeTypes = value;
\r
75 m_sequence.set_Renamed(CHANGETYPES_INDEX, new Asn1Integer(m_changeTypes));
\r
81 /// <summary> Returns true if entry change controls are to be returned with the
\r
85 /// <returns> true if entry change controls are to be returned with the
\r
86 /// search results. Otherwise, false is returned
\r
88 /// <summary> When set to true, requests that entry change controls be returned with
\r
89 /// the search results.
\r
92 /// <param name="returnControls"> true to return entry change controls.
\r
94 virtual public bool ReturnControls
\r
98 return m_returnControls;
\r
103 m_returnControls = value;
\r
104 m_sequence.set_Renamed(RETURNCONTROLS_INDEX, new Asn1Boolean(m_returnControls));
\r
110 /// <summary> getChangesOnly returns true if only changes are to be returned.
\r
111 /// Results from the initial search are not returned.
\r
114 /// <returns> true of only changes are to be returned
\r
116 /// <summary> When set to true, requests that only changes be returned, results from
\r
117 /// the initial search are not returned.
\r
119 /// <param name="changesOnly"> true to skip results for the initial search
\r
121 virtual public bool ChangesOnly
\r
125 return m_changesOnly;
\r
130 m_changesOnly = value;
\r
131 m_sequence.set_Renamed(CHANGESONLY_INDEX, new Asn1Boolean(m_changesOnly));
\r
137 /* private data members */
\r
138 private static int SEQUENCE_SIZE = 3;
\r
140 private static int CHANGETYPES_INDEX = 0;
\r
141 private static int CHANGESONLY_INDEX = 1;
\r
142 private static int RETURNCONTROLS_INDEX = 2;
\r
144 private static LBEREncoder s_encoder;
\r
146 private int m_changeTypes;
\r
147 private bool m_changesOnly;
\r
148 private bool m_returnControls;
\r
149 private Asn1Sequence m_sequence;
\r
151 /// <summary> The requestOID of the persistent search control</summary>
\r
152 private static System.String requestOID = "2.16.840.1.113730.3.4.3";
\r
154 /// <summary> The responseOID of the psersistent search - entry change control</summary>
\r
155 private static System.String responseOID = "2.16.840.1.113730.3.4.7";
\r
157 /// <summary> Change type specifying that you want to track additions of new entries
\r
158 /// to the directory.
\r
160 public const int ADD = 1;
\r
162 /// <summary> Change type specifying that you want to track removals of entries from
\r
165 public const int DELETE = 2;
\r
167 /// <summary> Change type specifying that you want to track modifications of entries
\r
168 /// in the directory.
\r
170 public const int MODIFY = 4;
\r
172 /// <summary> Change type specifying that you want to track modifications of the DNs
\r
173 /// of entries in the directory.
\r
175 public const int MODDN = 8;
\r
177 /// <summary> Change type specifying that you want to track any of the above
\r
180 public static readonly int ANY = ADD | DELETE | MODIFY | MODDN;
\r
182 /* public constructors */
\r
184 /// <summary> The default constructor. A control with changes equal to ANY,
\r
185 /// isCritical equal to true, changesOnly equal to true, and
\r
186 /// returnControls equal to true
\r
188 public LdapPersistSearchControl():this(ANY, true, true, true)
\r
193 /// <summary> <p>Constructs an LdapPersistSearchControl object according to the
\r
194 /// supplied parameters. The resulting control is used to specify a
\r
195 /// persistent search.</p>
\r
198 /// <param name="changeTypes"> the change types to monitor. The bitwise OR of any
\r
199 /// of the following values:
\r
200 /// <li> LdapPersistSearchControl.ADD</li>
\r
201 /// <li> LdapPersistSearchControl.DELETE</li>
\r
202 /// <li> LdapPersistSearchControl.MODIFY</li>
\r
203 /// <li> LdapPersistSearchControl.MODDN</li>
\r
204 /// To track all changes the value can be set to:
\r
205 /// <li> LdapPersistSearchControl.ANY</li>
\r
208 /// <param name="changesOnly"> true if you do not want the server to return
\r
209 /// all existing entries in the directory that match the search
\r
210 /// criteria. (Use this if you just want the changed entries to be
\r
214 /// <param name="returnControls"> true if you want the server to return entry
\r
215 /// change controls with each entry in the search results. You need to
\r
216 /// return entry change controls to discover what type of change
\r
217 /// and other additional information about the change.
\r
220 /// <param name="isCritical"> true if this control is critical to the search
\r
221 /// operation. If true and the server does not support this control,
\r
222 /// the server will not perform the search at all.
\r
224 public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical):base(requestOID, isCritical, null)
\r
227 m_changeTypes = changeTypes;
\r
228 m_changesOnly = changesOnly;
\r
229 m_returnControls = returnControls;
\r
231 m_sequence = new Asn1Sequence(SEQUENCE_SIZE);
\r
233 m_sequence.add(new Asn1Integer(m_changeTypes));
\r
234 m_sequence.add(new Asn1Boolean(m_changesOnly));
\r
235 m_sequence.add(new Asn1Boolean(m_returnControls));
\r
241 public override System.String ToString()
\r
243 sbyte[] data = m_sequence.getEncoding(s_encoder);
\r
245 System.Text.StringBuilder buf = new System.Text.StringBuilder(data.Length);
\r
247 for (int i = 0; i < data.Length; i++)
\r
249 buf.Append(data[i].ToString());
\r
250 if (i < data.Length - 1)
\r
254 return buf.ToString();
\r
257 /// <summary> Sets the encoded value of the LdapControlClass</summary>
\r
258 private void setValue()
\r
260 base.setValue(m_sequence.getEncoding(s_encoder));
\r
263 static LdapPersistSearchControl()
\r
265 s_encoder = new LBEREncoder();
\r
267 * This is where we register the control response
\r
270 /* Register the Entry Change control class which is returned by the
\r
271 * server in response to a persistent search request
\r
275 // Register LdapEntryChangeControl
\r
276 LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapEntryChangeControl"));
\r
278 catch (System.Exception e)
\r
283 } // end class LdapPersistentSearchControl
\r