3 * Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 #include "portable.h"
\r
10 #include <ac/string.h>
15 static char **set_join (char **lset, int op, char **rset);
16 static char **set_chase (SET_GATHER gatherer, void *cookie, char **set, char *attr, int attrlen, int closure);
17 static int set_samedn (char *dn1, char *dn2);
33 set_dispose (char **set)
38 for (i = 0; set[i]; i++)
45 set_join (char **lset, int op, char **rset)
52 if (lset == NULL || *lset == NULL) {
55 return(ch_calloc(1, sizeof(char *)));
61 if (rset == NULL || *rset == NULL) {
66 i = set_size(lset) + set_size(rset) + 1;
67 set = ch_calloc(i, sizeof(char *));
69 /* set_chase() depends on this routine to
70 * keep the first elements of the result
71 * set the same (and in the same order)
74 for (i = 0; lset[i]; i++)
77 for (i = 0; rset[i]; i++) {
78 for (j = 0; set[j]; j++) {
79 if (set_samedn(rset[i], set[j])) {
94 if (lset == NULL || *lset == NULL || rset == NULL || *rset == NULL) {
95 set = ch_calloc(1, sizeof(char *));
99 last = set_size(set) - 1;
100 for (i = 0; set[i]; i++) {
101 for (j = 0; rset[j]; j++) {
102 if (set_samedn(set[i], rset[j]))
105 if (rset[j] == NULL) {
122 set_chase (SET_GATHER gatherer, void *cookie, char **set, char *attr, int attrlen, int closure)
129 return(ch_calloc(1, sizeof(char *)));
134 if (attrlen > (sizeof(attrstr) - 1)) {
138 AC_MEMCPY(attrstr, attr, attrlen);
139 attrstr[attrlen] = 0;
141 nset = ch_calloc(1, sizeof(char *));
146 for (i = 0; set[i]; i++) {
147 vals = (gatherer)(cookie, set[i], attrstr);
149 nset = set_join(nset, '|', vals);
154 for (i = 0; nset[i]; i++) {
155 vals = (gatherer)(cookie, nset[i], attrstr);
157 nset = set_join(nset, '|', vals);
167 set_samedn (char *dn1, char *dn2)
171 while (*dn1 == ' ') dn1++;
172 while (*dn2 == ' ') dn2++;
173 while (*dn1 || *dn2) {
174 if (*dn1 != '=' && *dn1 != ','
175 && *dn2 != '=' && *dn2 != ',')
179 if (c1 >= 'a' && c1 <= 'z')
181 if (c2 >= 'a' && c2 <= 'z')
186 while (*dn1 == ' ') dn1++;
187 while (*dn2 == ' ') dn2++;
188 if (*dn1++ != *dn2++)
190 while (*dn1 == ' ') dn1++;
191 while (*dn2 == ' ') dn2++;
198 set_filter (SET_GATHER gatherer, void *cookie, char *filter, char *user, char *this, char ***results)
200 # define IS_SET(x) ( (long)(x) >= 256 )
201 # define IS_OP(x) ( (long)(x) < 256 )
202 # define SF_ERROR(x) { rc = -1; goto _error; }
203 # define SF_TOP() (char **)( (stp < 0) ? 0 : stack[stp] )
204 # define SF_POP() (char **)( (stp < 0) ? 0 : stack[stp--] )
205 # define SF_PUSH(x) { if (stp >= 63) SF_ERROR(overflow); stack[++stp] = (char **)(long)(x); }
208 int len, op, rc, stp;
215 while (c = *filter++) {
225 if (IS_SET(SF_TOP()))
234 if (SF_TOP() == (void *)'(') {
238 } else if (IS_OP(SF_TOP())) {
242 set = set_join(lset, op, set);
257 if (SF_TOP() == 0 || SF_TOP() == (void *)'(') {
260 } else if (IS_OP(SF_TOP())) {
263 set = set_join(lset, op, set);
275 if ((SF_TOP() == (void *)'/') || IS_SET(SF_TOP()))
278 (c = *filter++) && (c != ']');
284 set = ch_calloc(2, sizeof(char *));
287 *set = ch_calloc(len + 1, sizeof(char));
290 AC_MEMCPY(*set, &filter[-len - 1], len);
299 /* fall through to next case */
309 && (c < 'A' || c > 'Z')
310 && (c < 'a' || c > 'z'))
317 && ((c >= '0' && c <= '9')
318 || (c >= 'A' && c <= 'Z')
319 || (c >= 'a' && c <= 'z'));
323 && memcmp("this", filter, len) == 0)
325 if ((SF_TOP() == (void *)'/') || IS_SET(SF_TOP()))
327 set = ch_calloc(2, sizeof(char *));
330 *set = ch_strdup(this);
334 && memcmp("user", filter, len) == 0)
336 if ((SF_TOP() == (void *)'/') || IS_SET(SF_TOP()))
338 set = ch_calloc(2, sizeof(char *));
341 *set = ch_strdup(user);
344 } else if (SF_TOP() != (void *)'/') {
348 set = set_chase(gatherer, cookie, SF_POP(), filter, len, c == '*');
366 } else if (IS_OP(SF_TOP())) {
369 set = set_join(lset, op, set);
385 while (set = SF_POP()) {