2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
23 #include <ac/stdlib.h>
26 #include <ac/socket.h>
27 #include <ac/string.h>
33 ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
41 assert( LDAP_VALID( ld ) );
42 assert( entry != NULL );
43 assert( target != NULL );
46 LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values\n", 0, 0, 0 );
48 Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
53 /* skip sequence, dn, sequence of, and snag the first attr */
54 if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
55 ld->ld_errno = LDAP_DECODING_ERROR;
59 if ( strcasecmp( target, attr ) == 0 )
62 /* break out on success, return out on error */
67 if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
68 ld->ld_errno = LDAP_DECODING_ERROR;
72 if ( strcasecmp( target, attr ) == 0 )
81 * if we get this far, we've found the attribute and are sitting
82 * just before the set of values.
85 if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
86 ld->ld_errno = LDAP_DECODING_ERROR;
94 ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
101 assert( ld != NULL );
102 assert( LDAP_VALID( ld ) );
103 assert( entry != NULL );
104 assert( target != NULL );
107 LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values_len\n", 0, 0, 0 );
109 Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
112 ber = *entry->lm_ber;
114 /* skip sequence, dn, sequence of, and snag the first attr */
115 if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
116 ld->ld_errno = LDAP_DECODING_ERROR;
120 if ( strcasecmp( target, attr ) == 0 )
123 /* break out on success, return out on error */
128 if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
129 ld->ld_errno = LDAP_DECODING_ERROR;
133 if ( strcasecmp( target, attr ) == 0 )
141 * if we get this far, we've found the attribute and are sitting
142 * just before the set of values.
145 if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
146 ld->ld_errno = LDAP_DECODING_ERROR;
154 ldap_count_values( char **vals )
161 for ( i = 0; vals[i] != NULL; i++ )
168 ldap_count_values_len( struct berval **vals )
170 return( ldap_count_values( (char **) vals ) );
174 ldap_value_free( char **vals )
180 ldap_value_free_len( struct berval **vals )
182 ber_bvecfree( vals );
186 ldap_value_dup( char *const *vals )
195 for( i=0; vals[i]; i++ ) {
196 ; /* Count the number of values */
203 new = LDAP_MALLOC( (i+1)*sizeof(char *) ); /* Alloc array of pointers */
208 for( i=0; vals[i]; i++ ) {
209 new[i] = LDAP_STRDUP( vals[i] ); /* Dup each value */
210 if( new[i] == NULL ) {