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;
34 using Novell.Directory.Ldap.Asn1;
36 namespace Novell.Directory.Ldap.Controls
40 /// <summary> LdapPersistSearchControl is a Server Control that allows a client
41 /// to receive notifications from the server of changes to entries within
42 /// the searches result set. The client can be notified when an entry is
43 /// added to the result set, when an entry is deleted from the result set,
44 /// when a DN has been changed or when and attribute value has been changed.
46 public class LdapPersistSearchControl:LdapControl
48 /// <summary> Returns the change types to be monitored as a logical OR of any or
49 /// all of these values: ADD, DELETE, MODIFY, and/or MODDN.
52 /// <returns> the change types to be monitored. The logical or of any of
53 /// the following values: ADD, DELETE, MODIFY, and/or MODDN.
55 /// <summary> Sets the change types to be monitored.
57 /// types The change types to be monitored as a logical OR of any or all
58 /// of these types: ADD, DELETE, MODIFY, and/or MODDN. Can also be set
59 /// to the value ANY which is defined as the logical OR of all of the
62 virtual public int ChangeTypes
71 m_changeTypes = value;
72 m_sequence.set_Renamed(CHANGETYPES_INDEX, new Asn1Integer(m_changeTypes));
78 /// <summary> Returns true if entry change controls are to be returned with the
82 /// <returns> true if entry change controls are to be returned with the
83 /// search results. Otherwise, false is returned
85 /// <summary> When set to true, requests that entry change controls be returned with
86 /// the search results.
89 /// <param name="returnControls"> true to return entry change controls.
91 virtual public bool ReturnControls
95 return m_returnControls;
100 m_returnControls = value;
101 m_sequence.set_Renamed(RETURNCONTROLS_INDEX, new Asn1Boolean(m_returnControls));
107 /// <summary> getChangesOnly returns true if only changes are to be returned.
108 /// Results from the initial search are not returned.
111 /// <returns> true of only changes are to be returned
113 /// <summary> When set to true, requests that only changes be returned, results from
114 /// the initial search are not returned.
116 /// <param name="changesOnly"> true to skip results for the initial search
118 virtual public bool ChangesOnly
122 return m_changesOnly;
127 m_changesOnly = value;
128 m_sequence.set_Renamed(CHANGESONLY_INDEX, new Asn1Boolean(m_changesOnly));
134 /* private data members */
135 private static int SEQUENCE_SIZE = 3;
137 private static int CHANGETYPES_INDEX = 0;
138 private static int CHANGESONLY_INDEX = 1;
139 private static int RETURNCONTROLS_INDEX = 2;
141 private static LBEREncoder s_encoder;
143 private int m_changeTypes;
144 private bool m_changesOnly;
145 private bool m_returnControls;
146 private Asn1Sequence m_sequence;
148 /// <summary> The requestOID of the persistent search control</summary>
149 private static System.String requestOID = "2.16.840.1.113730.3.4.3";
151 /// <summary> The responseOID of the psersistent search - entry change control</summary>
152 private static System.String responseOID = "2.16.840.1.113730.3.4.7";
154 /// <summary> Change type specifying that you want to track additions of new entries
155 /// to the directory.
157 public const int ADD = 1;
159 /// <summary> Change type specifying that you want to track removals of entries from
162 public const int DELETE = 2;
164 /// <summary> Change type specifying that you want to track modifications of entries
165 /// in the directory.
167 public const int MODIFY = 4;
169 /// <summary> Change type specifying that you want to track modifications of the DNs
170 /// of entries in the directory.
172 public const int MODDN = 8;
174 /// <summary> Change type specifying that you want to track any of the above
177 public static readonly int ANY = ADD | DELETE | MODIFY | MODDN;
179 /* public constructors */
181 /// <summary> The default constructor. A control with changes equal to ANY,
182 /// isCritical equal to true, changesOnly equal to true, and
183 /// returnControls equal to true
185 public LdapPersistSearchControl():this(ANY, true, true, true)
190 /// <summary> Constructs an LdapPersistSearchControl object according to the
191 /// supplied parameters. The resulting control is used to specify a
192 /// persistent search.
195 /// <param name="changeTypes"> the change types to monitor. The bitwise OR of any
196 /// of the following values:
197 /// <li> LdapPersistSearchControl.ADD</li>
198 /// <li> LdapPersistSearchControl.DELETE</li>
199 /// <li> LdapPersistSearchControl.MODIFY</li>
200 /// <li> LdapPersistSearchControl.MODDN</li>
201 /// To track all changes the value can be set to:
202 /// <li> LdapPersistSearchControl.ANY</li>
205 /// <param name="changesOnly"> true if you do not want the server to return
206 /// all existing entries in the directory that match the search
207 /// criteria. (Use this if you just want the changed entries to be
211 /// <param name="returnControls"> true if you want the server to return entry
212 /// change controls with each entry in the search results. You need to
213 /// return entry change controls to discover what type of change
214 /// and other additional information about the change.
217 /// <param name="isCritical"> true if this control is critical to the search
218 /// operation. If true and the server does not support this control,
219 /// the server will not perform the search at all.
221 public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical):base(requestOID, isCritical, null)
224 m_changeTypes = changeTypes;
225 m_changesOnly = changesOnly;
226 m_returnControls = returnControls;
228 m_sequence = new Asn1Sequence(SEQUENCE_SIZE);
230 m_sequence.add(new Asn1Integer(m_changeTypes));
231 m_sequence.add(new Asn1Boolean(m_changesOnly));
232 m_sequence.add(new Asn1Boolean(m_returnControls));
238 public override System.String ToString()
240 sbyte[] data = m_sequence.getEncoding(s_encoder);
242 System.Text.StringBuilder buf = new System.Text.StringBuilder(data.Length);
244 for (int i = 0; i < data.Length; i++)
246 buf.Append(data[i].ToString());
247 if (i < data.Length - 1)
251 return buf.ToString();
254 /// <summary> Sets the encoded value of the LdapControlClass</summary>
255 private void setValue()
257 base.setValue(m_sequence.getEncoding(s_encoder));
260 static LdapPersistSearchControl()
262 s_encoder = new LBEREncoder();
264 * This is where we register the control response
267 /* Register the Entry Change control class which is returned by the
268 * server in response to a persistent search request
272 // Register LdapEntryChangeControl
273 LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapEntryChangeControl"));
275 catch (System.Exception e)
280 } // end class LdapPersistentSearchControl