| 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 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <memory> |
| 24 |
#include <list> |
| 25 |
#include <rtl/ref.hxx> |
| 26 |
#include <com/sun/star/ucb/ContentCreationException.hpp> |
| 27 |
#include <com/sun/star/ucb/XContentCreator.hpp> |
| 28 |
#include <ucbhelper/contenthelper.hxx> |
| 29 |
#include "DAVResourceAccess.hxx" |
| 30 |
#include "PropertyMap.hxx" |
| 31 |
|
| 32 |
namespace com::sun::star::beans { |
| 33 |
struct Property; |
| 34 |
struct PropertyValue; |
| 35 |
} |
| 36 |
|
| 37 |
namespace com::sun::star::io { |
| 38 |
class XInputStream; |
| 39 |
} |
| 40 |
|
| 41 |
namespace com::sun::star::sdbc { |
| 42 |
class XRow; |
| 43 |
} |
| 44 |
|
| 45 |
namespace com::sun::star::ucb { |
| 46 |
struct OpenCommandArgument3; |
| 47 |
struct PropertyCommandArgument; |
| 48 |
struct PostCommandArgument2; |
| 49 |
struct TransferInfo; |
| 50 |
} |
| 51 |
|
| 52 |
namespace http_dav_ucp |
| 53 |
{ |
| 54 |
|
| 55 |
|
| 56 |
// UNO service name for the content. |
| 57 |
inline constexpr OUString WEBDAV_CONTENT_SERVICE_NAME = u"com.sun.star.ucb.WebDAVContent"_ustr; |
| 58 |
|
| 59 |
|
| 60 |
class ContentProvider; |
| 61 |
class ContentProperties; |
| 62 |
class CachableContentProperties; |
| 63 |
|
| 64 |
class Content : public ::ucbhelper::ContentImplHelper, |
| 65 |
public css::ucb::XContentCreator |
| 66 |
{ |
| 67 |
enum ResourceType |
| 68 |
{ |
| 69 |
UNKNOWN, // the type of the Web resource is unknown |
| 70 |
NOT_FOUND, // the Web resource does not exists |
| 71 |
NON_DAV, // the Web resource exists but it's not DAV |
| 72 |
DAV, // the type of the Web resource is DAV with lock/unlock available |
| 73 |
DAV_NOLOCK // the type of the Web resource is DAV with no lock/unlock available |
| 74 |
}; |
| 75 |
|
| 76 |
std::unique_ptr< DAVResourceAccess > m_xResAccess; |
| 77 |
std::unique_ptr< CachableContentProperties > m_xCachedProps; // locally cached props |
| 78 |
OUString m_aEscapedTitle; |
| 79 |
// resource type for general DAV methods |
| 80 |
ResourceType m_eResourceType; |
| 81 |
// resource type for general LOCK method only |
| 82 |
ResourceType m_eResourceTypeForLocks; |
| 83 |
ContentProvider* m_pProvider; // No need for a ref, base class holds object |
| 84 |
bool m_bTransient; |
| 85 |
bool const m_bCollection; |
| 86 |
bool m_bDidGetOrHead; |
| 87 |
std::vector< OUString > m_aFailedPropNames; |
| 88 |
// Options Cache lifetime |
| 89 |
// for web site implementing OPTIONS, but not dav |
| 90 |
sal_uInt32 m_nOptsCacheLifeImplWeb; |
| 91 |
// for WebDAV site where OPTIONS is mandatory |
| 92 |
sal_uInt32 m_nOptsCacheLifeDAV; |
| 93 |
// same as above, but when the resource is locked by us |
| 94 |
sal_uInt32 m_nOptsCacheLifeDAVLocked; |
| 95 |
// For web site not implementing OPTIONS |
| 96 |
// during this time we assume the site doesn't turn to WebDAV |
| 97 |
// but remains a simple Web |
| 98 |
sal_uInt32 m_nOptsCacheLifeNotImpl; |
| 99 |
// When resource is not found |
| 100 |
// may be the resource is unavailable only briefly? |
| 101 |
// so better have this small |
| 102 |
sal_uInt32 m_nOptsCacheLifeNotFound; |
| 103 |
|
| 104 |
void initOptsCacheLifeTime(); |
| 105 |
|
| 106 |
private: |
| 107 |
virtual css::uno::Sequence< css::beans::Property > |
| 108 |
getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; |
| 109 |
virtual css::uno::Sequence< css::ucb::CommandInfo > |
| 110 |
getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; |
| 111 |
virtual OUString getParentURL() override; |
| 112 |
|
| 113 |
/// @throws css::uno::Exception |
| 114 |
bool isFolder( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 115 |
|
| 116 |
/// @throws css::uno::Exception |
| 117 |
css::uno::Reference< css::sdbc::XRow > |
| 118 |
getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties, |
| 119 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 120 |
|
| 121 |
/// @throws css::uno::Exception |
| 122 |
css::uno::Sequence< css::uno::Any > |
| 123 |
setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues, |
| 124 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 125 |
|
| 126 |
typedef rtl::Reference< Content > ContentRef; |
| 127 |
typedef std::vector< ContentRef > ContentRefList; |
| 128 |
void queryChildren( ContentRefList& rChildren); |
| 129 |
|
| 130 |
bool |
| 131 |
exchangeIdentity( const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId ); |
| 132 |
|
| 133 |
OUString |
| 134 |
getBaseURI( const std::unique_ptr< DAVResourceAccess > & rResAccess ); |
| 135 |
|
| 136 |
/// @throws css::uno::Exception |
| 137 |
ResourceType |
| 138 |
getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 139 |
|
| 140 |
/// @throws css::uno::Exception |
| 141 |
ResourceType |
| 142 |
getResourceType( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, |
| 143 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 144 |
bool * networkAccessAllowed = nullptr ); |
| 145 |
|
| 146 |
// Command "open" |
| 147 |
/// @throws css::uno::Exception |
| 148 |
css::uno::Any open( |
| 149 |
const css::ucb::OpenCommandArgument3 & rArg, |
| 150 |
const css::uno::Reference< |
| 151 |
css::ucb::XCommandEnvironment > & xEnv ); |
| 152 |
|
| 153 |
// Command "post" |
| 154 |
/// @throws css::uno::Exception |
| 155 |
void post( const css::ucb::PostCommandArgument2 & rArg, |
| 156 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 157 |
|
| 158 |
// Command "insert" |
| 159 |
/// @throws css::uno::Exception |
| 160 |
void insert( const css::uno::Reference< css::io::XInputStream > & xInputStream, |
| 161 |
bool bReplaceExisting, |
| 162 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 163 |
|
| 164 |
// Command "transfer" |
| 165 |
/// @throws css::uno::Exception |
| 166 |
void transfer( const css::ucb::TransferInfo & rArgs, |
| 167 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 168 |
|
| 169 |
// Command "delete" |
| 170 |
/// @throws css::uno::Exception |
| 171 |
void destroy( bool bDeletePhysical ); |
| 172 |
|
| 173 |
// Command "lock" |
| 174 |
/// @throws css::uno::Exception |
| 175 |
void lock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 176 |
|
| 177 |
// Command "unlock" |
| 178 |
/// @throws css::uno::Exception |
| 179 |
void unlock( const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 180 |
|
| 181 |
css::uno::Any MapDAVException( const DAVException & e, |
| 182 |
bool bWrite ); |
| 183 |
/// @throws css::uno::Exception |
| 184 |
void cancelCommandExecution( |
| 185 |
const DAVException & e, |
| 186 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv, |
| 187 |
bool bWrite = false ); |
| 188 |
|
| 189 |
static bool shouldAccessNetworkAfterException( const DAVException & e ); |
| 190 |
|
| 191 |
ResourceType resourceTypeForLocks( |
| 192 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment, |
| 193 |
const std::unique_ptr< DAVResourceAccess > & rResAccess ); |
| 194 |
|
| 195 |
ResourceType resourceTypeForLocks( |
| 196 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnvironment ); |
| 197 |
|
| 198 |
// XPropertyContainer replacement |
| 199 |
/// @throws css::beans::PropertyExistException |
| 200 |
/// @throws css::beans::IllegalTypeException |
| 201 |
/// @throws css::lang::IllegalArgumentException |
| 202 |
/// @throws css::uno::RuntimeException |
| 203 |
void addProperty( const css::ucb::PropertyCommandArgument &aCmdArg, |
| 204 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 205 |
|
| 206 |
/// @throws css::beans::PropertyExistException |
| 207 |
/// @throws css::beans::NotRemoveableException |
| 208 |
/// @throws css::uno::RuntimeException |
| 209 |
void removeProperty( const OUString& Name, |
| 210 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ); |
| 211 |
public: |
| 212 |
/// @throws css::ucb::ContentCreationException |
| 213 |
Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 214 |
ContentProvider* pProvider, |
| 215 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 216 |
rtl::Reference< DAVSessionFactory > const & rSessionFactory ); |
| 217 |
/// @throws css::ucb::ContentCreationException |
| 218 |
Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 219 |
ContentProvider* pProvider, |
| 220 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 221 |
rtl::Reference< DAVSessionFactory > const & rSessionFactory, |
| 222 |
bool isCollection ); |
| 223 |
virtual ~Content() override; |
| 224 |
|
| 225 |
// XInterface |
| 226 |
virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
| 227 |
virtual void SAL_CALL acquire() |
| 228 |
noexcept override; |
| 229 |
virtual void SAL_CALL release() |
| 230 |
noexcept override; |
| 231 |
|
| 232 |
// XTypeProvider |
| 233 |
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override; |
| 234 |
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; |
| 235 |
|
| 236 |
// XServiceInfo |
| 237 |
virtual OUString SAL_CALL |
| 238 |
getImplementationName() override; |
| 239 |
|
| 240 |
virtual css::uno::Sequence< OUString > SAL_CALL |
| 241 |
getSupportedServiceNames() override; |
| 242 |
|
| 243 |
// XContent |
| 244 |
virtual OUString SAL_CALL |
| 245 |
getContentType() override; |
| 246 |
|
| 247 |
// XCommandProcessor |
| 248 |
virtual css::uno::Any SAL_CALL |
| 249 |
execute( const css::ucb::Command& aCommand, |
| 250 |
sal_Int32 CommandId, |
| 251 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override; |
| 252 |
virtual void SAL_CALL |
| 253 |
abort( sal_Int32 CommandId ) override; |
| 254 |
|
| 255 |
// XPropertyContainer |
| 256 |
virtual void SAL_CALL |
| 257 |
addProperty( const OUString& Name, |
| 258 |
sal_Int16 Attributes, |
| 259 |
const css::uno::Any& DefaultValue ) override; |
| 260 |
|
| 261 |
virtual void SAL_CALL |
| 262 |
removeProperty( const OUString& Name ) override; |
| 263 |
|
| 264 |
|
| 265 |
// Additional interfaces |
| 266 |
|
| 267 |
|
| 268 |
// XContentCreator |
| 269 |
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL |
| 270 |
queryCreatableContentsInfo() override; |
| 271 |
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL |
| 272 |
createNewContent( const css::ucb::ContentInfo& Info ) override; |
| 273 |
|
| 274 |
|
| 275 |
// Non-interface methods. |
| 276 |
|
| 277 |
|
| 278 |
DAVResourceAccess & getResourceAccess() { return *m_xResAccess; } |
| 279 |
|
| 280 |
// Called from resultset data supplier. |
| 281 |
static css::uno::Reference< css::sdbc::XRow > |
| 282 |
getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rContext, |
| 283 |
const css::uno::Sequence< css::beans::Property >& rProperties, |
| 284 |
const ContentProperties& rData, |
| 285 |
const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider, |
| 286 |
const OUString& rContentId ); |
| 287 |
|
| 288 |
/// Use OPTIONS method to retrieve the type of the Web resource |
| 289 |
/// @throws css::uno::Exception |
| 290 |
void getResourceOptions( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, |
| 291 |
DAVOptions& rDAVOptions, |
| 292 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 293 |
bool * networkAccessAllowed = nullptr); |
| 294 |
|
| 295 |
static bool isResourceAvailable( const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv, |
| 296 |
const std::unique_ptr< DAVResourceAccess > & rResAccess, |
| 297 |
DAVOptions& rDAVOptions ); |
| 298 |
|
| 299 |
static void removeCachedPropertyNames( const OUString & rURL ); |
| 300 |
|
| 301 |
}; |
| 302 |
|
| 303 |
} |
| 304 |
|
| 305 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |