This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ls.go
1080 lines (890 loc) · 24.8 KB
/
ls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package schemax
/*
NewLDAPSyntaxes initializes a new [LDAPSyntaxes] instance.
*/
func NewLDAPSyntaxes() LDAPSyntaxes {
r := LDAPSyntaxes(newCollection(`ldapSyntaxes`))
r.cast().SetPushPolicy(r.canPush)
return r
}
/*
E returns the underlying error instance.
*/
func (r LDAPSyntax) E() (err error) {
if !r.IsZero() {
err = r.lDAPSyntax.err
} else {
err = ErrNilReceiver
}
return
}
/*
Identifier returns the first available instance identifier, which will
either be the DESC clause (output of [LDAPSyntax.Description]) or the
numeric OID (output of [LDAPSyntax.NumericOID]).
*/
func (r LDAPSyntax) Identifier() (ident string) {
if ident = r.Description(); len(ident) == 0 {
ident = r.NumericOID()
}
return
}
/*
IsIdentifiedAs returns a Boolean value indicative of whether id matches
either the numericOID or description of the receiver instance. Case is
not significant in the matching process.
*/
func (r LDAPSyntax) IsIdentifiedAs(id string) (ident bool) {
if !r.IsZero() {
ident = id == r.NumericOID() || eq(r.lDAPSyntax.Desc, id)
}
return
}
/*
Inventory returns an instance of [Inventory] which represents the current
inventory of [LDAPSyntaxes] instances within the receiver.
The keys are numeric OIDs, while the values are zero (0) or more string
slices, each representing a name by which the definition is known.
*/
func (r LDAPSyntaxes) Inventory() (inv Inventory) {
inv = make(Inventory, 0)
for i := 0; i < r.len(); i++ {
def := r.index(i)
inv[def.NumericOID()] = []string{def.Description()}
}
return
}
/*
Len returns the current integer length of the receiver instance.
*/
func (r LDAPSyntaxes) Len() int {
return r.len()
}
func (r LDAPSyntaxes) len() int {
return r.cast().Len()
}
/*
Contains calls [MatchingRules.Get] to return a Boolean value indicative of
a successful, non-zero retrieval of a [MatchingRule] instance -- matching
the provided id -- from within the receiver stack instance.
*/
func (r LDAPSyntaxes) Contains(id string) bool {
return r.contains(id)
}
func (r LDAPSyntaxes) contains(id string) bool {
return !r.get(id).IsZero()
}
/*
Marshal returns an error following an attempt to marshal the contents of
def, which may be either a [DefinitionMap] or map[string]any instance.
The receiver instance must be initialized prior to use of this method
using the [Schema.NewLDAPSyntax] method.
*/
func (r LDAPSyntax) Marshal(def any) error {
m, err := getMarshalMap(r, def)
if err != nil {
return err
}
for k, v := range m {
switch key := uc(k); key {
case `DESC`:
switch tv := v.(type) {
case string:
r.SetDescription(tv)
case []string:
r.SetDescription(tv[0])
}
case `NUMERICOID`:
switch tv := v.(type) {
case string:
r.SetNumericOID(tv)
case []string:
r.SetNumericOID(tv[0])
}
default:
if hasPfx(key, `X-`) {
switch tv := v.(type) {
case string:
r.SetExtension(key, tv)
case []string:
r.SetExtension(key, tv...)
}
}
}
}
if !r.Compliant() {
return ErrDefNonCompliant
}
r.SetStringer()
return nil
}
/*
SetData assigns x to the receiver instance. This is a general-use method and has no
specific intent beyond convenience. The contents may be subsequently accessed via the
[LDAPSyntax.Data] method.
This is a fluent method.
*/
func (r LDAPSyntax) SetData(x any) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setData(x)
}
return r
}
func (r *lDAPSyntax) setData(x any) {
r.data = x
}
/*
Data returns the underlying value (x) assigned to the receiver's data storage field. Data
can be set within the receiver instance by way of the [LDAPSyntax.SetData] method.
*/
func (r LDAPSyntax) Data() (x any) {
if !r.IsZero() {
x = r.lDAPSyntax.data
}
return
}
/*
SetSchema assigns an instance of [Schema] to the receiver instance. This allows
internal verification of certain actions without the need for user input of
an instance of [Schema] manually at each juncture.
Note that the underlying [Schema] instance is automatically set when creating
instances of this type by way of parsing, as well as if the receiver instance
was initialized using the [Schema.NewLDAPSyntax] method.
This is a fluent method.
*/
func (r LDAPSyntax) SetSchema(schema Schema) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setSchema(schema)
}
return r
}
func (r *lDAPSyntax) setSchema(schema Schema) *lDAPSyntax {
r.schema = schema
return r
}
/*
Schema returns the [Schema] instance associated with the receiver instance.
*/
func (r LDAPSyntax) Schema() (s Schema) {
if !r.IsZero() {
s = r.lDAPSyntax.getSchema()
}
return
}
func (r *lDAPSyntax) getSchema() (s Schema) {
if r != nil {
s = r.schema
}
return
}
/*
Compliant returns a Boolean value indicative of every [LDAPSyntax]
returning a compliant response from the [LDAPSyntax.Compliant] method.
*/
func (r LDAPSyntaxes) Compliant() bool {
var act int
for i := 0; i < r.Len(); i++ {
if r.Index(i).Compliant() {
act++
}
}
return act == r.Len()
}
/*
Compliant returns a Boolean value indicative of the receiver being fully
compliant per the required clauses of [§ 4.1.5 of RFC 4512]:
- Instance must not be nil
- Numeric OID must be present and valid
Successful returns result in the annihilation of the underlying error
instance.
[§ 4.1.5 of RFC 4512]: https://rfc-editor.org/rfc/rfc4512.html#section-4.1.5
*/
func (r LDAPSyntax) Compliant() bool {
if r.IsZero() {
return false
}
ok := isNumericOID(r.lDAPSyntax.OID)
if ok {
r.lDAPSyntax.err = nil
}
return ok
}
/*
SetStringer allows the assignment of an individual [Stringer] function or
method to all [LDAPSyntax] slices within the receiver stack instance.
Input of zero (0) variadic values, or an explicit nil, will overwrite all
preexisting stringer functions with the internal closure default, which is
based upon a one-time use of the [text/template] package by all receiver
slice instances.
Input of a non-nil closure function value will overwrite all preexisting
stringers.
This is a fluent method and may be used multiple times.
*/
func (r LDAPSyntaxes) SetStringer(function ...Stringer) LDAPSyntaxes {
for i := 0; i < r.Len(); i++ {
def := r.Index(i)
def.SetStringer(function...)
}
return r
}
/*
SetStringer allows the assignment of an individual [Stringer] function
or method to the receiver instance.
Input of zero (0) variadic values, or an explicit nil, will overwrite any
preexisting stringer function with the internal closure default, which is
based upon a one-time use of the [text/template] package by the receiver
instance.
Input of a non-nil closure function value will overwrite any preexisting
stringer.
This is a fluent method and may be used multiple times.
*/
func (r LDAPSyntax) SetStringer(function ...Stringer) LDAPSyntax {
if r.Compliant() {
r.lDAPSyntax.setStringer(function...)
}
return r
}
func (r *lDAPSyntax) setStringer(function ...Stringer) {
var stringer Stringer
if len(function) > 0 {
stringer = function[0]
}
if stringer == nil {
// no user provided closure means we
// defer to a general use stringer.
str, err := r.prepareString() // perform one-time text/template op
if err == nil {
// Save the stringer
r.stringer = func() string {
// Return a preserved value.
return str
}
} else {
r.err = err
}
return
}
// assign user-provided closure
r.stringer = stringer
}
/*
XOrigin returns an instance of [LDAPSyntaxes] containing only definitions
which bear the X-ORIGIN value of x. Case is not significant in the matching
process, nor is whitespace (e.g.: RFC 4517 vs. RFC4517).
*/
func (r LDAPSyntaxes) XOrigin(x string) (defs LDAPSyntaxes) {
defs = NewLDAPSyntaxes()
for i := 0; i < r.Len(); i++ {
def := r.Index(i)
if xo, found := def.Extensions().Get(`X-ORIGIN`); found {
if xo.Contains(x) {
defs.push(def)
}
}
}
return
}
/*
HumanReadable returns a Boolean value indicative of whether the receiver
is considered a HUMAN-READABLE (HR) syntax.
To that end, the determination is made based on the presence of the
'X-NOT-HUMAN-READABLE' [Extension] bearing a value of 'TRUE'. In this
state, a value of false is returned, indicating the [LDAPSyntax] is NOT
considered HUMAN-READABLE. A value of false is also returned if the
receiver is nil.
All other states return true.
*/
func (r LDAPSyntax) HumanReadable() bool {
if r.IsZero() {
return false
}
ext, _ := r.Extensions().Get(`X-NOT-HUMAN-READABLE`)
if ext.IsZero() {
return true
}
return !ext.Contains(`TRUE`) // invert evaluation
}
/*
String is a stringer method that returns the string representation
of the receiver instance.
*/
func (r LDAPSyntax) String() (def string) {
if !r.IsZero() {
if r.lDAPSyntax.stringer != nil {
def = r.lDAPSyntax.stringer()
}
}
return
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r LDAPSyntax) IsZero() bool {
return r.lDAPSyntax == nil
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r LDAPSyntaxes) IsZero() bool {
return r.cast().IsZero()
}
/*
OID is an alias for the [LDAPSyntax.NumericOID] method, as
[LDAPSyntax] instances do not allow for the assignment of
names. This method exists solely to satisfy Go's interface
signature requirements.
*/
func (r LDAPSyntax) OID() string { return r.NumericOID() }
/*
Name returns an empty string, as [LDAPSyntax] definitions do not
bear names. This method exists only to satisfy Go's interface
signature requirements.
*/
func (r LDAPSyntax) Name() string { return `` }
/*
Names returns an empty instance of [QuotedDescriptorList], as names do not
apply to [LDAPSyntax] definitions. This method exists only to satisfy
Go's interface signature requirements.
*/
func (r LDAPSyntax) Names() QuotedDescriptorList { return QuotedDescriptorList{} }
/*
String returns the string representation of the receiver instance.
*/
func (r LDAPSyntaxes) String() string {
return r.cast().String()
}
func (r LDAPSyntax) macro() (m []string) {
if !r.IsZero() {
m = r.lDAPSyntax.Macro
}
return
}
func (r LDAPSyntax) setOID(x string) {
if !r.IsZero() {
r.lDAPSyntax.OID = x
}
}
func (r LDAPSyntaxes) canPush(x ...any) (err error) {
if len(x) == 0 {
return
}
for i := 0; i < len(x) && err == nil; i++ {
instance := x[i]
if ls, ok := instance.(LDAPSyntax); !ok || ls.IsZero() {
err = ErrTypeAssert
} else if tst := r.get(ls.NumericOID()); !tst.IsZero() {
err = mkerr(ErrNotUnique.Error() + ": " + ls.Type() + `, ` + ls.NumericOID())
}
}
return
}
/*
SetNumericOID allows the manual assignment of a numeric OID to the
receiver instance if the following are all true:
- The input id value is a syntactically valid numeric OID
- The receiver does not already possess a numeric OID
This is a fluent method.
*/
func (r LDAPSyntax) SetNumericOID(id string) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setNumericOID(id)
}
return r
}
func (r *lDAPSyntax) setNumericOID(id string) {
if isNumericOID(id) {
// only set an OID when the receiver
// lacks one (iow: no modifications)
if len(r.OID) == 0 {
r.OID = id
}
} else {
r.err = ErrInvalidOID
}
return
}
/*
Extensions returns the [Extensions] instance -- if set -- within
the receiver.
*/
func (r LDAPSyntax) Extensions() (e Extensions) {
if !r.IsZero() {
e = r.lDAPSyntax.Extensions
}
return
}
/*
SetExtension assigns key x to value xstrs within the receiver's underlying
[Extensions] instance.
This is a fluent method.
*/
func (r LDAPSyntax) SetExtension(x string, xstrs ...string) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setExtension(x, xstrs...)
}
return r
}
func (r *lDAPSyntax) setExtension(x string, xstrs ...string) {
r.Extensions.Set(x, xstrs...)
}
/*
Maps returns slices of [DefinitionMap] instances.
*/
func (r LDAPSyntaxes) Maps() (defs DefinitionMaps) {
defs = make(DefinitionMaps, r.Len())
for i := 0; i < r.Len(); i++ {
defs[i] = r.Index(i).Map()
}
return
}
/*
Map marshals the receiver instance into an instance of
[DefinitionMap].
*/
func (r LDAPSyntax) Map() (def DefinitionMap) {
if r.IsZero() {
return
}
def = make(DefinitionMap, 0)
def[`NUMERICOID`] = []string{r.NumericOID()}
def[`DESC`] = []string{r.Description()}
def[`TYPE`] = []string{r.Type()}
def[`HR`] = []string{bool2str(r.HumanReadable())}
def[`RAW`] = []string{r.String()}
// copy our extensions from receiver r
// into destination def.
def = mapTransferExtensions(r, def)
// Clean up any empty fields
def.clean()
return
}
/*
Type returns the string literal "ldapSyntax".
*/
func (r LDAPSyntax) Type() string {
return `ldapSyntax`
}
/*
Type returns the string literal "ldapSyntaxes".
*/
func (r LDAPSyntaxes) Type() string {
return `ldapSyntaxes`
}
/*
Description returns the underlying (optional) descriptive text
assigned to the receiver instance.
*/
func (r LDAPSyntax) Description() (desc string) {
if !r.IsZero() {
desc = r.lDAPSyntax.Desc
}
return
}
/*
SetDescription parses desc into the underlying DESC clause within the
receiver instance. Although a RFC 4512-compliant QuotedString is
required, the outer single-quotes need not be specified literally.
This is a fluent method.
*/
func (r LDAPSyntax) SetDescription(desc string) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setDescription(desc)
}
return r
}
func (r *lDAPSyntax) setDescription(desc string) {
if len(desc) < 3 {
return
}
if rune(desc[0]) == rune(39) {
desc = desc[1:]
}
if rune(desc[len(desc)-1]) == rune(39) {
desc = desc[:len(desc)-1]
}
r.Desc = desc
return
}
/*
Obsolete only returns a false Boolean value, as definition obsolescence
does not apply to [LDAPSyntax] definitions. This method exists only to
satisfy Go's interface signature requirements.
*/
func (r LDAPSyntax) Obsolete() bool { return false }
/*
Get returns an instance of [LDAPSyntax] based upon a search for id within
the receiver stack instance.
The return instance, if not nil, was retrieved based upon a textual match of
either of the following:
- the numeric OID of an [LDAPSyntax] and the provided id
- the description text -- minus whitespace -- and the provided id
The return instance is nil if no match was made.
Case is not significant in the matching process.
*/
func (r LDAPSyntaxes) Get(id string) LDAPSyntax {
return r.get(id)
}
func (r LDAPSyntaxes) get(id string) (ls LDAPSyntax) {
for i := 0; i < r.len() && ls.IsZero(); i++ {
if _ls := r.index(i); !_ls.IsZero() {
if eq(_ls.lDAPSyntax.OID, id) {
ls = _ls
} else {
if desc := repAll(_ls.lDAPSyntax.Desc, ` `, ``); eq(desc, id) {
ls = _ls
}
}
}
}
return
}
/*
NumericOID returns the string representation of the numeric OID
held by the receiver instance.
*/
func (r LDAPSyntax) NumericOID() (noid string) {
if !r.IsZero() {
noid = r.lDAPSyntax.OID
}
return
}
/*
Index returns the instance of [LDAPSyntax] found within the
receiver stack instance at index N. If no instance is found at
the index specified, a zero [LDAPSyntax] instance is returned.
*/
func (r LDAPSyntaxes) Index(idx int) LDAPSyntax {
return r.index(idx)
}
func (r LDAPSyntaxes) index(idx int) (ls LDAPSyntax) {
slice, found := r.cast().Index(idx)
if found {
if _ls, ok := slice.(LDAPSyntax); ok {
ls = _ls
}
}
return
}
/*
Push returns an error following an attempt to push an [LDAPSyntax]
into the receiver stack instance.
*/
func (r LDAPSyntaxes) Push(ls any) error {
return r.push(ls)
}
func (r LDAPSyntaxes) push(x any) (err error) {
switch tv := x.(type) {
case LDAPSyntax:
if !tv.Compliant() {
err = ErrDefNonCompliant
break
}
r.cast().Push(tv)
default:
err = ErrInvalidType
}
return
}
/*
Parse returns an error following an attempt to parse raw into the receiver
instance.
Note that the receiver MUST possess a [Schema] reference prior to the execution
of this method.
Also note that successful execution of this method does NOT automatically push
the receiver into any [LDAPSyntaxes] stack, nor does it automatically execute
the [LDAPSyntax.SetStringer] method, leaving these tasks to the user. If the
automatic handling of these tasks is desired, see the [Schema.ParseLDAPSyntax]
method as an alternative.
*/
func (r LDAPSyntax) Parse(raw string) (err error) {
if r.IsZero() {
err = ErrNilReceiver
return
}
if r.getSchema().IsZero() {
err = ErrNilSchemaRef
return
}
err = r.lDAPSyntax.parse(raw)
return
}
func (r *lDAPSyntax) parse(raw string) error {
// parseLS wraps the antlr4512 LDAPSyntax parser/lexer
mp, err := parseLS(raw)
if err == nil {
// We received the parsed data from ANTLR (mp).
// Now we need to marshal it into the receiver.
var def LDAPSyntax
if def, err = r.schema.marshalLS(mp); err == nil {
r.OID = def.NumericOID()
_r := LDAPSyntax{r}
_r.replace(def)
}
}
return err
}
/*
NewLDAPSyntax initializes and returns a new instance of [LDAPSyntax],
ready for manual assembly. This method need not be used when creating
new [LDAPSyntax] instances by way of parsing, as that is handled on an
internal basis.
Use of this method does NOT automatically push the return instance into
the [Schema.LDAPSyntaxes] stack; this is left to the user.
Unlike the package-level [NewLDAPSyntax] function, this method will
automatically reference its originating [Schema] instance (the receiver).
This negates the need for manual use of the [LDAPSyntax.SetSchema]
method.
This is the recommended means of creating a new [LDAPSyntax] instance
wherever a single [Schema] is being used, which represents most use cases.
*/
func (r Schema) NewLDAPSyntax() LDAPSyntax {
return NewLDAPSyntax().SetSchema(r)
}
/*
NewLDAPSyntax initializes and returns a new instance of [LDAPSyntax],
ready for manual assembly. This method need not be used when creating
new [LDAPSyntax] instances by way of parsing, as that is handled on an
internal basis.
Use of this function does not automatically reference the "parent" [Schema]
instance, leaving it up to the user to invoke the [LDAPSyntax.SetSchema]
method manually.
When interacting with a single [Schema] instance, which represents most use
cases, use of the [Schema.NewLDAPSyntax] method is PREFERRED over use of
this package-level function.
However certain migration efforts, schema audits and other such activities
may require distinct associations of [LDAPSyntax] instances with specific
[Schema] instances. Use of this function allows the user to specify the
appropriate [Schema] instance at a later point for a specific instance of
an [LDAPSyntax] instance.
*/
func NewLDAPSyntax() LDAPSyntax {
ls := LDAPSyntax{newLDAPSyntax()}
ls.lDAPSyntax.Extensions.setDefinition(ls)
return ls
}
func newLDAPSyntax() *lDAPSyntax {
return &lDAPSyntax{
Extensions: NewExtensions(),
}
}
/*
Replace overrides the receiver with x. Both must bear an identical
numeric OID and x MUST be compliant.
Note that the relevant [Schema] instance must be configured to allow
definition override by way of the [AllowOverride] bit setting. See
the [Schema.Options] method for a means of accessing the settings
value.
Note that this method does not reallocate a new pointer instance
within the [LDAPSyntax] envelope type, thus all references to the
receiver instance within various stacks will be preserved.
This is a fluent method.
*/
func (r LDAPSyntax) Replace(x LDAPSyntax) LDAPSyntax {
if !r.Schema().Options().Positive(AllowOverride) {
return r
}
if !r.IsZero() && x.Compliant() {
r.lDAPSyntax.replace(x)
}
return r
}
func (r *lDAPSyntax) replace(x LDAPSyntax) {
if r.OID == `` {
r.err = ErrMissingNumericOID
return
} else if r.OID != x.NumericOID() {
r.err = ErrInvalidOID
return
}
r.OID = x.lDAPSyntax.OID
r.Desc = x.lDAPSyntax.Desc
r.Extensions = x.lDAPSyntax.Extensions
r.data = x.lDAPSyntax.data
r.schema = x.lDAPSyntax.schema
r.stringer = x.lDAPSyntax.stringer
r.synQual = x.lDAPSyntax.synQual
r.data = x.lDAPSyntax.data
}
/*
prepareString returns a string an an error indicative of an attempt
to represent the receiver instance as a string using [text/template].
*/
func (r *lDAPSyntax) prepareString() (str string, err error) {
buf := newBuf()
t := newTemplate(`ldapSyntax`).
Funcs(funcMap(map[string]any{
`ExtensionSet`: r.Extensions.tmplFunc,
}))
if t, err = t.Parse(lDAPSyntaxTmpl); err == nil {
if err = t.Execute(buf, struct {
Definition *lDAPSyntax
HIndent string
}{
Definition: r,
HIndent: hindent(r.schema.Options().Positive(HangingIndents)),
}); err == nil {
str = buf.String()
}
}
if err != nil {
r.err = err
}
return
}
/*
LDAPSyntaxes returns the [LDAPSyntaxes] instance from within the
receiver instance.
*/
func (r Schema) LDAPSyntaxes() (lss LDAPSyntaxes) {
slice, _ := r.cast().Index(ldapSyntaxesIndex)
lss, _ = slice.(LDAPSyntaxes)
return
}
/*
SetSyntaxQualifier assigns an instance of [SyntaxQualifier] to the receiver
instance. A nil value may be passed to disable syntax checking capabilities.
See the [LDAPSyntax.QualifySyntax] method for details on making active use
of the [SyntaxQualifier] capabilities.
This is a fluent method.
*/
func (r LDAPSyntax) SetSyntaxQualifier(function SyntaxQualifier) LDAPSyntax {
if !r.IsZero() {
r.lDAPSyntax.setSyntaxQualifier(function)
}
return r
}
func (r *lDAPSyntax) setSyntaxQualifier(function SyntaxQualifier) {
r.synQual = function
}
/*
QualifySyntax returns an error instance following an analysis of the
input value using the [SyntaxQualifier] instance previously assigned to
the receiver instance.
If a [SyntaxQualifier] is not assigned to the receiver instance, the
[ErrNilSyntaxQualifier] error is returned if and when this method is
executed. Otherwise, an error is returned based on the custom
[SyntaxQualifier] error handler devised within the user provided
closure.
A nil error return always indicates valid input value syntax.
See the [LDAPSyntax.SetSyntaxQualifier] method for information regarding
the assignment of an instance of [SyntaxQualifier] to the receiver.
*/
func (r LDAPSyntax) QualifySyntax(value any) (err error) {
if r.IsZero() {
err = ErrNilReceiver
} else if r.lDAPSyntax.synQual == nil {
err = ErrNilSyntaxQualifier
} else {
err = r.lDAPSyntax.synQual(value)
}
return
}
/*
LoadLDAPSyntaxes returns an error following an attempt to load all
built-in [LDAPSyntax] definitions into the receiver instance.
*/
func (r Schema) LoadLDAPSyntaxes() error {
return r.loadSyntaxes()
}
/*
loadSyntaxes returns an error following an attempt to load all
built-in ldapSyntax definitions found within this package into
the receiver instance.
*/
func (r Schema) loadSyntaxes() (err error) {
if !r.IsZero() {
funks := []func() error{
r.loadRFC4517Syntaxes,
r.loadRFC4523Syntaxes,
r.loadRFC4530Syntaxes,
r.loadRFC2307Syntaxes,
}
for i := 0; i < len(funks) && err == nil; i++ {
err = funks[i]()
}
}
return
}
/*
LoadRFC2307Syntaxes returns an error following an attempt to load
all RFC 2307 [LDAPSyntax] slices into the receiver instance.
*/
func (r Schema) LoadRFC2307Syntaxes() error {
return r.loadRFC2307Syntaxes()
}
func (r Schema) loadRFC2307Syntaxes() (err error) {
for k, v := range rfc2307Macros {
r.Macros().Set(k, v)
}
var i int
for i = 0; i < len(rfc2307LDAPSyntaxes) && err == nil; i++ {
ls := rfc2307LDAPSyntaxes[i]
err = r.ParseLDAPSyntax(string(ls))
}
if want := rfc2307LDAPSyntaxes.Len(); i != want {
if err == nil {
err = mkerr("Unexpected number of RFC2307 LDAPSyntaxes parsed: want " + itoa(want) + ", got " + itoa(i))