diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2018-01-25 16:00:07 +0300 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2018-02-01 12:40:22 +0100 |
commit | 65abd11d68ba9f849d89b98b6a56071411875c89 (patch) | |
tree | 2dfab863a55ebb37a464b0209f5b74f229c71d00 /ucb | |
parent | ae5f89fdcccb2cf74256b04771249fc8afca8794 (diff) |
Support for webdav:// and webdavs:// schemes from command line
We have currently support for WebDAV schemes as vnd.sun.star.webdav://
but it is not user and tools friendly.
Some related refactoring in ucb to reuse existing code instead of
manual parsing of URLs.
Change-Id: Ib14411796d6cf11afd80d5132abe67d4e46a42e1
Reviewed-on: https://gerrit.libreoffice.org/48585
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/CppunitTest_ucb_webdav_local_neon.mk | 1 | ||||
-rw-r--r-- | ucb/CppunitTest_ucb_webdav_neon_opts.mk | 1 | ||||
-rw-r--r-- | ucb/CppunitTest_ucb_webdav_propfindcache.mk | 1 | ||||
-rw-r--r-- | ucb/CppunitTest_ucb_webdav_res_access.mk | 1 | ||||
-rw-r--r-- | ucb/Library_ucpdav1.mk | 1 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavcontent.cxx | 44 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavprovider.cxx | 73 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavprovider.hxx | 25 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavcontent.cxx | 20 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavprovider.cxx | 74 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavprovider.hxx | 25 |
11 files changed, 96 insertions, 170 deletions
diff --git a/ucb/CppunitTest_ucb_webdav_local_neon.mk b/ucb/CppunitTest_ucb_webdav_local_neon.mk index df16e36409bd..2e920f4ca03f 100644 --- a/ucb/CppunitTest_ucb_webdav_local_neon.mk +++ b/ucb/CppunitTest_ucb_webdav_local_neon.mk @@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,ucb_webdav_local_neon, \ salhelper \ test \ ucbhelper \ + tl \ )) $(eval $(call gb_CppunitTest_use_library_objects,ucb_webdav_local_neon, \ diff --git a/ucb/CppunitTest_ucb_webdav_neon_opts.mk b/ucb/CppunitTest_ucb_webdav_neon_opts.mk index 91e167b083a9..df670ed7afdd 100644 --- a/ucb/CppunitTest_ucb_webdav_neon_opts.mk +++ b/ucb/CppunitTest_ucb_webdav_neon_opts.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,ucb_webdav_neon_opts, \ salhelper \ test \ ucbhelper \ + tl \ )) $(eval $(call gb_CppunitTest_use_library_objects,ucb_webdav_neon_opts, \ diff --git a/ucb/CppunitTest_ucb_webdav_propfindcache.mk b/ucb/CppunitTest_ucb_webdav_propfindcache.mk index ebbaee7898ed..8d4a12d32ad4 100644 --- a/ucb/CppunitTest_ucb_webdav_propfindcache.mk +++ b/ucb/CppunitTest_ucb_webdav_propfindcache.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,ucb_webdav_propfindcache, \ salhelper \ test \ ucbhelper \ + tl \ )) $(eval $(call gb_CppunitTest_use_library_objects,ucb_webdav_propfindcache, \ diff --git a/ucb/CppunitTest_ucb_webdav_res_access.mk b/ucb/CppunitTest_ucb_webdav_res_access.mk index ac48f87bc876..fa0669987bd2 100644 --- a/ucb/CppunitTest_ucb_webdav_res_access.mk +++ b/ucb/CppunitTest_ucb_webdav_res_access.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,ucb_webdav_res_access, \ salhelper \ test \ ucbhelper \ + tl \ )) $(eval $(call gb_CppunitTest_use_library_objects,ucb_webdav_res_access, \ diff --git a/ucb/Library_ucpdav1.mk b/ucb/Library_ucpdav1.mk index f4afd730c74c..c76489bd4847 100644 --- a/ucb/Library_ucpdav1.mk +++ b/ucb/Library_ucpdav1.mk @@ -26,6 +26,7 @@ $(eval $(call gb_Library_use_libraries,ucpdav1,\ sal \ salhelper \ ucbhelper \ + tl \ )) ifeq ($(WITH_WEBDAV),neon) diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx index c49caa3d8367..1c8327545268 100644 --- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx +++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx @@ -2778,25 +2778,29 @@ void Content::transfer( // Check source's and target's URL scheme OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase(); - if ( aScheme == WEBDAV_URL_SCHEME ) + if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) { - sourceURI.SetScheme( - HTTP_URL_SCHEME ); + sourceURI.SetScheme( HTTP_URL_SCHEME ); } - else if ( aScheme == WEBDAVS_URL_SCHEME ) + else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) { - sourceURI.SetScheme( - HTTPS_URL_SCHEME ); + sourceURI.SetScheme( HTTPS_URL_SCHEME ); } else if ( aScheme == DAV_URL_SCHEME ) { - sourceURI.SetScheme( - HTTP_URL_SCHEME ); + sourceURI.SetScheme( HTTP_URL_SCHEME ); } else if ( aScheme == DAVS_URL_SCHEME ) { - sourceURI.SetScheme( - HTTPS_URL_SCHEME ); + sourceURI.SetScheme( HTTPS_URL_SCHEME ); + } + else if ( aScheme == WEBDAV_URL_SCHEME ) + { + sourceURI.SetScheme( HTTP_URL_SCHEME ); + } + else if ( aScheme == WEBDAVS_URL_SCHEME ) + { + sourceURI.SetScheme( HTTPS_URL_SCHEME ); } else { @@ -2813,18 +2817,18 @@ void Content::transfer( } aScheme = targetURI.GetScheme().toAsciiLowerCase(); - if ( aScheme == WEBDAV_URL_SCHEME ) - targetURI.SetScheme( - HTTP_URL_SCHEME ); - else if ( aScheme == WEBDAVS_URL_SCHEME ) - targetURI.SetScheme( - HTTPS_URL_SCHEME ); + if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) + targetURI.SetScheme( HTTP_URL_SCHEME ); + else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) + targetURI.SetScheme( HTTPS_URL_SCHEME ); else if ( aScheme == DAV_URL_SCHEME ) - targetURI.SetScheme( - HTTP_URL_SCHEME ); + targetURI.SetScheme( HTTP_URL_SCHEME ); else if ( aScheme == DAVS_URL_SCHEME ) - targetURI.SetScheme( - HTTPS_URL_SCHEME ); + targetURI.SetScheme( HTTPS_URL_SCHEME ); + else if ( aScheme == WEBDAV_URL_SCHEME ) + targetURI.SetScheme( HTTP_URL_SCHEME ); + else if ( aScheme == WEBDAVS_URL_SCHEME ) + targetURI.SetScheme( HTTPS_URL_SCHEME ); // @@@ This implementation of 'transfer' only works // if the source and target are located at same host. diff --git a/ucb/source/ucp/webdav-neon/webdavprovider.cxx b/ucb/source/ucp/webdav-neon/webdavprovider.cxx index 142351f9db0d..16a0e21f351b 100644 --- a/ucb/source/ucp/webdav-neon/webdavprovider.cxx +++ b/ucb/source/ucp/webdav-neon/webdavprovider.cxx @@ -35,6 +35,7 @@ #include "webdavcontent.hxx" #include <osl/mutex.hxx> +#include <tools/urlobj.hxx> using namespace com::sun::star; using namespace webdav_ucp; @@ -127,76 +128,34 @@ ContentProvider::queryContent( ucb::XContentIdentifier >& Identifier ) { // Check URL scheme... + INetURLObject aURL( Identifier->getContentIdentifier() ); - const OUString aScheme - = Identifier->getContentProviderScheme().toAsciiLowerCase(); - if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME - && aScheme != WEBDAV_URL_SCHEME && aScheme != WEBDAVS_URL_SCHEME - && aScheme != DAV_URL_SCHEME && aScheme != DAVS_URL_SCHEME && aScheme != FTP_URL_SCHEME ) + if ( aURL.isSchemeEqualTo( INetProtocol::NotValid ) ) throw ucb::IllegalIdentifierException(); - // Normalize URL and create new Id, if nessacary. - OUString aURL = Identifier->getContentIdentifier(); - - // At least: <scheme> + "://" - if ( aURL.getLength() < ( aScheme.getLength() + 3 ) ) - throw ucb::IllegalIdentifierException(); - - if ( !aURL.match("://", aScheme.getLength()) ) + if ( !aURL.isAnyKnownWebDAVScheme() ) throw ucb::IllegalIdentifierException(); uno::Reference< ucb::XContentIdentifier > xCanonicId; - bool bNewId = false; - if ( aScheme == WEBDAV_URL_SCHEME ) - { - aURL = aURL.replaceAt( 0, - WEBDAV_URL_SCHEME_LENGTH, - HTTP_URL_SCHEME ); - bNewId = true; - } - else if ( aScheme == WEBDAVS_URL_SCHEME ) - { - aURL = aURL.replaceAt( 0, - WEBDAVS_URL_SCHEME_LENGTH, - HTTPS_URL_SCHEME ); - bNewId = true; - } - else if ( aScheme == DAV_URL_SCHEME ) + if (aURL.isSchemeEqualTo( INetProtocol::VndSunStarWebdav ) || + aURL.isSchemeEqualTo(DAV_URL_SCHEME) || + aURL.isSchemeEqualTo( INetProtocol::Webdav ) ) { - aURL = aURL.replaceAt( 0, - DAV_URL_SCHEME_LENGTH, - HTTP_URL_SCHEME ); - bNewId = true; + aURL.changeScheme( INetProtocol::Http ); + xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() ); } - else if ( aScheme == DAVS_URL_SCHEME ) + else if ( aURL.isSchemeEqualTo( INetProtocol::VndSunStarWebdavs ) || + aURL.isSchemeEqualTo( DAVS_URL_SCHEME ) || + aURL.isSchemeEqualTo( INetProtocol::Webdavs )) { - aURL = aURL.replaceAt( 0, - DAVS_URL_SCHEME_LENGTH, - HTTPS_URL_SCHEME ); - bNewId = true; + aURL.changeScheme( INetProtocol::Https ); + xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() ); } - - sal_Int32 nPos = aURL.lastIndexOf( '/' ); - if ( nPos != aURL.getLength() - 1 ) - { - // Find second slash in URL. - nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 ); - if ( nPos == -1 ) - throw ucb::IllegalIdentifierException(); - - nPos = aURL.indexOf( '/', nPos + 1 ); - if ( nPos == -1 ) - { - aURL += "/"; - bNewId = true; - } - } - - if ( bNewId ) - xCanonicId = new ::ucbhelper::ContentIdentifier( aURL ); else + { xCanonicId = Identifier; + } osl::MutexGuard aGuard( m_aMutex ); diff --git a/ucb/source/ucp/webdav-neon/webdavprovider.hxx b/ucb/source/ucp/webdav-neon/webdavprovider.hxx index 10e56674c894..9794cd413bf3 100644 --- a/ucb/source/ucp/webdav-neon/webdavprovider.hxx +++ b/ucb/source/ucp/webdav-neon/webdavprovider.hxx @@ -47,28 +47,21 @@ namespace webdav_ucp { // URL scheme. This is the scheme the provider will be able to create // contents for. The UCB will select the provider ( i.e. in order to create // contents ) according to this scheme. -#define WEBDAV_URL_SCHEME "vnd.sun.star.webdav" -#define WEBDAV_URL_SCHEME_LENGTH 19 - -#define WEBDAVS_URL_SCHEME "vnd.sun.star.webdavs" -#define WEBDAVS_URL_SCHEME_LENGTH 20 - -#define HTTP_URL_SCHEME "http" - -#define HTTPS_URL_SCHEME "https" - -#define DAV_URL_SCHEME "dav" -#define DAV_URL_SCHEME_LENGTH 3 - -#define DAVS_URL_SCHEME "davs" -#define DAVS_URL_SCHEME_LENGTH 4 +#define VNDSUNSTARWEBDAV_URL_SCHEME "vnd.sun.star.webdav" +#define VNDSUNSTARWEBDAVS_URL_SCHEME "vnd.sun.star.webdavs" +#define HTTP_URL_SCHEME "http" +#define HTTPS_URL_SCHEME "https" +#define DAV_URL_SCHEME "dav" +#define DAVS_URL_SCHEME "davs" +#define WEBDAV_URL_SCHEME "webdav" +#define WEBDAVS_URL_SCHEME "webdavs" #define FTP_URL_SCHEME "ftp" #define HTTP_CONTENT_TYPE "application/" HTTP_URL_SCHEME "-content" #define WEBDAV_CONTENT_TYPE HTTP_CONTENT_TYPE -#define WEBDAV_COLLECTION_TYPE "application/" WEBDAV_URL_SCHEME "-collection" +#define WEBDAV_COLLECTION_TYPE "application/" VNDSUNSTARWEBDAV_URL_SCHEME "-collection" class ContentProvider : public ::ucbhelper::ContentProviderImplHelper diff --git a/ucb/source/ucp/webdav/webdavcontent.cxx b/ucb/source/ucp/webdav/webdavcontent.cxx index 4911e5496f5a..b0ddfd0c3dbf 100644 --- a/ucb/source/ucp/webdav/webdavcontent.cxx +++ b/ucb/source/ucp/webdav/webdavcontent.cxx @@ -2568,11 +2568,11 @@ void Content::transfer( // Check source's and target's URL scheme OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase(); - if ( aScheme == WEBDAV_URL_SCHEME ) + if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) { sourceURI.SetScheme( HTTP_URL_SCHEME ); } - else if ( aScheme == WEBDAVS_URL_SCHEME ) + else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) { sourceURI.SetScheme( HTTPS_URL_SCHEME ); } @@ -2584,6 +2584,14 @@ void Content::transfer( { sourceURI.SetScheme( HTTPS_URL_SCHEME ); } + else if (aScheme == WEBDAV_URL_SCHEME) + { + sourceURI.SetScheme(HTTP_URL_SCHEME); + } + else if (aScheme == WEBDAVS_URL_SCHEME) + { + sourceURI.SetScheme(HTTPS_URL_SCHEME); + } else { if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME ) @@ -2599,14 +2607,18 @@ void Content::transfer( } aScheme = targetURI.GetScheme().toAsciiLowerCase(); - if ( aScheme == WEBDAV_URL_SCHEME ) + if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) targetURI.SetScheme( HTTP_URL_SCHEME ); - else if ( aScheme == WEBDAVS_URL_SCHEME ) + else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) targetURI.SetScheme( HTTPS_URL_SCHEME ); else if ( aScheme == DAV_URL_SCHEME ) targetURI.SetScheme( HTTP_URL_SCHEME ); else if ( aScheme == DAVS_URL_SCHEME ) targetURI.SetScheme( HTTPS_URL_SCHEME ); + else if (aScheme == WEBDAV_URL_SCHEME) + targetURI.SetScheme(HTTP_URL_SCHEME); + else if (aScheme == WEBDAVS_URL_SCHEME) + targetURI.SetScheme(HTTPS_URL_SCHEME); // @@@ This implementation of 'transfer' only works // if the source and target are located at same host. diff --git a/ucb/source/ucp/webdav/webdavprovider.cxx b/ucb/source/ucp/webdav/webdavprovider.cxx index 78ea35df5a71..b9f2f85e5493 100644 --- a/ucb/source/ucp/webdav/webdavprovider.cxx +++ b/ucb/source/ucp/webdav/webdavprovider.cxx @@ -28,6 +28,8 @@ #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/ucb/IllegalIdentifierException.hpp> +#include <tools/urlobj.hxx> + using namespace com::sun::star; using namespace http_dav_ucp; @@ -116,76 +118,34 @@ ContentProvider::queryContent( ucb::XContentIdentifier >& Identifier ) { // Check URL scheme... + INetURLObject aURL(Identifier->getContentIdentifier()); - const OUString aScheme - = Identifier->getContentProviderScheme().toAsciiLowerCase(); - if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME && - aScheme != WEBDAV_URL_SCHEME && aScheme != WEBDAVS_URL_SCHEME && - aScheme != DAV_URL_SCHEME && aScheme != DAVS_URL_SCHEME ) - throw ucb::IllegalIdentifierException(); - - // Normalize URL and create new Id, if nessacary. - OUString aURL = Identifier->getContentIdentifier(); - - // At least: <scheme> + "://" - if ( aURL.getLength() < ( aScheme.getLength() + 3 ) ) + if (aURL.isSchemeEqualTo(INetProtocol::NotValid)) throw ucb::IllegalIdentifierException(); - if ( !aURL.match("://", aScheme.getLength()) ) + if (!aURL.isAnyKnownWebDAVScheme()) throw ucb::IllegalIdentifierException(); uno::Reference< ucb::XContentIdentifier > xCanonicId; - bool bNewId = false; - if ( aScheme == WEBDAV_URL_SCHEME ) - { - aURL = aURL.replaceAt( 0, - WEBDAV_URL_SCHEME_LENGTH, - HTTP_URL_SCHEME ); - bNewId = true; - } - else if ( aScheme == WEBDAVS_URL_SCHEME ) - { - aURL = aURL.replaceAt( 0, - WEBDAVS_URL_SCHEME_LENGTH, - HTTPS_URL_SCHEME ); - bNewId = true; - } - else if ( aScheme == DAV_URL_SCHEME ) - { - aURL = aURL.replaceAt( 0, - DAV_URL_SCHEME_LENGTH, - HTTP_URL_SCHEME ); - bNewId = true; - } - else if ( aScheme == DAVS_URL_SCHEME ) + if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdav) || + aURL.isSchemeEqualTo(DAV_URL_SCHEME) || + aURL.isSchemeEqualTo(INetProtocol::Webdav)) { - aURL = aURL.replaceAt( 0, - DAVS_URL_SCHEME_LENGTH, - HTTPS_URL_SCHEME ); - bNewId = true; + aURL.changeScheme(INetProtocol::Http); + xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() ); } - - sal_Int32 nPos = aURL.lastIndexOf( '/' ); - if ( nPos != aURL.getLength() - 1 ) + else if (aURL.isSchemeEqualTo(INetProtocol::VndSunStarWebdavs) || + aURL.isSchemeEqualTo(DAVS_URL_SCHEME) || + aURL.isSchemeEqualTo(INetProtocol::Webdavs)) { - // Find second slash in URL. - nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 ); - if ( nPos == -1 ) - throw ucb::IllegalIdentifierException(); - - nPos = aURL.indexOf( '/', nPos + 1 ); - if ( nPos == -1 ) - { - aURL += "/"; - bNewId = true; - } + aURL.changeScheme(INetProtocol::Https); + xCanonicId = new ::ucbhelper::ContentIdentifier( aURL.getExternalURL() ); } - - if ( bNewId ) - xCanonicId = new ::ucbhelper::ContentIdentifier( aURL ); else + { xCanonicId = Identifier; + } osl::MutexGuard aGuard( m_aMutex ); diff --git a/ucb/source/ucp/webdav/webdavprovider.hxx b/ucb/source/ucp/webdav/webdavprovider.hxx index 383ffc119f7f..a9375260816b 100644 --- a/ucb/source/ucp/webdav/webdavprovider.hxx +++ b/ucb/source/ucp/webdav/webdavprovider.hxx @@ -41,26 +41,19 @@ namespace http_dav_ucp { // URL scheme. This is the scheme the provider will be able to create // contents for. The UCB will select the provider ( i.e. in order to create // contents ) according to this scheme. -#define WEBDAV_URL_SCHEME "vnd.sun.star.webdav" -#define WEBDAV_URL_SCHEME_LENGTH 19 - -#define WEBDAVS_URL_SCHEME "vnd.sun.star.webdavs" -#define WEBDAVS_URL_SCHEME_LENGTH 20 - -#define HTTP_URL_SCHEME "http" - -#define HTTPS_URL_SCHEME "https" - -#define DAV_URL_SCHEME "dav" -#define DAV_URL_SCHEME_LENGTH 3 - -#define DAVS_URL_SCHEME "davs" -#define DAVS_URL_SCHEME_LENGTH 4 +#define VNDSUNSTARWEBDAV_URL_SCHEME "vnd.sun.star.webdav" +#define VNDSUNSTARWEBDAVS_URL_SCHEME "vnd.sun.star.webdavs" +#define HTTP_URL_SCHEME "http" +#define HTTPS_URL_SCHEME "https" +#define DAV_URL_SCHEME "dav" +#define DAVS_URL_SCHEME "davs" +#define WEBDAV_URL_SCHEME "webdav" +#define WEBDAVS_URL_SCHEME "webdavs" #define HTTP_CONTENT_TYPE "application/" HTTP_URL_SCHEME "-content" #define WEBDAV_CONTENT_TYPE HTTP_CONTENT_TYPE -#define WEBDAV_COLLECTION_TYPE "application/" WEBDAV_URL_SCHEME "-collection" +#define WEBDAV_COLLECTION_TYPE "application/" VNDSUNSTARWEBDAV_URL_SCHEME "-collection" class ContentProvider : public ::ucbhelper::ContentProviderImplHelper |