1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
23 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
26 #include <boost/shared_ptr.hpp>
27 #include <osl/mutex.hxx>
28 #include "DAVSession.hxx"
29 #include "SerfUri.hxx"
33 namespace ucbhelper
{ class ProxyDecider
; }
35 namespace http_dav_ucp
38 class SerfRequestProcessor
;
42 // A DAVSession implementation using the neon/expat library
45 class SerfSession
: public DAVSession
52 OUString m_aProxyName
;
53 sal_Int32 m_nProxyPort
;
55 serf_connection_t
* m_pSerfConnection
;
56 serf_context_t
* m_pSerfContext
;
57 serf_bucket_alloc_t
* m_pSerfBucket_Alloc
;
58 bool m_bIsHeadRequestInProgress
;
59 bool m_bUseChunkedEncoding
;
60 sal_Int16 m_bNoOfTransferEncodingSwitches
;
62 const ucbhelper::InternetProxyDecider
& m_rProxyDecider
;
64 DAVRequestEnvironment m_aEnv
;
69 SerfRequestProcessor
* createReqProc( const OUString
& inPath
);
72 virtual ~SerfSession();
75 SerfSession( const rtl::Reference
< DAVSessionFactory
> & rSessionFactory
,
76 const OUString
& inUri
,
77 const ucbhelper::InternetProxyDecider
& rProxyDecider
)
78 throw ( DAVException
);
80 // Serf library callbacks
81 apr_status_t
setupSerfConnection( apr_socket_t
* inAprSocket
,
82 serf_bucket_t
**outSerfInputBucket
,
83 serf_bucket_t
**outSerfOutputBucket
,
84 apr_pool_t
* inAprPool
);
86 apr_status_t
provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry
,
89 serf_request_t
* inRequest
,
91 const char *inAuthProtocol
,
93 apr_pool_t
*inAprPool
);
95 apr_status_t
verifySerfCertificateChain (
97 const serf_ssl_certificate_t
* const * pCertificateChainBase64Encoded
,
98 int nCertificateChainLength
);
100 serf_bucket_t
* acceptSerfResponse( serf_request_t
* inSerfRequest
,
101 serf_bucket_t
* inSerfStreamBucket
,
102 apr_pool_t
* inAprPool
);
104 // Serf-related data structures
105 apr_pool_t
* getAprPool();
106 serf_bucket_alloc_t
* getSerfBktAlloc();
107 serf_context_t
* getSerfContext();
108 serf_connection_t
* getSerfConnection();
110 // DAVSession methods
111 virtual bool CanUse( const OUString
& inUri
) SAL_OVERRIDE
;
113 virtual bool UsesProxy() SAL_OVERRIDE
;
115 const DAVRequestEnvironment
& getRequestEnvironment() const
120 PROPFIND( const OUString
& inPath
,
122 const std::vector
< OUString
> & inPropNames
,
123 std::vector
< DAVResource
> & ioResources
,
124 const DAVRequestEnvironment
& rEnv
)
125 throw ( DAVException
) SAL_OVERRIDE
;
129 PROPFIND( const OUString
& inPath
,
131 std::vector
< DAVResourceInfo
>& ioResInfo
,
132 const DAVRequestEnvironment
& rEnv
)
133 throw ( DAVException
) SAL_OVERRIDE
;
136 PROPPATCH( const OUString
& inPath
,
137 const std::vector
< ProppatchValue
> & inValues
,
138 const DAVRequestEnvironment
& rEnv
)
139 throw ( DAVException
) SAL_OVERRIDE
;
142 HEAD( const OUString
& inPath
,
143 const std::vector
< OUString
> & inHeaderNames
,
144 DAVResource
& ioResource
,
145 const DAVRequestEnvironment
& rEnv
)
146 throw ( DAVException
) SAL_OVERRIDE
;
148 bool isHeadRequestInProgress();
150 virtual com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>
151 GET( const OUString
& inPath
,
152 const DAVRequestEnvironment
& rEnv
)
153 throw ( DAVException
) SAL_OVERRIDE
;
156 GET( const OUString
& inPath
,
157 com::sun::star::uno::Reference
<
158 com::sun::star::io::XOutputStream
> & ioOutputStream
,
159 const DAVRequestEnvironment
& rEnv
)
160 throw ( DAVException
) SAL_OVERRIDE
;
162 virtual com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>
163 GET( const OUString
& inPath
,
164 const std::vector
< OUString
> & inHeaderNames
,
165 DAVResource
& ioResource
,
166 const DAVRequestEnvironment
& rEnv
)
167 throw ( DAVException
) SAL_OVERRIDE
;
170 GET( const OUString
& inPath
,
171 com::sun::star::uno::Reference
<
172 com::sun::star::io::XOutputStream
> & ioOutputStream
,
173 const std::vector
< OUString
> & inHeaderNames
,
174 DAVResource
& ioResource
,
175 const DAVRequestEnvironment
& rEnv
)
176 throw ( DAVException
) SAL_OVERRIDE
;
179 PUT( const OUString
& inPath
,
180 const com::sun::star::uno::Reference
<
181 com::sun::star::io::XInputStream
> & inInputStream
,
182 const DAVRequestEnvironment
& rEnv
)
183 throw ( DAVException
) SAL_OVERRIDE
;
185 virtual com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>
186 POST( const OUString
& inPath
,
187 const OUString
& rContentType
,
188 const OUString
& rReferer
,
189 const com::sun::star::uno::Reference
<
190 com::sun::star::io::XInputStream
> & inInputStream
,
191 const DAVRequestEnvironment
& rEnv
)
192 throw ( DAVException
) SAL_OVERRIDE
;
195 POST( const OUString
& inPath
,
196 const OUString
& rContentType
,
197 const OUString
& rReferer
,
198 const com::sun::star::uno::Reference
<
199 com::sun::star::io::XInputStream
> & inInputStream
,
200 com::sun::star::uno::Reference
<
201 com::sun::star::io::XOutputStream
> & oOutputStream
,
202 const DAVRequestEnvironment
& rEnv
)
203 throw ( DAVException
) SAL_OVERRIDE
;
206 MKCOL( const OUString
& inPath
,
207 const DAVRequestEnvironment
& rEnv
)
208 throw ( DAVException
) SAL_OVERRIDE
;
211 COPY( const OUString
& inSourceURL
,
212 const OUString
& inDestinationURL
,
213 const DAVRequestEnvironment
& rEnv
,
215 throw ( DAVException
) SAL_OVERRIDE
;
218 MOVE( const OUString
& inSourceURL
,
219 const OUString
& inDestinationURL
,
220 const DAVRequestEnvironment
& rEnv
,
222 throw ( DAVException
) SAL_OVERRIDE
;
224 virtual void DESTROY( const OUString
& inPath
,
225 const DAVRequestEnvironment
& rEnv
)
226 throw ( DAVException
) SAL_OVERRIDE
;
229 virtual void LOCK( const OUString
& inURL
,
230 com::sun::star::ucb::Lock
& inLock
,
231 const DAVRequestEnvironment
& rEnv
)
232 throw ( DAVException
) SAL_OVERRIDE
;
234 // refresh existing lock.
235 virtual sal_Int64
LOCK( const OUString
& inURL
,
237 const DAVRequestEnvironment
& rEnv
)
238 throw ( DAVException
) SAL_OVERRIDE
;
240 virtual void UNLOCK( const OUString
& inURL
,
241 const DAVRequestEnvironment
& rEnv
)
242 throw ( DAVException
) SAL_OVERRIDE
;
246 throw ( DAVException
) SAL_OVERRIDE
;
248 const OUString
& getHostName() const { return m_aUri
.GetHost(); }
249 int getPort() const { return m_aUri
.GetPort(); }
251 bool isDomainMatch( const OUString
& certHostName
);
254 friend class SerfLockStore
;
257 throw ( DAVException
);
259 void Init( const DAVRequestEnvironment
& rEnv
)
260 throw ( DAVException
);
262 void HandleError( boost::shared_ptr
<SerfRequestProcessor
> rReqProc
)
263 throw ( DAVException
);
265 const ucbhelper::InternetProxyServer
& getProxySettings() const;
267 bool removeExpiredLocktoken( const OUString
& inURL
,
268 const DAVRequestEnvironment
& rEnv
);
270 // refresh lock, called by SerfLockStore::refreshLocks
271 bool LOCK( const OUString
& rLock
, sal_Int32
*plastChanceToSendRefreshRequest
);
273 // unlock, called by SerfLockStore::~SerfLockStore
274 void UNLOCK( const OUString
& rLock
);
277 // low level GET implementation, used by public GET implementations
278 static int GET( serf_connection_t * sess,
280 //ne_block_reader reader,
284 // Buffer-based PUT implementation. Serf only has file descriptor-
286 static int PUT( serf_connection_t * sess,
291 // Buffer-based POST implementation. Serf only has file descriptor-
293 int POST( serf_connection_t * sess,
296 //ne_block_reader reader,
298 const OUString & rContentType,
299 const OUString & rReferer );
302 // Helper: XInputStream -> Sequence< sal_Int8 >
303 static bool getDataFromInputStream(
304 const com::sun::star::uno::Reference
<
305 com::sun::star::io::XInputStream
> & xStream
,
306 com::sun::star::uno::Sequence
< sal_Int8
> & rData
,
307 bool bAppendTrailingZeroByte
);
310 OUString makeAbsoluteURL( OUString const & rURL ) const;
314 } // namespace http_dav_ucp
316 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFSESSION_HXX
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */