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