]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/fetch.c
ITS#5129 fix alock_close with Quick mode
[openldap] / libraries / liblutil / fetch.c
index 49a72c6e4ca4b0a9c3c5aff53b6098408d829cc9..104aa45179678ab031b5467ce31be58a948e81b5 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
  * Portions Copyright 1999-2003 Kurt D. Zeilenga.
  * All rights reserved.
  *
 #include "ldap_config.h"
 #include "ldif.h"
 
+FILE *
+ldif_open_url(
+       LDAP_CONST char *urlstr )
+{
+       FILE *url;
+
+       if( strncasecmp( "file:", urlstr, sizeof("file:")-1 ) == 0 ) {
+               char *p;
+               urlstr += sizeof("file:")-1;
+
+               /* we don't check for LDAP_DIRSEP since URLs should contain '/' */
+               if ( urlstr[0] == '/' && urlstr[1] == '/' ) {
+                       urlstr += 2;
+                       /* path must be absolute if authority is present */
+                       if ( urlstr[0] != '/' )
+                               return NULL;
+               }
+
+               p = ber_strdup( urlstr );
+               ldap_pvt_hex_unescape( p );
+
+               url = fopen( p, "rb" );
+
+               ber_memfree( p );
+       } else {
+#ifdef HAVE_FETCH
+               url = fetchGetURL( (char*) urlstr, "" );
+#else
+               url = NULL;
+#endif
+       }
+       return url;
+}
+
 int
 ldif_fetch_url(
     LDAP_CONST char    *urlstr,
     char       **valuep,
-    ber_len_t *vlenp
-)
+    ber_len_t *vlenp )
 {
        FILE *url;
        char buffer[1024];
@@ -54,31 +87,7 @@ ldif_fetch_url(
        *valuep = NULL;
        *vlenp = 0;
 
-#ifdef HAVE_FETCH
-       url = fetchGetURL( (char*) urlstr, "" );
-
-#else
-       if( strncasecmp( "file://", urlstr, sizeof("file://")-1 ) == 0 ) {
-               p = strchr( &urlstr[sizeof("file://")-1], '/' );
-               if( p == NULL ) {
-                       return -1;
-               }
-
-               /* we don't check for LDAP_DIRSEP since URLs should contain '/' */
-               if( *p != '/' ) {
-                       /* skip over false root */
-                       p++;
-               }
-
-               p = ber_strdup( p );
-               ldap_pvt_hex_unescape( p );
-
-               url = fopen( p, "rb" );
-
-       } else {
-               return -1;
-       }
-#endif
+       url = ldif_open_url( urlstr );
 
        if( url == NULL ) {
                return -1;