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 | |
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')
-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 |
3 files changed, 42 insertions, 77 deletions
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 |