| 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.Controls.LdapSortResponse.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; |
| 34 |
using Novell.Directory.Ldap.Asn1; |
| 35 |
|
| 36 |
namespace Novell.Directory.Ldap.Controls |
| 37 |
{ |
| 38 |
|
| 39 |
/// <summary> LdapSortResponse - will be added in newer version of Ldap |
| 40 |
/// Controls draft |
| 41 |
/// </summary> |
| 42 |
public class LdapSortResponse:LdapControl |
| 43 |
{ |
| 44 |
/// <summary> If not null, this returns the attribute that caused the sort |
| 45 |
/// operation to fail. |
| 46 |
/// </summary> |
| 47 |
virtual public System.String FailedAttribute |
| 48 |
{ |
| 49 |
get |
| 50 |
{ |
| 51 |
return failedAttribute; |
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
/// <summary> Returns the result code from the sort</summary> |
| 56 |
virtual public int ResultCode |
| 57 |
{ |
| 58 |
get |
| 59 |
{ |
| 60 |
return resultCode; |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
private System.String failedAttribute; |
| 66 |
private int resultCode; |
| 67 |
|
| 68 |
/// <summary> This constructor is usually called by the SDK to instantiate an |
| 69 |
/// a LdapControl corresponding to the Server response to a Ldap |
| 70 |
/// Sort Control request. Application programmers should not have |
| 71 |
/// any reason to call the constructor. This constructor besides |
| 72 |
/// constructing a LdapControl object parses the contents of the response |
| 73 |
/// control. |
| 74 |
/// |
| 75 |
/// RFC 2891 defines this response control as follows: |
| 76 |
/// |
| 77 |
/// The controlValue is an OCTET STRING, whose |
| 78 |
/// value is the BER encoding of a value of the following SEQUENCE: |
| 79 |
/// SortResult ::= SEQUENCE { |
| 80 |
/// sortResult ENUMERATED { |
| 81 |
/// success (0), -- results are sorted |
| 82 |
/// operationsError (1), -- server internal failure |
| 83 |
/// timeLimitExceeded (3), -- timelimit reached before |
| 84 |
/// -- sorting was completed |
| 85 |
/// strongAuthRequired (8), -- refused to return sorted |
| 86 |
/// -- results via insecure |
| 87 |
/// -- protocol |
| 88 |
/// adminLimitExceeded (11), -- too many matching entries |
| 89 |
/// -- for the server to sort |
| 90 |
/// noSuchAttribute (16), -- unrecognized attribute |
| 91 |
/// -- type in sort key |
| 92 |
/// inappropriateMatching (18), -- unrecognized or |
| 93 |
/// -- inappropriate matching |
| 94 |
/// -- rule in sort key |
| 95 |
/// insufficientAccessRights (50), -- refused to return sorted |
| 96 |
/// -- results to this client |
| 97 |
/// busy (51), -- too busy to process |
| 98 |
/// unwillingToPerform (53), -- unable to sort |
| 99 |
/// other (80) |
| 100 |
/// }, |
| 101 |
/// attributeType [0] AttributeDescription OPTIONAL } |
| 102 |
/// |
| 103 |
/// |
| 104 |
/// </summary> |
| 105 |
/// <param name="oid"> The OID of the control, as a dotted string. |
| 106 |
/// |
| 107 |
/// </param> |
| 108 |
/// <param name="critical"> True if the Ldap operation should be discarded if |
| 109 |
/// the control is not supported. False if |
| 110 |
/// the operation can be processed without the control. |
| 111 |
/// |
| 112 |
/// </param> |
| 113 |
/// <param name="values"> The control-specific data. |
| 114 |
/// </param> |
| 115 |
[CLSCompliantAttribute(false)] |
| 116 |
public LdapSortResponse(System.String oid, bool critical, sbyte[] values):base(oid, critical, values) |
| 117 |
{ |
| 118 |
|
| 119 |
// Create a decoder object |
| 120 |
LBERDecoder decoder = new LBERDecoder(); |
| 121 |
if (decoder == null) |
| 122 |
throw new System.IO.IOException("Decoding error"); |
| 123 |
|
| 124 |
// We should get back an enumerated type |
| 125 |
Asn1Object asnObj = decoder.decode(values); |
| 126 |
|
| 127 |
if ((asnObj == null) || (!(asnObj is Asn1Sequence))) |
| 128 |
throw new System.IO.IOException("Decoding error"); |
| 129 |
|
| 130 |
|
| 131 |
Asn1Object asn1Enum = ((Asn1Sequence) asnObj).get_Renamed(0); |
| 132 |
if ((asn1Enum != null) && (asn1Enum is Asn1Enumerated)) |
| 133 |
resultCode = ((Asn1Enumerated) asn1Enum).intValue(); |
| 134 |
|
| 135 |
// Second element is the attributeType |
| 136 |
if (((Asn1Sequence) asnObj).size() > 1) |
| 137 |
{ |
| 138 |
Asn1Object asn1String = ((Asn1Sequence) asnObj).get_Renamed(1); |
| 139 |
if ((asn1String != null) && (asn1String is Asn1OctetString)) |
| 140 |
failedAttribute = ((Asn1OctetString) asn1String).stringValue(); |
| 141 |
} |
| 142 |
return ; |
| 143 |
} |
| 144 |
} |
| 145 |
} |