Table of Contents | Previous | Next | Index

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

ldap_first_attribute()

The ldap_first_attribute() function returns the name of the first attribute in a entry returned by the ldap_first_entry() function, the ldap_next_entry() function, or the ldap_result() function.

For more information, see "Getting Attributes from an Entry" on page 129.

Syntax

#include <ldap.h>
char * ldap_first_attribute( LDAP *ld, LDAPMessage *entry,
   BerElement **ber );

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

Pointer to the LDAPMessage structure representing the entry returned by the ldap_first_entry() or

ldap_next_entry() function.

ber

A pointer to a BerElement allocated to keep track of its current position. Pass this pointer to subsequent calls to ldap_next_attribute() to step through the entry's attributes.

Returns

One of the following values:

Example

The following section of code retrieves each attribute for an entry.

#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a;
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 );
/* Retrieve the attributes the entry */
   for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL; 
    a = ldap_next_attribute( ld, e, ber ) ) {
      ...
      /* Code to get and manipulate attribute values */
      ...
      }
      ldap_memfree( a );
   }
   /* Free the BerElement from memory when done */
   if ( ber != NULL ) {
      ldap_ber_free( ber, 0 );
   }
...

See Also

ldap_first_entry(), ldap_next_entry(), ldap_next_attribute().


Table of Contents | Previous | Next | Index

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