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