+/* $OpenLDAP$ */
/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
#include <ac/stdlib.h>
-#include <ac/ctype.h>
#include <ac/errno.h>
#include <ac/regex.h>
#include <ac/string.h>
#define FILT_MAX_LINE_LEN 1024
-LDAPFiltDesc *
-ldap_init_getfilter( LDAP_CONST char *fname )
-{
- FILE *fp;
- char *buf;
- long rlen, len;
- int eof;
- LDAPFiltDesc *lfdp;
-
- if (( fp = fopen( fname, "r" )) == NULL ) {
- return( NULL );
- }
-
- if ( fseek( fp, 0L, SEEK_END ) != 0 ) { /* move to end to get len */
- fclose( fp );
- return( NULL );
- }
-
- len = ftell( fp );
-
- if ( fseek( fp, 0L, SEEK_SET ) != 0 ) { /* back to start of file */
- fclose( fp );
- return( NULL );
- }
-
- if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
- fclose( fp );
- return( NULL );
- }
-
- rlen = fread( buf, 1, (size_t)len, fp );
- eof = feof( fp );
- fclose( fp );
-
- if ( rlen != len && !eof ) { /* error: didn't get the whole file */
- LDAP_FREE( buf );
- return( NULL );
- }
-
-
- lfdp = ldap_init_getfilter_buf( buf, rlen );
- LDAP_FREE( buf );
-
- return( lfdp );
-}
-
-
-LDAPFiltDesc *
+static LDAPFiltDesc *
ldap_init_getfilter_buf( char *buf, ber_len_t buflen )
{
LDAPFiltDesc *lfdp;
fip = NULL;
tag = NULL;
- while ( buflen > 0 && ( tokcnt = next_line_tokens( &buf, &buflen, &tok ))
+ while ( buflen > 0 && ( tokcnt = ldap_int_next_line_tokens( &buf, &buflen, &tok ))
> 0 ) {
switch( tokcnt ) {
nextflp->lfl_tag = LDAP_STRDUP( tag );
nextflp->lfl_pattern = tok[ 0 ];
if ( (rc = regcomp( &re, nextflp->lfl_pattern, 0 )) != 0 ) {
-#ifdef LDAP_LIBUI
char error[512];
regerror(rc, &re, error, sizeof(error));
ldap_getfilter_free( lfdp );
- fprintf( stderr, "bad regular expression %s, %s\n",
- nextflp->lfl_pattern, error );
+ Debug( LDAP_DEBUG_ANY, "ldap_init_get_filter_buf: "
+ "bad regular expression %s, %s\n",
+ nextflp->lfl_pattern, error, 0 );
errno = EINVAL;
-#endif /* LDAP_LIBUI */
- free_strarray( tok );
+ LDAP_VFREE( tok );
return( NULL );
}
regfree(&re);
if (( nextfip = (LDAPFiltInfo *)LDAP_CALLOC( 1,
sizeof( LDAPFiltInfo ))) == NULL ) {
ldap_getfilter_free( lfdp );
- free_strarray( tok );
+ LDAP_VFREE( tok );
return( NULL );
}
if ( fip == NULL ) { /* first one */
} else if ( strcasecmp( tok[ 2 ], "base" ) == 0 ) {
nextfip->lfi_scope = LDAP_SCOPE_BASE;
} else {
- free_strarray( tok );
+ LDAP_VFREE( tok );
ldap_getfilter_free( lfdp );
errno = EINVAL;
return( NULL );
break;
default:
- free_strarray( tok );
+ LDAP_VFREE( tok );
ldap_getfilter_free( lfdp );
errno = EINVAL;
return( NULL );
return( lfdp );
}
-
-void
-ldap_setfilteraffixes( LDAPFiltDesc *lfdp, LDAP_CONST char *prefix, LDAP_CONST char *suffix )
+LDAPFiltDesc *
+ldap_init_getfilter( LDAP_CONST char *fname )
{
- if ( lfdp->lfd_filtprefix != NULL ) {
- LDAP_FREE( lfdp->lfd_filtprefix );
+ FILE *fp;
+ char *buf;
+ long rlen, len;
+ int eof;
+ LDAPFiltDesc *lfdp;
+
+ if (( fp = fopen( fname, "r" )) == NULL ) {
+ return( NULL );
}
- lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : LDAP_STRDUP( prefix );
- if ( lfdp->lfd_filtsuffix != NULL ) {
- LDAP_FREE( lfdp->lfd_filtsuffix );
+ if ( fseek( fp, 0L, SEEK_END ) != 0 ) { /* move to end to get len */
+ fclose( fp );
+ return( NULL );
+ }
+
+ len = ftell( fp );
+
+ if ( fseek( fp, 0L, SEEK_SET ) != 0 ) { /* back to start of file */
+ fclose( fp );
+ return( NULL );
+ }
+
+ if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
+ fclose( fp );
+ return( NULL );
}
- lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : LDAP_STRDUP( suffix );
-}
+ rlen = fread( buf, 1, (size_t)len, fp );
+ eof = feof( fp );
+ fclose( fp );
+
+ if ( rlen != len && !eof ) { /* error: didn't get the whole file */
+ LDAP_FREE( buf );
+ return( NULL );
+ }
+
+
+ lfdp = ldap_init_getfilter_buf( buf, rlen );
+ LDAP_FREE( buf );
+
+ return( lfdp );
+}
LDAPFiltInfo *
ldap_getfirstfilter(
return( ldap_getnextfilter( lfdp ));
}
+static void
+ldap_build_filter(
+ char *filtbuf,
+ ber_len_t buflen,
+ LDAP_CONST char *pattern,
+ LDAP_CONST char *prefix,
+ LDAP_CONST char *suffix,
+ LDAP_CONST char *attr,
+ LDAP_CONST char *value,
+ char **valwords );
LDAPFiltInfo *
ldap_getnextfilter( LDAPFiltDesc *lfdp )
return( &lfdp->lfd_retfi );
}
-
-void
+static void
ldap_build_filter(
char *filtbuf,
ber_len_t buflen,
if ( *p == '%' ) {
++p;
if ( *p == 'v' ) {
- if ( isdigit( (unsigned char) p[1] )) {
+ if ( LDAP_DIGIT( (unsigned char) p[1] )) {
++p;
wordnum = *p - '1';
if ( *(p+1) == '-' ) {
++p;
- if ( isdigit( (unsigned char) p[1] )) {
+ if ( LDAP_DIGIT( (unsigned char) p[1] )) {
++p;
endwordnum = *p - '1'; /* e.g., "%v2-4" */
if ( endwordnum > wordcount - 1 ) {
*f++ = ' ';
}
slen = strlen( valwords[ i ] );
- SAFEMEMCPY( f, valwords[ i ], slen );
+ AC_MEMCPY( f, valwords[ i ], slen );
f += slen;
}
}
if ( wordcount > 0 ) {
wordnum = wordcount - 1;
slen = strlen( valwords[ wordnum ] );
- SAFEMEMCPY( f, valwords[ wordnum ], slen );
+ AC_MEMCPY( f, valwords[ wordnum ], slen );
f += slen;
}
} else if ( value != NULL ) {
slen = strlen( value );
- SAFEMEMCPY( f, value, slen );
+ AC_MEMCPY( f, value, slen );
f += slen;
}
} else if ( *p == 'a' && attr != NULL ) {
slen = strlen( attr );
- SAFEMEMCPY( f, attr, slen );
+ AC_MEMCPY( f, attr, slen );
f += slen;
} else {
*f++ = *p;
}
}
-
static int
break_into_words( /* LDAP_CONST */ char *str, LDAP_CONST char *delims, char ***wordsp )
{