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.
#include <ldap.h>
int ldap_url_parse( char *url, LDAPURLDesc **ludpp );
url | |
ludpp | Pointer to a structure containing the components of the URL. |
LDAP_SUCCESS if successful. LDAP_URL_ERR_NOTLDAP if the URL does not begin with the "ldap://" or "ldaps://" prefix. LDAP_URL_ERR_NODN if the URL missing trailing slash after host or port.LDAP_URL_ERR_BADSCOPE if the scope within the URL is invalid. LDAP_URL_ERR_MEM if not enough free memory is available for this operation.LDAP_URL_ERR_PARAM if an invalid argument was passed to the function. #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 );
...
ldap_free_urldesc().
Last Updated: 10/01/98 17:06:23