openldap/libraries/libldap/getvalues.c
Kurt Zeilenga 669b8f4047 ber_int_t, ber_tag_t, ber_socket_t, ber_len_t
added lber_types.h.nt, lber_types.h.in
removal of NULLxxx internal macros (in favor of NULL).
ch_free added to slapd,slurpd/ch_malloc.c
#define free ch_free (should be removed after s/free/ch_free/g) in proto-slap.h
ch_malloc and friends use ber_memalloc and friends
1999-06-18 23:53:05 +00:00

159 lines
2.9 KiB
C

/*
* 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.
*
* getvalues.c
*/
#include "portable.h"
#include <stdio.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, LDAP_CONST char *target )
{
BerElement ber;
char *attr;
int found = 0;
char **vals;
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 ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return( NULL );
}
if ( strcasecmp( target, attr ) == 0 )
found = 1;
/* break out on success, return out on error */
while ( ! found ) {
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.
*/
if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return( NULL );
}
return( vals );
}
struct berval **
ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
{
BerElement ber;
char *attr;
int found = 0;
struct berval **vals;
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 ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return( NULL );
}
if ( strcasecmp( target, attr ) == 0 )
found = 1;
/* break out on success, return out on error */
while ( ! found ) {
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.
*/
if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return( NULL );
}
return( vals );
}
int
ldap_count_values( char **vals )
{
int i;
if ( vals == NULL )
return( 0 );
for ( i = 0; vals[i] != NULL; i++ )
; /* NULL */
return( i );
}
int
ldap_count_values_len( struct berval **vals )
{
return( ldap_count_values( (char **) vals ) );
}
void
ldap_value_free( char **vals )
{
LDAP_VFREE( vals );
}
void
ldap_value_free_len( struct berval **vals )
{
ber_bvecfree( vals );
}