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