Branch data Line data Source code
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 : :
30 : : #include "osl/diagnose.h"
31 : :
32 : : #include "com/sun/star/task/XInteractionAbort.hpp"
33 : : #include "com/sun/star/ucb/XWebDAVCommandEnvironment.hpp"
34 : :
35 : : #include "ucbhelper/simpleauthenticationrequest.hxx"
36 : : #include "comphelper/seekableinput.hxx"
37 : :
38 : : #include "DAVAuthListenerImpl.hxx"
39 : : #include "DAVResourceAccess.hxx"
40 : :
41 : : using namespace webdav_ucp;
42 : : using namespace com::sun::star;
43 : :
44 : : //=========================================================================
45 : : //=========================================================================
46 : : //
47 : : // DAVAuthListener_Impl Implementation.
48 : : //
49 : : //=========================================================================
50 : : //=========================================================================
51 : :
52 : : //=========================================================================
53 : : // virtual
54 : 0 : int DAVAuthListener_Impl::authenticate(
55 : : const ::rtl::OUString & inRealm,
56 : : const ::rtl::OUString & inHostName,
57 : : ::rtl::OUString & inoutUserName,
58 : : ::rtl::OUString & outPassWord,
59 : : sal_Bool bCanUseSystemCredentials )
60 : : {
61 [ # # ]: 0 : if ( m_xEnv.is() )
62 : : {
63 : : uno::Reference< task::XInteractionHandler > xIH
64 [ # # ][ # # ]: 0 : = m_xEnv->getInteractionHandler();
65 : :
66 [ # # ]: 0 : if ( xIH.is() )
67 : : {
68 : : // #102871# - Supply username and password from previous try.
69 : : // Password container service depends on this!
70 [ # # ]: 0 : if ( inoutUserName.isEmpty() )
71 : 0 : inoutUserName = m_aPrevUsername;
72 : :
73 [ # # ]: 0 : if ( outPassWord.isEmpty() )
74 : 0 : outPassWord = m_aPrevPassword;
75 : :
76 : : rtl::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest
77 : : = new ucbhelper::SimpleAuthenticationRequest(
78 : : m_aURL, inHostName, inRealm, inoutUserName,
79 : : outPassWord, ::rtl::OUString(),
80 : : true /*bAllowPersistentStoring*/,
81 [ # # ]: 0 : bCanUseSystemCredentials );
82 [ # # ][ # # ]: 0 : xIH->handle( xRequest.get() );
[ # # ][ # # ]
83 : :
84 : : rtl::Reference< ucbhelper::InteractionContinuation > xSelection
85 [ # # ]: 0 : = xRequest->getSelection();
86 : :
87 [ # # ]: 0 : if ( xSelection.is() )
88 : : {
89 : : // Handler handled the request.
90 : : uno::Reference< task::XInteractionAbort > xAbort(
91 [ # # ]: 0 : xSelection.get(), uno::UNO_QUERY );
92 [ # # ]: 0 : if ( !xAbort.is() )
93 : : {
94 : : const rtl::Reference<
95 : : ucbhelper::InteractionSupplyAuthentication > & xSupp
96 : 0 : = xRequest->getAuthenticationSupplier();
97 : :
98 : 0 : sal_Bool bUseSystemCredentials = sal_False;
99 : :
100 [ # # ]: 0 : if ( bCanUseSystemCredentials )
101 : : bUseSystemCredentials
102 : 0 : = xSupp->getUseSystemCredentials();
103 : :
104 [ # # ]: 0 : if ( bUseSystemCredentials )
105 : : {
106 : : // This is the (strange) way to tell neon to use
107 : : // system credentials.
108 : 0 : inoutUserName = rtl::OUString();
109 : 0 : outPassWord = rtl::OUString();
110 : : }
111 : : else
112 : : {
113 : 0 : inoutUserName = xSupp->getUserName();
114 : 0 : outPassWord = xSupp->getPassword();
115 : : }
116 : :
117 : : // #102871# - Remember username and password.
118 : 0 : m_aPrevUsername = inoutUserName;
119 : 0 : m_aPrevPassword = outPassWord;
120 : :
121 : : // go on.
122 : 0 : return 0;
123 [ # # ]: 0 : }
124 [ # # ][ # # ]: 0 : }
125 [ # # ]: 0 : }
126 : : }
127 : : // Abort.
128 : 0 : return -1;
129 : : }
130 : :
131 : : //=========================================================================
132 : : //=========================================================================
133 : : //
134 : : // DAVResourceAccess Implementation.
135 : : //
136 : : //=========================================================================
137 : : //=========================================================================
138 : :
139 : : //=========================================================================
140 : 2 : DAVResourceAccess::DAVResourceAccess(
141 : : const uno::Reference< lang::XMultiServiceFactory > & rSMgr,
142 : : rtl::Reference< DAVSessionFactory > const & rSessionFactory,
143 : : const rtl::OUString & rURL )
144 : : : m_aURL( rURL ),
145 : : m_xSessionFactory( rSessionFactory ),
146 [ + - ][ + - ]: 2 : m_xSMgr( rSMgr )
[ + - ]
147 : : {
148 : 2 : }
149 : :
150 : : //=========================================================================
151 : 0 : DAVResourceAccess::DAVResourceAccess( const DAVResourceAccess & rOther )
152 : : : m_aURL( rOther.m_aURL ),
153 : : m_aPath( rOther.m_aPath ),
154 : : m_aFlags( rOther.m_aFlags ),
155 : : m_xSession( rOther.m_xSession ),
156 : : m_xSessionFactory( rOther.m_xSessionFactory ),
157 : : m_xSMgr( rOther.m_xSMgr ),
158 [ # # ][ # # ]: 0 : m_aRedirectURIs( rOther.m_aRedirectURIs )
[ # # ][ # # ]
159 : : {
160 : 0 : }
161 : :
162 : : //=========================================================================
163 : 0 : DAVResourceAccess & DAVResourceAccess::operator=(
164 : : const DAVResourceAccess & rOther )
165 : : {
166 : 0 : m_aURL = rOther.m_aURL;
167 : 0 : m_aPath = rOther.m_aPath;
168 : 0 : m_aFlags = rOther.m_aFlags;
169 : 0 : m_xSession = rOther.m_xSession;
170 : 0 : m_xSessionFactory = rOther.m_xSessionFactory;
171 : 0 : m_xSMgr = rOther.m_xSMgr;
172 : 0 : m_aRedirectURIs = rOther.m_aRedirectURIs;
173 : :
174 : 0 : return *this;
175 : : }
176 : :
177 : : #if 0 // currently not used, but please don't remove code
178 : : //=========================================================================
179 : : void DAVResourceAccess::OPTIONS(
180 : : DAVCapabilities & rCapabilities,
181 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
182 : : throw( DAVException )
183 : : {
184 : : initialize();
185 : :
186 : : bool bRetry;
187 : : int errorCount = 0;
188 : : do
189 : : {
190 : : bRetry = false;
191 : : try
192 : : {
193 : : DAVRequestHeaders aHeaders;
194 : : getUserRequestHeaders( xEnv,
195 : : getRequestURI(),
196 : : rtl::OUString( "OPTIONS" ),
197 : : aHeaders );
198 : :
199 : : m_xSession->OPTIONS( getRequestURI(),
200 : : rCapabilities,
201 : : DAVRequestEnvironment(
202 : : getRequestURI(),
203 : : new DAVAuthListener_Impl( xEnv, m_aURL ),
204 : : aHeaders, xEnv) );
205 : : }
206 : : catch ( const DAVException & e )
207 : : {
208 : : errorCount++;
209 : : bRetry = handleException( e, errorCount );
210 : : if ( !bRetry )
211 : : throw;
212 : : }
213 : : }
214 : : while ( bRetry );
215 : : }
216 : : #endif
217 : :
218 : : //=========================================================================
219 : 0 : void DAVResourceAccess::PROPFIND(
220 : : const Depth nDepth,
221 : : const std::vector< rtl::OUString > & rPropertyNames,
222 : : std::vector< DAVResource > & rResources,
223 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
224 : : throw( DAVException )
225 : : {
226 : 0 : initialize();
227 : :
228 : 0 : int errorCount = 0;
229 : : bool bRetry;
230 [ # # ]: 0 : do
231 : : {
232 : 0 : bRetry = false;
233 : : try
234 : : {
235 [ # # ]: 0 : DAVRequestHeaders aHeaders;
236 : :
237 : : getUserRequestHeaders( xEnv,
238 [ # # ]: 0 : getRequestURI(),
239 : : rtl::OUString( "PROPFIND" ),
240 [ # # ]: 0 : aHeaders );
241 : :
242 [ # # ]: 0 : m_xSession->PROPFIND( getRequestURI(),
243 : : nDepth,
244 : : rPropertyNames,
245 : : rResources,
246 : : DAVRequestEnvironment(
247 [ # # ]: 0 : getRequestURI(),
248 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
249 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
250 : : }
251 [ # # ]: 0 : catch ( const DAVException & e )
252 : : {
253 : 0 : errorCount++;
254 [ # # ]: 0 : bRetry = handleException( e, errorCount );
255 [ # # ]: 0 : if ( !bRetry )
256 : 0 : throw;
257 : : }
258 : : }
259 : : while ( bRetry );
260 : 0 : }
261 : :
262 : : //=========================================================================
263 : 0 : void DAVResourceAccess::PROPFIND(
264 : : const Depth nDepth,
265 : : std::vector< DAVResourceInfo > & rResInfo,
266 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
267 : : throw( DAVException )
268 : : {
269 : 0 : initialize();
270 : :
271 : 0 : int errorCount = 0;
272 : : bool bRetry;
273 [ # # ]: 0 : do
274 : : {
275 : 0 : bRetry = false;
276 : : try
277 : : {
278 [ # # ]: 0 : DAVRequestHeaders aHeaders;
279 : : getUserRequestHeaders( xEnv,
280 [ # # ]: 0 : getRequestURI(),
281 : : rtl::OUString( "PROPFIND" ),
282 [ # # ]: 0 : aHeaders );
283 : :
284 [ # # ]: 0 : m_xSession->PROPFIND( getRequestURI(),
285 : : nDepth,
286 : : rResInfo,
287 : : DAVRequestEnvironment(
288 [ # # ]: 0 : getRequestURI(),
289 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
290 [ # # ][ # # ]: 0 : aHeaders, xEnv ) ) ;
[ # # ][ # # ]
[ # # ][ # # ]
291 : : }
292 [ # # ]: 0 : catch ( const DAVException & e )
293 : : {
294 : 0 : errorCount++;
295 [ # # ]: 0 : bRetry = handleException( e, errorCount );
296 [ # # ]: 0 : if ( !bRetry )
297 : 0 : throw;
298 : : }
299 : : }
300 : : while ( bRetry );
301 : 0 : }
302 : :
303 : : //=========================================================================
304 : 0 : void DAVResourceAccess::PROPPATCH(
305 : : const std::vector< ProppatchValue >& rValues,
306 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
307 : : throw( DAVException )
308 : : {
309 : 0 : initialize();
310 : :
311 : 0 : int errorCount = 0;
312 : : bool bRetry;
313 [ # # ]: 0 : do
314 : : {
315 : 0 : bRetry = false;
316 : : try
317 : : {
318 [ # # ]: 0 : DAVRequestHeaders aHeaders;
319 : : getUserRequestHeaders( xEnv,
320 [ # # ]: 0 : getRequestURI(),
321 : : rtl::OUString( "PROPPATCH" ),
322 [ # # ]: 0 : aHeaders );
323 : :
324 [ # # ]: 0 : m_xSession->PROPPATCH( getRequestURI(),
325 : : rValues,
326 : : DAVRequestEnvironment(
327 [ # # ]: 0 : getRequestURI(),
328 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
329 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
330 : : }
331 [ # # ]: 0 : catch ( const DAVException & e )
332 : : {
333 : 0 : errorCount++;
334 [ # # ]: 0 : bRetry = handleException( e, errorCount );
335 [ # # ]: 0 : if ( !bRetry )
336 : 0 : throw;
337 : : }
338 : : }
339 : : while ( bRetry );
340 : 0 : }
341 : :
342 : : //=========================================================================
343 : 0 : void DAVResourceAccess::HEAD(
344 : : const std::vector< rtl::OUString > & rHeaderNames,
345 : : DAVResource & rResource,
346 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
347 : : throw( DAVException )
348 : : {
349 : 0 : initialize();
350 : :
351 : 0 : int errorCount = 0;
352 : : bool bRetry;
353 [ # # ]: 0 : do
354 : : {
355 : 0 : bRetry = false;
356 : : try
357 : : {
358 [ # # ]: 0 : DAVRequestHeaders aHeaders;
359 : : getUserRequestHeaders( xEnv,
360 [ # # ]: 0 : getRequestURI(),
361 : : rtl::OUString("HEAD"),
362 [ # # ]: 0 : aHeaders );
363 : :
364 [ # # ]: 0 : m_xSession->HEAD( getRequestURI(),
365 : : rHeaderNames,
366 : : rResource,
367 : : DAVRequestEnvironment(
368 [ # # ]: 0 : getRequestURI(),
369 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
370 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
371 : : }
372 [ # # ]: 0 : catch ( const DAVException & e )
373 : : {
374 : 0 : errorCount++;
375 [ # # ]: 0 : bRetry = handleException( e, errorCount );
376 [ # # ]: 0 : if ( !bRetry )
377 : 0 : throw;
378 : : }
379 : : }
380 : : while ( bRetry );
381 : 0 : }
382 : :
383 : : //=========================================================================
384 : 0 : uno::Reference< io::XInputStream > DAVResourceAccess::GET(
385 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
386 : : throw( DAVException )
387 : : {
388 : 0 : initialize();
389 : :
390 : 0 : uno::Reference< io::XInputStream > xStream;
391 : 0 : int errorCount = 0;
392 : : bool bRetry;
393 [ # # ]: 0 : do
394 : : {
395 : 0 : bRetry = false;
396 : : try
397 : : {
398 [ # # ]: 0 : DAVRequestHeaders aHeaders;
399 : : getUserRequestHeaders( xEnv,
400 [ # # ]: 0 : getRequestURI(),
401 : : rtl::OUString("GET"),
402 [ # # ]: 0 : aHeaders );
403 : :
404 [ # # ]: 0 : xStream = m_xSession->GET( getRequestURI(),
405 : : DAVRequestEnvironment(
406 [ # # ]: 0 : getRequestURI(),
407 : : new DAVAuthListener_Impl(
408 [ # # ]: 0 : xEnv, m_aURL ),
409 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
410 : : }
411 [ # # ]: 0 : catch ( const DAVException & e )
412 : : {
413 : 0 : errorCount++;
414 [ # # ]: 0 : bRetry = handleException( e, errorCount );
415 [ # # ]: 0 : if ( !bRetry )
416 : 0 : throw;
417 : : }
418 : : }
419 : : while ( bRetry );
420 : :
421 : 0 : return xStream;
422 : : }
423 : :
424 : : //=========================================================================
425 : 0 : void DAVResourceAccess::GET(
426 : : uno::Reference< io::XOutputStream > & rStream,
427 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
428 : : throw( DAVException )
429 : : {
430 : 0 : initialize();
431 : :
432 : 0 : int errorCount = 0;
433 : : bool bRetry;
434 [ # # ]: 0 : do
435 : : {
436 : 0 : bRetry = false;
437 : : try
438 : : {
439 [ # # ]: 0 : DAVRequestHeaders aHeaders;
440 : : getUserRequestHeaders( xEnv,
441 [ # # ]: 0 : getRequestURI(),
442 : : rtl::OUString("GET"),
443 [ # # ]: 0 : aHeaders );
444 : :
445 [ # # ]: 0 : m_xSession->GET( getRequestURI(),
446 : : rStream,
447 : : DAVRequestEnvironment(
448 [ # # ]: 0 : getRequestURI(),
449 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
450 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
451 : : }
452 [ # # ]: 0 : catch ( const DAVException & e )
453 : : {
454 : 0 : errorCount++;
455 [ # # ]: 0 : bRetry = handleException( e, errorCount );
456 [ # # ]: 0 : if ( !bRetry )
457 : 0 : throw;
458 : : }
459 : : }
460 : : while ( bRetry );
461 : 0 : }
462 : :
463 : : //=========================================================================
464 : 0 : uno::Reference< io::XInputStream > DAVResourceAccess::GET(
465 : : const std::vector< rtl::OUString > & rHeaderNames,
466 : : DAVResource & rResource,
467 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
468 : : throw( DAVException )
469 : : {
470 : 0 : initialize();
471 : :
472 : 0 : uno::Reference< io::XInputStream > xStream;
473 : 0 : int errorCount = 0;
474 : : bool bRetry;
475 [ # # ]: 0 : do
476 : : {
477 : 0 : bRetry = false;
478 : : try
479 : : {
480 [ # # ]: 0 : DAVRequestHeaders aHeaders;
481 : : getUserRequestHeaders( xEnv,
482 [ # # ]: 0 : getRequestURI(),
483 : : rtl::OUString("GET"),
484 [ # # ]: 0 : aHeaders );
485 : :
486 [ # # ]: 0 : xStream = m_xSession->GET( getRequestURI(),
487 : : rHeaderNames,
488 : : rResource,
489 : : DAVRequestEnvironment(
490 [ # # ]: 0 : getRequestURI(),
491 : : new DAVAuthListener_Impl(
492 [ # # ]: 0 : xEnv, m_aURL ),
493 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
494 : : }
495 [ # # ]: 0 : catch ( const DAVException & e )
496 : : {
497 : 0 : errorCount++;
498 [ # # ]: 0 : bRetry = handleException( e, errorCount );
499 [ # # ]: 0 : if ( !bRetry )
500 : 0 : throw;
501 : : }
502 : : }
503 : : while ( bRetry );
504 : :
505 : 0 : return xStream;
506 : : }
507 : :
508 : : //=========================================================================
509 : 0 : void DAVResourceAccess::GET(
510 : : uno::Reference< io::XOutputStream > & rStream,
511 : : const std::vector< rtl::OUString > & rHeaderNames,
512 : : DAVResource & rResource,
513 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
514 : : throw( DAVException )
515 : : {
516 : 0 : initialize();
517 : :
518 : : bool bRetry;
519 : 0 : int errorCount = 0;
520 [ # # ]: 0 : do
521 : : {
522 : 0 : bRetry = false;
523 : : try
524 : : {
525 [ # # ]: 0 : DAVRequestHeaders aHeaders;
526 : : getUserRequestHeaders( xEnv,
527 [ # # ]: 0 : getRequestURI(),
528 : : rtl::OUString("GET"),
529 [ # # ]: 0 : aHeaders );
530 : :
531 [ # # ]: 0 : m_xSession->GET( getRequestURI(),
532 : : rStream,
533 : : rHeaderNames,
534 : : rResource,
535 : : DAVRequestEnvironment(
536 [ # # ]: 0 : getRequestURI(),
537 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
538 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
539 : : }
540 [ # # ]: 0 : catch ( const DAVException & e )
541 : : {
542 : 0 : errorCount++;
543 [ # # ]: 0 : bRetry = handleException( e, errorCount );
544 [ # # ]: 0 : if ( !bRetry )
545 : 0 : throw;
546 : : }
547 : : }
548 : : while ( bRetry );
549 : 0 : }
550 : :
551 : : //=========================================================================
552 : 0 : void DAVResourceAccess::abort()
553 : : throw( DAVException )
554 : : {
555 : : // 17.11.09 (tkr): abort currently disabled caused by issue i106766
556 : : // initialize();
557 : : // m_xSession->abort();
558 : : OSL_TRACE( "Not implemented. -> #i106766#" );
559 : 0 : }
560 : :
561 : : //=========================================================================
562 : : namespace {
563 : :
564 : 0 : void resetInputStream( const uno::Reference< io::XInputStream > & rStream )
565 : : throw( DAVException )
566 : : {
567 : : try
568 : : {
569 : : uno::Reference< io::XSeekable > xSeekable(
570 [ # # ]: 0 : rStream, uno::UNO_QUERY );
571 [ # # ]: 0 : if ( xSeekable.is() )
572 : : {
573 [ # # ][ # # ]: 0 : xSeekable->seek( 0 );
574 : 0 : return;
575 [ # # ]: 0 : }
[ # # # ]
576 : : }
577 : 0 : catch ( lang::IllegalArgumentException const & )
578 : : {
579 : : }
580 : 0 : catch ( io::IOException const & )
581 : : {
582 : : }
583 : :
584 : 0 : throw DAVException( DAVException::DAV_INVALID_ARG );
585 : : }
586 : :
587 : : } // namespace
588 : :
589 : : //=========================================================================
590 : 0 : void DAVResourceAccess::PUT(
591 : : const uno::Reference< io::XInputStream > & rStream,
592 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
593 : : throw( DAVException )
594 : : {
595 [ # # ]: 0 : initialize();
596 : :
597 : : // Make stream seekable, if it not. Needed, if request must be retried.
598 : : uno::Reference< io::XInputStream > xSeekableStream
599 : : = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap(
600 [ # # ]: 0 : rStream, m_xSMgr );
601 : :
602 : 0 : int errorCount = 0;
603 : 0 : bool bRetry = false;
604 [ # # ]: 0 : do
605 : : {
606 [ # # ]: 0 : if ( bRetry )
607 [ # # ]: 0 : resetInputStream( xSeekableStream );
608 : :
609 : 0 : bRetry = false;
610 : : try
611 : : {
612 [ # # ]: 0 : DAVRequestHeaders aHeaders;
613 : : getUserRequestHeaders( xEnv,
614 [ # # ]: 0 : getRequestURI(),
615 : : rtl::OUString("PUT"),
616 [ # # ]: 0 : aHeaders );
617 : :
618 [ # # ]: 0 : m_xSession->PUT( getRequestURI(),
619 : : xSeekableStream,
620 : : DAVRequestEnvironment(
621 [ # # ]: 0 : getRequestURI(),
622 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
623 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
624 : : }
625 [ # # ]: 0 : catch ( const DAVException & e )
626 : : {
627 : 0 : errorCount++;
628 [ # # ]: 0 : bRetry = handleException( e, errorCount );
629 [ # # ]: 0 : if ( !bRetry )
630 : 0 : throw;
631 : : }
632 : : }
633 : 0 : while ( bRetry );
634 : 0 : }
635 : :
636 : : //=========================================================================
637 : 0 : uno::Reference< io::XInputStream > DAVResourceAccess::POST(
638 : : const rtl::OUString & rContentType,
639 : : const rtl::OUString & rReferer,
640 : : const uno::Reference< io::XInputStream > & rInputStream,
641 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
642 : : throw ( DAVException )
643 : : {
644 [ # # ]: 0 : initialize();
645 : :
646 : : // Make stream seekable, if it not. Needed, if request must be retried.
647 : : uno::Reference< io::XInputStream > xSeekableStream
648 : : = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap(
649 [ # # ]: 0 : rInputStream, m_xSMgr );
650 : :
651 : 0 : uno::Reference< io::XInputStream > xStream;
652 : 0 : int errorCount = 0;
653 : 0 : bool bRetry = false;
654 [ # # ]: 0 : do
655 : : {
656 [ # # ]: 0 : if ( bRetry )
657 : : {
658 [ # # ]: 0 : resetInputStream( xSeekableStream );
659 : 0 : bRetry = false;
660 : : }
661 : :
662 : : try
663 : : {
664 [ # # ]: 0 : DAVRequestHeaders aHeaders;
665 : : getUserRequestHeaders( xEnv,
666 [ # # ]: 0 : getRequestURI(),
667 : : rtl::OUString("POST"),
668 [ # # ]: 0 : aHeaders );
669 : :
670 [ # # ]: 0 : xStream = m_xSession->POST( getRequestURI(),
671 : : rContentType,
672 : : rReferer,
673 : : xSeekableStream,
674 : : DAVRequestEnvironment(
675 [ # # ]: 0 : getRequestURI(),
676 : : new DAVAuthListener_Impl(
677 [ # # ]: 0 : xEnv, m_aURL ),
678 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
679 : : }
680 [ # # # # ]: 0 : catch ( const DAVException & e )
681 : : {
682 : 0 : errorCount++;
683 [ # # ]: 0 : bRetry = handleException( e, errorCount );
684 [ # # ]: 0 : if ( !bRetry )
685 : 0 : throw;
686 : :
687 [ # # ]: 0 : if ( e.getError() == DAVException::DAV_HTTP_REDIRECT )
688 : : {
689 : : // #i74980# - Upon POST redirect, do a GET.
690 [ # # ]: 0 : return GET( xEnv );
691 : : }
692 : : }
693 : : }
694 : : while ( bRetry );
695 : :
696 : 0 : return xStream;
697 : : }
698 : :
699 : : //=========================================================================
700 : 0 : void DAVResourceAccess::POST(
701 : : const rtl::OUString & rContentType,
702 : : const rtl::OUString & rReferer,
703 : : const uno::Reference< io::XInputStream > & rInputStream,
704 : : uno::Reference< io::XOutputStream > & rOutputStream,
705 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
706 : : throw ( DAVException )
707 : : {
708 [ # # ]: 0 : initialize();
709 : :
710 : : // Make stream seekable, if it not. Needed, if request must be retried.
711 : : uno::Reference< io::XInputStream > xSeekableStream
712 : : = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap(
713 [ # # ]: 0 : rInputStream, m_xSMgr );
714 : :
715 : 0 : int errorCount = 0;
716 : 0 : bool bRetry = false;
717 [ # # ]: 0 : do
718 : : {
719 [ # # ]: 0 : if ( bRetry )
720 : : {
721 [ # # ]: 0 : resetInputStream( xSeekableStream );
722 : 0 : bRetry = false;
723 : : }
724 : :
725 : : try
726 : : {
727 [ # # ]: 0 : DAVRequestHeaders aHeaders;
728 : : getUserRequestHeaders( xEnv,
729 [ # # ]: 0 : getRequestURI(),
730 : : rtl::OUString("POST"),
731 [ # # ]: 0 : aHeaders );
732 : :
733 [ # # ]: 0 : m_xSession->POST( getRequestURI(),
734 : : rContentType,
735 : : rReferer,
736 : : xSeekableStream,
737 : : rOutputStream,
738 : : DAVRequestEnvironment(
739 [ # # ]: 0 : getRequestURI(),
740 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
741 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
742 : : }
743 [ # # # # ]: 0 : catch ( const DAVException & e )
744 : : {
745 : 0 : errorCount++;
746 [ # # ]: 0 : bRetry = handleException( e, errorCount );
747 [ # # ]: 0 : if ( !bRetry )
748 : 0 : throw;
749 : :
750 [ # # ]: 0 : if ( e.getError() == DAVException::DAV_HTTP_REDIRECT )
751 : : {
752 : : // #i74980# - Upon POST redirect, do a GET.
753 [ # # ]: 0 : GET( rOutputStream, xEnv );
754 : 0 : return;
755 : : }
756 : : }
757 : : }
758 [ # # ]: 0 : while ( bRetry );
759 : : }
760 : :
761 : : //=========================================================================
762 : 0 : void DAVResourceAccess::MKCOL(
763 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
764 : : throw( DAVException )
765 : : {
766 : 0 : initialize();
767 : :
768 : 0 : int errorCount = 0;
769 : : bool bRetry;
770 [ # # ]: 0 : do
771 : : {
772 : 0 : bRetry = false;
773 : : try
774 : : {
775 [ # # ]: 0 : DAVRequestHeaders aHeaders;
776 : : getUserRequestHeaders( xEnv,
777 [ # # ]: 0 : getRequestURI(),
778 : : rtl::OUString("MKCOL"),
779 [ # # ]: 0 : aHeaders );
780 : :
781 [ # # ]: 0 : m_xSession->MKCOL( getRequestURI(),
782 : : DAVRequestEnvironment(
783 [ # # ]: 0 : getRequestURI(),
784 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
785 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
786 : : }
787 [ # # ]: 0 : catch ( const DAVException & e )
788 : : {
789 : 0 : errorCount++;
790 [ # # ]: 0 : bRetry = handleException( e, errorCount );
791 [ # # ]: 0 : if ( !bRetry )
792 : 0 : throw;
793 : : }
794 : : }
795 : : while ( bRetry );
796 : 0 : }
797 : :
798 : : //=========================================================================
799 : 0 : void DAVResourceAccess::COPY(
800 : : const ::rtl::OUString & rSourcePath,
801 : : const ::rtl::OUString & rDestinationURI,
802 : : sal_Bool bOverwrite,
803 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
804 : : throw( DAVException )
805 : : {
806 : 0 : initialize();
807 : :
808 : 0 : int errorCount = 0;
809 : : bool bRetry;
810 [ # # ]: 0 : do
811 : : {
812 : 0 : bRetry = false;
813 : : try
814 : : {
815 [ # # ]: 0 : DAVRequestHeaders aHeaders;
816 : : getUserRequestHeaders( xEnv,
817 [ # # ]: 0 : getRequestURI(),
818 : : rtl::OUString("COPY"),
819 [ # # ]: 0 : aHeaders );
820 : :
821 : 0 : m_xSession->COPY( rSourcePath,
822 : : rDestinationURI,
823 : : DAVRequestEnvironment(
824 [ # # ]: 0 : getRequestURI(),
825 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
826 : : aHeaders, xEnv ),
827 [ # # ][ # # ]: 0 : bOverwrite );
[ # # ][ # # ]
[ # # ][ # # ]
828 : : }
829 [ # # ]: 0 : catch ( const DAVException & e )
830 : : {
831 : 0 : errorCount++;
832 [ # # ]: 0 : bRetry = handleException( e, errorCount );
833 [ # # ]: 0 : if ( !bRetry )
834 : 0 : throw;
835 : : }
836 : : }
837 : : while ( bRetry );
838 : 0 : }
839 : :
840 : : //=========================================================================
841 : 0 : void DAVResourceAccess::MOVE(
842 : : const ::rtl::OUString & rSourcePath,
843 : : const ::rtl::OUString & rDestinationURI,
844 : : sal_Bool bOverwrite,
845 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
846 : : throw( DAVException )
847 : : {
848 : 0 : initialize();
849 : :
850 : 0 : int errorCount = 0;
851 : : bool bRetry;
852 [ # # ]: 0 : do
853 : : {
854 : 0 : bRetry = false;
855 : : try
856 : : {
857 [ # # ]: 0 : DAVRequestHeaders aHeaders;
858 : : getUserRequestHeaders( xEnv,
859 [ # # ]: 0 : getRequestURI(),
860 : : rtl::OUString("MOVE"),
861 [ # # ]: 0 : aHeaders );
862 : :
863 : 0 : m_xSession->MOVE( rSourcePath,
864 : : rDestinationURI,
865 : : DAVRequestEnvironment(
866 [ # # ]: 0 : getRequestURI(),
867 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
868 : : aHeaders, xEnv ),
869 [ # # ][ # # ]: 0 : bOverwrite );
[ # # ][ # # ]
[ # # ][ # # ]
870 : : }
871 [ # # ]: 0 : catch ( const DAVException & e )
872 : : {
873 : 0 : errorCount++;
874 [ # # ]: 0 : bRetry = handleException( e, errorCount );
875 [ # # ]: 0 : if ( !bRetry )
876 : 0 : throw;
877 : : }
878 : : }
879 : : while ( bRetry );
880 : 0 : }
881 : :
882 : : //=========================================================================
883 : 0 : void DAVResourceAccess::DESTROY(
884 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
885 : : throw( DAVException )
886 : : {
887 : 0 : initialize();
888 : :
889 : 0 : int errorCount = 0;
890 : : bool bRetry;
891 [ # # ]: 0 : do
892 : : {
893 : 0 : bRetry = false;
894 : : try
895 : : {
896 [ # # ]: 0 : DAVRequestHeaders aHeaders;
897 : : getUserRequestHeaders( xEnv,
898 [ # # ]: 0 : getRequestURI(),
899 : : rtl::OUString( "DESTROY" ),
900 [ # # ]: 0 : aHeaders );
901 : :
902 [ # # ]: 0 : m_xSession->DESTROY( getRequestURI(),
903 : : DAVRequestEnvironment(
904 [ # # ]: 0 : getRequestURI(),
905 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
906 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
907 : : }
908 [ # # ]: 0 : catch ( const DAVException & e )
909 : : {
910 : 0 : errorCount++;
911 [ # # ]: 0 : bRetry = handleException( e, errorCount );
912 [ # # ]: 0 : if ( !bRetry )
913 : 0 : throw;
914 : : }
915 : : }
916 : : while ( bRetry );
917 : 0 : }
918 : :
919 : : //=========================================================================
920 : : // set new lock.
921 : 0 : void DAVResourceAccess::LOCK(
922 : : ucb::Lock & inLock,
923 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
924 : : throw ( DAVException )
925 : : {
926 : 0 : initialize();
927 : :
928 : 0 : int errorCount = 0;
929 : : bool bRetry;
930 [ # # ]: 0 : do
931 : : {
932 : 0 : bRetry = false;
933 : : try
934 : : {
935 [ # # ]: 0 : DAVRequestHeaders aHeaders;
936 : : getUserRequestHeaders( xEnv,
937 [ # # ]: 0 : getRequestURI(),
938 : : rtl::OUString("LOCK"),
939 [ # # ]: 0 : aHeaders );
940 : :
941 [ # # ]: 0 : m_xSession->LOCK( getRequestURI(),
942 : : inLock,
943 : : DAVRequestEnvironment(
944 [ # # ]: 0 : getRequestURI(),
945 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
946 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
947 : : }
948 [ # # ]: 0 : catch ( const DAVException & e )
949 : : {
950 : 0 : errorCount++;
951 [ # # ]: 0 : bRetry = handleException( e, errorCount );
952 [ # # ]: 0 : if ( !bRetry )
953 : 0 : throw;
954 : : }
955 : : }
956 : : while ( bRetry );
957 : 0 : }
958 : :
959 : : #if 0 // currently not used, but please don't remove code
960 : : //=========================================================================
961 : : // refresh existing lock.
962 : : sal_Int64 DAVResourceAccess::LOCK(
963 : : sal_Int64 nTimeout,
964 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
965 : : throw ( DAVException )
966 : : {
967 : : initialize();
968 : :
969 : : sal_Int64 nNewTimeout = 0;
970 : : int errorCount = 0;
971 : : bool bRetry;
972 : : do
973 : : {
974 : : bRetry = false;
975 : : try
976 : : {
977 : : DAVRequestHeaders aHeaders;
978 : : getUserRequestHeaders( xEnv,
979 : : getRequestURI(),
980 : : rtl::OUString("LOCK"),
981 : : aHeaders );
982 : :
983 : : nNewTimeout = m_xSession->LOCK( getRequestURI(),
984 : : nTimeout,
985 : : DAVRequestEnvironment(
986 : : getRequestURI(),
987 : : new DAVAuthListener_Impl(
988 : : xEnv, m_aURL ),
989 : : aHeaders, xEnv ) );
990 : : }
991 : : catch ( const DAVException & e )
992 : : {
993 : : errorCount++;
994 : : bRetry = handleException( e, errorCount );
995 : : if ( !bRetry )
996 : : throw;
997 : : }
998 : : }
999 : : while ( bRetry );
1000 : :
1001 : : return nNewTimeout;
1002 : : }
1003 : : #endif
1004 : :
1005 : : //=========================================================================
1006 : 0 : void DAVResourceAccess::UNLOCK(
1007 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1008 : : throw ( DAVException )
1009 : : {
1010 : 0 : initialize();
1011 : :
1012 : 0 : int errorCount = 0;
1013 : : bool bRetry;
1014 [ # # ]: 0 : do
1015 : : {
1016 : 0 : bRetry = false;
1017 : : try
1018 : : {
1019 [ # # ]: 0 : DAVRequestHeaders aHeaders;
1020 : : getUserRequestHeaders( xEnv,
1021 [ # # ]: 0 : getRequestURI(),
1022 : : rtl::OUString("UNLOCK"),
1023 [ # # ]: 0 : aHeaders );
1024 : :
1025 [ # # ]: 0 : m_xSession->UNLOCK( getRequestURI(),
1026 : : DAVRequestEnvironment(
1027 [ # # ]: 0 : getRequestURI(),
1028 [ # # ]: 0 : new DAVAuthListener_Impl( xEnv, m_aURL ),
1029 [ # # ][ # # ]: 0 : aHeaders, xEnv ) );
[ # # ][ # # ]
[ # # ][ # # ]
1030 : : }
1031 [ # # ]: 0 : catch ( const DAVException & e )
1032 : : {
1033 : 0 : errorCount++;
1034 [ # # ]: 0 : bRetry = handleException( e, errorCount );
1035 [ # # ]: 0 : if ( !bRetry )
1036 : 0 : throw;
1037 : : }
1038 : : }
1039 : : while ( bRetry );
1040 : 0 : }
1041 : :
1042 : : //=========================================================================
1043 : 0 : void DAVResourceAccess::setFlags( const uno::Sequence< beans::NamedValue >& rFlags )
1044 : : throw ( DAVException )
1045 : : {
1046 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1047 [ # # ][ # # ]: 0 : m_aFlags = rFlags;
1048 : 0 : }
1049 : :
1050 : : //=========================================================================
1051 : 0 : void DAVResourceAccess::setURL( const rtl::OUString & rNewURL )
1052 : : throw( DAVException )
1053 : : {
1054 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1055 : 0 : m_aURL = rNewURL;
1056 [ # # ]: 0 : m_aPath = rtl::OUString(); // Next initialize() will create new session.
1057 : 0 : }
1058 : :
1059 : : //=========================================================================
1060 : : // init dav session and path
1061 : 0 : void DAVResourceAccess::initialize()
1062 : : throw ( DAVException )
1063 : : {
1064 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1065 [ # # ]: 0 : if ( m_aPath.isEmpty() )
1066 : : {
1067 [ # # ]: 0 : NeonUri aURI( m_aURL );
1068 : 0 : rtl::OUString aPath( aURI.GetPath() );
1069 : :
1070 : : /* #134089# - Check URI */
1071 [ # # ]: 0 : if ( aPath.isEmpty() )
1072 : 0 : throw DAVException( DAVException::DAV_INVALID_ARG );
1073 : :
1074 : : /* #134089# - Check URI */
1075 [ # # ]: 0 : if ( aURI.GetHost().isEmpty() )
1076 : 0 : throw DAVException( DAVException::DAV_INVALID_ARG );
1077 : :
1078 [ # # ][ # # ]: 0 : if ( !m_xSession.is() || !m_xSession->CanUse( m_aURL, m_aFlags ) )
[ # # ][ # # ]
1079 : : {
1080 [ # # ]: 0 : m_xSession.clear();
1081 : :
1082 : : // create new webdav session
1083 : : m_xSession
1084 [ # # ][ # # ]: 0 : = m_xSessionFactory->createDAVSession( m_aURL, m_aFlags, m_xSMgr );
[ # # ]
1085 : :
1086 [ # # ]: 0 : if ( !m_xSession.is() )
1087 : 0 : return;
1088 : : }
1089 : :
1090 : : // Own URI is needed for redirect cycle detection.
1091 [ # # ]: 0 : m_aRedirectURIs.push_back( aURI );
1092 : :
1093 : : // Success.
1094 : 0 : m_aPath = aPath;
1095 : :
1096 : : // Not only the path has to be encoded
1097 [ # # ][ # # ]: 0 : m_aURL = aURI.GetURI();
[ # # ]
1098 [ # # ][ # # ]: 0 : }
1099 : : }
1100 : :
1101 : : //=========================================================================
1102 : 0 : const rtl::OUString & DAVResourceAccess::getRequestURI() const
1103 : : {
1104 : : OSL_ENSURE( m_xSession.is(),
1105 : : "DAVResourceAccess::getRequestURI - Not initialized!" );
1106 : :
1107 : : // In case a proxy is used we have to use the absolute URI for a request.
1108 [ # # ]: 0 : if ( m_xSession->UsesProxy() )
1109 : 0 : return m_aURL;
1110 : :
1111 : 0 : return m_aPath;
1112 : : }
1113 : :
1114 : : //=========================================================================
1115 : : // static
1116 : 0 : void DAVResourceAccess::getUserRequestHeaders(
1117 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv,
1118 : : const rtl::OUString & rURI,
1119 : : const rtl::OUString & rMethod,
1120 : : DAVRequestHeaders & rRequestHeaders )
1121 : : {
1122 [ # # ]: 0 : if ( xEnv.is() )
1123 : : {
1124 : : uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv(
1125 [ # # ]: 0 : xEnv, uno::UNO_QUERY );
1126 : :
1127 [ # # ]: 0 : if ( xDAVEnv.is() )
1128 : : {
1129 : : uno::Sequence< beans::NamedValue > aRequestHeaders
1130 [ # # ][ # # ]: 0 : = xDAVEnv->getUserRequestHeaders( rURI, rMethod );
1131 : :
1132 [ # # ]: 0 : for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n )
1133 : : {
1134 : 0 : rtl::OUString aValue;
1135 [ # # ]: 0 : sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue;
1136 : :
1137 : : if ( !isString )
1138 : : {
1139 : : OSL_ENSURE( isString,
1140 : : "DAVResourceAccess::getUserRequestHeaders :"
1141 : : "Value is not a string! Ignoring..." );
1142 : : }
1143 : :
1144 : : rRequestHeaders.push_back(
1145 [ # # ][ # # ]: 0 : DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) );
1146 [ # # ]: 0 : }
1147 : 0 : }
1148 : : }
1149 : :
1150 : : // Make sure a User-Agent header is always included, as at least
1151 : : // en.wikipedia.org:80 forces back 403 "Scripts should use an informative
1152 : : // User-Agent string with contact information, or they may be IP-blocked
1153 : : // without notice" otherwise:
1154 [ # # ][ # # ]: 0 : for ( DAVRequestHeaders::iterator i(rRequestHeaders.begin());
1155 : 0 : i != rRequestHeaders.end(); ++i )
1156 : : {
1157 [ # # ]: 0 : if ( i->first.equalsIgnoreAsciiCase( "User-Agent" ) )
1158 : : {
1159 : 0 : return;
1160 : : }
1161 : : }
1162 : : rRequestHeaders.push_back(
1163 [ # # ]: 0 : DAVRequestHeader( "User-Agent", "LibreOffice" ) );
1164 : : }
1165 : :
1166 : : //=========================================================================
1167 : 0 : sal_Bool DAVResourceAccess::detectRedirectCycle(
1168 : : const rtl::OUString& rRedirectURL )
1169 : : throw ( DAVException )
1170 : : {
1171 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1172 : :
1173 [ # # ]: 0 : NeonUri aUri( rRedirectURL );
1174 : :
1175 [ # # ]: 0 : std::vector< NeonUri >::const_iterator it = m_aRedirectURIs.begin();
1176 [ # # ]: 0 : std::vector< NeonUri >::const_iterator end = m_aRedirectURIs.end();
1177 : :
1178 [ # # ][ # # ]: 0 : while ( it != end )
1179 : : {
1180 [ # # ][ # # ]: 0 : if ( aUri == (*it) )
1181 : 0 : return sal_True;
1182 : :
1183 : 0 : ++it;
1184 : : }
1185 : :
1186 [ # # ][ # # ]: 0 : return sal_False;
1187 : : }
1188 : :
1189 : : //=========================================================================
1190 : 0 : void DAVResourceAccess::resetUri()
1191 : : {
1192 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1193 [ # # ]: 0 : if ( !m_aRedirectURIs.empty() )
1194 : : {
1195 [ # # ]: 0 : std::vector< NeonUri >::const_iterator it = m_aRedirectURIs.begin();
1196 : :
1197 : 0 : NeonUri aUri( (*it) );
1198 : 0 : m_aRedirectURIs.clear();
1199 [ # # ]: 0 : setURL ( aUri.GetURI() );
1200 [ # # ][ # # ]: 0 : initialize();
1201 [ # # ]: 0 : }
1202 : 0 : }
1203 : :
1204 : : //=========================================================================
1205 : 0 : sal_Bool DAVResourceAccess::handleException( const DAVException & e, int errorCount )
1206 : : throw ( DAVException )
1207 : : {
1208 [ # # # # ]: 0 : switch ( e.getError() )
1209 : : {
1210 : : case DAVException::DAV_HTTP_REDIRECT:
1211 [ # # ]: 0 : if ( !detectRedirectCycle( e.getData() ) )
1212 : : {
1213 : : // set new URL and path.
1214 : 0 : setURL( e.getData() );
1215 : 0 : initialize();
1216 : 0 : return sal_True;
1217 : : }
1218 : 0 : return sal_False;
1219 : : // #67048# copy & paste images doesn't display.
1220 : : // if we have a bad connection try again. Up to three times.
1221 : : case DAVException::DAV_HTTP_ERROR:
1222 : : // retry up to three times, if not a client-side error.
1223 [ # # ][ # # ]: 0 : if ( ( e.getStatus() < 400 || e.getStatus() >= 500 ) &&
[ # # ][ # # ]
1224 : : errorCount < 3 )
1225 : : {
1226 : 0 : return sal_True;
1227 : : }
1228 : 0 : return sal_False;
1229 : : // if connection has said retry then retry!
1230 : : case DAVException::DAV_HTTP_RETRY:
1231 : 0 : return sal_True;
1232 : : default:
1233 : 0 : return sal_False; // Abort
1234 : : }
1235 : : }
1236 : :
1237 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|