1 /* fetch.c - routines for fetching data at URLs */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2017 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Kurt D. Zeilenga.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
17 /* This work was initially developed by Kurt D. Zeilenga for
18 * inclusion in OpenLDAP Software.
25 #include <ac/stdlib.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
37 #include "ldap_config.h"
42 LDAP_CONST char *urlstr )
46 if( strncasecmp( "file:", urlstr, sizeof("file:")-1 ) == 0 ) {
48 urlstr += sizeof("file:")-1;
50 /* we don't check for LDAP_DIRSEP since URLs should contain '/' */
51 if ( urlstr[0] == '/' && urlstr[1] == '/' ) {
53 /* path must be absolute if authority is present
54 * technically, file://hostname/path is also legal but we don't
55 * accept a non-empty hostname
57 if ( urlstr[0] != '/' ) {
59 /* An absolute path in improper file://C:/foo/bar format */
60 if ( urlstr[1] != ':' )
65 /* An absolute path in proper file:///C:/foo/bar format */
66 if ( urlstr[2] == ':' )
71 p = ber_strdup( urlstr );
73 /* But we should convert to LDAP_DIRSEP before use */
74 if ( LDAP_DIRSEP[0] != '/' ) {
76 while (( s = strchr( s, '/' )))
77 *s++ = LDAP_DIRSEP[0];
80 ldap_pvt_hex_unescape( p );
82 url = fopen( p, "rb" );
87 url = fetchGetURL( (char*) urlstr, "" );
97 LDAP_CONST char *urlstr,
110 url = ldif_open_url( urlstr );
118 while( (bytes = fread( buffer, 1, sizeof(buffer), url )) != 0 ) {
119 char *newp = ber_memrealloc( p, total + bytes + 1 );
126 AC_MEMCPY( &p[total], buffer, bytes );
133 char *newp = ber_memrealloc( p, 1 );