Table of Contents | Previous | Next | Index

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

ldap_get_values_len()

The ldap_get_values_len() function returns a NULL-terminated array of pointers to berval structures, each containing the length and pointer to a binary value of an attribute for a given entry. Use the ldap_get_values() routine instead of this routine if the attribute values are string values.

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

Syntax

#include <ldap.h>
struct berval ** ldap_get_values_len( 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 the first value of the jpegPhoto attribute and saves the JPEG data to a file.

#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
struct berval photo_data;
struct berval **list_of_photos;
FILE *out;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
...
/* 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 value of the jpegPhoto attribute */
if ( ( list_of_photos = ldap_get_values_len( ld, e, "jpegPhoto" ) ) != NULL ) {
   /* Prepare to write the JPEG data to a file */
   if ( ( out = fopen( "photo.jpg", "wb" ) ) == NULL ) {
      perror( "fopen" );
      return( 1 );
   }
   /* Get the first JPEG */
   photo_data = *list_of_photos[0];
   /* Write the JPEG data to a file */
   fwrite( photo_data.bv_val, photo_data.bv_len, 1, out );
   fclose( out );
   /* Free the attribute values from memory when done. */
   ldap_value_free_len( list_of_photos );
}
...

See Also

ldap_first_entry(), ldap_next_entry(), ldap_first_attribute(), ldap_next_attribute(), ldap_get_lang_values_len(), ldap_get_values().


Table of Contents | Previous | Next | Index

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