xref: /AOO41X/main/ucb/source/ucp/webdav/SerfSession.hxx (revision dcefce6ce885c17ab06b686ebe819428fa9ddffe)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_SERFSESSION_HXX
25 #define INCLUDED_SERFSESSION_HXX
26 
27 #include <vector>
28 #include <osl/mutex.hxx>
29 #include "DAVSession.hxx"
30 #include "SerfTypes.hxx"
31 //#include "SerfLockStore.hxx"
32 #include <SerfUri.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 
35 namespace ucbhelper { class ProxyDecider; }
36 
37 namespace http_dav_ucp
38 {
39 
40 class SerfRequestProcessor;
41 
42 // -------------------------------------------------------------------
43 // SerfSession
44 // A DAVSession implementation using the neon/expat library
45 // -------------------------------------------------------------------
46 
47 class SerfSession : public DAVSession
48 {
49 private:
50     osl::Mutex              m_aMutex;
51 
52     SerfUri                 m_aUri;
53 
54     rtl::OUString           m_aProxyName;
55     sal_Int32               m_nProxyPort;
56 
57     SerfConnection*         m_pSerfConnection;
58     serf_context_t*         m_pSerfContext;
59     serf_bucket_alloc_t*    m_pSerfBucket_Alloc;
60     bool                    m_bIsHeadRequestInProgress;
61 
62     const ucbhelper::InternetProxyDecider & m_rProxyDecider;
63 
64     DAVRequestEnvironment m_aEnv;
65 
66     static bool          m_bGlobalsInited;
67     static osl::Mutex m_aGlobalMutex;
68 //    static SerfLockStore m_aSerfLockStore;
69 
70     char* getHostinfo();
71     bool isSSLNeeded();
72 
73 protected:
74     virtual ~SerfSession();
75 
76 public:
77     SerfSession( const rtl::Reference< DAVSessionFactory > & rSessionFactory,
78                  const rtl::OUString& inUri,
79                  const ucbhelper::InternetProxyDecider & rProxyDecider )
80         throw ( DAVException );
81 
82     // Serf library callbacks
83     apr_status_t setupSerfConnection( apr_socket_t * inAprSocket,
84                                       serf_bucket_t **outSerfInputBucket,
85                                       serf_bucket_t **outSerfOutputBucket,
86                                       apr_pool_t* inAprPool );
87 
88     apr_status_t provideSerfCredentials( bool bGiveProvidedCredentialsASecondTry,
89                                          char ** outUsername,
90                                          char ** outPassword,
91                                          serf_request_t * inRequest,
92                                          int inCode,
93                                          const char *inAuthProtocol,
94                                          const char *inRealm,
95                                          apr_pool_t *inAprPool );
96 
97     apr_status_t verifySerfCertificate( int inFailures,
98                                         const serf_ssl_certificate_t * inCert );
99 
100     serf_bucket_t* acceptSerfResponse( serf_request_t * inSerfRequest,
101                                        serf_bucket_t * inSerfStreamBucket,
102                                        apr_pool_t* inAprPool );
103 
104     // Serf-related data structures
105     apr_pool_t* getAprPool();
106     serf_bucket_alloc_t* getSerfBktAlloc();
107     serf_context_t* getSerfContext();
108     SerfConnection* getSerfConnection();
109 
110     // DAVSession methods
111     virtual sal_Bool CanUse( const ::rtl::OUString & inUri );
112 
113     virtual sal_Bool UsesProxy();
114 
115     const DAVRequestEnvironment & getRequestEnvironment() const
116     { return m_aEnv; }
117 
118     // allprop & named
119     virtual void
120     PROPFIND( const ::rtl::OUString & inPath,
121               const Depth inDepth,
122               const std::vector< ::rtl::OUString > & inPropNames,
123               std::vector< DAVResource > & ioResources,
124               const DAVRequestEnvironment & rEnv )
125         throw ( DAVException );
126 
127     // propnames
128     virtual void
129     PROPFIND( const ::rtl::OUString & inPath,
130               const Depth inDepth,
131               std::vector< DAVResourceInfo >& ioResInfo,
132               const DAVRequestEnvironment & rEnv )
133         throw ( DAVException );
134 
135     virtual void
136     PROPPATCH( const ::rtl::OUString & inPath,
137                const std::vector< ProppatchValue > & inValues,
138                const DAVRequestEnvironment & rEnv )
139         throw ( DAVException );
140 
141     virtual void
142     HEAD( const ::rtl::OUString &  inPath,
143           const std::vector< ::rtl::OUString > & inHeaderNames,
144           DAVResource & ioResource,
145           const DAVRequestEnvironment & rEnv )
146         throw ( DAVException );
147 
148     bool isHeadRequestInProgress();
149 
150     virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
151     GET( const ::rtl::OUString & inPath,
152          const DAVRequestEnvironment & rEnv )
153         throw ( DAVException );
154 
155     virtual void
156     GET( const ::rtl::OUString & inPath,
157          com::sun::star::uno::Reference<
158              com::sun::star::io::XOutputStream > &  ioOutputStream,
159          const DAVRequestEnvironment & rEnv )
160         throw ( DAVException );
161 
162     virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
163     GET( const ::rtl::OUString & inPath,
164          const std::vector< ::rtl::OUString > & inHeaderNames,
165          DAVResource & ioResource,
166          const DAVRequestEnvironment & rEnv )
167         throw ( DAVException );
168 
169     virtual void
170     GET( const ::rtl::OUString & inPath,
171          com::sun::star::uno::Reference<
172              com::sun::star::io::XOutputStream > & ioOutputStream,
173          const std::vector< ::rtl::OUString > & inHeaderNames,
174          DAVResource & ioResource,
175          const DAVRequestEnvironment & rEnv )
176         throw ( DAVException );
177 
178     virtual void
179     PUT( const ::rtl::OUString & inPath,
180          const com::sun::star::uno::Reference<
181              com::sun::star::io::XInputStream > & inInputStream,
182          const DAVRequestEnvironment & rEnv )
183         throw ( DAVException );
184 
185     virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
186     POST( const rtl::OUString & inPath,
187           const rtl::OUString & rContentType,
188           const rtl::OUString & rReferer,
189           const com::sun::star::uno::Reference<
190               com::sun::star::io::XInputStream > & inInputStream,
191           const DAVRequestEnvironment & rEnv )
192         throw ( DAVException );
193 
194     virtual void
195     POST( const rtl::OUString & inPath,
196           const rtl::OUString & rContentType,
197           const rtl::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 );
204 
205     virtual void
206     MKCOL( const ::rtl::OUString & inPath,
207            const DAVRequestEnvironment & rEnv )
208         throw ( DAVException );
209 
210     virtual void
211     COPY( const ::rtl::OUString & inSourceURL,
212           const ::rtl::OUString & inDestinationURL,
213           const DAVRequestEnvironment & rEnv,
214           sal_Bool inOverWrite )
215         throw ( DAVException );
216 
217     virtual void
218     MOVE( const ::rtl::OUString & inSourceURL,
219           const ::rtl::OUString & inDestinationURL,
220           const DAVRequestEnvironment & rEnv,
221           sal_Bool inOverWrite )
222         throw ( DAVException );
223 
224     virtual void DESTROY( const ::rtl::OUString & inPath,
225                           const DAVRequestEnvironment & rEnv )
226         throw ( DAVException );
227 
228     // set new lock.
229     virtual void LOCK( const ::rtl::OUString & inURL,
230                        com::sun::star::ucb::Lock & inLock,
231                        const DAVRequestEnvironment & rEnv )
232         throw ( DAVException );
233 
234     // refresh existing lock.
235     virtual sal_Int64 LOCK( const ::rtl::OUString & inURL,
236                             sal_Int64 nTimeout,
237                             const DAVRequestEnvironment & rEnv )
238         throw ( DAVException );
239 
240     virtual void UNLOCK( const ::rtl::OUString & inURL,
241                          const DAVRequestEnvironment & rEnv )
242         throw ( DAVException );
243 
244     // helpers
245     virtual void abort()
246         throw ( DAVException );
247 
248     const rtl::OUString & getHostName() const { return m_aUri.GetHost(); }
249     int getPort() const { return m_aUri.GetPort(); }
250 
251     const ::uno::Reference< ::lang::XMultiServiceFactory > getMSF()
252     { return m_xFactory->getServiceFactory(); }
253 
254     sal_Bool isDomainMatch( rtl::OUString certHostName );
255 
256 private:
257     friend class SerfLockStore;
258 
259     void Init( void )
260         throw ( DAVException );
261 
262     void Init( const DAVRequestEnvironment & rEnv )
263         throw ( DAVException );
264 
265     void HandleError( SerfRequestProcessor& rReqProc,
266                       const rtl::OUString & inPath,
267                       const DAVRequestEnvironment & rEnv )
268         throw ( DAVException );
269 
270     const ucbhelper::InternetProxyServer & getProxySettings() const;
271 
272     bool removeExpiredLocktoken( const rtl::OUString & inURL,
273                                  const DAVRequestEnvironment & rEnv );
274 
275     // refresh lock, called by SerfLockStore::refreshLocks
276     bool LOCK( SerfLock * pLock,
277                sal_Int32 & rlastChanceToSendRefreshRequest );
278 
279     // unlock, called by SerfLockStore::~SerfLockStore
280     bool UNLOCK( SerfLock * pLock );
281 
282     /*
283     // low level GET implementation, used by public GET implementations
284     static int GET( SerfConnection * sess,
285                     const char * uri,
286                     //ne_block_reader reader,
287                     bool getheaders,
288                     void * userdata );
289 
290     // Buffer-based PUT implementation. Serf only has file descriptor-
291     // based API.
292     static int PUT( SerfConnection * sess,
293                     const char * uri,
294                     const char * buffer,
295                     size_t size );
296 
297     // Buffer-based POST implementation. Serf only has file descriptor-
298     // based API.
299     int POST( SerfConnection * sess,
300               const char * uri,
301               const char * buffer,
302               //ne_block_reader reader,
303               void * userdata,
304               const rtl::OUString & rContentType,
305               const rtl::OUString & rReferer );
306     */
307 
308     // Helper: XInputStream -> Sequence< sal_Int8 >
309     static bool getDataFromInputStream(
310         const com::sun::star::uno::Reference<
311             com::sun::star::io::XInputStream > & xStream,
312         com::sun::star::uno::Sequence< sal_Int8 > & rData,
313         bool bAppendTrailingZeroByte );
314 
315     /*
316     rtl::OUString makeAbsoluteURL( rtl::OUString const & rURL ) const;
317     */
318 };
319 
320 } // namespace http_dav_ucp
321 
322 #endif // INCLUDED_SERFSESSION_HXX
323