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.RfcLdapResult.cs
25 //
26 // Author:
27 //   Sunil Kumar (Sunilk@novell.com)
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31 
32 using System;
33 using Novell.Directory.Ldap.Asn1;
34 
35 namespace Novell.Directory.Ldap.Rfc2251
36 {
37 
38 	/// <summary> Represents an LdapResult.
39 	///
40 	/// <pre>
41 	/// LdapResult ::= SEQUENCE {
42 	/// resultCode      ENUMERATED {
43 	/// success                      (0),
44 	/// operationsError              (1),
45 	/// protocolError                (2),
46 	/// timeLimitExceeded            (3),
47 	/// sizeLimitExceeded            (4),
48 	/// compareFalse                 (5),
49 	/// compareTrue                  (6),
50 	/// authMethodNotSupported       (7),
51 	/// strongAuthRequired           (8),
52 	/// -- 9 reserved --
53 	/// referral                     (10),  -- new
54 	/// adminLimitExceeded           (11),  -- new
55 	/// unavailableCriticalExtension (12),  -- new
56 	/// confidentialityRequired      (13),  -- new
57 	/// saslBindInProgress           (14),  -- new
58 	/// noSuchAttribute              (16),
59 	/// undefinedAttributeType       (17),
60 	/// inappropriateMatching        (18),
61 	/// constraintViolation          (19),
62 	/// attributeOrValueExists       (20),
63 	/// invalidAttributeSyntax       (21),
64 	/// -- 22-31 unused --
65 	/// noSuchObject                 (32),
66 	/// aliasProblem                 (33),
67 	/// invalidDNSyntax              (34),
68 	/// -- 35 reserved for undefined isLeaf --
69 	/// aliasDereferencingProblem    (36),
70 	/// -- 37-47 unused --
71 	/// inappropriateAuthentication  (48),
72 	///
73 	/// invalidCredentials           (49),
74 	/// insufficientAccessRights     (50),
75 	/// busy                         (51),
76 	/// unavailable                  (52),
77 	/// unwillingToPerform           (53),
78 	/// loopDetect                   (54),
79 	/// -- 55-63 unused --
80 	/// namingViolation              (64),
81 	/// objectClassViolation         (65),
82 	/// notAllowedOnNonLeaf          (66),
83 	/// notAllowedOnRDN              (67),
84 	/// entryAlreadyExists           (68),
85 	/// objectClassModsProhibited    (69),
86 	/// -- 70 reserved for CLdap --
87 	/// affectsMultipleDSAs          (71), -- new
88 	/// -- 72-79 unused --
89 	/// other                        (80) },
90 	/// -- 81-90 reserved for APIs --
91 	/// matchedDN       LdapDN,
92 	/// errorMessage    LdapString,
93 	/// referral        [3] Referral OPTIONAL }
94 	/// </pre>
95 	///
96 	/// </summary>
97 	public class RfcLdapResult:Asn1Sequence, RfcResponse
98 	{
99 
100 		/// <summary> Context-specific TAG for optional Referral.</summary>
101 		public const int REFERRAL = 3;
102 
103 		//*************************************************************************
104 		// Constructors for RfcLdapResult
105 		//*************************************************************************
106 
107 		/// <summary> Constructs an RfcLdapResult from parameters
108 		///
109 		/// </summary>
110 		/// <param name="resultCode">the result code of the operation
111 		///
112 		/// </param>
113 		/// <param name="matchedDN">the matched DN returned from the server
114 		///
115 		/// </param>
116 		/// <param name="errorMessage">the diagnostic message returned from the server
117 		/// </param>
RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage)118 		public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage):this(resultCode, matchedDN, errorMessage, null)
119 		{
120 			return ;
121 		}
122 
123 		/// <summary> Constructs an RfcLdapResult from parameters
124 		///
125 		/// </summary>
126 		/// <param name="resultCode">the result code of the operation
127 		///
128 		/// </param>
129 		/// <param name="matchedDN">the matched DN returned from the server
130 		///
131 		/// </param>
132 		/// <param name="errorMessage">the diagnostic message returned from the server
133 		///
134 		/// </param>
135 		/// <param name="referral">the referral(s) returned by the server
136 		/// </param>
RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, RfcReferral referral)137 		public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, RfcReferral referral):base(4)
138 		{
139 			add(resultCode);
140 			add(matchedDN);
141 			add(errorMessage);
142 			if (referral != null)
143 				add(referral);
144 			return ;
145 		}
146 
147 		/// <summary> Constructs an RfcLdapResult from the inputstream</summary>
148 		[CLSCompliantAttribute(false)]
RfcLdapResult(Asn1Decoder dec, System.IO.Stream in_Renamed, int len)149 		public RfcLdapResult(Asn1Decoder dec, System.IO.Stream in_Renamed, int len):base(dec, in_Renamed, len)
150 		{
151 
152 			// Decode optional referral from Asn1OctetString to Referral.
153 			if (size() > 3)
154 			{
155 				Asn1Tagged obj = (Asn1Tagged) get_Renamed(3);
156 				Asn1Identifier id = obj.getIdentifier();
157 				if (id.Tag == RfcLdapResult.REFERRAL)
158 				{
159 					sbyte[] content = ((Asn1OctetString) obj.taggedValue()).byteValue();
160 					System.IO.MemoryStream bais = new System.IO.MemoryStream(SupportClass.ToByteArray(content));
161 					set_Renamed(3, new RfcReferral(dec, bais, content.Length));
162 				}
163 			}
164 			return ;
165 		}
166 
167 		//*************************************************************************
168 		// Accessors
169 		//*************************************************************************
170 
171 		/// <summary> Returns the result code from the server
172 		///
173 		/// </summary>
174 		/// <returns> the result code
175 		/// </returns>
getResultCode()176 		public Asn1Enumerated getResultCode()
177 		{
178 			return (Asn1Enumerated) get_Renamed(0);
179 		}
180 
181 		/// <summary> Returns the matched DN from the server
182 		///
183 		/// </summary>
184 		/// <returns> the matched DN
185 		/// </returns>
getMatchedDN()186 		public RfcLdapDN getMatchedDN()
187 		{
188 			return new RfcLdapDN(((Asn1OctetString) get_Renamed(1)).byteValue());
189 		}
190 
191 		/// <summary> Returns the error message from the server
192 		///
193 		/// </summary>
194 		/// <returns> the server error message
195 		/// </returns>
getErrorMessage()196 		public RfcLdapString getErrorMessage()
197 		{
198 			return new RfcLdapString(((Asn1OctetString) get_Renamed(2)).byteValue());
199 		}
200 
201 		/// <summary> Returns the referral(s) from the server
202 		///
203 		/// </summary>
204 		/// <returns> the referral(s)
205 		/// </returns>
getReferral()206 		public RfcReferral getReferral()
207 		{
208 			return (size() > 3)?(RfcReferral) get_Renamed(3):null;
209 		}
210 	}
211 }
212