-static Filter *
-str2simple( char *str )
-{
- Filter *f;
- char *s;
- char *value, savechar;
-
- Debug( LDAP_DEBUG_FILTER, "str2simple \"%s\"\n", str, 0, 0 );
-
- if ( (s = strchr( str, '=' )) == NULL ) {
- return( NULL );
- }
- value = s + 1;
- *s-- = '\0';
- savechar = *s;
-
- f = (Filter *) ch_calloc( 1, sizeof(Filter) );
-
- switch ( *s ) {
- case '<':
- f->f_choice = LDAP_FILTER_LE;
- *s = '\0';
- break;
- case '>':
- f->f_choice = LDAP_FILTER_GE;
- *s = '\0';
- break;
- case '~':
- f->f_choice = LDAP_FILTER_APPROX;
- *s = '\0';
- break;
- default:
- if ( strchr( 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 );
- if ( str2subvals( value, f ) != 0 ) {
- filter_free( f );
- *(value-1) = '=';
- return( NULL );
- }
- *(value-1) = '=';
- return( f );
- }
- break;
- }
-
- if ( f->f_choice == LDAP_FILTER_PRESENT ) {
- f->f_type = strdup( str );
- } else {
- f->f_avtype = strdup( str );
- f->f_avvalue.bv_val = strdup( value );
- f->f_avvalue.bv_len = strlen( value );
- }
-
- *s = savechar;
- *(value-1) = '=';
- return( f );
-}
-
-static int
-str2subvals( char *val, Filter *f )
-{
- char *nextstar;
- int gotstar;
-
- Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", val, 0, 0 );
-
- gotstar = 0;
- while ( val != NULL && *val ) {
- if ( (nextstar = strchr( val, '*' )) != NULL )
- *nextstar++ = '\0';
-
- if ( gotstar == 0 ) {
- f->f_sub_initial = strdup( val );
- } else if ( nextstar == NULL ) {
- f->f_sub_final = strdup( val );
- } else {
- charray_add( &f->f_sub_any, strdup( val ) );
- }
-
- gotstar = 1;
- if ( nextstar != NULL )
- *(nextstar-1) = '*';
- val = nextstar;
- }
-
- return( 0 );
-}
-
-/*
- * find_matching_paren - return a pointer to the right paren in s matching
- * the left paren to which *s currently points
- */
-
-static char *
-find_matching_paren( char *s )
-{
- int balance, escape;
-
- balance = 0;
- escape = 0;
- for ( ; *s; s++ ) {
- if ( escape == 0 ) {
- if ( *s == '(' )
- balance++;
- else if ( *s == ')' )
- balance--;
- }
- if ( balance == 0 ) {
- return( s );
- }
- if ( *s == '\\' && ! escape )
- escape = 1;
- else
- escape = 0;
- }