Class: Treequel::Schema
- Inherits:
-
Object
- Object
- Treequel::Schema
- Extended by:
- Loggability
- Includes:
- Constants::Patterns
- Defined in:
- lib/treequel/schema.rb,
lib/treequel/schema/objectclass.rb
Overview
This is a collection of classes for representing objectClasses in a Treequel::Schema.
Authors
-
Michael Granger <[email protected]>
-
Mahlon E. Smith <[email protected]>
:include: LICENSE
–
Please see the file LICENSE in the base directory for licensing details.
Defined Under Namespace
Classes: AbstractObjectClass, AttributeType, AuxiliaryObjectClass, LDAPSyntax, MatchingRule, MatchingRuleUse, ObjectClass, StructuralObjectClass, Table
Constant Summary collapse
- OBJECTCLASS_TYPES =
The types of objectClass as specified in the schema, along with which Ruby class corresponds to it. Each class registers itself as it’s defined.
{}
Constants included from Constants::Patterns
Constants::Patterns::ALPHA, Constants::Patterns::AMPERSAND, Constants::Patterns::ASSERTIONVALUE, Constants::Patterns::ASTERISK, Constants::Patterns::ATTRIBUTE_TYPE, Constants::Patterns::ATTRIBUTE_TYPE_AND_VALUE, Constants::Patterns::ATTRIBUTE_VALUE, Constants::Patterns::BASE64_CHAR, Constants::Patterns::BASE64_STRING, Constants::Patterns::COLON, Constants::Patterns::COMMA, Constants::Patterns::DESCR, Constants::Patterns::DIGIT, Constants::Patterns::DISTINGUISHED_NAME, Constants::Patterns::DN_ESCAPED, Constants::Patterns::DOLLAR, Constants::Patterns::DOT, Constants::Patterns::DQUOTE, Constants::Patterns::DSTRING, Constants::Patterns::EQUALS, Constants::Patterns::ESC, Constants::Patterns::ESCAPED, Constants::Patterns::EXCLAMATION, Constants::Patterns::EXTENSIONS, Constants::Patterns::FILL, Constants::Patterns::FOLD, Constants::Patterns::HEX, Constants::Patterns::HEXPAIR, Constants::Patterns::HEXSTRING, Constants::Patterns::HYPHEN, Constants::Patterns::KEYCHAR, Constants::Patterns::KEYSTRING, Constants::Patterns::KIND, Constants::Patterns::LANGLE, Constants::Patterns::LCURLY, Constants::Patterns::LDAP_ATTRIBUTE_DESCRIPTION, Constants::Patterns::LDAP_ATTRIBUTE_TYPE_DESCRIPTION, Constants::Patterns::LDAP_MATCHING_RULE_DESCRIPTION, Constants::Patterns::LDAP_MATCHING_RULE_USE_DESCRIPTION, Constants::Patterns::LDAP_MISORDERED_DESC_OBJECTCLASS_DESCRIPTION, Constants::Patterns::LDAP_MISORDERED_KIND_OBJECTCLASS_DESCRIPTION, Constants::Patterns::LDAP_MISORDERED_SYNTAX_ATTRIBUTE_TYPE_DESCRIPTION, Constants::Patterns::LDAP_OBJECTCLASS_DESCRIPTION, Constants::Patterns::LDAP_SUBSTRING_FILTER, Constants::Patterns::LDAP_SUBSTRING_FILTER_VALUE, Constants::Patterns::LDAP_SYNTAX_DESCRIPTION, Constants::Patterns::LDAP_TRAILING_KIND_OBJECTCLASS_DESCRIPTION, Constants::Patterns::LDAP_UNESCAPE_SQUOTE_ATTRIBUTE_TYPE_DESCRIPTION, Constants::Patterns::LDIF_ATTRIBUTE_DESCRIPTION, Constants::Patterns::LDIF_ATTRIBUTE_TYPE, Constants::Patterns::LDIF_ATTRTYPE_OPTION, Constants::Patterns::LDIF_ATTRTYPE_OPTIONS, Constants::Patterns::LDIF_ATTRVAL_SPEC, Constants::Patterns::LDIF_ATTR_TYPE_CHARS, Constants::Patterns::LDIF_OPT_CHAR, Constants::Patterns::LDIF_SAFE_CHAR, Constants::Patterns::LDIF_SAFE_INIT_CHAR, Constants::Patterns::LDIF_SAFE_STRING, Constants::Patterns::LDIF_VALUE_SPEC, Constants::Patterns::LDIGIT, Constants::Patterns::LEADCHAR, Constants::Patterns::LEADKEYCHAR, Constants::Patterns::LEN, Constants::Patterns::LPAREN, Constants::Patterns::LUTF1, Constants::Patterns::MALFORMED_DSTRING, Constants::Patterns::MALFORMED_QDSTRING, Constants::Patterns::NOIDLEN, Constants::Patterns::NORMAL, Constants::Patterns::NUL, Constants::Patterns::NUMBER, Constants::Patterns::NUMERICOID, Constants::Patterns::OCTET, Constants::Patterns::OID, Constants::Patterns::OIDLIST, Constants::Patterns::OIDS, Constants::Patterns::PAIR, Constants::Patterns::PLUS, Constants::Patterns::QDESCR, Constants::Patterns::QDESCRLIST, Constants::Patterns::QDESCRS, Constants::Patterns::QDSTRING, Constants::Patterns::QDSTRINGLIST, Constants::Patterns::QDSTRINGS, Constants::Patterns::QQ, Constants::Patterns::QS, Constants::Patterns::QUOTED_DESCR, Constants::Patterns::QUOTED_NUMERICOID, Constants::Patterns::QUTF1, Constants::Patterns::QUTF8, Constants::Patterns::RANGLE, Constants::Patterns::RCURLY, Constants::Patterns::RELATIVE_DISTINGUISHED_NAME, Constants::Patterns::RPAREN, Constants::Patterns::SEMI, Constants::Patterns::SEP, Constants::Patterns::SHARP, Constants::Patterns::SP, Constants::Patterns::SPACE, Constants::Patterns::SPECIAL, Constants::Patterns::SQUOTE, Constants::Patterns::STRING, Constants::Patterns::STRINGCHAR, Constants::Patterns::SUTF1, Constants::Patterns::TILDE, Constants::Patterns::TRAILCHAR, Constants::Patterns::TUTF1, Constants::Patterns::UNESCAPED, Constants::Patterns::URI_REF, Constants::Patterns::USAGE, Constants::Patterns::USCORE, Constants::Patterns::UTF0, Constants::Patterns::UTF1, Constants::Patterns::UTF1SUBSET, Constants::Patterns::UTF2, Constants::Patterns::UTF3, Constants::Patterns::UTF4, Constants::Patterns::UTF8, Constants::Patterns::UTFMB, Constants::Patterns::VALUEENCODING, Constants::Patterns::VERTBAR, Constants::Patterns::WSP, Constants::Patterns::XSTRING
Instance Attribute Summary collapse
-
#attribute_types ⇒ Object
readonly
The hash of Treequel::Schema::AttributeType objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the attributeTypes in the directory’s schema.
-
#ldap_syntaxes ⇒ Object
readonly
The hash of Treequel::Schema::LDAPSyntax objects, keyed by OID, that describe the syntaxes in the directory’s schema.
-
#matching_rule_uses ⇒ Object
(also: #matching_rule_use)
readonly
The hash of Treequel::Schema::MatchingRuleUse objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the attributes to which a matchingRule can be applied.
-
#matching_rules ⇒ Object
readonly
The hash of Treequel::Schema::MatchingRule objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the matchingRules int he directory’s schema.
-
#object_classes ⇒ Object
readonly
The table of Treequel::Schema::ObjectClass objects, keyed by OID and any associated NAME attributes (as Symbols), that describes the objectClasses in the directory’s schema.
Class Method Summary collapse
-
.oids(*oids) ⇒ Object
Return a description of the given
oidssuitable for inclusion in an RFC4512-style schema description entry. -
.parse_names(names) ⇒ Object
Parse the given short
namesstring (a ‘qdescrs’ in the BNF) into an Array of zero or more Strings. -
.parse_oid(oidstring) ⇒ Object
Parse a single OID into either a numeric OID string or a Symbol.
-
.parse_oids(oidstring) ⇒ Object
Parse the given
oidstringinto an Array of OIDs, with Strings for numeric OIDs and Symbols for aliases. -
.qdescrs(*descriptors) ⇒ Object
Return a description of the given
descriptorssuitable for inclusion in an RFC4512-style schema description entry. -
.qdstring(string) ⇒ Object
Escape and quote the specified
stringaccording to the rules in RFC4512/2252. -
.strict_parse_mode=(newval) ⇒ Object
Set the strict-parsing
flag. -
.strict_parse_mode? ⇒ Boolean
Test whether or not strict-parsing mode is in effect.
-
.unquote_desc(desc) ⇒ Object
Return a new string which is
descwith quotes stripped and any escaped characters un-escaped.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Schema
constructor
Create a new Treequel::Schema from the specified
hash. -
#inspect ⇒ Object
Return a human-readable representation of the object suitable for debugging.
-
#operational_attribute_types ⇒ Object
Return the Treequel::Schema::AttributeType objects that correspond to the operational attributes that are supported by the directory.
-
#to_s ⇒ Object
Return the schema as a human-readable english string.
Constructor Details
#initialize(hash) ⇒ Schema
Create a new Treequel::Schema from the specified hash. The hash should be of the same form as the one returned by LDAP::Conn.schema, i.e., a Hash of Arrays associated with the keys “objectClasses”, “ldapSyntaxes”, “matchingRuleUse”, “attributeTypes”, and “matchingRules”.
178 179 180 181 182 183 184 |
# File 'lib/treequel/schema.rb', line 178 def initialize( hash ) @object_classes = self.parse_objectclasses( hash['objectClasses'] || [] ) @attribute_types = self.parse_attribute_types( hash['attributeTypes'] || [] ) @ldap_syntaxes = self.parse_ldap_syntaxes( hash['ldapSyntaxes'] || [] ) @matching_rules = self.parse_matching_rules( hash['matchingRules'] || [] ) @matching_rule_uses = self.parse_matching_rule_uses( hash['matchingRuleUse'] || [] ) end |
Instance Attribute Details
#attribute_types ⇒ Object (readonly)
The hash of Treequel::Schema::AttributeType objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the attributeTypes in the directory’s schema.
197 198 199 |
# File 'lib/treequel/schema.rb', line 197 def attribute_types @attribute_types end |
#ldap_syntaxes ⇒ Object (readonly)
The hash of Treequel::Schema::LDAPSyntax objects, keyed by OID, that describe the syntaxes in the directory’s schema.
201 202 203 |
# File 'lib/treequel/schema.rb', line 201 def ldap_syntaxes @ldap_syntaxes end |
#matching_rule_uses ⇒ Object (readonly) Also known as: matching_rule_use
The hash of Treequel::Schema::MatchingRuleUse objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the attributes to which a matchingRule can be applied.
209 210 211 |
# File 'lib/treequel/schema.rb', line 209 def matching_rule_uses @matching_rule_uses end |
#matching_rules ⇒ Object (readonly)
The hash of Treequel::Schema::MatchingRule objects, keyed by OID and any associated NAME attributes (as Symbols), that describe the matchingRules int he directory’s schema.
205 206 207 |
# File 'lib/treequel/schema.rb', line 205 def matching_rules @matching_rules end |
#object_classes ⇒ Object (readonly)
The table of Treequel::Schema::ObjectClass objects, keyed by OID and any associated NAME attributes (as Symbols), that describes the objectClasses in the directory’s schema.
193 194 195 |
# File 'lib/treequel/schema.rb', line 193 def object_classes @object_classes end |
Class Method Details
.oids(*oids) ⇒ Object
Return a description of the given oids suitable for inclusion in an RFC4512-style schema description entry.
159 160 161 162 163 164 165 166 |
# File 'lib/treequel/schema.rb', line 159 def self::oids( *oids ) oids.flatten! if oids.length > 1 return "( %s )" % [ oids.join(" $ ") ] else return oids.first end end |
.parse_names(names) ⇒ Object
Parse the given short names string (a ‘qdescrs’ in the BNF) into an Array of zero or more Strings.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/treequel/schema.rb', line 98 def self::parse_names( names ) # Treequel.logger.debug " parsing NAME attribute from: %p" % [ names ] # Unspecified if names.nil? # Treequel.logger.debug " no NAME attribute" return [] # Multi-value elsif names =~ /#{LPAREN} #{WSP} (#{QDESCRLIST}) #{WSP} #{RPAREN}/x # Treequel.logger.debug " parsing a NAME list from %p" % [ $1 ] return $1.scan( QDESCR ).collect {|qd| qd[1..-2].untaint.to_sym } # Single-value else # Return the name without the quotes # Treequel.logger.debug " dequoting a single NAME" return [ names[1..-2].untaint.to_sym ] end end |
.parse_oid(oidstring) ⇒ Object
Parse a single OID into either a numeric OID string or a Symbol.
87 88 89 90 91 92 93 |
# File 'lib/treequel/schema.rb', line 87 def self::parse_oid( oidstring ) if oidstring =~ NUMERICOID return oidstring.untaint else return oidstring.untaint.to_sym end end |
.parse_oids(oidstring) ⇒ Object
Parse the given oidstring into an Array of OIDs, with Strings for numeric OIDs and Symbols for aliases.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/treequel/schema.rb', line 62 def self::parse_oids( oidstring ) return [] unless oidstring unless /^ #{OIDS} $/x.match( oidstring.strip ) raise Treequel::ParseError, "couldn't find an OIDLIST in %p" % [ oidstring ] end oids = $MATCH # Treequel.logger.debug " found OIDs: %p" % [ oids ] # If it's an OIDLIST, strip off leading and trailing parens and whitespace, then split # on ' $ ' and parse each OID if oids.include?( '$' ) parse_oid = self.method( :parse_oid ) return $MATCH[1..-2].strip.split( /#{WSP} #{DOLLAR} #{WSP}/x ).collect( &parse_oid ) else return [ self.parse_oid(oids) ] end end |
.qdescrs(*descriptors) ⇒ Object
Return a description of the given descriptors suitable for inclusion in an RFC4512-style schema description entry.
130 131 132 133 134 135 136 137 |
# File 'lib/treequel/schema.rb', line 130 def self::qdescrs( *descriptors ) descriptors.flatten! if descriptors.length > 1 return "( %s )" % [ descriptors.collect {|str| self.qdstring(str) }.join(" ") ] else return self.qdstring( descriptors.first ) end end |
.qdstring(string) ⇒ Object
Escape and quote the specified string according to the rules in RFC4512/2252.
152 153 154 |
# File 'lib/treequel/schema.rb', line 152 def self::qdstring( string ) return "'%s'" % [ string.to_s.gsub(/\\/, '\\\\5c').gsub(/'/, '\\\\27') ] end |
.strict_parse_mode=(newval) ⇒ Object
Set the strict-parsing flag. Setting this to a true value causes schema-parsing errors to be propagated to the caller instead of handled by the constructor, which is the default behavior.
49 50 51 |
# File 'lib/treequel/schema.rb', line 49 def self::strict_parse_mode=( newval ) @strict_parse_mode = newval ? true : false end |
.strict_parse_mode? ⇒ Boolean
Test whether or not strict-parsing mode is in effect.
55 56 57 |
# File 'lib/treequel/schema.rb', line 55 def self::strict_parse_mode? return @strict_parse_mode ? true : false end |
.unquote_desc(desc) ⇒ Object
Return a new string which is desc with quotes stripped and any escaped characters un-escaped.
122 123 124 125 |
# File 'lib/treequel/schema.rb', line 122 def self::unquote_desc( desc ) return nil if desc.nil? return desc.gsub( QQ, "'" ).gsub( QS, '\\' )[ 1..-2 ] end |
Instance Method Details
#inspect ⇒ Object
Return a human-readable representation of the object suitable for debugging.
229 230 231 232 233 234 235 |
# File 'lib/treequel/schema.rb', line 229 def inspect return %{#<%s:0x%0x %s>} % [ self.class.name, self.object_id / 2, self.ivar_descriptions.join( ', ' ), ] end |
#operational_attribute_types ⇒ Object
Return the Treequel::Schema::AttributeType objects that correspond to the operational attributes that are supported by the directory.
215 216 217 |
# File 'lib/treequel/schema.rb', line 215 def operational_attribute_types return self.attribute_types.values.find_all {|attrtype| attrtype.operational? }.uniq end |
#to_s ⇒ Object
Return the schema as a human-readable english string.
221 222 223 224 225 |
# File 'lib/treequel/schema.rb', line 221 def to_s parts = [ "Schema:" ] parts << self.ivar_descriptions.collect {|desc| ' ' + desc } return parts.join( $/ ) end |