]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/fetch.c
cleanup
[openldap] / libraries / liblutil / fetch.c
index fb9e5ddaf0c3fa270d82f7d1cf2724faa5c0c75b..661bc1e75b164b45cc9be39466a2d942ca1a2fe8 100644 (file)
@@ -1,9 +1,8 @@
 /* fetch.c - routines for fetching data at URLs */
 /* $OpenLDAP$ */
-/* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2004 The OpenLDAP Foundation.
+ * Copyright 1999-2006 The OpenLDAP Foundation.
  * Portions Copyright 1999-2003 Kurt D. Zeilenga.
  * All rights reserved.
  *
 #include "ldap_config.h"
 #include "ldif.h"
 
-int
-ldif_fetch_url(
-    LDAP_CONST char    *urlstr,
-    char       **valuep,
-    ber_len_t *vlenp
-)
+FILE *
+ldif_open_url(
+       LDAP_CONST char *urlstr )
 {
        FILE *url;
-       char buffer[1024];
        char *p = NULL;
-       size_t total;
-       size_t bytes;
-
-       *valuep = NULL;
-       *vlenp = 0;
-
 #ifdef HAVE_FETCH
        url = fetchGetURL( (char*) urlstr, "" );
 
@@ -62,11 +51,11 @@ ldif_fetch_url(
        if( strncasecmp( "file://", urlstr, sizeof("file://")-1 ) == 0 ) {
                p = strchr( &urlstr[sizeof("file://")-1], '/' );
                if( p == NULL ) {
-                       return -1;
+                       return NULL;
                }
 
                /* we don't check for LDAP_DIRSEP since URLs should contain '/' */
-               if( *p != '/' ) {
+               if( p[1] == '.' && ( p[2] == '/' || ( p[2] == '.' && p[3] == '/' ))) {
                        /* skip over false root */
                        p++;
                }
@@ -76,10 +65,30 @@ ldif_fetch_url(
 
                url = fopen( p, "rb" );
 
+               ber_memfree( p );
        } else {
-               return -1;
+               return NULL;
        }
 #endif
+       return url;
+}
+
+int
+ldif_fetch_url(
+    LDAP_CONST char    *urlstr,
+    char       **valuep,
+    ber_len_t *vlenp )
+{
+       FILE *url;
+       char buffer[1024];
+       char *p = NULL;
+       size_t total;
+       size_t bytes;
+
+       *valuep = NULL;
+       *vlenp = 0;
+
+       url = ldif_open_url( urlstr );
 
        if( url == NULL ) {
                return -1;