Kaydet (Commit) f90e26b6 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

tdf#107461: For Unix-like OS, support file://<hostname>/... URLs

...where <hostname> matches whatever osl_getLocalHostname reports.  (And, for
simplicity, don't support variations where e.g. one of the two FQDNs has an
optional final dot while the other has not.)

(It is not clear to me whether a similar change should also be done for the
Windows-specific code in sal/osl/w32/file_url.cxx.  On Windows, file URLs with a
host component are generally interpreted as UNC pathnames, and in some local
test on a Windows 8 machine whose hostname is reported as "win8", passing a URL
like <file://win8/Users/me/Documents/...> (i.e., without a C: drive letter) to
LO already worked to access files on the default drive C: at least.)

Change-Id: I7a69b6d4ca76a71223def7b90d7c3b8b731ee86d
Reviewed-on: https://gerrit.libreoffice.org/67437
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 48f14514
......@@ -30,6 +30,7 @@
#include <osl/file.hxx>
#include <osl/security.hxx>
#include <osl/socket.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
#include <osl/process.h>
......@@ -136,7 +137,9 @@ oslFileError getSystemPathFromFileUrl(
// Handle query or fragment:
if (url.indexOf('?', i) != -1 || url.indexOf('#', i) != -1)
return osl_File_E_INVAL;
// Handle authority:
// Handle authority, supporting a host of "localhost", "", or the exact value (e.g.,
// not supporting an additional final dot, for simplicity) reported by osl_getLocalHostname
// (and, in each case, ignoring case of ASCII letters):
if (url.getLength() - i >= 2 && url[i] == '/' && url[i + 1] == '/')
i += 2;
......@@ -153,7 +156,14 @@ oslFileError getSystemPathFromFileUrl(
!= 0))
return osl_File_E_INVAL;
OUString hostname;
if (osl_getLocalHostname(&hostname.pData) != osl_Socket_Ok
|| (rtl_ustr_compareIgnoreAsciiCase_WithLength(
url.pData->buffer + i, j - i, hostname.getStr(), hostname.getLength())
!= 0))
return osl_File_E_INVAL;
i = j;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment