From 46c645bf4e9909f5296e75028f1f5434e83942d2 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 4 Feb 2019 17:38:29 +0100 Subject: Move dubious file: -> smb: conversion from INetURLObject to file UCP The Linux-only conversion of file URLs with a non-empty (other than "localhost") authority to smb URLs had been added in 2010 with 0b9ef81ba5ff08d85f21275222458a5b9b9e484c "tools-urlobj-smb-scheme-patch.diff: migrated" (applying a Go-oo patch?) but giving no rationale beyond "process relative SMB paths (in hyperlinks) correctly". That makes it hard to tell whether that patch is (still) actively useful for anything, or was just a misguided hack from the beginning: * Why make this Linux only? What about other non-Windows OSs? (On Windows, such URLs can be resolved as UNC pathnames.) If the reason for Linux-only was that it is the only OS where LO can handle smb URLs via GIO, why not make it conditional on ENABLE_GIO? * Why map to smb? There are various remote file access protocols. Hardcoding smb looks arbitrary here. Anyway, INetURLObject is arguably at a wrong level for such a patch. To not drop the hack wholesale, reimplement it in the file UCP, forwarding to a potential other UCP that can handle smb URLs any file:///... URLs (rewritten as smb URLs) that the file UCP cannot handle itself. (file://localhost/... URLs will already have been normalized to file:///... by INetURLObject when they reach the file UCP, and even if they were not, the osl/file.hxx functionality underlying fileaccess::TaskManager::getUnqFromUrl knows how to handle them, so they will not take the forward-to-smb code branch.) (The corresponding #ifdef WIN code from 0b9ef81ba5ff08d85f21275222458a5b9b9e484c has already been removed with 82034b04e81b74a048595b0eac0f73581ecbc9e4 "tdf#119326 crash when adding "Windows Share" File resource".) (I came across that 2010 patch while looking into "Does not support 'file://' scheme with actual hostname". A next step would be to make the file UCP actually handle any file:///... URLs that denote the local host.) Change-Id: I77242705dc4c6c1e9cb3a4f32253224ac6cb13cb Reviewed-on: https://gerrit.libreoffice.org/67372 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- tools/qa/cppunit/test_urlobj.cxx | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'tools/qa') diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx index 581a19478e67..2c391fbf513d 100644 --- a/tools/qa/cppunit/test_urlobj.cxx +++ b/tools/qa/cppunit/test_urlobj.cxx @@ -49,11 +49,7 @@ namespace tools_urlobj void urlobjTest_001( ) { INetURLObject aUrl( OUString( "file://10.10.1.1/sampledir/sample.file" ) ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://10.10.1.1/sampledir/sample.file"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("10.10.1.1"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/sampledir/sample.file"), @@ -70,11 +66,7 @@ namespace tools_urlobj aUrl. setFSysPath( "\\\\137.65.170.24\\c$\\Img0001.jpg", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://137.65.170.24/c$/Img0001.jpg"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"), @@ -91,11 +83,7 @@ namespace tools_urlobj aUrl. setFSysPath( "\\\\hive-winxp-x86\\pmladek\\test2.odt", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://hive-winxp-x86/pmladek/test2.odt"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"), @@ -105,11 +93,7 @@ namespace tools_urlobj void urlobjTest_004( ) { INetURLObject aUrl( OUString( "smb://10.10.1.1/sampledir/sample.file" ) ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://10.10.1.1/sampledir/sample.file"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL( INetProtocol::Smb, aUrl.GetProtocol( ) ); -#endif CPPUNIT_ASSERT_EQUAL(OUString("10.10.1.1"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/sampledir/sample.file"), @@ -124,11 +108,7 @@ namespace tools_urlobj INetURLObject aUrl; aUrl.setFSysPath( "//137.65.170.24/c$/Img0001.jpg", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://137.65.170.24/c$/Img0001.jpg"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"), @@ -144,11 +124,7 @@ namespace tools_urlobj INetURLObject aUrl; aUrl.setFSysPath( "//hive-winxp-x86/pmladek/test2.odt", FSysStyle::Detect ); -#ifdef LINUX - CPPUNIT_ASSERT_EQUAL(OUString("smb://hive-winxp-x86/pmladek/test2.odt"), - aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - CPPUNIT_ASSERT_EQUAL(INetProtocol::Smb, aUrl.GetProtocol()); -#endif + CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol()); CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"), aUrl.GetHost(INetURLObject::DecodeMechanism::NONE)); CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"), -- cgit