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/source/ucp/webdav-neon | |
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/source/ucp/webdav-neon')
-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 |
3 files changed, 49 insertions, 93 deletions
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 |