* LIBLDAP url.c -- LDAP URL related routines
*
* LDAP URLs look like this:
- * ldap[s]://host:port/dn[[?attributes[?scope[?filter[?extensions]]]]
+ * ldap[s]://host:port[/[dn[?[attributes][?[scope][?[filter][?exts]]]]]]
*
* where:
* attributes is a comma separated list
/* scan forward for '/' that marks end of hostport and begin. of dn */
p = strchr( url, '/' );
- if( p == NULL ) {
- LDAP_FREE( url );
- ldap_free_urldesc( ludp );
- return LDAP_URL_ERR_BADURL;
+ if( p != NULL ) {
+ /* terminate hostport; point to start of dn */
+ *p++ = '\0';
}
- /* terminate hostport; point to start of dn */
- *p++ = '\0';
-
if (( q = strchr( url, ':' )) != NULL ) {
*q++ = '\0';
hex_unescape( q );
return LDAP_URL_ERR_MEM;
}
+ if( p == NULL ) {
+ LDAP_FREE( url );
+ *ludpp = ludp;
+ return LDAP_URL_SUCCESS;
+ }
+
/* scan forward for '?' that may marks end of dn */
q = strchr( p, '?' );
- if( q == NULL ) {
- /* no '?' */
+ if( q != NULL ) {
+ /* terminate dn part */
+ *q++ = '\0';
+ }
+
+ if( *p != '\0' ) {
+ /* parse dn part */
hex_unescape( p );
ludp->lud_dn = LDAP_STRDUP( p );
-
- if( ludp->lud_dn == NULL ) {
- LDAP_FREE( url );
- ldap_free_urldesc( ludp );
- return LDAP_URL_ERR_MEM;
- }
-
- LDAP_FREE( url );
- *ludpp = ludp;
- return LDAP_URL_SUCCESS;
+ } else {
+ ludp->lud_dn = LDAP_STRDUP( "" );
}
- *q++ = '\0';
- hex_unescape( p );
- ludp->lud_dn = LDAP_STRDUP( p );
-
if( ludp->lud_dn == NULL ) {
LDAP_FREE( url );
ldap_free_urldesc( ludp );
return LDAP_URL_ERR_MEM;
}
+ if( q == NULL ) {
+ /* no more */
+ LDAP_FREE( url );
+ *ludpp = ludp;
+ return LDAP_URL_SUCCESS;
+ }
+
/* scan forward for '?' that may marks end of attributes */
p = q;
q = strchr( p, '?' );
if( q != NULL ) {
+ /* terminate attributes part */
*q++ = '\0';
}
+
if( *p != '\0' ) {
+ /* parse attributes */
hex_unescape( p );
ludp->lud_attrs = ldap_str2charray( p, "," );
return LDAP_URL_ERR_BADATTRS;
}
}
+
if ( q == NULL ) {
- /* no '?' */
+ /* no more */
LDAP_FREE( url );
*ludpp = ludp;
return LDAP_URL_SUCCESS;
q = strchr( p, '?' );
if( q != NULL ) {
+ /* terminate the scope part */
*q++ = '\0';
}
+
if( *p != '\0' ) {
+ /* parse the scope */
hex_unescape( p );
ludp->lud_scope = str2scope( p );
return LDAP_URL_ERR_BADSCOPE;
}
}
+
if ( q == NULL ) {
- /* no '?' */
+ /* no more */
LDAP_FREE( url );
*ludpp = ludp;
return LDAP_URL_SUCCESS;
q = strchr( p, '?' );
if( q != NULL ) {
+ /* terminate the filter part */
*q++ = '\0';
}
+
if( *p != '\0' ) {
+ /* parse the filter */
hex_unescape( p );
if( ! *p ) {
return LDAP_URL_ERR_MEM;
}
}
+
if ( q == NULL ) {
- /* no '?' */
+ /* no more */
LDAP_FREE( url );
*ludpp = ludp;
return LDAP_URL_SUCCESS;
return LDAP_URL_ERR_BADURL;
}
+ /* parse the extensions */
ludp->lud_exts = ldap_str2charray( p, "," );
if( ludp->lud_exts == NULL ) {
}
if( i == 0 ) {
+ /* must have 1 or more */
ldap_charray_free( ludp->lud_exts );
LDAP_FREE( url );
ldap_free_urldesc( ludp );
return LDAP_URL_ERR_BADEXTS;
}
+ /* no more */
*ludpp = ludp;
-
LDAP_FREE( url );
return LDAP_URL_SUCCESS;
}