]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getfilter.c
rename ldap_pvt_init_utils() to ldap_int_utils_init() and provide
[openldap] / libraries / libldap / getfilter.c
index 5f9bffbe47e0c53611072b758fbdfdae8a0b08e5..94f73c3c77d804c8014b9678cfa21c507b15b9ce 100644 (file)
@@ -1,4 +1,8 @@
 /*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  *  Copyright (c) 1993 Regents of the University of Michigan.
  *  All rights reserved.
  *
 
 #include "portable.h"
 
-#ifndef lint 
-static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
-#include <ctype.h>
 
+#include <ac/ctype.h>
 #include <ac/errno.h>
 #include <ac/regex.h>
 #include <ac/string.h>
+#include <ac/time.h>
 #include <ac/unistd.h>
 
-#include <sys/types.h>
 #ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
 #endif
 
-#include "lber.h"
-#include "ldap.h"
+#include "ldap-int.h"
 
-static int break_into_words LDAP_P(( char *str, char *delims, char ***wordsp ));
-int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp ));
-void free_strarray LDAP_P(( char **sap ));
+static int break_into_words LDAP_P((
+       /* LDAP_CONST */ char *str,
+       LDAP_CONST char *delims,
+       char ***wordsp ));
 
 #define FILT_MAX_LINE_LEN      1024
 
 LDAPFiltDesc *
-ldap_init_getfilter( char *fname )
+ldap_init_getfilter( LDAP_CONST char *fname )
 {
     FILE               *fp;
     char               *buf;
@@ -125,11 +125,9 @@ ldap_init_getfilter_buf( char *buf, long buflen )
                char error[512];
                regerror(rc, &re, error, sizeof(error));
                ldap_getfilter_free( lfdp );
-               fprintf( stderr, "bad regular expresssion %s, %s\n",
+               fprintf( stderr, "bad regular expression %s, %s\n",
                        nextflp->lfl_pattern, error );
-#if !defined( MACOS ) && !defined( DOS )
                errno = EINVAL;
-#endif
 #endif /* LDAP_LIBUI */
                free_strarray( tok );
                return( NULL );
@@ -179,9 +177,7 @@ ldap_init_getfilter_buf( char *buf, long buflen )
                    } else {
                        free_strarray( tok );
                        ldap_getfilter_free( lfdp );
-#if !defined( MACOS ) && !defined( DOS )
                        errno = EINVAL;
-#endif
                        return( NULL );
                    }
                    free( tok[ 2 ] );
@@ -198,9 +194,7 @@ ldap_init_getfilter_buf( char *buf, long buflen )
        default:
            free_strarray( tok );
            ldap_getfilter_free( lfdp );
-#if !defined( MACOS ) && !defined( DOS )
            errno = EINVAL;
-#endif
            return( NULL );
        }
     }
@@ -214,7 +208,7 @@ ldap_init_getfilter_buf( char *buf, long buflen )
 
 
 void
-ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix )
+ldap_setfilteraffixes( LDAPFiltDesc *lfdp, LDAP_CONST char *prefix, LDAP_CONST char *suffix )
 {
     if ( lfdp->lfd_filtprefix != NULL ) {
        free( lfdp->lfd_filtprefix );
@@ -229,7 +223,10 @@ ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix )
 
 
 LDAPFiltInfo *
-ldap_getfirstfilter( LDAPFiltDesc *lfdp, char *tagpat, char *value )
+ldap_getfirstfilter(
+       LDAPFiltDesc *lfdp,
+       /* LDAP_CONST */ char *tagpat,
+       /* LDAP_CONST */ char *value )
 {
     LDAPFiltList       *flp;
        int                             rc;
@@ -314,10 +311,18 @@ ldap_getnextfilter( LDAPFiltDesc *lfdp )
 
 
 void
-ldap_build_filter( char *filtbuf, unsigned long buflen, char *pattern,
-       char *prefix, char *suffix, char *attr, char *value, char **valwords )
+ldap_build_filter(
+       char *filtbuf,
+       unsigned long buflen,
+       LDAP_CONST char *pattern,
+       LDAP_CONST char *prefix,
+       LDAP_CONST char *suffix,
+       LDAP_CONST char *attr,
+       LDAP_CONST char *value,
+       char **valwords )
 {
-       char    *p, *f;
+       const char *p;
+       char *f;
        size_t  slen;
        int     i, wordcount, wordnum, endwordnum;
        
@@ -340,12 +345,12 @@ ldap_build_filter( char *filtbuf, unsigned long buflen, char *pattern,
            if ( *p == '%' ) {
                ++p;
                if ( *p == 'v' ) {
-                   if ( isdigit( *(p+1))) {
+                   if ( isdigit( (unsigned char) p[1] )) {
                        ++p;
                        wordnum = *p - '1';
                        if ( *(p+1) == '-' ) {
                            ++p;
-                           if ( isdigit( *(p+1))) {
+                           if ( isdigit( (unsigned char) p[1] )) {
                                ++p;
                                endwordnum = *p - '1';  /* e.g., "%v2-4" */
                                if ( endwordnum > wordcount - 1 ) {
@@ -410,18 +415,19 @@ ldap_build_filter( char *filtbuf, unsigned long buflen, char *pattern,
 
 
 static int
-break_into_words( char *str, char *delims, char ***wordsp )
+break_into_words( /* LDAP_CONST */ char *str, LDAP_CONST char *delims, char ***wordsp )
 {
     char       *word, **words;
     int                count;
-       
+    char        *tok_r;        
+
     if (( words = (char **)calloc( 1, sizeof( char * ))) == NULL ) {
        return( -1 );
     }
     count = 0;
     words[ count ] = NULL;
 
-    word = strtok( str, delims );
+    word = ldap_pvt_strtok( str, delims, &tok_r );
     while ( word != NULL ) {
        if (( words = (char **)realloc( words,
                ( count + 2 ) * sizeof( char * ))) == NULL ) {
@@ -430,7 +436,7 @@ break_into_words( char *str, char *delims, char ***wordsp )
 
        words[ count ] = word;
        words[ ++count ] = NULL;
-       word = strtok( NULL, delims );
+       word = ldap_pvt_strtok( NULL, delims, &tok_r );
     }
        
     *wordsp = words;