**** Merged from MCS ****
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Extensions / SetReplicationFilterRequest.cs
blobbbfa9850b7214e3a2f3ba9ec403c2bf0312489f5
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:
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
21 * SOFTWARE.
22 *******************************************************************************/
24 // Novell.Directory.Ldap.Extensions.SetReplicationFilterRequest.cs
26 // Author:
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
32 using System;
33 using Novell.Directory.Ldap;
34 using Novell.Directory.Ldap.Asn1;
35 using Novell.Directory.Ldap.Utilclass;
37 namespace Novell.Directory.Ldap.Extensions
40 /// <summary>
41 /// Sets the Replication filter for all replicas on the server.
42 ///
43 /// The filter specified is a an array of classnames-attribute names pairs.
44 ///
45 /// To set the filter for all replicas on the connected server, you must
46 /// create an instance of this class and then call the
47 /// extendedOperation method with this object as the required
48 /// LdapExtendedOperation parameter.
49 ///
50 /// The SetReplicationFilterRequest extension uses the following OID:
51 /// 2.16.840.1.113719.1.27.100.35
52 ///
53 /// The requestValue has the following format:
54 ///
55 /// requestValue ::=
56 /// serverName LdapDN
57 /// SEQUENCE of SEQUENCE {
58 /// classname OCTET STRING
59 /// SEQUENCE of ATTRIBUTES
60 /// }
61 /// where
62 /// ATTRIBUTES:: OCTET STRING
63 /// </summary>
64 public class SetReplicationFilterRequest:LdapExtendedOperation
67 /// <summary>
68 /// Constructs an extended operations object which contains the ber encoded
69 /// replication filter.
70 ///
71 /// </summary>
72 /// <param name="serverDN">The server on which the replication filter needs to be set
73 ///
74 /// </param>
75 /// <param name="replicationFilter">An array of String Arrays. Each array starting with
76 /// a class name followed by the attribute names for that class that should comprise
77 /// the replication filter.
78 ///
79 /// </param>
80 /// <exception> LdapException A general exception which includes an error
81 /// message and an Ldap error code.
82 /// </exception>
83 public SetReplicationFilterRequest(System.String serverDN, System.String[][] replicationFilter):base(ReplicationConstants.SET_REPLICATION_FILTER_REQ, null)
86 try
89 if ((System.Object) serverDN == null)
90 throw new System.ArgumentException(ExceptionMessages.PARAM_ERROR);
92 System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
93 LBEREncoder encoder = new LBEREncoder();
95 Asn1OctetString asn1_serverDN = new Asn1OctetString(serverDN);
97 // Add the serverDN to encoded data
98 asn1_serverDN.encode(encoder, encodedData);
100 // The toplevel sequenceOF
101 Asn1SequenceOf asn1_replicationFilter = new Asn1SequenceOf();
103 if (replicationFilter == null)
105 asn1_replicationFilter.encode(encoder, encodedData);
106 setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
107 return ;
110 int i = 0;
111 // for every element in the array
112 while ((i < replicationFilter.Length) && (replicationFilter[i] != null))
116 // The following additional Sequence is not needed
117 // as defined by the Asn1. But the server and the
118 // C client are encoding it. Remove this when server
119 // and C client are fixed to conform to the published Asn1.
120 Asn1Sequence buginAsn1Representation = new Asn1Sequence();
122 // Add the classname to the sequence -
123 buginAsn1Representation.add(new Asn1OctetString(replicationFilter[i][0]));
125 // Start a sequenceOF for attributes
126 Asn1SequenceOf asn1_attributeList = new Asn1SequenceOf();
128 // For every attribute in the array - remember attributes start after
129 // the first element
130 int j = 1;
131 while ((j < replicationFilter[i].Length) && ((System.Object) replicationFilter[i][j] != null))
134 // Add the attribute name to the inner SequenceOf
135 asn1_attributeList.add(new Asn1OctetString(replicationFilter[i][j]));
136 j++;
140 // Add the attributeList to the sequence - extra add due to bug
141 buginAsn1Representation.add(asn1_attributeList);
142 asn1_replicationFilter.add(buginAsn1Representation);
143 i++;
146 asn1_replicationFilter.encode(encoder, encodedData);
147 setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
149 catch (System.IO.IOException ioe)
151 throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (System.String) null);