| 1 |
/****************************************************************************** |
| 2 |
* The MIT License |
| 3 |
* Copyright (c) 2003 Novell Inc. www.novell.com |
| 4 |
* |
| 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: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 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 |
| 21 |
* SOFTWARE. |
| 22 |
*******************************************************************************/ |
| 23 |
// |
| 24 |
// Novell.Directory.Ldap.Controls.LdapPersistSearchControl.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Sunil Kumar ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2003 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
using System; |
| 33 |
using Novell.Directory.Ldap; |
| 34 |
using Novell.Directory.Ldap.Asn1; |
| 35 |
|
| 36 |
namespace Novell.Directory.Ldap.Controls |
| 37 |
{ |
| 38 |
|
| 39 |
|
| 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. |
| 45 |
/// </summary> |
| 46 |
public class LdapPersistSearchControl:LdapControl |
| 47 |
{ |
| 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. |
| 50 |
/// |
| 51 |
/// </summary> |
| 52 |
/// <returns> the change types to be monitored. The logical or of any of |
| 53 |
/// the following values: ADD, DELETE, MODIFY, and/or MODDN. |
| 54 |
/// </returns> |
| 55 |
/// <summary> Sets the change types to be monitored. |
| 56 |
/// |
| 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 |
| 60 |
/// preceding values. |
| 61 |
/// </summary> |
| 62 |
virtual public int ChangeTypes |
| 63 |
{ |
| 64 |
get |
| 65 |
{ |
| 66 |
return m_changeTypes; |
| 67 |
} |
| 68 |
|
| 69 |
set |
| 70 |
{ |
| 71 |
m_changeTypes = value; |
| 72 |
m_sequence.set_Renamed(CHANGETYPES_INDEX, new Asn1Integer(m_changeTypes)); |
| 73 |
setValue(); |
| 74 |
return ; |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
/// <summary> Returns true if entry change controls are to be returned with the |
| 79 |
/// search results. |
| 80 |
/// |
| 81 |
/// </summary> |
| 82 |
/// <returns> true if entry change controls are to be returned with the |
| 83 |
/// search results. Otherwise, false is returned |
| 84 |
/// </returns> |
| 85 |
/// <summary> When set to true, requests that entry change controls be returned with |
| 86 |
/// the search results. |
| 87 |
/// |
| 88 |
/// </summary> |
| 89 |
/// <param name="returnControls"> true to return entry change controls. |
| 90 |
/// </param> |
| 91 |
virtual public bool ReturnControls |
| 92 |
{ |
| 93 |
get |
| 94 |
{ |
| 95 |
return m_returnControls; |
| 96 |
} |
| 97 |
|
| 98 |
set |
| 99 |
{ |
| 100 |
m_returnControls = value; |
| 101 |
m_sequence.set_Renamed(RETURNCONTROLS_INDEX, new Asn1Boolean(m_returnControls)); |
| 102 |
setValue(); |
| 103 |
return ; |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
/// <summary> getChangesOnly returns true if only changes are to be returned. |
| 108 |
/// Results from the initial search are not returned. |
| 109 |
/// |
| 110 |
/// </summary> |
| 111 |
/// <returns> true of only changes are to be returned |
| 112 |
/// </returns> |
| 113 |
/// <summary> When set to true, requests that only changes be returned, results from |
| 114 |
/// the initial search are not returned. |
| 115 |
/// </summary> |
| 116 |
/// <param name="changesOnly"> true to skip results for the initial search |
| 117 |
/// </param> |
| 118 |
virtual public bool ChangesOnly |
| 119 |
{ |
| 120 |
get |
| 121 |
{ |
| 122 |
return m_changesOnly; |
| 123 |
} |
| 124 |
|
| 125 |
set |
| 126 |
{ |
| 127 |
m_changesOnly = value; |
| 128 |
m_sequence.set_Renamed(CHANGESONLY_INDEX, new Asn1Boolean(m_changesOnly)); |
| 129 |
setValue(); |
| 130 |
return ; |
| 131 |
} |
| 132 |
|
| 133 |
} |
| 134 |
/* private data members */ |
| 135 |
private static int SEQUENCE_SIZE = 3; |
| 136 |
|
| 137 |
private static int CHANGETYPES_INDEX = 0; |
| 138 |
private static int CHANGESONLY_INDEX = 1; |
| 139 |
private static int RETURNCONTROLS_INDEX = 2; |
| 140 |
|
| 141 |
private static LBEREncoder s_encoder; |
| 142 |
|
| 143 |
private int m_changeTypes; |
| 144 |
private bool m_changesOnly; |
| 145 |
private bool m_returnControls; |
| 146 |
private Asn1Sequence m_sequence; |
| 147 |
|
| 148 |
/// <summary> The requestOID of the persistent search control</summary> |
| 149 |
private static System.String requestOID = "2.16.840.1.113730.3.4.3"; |
| 150 |
|
| 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"; |
| 153 |
|
| 154 |
/// <summary> Change type specifying that you want to track additions of new entries |
| 155 |
/// to the directory. |
| 156 |
/// </summary> |
| 157 |
public const int ADD = 1; |
| 158 |
|
| 159 |
/// <summary> Change type specifying that you want to track removals of entries from |
| 160 |
/// the directory. |
| 161 |
/// </summary> |
| 162 |
public const int DELETE = 2; |
| 163 |
|
| 164 |
/// <summary> Change type specifying that you want to track modifications of entries |
| 165 |
/// in the directory. |
| 166 |
/// </summary> |
| 167 |
public const int MODIFY = 4; |
| 168 |
|
| 169 |
/// <summary> Change type specifying that you want to track modifications of the DNs |
| 170 |
/// of entries in the directory. |
| 171 |
/// </summary> |
| 172 |
public const int MODDN = 8; |
| 173 |
|
| 174 |
/// <summary> Change type specifying that you want to track any of the above |
| 175 |
/// modifications. |
| 176 |
/// </summary> |
| 177 |
public static readonly int ANY = ADD | DELETE | MODIFY | MODDN; |
| 178 |
|
| 179 |
/* public constructors */ |
| 180 |
|
| 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 |
| 184 |
/// </summary> |
| 185 |
public LdapPersistSearchControl():this(ANY, true, true, true) |
| 186 |
{ |
| 187 |
return ; |
| 188 |
} |
| 189 |
|
| 190 |
/// <summary> Constructs an LdapPersistSearchControl object according to the |
| 191 |
/// supplied parameters. The resulting control is used to specify a |
| 192 |
/// persistent search. |
| 193 |
/// |
| 194 |
/// </summary> |
| 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> |
| 203 |
/// |
| 204 |
/// </param> |
| 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 |
| 208 |
/// returned.) |
| 209 |
/// |
| 210 |
/// </param> |
| 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. |
| 215 |
/// |
| 216 |
/// </param> |
| 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. |
| 220 |
/// </param> |
| 221 |
public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical):base(requestOID, isCritical, null) |
| 222 |
{ |
| 223 |
|
| 224 |
m_changeTypes = changeTypes; |
| 225 |
m_changesOnly = changesOnly; |
| 226 |
m_returnControls = returnControls; |
| 227 |
|
| 228 |
m_sequence = new Asn1Sequence(SEQUENCE_SIZE); |
| 229 |
|
| 230 |
m_sequence.add(new Asn1Integer(m_changeTypes)); |
| 231 |
m_sequence.add(new Asn1Boolean(m_changesOnly)); |
| 232 |
m_sequence.add(new Asn1Boolean(m_returnControls)); |
| 233 |
|
| 234 |
setValue(); |
| 235 |
return ; |
| 236 |
} |
| 237 |
|
| 238 |
public override System.String ToString() |
| 239 |
{ |
| 240 |
sbyte[] data = m_sequence.getEncoding(s_encoder); |
| 241 |
|
| 242 |
System.Text.StringBuilder buf = new System.Text.StringBuilder(data.Length); |
| 243 |
|
| 244 |
for (int i = 0; i < data.Length; i++) |
| 245 |
{ |
| 246 |
buf.Append(data[i].ToString()); |
| 247 |
if (i < data.Length - 1) |
| 248 |
buf.Append(","); |
| 249 |
} |
| 250 |
|
| 251 |
return buf.ToString(); |
| 252 |
} |
| 253 |
|
| 254 |
/// <summary> Sets the encoded value of the LdapControlClass</summary> |
| 255 |
private void setValue() |
| 256 |
{ |
| 257 |
base.setValue(m_sequence.getEncoding(s_encoder)); |
| 258 |
return ; |
| 259 |
} |
| 260 |
static LdapPersistSearchControl() |
| 261 |
{ |
| 262 |
s_encoder = new LBEREncoder(); |
| 263 |
/* |
| 264 |
* This is where we register the control response |
| 265 |
*/ |
| 266 |
{ |
| 267 |
/* Register the Entry Change control class which is returned by the |
| 268 |
* server in response to a persistent search request |
| 269 |
*/ |
| 270 |
try |
| 271 |
{ |
| 272 |
// Register LdapEntryChangeControl |
| 273 |
LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapEntryChangeControl")); |
| 274 |
} |
| 275 |
catch (System.Exception e) |
| 276 |
{ |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} // end class LdapPersistentSearchControl |
| 281 |
} |