fileurl.c revision 1
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * The contents of this file are subject to the Netscape Public 2N/A * License Version 1.1 (the "License"); you may not use this file 2N/A * except in compliance with the License. You may obtain a copy of 2N/A * Software distributed under the License is distributed on an "AS 2N/A * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 2N/A * implied. See the License for the specific language governing 2N/A * rights and limitations under the License. 2N/A * The Original Code is Mozilla Communicator client code, released 2N/A * The Initial Developer of the Original Code is Netscape 2N/A * Communications Corporation. Portions created by Netscape are 2N/A * Copyright (C) 1998-1999 Netscape Communications Corporation. All 2N/A * Used by ldapmodify. 2N/A#
endif /* SOLARIS_LDAP_CMD */ * Convert a file URL to a local path. * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and *localpathp is * set point to an allocated string. If not, an different LDAPTOOL_FILEURL_ * error code is returned. * See RFCs 1738 and 2396 for a specification for file URLs... but * Netscape Navigator seems to be a bit more lenient in what it will * accept, especially on Windows). * This function parses file URLs of these three forms: * file://host/path (rejected with a ...NONLOCAL error) * On Windows, we convert leading drive letters of the form C| to C: * and if a drive letter is present we strip off the slash that precedes * path. Otherwise, the leading slash is returned. * Make sure this is a file URL we can handle. path =
fileurl +
5;
/* skip past "file:" scheme prefix */ ++
path;
/* skip past '/' at end of "file:/" */ * Make sure it is for the local host. }
else {
/* URL is of the form file:/path */ * The remainder is now of the form /path. On Windows, skip past the * leading slash if a drive letter is present. * Duplicate the path so we can safely alter it. * Unescape any %HH sequences. * Convert forward slashes to backslashes for Windows. Also, * if we see a drive letter / vertical bar combination (e.g., c|) * at the beginning of the path, replace the '|' with a ':'. * Convert a local path to a file URL. * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and *urlp is * set point to an allocated string. If not, an different LDAPTOOL_FILEURL_ * error code is returned. At present, the only possible error is * LDAPTOOL_FILEURL_NOMEMORY. * This function produces file URLs of the form file:path. * On Windows, we convert leading drive letters to C|. * Allocate space for the URL, taking into account that path may * expand during the hex escaping process. * On Windows, convert leading drive letters (e.g., C:) to the correct URL * Append the path, encoding any URL-special characters using the %HH * On Windows, convert backwards slashes in the path to forward ones. * Populate *bvp from "value" of length "vlen." * If recognize_url_syntax is non-zero, :<fileurl is recognized. * If always_try_file is recognized and no file URL was found, an * attempt is made to stat and read the value as if it were the name * If reporterrs is non-zero, specific error messages are printed to * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len * and bvp->bv_val are set (the latter is set to malloc'd memory). * Upon failure, a different LDAPTOOL_FILEURL_ error code is returned. /* recognize "attr :< url" syntax if LDIF version is >= 1 */ * We only support file:// URLs for now. gettext(
"%s: unable to process URL \"%s\" --" gettext(
"%s: unable to process URL \"%s\" -- only" " local file:// URLs are supported.\n"),
gettext(
"%s: %s is a directory, not a file\n"),
gettext(
"%s: unable to process URL \"%s\"" * Map an LDAPTOOL_FILEURL_ error code to an LDAP error code (crude). * Populate *bvp with the contents of the file named by "path". * If reporterrs is non-zero, specific error messages are printed to * If successful, LDAPTOOL_FILEURL_SUCCESS is returned and bvp->bv_len * and bvp->bv_val are set (the latter is set to malloc'd memory). * Upon failure, a different LDAPTOOL_FILEURL_ error code is returned. #
endif /* SOLARIS_LDAP_CMD */ * Return a non-zero value if the string s begins with prefix and zero if not. * Remove URL hex escapes from s... done in place. The basic concept for * this routine is borrowed from the WWW library HTUnEscape() routine. * A similar function called nsldapi_hex_unescape can be found in for ( p = s; *s !=
'\0'; ++s ) {
* Return the integer equivalent of one hex digit (in c). return( c >=
'0' && c <=
'9' ? c -
'0' : c >=
'A' && c <=
'F' ? c -
'A' +
10 ( c >=
'@' && c <=
'Z' ) || \
( c >=
'a' && c <=
'z' ))
* Like strcat(), except if any URL-special characters are found in s2 * they are escaped using the %HH convention and backslash characters are * converted to forward slashes on Windows. * Maximum space needed in s1 is 3 * strlen( s2 ) + 1. * A similar function that does not convert the slashes called char *
hexdig =
"0123456789ABCDEF";
for ( q =
s2; *q !=
'\0'; ++q ) {
*p++ =
hexdig[
0x0F & ((*(
unsigned char*)q) >>
4) ];