| 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.DebugParameter.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Anil Bhatia ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2003 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
using System; |
| 33 |
using System.Collections; |
| 34 |
using System.IO; |
| 35 |
using System.Text; |
| 36 |
|
| 37 |
using Novell.Directory.Ldap.Asn1; |
| 38 |
|
| 39 |
namespace Novell.Directory.Ldap.Events.Edir.EventData |
| 40 |
{ |
| 41 |
/// <summary> |
| 42 |
/// This class represents the Debug Paramenter that is part of |
| 43 |
/// the DebugEventData. |
| 44 |
/// </summary> |
| 45 |
public class DebugParameter |
| 46 |
{ |
| 47 |
protected DebugParameterType debug_type; |
| 48 |
public DebugParameterType DebugType |
| 49 |
{ |
| 50 |
get |
| 51 |
{ |
| 52 |
return debug_type; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
protected object objData; |
| 57 |
public object Data |
| 58 |
{ |
| 59 |
get |
| 60 |
{ |
| 61 |
return objData; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
public DebugParameter(Asn1Tagged dseObject) |
| 66 |
{ |
| 67 |
switch ((DebugParameterType)(dseObject.getIdentifier().Tag)) |
| 68 |
{ |
| 69 |
case DebugParameterType.ENTRYID: |
| 70 |
case DebugParameterType.INTEGER: |
| 71 |
objData = getTaggedIntValue(dseObject); |
| 72 |
break; |
| 73 |
|
| 74 |
case DebugParameterType.BINARY: |
| 75 |
objData = ((Asn1OctetString) dseObject.taggedValue()).byteValue(); |
| 76 |
break; |
| 77 |
|
| 78 |
case DebugParameterType.STRING: |
| 79 |
objData = ((Asn1OctetString) dseObject.taggedValue()).stringValue(); |
| 80 |
break; |
| 81 |
|
| 82 |
case DebugParameterType.TIMESTAMP: |
| 83 |
objData = new DSETimeStamp(getTaggedSequence(dseObject)); |
| 84 |
break; |
| 85 |
|
| 86 |
case DebugParameterType.TIMEVECTOR: |
| 87 |
ArrayList timeVector = new ArrayList(); |
| 88 |
Asn1Sequence seq = getTaggedSequence(dseObject); |
| 89 |
int count = ((Asn1Integer) seq.get_Renamed(0)).intValue(); |
| 90 |
if (count > 0) |
| 91 |
{ |
| 92 |
Asn1Sequence timeSeq = (Asn1Sequence) seq.get_Renamed(1); |
| 93 |
|
| 94 |
for (int i = 0; i < count; i++) |
| 95 |
{ |
| 96 |
timeVector.Add(new DSETimeStamp((Asn1Sequence) timeSeq.get_Renamed(i))); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
objData = timeVector; |
| 101 |
break; |
| 102 |
|
| 103 |
case DebugParameterType.ADDRESS: |
| 104 |
objData = new ReferralAddress(getTaggedSequence(dseObject)); |
| 105 |
break; |
| 106 |
|
| 107 |
default: |
| 108 |
throw new IOException("Unknown Tag in DebugParameter.."); |
| 109 |
} |
| 110 |
|
| 111 |
debug_type = (DebugParameterType)(dseObject.getIdentifier().Tag); |
| 112 |
} |
| 113 |
|
| 114 |
protected int getTaggedIntValue(Asn1Tagged tagVal) |
| 115 |
{ |
| 116 |
Asn1Object obj = tagVal.taggedValue(); |
| 117 |
byte[] dataBytes = SupportClass.ToByteArray(((Asn1OctetString) obj).byteValue()); |
| 118 |
|
| 119 |
MemoryStream decodedData = new MemoryStream(dataBytes); |
| 120 |
LBERDecoder decoder = new LBERDecoder(); |
| 121 |
|
| 122 |
return ((int) decoder.decodeNumeric( |
| 123 |
decodedData, |
| 124 |
dataBytes.Length)); |
| 125 |
} |
| 126 |
|
| 127 |
protected Asn1Sequence getTaggedSequence(Asn1Tagged tagVal) |
| 128 |
{ |
| 129 |
Asn1Object obj = tagVal.taggedValue(); |
| 130 |
byte[] dataBytes = SupportClass.ToByteArray(((Asn1OctetString) obj).byteValue()); |
| 131 |
|
| 132 |
MemoryStream decodedData = new MemoryStream(dataBytes); |
| 133 |
LBERDecoder decoder = new LBERDecoder(); |
| 134 |
|
| 135 |
return new Asn1Sequence(decoder, decodedData, dataBytes.Length); |
| 136 |
} |
| 137 |
|
| 138 |
/// <summary> |
| 139 |
/// Returns a string representation of the object. |
| 140 |
/// </summary> |
| 141 |
public override string ToString() |
| 142 |
{ |
| 143 |
StringBuilder buf = new StringBuilder(); |
| 144 |
buf.Append("[DebugParameter"); |
| 145 |
if (Enum.IsDefined(debug_type.GetType(), debug_type)) |
| 146 |
{ |
| 147 |
buf.AppendFormat("(type={0},", debug_type); |
| 148 |
buf.AppendFormat("value={0})", objData); |
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
buf.Append("(type=Unknown)"); |
| 153 |
} |
| 154 |
buf.Append("]"); |
| 155 |
|
| 156 |
return buf.ToString(); |
| 157 |
} |
| 158 |
} |
| 159 |
} |