]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getvalues.c
Merge remote branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / libraries / libldap / getvalues.c
index 2833e18f5d362aea35b0a1aa43f8a824a18878df..95fd784e5c98577ae992216856737fdd38881859 100644 (file)
@@ -1,12 +1,19 @@
-/*
- * 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-2012 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
- *  getvalues.c
+ * 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"
@@ -30,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 );
        }
@@ -48,7 +60,7 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
                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 );
                }
@@ -82,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 );
        }
@@ -100,7 +117,7 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
                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 );
                }
@@ -156,3 +173,39 @@ ldap_value_free_len( struct berval **vals )
 {
        ber_bvecfree( vals );
 }
+
+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;
+       }
+
+       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;
+}
+