12f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 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 10cdf0e10cSrcweir * 112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 202f86921cSAndrew Rist *************************************************************/ 212f86921cSAndrew Rist 222f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "osl/diagnose.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp" 30cdf0e10cSrcweir #include "com/sun/star/ucb/XWebDAVCommandEnvironment.hpp" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "ucbhelper/simpleauthenticationrequest.hxx" 33cdf0e10cSrcweir #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, 56*fb7f54d2SOliver-Rainer Wittmann sal_Bool bCanUseSystemCredentials, 57*fb7f54d2SOliver-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 { 66*fb7f54d2SOliver-Rainer Wittmann // Providing previously retrieved credentials will cause the password 67*fb7f54d2SOliver-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! 70*fb7f54d2SOliver-Rainer Wittmann if ( inoutUserName.getLength() == 0 && bUsePreviousCredentials ) 71cdf0e10cSrcweir inoutUserName = m_aPrevUsername; 72cdf0e10cSrcweir 73*fb7f54d2SOliver-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(), 196cdf0e10cSrcweir rtl::OUString::createFromAscii( 197cdf0e10cSrcweir "PROPFIND" ), 198cdf0e10cSrcweir aHeaders ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir m_xSession->PROPFIND( getRequestURI(), 201cdf0e10cSrcweir nDepth, 202cdf0e10cSrcweir rPropertyNames, 203cdf0e10cSrcweir rResources, 204cdf0e10cSrcweir DAVRequestEnvironment( 205cdf0e10cSrcweir getRequestURI(), 206cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 207cdf0e10cSrcweir aHeaders, xEnv ) ); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir catch ( DAVException & e ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir errorCount++; 212cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 213cdf0e10cSrcweir if ( !bRetry ) 214cdf0e10cSrcweir throw; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir while ( bRetry ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir //========================================================================= 221cdf0e10cSrcweir void DAVResourceAccess::PROPFIND( 222cdf0e10cSrcweir const Depth nDepth, 223cdf0e10cSrcweir std::vector< DAVResourceInfo > & rResInfo, 224cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 225cdf0e10cSrcweir throw( DAVException ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir initialize(); 228cdf0e10cSrcweir 229cdf0e10cSrcweir int errorCount = 0; 230cdf0e10cSrcweir bool bRetry; 231cdf0e10cSrcweir do 232cdf0e10cSrcweir { 233cdf0e10cSrcweir bRetry = false; 234cdf0e10cSrcweir try 235cdf0e10cSrcweir { 236cdf0e10cSrcweir DAVRequestHeaders aHeaders; 237cdf0e10cSrcweir getUserRequestHeaders( xEnv, 238cdf0e10cSrcweir getRequestURI(), 239cdf0e10cSrcweir rtl::OUString::createFromAscii( 240cdf0e10cSrcweir "PROPFIND" ), 241cdf0e10cSrcweir aHeaders ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir m_xSession->PROPFIND( getRequestURI(), 244cdf0e10cSrcweir nDepth, 245cdf0e10cSrcweir rResInfo, 246cdf0e10cSrcweir DAVRequestEnvironment( 247cdf0e10cSrcweir getRequestURI(), 248cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 249cdf0e10cSrcweir aHeaders, xEnv ) ) ; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir catch ( DAVException & e ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir errorCount++; 254cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 255cdf0e10cSrcweir if ( !bRetry ) 256cdf0e10cSrcweir throw; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir while ( bRetry ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir //========================================================================= 263cdf0e10cSrcweir void DAVResourceAccess::PROPPATCH( 264cdf0e10cSrcweir const std::vector< ProppatchValue >& rValues, 265cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 266cdf0e10cSrcweir throw( DAVException ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir initialize(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir int errorCount = 0; 271cdf0e10cSrcweir bool bRetry; 272cdf0e10cSrcweir do 273cdf0e10cSrcweir { 274cdf0e10cSrcweir bRetry = false; 275cdf0e10cSrcweir try 276cdf0e10cSrcweir { 277cdf0e10cSrcweir DAVRequestHeaders aHeaders; 278cdf0e10cSrcweir getUserRequestHeaders( xEnv, 279cdf0e10cSrcweir getRequestURI(), 280cdf0e10cSrcweir rtl::OUString::createFromAscii( 281cdf0e10cSrcweir "PROPPATCH" ), 282cdf0e10cSrcweir aHeaders ); 283cdf0e10cSrcweir 284cdf0e10cSrcweir m_xSession->PROPPATCH( getRequestURI(), 285cdf0e10cSrcweir rValues, 286cdf0e10cSrcweir DAVRequestEnvironment( 287cdf0e10cSrcweir getRequestURI(), 288cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 289cdf0e10cSrcweir aHeaders, xEnv ) ); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir catch ( DAVException & e ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir errorCount++; 294cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 295cdf0e10cSrcweir if ( !bRetry ) 296cdf0e10cSrcweir throw; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir while ( bRetry ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir //========================================================================= 303cdf0e10cSrcweir void DAVResourceAccess::HEAD( 304cdf0e10cSrcweir const std::vector< rtl::OUString > & rHeaderNames, 305cdf0e10cSrcweir DAVResource & rResource, 306cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 307cdf0e10cSrcweir throw( DAVException ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir initialize(); 310cdf0e10cSrcweir 311cdf0e10cSrcweir int errorCount = 0; 312cdf0e10cSrcweir bool bRetry; 313cdf0e10cSrcweir do 314cdf0e10cSrcweir { 315cdf0e10cSrcweir bRetry = false; 316cdf0e10cSrcweir try 317cdf0e10cSrcweir { 318cdf0e10cSrcweir DAVRequestHeaders aHeaders; 319cdf0e10cSrcweir getUserRequestHeaders( xEnv, 320cdf0e10cSrcweir getRequestURI(), 321cdf0e10cSrcweir rtl::OUString::createFromAscii( "HEAD" ), 322cdf0e10cSrcweir aHeaders ); 323cdf0e10cSrcweir 324cdf0e10cSrcweir m_xSession->HEAD( getRequestURI(), 325cdf0e10cSrcweir rHeaderNames, 326cdf0e10cSrcweir rResource, 327cdf0e10cSrcweir DAVRequestEnvironment( 328cdf0e10cSrcweir getRequestURI(), 329cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 330cdf0e10cSrcweir aHeaders, xEnv ) ); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir catch ( DAVException & e ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir errorCount++; 335cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 336cdf0e10cSrcweir if ( !bRetry ) 337cdf0e10cSrcweir throw; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir } 340cdf0e10cSrcweir while ( bRetry ); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir //========================================================================= 344cdf0e10cSrcweir uno::Reference< io::XInputStream > DAVResourceAccess::GET( 345cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 346cdf0e10cSrcweir throw( DAVException ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir initialize(); 349cdf0e10cSrcweir 350cdf0e10cSrcweir uno::Reference< io::XInputStream > xStream; 351cdf0e10cSrcweir int errorCount = 0; 352cdf0e10cSrcweir bool bRetry; 353cdf0e10cSrcweir do 354cdf0e10cSrcweir { 355cdf0e10cSrcweir bRetry = false; 356cdf0e10cSrcweir try 357cdf0e10cSrcweir { 358cdf0e10cSrcweir DAVRequestHeaders aHeaders; 359cdf0e10cSrcweir getUserRequestHeaders( xEnv, 360cdf0e10cSrcweir getRequestURI(), 361cdf0e10cSrcweir rtl::OUString::createFromAscii( "GET" ), 362cdf0e10cSrcweir aHeaders ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir xStream = m_xSession->GET( getRequestURI(), 365cdf0e10cSrcweir DAVRequestEnvironment( 366cdf0e10cSrcweir getRequestURI(), 367cdf0e10cSrcweir new DAVAuthListener_Impl( 368cdf0e10cSrcweir xEnv, m_aURL ), 369cdf0e10cSrcweir aHeaders, xEnv ) ); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir catch ( DAVException & e ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir errorCount++; 374cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 375cdf0e10cSrcweir if ( !bRetry ) 376cdf0e10cSrcweir throw; 377cdf0e10cSrcweir } 378cdf0e10cSrcweir } 379cdf0e10cSrcweir while ( bRetry ); 380cdf0e10cSrcweir 381cdf0e10cSrcweir return xStream; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir //========================================================================= 385cdf0e10cSrcweir void DAVResourceAccess::GET( 386cdf0e10cSrcweir uno::Reference< io::XOutputStream > & rStream, 387cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 388cdf0e10cSrcweir throw( DAVException ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir initialize(); 391cdf0e10cSrcweir 392cdf0e10cSrcweir int errorCount = 0; 393cdf0e10cSrcweir bool bRetry; 394cdf0e10cSrcweir do 395cdf0e10cSrcweir { 396cdf0e10cSrcweir bRetry = false; 397cdf0e10cSrcweir try 398cdf0e10cSrcweir { 399cdf0e10cSrcweir DAVRequestHeaders aHeaders; 400cdf0e10cSrcweir getUserRequestHeaders( xEnv, 401cdf0e10cSrcweir getRequestURI(), 402cdf0e10cSrcweir rtl::OUString::createFromAscii( "GET" ), 403cdf0e10cSrcweir aHeaders ); 404cdf0e10cSrcweir 405cdf0e10cSrcweir m_xSession->GET( getRequestURI(), 406cdf0e10cSrcweir rStream, 407cdf0e10cSrcweir DAVRequestEnvironment( 408cdf0e10cSrcweir getRequestURI(), 409cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 410cdf0e10cSrcweir aHeaders, xEnv ) ); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir catch ( DAVException & e ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir errorCount++; 415cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 416cdf0e10cSrcweir if ( !bRetry ) 417cdf0e10cSrcweir throw; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } 420cdf0e10cSrcweir while ( bRetry ); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir //========================================================================= 424cdf0e10cSrcweir uno::Reference< io::XInputStream > DAVResourceAccess::GET( 425cdf0e10cSrcweir const std::vector< rtl::OUString > & rHeaderNames, 426cdf0e10cSrcweir DAVResource & rResource, 427cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 428cdf0e10cSrcweir throw( DAVException ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir initialize(); 431cdf0e10cSrcweir 432cdf0e10cSrcweir uno::Reference< io::XInputStream > xStream; 433cdf0e10cSrcweir int errorCount = 0; 434cdf0e10cSrcweir bool bRetry; 435cdf0e10cSrcweir do 436cdf0e10cSrcweir { 437cdf0e10cSrcweir bRetry = false; 438cdf0e10cSrcweir try 439cdf0e10cSrcweir { 440cdf0e10cSrcweir DAVRequestHeaders aHeaders; 441cdf0e10cSrcweir getUserRequestHeaders( xEnv, 442cdf0e10cSrcweir getRequestURI(), 443cdf0e10cSrcweir rtl::OUString::createFromAscii( "GET" ), 444cdf0e10cSrcweir aHeaders ); 445cdf0e10cSrcweir 446cdf0e10cSrcweir xStream = m_xSession->GET( getRequestURI(), 447cdf0e10cSrcweir rHeaderNames, 448cdf0e10cSrcweir rResource, 449cdf0e10cSrcweir DAVRequestEnvironment( 450cdf0e10cSrcweir getRequestURI(), 451cdf0e10cSrcweir new DAVAuthListener_Impl( 452cdf0e10cSrcweir xEnv, m_aURL ), 453cdf0e10cSrcweir aHeaders, xEnv ) ); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir catch ( DAVException & e ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir errorCount++; 458cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 459cdf0e10cSrcweir if ( !bRetry ) 460cdf0e10cSrcweir throw; 461cdf0e10cSrcweir } 462cdf0e10cSrcweir } 463cdf0e10cSrcweir while ( bRetry ); 464cdf0e10cSrcweir 465cdf0e10cSrcweir return xStream; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir //========================================================================= 469cdf0e10cSrcweir void DAVResourceAccess::GET( 470cdf0e10cSrcweir uno::Reference< io::XOutputStream > & rStream, 471cdf0e10cSrcweir const std::vector< rtl::OUString > & rHeaderNames, 472cdf0e10cSrcweir DAVResource & rResource, 473cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 474cdf0e10cSrcweir throw( DAVException ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir initialize(); 477cdf0e10cSrcweir 478cdf0e10cSrcweir bool bRetry; 479cdf0e10cSrcweir int errorCount = 0; 480cdf0e10cSrcweir do 481cdf0e10cSrcweir { 482cdf0e10cSrcweir bRetry = false; 483cdf0e10cSrcweir try 484cdf0e10cSrcweir { 485cdf0e10cSrcweir DAVRequestHeaders aHeaders; 486cdf0e10cSrcweir getUserRequestHeaders( xEnv, 487cdf0e10cSrcweir getRequestURI(), 488cdf0e10cSrcweir rtl::OUString::createFromAscii( "GET" ), 489cdf0e10cSrcweir aHeaders ); 490cdf0e10cSrcweir 491cdf0e10cSrcweir m_xSession->GET( getRequestURI(), 492cdf0e10cSrcweir rStream, 493cdf0e10cSrcweir rHeaderNames, 494cdf0e10cSrcweir rResource, 495cdf0e10cSrcweir DAVRequestEnvironment( 496cdf0e10cSrcweir getRequestURI(), 497cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 498cdf0e10cSrcweir aHeaders, xEnv ) ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir catch ( DAVException & e ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir errorCount++; 503cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 504cdf0e10cSrcweir if ( !bRetry ) 505cdf0e10cSrcweir throw; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir } 508cdf0e10cSrcweir while ( bRetry ); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir //========================================================================= 512cdf0e10cSrcweir void DAVResourceAccess::abort() 513cdf0e10cSrcweir throw( DAVException ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir // 17.11.09 (tkr): abort currently disabled caused by issue i106766 516cdf0e10cSrcweir // initialize(); 517cdf0e10cSrcweir // m_xSession->abort(); 518cdf0e10cSrcweir OSL_TRACE( "Not implemented. -> #i106766#" ); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir //========================================================================= 522cdf0e10cSrcweir namespace { 523cdf0e10cSrcweir 524cdf0e10cSrcweir void resetInputStream( const uno::Reference< io::XInputStream > & rStream ) 525cdf0e10cSrcweir throw( DAVException ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir try 528cdf0e10cSrcweir { 529cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekable( 530cdf0e10cSrcweir rStream, uno::UNO_QUERY ); 531cdf0e10cSrcweir if ( xSeekable.is() ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir xSeekable->seek( 0 ); 534cdf0e10cSrcweir return; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir } 537cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir } 540cdf0e10cSrcweir catch ( io::IOException const & ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir throw DAVException( DAVException::DAV_INVALID_ARG ); 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir } // namespace 548cdf0e10cSrcweir 549cdf0e10cSrcweir //========================================================================= 550cdf0e10cSrcweir void DAVResourceAccess::PUT( 551cdf0e10cSrcweir const uno::Reference< io::XInputStream > & rStream, 552cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 553cdf0e10cSrcweir throw( DAVException ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir initialize(); 556cdf0e10cSrcweir 557cdf0e10cSrcweir // Make stream seekable, if it not. Needed, if request must be retried. 558cdf0e10cSrcweir uno::Reference< io::XInputStream > xSeekableStream 559cdf0e10cSrcweir = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( 560cdf0e10cSrcweir rStream, m_xSMgr ); 561cdf0e10cSrcweir 562cdf0e10cSrcweir int errorCount = 0; 563cdf0e10cSrcweir bool bRetry = false; 564cdf0e10cSrcweir do 565cdf0e10cSrcweir { 566cdf0e10cSrcweir if ( bRetry ) 567cdf0e10cSrcweir resetInputStream( xSeekableStream ); 568cdf0e10cSrcweir 569cdf0e10cSrcweir bRetry = false; 570cdf0e10cSrcweir try 571cdf0e10cSrcweir { 572cdf0e10cSrcweir DAVRequestHeaders aHeaders; 573cdf0e10cSrcweir getUserRequestHeaders( xEnv, 574cdf0e10cSrcweir getRequestURI(), 575cdf0e10cSrcweir rtl::OUString::createFromAscii( "PUT" ), 576cdf0e10cSrcweir aHeaders ); 577cdf0e10cSrcweir 578cdf0e10cSrcweir m_xSession->PUT( getRequestURI(), 579cdf0e10cSrcweir xSeekableStream, 580cdf0e10cSrcweir DAVRequestEnvironment( 581cdf0e10cSrcweir getRequestURI(), 582cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 583cdf0e10cSrcweir aHeaders, xEnv ) ); 584cdf0e10cSrcweir } 585cdf0e10cSrcweir catch ( DAVException & e ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir errorCount++; 588cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 589cdf0e10cSrcweir if ( !bRetry ) 590cdf0e10cSrcweir throw; 591cdf0e10cSrcweir } 592cdf0e10cSrcweir } 593cdf0e10cSrcweir while ( bRetry ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir 596cdf0e10cSrcweir //========================================================================= 597cdf0e10cSrcweir uno::Reference< io::XInputStream > DAVResourceAccess::POST( 598cdf0e10cSrcweir const rtl::OUString & rContentType, 599cdf0e10cSrcweir const rtl::OUString & rReferer, 600cdf0e10cSrcweir const uno::Reference< io::XInputStream > & rInputStream, 601cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 602cdf0e10cSrcweir throw ( DAVException ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir initialize(); 605cdf0e10cSrcweir 606cdf0e10cSrcweir // Make stream seekable, if it not. Needed, if request must be retried. 607cdf0e10cSrcweir uno::Reference< io::XInputStream > xSeekableStream 608cdf0e10cSrcweir = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( 609cdf0e10cSrcweir rInputStream, m_xSMgr ); 610cdf0e10cSrcweir 611cdf0e10cSrcweir uno::Reference< io::XInputStream > xStream; 612cdf0e10cSrcweir int errorCount = 0; 613cdf0e10cSrcweir bool bRetry = false; 614cdf0e10cSrcweir do 615cdf0e10cSrcweir { 616cdf0e10cSrcweir if ( bRetry ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir resetInputStream( xSeekableStream ); 619cdf0e10cSrcweir bRetry = false; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir try 623cdf0e10cSrcweir { 624cdf0e10cSrcweir DAVRequestHeaders aHeaders; 625cdf0e10cSrcweir getUserRequestHeaders( xEnv, 626cdf0e10cSrcweir getRequestURI(), 627cdf0e10cSrcweir rtl::OUString::createFromAscii( "POST" ), 628cdf0e10cSrcweir aHeaders ); 629cdf0e10cSrcweir 630cdf0e10cSrcweir xStream = m_xSession->POST( getRequestURI(), 631cdf0e10cSrcweir rContentType, 632cdf0e10cSrcweir rReferer, 633cdf0e10cSrcweir xSeekableStream, 634cdf0e10cSrcweir DAVRequestEnvironment( 635cdf0e10cSrcweir getRequestURI(), 636cdf0e10cSrcweir new DAVAuthListener_Impl( 637cdf0e10cSrcweir xEnv, m_aURL ), 638cdf0e10cSrcweir aHeaders, xEnv ) ); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir catch ( DAVException & e ) 641cdf0e10cSrcweir { 642cdf0e10cSrcweir errorCount++; 643cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 644cdf0e10cSrcweir if ( !bRetry ) 645cdf0e10cSrcweir throw; 646cdf0e10cSrcweir 647cdf0e10cSrcweir if ( e.getError() == DAVException::DAV_HTTP_REDIRECT ) 648cdf0e10cSrcweir { 649cdf0e10cSrcweir // #i74980# - Upon POST redirect, do a GET. 650cdf0e10cSrcweir return GET( xEnv ); 651cdf0e10cSrcweir } 652cdf0e10cSrcweir } 653cdf0e10cSrcweir } 654cdf0e10cSrcweir while ( bRetry ); 655cdf0e10cSrcweir 656cdf0e10cSrcweir return xStream; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir //========================================================================= 660cdf0e10cSrcweir void DAVResourceAccess::POST( 661cdf0e10cSrcweir const rtl::OUString & rContentType, 662cdf0e10cSrcweir const rtl::OUString & rReferer, 663cdf0e10cSrcweir const uno::Reference< io::XInputStream > & rInputStream, 664cdf0e10cSrcweir uno::Reference< io::XOutputStream > & rOutputStream, 665cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 666cdf0e10cSrcweir throw ( DAVException ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir initialize(); 669cdf0e10cSrcweir 670cdf0e10cSrcweir // Make stream seekable, if it not. Needed, if request must be retried. 671cdf0e10cSrcweir uno::Reference< io::XInputStream > xSeekableStream 672cdf0e10cSrcweir = comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( 673cdf0e10cSrcweir rInputStream, m_xSMgr ); 674cdf0e10cSrcweir 675cdf0e10cSrcweir int errorCount = 0; 676cdf0e10cSrcweir bool bRetry = false; 677cdf0e10cSrcweir do 678cdf0e10cSrcweir { 679cdf0e10cSrcweir if ( bRetry ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir resetInputStream( xSeekableStream ); 682cdf0e10cSrcweir bRetry = false; 683cdf0e10cSrcweir } 684cdf0e10cSrcweir 685cdf0e10cSrcweir try 686cdf0e10cSrcweir { 687cdf0e10cSrcweir DAVRequestHeaders aHeaders; 688cdf0e10cSrcweir getUserRequestHeaders( xEnv, 689cdf0e10cSrcweir getRequestURI(), 690cdf0e10cSrcweir rtl::OUString::createFromAscii( "POST" ), 691cdf0e10cSrcweir aHeaders ); 692cdf0e10cSrcweir 693cdf0e10cSrcweir m_xSession->POST( getRequestURI(), 694cdf0e10cSrcweir rContentType, 695cdf0e10cSrcweir rReferer, 696cdf0e10cSrcweir xSeekableStream, 697cdf0e10cSrcweir rOutputStream, 698cdf0e10cSrcweir DAVRequestEnvironment( 699cdf0e10cSrcweir getRequestURI(), 700cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 701cdf0e10cSrcweir aHeaders, xEnv ) ); 702cdf0e10cSrcweir } 703cdf0e10cSrcweir catch ( DAVException & e ) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir errorCount++; 706cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 707cdf0e10cSrcweir if ( !bRetry ) 708cdf0e10cSrcweir throw; 709cdf0e10cSrcweir 710cdf0e10cSrcweir if ( e.getError() == DAVException::DAV_HTTP_REDIRECT ) 711cdf0e10cSrcweir { 712cdf0e10cSrcweir // #i74980# - Upon POST redirect, do a GET. 713cdf0e10cSrcweir GET( rOutputStream, xEnv ); 714cdf0e10cSrcweir return; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir } 717cdf0e10cSrcweir } 718cdf0e10cSrcweir while ( bRetry ); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir //========================================================================= 722cdf0e10cSrcweir void DAVResourceAccess::MKCOL( 723cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 724cdf0e10cSrcweir throw( DAVException ) 725cdf0e10cSrcweir { 726cdf0e10cSrcweir initialize(); 727cdf0e10cSrcweir 728cdf0e10cSrcweir int errorCount = 0; 729cdf0e10cSrcweir bool bRetry; 730cdf0e10cSrcweir do 731cdf0e10cSrcweir { 732cdf0e10cSrcweir bRetry = false; 733cdf0e10cSrcweir try 734cdf0e10cSrcweir { 735cdf0e10cSrcweir DAVRequestHeaders aHeaders; 736cdf0e10cSrcweir getUserRequestHeaders( xEnv, 737cdf0e10cSrcweir getRequestURI(), 738cdf0e10cSrcweir rtl::OUString::createFromAscii( "MKCOL" ), 739cdf0e10cSrcweir aHeaders ); 740cdf0e10cSrcweir 741cdf0e10cSrcweir m_xSession->MKCOL( getRequestURI(), 742cdf0e10cSrcweir DAVRequestEnvironment( 743cdf0e10cSrcweir getRequestURI(), 744cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 745cdf0e10cSrcweir aHeaders, xEnv ) ); 746cdf0e10cSrcweir } 747cdf0e10cSrcweir catch ( DAVException & e ) 748cdf0e10cSrcweir { 749cdf0e10cSrcweir errorCount++; 750cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 751cdf0e10cSrcweir if ( !bRetry ) 752cdf0e10cSrcweir throw; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir } 755cdf0e10cSrcweir while ( bRetry ); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir //========================================================================= 759cdf0e10cSrcweir void DAVResourceAccess::COPY( 760cdf0e10cSrcweir const ::rtl::OUString & rSourcePath, 761cdf0e10cSrcweir const ::rtl::OUString & rDestinationURI, 762cdf0e10cSrcweir sal_Bool bOverwrite, 763cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 764cdf0e10cSrcweir throw( DAVException ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir initialize(); 767cdf0e10cSrcweir 768cdf0e10cSrcweir int errorCount = 0; 769cdf0e10cSrcweir bool bRetry; 770cdf0e10cSrcweir do 771cdf0e10cSrcweir { 772cdf0e10cSrcweir bRetry = false; 773cdf0e10cSrcweir try 774cdf0e10cSrcweir { 775cdf0e10cSrcweir DAVRequestHeaders aHeaders; 776cdf0e10cSrcweir getUserRequestHeaders( xEnv, 777cdf0e10cSrcweir getRequestURI(), 778cdf0e10cSrcweir rtl::OUString::createFromAscii( "COPY" ), 779cdf0e10cSrcweir aHeaders ); 780cdf0e10cSrcweir 781cdf0e10cSrcweir m_xSession->COPY( rSourcePath, 782cdf0e10cSrcweir rDestinationURI, 783cdf0e10cSrcweir DAVRequestEnvironment( 784cdf0e10cSrcweir getRequestURI(), 785cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 786cdf0e10cSrcweir aHeaders, xEnv ), 787cdf0e10cSrcweir bOverwrite ); 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::MOVE( 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(), 820cdf0e10cSrcweir rtl::OUString::createFromAscii( "MOVE" ), 821cdf0e10cSrcweir aHeaders ); 822cdf0e10cSrcweir 823cdf0e10cSrcweir m_xSession->MOVE( 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::DESTROY( 844cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 845cdf0e10cSrcweir throw( DAVException ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir initialize(); 848cdf0e10cSrcweir 849cdf0e10cSrcweir int errorCount = 0; 850cdf0e10cSrcweir bool bRetry; 851cdf0e10cSrcweir do 852cdf0e10cSrcweir { 853cdf0e10cSrcweir bRetry = false; 854cdf0e10cSrcweir try 855cdf0e10cSrcweir { 856cdf0e10cSrcweir DAVRequestHeaders aHeaders; 857cdf0e10cSrcweir getUserRequestHeaders( xEnv, 858cdf0e10cSrcweir getRequestURI(), 859cdf0e10cSrcweir rtl::OUString::createFromAscii( 860cdf0e10cSrcweir "DESTROY" ), 861cdf0e10cSrcweir aHeaders ); 862cdf0e10cSrcweir 863cdf0e10cSrcweir m_xSession->DESTROY( getRequestURI(), 864cdf0e10cSrcweir DAVRequestEnvironment( 865cdf0e10cSrcweir getRequestURI(), 866cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 867cdf0e10cSrcweir aHeaders, xEnv ) ); 868cdf0e10cSrcweir } 869cdf0e10cSrcweir catch ( DAVException & e ) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir errorCount++; 872cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 873cdf0e10cSrcweir if ( !bRetry ) 874cdf0e10cSrcweir throw; 875cdf0e10cSrcweir } 876cdf0e10cSrcweir } 877cdf0e10cSrcweir while ( bRetry ); 878cdf0e10cSrcweir } 879cdf0e10cSrcweir 880cdf0e10cSrcweir //========================================================================= 881cdf0e10cSrcweir // set new lock. 882cdf0e10cSrcweir void DAVResourceAccess::LOCK( 883cdf0e10cSrcweir ucb::Lock & inLock, 884cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 885cdf0e10cSrcweir throw ( DAVException ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir initialize(); 888cdf0e10cSrcweir 889cdf0e10cSrcweir int errorCount = 0; 890cdf0e10cSrcweir bool bRetry; 891cdf0e10cSrcweir do 892cdf0e10cSrcweir { 893cdf0e10cSrcweir bRetry = false; 894cdf0e10cSrcweir try 895cdf0e10cSrcweir { 896cdf0e10cSrcweir DAVRequestHeaders aHeaders; 897cdf0e10cSrcweir getUserRequestHeaders( xEnv, 898cdf0e10cSrcweir getRequestURI(), 899cdf0e10cSrcweir rtl::OUString::createFromAscii( "LOCK" ), 900cdf0e10cSrcweir aHeaders ); 901cdf0e10cSrcweir 902cdf0e10cSrcweir m_xSession->LOCK( getRequestURI(), 903cdf0e10cSrcweir inLock, 904cdf0e10cSrcweir DAVRequestEnvironment( 905cdf0e10cSrcweir getRequestURI(), 906cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 907cdf0e10cSrcweir aHeaders, xEnv ) ); 908cdf0e10cSrcweir } 909cdf0e10cSrcweir catch ( DAVException & e ) 910cdf0e10cSrcweir { 911cdf0e10cSrcweir errorCount++; 912cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 913cdf0e10cSrcweir if ( !bRetry ) 914cdf0e10cSrcweir throw; 915cdf0e10cSrcweir } 916cdf0e10cSrcweir } 917cdf0e10cSrcweir while ( bRetry ); 918cdf0e10cSrcweir } 919cdf0e10cSrcweir 920cdf0e10cSrcweir #if 0 // currently not used, but please don't remove code 921cdf0e10cSrcweir //========================================================================= 922cdf0e10cSrcweir // refresh existing lock. 923cdf0e10cSrcweir sal_Int64 DAVResourceAccess::LOCK( 924cdf0e10cSrcweir sal_Int64 nTimeout, 925cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 926cdf0e10cSrcweir throw ( DAVException ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir initialize(); 929cdf0e10cSrcweir 930cdf0e10cSrcweir sal_Int64 nNewTimeout = 0; 931cdf0e10cSrcweir int errorCount = 0; 932cdf0e10cSrcweir bool bRetry; 933cdf0e10cSrcweir do 934cdf0e10cSrcweir { 935cdf0e10cSrcweir bRetry = false; 936cdf0e10cSrcweir try 937cdf0e10cSrcweir { 938cdf0e10cSrcweir DAVRequestHeaders aHeaders; 939cdf0e10cSrcweir getUserRequestHeaders( xEnv, 940cdf0e10cSrcweir getRequestURI(), 941cdf0e10cSrcweir rtl::OUString::createFromAscii( "LOCK" ), 942cdf0e10cSrcweir aHeaders ); 943cdf0e10cSrcweir 944cdf0e10cSrcweir nNewTimeout = m_xSession->LOCK( getRequestURI(), 945cdf0e10cSrcweir nTimeout, 946cdf0e10cSrcweir DAVRequestEnvironment( 947cdf0e10cSrcweir getRequestURI(), 948cdf0e10cSrcweir new DAVAuthListener_Impl( 949cdf0e10cSrcweir xEnv, m_aURL ), 950cdf0e10cSrcweir aHeaders, xEnv ) ); 951cdf0e10cSrcweir } 952cdf0e10cSrcweir catch ( DAVException & e ) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir errorCount++; 955cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 956cdf0e10cSrcweir if ( !bRetry ) 957cdf0e10cSrcweir throw; 958cdf0e10cSrcweir } 959cdf0e10cSrcweir } 960cdf0e10cSrcweir while ( bRetry ); 961cdf0e10cSrcweir 962cdf0e10cSrcweir return nNewTimeout; 963cdf0e10cSrcweir } 964cdf0e10cSrcweir #endif 965cdf0e10cSrcweir 966cdf0e10cSrcweir //========================================================================= 967cdf0e10cSrcweir void DAVResourceAccess::UNLOCK( 968cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 969cdf0e10cSrcweir throw ( DAVException ) 970cdf0e10cSrcweir { 971cdf0e10cSrcweir initialize(); 972cdf0e10cSrcweir 973cdf0e10cSrcweir int errorCount = 0; 974cdf0e10cSrcweir bool bRetry; 975cdf0e10cSrcweir do 976cdf0e10cSrcweir { 977cdf0e10cSrcweir bRetry = false; 978cdf0e10cSrcweir try 979cdf0e10cSrcweir { 980cdf0e10cSrcweir DAVRequestHeaders aHeaders; 981cdf0e10cSrcweir getUserRequestHeaders( xEnv, 982cdf0e10cSrcweir getRequestURI(), 983cdf0e10cSrcweir rtl::OUString::createFromAscii( "UNLOCK" ), 984cdf0e10cSrcweir aHeaders ); 985cdf0e10cSrcweir 986cdf0e10cSrcweir m_xSession->UNLOCK( getRequestURI(), 987cdf0e10cSrcweir DAVRequestEnvironment( 988cdf0e10cSrcweir getRequestURI(), 989cdf0e10cSrcweir new DAVAuthListener_Impl( xEnv, m_aURL ), 990cdf0e10cSrcweir aHeaders, xEnv ) ); 991cdf0e10cSrcweir } 992cdf0e10cSrcweir catch ( DAVException & e ) 993cdf0e10cSrcweir { 994cdf0e10cSrcweir errorCount++; 995cdf0e10cSrcweir bRetry = handleException( e, errorCount ); 996cdf0e10cSrcweir if ( !bRetry ) 997cdf0e10cSrcweir throw; 998cdf0e10cSrcweir } 999cdf0e10cSrcweir } 1000cdf0e10cSrcweir while ( bRetry ); 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir //========================================================================= 1004cdf0e10cSrcweir void DAVResourceAccess::setURL( const rtl::OUString & rNewURL ) 1005cdf0e10cSrcweir throw( DAVException ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1008cdf0e10cSrcweir m_aURL = rNewURL; 1009cdf0e10cSrcweir m_aPath = rtl::OUString(); // Next initialize() will create new session. 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir //========================================================================= 1013cdf0e10cSrcweir // init dav session and path 1014cdf0e10cSrcweir void DAVResourceAccess::initialize() 1015cdf0e10cSrcweir throw ( DAVException ) 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1018cdf0e10cSrcweir if ( m_aPath.getLength() == 0 ) 1019cdf0e10cSrcweir { 102059ddfc10SAndre Fischer SerfUri aURI( m_aURL ); 1021cdf0e10cSrcweir rtl::OUString aPath( aURI.GetPath() ); 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir /* #134089# - Check URI */ 1024cdf0e10cSrcweir if ( !aPath.getLength() ) 1025cdf0e10cSrcweir throw DAVException( DAVException::DAV_INVALID_ARG ); 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir /* #134089# - Check URI */ 1028cdf0e10cSrcweir if ( !aURI.GetHost().getLength() ) 1029cdf0e10cSrcweir throw DAVException( DAVException::DAV_INVALID_ARG ); 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir if ( !m_xSession.is() || !m_xSession->CanUse( m_aURL ) ) 1032cdf0e10cSrcweir { 1033cdf0e10cSrcweir m_xSession.clear(); 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir // create new webdav session 1036cdf0e10cSrcweir m_xSession 1037cdf0e10cSrcweir = m_xSessionFactory->createDAVSession( m_aURL, m_xSMgr ); 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir if ( !m_xSession.is() ) 1040cdf0e10cSrcweir return; 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir // Own URI is needed for redirect cycle detection. 1044cdf0e10cSrcweir m_aRedirectURIs.push_back( aURI ); 1045cdf0e10cSrcweir 1046cdf0e10cSrcweir // Success. 1047cdf0e10cSrcweir m_aPath = aPath; 1048cdf0e10cSrcweir 1049cdf0e10cSrcweir // Not only the path has to be encoded 1050cdf0e10cSrcweir m_aURL = aURI.GetURI(); 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir } 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir //========================================================================= 1055cdf0e10cSrcweir const rtl::OUString & DAVResourceAccess::getRequestURI() const 1056cdf0e10cSrcweir { 1057cdf0e10cSrcweir OSL_ENSURE( m_xSession.is(), 1058cdf0e10cSrcweir "DAVResourceAccess::getRequestURI - Not initialized!" ); 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir // In case a proxy is used we have to use the absolute URI for a request. 1061cdf0e10cSrcweir if ( m_xSession->UsesProxy() ) 1062cdf0e10cSrcweir return m_aURL; 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir return m_aPath; 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir //========================================================================= 1068cdf0e10cSrcweir // static 1069cdf0e10cSrcweir void DAVResourceAccess::getUserRequestHeaders( 1070cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv, 1071cdf0e10cSrcweir const rtl::OUString & rURI, 1072cdf0e10cSrcweir const rtl::OUString & rMethod, 1073cdf0e10cSrcweir DAVRequestHeaders & rRequestHeaders ) 1074cdf0e10cSrcweir { 1075cdf0e10cSrcweir if ( xEnv.is() ) 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir uno::Reference< ucb::XWebDAVCommandEnvironment > xDAVEnv( 1078cdf0e10cSrcweir xEnv, uno::UNO_QUERY ); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir if ( xDAVEnv.is() ) 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aRequestHeaders 1083cdf0e10cSrcweir = xDAVEnv->getUserRequestHeaders( rURI, rMethod ); 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aRequestHeaders.getLength(); ++n ) 1086cdf0e10cSrcweir { 1087cdf0e10cSrcweir rtl::OUString aValue; 1088cdf0e10cSrcweir sal_Bool isString = aRequestHeaders[ n ].Value >>= aValue; 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir if ( !isString ) 1091cdf0e10cSrcweir { 1092cdf0e10cSrcweir OSL_ENSURE( isString, 1093cdf0e10cSrcweir "DAVResourceAccess::getUserRequestHeaders :" 1094cdf0e10cSrcweir "Value is not a string! Ignoring..." ); 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir rRequestHeaders.push_back( 1098cdf0e10cSrcweir DAVRequestHeader( aRequestHeaders[ n ].Name, aValue ) ); 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir } 1101cdf0e10cSrcweir } 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir //========================================================================= 1105cdf0e10cSrcweir sal_Bool DAVResourceAccess::detectRedirectCycle( 1106cdf0e10cSrcweir const rtl::OUString& rRedirectURL ) 1107cdf0e10cSrcweir throw ( DAVException ) 1108cdf0e10cSrcweir { 1109cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1110cdf0e10cSrcweir 111159ddfc10SAndre Fischer SerfUri aUri( rRedirectURL ); 1112cdf0e10cSrcweir 111359ddfc10SAndre Fischer std::vector< SerfUri >::const_iterator it = m_aRedirectURIs.begin(); 111459ddfc10SAndre Fischer std::vector< SerfUri >::const_iterator end = m_aRedirectURIs.end(); 1115cdf0e10cSrcweir 1116cdf0e10cSrcweir while ( it != end ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir if ( aUri == (*it) ) 1119cdf0e10cSrcweir return sal_True; 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir it++; 1122cdf0e10cSrcweir } 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir return sal_False; 1125cdf0e10cSrcweir } 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir //========================================================================= 1128cdf0e10cSrcweir void DAVResourceAccess::resetUri() 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1131cdf0e10cSrcweir if ( m_aRedirectURIs.size() > 0 ) 1132cdf0e10cSrcweir { 113359ddfc10SAndre Fischer std::vector< SerfUri >::const_iterator it = m_aRedirectURIs.begin(); 1134cdf0e10cSrcweir 113559ddfc10SAndre Fischer SerfUri aUri( (*it) ); 1136cdf0e10cSrcweir m_aRedirectURIs.clear(); 1137cdf0e10cSrcweir setURL ( aUri.GetURI() ); 1138cdf0e10cSrcweir initialize(); 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir } 1141cdf0e10cSrcweir 1142cdf0e10cSrcweir //========================================================================= 1143cdf0e10cSrcweir sal_Bool DAVResourceAccess::handleException( DAVException & e, int errorCount ) 1144cdf0e10cSrcweir throw ( DAVException ) 1145cdf0e10cSrcweir { 1146cdf0e10cSrcweir switch ( e.getError() ) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir case DAVException::DAV_HTTP_REDIRECT: 1149cdf0e10cSrcweir if ( !detectRedirectCycle( e.getData() ) ) 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir // set new URL and path. 1152cdf0e10cSrcweir setURL( e.getData() ); 1153cdf0e10cSrcweir initialize(); 1154cdf0e10cSrcweir return sal_True; 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir return sal_False; 1157cdf0e10cSrcweir // --> tkr #67048# copy & paste images doesn't display. 1158cdf0e10cSrcweir // if we have a bad connection try again. Up to three times. 1159cdf0e10cSrcweir case DAVException::DAV_HTTP_ERROR: 1160cdf0e10cSrcweir // retry up to three times, if not a client-side error. 1161cdf0e10cSrcweir if ( ( e.getStatus() < 400 || e.getStatus() >= 500 ) && 1162cdf0e10cSrcweir errorCount < 3 ) 1163cdf0e10cSrcweir { 1164cdf0e10cSrcweir return sal_True; 1165cdf0e10cSrcweir } 1166cdf0e10cSrcweir return sal_False; 1167cdf0e10cSrcweir // <-- 1168cdf0e10cSrcweir // --> tkr: if connection has said retry then retry! 1169cdf0e10cSrcweir case DAVException::DAV_HTTP_RETRY: 1170cdf0e10cSrcweir return sal_True; 1171cdf0e10cSrcweir // <-- 1172cdf0e10cSrcweir default: 1173cdf0e10cSrcweir return sal_False; // Abort 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir } 1176