]> git.sur5r.net Git - openldap/blob - servers/slapd/str2filter.c
52e5d791698a4f2d925d503ee8ce43b9af290236
[openldap] / servers / slapd / str2filter.c
1 /* str2filter.c - parse an RFC 2554 string filter */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/ctype.h>
33 #include <ac/socket.h>
34
35 #include "slap.h"
36
37 #if 0 /* unused */
38 static char     *find_matching_paren( const char *s );
39 #endif /* unused */
40 static Filter   *str2list( const char *str, long unsigned int ftype);
41 static Filter   *str2simple( const char *str);
42 static int      str2subvals( const char *val, Filter *f);
43
44 Filter *
45 str2filter_x( Operation *op, const char *str )
46 {
47         int rc;
48         Filter  *f = NULL;
49         BerElementBuffer berbuf;
50         BerElement *ber = (BerElement *)&berbuf;
51         const char *text = NULL;
52
53         Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
54
55         if ( str == NULL || *str == '\0' ) {
56                 return NULL;
57         }
58
59         ber_init2( ber, NULL, LBER_USE_DER );
60         if ( op->o_tmpmemctx ) {
61                 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
62         }
63
64         rc = ldap_pvt_put_filter( ber, str );
65         if( rc < 0 ) {
66                 goto done;
67         }
68
69         ber_reset( ber, 1 );
70
71         rc = get_filter( op, ber, &f, &text );
72
73 done:
74         ber_free_buf( ber );
75
76         return f;
77 }
78
79 Filter *
80 str2filter( const char *str )
81 {
82         Operation op = {0};
83         Opheader ohdr = {0};
84
85         op.o_hdr = &ohdr;
86         op.o_tmpmemctx = NULL;
87         op.o_tmpmfuncs = &ch_mfuncs;
88
89         return str2filter_x( &op, str );
90 }