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.Rfc2251.RfcExtendedResponse.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using Novell.Directory.Ldap.Asn1;
34 using Novell.Directory.Ldap;
36 namespace Novell.Directory.Ldap.Rfc2251
39 /// <summary> Represents an Ldap Extended Response.
42 /// ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
43 /// COMPONENTS OF LdapResult,
44 /// responseName [10] LdapOID OPTIONAL,
45 /// response [11] OCTET STRING OPTIONAL }
48 public class RfcExtendedResponse:Asn1Sequence, RfcResponse
50 /// <summary> </summary>
51 virtual public RfcLdapOID ResponseName
55 return (responseNameIndex != 0)?(RfcLdapOID) get_Renamed(responseNameIndex):null;
59 /// <summary> </summary>
60 [CLSCompliantAttribute(false)]
61 virtual public Asn1OctetString Response
65 return (responseIndex != 0)?(Asn1OctetString) get_Renamed(responseIndex):null;
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;
75 private int referralIndex;
76 private int responseNameIndex;
77 private int responseIndex;
79 //*************************************************************************
80 // Constructors for ExtendedResponse
81 //*************************************************************************
83 /// <summary> The only time a client will create a ExtendedResponse is when it is
84 /// decoding it from an InputStream
86 [CLSCompliantAttribute(false)]
87 public RfcExtendedResponse(Asn1Decoder dec, System.IO.Stream in_Renamed, int len):base(dec, in_Renamed, len)
91 // decode optional tagged elements
94 for (int i = 3; i < size(); i++)
96 Asn1Tagged obj = (Asn1Tagged) get_Renamed(i);
97 Asn1Identifier id = obj.getIdentifier();
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));
109 set_Renamed(i, new RfcLdapOID(((Asn1OctetString) obj.taggedValue()).byteValue()));
110 responseNameIndex = i;
114 set_Renamed(i, obj.taggedValue());
122 //*************************************************************************
124 //*************************************************************************
126 /// <summary> </summary>
127 public Asn1Enumerated getResultCode()
129 return (Asn1Enumerated) get_Renamed(0);
132 /// <summary> </summary>
133 public RfcLdapDN getMatchedDN()
135 return new RfcLdapDN(((Asn1OctetString) get_Renamed(1)).byteValue());
138 /// <summary> </summary>
139 public RfcLdapString getErrorMessage()
141 return new RfcLdapString(((Asn1OctetString) get_Renamed(2)).byteValue());
144 /// <summary> </summary>
145 public RfcReferral getReferral()
147 return (referralIndex != 0)?(RfcReferral) get_Renamed(referralIndex):null;
150 /// <summary> Override getIdentifier to return an application-wide id.</summary>
151 public override Asn1Identifier getIdentifier()
153 return new Asn1Identifier(Asn1Identifier.APPLICATION, true, LdapMessage.EXTENDED_RESPONSE);