* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapExtendedRequest.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.LdapExtendedRequest.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 Asn1OctetString = Novell.Directory.Ldap.Asn1.Asn1OctetString;
34 using Asn1Tagged = Novell.Directory.Ldap.Asn1.Asn1Tagged;
35 using RfcExtendedRequest = Novell.Directory.Ldap.Rfc2251.RfcExtendedRequest;
36 using RfcLdapOID = Novell.Directory.Ldap.Rfc2251.RfcLdapOID;
37
38 namespace Novell.Directory.Ldap
39 {
40         
41         /// <summary> Represents an Ldap Extended Request.
42         /// 
43         /// </summary>
44         /// <seealso cref="LdapConnection.SendRequest">
45         /// </seealso> 
46    /*
47         *       ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
48         *               requestName      [0] LdapOID,
49         *               requestValue     [1] OCTET STRING OPTIONAL }
50         */
51         public class LdapExtendedRequest:LdapMessage
52         {
53                 /// <summary> Retrieves an extended operation from this request</summary>
54                 /// <returns> extended operation represented in this request.
55                 /// </returns>
56                 virtual public LdapExtendedOperation ExtendedOperation
57                 {
58                         get
59                         {
60                                 RfcExtendedRequest xreq = (RfcExtendedRequest) this.Asn1Object.get_Renamed(1);
61                                 
62                                 //Zeroth element is the OID, element one is the value
63                                 Asn1Tagged tag = (Asn1Tagged) xreq.get_Renamed(0);
64                                 RfcLdapOID oid = (RfcLdapOID) tag.taggedValue();
65                                 System.String requestID = oid.stringValue();
66                                 
67                                 sbyte[] requestValue = null;
68                                 if (xreq.size() >= 2)
69                                 {
70                                         tag = (Asn1Tagged) xreq.get_Renamed(1);
71                                         Asn1OctetString value_Renamed = (Asn1OctetString) tag.taggedValue();
72                                         requestValue = value_Renamed.byteValue();
73                                 }
74                                 return new LdapExtendedOperation(requestID, requestValue);
75                         }
76                         
77                 }
78                 /// <summary> Constructs an LdapExtendedRequest.
79                 /// 
80                 /// </summary>
81                 /// <param name="op"> The object which contains (1) an identifier of an extended
82                 /// operation which should be recognized by the particular Ldap
83                 /// server this client is connected to, and (2) an operation-
84                 /// specific sequence of octet strings or BER-encoded values.
85                 /// 
86                 /// </param>
87                 /// <param name="cont">Any controls that apply to the extended request
88                 /// or null if none.
89                 /// </param>
90                 public LdapExtendedRequest(LdapExtendedOperation op, LdapControl[] cont):base(LdapMessage.EXTENDED_REQUEST, new RfcExtendedRequest(new RfcLdapOID(op.getID()), (op.getValue() != null)?new Asn1OctetString(op.getValue()):null), cont)
91                 {
92                         return ;
93                 }
94         }
95 }