diff options
author | Sunil Kumar <sunilk@mono-cvs.ximian.com> | 2003-12-10 14:05:54 +0300 |
---|---|---|
committer | Sunil Kumar <sunilk@mono-cvs.ximian.com> | 2003-12-10 14:05:54 +0300 |
commit | 4dfed54d4fb10dde0b344d55acbeae6e973a8aca (patch) | |
tree | 76729db54b6023296499667efc9a1494db77a151 /mcs/class/Novell.Directory.Ldap | |
parent | c7ec03d483b9ada69e30d759733e08ec2967536f (diff) |
Added Support for Schema operation
svn path=/trunk/mcs/; revision=20954
Diffstat (limited to 'mcs/class/Novell.Directory.Ldap')
11 files changed, 3446 insertions, 1 deletions
diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapAttributeSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapAttributeSchema.cs new file mode 100755 index 00000000000..945a1341f2d --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapAttributeSchema.cs @@ -0,0 +1,459 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapAttributeSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// +using System; +using Novell.Directory.Ldap.Utilclass; + +namespace Novell.Directory.Ldap +{ + + /// <summary> The definition of an attribute type in the schema. + /// + /// <p>LdapAttributeSchema is used to discover an attribute's + /// syntax, and add or delete an attribute definition. + /// RFC 2252, "Lightweight Directory Access Protocol (v3): + /// Attribute Syntax Definitions" contains a description + /// of the information on the Ldap representation of schema. + /// draft-sermerseim-nds-ldap-schema-02, "Ldap Schema for NDS" + /// defines the schema descriptions and non-standard syntaxes + /// used by Novell eDirectory. + /// + /// </summary> + /// <seealso cref="LdapSchema"> + /// </seealso> + public class LdapAttributeSchema:LdapSchemaElement + { + private void InitBlock() + { + usage = USER_APPLICATIONS; + } + /// <summary> Returns the object identifer of the syntax of the attribute, in + /// dotted numerical format. + /// + /// </summary> + /// <returns> The object identifer of the attribute's syntax. + /// </returns> + virtual public System.String SyntaxString + { + get + { + return syntaxString; + } + + } + /// <summary> Returns the name of the attribute type which this attribute derives + /// from, or null if there is no superior attribute. + /// + /// </summary> + /// <returns> The attribute's superior attribute, or null if there is none. + /// </returns> + virtual public System.String Superior + { + get + { + return superior; + } + + } + /// <summary> Returns true if the attribute is single-valued. + /// + /// </summary> + /// <returns> True if the attribute is single-valued; false if the attribute + /// is multi-valued. + /// </returns> + virtual public bool SingleValued + { + get + { + return single; + } + + } + /// <summary> Returns the matching rule for this attribute. + /// + /// </summary> + /// <returns> The attribute's equality matching rule; null if it has no equality + /// matching rule. + /// </returns> + virtual public System.String EqualityMatchingRule + { + get + { + return equality; + } + + } + /// <summary> Returns the ordering matching rule for this attribute. + /// + /// </summary> + /// <returns> The attribute's ordering matching rule; null if it has no ordering + /// matching rule. + /// </returns> + virtual public System.String OrderingMatchingRule + { + get + { + return ordering; + } + + } + /// <summary> Returns the substring matching rule for this attribute. + /// + /// </summary> + /// <returns> The attribute's substring matching rule; null if it has no substring + /// matching rule. + /// </returns> + virtual public System.String SubstringMatchingRule + { + get + { + return substring; + } + + } + /// <summary> Returns true if the attribute is a collective attribute. + /// + /// </summary> + /// <returns> True if the attribute is a collective; false if the attribute + /// is not a collective attribute. + /// </returns> + virtual public bool Collective + { + get + { + return collective; + } + + } + /// <summary> Returns false if the attribute is read-only. + /// + /// </summary> + /// <returns> False if the attribute is read-only; true if the attribute + /// is read-write. + /// </returns> + virtual public bool UserModifiable + { + get + { + return userMod; + } + + } + /// <summary> Returns the usage of the attribute. + /// + /// </summary> + /// <returns> One of the following values: USER_APPLICATIONS, + /// DIRECTORY_OPERATION, DISTRIBUTED_OPERATION or + /// DSA_OPERATION. + /// </returns> + virtual public int Usage + { + get + { + return usage; + } + + } + + private System.String syntaxString; + private bool single = false; + private System.String superior; + private System.String equality; + private System.String ordering; + private System.String substring; + private bool collective = false; + private bool userMod = true; + private int usage; + + /// <summary> Indicates that the attribute usage is for ordinary application + /// or user data. + /// </summary> + public const int USER_APPLICATIONS = 0; + /// <summary> Indicates that the attribute usage is for directory operations. + /// Values are vendor specific. + /// </summary> + public const int DIRECTORY_OPERATION = 1; + /// <summary> Indicates that the attribute usage is for distributed operational + /// attributes. These hold server (DSA) information that is shared among + /// servers holding replicas of the entry. + /// </summary> + public const int DISTRIBUTED_OPERATION = 2; + /// <summary> Indicates that the attribute usage is for local operational attributes. + /// These hold server (DSA) information that is local to a server. + /// </summary> + public const int DSA_OPERATION = 3; + + /// <summary> Constructs an attribute definition for adding to or deleting from a + /// directory's schema. + /// + /// </summary> + /// <param name="names">Names of the attribute. + /// <br><br> + /// </param> + /// <param name="oid"> Object identifer of the attribute, in + /// dotted numerical format. + /// <br><br> + /// </param> + /// <param name="description"> Optional description of the attribute. + /// <br><br> + /// </param> + /// <param name="syntaxString"> Object identifer of the syntax of the + /// attribute, in dotted numerical format. + /// <br><br> + /// </param> + /// <param name="single"> True if the attribute is to be single-valued. + /// <br><br> + /// </param> + /// <param name="superior"> Optional name of the attribute type which this + /// attribute type derives from; null if there is no + /// superior attribute type. + /// <br><br> + /// </param> + /// <param name="obsolete"> True if the attribute is obsolete. + /// <br><br> + /// </param> + /// <param name="equality"> Optional matching rule name; null if there is not + /// an equality matching rule for this attribute. + /// <br><br> + /// </param> + /// <param name="ordering">Optional matching rule name; null if there is not + /// an ordering matching rule for this attribute. + /// <br><br> + /// </param> + /// <param name="substring"> Optional matching rule name; null if there is not + /// a substring matching rule for this attribute. + /// <br><br> + /// </param> + /// <param name="collective"> True of this attribute is a collective attribute + /// <br><br> + /// </param> + /// <param name="isUserModifiable"> False if this attribute is a read-only attribute + /// <br><br> + /// </param> + /// <param name="usage"> Describes what the attribute is used for. Must be + /// one of the following: USER_APPLICATIONS, + /// DIRECTORY_OPERATION, DISTRIBUTED_OPERATION or + /// DSA_OPERATION. + /// </param> + public LdapAttributeSchema(System.String[] names, System.String oid, System.String description, System.String syntaxString, bool single, System.String superior, bool obsolete, System.String equality, System.String ordering, System.String substring, bool collective, bool isUserModifiable, int usage):base(LdapSchema.schemaTypeNames[LdapSchema.ATTRIBUTE]) + { + InitBlock(); + base.names = names; + base.oid = oid; + base.description = description; + base.obsolete = obsolete; + this.syntaxString = syntaxString; + this.single = single; + this.equality = equality; + this.ordering = ordering; + this.substring = substring; + this.collective = collective; + this.userMod = isUserModifiable; + this.usage = usage; + base.Value = formatString(); + return ; + } + + + + /// <summary> Constructs an attribute definition from the raw string value returned + /// on a directory query for "attributetypes". + /// + /// </summary> + /// <param name="raw"> The raw string value returned on a directory + /// query for "attributetypes". + /// </param> + public LdapAttributeSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.ATTRIBUTE]) + { + InitBlock(); + try + { + SchemaParser parser = new SchemaParser(raw); + + if (parser.Names != null) + base.names = parser.Names; + if ((System.Object) parser.ID != null) + base.oid = parser.ID; + if ((System.Object) parser.Description != null) + base.description = parser.Description; + if ((System.Object) parser.Syntax != null) + syntaxString = parser.Syntax; + if ((System.Object) parser.Superior != null) + syntaxString = parser.Superior; + single = parser.Single; + base.obsolete = parser.Obsolete; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + throw new System.SystemException(e.ToString()); + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element attribute. + /// + /// </summary> + /// <returns> A string representation of the attribute's definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((System.Object) (token = Superior) != null) + { + valueBuffer.Append(" SUP "); + valueBuffer.Append("'" + token + "'"); + } + if ((System.Object) (token = EqualityMatchingRule) != null) + { + valueBuffer.Append(" EQUALITY "); + valueBuffer.Append("'" + token + "'"); + } + if ((System.Object) (token = OrderingMatchingRule) != null) + { + valueBuffer.Append(" ORDERING "); + valueBuffer.Append("'" + token + "'"); + } + if ((System.Object) (token = SubstringMatchingRule) != null) + { + valueBuffer.Append(" SUBSTR "); + valueBuffer.Append("'" + token + "'"); + } + if ((System.Object) (token = SyntaxString) != null) + { + valueBuffer.Append(" SYNTAX "); + valueBuffer.Append(token); + } + if (SingleValued) + { + valueBuffer.Append(" SINGLE-VALUE"); + } + if (Collective) + { + valueBuffer.Append(" COLLECTIVE"); + } + if (UserModifiable == false) + { + valueBuffer.Append(" NO-USER-MODIFICATION"); + } + int useType; + if ((useType = Usage) != USER_APPLICATIONS) + { + switch (useType) + { + + case DIRECTORY_OPERATION: + valueBuffer.Append(" USAGE directoryOperation"); + break; + + case DISTRIBUTED_OPERATION: + valueBuffer.Append(" USAGE distributedOperation"); + break; + + case DSA_OPERATION: + valueBuffer.Append(" USAGE dSAOperation"); + break; + + default: + break; + + } + } + System.Collections.IEnumerator en = QualifierNames; + + while (en.MoveNext()) + { + token = ((System.String) en.Current); + if (((System.Object) token != null)) + { + valueBuffer.Append(" " + token); + strArray = getQualifier(token); + if (strArray != null) + { + if (strArray.Length > 1) + valueBuffer.Append("("); + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapConnection.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapConnection.cs index b296d1e6f22..1a898417026 100755 --- a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapConnection.cs +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapConnection.cs @@ -584,7 +584,6 @@ namespace Novell.Directory.Ldap conn = new Connection(); return ; } - /* * The following are methods that affect the operation of * LdapConnection, but are not Ldap requests. @@ -3621,5 +3620,111 @@ namespace Novell.Directory.Ldap } return ; } + + //************************************************************************* + // Schema Related methods + //************************************************************************* + + /// <summary> Retrieves the schema associated with a particular schema DN in the + /// directory server. + /// <p>The schema DN for a particular entry is obtained by calling the + /// getSchemaDN method of LDAPConnection</p> + /// + /// </summary> + /// <param name="schemaDN">The schema DN used to fetch the schema. + /// + /// </param> + /// <returns> An LDAPSchema entry containing schema attributes. If the + /// entry contains no schema attributes then the returned LDAPSchema object + /// will be empty. + /// + /// </returns> + /// <exception cref=""> LDAPException This exception occurs if the schema entry + /// cannot be retrieved with this connection. + /// </exception> + /// <seealso cref="#getSchemaDN()"> + /// </seealso> + /// <seealso cref="#getSchemaDN(String)"> + /// </seealso> + public virtual LdapSchema FetchSchema(System.String schemaDN) + { + LdapEntry ent = Read(schemaDN, LdapSchema.schemaTypeNames); + return new LdapSchema(ent); + } + + /// <summary> Retrieves the Distiguished Name (DN) for the schema advertised in the + /// root DSE of the Directory Server. + /// + /// <p>The DN can be used with the methods fetchSchema and modify to retreive + /// and extend schema definitions. The schema entry is located by reading + /// subschemaSubentry attribute of the root DSE. This is equivalent to + /// calling {@link #getSchemaDN(String) } with the DN parameter as an empty + /// string: <code>getSchemaDN("")</code>. + /// </p> + /// + /// </summary> + /// <returns> Distinguished Name of a schema entry in effect for the + /// Directory. + /// </returns> + /// <exception cref=""> LDAPException This exception occurs if the schema DN + /// cannot be retrieved, or if the subschemaSubentry attribute associated + /// with the root DSE contains multiple values. + /// + /// </exception> + /// <seealso cref="#fetchSchema"> + /// </seealso> + /// <seealso cref="#modify"> + /// </seealso> + public virtual System.String GetSchemaDN() + { + return GetSchemaDN(""); + } + + /// <summary> Retrieves the Distiguished Name (DN) of the schema associated with a + /// entry in the Directory. + /// + /// <p>The DN can be used with the methods fetchSchema and modify to retreive + /// and extend schema definitions. Reads the subschemaSubentry of the entry + /// specified.<p> + /// + /// </summary> + /// <param name="dn"> Distinguished Name of any entry. The subschemaSubentry + /// attribute is queried from this entry. + /// + /// </param> + /// <returns> Distinguished Name of a schema entry in effect for the entry + /// identified by <code>dn</code>. + /// + /// </returns> + /// <exception cref=""> LDAPException This exception occurs if a null or empty + /// value is passed as dn, if the subschemasubentry attribute cannot + /// be retrieved, or the subschemasubentry contains multiple values. + /// + /// </exception> + /// <seealso cref="#fetchSchema"> + /// </seealso> + /// <seealso cref="#modify"> + /// </seealso> + public virtual System.String GetSchemaDN(System.String dn) + { + System.String[] attrSubSchema = new System.String[]{"subschemaSubentry"}; + + /* Read the entries subschemaSubentry attribute. Throws an exception if + * no entries are returned. */ + LdapEntry ent = this.Read(dn, attrSubSchema); + + LdapAttribute attr = ent.getAttribute(attrSubSchema[0]); + System.String[] values = attr.StringValueArray; + if (values == null || values.Length < 1) + { + throw new LdapLocalException(ExceptionMessages.NO_SCHEMA, new System.Object[]{dn}, LdapException.NO_RESULTS_RETURNED); + } + else if (values.Length > 1) + { + throw new LdapLocalException(ExceptionMessages.MULTIPLE_SCHEMA, new System.Object[]{dn}, LdapException.CONSTRAINT_VIOLATION); + } + return values[0]; + } + } } diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITContentRuleSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITContentRuleSchema.cs new file mode 100755 index 00000000000..a3d679edf99 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITContentRuleSchema.cs @@ -0,0 +1,356 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapDITContentRuleSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; +using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier; + +namespace Novell.Directory.Ldap +{ + + /// <summary> Represents a DIT (Directory Information Tree) content rule + /// in a directory schema. + /// + /// <p>The LdapDITContentRuleSchema class is used to discover or modify + /// additional auxiliary classes, mandatory and optional attributes, and + /// restricted attributes in effect for an object class.</p> + /// </summary> + public class LdapDITContentRuleSchema:LdapSchemaElement + { + /// <summary> Returns the list of allowed auxiliary classes. + /// + /// </summary> + /// <returns> The list of allowed auxiliary classes. + /// </returns> + virtual public System.String[] AuxiliaryClasses + { + get + { + return auxiliary; + } + + } + /// <summary> Returns the list of additional required attributes for an entry + /// controlled by this content rule. + /// + /// </summary> + /// <returns> The list of additional required attributes. + /// </returns> + virtual public System.String[] RequiredAttributes + { + get + { + return required; + } + + } + /// <summary> Returns the list of additional optional attributes for an entry + /// controlled by this content rule. + /// + /// </summary> + /// <returns> The list of additional optional attributes. + /// </returns> + virtual public System.String[] OptionalAttributes + { + get + { + return optional; + } + + } + /// <summary> Returns the list of precluded attributes for an entry controlled by + /// this content rule. + /// + /// </summary> + /// <returns> The list of precluded attributes. + /// </returns> + virtual public System.String[] PrecludedAttributes + { + get + { + return precluded; + } + + } + private System.String[] auxiliary = new System.String[]{""}; + private System.String[] required = new System.String[]{""}; + private System.String[] optional = new System.String[]{""}; + private System.String[] precluded = new System.String[]{""}; + + /// <summary> Constructs a DIT content rule for adding to or deleting from the + /// schema. + /// + /// </summary> + /// <param name="names"> The names of the content rule. + /// <br><br> + /// </param> + /// <param name="oid"> The unique object identifier of the content rule - + /// in dotted numerical format. + /// <br><br> + /// </param> + /// <param name="description">The optional description of the content rule. + /// <br><br> + /// </param> + /// <param name="obsolete"> True if the content rule is obsolete. + /// <br><br> + /// </param> + /// <param name="auxiliary"> A list of auxiliary object classes allowed for + /// an entry to which this content rule applies. + /// These may either be specified by name or + /// numeric oid. + /// <br><br> + /// </param> + /// <param name="required"> A list of attributes that an entry + /// to which this content rule applies must + /// contain in addition to its normal set of + /// mandatory attributes. These attributes may be + /// specified by either name or numeric oid. + /// <br><br> + /// </param> + /// <param name="optional"> A list of attributes that an entry + /// to which this content rule applies may contain + /// in addition to its normal set of optional + /// attributes. These attributes may be specified by + /// either name or numeric oid. + /// <br><br> + /// </param> + /// <param name="precluded"> A list, consisting of a subset of the optional + /// attributes of the structural and + /// auxiliary object classes which are precluded + /// from an entry to which this content rule + /// applies. These may be specified by either name + /// or numeric oid. + /// </param> + public LdapDITContentRuleSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String[] auxiliary, System.String[] required, System.String[] optional, System.String[] precluded):base(LdapSchema.schemaTypeNames[LdapSchema.DITCONTENT]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + base.oid = oid; + base.description = description; + base.obsolete = obsolete; + this.auxiliary = auxiliary; + this.required = required; + this.optional = optional; + this.precluded = precluded; + base.Value = formatString(); + return ; + } + + /// <summary> Constructs a DIT content rule from the raw string value returned from a + /// schema query for dITContentRules. + /// + /// </summary> + /// <param name="raw"> The raw string value returned from a schema query + /// for content rules. + /// </param> + public LdapDITContentRuleSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.DITCONTENT]) + { + base.obsolete = false; + try + { + SchemaParser parser = new SchemaParser(raw); + + if (parser.Names != null) + { + base.names = new System.String[parser.Names.Length]; + parser.Names.CopyTo(base.names, 0); + } + + if ((System.Object) parser.ID != null) + base.oid = parser.ID; + if ((System.Object) parser.Description != null) + base.description = parser.Description; + if (parser.Auxiliary != null) + { + auxiliary = new System.String[parser.Auxiliary.Length]; + parser.Auxiliary.CopyTo(auxiliary, 0); + } + if (parser.Required != null) + { + required = new System.String[parser.Required.Length]; + parser.Required.CopyTo(required, 0); + } + if (parser.Optional != null) + { + optional = new System.String[parser.Optional.Length]; + parser.Optional.CopyTo(optional, 0); + } + if (parser.Precluded != null) + { + precluded = new System.String[parser.Precluded.Length]; + parser.Precluded.CopyTo(precluded, 0); + } + base.obsolete = parser.Obsolete; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element class. + /// + /// </summary> + /// <returns> A string representation of the class' definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((strArray = AuxiliaryClasses) != null) + { + valueBuffer.Append(" AUX "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if ((strArray = RequiredAttributes) != null) + { + valueBuffer.Append(" MUST "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if ((strArray = OptionalAttributes) != null) + { + valueBuffer.Append(" MAY "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if ((strArray = PrecludedAttributes) != null) + { + valueBuffer.Append(" NOT "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + System.Collections.IEnumerator en; + if ((en = QualifierNames) != null) + { + System.String qualName; + System.String[] qualValue; + while (en.MoveNext()) + { + qualName = ((System.String) en.Current); + valueBuffer.Append(" " + qualName + " "); + if ((qualValue = getQualifier(qualName)) != null) + { + if (qualValue.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < qualValue.Length; i++) + { + if (i > 0) + valueBuffer.Append(" "); + valueBuffer.Append("'" + qualValue[i] + "'"); + } + if (qualValue.Length > 1) + valueBuffer.Append(" )"); + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITStructureRuleSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITStructureRuleSchema.cs new file mode 100755 index 00000000000..f33c98df941 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapDITStructureRuleSchema.cs @@ -0,0 +1,291 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapDITStructureRuleSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; +using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier; + +namespace Novell.Directory.Ldap +{ + + /// <summary> Represents the definition of a specific DIT (Directory Information Tree) + /// structure rule in the directory schema. + /// + /// <p>The LdapDITStructureRuleSchema class represents the definition of a DIT + /// Structure Rule. It is used to discover or modify which + /// object classes a particular object class may be subordinate to in the DIT.</p> + /// + /// </summary> + + public class LdapDITStructureRuleSchema:LdapSchemaElement + { + /// <summary> Returns the rule ID for this structure rule. + /// + /// <p>The getRuleID method returns an integer rather than a dotted + /// decimal OID. Objects of this class do not have an OID, + /// thus getID can return null. </p> + /// + /// + /// </summary> + /// <returns> The rule ID for this structure rule. + /// </returns> + virtual public int RuleID + { + + + get + { + return ruleID; + } + + } + /// <summary> Returns the NameForm that this structure rule controls. + /// + /// <p>You can get the actual object class that this structure rule controls + /// by calling the getNameForm.getObjectClass method.</p> + /// + /// </summary> + /// <returns> The NameForm that this structure rule controls. + /// </returns> + virtual public System.String NameForm + { + get + { + return nameForm; + } + + } + /// <summary> Returns a list of all structure rules that are superior to this + /// structure rule. + /// + /// <p>To resolve to an object class, you need to first + /// resolve the superior ID to another structure rule, then call + /// the getNameForm.getObjectClass method on that structure rule.</p> + /// + /// </summary> + /// <returns> A list of all structure rules that are superior to this structure rule. + /// </returns> + virtual public System.String[] Superiors + { + get + { + return superiorIDs; + } + + } + private int ruleID = 0; + private System.String nameForm = ""; + private System.String[] superiorIDs = new System.String[]{""}; + + /// <summary>Constructs a DIT structure rule for adding to or deleting from the + /// schema. + /// + /// </summary> + /// <param name="names"> The names of the structure rule. + /// <br><br> + /// </param> + /// <param name="ruleID"> The unique identifier of the structure rule. NOTE: + /// this is an integer, not a dotted numerical + /// identifier. Structure rules aren't identified + /// by OID. + /// <br><br> + /// </param> + /// <param name="description">An optional description of the structure rule. + /// <br><br> + /// </param> + /// <param name="obsolete"> True if the structure rule is obsolete. + /// <br><br> + /// </param> + /// <param name="nameForm"> Either the identifier or name of a name form. + /// This is used to indirectly refer to the object + /// class that this structure rule applies to. + /// <br><br> + /// </param> + /// <param name="superiorIDs">A list of superior structure rules - specified + /// by their integer ID. The object class + /// specified by this structure rule (via the + /// nameForm parameter) may only be subordinate in + /// the DIT to object classes of those represented + /// by the structure rules here; it may be null. + /// + /// </param> + public LdapDITStructureRuleSchema(System.String[] names, int ruleID, System.String description, bool obsolete, System.String nameForm, System.String[] superiorIDs):base(LdapSchema.schemaTypeNames[LdapSchema.DITSTRUCTURE]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + this.ruleID = ruleID; + base.description = description; + base.obsolete = obsolete; + this.nameForm = nameForm; + this.superiorIDs = superiorIDs; + base.Value = formatString(); + return ; + } + + /// <summary> Constructs a DIT structure rule from the raw string value returned from + /// a schema query for dITStructureRules. + /// + /// </summary> + /// <param name="raw"> The raw string value returned from a schema + /// query for dITStructureRules. + /// </param> + public LdapDITStructureRuleSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.DITSTRUCTURE]) + { + base.obsolete = false; + try + { + SchemaParser parser = new SchemaParser(raw); + + if (parser.Names != null) + { + base.names = new System.String[parser.Names.Length]; + parser.Names.CopyTo(base.names, 0); + } + + if ((System.Object) parser.ID != null) + ruleID = System.Int32.Parse(parser.ID); + if ((System.Object) parser.Description != null) + base.description = parser.Description; + if (parser.Superiors != null) + { + superiorIDs = new System.String[parser.Superiors.Length]; + parser.Superiors.CopyTo(superiorIDs, 0); + } + if ((System.Object) parser.NameForm != null) + nameForm = parser.NameForm; + base.obsolete = parser.Obsolete; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element class. + /// + /// </summary> + /// <returns> A string representation of the class' definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + token = RuleID.ToString(); + valueBuffer.Append(token); + + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((System.Object) (token = NameForm) != null) + { + valueBuffer.Append(" FORM "); + valueBuffer.Append("'" + token + "'"); + } + if ((strArray = Superiors) != null) + { + valueBuffer.Append(" SUP "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + + System.Collections.IEnumerator en; + if ((en = QualifierNames) != null) + { + System.String qualName; + System.String[] qualValue; + while (en.MoveNext()) + { + qualName = ((System.String) en.Current); + valueBuffer.Append(" " + qualName + " "); + if ((qualValue = getQualifier(qualName)) != null) + { + if (qualValue.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < qualValue.Length; i++) + { + if (i > 0) + valueBuffer.Append(" "); + valueBuffer.Append("'" + qualValue[i] + "'"); + } + if (qualValue.Length > 1) + valueBuffer.Append(" )"); + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleSchema.cs new file mode 100755 index 00000000000..d3e5ddec83e --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleSchema.cs @@ -0,0 +1,216 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapMatchingRuleSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; + +namespace Novell.Directory.Ldap +{ + /// <summary> The schematic definition of a particular matching rule + /// in a particular Directory Server. + /// + /// <p>The LdapMatchingRuleSchema class represents the definition of a mathcing + /// rule. It is used to query matching rule syntax, and to add or delete a + /// matching rule definition in a directory. + /// + /// <p>Novell eDirectory does not currently allow matching rules to be added + /// or deleted from the schema.</p> + /// + /// </summary> + /// <seealso cref="LdapAttributeSchema"> + /// </seealso> + /// <seealso cref="LdapSchemaElement"> + /// </seealso> + /// <seealso cref="LdapSchema"> + /// </seealso> + public class LdapMatchingRuleSchema:LdapSchemaElement + { + /// <summary> Returns the OIDs of the attributes to which this rule applies. + /// + /// </summary> + /// <returns> The OIDs of the attributes to which this matching rule applies. + /// </returns> + virtual public System.String[] Attributes + { + get + { + return attributes; + } + + } + /// <summary> Returns the OID of the syntax that this matching rule is valid for. + /// + /// </summary> + /// <returns> The OID of the syntax that this matching rule is valid for. + /// </returns> + virtual public System.String SyntaxString + { + get + { + return syntaxString; + } + + } + private System.String syntaxString; + private System.String[] attributes; + /// <summary> Constructs a matching rule definition for adding to or deleting from + /// a directory. + /// + /// </summary> + /// <param name="names"> The names of the attribute. + /// <br><br> + /// </param> + /// <param name="oid"> Object Identifier of the attribute - in + /// dotted-decimal format. + /// <br><br> + /// </param> + /// <param name="description"> Optional description of the attribute. + /// <br><br> + /// </param> + /// <param name="attributes"> The OIDs of attributes to which the rule applies. + /// This parameter may be null. All attributes added to + /// this array must use the same syntax. + /// <br><br> + /// </param> + /// <param name="obsolete"> true if this matching rule is obsolete. + /// <br><br> + /// + /// </param> + /// <param name="syntaxString"> The unique object identifer of the syntax of the + /// attribute, in dotted numerical format. + /// <br><br> + /// </param> + public LdapMatchingRuleSchema(System.String[] names, System.String oid, System.String description, System.String[] attributes, bool obsolete, System.String syntaxString):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + base.oid = oid; + base.description = description; + base.obsolete = obsolete; + this.attributes = new System.String[attributes.Length]; + attributes.CopyTo(this.attributes, 0); + this.syntaxString = syntaxString; + base.Value = formatString(); + return ; + } + + + /// <summary> Constructs a matching rule definition from the raw string values + /// returned from a schema query for "matchingRule" and for + /// "matchingRuleUse" for the same rule. + /// + /// </summary> + /// <param name="rawMatchingRule"> The raw string value returned on a directory + /// query for "matchingRule". + /// <br><br> + /// </param> + /// <param name="rawMatchingRuleUse"> The raw string value returned on a directory + /// query for "matchingRuleUse". + /// </param> + public LdapMatchingRuleSchema(System.String rawMatchingRule, System.String rawMatchingRuleUse):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING]) + { + try + { + SchemaParser matchParser = new SchemaParser(rawMatchingRule); + base.names = new System.String[matchParser.Names.Length]; + matchParser.Names.CopyTo(base.names, 0); + base.oid = matchParser.ID; + base.description = matchParser.Description; + base.obsolete = matchParser.Obsolete; + this.syntaxString = matchParser.Syntax; + if ((System.Object) rawMatchingRuleUse != null) + { + SchemaParser matchUseParser = new SchemaParser(rawMatchingRuleUse); + this.attributes = matchUseParser.Applies; + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element attribute. + /// + /// </summary> + /// <returns> A string representation of the attribute's definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((System.Object) (token = SyntaxString) != null) + { + valueBuffer.Append(" SYNTAX "); + valueBuffer.Append(token); + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleUseSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleUseSchema.cs new file mode 100755 index 00000000000..39d957790f3 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapMatchingRuleUseSchema.cs @@ -0,0 +1,196 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapMatchingRuleUseSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; + +namespace Novell.Directory.Ldap +{ + + /// <summary>Represents the definition of a specific matching rule use in the + /// directory schema. + /// + /// <p>The LdapMatchingRuleUseSchema class represents the definition of a + /// matching rule use. It is used to discover or modify which attributes are + /// suitable for use with an extensible matching rule. It contains the name and + /// identifier of a matching rule, and a list of attributes which + /// it applies to.</p> + /// + /// </summary> + /// <seealso cref="LdapAttributeSchema"> + /// </seealso> + /// <seealso cref="LdapSchemaElement"> + /// </seealso> + /// <seealso cref="LdapSchema"> + /// </seealso> + public class LdapMatchingRuleUseSchema:LdapSchemaElement + { + /// <summary> Returns an array of all the attributes which this matching rule + /// applies to. + /// + /// </summary> + /// <returns> An array of all the attributes which this matching rule applies to. + /// </returns> + virtual public System.String[] Attributes + { + get + { + return attributes; + } + + } + private System.String[] attributes; + + /// <summary> Constructs a matching rule use definition for adding to or deleting + /// from the schema. + /// + /// </summary> + /// <param name="names"> Name(s) of the matching rule. + /// </br></br> + /// </param> + /// <param name="oid"> Object Identifier of the the matching rule + /// in dotted-decimal format. + /// </br></br> + /// </param> + /// <param name="description">Optional description of the matching rule use. + /// </br></br> + /// </param> + /// <param name="obsolete"> True if the matching rule use is obsolete. + /// </br></br> + /// </param> + /// <param name="attributes"> List of attributes that this matching rule + /// applies to. These values may be either the + /// names or numeric oids of the attributes. + /// </param> + public LdapMatchingRuleUseSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String[] attributes):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING_USE]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + base.oid = oid; + base.description = description; + base.obsolete = obsolete; + this.attributes = new System.String[attributes.Length]; + attributes.CopyTo(this.attributes, 0); + base.Value = formatString(); + return ; + } + + + + /// <summary> Constructs a matching rule use definition from the raw string value + /// returned on a schema query for matchingRuleUse. + /// + /// </summary> + /// <param name="raw"> The raw string value returned on a schema + /// query for matchingRuleUse. + /// </param> + public LdapMatchingRuleUseSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING_USE]) + { + try + { + SchemaParser matchParser = new SchemaParser(raw); + base.names = new System.String[matchParser.Names.Length]; + matchParser.Names.CopyTo(base.names, 0); + base.oid = matchParser.ID; + base.description = matchParser.Description; + base.obsolete = matchParser.Obsolete; + this.attributes = matchParser.Applies; + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element attribute. + /// + /// </summary> + /// <returns> A string representation of the attribute's definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((strArray = Attributes) != null) + { + valueBuffer.Append(" APPLIES "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapNameFormSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapNameFormSchema.cs new file mode 100755 index 00000000000..30cb7130a61 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapNameFormSchema.cs @@ -0,0 +1,305 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapAttributeSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; +using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier; + +namespace Novell.Directory.Ldap +{ + + /// <summary> A specific a name form in the directory schema. + /// + /// <p>The LdapNameFormSchema class represents the definition of a Name Form. It + /// is used to discover or modify the allowed naming attributes for a particular + /// object class.</p> + /// + /// </summary> + /// <seealso cref="LdapSchemaElement"> + /// </seealso> + /// <seealso cref="LdapSchema"> + /// </seealso> + + public class LdapNameFormSchema:LdapSchemaElement + { + /// <summary> Returns the name of the object class which this name form applies to. + /// + /// </summary> + /// <returns> The name of the object class. + /// </returns> + virtual public System.String ObjectClass + { + get + { + return objectClass; + } + + } + /// <summary> Returns the list of required naming attributes for an entry + /// controlled by this name form. + /// + /// </summary> + /// <returns> The list of required naming attributes. + /// </returns> + virtual public System.String[] RequiredNamingAttributes + { + get + { + return required; + } + + } + /// <summary> Returns the list of optional naming attributes for an entry + /// controlled by this content rule. + /// + /// </summary> + /// <returns> The list of the optional naming attributes. + /// </returns> + virtual public System.String[] OptionalNamingAttributes + { + get + { + return optional; + } + + } + private System.String objectClass; + private System.String[] required; + private System.String[] optional; + + /// <summary> Constructs a name form for adding to or deleting from the schema. + /// + /// </summary> + /// <param name="names"> The name(s) of the name form.</br></br> + /// + /// </param> + /// <param name="oid"> The unique object identifier of the name form - in + /// dotted numerical format.</br></br> + /// + /// </param> + /// <param name="description">An optional description of the name form.</br></br> + /// + /// </param> + /// <param name="obsolete"> True if the name form is obsolete.</br></br> + /// + /// </param> + /// <param name="objectClass">The object to which this name form applies. + /// This may be specified by either name or + /// numeric oid.</br></br> + /// + /// </param> + /// <param name="required"> A list of the attributes that must be present + /// in the RDN of an entry that this name form + /// controls. These attributes may be specified by + /// either name or numeric oid.</br></br> + /// + /// </param> + /// <param name="optional"> A list of the attributes that may be present + /// in the RDN of an entry that this name form + /// controls. These attributes may be specified by + /// either name or numeric oid.</br></br> + /// </param> + public LdapNameFormSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String objectClass, System.String[] required, System.String[] optional):base(LdapSchema.schemaTypeNames[LdapSchema.NAME_FORM]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + base.oid = oid; + base.description = description; + base.obsolete = obsolete; + this.objectClass = objectClass; + this.required = new System.String[required.Length]; + required.CopyTo(this.required, 0); + this.optional = new System.String[optional.Length]; + optional.CopyTo(this.optional, 0); + base.Value = formatString(); + return ; + } + + /* + } + + /** + * Constructs a Name Form from the raw string value returned on a + * schema query for nameForms. + * + * @param raw The raw string value returned on a schema + * query for nameForms. + */ + public LdapNameFormSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.NAME_FORM]) + { + base.obsolete = false; + try + { + SchemaParser parser = new SchemaParser(raw); + + if (parser.Names != null) + { + base.names = new System.String[parser.Names.Length]; + parser.Names.CopyTo(base.names, 0); + } + if ((System.Object) parser.ID != null) + base.oid = new System.Text.StringBuilder(parser.ID).ToString(); + if ((System.Object) parser.Description != null) + base.description = new System.Text.StringBuilder(parser.Description).ToString(); + if (parser.Required != null) + { + required = new System.String[parser.Required.Length]; + parser.Required.CopyTo(required, 0); + } + if (parser.Optional != null) + { + optional = new System.String[parser.Optional.Length]; + parser.Optional.CopyTo(optional, 0); + } + if ((System.Object) parser.ObjectClass != null) + objectClass = parser.ObjectClass; + base.obsolete = parser.Obsolete; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element class. + /// + /// </summary> + /// <returns> A string representation of the class' definition. + /// </returns> + protected internal override System.String formatString() + { + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((System.Object) (token = ObjectClass) != null) + { + valueBuffer.Append(" OC "); + valueBuffer.Append("'" + token + "'"); + } + if ((strArray = RequiredNamingAttributes) != null) + { + valueBuffer.Append(" MUST "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if ((strArray = OptionalNamingAttributes) != null) + { + valueBuffer.Append(" MAY "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + System.Collections.IEnumerator en; + if ((en = QualifierNames) != null) + { + System.String qualName; + System.String[] qualValue; + while (en.MoveNext()) + { + qualName = ((System.String) en.Current); + valueBuffer.Append(" " + qualName + " "); + if ((qualValue = getQualifier(qualName)) != null) + { + if (qualValue.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < qualValue.Length; i++) + { + if (i > 0) + valueBuffer.Append(" "); + valueBuffer.Append("'" + qualValue[i] + "'"); + } + if (qualValue.Length > 1) + valueBuffer.Append(" )"); + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapObjectClassSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapObjectClassSchema.cs new file mode 100755 index 00000000000..eba2ffa0d6e --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapObjectClassSchema.cs @@ -0,0 +1,376 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapObjectClassSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using Novell.Directory.Ldap.Utilclass; + +namespace Novell.Directory.Ldap +{ + + /// <summary> The schema definition of an object class in a directory server. + /// + /// <p>The LdapObjectClassSchema class represents the definition of an object + /// class. It is used to query the syntax of an object class. + /// + /// </summary> + /// <seealso cref="LdapSchemaElement"> + /// </seealso> + /// <seealso cref="LdapSchema"> + /// </seealso> + public class LdapObjectClassSchema:LdapSchemaElement + { + /// <summary> Returns the object classes from which this one derives. + /// + /// </summary> + /// <returns> The object classes superior to this class. + /// </returns> + virtual public System.String[] Superiors + { + get + { + return superiors; + } + + } + /// <summary> Returns a list of attributes required for an entry with this object + /// class. + /// + /// </summary> + /// <returns> The list of required attributes defined for this class. + /// </returns> + virtual public System.String[] RequiredAttributes + { + get + { + return required; + } + + } + /// <summary> Returns a list of optional attributes but not required of an entry + /// with this object class. + /// + /// </summary> + /// <returns> The list of optional attributes defined for this class. + /// </returns> + virtual public System.String[] OptionalAttributes + { + get + { + return optional; + } + + } + /// <summary> Returns the type of object class. + /// + /// <p>The getType method returns one of the following constants defined in + /// LdapObjectClassSchema: + /// <ul> + /// <li>ABSTRACT</li> + /// <li>AUXILIARY</li> + /// <li>STRUCTURAL</li> + /// </ul> + /// <p>See the LdapSchemaElement.getQualifier method for information on + /// obtaining the X-NDS flags.</p> + /// + /// </summary> + /// <returns> The type of object class. + /// </returns> + virtual public int Type + { + get + { + return type; + } + + } + internal System.String[] superiors; + internal System.String[] required; + internal System.String[] optional; + internal int type = - 1; + + /// <summary> This class definition defines an abstract schema class. + /// + /// <p>This is equivalent to setting the Novell eDirectory effective class + /// flag to true.</p> + /// </summary> + public const int ABSTRACT = 0; + + /// <summary> This class definition defines a structural schema class. + /// + /// <p>This is equivalent to setting the Novell eDirectory effective class + /// flag to true.</p> + /// </summary> + public const int STRUCTURAL = 1; + + /// <summary> This class definition defines an auxiliary schema class.</summary> + public const int AUXILIARY = 2; + + /// <summary> Constructs an object class definition for adding to or deleting from + /// a directory's schema. + /// + /// </summary> + /// <param name="names"> Name(s) of the object class. + /// <br><br> + /// </param> + /// <param name="oid"> Object Identifer of the object class - in + /// dotted-decimal format. + /// <br><br> + /// </param> + /// <param name="description"> Optional description of the object class. + /// <br><br> + /// </param> + /// <param name="superiors"> The object classes from which this one derives. + /// <br><br> + /// </param> + /// <param name="required"> A list of attributes required + /// for an entry with this object class. + /// <br><br> + /// </param> + /// <param name="optional"> A list of attributes acceptable but not required + /// for an entry with this object class. + /// <br><br> + /// </param> + /// <param name="type"> One of ABSTRACT, AUXILIARY, or STRUCTURAL. These + /// constants are defined in LdapObjectClassSchema. + /// <br><br> + /// </param> + /// <param name="obsolete"> true if this object is obsolete + /// + /// </param> + public LdapObjectClassSchema(System.String[] names, System.String oid, System.String[] superiors, System.String description, System.String[] required, System.String[] optional, int type, bool obsolete):base(LdapSchema.schemaTypeNames[LdapSchema.OBJECT_CLASS]) + { + base.names = new System.String[names.Length]; + names.CopyTo(base.names, 0); + base.oid = oid; + base.description = description; + this.type = type; + this.obsolete = obsolete; + if (superiors != null) + { + this.superiors = new System.String[superiors.Length]; + superiors.CopyTo(this.superiors, 0); + } + if (required != null) + { + this.required = new System.String[required.Length]; + required.CopyTo(this.required, 0); + } + if (optional != null) + { + this.optional = new System.String[optional.Length]; + optional.CopyTo(this.optional, 0); + } + base.Value = formatString(); + return ; + } + + + + /// <summary> Constructs an object class definition from the raw string value + /// returned from a directory query for "objectClasses". + /// + /// </summary> + /// <param name="raw"> The raw string value returned from a directory + /// query for "objectClasses". + /// </param> + public LdapObjectClassSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.OBJECT_CLASS]) + { + try + { + SchemaParser parser = new SchemaParser(raw); + + if (parser.Names != null) + { + base.names = new System.String[parser.Names.Length]; + parser.Names.CopyTo(base.names, 0); + } + + if ((System.Object) parser.ID != null) + base.oid = parser.ID; + if ((System.Object) parser.Description != null) + base.description = parser.Description; + base.obsolete = parser.Obsolete; + if (parser.Required != null) + { + required = new System.String[parser.Required.Length]; + parser.Required.CopyTo(required, 0); + } + if (parser.Optional != null) + { + optional = new System.String[parser.Optional.Length]; + parser.Optional.CopyTo(optional, 0); + } + if (parser.Superiors != null) + { + superiors = new System.String[parser.Superiors.Length]; + parser.Superiors.CopyTo(superiors, 0); + } + type = parser.Type; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element class. + /// + /// </summary> + /// <returns> A string representation of the class' definition. + /// </returns> + protected internal override System.String formatString() + { + + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + System.String[] strArray; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + strArray = Names; + if (strArray != null) + { + valueBuffer.Append(" NAME "); + if (strArray.Length == 1) + { + valueBuffer.Append("'" + strArray[0] + "'"); + } + else + { + valueBuffer.Append("( "); + + for (int i = 0; i < strArray.Length; i++) + { + valueBuffer.Append(" '" + strArray[i] + "'"); + } + valueBuffer.Append(" )"); + } + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + if (Obsolete) + { + valueBuffer.Append(" OBSOLETE"); + } + if ((strArray = Superiors) != null) + { + valueBuffer.Append(" SUP "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if (Type != - 1) + { + if (Type == LdapObjectClassSchema.ABSTRACT) + valueBuffer.Append(" ABSTRACT"); + else if (Type == LdapObjectClassSchema.AUXILIARY) + valueBuffer.Append(" AUXILIARY"); + else if (Type == LdapObjectClassSchema.STRUCTURAL) + valueBuffer.Append(" STRUCTURAL"); + } + if ((strArray = RequiredAttributes) != null) + { + valueBuffer.Append(" MUST "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + if ((strArray = OptionalAttributes) != null) + { + valueBuffer.Append(" MAY "); + if (strArray.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < strArray.Length; i++) + { + if (i > 0) + valueBuffer.Append(" $ "); + valueBuffer.Append(strArray[i]); + } + if (strArray.Length > 1) + valueBuffer.Append(" )"); + } + System.Collections.IEnumerator en; + if ((en = QualifierNames) != null) + { + System.String qualName; + System.String[] qualValue; + while (en.MoveNext()) + { + qualName = ((System.String) en.Current); + valueBuffer.Append(" " + qualName + " "); + if ((qualValue = getQualifier(qualName)) != null) + { + if (qualValue.Length > 1) + valueBuffer.Append("( "); + for (int i = 0; i < qualValue.Length; i++) + { + if (i > 0) + valueBuffer.Append(" "); + valueBuffer.Append("'" + qualValue[i] + "'"); + } + if (qualValue.Length > 1) + valueBuffer.Append(" )"); + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchema.cs new file mode 100755 index 00000000000..69fa1e356ce --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchema.cs @@ -0,0 +1,688 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using Novell.Directory.Ldap.Utilclass; + +namespace Novell.Directory.Ldap +{ + + /// <summary> <p>Represents a schema entry that controls one or more entries held by a + /// Directory Server.</p> + /// + /// <p><code>LdapSchema</code> Contains methods to parse schema attributes into + /// individual schema definitions, represented by subclasses of + /// {@link LdapSchemaElement}. Schema may be retrieved from a Directory server + /// with the fetchSchema method of LdapConnection or by creating an LdapEntry + /// containing schema attributes. The following sample code demonstrates how to + /// retrieve schema elements from LdapSchema + /// </p> + /// <pre><code> + /// . + /// . + /// . + /// LdapSchema schema; + /// LdapSchemaElement element; + /// + /// // connect to the server + /// lc.connect( ldapHost, ldapPort ); + /// lc.bind( ldapVersion, loginDN, password ); + /// + /// // read the schema from the directory + /// schema = lc.fetchSchema( lc.getSchemaDN() ); + /// + /// // retrieve the definition of common name + /// element = schema.getAttributeSchema( "cn" ); + /// System.out.println("The attribute cn has an oid of " + element.getID()); + /// . + /// . + /// . + /// </code></pre> + /// </p> + /// + /// </summary> + /// <seealso cref="LdapSchemaElement"> + /// </seealso> + /// <seealso cref="LdapConnection#fetchSchema"> + /// </seealso> + /// <seealso cref="LdapConnection#getSchemaDN"> + /// </seealso> + public class LdapSchema:LdapEntry + { + private void InitBlock() + { + nameTable = new System.Collections.Hashtable[8]; + idTable = new System.Collections.Hashtable[8]; + } + /// <summary> Returns an enumeration of attribute definitions. + /// + /// </summary> + /// <returns> An enumeration of attribute definitions. + /// </returns> + virtual public System.Collections.IEnumerator AttributeSchemas + { + get + { + return new EnumeratedIterator(idTable[ATTRIBUTE].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of DIT content rule definitions. + /// + /// </summary> + /// <returns> An enumeration of DIT content rule definitions. + /// </returns> + virtual public System.Collections.IEnumerator DITContentRuleSchemas + { + get + { + return new EnumeratedIterator(idTable[DITCONTENT].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of DIT structure rule definitions. + /// + /// </summary> + /// <returns> An enumeration of DIT structure rule definitions. + /// </returns> + virtual public System.Collections.IEnumerator DITStructureRuleSchemas + { + get + { + return new EnumeratedIterator(idTable[DITSTRUCTURE].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of matching rule definitions. + /// + /// </summary> + /// <returns> An enumeration of matching rule definitions. + /// </returns> + virtual public System.Collections.IEnumerator MatchingRuleSchemas + { + get + { + return new EnumeratedIterator(idTable[MATCHING].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of matching rule use definitions. + /// + /// </summary> + /// <returns> An enumeration of matching rule use definitions. + /// </returns> + virtual public System.Collections.IEnumerator MatchingRuleUseSchemas + { + get + { + return new EnumeratedIterator(idTable[MATCHING_USE].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of name form definitions. + /// + /// </summary> + /// <returns> An enumeration of name form definitions. + /// </returns> + virtual public System.Collections.IEnumerator NameFormSchemas + { + get + { + return new EnumeratedIterator(idTable[NAME_FORM].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of object class definitions. + /// + /// </summary> + /// <returns> An enumeration of object class definitions. + /// </returns> + virtual public System.Collections.IEnumerator ObjectClassSchemas + { + get + { + return new EnumeratedIterator(idTable[OBJECT_CLASS].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of syntax definitions. + /// + /// </summary> + /// <returns> An enumeration of syntax definitions. + /// </returns> + virtual public System.Collections.IEnumerator SyntaxSchemas + { + get + { + return new EnumeratedIterator(idTable[SYNTAX].Values.GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of attribute names. + /// + /// </summary> + /// <returns> An enumeration of attribute names. + /// </returns> + virtual public System.Collections.IEnumerator AttributeNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[ATTRIBUTE].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of DIT content rule names. + /// + /// </summary> + /// <returns> An enumeration of DIT content rule names. + /// </returns> + virtual public System.Collections.IEnumerator DITContentRuleNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[DITCONTENT].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of DIT structure rule names. + /// + /// </summary> + /// <returns> An enumeration of DIT structure rule names. + /// </returns> + virtual public System.Collections.IEnumerator DITStructureRuleNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[DITSTRUCTURE].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of matching rule names. + /// + /// </summary> + /// <returns> An enumeration of matching rule names. + /// </returns> + virtual public System.Collections.IEnumerator MatchingRuleNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[MATCHING].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of matching rule use names. + /// + /// </summary> + /// <returns> An enumeration of matching rule use names. + /// </returns> + virtual public System.Collections.IEnumerator MatchingRuleUseNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[MATCHING_USE].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of name form names. + /// + /// </summary> + /// <returns> An enumeration of name form names. + /// </returns> + virtual public System.Collections.IEnumerator NameFormNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[NAME_FORM].Keys).GetEnumerator()); + } + + } + /// <summary> Returns an enumeration of object class names. + /// + /// </summary> + /// <returns> An enumeration of object class names. + /// </returns> + virtual public System.Collections.IEnumerator ObjectClassNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(nameTable[OBJECT_CLASS].Keys).GetEnumerator()); + } + + } + + /// <summary>The idTable hash on the oid (or integer ID for DITStructureRule) and + /// is used for retrieving enumerations + /// </summary> + private System.Collections.Hashtable[] idTable; + + /// <summary>The nameTable will hash on the names (if available). To insure + /// case-insensibility, the Keys for this table will be a String cast to + /// Uppercase. + /// </summary> + private System.Collections.Hashtable[] nameTable; + + /*package*/ /// <summary> The following lists the Ldap names of subschema attributes for + /// schema elements (definitions): + /// </summary> + internal static readonly System.String[] schemaTypeNames = new System.String[]{"attributeTypes", "objectClasses", "ldapSyntaxes", "nameForms", "dITContentRules", "dITStructureRules", "matchingRules", "matchingRuleUse"}; + + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int ATTRIBUTE = 0; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int OBJECT_CLASS = 1; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int SYNTAX = 2; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int NAME_FORM = 3; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int DITCONTENT = 4; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int DITSTRUCTURE = 5; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int MATCHING = 6; + /// <summary>An index into the the arrays schemaTypeNames, idTable, and nameTable </summary> + /*package*/ + internal const int MATCHING_USE = 7; + + + /// <summary> Constructs an LdapSchema object from attributes of an LdapEntry. + /// <p>The object is empty if the entry parameter contains no schema + /// attributes. The recognized schema attributes are the following: <br> + /// <pre><code> + /// "attributeTypes", "objectClasses", "ldapSyntaxes", + /// "nameForms", "dITContentRules", "dITStructureRules", + /// "matchingRules","matchingRuleUse" + /// </code></pre> + /// </summary> + /// <param name="ent"> An LdapEntry containing schema information. + /// </param> + public LdapSchema(LdapEntry ent):base(ent.DN, ent.getAttributeSet()) + { + InitBlock(); + //reset all definitions + for (int i = 0; i < schemaTypeNames.Length; i++) + { + idTable[i] = new System.Collections.Hashtable(); + nameTable[i] = new System.Collections.Hashtable(); + } + System.Collections.IEnumerator itr = base.getAttributeSet().GetEnumerator(); + while (itr.MoveNext()) + { + + LdapAttribute attr = (LdapAttribute) itr.Current; + System.String value_Renamed, attrName = attr.Name; + System.Collections.IEnumerator enumString = attr.StringValues; + + if (attrName.ToUpper().Equals(schemaTypeNames[OBJECT_CLASS].ToUpper())) + { + LdapObjectClassSchema classSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + try + { + classSchema = new LdapObjectClassSchema(value_Renamed); + } + catch (System.Exception e) + { + continue; //Error parsing: do not add this definition + } + addElement(OBJECT_CLASS, classSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[ATTRIBUTE].ToUpper())) + { + LdapAttributeSchema attrSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + try + { + attrSchema = new LdapAttributeSchema(value_Renamed); + } + catch (System.Exception e) + { + continue; //Error parsing: do not add this definition + } + addElement(ATTRIBUTE, attrSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[SYNTAX].ToUpper())) + { + LdapSyntaxSchema syntaxSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + syntaxSchema = new LdapSyntaxSchema(value_Renamed); + addElement(SYNTAX, syntaxSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING].ToUpper())) + { + LdapMatchingRuleSchema matchingRuleSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + matchingRuleSchema = new LdapMatchingRuleSchema(value_Renamed, null); + addElement(MATCHING, matchingRuleSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING_USE].ToUpper())) + { + LdapMatchingRuleUseSchema matchingRuleUseSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + matchingRuleUseSchema = new LdapMatchingRuleUseSchema(value_Renamed); + addElement(MATCHING_USE, matchingRuleUseSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[DITCONTENT].ToUpper())) + { + LdapDITContentRuleSchema dITContentRuleSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + dITContentRuleSchema = new LdapDITContentRuleSchema(value_Renamed); + addElement(DITCONTENT, dITContentRuleSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[DITSTRUCTURE].ToUpper())) + { + LdapDITStructureRuleSchema dITStructureRuleSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + dITStructureRuleSchema = new LdapDITStructureRuleSchema(value_Renamed); + addElement(DITSTRUCTURE, dITStructureRuleSchema); + } + } + else if (attrName.ToUpper().Equals(schemaTypeNames[NAME_FORM].ToUpper())) + { + LdapNameFormSchema nameFormSchema; + while (enumString.MoveNext()) + { + value_Renamed = ((System.String) enumString.Current); + nameFormSchema = new LdapNameFormSchema(value_Renamed); + addElement(NAME_FORM, nameFormSchema); + } + } + //All non schema attributes are ignored. + continue; + } + return ; + } + + /// <summary> Adds the schema definition to the idList and nameList HashMaps. + /// This method is used by the methods fetchSchema and add. + /// + /// Note that the nameTable has all keys cast to Upper-case. This is so we + /// can have a case-insensitive HashMap. The getXXX (String key) methods + /// will also cast to uppercase. + /// + /// </summary> + /// <param name="schemaType"> Type of schema definition, use one of the final + /// integers defined at the top of this class: + /// ATTRIBUTE, OBJECT_CLASS, SYNTAX, NAME_FORM, + /// DITCONTENT, DITSTRUCTURE, MATCHING, MATCHING_USE + /// + /// </param> + /// <param name="element"> Schema element definition. + /// </param> + private void addElement(int schemaType, LdapSchemaElement element) + { + SupportClass.PutElement(idTable[schemaType], element.ID, element); + System.String[] names = element.Names; + for (int i = 0; i < names.Length; i++) + { + SupportClass.PutElement(nameTable[schemaType], names[i].ToUpper(), element); + } + return ; + } + + // ####################################################################### + // The following methods retrieve a SchemaElement given a Key name: + // ####################################################################### + + /// <summary> This function abstracts retrieving LdapSchemaElements from the local + /// copy of schema in this LdapSchema class. This is used by + /// <code>getXXX(String name)</code> functions. + /// + /// <p>Note that the nameTable has all keys cast to Upper-case. This is so + /// we can have a case-insensitive HashMap. The getXXX (String key) + /// methods will also cast to uppercase.</p> + /// + /// <p>The first character of a NAME string can only be an alpha character + /// (see section 4.1 of rfc2252) Thus if the first character is a digit we + /// can conclude it is an OID. Note that this digit is ASCII only.</p> + /// + /// </summary> + /// <param name="schemaType">Specifies which list is to be used in schema + /// lookup. + /// </param> + /// <param name="key"> The key can be either an OID or a name string. + /// </param> + private LdapSchemaElement getSchemaElement(int schemaType, System.String key) + { + if ((System.Object) key == null || key.ToUpper().Equals("".ToUpper())) + return null; + char c = key[0]; + if (c >= '0' && c <= '9') + { + //oid lookup + return (LdapSchemaElement) idTable[schemaType][key]; + } + else + { + //name lookup + return (LdapSchemaElement) nameTable[schemaType][key.ToUpper()]; + } + } + + /// <summary> Returns a particular attribute definition, or null if not found. + /// + /// </summary> + /// <param name="name"> Name or OID of the attribute for which a definition is + /// to be returned. + /// + /// </param> + /// <returns> The attribute definition, or null if not found. + /// </returns> + public virtual LdapAttributeSchema getAttributeSchema(System.String name) + { + return (LdapAttributeSchema) getSchemaElement(ATTRIBUTE, name); + } + + /// <summary> Returns a particular DIT content rule definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name of the DIT content rule use for which a + /// definition is to be returned. + /// + /// </param> + /// <returns> The DIT content rule definition, or null if not found. + /// </returns> + public virtual LdapDITContentRuleSchema getDITContentRuleSchema(System.String name) + { + return (LdapDITContentRuleSchema) getSchemaElement(DITCONTENT, name); + } + + /// <summary> Returns a particular DIT structure rule definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name of the DIT structure rule use for which a + /// definition is to be returned. + /// + /// </param> + /// <returns> The DIT structure rule definition, or null if not found. + /// </returns> + public virtual LdapDITStructureRuleSchema getDITStructureRuleSchema(System.String name) + { + return (LdapDITStructureRuleSchema) getSchemaElement(DITSTRUCTURE, name); + } + + /// <summary> Returns a particular DIT structure rule definition, or null if not found. + /// + /// </summary> + /// <param name="ID"> The ID of the DIT structure rule use for which a + /// definition is to be returned. + /// + /// </param> + /// <returns> The DIT structure rule definition, or null if not found. + /// </returns> + public virtual LdapDITStructureRuleSchema getDITStructureRuleSchema(int ID) + { + System.Int32 IDKey = ID; + return (LdapDITStructureRuleSchema) idTable[DITSTRUCTURE][IDKey]; + } + + /// <summary> Returns a particular matching rule definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name of the matching rule for which a definition + /// is to be returned. + /// + /// </param> + /// <returns> The matching rule definition, or null if not found. + /// </returns> + public virtual LdapMatchingRuleSchema getMatchingRuleSchema(System.String name) + { + return (LdapMatchingRuleSchema) getSchemaElement(MATCHING, name); + } + + /// <summary> Returns a particular matching rule use definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name of the matching rule use for which a definition + /// is to be returned. + /// + /// </param> + /// <returns> The matching rule use definition, or null if not found. + /// </returns> + public virtual LdapMatchingRuleUseSchema getMatchingRuleUseSchema(System.String name) + { + return (LdapMatchingRuleUseSchema) getSchemaElement(MATCHING_USE, name); + } + + /// <summary> Returns a particular name form definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name of the name form for which a definition + /// is to be returned. + /// + /// </param> + /// <returns> The name form definition, or null if not found. + /// </returns> + public virtual LdapNameFormSchema getNameFormSchema(System.String name) + { + return (LdapNameFormSchema) getSchemaElement(NAME_FORM, name); + } + + /// <summary> Returns a particular object class definition, or null if not found. + /// + /// </summary> + /// <param name="name"> The name or OID of the object class for which a + /// definition is to be returned. + /// + /// </param> + /// <returns> The object class definition, or null if not found. + /// </returns> + public virtual LdapObjectClassSchema getObjectClassSchema(System.String name) + { + return (LdapObjectClassSchema) getSchemaElement(OBJECT_CLASS, name); + } + + /// <summary> Returns a particular syntax definition, or null if not found. + /// + /// </summary> + /// <param name="oid"> The oid of the syntax for which a definition + /// is to be returned. + /// + /// </param> + /// <returns> The syntax definition, or null if not found. + /// </returns> + public virtual LdapSyntaxSchema getSyntaxSchema(System.String oid) + { + return (LdapSyntaxSchema) getSchemaElement(SYNTAX, oid); + } + + // ######################################################################## + // The following methods return an Enumeration of SchemaElements by schema type + // ######################################################################## + + // ####################################################################### + // The following methods retrieve an Enumeration of Names of a schema type + // ####################################################################### + + + /// <summary> This helper function returns a number that represents the type of schema + /// definition the element represents. The top of this file enumerates + /// these types. + /// + /// </summary> + /// <param name="element"> A class extending LdapSchemaElement. + /// + /// </param> + /// <returns> a Number that identifies the type of schema element and + /// will be one of the following: + /// ATTRIBUTE, OBJECT_CLASS, SYNTAX, NAME_FORM, + /// DITCONTENT, DITSTRUCTURE, MATCHING, MATCHING_USE + /// </returns> + private int getType(LdapSchemaElement element) + { + if (element is LdapAttributeSchema) + return LdapSchema.ATTRIBUTE; + else if (element is LdapObjectClassSchema) + return LdapSchema.OBJECT_CLASS; + else if (element is LdapSyntaxSchema) + return LdapSchema.SYNTAX; + else if (element is LdapNameFormSchema) + return LdapSchema.NAME_FORM; + else if (element is LdapMatchingRuleSchema) + return LdapSchema.MATCHING; + else if (element is LdapMatchingRuleUseSchema) + return LdapSchema.MATCHING_USE; + else if (element is LdapDITContentRuleSchema) + return LdapSchema.DITCONTENT; + else if (element is LdapDITStructureRuleSchema) + return LdapSchema.DITSTRUCTURE; + else + throw new System.ArgumentException("The specified schema element type is not recognized"); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchemaElement.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchemaElement.cs new file mode 100755 index 00000000000..c1498926624 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSchemaElement.cs @@ -0,0 +1,290 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapSchemaElement.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// +using System; +using Novell.Directory.Ldap.Utilclass; + +namespace Novell.Directory.Ldap +{ + + /// <summary> The LdapSchemaElement class is the base class representing schema + /// elements (definitions) in Ldap. + /// + /// <p>An LdapSchemaElement is read-only, single-valued LdapAttribute. + /// Therefore, it does not support the addValue and removeValue methods from + /// LdapAttribute. This class overrides those methods and throws + /// <code>UnsupportedOperationException<code> if either of those methods are + /// invoked by an application.<p> + /// + /// </summary> + /// <seealso cref="LdapSchema"> + /// </seealso> + /// <seealso cref="LdapConnection#fetchSchema"> + /// </seealso> + public abstract class LdapSchemaElement:LdapAttribute + { + private void InitBlock() + { + hashQualifier = new System.Collections.Hashtable(); + } + /// <summary> Returns an array of names for the element, or null if + /// none is found. + /// + /// <p>The getNames method accesses the NAME qualifier (from the BNF + /// descriptions of Ldap schema definitions). The array consists of all + /// values of the NAME qualifier. </p> + /// + /// </summary> + /// <returns> An array of names for the element, or null if none + /// is found. + /// </returns> + virtual public System.String[] Names + { + get + { + if (names == null) + return null; + System.String[] generated_var = new System.String[names.Length]; + names.CopyTo(generated_var, 0); + return generated_var; + } + + } + /// <summary> Returns the description of the element. + /// + /// <p>The getDescription method returns the value of the DESC qualifier + /// (from the BNF descriptions of Ldap schema definitions). </p> + /// + /// </summary> + /// <returns> The description of the element. + /// + /// </returns> + virtual public System.String Description + { + get + { + return description; + } + + } + /// <summary> Returns the unique object identifier (OID) of the element. + /// + /// </summary> + /// <returns> The OID of the element. + /// </returns> + virtual public System.String ID + { + get + { + return oid; + } + + } + /// <summary> Returns an enumeration of all qualifiers of the element which are + /// vendor specific (begin with "X-"). + /// + /// </summary> + /// <returns> An enumeration of all qualifiers of the element. + /// </returns> + virtual public System.Collections.IEnumerator QualifierNames + { + get + { + return new EnumeratedIterator(new SupportClass.SetSupport(hashQualifier.Keys).GetEnumerator()); + } + + } + /// <summary> Returns whether the element has the OBSOLETE qualifier + /// in its Ldap definition. + /// + /// </summary> + /// <returns> True if the Ldap definition contains the OBSOLETE qualifier; + /// false if OBSOLETE qualifier is not present. + /// </returns> + virtual public bool Obsolete + { + get + { + return obsolete; + } + + } + + /// <summary> Creates an LdapSchemaElement by setting the name of the LdapAttribute. + /// Because this is the only constructor, all extended classes are expected + /// to call this constructor. The value of the LdapAttribute must be set + /// by the setValue method. + /// </summary> + /// <param name="attrName"> The attribute name of the schema definition. Valid + /// names are one of the following: + /// "attributeTypes", "objectClasses", "ldapSyntaxes", + /// "nameForms", "dITContentRules", "dITStructureRules", + /// "matchingRules", or "matchingRuleUse" + /// </param> + protected internal LdapSchemaElement(System.String attrName):base(attrName) + { + InitBlock(); + } + /// <summary> The names of the schema element.</summary> + [CLSCompliantAttribute(false)] + protected internal System.String[] names = new System.String[]{""}; + + /// <summary> The OID for the schema element.</summary> + protected internal System.String oid = ""; + + /// <summary> The description for the schema element.</summary> + [CLSCompliantAttribute(false)] + protected internal System.String description = ""; + + /// <summary> If present, indicates that the element is obsolete, no longer in use in + /// the directory. + /// </summary> + [CLSCompliantAttribute(false)] + protected internal bool obsolete = false; + + /// <summary> A string array of optional, or vendor-specific, qualifiers for the + /// schema element. + /// + /// <p> These optional qualifiers begin with "X-"; the Novell eDirectory + /// specific qualifiers begin with "X-NDS". </p> + /// </summary> + protected internal System.String[] qualifier = new System.String[]{""}; + + /// <summary> A hash table that contains the vendor-specific qualifiers (for example, + /// the X-NDS flags). + /// </summary> + protected internal System.Collections.Hashtable hashQualifier; + + /// <summary> Returns an array of all values of a specified optional or non- + /// standard qualifier of the element. + /// + /// <p>The getQualifier method may be used to access the values of + /// vendor-specific qualifiers (which begin with "X-").</p> + /// + /// </summary> + /// <param name="name"> The name of the qualifier, case-sensitive. + /// + /// </param> + /// <returns> An array of values for the specified non-standard qualifier. + /// </returns> + public virtual System.String[] getQualifier(System.String name) + { + AttributeQualifier attr = (AttributeQualifier) hashQualifier[name]; + if (attr != null) + { + return attr.Values; + } + return null; + } + + /// <summary> Returns a string in a format suitable for directly adding to a directory, + /// as a value of the particular schema element. + /// + /// </summary> + /// <returns> A string that can be used to add the element to the directory. + /// </returns> + public override System.String ToString() + { + return formatString(); + } + + /// <summary> Implementations of formatString format a schema element into a string + /// suitable for using in a modify (ADD) operation to the directory. + /// toString uses this method. This method is needed because a call to + /// setQualifier requires reconstructing the string value of the schema + /// element. + /// </summary> + abstract protected internal System.String formatString(); + + /// <summary> Sets the values of a specified optional or non-standard qualifier of + /// the element. + /// + /// <p>The setQualifier method is used to set the values of vendor- + /// specific qualifiers (which begin with "X-"). + /// + /// </summary> + /// <param name="name"> The name of the qualifier, case-sensitive. + /// <br><br> + /// </param> + /// <param name="values"> The values to set for the qualifier. + /// </param> + public virtual void setQualifier(System.String name, System.String[] values) + { + AttributeQualifier attrQualifier = new AttributeQualifier(name, values); + SupportClass.PutElement(hashQualifier, name, attrQualifier); + + /* + * This is the only method that modifies the schema element. + * We need to reset the attribute value since it has changed. + */ + base.Value = formatString(); + return ; + } + + /// <summary> LdapSchemaElement is read-only and this method is over-ridden to + /// throw an exception. + /// @throws UnsupportedOperationException always thrown since + /// LdapSchemaElement is read-only + /// </summary> + public override void addValue(System.String value_Renamed) + { + throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement"); + } + + /// <summary> LdapSchemaElement is read-only and this method is over-ridden to + /// throw an exception. + /// @throws UnsupportedOperationException always thrown since + /// LdapSchemaElement is read-only + /// </summary> + public virtual void addValue(System.Byte[] value_Renamed) + { + throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement"); + } + /// <summary> LdapSchemaElement is read-only and this method is over-ridden to + /// throw an exception. + /// @throws UnsupportedOperationException always thrown since + /// LdapSchemaElement is read-only + /// </summary> + public override void removeValue(System.String value_Renamed) + { + throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement"); + } + + /// <summary> LdapSchemaElement is read-only and this method is over-ridden to + /// throw an exception. + /// @throws UnsupportedOperationException always thrown since + /// LdapSchemaElement is read-only + /// </summary> + public virtual void removeValue(System.Byte[] value_Renamed) + { + throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement"); + } + } +}
\ No newline at end of file diff --git a/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSyntaxSchema.cs b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSyntaxSchema.cs new file mode 100755 index 00000000000..51ca55014e2 --- /dev/null +++ b/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapSyntaxSchema.cs @@ -0,0 +1,163 @@ +/****************************************************************************** +* The MIT License +* Copyright (c) 2003 Novell Inc. www.novell.com +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the Software), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*******************************************************************************/ +// +// Novell.Directory.Ldap.LdapSyntaxSchema.cs +// +// Author: +// Sunil Kumar (Sunilk@novell.com) +// +// (C) 2003 Novell, Inc (http://www.novell.com) +// + +using System; +using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; +using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier; + +namespace Novell.Directory.Ldap +{ + + /// <summary> Represents a syntax definition in the directory schema. + /// + /// <p>The LdapSyntaxSchema class represents the definition of a syntax. It is + /// used to discover the known set of syntaxes in effect for the subschema. </p> + /// + /// <p>Although this extends LdapSchemaElement, it does not use the name or + /// obsolete members. Therefore, calls to the getName method always return + /// null and to the isObsolete method always returns false. There is also no + /// matching getSyntaxNames method in LdapSchema. Note also that adding and + /// removing syntaxes is not typically a supported feature of Ldap servers.</p> + /// </summary> + + public class LdapSyntaxSchema:LdapSchemaElement + { + + /// <summary> Constructs a syntax for adding to or deleting from the schema. + /// + /// <p>Adding and removing syntaxes is not typically a supported + /// feature of Ldap servers. Novell eDirectory does not allow syntaxes to + /// be added or removed.</p> + /// + /// </summary> + /// <param name="oid"> The unique object identifier of the syntax - in + /// dotted numerical format.</br></br> + /// + /// </param> + /// <param name="description">An optional description of the syntax. + /// </param> + public LdapSyntaxSchema(System.String oid, System.String description):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX]) + { + base.oid = oid; + base.description = description; + base.Value = formatString(); + return ; + } + + /// <summary> Constructs a syntax from the raw string value returned on a schema + /// query for LdapSyntaxes. + /// + /// </summary> + /// <param name="raw"> The raw string value returned from a schema + /// query for ldapSyntaxes. + /// </param> + public LdapSyntaxSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX]) + { + try + { + SchemaParser parser = new SchemaParser(raw); + + if ((System.Object) parser.ID != null) + base.oid = parser.ID; + if ((System.Object) parser.Description != null) + base.description = parser.Description; + System.Collections.IEnumerator qualifiers = parser.Qualifiers; + AttributeQualifier attrQualifier; + while (qualifiers.MoveNext()) + { + attrQualifier = (AttributeQualifier) qualifiers.Current; + setQualifier(attrQualifier.Name, attrQualifier.Values); + } + base.Value = formatString(); + } + catch (System.IO.IOException e) + { + throw new System.SystemException(e.ToString()); + } + return ; + } + + /// <summary> Returns a string in a format suitable for directly adding to a + /// directory, as a value of the particular schema element class. + /// + /// </summary> + /// <returns> A string representation of the syntax's definition. + /// </returns> + protected internal override System.String formatString() + { + System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); + System.String token; + + if ((System.Object) (token = ID) != null) + { + valueBuffer.Append(token); + } + if ((System.Object) (token = Description) != null) + { + valueBuffer.Append(" DESC "); + valueBuffer.Append("'" + token + "'"); + } + + System.Collections.IEnumerator en; + if ((en = QualifierNames) != null) + { + System.String qualName; + System.String[] qualValue; + while (en.MoveNext()) + { + qualName = ((System.String) en.Current); + valueBuffer.Append(" " + qualName + " "); + if ((qualValue = getQualifier(qualName)) != null) + { + if (qualValue.Length > 1) + { + valueBuffer.Append("( "); + for (int i = 0; i < qualValue.Length; i++) + { + if (i > 0) + { + valueBuffer.Append(" "); + } + valueBuffer.Append("'" + qualValue[i] + "'"); + } + if (qualValue.Length > 1) + { + valueBuffer.Append(" )"); + } + } + } + } + } + valueBuffer.Append(" )"); + return valueBuffer.ToString(); + } + } +}
\ No newline at end of file |