Table of Contents | Previous | Next | Index

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

ldap_getfirstfilter()

The ldap_getfirstfilter() function retrieves the first filter that is appropriate for a given value. For more information, see "Retrieving Filters" on page 161.

Syntax

#include <ldap.h>
LDAPFiltInfo * ldap_getfirstfilter( LDAPFiltDesc *lfdp,
   char *tagpat, char *value );

Parameters

This function has the following parameters:

lfdp

Pointer to an LDAPFiltDesc structure.

tagpat

Regular expression for a tag in the filter configuration.

value

Value for which to find the first appropriate filter.

Returns

One of the following values:

Example

The following section of code is based on the getfilt command-line program example provided with the Directory SDK. The program prompts the user to enter search criteria. Based on the criteria entered, the program retrieves filters that match the search criteria. The example uses the filter configuration file shown in "Understanding the Configuration File Syntax" on page 158.

#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a, *dn;
char **vals;
int i;
LDAPFiltDesc *ldfp;
LDAPFiltInfo *ldfi;
char buf[ 80 ]; /* Contains the search criteria */
int found;
...
/* Load the filter configuration file into an LDAPFiltDesc structure */
if ( ( ldfp = ldap_init_getfilter( "myfilters.conf" ) ) == NULL ) {
   perror( "Cannot open filter configuration file" );
   return( 1 );
}
/* Read a string to search for */ 
printf( "Enter a string to search for: " ); 
gets( buf ); 
if ( strlen( buf ) == 0 ) { 
   fprintf( stderr, "usage: %s search-string\n", argv[ 0 ]); 
   return( 1 ); 
}
/* Select a filter to use when searching for the value in buf */
found = 0;
for ( ldfi = ldap_getfirstfilter( ldfp, "people", buf ); ldfi != NULL; ldfi = ldap_getnextfilter( ldfp ) ) {
   /* Use the selected filter to search the directory */
   if ( ldap_search_s( ld, "o=Airius.com, ldfi->lfi_scope, 
    ldfi->lfi_filter, NULL, 0, &result ) != LDAP_SUCCESS ) {
      ldap_perror( ld, "ldap_search_s" );
      return( 1 );
   } else {
      /* Once a filter gets results back, stop iterating through the different filters */ 
      if ( ( found = ldap_count_entries( ld, result ) > 0 ) ) {
         break;
      } else { 
         ldap_msgfree( result );
      }
   }
}
if ( found == 0 ) {
   printf( "No matching entries found.\n" );
} else {
   printf( "Found %d %s match%s for \"%s\"\n\n", found, 
    ldfi->lfi_desc, found == 1 ? "" : "es", buf );
}
ldap_msgfree( result );
ldap_getfilter_free( ldfp );
...

See Also

ldap_init_getfilter(), ldap_init_getfilter_buf(), ldap_getnextfilter().


Table of Contents | Previous | Next | Index

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