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 0
/
Copy pathmu.go
150 lines (122 loc) · 3.52 KB
/
mu.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
package antlr4512
/*
MatchingRuleUse implements RFC 4512 Section 4.1.4.
*/
type MatchingRuleUse struct {
OID string
Macro []string
Name []string
Desc string
Obsolete bool
Applies []string
Extensions map[string][]string
}
/*
MatchingRuleUses is an instance of slices of [MatchingRuleUse] instances.
*/
type MatchingRuleUses []MatchingRuleUse
/*
ParseMatchingRuleUse processes raw into an instance of [MatchingRuleUse]. Note
that it is unusual for this function to be used and exists mainly for the sake
of completeness.
A [MatchingRuleUse] instance is simply a manifest of attributeType instances
which utilize a given [MatchingRule] for EQUALITY, SUBSTR and ORDERING fields.
Generally, these [MatchingRuleUse] instances are created -- by the DSA -- based
on equivalent [MatchingRule] instances, and only manifest when the number of
"applied" [AttributeType] users is greater than zero (0) for the relevant
[MatchingRule].
In short, one generally need only load ldapSyntax, matchingRule and attributeType
definitions to initialize or extend matchingRuleUse instances.
*/
func ParseMatchingRuleUse(raw string) (mu MatchingRuleUse, err error) {
var i Instance
if i, err = ParseInstance(raw); err != nil {
return
}
// Ensure what went in matches precisely what came out
x := i.P.MatchingRuleUseDescription()
if err = mu.process(x); err == nil {
ptext := x.GetText()
if raw != ptext {
err = errorf("Inconsistent %T parse results or bad content", mu)
}
}
return
}
func (r *MatchingRuleUse) process(ctx IMatchingRuleUseDescriptionContext) (err error) {
if err = parenContext(ctx.OpenParen(), ctx.CloseParen()); err != nil {
return
}
for k, ct := 0, ctx.GetChildCount(); k < ct && err == nil; k++ {
switch tv := ctx.GetChild(k).(type) {
case *NumericOIDOrMacroContext:
r.OID, r.Macro, err = numOIDContext(tv)
case *NameContext,
*ExtensionsContext,
*DescriptionContext:
err = r.setMisc(tv)
case *ObsolescenceContext:
r.Obsolete = true
case *AppliesContext:
err = r.appliesContext(tv)
default:
err = isErrImpl(`matchingRuleUse`, r.OID, tv)
}
}
if len(r.OID) == 0 {
err = errorf("Missing numeric OID for %T", r)
} else if len(r.Applies) == 0 {
err = errorf("Missing applied OIDs for %T", r)
}
return
}
func (r *MatchingRuleUse) setMisc(ctx any) (err error) {
switch tv := ctx.(type) {
case *NameContext:
r.Name, err = nameContext(tv.Names())
case *DescriptionContext:
r.Desc, err = descContext(tv)
case *ExtensionsContext:
r.Extensions, err = extContext(tv)
default:
err = errorf("Unknown miscellaneous context '%T'", ctx)
}
return
}
func (r *MatchingRuleUse) setCritical(ctx any) (err error) {
switch tv := ctx.(type) {
case *NumericOIDContext:
r.OID, _, err = numOIDContext(tv)
default:
err = errorf("Unknown critical context '%T'", ctx)
}
return
}
func (r *MatchingRuleUse) appliesContext(ctx *AppliesContext) (err error) {
if ctx != nil {
var n, d []string
if x := ctx.OID(); x != nil {
n, d, err = oIDContext(x.(*OIDContext))
} else if y := ctx.OIDs(); y != nil {
if err = parenContext(y.OpenParen(), y.CloseParen()); err != nil {
return
}
n, d, err = oIDsContext(y.(*OIDsContext))
}
var applies []string
if err == nil {
applies = append(applies, n...)
applies = append(applies, d...)
}
if len(applies) == 0 {
if err != nil {
err = errorf("No applied types found in %T: %v", ctx, err)
} else {
err = errorf("No applied types found in %T", ctx)
}
} else {
r.Applies = applies
}
}
return
}