1
/* $OpenLDAP: pkg/ldap/libraries/libldap/getvalues.c,v 1.26.2.3 2008/02/11 23:26:41 kurt Exp $ */
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
* Copyright 1998-2008 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 );
45
Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
49
/* skip sequence, dn, sequence of, and snag the first attr */
50
if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
51
ld->ld_errno = LDAP_DECODING_ERROR;
55
if ( strcasecmp( target, attr ) == 0 )
58
/* break out on success, return out on error */
63
if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
64
ld->ld_errno = LDAP_DECODING_ERROR;
68
if ( strcasecmp( target, attr ) == 0 )
77
* if we get this far, we've found the attribute and are sitting
78
* just before the set of values.
81
if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
82
ld->ld_errno = LDAP_DECODING_ERROR;
90
ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
98
assert( LDAP_VALID( ld ) );
99
assert( entry != NULL );
100
assert( target != NULL );
102
Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
104
ber = *entry->lm_ber;
106
/* skip sequence, dn, sequence of, and snag the first attr */
107
if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
108
ld->ld_errno = LDAP_DECODING_ERROR;
112
if ( strcasecmp( target, attr ) == 0 )
115
/* break out on success, return out on error */
120
if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
121
ld->ld_errno = LDAP_DECODING_ERROR;
125
if ( strcasecmp( target, attr ) == 0 )
133
* if we get this far, we've found the attribute and are sitting
134
* just before the set of values.
137
if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
138
ld->ld_errno = LDAP_DECODING_ERROR;
146
ldap_count_values( char **vals )
153
for ( i = 0; vals[i] != NULL; i++ )
160
ldap_count_values_len( struct berval **vals )
162
return( ldap_count_values( (char **) vals ) );
166
ldap_value_free( char **vals )
172
ldap_value_free_len( struct berval **vals )
174
ber_bvecfree( vals );
178
ldap_value_dup( char *const *vals )
187
for( i=0; vals[i]; i++ ) {
188
; /* Count the number of values */
195
new = LDAP_MALLOC( (i+1)*sizeof(char *) ); /* Alloc array of pointers */
200
for( i=0; vals[i]; i++ ) {
201
new[i] = LDAP_STRDUP( vals[i] ); /* Dup each value */
202
if( new[i] == NULL ) {