LibreOffice Module ucb (master)  1
DAVResourceAccess.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include <com/sun/star/task/XInteractionAbort.hpp>
22 #include <com/sun/star/ucb/XWebDAVCommandEnvironment.hpp>
23 
26 #include <sal/log.hxx>
27 
28 #include "DAVAuthListenerImpl.hxx"
29 #include "DAVResourceAccess.hxx"
30 
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <com/sun/star/io/IOException.hpp>
33 
34 using namespace http_dav_ucp;
35 using namespace com::sun::star;
36 
37 
38 // DAVAuthListener_Impl Implementation.
39 
40 
41 // virtual
43  const OUString & inRealm,
44  const OUString & inHostName,
45  OUString & inoutUserName,
46  OUString & outPassWord,
47  bool bCanUseSystemCredentials,
48  bool bUsePreviousCredentials )
49 {
50  if ( m_xEnv.is() )
51  {
52  uno::Reference< task::XInteractionHandler > xIH
53  = m_xEnv->getInteractionHandler();
54 
55  if ( xIH.is() )
56  {
57  // Providing previously retrieved credentials will cause the password
58  // container to reject these. Thus, the credential input dialog will be shown again.
59  // #102871# - Supply username and password from previous try.
60  // Password container service depends on this!
61  if ( inoutUserName.isEmpty() && bUsePreviousCredentials )
62  inoutUserName = m_aPrevUsername;
63 
64  if ( outPassWord.isEmpty() && bUsePreviousCredentials )
65  outPassWord = m_aPrevPassword;
66 
69  m_aURL, inHostName, inRealm, inoutUserName,
70  outPassWord,
71  true /*bAllowPersistentStoring*/,
72  bCanUseSystemCredentials );
73  xIH->handle( xRequest.get() );
74 
76  = xRequest->getSelection();
77 
78  if ( xSelection.is() )
79  {
80  // Handler handled the request.
81  uno::Reference< task::XInteractionAbort > xAbort(
82  xSelection.get(), uno::UNO_QUERY );
83  if ( !xAbort.is() )
84  {
85  const rtl::Reference<
87  = xRequest->getAuthenticationSupplier();
88 
89  bool bUseSystemCredentials = false;
90 
91  if ( bCanUseSystemCredentials )
92  bUseSystemCredentials
93  = xSupp->getUseSystemCredentials();
94 
95  if ( bUseSystemCredentials )
96  {
97  // This is the (strange) way to tell neon to use
98  // system credentials.
99  inoutUserName.clear();
100  outPassWord.clear();
101  }
102  else
103  {
104  inoutUserName = xSupp->getUserName();
105  outPassWord = xSupp->getPassword();
106  }
107 
108  // #102871# - Remember username and password.
109  m_aPrevUsername = inoutUserName;
110  m_aPrevPassword = outPassWord;
111 
112  // go on.
113  return 0;
114  }
115  }
116  }
117  }
118  // Abort.
119  return -1;
120 }
121 
122 
123 // DAVResourceAccess Implementation.
124 
125 
127  const uno::Reference< uno::XComponentContext > & rContext,
128  rtl::Reference< DAVSessionFactory > const & rSessionFactory,
129  const OUString & rURL )
130 : m_aURL( rURL ),
131  m_xSessionFactory( rSessionFactory ),
132  m_xContext( rContext )
133 {
134 }
135 
136 
138 : m_aURL( rOther.m_aURL ),
139  m_aPath( rOther.m_aPath ),
140  m_xSession( rOther.m_xSession ),
141  m_xSessionFactory( rOther.m_xSessionFactory ),
142  m_xContext( rOther.m_xContext ),
143  m_aRedirectURIs( rOther.m_aRedirectURIs )
144 {
145 }
146 
147 
149  const DAVResourceAccess & rOther )
150 {
151  m_aURL = rOther.m_aURL;
152  m_aPath = rOther.m_aPath;
153  m_xSession = rOther.m_xSession;
155  m_xContext = rOther.m_xContext;
157 
158  return *this;
159 }
160 
161 
163  const Depth nDepth,
164  const std::vector< OUString > & rPropertyNames,
165  std::vector< DAVResource > & rResources,
166  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
167 {
168  initialize();
169 
170  int errorCount = 0;
171  bool bRetry;
172  do
173  {
174  bRetry = false;
175  try
176  {
177  DAVRequestHeaders aHeaders;
178 
179  getUserRequestHeaders( xEnv,
180  getRequestURI(),
181  ucb::WebDAVHTTPMethod_PROPFIND,
182  aHeaders );
183 
184  m_xSession->PROPFIND( getRequestURI(),
185  nDepth,
186  rPropertyNames,
187  rResources,
189  getRequestURI(),
190  new DAVAuthListener_Impl( xEnv, m_aURL ),
191  aHeaders, xEnv ) );
192  }
193  catch ( DAVException & e )
194  {
195  errorCount++;
196  bRetry = handleException( e, errorCount );
197  if ( !bRetry )
198  throw;
199  }
200  }
201  while ( bRetry );
202 }
203 
204 
206  const Depth nDepth,
207  std::vector< DAVResourceInfo > & rResInfo,
208  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
209 {
210  initialize();
211 
212  int errorCount = 0;
213  bool bRetry;
214  do
215  {
216  bRetry = false;
217  try
218  {
219  DAVRequestHeaders aHeaders;
220  getUserRequestHeaders( xEnv,
221  getRequestURI(),
222  ucb::WebDAVHTTPMethod_PROPFIND,
223  aHeaders );
224 
225  m_xSession->PROPFIND( getRequestURI(),
226  nDepth,
227  rResInfo,
229  getRequestURI(),
230  new DAVAuthListener_Impl( xEnv, m_aURL ),
231  aHeaders, xEnv ) ) ;
232  }
233  catch ( DAVException & e )
234  {
235  errorCount++;
236  bRetry = handleException( e, errorCount );
237  if ( !bRetry )
238  throw;
239  }
240  }
241  while ( bRetry );
242 }
243 
244 
246  const std::vector< ProppatchValue >& rValues,
247  const uno::Reference< ucb::XCommandEnvironment >& xEnv )
248 {
249  initialize();
250 
251  int errorCount = 0;
252  bool bRetry;
253  do
254  {
255  bRetry = false;
256  try
257  {
258  DAVRequestHeaders aHeaders;
259  getUserRequestHeaders( xEnv,
260  getRequestURI(),
261  ucb::WebDAVHTTPMethod_PROPPATCH,
262  aHeaders );
263 
264  m_xSession->PROPPATCH( getRequestURI(),
265  rValues,
267  getRequestURI(),
268  new DAVAuthListener_Impl( xEnv, m_aURL ),
269  aHeaders, xEnv ) );
270  }
271  catch ( DAVException & e )
272  {
273  errorCount++;
274  bRetry = handleException( e, errorCount );
275  if ( !bRetry )
276  throw;
277  }
278  }
279  while ( bRetry );
280 }
281 
282 
284  const std::vector< OUString > & rHeaderNames,
285  DAVResource & rResource,
286  const uno::Reference< ucb::XCommandEnvironment >& xEnv )
287 {
288  initialize();
289 
290  int errorCount = 0;
291  bool bRetry;
292  do
293  {
294  bRetry = false;
295  try
296  {
297  DAVRequestHeaders aHeaders;
298  getUserRequestHeaders( xEnv,
299  getRequestURI(),
300  ucb::WebDAVHTTPMethod_HEAD,
301  aHeaders );
302 
303  m_xSession->HEAD( getRequestURI(),
304  rHeaderNames,
305  rResource,
307  getRequestURI(),
308  new DAVAuthListener_Impl( xEnv, m_aURL ),
309  aHeaders, xEnv ) );
310  }
311  catch ( DAVException & e )
312  {
313  errorCount++;
314  bRetry = handleException( e, errorCount );
315  if ( !bRetry )
316  throw;
317  }
318  }
319  while ( bRetry );
320 }
321 
322 
323 uno::Reference< io::XInputStream > DAVResourceAccess::GET(
324  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
325 {
326  initialize();
327 
328  uno::Reference< io::XInputStream > xStream;
329  int errorCount = 0;
330  bool bRetry;
331  do
332  {
333  bRetry = false;
334  try
335  {
336  DAVRequestHeaders aHeaders;
337  getUserRequestHeaders( xEnv,
338  getRequestURI(),
339  ucb::WebDAVHTTPMethod_GET,
340  aHeaders );
341 
342  xStream = m_xSession->GET( getRequestURI(),
344  getRequestURI(),
346  xEnv, m_aURL ),
347  aHeaders, xEnv ) );
348  }
349  catch ( DAVException & e )
350  {
351  errorCount++;
352  bRetry = handleException( e, errorCount );
353  if ( !bRetry )
354  throw;
355  }
356  }
357  while ( bRetry );
358 
359  return xStream;
360 }
361 
362 
364  uno::Reference< io::XOutputStream > & rStream,
365  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
366 {
367  initialize();
368 
369  int errorCount = 0;
370  bool bRetry;
371  do
372  {
373  bRetry = false;
374  try
375  {
376  DAVRequestHeaders aHeaders;
377  getUserRequestHeaders( xEnv,
378  getRequestURI(),
379  ucb::WebDAVHTTPMethod_GET,
380  aHeaders );
381 
382  m_xSession->GET( getRequestURI(),
383  rStream,
385  getRequestURI(),
386  new DAVAuthListener_Impl( xEnv, m_aURL ),
387  aHeaders, xEnv ) );
388  }
389  catch ( DAVException & e )
390  {
391  errorCount++;
392  bRetry = handleException( e, errorCount );
393  if ( !bRetry )
394  throw;
395  }
396  }
397  while ( bRetry );
398 }
399 
400 
401 uno::Reference< io::XInputStream > DAVResourceAccess::GET(
402  const std::vector< OUString > & rHeaderNames,
403  DAVResource & rResource,
404  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
405 {
406  initialize();
407 
408  uno::Reference< io::XInputStream > xStream;
409  int errorCount = 0;
410  bool bRetry;
411  do
412  {
413  bRetry = false;
414  try
415  {
416  DAVRequestHeaders aHeaders;
417  getUserRequestHeaders( xEnv,
418  getRequestURI(),
419  ucb::WebDAVHTTPMethod_GET,
420  aHeaders );
421 
422  xStream = m_xSession->GET( getRequestURI(),
423  rHeaderNames,
424  rResource,
426  getRequestURI(),
428  xEnv, m_aURL ),
429  aHeaders, xEnv ) );
430  }
431  catch ( DAVException & e )
432  {
433  errorCount++;
434  bRetry = handleException( e, errorCount );
435  if ( !bRetry )
436  throw;
437  }
438  }
439  while ( bRetry );
440 
441  return xStream;
442 }
443 
444 
445 uno::Reference< io::XInputStream > DAVResourceAccess::GET(
446  DAVRequestHeaders &rRequestHeaders,
447  const std::vector< OUString > & rHeaderNames,
448  DAVResource & rResource,
449  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
450 {
451  initialize();
452 
453  uno::Reference< io::XInputStream > xStream;
454  int errorCount = 0;
455  bool bRetry;
456  do
457  {
458  bRetry = false;
459  try
460  {
461  getUserRequestHeaders( xEnv,
462  getRequestURI(),
463  ucb::WebDAVHTTPMethod_GET,
464  rRequestHeaders );
465 
466  xStream = m_xSession->GET( getRequestURI(),
467  rHeaderNames,
468  rResource,
470  getRequestURI(),
472  xEnv, m_aURL ),
473  rRequestHeaders, xEnv ) );
474  }
475  catch ( DAVException & e )
476  {
477  errorCount++;
478  bRetry = handleException( e, errorCount );
479  if ( !bRetry )
480  throw;
481  }
482  }
483  while ( bRetry );
484 
485  return xStream;
486 }
487 
488 
490  uno::Reference< io::XOutputStream > & rStream,
491  const std::vector< OUString > & rHeaderNames,
492  DAVResource & rResource,
493  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
494 {
495  initialize();
496 
497  bool bRetry;
498  int errorCount = 0;
499  do
500  {
501  bRetry = false;
502  try
503  {
504  DAVRequestHeaders aHeaders;
505  getUserRequestHeaders( xEnv,
506  getRequestURI(),
507  ucb::WebDAVHTTPMethod_GET,
508  aHeaders );
509 
510  m_xSession->GET( getRequestURI(),
511  rStream,
512  rHeaderNames,
513  rResource,
515  getRequestURI(),
516  new DAVAuthListener_Impl( xEnv, m_aURL ),
517  aHeaders, xEnv ) );
518  }
519  catch ( DAVException & e )
520  {
521  errorCount++;
522  bRetry = handleException( e, errorCount );
523  if ( !bRetry )
524  throw;
525  }
526  }
527  while ( bRetry );
528 }
529 
530 
532 {
533  // 17.11.09 (tkr): abort currently disabled caused by issue i106766
534  // initialize();
535  // m_xSession->abort();
536  SAL_INFO("ucb.ucp.webdav", "Not implemented. -> #i106766#" );
537 }
538 
539 
540 namespace {
541 
543  void resetInputStream( const uno::Reference< io::XInputStream > & rStream )
544  {
545  try
546  {
547  uno::Reference< io::XSeekable > xSeekable(
548  rStream, uno::UNO_QUERY );
549  if ( xSeekable.is() )
550  {
551  xSeekable->seek( 0 );
552  return;
553  }
554  }
555  catch ( lang::IllegalArgumentException const & )
556  {
557  }
558  catch ( io::IOException const & )
559  {
560  }
561 
563  }
564 
565 } // namespace
566 
567 
569  const uno::Reference< io::XInputStream > & rStream,
570  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
571 {
572  initialize();
573 
574  // Make stream seekable, if it not. Needed, if request must be retried.
575  uno::Reference< io::XInputStream > xSeekableStream
577  rStream, m_xContext );
578 
579  int errorCount = 0;
580  bool bRetry = false;
581  do
582  {
583  if ( bRetry )
584  resetInputStream( xSeekableStream );
585 
586  bRetry = false;
587  try
588  {
589  DAVRequestHeaders aHeaders;
590  getUserRequestHeaders( xEnv,
591  getRequestURI(),
592  ucb::WebDAVHTTPMethod_PUT,
593  aHeaders );
594 
595  m_xSession->PUT( getRequestURI(),
596  xSeekableStream,
598  getRequestURI(),
599  new DAVAuthListener_Impl( xEnv, m_aURL ),
600  aHeaders, xEnv ) );
601  }
602  catch ( DAVException & e )
603  {
604  errorCount++;
605  bRetry = handleException( e, errorCount );
606  if ( !bRetry )
607  throw;
608  }
609  }
610  while ( bRetry );
611 }
612 
613 
614 uno::Reference< io::XInputStream > DAVResourceAccess::POST(
615  const OUString & rContentType,
616  const OUString & rReferer,
617  const uno::Reference< io::XInputStream > & rInputStream,
618  const uno::Reference< ucb::XCommandEnvironment >& xEnv )
619 {
620  initialize();
621 
622  // Make stream seekable, if it not. Needed, if request must be retried.
623  uno::Reference< io::XInputStream > xSeekableStream
625  rInputStream, m_xContext );
626 
627  uno::Reference< io::XInputStream > xStream;
628  int errorCount = 0;
629  bool bRetry = false;
630  do
631  {
632  if ( bRetry )
633  {
634  resetInputStream( xSeekableStream );
635  bRetry = false;
636  }
637 
638  try
639  {
640  DAVRequestHeaders aHeaders;
641  getUserRequestHeaders( xEnv,
642  getRequestURI(),
643  ucb::WebDAVHTTPMethod_POST,
644  aHeaders );
645 
646  xStream = m_xSession->POST( getRequestURI(),
647  rContentType,
648  rReferer,
649  xSeekableStream,
651  getRequestURI(),
653  xEnv, m_aURL ),
654  aHeaders, xEnv ) );
655  }
656  catch ( DAVException & e )
657  {
658  errorCount++;
659  bRetry = handleException( e, errorCount );
660  if ( !bRetry )
661  throw;
662 
664  {
665  // #i74980# - Upon POST redirect, do a GET.
666  return GET( xEnv );
667  }
668  }
669  }
670  while ( bRetry );
671 
672  return xStream;
673 }
674 
675 
677  const OUString & rContentType,
678  const OUString & rReferer,
679  const uno::Reference< io::XInputStream > & rInputStream,
680  uno::Reference< io::XOutputStream > & rOutputStream,
681  const uno::Reference< ucb::XCommandEnvironment >& xEnv )
682 {
683  initialize();
684 
685  // Make stream seekable, if it not. Needed, if request must be retried.
686  uno::Reference< io::XInputStream > xSeekableStream
688  rInputStream, m_xContext );
689 
690  int errorCount = 0;
691  bool bRetry = false;
692  do
693  {
694  if ( bRetry )
695  {
696  resetInputStream( xSeekableStream );
697  bRetry = false;
698  }
699 
700  try
701  {
702  DAVRequestHeaders aHeaders;
703  getUserRequestHeaders( xEnv,
704  getRequestURI(),
705  ucb::WebDAVHTTPMethod_POST,
706  aHeaders );
707 
708  m_xSession->POST( getRequestURI(),
709  rContentType,
710  rReferer,
711  xSeekableStream,
712  rOutputStream,
714  getRequestURI(),
715  new DAVAuthListener_Impl( xEnv, m_aURL ),
716  aHeaders, xEnv ) );
717  }
718  catch ( DAVException & e )
719  {
720  errorCount++;
721  bRetry = handleException( e, errorCount );
722  if ( !bRetry )
723  throw;
724 
726  {
727  // #i74980# - Upon POST redirect, do a GET.
728  GET( rOutputStream, xEnv );
729  return;
730  }
731  }
732  }
733  while ( bRetry );
734 }
735 
736 
738  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
739 {
740  initialize();
741 
742  int errorCount = 0;
743  bool bRetry;
744  do
745  {
746  bRetry = false;
747  try
748  {
749  DAVRequestHeaders aHeaders;
750  getUserRequestHeaders( xEnv,
751  getRequestURI(),
752  ucb::WebDAVHTTPMethod_MKCOL,
753  aHeaders );
754 
755  m_xSession->MKCOL( getRequestURI(),
757  getRequestURI(),
758  new DAVAuthListener_Impl( xEnv, m_aURL ),
759  aHeaders, xEnv ) );
760  }
761  catch ( DAVException & e )
762  {
763  errorCount++;
764  bRetry = handleException( e, errorCount );
765  if ( !bRetry )
766  throw;
767  }
768  }
769  while ( bRetry );
770 }
771 
772 
774  const OUString & rSourcePath,
775  const OUString & rDestinationURI,
776  bool bOverwrite,
777  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
778 {
779  initialize();
780 
781  int errorCount = 0;
782  bool bRetry;
783  do
784  {
785  bRetry = false;
786  try
787  {
788  DAVRequestHeaders aHeaders;
789  getUserRequestHeaders( xEnv,
790  getRequestURI(),
791  ucb::WebDAVHTTPMethod_COPY,
792  aHeaders );
793 
794  m_xSession->COPY( rSourcePath,
795  rDestinationURI,
797  getRequestURI(),
798  new DAVAuthListener_Impl( xEnv, m_aURL ),
799  aHeaders, xEnv ),
800  bOverwrite );
801  }
802  catch ( DAVException & e )
803  {
804  errorCount++;
805  bRetry = handleException( e, errorCount );
806  if ( !bRetry )
807  throw;
808  }
809  }
810  while ( bRetry );
811 }
812 
813 
815  const OUString & rSourcePath,
816  const OUString & rDestinationURI,
817  bool bOverwrite,
818  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
819 {
820  initialize();
821 
822  int errorCount = 0;
823  bool bRetry;
824  do
825  {
826  bRetry = false;
827  try
828  {
829  DAVRequestHeaders aHeaders;
830  getUserRequestHeaders( xEnv,
831  getRequestURI(),
832  ucb::WebDAVHTTPMethod_MOVE,
833  aHeaders );
834 
835  m_xSession->MOVE( rSourcePath,
836  rDestinationURI,
838  getRequestURI(),
839  new DAVAuthListener_Impl( xEnv, m_aURL ),
840  aHeaders, xEnv ),
841  bOverwrite );
842  }
843  catch ( DAVException & e )
844  {
845  errorCount++;
846  bRetry = handleException( e, errorCount );
847  if ( !bRetry )
848  throw;
849  }
850  }
851  while ( bRetry );
852 }
853 
854 
856  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
857 {
858  initialize();
859 
860  int errorCount = 0;
861  bool bRetry;
862  do
863  {
864  bRetry = false;
865  try
866  {
867  DAVRequestHeaders aHeaders;
868  getUserRequestHeaders( xEnv,
869  getRequestURI(),
870  ucb::WebDAVHTTPMethod_DELETE,
871  aHeaders );
872 
873  m_xSession->DESTROY( getRequestURI(),
875  getRequestURI(),
876  new DAVAuthListener_Impl( xEnv, m_aURL ),
877  aHeaders, xEnv ) );
878  }
879  catch ( DAVException & e )
880  {
881  errorCount++;
882  bRetry = handleException( e, errorCount );
883  if ( !bRetry )
884  throw;
885  }
886  }
887  while ( bRetry );
888 }
889 
890 
891 // set new lock.
893  ucb::Lock & inLock,
894  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
895 {
896  initialize();
897 
898  int errorCount = 0;
899  bool bRetry;
900  do
901  {
902  bRetry = false;
903  try
904  {
905  DAVRequestHeaders aHeaders;
906  getUserRequestHeaders( xEnv,
907  getRequestURI(),
908  ucb::WebDAVHTTPMethod_LOCK,
909  aHeaders );
910 
911  m_xSession->LOCK( getRequestURI(),
912  inLock,
914  getRequestURI(),
915  new DAVAuthListener_Impl( xEnv, m_aURL ),
916  aHeaders, xEnv ) );
917  }
918  catch ( DAVException & e )
919  {
920  errorCount++;
921  bRetry = handleException( e, errorCount );
922  if ( !bRetry )
923  throw;
924  }
925  }
926  while ( bRetry );
927 }
928 
930  const uno::Reference< ucb::XCommandEnvironment > & xEnv )
931 {
932  initialize();
933 
934  int errorCount = 0;
935  bool bRetry;
936  do
937  {
938  bRetry = false;
939  try
940  {
941  DAVRequestHeaders aHeaders;
942  getUserRequestHeaders( xEnv,
943  getRequestURI(),
944  ucb::WebDAVHTTPMethod_UNLOCK,
945  aHeaders );
946 
947  m_xSession->UNLOCK( getRequestURI(),
949  getRequestURI(),
950  new DAVAuthListener_Impl( xEnv, m_aURL ),
951  aHeaders, xEnv ) );
952  }
953  catch ( DAVException & e )
954  {
955  errorCount++;
956  bRetry = handleException( e, errorCount );
957  if ( !bRetry )
958  throw;
959  }
960  }
961  while ( bRetry );
962 }
963 
964 
965 void DAVResourceAccess::setURL( const OUString & rNewURL )
966 {
967  osl::Guard< osl::Mutex > aGuard( m_aMutex );
968  m_aURL = rNewURL;
969  m_aPath.clear(); // Next initialize() will create new session.
970 }
971 
972 
973 // init dav session and path
975 {
976  osl::Guard< osl::Mutex > aGuard( m_aMutex );
977  if ( m_aPath.isEmpty() )
978  {
979  SerfUri aURI( m_aURL );
980  OUString aPath( aURI.GetPath() );
981 
982  /* #134089# - Check URI */
983  if ( aPath.isEmpty() )
985 
986  /* #134089# - Check URI */
987  if ( aURI.GetHost().isEmpty() )
989 
990  if ( !m_xSession.is() || !m_xSession->CanUse( m_aURL ) )
991  {
992  m_xSession.clear();
993 
994  // create new webdav session
995  m_xSession
996  = m_xSessionFactory->createDAVSession( m_aURL, m_xContext );
997 
998  if ( !m_xSession.is() )
999  return;
1000  }
1001 
1002  // Own URI is needed for redirect cycle detection.
1003  m_aRedirectURIs.push_back( aURI );
1004 
1005  // Success.
1006  m_aPath = aPath;
1007 
1008  // Not only the path has to be encoded
1009  m_aURL = aURI.GetURI();
1010  }
1011 }
1012 
1013 
1014 const OUString & DAVResourceAccess::getRequestURI() const
1015 {
1016  SAL_WARN_IF( !m_xSession.is(), "ucb.ucp.webdav",
1017  "DAVResourceAccess::getRequestURI - Not initialized!" );
1018 
1019  // In case a proxy is used we have to use the absolute URI for a request.
1020  if ( m_xSession->UsesProxy() )
1021  return m_aURL;
1022 
1023  return m_aPath;
1024 }
1025 
1026 
1027 // static
1029  const uno::Reference< ucb::XCommandEnvironment > & xEnv,
1030  const OUString & rURI,
1031  ucb::WebDAVHTTPMethod eMethod,
1032  DAVRequestHeaders & rRequestHeaders )
1033 {
1034  if ( !xEnv.is() )
1035  return;
1036 
1037  uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv(
1038  xEnv, uno::UNO_QUERY );
1039 
1040  if ( !xDAVEnv.is() )
1041  return;
1042 
1043  uno::Sequence< beans::StringPair > aRequestHeaders
1044  = xDAVEnv->getUserRequestHeaders( rURI, eMethod );
1045 
1046  for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n )
1047  {
1048  rRequestHeaders.push_back(
1049  DAVRequestHeader( aRequestHeaders[ n ].First,
1050  aRequestHeaders[ n ].Second ) );
1051  }
1052 }
1053 
1054 
1056  const OUString& rRedirectURL )
1057 {
1058  osl::Guard< osl::Mutex > aGuard( m_aMutex );
1059 
1060  SerfUri aUri( rRedirectURL );
1061 
1062  return std::any_of(m_aRedirectURIs.begin(), m_aRedirectURIs.end(),
1063  [&aUri](const SerfUri& rUri) { return aUri == rUri; });
1064 }
1065 
1066 
1068 {
1069  osl::Guard< osl::Mutex > aGuard( m_aMutex );
1070  if ( ! m_aRedirectURIs.empty() )
1071  {
1072  std::vector< SerfUri >::const_iterator it = m_aRedirectURIs.begin();
1073 
1074  SerfUri aUri( *it );
1075  m_aRedirectURIs.clear();
1076  setURL ( aUri.GetURI() );
1077  initialize();
1078  }
1079 }
1080 
1081 
1083 {
1084  switch ( e.getError() )
1085  {
1087  if ( !detectRedirectCycle( e.getData() ) )
1088  {
1089  // set new URL and path.
1090  setURL( e.getData() );
1091  initialize();
1092  return true;
1093  }
1094  return false;
1095  // --> tkr #67048# copy & paste images doesn't display.
1096  // if we have a bad connection try again. Up to three times.
1098  // retry up to three times, if not a client-side error.
1099  if ( ( e.getStatus() < 400 || e.getStatus() >= 500 ||
1100  e.getStatus() == 413 ) &&
1101  errorCount < 3 )
1102  {
1103  return true;
1104  }
1105  return false;
1106  // <--
1107  // --> tkr: if connection has said retry then retry!
1109  return true;
1110  // <--
1111  default:
1112  return false; // Abort
1113  }
1114 }
1115 
1116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< DAVRequestHeader > DAVRequestHeaders
const ExceptionCode & getError() const
DAVResourceAccess & operator=(const DAVResourceAccess &rOther)
void DESTROY(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
const OUString & getData() const
css::uno::Reference< css::io::XInputStream > POST(const OUString &rContentType, const OUString &rReferer, const css::uno::Reference< css::io::XInputStream > &rInputStream, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
Reference< XInputStream > xStream
const OUString & GetHost() const
Definition: SerfUri.hxx:73
rtl::Reference< DAVSession > m_xSession
void MKCOL(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void UNLOCK(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::uno::XComponentContext > m_xContext
void MOVE(const OUString &rSourcePath, const OUString &rDestinationURI, bool bOverwrite, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void COPY(const OUString &rSourcePath, const OUString &rDestinationURI, bool bOverwrite, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::io::XInputStream > GET(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void setURL(const OUString &rNewURL)
const OUString & GetPath() const
Definition: SerfUri.hxx:77
std::pair< OUString, OUString > DAVRequestHeader
void PROPFIND(const Depth nDepth, const std::vector< OUString > &rPropertyNames, std::vector< DAVResource > &rResources, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
bool detectRedirectCycle(const OUString &rRedirectURL)
rtl::Reference< DAVSessionFactory > m_xSessionFactory
void HEAD(const std::vector< OUString > &rHeaderNames, DAVResource &rResource, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
#define SAL_WARN_IF(condition, area, stream)
std::vector< SerfUri > m_aRedirectURIs
#define SAL_INFO(area, stream)
static css::uno::Reference< css::io::XInputStream > CheckSeekableCanWrap(const css::uno::Reference< css::io::XInputStream > &xInStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
static void getUserRequestHeaders(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, const OUString &rURI, css::ucb::WebDAVHTTPMethod eMethod, DAVRequestHeaders &rRequestHeaders)
void PROPPATCH(const std::vector< ProppatchValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void PUT(const css::uno::Reference< css::io::XInputStream > &rStream, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
const OUString & getRequestURI() const
void LOCK(css::ucb::Lock &inLock, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual int authenticate(const OUString &inRealm, const OUString &inHostName, OUString &inoutUserName, OUString &outPassWord, bool bCanUseSystemCredentials, bool bUsePreviousCredentials=true) override
sal_uInt16 getStatus() const
bool handleException(DAVException &e, int errorCount)
const uno::Reference< uno::XComponentContext > m_xContext
const OUString & GetURI() const
Definition: SerfUri.hxx:67