]> git.sur5r.net Git - openldap/blob - servers/slapd/str2filter.c
Happy new year
[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 #ifdef NEW_LOGGING
55         LDAP_LOG( FILTER, ENTRY,  "str2filter: \"%s\"\n", str, 0, 0 );
56 #else
57         Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
58 #endif
59
60         if ( str == NULL || *str == '\0' ) {
61                 return NULL;
62         }
63
64         ber_init2( ber, NULL, LBER_USE_DER );
65         if ( op->o_tmpmemctx ) {
66                 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
67         }
68
69         rc = ldap_pvt_put_filter( ber, str );
70         if( rc < 0 ) {
71                 goto done;
72         }
73
74         ber_reset( ber, 1 );
75
76         rc = get_filter( op, ber, &f, &text );
77
78 done:
79         ber_free_buf( ber );
80
81         return f;
82 }
83
84 Filter *
85 str2filter( const char *str )
86 {
87         Operation op = {0};
88
89         op.o_tmpmemctx = NULL;
90         op.o_tmpmfuncs = &ch_mfuncs;
91
92         return str2filter_x( &op, str );
93 }