LibreOffice Module ucb (master)  1
NeonSession.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #pragma once
30 
31 #include <config_lgpl.h>
32 #include <vector>
33 #include <osl/mutex.hxx>
34 #include "DAVSession.hxx"
35 #include "NeonTypes.hxx"
36 #include "NeonLockStore.hxx"
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 
39 namespace ucbhelper { class ProxyDecider; }
40 
41 namespace webdav_ucp
42 {
43 
44 // A DAVSession implementation using the neon/expat library
45 class NeonSession : public DAVSession
46 {
47 private:
48  osl::Mutex m_aMutex;
49  OUString m_aScheme;
50  OUString m_aHostName;
51  OUString m_aProxyName;
52  sal_Int32 m_nPort;
53  sal_Int32 m_nProxyPort;
54  css::uno::Sequence< css::beans::NamedValue > m_aFlags;
56  bool m_bNeedNewSession = false; // Something happened that could invalidate m_pHttpSession
59 
60  // @@@ This should really be per-request data. But Neon currently
61  // (0.23.5) has no interface for passing per-request user data.
62  // Theoretically, a NeonSession instance could handle multiple requests
63  // at a time --currently it doesn't. Thus this is not an issue at the
64  // moment.
66 
67  static bool m_bGlobalsInited;
69 
70 protected:
71  virtual ~NeonSession() override;
72 
73 public:
75  NeonSession( const rtl::Reference< DAVSessionFactory > & rSessionFactory,
76  const OUString& inUri,
77  const css::uno::Sequence< css::beans::NamedValue >& rFlags,
78  const ucbhelper::InternetProxyDecider & rProxyDecider );
79 
80  // DAVSession methods
81  virtual bool CanUse( const OUString & inPath,
82  const css::uno::Sequence< css::beans::NamedValue >& rFlags ) override;
83 
84  virtual bool UsesProxy() override;
85 
87  { return m_aEnv; }
88 
89  virtual void
90  OPTIONS( const OUString & inPath,
91  DAVOptions& rOptions, // contains the name+values
92  const DAVRequestEnvironment & rEnv ) override;
93 
94  // allprop & named
95  virtual void
96  PROPFIND( const OUString & inPath,
97  const Depth inDepth,
98  const std::vector< OUString > & inPropNames,
99  std::vector< DAVResource > & ioResources,
100  const DAVRequestEnvironment & rEnv ) override;
101 
102  // propnames
103  virtual void
104  PROPFIND( const OUString & inPath,
105  const Depth inDepth,
106  std::vector< DAVResourceInfo >& ioResInfo,
107  const DAVRequestEnvironment & rEnv ) override;
108 
109  virtual void
110  PROPPATCH( const OUString & inPath,
111  const std::vector< ProppatchValue > & inValues,
112  const DAVRequestEnvironment & rEnv ) override;
113 
114  virtual void
115  HEAD( const OUString & inPath,
116  const std::vector< OUString > & inHeaderNames,
117  DAVResource & ioResource,
118  const DAVRequestEnvironment & rEnv ) override;
119 
120  virtual css::uno::Reference< css::io::XInputStream >
121  GET( const OUString & inPath,
122  const DAVRequestEnvironment & rEnv ) override;
123 
124  virtual void
125  GET( const OUString & inPath,
126  css::uno::Reference< css::io::XOutputStream > & ioOutputStream,
127  const DAVRequestEnvironment & rEnv ) override;
128 
129  virtual css::uno::Reference< css::io::XInputStream >
130  GET( const OUString & inPath,
131  const std::vector< OUString > & inHeaderNames,
132  DAVResource & ioResource,
133  const DAVRequestEnvironment & rEnv ) override;
134 
135  virtual void
136  GET0( const OUString & inPath,
137  const std::vector< OUString > & inHeaderNames,
138  DAVResource & ioResource,
139  const DAVRequestEnvironment & rEnv ) override;
140 
141  virtual void
142  GET( const OUString & inPath,
143  css::uno::Reference< css::io::XOutputStream > & ioOutputStream,
144  const std::vector< OUString > & inHeaderNames,
145  DAVResource & ioResource,
146  const DAVRequestEnvironment & rEnv ) override;
147 
148  virtual void
149  PUT( const OUString & inPath,
150  const css::uno::Reference< css::io::XInputStream > & inInputStream,
151  const DAVRequestEnvironment & rEnv ) override;
152 
153  virtual css::uno::Reference< css::io::XInputStream >
154  POST( const OUString & inPath,
155  const OUString & rContentType,
156  const OUString & rReferer,
157  const css::uno::Reference< css::io::XInputStream > & inInputStream,
158  const DAVRequestEnvironment & rEnv ) override;
159 
160  virtual void
161  POST( const OUString & inPath,
162  const OUString & rContentType,
163  const OUString & rReferer,
164  const css::uno::Reference< css::io::XInputStream > & inInputStream,
165  css::uno::Reference< css::io::XOutputStream > & oOutputStream,
166  const DAVRequestEnvironment & rEnv ) override;
167 
168  virtual void
169  MKCOL( const OUString & inPath,
170  const DAVRequestEnvironment & rEnv ) override;
171 
172  virtual void
173  COPY( const OUString & inSourceURL,
174  const OUString & inDestinationURL,
175  const DAVRequestEnvironment & rEnv,
176  bool inOverWrite ) override;
177 
178  virtual void
179  MOVE( const OUString & inSourceURL,
180  const OUString & inDestinationURL,
181  const DAVRequestEnvironment & rEnv,
182  bool inOverWrite ) override;
183 
184  virtual void DESTROY( const OUString & inPath,
185  const DAVRequestEnvironment & rEnv ) override;
186 
187  // set new lock.
188  virtual void LOCK( const OUString & inURL,
189  css::ucb::Lock & inLock,
190  const DAVRequestEnvironment & rEnv ) override;
191 
192  virtual void UNLOCK( const OUString & inURL,
193  const DAVRequestEnvironment & rEnv ) override;
194 
195  // helpers
196  virtual void abort() override;
197 
198  const OUString & getHostName() const { return m_aHostName; }
199 
200  ::uno::Reference< ::uno::XComponentContext > const & getComponentContext() const
201  { return m_xFactory->getComponentContext(); }
202 
203  const void * getRequestData() const { return m_pRequestData; }
204 
205  bool isDomainMatch( const OUString& certHostName );
206 
207  int CertificationNotify(const ne_ssl_certificate *cert);
208 
209  int NeonAuth(const char* inAuthProtocol, const char* inRealm,
210  int attempt, char* inoutUserName, char * inoutPassWord);
211 
212  void PreSendRequest(ne_request* req, ne_buffer* headers);
213 
214 private:
215  friend class NeonLockStore;
216 
218  void Init();
219 
221  void Init( const DAVRequestEnvironment & rEnv );
222 
223  // ret: true => retry request.
225  void HandleError( int nError,
226  const OUString & inPath,
227  const DAVRequestEnvironment & rEnv );
228 
230 
231  bool removeExpiredLocktoken( const OUString & inURL,
232  const DAVRequestEnvironment & rEnv );
233 
234  // refresh lock, called by NeonLockStore::refreshLocks
235  bool LOCK( NeonLock * pLock,
236  sal_Int32 & rlastChanceToSendRefreshRequest );
237 
238  // unlock, called by NeonLockStore::~NeonLockStore
239  bool UNLOCK( NeonLock * pLock );
240 
241  // low level GET implementation, used by public GET implementations
242  static int GET( ne_session * sess,
243  const char * uri,
244  ne_block_reader reader,
245  bool getheaders,
246  void * userdata );
247 
248  // low level GET implementation, used by public GET implementations
249  // used as a HEAD substitute when head is not available
250  static int GET0( ne_session * sess,
251  const char * uri,
252  bool getheaders,
253  void * userdata );
254 
255  // Buffer-based PUT implementation. Neon only has file descriptor-
256  // based API.
257  static int PUT( ne_session * sess,
258  const char * uri,
259  const char * buffer,
260  size_t size );
261 
262  // Buffer-based POST implementation. Neon only has file descriptor-
263  // based API.
264  int POST( ne_session * sess,
265  const char * uri,
266  const char * buffer,
267  ne_block_reader reader,
268  void * userdata,
269  const OUString & rContentType,
270  const OUString & rReferer );
271 
272  // Helper: XInputStream -> Sequence< sal_Int8 >
273  static bool getDataFromInputStream(
274  const css::uno::Reference< css::io::XInputStream > & xStream,
275  css::uno::Sequence< sal_Int8 > & rData,
276  bool bAppendTrailingZeroByte );
277 
278  OUString makeAbsoluteURL( OUString const & rURL ) const;
279 };
280 
281 osl::Mutex& getGlobalNeonMutex();
282 
283 } // namespace webdav_ucp
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int NeonAuth(const char *inAuthProtocol, const char *inRealm, int attempt, char *inoutUserName, char *inoutPassWord)
DAVRequestEnvironment m_aEnv
Definition: NeonSession.hxx:65
const OUString & getHostName() const
virtual void LOCK(const OUString &inURL, css::ucb::Lock &inLock, const DAVRequestEnvironment &rEnv) override
virtual void PROPPATCH(const OUString &inPath, const std::vector< ProppatchValue > &inValues, const DAVRequestEnvironment &rEnv) override
const DAVRequestEnvironment & getRequestEnvironment() const
Definition: NeonSession.hxx:86
const void * getRequestData() const
virtual void GET0(const OUString &inPath, const std::vector< OUString > &inHeaderNames, DAVResource &ioResource, const DAVRequestEnvironment &rEnv) override
OUString makeAbsoluteURL(OUString const &rURL) const
virtual void abort() override
virtual void OPTIONS(const OUString &inPath, DAVOptions &rOptions, const DAVRequestEnvironment &rEnv) override
static NeonLockStore m_aNeonLockStore
Definition: NeonSession.hxx:68
const ucbhelper::InternetProxyDecider & m_rProxyDecider
Definition: NeonSession.hxx:58
NeonSession(const rtl::Reference< DAVSessionFactory > &rSessionFactory, const OUString &inUri, const css::uno::Sequence< css::beans::NamedValue > &rFlags, const ucbhelper::InternetProxyDecider &rProxyDecider)
ne_session HttpSession
Definition: NeonTypes.hxx:46
::uno::Reference< ::uno::XComponentContext > const & getComponentContext() const
virtual void UNLOCK(const OUString &inURL, const DAVRequestEnvironment &rEnv) override
virtual void DESTROY(const OUString &inPath, const DAVRequestEnvironment &rEnv) override
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
bool removeExpiredLocktoken(const OUString &inURL, const DAVRequestEnvironment &rEnv)
static bool m_bGlobalsInited
Definition: NeonSession.hxx:67
virtual void COPY(const OUString &inSourceURL, const OUString &inDestinationURL, const DAVRequestEnvironment &rEnv, bool inOverWrite) override
static bool getDataFromInputStream(const css::uno::Reference< css::io::XInputStream > &xStream, css::uno::Sequence< sal_Int8 > &rData, bool bAppendTrailingZeroByte)
osl::Mutex & getGlobalNeonMutex()
struct ne_lock NeonLock
Definition: NeonTypes.hxx:52
virtual ~NeonSession() override
void PreSendRequest(ne_request *req, ne_buffer *headers)
HttpSession * m_pHttpSession
Definition: NeonSession.hxx:55
virtual bool UsesProxy() override
virtual void PROPFIND(const OUString &inPath, const Depth inDepth, const std::vector< OUString > &inPropNames, std::vector< DAVResource > &ioResources, const DAVRequestEnvironment &rEnv) override
ucbhelper::InternetProxyServer getProxySettings() const
virtual void MKCOL(const OUString &inPath, const DAVRequestEnvironment &rEnv) override
virtual bool CanUse(const OUString &inPath, const css::uno::Sequence< css::beans::NamedValue > &rFlags) override
bool isDomainMatch(const OUString &certHostName)
virtual void MOVE(const OUString &inSourceURL, const OUString &inDestinationURL, const DAVRequestEnvironment &rEnv, bool inOverWrite) override
int CertificationNotify(const ne_ssl_certificate *cert)
void HandleError(int nError, const OUString &inPath, const DAVRequestEnvironment &rEnv)
virtual css::uno::Reference< css::io::XInputStream > GET(const OUString &inPath, const DAVRequestEnvironment &rEnv) override
virtual void HEAD(const OUString &inPath, const std::vector< OUString > &inHeaderNames, DAVResource &ioResource, const DAVRequestEnvironment &rEnv) override
css::uno::Sequence< css::beans::NamedValue > m_aFlags
Definition: NeonSession.hxx:54
rtl::Reference< DAVSessionFactory > m_xFactory
virtual void PUT(const OUString &inPath, const css::uno::Reference< css::io::XInputStream > &inInputStream, const DAVRequestEnvironment &rEnv) override