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