1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_NEONSESSION_HXX
30 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_NEONSESSION_HXX
32 #include <config_lgpl.h>
34 #include <osl/mutex.hxx>
35 #include "DAVSession.hxx"
36 #include "NeonTypes.hxx"
37 #include "NeonLockStore.hxx"
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 namespace ucbhelper
{ class ProxyDecider
; }
45 // A DAVSession implementation using the neon/expat library
46 class NeonSession
: public DAVSession
52 OUString m_aProxyName
;
54 sal_Int32 m_nProxyPort
;
55 css::uno::Sequence
< css::beans::NamedValue
> const m_aFlags
;
56 HttpSession
* m_pHttpSession
;
57 bool m_bNeedNewSession
= false; // Something happened that could invalidate m_pHttpSession
58 void * const m_pRequestData
;
59 const ucbhelper::InternetProxyDecider
& m_rProxyDecider
;
61 // @@@ This should really be per-request data. But Neon currently
62 // (0.23.5) has no interface for passing per-request user data.
63 // Theoretically, a NeonSession instance could handle multiple requests
64 // at a time --currently it doesn't. Thus this is not an issue at the
66 DAVRequestEnvironment m_aEnv
;
68 static bool m_bGlobalsInited
;
69 static NeonLockStore m_aNeonLockStore
;
72 virtual ~NeonSession() override
;
75 /// @throws std::exception
76 NeonSession( const rtl::Reference
< DAVSessionFactory
> & rSessionFactory
,
77 const OUString
& inUri
,
78 const css::uno::Sequence
< css::beans::NamedValue
>& rFlags
,
79 const ucbhelper::InternetProxyDecider
& rProxyDecider
);
82 virtual bool CanUse( const OUString
& inPath
,
83 const css::uno::Sequence
< css::beans::NamedValue
>& rFlags
) override
;
85 virtual bool UsesProxy() override
;
87 const DAVRequestEnvironment
& getRequestEnvironment() const
91 OPTIONS( const OUString
& inPath
,
92 DAVOptions
& rOptions
, // contains the name+values
93 const DAVRequestEnvironment
& rEnv
) override
;
97 PROPFIND( const OUString
& inPath
,
99 const std::vector
< OUString
> & inPropNames
,
100 std::vector
< DAVResource
> & ioResources
,
101 const DAVRequestEnvironment
& rEnv
) override
;
105 PROPFIND( const OUString
& inPath
,
107 std::vector
< DAVResourceInfo
>& ioResInfo
,
108 const DAVRequestEnvironment
& rEnv
) override
;
111 PROPPATCH( const OUString
& inPath
,
112 const std::vector
< ProppatchValue
> & inValues
,
113 const DAVRequestEnvironment
& rEnv
) override
;
116 HEAD( const OUString
& inPath
,
117 const std::vector
< OUString
> & inHeaderNames
,
118 DAVResource
& ioResource
,
119 const DAVRequestEnvironment
& rEnv
) override
;
121 virtual css::uno::Reference
< css::io::XInputStream
>
122 GET( const OUString
& inPath
,
123 const DAVRequestEnvironment
& rEnv
) override
;
126 GET( const OUString
& inPath
,
127 css::uno::Reference
< css::io::XOutputStream
> & ioOutputStream
,
128 const DAVRequestEnvironment
& rEnv
) override
;
130 virtual css::uno::Reference
< css::io::XInputStream
>
131 GET( const OUString
& inPath
,
132 const std::vector
< OUString
> & inHeaderNames
,
133 DAVResource
& ioResource
,
134 const DAVRequestEnvironment
& rEnv
) override
;
137 GET0( const OUString
& inPath
,
138 const std::vector
< OUString
> & inHeaderNames
,
139 DAVResource
& ioResource
,
140 const DAVRequestEnvironment
& rEnv
) override
;
143 GET( const OUString
& inPath
,
144 css::uno::Reference
< css::io::XOutputStream
> & ioOutputStream
,
145 const std::vector
< OUString
> & inHeaderNames
,
146 DAVResource
& ioResource
,
147 const DAVRequestEnvironment
& rEnv
) override
;
150 PUT( const OUString
& inPath
,
151 const css::uno::Reference
< css::io::XInputStream
> & inInputStream
,
152 const DAVRequestEnvironment
& rEnv
) override
;
154 virtual css::uno::Reference
< css::io::XInputStream
>
155 POST( const OUString
& inPath
,
156 const OUString
& rContentType
,
157 const OUString
& rReferer
,
158 const css::uno::Reference
< css::io::XInputStream
> & inInputStream
,
159 const DAVRequestEnvironment
& rEnv
) override
;
162 POST( const OUString
& inPath
,
163 const OUString
& rContentType
,
164 const OUString
& rReferer
,
165 const css::uno::Reference
< css::io::XInputStream
> & inInputStream
,
166 css::uno::Reference
< css::io::XOutputStream
> & oOutputStream
,
167 const DAVRequestEnvironment
& rEnv
) override
;
170 MKCOL( const OUString
& inPath
,
171 const DAVRequestEnvironment
& rEnv
) override
;
174 COPY( const OUString
& inSourceURL
,
175 const OUString
& inDestinationURL
,
176 const DAVRequestEnvironment
& rEnv
,
177 bool inOverWrite
) override
;
180 MOVE( const OUString
& inSourceURL
,
181 const OUString
& inDestinationURL
,
182 const DAVRequestEnvironment
& rEnv
,
183 bool inOverWrite
) override
;
185 virtual void DESTROY( const OUString
& inPath
,
186 const DAVRequestEnvironment
& rEnv
) override
;
189 virtual void LOCK( const OUString
& inURL
,
190 css::ucb::Lock
& inLock
,
191 const DAVRequestEnvironment
& rEnv
) override
;
193 virtual void UNLOCK( const OUString
& inURL
,
194 const DAVRequestEnvironment
& rEnv
) override
;
197 virtual void abort() override
;
199 const OUString
& getHostName() const { return m_aHostName
; }
201 ::uno::Reference
< ::uno::XComponentContext
> const & getComponentContext() const
202 { return m_xFactory
->getComponentContext(); }
204 const void * getRequestData() const { return m_pRequestData
; }
206 bool isDomainMatch( const OUString
& certHostName
);
208 int CertificationNotify(const ne_ssl_certificate
*cert
);
210 int NeonAuth(const char* inAuthProtocol
, const char* inRealm
,
211 int attempt
, char* inoutUserName
, char * inoutPassWord
);
213 void PreSendRequest(ne_request
* req
, ne_buffer
* headers
);
216 friend class NeonLockStore
;
218 /// @throws css::uno::RuntimeException
221 /// @throws css::uno::RuntimeException
222 void Init( const DAVRequestEnvironment
& rEnv
);
224 // ret: true => retry request.
225 /// @throws std::exception
226 void HandleError( int nError
,
227 const OUString
& inPath
,
228 const DAVRequestEnvironment
& rEnv
);
230 ucbhelper::InternetProxyServer
getProxySettings() const;
232 bool removeExpiredLocktoken( const OUString
& inURL
,
233 const DAVRequestEnvironment
& rEnv
);
235 // refresh lock, called by NeonLockStore::refreshLocks
236 bool LOCK( NeonLock
* pLock
,
237 sal_Int32
& rlastChanceToSendRefreshRequest
);
239 // unlock, called by NeonLockStore::~NeonLockStore
240 bool UNLOCK( NeonLock
* pLock
);
242 // low level GET implementation, used by public GET implementations
243 static int GET( ne_session
* sess
,
245 ne_block_reader reader
,
249 // low level GET implementation, used by public GET implementations
250 // used as a HEAD substitute when head is not available
251 static int GET0( ne_session
* sess
,
256 // Buffer-based PUT implementation. Neon only has file descriptor-
258 static int PUT( ne_session
* sess
,
263 // Buffer-based POST implementation. Neon only has file descriptor-
265 int POST( ne_session
* sess
,
268 ne_block_reader reader
,
270 const OUString
& rContentType
,
271 const OUString
& rReferer
);
273 // Helper: XInputStream -> Sequence< sal_Int8 >
274 static bool getDataFromInputStream(
275 const css::uno::Reference
< css::io::XInputStream
> & xStream
,
276 css::uno::Sequence
< sal_Int8
> & rData
,
277 bool bAppendTrailingZeroByte
);
279 OUString
makeAbsoluteURL( OUString
const & rURL
) const;
282 osl::Mutex
& getGlobalNeonMutex();
284 } // namespace webdav_ucp
286 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_NEONSESSION_HXX
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */