Debian Codegraph @

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Rfc2251/RfcExtendedResponse.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.Rfc2251.RfcExtendedResponse.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.Asn1;
34 using Novell.Directory.Ldap;
35
36 namespace Novell.Directory.Ldap.Rfc2251
37 {
38
39 /// <summary> Represents an Ldap Extended Response.
40 ///
41 /// <pre>
42 /// ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
43 /// COMPONENTS OF LdapResult,
44 /// responseName [10] LdapOID OPTIONAL,
45 /// response [11] OCTET STRING OPTIONAL }
46 /// </pre>
47 /// </summary>
48 public class RfcExtendedResponse:Asn1Sequence, RfcResponse
49 {
50 /// <summary> </summary>
51 virtual public RfcLdapOID ResponseName
52 {
53 get
54 {
55 return (responseNameIndex != 0)?(RfcLdapOID) get_Renamed(responseNameIndex):null;
56 }
57
58 }
59 /// <summary> </summary>
60 [CLSCompliantAttribute(false)]
61 virtual public Asn1OctetString Response
62 {
63 get
64 {
65 return (responseIndex != 0)?(Asn1OctetString) get_Renamed(responseIndex):null;
66 }
67
68 }
69
70 /// <summary> Context-specific TAG for optional responseName.</summary>
71 public const int RESPONSE_NAME = 10;
72 /// <summary> Context-specific TAG for optional response.</summary>
73 public const int RESPONSE = 11;
74
75 private int referralIndex;
76 private int responseNameIndex;
77 private int responseIndex;
78
79 //*************************************************************************
80 // Constructors for ExtendedResponse
81 //*************************************************************************
82
83 /// <summary> The only time a client will create a ExtendedResponse is when it is
84 /// decoding it from an InputStream
85 /// </summary>
86 [CLSCompliantAttribute(false)]
87 public RfcExtendedResponse(Asn1Decoder dec, System.IO.Stream in_Renamed, int len):base(dec, in_Renamed, len)
88 {
89
90
91 // decode optional tagged elements
92 if (size() > 3)
93 {
94 for (int i = 3; i < size(); i++)
95 {
96 Asn1Tagged obj = (Asn1Tagged) get_Renamed(i);
97 Asn1Identifier id = obj.getIdentifier();
98 switch (id.Tag)
99 {
100
101 case RfcLdapResult.REFERRAL:
102 sbyte[] content = ((Asn1OctetString) obj.taggedValue()).byteValue();
103 System.IO.MemoryStream bais = new System.IO.MemoryStream(SupportClass.ToByteArray(content));
104 set_Renamed(i, new RfcReferral(dec, bais, content.Length));
105 referralIndex = i;
106 break;
107
108 case RESPONSE_NAME:
109 set_Renamed(i, new RfcLdapOID(((Asn1OctetString) obj.taggedValue()).byteValue()));
110 responseNameIndex = i;
111 break;
112
113 case RESPONSE:
114 set_Renamed(i, obj.taggedValue());
115 responseIndex = i;
116 break;
117 }
118 }
119 }
120 }
121
122 //*************************************************************************
123 // Accessors
124 //*************************************************************************
125
126 /// <summary> </summary>
127 public Asn1Enumerated getResultCode()
128 {
129 return (Asn1Enumerated) get_Renamed(0);
130 }
131
132 /// <summary> </summary>
133 public RfcLdapDN getMatchedDN()
134 {
135 return new RfcLdapDN(((Asn1OctetString) get_Renamed(1)).byteValue());
136 }
137
138 /// <summary> </summary>
139 public RfcLdapString getErrorMessage()
140 {
141 return new RfcLdapString(((Asn1OctetString) get_Renamed(2)).byteValue());
142 }
143
144 /// <summary> </summary>
145 public RfcReferral getReferral()
146 {
147 return (referralIndex != 0)?(RfcReferral) get_Renamed(referralIndex):null;
148 }
149
150 /// <summary> Override getIdentifier to return an application-wide id.</summary>
151 public override Asn1Identifier getIdentifier()
152 {
153 return new Asn1Identifier(Asn1Identifier.APPLICATION, true, LdapMessage.EXTENDED_RESPONSE);
154 }
155 }
156 }