]> git.sur5r.net Git - openldap/blob - servers/slapd/str2filter.c
unifdef -UNEW_LOGGING
[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 #include <ldap_pvt.h>
37
38 #if 0 /* unused */
39 static char     *find_matching_paren( const char *s );
40 #endif /* unused */
41 static Filter   *str2list( const char *str, long unsigned int ftype);
42 static Filter   *str2simple( const char *str);
43 static int      str2subvals( const char *val, Filter *f);
44
45 Filter *
46 str2filter_x( Operation *op, const char *str )
47 {
48         int rc;
49         Filter  *f = NULL;
50         BerElementBuffer berbuf;
51         BerElement *ber = (BerElement *)&berbuf;
52         const char *text = NULL;
53
54         Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
55
56         if ( str == NULL || *str == '\0' ) {
57                 return NULL;
58         }
59
60         ber_init2( ber, NULL, LBER_USE_DER );
61         if ( op->o_tmpmemctx ) {
62                 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
63         }
64
65         rc = ldap_pvt_put_filter( ber, str );
66         if( rc < 0 ) {
67                 goto done;
68         }
69
70         ber_reset( ber, 1 );
71
72         rc = get_filter( op, ber, &f, &text );
73
74 done:
75         ber_free_buf( ber );
76
77         return f;
78 }
79
80 Filter *
81 str2filter( const char *str )
82 {
83         Operation op = {0};
84
85         op.o_tmpmemctx = NULL;
86         op.o_tmpmfuncs = &ch_mfuncs;
87
88         return str2filter_x( &op, str );
89 }