| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <memory> |
| 21 |
|
| 22 |
#include <cppuhelper/queryinterface.hxx> |
| 23 |
#include <rtl/uri.hxx> |
| 24 |
#include <sal/log.hxx> |
| 25 |
#include <officecfg/Office/Common.hxx> |
| 26 |
#include <officecfg/Inet.hxx> |
| 27 |
#include <ucbhelper/contentidentifier.hxx> |
| 28 |
#include <ucbhelper/macros.hxx> |
| 29 |
#include <ucbhelper/propertyvalueset.hxx> |
| 30 |
#include <ucbhelper/simpleinteractionrequest.hxx> |
| 31 |
#include <ucbhelper/cancelcommandexecution.hxx> |
| 32 |
#include <svl/lockfilecommon.hxx> |
| 33 |
|
| 34 |
#include <com/sun/star/beans/IllegalTypeException.hpp> |
| 35 |
#include <com/sun/star/beans/NotRemoveableException.hpp> |
| 36 |
#include <com/sun/star/beans/PropertyAttribute.hpp> |
| 37 |
#include <com/sun/star/beans/PropertyExistException.hpp> |
| 38 |
#include <com/sun/star/beans/PropertySetInfoChange.hpp> |
| 39 |
#include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp> |
| 40 |
#include <com/sun/star/beans/PropertyValue.hpp> |
| 41 |
#include <com/sun/star/io/XActiveDataSink.hpp> |
| 42 |
#include <com/sun/star/io/XOutputStream.hpp> |
| 43 |
#include <com/sun/star/lang/IllegalAccessException.hpp> |
| 44 |
#include <com/sun/star/lang/IllegalArgumentException.hpp> |
| 45 |
#include <com/sun/star/sdbc/SQLException.hpp> |
| 46 |
#include <com/sun/star/task/PasswordContainerInteractionHandler.hpp> |
| 47 |
#include <com/sun/star/ucb/CommandEnvironment.hpp> |
| 48 |
#include <com/sun/star/ucb/CommandFailedException.hpp> |
| 49 |
#include <com/sun/star/ucb/ContentInfoAttribute.hpp> |
| 50 |
#include <com/sun/star/ucb/IllegalIdentifierException.hpp> |
| 51 |
#include <com/sun/star/ucb/InsertCommandArgument.hpp> |
| 52 |
#include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> |
| 53 |
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> |
| 54 |
#include <com/sun/star/ucb/InteractiveLockingLockedException.hpp> |
| 55 |
#include <com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp> |
| 56 |
#include <com/sun/star/ucb/InteractiveLockingNotLockedException.hpp> |
| 57 |
#include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp> |
| 58 |
#include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp> |
| 59 |
#include <com/sun/star/ucb/InteractiveNetworkReadException.hpp> |
| 60 |
#include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp> |
| 61 |
#include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp> |
| 62 |
#include <com/sun/star/ucb/MissingInputStreamException.hpp> |
| 63 |
#include <com/sun/star/ucb/MissingPropertiesException.hpp> |
| 64 |
#include <com/sun/star/ucb/NameClash.hpp> |
| 65 |
#include <com/sun/star/ucb/NameClashException.hpp> |
| 66 |
#include <com/sun/star/ucb/OpenCommandArgument3.hpp> |
| 67 |
#include <com/sun/star/ucb/OpenMode.hpp> |
| 68 |
#include <com/sun/star/ucb/PostCommandArgument2.hpp> |
| 69 |
#include <com/sun/star/ucb/PropertyCommandArgument.hpp> |
| 70 |
#include <com/sun/star/ucb/TransferInfo.hpp> |
| 71 |
#include <com/sun/star/ucb/UnsupportedCommandException.hpp> |
| 72 |
#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> |
| 73 |
#include <com/sun/star/ucb/UnsupportedNameClashException.hpp> |
| 74 |
#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp> |
| 75 |
#include <com/sun/star/ucb/XCommandInfo.hpp> |
| 76 |
#include <com/sun/star/ucb/XPersistentPropertySet.hpp> |
| 77 |
#include <com/sun/star/uno/XComponentContext.hpp> |
| 78 |
|
| 79 |
#include "webdavcontent.hxx" |
| 80 |
#include "webdavprovider.hxx" |
| 81 |
#include "webdavresultset.hxx" |
| 82 |
#include "ContentProperties.hxx" |
| 83 |
#include "CurlUri.hxx" |
| 84 |
#include "UCBDeadPropertyValue.hxx" |
| 85 |
#include "DAVException.hxx" |
| 86 |
#include "DAVProperties.hxx" |
| 87 |
|
| 88 |
using namespace com::sun::star; |
| 89 |
using namespace http_dav_ucp; |
| 90 |
|
| 91 |
namespace |
| 92 |
{ |
| 93 |
void lcl_sendPartialGETRequest( bool &bError, |
| 94 |
DAVException &aLastException, |
| 95 |
const std::vector< OUString >& rProps, |
| 96 |
std::vector< OUString > &aHeaderNames, |
| 97 |
const std::unique_ptr< DAVResourceAccess > &xResAccess, |
| 98 |
std::unique_ptr< ContentProperties > &xProps, |
| 99 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 100 |
{ |
| 101 |
DAVResource aResource; |
| 102 |
DAVRequestHeaders aPartialGet; |
| 103 |
aPartialGet.emplace_back( |
| 104 |
u"Range"_ustr, // see <https://tools.ietf.org/html/rfc7233#section-3.1> |
| 105 |
u"bytes=0-0"_ustr); |
| 106 |
|
| 107 |
bool bIsRequestSize = std::any_of(aHeaderNames.begin(), aHeaderNames.end(), |
| 108 |
[](const OUString& rHeaderName) { return rHeaderName == "Content-Length"; }); |
| 109 |
|
| 110 |
if ( bIsRequestSize ) |
| 111 |
{ |
| 112 |
// we need to know if the server accepts range requests for a resource |
| 113 |
// and the range unit it uses |
| 114 |
aHeaderNames.emplace_back("Accept-Ranges"); // see <https://tools.ietf.org/html/rfc7233#section-2.3> |
| 115 |
aHeaderNames.emplace_back("Content-Range"); // see <https://tools.ietf.org/html/rfc7233#section-4.2> |
| 116 |
} |
| 117 |
try |
| 118 |
{ |
| 119 |
xResAccess->GET0( aPartialGet, aHeaderNames, aResource, xEnv ); |
| 120 |
bError = false; |
| 121 |
|
| 122 |
if ( bIsRequestSize ) |
| 123 |
{ |
| 124 |
// the ContentProperties maps "Content-Length" to the UCB "Size" property |
| 125 |
// This would have an unrealistic value of 1 byte because we did only a partial GET |
| 126 |
// Solution: if "Content-Range" is present, map it with UCB "Size" property |
| 127 |
OUString aAcceptRanges, aContentRange, aContentLength; |
| 128 |
std::vector< DAVPropertyValue > &aResponseProps = aResource.properties; |
| 129 |
for ( const auto& rResponseProp : aResponseProps ) |
| 130 |
{ |
| 131 |
if ( rResponseProp.Name == "Accept-Ranges" ) |
| 132 |
rResponseProp.Value >>= aAcceptRanges; |
| 133 |
else if ( rResponseProp.Name == "Content-Range" ) |
| 134 |
rResponseProp.Value >>= aContentRange; |
| 135 |
else if ( rResponseProp.Name == "Content-Length" ) |
| 136 |
rResponseProp.Value >>= aContentLength; |
| 137 |
} |
| 138 |
|
| 139 |
sal_Int64 nSize = 1; |
| 140 |
if ( aContentLength.getLength() ) |
| 141 |
{ |
| 142 |
nSize = aContentLength.toInt64(); |
| 143 |
} |
| 144 |
|
| 145 |
// according to http://tools.ietf.org/html/rfc2616#section-3.12 |
| 146 |
// the only range unit defined is "bytes" and implementations |
| 147 |
// MAY ignore ranges specified using other units. |
| 148 |
if ( nSize == 1 && |
| 149 |
aContentRange.getLength() && |
| 150 |
aAcceptRanges == "bytes" ) |
| 151 |
{ |
| 152 |
// Parse the Content-Range to get the size |
| 153 |
// vid. http://tools.ietf.org/html/rfc2616#section-14.16 |
| 154 |
// Content-Range: <range unit> <bytes range>/<size> |
| 155 |
sal_Int32 nSlash = aContentRange.lastIndexOf( '/' ); |
| 156 |
if ( nSlash != -1 ) |
| 157 |
{ |
| 158 |
OUString aSize = aContentRange.copy( nSlash + 1 ); |
| 159 |
// "*" means that the instance-length is unknown at the time when the response was generated |
| 160 |
if ( aSize != "*" ) |
| 161 |
{ |
| 162 |
auto it = std::find_if(aResponseProps.begin(), aResponseProps.end(), |
| 163 |
[](const DAVPropertyValue& rProp) { return rProp.Name == "Content-Length"; }); |
| 164 |
if (it != aResponseProps.end()) |
| 165 |
{ |
| 166 |
it->Value <<= aSize; |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
if (xProps) |
| 174 |
xProps->addProperties( |
| 175 |
rProps, |
| 176 |
ContentProperties( aResource ) ); |
| 177 |
else |
| 178 |
xProps.reset ( new ContentProperties( aResource ) ); |
| 179 |
} |
| 180 |
catch ( DAVException const & ex ) |
| 181 |
{ |
| 182 |
aLastException = ex; |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
// Static value, to manage a simple OPTIONS cache |
| 188 |
// Key is the URL, element is the DAVOptions resulting from an OPTIONS call. |
| 189 |
// Cached DAVOptions have a lifetime that depends on the errors received or not received |
| 190 |
// and on the value of received options. |
| 191 |
static DAVOptionsCache aStaticDAVOptionsCache; |
| 192 |
|
| 193 |
|
| 194 |
// Content Implementation. |
| 195 |
|
| 196 |
|
| 197 |
// ctr for content on an existing webdav resource |
| 198 |
Content::Content( |
| 199 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 200 |
ContentProvider* pProvider, |
| 201 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 202 |
rtl::Reference< DAVSessionFactory > const & rSessionFactory ) |
| 203 |
: ContentImplHelper( rxContext, pProvider, Identifier ), |
| 204 |
m_eResourceType( UNKNOWN ), |
| 205 |
m_eResourceTypeForLocks( UNKNOWN ), |
| 206 |
m_pProvider( pProvider ), |
| 207 |
m_bTransient( false ), |
| 208 |
m_bCollection( false ), |
| 209 |
m_bDidGetOrHead( false ) |
| 210 |
{ |
| 211 |
try |
| 212 |
{ |
| 213 |
initOptsCacheLifeTime(); |
| 214 |
m_xResAccess.reset( new DAVResourceAccess( |
| 215 |
rxContext, |
| 216 |
rSessionFactory, |
| 217 |
Identifier->getContentIdentifier() ) ); |
| 218 |
|
| 219 |
CurlUri const aURI( Identifier->getContentIdentifier() ); |
| 220 |
m_aEscapedTitle = aURI.GetPathBaseName(); |
| 221 |
} |
| 222 |
catch ( DAVException const & ) |
| 223 |
{ |
| 224 |
throw ucb::ContentCreationException(); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
// ctr for content on a non-existing webdav resource |
| 230 |
Content::Content( |
| 231 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 232 |
ContentProvider* pProvider, |
| 233 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 234 |
rtl::Reference< DAVSessionFactory > const & rSessionFactory, |
| 235 |
bool isCollection ) |
| 236 |
: ContentImplHelper( rxContext, pProvider, Identifier ), |
| 237 |
m_eResourceType( UNKNOWN ), |
| 238 |
m_eResourceTypeForLocks( UNKNOWN ), |
| 239 |
m_pProvider( pProvider ), |
| 240 |
m_bTransient( true ), |
| 241 |
m_bCollection( isCollection ), |
| 242 |
m_bDidGetOrHead( false ) |
| 243 |
{ |
| 244 |
try |
| 245 |
{ |
| 246 |
initOptsCacheLifeTime(); |
| 247 |
m_xResAccess.reset( new DAVResourceAccess( |
| 248 |
rxContext, rSessionFactory, Identifier->getContentIdentifier() ) ); |
| 249 |
} |
| 250 |
catch ( DAVException const & ) |
| 251 |
{ |
| 252 |
throw ucb::ContentCreationException(); |
| 253 |
} |
| 254 |
|
| 255 |
// Do not set m_aEscapedTitle here! Content::insert relays on this!!! |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
// virtual |
| 260 |
Content::~Content() |
| 261 |
{ |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
// XInterface methods. |
| 266 |
|
| 267 |
|
| 268 |
// virtual |
| 269 |
void SAL_CALL Content::acquire() noexcept |
| 270 |
{ |
| 271 |
ContentImplHelper::acquire(); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
// virtual |
| 276 |
void SAL_CALL Content::release() noexcept |
| 277 |
{ |
| 278 |
ContentImplHelper::release(); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
// virtual |
| 283 |
uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType ) |
| 284 |
{ |
| 285 |
// Note: isFolder may require network activities! So call it only |
| 286 |
// if it is really necessary!!! |
| 287 |
uno::Any aRet = cppu::queryInterface( |
| 288 |
rType, |
| 289 |
static_cast< ucb::XContentCreator * >( this ) ); |
| 290 |
if ( aRet.hasValue() ) |
| 291 |
{ |
| 292 |
try |
| 293 |
{ |
| 294 |
uno::Reference< task::XInteractionHandler > xIH( |
| 295 |
task::PasswordContainerInteractionHandler::create(m_xContext) ); |
| 296 |
|
| 297 |
// Supply a command env to isFolder() that contains an interaction |
| 298 |
// handler that uses the password container service to obtain |
| 299 |
// credentials without displaying a password gui. |
| 300 |
|
| 301 |
uno::Reference< ucb::XCommandEnvironment > xCmdEnv( |
| 302 |
ucb::CommandEnvironment::create( |
| 303 |
m_xContext, |
| 304 |
xIH, |
| 305 |
uno::Reference< ucb::XProgressHandler >() ) ); |
| 306 |
|
| 307 |
return isFolder( xCmdEnv ) ? aRet : uno::Any(); |
| 308 |
} |
| 309 |
catch ( uno::RuntimeException const & ) |
| 310 |
{ |
| 311 |
throw; |
| 312 |
} |
| 313 |
catch ( uno::Exception const & ) |
| 314 |
{ |
| 315 |
return uno::Any(); |
| 316 |
} |
| 317 |
} |
| 318 |
return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
// XTypeProvider methods. |
| 323 |
|
| 324 |
|
| 325 |
XTYPEPROVIDER_COMMON_IMPL( Content ); |
| 326 |
|
| 327 |
|
| 328 |
// virtual |
| 329 |
uno::Sequence< uno::Type > SAL_CALL Content::getTypes() |
| 330 |
{ |
| 331 |
bool bFolder = false; |
| 332 |
try |
| 333 |
{ |
| 334 |
bFolder |
| 335 |
= isFolder( uno::Reference< ucb::XCommandEnvironment >() ); |
| 336 |
} |
| 337 |
catch ( uno::RuntimeException const & ) |
| 338 |
{ |
| 339 |
throw; |
| 340 |
} |
| 341 |
catch ( uno::Exception const & ) |
| 342 |
{ |
| 343 |
} |
| 344 |
|
| 345 |
if ( bFolder ) |
| 346 |
{ |
| 347 |
static cppu::OTypeCollection s_aFolderTypes( |
| 348 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 349 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 350 |
CPPU_TYPE_REF( lang::XComponent ), |
| 351 |
CPPU_TYPE_REF( ucb::XContent ), |
| 352 |
CPPU_TYPE_REF( ucb::XCommandProcessor ), |
| 353 |
CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), |
| 354 |
CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), |
| 355 |
CPPU_TYPE_REF( beans::XPropertyContainer ), |
| 356 |
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), |
| 357 |
CPPU_TYPE_REF( container::XChild ), |
| 358 |
CPPU_TYPE_REF( ucb::XContentCreator ) ); |
| 359 |
|
| 360 |
return s_aFolderTypes.getTypes(); |
| 361 |
} |
| 362 |
else |
| 363 |
{ |
| 364 |
static cppu::OTypeCollection s_aDocumentTypes( |
| 365 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 366 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 367 |
CPPU_TYPE_REF( lang::XComponent ), |
| 368 |
CPPU_TYPE_REF( ucb::XContent ), |
| 369 |
CPPU_TYPE_REF( ucb::XCommandProcessor ), |
| 370 |
CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), |
| 371 |
CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), |
| 372 |
CPPU_TYPE_REF( beans::XPropertyContainer ), |
| 373 |
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), |
| 374 |
CPPU_TYPE_REF( container::XChild ) ); |
| 375 |
|
| 376 |
return s_aDocumentTypes.getTypes(); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
// XServiceInfo methods. |
| 382 |
|
| 383 |
|
| 384 |
// virtual |
| 385 |
OUString SAL_CALL Content::getImplementationName() |
| 386 |
{ |
| 387 |
return u"com.sun.star.comp.ucb.WebDAVContent"_ustr; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
// virtual |
| 392 |
uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames() |
| 393 |
{ |
| 394 |
uno::Sequence<OUString> aSNS { WEBDAV_CONTENT_SERVICE_NAME }; |
| 395 |
return aSNS; |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
// XContent methods. |
| 400 |
|
| 401 |
|
| 402 |
// virtual |
| 403 |
OUString SAL_CALL Content::getContentType() |
| 404 |
{ |
| 405 |
bool bFolder = false; |
| 406 |
try |
| 407 |
{ |
| 408 |
bFolder |
| 409 |
= isFolder( uno::Reference< ucb::XCommandEnvironment >() ); |
| 410 |
} |
| 411 |
catch ( uno::RuntimeException const & ) |
| 412 |
{ |
| 413 |
throw; |
| 414 |
} |
| 415 |
catch ( uno::Exception const & ) |
| 416 |
{ |
| 417 |
} |
| 418 |
|
| 419 |
if ( bFolder ) |
| 420 |
return WEBDAV_COLLECTION_TYPE; |
| 421 |
|
| 422 |
return WEBDAV_CONTENT_TYPE; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
// XCommandProcessor methods. |
| 427 |
|
| 428 |
|
| 429 |
// virtual |
| 430 |
uno::Any SAL_CALL Content::execute( |
| 431 |
const ucb::Command& aCommand, |
| 432 |
sal_Int32 /*CommandId*/, |
| 433 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 434 |
{ |
| 435 |
SAL_INFO("ucb.ucp.webdav", ">>>>> Content::execute: start: command: " << aCommand.Name |
| 436 |
<< ", env: " << (Environment.is() ? "present" : "missing") ); |
| 437 |
|
| 438 |
uno::Any aRet; |
| 439 |
|
| 440 |
if ( aCommand.Name == "getPropertyValues" ) |
| 441 |
{ |
| 442 |
|
| 443 |
// getPropertyValues |
| 444 |
|
| 445 |
|
| 446 |
uno::Sequence< beans::Property > Properties; |
| 447 |
if ( !( aCommand.Argument >>= Properties ) ) |
| 448 |
{ |
| 449 |
ucbhelper::cancelCommandExecution( |
| 450 |
uno::Any( lang::IllegalArgumentException( |
| 451 |
u"Wrong argument type!"_ustr, |
| 452 |
getXWeak(), |
| 453 |
-1 ) ), |
| 454 |
Environment ); |
| 455 |
// Unreachable |
| 456 |
} |
| 457 |
|
| 458 |
aRet <<= getPropertyValues( Properties, Environment ); |
| 459 |
} |
| 460 |
else if ( aCommand.Name == "setPropertyValues" ) |
| 461 |
{ |
| 462 |
|
| 463 |
// setPropertyValues |
| 464 |
|
| 465 |
|
| 466 |
uno::Sequence< beans::PropertyValue > aProperties; |
| 467 |
if ( !( aCommand.Argument >>= aProperties ) ) |
| 468 |
{ |
| 469 |
ucbhelper::cancelCommandExecution( |
| 470 |
uno::Any( lang::IllegalArgumentException( |
| 471 |
u"Wrong argument type!"_ustr, |
| 472 |
getXWeak(), |
| 473 |
-1 ) ), |
| 474 |
Environment ); |
| 475 |
// Unreachable |
| 476 |
} |
| 477 |
|
| 478 |
if ( !aProperties.getLength() ) |
| 479 |
{ |
| 480 |
ucbhelper::cancelCommandExecution( |
| 481 |
uno::Any( lang::IllegalArgumentException( |
| 482 |
u"No properties!"_ustr, |
| 483 |
getXWeak(), |
| 484 |
-1 ) ), |
| 485 |
Environment ); |
| 486 |
// Unreachable |
| 487 |
} |
| 488 |
|
| 489 |
aRet <<= setPropertyValues( aProperties, Environment ); |
| 490 |
} |
| 491 |
else if ( aCommand.Name == "getPropertySetInfo" ) |
| 492 |
{ |
| 493 |
|
| 494 |
// getPropertySetInfo |
| 495 |
|
| 496 |
|
| 497 |
// Note: Implemented by base class. |
| 498 |
aRet <<= getPropertySetInfo( Environment, |
| 499 |
false /* don't cache data */ ); |
| 500 |
} |
| 501 |
else if ( aCommand.Name == "getCommandInfo" ) |
| 502 |
{ |
| 503 |
|
| 504 |
// getCommandInfo |
| 505 |
|
| 506 |
|
| 507 |
// Note: Implemented by base class. |
| 508 |
aRet <<= getCommandInfo( Environment, false ); |
| 509 |
} |
| 510 |
else if ( aCommand.Name == "open" ) |
| 511 |
{ |
| 512 |
|
| 513 |
// open |
| 514 |
|
| 515 |
|
| 516 |
ucb::OpenCommandArgument3 aOpenCommand; |
| 517 |
ucb::OpenCommandArgument2 aTmp; |
| 518 |
if ( !( aCommand.Argument >>= aTmp ) ) |
| 519 |
{ |
| 520 |
ucbhelper::cancelCommandExecution( |
| 521 |
uno::Any( lang::IllegalArgumentException( |
| 522 |
u"Wrong argument type!"_ustr, |
| 523 |
getXWeak(), |
| 524 |
-1 ) ), |
| 525 |
Environment ); |
| 526 |
// Unreachable |
| 527 |
} |
| 528 |
if ( !( aCommand.Argument >>= aOpenCommand ) ) |
| 529 |
{ |
| 530 |
// compat mode, extract Arg2 info into newer structure |
| 531 |
aOpenCommand.Mode = aTmp.Mode; |
| 532 |
aOpenCommand.Priority = aTmp.Priority; |
| 533 |
aOpenCommand.Sink = aTmp.Sink; |
| 534 |
aOpenCommand.Properties = aTmp.Properties; |
| 535 |
aOpenCommand.SortingInfo = aTmp.SortingInfo; |
| 536 |
} |
| 537 |
|
| 538 |
aRet = open( aOpenCommand, Environment ); |
| 539 |
|
| 540 |
} |
| 541 |
else if ( aCommand.Name == "insert" ) |
| 542 |
{ |
| 543 |
|
| 544 |
// insert |
| 545 |
|
| 546 |
|
| 547 |
ucb::InsertCommandArgument arg; |
| 548 |
if ( !( aCommand.Argument >>= arg ) ) |
| 549 |
{ |
| 550 |
ucbhelper::cancelCommandExecution( |
| 551 |
uno::Any( lang::IllegalArgumentException( |
| 552 |
u"Wrong argument type!"_ustr, |
| 553 |
getXWeak(), |
| 554 |
-1 ) ), |
| 555 |
Environment ); |
| 556 |
// Unreachable |
| 557 |
} |
| 558 |
|
| 559 |
insert( arg.Data, arg.ReplaceExisting, Environment ); |
| 560 |
} |
| 561 |
else if ( aCommand.Name == "delete" ) |
| 562 |
{ |
| 563 |
|
| 564 |
// delete |
| 565 |
|
| 566 |
|
| 567 |
bool bDeletePhysical = false; |
| 568 |
aCommand.Argument >>= bDeletePhysical; |
| 569 |
|
| 570 |
// KSO: Ignore parameter and destroy the content, if you don't support |
| 571 |
// putting objects into trashcan. ( Since we do not have a trash can |
| 572 |
// service yet (src603), you actually have no other choice. ) |
| 573 |
// if ( bDeletePhysical ) |
| 574 |
// { |
| 575 |
try |
| 576 |
{ |
| 577 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 578 |
{ |
| 579 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 580 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 581 |
} |
| 582 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 583 |
// clean cached value of PROPFIND property names |
| 584 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 585 |
xResAccess->DESTROY( Environment ); |
| 586 |
{ |
| 587 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 588 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 589 |
} |
| 590 |
} |
| 591 |
catch ( DAVException const & e ) |
| 592 |
{ |
| 593 |
cancelCommandExecution( e, Environment, true ); |
| 594 |
// Unreachable |
| 595 |
} |
| 596 |
// } |
| 597 |
|
| 598 |
// Propagate destruction. |
| 599 |
destroy( bDeletePhysical ); |
| 600 |
|
| 601 |
// Remove own and all children's Additional Core Properties. |
| 602 |
removeAdditionalPropertySet(); |
| 603 |
} |
| 604 |
else if ( aCommand.Name == "transfer" && isFolder( Environment ) ) |
| 605 |
{ |
| 606 |
|
| 607 |
// transfer |
| 608 |
// ( Not available at documents ) |
| 609 |
|
| 610 |
|
| 611 |
ucb::TransferInfo transferArgs; |
| 612 |
if ( !( aCommand.Argument >>= transferArgs ) ) |
| 613 |
{ |
| 614 |
ucbhelper::cancelCommandExecution( |
| 615 |
uno::Any( lang::IllegalArgumentException( |
| 616 |
u"Wrong argument type!"_ustr, |
| 617 |
getXWeak(), |
| 618 |
-1 ) ), |
| 619 |
Environment ); |
| 620 |
// Unreachable |
| 621 |
} |
| 622 |
|
| 623 |
transfer( transferArgs, Environment ); |
| 624 |
} |
| 625 |
else if ( aCommand.Name == "post" ) |
| 626 |
{ |
| 627 |
|
| 628 |
// post |
| 629 |
|
| 630 |
|
| 631 |
ucb::PostCommandArgument2 aArg; |
| 632 |
if ( !( aCommand.Argument >>= aArg ) ) |
| 633 |
{ |
| 634 |
ucbhelper::cancelCommandExecution( |
| 635 |
uno::Any( lang::IllegalArgumentException( |
| 636 |
u"Wrong argument type!"_ustr, |
| 637 |
getXWeak(), |
| 638 |
-1 ) ), |
| 639 |
Environment ); |
| 640 |
// Unreachable |
| 641 |
} |
| 642 |
|
| 643 |
post( aArg, Environment ); |
| 644 |
} |
| 645 |
else if ( aCommand.Name == "lock" ) |
| 646 |
{ |
| 647 |
|
| 648 |
// lock |
| 649 |
|
| 650 |
ResourceType eType = resourceTypeForLocks( Environment ); |
| 651 |
// when the resource is not yet present the lock is used to create it |
| 652 |
// see: http://tools.ietf.org/html/rfc4918#section-7.3 |
| 653 |
// If the resource doesn't exists and the lock is not enabled (DAV with |
| 654 |
// no lock or a simple web) the error will be dealt with inside lock() method |
| 655 |
if ( eType == NOT_FOUND || |
| 656 |
eType == DAV ) |
| 657 |
{ |
| 658 |
lock( Environment ); |
| 659 |
if ( eType == NOT_FOUND ) |
| 660 |
{ |
| 661 |
m_eResourceType = UNKNOWN; // lock may have created it, need to check again |
| 662 |
m_eResourceTypeForLocks = UNKNOWN; |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
else if ( aCommand.Name == "unlock" ) |
| 667 |
{ |
| 668 |
|
| 669 |
// unlock |
| 670 |
// do not check for a DAV resource |
| 671 |
// the lock store will be checked before sending |
| 672 |
unlock( Environment ); |
| 673 |
} |
| 674 |
else if ( aCommand.Name == "createNewContent" && |
| 675 |
isFolder( Environment ) ) |
| 676 |
{ |
| 677 |
|
| 678 |
// createNewContent |
| 679 |
|
| 680 |
|
| 681 |
ucb::ContentInfo aArg; |
| 682 |
if ( !( aCommand.Argument >>= aArg ) ) |
| 683 |
{ |
| 684 |
ucbhelper::cancelCommandExecution( |
| 685 |
uno::Any( lang::IllegalArgumentException( |
| 686 |
u"Wrong argument type!"_ustr, |
| 687 |
getXWeak(), |
| 688 |
-1 ) ), |
| 689 |
Environment ); |
| 690 |
// Unreachable |
| 691 |
} |
| 692 |
|
| 693 |
aRet <<= createNewContent( aArg ); |
| 694 |
} |
| 695 |
else if ( aCommand.Name == "addProperty" ) |
| 696 |
{ |
| 697 |
ucb::PropertyCommandArgument aPropArg; |
| 698 |
if ( !( aCommand.Argument >>= aPropArg )) |
| 699 |
{ |
| 700 |
ucbhelper::cancelCommandExecution( |
| 701 |
uno::Any( lang::IllegalArgumentException( |
| 702 |
u"Wrong argument type!"_ustr, |
| 703 |
getXWeak(), |
| 704 |
-1 ) ), |
| 705 |
Environment ); |
| 706 |
} |
| 707 |
|
| 708 |
// TODO when/if XPropertyContainer is removed, |
| 709 |
// the command execution can be canceled in addProperty |
| 710 |
try |
| 711 |
{ |
| 712 |
addProperty( aPropArg, Environment ); |
| 713 |
} |
| 714 |
catch ( const beans::PropertyExistException &e ) |
| 715 |
{ |
| 716 |
ucbhelper::cancelCommandExecution( uno::Any( e ), Environment ); |
| 717 |
} |
| 718 |
catch ( const beans::IllegalTypeException&e ) |
| 719 |
{ |
| 720 |
ucbhelper::cancelCommandExecution( uno::Any( e ), Environment ); |
| 721 |
} |
| 722 |
catch ( const lang::IllegalArgumentException&e ) |
| 723 |
{ |
| 724 |
ucbhelper::cancelCommandExecution( uno::Any( e ), Environment ); |
| 725 |
} |
| 726 |
} |
| 727 |
else if ( aCommand.Name == "removeProperty" ) |
| 728 |
{ |
| 729 |
OUString sPropName; |
| 730 |
if ( !( aCommand.Argument >>= sPropName ) ) |
| 731 |
{ |
| 732 |
ucbhelper::cancelCommandExecution( |
| 733 |
uno::Any( lang::IllegalArgumentException( |
| 734 |
u"Wrong argument type!"_ustr, |
| 735 |
getXWeak(), |
| 736 |
-1 ) ), |
| 737 |
Environment ); |
| 738 |
} |
| 739 |
|
| 740 |
// TODO when/if XPropertyContainer is removed, |
| 741 |
// the command execution can be canceled in removeProperty |
| 742 |
try |
| 743 |
{ |
| 744 |
removeProperty( sPropName, Environment ); |
| 745 |
} |
| 746 |
catch( const beans::UnknownPropertyException &e ) |
| 747 |
{ |
| 748 |
ucbhelper::cancelCommandExecution( uno::Any( e ), Environment ); |
| 749 |
} |
| 750 |
catch( const beans::NotRemoveableException &e ) |
| 751 |
{ |
| 752 |
ucbhelper::cancelCommandExecution( uno::Any( e ), Environment ); |
| 753 |
} |
| 754 |
} |
| 755 |
else |
| 756 |
{ |
| 757 |
|
| 758 |
// Unsupported command |
| 759 |
|
| 760 |
|
| 761 |
ucbhelper::cancelCommandExecution( |
| 762 |
uno::Any( ucb::UnsupportedCommandException( |
| 763 |
aCommand.Name, |
| 764 |
getXWeak() ) ), |
| 765 |
Environment ); |
| 766 |
// Unreachable |
| 767 |
} |
| 768 |
|
| 769 |
SAL_INFO("ucb.ucp.webdav", "<<<<< Content::execute: end: command: " << aCommand.Name); |
| 770 |
|
| 771 |
return aRet; |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
// virtual |
| 776 |
void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) |
| 777 |
{ |
| 778 |
try |
| 779 |
{ |
| 780 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 781 |
{ |
| 782 |
osl::MutexGuard aGuard( m_aMutex ); |
| 783 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 784 |
} |
| 785 |
xResAccess->abort(); |
| 786 |
{ |
| 787 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 788 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 789 |
} |
| 790 |
} |
| 791 |
catch ( DAVException const & ) |
| 792 |
{ |
| 793 |
// abort failed! |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
// XPropertyContainer methods. |
| 799 |
|
| 800 |
|
| 801 |
void Content::addProperty( const css::ucb::PropertyCommandArgument &aCmdArg, |
| 802 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 803 |
{ |
| 804 |
// if ( m_bTransient ) |
| 805 |
// @@@ ??? |
| 806 |
const beans::Property aProperty = aCmdArg.Property; |
| 807 |
const uno::Any aDefaultValue = aCmdArg.DefaultValue; |
| 808 |
|
| 809 |
// check property Name |
| 810 |
if ( !aProperty.Name.getLength() ) |
| 811 |
throw lang::IllegalArgumentException( |
| 812 |
u"\"addProperty\" with empty Property.Name"_ustr, |
| 813 |
getXWeak(), |
| 814 |
-1 ); |
| 815 |
|
| 816 |
// Check property type. |
| 817 |
if ( !UCBDeadPropertyValue::supportsType( aProperty.Type ) ) |
| 818 |
throw beans::IllegalTypeException( |
| 819 |
u"\"addProperty\" unsupported Property.Type"_ustr, |
| 820 |
getXWeak() ); |
| 821 |
|
| 822 |
// check default value |
| 823 |
if ( aDefaultValue.hasValue() && aDefaultValue.getValueType() != aProperty.Type ) |
| 824 |
throw beans::IllegalTypeException( |
| 825 |
u"\"addProperty\" DefaultValue does not match Property.Type"_ustr, |
| 826 |
getXWeak() ); |
| 827 |
|
| 828 |
|
| 829 |
// Make sure a property with the requested name does not already |
| 830 |
// exist in dynamic and static(!) properties. |
| 831 |
|
| 832 |
|
| 833 |
// Take into account special properties with custom namespace |
| 834 |
// using <prop:the_propname xmlns:prop="the_namespace"> |
| 835 |
OUString aSpecialName; |
| 836 |
bool bIsSpecial = DAVProperties::isUCBSpecialProperty( aProperty.Name, aSpecialName ); |
| 837 |
|
| 838 |
// Note: This requires network access! |
| 839 |
if ( getPropertySetInfo( xEnv, false /* don't cache data */ ) |
| 840 |
->hasPropertyByName( bIsSpecial ? aSpecialName : aProperty.Name ) ) |
| 841 |
{ |
| 842 |
// Property does already exist. |
| 843 |
throw beans::PropertyExistException(); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
// Add a new dynamic property. |
| 848 |
|
| 849 |
|
| 850 |
ProppatchValue aValue( PROPSET, aProperty.Name, aDefaultValue ); |
| 851 |
|
| 852 |
std::vector< ProppatchValue > aProppatchValues; |
| 853 |
aProppatchValues.push_back( aValue ); |
| 854 |
|
| 855 |
try |
| 856 |
{ |
| 857 |
// Set property value at server. |
| 858 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 859 |
{ |
| 860 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 861 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 862 |
} |
| 863 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 864 |
// clean cached value of PROPFIND property names |
| 865 |
// PROPPATCH can change them |
| 866 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 867 |
xResAccess->PROPPATCH( aProppatchValues, xEnv ); |
| 868 |
{ |
| 869 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 870 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 871 |
} |
| 872 |
|
| 873 |
// Notify propertyset info change listeners. |
| 874 |
beans::PropertySetInfoChangeEvent evt( |
| 875 |
getXWeak(), |
| 876 |
bIsSpecial ? aSpecialName : aProperty.Name, |
| 877 |
-1, // No handle available |
| 878 |
beans::PropertySetInfoChange::PROPERTY_INSERTED ); |
| 879 |
notifyPropertySetInfoChange( evt ); |
| 880 |
} |
| 881 |
catch ( DAVException const & e ) |
| 882 |
{ |
| 883 |
if ( e.getStatus() == SC_FORBIDDEN ) |
| 884 |
{ |
| 885 |
// Support for setting arbitrary dead properties is optional! |
| 886 |
|
| 887 |
// Store property locally. |
| 888 |
ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name, |
| 889 |
aProperty.Attributes, |
| 890 |
aDefaultValue ); |
| 891 |
} |
| 892 |
else |
| 893 |
{ |
| 894 |
if ( shouldAccessNetworkAfterException( e ) ) |
| 895 |
{ |
| 896 |
try |
| 897 |
{ |
| 898 |
const ResourceType eType = getResourceType( xEnv ); |
| 899 |
switch ( eType ) |
| 900 |
{ |
| 901 |
case UNKNOWN: |
| 902 |
case DAV: |
| 903 |
throw lang::IllegalArgumentException(); |
| 904 |
|
| 905 |
case NON_DAV: |
| 906 |
// Store property locally. |
| 907 |
ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name, |
| 908 |
aProperty.Attributes, |
| 909 |
aDefaultValue ); |
| 910 |
break; |
| 911 |
|
| 912 |
default: |
| 913 |
SAL_WARN( "ucb.ucp.webdav", |
| 914 |
"Content::addProperty - " |
| 915 |
"Unsupported resource type!" ); |
| 916 |
break; |
| 917 |
} |
| 918 |
} |
| 919 |
catch ( uno::Exception const & ) |
| 920 |
{ |
| 921 |
SAL_WARN( "ucb.ucp.webdav", |
| 922 |
"Content::addProperty - " |
| 923 |
"Unable to determine resource type!" ); |
| 924 |
} |
| 925 |
} |
| 926 |
else |
| 927 |
{ |
| 928 |
SAL_WARN( "ucb.ucp.webdav", |
| 929 |
"Content::addProperty - " |
| 930 |
"Unable to determine resource type!" ); |
| 931 |
} |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
void Content::removeProperty( const OUString& Name, |
| 937 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 938 |
{ |
| 939 |
#if 0 |
| 940 |
// @@@ REMOVABLE at the moment not properly set in the PropSetInfo |
| 941 |
try |
| 942 |
{ |
| 943 |
beans::Property aProp |
| 944 |
= getPropertySetInfo( xEnv, false /* don't cache data */ ) |
| 945 |
->getPropertyByName( Name ); |
| 946 |
|
| 947 |
if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) ) |
| 948 |
{ |
| 949 |
// Not removable! |
| 950 |
throw beans::NotRemoveableException(); |
| 951 |
} |
| 952 |
} |
| 953 |
catch ( beans::UnknownPropertyException const & ) |
| 954 |
{ |
| 955 |
//SAL_WARN( "ucb.ucp.webdav", "removeProperty - Unknown property!" ); |
| 956 |
throw; |
| 957 |
} |
| 958 |
#endif |
| 959 |
|
| 960 |
// Try to remove property from server. |
| 961 |
try |
| 962 |
{ |
| 963 |
std::vector< ProppatchValue > aProppatchValues; |
| 964 |
ProppatchValue aValue( PROPREMOVE, Name, uno::Any() ); |
| 965 |
aProppatchValues.push_back( aValue ); |
| 966 |
|
| 967 |
// Remove property value from server. |
| 968 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 969 |
{ |
| 970 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 971 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 972 |
} |
| 973 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 974 |
// clean cached value of PROPFIND property names |
| 975 |
// PROPPATCH can change them |
| 976 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 977 |
xResAccess->PROPPATCH( aProppatchValues, xEnv ); |
| 978 |
{ |
| 979 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 980 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 981 |
} |
| 982 |
|
| 983 |
// Notify propertyset info change listeners. |
| 984 |
beans::PropertySetInfoChangeEvent evt( |
| 985 |
getXWeak(), |
| 986 |
Name, |
| 987 |
-1, // No handle available |
| 988 |
beans::PropertySetInfoChange::PROPERTY_REMOVED ); |
| 989 |
notifyPropertySetInfoChange( evt ); |
| 990 |
} |
| 991 |
catch ( DAVException const & e ) |
| 992 |
{ |
| 993 |
if ( e.getStatus() == SC_FORBIDDEN ) |
| 994 |
{ |
| 995 |
// Support for setting arbitrary dead properties is optional! |
| 996 |
|
| 997 |
// Try to remove property from local store. |
| 998 |
ContentImplHelper::removeProperty( Name ); |
| 999 |
} |
| 1000 |
else |
| 1001 |
{ |
| 1002 |
if ( shouldAccessNetworkAfterException( e ) ) |
| 1003 |
{ |
| 1004 |
try |
| 1005 |
{ |
| 1006 |
const ResourceType eType = getResourceType( xEnv ); |
| 1007 |
switch ( eType ) |
| 1008 |
{ |
| 1009 |
case UNKNOWN: |
| 1010 |
case DAV: |
| 1011 |
throw beans::UnknownPropertyException(Name); |
| 1012 |
|
| 1013 |
case NON_DAV: |
| 1014 |
// Try to remove property from local store. |
| 1015 |
ContentImplHelper::removeProperty( Name ); |
| 1016 |
break; |
| 1017 |
|
| 1018 |
default: |
| 1019 |
SAL_WARN( "ucb.ucp.webdav", |
| 1020 |
"Content::removeProperty - " |
| 1021 |
"Unsupported resource type!" ); |
| 1022 |
break; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
catch ( uno::Exception const & ) |
| 1026 |
{ |
| 1027 |
SAL_WARN( "ucb.ucp.webdav", |
| 1028 |
"Content::removeProperty - " |
| 1029 |
"Unable to determine resource type!" ); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
else |
| 1033 |
{ |
| 1034 |
SAL_WARN( "ucb.ucp.webdav", |
| 1035 |
"Content::removeProperty - " |
| 1036 |
"Unable to determine resource type!" ); |
| 1037 |
// throw beans::UnknownPropertyException(); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
// virtual |
| 1044 |
void SAL_CALL Content::addProperty( const OUString& Name, |
| 1045 |
sal_Int16 Attributes, |
| 1046 |
const uno::Any& DefaultValue ) |
| 1047 |
{ |
| 1048 |
beans::Property aProperty; |
| 1049 |
aProperty.Name = Name; |
| 1050 |
aProperty.Type = DefaultValue.getValueType(); |
| 1051 |
aProperty.Attributes = Attributes; |
| 1052 |
aProperty.Handle = -1; |
| 1053 |
|
| 1054 |
addProperty( ucb::PropertyCommandArgument( aProperty, DefaultValue ), |
| 1055 |
uno::Reference< ucb::XCommandEnvironment >()); |
| 1056 |
} |
| 1057 |
|
| 1058 |
// virtual |
| 1059 |
void SAL_CALL Content::removeProperty( const OUString& Name ) |
| 1060 |
{ |
| 1061 |
removeProperty( Name, |
| 1062 |
uno::Reference< ucb::XCommandEnvironment >() ); |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
// XContentCreator methods. |
| 1067 |
|
| 1068 |
|
| 1069 |
// virtual |
| 1070 |
uno::Sequence< ucb::ContentInfo > SAL_CALL |
| 1071 |
Content::queryCreatableContentsInfo() |
| 1072 |
{ |
| 1073 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 1074 |
|
| 1075 |
uno::Sequence< ucb::ContentInfo > aSeq( 2 ); |
| 1076 |
|
| 1077 |
// document. |
| 1078 |
aSeq.getArray()[ 0 ].Type = WEBDAV_CONTENT_TYPE; |
| 1079 |
aSeq.getArray()[ 0 ].Attributes |
| 1080 |
= ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM |
| 1081 |
| ucb::ContentInfoAttribute::KIND_DOCUMENT; |
| 1082 |
|
| 1083 |
beans::Property aProp; |
| 1084 |
m_pProvider->getProperty( u"Title"_ustr, aProp ); |
| 1085 |
|
| 1086 |
uno::Sequence< beans::Property > aDocProps( 1 ); |
| 1087 |
aDocProps.getArray()[ 0 ] = aProp; |
| 1088 |
aSeq.getArray()[ 0 ].Properties = std::move(aDocProps); |
| 1089 |
|
| 1090 |
// folder. |
| 1091 |
aSeq.getArray()[ 1 ].Type = WEBDAV_COLLECTION_TYPE; |
| 1092 |
aSeq.getArray()[ 1 ].Attributes |
| 1093 |
= ucb::ContentInfoAttribute::KIND_FOLDER; |
| 1094 |
|
| 1095 |
uno::Sequence< beans::Property > aFolderProps( 1 ); |
| 1096 |
aFolderProps.getArray()[0] = std::move(aProp); |
| 1097 |
aSeq.getArray()[ 1 ].Properties = std::move(aFolderProps); |
| 1098 |
return aSeq; |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
// virtual |
| 1103 |
uno::Reference< ucb::XContent > SAL_CALL |
| 1104 |
Content::createNewContent( const ucb::ContentInfo& Info ) |
| 1105 |
{ |
| 1106 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 1107 |
|
| 1108 |
if ( !Info.Type.getLength() ) |
| 1109 |
return uno::Reference< ucb::XContent >(); |
| 1110 |
|
| 1111 |
if ( ( Info.Type != WEBDAV_COLLECTION_TYPE ) |
| 1112 |
&& |
| 1113 |
( Info.Type != WEBDAV_CONTENT_TYPE ) ) |
| 1114 |
return uno::Reference< ucb::XContent >(); |
| 1115 |
|
| 1116 |
OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 1117 |
|
| 1118 |
SAL_WARN_IF( aURL.isEmpty(), "ucb.ucp.webdav", |
| 1119 |
"WebdavContent::createNewContent - empty identifier!" ); |
| 1120 |
|
| 1121 |
if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) |
| 1122 |
aURL += "/"; |
| 1123 |
|
| 1124 |
bool isCollection; |
| 1125 |
if ( Info.Type == WEBDAV_COLLECTION_TYPE ) |
| 1126 |
{ |
| 1127 |
aURL += "New_Collection"; |
| 1128 |
isCollection = true; |
| 1129 |
} |
| 1130 |
else |
| 1131 |
{ |
| 1132 |
aURL += "New_Content"; |
| 1133 |
isCollection = false; |
| 1134 |
} |
| 1135 |
|
| 1136 |
uno::Reference< ucb::XContentIdentifier > xId( |
| 1137 |
new ::ucbhelper::ContentIdentifier( aURL ) ); |
| 1138 |
|
| 1139 |
// create the local content |
| 1140 |
try |
| 1141 |
{ |
| 1142 |
return new ::http_dav_ucp::Content( m_xContext, |
| 1143 |
m_pProvider, |
| 1144 |
xId, |
| 1145 |
m_xResAccess->getSessionFactory(), |
| 1146 |
isCollection ); |
| 1147 |
} |
| 1148 |
catch ( ucb::ContentCreationException & ) |
| 1149 |
{ |
| 1150 |
return uno::Reference< ucb::XContent >(); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
// virtual |
| 1156 |
OUString Content::getParentURL() |
| 1157 |
{ |
| 1158 |
// <scheme>:// -> "" |
| 1159 |
// <scheme>://foo -> "" |
| 1160 |
// <scheme>://foo/ -> "" |
| 1161 |
// <scheme>://foo/bar -> <scheme>://foo/ |
| 1162 |
// <scheme>://foo/bar/ -> <scheme>://foo/ |
| 1163 |
// <scheme>://foo/bar/abc -> <scheme>://foo/bar/ |
| 1164 |
|
| 1165 |
OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 1166 |
|
| 1167 |
sal_Int32 nPos = aURL.lastIndexOf( '/' ); |
| 1168 |
if ( nPos == ( aURL.getLength() - 1 ) ) |
| 1169 |
{ |
| 1170 |
// Trailing slash found. Skip. |
| 1171 |
nPos = aURL.lastIndexOf( '/', nPos ); |
| 1172 |
} |
| 1173 |
|
| 1174 |
sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos ); |
| 1175 |
if ( nPos1 != -1 ) |
| 1176 |
nPos1 = aURL.lastIndexOf( '/', nPos1 ); |
| 1177 |
|
| 1178 |
if ( nPos1 == -1 ) |
| 1179 |
return OUString(); |
| 1180 |
|
| 1181 |
return aURL.copy( 0, nPos + 1 ); |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
// Non-interface methods. |
| 1186 |
|
| 1187 |
|
| 1188 |
// static |
| 1189 |
uno::Reference< sdbc::XRow > Content::getPropertyValues( |
| 1190 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 1191 |
const uno::Sequence< beans::Property >& rProperties, |
| 1192 |
const ContentProperties& rData, |
| 1193 |
const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider, |
| 1194 |
const OUString& rContentId ) |
| 1195 |
{ |
| 1196 |
// Note: Empty sequence means "get values of all supported properties". |
| 1197 |
|
| 1198 |
rtl::Reference< ::ucbhelper::PropertyValueSet > xRow |
| 1199 |
= new ::ucbhelper::PropertyValueSet( rxContext ); |
| 1200 |
|
| 1201 |
sal_Int32 nCount = rProperties.getLength(); |
| 1202 |
if ( nCount ) |
| 1203 |
{ |
| 1204 |
uno::Reference< beans::XPropertySet > xAdditionalPropSet; |
| 1205 |
bool bTriedToGetAdditionalPropSet = false; |
| 1206 |
|
| 1207 |
const beans::Property* pProps = rProperties.getConstArray(); |
| 1208 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 1209 |
{ |
| 1210 |
const beans::Property& rProp = pProps[ n ]; |
| 1211 |
|
| 1212 |
// Process standard UCB, DAV and HTTP properties. |
| 1213 |
const uno::Any & rValue = rData.getValue( rProp.Name ); |
| 1214 |
if ( rValue.hasValue() ) |
| 1215 |
{ |
| 1216 |
xRow->appendObject( rProp, rValue ); |
| 1217 |
} |
| 1218 |
else |
| 1219 |
{ |
| 1220 |
// Process local Additional Properties. |
| 1221 |
if ( !bTriedToGetAdditionalPropSet && !xAdditionalPropSet.is() ) |
| 1222 |
{ |
| 1223 |
xAdditionalPropSet = |
| 1224 |
rProvider->getAdditionalPropertySet( rContentId, |
| 1225 |
false ); |
| 1226 |
bTriedToGetAdditionalPropSet = true; |
| 1227 |
} |
| 1228 |
|
| 1229 |
if ( !xAdditionalPropSet.is() || |
| 1230 |
!xRow->appendPropertySetValue( |
| 1231 |
xAdditionalPropSet, rProp ) ) |
| 1232 |
{ |
| 1233 |
// Append empty entry. |
| 1234 |
xRow->appendVoid( rProp ); |
| 1235 |
} |
| 1236 |
} |
| 1237 |
} |
| 1238 |
} |
| 1239 |
else |
| 1240 |
{ |
| 1241 |
// Append all standard UCB, DAV and HTTP properties. |
| 1242 |
|
| 1243 |
const std::unique_ptr< PropertyValueMap > & xProps = rData.getProperties(); |
| 1244 |
|
| 1245 |
ContentProvider * pProvider |
| 1246 |
= static_cast< ContentProvider * >( rProvider.get() ); |
| 1247 |
beans::Property aProp; |
| 1248 |
|
| 1249 |
for ( const auto& rProp : *xProps ) |
| 1250 |
{ |
| 1251 |
if ( pProvider->getProperty( rProp.first, aProp ) ) |
| 1252 |
xRow->appendObject( aProp, rProp.second.value() ); |
| 1253 |
} |
| 1254 |
|
| 1255 |
// Append all local Additional Properties. |
| 1256 |
uno::Reference< beans::XPropertySet > xSet = |
| 1257 |
rProvider->getAdditionalPropertySet( rContentId, false ); |
| 1258 |
xRow->appendPropertySet( xSet ); |
| 1259 |
} |
| 1260 |
|
| 1261 |
return uno::Reference<sdbc::XRow>(xRow); |
| 1262 |
} |
| 1263 |
|
| 1264 |
namespace { |
| 1265 |
void GetPropsUsingHeadRequest(DAVResource& resource, |
| 1266 |
const std::unique_ptr< DAVResourceAccess >& xResAccess, |
| 1267 |
const std::vector< OUString >& aHTTPNames, |
| 1268 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv) |
| 1269 |
{ |
| 1270 |
if (!aHTTPNames.empty()) |
| 1271 |
{ |
| 1272 |
DAVOptions aDAVOptions; |
| 1273 |
OUString aTargetURL = xResAccess->getURL(); |
| 1274 |
// retrieve the cached options if any |
| 1275 |
aStaticDAVOptionsCache.getDAVOptions(aTargetURL, aDAVOptions); |
| 1276 |
|
| 1277 |
// clean cached value of PROPFIND property names |
| 1278 |
// PROPPATCH can change them |
| 1279 |
Content::removeCachedPropertyNames(aTargetURL); |
| 1280 |
// test if HEAD allowed, if not, throw, should be caught immediately |
| 1281 |
// SC_GONE used internally by us, see comment in Content::getPropertyValues |
| 1282 |
// in the catch scope |
| 1283 |
if (aDAVOptions.getHttpResponseStatusCode() != SC_GONE && |
| 1284 |
!aDAVOptions.isHeadAllowed()) |
| 1285 |
{ |
| 1286 |
throw DAVException(DAVException::DAV_HTTP_ERROR, u"405 Not Implemented"_ustr, SC_METHOD_NOT_ALLOWED); |
| 1287 |
} |
| 1288 |
// if HEAD is enabled on this site |
| 1289 |
// check if there is a relevant HTTP response status code cached |
| 1290 |
if (aDAVOptions.getHttpResponseStatusCode() != SC_NONE) |
| 1291 |
{ |
| 1292 |
// throws exception as if there was a server error, a DAV exception |
| 1293 |
throw DAVException(DAVException::DAV_HTTP_ERROR, |
| 1294 |
aDAVOptions.getHttpResponseStatusText(), |
| 1295 |
aDAVOptions.getHttpResponseStatusCode()); |
| 1296 |
// Unreachable |
| 1297 |
} |
| 1298 |
|
| 1299 |
xResAccess->HEAD(aHTTPNames, resource, xEnv); |
| 1300 |
} |
| 1301 |
} |
| 1302 |
} |
| 1303 |
|
| 1304 |
uno::Reference< sdbc::XRow > Content::getPropertyValues( |
| 1305 |
const uno::Sequence< beans::Property >& rProperties, |
| 1306 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 1307 |
{ |
| 1308 |
std::unique_ptr< ContentProperties > xProps; |
| 1309 |
std::unique_ptr< ContentProperties > xCachedProps; |
| 1310 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 1311 |
OUString aUnescapedTitle; |
| 1312 |
bool bHasAll = false; |
| 1313 |
uno::Reference< uno::XComponentContext > xContext; |
| 1314 |
uno::Reference< ucb::XContentIdentifier > xIdentifier; |
| 1315 |
rtl::Reference< ::ucbhelper::ContentProviderImplHelper > xProvider; |
| 1316 |
|
| 1317 |
{ |
| 1318 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 1319 |
|
| 1320 |
aUnescapedTitle = DecodeURI(m_aEscapedTitle); |
| 1321 |
xContext.set( m_xContext ); |
| 1322 |
xIdentifier.set( m_xIdentifier ); |
| 1323 |
xProvider = m_xProvider; |
| 1324 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 1325 |
|
| 1326 |
// First, ask cache... |
| 1327 |
if (m_xCachedProps) |
| 1328 |
{ |
| 1329 |
xCachedProps.reset( new ContentProperties( *m_xCachedProps ) ); |
| 1330 |
|
| 1331 |
std::vector< OUString > aMissingProps; |
| 1332 |
if ( xCachedProps->containsAllNames( rProperties, aMissingProps ) ) |
| 1333 |
{ |
| 1334 |
// All properties are already in cache! No server access needed. |
| 1335 |
bHasAll = true; |
| 1336 |
} |
| 1337 |
|
| 1338 |
// use the cached ContentProperties instance |
| 1339 |
xProps.reset( new ContentProperties( *xCachedProps ) ); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
bool bNetworkAccessAllowed = true; |
| 1344 |
|
| 1345 |
if ( !m_bTransient && !bHasAll ) |
| 1346 |
{ |
| 1347 |
// Obtain values from server... |
| 1348 |
|
| 1349 |
|
| 1350 |
// First, identify whether resource is DAV or not |
| 1351 |
const ResourceType eType = getResourceType( |
| 1352 |
xEnv, xResAccess, &bNetworkAccessAllowed ); |
| 1353 |
|
| 1354 |
if ( eType == DAV ) |
| 1355 |
{ |
| 1356 |
// cache lookup... getResourceType may fill the props cache via |
| 1357 |
// PROPFIND! |
| 1358 |
if (m_xCachedProps) |
| 1359 |
{ |
| 1360 |
xCachedProps.reset( |
| 1361 |
new ContentProperties( *m_xCachedProps ) ); |
| 1362 |
|
| 1363 |
std::vector< OUString > aMissingProps; |
| 1364 |
if ( xCachedProps->containsAllNames( |
| 1365 |
rProperties, aMissingProps ) ) |
| 1366 |
{ |
| 1367 |
// All properties are already in cache! No server access |
| 1368 |
// needed. |
| 1369 |
bHasAll = true; |
| 1370 |
} |
| 1371 |
|
| 1372 |
// use the cached ContentProperties instance |
| 1373 |
xProps.reset( new ContentProperties( *xCachedProps ) ); |
| 1374 |
} |
| 1375 |
|
| 1376 |
if ( !bHasAll ) |
| 1377 |
{ |
| 1378 |
// Only DAV resources support PROPFIND |
| 1379 |
std::vector< OUString > aPropNames; |
| 1380 |
|
| 1381 |
const uno::Sequence< beans::Property >& aProperties(rProperties); |
| 1382 |
|
| 1383 |
if ( aProperties.getLength() > 0 ) |
| 1384 |
ContentProperties::UCBNamesToDAVNames( |
| 1385 |
aProperties, aPropNames ); |
| 1386 |
|
| 1387 |
if ( !aPropNames.empty() ) |
| 1388 |
{ |
| 1389 |
std::vector< DAVResource > resources; |
| 1390 |
try |
| 1391 |
{ |
| 1392 |
xResAccess->PROPFIND( |
| 1393 |
DAVZERO, aPropNames, resources, xEnv ); |
| 1394 |
|
| 1395 |
if ( 1 == resources.size() ) |
| 1396 |
{ |
| 1397 |
#if defined SAL_LOG_INFO |
| 1398 |
{//debug |
| 1399 |
// print received resources |
| 1400 |
std::vector< DAVPropertyValue >::const_iterator it = resources[0].properties.begin(); |
| 1401 |
std::vector< DAVPropertyValue >::const_iterator end = resources[0].properties.end(); |
| 1402 |
while ( it != end ) |
| 1403 |
{ |
| 1404 |
OUString aPropValue; |
| 1405 |
bool bValue; |
| 1406 |
uno::Sequence< ucb::LockEntry > aSupportedLocks; |
| 1407 |
if( (*it).Value >>= aPropValue ) |
| 1408 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getPropertyValues) - returned property: " << (*it).Name << ":" << aPropValue ); |
| 1409 |
else if( (*it).Value >>= bValue ) |
| 1410 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getPropertyValues) - returned property: " << (*it).Name << ":" << |
| 1411 |
( bValue ? "true" : "false" ) ); |
| 1412 |
else if( (*it).Value >>= aSupportedLocks ) |
| 1413 |
{ |
| 1414 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getPropertyValues) - returned property: " << (*it).Name << ":" ); |
| 1415 |
for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n ) |
| 1416 |
{ |
| 1417 |
SAL_INFO( "ucb.ucp.webdav"," scope: " |
| 1418 |
<< (aSupportedLocks[n].Scope == ucb::LockScope_SHARED ? "shared" : "exclusive") |
| 1419 |
<< ", type: " |
| 1420 |
<< (aSupportedLocks[n].Type != ucb::LockType_WRITE ? "" : "write") ); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
++it; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
#endif |
| 1427 |
if (xProps) |
| 1428 |
xProps->addProperties( |
| 1429 |
aPropNames, |
| 1430 |
ContentProperties( resources[ 0 ] )); |
| 1431 |
else |
| 1432 |
xProps.reset( |
| 1433 |
new ContentProperties( resources[ 0 ] ) ); |
| 1434 |
} |
| 1435 |
} |
| 1436 |
catch ( DAVException const & e ) |
| 1437 |
{ |
| 1438 |
bNetworkAccessAllowed = bNetworkAccessAllowed |
| 1439 |
&& shouldAccessNetworkAfterException( e ); |
| 1440 |
|
| 1441 |
if ( !bNetworkAccessAllowed ) |
| 1442 |
{ |
| 1443 |
cancelCommandExecution( e, xEnv ); |
| 1444 |
// unreachable |
| 1445 |
} |
| 1446 |
} |
| 1447 |
} |
| 1448 |
} |
| 1449 |
} |
| 1450 |
|
| 1451 |
if ( bNetworkAccessAllowed ) |
| 1452 |
{ |
| 1453 |
// All properties obtained already? |
| 1454 |
std::vector< OUString > aMissingProps; |
| 1455 |
if ( !( xProps |
| 1456 |
&& xProps->containsAllNames(rProperties, aMissingProps)) |
| 1457 |
// i#121922 for non-DAV, uncacheable properties must be fetched |
| 1458 |
// regardless of m_bDidGetOrHead. |
| 1459 |
// But SharePoint may do weird things on HEAD so for DAV |
| 1460 |
// only do this if required. |
| 1461 |
&& (eType != DAV || !m_bDidGetOrHead)) |
| 1462 |
{ |
| 1463 |
// Possibly the missing props can be obtained using a HEAD |
| 1464 |
// request. |
| 1465 |
|
| 1466 |
std::vector< OUString > aHeaderNames; |
| 1467 |
ContentProperties::UCBNamesToHTTPNames( |
| 1468 |
rProperties, |
| 1469 |
aHeaderNames ); |
| 1470 |
|
| 1471 |
if( eType != DAV ) |
| 1472 |
{ |
| 1473 |
// in case of not DAV PROFIND (previously in program flow) failed |
| 1474 |
// so we need to add the only prop that's common |
| 1475 |
// to DAV and NON_DAV: MediaType, that maps to Content-Type |
| 1476 |
aHeaderNames.emplace_back("Content-Type"); |
| 1477 |
} |
| 1478 |
|
| 1479 |
if (!aHeaderNames.empty()) try |
| 1480 |
{ |
| 1481 |
DAVResource resource; |
| 1482 |
GetPropsUsingHeadRequest(resource, xResAccess, aHeaderNames, xEnv); |
| 1483 |
m_bDidGetOrHead = true; |
| 1484 |
|
| 1485 |
if (xProps) |
| 1486 |
xProps->addProperties( |
| 1487 |
aMissingProps, |
| 1488 |
ContentProperties( resource ) ); |
| 1489 |
else |
| 1490 |
xProps.reset ( new ContentProperties( resource ) ); |
| 1491 |
|
| 1492 |
if (m_eResourceType == NON_DAV) |
| 1493 |
xProps->addProperties(aMissingProps, |
| 1494 |
ContentProperties( |
| 1495 |
aUnescapedTitle, |
| 1496 |
false)); |
| 1497 |
} |
| 1498 |
catch ( DAVException const & e ) |
| 1499 |
{ |
| 1500 |
// non "general-purpose servers" may not support HEAD requests |
| 1501 |
// see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1 |
| 1502 |
// In this case, perform a partial GET only to get the header info |
| 1503 |
// vid. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 |
| 1504 |
// WARNING if the server does not support partial GETs, |
| 1505 |
// the GET will transfer the whole content |
| 1506 |
bool bError = true; |
| 1507 |
DAVException aLastException = e; |
| 1508 |
OUString aTargetURL = xResAccess->getURL(); |
| 1509 |
|
| 1510 |
if ( e.getError() == DAVException::DAV_HTTP_ERROR ) |
| 1511 |
{ |
| 1512 |
// According to the spec. the origin server SHOULD return |
| 1513 |
// * 405 (Method Not Allowed): |
| 1514 |
// the method is known but not allowed for the requested resource |
| 1515 |
// * 501 (Not Implemented): |
| 1516 |
// the method is unrecognized or not implemented |
| 1517 |
// * 404 (SC_NOT_FOUND) |
| 1518 |
// is for google-code server and for MS IIS 10.0 Web server |
| 1519 |
// when only GET is enabled |
| 1520 |
if ( aLastException.getStatus() == SC_NOT_IMPLEMENTED || |
| 1521 |
aLastException.getStatus() == SC_METHOD_NOT_ALLOWED || |
| 1522 |
aLastException.getStatus() == SC_NOT_FOUND ) |
| 1523 |
{ |
| 1524 |
SAL_WARN( "ucb.ucp.webdav", "HEAD probably not implemented: fall back to a partial GET" ); |
| 1525 |
aStaticDAVOptionsCache.setHeadAllowed( aTargetURL, false ); |
| 1526 |
lcl_sendPartialGETRequest( bError, |
| 1527 |
aLastException, |
| 1528 |
aMissingProps, |
| 1529 |
aHeaderNames, |
| 1530 |
xResAccess, |
| 1531 |
xProps, |
| 1532 |
xEnv ); |
| 1533 |
m_bDidGetOrHead = !bError; |
| 1534 |
} |
| 1535 |
} |
| 1536 |
|
| 1537 |
if ( bError ) |
| 1538 |
{ |
| 1539 |
DAVOptions aDAVOptionsException; |
| 1540 |
|
| 1541 |
aDAVOptionsException.setURL( aTargetURL ); |
| 1542 |
// check if the error was SC_NOT_FOUND, meaning that the |
| 1543 |
// GET fall back didn't succeeded and the element is really missing |
| 1544 |
// we will consider the resource SC_GONE (410) for some time |
| 1545 |
// we use SC_GONE because has the same meaning of SC_NOT_FOUND (404) |
| 1546 |
// see: |
| 1547 |
// <https://tools.ietf.org/html/rfc7231#section-6.5.9> (retrieved 2016-10-09) |
| 1548 |
// apparently it's not used to mark the missing HEAD method (so far...) |
| 1549 |
sal_uInt16 ResponseStatusCode = |
| 1550 |
( aLastException.getStatus() == SC_NOT_FOUND ) ? |
| 1551 |
SC_GONE : |
| 1552 |
aLastException.getStatus(); |
| 1553 |
aDAVOptionsException.setHttpResponseStatusCode( ResponseStatusCode ); |
| 1554 |
aDAVOptionsException.setHttpResponseStatusText( aLastException.getData() ); |
| 1555 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptionsException, |
| 1556 |
m_nOptsCacheLifeNotFound ); |
| 1557 |
|
| 1558 |
if ( !shouldAccessNetworkAfterException( aLastException ) ) |
| 1559 |
{ |
| 1560 |
cancelCommandExecution( aLastException, xEnv ); |
| 1561 |
// unreachable |
| 1562 |
} |
| 1563 |
} |
| 1564 |
} |
| 1565 |
} |
| 1566 |
} |
| 1567 |
|
| 1568 |
// might trigger HTTP redirect. |
| 1569 |
// Therefore, title must be updated here. |
| 1570 |
CurlUri const aUri( xResAccess->getURL() ); |
| 1571 |
aUnescapedTitle = aUri.GetPathBaseNameUnescaped(); |
| 1572 |
|
| 1573 |
if ( eType == UNKNOWN ) |
| 1574 |
{ |
| 1575 |
xProps.reset( new ContentProperties( aUnescapedTitle ) ); |
| 1576 |
} |
| 1577 |
|
| 1578 |
// For DAV resources we only know the Title, for non-DAV |
| 1579 |
// resources we additionally know that it is a document. |
| 1580 |
|
| 1581 |
else if ( eType == DAV ) |
| 1582 |
{ |
| 1583 |
if (!xProps) |
| 1584 |
xProps.reset(new ContentProperties(aUnescapedTitle)); |
| 1585 |
else |
| 1586 |
xProps->addProperty(u"Title"_ustr, uno::Any(aUnescapedTitle), true); |
| 1587 |
} |
| 1588 |
else |
| 1589 |
{ |
| 1590 |
if (!xProps) |
| 1591 |
xProps.reset( new ContentProperties( aUnescapedTitle, false ) ); |
| 1592 |
else |
| 1593 |
xProps->addProperty( |
| 1594 |
u"Title"_ustr, |
| 1595 |
uno::Any( aUnescapedTitle ), |
| 1596 |
true ); |
| 1597 |
|
| 1598 |
xProps->addProperty( |
| 1599 |
u"IsFolder"_ustr, |
| 1600 |
uno::Any( false ), |
| 1601 |
true ); |
| 1602 |
xProps->addProperty( |
| 1603 |
u"IsDocument"_ustr, |
| 1604 |
uno::Any( true ), |
| 1605 |
true ); |
| 1606 |
xProps->addProperty( |
| 1607 |
u"ContentType"_ustr, |
| 1608 |
uno::Any( WEBDAV_CONTENT_TYPE ), |
| 1609 |
true ); |
| 1610 |
} |
| 1611 |
} |
| 1612 |
else |
| 1613 |
{ |
| 1614 |
// No server access for just created (not yet committed) objects. |
| 1615 |
// Only a minimal set of properties supported at this stage. |
| 1616 |
if (m_bTransient) |
| 1617 |
xProps.reset( new ContentProperties( aUnescapedTitle, |
| 1618 |
m_bCollection ) ); |
| 1619 |
} |
| 1620 |
|
| 1621 |
// Add a default for the properties requested but not found. |
| 1622 |
// Determine still missing properties, add a default. |
| 1623 |
// Some client function doesn't expect a void uno::Any, |
| 1624 |
// but instead wants some sort of default. |
| 1625 |
std::vector< OUString > aMissingProps; |
| 1626 |
if ( !xProps->containsAllNames( |
| 1627 |
rProperties, aMissingProps ) ) |
| 1628 |
{ |
| 1629 |
// |
| 1630 |
for ( std::vector< rtl::OUString >::const_iterator it = aMissingProps.begin(); |
| 1631 |
it != aMissingProps.end(); ++it ) |
| 1632 |
{ |
| 1633 |
// For the time being only a couple of properties need to be added |
| 1634 |
if ( (*it) == "DateModified" || (*it) == "DateCreated" ) |
| 1635 |
{ |
| 1636 |
util::DateTime aDate; |
| 1637 |
xProps->addProperty( |
| 1638 |
(*it), |
| 1639 |
uno::Any( aDate ), |
| 1640 |
true ); |
| 1641 |
} |
| 1642 |
else if (bNetworkAccessAllowed) // don't set these if connection failed |
| 1643 |
{ |
| 1644 |
// If WebDAV didn't return the resource type, assume default |
| 1645 |
// This happens e.g. for lists exported by SharePoint |
| 1646 |
if ((*it) == "IsFolder") |
| 1647 |
{ |
| 1648 |
xProps->addProperty( |
| 1649 |
(*it), |
| 1650 |
uno::Any( false ), |
| 1651 |
true ); |
| 1652 |
} |
| 1653 |
else if ((*it) == "IsDocument") |
| 1654 |
{ |
| 1655 |
xProps->addProperty( |
| 1656 |
(*it), |
| 1657 |
uno::Any( true ), |
| 1658 |
true ); |
| 1659 |
} |
| 1660 |
} |
| 1661 |
} |
| 1662 |
} |
| 1663 |
|
| 1664 |
sal_Int32 nCount = rProperties.getLength(); |
| 1665 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 1666 |
{ |
| 1667 |
const OUString rName = rProperties[ n ].Name; |
| 1668 |
if ( rName == "BaseURI" ) |
| 1669 |
{ |
| 1670 |
// Add BaseURI property, if requested. |
| 1671 |
xProps->addProperty( |
| 1672 |
u"BaseURI"_ustr, |
| 1673 |
uno::Any( getBaseURI( xResAccess ) ), |
| 1674 |
true ); |
| 1675 |
} |
| 1676 |
else if ( rName == "CreatableContentsInfo" ) |
| 1677 |
{ |
| 1678 |
// Add CreatableContentsInfo property, if requested. |
| 1679 |
bool bFolder = false; |
| 1680 |
xProps->getValue( u"IsFolder"_ustr ) |
| 1681 |
>>= bFolder; |
| 1682 |
xProps->addProperty( |
| 1683 |
u"CreatableContentsInfo"_ustr, |
| 1684 |
uno::Any( bFolder |
| 1685 |
? queryCreatableContentsInfo() |
| 1686 |
: uno::Sequence< ucb::ContentInfo >() ), |
| 1687 |
true ); |
| 1688 |
} |
| 1689 |
} |
| 1690 |
|
| 1691 |
uno::Reference< sdbc::XRow > xResultRow |
| 1692 |
= getPropertyValues( xContext, |
| 1693 |
rProperties, |
| 1694 |
*xProps, |
| 1695 |
xProvider, |
| 1696 |
xIdentifier->getContentIdentifier() ); |
| 1697 |
|
| 1698 |
{ |
| 1699 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 1700 |
|
| 1701 |
if (!m_xCachedProps) |
| 1702 |
m_xCachedProps.reset( new CachableContentProperties( *xProps ) ); |
| 1703 |
else |
| 1704 |
m_xCachedProps->addProperties( *xProps ); |
| 1705 |
|
| 1706 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 1707 |
m_aEscapedTitle = EncodeSegment(aUnescapedTitle); |
| 1708 |
} |
| 1709 |
|
| 1710 |
return xResultRow; |
| 1711 |
} |
| 1712 |
|
| 1713 |
|
| 1714 |
uno::Sequence< uno::Any > Content::setPropertyValues( |
| 1715 |
const uno::Sequence< beans::PropertyValue >& rValues, |
| 1716 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 1717 |
{ |
| 1718 |
uno::Reference< ucb::XContentIdentifier > xIdentifier; |
| 1719 |
rtl::Reference< ContentProvider > xProvider; |
| 1720 |
bool bTransient; |
| 1721 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 1722 |
|
| 1723 |
{ |
| 1724 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 1725 |
|
| 1726 |
xProvider.set( m_pProvider ); |
| 1727 |
xIdentifier.set( m_xIdentifier ); |
| 1728 |
bTransient = m_bTransient; |
| 1729 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 1730 |
} |
| 1731 |
|
| 1732 |
uno::Sequence< uno::Any > aRet( rValues.getLength() ); |
| 1733 |
auto aRetRange = asNonConstRange(aRet); |
| 1734 |
uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() ); |
| 1735 |
sal_Int32 nChanged = 0; |
| 1736 |
|
| 1737 |
beans::PropertyChangeEvent aEvent; |
| 1738 |
aEvent.Source = getXWeak(); |
| 1739 |
aEvent.Further = false; |
| 1740 |
// aEvent.PropertyName = |
| 1741 |
aEvent.PropertyHandle = -1; |
| 1742 |
// aEvent.OldValue = |
| 1743 |
// aEvent.NewValue = |
| 1744 |
|
| 1745 |
std::vector< ProppatchValue > aProppatchValues; |
| 1746 |
std::vector< sal_Int32 > aProppatchPropsPositions; |
| 1747 |
|
| 1748 |
uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet; |
| 1749 |
bool bTriedToGetAdditionalPropSet = false; |
| 1750 |
|
| 1751 |
bool bExchange = false; |
| 1752 |
OUString aNewTitle; |
| 1753 |
OUString aOldTitle; |
| 1754 |
sal_Int32 nTitlePos = -1; |
| 1755 |
|
| 1756 |
uno::Reference< beans::XPropertySetInfo > xInfo; |
| 1757 |
|
| 1758 |
const beans::PropertyValue* pValues = rValues.getConstArray(); |
| 1759 |
sal_Int32 nCount = rValues.getLength(); |
| 1760 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 1761 |
{ |
| 1762 |
const beans::PropertyValue& rValue = pValues[ n ]; |
| 1763 |
const OUString & rName = rValue.Name; |
| 1764 |
|
| 1765 |
beans::Property aTmpProp; |
| 1766 |
xProvider->getProperty( rName, aTmpProp ); |
| 1767 |
|
| 1768 |
if ( aTmpProp.Attributes & beans::PropertyAttribute::READONLY ) |
| 1769 |
{ |
| 1770 |
// Read-only property! |
| 1771 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1772 |
u"Property is read-only!"_ustr, |
| 1773 |
getXWeak() ); |
| 1774 |
continue; |
| 1775 |
} |
| 1776 |
|
| 1777 |
|
| 1778 |
// Mandatory props. |
| 1779 |
|
| 1780 |
|
| 1781 |
if ( rName == "ContentType" ) |
| 1782 |
{ |
| 1783 |
// Read-only property! |
| 1784 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1785 |
u"Property is read-only!"_ustr, |
| 1786 |
getXWeak() ); |
| 1787 |
} |
| 1788 |
else if ( rName == "IsDocument" ) |
| 1789 |
{ |
| 1790 |
// Read-only property! |
| 1791 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1792 |
u"Property is read-only!"_ustr, |
| 1793 |
getXWeak() ); |
| 1794 |
} |
| 1795 |
else if ( rName == "IsFolder" ) |
| 1796 |
{ |
| 1797 |
// Read-only property! |
| 1798 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1799 |
u"Property is read-only!"_ustr, |
| 1800 |
getXWeak() ); |
| 1801 |
} |
| 1802 |
else if ( rName == "Title" ) |
| 1803 |
{ |
| 1804 |
OUString aNewValue; |
| 1805 |
if ( rValue.Value >>= aNewValue ) |
| 1806 |
{ |
| 1807 |
// No empty titles! |
| 1808 |
if ( aNewValue.getLength() > 0 ) |
| 1809 |
{ |
| 1810 |
try |
| 1811 |
{ |
| 1812 |
CurlUri const aURI(xIdentifier->getContentIdentifier()); |
| 1813 |
aOldTitle = aURI.GetPathBaseNameUnescaped(); |
| 1814 |
|
| 1815 |
if ( aNewValue != aOldTitle ) |
| 1816 |
{ |
| 1817 |
// modified title -> modified URL -> exchange ! |
| 1818 |
if ( !bTransient ) |
| 1819 |
bExchange = true; |
| 1820 |
|
| 1821 |
// new value will be set later... |
| 1822 |
aNewTitle = aNewValue; |
| 1823 |
|
| 1824 |
// remember position within sequence of values (for |
| 1825 |
// error handling). |
| 1826 |
nTitlePos = n; |
| 1827 |
} |
| 1828 |
} |
| 1829 |
catch ( DAVException const & ) |
| 1830 |
{ |
| 1831 |
aRetRange[ n ] <<= lang::IllegalArgumentException( |
| 1832 |
u"Invalid content identifier!"_ustr, |
| 1833 |
getXWeak(), |
| 1834 |
-1 ); |
| 1835 |
} |
| 1836 |
} |
| 1837 |
else |
| 1838 |
{ |
| 1839 |
aRetRange[ n ] <<= lang::IllegalArgumentException( |
| 1840 |
u"Empty title not allowed!"_ustr, |
| 1841 |
getXWeak(), |
| 1842 |
-1 ); |
| 1843 |
} |
| 1844 |
} |
| 1845 |
else |
| 1846 |
{ |
| 1847 |
aRetRange[ n ] <<= beans::IllegalTypeException( |
| 1848 |
u"Property value has wrong type!"_ustr, |
| 1849 |
getXWeak() ); |
| 1850 |
} |
| 1851 |
} |
| 1852 |
else |
| 1853 |
{ |
| 1854 |
|
| 1855 |
// Optional props. |
| 1856 |
|
| 1857 |
|
| 1858 |
OUString aSpecialName; |
| 1859 |
bool bIsSpecial = DAVProperties::isUCBSpecialProperty( rName, aSpecialName ); |
| 1860 |
|
| 1861 |
if ( !xInfo.is() ) |
| 1862 |
xInfo = getPropertySetInfo( xEnv, |
| 1863 |
false /* don't cache data */ ); |
| 1864 |
|
| 1865 |
if ( !xInfo->hasPropertyByName( bIsSpecial ? aSpecialName : rName ) ) |
| 1866 |
{ |
| 1867 |
// Check, whether property exists. Skip otherwise. |
| 1868 |
// PROPPATCH::set would add the property automatically, which |
| 1869 |
// is not allowed for "setPropertyValues" command! |
| 1870 |
aRetRange[ n ] <<= beans::UnknownPropertyException( |
| 1871 |
u"Property is unknown!"_ustr, |
| 1872 |
getXWeak() ); |
| 1873 |
continue; |
| 1874 |
} |
| 1875 |
|
| 1876 |
if ( rName == "Size" ) |
| 1877 |
{ |
| 1878 |
// Read-only property! |
| 1879 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1880 |
u"Property is read-only!"_ustr, |
| 1881 |
getXWeak() ); |
| 1882 |
} |
| 1883 |
else if ( rName == "DateCreated" ) |
| 1884 |
{ |
| 1885 |
// Read-only property! |
| 1886 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1887 |
u"Property is read-only!"_ustr, |
| 1888 |
getXWeak() ); |
| 1889 |
} |
| 1890 |
else if ( rName == "DateModified" ) |
| 1891 |
{ |
| 1892 |
// Read-only property! |
| 1893 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1894 |
u"Property is read-only!"_ustr, |
| 1895 |
getXWeak() ); |
| 1896 |
} |
| 1897 |
else if ( rName == "MediaType" ) |
| 1898 |
{ |
| 1899 |
// Read-only property! |
| 1900 |
// (but could be writable, if 'getcontenttype' would be) |
| 1901 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1902 |
u"Property is read-only!"_ustr, |
| 1903 |
getXWeak() ); |
| 1904 |
} |
| 1905 |
if ( rName == "CreatableContentsInfo" ) |
| 1906 |
{ |
| 1907 |
// Read-only property! |
| 1908 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1909 |
u"Property is read-only!"_ustr, |
| 1910 |
getXWeak() ); |
| 1911 |
} |
| 1912 |
else |
| 1913 |
{ |
| 1914 |
if ( getResourceType( xEnv, xResAccess ) == DAV ) |
| 1915 |
{ |
| 1916 |
// Property value will be set on server. |
| 1917 |
ProppatchValue aValue( PROPSET, rName, rValue.Value ); |
| 1918 |
aProppatchValues.push_back( aValue ); |
| 1919 |
|
| 1920 |
// remember position within sequence of values (for |
| 1921 |
// error handling). |
| 1922 |
aProppatchPropsPositions.push_back( n ); |
| 1923 |
} |
| 1924 |
else |
| 1925 |
{ |
| 1926 |
// Property value will be stored in local property store. |
| 1927 |
if ( !bTriedToGetAdditionalPropSet && |
| 1928 |
!xAdditionalPropSet.is() ) |
| 1929 |
{ |
| 1930 |
xAdditionalPropSet |
| 1931 |
= getAdditionalPropertySet( false ); |
| 1932 |
bTriedToGetAdditionalPropSet = true; |
| 1933 |
} |
| 1934 |
|
| 1935 |
if ( xAdditionalPropSet.is() ) |
| 1936 |
{ |
| 1937 |
try |
| 1938 |
{ |
| 1939 |
uno::Any aOldValue |
| 1940 |
= xAdditionalPropSet->getPropertyValue( rName ); |
| 1941 |
if ( aOldValue != rValue.Value ) |
| 1942 |
{ |
| 1943 |
xAdditionalPropSet->setPropertyValue( |
| 1944 |
rName, rValue.Value ); |
| 1945 |
|
| 1946 |
aEvent.PropertyName = rName; |
| 1947 |
aEvent.OldValue = std::move(aOldValue); |
| 1948 |
aEvent.NewValue = rValue.Value; |
| 1949 |
|
| 1950 |
aChanges.getArray()[ nChanged ] = aEvent; |
| 1951 |
nChanged++; |
| 1952 |
} |
| 1953 |
} |
| 1954 |
catch ( beans::UnknownPropertyException const & e ) |
| 1955 |
{ |
| 1956 |
aRetRange[ n ] <<= e; |
| 1957 |
} |
| 1958 |
catch ( lang::WrappedTargetException const & e ) |
| 1959 |
{ |
| 1960 |
aRetRange[ n ] <<= e; |
| 1961 |
} |
| 1962 |
catch ( beans::PropertyVetoException const & e ) |
| 1963 |
{ |
| 1964 |
aRetRange[ n ] <<= e; |
| 1965 |
} |
| 1966 |
catch ( lang::IllegalArgumentException const & e ) |
| 1967 |
{ |
| 1968 |
aRetRange[ n ] <<= e; |
| 1969 |
} |
| 1970 |
} |
| 1971 |
else |
| 1972 |
{ |
| 1973 |
aRetRange[ n ] <<= uno::Exception( |
| 1974 |
u"No property set for storing the value!"_ustr, |
| 1975 |
getXWeak() ); |
| 1976 |
} |
| 1977 |
} |
| 1978 |
} |
| 1979 |
} |
| 1980 |
} // for |
| 1981 |
|
| 1982 |
if ( !bTransient && (!aProppatchValues.empty()) ) |
| 1983 |
{ |
| 1984 |
try |
| 1985 |
{ |
| 1986 |
// clean cached value of PROPFIND property names |
| 1987 |
// PROPPATCH can change them |
| 1988 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 1989 |
// Set property values at server. |
| 1990 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 1991 |
xResAccess->PROPPATCH( aProppatchValues, xEnv ); |
| 1992 |
|
| 1993 |
for ( const auto& rProppatchValue : aProppatchValues ) |
| 1994 |
{ |
| 1995 |
aEvent.PropertyName = rProppatchValue.name; |
| 1996 |
aEvent.OldValue = uno::Any(); // @@@ too expensive to obtain! |
| 1997 |
aEvent.NewValue = rProppatchValue.value; |
| 1998 |
|
| 1999 |
aChanges.getArray()[ nChanged ] = aEvent; |
| 2000 |
nChanged++; |
| 2001 |
} |
| 2002 |
} |
| 2003 |
catch ( DAVException const & e ) |
| 2004 |
{ |
| 2005 |
// SAL_WARN( "ucb.ucp.webdav", |
| 2006 |
// "Content::setPropertyValues - PROPPATCH failed!" ); |
| 2007 |
|
| 2008 |
#if 1 |
| 2009 |
cancelCommandExecution( e, xEnv ); |
| 2010 |
// unreachable |
| 2011 |
#else |
| 2012 |
// Note: PROPPATCH either sets ALL property values OR NOTHING. |
| 2013 |
|
| 2014 |
std::vector< sal_Int32 >::const_iterator it |
| 2015 |
= aProppatchPropsPositions.begin(); |
| 2016 |
std::vector< sal_Int32 >::const_iterator end |
| 2017 |
= aProppatchPropsPositions.end(); |
| 2018 |
|
| 2019 |
while ( it != end ) |
| 2020 |
{ |
| 2021 |
// Set error. |
| 2022 |
aRetRange[ (*it) ] <<= MapDAVException( e, true ); |
| 2023 |
++it; |
| 2024 |
} |
| 2025 |
#endif |
| 2026 |
} |
| 2027 |
} |
| 2028 |
|
| 2029 |
if ( bExchange ) |
| 2030 |
{ |
| 2031 |
// Assemble new content identifier... |
| 2032 |
|
| 2033 |
OUString aNewURL = getParentURL(); |
| 2034 |
if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) ) |
| 2035 |
aNewURL += "/"; |
| 2036 |
|
| 2037 |
aNewURL += EncodeSegment(aNewTitle); |
| 2038 |
|
| 2039 |
uno::Reference< ucb::XContentIdentifier > xNewId |
| 2040 |
= new ::ucbhelper::ContentIdentifier( aNewURL ); |
| 2041 |
const uno::Reference< ucb::XContentIdentifier >& xOldId = xIdentifier; |
| 2042 |
|
| 2043 |
try |
| 2044 |
{ |
| 2045 |
CurlUri const sourceURI( xOldId->getContentIdentifier() ); |
| 2046 |
CurlUri targetURI( xNewId->getContentIdentifier() ); |
| 2047 |
|
| 2048 |
targetURI.SetScheme( sourceURI.GetScheme() ); |
| 2049 |
|
| 2050 |
// clean cached value of PROPFIND property names |
| 2051 |
removeCachedPropertyNames( sourceURI.GetURI() ); |
| 2052 |
removeCachedPropertyNames( targetURI.GetURI() ); |
| 2053 |
aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); |
| 2054 |
aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); |
| 2055 |
xResAccess->MOVE( |
| 2056 |
sourceURI.GetRelativeReference(), targetURI.GetURI(), false, xEnv ); |
| 2057 |
|
| 2058 |
// @@@ Should check for resources that could not be moved |
| 2059 |
// (due to source access or target overwrite) and send |
| 2060 |
// this information through the interaction handler. |
| 2061 |
|
| 2062 |
// @@@ Existing content should be checked to see if it needs |
| 2063 |
// to be deleted at the source |
| 2064 |
|
| 2065 |
// @@@ Existing content should be checked to see if it has |
| 2066 |
// been overwritten at the target |
| 2067 |
|
| 2068 |
if ( exchangeIdentity( xNewId ) ) |
| 2069 |
{ |
| 2070 |
xResAccess->setURL( aNewURL ); |
| 2071 |
|
| 2072 |
// DAV resources store all additional props on server! |
| 2073 |
// // Adapt Additional Core Properties. |
| 2074 |
// renameAdditionalPropertySet( xOldId->getContentIdentifier(), |
| 2075 |
// xNewId->getContentIdentifier(), |
| 2076 |
// true ); |
| 2077 |
} |
| 2078 |
else |
| 2079 |
{ |
| 2080 |
// Do not set new title! |
| 2081 |
aNewTitle.clear(); |
| 2082 |
|
| 2083 |
// Set error . |
| 2084 |
aRetRange[ nTitlePos ] <<= uno::Exception( |
| 2085 |
u"Exchange failed!"_ustr, |
| 2086 |
getXWeak() ); |
| 2087 |
} |
| 2088 |
} |
| 2089 |
catch ( DAVException const & e ) |
| 2090 |
{ |
| 2091 |
// Do not set new title! |
| 2092 |
aNewTitle.clear(); |
| 2093 |
|
| 2094 |
// Set error . |
| 2095 |
aRetRange[ nTitlePos ] = MapDAVException( e, true ); |
| 2096 |
} |
| 2097 |
} |
| 2098 |
|
| 2099 |
if ( aNewTitle.getLength() ) |
| 2100 |
{ |
| 2101 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2102 |
|
| 2103 |
aEvent.PropertyName = "Title"; |
| 2104 |
aEvent.OldValue <<= aOldTitle; |
| 2105 |
aEvent.NewValue <<= aNewTitle; |
| 2106 |
|
| 2107 |
m_aEscapedTitle = EncodeSegment(aNewTitle); |
| 2108 |
|
| 2109 |
aChanges.getArray()[ nChanged ] = std::move(aEvent); |
| 2110 |
nChanged++; |
| 2111 |
} |
| 2112 |
|
| 2113 |
if ( nChanged > 0 ) |
| 2114 |
{ |
| 2115 |
aChanges.realloc( nChanged ); |
| 2116 |
notifyPropertiesChange( aChanges ); |
| 2117 |
} |
| 2118 |
|
| 2119 |
{ |
| 2120 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2121 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 2122 |
} |
| 2123 |
|
| 2124 |
return aRet; |
| 2125 |
} |
| 2126 |
|
| 2127 |
|
| 2128 |
uno::Any Content::open( |
| 2129 |
const ucb::OpenCommandArgument3 & rArg, |
| 2130 |
const uno::Reference< ucb::XCommandEnvironment > & xEnv ) |
| 2131 |
{ |
| 2132 |
uno::Any aRet; |
| 2133 |
|
| 2134 |
bool bOpenFolder = ( ( rArg.Mode == ucb::OpenMode::ALL ) || |
| 2135 |
( rArg.Mode == ucb::OpenMode::FOLDERS ) || |
| 2136 |
( rArg.Mode == ucb::OpenMode::DOCUMENTS ) ); |
| 2137 |
if ( bOpenFolder ) |
| 2138 |
{ |
| 2139 |
if ( isFolder( xEnv ) ) |
| 2140 |
{ |
| 2141 |
// Open collection. |
| 2142 |
|
| 2143 |
uno::Reference< ucb::XDynamicResultSet > xSet |
| 2144 |
= new DynamicResultSet( m_xContext, this, rArg, xEnv ); |
| 2145 |
aRet <<= xSet; |
| 2146 |
} |
| 2147 |
else |
| 2148 |
{ |
| 2149 |
// Error: Not a folder! |
| 2150 |
|
| 2151 |
ucbhelper::cancelCommandExecution( |
| 2152 |
uno::Any( |
| 2153 |
lang::IllegalArgumentException( |
| 2154 |
u"Non-folder resource cannot be opened as folder! Wrong Open Mode!"_ustr, |
| 2155 |
getXWeak(), |
| 2156 |
-1 ) ), |
| 2157 |
xEnv ); |
| 2158 |
// Unreachable |
| 2159 |
} |
| 2160 |
} |
| 2161 |
|
| 2162 |
if ( rArg.Sink.is() ) |
| 2163 |
{ |
| 2164 |
// Open document. |
| 2165 |
|
| 2166 |
if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) || |
| 2167 |
( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) ) |
| 2168 |
{ |
| 2169 |
// Currently(?) unsupported. |
| 2170 |
ucbhelper::cancelCommandExecution( |
| 2171 |
uno::Any( |
| 2172 |
ucb::UnsupportedOpenModeException( |
| 2173 |
OUString(), |
| 2174 |
getXWeak(), |
| 2175 |
sal_Int16( rArg.Mode ) ) ), |
| 2176 |
xEnv ); |
| 2177 |
// Unreachable |
| 2178 |
} |
| 2179 |
|
| 2180 |
uno::Reference< io::XOutputStream > xOut( rArg.Sink, uno::UNO_QUERY ); |
| 2181 |
if ( xOut.is() ) |
| 2182 |
{ |
| 2183 |
// PUSH: write data |
| 2184 |
try |
| 2185 |
{ |
| 2186 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2187 |
|
| 2188 |
{ |
| 2189 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2190 |
|
| 2191 |
xResAccess.reset( |
| 2192 |
new DAVResourceAccess( *m_xResAccess ) ); |
| 2193 |
} |
| 2194 |
|
| 2195 |
xResAccess->setFlags( rArg.OpeningFlags ); |
| 2196 |
DAVResource aResource; |
| 2197 |
std::vector< OUString > aHeaders; |
| 2198 |
|
| 2199 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2200 |
xResAccess->GET( xOut, aHeaders, aResource, xEnv ); |
| 2201 |
m_bDidGetOrHead = true; |
| 2202 |
|
| 2203 |
{ |
| 2204 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2205 |
|
| 2206 |
// cache headers. |
| 2207 |
if (!m_xCachedProps) |
| 2208 |
m_xCachedProps.reset( |
| 2209 |
new CachableContentProperties( ContentProperties( aResource ) ) ); |
| 2210 |
else |
| 2211 |
m_xCachedProps->addProperties( ContentProperties( aResource ) ); |
| 2212 |
|
| 2213 |
m_xResAccess.reset( |
| 2214 |
new DAVResourceAccess( *xResAccess ) ); |
| 2215 |
} |
| 2216 |
} |
| 2217 |
catch ( DAVException const & e ) |
| 2218 |
{ |
| 2219 |
cancelCommandExecution( e, xEnv ); |
| 2220 |
// Unreachable |
| 2221 |
} |
| 2222 |
} |
| 2223 |
else |
| 2224 |
{ |
| 2225 |
uno::Reference< io::XActiveDataSink > xDataSink( rArg.Sink, uno::UNO_QUERY ); |
| 2226 |
if ( xDataSink.is() ) |
| 2227 |
{ |
| 2228 |
// PULL: wait for client read |
| 2229 |
OUString aTargetURL = m_xIdentifier->getContentIdentifier(); |
| 2230 |
try |
| 2231 |
{ |
| 2232 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2233 |
{ |
| 2234 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2235 |
|
| 2236 |
xResAccess.reset( |
| 2237 |
new DAVResourceAccess( *m_xResAccess ) ); |
| 2238 |
} |
| 2239 |
xResAccess->setFlags( rArg.OpeningFlags ); |
| 2240 |
|
| 2241 |
// fill inputstream sync; return if all data present |
| 2242 |
DAVResource aResource; |
| 2243 |
std::vector< OUString > aHeaders; |
| 2244 |
|
| 2245 |
aTargetURL = xResAccess->getURL(); |
| 2246 |
removeCachedPropertyNames( aTargetURL ); |
| 2247 |
// check if the resource was present on the server |
| 2248 |
// first update it, if necessary |
| 2249 |
// if the open is called directly, without the default open sequence, |
| 2250 |
// e.g. the one used when opening a file looking for properties |
| 2251 |
// first this call will have no effect, since OPTIONS would have already been called |
| 2252 |
// as a consequence of getPropertyValues() |
| 2253 |
DAVOptions aDAVOptions; |
| 2254 |
getResourceOptions( xEnv, aDAVOptions, xResAccess ); |
| 2255 |
|
| 2256 |
if (aDAVOptions.getHttpResponseStatusCode() != SC_NONE |
| 2257 |
// tdf#148426 fall back to GET in case of 500 |
| 2258 |
&& aDAVOptions.getHttpResponseStatusCode() != SC_INTERNAL_SERVER_ERROR) |
| 2259 |
{ |
| 2260 |
// throws exception as if there was a server error, a DAV exception |
| 2261 |
switch (aDAVOptions.getHttpResponseStatusCode()) |
| 2262 |
{ |
| 2263 |
case USC_CONNECT_FAILED: |
| 2264 |
{ |
| 2265 |
CurlUri aUri(aTargetURL); |
| 2266 |
throw DAVException( |
| 2267 |
DAVException::DAV_HTTP_CONNECT, |
| 2268 |
ConnectionEndPointString(aUri.GetHost(), aUri.GetPort()), |
| 2269 |
aDAVOptions.getHttpResponseStatusText()); |
| 2270 |
} |
| 2271 |
default: |
| 2272 |
break; |
| 2273 |
} |
| 2274 |
throw DAVException( DAVException::DAV_HTTP_ERROR, |
| 2275 |
aDAVOptions.getHttpResponseStatusText(), |
| 2276 |
aDAVOptions.getHttpResponseStatusCode() ); |
| 2277 |
} |
| 2278 |
uno::Reference< io::XInputStream > xIn |
| 2279 |
= xResAccess->GET( aHeaders, aResource, xEnv ); |
| 2280 |
m_bDidGetOrHead = true; |
| 2281 |
|
| 2282 |
{ |
| 2283 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2284 |
|
| 2285 |
// cache headers. |
| 2286 |
if (!m_xCachedProps) |
| 2287 |
m_xCachedProps.reset( |
| 2288 |
new CachableContentProperties( ContentProperties( aResource ) ) ); |
| 2289 |
else |
| 2290 |
m_xCachedProps->addProperties( |
| 2291 |
aResource.properties ); |
| 2292 |
|
| 2293 |
m_xResAccess.reset( |
| 2294 |
new DAVResourceAccess( *xResAccess ) ); |
| 2295 |
} |
| 2296 |
|
| 2297 |
xDataSink->setInputStream( xIn ); |
| 2298 |
} |
| 2299 |
catch ( DAVException const & e ) |
| 2300 |
{ |
| 2301 |
//TODO cache the http error if not yet cached |
| 2302 |
cancelCommandExecution( e, xEnv ); |
| 2303 |
// Unreachable |
| 2304 |
} |
| 2305 |
} |
| 2306 |
else |
| 2307 |
{ |
| 2308 |
// Note: aOpenCommand.Sink may contain an XStream |
| 2309 |
// implementation. Support for this type of |
| 2310 |
// sink is optional... |
| 2311 |
ucbhelper::cancelCommandExecution( |
| 2312 |
uno::Any( |
| 2313 |
ucb::UnsupportedDataSinkException( |
| 2314 |
OUString(), |
| 2315 |
getXWeak(), |
| 2316 |
rArg.Sink ) ), |
| 2317 |
xEnv ); |
| 2318 |
// Unreachable |
| 2319 |
} |
| 2320 |
} |
| 2321 |
} |
| 2322 |
|
| 2323 |
return aRet; |
| 2324 |
} |
| 2325 |
|
| 2326 |
|
| 2327 |
void Content::post( |
| 2328 |
const ucb::PostCommandArgument2 & rArg, |
| 2329 |
const uno::Reference< ucb::XCommandEnvironment > & xEnv ) |
| 2330 |
{ |
| 2331 |
uno::Reference< io::XActiveDataSink > xSink( rArg.Sink, uno::UNO_QUERY ); |
| 2332 |
if ( xSink.is() ) |
| 2333 |
{ |
| 2334 |
try |
| 2335 |
{ |
| 2336 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2337 |
{ |
| 2338 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2339 |
xResAccess.reset( |
| 2340 |
new DAVResourceAccess( *m_xResAccess ) ); |
| 2341 |
} |
| 2342 |
|
| 2343 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2344 |
uno::Reference< io::XInputStream > xResult |
| 2345 |
= xResAccess->POST( rArg.MediaType, |
| 2346 |
rArg.Referer, |
| 2347 |
rArg.Source, |
| 2348 |
xEnv ); |
| 2349 |
|
| 2350 |
{ |
| 2351 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2352 |
m_xResAccess.reset( |
| 2353 |
new DAVResourceAccess( *xResAccess ) ); |
| 2354 |
} |
| 2355 |
|
| 2356 |
xSink->setInputStream( xResult ); |
| 2357 |
} |
| 2358 |
catch ( DAVException const & e ) |
| 2359 |
{ |
| 2360 |
cancelCommandExecution( e, xEnv, true ); |
| 2361 |
// Unreachable |
| 2362 |
} |
| 2363 |
} |
| 2364 |
else |
| 2365 |
{ |
| 2366 |
uno::Reference< io::XOutputStream > xResult( rArg.Sink, uno::UNO_QUERY ); |
| 2367 |
if ( xResult.is() ) |
| 2368 |
{ |
| 2369 |
try |
| 2370 |
{ |
| 2371 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2372 |
{ |
| 2373 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2374 |
xResAccess.reset( |
| 2375 |
new DAVResourceAccess( *m_xResAccess ) ); |
| 2376 |
} |
| 2377 |
|
| 2378 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2379 |
xResAccess->POST( rArg.MediaType, |
| 2380 |
rArg.Referer, |
| 2381 |
rArg.Source, |
| 2382 |
xResult, |
| 2383 |
xEnv ); |
| 2384 |
|
| 2385 |
{ |
| 2386 |
osl::MutexGuard aGuard( m_aMutex ); |
| 2387 |
m_xResAccess.reset( |
| 2388 |
new DAVResourceAccess( *xResAccess ) ); |
| 2389 |
} |
| 2390 |
} |
| 2391 |
catch ( DAVException const & e ) |
| 2392 |
{ |
| 2393 |
cancelCommandExecution( e, xEnv, true ); |
| 2394 |
// Unreachable |
| 2395 |
} |
| 2396 |
} |
| 2397 |
else |
| 2398 |
{ |
| 2399 |
ucbhelper::cancelCommandExecution( |
| 2400 |
uno::Any( |
| 2401 |
ucb::UnsupportedDataSinkException( |
| 2402 |
OUString(), |
| 2403 |
getXWeak(), |
| 2404 |
rArg.Sink ) ), |
| 2405 |
xEnv ); |
| 2406 |
// Unreachable |
| 2407 |
} |
| 2408 |
} |
| 2409 |
} |
| 2410 |
|
| 2411 |
|
| 2412 |
void Content::queryChildren( ContentRefList& rChildren ) |
| 2413 |
{ |
| 2414 |
// Obtain a list with a snapshot of all currently instantiated contents |
| 2415 |
// from provider and extract the contents which are direct children |
| 2416 |
// of this content. |
| 2417 |
|
| 2418 |
::ucbhelper::ContentRefList aAllContents; |
| 2419 |
m_xProvider->queryExistingContents( aAllContents ); |
| 2420 |
|
| 2421 |
OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 2422 |
sal_Int32 nURLPos = aURL.lastIndexOf( '/' ); |
| 2423 |
|
| 2424 |
if ( nURLPos != ( aURL.getLength() - 1 ) ) |
| 2425 |
{ |
| 2426 |
// No trailing slash found. Append. |
| 2427 |
aURL += "/"; |
| 2428 |
} |
| 2429 |
|
| 2430 |
sal_Int32 nLen = aURL.getLength(); |
| 2431 |
|
| 2432 |
for ( const auto& rChild : aAllContents ) |
| 2433 |
{ |
| 2434 |
::ucbhelper::ContentImplHelperRef xChild = rChild; |
| 2435 |
OUString aChildURL |
| 2436 |
= xChild->getIdentifier()->getContentIdentifier(); |
| 2437 |
|
| 2438 |
// Is aURL a prefix of aChildURL? |
| 2439 |
if ( ( aChildURL.getLength() > nLen ) && |
| 2440 |
( aChildURL.startsWith( aURL ) ) ) |
| 2441 |
{ |
| 2442 |
sal_Int32 nPos = nLen; |
| 2443 |
nPos = aChildURL.indexOf( '/', nPos ); |
| 2444 |
|
| 2445 |
if ( ( nPos == -1 ) || |
| 2446 |
( nPos == ( aChildURL.getLength() - 1 ) ) ) |
| 2447 |
{ |
| 2448 |
// No further slashes / only a final slash. It's a child! |
| 2449 |
rChildren.push_back( |
| 2450 |
::http_dav_ucp::Content::ContentRef( |
| 2451 |
static_cast< ::http_dav_ucp::Content * >( |
| 2452 |
xChild.get() ) ) ); |
| 2453 |
} |
| 2454 |
} |
| 2455 |
} |
| 2456 |
} |
| 2457 |
|
| 2458 |
|
| 2459 |
void Content::insert( |
| 2460 |
const uno::Reference< io::XInputStream > & xInputStream, |
| 2461 |
bool bReplaceExisting, |
| 2462 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 2463 |
{ |
| 2464 |
bool bTransient, bCollection; |
| 2465 |
OUString aEscapedTitle; |
| 2466 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2467 |
|
| 2468 |
{ |
| 2469 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2470 |
|
| 2471 |
bTransient = m_bTransient; |
| 2472 |
bCollection = m_bCollection; |
| 2473 |
aEscapedTitle = m_aEscapedTitle; |
| 2474 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 2475 |
} |
| 2476 |
|
| 2477 |
// Check, if all required properties are present. |
| 2478 |
|
| 2479 |
if ( aEscapedTitle.isEmpty() ) |
| 2480 |
{ |
| 2481 |
SAL_WARN( "ucb.ucp.webdav", "Content::insert - Title missing!" ); |
| 2482 |
|
| 2483 |
uno::Sequence<OUString> aProps { u"Title"_ustr }; |
| 2484 |
ucbhelper::cancelCommandExecution( |
| 2485 |
uno::Any( ucb::MissingPropertiesException( |
| 2486 |
OUString(), |
| 2487 |
getXWeak(), |
| 2488 |
aProps ) ), |
| 2489 |
Environment ); |
| 2490 |
// Unreachable |
| 2491 |
} |
| 2492 |
|
| 2493 |
if ( !bReplaceExisting ) |
| 2494 |
{ |
| 2495 |
/* [RFC 2616] - HTTP |
| 2496 |
|
| 2497 |
The PUT method requests that the enclosed entity be stored under the |
| 2498 |
supplied Request-URI. If the Request-URI refers to an already |
| 2499 |
existing resource, the enclosed entity SHOULD be considered as a |
| 2500 |
modified version of the one residing on the origin server. |
| 2501 |
*/ |
| 2502 |
|
| 2503 |
/* [RFC 2518] - WebDAV |
| 2504 |
|
| 2505 |
MKCOL creates a new collection resource at the location specified by |
| 2506 |
the Request-URI. If the resource identified by the Request-URI is |
| 2507 |
non-null then the MKCOL MUST fail. |
| 2508 |
*/ |
| 2509 |
|
| 2510 |
// ==> Complain on PUT, continue on MKCOL. |
| 2511 |
if ( !bTransient || !bCollection ) |
| 2512 |
{ |
| 2513 |
#undef ERROR |
| 2514 |
ucb::UnsupportedNameClashException aEx( |
| 2515 |
u"Unable to write without overwrite!"_ustr, |
| 2516 |
getXWeak(), |
| 2517 |
ucb::NameClash::ERROR ); |
| 2518 |
|
| 2519 |
uno::Reference< task::XInteractionHandler > xIH; |
| 2520 |
|
| 2521 |
if ( Environment.is() ) |
| 2522 |
xIH = Environment->getInteractionHandler(); |
| 2523 |
|
| 2524 |
if ( xIH.is() ) |
| 2525 |
{ |
| 2526 |
uno::Any aExAsAny( aEx ); |
| 2527 |
|
| 2528 |
rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest |
| 2529 |
= new ucbhelper::SimpleInteractionRequest( |
| 2530 |
aExAsAny, |
| 2531 |
ContinuationFlags::Approve |
| 2532 |
| ContinuationFlags::Disapprove ); |
| 2533 |
xIH->handle( xRequest ); |
| 2534 |
|
| 2535 |
const ContinuationFlags nResp = xRequest->getResponse(); |
| 2536 |
|
| 2537 |
switch ( nResp ) |
| 2538 |
{ |
| 2539 |
case ContinuationFlags::NONE: |
| 2540 |
// Not handled; throw. |
| 2541 |
throw aEx; |
| 2542 |
// break; |
| 2543 |
|
| 2544 |
case ContinuationFlags::Approve: |
| 2545 |
// Continue -> Overwrite. |
| 2546 |
bReplaceExisting = true; |
| 2547 |
break; |
| 2548 |
|
| 2549 |
case ContinuationFlags::Disapprove: |
| 2550 |
// Abort. |
| 2551 |
throw ucb::CommandFailedException( |
| 2552 |
OUString(), |
| 2553 |
uno::Reference< uno::XInterface >(), |
| 2554 |
aExAsAny ); |
| 2555 |
// break; |
| 2556 |
|
| 2557 |
default: |
| 2558 |
SAL_WARN( "ucb.ucp.webdav", |
| 2559 |
"Content::insert - " |
| 2560 |
"Unknown interaction selection!" ); |
| 2561 |
throw ucb::CommandFailedException( |
| 2562 |
u"Unknown interaction selection!"_ustr, |
| 2563 |
uno::Reference< uno::XInterface >(), |
| 2564 |
aExAsAny ); |
| 2565 |
// break; |
| 2566 |
} |
| 2567 |
} |
| 2568 |
else |
| 2569 |
{ |
| 2570 |
// No IH; throw. |
| 2571 |
throw aEx; |
| 2572 |
} |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
if ( bTransient ) |
| 2577 |
{ |
| 2578 |
// Assemble new content identifier... |
| 2579 |
OUString aURL = getParentURL(); |
| 2580 |
if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) ) |
| 2581 |
aURL += "/"; |
| 2582 |
|
| 2583 |
aURL += aEscapedTitle; |
| 2584 |
|
| 2585 |
try |
| 2586 |
{ |
| 2587 |
xResAccess->setURL( aURL ); |
| 2588 |
|
| 2589 |
if ( bCollection ) |
| 2590 |
{ |
| 2591 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 2592 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2593 |
xResAccess->MKCOL( Environment ); |
| 2594 |
} |
| 2595 |
else |
| 2596 |
{ |
| 2597 |
// remove options from cache, PUT may change it |
| 2598 |
// it will be refreshed when needed |
| 2599 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 2600 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2601 |
xResAccess->PUT( xInputStream, Environment ); |
| 2602 |
// clean cached value of PROPFIND properties names |
| 2603 |
} |
| 2604 |
// no error , set the resourcetype to unknown type |
| 2605 |
// the resource may have transitioned from NOT FOUND or UNKNOWN to something else |
| 2606 |
// depending on the server behaviour |
| 2607 |
// this will force a recheck of the resource type |
| 2608 |
m_eResourceType = UNKNOWN; |
| 2609 |
m_eResourceTypeForLocks = UNKNOWN; |
| 2610 |
} |
| 2611 |
catch ( DAVException const & except ) |
| 2612 |
{ |
| 2613 |
if ( bCollection ) |
| 2614 |
{ |
| 2615 |
if ( except.getStatus() == SC_METHOD_NOT_ALLOWED ) |
| 2616 |
{ |
| 2617 |
// [RFC 2518] - WebDAV |
| 2618 |
// 405 (Method Not Allowed) - MKCOL can only be |
| 2619 |
// executed on a deleted/non-existent resource. |
| 2620 |
|
| 2621 |
if ( bReplaceExisting ) |
| 2622 |
{ |
| 2623 |
// Destroy old resource. |
| 2624 |
try |
| 2625 |
{ |
| 2626 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2627 |
xResAccess->DESTROY( Environment ); |
| 2628 |
} |
| 2629 |
catch ( DAVException const & e ) |
| 2630 |
{ |
| 2631 |
cancelCommandExecution( e, Environment, true ); |
| 2632 |
// Unreachable |
| 2633 |
} |
| 2634 |
|
| 2635 |
// Insert (recursion!). |
| 2636 |
insert( xInputStream, bReplaceExisting, Environment ); |
| 2637 |
|
| 2638 |
{ |
| 2639 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2640 |
m_xResAccess.reset( |
| 2641 |
new DAVResourceAccess( *xResAccess ) ); |
| 2642 |
} |
| 2643 |
|
| 2644 |
// Success! |
| 2645 |
return; |
| 2646 |
} |
| 2647 |
else |
| 2648 |
{ |
| 2649 |
OUString aTitle; |
| 2650 |
try |
| 2651 |
{ |
| 2652 |
CurlUri const aURI( aURL ); |
| 2653 |
aTitle = aURI.GetPathBaseNameUnescaped(); |
| 2654 |
} |
| 2655 |
catch ( DAVException const & ) |
| 2656 |
{ |
| 2657 |
} |
| 2658 |
|
| 2659 |
ucbhelper::cancelCommandExecution( |
| 2660 |
uno::Any( |
| 2661 |
ucb::NameClashException( |
| 2662 |
OUString(), |
| 2663 |
getXWeak(), |
| 2664 |
task::InteractionClassification_ERROR, |
| 2665 |
aTitle ) ), |
| 2666 |
Environment ); |
| 2667 |
// Unreachable |
| 2668 |
} |
| 2669 |
} |
| 2670 |
} |
| 2671 |
|
| 2672 |
cancelCommandExecution( except, Environment, true ); |
| 2673 |
// Unreachable |
| 2674 |
} |
| 2675 |
|
| 2676 |
{ |
| 2677 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2678 |
m_xIdentifier |
| 2679 |
= new ::ucbhelper::ContentIdentifier( aURL ); |
| 2680 |
} |
| 2681 |
|
| 2682 |
inserted(); |
| 2683 |
|
| 2684 |
{ |
| 2685 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2686 |
m_bTransient = false; |
| 2687 |
} |
| 2688 |
} |
| 2689 |
else |
| 2690 |
{ |
| 2691 |
if ( !xInputStream.is() ) |
| 2692 |
{ |
| 2693 |
ucbhelper::cancelCommandExecution( |
| 2694 |
uno::Any( |
| 2695 |
ucb::MissingInputStreamException( |
| 2696 |
OUString(), |
| 2697 |
getXWeak() ) ), |
| 2698 |
Environment ); |
| 2699 |
// Unreachable |
| 2700 |
} |
| 2701 |
|
| 2702 |
// save the URL since it may change due to redirection |
| 2703 |
OUString aTargetUrl = xResAccess->getURL(); |
| 2704 |
try |
| 2705 |
{ |
| 2706 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 2707 |
// remove options from cache, PUT may change it |
| 2708 |
// it will be refreshed when needed |
| 2709 |
aStaticDAVOptionsCache.removeDAVOptions( aTargetUrl ); |
| 2710 |
xResAccess->PUT( xInputStream, Environment ); |
| 2711 |
} |
| 2712 |
catch ( DAVException const & e ) |
| 2713 |
{ |
| 2714 |
cancelCommandExecution( e, Environment, true ); |
| 2715 |
// Unreachable |
| 2716 |
} |
| 2717 |
} |
| 2718 |
|
| 2719 |
{ |
| 2720 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2721 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 2722 |
} |
| 2723 |
} |
| 2724 |
|
| 2725 |
|
| 2726 |
void Content::transfer( |
| 2727 |
const ucb::TransferInfo & rArgs, |
| 2728 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 2729 |
{ |
| 2730 |
uno::Reference< uno::XComponentContext > xContext; |
| 2731 |
uno::Reference< ucb::XContentIdentifier > xIdentifier; |
| 2732 |
uno::Reference< ucb::XContentProvider > xProvider; |
| 2733 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 2734 |
|
| 2735 |
{ |
| 2736 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2737 |
|
| 2738 |
xContext.set( m_xContext ); |
| 2739 |
xIdentifier.set( m_xIdentifier ); |
| 2740 |
xProvider.set( m_xProvider ); |
| 2741 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 2742 |
} |
| 2743 |
|
| 2744 |
OUString aTargetURI; |
| 2745 |
try |
| 2746 |
{ |
| 2747 |
CurlUri sourceURI( rArgs.SourceURL ); |
| 2748 |
CurlUri targetURI( xIdentifier->getContentIdentifier() ); |
| 2749 |
|
| 2750 |
aTargetURI = targetURI.GetPathBaseNameUnescaped(); |
| 2751 |
|
| 2752 |
// Check source's and target's URL scheme |
| 2753 |
|
| 2754 |
OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase(); |
| 2755 |
if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) |
| 2756 |
{ |
| 2757 |
sourceURI.SetScheme( HTTP_URL_SCHEME ); |
| 2758 |
} |
| 2759 |
else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) |
| 2760 |
{ |
| 2761 |
sourceURI.SetScheme( HTTPS_URL_SCHEME ); |
| 2762 |
} |
| 2763 |
else if ( aScheme == DAV_URL_SCHEME ) |
| 2764 |
{ |
| 2765 |
sourceURI.SetScheme( HTTP_URL_SCHEME ); |
| 2766 |
} |
| 2767 |
else if ( aScheme == DAVS_URL_SCHEME ) |
| 2768 |
{ |
| 2769 |
sourceURI.SetScheme( HTTPS_URL_SCHEME ); |
| 2770 |
} |
| 2771 |
else if (aScheme == WEBDAV_URL_SCHEME) |
| 2772 |
{ |
| 2773 |
sourceURI.SetScheme(HTTP_URL_SCHEME); |
| 2774 |
} |
| 2775 |
else if (aScheme == WEBDAVS_URL_SCHEME) |
| 2776 |
{ |
| 2777 |
sourceURI.SetScheme(HTTPS_URL_SCHEME); |
| 2778 |
} |
| 2779 |
else |
| 2780 |
{ |
| 2781 |
if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME ) |
| 2782 |
{ |
| 2783 |
ucbhelper::cancelCommandExecution( |
| 2784 |
uno::Any( |
| 2785 |
ucb::InteractiveBadTransferURLException( |
| 2786 |
u"Unsupported URL scheme!"_ustr, |
| 2787 |
getXWeak() ) ), |
| 2788 |
Environment ); |
| 2789 |
// Unreachable |
| 2790 |
} |
| 2791 |
} |
| 2792 |
|
| 2793 |
aScheme = targetURI.GetScheme().toAsciiLowerCase(); |
| 2794 |
if ( aScheme == VNDSUNSTARWEBDAV_URL_SCHEME) |
| 2795 |
targetURI.SetScheme( HTTP_URL_SCHEME ); |
| 2796 |
else if ( aScheme == VNDSUNSTARWEBDAVS_URL_SCHEME) |
| 2797 |
targetURI.SetScheme( HTTPS_URL_SCHEME ); |
| 2798 |
else if ( aScheme == DAV_URL_SCHEME ) |
| 2799 |
targetURI.SetScheme( HTTP_URL_SCHEME ); |
| 2800 |
else if ( aScheme == DAVS_URL_SCHEME ) |
| 2801 |
targetURI.SetScheme( HTTPS_URL_SCHEME ); |
| 2802 |
else if (aScheme == WEBDAV_URL_SCHEME) |
| 2803 |
targetURI.SetScheme(HTTP_URL_SCHEME); |
| 2804 |
else if (aScheme == WEBDAVS_URL_SCHEME) |
| 2805 |
targetURI.SetScheme(HTTPS_URL_SCHEME); |
| 2806 |
|
| 2807 |
// @@@ This implementation of 'transfer' only works |
| 2808 |
// if the source and target are located at same host. |
| 2809 |
// (Neon does not support cross-server copy/move) |
| 2810 |
|
| 2811 |
// Check for same host |
| 2812 |
|
| 2813 |
if ( sourceURI.GetHost().getLength() && |
| 2814 |
( sourceURI.GetHost() != targetURI.GetHost() ) ) |
| 2815 |
{ |
| 2816 |
ucbhelper::cancelCommandExecution( |
| 2817 |
uno::Any( ucb::InteractiveBadTransferURLException( |
| 2818 |
u"Different hosts!"_ustr, |
| 2819 |
getXWeak() ) ), |
| 2820 |
Environment ); |
| 2821 |
// Unreachable |
| 2822 |
} |
| 2823 |
|
| 2824 |
OUString aTitle = rArgs.NewTitle; |
| 2825 |
|
| 2826 |
if ( aTitle.isEmpty() ) |
| 2827 |
aTitle = sourceURI.GetPathBaseNameUnescaped(); |
| 2828 |
|
| 2829 |
if ( aTitle == "/" ) |
| 2830 |
{ |
| 2831 |
// kso: ??? |
| 2832 |
aTitle.clear(); |
| 2833 |
} |
| 2834 |
|
| 2835 |
targetURI.AppendPath( aTitle ); |
| 2836 |
|
| 2837 |
OUString aTargetURL = xIdentifier->getContentIdentifier(); |
| 2838 |
if ( ( aTargetURL.lastIndexOf( '/' ) + 1 ) |
| 2839 |
!= aTargetURL.getLength() ) |
| 2840 |
aTargetURL += "/"; |
| 2841 |
|
| 2842 |
aTargetURL += aTitle; |
| 2843 |
|
| 2844 |
uno::Reference< ucb::XContentIdentifier > xTargetId |
| 2845 |
= new ::ucbhelper::ContentIdentifier( aTargetURL ); |
| 2846 |
|
| 2847 |
DAVResourceAccess aSourceAccess( xContext, |
| 2848 |
xResAccess->getSessionFactory(), |
| 2849 |
sourceURI.GetURI() ); |
| 2850 |
|
| 2851 |
if ( rArgs.MoveData ) |
| 2852 |
{ |
| 2853 |
uno::Reference< ucb::XContentIdentifier > xId |
| 2854 |
= new ::ucbhelper::ContentIdentifier( rArgs.SourceURL ); |
| 2855 |
|
| 2856 |
// Note: The static cast is okay here, because its sure that |
| 2857 |
// xProvider is always the WebDAVContentProvider. |
| 2858 |
rtl::Reference< Content > xSource |
| 2859 |
= static_cast< Content * >( |
| 2860 |
xProvider->queryContent( xId ).get() ); |
| 2861 |
|
| 2862 |
// [RFC 2518] - WebDAV |
| 2863 |
// If a resource exists at the destination and the Overwrite |
| 2864 |
// header is "T" then prior to performing the move the server |
| 2865 |
// MUST perform a DELETE with "Depth: infinity" on the |
| 2866 |
// destination resource. If the Overwrite header is set to |
| 2867 |
// "F" then the operation will fail. |
| 2868 |
|
| 2869 |
aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); |
| 2870 |
aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); |
| 2871 |
aSourceAccess.MOVE( sourceURI.GetRelativeReference(), |
| 2872 |
targetURI.GetURI(), |
| 2873 |
rArgs.NameClash |
| 2874 |
== ucb::NameClash::OVERWRITE, |
| 2875 |
Environment ); |
| 2876 |
|
| 2877 |
if ( xSource.is() ) |
| 2878 |
{ |
| 2879 |
// Propagate destruction to listeners. |
| 2880 |
xSource->destroy( true ); |
| 2881 |
} |
| 2882 |
|
| 2883 |
// DAV resources store all additional props on server! |
| 2884 |
// // Rename own and all children's Additional Core Properties. |
| 2885 |
// renameAdditionalPropertySet( xId->getContentIdentifier(), |
| 2886 |
// xTargetId->getContentIdentifier(), |
| 2887 |
// true ); |
| 2888 |
} |
| 2889 |
else |
| 2890 |
{ |
| 2891 |
// [RFC 2518] - WebDAV |
| 2892 |
// If a resource exists at the destination and the Overwrite |
| 2893 |
// header is "T" then prior to performing the copy the server |
| 2894 |
// MUST perform a DELETE with "Depth: infinity" on the |
| 2895 |
// destination resource. If the Overwrite header is set to |
| 2896 |
// "F" then the operation will fail. |
| 2897 |
|
| 2898 |
aStaticDAVOptionsCache.removeDAVOptions( sourceURI.GetURI() ); |
| 2899 |
aStaticDAVOptionsCache.removeDAVOptions( targetURI.GetURI() ); |
| 2900 |
aSourceAccess.COPY( sourceURI.GetRelativeReference(), |
| 2901 |
targetURI.GetURI(), |
| 2902 |
rArgs.NameClash |
| 2903 |
== ucb::NameClash::OVERWRITE, |
| 2904 |
Environment ); |
| 2905 |
|
| 2906 |
// DAV resources store all additional props on server! |
| 2907 |
// // Copy own and all children's Additional Core Properties. |
| 2908 |
// copyAdditionalPropertySet( xId->getContentIdentifier(), |
| 2909 |
// xTargetId->getContentIdentifier(), |
| 2910 |
// true ); |
| 2911 |
} |
| 2912 |
|
| 2913 |
// Note: The static cast is okay here, because its sure that |
| 2914 |
// xProvider is always the WebDAVContentProvider. |
| 2915 |
rtl::Reference< Content > xTarget |
| 2916 |
= static_cast< Content * >( |
| 2917 |
xProvider->queryContent( xTargetId ).get() ); |
| 2918 |
|
| 2919 |
// Announce transferred content in its new folder. |
| 2920 |
xTarget->inserted(); |
| 2921 |
} |
| 2922 |
catch ( ucb::IllegalIdentifierException const & ) |
| 2923 |
{ |
| 2924 |
// queryContent |
| 2925 |
} |
| 2926 |
catch ( DAVException const & e ) |
| 2927 |
{ |
| 2928 |
// [RFC 2518] - WebDAV |
| 2929 |
// 412 (Precondition Failed) - The server was unable to maintain |
| 2930 |
// the liveness of the properties listed in the propertybehavior |
| 2931 |
// XML element or the Overwrite header is "F" and the state of |
| 2932 |
// the destination resource is non-null. |
| 2933 |
|
| 2934 |
if ( e.getStatus() == SC_PRECONDITION_FAILED ) |
| 2935 |
{ |
| 2936 |
switch ( rArgs.NameClash ) |
| 2937 |
{ |
| 2938 |
case 0/*ucb::NameClash::ERROR*/: |
| 2939 |
{ |
| 2940 |
ucbhelper::cancelCommandExecution( |
| 2941 |
uno::Any( |
| 2942 |
ucb::NameClashException( |
| 2943 |
OUString(), |
| 2944 |
getXWeak(), |
| 2945 |
task::InteractionClassification_ERROR, |
| 2946 |
aTargetURI ) ), |
| 2947 |
Environment ); |
| 2948 |
// Unreachable |
| 2949 |
} |
| 2950 |
[[fallthrough]]; |
| 2951 |
|
| 2952 |
case ucb::NameClash::OVERWRITE: |
| 2953 |
break; |
| 2954 |
|
| 2955 |
case ucb::NameClash::KEEP: // deprecated |
| 2956 |
case ucb::NameClash::RENAME: |
| 2957 |
case ucb::NameClash::ASK: |
| 2958 |
default: |
| 2959 |
{ |
| 2960 |
ucbhelper::cancelCommandExecution( |
| 2961 |
uno::Any( |
| 2962 |
ucb::UnsupportedNameClashException( |
| 2963 |
OUString(), |
| 2964 |
getXWeak(), |
| 2965 |
rArgs.NameClash ) ), |
| 2966 |
Environment ); |
| 2967 |
// Unreachable |
| 2968 |
} |
| 2969 |
} |
| 2970 |
} |
| 2971 |
|
| 2972 |
cancelCommandExecution( e, Environment, true ); |
| 2973 |
// Unreachable |
| 2974 |
} |
| 2975 |
|
| 2976 |
{ |
| 2977 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2978 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 2979 |
} |
| 2980 |
} |
| 2981 |
|
| 2982 |
|
| 2983 |
void Content::destroy( bool bDeletePhysical ) |
| 2984 |
{ |
| 2985 |
// @@@ take care about bDeletePhysical -> trashcan support |
| 2986 |
|
| 2987 |
uno::Reference< ucb::XContent > xThis = this; |
| 2988 |
|
| 2989 |
deleted(); |
| 2990 |
|
| 2991 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 2992 |
|
| 2993 |
// Process instantiated children... |
| 2994 |
|
| 2995 |
::http_dav_ucp::Content::ContentRefList aChildren; |
| 2996 |
queryChildren( aChildren ); |
| 2997 |
|
| 2998 |
for ( auto& rChild : aChildren ) |
| 2999 |
{ |
| 3000 |
rChild->destroy( bDeletePhysical ); |
| 3001 |
} |
| 3002 |
} |
| 3003 |
|
| 3004 |
// returns the resource type, to be checked for locks |
| 3005 |
Content::ResourceType Content::resourceTypeForLocks( |
| 3006 |
const uno::Reference< ucb::XCommandEnvironment >& Environment, |
| 3007 |
const std::unique_ptr< DAVResourceAccess > & rResAccess) |
| 3008 |
{ |
| 3009 |
ResourceType eResourceTypeForLocks = UNKNOWN; |
| 3010 |
{ |
| 3011 |
osl::MutexGuard g(m_aMutex); |
| 3012 |
//check if cache contains what we need, usually the first PROPFIND on the URI has supported lock |
| 3013 |
if (m_xCachedProps) |
| 3014 |
{ |
| 3015 |
uno::Sequence< ucb::LockEntry > aSupportedLocks; |
| 3016 |
if ( m_xCachedProps->getValue( DAVProperties::SUPPORTEDLOCK ) |
| 3017 |
>>= aSupportedLocks ) //get the cached value for supportedlock |
| 3018 |
{ |
| 3019 |
for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n ) |
| 3020 |
{ |
| 3021 |
if ( aSupportedLocks[ n ].Scope |
| 3022 |
== ucb::LockScope_EXCLUSIVE && |
| 3023 |
aSupportedLocks[ n ].Type |
| 3024 |
== ucb::LockType_WRITE ) |
| 3025 |
eResourceTypeForLocks = DAV; |
| 3026 |
} |
| 3027 |
} |
| 3028 |
} |
| 3029 |
} |
| 3030 |
|
| 3031 |
const OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 3032 |
|
| 3033 |
if ( eResourceTypeForLocks == UNKNOWN ) |
| 3034 |
{ |
| 3035 |
// resource type for lock/unlock operations still unknown, need to ask the server |
| 3036 |
|
| 3037 |
//{ |
| 3038 |
DAVOptions aDAVOptions; |
| 3039 |
getResourceOptions( Environment, aDAVOptions, rResAccess ); |
| 3040 |
if( aDAVOptions.isClass1() || |
| 3041 |
aDAVOptions.isClass2() || |
| 3042 |
aDAVOptions.isClass3() ) |
| 3043 |
{ |
| 3044 |
// this is at least a DAV, lock to be confirmed |
| 3045 |
// class 2 is needed for full lock support |
| 3046 |
// see |
| 3047 |
// <https://tools.ietf.org/html/rfc4918#section-18.2> |
| 3048 |
eResourceTypeForLocks = DAV_NOLOCK; |
| 3049 |
if( aDAVOptions.isClass2() ) |
| 3050 |
{ |
| 3051 |
// ok, possible lock, check for it |
| 3052 |
try |
| 3053 |
{ |
| 3054 |
// we need only DAV:supportedlock |
| 3055 |
std::vector< DAVResource > resources; |
| 3056 |
std::vector< OUString > aPropNames; |
| 3057 |
uno::Sequence< beans::Property > aProperties( 1 ); |
| 3058 |
aProperties.getArray()[ 0 ].Name = DAVProperties::SUPPORTEDLOCK; |
| 3059 |
|
| 3060 |
ContentProperties::UCBNamesToDAVNames( aProperties, aPropNames ); |
| 3061 |
rResAccess->PROPFIND( DAVZERO, aPropNames, resources, Environment ); |
| 3062 |
|
| 3063 |
bool wasSupportedlockFound = false; |
| 3064 |
|
| 3065 |
// only one resource should be returned |
| 3066 |
if ( resources.size() == 1 ) |
| 3067 |
{ |
| 3068 |
// we may have received a bunch of other properties |
| 3069 |
// (some servers seems to do so) |
| 3070 |
// but we need only supported lock for this check |
| 3071 |
// all returned properties are in |
| 3072 |
// resources.properties[n].Name/.Value |
| 3073 |
|
| 3074 |
std::vector< DAVPropertyValue >::iterator it; |
| 3075 |
|
| 3076 |
for ( it = resources[0].properties.begin(); |
| 3077 |
it != resources[0].properties.end(); ++it) |
| 3078 |
{ |
| 3079 |
if ( (*it).Name == DAVProperties::SUPPORTEDLOCK ) |
| 3080 |
{ |
| 3081 |
wasSupportedlockFound = true; |
| 3082 |
uno::Sequence< ucb::LockEntry > aSupportedLocks; |
| 3083 |
if ( (*it).Value >>= aSupportedLocks ) |
| 3084 |
{ |
| 3085 |
for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n ) |
| 3086 |
{ |
| 3087 |
// TODO: if the lock type is changed from 'exclusive write' to 'shared write' |
| 3088 |
// e.g. to implement 'Calc shared file feature', the ucb::LockScope_EXCLUSIVE |
| 3089 |
// value should be checked as well, adaptation the code may be needed |
| 3090 |
if ( aSupportedLocks[ n ].Scope == ucb::LockScope_EXCLUSIVE && |
| 3091 |
aSupportedLocks[ n ].Type == ucb::LockType_WRITE ) |
| 3092 |
{ |
| 3093 |
// requested locking mode is supported |
| 3094 |
eResourceTypeForLocks = DAV; |
| 3095 |
SAL_INFO( "ucb.ucp.webdav", "resourceTypeForLocks - URL: <" |
| 3096 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV lock/unlock supported"); |
| 3097 |
break; |
| 3098 |
} |
| 3099 |
} |
| 3100 |
break; |
| 3101 |
} |
| 3102 |
} |
| 3103 |
} |
| 3104 |
} |
| 3105 |
else |
| 3106 |
{ |
| 3107 |
// PROPFIND failed; check if HEAD contains Content-Disposition: attachment (RFC1806, HTTP/1.1 19.5.1), |
| 3108 |
// which supposedly means no lock for the resource (happens e.g. with SharePoint exported lists) |
| 3109 |
OUString sContentDisposition; |
| 3110 |
// First, check cached properties |
| 3111 |
if (m_xCachedProps) |
| 3112 |
{ |
| 3113 |
if ((m_xCachedProps->getValue(u"Content-Disposition"_ustr) >>= sContentDisposition) |
| 3114 |
&& sContentDisposition.startsWithIgnoreAsciiCase("attachment")) |
| 3115 |
{ |
| 3116 |
eResourceTypeForLocks = DAV_NOLOCK; |
| 3117 |
wasSupportedlockFound = true; |
| 3118 |
} |
| 3119 |
} |
| 3120 |
// If no data in cache, try HEAD request |
| 3121 |
if (sContentDisposition.isEmpty() && !m_bDidGetOrHead) try |
| 3122 |
{ |
| 3123 |
DAVResource resource; |
| 3124 |
GetPropsUsingHeadRequest(resource, rResAccess, {u"Content-Disposition"_ustr}, Environment); |
| 3125 |
m_bDidGetOrHead = true; |
| 3126 |
for (const auto& it : resource.properties) |
| 3127 |
{ |
| 3128 |
if (it.Name.equalsIgnoreAsciiCase("Content-Disposition")) |
| 3129 |
{ |
| 3130 |
if ((it.Value >>= sContentDisposition) && sContentDisposition.equalsIgnoreAsciiCase("attachment")) |
| 3131 |
{ |
| 3132 |
eResourceTypeForLocks = DAV_NOLOCK; |
| 3133 |
wasSupportedlockFound = true; |
| 3134 |
} |
| 3135 |
break; |
| 3136 |
} |
| 3137 |
} |
| 3138 |
} |
| 3139 |
catch (...){} |
| 3140 |
} |
| 3141 |
// check if this is still only a DAV_NOLOCK |
| 3142 |
// a fallback for resources that do not have DAVProperties::SUPPORTEDLOCK property |
| 3143 |
// we check for the returned OPTION if LOCK is allowed on the resource |
| 3144 |
if ( !wasSupportedlockFound && eResourceTypeForLocks == DAV_NOLOCK ) |
| 3145 |
{ |
| 3146 |
SAL_INFO( "ucb.ucp.webdav", "This WebDAV server has no supportedlock property, check for allowed LOCK method in OPTIONS" ); |
| 3147 |
// ATTENTION: if the lock type is changed from 'exclusive write' to 'shared write' |
| 3148 |
// e.g. to implement 'Calc shared file feature' on WebDAV directly, and we arrive to this fallback |
| 3149 |
// and the LOCK is allowed, we should assume that only exclusive write lock is available |
| 3150 |
// this is just a reminder... |
| 3151 |
if ( aDAVOptions.isLockAllowed() ) |
| 3152 |
eResourceTypeForLocks = DAV; |
| 3153 |
} |
| 3154 |
} |
| 3155 |
catch ( DAVException const & e ) |
| 3156 |
{ |
| 3157 |
rResAccess->resetUri(); |
| 3158 |
//grab the error code |
| 3159 |
switch( e.getStatus() ) |
| 3160 |
{ |
| 3161 |
case SC_NOT_FOUND: |
| 3162 |
SAL_WARN( "ucb.ucp.webdav", "resourceTypeForLocks() - URL: <" |
| 3163 |
<< m_xIdentifier->getContentIdentifier() << "> was not found. "); |
| 3164 |
eResourceTypeForLocks = NOT_FOUND; |
| 3165 |
break; |
| 3166 |
// some servers returns SC_FORBIDDEN, instead |
| 3167 |
// the meaning of SC_FORBIDDEN is, according to <http://tools.ietf.org/html/rfc7231#section-6.5.3>: |
| 3168 |
// The 403 (Forbidden) status code indicates that the server understood |
| 3169 |
// the request but refuses to authorize it |
| 3170 |
case SC_FORBIDDEN: |
| 3171 |
// Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED are |
| 3172 |
// part of base http 1.1 RFCs |
| 3173 |
case SC_NOT_IMPLEMENTED: // <http://tools.ietf.org/html/rfc7231#section-6.6.2> |
| 3174 |
case SC_METHOD_NOT_ALLOWED: // <http://tools.ietf.org/html/rfc7231#section-6.5.5> |
| 3175 |
// they all mean the resource is NON_DAV |
| 3176 |
SAL_WARN( "ucb.ucp.webdav", "resourceTypeForLocks() DAVException (SC_FORBIDDEN, SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <" |
| 3177 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3178 |
eResourceTypeForLocks = NON_DAV; |
| 3179 |
break; |
| 3180 |
default: |
| 3181 |
//fallthrough |
| 3182 |
SAL_WARN( "ucb.ucp.webdav", "resourceTypeForLocks() DAVException - URL: <" |
| 3183 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3184 |
eResourceTypeForLocks = UNKNOWN; |
| 3185 |
} |
| 3186 |
} |
| 3187 |
} |
| 3188 |
} |
| 3189 |
else |
| 3190 |
eResourceTypeForLocks = NON_DAV; |
| 3191 |
|
| 3192 |
//} |
| 3193 |
} |
| 3194 |
osl::MutexGuard g(m_aMutex); |
| 3195 |
if (m_eResourceTypeForLocks == UNKNOWN) |
| 3196 |
{ |
| 3197 |
m_eResourceTypeForLocks = eResourceTypeForLocks; |
| 3198 |
} |
| 3199 |
else |
| 3200 |
{ |
| 3201 |
SAL_WARN_IF( |
| 3202 |
eResourceTypeForLocks != m_eResourceTypeForLocks, "ucb.ucp.webdav", |
| 3203 |
"different resource types for <" << aURL << ">: " |
| 3204 |
<< +eResourceTypeForLocks << " vs. " << +m_eResourceTypeForLocks); |
| 3205 |
} |
| 3206 |
SAL_INFO( "ucb.ucp.webdav", "resourceTypeForLocks() - URL: <" |
| 3207 |
<< m_xIdentifier->getContentIdentifier() << ">, m_eResourceTypeForLocks: " << m_eResourceTypeForLocks ); |
| 3208 |
return m_eResourceTypeForLocks; |
| 3209 |
} |
| 3210 |
|
| 3211 |
Content::ResourceType Content::resourceTypeForLocks( |
| 3212 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 3213 |
{ |
| 3214 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 3215 |
{ |
| 3216 |
osl::MutexGuard aGuard( m_aMutex ); |
| 3217 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 3218 |
} |
| 3219 |
Content::ResourceType ret = resourceTypeForLocks( Environment, xResAccess ); |
| 3220 |
{ |
| 3221 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3222 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 3223 |
} |
| 3224 |
return ret; |
| 3225 |
} |
| 3226 |
|
| 3227 |
void Content::lock( |
| 3228 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 3229 |
{ |
| 3230 |
// prepare aURL to be used in exception, see below |
| 3231 |
OUString aURL; |
| 3232 |
if ( m_bTransient ) |
| 3233 |
{ |
| 3234 |
aURL = getParentURL(); |
| 3235 |
if ( aURL.lastIndexOf('/') != ( aURL.getLength() - 1 ) ) |
| 3236 |
aURL += "/"; |
| 3237 |
|
| 3238 |
aURL += m_aEscapedTitle; |
| 3239 |
} |
| 3240 |
else |
| 3241 |
{ |
| 3242 |
aURL = m_xIdentifier->getContentIdentifier(); |
| 3243 |
} |
| 3244 |
|
| 3245 |
try |
| 3246 |
{ |
| 3247 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 3248 |
{ |
| 3249 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3250 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 3251 |
} |
| 3252 |
|
| 3253 |
uno::Any aOwnerAny; |
| 3254 |
OUString const user(officecfg::Office::Common::Save::Document::UseUserData::get() |
| 3255 |
? " - " + ::svt::LockFileCommon::GetOOOUserName() |
| 3256 |
: OUString()); |
| 3257 |
aOwnerAny <<= OUString("LibreOffice" + user); |
| 3258 |
|
| 3259 |
ucb::Lock aLock( |
| 3260 |
ucb::LockScope_EXCLUSIVE, |
| 3261 |
ucb::LockType_WRITE, |
| 3262 |
ucb::LockDepth_ZERO, |
| 3263 |
aOwnerAny, |
| 3264 |
180, // lock timeout in secs |
| 3265 |
//-1, // infinite lock |
| 3266 |
uno::Sequence< OUString >() ); |
| 3267 |
|
| 3268 |
// OPTIONS may change as a consequence of the lock operation |
| 3269 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 3270 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 3271 |
xResAccess->LOCK( aLock, Environment ); |
| 3272 |
|
| 3273 |
{ |
| 3274 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3275 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 3276 |
} |
| 3277 |
} |
| 3278 |
catch ( DAVException const & e ) |
| 3279 |
{ |
| 3280 |
// check if the exception thrown is 'already locked' |
| 3281 |
// this exception is mapped directly to the ucb correct one, without |
| 3282 |
// going into the cancelCommandExecution() user interaction |
| 3283 |
// this exception should be managed by the issuer of 'lock' command |
| 3284 |
switch( e.getError() ) |
| 3285 |
{ |
| 3286 |
case DAVException::DAV_LOCKED: |
| 3287 |
{ |
| 3288 |
SAL_WARN( "ucb.ucp.webdav", "lock(): resource already locked - URL: <" |
| 3289 |
<< m_xIdentifier->getContentIdentifier() << ">"); |
| 3290 |
throw |
| 3291 |
ucb::InteractiveLockingLockedException( |
| 3292 |
u"Locked!"_ustr, |
| 3293 |
getXWeak(), |
| 3294 |
task::InteractionClassification_ERROR, |
| 3295 |
aURL, |
| 3296 |
false ); |
| 3297 |
} |
| 3298 |
break; |
| 3299 |
case DAVException::DAV_HTTP_NOAUTH: |
| 3300 |
case DAVException::DAV_HTTP_AUTH: |
| 3301 |
{ |
| 3302 |
SAL_WARN( "ucb.ucp.webdav", "lock(): DAVException Authentication error - URL: <" |
| 3303 |
<< m_xIdentifier->getContentIdentifier() << ">" ); |
| 3304 |
// DAVException::DAV_HTTP_AUTH exception can mean: |
| 3305 |
// - interaction handler for credential management not present (happens, depending |
| 3306 |
// on the LO framework processing) |
| 3307 |
// - the remote site is a WebDAV with special configuration: read/only for read operations |
| 3308 |
// and read/write for write operations, the user is not allowed to lock/write and |
| 3309 |
// she cancelled the credentials request. |
| 3310 |
// this is not actually an error, but the exception is sent directly from here, avoiding the automatic |
| 3311 |
// management that takes part in cancelCommandExecution() below |
| 3312 |
// Unfortunately there is no InteractiveNetwork*Exception available to signal this |
| 3313 |
// since it mostly happens on read/only part of webdav, this appears to be the most correct exception available |
| 3314 |
throw |
| 3315 |
ucb::InteractiveNetworkWriteException( |
| 3316 |
u"Authentication error while trying to lock! Write only WebDAV perhaps?"_ustr, |
| 3317 |
getXWeak(), |
| 3318 |
task::InteractionClassification_ERROR, |
| 3319 |
e.getData() ); |
| 3320 |
} |
| 3321 |
break; |
| 3322 |
case DAVException::DAV_HTTP_ERROR: |
| 3323 |
//grab the error code |
| 3324 |
switch( e.getStatus() ) |
| 3325 |
{ |
| 3326 |
// The 'case SC_NOT_FOUND' just below tries to solve a problem in eXo Platform |
| 3327 |
// WebDAV connector which apparently fail on resource first creation |
| 3328 |
// rfc4918 section-7.3 (see link below) |
| 3329 |
case SC_NOT_FOUND: // <http://tools.ietf.org/html/rfc7231#section-6.5.4> |
| 3330 |
// The 'case SC_PRECONDITION_FAILED' just below tries to solve a problem |
| 3331 |
// in SharePoint when locking the resource on first creation fails due to this: |
| 3332 |
// <https://msdn.microsoft.com/en-us/library/jj575265%28v=office.12%29.aspx#id15> |
| 3333 |
// (retrieved on 2015-08-14) |
| 3334 |
case SC_PRECONDITION_FAILED: // <http://tools.ietf.org/html/rfc7232#section-4.2> |
| 3335 |
// Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED are |
| 3336 |
// part of base http 1.1 RFCs |
| 3337 |
case SC_NOT_IMPLEMENTED: // <http://tools.ietf.org/html/rfc7231#section-6.6.2> |
| 3338 |
case SC_METHOD_NOT_ALLOWED: // <http://tools.ietf.org/html/rfc7231#section-6.5.5> |
| 3339 |
SAL_WARN( "ucb.ucp.webdav", "lock() DAVException (SC_NOT_FOUND, SC_PRECONDITION_FAILED, SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <" |
| 3340 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3341 |
// act as nothing happened |
| 3342 |
// that's because when a resource is first created |
| 3343 |
// the lock is sent before the put, so the resource |
| 3344 |
// is actually created by LOCK, locking it before |
| 3345 |
// the first PUT, but if LOCK is not supported |
| 3346 |
// (simple web or DAV with lock disabled) we end with one of these http |
| 3347 |
// errors. |
| 3348 |
// These same errors may be reported when the LOCK on an unmapped |
| 3349 |
// (i.e. non existent) resource is not implemented. |
| 3350 |
// Detailed specification in: |
| 3351 |
// <http://tools.ietf.org/html/rfc4918#section-7.3> |
| 3352 |
return; |
| 3353 |
default: |
| 3354 |
//fallthrough |
| 3355 |
; |
| 3356 |
} |
| 3357 |
break; |
| 3358 |
case DAVException::DAV_LOCKED_SELF: |
| 3359 |
// we already hold the lock and it is in our internal lockstore |
| 3360 |
// just return as if the lock was successful |
| 3361 |
return; |
| 3362 |
default: |
| 3363 |
//fallthrough |
| 3364 |
; |
| 3365 |
} |
| 3366 |
|
| 3367 |
SAL_WARN( "ucb.ucp.webdav","lock() DAVException - URL: <" |
| 3368 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3369 |
cancelCommandExecution( e, Environment, false ); |
| 3370 |
// Unreachable |
| 3371 |
} |
| 3372 |
} |
| 3373 |
|
| 3374 |
|
| 3375 |
void Content::unlock( |
| 3376 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 3377 |
{ |
| 3378 |
|
| 3379 |
try |
| 3380 |
{ |
| 3381 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 3382 |
{ |
| 3383 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3384 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 3385 |
} |
| 3386 |
|
| 3387 |
// check if the target URL is a Class1 DAV |
| 3388 |
DAVOptions aDAVOptions; |
| 3389 |
getResourceOptions( Environment, aDAVOptions, xResAccess ); |
| 3390 |
|
| 3391 |
// at least class one is needed |
| 3392 |
if( aDAVOptions.isClass1() ) |
| 3393 |
{ |
| 3394 |
// remove options from cache, unlock may change it |
| 3395 |
// it will be refreshed when needed |
| 3396 |
aStaticDAVOptionsCache.removeDAVOptions( xResAccess->getURL() ); |
| 3397 |
// clean cached value of PROPFIND properties names |
| 3398 |
removeCachedPropertyNames( xResAccess->getURL() ); |
| 3399 |
xResAccess->UNLOCK( Environment ); |
| 3400 |
} |
| 3401 |
|
| 3402 |
{ |
| 3403 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3404 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 3405 |
} |
| 3406 |
} |
| 3407 |
catch ( DAVException const & e ) |
| 3408 |
{ |
| 3409 |
switch( e.getError() ) |
| 3410 |
{ |
| 3411 |
case DAVException::DAV_NOT_LOCKED: |
| 3412 |
SAL_WARN( "ucb.ucp.webdav", "unlock(): DAVException::DAV_NOT_LOCKED - URL: <" |
| 3413 |
<< m_xIdentifier->getContentIdentifier() << ">"); |
| 3414 |
// means that we don't own any lock on this resource |
| 3415 |
// intercepted here to remove a confusing indication to the user |
| 3416 |
// unfortunately this happens in some WebDAV server configuration |
| 3417 |
// acting as WebDAV and having lock/unlock enabled only |
| 3418 |
// for authorized user. |
| 3419 |
return; |
| 3420 |
case DAVException::DAV_HTTP_ERROR: |
| 3421 |
//grab the error code |
| 3422 |
switch( e.getStatus() ) |
| 3423 |
{ |
| 3424 |
// Errors SC_NOT_IMPLEMENTED and SC_METHOD_NOT_ALLOWED are |
| 3425 |
// part of base http 1.1 RFCs |
| 3426 |
case SC_NOT_IMPLEMENTED: // <http://tools.ietf.org/html/rfc7231#section-6.6.2> |
| 3427 |
case SC_METHOD_NOT_ALLOWED: // <http://tools.ietf.org/html/rfc7231#section-6.5.5> |
| 3428 |
SAL_WARN( "ucb.ucp.webdav", "unlock() DAVException (SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED) - URL: <" |
| 3429 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3430 |
return; |
| 3431 |
default: |
| 3432 |
//fallthrough |
| 3433 |
; |
| 3434 |
} |
| 3435 |
break; |
| 3436 |
default: |
| 3437 |
//fallthrough |
| 3438 |
; |
| 3439 |
} |
| 3440 |
SAL_WARN( "ucb.ucp.webdav","unlock() DAVException - URL: <" |
| 3441 |
<< m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3442 |
cancelCommandExecution( e, Environment, false ); |
| 3443 |
// Unreachable |
| 3444 |
} |
| 3445 |
} |
| 3446 |
|
| 3447 |
|
| 3448 |
bool Content::exchangeIdentity( |
| 3449 |
const uno::Reference< ucb::XContentIdentifier >& xNewId ) |
| 3450 |
{ |
| 3451 |
if ( !xNewId.is() ) |
| 3452 |
return false; |
| 3453 |
|
| 3454 |
osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 3455 |
|
| 3456 |
uno::Reference< ucb::XContent > xThis = this; |
| 3457 |
|
| 3458 |
// Already persistent? |
| 3459 |
if ( m_bTransient ) |
| 3460 |
{ |
| 3461 |
SAL_WARN( "ucb.ucp.webdav", "Content::exchangeIdentity - Not persistent!" ); |
| 3462 |
return false; |
| 3463 |
} |
| 3464 |
|
| 3465 |
// Exchange own identity. |
| 3466 |
|
| 3467 |
// Fail, if a content with given id already exists. |
| 3468 |
// if ( !hasData( xNewId ) ) |
| 3469 |
{ |
| 3470 |
OUString aOldURL = m_xIdentifier->getContentIdentifier(); |
| 3471 |
|
| 3472 |
aGuard.clear(); |
| 3473 |
if ( exchange( xNewId ) ) |
| 3474 |
{ |
| 3475 |
// Process instantiated children... |
| 3476 |
|
| 3477 |
ContentRefList aChildren; |
| 3478 |
queryChildren( aChildren ); |
| 3479 |
|
| 3480 |
for ( const auto& rChild : aChildren ) |
| 3481 |
{ |
| 3482 |
ContentRef xChild = rChild; |
| 3483 |
|
| 3484 |
// Create new content identifier for the child... |
| 3485 |
uno::Reference< ucb::XContentIdentifier > |
| 3486 |
xOldChildId = xChild->getIdentifier(); |
| 3487 |
OUString aOldChildURL |
| 3488 |
= xOldChildId->getContentIdentifier(); |
| 3489 |
OUString aNewChildURL |
| 3490 |
= aOldChildURL.replaceAt( |
| 3491 |
0, |
| 3492 |
aOldURL.getLength(), |
| 3493 |
xNewId->getContentIdentifier() ); |
| 3494 |
uno::Reference< ucb::XContentIdentifier > xNewChildId |
| 3495 |
= new ::ucbhelper::ContentIdentifier( aNewChildURL ); |
| 3496 |
|
| 3497 |
if ( !xChild->exchangeIdentity( xNewChildId ) ) |
| 3498 |
return false; |
| 3499 |
} |
| 3500 |
return true; |
| 3501 |
} |
| 3502 |
} |
| 3503 |
|
| 3504 |
SAL_WARN( "ucb.ucp.webdav", |
| 3505 |
"Content::exchangeIdentity - " |
| 3506 |
"Panic! Cannot exchange identity!" ); |
| 3507 |
return false; |
| 3508 |
} |
| 3509 |
|
| 3510 |
|
| 3511 |
bool Content::isFolder( |
| 3512 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 3513 |
{ |
| 3514 |
{ |
| 3515 |
osl::MutexGuard aGuard( m_aMutex ); |
| 3516 |
|
| 3517 |
if ( m_bTransient ) |
| 3518 |
return m_bCollection; |
| 3519 |
} |
| 3520 |
|
| 3521 |
uno::Sequence< beans::Property > aProperties( 1 ); |
| 3522 |
auto pProperties = aProperties.getArray(); |
| 3523 |
pProperties[ 0 ].Name = "IsFolder"; |
| 3524 |
pProperties[ 0 ].Handle = -1; |
| 3525 |
uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, xEnv ) ); |
| 3526 |
if ( xRow.is() ) |
| 3527 |
{ |
| 3528 |
try |
| 3529 |
{ |
| 3530 |
return xRow->getBoolean( 1 ); |
| 3531 |
} |
| 3532 |
catch ( sdbc::SQLException const & ) |
| 3533 |
{ |
| 3534 |
} |
| 3535 |
} |
| 3536 |
|
| 3537 |
return false; |
| 3538 |
} |
| 3539 |
|
| 3540 |
|
| 3541 |
uno::Any Content::MapDAVException( const DAVException & e, bool bWrite ) |
| 3542 |
{ |
| 3543 |
// Map DAVException... |
| 3544 |
uno::Any aException; |
| 3545 |
|
| 3546 |
OUString aURL; |
| 3547 |
if ( m_bTransient ) |
| 3548 |
{ |
| 3549 |
aURL = getParentURL(); |
| 3550 |
if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) ) |
| 3551 |
aURL += "/"; |
| 3552 |
|
| 3553 |
aURL += m_aEscapedTitle; |
| 3554 |
} |
| 3555 |
else |
| 3556 |
{ |
| 3557 |
aURL = m_xIdentifier->getContentIdentifier(); |
| 3558 |
} |
| 3559 |
|
| 3560 |
switch ( e.getStatus() ) |
| 3561 |
{ |
| 3562 |
case SC_NOT_FOUND: |
| 3563 |
{ |
| 3564 |
uno::Sequence<uno::Any> aArgs{ uno::Any(beans::PropertyValue( |
| 3565 |
u"Uri"_ustr, -1, uno::Any(aURL), beans::PropertyState_DIRECT_VALUE)) }; |
| 3566 |
|
| 3567 |
aException <<= |
| 3568 |
ucb::InteractiveAugmentedIOException( |
| 3569 |
u"Not found!"_ustr, |
| 3570 |
getXWeak(), |
| 3571 |
task::InteractionClassification_ERROR, |
| 3572 |
ucb::IOErrorCode_NOT_EXISTING, |
| 3573 |
aArgs ); |
| 3574 |
return aException; |
| 3575 |
} |
| 3576 |
default: |
| 3577 |
break; |
| 3578 |
} |
| 3579 |
|
| 3580 |
switch ( e.getError() ) |
| 3581 |
{ |
| 3582 |
case DAVException::DAV_HTTP_ERROR: |
| 3583 |
{ |
| 3584 |
if ( bWrite ) |
| 3585 |
aException <<= |
| 3586 |
ucb::InteractiveNetworkWriteException( |
| 3587 |
e.getData(), |
| 3588 |
getXWeak(), |
| 3589 |
task::InteractionClassification_ERROR, |
| 3590 |
e.getData() ); |
| 3591 |
else |
| 3592 |
aException <<= |
| 3593 |
ucb::InteractiveNetworkReadException( |
| 3594 |
e.getData(), |
| 3595 |
getXWeak(), |
| 3596 |
task::InteractionClassification_ERROR, |
| 3597 |
e.getData() ); |
| 3598 |
break; |
| 3599 |
} |
| 3600 |
|
| 3601 |
case DAVException::DAV_HTTP_LOOKUP: |
| 3602 |
aException <<= |
| 3603 |
ucb::InteractiveNetworkResolveNameException( |
| 3604 |
OUString(), |
| 3605 |
getXWeak(), |
| 3606 |
task::InteractionClassification_ERROR, |
| 3607 |
e.getData() ); |
| 3608 |
break; |
| 3609 |
|
| 3610 |
// @@@ No matching InteractiveNetwork*Exception |
| 3611 |
// case DAVException::DAV_HTTP_AUTH: |
| 3612 |
// break; |
| 3613 |
|
| 3614 |
// @@@ No matching InteractiveNetwork*Exception |
| 3615 |
// case DAVException::DAV_HTTP_AUTHPROXY: |
| 3616 |
// break; |
| 3617 |
|
| 3618 |
case DAVException::DAV_HTTP_TIMEOUT: |
| 3619 |
case DAVException::DAV_HTTP_CONNECT: |
| 3620 |
aException <<= |
| 3621 |
ucb::InteractiveNetworkConnectException( |
| 3622 |
e.getMessage(), |
| 3623 |
getXWeak(), |
| 3624 |
task::InteractionClassification_ERROR, |
| 3625 |
e.getData() ); |
| 3626 |
break; |
| 3627 |
|
| 3628 |
// @@@ No matching InteractiveNetwork*Exception |
| 3629 |
// case DAVException::DAV_HTTP_REDIRECT: |
| 3630 |
// break; |
| 3631 |
|
| 3632 |
// @@@ No matching InteractiveNetwork*Exception |
| 3633 |
// case DAVException::DAV_SESSION_CREATE: |
| 3634 |
// break; |
| 3635 |
|
| 3636 |
case DAVException::DAV_INVALID_ARG: |
| 3637 |
aException <<= |
| 3638 |
lang::IllegalArgumentException( |
| 3639 |
OUString(), |
| 3640 |
getXWeak(), |
| 3641 |
-1 ); |
| 3642 |
break; |
| 3643 |
|
| 3644 |
case DAVException::DAV_LOCKED: |
| 3645 |
#if 1 |
| 3646 |
aException <<= |
| 3647 |
ucb::InteractiveLockingLockedException( |
| 3648 |
u"Locked!"_ustr, |
| 3649 |
getXWeak(), |
| 3650 |
task::InteractionClassification_ERROR, |
| 3651 |
aURL, |
| 3652 |
false ); // not SelfOwned |
| 3653 |
#else |
| 3654 |
{ |
| 3655 |
uno::Sequence< uno::Any > aArgs( 1 ); |
| 3656 |
aArgs[ 0 ] <<= beans::PropertyValue( |
| 3657 |
OUString("Uri"), -1, |
| 3658 |
uno::makeAny(aURL), |
| 3659 |
beans::PropertyState_DIRECT_VALUE); |
| 3660 |
|
| 3661 |
aException <<= |
| 3662 |
ucb::InteractiveAugmentedIOException( |
| 3663 |
OUString( "Locked!" ), |
| 3664 |
getXWeak(), |
| 3665 |
task::InteractionClassification_ERROR, |
| 3666 |
ucb::IOErrorCode_LOCKING_VIOLATION, |
| 3667 |
aArgs ); |
| 3668 |
} |
| 3669 |
#endif |
| 3670 |
break; |
| 3671 |
|
| 3672 |
case DAVException::DAV_LOCKED_SELF: |
| 3673 |
aException <<= |
| 3674 |
ucb::InteractiveLockingLockedException( |
| 3675 |
u"Locked (self)!"_ustr, |
| 3676 |
getXWeak(), |
| 3677 |
task::InteractionClassification_ERROR, |
| 3678 |
aURL, |
| 3679 |
true ); // SelfOwned |
| 3680 |
break; |
| 3681 |
|
| 3682 |
case DAVException::DAV_NOT_LOCKED: |
| 3683 |
aException <<= |
| 3684 |
ucb::InteractiveLockingNotLockedException( |
| 3685 |
u"Not locked!"_ustr, |
| 3686 |
getXWeak(), |
| 3687 |
task::InteractionClassification_ERROR, |
| 3688 |
aURL ); |
| 3689 |
break; |
| 3690 |
|
| 3691 |
case DAVException::DAV_LOCK_EXPIRED: |
| 3692 |
aException <<= |
| 3693 |
ucb::InteractiveLockingLockExpiredException( |
| 3694 |
u"Lock expired!"_ustr, |
| 3695 |
getXWeak(), |
| 3696 |
task::InteractionClassification_ERROR, |
| 3697 |
aURL ); |
| 3698 |
break; |
| 3699 |
|
| 3700 |
default: |
| 3701 |
aException <<= |
| 3702 |
ucb::InteractiveNetworkGeneralException( |
| 3703 |
OUString(), |
| 3704 |
getXWeak(), |
| 3705 |
task::InteractionClassification_ERROR ); |
| 3706 |
break; |
| 3707 |
} |
| 3708 |
|
| 3709 |
return aException; |
| 3710 |
} |
| 3711 |
|
| 3712 |
|
| 3713 |
// static |
| 3714 |
bool Content::shouldAccessNetworkAfterException( const DAVException & e ) |
| 3715 |
{ |
| 3716 |
if ( ( e.getStatus() == SC_NOT_FOUND ) || |
| 3717 |
( e.getStatus() == SC_GONE ) || |
| 3718 |
( e.getError() == DAVException::DAV_HTTP_TIMEOUT ) || |
| 3719 |
( e.getError() == DAVException::DAV_HTTP_LOOKUP ) || |
| 3720 |
( e.getError() == DAVException::DAV_HTTP_CONNECT ) || |
| 3721 |
( e.getError() == DAVException::DAV_HTTP_NOAUTH ) || |
| 3722 |
( e.getError() == DAVException::DAV_HTTP_AUTH ) || |
| 3723 |
( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) ) |
| 3724 |
return false; |
| 3725 |
|
| 3726 |
return true; |
| 3727 |
} |
| 3728 |
|
| 3729 |
|
| 3730 |
void Content::cancelCommandExecution( |
| 3731 |
const DAVException & e, |
| 3732 |
const uno::Reference< ucb::XCommandEnvironment > & xEnv, |
| 3733 |
bool bWrite /* = false */ ) |
| 3734 |
{ |
| 3735 |
ucbhelper::cancelCommandExecution( MapDAVException( e, bWrite ), xEnv ); |
| 3736 |
// Unreachable |
| 3737 |
} |
| 3738 |
|
| 3739 |
|
| 3740 |
OUString |
| 3741 |
Content::getBaseURI( const std::unique_ptr< DAVResourceAccess > & rResAccess ) |
| 3742 |
{ |
| 3743 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3744 |
|
| 3745 |
// First, try to obtain value of response header "Content-Location". |
| 3746 |
if (m_xCachedProps) |
| 3747 |
{ |
| 3748 |
OUString aLocation; |
| 3749 |
m_xCachedProps->getValue( u"Content-Location"_ustr ) >>= aLocation; |
| 3750 |
if ( aLocation.getLength() ) |
| 3751 |
{ |
| 3752 |
try |
| 3753 |
{ |
| 3754 |
// Do not use m_xIdentifier->getContentIdentifier() because it |
| 3755 |
// for example does not reflect redirects applied to requests |
| 3756 |
// done using the original URI but m_xResAccess' URI does. |
| 3757 |
return rtl::Uri::convertRelToAbs( rResAccess->getURL(), |
| 3758 |
aLocation ); |
| 3759 |
} |
| 3760 |
catch ( rtl::MalformedUriException const & ) |
| 3761 |
{ |
| 3762 |
} |
| 3763 |
} |
| 3764 |
} |
| 3765 |
|
| 3766 |
return rResAccess->getURL(); |
| 3767 |
} |
| 3768 |
|
| 3769 |
// resource type is the type of the WebDAV resource |
| 3770 |
Content::ResourceType Content::getResourceType( |
| 3771 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv, |
| 3772 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 3773 |
bool * networkAccessAllowed ) |
| 3774 |
{ |
| 3775 |
{ |
| 3776 |
osl::MutexGuard g(m_aMutex); |
| 3777 |
if (m_eResourceType != UNKNOWN) { |
| 3778 |
return m_eResourceType; |
| 3779 |
} |
| 3780 |
} |
| 3781 |
|
| 3782 |
ResourceType eResourceType = UNKNOWN; |
| 3783 |
DAVOptions aDAVOptions; |
| 3784 |
|
| 3785 |
{ |
| 3786 |
getResourceOptions( xEnv, aDAVOptions, rResAccess, networkAccessAllowed ); |
| 3787 |
|
| 3788 |
// at least class one is needed |
| 3789 |
if( aDAVOptions.isClass1() ) |
| 3790 |
{ |
| 3791 |
try |
| 3792 |
{ |
| 3793 |
// Try to fetch some frequently used property value, e.g. those |
| 3794 |
// used when loading documents... along with identifying whether |
| 3795 |
// this is a DAV resource. |
| 3796 |
std::vector< DAVResource > resources; |
| 3797 |
std::vector< OUString > aPropNames; |
| 3798 |
uno::Sequence< beans::Property > aProperties( 5 ); |
| 3799 |
auto pProperties = aProperties.getArray(); |
| 3800 |
pProperties[ 0 ].Name = "IsFolder"; |
| 3801 |
pProperties[ 1 ].Name = "IsDocument"; |
| 3802 |
pProperties[ 2 ].Name = "IsReadOnly"; |
| 3803 |
pProperties[ 3 ].Name = "MediaType"; |
| 3804 |
pProperties[ 4 ].Name = DAVProperties::SUPPORTEDLOCK; |
| 3805 |
|
| 3806 |
ContentProperties::UCBNamesToDAVNames( aProperties, aPropNames ); |
| 3807 |
|
| 3808 |
rResAccess->PROPFIND( DAVZERO, aPropNames, resources, xEnv ); |
| 3809 |
|
| 3810 |
if ( resources.size() == 1 ) |
| 3811 |
{ |
| 3812 |
#if defined SAL_LOG_INFO |
| 3813 |
{//debug |
| 3814 |
// print received resources |
| 3815 |
std::vector< DAVPropertyValue >::const_iterator it = resources[0].properties.begin(); |
| 3816 |
std::vector< DAVPropertyValue >::const_iterator end = resources[0].properties.end(); |
| 3817 |
while ( it != end ) |
| 3818 |
{ |
| 3819 |
OUString aPropValue; |
| 3820 |
bool bValue; |
| 3821 |
uno::Sequence< ucb::LockEntry > aSupportedLocks; |
| 3822 |
if((*it).Value >>= aPropValue ) |
| 3823 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getResourceType) - ret'd prop: " << (*it).Name << ":" << aPropValue ); |
| 3824 |
else if( (*it).Value >>= bValue ) |
| 3825 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getResourceType) - ret'd prop: " << (*it).Name << ":" << |
| 3826 |
( bValue ? "true" : "false" ) ); |
| 3827 |
else if( (*it).Value >>= aSupportedLocks ) |
| 3828 |
{ |
| 3829 |
SAL_INFO( "ucb.ucp.webdav", "PROPFIND (getResourceType) - ret'd prop: " << (*it).Name << ":" ); |
| 3830 |
for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n ) |
| 3831 |
{ |
| 3832 |
SAL_INFO( "ucb.ucp.webdav","PROPFIND (getResourceType) - supportedlock[" << n <<"]: scope: " |
| 3833 |
<< (aSupportedLocks[n].Scope == ucb::LockScope_SHARED ? "shared" : "exclusive") |
| 3834 |
<< ", type: " |
| 3835 |
<< (aSupportedLocks[n].Type != ucb::LockType_WRITE ? "" : "write") ); |
| 3836 |
} |
| 3837 |
} |
| 3838 |
++it; |
| 3839 |
} |
| 3840 |
} |
| 3841 |
#endif |
| 3842 |
osl::MutexGuard g(m_aMutex); |
| 3843 |
m_xCachedProps.reset( |
| 3844 |
new CachableContentProperties( ContentProperties( resources[ 0 ] ) ) ); |
| 3845 |
m_xCachedProps->containsAllNames( |
| 3846 |
aProperties, m_aFailedPropNames ); |
| 3847 |
} |
| 3848 |
eResourceType = DAV; |
| 3849 |
} |
| 3850 |
catch ( DAVException const & e ) |
| 3851 |
{ |
| 3852 |
rResAccess->resetUri(); |
| 3853 |
|
| 3854 |
SAL_WARN( "ucb.ucp.webdav", "Content::getResourceType returned errors, DAV ExceptionCode: " << e.getError() << ", HTTP error: " << e.getStatus() ); |
| 3855 |
|
| 3856 |
if ( e.getStatus() == SC_METHOD_NOT_ALLOWED ) |
| 3857 |
{ |
| 3858 |
// Status SC_METHOD_NOT_ALLOWED is a safe indicator that the |
| 3859 |
// resource is NON_DAV |
| 3860 |
eResourceType = NON_DAV; |
| 3861 |
} |
| 3862 |
else if (networkAccessAllowed != nullptr) |
| 3863 |
{ |
| 3864 |
*networkAccessAllowed = *networkAccessAllowed |
| 3865 |
&& shouldAccessNetworkAfterException(e); |
| 3866 |
} |
| 3867 |
if ( e.getStatus() == SC_NOT_FOUND ) |
| 3868 |
{ |
| 3869 |
// arrives here if OPTIONS is still cached for a resource previously available |
| 3870 |
// operate on the OPTIONS cache: |
| 3871 |
// if OPTIONS was not found, do nothing |
| 3872 |
// else OPTIONS returned on a resource not existent (example a server that allows lock on null resource) set |
| 3873 |
// not found and adjust lifetime accordingly |
| 3874 |
DAVOptions aDAVOptionsInner; |
| 3875 |
if (aStaticDAVOptionsCache.getDAVOptions(rResAccess->getURL(), aDAVOptionsInner)) |
| 3876 |
{ |
| 3877 |
// TODO? get redirected url |
| 3878 |
aDAVOptionsInner.setHttpResponseStatusCode( e.getStatus() ); |
| 3879 |
aDAVOptionsInner.setHttpResponseStatusText( e.getData() ); |
| 3880 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptionsInner, |
| 3881 |
m_nOptsCacheLifeNotFound ); |
| 3882 |
} |
| 3883 |
} |
| 3884 |
// if the two net events below happen, something |
| 3885 |
// is going on to the connection so break the command flow |
| 3886 |
if ( ( e.getError() == DAVException::DAV_HTTP_TIMEOUT ) || |
| 3887 |
( e.getError() == DAVException::DAV_HTTP_CONNECT ) ) |
| 3888 |
{ |
| 3889 |
cancelCommandExecution( e, xEnv ); |
| 3890 |
// unreachable |
| 3891 |
} |
| 3892 |
|
| 3893 |
// cancel command execution is case that no user authentication data has been provided. |
| 3894 |
if ( e.getError() == DAVException::DAV_HTTP_NOAUTH ) |
| 3895 |
{ |
| 3896 |
cancelCommandExecution( e, uno::Reference< ucb::XCommandEnvironment >() ); |
| 3897 |
} |
| 3898 |
} |
| 3899 |
} |
| 3900 |
else |
| 3901 |
{ |
| 3902 |
rResAccess->resetUri(); |
| 3903 |
|
| 3904 |
// first check if the cached error can be mapped to DAVException::DAV_HTTP_TIMEOUT or mapped to DAVException::DAV_HTTP_CONNECT |
| 3905 |
if (aDAVOptions.getHttpResponseStatusCode() == USC_CONNECT_FAILED |
| 3906 |
|| aDAVOptions.getHttpResponseStatusCode() == USC_CONNECTION_TIMED_OUT |
| 3907 |
// can't get any reliable info without auth => cancel request |
| 3908 |
|| aDAVOptions.getHttpResponseStatusCode() == USC_AUTH_FAILED |
| 3909 |
|| aDAVOptions.getHttpResponseStatusCode() == USC_AUTHPROXY_FAILED) |
| 3910 |
{ |
| 3911 |
// behave same as DAVException::DAV_HTTP_TIMEOUT or DAVException::DAV_HTTP_CONNECT was thrown |
| 3912 |
try |
| 3913 |
{ |
| 3914 |
// extract host name and connection port |
| 3915 |
CurlUri theUri( rResAccess->getURL() ); |
| 3916 |
const OUString& aHostName = theUri.GetHost(); |
| 3917 |
sal_Int32 nPort = theUri.GetPort(); |
| 3918 |
DAVException::ExceptionCode e{}; |
| 3919 |
switch (aDAVOptions.getHttpResponseStatusCode()) |
| 3920 |
{ |
| 3921 |
case USC_CONNECT_FAILED: |
| 3922 |
e = DAVException::DAV_HTTP_CONNECT; |
| 3923 |
throw DAVException(e, |
| 3924 |
ConnectionEndPointString(aHostName, nPort), |
| 3925 |
aDAVOptions.getHttpResponseStatusText()); |
| 3926 |
break; |
| 3927 |
case USC_CONNECTION_TIMED_OUT: |
| 3928 |
e = DAVException::DAV_HTTP_TIMEOUT; |
| 3929 |
throw DAVException(e, |
| 3930 |
ConnectionEndPointString(aHostName, nPort), |
| 3931 |
aDAVOptions.getHttpResponseStatusText()); |
| 3932 |
break; |
| 3933 |
case USC_AUTH_FAILED: |
| 3934 |
e = DAVException::DAV_HTTP_AUTH; |
| 3935 |
break; |
| 3936 |
case USC_AUTHPROXY_FAILED: |
| 3937 |
e = DAVException::DAV_HTTP_AUTHPROXY; |
| 3938 |
break; |
| 3939 |
default: |
| 3940 |
assert(false); |
| 3941 |
} |
| 3942 |
throw DAVException( e, |
| 3943 |
ConnectionEndPointString(aHostName, nPort) ); |
| 3944 |
} |
| 3945 |
catch ( DAVException& exp ) |
| 3946 |
{ |
| 3947 |
cancelCommandExecution( exp, xEnv ); |
| 3948 |
} |
| 3949 |
} |
| 3950 |
|
| 3951 |
if ( aDAVOptions.getHttpResponseStatusCode() != SC_NOT_FOUND && |
| 3952 |
aDAVOptions.getHttpResponseStatusCode() != SC_GONE ) // the cached OPTIONS can have SC_GONE |
| 3953 |
{ |
| 3954 |
eResourceType = NON_DAV; |
| 3955 |
} |
| 3956 |
else |
| 3957 |
{ |
| 3958 |
//resource doesn't exist |
| 3959 |
if ( networkAccessAllowed != nullptr ) |
| 3960 |
*networkAccessAllowed = false; |
| 3961 |
} |
| 3962 |
} |
| 3963 |
} |
| 3964 |
|
| 3965 |
osl::MutexGuard g(m_aMutex); |
| 3966 |
if (m_eResourceType == UNKNOWN) { |
| 3967 |
m_eResourceType = eResourceType; |
| 3968 |
} else { |
| 3969 |
SAL_WARN_IF( |
| 3970 |
eResourceType != m_eResourceType, "ucb.ucp.webdav", |
| 3971 |
"different resource types for <" << rResAccess->getURL() << ">: " |
| 3972 |
<< +eResourceType << " vs. " << +m_eResourceType); |
| 3973 |
} |
| 3974 |
SAL_INFO( "ucb.ucp.webdav", "m_eResourceType for <" << rResAccess->getURL() << ">: " << m_eResourceType ); |
| 3975 |
return m_eResourceType; |
| 3976 |
} |
| 3977 |
|
| 3978 |
|
| 3979 |
Content::ResourceType Content::getResourceType( |
| 3980 |
const uno::Reference< ucb::XCommandEnvironment >& xEnv ) |
| 3981 |
{ |
| 3982 |
std::unique_ptr< DAVResourceAccess > xResAccess; |
| 3983 |
{ |
| 3984 |
osl::MutexGuard aGuard( m_aMutex ); |
| 3985 |
xResAccess.reset( new DAVResourceAccess( *m_xResAccess ) ); |
| 3986 |
} |
| 3987 |
const Content::ResourceType ret = getResourceType( xEnv, xResAccess ); |
| 3988 |
{ |
| 3989 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 3990 |
m_xResAccess.reset( new DAVResourceAccess( *xResAccess ) ); |
| 3991 |
} |
| 3992 |
return ret; |
| 3993 |
} |
| 3994 |
|
| 3995 |
|
| 3996 |
void Content::initOptsCacheLifeTime() |
| 3997 |
{ |
| 3998 |
// see description in |
| 3999 |
// officecfg/registry/schema/org/openoffice/Inet.xcs |
| 4000 |
// for use of these field values. |
| 4001 |
sal_uInt32 nAtime; |
| 4002 |
nAtime = officecfg::Inet::Settings::OptsCacheLifeImplWeb::get(); |
| 4003 |
m_nOptsCacheLifeImplWeb = std::max( sal_uInt32( 0 ), |
| 4004 |
std::min( nAtime, sal_uInt32( 3600 ) ) ); |
| 4005 |
|
| 4006 |
nAtime = officecfg::Inet::Settings::OptsCacheLifeDAV::get(); |
| 4007 |
m_nOptsCacheLifeDAV = std::max( sal_uInt32( 0 ), |
| 4008 |
std::min( nAtime, sal_uInt32( 3600 ) ) ); |
| 4009 |
|
| 4010 |
nAtime = officecfg::Inet::Settings::OptsCacheLifeDAVLocked::get(); |
| 4011 |
m_nOptsCacheLifeDAVLocked = std::max( sal_uInt32( 0 ), |
| 4012 |
std::min( nAtime, sal_uInt32( 3600 ) ) ); |
| 4013 |
|
| 4014 |
nAtime = officecfg::Inet::Settings::OptsCacheLifeNotImpl::get(); |
| 4015 |
m_nOptsCacheLifeNotImpl = std::max( sal_uInt32( 0 ), |
| 4016 |
std::min( nAtime, sal_uInt32( 43200 ) ) ); |
| 4017 |
|
| 4018 |
nAtime = officecfg::Inet::Settings::OptsCacheLifeNotFound::get(); |
| 4019 |
m_nOptsCacheLifeNotFound = std::max( sal_uInt32( 0 ), |
| 4020 |
std::min( nAtime, sal_uInt32( 30 ) ) ); |
| 4021 |
} |
| 4022 |
|
| 4023 |
|
| 4024 |
void Content::getResourceOptions( |
| 4025 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, |
| 4026 |
DAVOptions& rDAVOptions, |
| 4027 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 4028 |
bool * networkAccessAllowed ) |
| 4029 |
{ |
| 4030 |
OUString aRedirURL; |
| 4031 |
OUString aTargetURL = rResAccess->getURL(); |
| 4032 |
DAVOptions aDAVOptions; |
| 4033 |
// first check if in cache, if not, then send method to server |
| 4034 |
if ( !aStaticDAVOptionsCache.getDAVOptions( aTargetURL, aDAVOptions ) ) |
| 4035 |
{ |
| 4036 |
try |
| 4037 |
{ |
| 4038 |
rResAccess->OPTIONS( aDAVOptions, xEnv ); |
| 4039 |
// IMPORTANT:the correctly implemented server will answer without errors, even if the resource is not present |
| 4040 |
sal_uInt32 nLifeTime = ( aDAVOptions.isClass1() || |
| 4041 |
aDAVOptions.isClass2() || |
| 4042 |
aDAVOptions.isClass3() ) ? |
| 4043 |
m_nOptsCacheLifeDAV : // a WebDAV site |
| 4044 |
m_nOptsCacheLifeImplWeb; // a site implementing OPTIONS but |
| 4045 |
// it's not DAV |
| 4046 |
// if resource is locked, will use a |
| 4047 |
// different lifetime |
| 4048 |
if( aDAVOptions.isLocked() ) |
| 4049 |
nLifeTime = m_nOptsCacheLifeDAVLocked; |
| 4050 |
|
| 4051 |
// check if redirected |
| 4052 |
aRedirURL = rResAccess->getURL(); |
| 4053 |
if( aRedirURL == aTargetURL) |
| 4054 |
{ // no redirection |
| 4055 |
aRedirURL.clear(); |
| 4056 |
} |
| 4057 |
// cache this URL's option |
| 4058 |
aDAVOptions.setURL( aTargetURL ); |
| 4059 |
aDAVOptions.setRedirectedURL( aRedirURL ); |
| 4060 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4061 |
nLifeTime ); |
| 4062 |
} |
| 4063 |
catch ( DAVException const & e ) |
| 4064 |
{ |
| 4065 |
// first, remove from cache, will be added if needed, depending on the error received |
| 4066 |
aStaticDAVOptionsCache.removeDAVOptions( aTargetURL ); |
| 4067 |
rResAccess->resetUri(); |
| 4068 |
|
| 4069 |
aDAVOptions.setURL( aTargetURL ); |
| 4070 |
aDAVOptions.setRedirectedURL( aRedirURL ); |
| 4071 |
switch( e.getError() ) |
| 4072 |
{ |
| 4073 |
case DAVException::DAV_HTTP_TIMEOUT: |
| 4074 |
case DAVException::DAV_HTTP_CONNECT: |
| 4075 |
{ |
| 4076 |
// something bad happened to the connection |
| 4077 |
// not same as not found, this instead happens when the server doesn't exist or doesn't answer at all |
| 4078 |
// probably a new bit stating 'timed out' should be added to opts var? |
| 4079 |
// in any case abort the command |
| 4080 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAVException: DAV_HTTP_" << (e.getError() == DAVException::DAV_HTTP_TIMEOUT ? "TIMEOUT" : "CONNECT") << " for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4081 |
// cache the internal unofficial status code |
| 4082 |
|
| 4083 |
aDAVOptions.setHttpResponseStatusCode(e.getError() == DAVException::DAV_HTTP_CONNECT ? USC_CONNECT_FAILED : USC_CONNECTION_TIMED_OUT); |
| 4084 |
// ugly: this is not a HTTP status from the server but message |
| 4085 |
// from libcurl but the string member is unused... |
| 4086 |
aDAVOptions.setHttpResponseStatusText(e.getMessage()); |
| 4087 |
// used only internally, so the text doesn't really matter.. |
| 4088 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4089 |
m_nOptsCacheLifeNotFound ); |
| 4090 |
if ( networkAccessAllowed != nullptr ) |
| 4091 |
{ |
| 4092 |
*networkAccessAllowed = *networkAccessAllowed |
| 4093 |
&& shouldAccessNetworkAfterException(e); |
| 4094 |
} |
| 4095 |
} |
| 4096 |
break; |
| 4097 |
case DAVException::DAV_HTTP_LOOKUP: |
| 4098 |
{ |
| 4099 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAVException: DAV_HTTP_LOOKUP for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4100 |
aDAVOptions.setHttpResponseStatusCode( USC_LOOKUP_FAILED ); |
| 4101 |
// used only internally, so the text doesn't really matter.. |
| 4102 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4103 |
m_nOptsCacheLifeNotFound ); |
| 4104 |
if ( networkAccessAllowed != nullptr ) |
| 4105 |
{ |
| 4106 |
*networkAccessAllowed = *networkAccessAllowed |
| 4107 |
&& shouldAccessNetworkAfterException(e); |
| 4108 |
} |
| 4109 |
} |
| 4110 |
break; |
| 4111 |
case DAVException::DAV_HTTP_NOAUTH: |
| 4112 |
case DAVException::DAV_HTTP_AUTH: |
| 4113 |
{ |
| 4114 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAVException: DAV_HTTP_AUTH for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4115 |
// - the remote site is a WebDAV with special configuration: read/only for read operations |
| 4116 |
// and read/write for write operations, the user is not allowed to lock/write and |
| 4117 |
// she cancelled the credentials request. |
| 4118 |
// this is not actually an error, it means only that for current user this is a standard web, |
| 4119 |
// though possibly DAV enabled |
| 4120 |
aDAVOptions.setHttpResponseStatusCode( USC_AUTH_FAILED ); |
| 4121 |
// used only internally, so the text doesn't really matter.. |
| 4122 |
if (xEnv && xEnv->getInteractionHandler()) |
| 4123 |
{ // only cache if there actually was a chance to request auth |
| 4124 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4125 |
m_nOptsCacheLifeNotFound ); |
| 4126 |
} |
| 4127 |
if ( networkAccessAllowed != nullptr ) |
| 4128 |
{ |
| 4129 |
*networkAccessAllowed = *networkAccessAllowed |
| 4130 |
&& shouldAccessNetworkAfterException(e); |
| 4131 |
} |
| 4132 |
} |
| 4133 |
break; |
| 4134 |
case DAVException::DAV_HTTP_AUTHPROXY: |
| 4135 |
{ |
| 4136 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAVException: DAV_HTTP_AUTHPROXY for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4137 |
aDAVOptions.setHttpResponseStatusCode( USC_AUTHPROXY_FAILED ); |
| 4138 |
// used only internally, so the text doesn't really matter.. |
| 4139 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4140 |
m_nOptsCacheLifeNotFound ); |
| 4141 |
if ( networkAccessAllowed != nullptr ) |
| 4142 |
{ |
| 4143 |
*networkAccessAllowed = *networkAccessAllowed |
| 4144 |
&& shouldAccessNetworkAfterException(e); |
| 4145 |
} |
| 4146 |
} |
| 4147 |
break; |
| 4148 |
case DAVException::DAV_HTTP_ERROR: |
| 4149 |
{ |
| 4150 |
switch( e.getStatus() ) |
| 4151 |
{ |
| 4152 |
case SC_FORBIDDEN: |
| 4153 |
{ |
| 4154 |
SAL_WARN( "ucb.ucp.webdav","OPTIONS - SC_FORBIDDEN for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4155 |
// cache it, so OPTIONS won't be called again, this URL does not support it |
| 4156 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4157 |
m_nOptsCacheLifeNotImpl ); |
| 4158 |
} |
| 4159 |
break; |
| 4160 |
case SC_BAD_REQUEST: |
| 4161 |
case SC_INTERNAL_SERVER_ERROR: |
| 4162 |
{ |
| 4163 |
SAL_WARN( "ucb.ucp.webdav","OPTIONS - SC_BAD_REQUEST or SC_INTERNAL_SERVER_ERROR for URL <" << m_xIdentifier->getContentIdentifier() << ">, HTTP error: "<< e.getStatus() |
| 4164 |
<< ", '" << e.getData() << "'" ); |
| 4165 |
// cache it, so OPTIONS won't be called again, this URL detect some problem while answering the method |
| 4166 |
aDAVOptions.setHttpResponseStatusCode( e.getStatus() ); |
| 4167 |
aDAVOptions.setHttpResponseStatusText( e.getData() ); |
| 4168 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4169 |
m_nOptsCacheLifeNotFound ); |
| 4170 |
} |
| 4171 |
break; |
| 4172 |
case SC_NOT_IMPLEMENTED: |
| 4173 |
case SC_METHOD_NOT_ALLOWED: |
| 4174 |
{ |
| 4175 |
// OPTIONS method must be implemented in DAV |
| 4176 |
// resource is NON_DAV, or not advertising it |
| 4177 |
SAL_WARN( "ucb.ucp.webdav","OPTIONS - SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED for URL <" << m_xIdentifier->getContentIdentifier() << ">, HTTP error: "<< e.getStatus() |
| 4178 |
<< ", '" << e.getData() << "'" ); |
| 4179 |
// cache it, so OPTIONS won't be called again, this URL does not support it |
| 4180 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4181 |
m_nOptsCacheLifeNotImpl ); |
| 4182 |
} |
| 4183 |
break; |
| 4184 |
case SC_NOT_FOUND: |
| 4185 |
{ |
| 4186 |
// Apparently on IIS 10.0, if you disabled OPTIONS method, this error is the one reported, |
| 4187 |
// instead of SC_NOT_IMPLEMENTED or SC_METHOD_NOT_ALLOWED. |
| 4188 |
// So check if this is an available resource, or a real 'Not Found' event. |
| 4189 |
sal_uInt32 nLifeTime = m_nOptsCacheLifeNotFound; |
| 4190 |
if( isResourceAvailable( xEnv, rResAccess, aDAVOptions ) ) |
| 4191 |
{ |
| 4192 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - Got an SC_NOT_FOUND, but the URL <" << m_xIdentifier->getContentIdentifier() << "> resource exists" ); |
| 4193 |
nLifeTime = m_nOptsCacheLifeNotImpl; |
| 4194 |
} |
| 4195 |
else |
| 4196 |
{ |
| 4197 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - SC_NOT_FOUND for URL <" << m_xIdentifier->getContentIdentifier() << ">" ); |
| 4198 |
if ( networkAccessAllowed != nullptr ) |
| 4199 |
{ |
| 4200 |
*networkAccessAllowed = *networkAccessAllowed |
| 4201 |
&& shouldAccessNetworkAfterException(e); |
| 4202 |
} |
| 4203 |
} |
| 4204 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4205 |
nLifeTime ); |
| 4206 |
} |
| 4207 |
break; |
| 4208 |
default: |
| 4209 |
{ |
| 4210 |
SAL_WARN( "ucb.ucp.webdav", "OPTIONS - DAV_HTTP_ERROR, for URL <" << m_xIdentifier->getContentIdentifier() << ">, HTTP error: "<< e.getStatus() |
| 4211 |
<< ", '" << e.getData() << "'" ); |
| 4212 |
aDAVOptions.setHttpResponseStatusCode( e.getStatus() ); |
| 4213 |
aDAVOptions.setHttpResponseStatusText( e.getData() ); |
| 4214 |
// cache it, so OPTIONS won't be called again, this URL does not support it |
| 4215 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4216 |
m_nOptsCacheLifeNotImpl ); |
| 4217 |
} |
| 4218 |
break; |
| 4219 |
} |
| 4220 |
} |
| 4221 |
break; |
| 4222 |
// The 'DAVException::DAV_HTTP_REDIRECT' means we reached the maximum |
| 4223 |
// number of redirections, consider the resource type as UNKNOWN |
| 4224 |
// possibly a normal web site, not DAV |
| 4225 |
case DAVException::DAV_HTTP_REDIRECT: |
| 4226 |
default: |
| 4227 |
{ |
| 4228 |
SAL_WARN( "ucb.ucp.webdav","OPTIONS - General DAVException (or max DAV_HTTP_REDIRECT reached) for URL <" << m_xIdentifier->getContentIdentifier() << ">, DAV ExceptionCode: " |
| 4229 |
<< e.getError() << ", HTTP error: "<< e.getStatus() ); |
| 4230 |
aStaticDAVOptionsCache.addDAVOptions( aDAVOptions, |
| 4231 |
m_nOptsCacheLifeNotImpl ); |
| 4232 |
} |
| 4233 |
break; |
| 4234 |
} |
| 4235 |
} |
| 4236 |
} |
| 4237 |
else |
| 4238 |
{ |
| 4239 |
// check current response status code, perhaps we need to set networkAccessAllowed |
| 4240 |
sal_uInt16 CachedResponseStatusCode = aDAVOptions.getHttpResponseStatusCode(); |
| 4241 |
if ( networkAccessAllowed != nullptr && |
| 4242 |
( ( CachedResponseStatusCode == SC_NOT_FOUND ) || |
| 4243 |
( CachedResponseStatusCode == SC_GONE ) || |
| 4244 |
( CachedResponseStatusCode == USC_CONNECT_FAILED ) || |
| 4245 |
( CachedResponseStatusCode == USC_CONNECTION_TIMED_OUT ) || |
| 4246 |
( CachedResponseStatusCode == USC_LOOKUP_FAILED ) || |
| 4247 |
( CachedResponseStatusCode == USC_AUTH_FAILED ) || |
| 4248 |
( CachedResponseStatusCode == USC_AUTHPROXY_FAILED ) |
| 4249 |
) |
| 4250 |
) |
| 4251 |
{ |
| 4252 |
*networkAccessAllowed = *networkAccessAllowed && false; |
| 4253 |
} |
| 4254 |
} |
| 4255 |
rDAVOptions = aDAVOptions; |
| 4256 |
} |
| 4257 |
|
| 4258 |
//static |
| 4259 |
bool Content::isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, |
| 4260 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 4261 |
DAVOptions& rDAVOptions ) |
| 4262 |
{ |
| 4263 |
std::vector< rtl::OUString > aHeaderNames; |
| 4264 |
DAVResource aResource; |
| 4265 |
|
| 4266 |
try |
| 4267 |
{ |
| 4268 |
// To check for the physical URL resource availability, first |
| 4269 |
// try using a simple HEAD command |
| 4270 |
// if HEAD is successful, set element found. |
| 4271 |
rResAccess->HEAD( aHeaderNames, aResource, xEnv ); |
| 4272 |
rDAVOptions.setHttpResponseStatusCode( 0 ); |
| 4273 |
rDAVOptions.setHttpResponseStatusText(u""_ustr); |
| 4274 |
return true; |
| 4275 |
} |
| 4276 |
catch ( DAVException const & e ) |
| 4277 |
{ |
| 4278 |
if ( e.getError() == DAVException::DAV_HTTP_ERROR ) |
| 4279 |
{ |
| 4280 |
if ( e.getStatus() == SC_NOT_IMPLEMENTED || |
| 4281 |
e.getStatus() == SC_METHOD_NOT_ALLOWED || |
| 4282 |
e.getStatus() == SC_NOT_FOUND ) |
| 4283 |
{ |
| 4284 |
SAL_WARN( "ucb.ucp.webdav", "HEAD probably not implemented: fall back to a partial GET" ); |
| 4285 |
// set in cached OPTIONS "HEAD not implemented" |
| 4286 |
// so it won't be used again on this resource |
| 4287 |
rDAVOptions.setHeadAllowed( false ); |
| 4288 |
try |
| 4289 |
{ |
| 4290 |
// do a GET with a payload of 0, the server does not |
| 4291 |
// support HEAD (or has HEAD disabled) |
| 4292 |
DAVRequestHeaders aPartialGet; |
| 4293 |
aPartialGet.emplace_back( |
| 4294 |
u"Range"_ustr, |
| 4295 |
u"bytes=0-0"_ustr); |
| 4296 |
|
| 4297 |
rResAccess->GET0( aPartialGet, |
| 4298 |
aHeaderNames, |
| 4299 |
aResource, |
| 4300 |
xEnv ); |
| 4301 |
return true; |
| 4302 |
} |
| 4303 |
catch ( DAVException const & ex ) |
| 4304 |
{ |
| 4305 |
if ( ex.getError() == DAVException::DAV_HTTP_ERROR ) |
| 4306 |
{ |
| 4307 |
rDAVOptions.setHttpResponseStatusCode( ex.getStatus() ); |
| 4308 |
rDAVOptions.setHttpResponseStatusText( ex.getData() ); |
| 4309 |
} |
| 4310 |
} |
| 4311 |
} |
| 4312 |
else |
| 4313 |
{ |
| 4314 |
rDAVOptions.setHttpResponseStatusCode( e.getStatus() ); |
| 4315 |
rDAVOptions.setHttpResponseStatusText( e.getData() ); |
| 4316 |
} |
| 4317 |
} |
| 4318 |
return false; |
| 4319 |
} |
| 4320 |
catch ( ... ) |
| 4321 |
{ |
| 4322 |
} |
| 4323 |
// set SC_NOT_IMPLEMENTED since at a minimum GET must be implemented in a basic Web server |
| 4324 |
rDAVOptions.setHttpResponseStatusCode( SC_NOT_IMPLEMENTED ); |
| 4325 |
rDAVOptions.setHttpResponseStatusText(u""_ustr); |
| 4326 |
return false; |
| 4327 |
} |
| 4328 |
|
| 4329 |
|
| 4330 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |