]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getvalues.c
silence warnings
[openldap] / libraries / libldap / getvalues.c
index 865688e535635a37966e574e856a3a0fe58cf21a..d2f3c2fa37cdd415fbfabdcbf57d8404b0fabb10 100644 (file)
@@ -1,18 +1,26 @@
-/*
- * Copyright 1998-1999 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.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2009 The OpenLDAP Foundation.
+ * All rights reserved.
  *
- *  getvalues.c
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1990 Regents of the University of Michigan.
+ * All rights reserved.
  */
 
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
 #include <ac/socket.h>
@@ -29,12 +37,17 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
        int             found = 0;
        char            **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -44,10 +57,10 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 
        /* break out on success, return out on error */
        while ( ! found ) {
-               free(attr);
+               LDAP_FREE(attr);
                attr = NULL;
 
-               if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
@@ -57,7 +70,7 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 
        }
 
-       free(attr);
+       LDAP_FREE(attr);
        attr = NULL;
 
        /* 
@@ -81,12 +94,17 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
        int             found = 0;
        struct berval   **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -96,10 +114,10 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
 
        /* break out on success, return out on error */
        while ( ! found ) {
-               free( attr );
+               LDAP_FREE( attr );
                attr = NULL;
 
-               if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
@@ -108,7 +126,7 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
                        break;
        }
 
-       free( attr );
+       LDAP_FREE( attr );
        attr = NULL;
 
        /* 
@@ -147,25 +165,47 @@ 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;
+       ber_bvecfree( vals );
+}
 
-       if ( vals == NULL )
-               return;
-       for ( i = 0; vals[i] != NULL; i++ ) {
-               free( vals[i]->bv_val );
-               free( vals[i] );
+char **
+ldap_value_dup( char *const *vals )
+{
+       char **new;
+       int i;
+
+       if( vals == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               ;   /* Count the number of values */
+       }
+
+       if( i == 0 ) {
+               return NULL;
        }
-       free( (char *) vals );
+
+       new = LDAP_MALLOC( (i+1)*sizeof(char *) );  /* Alloc array of pointers */
+       if( new == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               new[i] = LDAP_STRDUP( vals[i] );   /* Dup each value */
+               if( new[i] == NULL ) {
+                       LDAP_VFREE( new );
+                       return NULL;
+               }
+       }
+       new[i] = NULL;
+
+       return new;
 }
+