treequel 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/ChangeLog +354 -0
  2. data/LICENSE +27 -0
  3. data/README +66 -0
  4. data/Rakefile +345 -0
  5. data/Rakefile.local +43 -0
  6. data/bin/treeirb +14 -0
  7. data/bin/treequel +229 -0
  8. data/examples/company-directory.rb +112 -0
  9. data/examples/ldap-monitor.rb +143 -0
  10. data/examples/ldap-monitor/public/css/master.css +328 -0
  11. data/examples/ldap-monitor/public/images/card_small.png +0 -0
  12. data/examples/ldap-monitor/public/images/chain_small.png +0 -0
  13. data/examples/ldap-monitor/public/images/globe_small.png +0 -0
  14. data/examples/ldap-monitor/public/images/globe_small_green.png +0 -0
  15. data/examples/ldap-monitor/public/images/plug.png +0 -0
  16. data/examples/ldap-monitor/public/images/shadows/large-30-down.png +0 -0
  17. data/examples/ldap-monitor/public/images/tick.png +0 -0
  18. data/examples/ldap-monitor/public/images/tick_circle.png +0 -0
  19. data/examples/ldap-monitor/public/images/treequel-favicon.png +0 -0
  20. data/examples/ldap-monitor/views/backends.erb +41 -0
  21. data/examples/ldap-monitor/views/connections.erb +74 -0
  22. data/examples/ldap-monitor/views/databases.erb +39 -0
  23. data/examples/ldap-monitor/views/dump_subsystem.erb +14 -0
  24. data/examples/ldap-monitor/views/index.erb +14 -0
  25. data/examples/ldap-monitor/views/layout.erb +35 -0
  26. data/examples/ldap-monitor/views/listeners.erb +30 -0
  27. data/examples/ldap_state.rb +62 -0
  28. data/lib/treequel.rb +145 -0
  29. data/lib/treequel/branch.rb +589 -0
  30. data/lib/treequel/branchcollection.rb +204 -0
  31. data/lib/treequel/branchset.rb +360 -0
  32. data/lib/treequel/constants.rb +604 -0
  33. data/lib/treequel/directory.rb +541 -0
  34. data/lib/treequel/exceptions.rb +32 -0
  35. data/lib/treequel/filter.rb +704 -0
  36. data/lib/treequel/mixins.rb +325 -0
  37. data/lib/treequel/schema.rb +245 -0
  38. data/lib/treequel/schema/attributetype.rb +252 -0
  39. data/lib/treequel/schema/ldapsyntax.rb +96 -0
  40. data/lib/treequel/schema/matchingrule.rb +124 -0
  41. data/lib/treequel/schema/matchingruleuse.rb +124 -0
  42. data/lib/treequel/schema/objectclass.rb +289 -0
  43. data/lib/treequel/sequel_integration.rb +26 -0
  44. data/lib/treequel/utils.rb +169 -0
  45. data/rake/191_compat.rb +26 -0
  46. data/rake/dependencies.rb +76 -0
  47. data/rake/helpers.rb +434 -0
  48. data/rake/hg.rb +261 -0
  49. data/rake/manual.rb +782 -0
  50. data/rake/packaging.rb +135 -0
  51. data/rake/publishing.rb +318 -0
  52. data/rake/rdoc.rb +30 -0
  53. data/rake/style.rb +62 -0
  54. data/rake/svn.rb +668 -0
  55. data/rake/testing.rb +187 -0
  56. data/rake/verifytask.rb +64 -0
  57. data/rake/win32.rb +190 -0
  58. data/spec/lib/constants.rb +93 -0
  59. data/spec/lib/helpers.rb +100 -0
  60. data/spec/treequel/branch_spec.rb +569 -0
  61. data/spec/treequel/branchcollection_spec.rb +213 -0
  62. data/spec/treequel/branchset_spec.rb +376 -0
  63. data/spec/treequel/directory_spec.rb +487 -0
  64. data/spec/treequel/filter_spec.rb +482 -0
  65. data/spec/treequel/mixins_spec.rb +330 -0
  66. data/spec/treequel/schema/attributetype_spec.rb +237 -0
  67. data/spec/treequel/schema/ldapsyntax_spec.rb +83 -0
  68. data/spec/treequel/schema/matchingrule_spec.rb +158 -0
  69. data/spec/treequel/schema/matchingruleuse_spec.rb +137 -0
  70. data/spec/treequel/schema/objectclass_spec.rb +262 -0
  71. data/spec/treequel/schema_spec.rb +118 -0
  72. data/spec/treequel/utils_spec.rb +49 -0
  73. data/spec/treequel_spec.rb +179 -0
  74. metadata +169 -0
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'English'
4
+
5
+ require 'treequel'
6
+ require 'treequel/mixins'
7
+ require 'treequel/schema'
8
+ require 'treequel/exceptions'
9
+
10
+
11
+ # This is a class for representing attributeType declarations in a Treequel::Schema.
12
+ #
13
+ # == Authors
14
+ #
15
+ # * Michael Granger <ged@FaerieMUD.org>
16
+ # * Mahlon E. Smith <mahlon@martini.nu>
17
+ #
18
+ # :include: LICENSE
19
+ #
20
+ #--
21
+ #
22
+ # Please see the file LICENSE in the base directory for licensing details.
23
+ #
24
+ class Treequel::Schema::AttributeType
25
+ include Treequel::Loggable,
26
+ Treequel::Constants::Patterns
27
+
28
+ extend Treequel::AttributeDeclarations
29
+
30
+
31
+ #############################################################
32
+ ### C L A S S M E T H O D S
33
+ #############################################################
34
+
35
+ ### Parse an AttributeType entry from a attributeType description from a schema.
36
+ def self::parse( schema, description )
37
+ unless match = ( LDAP_ATTRIBUTE_TYPE_DESCRIPTION.match(description) )
38
+ raise Treequel::ParseError, "failed to parse attributeType from %p" % [ description ]
39
+ end
40
+
41
+ oid, names, desc, obsolete, sup_oid, eqmatch_oid, ordmatch_oid, submatch_oid, syntax_oid,
42
+ single, collective, nousermod, usagetype, extensions = match.captures
43
+
44
+ # Normalize the attributes
45
+ names = Treequel::Schema.parse_names( names )
46
+ desc = Treequel::Schema.unquote_desc( desc )
47
+
48
+ sup_oid = Treequel::Schema.parse_oid( sup_oid ) if sup_oid
49
+ eqmatch_oid = Treequel::Schema.parse_oid( eqmatch_oid ) if eqmatch_oid
50
+ ordmatch_oid = Treequel::Schema.parse_oid( ordmatch_oid ) if ordmatch_oid
51
+ submatch_oid = Treequel::Schema.parse_oid( submatch_oid ) if submatch_oid
52
+
53
+ return self.new( schema, oid,
54
+ :names => names,
55
+ :desc => desc,
56
+ :obsolete => obsolete,
57
+ :sup_oid => sup_oid,
58
+ :eqmatch_oid => eqmatch_oid,
59
+ :ordmatch_oid => ordmatch_oid,
60
+ :submatch_oid => submatch_oid,
61
+ :syntax_oid => syntax_oid,
62
+ :single => single,
63
+ :collective => collective,
64
+ :user_modifiable => nousermod ? false : true,
65
+ :usagetype => usagetype,
66
+ :extensions => extensions
67
+ )
68
+ end
69
+
70
+
71
+ #############################################################
72
+ ### I N S T A N C E M E T H O D S
73
+ #############################################################
74
+
75
+ ### Create a new AttributeType
76
+ def initialize( schema, oid, attributes )
77
+
78
+ @schema = schema
79
+
80
+ @oid = oid
81
+ @names = attributes[:names]
82
+ @desc = attributes[:desc]
83
+ @obsolete = attributes[:obsolete] ? true : false
84
+ @sup_oid = attributes[:sup_oid]
85
+ @eqmatch_oid = attributes[:eqmatch_oid]
86
+ @ordmatch_oid = attributes[:ordmatch_oid]
87
+ @submatch_oid = attributes[:submatch_oid]
88
+ @single = attributes[:single] ? true : false
89
+ @collective = attributes[:collective] ? true : false
90
+ @user_modifiable = attributes[:user_modifiable] ? true : false
91
+ @usagetype = attributes[:usagetype]
92
+ @extensions = attributes[:extensions]
93
+
94
+ @syntax_oid, @syntax_len = self.split_syntax_oid( attributes[:syntax_oid] ) if
95
+ attributes[:syntax_oid]
96
+
97
+ super()
98
+ end
99
+
100
+
101
+ ######
102
+ public
103
+ ######
104
+
105
+ # The schema the attributeType belongs to
106
+ attr_reader :schema
107
+
108
+ # The attributeType's oid
109
+ attr_reader :oid
110
+
111
+ # The Array of the attributeType's names
112
+ attr_reader :names
113
+
114
+ # The attributeType's description
115
+ attr_accessor :desc
116
+
117
+ # Is the attributeType obsolete?
118
+ predicate_attr :obsolete
119
+
120
+ # The attributeType's superior class's OID
121
+ attr_accessor :sup_oid
122
+
123
+ # The oid of the attributeType's equality matching rule
124
+ attr_accessor :eqmatch_oid
125
+
126
+ # The oid of the attributeType's order matching rule
127
+ attr_accessor :ordmatch_oid
128
+
129
+ # The oid of the attributeType's substring matching rule
130
+ attr_accessor :submatch_oid
131
+
132
+ # The oid of the attributeType's value syntax
133
+ attr_accessor :syntax_oid
134
+
135
+ # The (optional) syntax length qualifier (nil if not present)
136
+ attr_accessor :syntax_len
137
+
138
+ # Are attributes of this type restricted to a single value?
139
+ predicate_attr :single
140
+
141
+ # Are attributes of this type collective?
142
+ predicate_attr :collective
143
+
144
+ # Are attributes of this type user-modifiable?
145
+ predicate_attr :user_modifiable
146
+
147
+ # The application of this attributeType
148
+ attr_accessor :usagetype
149
+
150
+ # The attributeType's extensions (as a String)
151
+ attr_accessor :extensions
152
+
153
+
154
+ ### Return the first of the attributeType's names, if it has any, or +nil+.
155
+ def name
156
+ return self.names.first
157
+ end
158
+
159
+
160
+ ### Return the Treequel::Schema::AttributeType instance that corresponds to
161
+ ### the receiver's superior type. If the attributeType doesn't have a SUP
162
+ ### attribute, this method returns +nil+.
163
+ def sup
164
+ return nil unless oid = self.sup_oid
165
+ return self.schema.attribute_types[ oid ]
166
+ end
167
+
168
+
169
+ ### Return a human-readable representation of the object suitable for debugging
170
+ def inspect
171
+ return "#<%s:0x%0x %s(%s) %p %sSYNTAX: %p (length: %s)>" % [
172
+ self.class.name,
173
+ self.object_id / 2,
174
+ self.name,
175
+ self.oid,
176
+ self.desc,
177
+ self.is_single? ? '(SINGLE) ' : '',
178
+ self.syntax_oid,
179
+ self.syntax_len ? self.syntax_len : 'unlimited',
180
+ ]
181
+ end
182
+
183
+
184
+ ### Return the Treequel::Schema::MatchingRule that corresponds to the EQUALITY
185
+ ### matchingRule of the receiving attributeType.
186
+ def equality_matching_rule
187
+ if oid = self.eqmatch_oid
188
+ return self.schema.matching_rules[ oid ]
189
+ elsif self.sup
190
+ return self.sup.equality_matching_rule
191
+ else
192
+ return nil
193
+ end
194
+ end
195
+
196
+
197
+ ### Return the Treequel::Schema::MatchingRule that corresponds to the ORDERING
198
+ ### matchingRule of the receiving attributeType.
199
+ def ordering_matching_rule
200
+ if oid = self.ordmatch_oid
201
+ return self.schema.matching_rules[ oid ]
202
+ elsif self.sup
203
+ return self.sup.ordering_matching_rule
204
+ else
205
+ return nil
206
+ end
207
+ end
208
+
209
+
210
+ ### Return the Treequel::Schema::MatchingRule that corresponds to the SUBSTR
211
+ ### matchingRule of the receiving attributeType.
212
+ def substr_matching_rule
213
+ if oid = self.submatch_oid
214
+ return self.schema.matching_rules[ oid ]
215
+ elsif self.sup
216
+ return self.sup.substr_matching_rule
217
+ else
218
+ return nil
219
+ end
220
+ end
221
+
222
+
223
+ ### Return the Treequel::Schema::LDAPSyntax that corresponds to the receiver's SYNTAX attribute.
224
+ def syntax
225
+ if oid = self.syntax_oid
226
+ return self.schema.ldap_syntaxes[ oid ]
227
+ elsif self.sup
228
+ return self.sup.syntax
229
+ else
230
+ return nil
231
+ end
232
+ end
233
+
234
+
235
+ #########
236
+ protected
237
+ #########
238
+
239
+ ### Split a numeric OID with an optional length qualifier into a numeric OID and length. If
240
+ ### no length qualifier is present, it will be nil.
241
+ def split_syntax_oid( noidlen )
242
+ unless noidlen =~ /^(#{NUMERICOID}) (?:#{LCURLY} (#{LEN}) #{RCURLY})?$/x
243
+ raise Treequel::ParseError, "invalid numeric syntax OID with length: %p" % [ noidlen ]
244
+ end
245
+
246
+ oid, len = $1, $2
247
+
248
+ return oid, len ? Integer(len) : nil
249
+ end
250
+
251
+ end # class Treequel::Schema::AttributeType
252
+
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'English'
4
+
5
+ require 'treequel'
6
+ require 'treequel/mixins'
7
+ require 'treequel/schema'
8
+ require 'treequel/exceptions'
9
+
10
+
11
+ # This is a class for representing ldapSyntax declarations in a Treequel::Schema.
12
+ #
13
+ # == Authors
14
+ #
15
+ # * Michael Granger <ged@FaerieMUD.org>
16
+ #
17
+ # :include: LICENSE
18
+ #
19
+ #--
20
+ #
21
+ # Please see the file LICENSE in the base directory for licensing details.
22
+ #
23
+ class Treequel::Schema::LDAPSyntax
24
+ include Treequel::Loggable,
25
+ Treequel::Constants::Patterns
26
+
27
+ extend Treequel::AttributeDeclarations
28
+
29
+
30
+ #############################################################
31
+ ### C L A S S M E T H O D S
32
+ #############################################################
33
+
34
+ ### Parse an LDAPSyntax entry from an ldapSyntax description from a schema.
35
+ def self::parse( schema, description )
36
+ unless match = ( LDAP_SYNTAX_DESCRIPTION.match(description) )
37
+ raise Treequel::ParseError, "failed to parse syntax from %p" % [ description ]
38
+ end
39
+
40
+ oid, desc, extensions = match.captures
41
+ # Treequel.logger.debug " parsed syntax: %p" % [ match.captures ]
42
+
43
+ # Normalize the attributes
44
+ desc = Treequel::Schema.unquote_desc( desc )
45
+
46
+ return self.new( schema, oid, desc, extensions )
47
+ end
48
+
49
+
50
+ #############################################################
51
+ ### I N S T A N C E M E T H O D S
52
+ #############################################################
53
+
54
+ ### Create a new LDAPSyntax
55
+ def initialize( schema, oid, desc=nil, extensions=nil )
56
+
57
+ @schema = schema
58
+
59
+ @oid = oid
60
+ @desc = desc
61
+ @extensions = extensions
62
+
63
+ super()
64
+ end
65
+
66
+
67
+ ######
68
+ public
69
+ ######
70
+
71
+ # The schema the syntax belongs to
72
+ attr_reader :schema
73
+
74
+ # The syntax's oid
75
+ attr_reader :oid
76
+
77
+ # The syntax's description
78
+ attr_accessor :desc
79
+
80
+ # The syntax's extensions (as a String)
81
+ attr_accessor :extensions
82
+
83
+
84
+ ### Return a human-readable representation of the object suitable for debugging
85
+ def inspect
86
+ return "#<%s:0x%0x %s(%s)>" % [
87
+ self.class.name,
88
+ self.object_id / 2,
89
+ self.oid,
90
+ self.desc,
91
+ ]
92
+ end
93
+
94
+
95
+ end # class Treequel::Schema::LDAPSyntax
96
+
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'English'
4
+
5
+ require 'treequel'
6
+ require 'treequel/mixins'
7
+ require 'treequel/schema'
8
+ require 'treequel/exceptions'
9
+
10
+
11
+ # This is a class for representing matchingRule declarations in a Treequel::Schema.
12
+ #
13
+ # == Authors
14
+ #
15
+ # * Michael Granger <ged@FaerieMUD.org>
16
+ #
17
+ # :include: LICENSE
18
+ #
19
+ #--
20
+ #
21
+ # Please see the file LICENSE in the base directory for licensing details.
22
+ #
23
+ class Treequel::Schema::MatchingRule
24
+ include Treequel::Loggable,
25
+ Treequel::Constants::Patterns
26
+
27
+ extend Treequel::AttributeDeclarations
28
+
29
+
30
+ #############################################################
31
+ ### C L A S S M E T H O D S
32
+ #############################################################
33
+
34
+ ### Parse an MatchingRule entry from a matchingRule description from a schema.
35
+ def self::parse( schema, description )
36
+ unless match = ( LDAP_MATCHING_RULE_DESCRIPTION.match(description) )
37
+ raise Treequel::ParseError, "failed to parse matchingRule from %p" % [ description ]
38
+ end
39
+
40
+ oid, names, desc, obsolete, syntax_oid, extensions = match.captures
41
+ # Treequel.logger.debug " parsed matchingRule: %p" % [ match.captures ]
42
+
43
+ # Normalize the attributes
44
+ names = Treequel::Schema.parse_names( names )
45
+ desc = Treequel::Schema.unquote_desc( desc )
46
+
47
+ return self.new( schema, oid, syntax_oid, names, desc, obsolete, extensions )
48
+ end
49
+
50
+
51
+ #############################################################
52
+ ### I N S T A N C E M E T H O D S
53
+ #############################################################
54
+
55
+ ### Create a new MatchingRule
56
+ def initialize( schema, oid, syntax_oid, names=nil, desc=nil, obsolete=false, extensions=nil )
57
+
58
+ @schema = schema
59
+
60
+ @oid = oid
61
+ @syntax_oid = syntax_oid
62
+ @names = names
63
+ @desc = desc
64
+ @obsolete = obsolete ? true : false
65
+ @extensions = extensions
66
+
67
+ super()
68
+ end
69
+
70
+
71
+ ######
72
+ public
73
+ ######
74
+
75
+ # The schema the matchingRule belongs to
76
+ attr_reader :schema
77
+
78
+ # The matchingRule's oid
79
+ attr_reader :oid
80
+
81
+ # The oid of the matchingRule's SYNTAX
82
+ attr_accessor :syntax_oid
83
+
84
+ # The Array of the matchingRule's names
85
+ attr_reader :names
86
+
87
+ # The matchingRule's description
88
+ attr_accessor :desc
89
+
90
+ # Is the matchingRule obsolete?
91
+ predicate_attr :obsolete
92
+
93
+ # The matchingRule's extensions (as a String)
94
+ attr_accessor :extensions
95
+
96
+
97
+ ### Return the first of the matchingRule's names, if it has any, or +nil+.
98
+ def name
99
+ return self.names.first
100
+ end
101
+
102
+
103
+ ### Return a human-readable representation of the object suitable for debugging
104
+ def inspect
105
+ return "#<%s:0x%0x %s(%s) %s %sSYNTAX: %p>" % [
106
+ self.class.name,
107
+ self.object_id / 2,
108
+ self.name,
109
+ self.oid,
110
+ self.desc,
111
+ self.obsolete? ? "(OBSOLETE)" : '',
112
+ self.syntax,
113
+ ]
114
+ end
115
+
116
+
117
+ ### Return the Treequel::Schema::LDAPSyntax object that corresponds to the matchingRule's
118
+ ### SYNTAX attribute.
119
+ def syntax
120
+ return self.schema.ldap_syntaxes[ self.syntax_oid ]
121
+ end
122
+
123
+ end # class Treequel::Schema::MatchingRule
124
+