Table of Contents | Previous | Next | Index

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

ldap_url_parse()

The ldap_url_parse() function parses an LDAP URL into its components. For more information, see "Getting the Components of an LDAP URL" on page 249.

Syntax

#include <ldap.h>
int ldap_url_parse( char *url, LDAPURLDesc **ludpp );

Parameters

This function has the following parameters:

url

The URL that you want to check.

ludpp

Pointer to a structure containing the components of the URL.

Returns

One of the following values:

Example

The following section of code parses an LDAP URL and prints out each component of the URL.

#include <stdio.h>
#include <ldap.h>
...
char *my_url = "ldap://ldap.netscape.com:5000/o=Airius.com?cn,mail,telephoneNumber?sub?(sn=Jensen)";
LDAPURLDesc *ludpp;
int res, i;
...
if ( ( res = ldap_url_parse( my_url, &ludpp ) ) != 0 ) {
   switch( res ){
      case LDAP_URL_ERR_NOTLDAP:
         printf( "URL does not begin with \"ldap://\"\n" );
         break;
      case LDAP_URL_ERR_NODN:
         printf( "URL missing trailing slash after host or port\n" );
         break;
      case LDAP_URL_ERR_BADSCOPE:
         printf( "URL contains an invalid scope\n" );
         break;
      case LDAP_URL_ERR_MEM:
         printf( "Not enough memory\n" );
         break;
      default:
         printf( "Unknown error\n" );
   }
   return( 1 );
}
printf( "Components of the URL:\n" );
printf( "Host name: %s\n", ludpp->lud_host );
printf( "Port number: %d\n", ludpp->lud_port );
if ( ludpp->lud_dn != NULL ) { 
   printf( "Base entry: %s\n", ludpp->lud_dn ); 
} else { 
   printf( "Base entry: Root DN\n" ); 
} 
if ( ludpp->lud_attrs != NULL ) { 
   printf( "Attributes returned: \n" ); 
   for ( i=0; ludpp->lud_attrs[i] != NULL; i++ ) { 
      printf( "\t%s\n", ludpp->lud_attrs[i] ); 
} 
} else { 
        printf( "No attributes returned.\n" ); 
} 
printf( "Scope of the search: " );
switch( ludpp->lud_scope ) {
   case LDAP_SCOPE_BASE:
      printf( "base\n" );
      break;
   case LDAP_SCOPE_ONELEVEL:
      printf( "one\n" );
      break;
   case LDAP_SCOPE_SUBTREE:
      printf( "sub\n" );
      break;
   default:
      printf( "Unknown scope\n" );
}
printf( "Filter: %s\n", ludpp->lud_filter );
...

See Also

ldap_free_urldesc().


Table of Contents | Previous | Next | Index

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