| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 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 |
|
| 10 |
#pragma once |
| 11 |
|
| 12 |
#include "DAVSession.hxx" |
| 13 |
#include "CurlUri.hxx" |
| 14 |
|
| 15 |
#include <curl/curl.h> |
| 16 |
|
| 17 |
#include <atomic> |
| 18 |
#include <mutex> |
| 19 |
|
| 20 |
namespace http_dav_ucp |
| 21 |
{ |
| 22 |
/// implementation of libcurl HTTP/DAV back-end |
| 23 |
class CurlSession : public DAVSession |
| 24 |
{ |
| 25 |
private: |
| 26 |
/// mutex required to access all other non-const members |
| 27 |
::std::mutex m_Mutex; |
| 28 |
css::uno::Reference<css::uno::XComponentContext> const m_xContext; |
| 29 |
/// flags may be passed to constructor, e.g. "KeepAlive" |
| 30 |
css::uno::Sequence<css::beans::NamedValue> const m_Flags; |
| 31 |
CurlUri const m_URI; |
| 32 |
/// buffer for libcurl detailed error messages |
| 33 |
char m_ErrorBuffer[CURL_ERROR_SIZE]; |
| 34 |
/// proxy is used if non-empty |
| 35 |
OUString const m_Proxy; |
| 36 |
/// once authentication was successful, rely on m_pCurl's data |
| 37 |
bool m_isAuthenticated = false; |
| 38 |
bool m_isAuthenticatedProxy = false; |
| 39 |
/// read timeout in milliseconds (connection timeout is stored in m_pCurl) |
| 40 |
int m_nReadTimeout = 0; |
| 41 |
/// flag to signal abort to transferring thread |
| 42 |
::std::atomic<bool> m_AbortFlag = false; |
| 43 |
|
| 44 |
/// libcurl multi handle |
| 45 |
::std::unique_ptr<CURLM, deleter_from_fn<CURLM, curl_multi_cleanup>> m_pCurlMulti; |
| 46 |
/// libcurl easy handle |
| 47 |
::std::unique_ptr<CURL, deleter_from_fn<CURL, curl_easy_cleanup>> m_pCurl; |
| 48 |
|
| 49 |
// this class exists just to hide the implementation details in cxx file |
| 50 |
friend struct CurlProcessor; |
| 51 |
|
| 52 |
public: |
| 53 |
explicit CurlSession(css::uno::Reference<css::uno::XComponentContext> xContext, |
| 54 |
::rtl::Reference<DAVSessionFactory> const& rpFactory, OUString const& rURI, |
| 55 |
css::uno::Sequence<css::beans::NamedValue> const& rFlags, |
| 56 |
::ucbhelper::InternetProxyDecider const& rProxyDecider); |
| 57 |
virtual ~CurlSession() override; |
| 58 |
|
| 59 |
virtual auto CanUse(OUString const& rURI, |
| 60 |
css::uno::Sequence<css::beans::NamedValue> const& rFlags) -> bool override; |
| 61 |
|
| 62 |
virtual auto UsesProxy() -> bool override; |
| 63 |
|
| 64 |
// DAV methods |
| 65 |
virtual auto OPTIONS(OUString const& rURIReference, DAVOptions& rOptions, |
| 66 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 67 |
|
| 68 |
virtual auto PROPFIND(OUString const& rURIReference, Depth depth, |
| 69 |
::std::vector<OUString> const& rPropertyNames, |
| 70 |
::std::vector<DAVResource>& o_rResources, |
| 71 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 72 |
|
| 73 |
virtual auto PROPFIND(OUString const& rURIReference, Depth depth, |
| 74 |
::std::vector<DAVResourceInfo>& o_rResourceInfos, |
| 75 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 76 |
|
| 77 |
virtual auto PROPPATCH(OUString const& rURIReference, |
| 78 |
::std::vector<ProppatchValue> const& rValues, |
| 79 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 80 |
|
| 81 |
virtual auto HEAD(OUString const& rURIReference, ::std::vector<OUString> const& rHeaderNames, |
| 82 |
DAVResource& io_rResource, DAVRequestEnvironment const& rEnv) |
| 83 |
-> void override; |
| 84 |
|
| 85 |
virtual auto GET(OUString const& rURIReference, DAVRequestEnvironment const& rEnv) |
| 86 |
-> css::uno::Reference<css::io::XInputStream> override; |
| 87 |
|
| 88 |
virtual auto GET(OUString const& rURIReference, |
| 89 |
css::uno::Reference<css::io::XOutputStream>& rxOutStream, |
| 90 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 91 |
|
| 92 |
virtual auto GET(OUString const& rURIReference, ::std::vector<OUString> const& rHeaderNames, |
| 93 |
DAVResource& io_rResource, DAVRequestEnvironment const& rEnv) |
| 94 |
-> css::uno::Reference<css::io::XInputStream> override; |
| 95 |
|
| 96 |
virtual auto GET(OUString const& rURIReference, |
| 97 |
css::uno::Reference<css::io::XOutputStream>& rxOutStream, |
| 98 |
::std::vector<OUString> const& rHeaderNames, DAVResource& io_rResource, |
| 99 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 100 |
|
| 101 |
virtual auto PUT(OUString const& rURIReference, |
| 102 |
css::uno::Reference<css::io::XInputStream> const& rxInStream, |
| 103 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 104 |
|
| 105 |
virtual auto POST(OUString const& rURIReference, OUString const& rContentType, |
| 106 |
OUString const& rReferer, |
| 107 |
css::uno::Reference<css::io::XInputStream> const& rxInStream, |
| 108 |
DAVRequestEnvironment const& rEnv) |
| 109 |
-> css::uno::Reference<css::io::XInputStream> override; |
| 110 |
|
| 111 |
virtual auto POST(OUString const& rURIReference, OUString const& rContentType, |
| 112 |
OUString const& rReferer, |
| 113 |
css::uno::Reference<css::io::XInputStream> const& rxInStream, |
| 114 |
css::uno::Reference<css::io::XOutputStream>& rxOutStream, |
| 115 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 116 |
|
| 117 |
virtual auto MKCOL(OUString const& rURIReference, DAVRequestEnvironment const& rEnv) |
| 118 |
-> void override; |
| 119 |
|
| 120 |
virtual auto COPY(OUString const& rSourceURIReference, OUString const& rDestinationURI, |
| 121 |
DAVRequestEnvironment const& rEnv, bool isOverwrite = false) -> void override; |
| 122 |
|
| 123 |
virtual auto MOVE(OUString const& rSourceURIReference, OUString const& rDestinationURI, |
| 124 |
DAVRequestEnvironment const& rEnv, bool isOverwrite = false) -> void override; |
| 125 |
|
| 126 |
virtual auto DESTROY(OUString const& rURIReference, DAVRequestEnvironment const& rEnv) |
| 127 |
-> void override; |
| 128 |
|
| 129 |
virtual auto LOCK(OUString const& rURIReference, css::ucb::Lock /*const*/& rLock, |
| 130 |
DAVRequestEnvironment const& rEnv) -> void override; |
| 131 |
|
| 132 |
virtual auto UNLOCK(OUString const& rURIReference, DAVRequestEnvironment const& rEnv) |
| 133 |
-> void override; |
| 134 |
|
| 135 |
virtual auto abort() -> void override; |
| 136 |
|
| 137 |
auto NonInteractive_LOCK(OUString const& rURI, ::std::u16string_view rLockToken, |
| 138 |
sal_Int32& o_rLastChanceToSendRefreshRequest, bool& o_rIsAuthFailed) |
| 139 |
-> bool; |
| 140 |
auto NonInteractive_UNLOCK(OUString const& rURI) -> void; |
| 141 |
}; |
| 142 |
|
| 143 |
} // namespace http_dav_ucp |
| 144 |
|
| 145 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |