Debian Codegraph @

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Events.Edir.EventData/GeneralDSEventData.cs

raw
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.Events.Edir.EventData.GeneralDSEventData.cs
25 //
26 // Author:
27 // Anil Bhatia ([email protected])
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31
32 using System.IO;
33 using System.Text;
34
35 using Novell.Directory.Ldap.Asn1;
36
37 namespace Novell.Directory.Ldap.Events.Edir.EventData
38 {
39 /// <summary>
40 /// The class represents the data for General DS Events.
41 /// </summary>
42 public class GeneralDSEventData : BaseEdirEventData
43 {
44 protected int ds_time;
45 public int DSTime
46 {
47 get
48 {
49 return ds_time;
50 }
51 }
52
53 protected int milli_seconds;
54 public int MilliSeconds
55 {
56 get
57 {
58 return milli_seconds;
59 }
60 }
61
62 protected int nVerb;
63 public int Verb
64 {
65 get
66 {
67 return nVerb;
68 }
69 }
70
71 protected int current_process;
72 public int CurrentProcess
73 {
74 get
75 {
76 return current_process;
77 }
78 }
79
80 protected string strPerpetratorDN;
81 public string PerpetratorDN
82 {
83 get
84 {
85 return strPerpetratorDN;
86 }
87 }
88
89 protected int[] integer_values;
90 public int[] IntegerValues
91 {
92 get
93 {
94 return integer_values;
95 }
96 }
97
98 protected string[] string_values;
99 public string[] StringValues
100 {
101 get
102 {
103 return string_values;
104 }
105 }
106
107 public GeneralDSEventData(EdirEventDataType eventDataType, Asn1Object message)
108 : base(eventDataType, message)
109 {
110 int[] length = new int[1];
111
112 ds_time = getTaggedIntValue(
113 (Asn1Tagged) decoder.decode(decodedData, length),
114 GeneralEventField.EVT_TAG_GEN_DSTIME);
115 milli_seconds = getTaggedIntValue(
116 (Asn1Tagged) decoder.decode(decodedData, length),
117 GeneralEventField.EVT_TAG_GEN_MILLISEC);
118
119 nVerb = getTaggedIntValue(
120 (Asn1Tagged) decoder.decode(decodedData, length),
121 GeneralEventField.EVT_TAG_GEN_VERB);
122 current_process = getTaggedIntValue(
123 (Asn1Tagged) decoder.decode(decodedData, length),
124 GeneralEventField.EVT_TAG_GEN_CURRPROC);
125
126 strPerpetratorDN = getTaggedStringValue(
127 (Asn1Tagged) decoder.decode(decodedData, length),
128 GeneralEventField.EVT_TAG_GEN_PERP);
129
130 Asn1Tagged temptaggedvalue =
131 ((Asn1Tagged) decoder.decode(decodedData, length));
132
133 if (temptaggedvalue.getIdentifier().Tag
134 == (int) GeneralEventField.EVT_TAG_GEN_INTEGERS)
135 {
136 //Integer List.
137 Asn1Sequence inteseq = getTaggedSequence(temptaggedvalue, GeneralEventField.EVT_TAG_GEN_INTEGERS);
138 Asn1Object[] intobject = inteseq.toArray();
139 integer_values = new int[intobject.Length];
140
141 for (int i = 0; i < intobject.Length; i++)
142 {
143 integer_values[i] = ((Asn1Integer) intobject[i]).intValue();
144 }
145
146 //second decoding for Strings.
147 temptaggedvalue = ((Asn1Tagged) decoder.decode(decodedData, length));
148 }
149 else
150 {
151 integer_values = null;
152 }
153
154 if ((temptaggedvalue.getIdentifier().Tag
155 == (int) GeneralEventField.EVT_TAG_GEN_STRINGS)
156 && (temptaggedvalue.getIdentifier().Constructed))
157 {
158 //String values.
159 Asn1Sequence inteseq =
160 getTaggedSequence(temptaggedvalue, GeneralEventField.EVT_TAG_GEN_STRINGS);
161 Asn1Object[] stringobject = inteseq.toArray();
162 string_values = new string[stringobject.Length];
163
164 for (int i = 0; i < stringobject.Length; i++)
165 {
166 string_values[i] =
167 ((Asn1OctetString) stringobject[i]).stringValue();
168 }
169 }
170 else
171 {
172 string_values = null;
173 }
174
175 DataInitDone();
176 }
177
178 protected int getTaggedIntValue(Asn1Tagged tagvalue, GeneralEventField tagid)
179 {
180 Asn1Object obj = tagvalue.taggedValue();
181
182 if ((int)tagid != tagvalue.getIdentifier().Tag)
183 {
184 throw new IOException("Unknown Tagged Data");
185 }
186
187 byte[] dbytes = SupportClass.ToByteArray(((Asn1OctetString) obj).byteValue());
188 MemoryStream data = new MemoryStream(dbytes);
189
190 LBERDecoder dec = new LBERDecoder();
191
192 int length = dbytes.Length;
193
194 return (int)(dec.decodeNumeric(data, length));
195 }
196
197 protected string getTaggedStringValue(Asn1Tagged tagvalue, GeneralEventField tagid)
198 {
199 Asn1Object obj = tagvalue.taggedValue();
200
201 if ((int)tagid != tagvalue.getIdentifier().Tag)
202 {
203 throw new IOException("Unknown Tagged Data");
204 }
205
206 byte[] dbytes = SupportClass.ToByteArray(((Asn1OctetString) obj).byteValue());
207 MemoryStream data = new MemoryStream(dbytes);
208
209 LBERDecoder dec = new LBERDecoder();
210
211 int length = dbytes.Length;
212
213 return (string) dec.decodeCharacterString(data, length);
214 }
215
216 protected Asn1Sequence getTaggedSequence(Asn1Tagged tagvalue, GeneralEventField tagid)
217 {
218 Asn1Object obj = tagvalue.taggedValue();
219
220 if ((int)tagid != tagvalue.getIdentifier().Tag)
221 {
222 throw new IOException("Unknown Tagged Data");
223 }
224
225 byte[] dbytes = SupportClass.ToByteArray(((Asn1OctetString) obj).byteValue());
226 MemoryStream data = new MemoryStream(dbytes);
227
228 LBERDecoder dec = new LBERDecoder();
229 int length = dbytes.Length;
230
231 return new Asn1Sequence(dec, data, length);
232 }
233
234 /// <summary>
235 /// Returns a string representation of the object.
236 /// </summary>
237 public override string ToString()
238 {
239 StringBuilder buf = new StringBuilder();
240
241 buf.Append("[GeneralDSEventData");
242 buf.AppendFormat("(DSTime={0})", ds_time);
243 buf.AppendFormat("(MilliSeconds={0})", milli_seconds);
244 buf.AppendFormat("(verb={0})",nVerb);
245 buf.AppendFormat("(currentProcess={0})", current_process);
246 buf.AppendFormat("(PerpetartorDN={0})", strPerpetratorDN);
247 buf.AppendFormat("(Integer Values={0})", integer_values);
248 buf.AppendFormat("(String Values={0})", string_values);
249 buf.Append("]");
250
251 return buf.ToString();
252 }
253 }
254 }