LibreOffice Module ucb (master) 1
CurlSession.hxx
Go to the documentation of this file.
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
20namespace http_dav_ucp
21{
23class CurlSession : public DAVSession
24{
25private:
27 ::std::mutex m_Mutex;
28 css::uno::Reference<css::uno::XComponentContext> const m_xContext;
30 css::uno::Sequence<css::beans::NamedValue> const m_Flags;
33 char m_ErrorBuffer[CURL_ERROR_SIZE];
37 bool m_isAuthenticated = false;
42 ::std::atomic<bool> m_AbortFlag = false;
43
45 ::std::unique_ptr<CURLM, deleter_from_fn<CURLM, curl_multi_cleanup>> m_pCurlMulti;
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
52public:
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: */
implementation of libcurl HTTP/DAV back-end
Definition: CurlSession.hxx:24
::std::mutex m_Mutex
mutex required to access all other non-const members
Definition: CurlSession.hxx:27
virtual auto PUT(OUString const &rURIReference, css::uno::Reference< css::io::XInputStream > const &rxInStream, DAVRequestEnvironment const &rEnv) -> void override
virtual auto PROPPATCH(OUString const &rURIReference, ::std::vector< ProppatchValue > const &rValues, DAVRequestEnvironment const &rEnv) -> void override
int m_nReadTimeout
read timeout in milliseconds (connection timeout is stored in m_pCurl)
Definition: CurlSession.hxx:40
virtual auto POST(OUString const &rURIReference, OUString const &rContentType, OUString const &rReferer, css::uno::Reference< css::io::XInputStream > const &rxInStream, DAVRequestEnvironment const &rEnv) -> css::uno::Reference< css::io::XInputStream > override
virtual auto LOCK(OUString const &rURIReference, css::ucb::Lock &rLock, DAVRequestEnvironment const &rEnv) -> void override
virtual auto PROPFIND(OUString const &rURIReference, Depth depth, ::std::vector< OUString > const &rPropertyNames, ::std::vector< DAVResource > &o_rResources, DAVRequestEnvironment const &rEnv) -> void override
virtual auto HEAD(OUString const &rURIReference, ::std::vector< OUString > const &rHeaderNames, DAVResource &io_rResource, DAVRequestEnvironment const &rEnv) -> void override
virtual auto abort() -> void override
::std::unique_ptr< CURLM, deleter_from_fn< CURLM, curl_multi_cleanup > > m_pCurlMulti
libcurl multi handle
Definition: CurlSession.hxx:45
virtual auto UNLOCK(OUString const &rURIReference, DAVRequestEnvironment const &rEnv) -> void override
virtual auto COPY(OUString const &rSourceURIReference, OUString const &rDestinationURI, DAVRequestEnvironment const &rEnv, bool isOverwrite=false) -> void override
auto NonInteractive_UNLOCK(OUString const &rURI) -> void
virtual ~CurlSession() override
virtual auto DESTROY(OUString const &rURIReference, DAVRequestEnvironment const &rEnv) -> void override
css::uno::Sequence< css::beans::NamedValue > const m_Flags
flags may be passed to constructor, e.g. "KeepAlive"
Definition: CurlSession.hxx:30
virtual auto GET(OUString const &rURIReference, css::uno::Reference< css::io::XOutputStream > &rxOutStream, DAVRequestEnvironment const &rEnv) -> void override
char m_ErrorBuffer[CURL_ERROR_SIZE]
buffer for libcurl detailed error messages
Definition: CurlSession.hxx:33
virtual auto UsesProxy() -> bool override
auto NonInteractive_LOCK(OUString const &rURI, ::std::u16string_view rLockToken, sal_Int32 &o_rLastChanceToSendRefreshRequest, bool &o_rIsAuthFailed) -> bool
virtual auto MKCOL(OUString const &rURIReference, DAVRequestEnvironment const &rEnv) -> void override
bool m_isAuthenticated
once authentication was successful, rely on m_pCurl's data
Definition: CurlSession.hxx:37
virtual auto GET(OUString const &rURIReference, css::uno::Reference< css::io::XOutputStream > &rxOutStream, ::std::vector< OUString > const &rHeaderNames, DAVResource &io_rResource, DAVRequestEnvironment const &rEnv) -> void override
virtual auto MOVE(OUString const &rSourceURIReference, OUString const &rDestinationURI, DAVRequestEnvironment const &rEnv, bool isOverwrite=false) -> void override
virtual auto GET(OUString const &rURIReference, DAVRequestEnvironment const &rEnv) -> css::uno::Reference< css::io::XInputStream > override
CurlSession(css::uno::Reference< css::uno::XComponentContext > xContext, ::rtl::Reference< DAVSessionFactory > const &rpFactory, OUString const &rURI, css::uno::Sequence< css::beans::NamedValue > const &rFlags, ::ucbhelper::InternetProxyDecider const &rProxyDecider)
::std::atomic< bool > m_AbortFlag
flag to signal abort to transferring thread
Definition: CurlSession.hxx:42
::std::unique_ptr< CURL, deleter_from_fn< CURL, curl_easy_cleanup > > m_pCurl
libcurl easy handle
Definition: CurlSession.hxx:47
virtual auto POST(OUString const &rURIReference, OUString const &rContentType, OUString const &rReferer, css::uno::Reference< css::io::XInputStream > const &rxInStream, css::uno::Reference< css::io::XOutputStream > &rxOutStream, DAVRequestEnvironment const &rEnv) -> void override
virtual auto CanUse(OUString const &rURI, css::uno::Sequence< css::beans::NamedValue > const &rFlags) -> bool override
::ucbhelper::InternetProxyServer const m_Proxy
proxy is used if aName is non-empty
Definition: CurlSession.hxx:35
css::uno::Reference< css::uno::XComponentContext > const m_xContext
Definition: CurlSession.hxx:28
virtual auto OPTIONS(OUString const &rURIReference, DAVOptions &rOptions, DAVRequestEnvironment const &rEnv) -> void override
this is just a bunch of static member functions called from CurlSession