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 verifySerfCertificateChain ( 98 int nFailures, 99 const char** pCertificateChainBase64Encoded, 100 int nCertificateChainLength); 101 102 serf_bucket_t* acceptSerfResponse( serf_request_t * inSerfRequest, 103 serf_bucket_t * inSerfStreamBucket, 104 apr_pool_t* inAprPool ); 105 106 // Serf-related data structures 107 apr_pool_t* getAprPool(); 108 serf_bucket_alloc_t* getSerfBktAlloc(); 109 serf_context_t* getSerfContext(); 110 SerfConnection* getSerfConnection(); 111 112 // DAVSession methods 113 virtual sal_Bool CanUse( const ::rtl::OUString & inUri ); 114 115 virtual sal_Bool UsesProxy(); 116 117 const DAVRequestEnvironment & getRequestEnvironment() const 118 { return m_aEnv; } 119 120 // allprop & named 121 virtual void 122 PROPFIND( const ::rtl::OUString & inPath, 123 const Depth inDepth, 124 const std::vector< ::rtl::OUString > & inPropNames, 125 std::vector< DAVResource > & ioResources, 126 const DAVRequestEnvironment & rEnv ) 127 throw ( DAVException ); 128 129 // propnames 130 virtual void 131 PROPFIND( const ::rtl::OUString & inPath, 132 const Depth inDepth, 133 std::vector< DAVResourceInfo >& ioResInfo, 134 const DAVRequestEnvironment & rEnv ) 135 throw ( DAVException ); 136 137 virtual void 138 PROPPATCH( const ::rtl::OUString & inPath, 139 const std::vector< ProppatchValue > & inValues, 140 const DAVRequestEnvironment & rEnv ) 141 throw ( DAVException ); 142 143 virtual void 144 HEAD( const ::rtl::OUString & inPath, 145 const std::vector< ::rtl::OUString > & inHeaderNames, 146 DAVResource & ioResource, 147 const DAVRequestEnvironment & rEnv ) 148 throw ( DAVException ); 149 150 bool isHeadRequestInProgress(); 151 152 virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > 153 GET( const ::rtl::OUString & inPath, 154 const DAVRequestEnvironment & rEnv ) 155 throw ( DAVException ); 156 157 virtual void 158 GET( const ::rtl::OUString & inPath, 159 com::sun::star::uno::Reference< 160 com::sun::star::io::XOutputStream > & ioOutputStream, 161 const DAVRequestEnvironment & rEnv ) 162 throw ( DAVException ); 163 164 virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > 165 GET( const ::rtl::OUString & inPath, 166 const std::vector< ::rtl::OUString > & inHeaderNames, 167 DAVResource & ioResource, 168 const DAVRequestEnvironment & rEnv ) 169 throw ( DAVException ); 170 171 virtual void 172 GET( const ::rtl::OUString & inPath, 173 com::sun::star::uno::Reference< 174 com::sun::star::io::XOutputStream > & ioOutputStream, 175 const std::vector< ::rtl::OUString > & inHeaderNames, 176 DAVResource & ioResource, 177 const DAVRequestEnvironment & rEnv ) 178 throw ( DAVException ); 179 180 virtual void 181 PUT( const ::rtl::OUString & inPath, 182 const com::sun::star::uno::Reference< 183 com::sun::star::io::XInputStream > & inInputStream, 184 const DAVRequestEnvironment & rEnv ) 185 throw ( DAVException ); 186 187 virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > 188 POST( const rtl::OUString & inPath, 189 const rtl::OUString & rContentType, 190 const rtl::OUString & rReferer, 191 const com::sun::star::uno::Reference< 192 com::sun::star::io::XInputStream > & inInputStream, 193 const DAVRequestEnvironment & rEnv ) 194 throw ( DAVException ); 195 196 virtual void 197 POST( const rtl::OUString & inPath, 198 const rtl::OUString & rContentType, 199 const rtl::OUString & rReferer, 200 const com::sun::star::uno::Reference< 201 com::sun::star::io::XInputStream > & inInputStream, 202 com::sun::star::uno::Reference< 203 com::sun::star::io::XOutputStream > & oOutputStream, 204 const DAVRequestEnvironment & rEnv ) 205 throw ( DAVException ); 206 207 virtual void 208 MKCOL( const ::rtl::OUString & inPath, 209 const DAVRequestEnvironment & rEnv ) 210 throw ( DAVException ); 211 212 virtual void 213 COPY( const ::rtl::OUString & inSourceURL, 214 const ::rtl::OUString & inDestinationURL, 215 const DAVRequestEnvironment & rEnv, 216 sal_Bool inOverWrite ) 217 throw ( DAVException ); 218 219 virtual void 220 MOVE( const ::rtl::OUString & inSourceURL, 221 const ::rtl::OUString & inDestinationURL, 222 const DAVRequestEnvironment & rEnv, 223 sal_Bool inOverWrite ) 224 throw ( DAVException ); 225 226 virtual void DESTROY( const ::rtl::OUString & inPath, 227 const DAVRequestEnvironment & rEnv ) 228 throw ( DAVException ); 229 230 // set new lock. 231 virtual void LOCK( const ::rtl::OUString & inURL, 232 com::sun::star::ucb::Lock & inLock, 233 const DAVRequestEnvironment & rEnv ) 234 throw ( DAVException ); 235 236 // refresh existing lock. 237 virtual sal_Int64 LOCK( const ::rtl::OUString & inURL, 238 sal_Int64 nTimeout, 239 const DAVRequestEnvironment & rEnv ) 240 throw ( DAVException ); 241 242 virtual void UNLOCK( const ::rtl::OUString & inURL, 243 const DAVRequestEnvironment & rEnv ) 244 throw ( DAVException ); 245 246 // helpers 247 virtual void abort() 248 throw ( DAVException ); 249 250 const rtl::OUString & getHostName() const { return m_aUri.GetHost(); } 251 int getPort() const { return m_aUri.GetPort(); } 252 253 const ::uno::Reference< ::lang::XMultiServiceFactory > getMSF() 254 { return m_xFactory->getServiceFactory(); } 255 256 sal_Bool isDomainMatch( rtl::OUString certHostName ); 257 258 private: 259 friend class SerfLockStore; 260 261 void Init( void ) 262 throw ( DAVException ); 263 264 void Init( const DAVRequestEnvironment & rEnv ) 265 throw ( DAVException ); 266 267 void HandleError( SerfRequestProcessor& rReqProc, 268 const rtl::OUString & inPath, 269 const DAVRequestEnvironment & rEnv ) 270 throw ( DAVException ); 271 272 const ucbhelper::InternetProxyServer & getProxySettings() const; 273 274 bool removeExpiredLocktoken( const rtl::OUString & inURL, 275 const DAVRequestEnvironment & rEnv ); 276 277 // refresh lock, called by SerfLockStore::refreshLocks 278 bool LOCK( SerfLock * pLock, 279 sal_Int32 & rlastChanceToSendRefreshRequest ); 280 281 // unlock, called by SerfLockStore::~SerfLockStore 282 bool UNLOCK( SerfLock * pLock ); 283 284 /* 285 // low level GET implementation, used by public GET implementations 286 static int GET( SerfConnection * sess, 287 const char * uri, 288 //ne_block_reader reader, 289 bool getheaders, 290 void * userdata ); 291 292 // Buffer-based PUT implementation. Serf only has file descriptor- 293 // based API. 294 static int PUT( SerfConnection * sess, 295 const char * uri, 296 const char * buffer, 297 size_t size ); 298 299 // Buffer-based POST implementation. Serf only has file descriptor- 300 // based API. 301 int POST( SerfConnection * sess, 302 const char * uri, 303 const char * buffer, 304 //ne_block_reader reader, 305 void * userdata, 306 const rtl::OUString & rContentType, 307 const rtl::OUString & rReferer ); 308 */ 309 310 // Helper: XInputStream -> Sequence< sal_Int8 > 311 static bool getDataFromInputStream( 312 const com::sun::star::uno::Reference< 313 com::sun::star::io::XInputStream > & xStream, 314 com::sun::star::uno::Sequence< sal_Int8 > & rData, 315 bool bAppendTrailingZeroByte ); 316 317 /* 318 rtl::OUString makeAbsoluteURL( rtl::OUString const & rURL ) const; 319 */ 320 }; 321 322 } // namespace http_dav_ucp 323 324 #endif // INCLUDED_SERFSESSION_HXX 325