Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_get_values()

The ldap_get_values() function returns a NULL-terminated array of an attribute's string values for a given entry. Use the ldap_get_values_len() function instead of this function if the attribute values are binary.

For more information, see "Getting the Values of an Attribute" on page 131.

Syntax

#include <ldap.h>
char ** ldap_get_values( LDAP *ld, LDAPMessage *entry,
   const char *target );

Parameters

This function has the following parameters:

ld

Connection handle, which is a pointer to an LDAP structure containing information about the connection to the LDAP server.

entry

Result returned by the ldap_result() or ldap_search_s() function.

target

Attribute returned by ldap_first_attribute() or ldap_next_attribute(), or the attribute as a literal string, such as "jpegPhoto" or "audio".

Returns

One of the following values:

Example

The following section of code gets and prints the values of an attribute in an entry. This example assumes that all attributes have string values.

#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a;
char **vals;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
int i;
...
/* Search the directory */
if ( ldap_search_s( ld, my_searchbase, LDAP_SCOPE_SUBTREE, my_filter, 
   NULL, 0, &result ) != LDAP_SUCCESS ) {
   ldap_perror( ld, "ldap_search_s" );
   return( 1 );
}
/* Get the first matching entry.*/
e = ldap_first_entry( ld, result );
/* Get the first matching attribute */
a = ldap_first_attribute( ld, e, &ber );
/* Get the values of the attribute */
if ( ( vals = ldap_get_values( ld, e, a ) ) != NULL ) {
   for ( i = 0; vals[i] != NULL; i++ ) {
      /* Print the name of the attribute and each value */
      printf( "%s: %s\n", a, vals[i] );
   }
   /* Free the attribute values from memory when done. */
   ldap_value_free( vals );
}
...

See Also

ldap_first_entry(), ldap_next_entry(), ldap_first_attribute(), ldap_next_attribute(), ldap_get_lang_values(), ldap_get_values_len().


Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23