Back to index

openldap  2.4.31
str2filter.c
Go to the documentation of this file.
00001 /* str2filter.c - parse an RFC 4515 string filter */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
00017  * All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms are permitted
00020  * provided that this notice is preserved and that due credit is given
00021  * to the University of Michigan at Ann Arbor. The name of the University
00022  * may not be used to endorse or promote products derived from this
00023  * software without specific prior written permission. This software
00024  * is provided ``as is'' without express or implied warranty.
00025  */
00026 
00027 #include "portable.h"
00028 
00029 #include <stdio.h>
00030 
00031 #include <ac/string.h>
00032 #include <ac/ctype.h>
00033 #include <ac/socket.h>
00034 
00035 #include "slap.h"
00036 
00037 
00038 Filter *
00039 str2filter_x( Operation *op, const char *str )
00040 {
00041        int rc;
00042        Filter *f = NULL;
00043        BerElementBuffer berbuf;
00044        BerElement *ber = (BerElement *)&berbuf;
00045        const char *text = NULL;
00046 
00047        Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
00048 
00049        if ( str == NULL || *str == '\0' ) {
00050               return NULL;
00051        }
00052 
00053        ber_init2( ber, NULL, LBER_USE_DER );
00054        if ( op->o_tmpmemctx ) {
00055               ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
00056        }
00057 
00058        rc = ldap_pvt_put_filter( ber, str );
00059        if( rc < 0 ) {
00060               goto done;
00061        }
00062 
00063        ber_reset( ber, 1 );
00064 
00065        rc = get_filter( op, ber, &f, &text );
00066 
00067 done:
00068        ber_free_buf( ber );
00069 
00070        return f;
00071 }
00072 
00073 Filter *
00074 str2filter( const char *str )
00075 {
00076        Operation op = {0};
00077        Opheader ohdr = {0};
00078 
00079        op.o_hdr = &ohdr;
00080        op.o_tmpmemctx = NULL;
00081        op.o_tmpmfuncs = &ch_mfuncs;
00082 
00083        return str2filter_x( &op, str );
00084 }