/* str2filter.c - parse an rfc 1588 string filter */
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
+#include "portable.h"
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/ctype.h>
+#include <ac/socket.h>
+
#include "slap.h"
+#include <ldap_pvt.h>
-static char *find_matching_paren();
-static Filter *str2list();
-static Filter *str2simple();
-static int str2subvals();
+static char *find_matching_paren( const char *s );
+static Filter *str2list( const char *str, long unsigned int ftype);
+static Filter *str2simple( const char *str);
+static int str2subvals( const char *val, Filter *f);
Filter *
-str2filter( char *str )
+str2filter( const char *str )
{
- Filter *f;
- char *end;
+ Filter *f = NULL;
+ char *end, *freeme;
Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
return( NULL );
}
+ str = freeme = ch_strdup( str );
+
switch ( *str ) {
case '(':
if ( (end = find_matching_paren( str )) == NULL ) {
filter_free( f );
+ free( freeme );
return( NULL );
}
*end = '\0';
break;
}
+ free( freeme );
return( f );
}
*/
static Filter *
-str2list( char *str, unsigned long ftype )
+str2list( const char *str, unsigned long ftype )
{
Filter *f;
Filter **fp;
fp = &f->f_list;
while ( *str ) {
- while ( *str && isspace( *str ) )
+ while ( *str && isspace( (unsigned char) *str ) )
str++;
if ( *str == '\0' )
break;
}
static Filter *
-str2simple( char *str )
+str2simple( const char *str )
{
Filter *f;
char *s;
char *value, savechar;
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+ int rc;
+ const char *text;
+#endif
Debug( LDAP_DEBUG_FILTER, "str2simple \"%s\"\n", str, 0, 0 );
if ( (s = strchr( str, '=' )) == NULL ) {
return( NULL );
}
- value = s + 1;
- *s-- = '\0';
+ value = &s[1];
+
+ *s-- = '\0'; /* we shouldn't be mucking with str */
savechar = *s;
f = (Filter *) ch_calloc( 1, sizeof(Filter) );
f->f_choice = LDAP_FILTER_APPROX;
*s = '\0';
break;
+ case ':':
+ f->f_choice = LDAP_FILTER_EXT;
+ *s = '\0';
+ return NULL;
+ break;
+
default:
- if ( strchr( value, '*' ) == NULL ) {
+ if ( ldap_pvt_find_wildcard( value ) == NULL ) {
f->f_choice = LDAP_FILTER_EQUALITY;
} else if ( strcmp( value, "*" ) == 0 ) {
f->f_choice = LDAP_FILTER_PRESENT;
} else {
f->f_choice = LDAP_FILTER_SUBSTRINGS;
- f->f_sub_type = strdup( str );
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+ f->f_sub = ch_calloc( 1, sizeof( SubstringsAssertion ) );
+ rc = slap_str2ad( str, &f->f_sub_desc, &text );
+ if( rc != LDAP_SUCCESS ) {
+ filter_free( f );
+ *(value-1) = '=';
+ return NULL;
+ }
+#else
+ f->f_sub_type = ch_strdup( str );
+#endif
if ( str2subvals( value, f ) != 0 ) {
filter_free( f );
*(value-1) = '=';
}
if ( f->f_choice == LDAP_FILTER_PRESENT ) {
- f->f_type = strdup( str );
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+ rc = slap_str2ad( str, &f->f_desc, &text );
+ if( rc != LDAP_SUCCESS ) {
+ filter_free( f );
+ *(value-1) = '=';
+ return NULL;
+ }
+#else
+ f->f_type = ch_strdup( str );
+#endif
} else {
- f->f_avtype = strdup( str );
- f->f_avvalue.bv_val = strdup( value );
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+ char *tmp;
+
+ f->f_ava = ch_calloc( 1, sizeof( AttributeAssertion ) );
+ f->f_av_desc = NULL;
+ rc = slap_str2ad( str, &f->f_av_desc, &text );
+ if( rc != LDAP_SUCCESS ) {
+ filter_free( f );
+ *(value-1) = '=';
+ return NULL;
+ }
+
+ tmp = ch_strdup( value );
+ ldap_pvt_filter_value_unescape( tmp );
+ f->f_av_value = ber_bvstr( tmp );
+#else
+ f->f_avtype = ch_strdup( str );
+ f->f_avvalue.bv_val = ch_strdup( value );
+ ldap_pvt_filter_value_unescape( f->f_avvalue.bv_val );
f->f_avvalue.bv_len = strlen( value );
+#endif
}
*s = savechar;
*(value-1) = '=';
+
return( f );
}
static int
-str2subvals( char *val, Filter *f )
+str2subvals( const char *in, Filter *f )
{
- char *nextstar;
+ char *nextstar, *val, *freeme;
int gotstar;
- Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", val, 0, 0 );
+ Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", in, 0, 0 );
+ if( in == NULL ) return 0;
+
+ val = freeme = ch_strdup( in );
gotstar = 0;
- while ( val != NULL && *val ) {
- if ( (nextstar = strchr( val, '*' )) != NULL )
+
+ while ( *val ) {
+ if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL )
*nextstar++ = '\0';
+ ldap_pvt_filter_value_unescape( val );
+
if ( gotstar == 0 ) {
- f->f_sub_initial = strdup( val );
+ f->f_sub_initial = ber_bvstrdup( val );
+
} else if ( nextstar == NULL ) {
- f->f_sub_final = strdup( val );
+ f->f_sub_final = ber_bvstrdup( val );
+
} else {
- charray_add( &f->f_sub_any, strdup( val ) );
+ charray_add( (char ***) &f->f_sub_any, (char *) ber_bvstrdup( val ) );
}
gotstar = 1;
- if ( nextstar != NULL )
- *(nextstar-1) = '*';
val = nextstar;
}
+ free( freeme );
return( 0 );
}
*/
static char *
-find_matching_paren( char *s )
+find_matching_paren( const char *s )
{
int balance, escape;
balance--;
}
if ( balance == 0 ) {
- return( s );
+ return (char *) s;
}
if ( *s == '\\' && ! escape )
escape = 1;
escape = 0;
}
- return( NULL );
+ return NULL;
}