]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getfilter.c
Cast char* argument to hh_to_c() to Byte*
[openldap] / libraries / libldap / getfilter.c
index 58eccc7670ed4b4317b8522c5e558f7dd919f03f..d69ff0e9e881f17e3c1443a87c2105dbe9d6c583 100644 (file)
@@ -1,46 +1,33 @@
 /*
+ * 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.
  *
  *  getfilter.c -- optional add-on to libldap
  */
 
-#define DISABLE_BRIDGE
 #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 <ac/ctype.h>
+#include <ac/errno.h>
+#include <ac/regex.h>
 #include <ac/string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <regex.h>
-
-#ifdef MACOS
-#include "macos.h"
-#else /* MACOS */
-#ifdef DOS
-#include <malloc.h>
-#include "msdos.h"
-#else /* DOS */
-#include <sys/types.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#include <sys/errno.h>
-#ifndef VMS
-#include <unistd.h>
-#endif /* VMS */
-#endif /* DOS */
-#endif /* MACOS */
+#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 ));
 
 #define FILT_MAX_LINE_LEN      1024
 
@@ -131,16 +118,14 @@ ldap_init_getfilter_buf( char *buf, long buflen )
            nextflp->lfl_tag = strdup( tag );
            nextflp->lfl_pattern = tok[ 0 ];
            if ( (rc = regcomp( &re, nextflp->lfl_pattern, 0 )) != 0 ) {
-#ifndef NO_USERINTERFACE
+#ifdef LDAP_LIBUI
                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 /* NO_USERINTERFACE */
+#endif /* LDAP_LIBUI */
                free_strarray( tok );
                return( NULL );
            }
@@ -189,9 +174,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 ] );
@@ -208,9 +191,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 );
        }
     }
@@ -350,12 +331,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 ) {
@@ -402,14 +383,16 @@ ldap_build_filter( char *filtbuf, unsigned long buflen, char *pattern,
                *f++ = *p;
            }
                
-           if ( f - filtbuf > buflen ) {
+           if ( (unsigned long) (f - filtbuf) > buflen ) {
                /* sanity check */
                --f;
                break;
            }
        }
 
-       if ( suffix != NULL && ( f - filtbuf ) < buflen ) {
+       if ( suffix != NULL && (
+               (unsigned long) ( f - filtbuf ) < buflen ) )
+       {
            strcpy( f, suffix );
        } else {
            *f = '\0';
@@ -422,14 +405,15 @@ break_into_words( char *str, 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 ) {
@@ -438,7 +422,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;