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.
#include <ldap.h>
struct berval ** ldap_get_values_len( LDAP *ld,
LDAPMessage *entry, const char *target );
ld |
Connection handle, which is a pointer to an |
entry |
Result returned by the |
target |
Attribute returned by |
LDAP structure. To get the error code, call the ldap_get_lderrno() function. (See "Result Codes" on page 691 for a complete listing of error codes.) 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 );
}
...
ldap_first_entry(), ldap_next_entry(), ldap_first_attribute(), ldap_next_attribute(), ldap_get_lang_values_len(), ldap_get_values().
Last Updated: 10/01/98 17:06:23