]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getvalues.c
VLV clean
[openldap] / libraries / libldap / getvalues.c
index 52802aa6cabe42c8cf3f6c073c0fd9bfb289f80b..bbf16d8c411c3e6b8981527cd216ea12517b8f56 100644 (file)
@@ -1,50 +1,51 @@
+/* $OpenLDAP$ */
 /*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  *  Copyright (c) 1990 Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  getvalues.c
  */
 
-#ifndef lint 
-static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
+#include "portable.h"
 
 #include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef MACOS
-#include "macos.h"
-#else /* MACOS */
-#if defined( DOS ) || defined( _WIN32 )
-#include <malloc.h>
-#include "msdos.h"
-#else /* DOS */
-#include <sys/types.h>
-#include <sys/socket.h>
-#endif /* DOS */
-#endif /* MACOS */
-
-#include "lber.h"
-#include "ldap.h"
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "ldap-int.h"
 
 char **
-ldap_get_values( LDAP *ld, LDAPMessage *entry, char *target )
+ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 {
        BerElement      ber;
-       char            attr[LDAP_MAX_ATTR_LEN];
+       char            *attr;
        int             found = 0;
-       long            len;
        char            **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "getvalues", LDAP_LEVEL_ENTRY, "ldap_get_values\n" ));
+#else
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
+#endif
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       len = sizeof(attr);
-       if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -54,16 +55,22 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, char *target )
 
        /* break out on success, return out on error */
        while ( ! found ) {
-               len = sizeof(attr);
-               if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) {
+               LDAP_FREE(attr);
+               attr = NULL;
+
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
 
                if ( strcasecmp( target, attr ) == 0 )
                        break;
+
        }
 
+       LDAP_FREE(attr);
+       attr = NULL;
+
        /* 
         * if we get this far, we've found the attribute and are sitting
         * just before the set of values.
@@ -78,21 +85,28 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, char *target )
 }
 
 struct berval **
-ldap_get_values_len( LDAP *ld, LDAPMessage *entry, char *target )
+ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 {
        BerElement      ber;
-       char            attr[LDAP_MAX_ATTR_LEN];
+       char            *attr;
        int             found = 0;
-       long            len;
        struct berval   **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "getvalues", LDAP_LEVEL_ENTRY, "ldap_get_values_len\n" ));
+#else
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
+#endif
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       len = sizeof(attr);
-       if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -102,8 +116,10 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, char *target )
 
        /* break out on success, return out on error */
        while ( ! found ) {
-               len = sizeof(attr);
-               if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) {
+               LDAP_FREE( attr );
+               attr = NULL;
+
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
@@ -112,6 +128,9 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, char *target )
                        break;
        }
 
+       LDAP_FREE( attr );
+       attr = NULL;
+
        /* 
         * if we get this far, we've found the attribute and are sitting
         * just before the set of values.
@@ -148,25 +167,11 @@ ldap_count_values_len( struct berval **vals )
 void
 ldap_value_free( char **vals )
 {
-       int     i;
-
-       if ( vals == NULL )
-               return;
-       for ( i = 0; vals[i] != NULL; i++ )
-               free( vals[i] );
-       free( (char *) vals );
+       LDAP_VFREE( vals );
 }
 
 void
 ldap_value_free_len( struct berval **vals )
 {
-       int     i;
-
-       if ( vals == NULL )
-               return;
-       for ( i = 0; vals[i] != NULL; i++ ) {
-               free( vals[i]->bv_val );
-               free( vals[i] );
-       }
-       free( (char *) vals );
+       ber_bvecfree( vals );
 }