]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/url.c
Update ld->ld_errno if LDAP_DECODING_ERROR...
[openldap] / libraries / libldap / url.c
index 4f0a5635f253403ecce56246ec5eb75a7c9c6b28..b632c688f8da78a9b5014bf506d60ab48bef76a9 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
@@ -40,8 +41,6 @@ static const char* skip_url_prefix LDAP_P((
        const char *url,
        int *enclosedp,
        int *ldaps ));
-static void hex_unescape LDAP_P(( char *s ));
-static int unhex( char c );
 
 
 int
@@ -88,13 +87,13 @@ skip_url_prefix(
  * return non-zero if this looks like a LDAP URL; zero if not
  * if non-zero returned, *urlp will be moved past "ldap://" part of URL
  */
-       char* p;
+       const char *p;
 
        if ( url == NULL ) {
                return( NULL );
        }
 
-       p = (char *) url;
+       p = url;
 
        /* skip leading '<' (if any) */
        if ( *p == '<' ) {
@@ -210,6 +209,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
     ludp->lud_filter = NULL;
        ludp->lud_ldaps = ldaps;
        ludp->lud_scope = LDAP_SCOPE_BASE;
+
        ludp->lud_filter = LDAP_STRDUP("(objectClass=*)");
 
        if( ludp->lud_filter == NULL ) {
@@ -228,7 +228,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
 
        if (( q = strchr( url, ':' )) != NULL ) {
                *q++ = '\0';
-               hex_unescape( q );
+               ldap_pvt_hex_unescape( q );
 
                if( *q == '\0' ) {
                        LDAP_FREE( url );
@@ -239,7 +239,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
                ludp->lud_port = atoi( q );
        }
 
-       hex_unescape( url );
+       ldap_pvt_hex_unescape( url );
        ludp->lud_host = LDAP_STRDUP( url );
 
        if( ludp->lud_host == NULL ) {
@@ -264,7 +264,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
 
        if( *p != '\0' ) {
                /* parse dn part */
-               hex_unescape( p );
+               ldap_pvt_hex_unescape( p );
                ludp->lud_dn = LDAP_STRDUP( p );
        } else {
                ludp->lud_dn = LDAP_STRDUP( "" );
@@ -294,7 +294,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
 
        if( *p != '\0' ) {
                /* parse attributes */
-               hex_unescape( p );
+               ldap_pvt_hex_unescape( p );
                ludp->lud_attrs = ldap_str2charray( p, "," );
 
                if( ludp->lud_attrs == NULL ) {
@@ -322,7 +322,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
 
        if( *p != '\0' ) {
                /* parse the scope */
-               hex_unescape( p );
+               ldap_pvt_hex_unescape( p );
                ludp->lud_scope = str2scope( p );
 
                if( ludp->lud_scope == -1 ) {
@@ -350,7 +350,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
 
        if( *p != '\0' ) {
                /* parse the filter */
-               hex_unescape( p );
+               ldap_pvt_hex_unescape( p );
 
                if( ! *p ) {
                        /* missing filter */
@@ -359,6 +359,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
                        return LDAP_URL_ERR_BADFILTER;
                }
 
+               LDAP_FREE( ludp->lud_filter );
                ludp->lud_filter = LDAP_STRDUP( p );
 
                if( ludp->lud_filter == NULL ) {
@@ -396,7 +397,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
        }
 
        for( i=0; ludp->lud_exts[i] != NULL; i++ ) {
-               hex_unescape( ludp->lud_exts[i] );
+               ldap_pvt_hex_unescape( ludp->lud_exts[i] );
        }
 
        if( i == 0 ) {
@@ -542,8 +543,8 @@ ldap_url_search_s(
 }
 
 
-static void
-hex_unescape( char *s )
+void
+ldap_pvt_hex_unescape( char *s )
 {
 /*
  * Remove URL hex escapes from s... done in place.  The basic concept for
@@ -554,10 +555,10 @@ hex_unescape( char *s )
        for ( p = s; *s != '\0'; ++s ) {
                if ( *s == '%' ) {
                        if ( *++s != '\0' ) {
-                               *p = unhex( *s ) << 4;
+                               *p = ldap_pvt_unhex( *s ) << 4;
                        }
                        if ( *++s != '\0' ) {
-                               *p++ += unhex( *s );
+                               *p++ += ldap_pvt_unhex( *s );
                        }
                } else {
                        *p++ = *s;
@@ -568,8 +569,8 @@ hex_unescape( char *s )
 }
 
 
-static int
-unhex( char c )
+int
+ldap_pvt_unhex( int c )
 {
        return( c >= '0' && c <= '9' ? c - '0'
            : c >= 'A' && c <= 'F' ? c - 'A' + 10