LibreOffice Module ucb (master)  1
SerfSession.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
22 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
23 
24 #include <osl/mutex.hxx>
25 #include <memory>
26 #include <vector>
27 #include "DAVSession.hxx"
28 #include "SerfUri.hxx"
29 
30 #include <serf.h>
31 
32 namespace ucbhelper { class ProxyDecider; }
33 
34 namespace http_dav_ucp
35 {
36 
37 class SerfRequestProcessor;
38 
39 
40 // SerfSession
41 // A DAVSession implementation using the neon/expat library
42 
43 
44 class SerfSession : public DAVSession
45 {
46 private:
47  osl::Mutex m_aMutex;
48 
50 
51  OUString m_aProxyName;
52  sal_Int32 m_nProxyPort;
53 
54  serf_connection_t* m_pSerfConnection;
55  serf_context_t* m_pSerfContext;
56  serf_bucket_alloc_t* m_pSerfBucket_Alloc;
60 
62 
64 
65  char* getHostinfo();
66  bool isSSLNeeded();
67 
68  SerfRequestProcessor* createReqProc( const OUString & inPath );
69 
70 protected:
71  virtual ~SerfSession() override;
72 
73 public:
75  SerfSession( const rtl::Reference< DAVSessionFactory > & rSessionFactory,
76  const OUString& inUri,
77  const ucbhelper::InternetProxyDecider & rProxyDecider );
78 
79  // Serf library callbacks
80  apr_status_t setupSerfConnection( apr_socket_t * inAprSocket,
81  serf_bucket_t **outSerfInputBucket,
82  serf_bucket_t **outSerfOutputBucket,
83  apr_pool_t* inAprPool );
84 
85  apr_status_t provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry,
86  char ** outUsername,
87  char ** outPassword,
88  serf_request_t * inRequest,
89  int inCode,
90  const char *inAuthProtocol,
91  const char *inRealm,
92  apr_pool_t *inAprPool );
93 
94  apr_status_t verifySerfCertificateChain (
95  int nFailures,
96  const serf_ssl_certificate_t * const * pCertificateChainBase64Encoded,
97  int nCertificateChainLength);
98 
99  serf_bucket_t* acceptSerfResponse( serf_request_t * inSerfRequest,
100  serf_bucket_t * inSerfStreamBucket,
101  apr_pool_t* inAprPool );
102 
103  // Serf-related data structures
104  static apr_pool_t* getAprPool();
105  serf_bucket_alloc_t* getSerfBktAlloc();
106  serf_context_t* getSerfContext();
107  serf_connection_t* getSerfConnection();
108 
109  // DAVSession methods
110  virtual bool CanUse( const OUString & inUri ) override;
111 
112  virtual bool UsesProxy() override;
113 
115  { return m_aEnv; }
116 
117  // allprop & named
118  virtual void
119  PROPFIND( const OUString & inPath,
120  const Depth inDepth,
121  const std::vector< OUString > & inPropNames,
122  std::vector< DAVResource > & ioResources,
123  const DAVRequestEnvironment & rEnv ) override;
124 
125  // propnames
126  virtual void
127  PROPFIND( const OUString & inPath,
128  const Depth inDepth,
129  std::vector< DAVResourceInfo >& ioResInfo,
130  const DAVRequestEnvironment & rEnv ) override;
131 
132  virtual void
133  PROPPATCH( const OUString & inPath,
134  const std::vector< ProppatchValue > & inValues,
135  const DAVRequestEnvironment & rEnv ) override;
136 
137  virtual void
138  HEAD( const OUString & inPath,
139  const std::vector< OUString > & inHeaderNames,
140  DAVResource & ioResource,
141  const DAVRequestEnvironment & rEnv ) override;
142 
144 
145  virtual css::uno::Reference< css::io::XInputStream >
146  GET( const OUString & inPath,
147  const DAVRequestEnvironment & rEnv ) override;
148 
149  virtual void
150  GET( const OUString & inPath,
151  css::uno::Reference< css::io::XOutputStream > & ioOutputStream,
152  const DAVRequestEnvironment & rEnv ) override;
153 
154  virtual css::uno::Reference< css::io::XInputStream >
155  GET( const OUString & inPath,
156  const std::vector< OUString > & inHeaderNames,
157  DAVResource & ioResource,
158  const DAVRequestEnvironment & rEnv ) override;
159 
160  virtual void
161  GET( const OUString & inPath,
162  css::uno::Reference< css::io::XOutputStream > & ioOutputStream,
163  const std::vector< OUString > & inHeaderNames,
164  DAVResource & ioResource,
165  const DAVRequestEnvironment & rEnv ) override;
166 
167  virtual void
168  PUT( const OUString & inPath,
169  const css::uno::Reference< css::io::XInputStream > & inInputStream,
170  const DAVRequestEnvironment & rEnv ) override;
171 
172  virtual css::uno::Reference< css::io::XInputStream >
173  POST( const OUString & inPath,
174  const OUString & rContentType,
175  const OUString & rReferer,
176  const css::uno::Reference< css::io::XInputStream > & inInputStream,
177  const DAVRequestEnvironment & rEnv ) override;
178 
179  virtual void
180  POST( const OUString & inPath,
181  const OUString & rContentType,
182  const OUString & rReferer,
183  const css::uno::Reference< css::io::XInputStream > & inInputStream,
184  css::uno::Reference< css::io::XOutputStream > & oOutputStream,
185  const DAVRequestEnvironment & rEnv ) override;
186 
187  virtual void
188  MKCOL( const OUString & inPath,
189  const DAVRequestEnvironment & rEnv ) override;
190 
191  virtual void
192  COPY( const OUString & inSourceURL,
193  const OUString & inDestinationURL,
194  const DAVRequestEnvironment & rEnv,
195  bool inOverWrite = false ) override;
196 
197  virtual void
198  MOVE( const OUString & inSourceURL,
199  const OUString & inDestinationURL,
200  const DAVRequestEnvironment & rEnv,
201  bool inOverWrite = false ) override;
202 
203  virtual void DESTROY( const OUString & inPath,
204  const DAVRequestEnvironment & rEnv ) override;
205 
206  // set new lock.
207  virtual void LOCK( const OUString & inURL,
208  css::ucb::Lock & inLock,
209  const DAVRequestEnvironment & rEnv ) override;
210 
211  // refresh existing lock.
212  virtual sal_Int64 LOCK( const OUString & inURL,
213  sal_Int64 nTimeout,
214  const DAVRequestEnvironment & rEnv ) override;
215 
216  virtual void UNLOCK( const OUString & inURL,
217  const DAVRequestEnvironment & rEnv ) override;
218 
219  // helpers
220  virtual void abort() override;
221 
222  const OUString & getHostName() const { return m_aUri.GetHost(); }
223  int getPort() const { return m_aUri.GetPort(); }
224 
225  bool isDomainMatch( const OUString & certHostName );
226 
227 private:
228  friend class SerfLockStore;
229 
231  void Init();
232 
234  void Init( const DAVRequestEnvironment & rEnv );
235 
237  void HandleError( std::shared_ptr<SerfRequestProcessor> rReqProc );
238 
240 
241  static bool removeExpiredLocktoken( const OUString & inURL,
242  const DAVRequestEnvironment & rEnv );
243 
244  // refresh lock, called by SerfLockStore::refreshLocks
245  bool LOCK( const OUString& rLock, sal_Int32 *plastChanceToSendRefreshRequest );
246 
247  // unlock, called by SerfLockStore::~SerfLockStore
248  void UNLOCK( const OUString& rLock );
249 
250  // Helper: XInputStream -> Sequence< sal_Int8 >
251  static bool getDataFromInputStream(
252  const css::uno::Reference<
253  css::io::XInputStream > & xStream,
254  css::uno::Sequence< sal_Int8 > & rData,
255  bool bAppendTrailingZeroByte );
256 };
257 
258 } // namespace http_dav_ucp
259 
260 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SerfSession(const rtl::Reference< DAVSessionFactory > &rSessionFactory, const OUString &inUri, const ucbhelper::InternetProxyDecider &rProxyDecider)
Definition: SerfSession.cxx:59
virtual void COPY(const OUString &inSourceURL, const OUString &inDestinationURL, const DAVRequestEnvironment &rEnv, bool inOverWrite=false) override
ucbhelper::InternetProxyServer getProxySettings() const
serf_context_t * getSerfContext()
const OUString & getHostName() const
static bool removeExpiredLocktoken(const OUString &inURL, const DAVRequestEnvironment &rEnv)
virtual void HEAD(const OUString &inPath, const std::vector< OUString > &inHeaderNames, DAVResource &ioResource, const DAVRequestEnvironment &rEnv) override
apr_status_t verifySerfCertificateChain(int nFailures, const serf_ssl_certificate_t *const *pCertificateChainBase64Encoded, int nCertificateChainLength)
apr_status_t setupSerfConnection(apr_socket_t *inAprSocket, serf_bucket_t **outSerfInputBucket, serf_bucket_t **outSerfOutputBucket, apr_pool_t *inAprPool)
static bool getDataFromInputStream(const css::uno::Reference< css::io::XInputStream > &xStream, css::uno::Sequence< sal_Int8 > &rData, bool bAppendTrailingZeroByte)
virtual void PROPFIND(const OUString &inPath, const Depth inDepth, const std::vector< OUString > &inPropNames, std::vector< DAVResource > &ioResources, const DAVRequestEnvironment &rEnv) override
const OUString & GetHost() const
Definition: SerfUri.hxx:73
serf_bucket_t * acceptSerfResponse(serf_request_t *inSerfRequest, serf_bucket_t *inSerfStreamBucket, apr_pool_t *inAprPool)
sal_Int16 m_bNoOfTransferEncodingSwitches
Definition: SerfSession.hxx:59
sal_Int32 GetPort() const
Definition: SerfUri.hxx:75
serf_bucket_alloc_t * getSerfBktAlloc()
virtual void DESTROY(const OUString &inPath, const DAVRequestEnvironment &rEnv) override
apr_status_t provideSerfCredentials(bool bGiveProvidedCredentialsASecondTry, char **outUsername, char **outPassword, serf_request_t *inRequest, int inCode, const char *inAuthProtocol, const char *inRealm, apr_pool_t *inAprPool)
serf_context_t * m_pSerfContext
Definition: SerfSession.hxx:55
serf_connection_t * getSerfConnection()
virtual void abort() override
virtual void PROPPATCH(const OUString &inPath, const std::vector< ProppatchValue > &inValues, const DAVRequestEnvironment &rEnv) override
void HandleError(std::shared_ptr< SerfRequestProcessor > rReqProc)
DAVRequestEnvironment m_aEnv
Definition: SerfSession.hxx:63
static apr_pool_t * getAprPool()
serf_bucket_alloc_t * m_pSerfBucket_Alloc
Definition: SerfSession.hxx:56
virtual void MOVE(const OUString &inSourceURL, const OUString &inDestinationURL, const DAVRequestEnvironment &rEnv, bool inOverWrite=false) override
virtual ~SerfSession() override
Definition: SerfSession.cxx:84
virtual css::uno::Reference< css::io::XInputStream > POST(const OUString &inPath, const OUString &rContentType, const OUString &rReferer, const css::uno::Reference< css::io::XInputStream > &inInputStream, const DAVRequestEnvironment &rEnv) override
virtual css::uno::Reference< css::io::XInputStream > GET(const OUString &inPath, const DAVRequestEnvironment &rEnv) override
virtual void PUT(const OUString &inPath, const css::uno::Reference< css::io::XInputStream > &inInputStream, const DAVRequestEnvironment &rEnv) override
virtual void LOCK(const OUString &inURL, css::ucb::Lock &inLock, const DAVRequestEnvironment &rEnv) override
const ucbhelper::InternetProxyDecider & m_rProxyDecider
Definition: SerfSession.hxx:61
virtual void UNLOCK(const OUString &inURL, const DAVRequestEnvironment &rEnv) override
virtual bool CanUse(const OUString &inUri) override
serf_connection_t * m_pSerfConnection
Definition: SerfSession.hxx:54
const DAVRequestEnvironment & getRequestEnvironment() const
bool isDomainMatch(const OUString &certHostName)
virtual bool UsesProxy() override
SerfRequestProcessor * createReqProc(const OUString &inPath)
virtual void MKCOL(const OUString &inPath, const DAVRequestEnvironment &rEnv) override