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.LdapEntryChangeControl.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
39 /// <summary> LdapEntryChangeControl is a Server Control returned at the request
40 /// of the client in response to a persistent search request. It
41 /// contains additional information about a change such as what type of
44 public class LdapEntryChangeControl
:LdapControl
46 /// <summary> returns the record number of the change in the servers change log.
49 /// <returns> the record number of the change in the server's change log.
50 /// The server may not return a change number. In this case the return
53 virtual public bool HasChangeNumber
59 return m_hasChangeNumber
;
63 /// <summary> returns the record number of the change in the servers change log.
66 /// <returns> the record number of the change in the server's change log.
67 /// The server may not return a change number. In this case the return
70 virtual public int ChangeNumber
76 return m_changeNumber
;
80 /// <summary> Returns the type of change that occured
83 /// <returns> returns one of the following values indicating the type of
84 /// change that occurred:
85 /// LdapPersistSearchControl.ADD
86 /// LdapPersistSearchControl.DELETE
87 /// LdapPersistSearchControl.MODIFY
88 /// LdapPersistSearchControl.MODDN.
90 virtual public int ChangeType
98 /// <summary> Returns the previous DN of the entry, if it was renamed.
101 /// <returns> the previous DN of the entry if the entry was renamed (ie. if the
102 /// change type is LdapersistSearchControl.MODDN.
104 virtual public System
.String PreviousDN
112 private int m_changeType
;
113 private System
.String m_previousDN
;
114 private bool m_hasChangeNumber
;
115 private int m_changeNumber
;
117 /// <summary> This constructor is called by the SDK to create an
118 /// LdapEntryChangeControl. This constructor should NOT be called by
119 /// application developers. It must be public since it resides in a
120 /// different package than the classes that call it.
121 /// The Entry Change Control is defined as follows:
122 /// EntryChangeNotification ::= SEQUENCE {
123 /// changeType ENUMERATED {
129 /// previousDN LdapDN OPTIONAL, -- modifyDN ops. only
130 /// changeNumber INTEGER OPTIONAL -- if supported
134 /// <param name="oid"> The OID of the control, as a dotted string.
137 /// <param name="critical"> True if the Ldap operation should be discarded if
138 /// the control is not supported. False if
139 /// the operation can be processed without the control.
142 /// <param name="value"> The control-specific data.
144 [CLSCompliantAttribute(false)]
145 public LdapEntryChangeControl(System
.String oid
, bool critical
, sbyte[] value_Renamed
):base(oid
, critical
, value_Renamed
)
148 // Create a decoder objet
149 LBERDecoder decoder
= new LBERDecoder();
151 throw new System
.IO
.IOException("Decoding error.");
153 // We should get a sequence initially
154 Asn1Object asnObj
= decoder
.decode(value_Renamed
);
156 if ((asnObj
== null) || (!(asnObj
is Asn1Sequence
)))
157 throw new System
.IO
.IOException("Decoding error.");
159 Asn1Sequence sequence
= (Asn1Sequence
) asnObj
;
162 // The first element in the sequence should be an enumerated type
163 Asn1Object asn1Obj
= sequence
.get_Renamed(0);
164 if ((asn1Obj
== null) || (!(asn1Obj
is Asn1Enumerated
)))
165 throw new System
.IO
.IOException("Decoding error.");
167 m_changeType
= ((Asn1Enumerated
) asn1Obj
).intValue();
169 //check for optional elements
170 if ((sequence
.size() > 1) && (m_changeType
== 8))
173 // get the previous DN - it is encoded as an octet string
174 asn1Obj
= sequence
.get_Renamed(1);
175 if ((asn1Obj
== null) || (!(asn1Obj
is Asn1OctetString
)))
176 throw new System
.IO
.IOException("Decoding error get previous DN");
178 m_previousDN
= ((Asn1OctetString
) asn1Obj
).stringValue();
185 //check for change number
186 if (sequence
.size() == 3)
188 asn1Obj
= sequence
.get_Renamed(2);
189 if ((asn1Obj
== null) || (!(asn1Obj
is Asn1Integer
)))
190 throw new System
.IO
.IOException("Decoding error getting change number");
192 m_changeNumber
= ((Asn1Integer
) asn1Obj
).intValue();
193 m_hasChangeNumber
= true;
196 m_hasChangeNumber
= false;
200 /// <summary> Returns a string representation of the control for debugging.</summary>
201 public override System
.String
ToString()
203 return base.ToString();
205 } //end class LdapEntryChangeControl