Source tree pruned and flattened.
[clldap.git] / filter.lisp
blob1a6692d95710e862e2a19d76e90048ea03be1e55
1 (in-package :net.quadium.ldap)
3 (defun convert-search-filter (filter)
4 "Returns a filter string created from the FILTER sexp.
6 Example:
7 (convert-search-filter '(and (not (or (= \"objectClass\" \"computer\")
8 (= \"objectClass\" \"group\")))
9 (= \"location\" \"millenia*\")))
10 => \"(&(!(|(objectClass=computer)(objectClass=group)))(location=millenia*))\""
11 (cond
12 ((null filter) "")
13 ((member (car filter) '(= ~= <= >=))
14 (destructuring-bind (filter-type attribute-type attribute-value)
15 filter
16 (format nil "(~A~A~A)"
17 (ldap-escape attribute-type) filter-type (ldap-escape attribute-value))))
18 ((member (car filter) '(and or))
19 (format nil "(~A~{~A~})"
20 (ecase (car filter)
21 (and #\&)
22 (or #\|))
23 (mapcar 'convert-search-filter (cdr filter))))
24 ((eq (car filter) 'not)
25 (format nil "(!~A)" (convert-search-filter (cadr filter))))))