Commit | Line | Data |
---|---|---|
04c6839a WJ |
1 | /* filter.c - Directory Operation Filters */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/dsap/common/RCS/filter.c,v 7.3 91/02/22 09:19:21 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/dsap/common/RCS/filter.c,v 7.3 91/02/22 09:19:21 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: filter.c,v $ | |
12 | * Revision 7.3 91/02/22 09:19:21 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.2 90/10/17 11:41:59 mrose | |
16 | * sync | |
17 | * | |
18 | * Revision 7.1 90/07/09 14:34:32 mrose | |
19 | * sync | |
20 | * | |
21 | * Revision 7.0 89/11/23 21:42:17 mrose | |
22 | * Release 6.0 | |
23 | * | |
24 | */ | |
25 | ||
26 | /* | |
27 | * NOTICE | |
28 | * | |
29 | * Acquisition, use, and distribution of this module and related | |
30 | * materials are subject to the restrictions of a license agreement. | |
31 | * Consult the Preface in the User's Manual for the full terms of | |
32 | * this agreement. | |
33 | * | |
34 | */ | |
35 | ||
36 | ||
37 | /* LINTLIBRARY */ | |
38 | ||
39 | #include "quipu/util.h" | |
40 | #include "quipu/ds_search.h" | |
41 | ||
42 | extern LLog * log_dsap; | |
43 | ||
44 | filter_free (filt) | |
45 | Filter filt; | |
46 | { | |
47 | register Filter ptr; | |
48 | register Filter next; | |
49 | ||
50 | for (ptr = filt; ptr != NULLFILTER; ptr=next) { | |
51 | if (ptr->flt_type == FILTER_ITEM) { | |
52 | switch (ptr->FUITEM.fi_type) { | |
53 | case FILTERITEM_EQUALITY: | |
54 | case FILTERITEM_GREATEROREQUAL: | |
55 | case FILTERITEM_LESSOREQUAL: | |
56 | case FILTERITEM_APPROX: | |
57 | AttrT_free (ptr->FUITEM.UNAVA.ava_type); | |
58 | AttrV_free (ptr->FUITEM.UNAVA.ava_value); | |
59 | break; | |
60 | case FILTERITEM_PRESENT: | |
61 | AttrT_free (ptr->FUITEM.UNTYPE); | |
62 | break; | |
63 | case FILTERITEM_SUBSTRINGS: | |
64 | AttrT_free (ptr->FUITEM.UNSUB.fi_sub_type); | |
65 | avs_free (ptr->FUITEM.UNSUB.fi_sub_initial); | |
66 | avs_free (ptr->FUITEM.UNSUB.fi_sub_any); | |
67 | avs_free (ptr->FUITEM.UNSUB.fi_sub_final); | |
68 | break; | |
69 | } | |
70 | } else | |
71 | filter_free (ptr->flt_un.flt_un_filter); | |
72 | ||
73 | next = ptr->flt_next; | |
74 | free ((char *) ptr); | |
75 | } | |
76 | } | |
77 | ||
78 | filter_append (a,b) | |
79 | Filter a,b; | |
80 | { | |
81 | register Filter ptr,trail; | |
82 | ||
83 | if ( a == NULLFILTER) | |
84 | DLOG (log_dsap,LLOG_DEBUG,("appending to null filter !")); | |
85 | ||
86 | for (ptr=a; ptr!= NULLFILTER; ptr=ptr->flt_next) | |
87 | trail = ptr; | |
88 | ||
89 | trail->flt_next = b; | |
90 | } | |
91 | ||
92 | ||
93 | Filter strfilter (at,s,type) | |
94 | AttributeType at; | |
95 | char * s; | |
96 | char type; | |
97 | { | |
98 | Filter filt; | |
99 | ||
100 | at = AttrT_cpy (at); | |
101 | filt = filter_alloc (); | |
102 | filt -> flt_next = NULLFILTER; | |
103 | filt -> flt_type = FILTER_ITEM; | |
104 | ||
105 | if (type == FILTERITEM_SUBSTRINGS || type == -FILTERITEM_SUBSTRINGS) { | |
106 | char *dp; | |
107 | ||
108 | if (*s == '*' && !s[1]) { | |
109 | filt -> FUITEM.fi_type = FILTERITEM_PRESENT; | |
110 | filt -> FUITEM.UNTYPE = at; | |
111 | goto all_done; | |
112 | } | |
113 | ||
114 | filt -> FUITEM.fi_type = FILTERITEM_SUBSTRINGS; | |
115 | filt -> FUITEM.UNSUB.fi_sub_type = at; | |
116 | filt -> FUITEM.UNSUB.fi_sub_initial = NULLAV; | |
117 | filt -> FUITEM.UNSUB.fi_sub_any = NULLAV; | |
118 | filt -> FUITEM.UNSUB.fi_sub_final = NULLAV; | |
119 | if (dp = index (s, '*')) { | |
120 | char buffer[BUFSIZ]; | |
121 | ||
122 | (void) strcpy (buffer, s); | |
123 | dp = buffer + (dp - s); | |
124 | s = buffer; | |
125 | ||
126 | *dp++ = NULL; | |
127 | if (*s) | |
128 | filt -> FUITEM.UNSUB.fi_sub_initial = | |
129 | str2avs (s, filt -> FUITEM.UNSUB.fi_sub_type); | |
130 | s = dp; | |
131 | ||
132 | if (dp = rindex (s, '*')) { | |
133 | AV_Sequence any_end = NULL; | |
134 | ||
135 | *dp++ = NULL; | |
136 | if (*dp) | |
137 | filt -> FUITEM.UNSUB.fi_sub_final = | |
138 | str2avs (dp, filt -> FUITEM.UNSUB.fi_sub_type); | |
139 | ||
140 | do { | |
141 | if (dp = index (s, '*')) | |
142 | *dp++ = NULL; | |
143 | if (*s) { | |
144 | AV_Sequence any = | |
145 | str2avs (s, | |
146 | filt -> FUITEM.UNSUB.fi_sub_type); | |
147 | ||
148 | if (any_end) { | |
149 | any_end -> avseq_next = any; | |
150 | any_end = any_end -> avseq_next; | |
151 | } | |
152 | else | |
153 | filt -> FUITEM.UNSUB.fi_sub_any = any_end = any; | |
154 | } | |
155 | } while (s = dp); | |
156 | } | |
157 | else | |
158 | if (*s) | |
159 | filt -> FUITEM.UNSUB.fi_sub_final = | |
160 | str2avs (s, filt -> FUITEM.UNSUB.fi_sub_type); | |
161 | } | |
162 | else | |
163 | if (type == FILTERITEM_SUBSTRINGS) | |
164 | filt -> FUITEM.UNSUB.fi_sub_any = | |
165 | str2avs (s, filt -> FUITEM.UNSUB.fi_sub_type); | |
166 | else | |
167 | filt -> FUITEM.UNSUB.fi_sub_initial = | |
168 | str2avs (s, filt -> FUITEM.UNSUB.fi_sub_type); | |
169 | } | |
170 | else { | |
171 | filt -> FUITEM.fi_type = type; | |
172 | filt -> FUITEM.UNAVA.ava_type = at; | |
173 | filt -> FUITEM.UNAVA.ava_value = | |
174 | str2AttrV (s, filt -> FUITEM.UNAVA.ava_type -> oa_syntax); | |
175 | } | |
176 | all_done: ; | |
177 | ||
178 | return filt; | |
179 | } | |
180 | ||
181 | Filter ocfilter (s) | |
182 | char * s; | |
183 | { | |
184 | Filter filt; | |
185 | ||
186 | filt = filter_alloc (); | |
187 | filt->flt_next = NULLFILTER; | |
188 | filt->flt_type = FILTER_ITEM; | |
189 | filt->FUITEM.fi_type = FILTERITEM_EQUALITY; | |
190 | if ((filt->FUITEM.UNAVA.ava_type = AttrT_new ("ObjectClass")) == NULLAttrT) { | |
191 | LLOG (log_dsap,LLOG_EXCEPTIONS,("ObjectClass attribute unknown")) | |
192 | return NULLFILTER; | |
193 | } | |
194 | filt->FUITEM.UNAVA.ava_value = str2AttrV(s, | |
195 | filt->FUITEM.UNAVA.ava_type->oa_syntax); | |
196 | if (filt->FUITEM.UNAVA.ava_value == NULLAttrV) { | |
197 | LLOG (log_dsap,LLOG_EXCEPTIONS,("'%s' unknown",s)); | |
198 | return NULLFILTER; | |
199 | } | |
200 | ||
201 | return filt; | |
202 | } | |
203 | ||
204 | Filter joinfilter (f, type) | |
205 | Filter f; | |
206 | char type; | |
207 | { | |
208 | Filter filt; | |
209 | ||
210 | filt = filter_alloc (); | |
211 | filt->flt_next = NULLFILTER; | |
212 | filt->flt_type = type; | |
213 | filt->FUFILT = f; | |
214 | ||
215 | return filt; | |
216 | } | |
217 | ||
218 | /* ARGSUSED */ | |
219 | ||
220 | int fi_print (ps, fi, format) | |
221 | PS ps; | |
222 | Filter fi; | |
223 | int format; | |
224 | { | |
225 | print_filter (ps, fi, 0); | |
226 | } | |
227 | ||
228 | ||
229 | print_filter (nps, fi, level) | |
230 | PS nps; | |
231 | register Filter fi; | |
232 | int level; | |
233 | { | |
234 | char *cp; | |
235 | register Filter fi2; | |
236 | register struct filter_item *fi3; | |
237 | ||
238 | switch (fi -> flt_type) { | |
239 | case FILTER_ITEM: | |
240 | fi3 = &fi -> FUITEM; | |
241 | if (level) | |
242 | ps_print (nps, "("); | |
243 | switch (fi3 -> fi_type) { | |
244 | case FILTERITEM_APPROX: | |
245 | cp = "~="; | |
246 | goto item; | |
247 | ||
248 | case FILTERITEM_EQUALITY: | |
249 | cp = "="; | |
250 | goto item; | |
251 | ||
252 | case FILTERITEM_GREATEROREQUAL: | |
253 | cp = ">="; | |
254 | goto item; | |
255 | ||
256 | case FILTERITEM_LESSOREQUAL: | |
257 | cp = ">="; | |
258 | item: ; | |
259 | AttrT_print (nps, fi3 -> UNAVA.ava_type, EDBOUT); | |
260 | ps_print (nps, cp); | |
261 | AttrV_print (nps, fi3 -> UNAVA.ava_value, EDBOUT); | |
262 | break; | |
263 | ||
264 | case FILTERITEM_SUBSTRINGS: | |
265 | AttrT_print (nps, fi3 -> UNSUB.fi_sub_type, EDBOUT); | |
266 | ps_print (nps, "="); | |
267 | avs_print_aux (nps, fi3 -> UNSUB.fi_sub_initial,EDBOUT,"*"); | |
268 | ps_print (nps, "*"); | |
269 | avs_print_aux (nps, fi3 -> UNSUB.fi_sub_any, EDBOUT, "*"); | |
270 | ps_print (nps, "*"); | |
271 | avs_print_aux (nps, fi3 -> UNSUB.fi_sub_final, EDBOUT, "*"); | |
272 | break; | |
273 | ||
274 | case FILTERITEM_PRESENT: | |
275 | AttrT_print (nps, fi3 -> UNTYPE, EDBOUT); | |
276 | ps_print (nps, "=*"); | |
277 | break; | |
278 | ||
279 | default: | |
280 | ps_printf (nps, | |
281 | "[internal error--malformed filter item type 0x%x]", | |
282 | fi3 -> fi_type); | |
283 | break; | |
284 | } | |
285 | if (level) | |
286 | ps_print (nps, ")"); | |
287 | break; | |
288 | ||
289 | case FILTER_AND: | |
290 | cp = "&"; | |
291 | goto op; | |
292 | case FILTER_OR: | |
293 | cp = "|"; | |
294 | goto op; | |
295 | ||
296 | case FILTER_NOT: | |
297 | cp = "!"; | |
298 | op: ; | |
299 | ps_printf (nps, "(%s", cp); | |
300 | level++; | |
301 | for (fi2 = fi -> FUFILT; fi2; fi2 = fi2 -> flt_next) { | |
302 | ps_print (nps, " "); | |
303 | print_filter (nps, fi2, level); | |
304 | } | |
305 | ps_print (nps, ")"); | |
306 | break; | |
307 | ||
308 | default: | |
309 | ps_printf (nps, "[internal error--malformed filter type 0x%x]", | |
310 | fi -> flt_type); | |
311 | } | |
312 | } |