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