]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/url.c
Added support for BDB 4.1.17
[openldap] / libraries / libldap / url.c
index c58ba59f7fdaaa78507d28403ec3dd99d7fe1118..8bf8bd56d56f7a9d86cb7d1c5f897c48a86f49af 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /*  Portions
@@ -17,7 +17,7 @@
  *   scope is one of these three strings:  base one sub (default=base)
  *   filter is an string-represented filter as in RFC 2254
  *
- *  e.g.,  ldap://host:port/dc=com?o,cn?base?o=openldap?extension
+ *  e.g.,  ldap://host:port/dc=com?o,cn?base?(o=openldap)?extension
  *
  *  We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
  */
@@ -34,7 +34,6 @@
 
 #include "ldap-int.h"
 
-
 /* local functions */
 static const char* skip_url_prefix LDAP_P((
        const char *url,
@@ -69,7 +68,8 @@ int ldap_pvt_url_scheme2proto( const char *scheme )
        return -1;
 }
 
-LDAP_F(int) ldap_pvt_url_scheme2tls( const char *scheme )
+int
+ldap_pvt_url_scheme2tls( const char *scheme )
 {
        assert( scheme );
 
@@ -156,10 +156,10 @@ skip_url_prefix(
        int *enclosedp,
        const char **scheme )
 {
-/*
- * 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
- */
+       /*
       * 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
       */
        const char *p;
 
        if ( url == NULL ) {
@@ -286,6 +286,7 @@ static int hex_escape( char *buf, const char *s, int list )
                }
        }
 
+       buf[pos] = '\0';
        return pos;
 }
 
@@ -443,7 +444,11 @@ ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
         * because a call to LDAP_INT_GLOBAL_OPT() will try to allocate
         * the options and cause infinite recursion
         */
+#ifdef NEW_LOGGING
+       LDAP_LOG ( OPERATION, ENTRY, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
+#else
        Debug( LDAP_DEBUG_TRACE, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
+#endif
 #endif
 
        *ludpp = NULL;  /* pessimistic */
@@ -766,6 +771,10 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
        if ((*ludpp)->lud_port == 0) {
                if( strcmp((*ludpp)->lud_scheme, "ldap") == 0 ) {
                        (*ludpp)->lud_port = LDAP_PORT;
+#ifdef LDAP_CONNECTIONLESS
+               } else if( strcmp((*ludpp)->lud_scheme, "cldap") == 0 ) {
+                       (*ludpp)->lud_port = LDAP_PORT;
+#endif
                } else if( strcmp((*ludpp)->lud_scheme, "ldaps") == 0 ) {
                        (*ludpp)->lud_port = LDAPS_PORT;
                }
@@ -876,12 +885,12 @@ ldap_url_parselist (LDAPURLDesc **ludlist, const char *url )
        LDAPURLDesc *ludp;
        char **urls;
 
-       *ludlist = NULL;
+       assert( ludlist != NULL );
+       assert( url != NULL );
 
-       if (url == NULL)
-               return LDAP_PARAM_ERROR;
+       *ludlist = NULL;
 
-       urls = ldap_str2charray((char *)url, ", ");
+       urls = ldap_str2charray(url, ", ");
        if (urls == NULL)
                return LDAP_NO_MEMORY;
 
@@ -913,12 +922,12 @@ ldap_url_parsehosts(
        LDAPURLDesc *ludp;
        char **specs, *p;
 
-       *ludlist = NULL;
+       assert( ludlist != NULL );
+       assert( hosts != NULL );
 
-       if (hosts == NULL)
-               return LDAP_PARAM_ERROR;
+       *ludlist = NULL;
 
-       specs = ldap_str2charray((char *)hosts, ", ");
+       specs = ldap_str2charray(hosts, ", ");
        if (specs == NULL)
                return LDAP_NO_MEMORY;
 
@@ -1109,92 +1118,14 @@ ldap_free_urldesc( LDAPURLDesc *ludp )
        LDAP_FREE( ludp );
 }
 
-
-
-int
-ldap_url_search( LDAP *ld, LDAP_CONST char *url, int attrsonly )
+static int
+ldap_int_unhex( int c )
 {
-       int             err;
-       LDAPURLDesc     *ludp;
-       BerElement      *ber;
-       LDAPreqinfo  bind;
-
-       assert( ld != NULL );
-       assert( LDAP_VALID( ld ) );
-
-       if ( ldap_url_parse( url, &ludp ) != 0 ) {
-               ld->ld_errno = LDAP_PARAM_ERROR;
-               return( -1 );
-       }
-
-       if( ludp->lud_crit_exts ) {
-               /* we don't support any extension (yet) */
-               ld->ld_errno = LDAP_NOT_SUPPORTED;
-               return( -1 );
-       }
-
-       ber = ldap_build_search_req( ld, ludp->lud_dn, ludp->lud_scope,
-           ludp->lud_filter, ludp->lud_attrs, attrsonly, NULL, NULL,
-               -1, -1 );
-
-       if ( ber == NULL ) {
-               err = -1;
-       } else {
-               bind.ri_request = LDAP_REQ_SEARCH;
-               bind.ri_msgid = ld->ld_msgid;
-               bind.ri_url = (char *)url;
-               err = ldap_send_server_request(
-                                       ld, ber, ld->ld_msgid, NULL,
-                                       NULL, NULL, &bind );
-       }
-
-       ldap_free_urldesc( ludp );
-       return( err );
-}
-
-
-int
-ldap_url_search_st( LDAP *ld, LDAP_CONST char *url, int attrsonly,
-       struct timeval *timeout, LDAPMessage **res )
-{
-       int     msgid;
-
-       if (( msgid = ldap_url_search( ld, url, attrsonly )) == -1 ) {
-               return( ld->ld_errno );
-       }
-
-       if ( ldap_result( ld, msgid, 1, timeout, res ) == -1 ) {
-               return( ld->ld_errno );
-       }
-
-       if ( ld->ld_errno == LDAP_TIMEOUT ) {
-               (void) ldap_abandon( ld, msgid );
-               ld->ld_errno = LDAP_TIMEOUT;
-               return( ld->ld_errno );
-       }
-
-       return( ldap_result2error( ld, *res, 0 ));
-}
-
-
-int
-ldap_url_search_s(
-       LDAP *ld, LDAP_CONST char *url, int attrsonly, LDAPMessage **res )
-{
-       int     msgid;
-
-       if (( msgid = ldap_url_search( ld, url, attrsonly )) == -1 ) {
-               return( ld->ld_errno );
-       }
-
-       if ( ldap_result( ld, msgid, 1, (struct timeval *)NULL, res ) == -1 ) {
-               return( ld->ld_errno );
-       }
-
-       return( ldap_result2error( ld, *res, 0 ));
+       return( c >= '0' && c <= '9' ? c - '0'
+           : c >= 'A' && c <= 'F' ? c - 'A' + 10
+           : c - 'a' + 10 );
 }
 
-
 void
 ldap_pvt_hex_unescape( char *s )
 {
@@ -1206,12 +1137,14 @@ ldap_pvt_hex_unescape( char *s )
 
        for ( p = s; *s != '\0'; ++s ) {
                if ( *s == '%' ) {
-                       if ( *++s != '\0' ) {
-                               *p = ldap_pvt_unhex( *s ) << 4;
+                       if ( *++s == '\0' ) {
+                               break;
                        }
-                       if ( *++s != '\0' ) {
-                               *p++ += ldap_pvt_unhex( *s );
+                       *p = ldap_int_unhex( *s ) << 4;
+                       if ( *++s == '\0' ) {
+                               break;
                        }
+                       *p++ += ldap_int_unhex( *s );
                } else {
                        *p++ = *s;
                }
@@ -1221,10 +1154,3 @@ ldap_pvt_hex_unescape( char *s )
 }
 
 
-int
-ldap_pvt_unhex( int c )
-{
-       return( c >= '0' && c <= '9' ? c - '0'
-           : c >= 'A' && c <= 'F' ? c - 'A' + 10
-           : c - 'a' + 10 );
-}