From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/misc/simplefileaccessinteraction.cxx | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 comphelper/source/misc/simplefileaccessinteraction.cxx (limited to 'comphelper/source/misc/simplefileaccessinteraction.cxx') diff --git a/comphelper/source/misc/simplefileaccessinteraction.cxx b/comphelper/source/misc/simplefileaccessinteraction.cxx new file mode 100644 index 000000000..8cd77af7d --- /dev/null +++ b/comphelper/source/misc/simplefileaccessinteraction.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace comphelper +{ +/// Will handle com::sun::star::ucb::InteractiveIOException and derived classes +const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0; +/// Will handle com::sun::star::ucb::UnsupportedDataSinkException +const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1; +/// Will handle com::sun::star::ucb::InteractiveNetworkException +const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION = 2; +/// Will handle com::sun::star::ucb::CertificateValidationRequest +const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3; +/// Will handle com::sun::star::ucb::AuthenticationRequest +const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4; + +SimpleFileAccessInteraction::SimpleFileAccessInteraction( + const css::uno::Reference& xHandler) +{ + std::vector<::ucbhelper::InterceptedInteraction::InterceptedRequest> lInterceptions{ + { //intercept standard IO error exception (local file and WebDAV) + css::uno::Any(css::ucb::InteractiveIOException()), + cppu::UnoType::get(), HANDLE_INTERACTIVEIOEXCEPTION }, + { //intercept internal error + css::uno::Any(css::ucb::UnsupportedDataSinkException()), + cppu::UnoType::get(), HANDLE_UNSUPPORTEDDATASINKEXCEPTION }, + { + //intercept network error exception (WebDAV ucp provider) + css::uno::Any(css::ucb::InteractiveNetworkException()), + cppu::UnoType::get(), + HANDLE_INTERACTIVENETWORKEXCEPTION, + }, + { //intercept certificate validation request (WebDAV ucp provider) + css::uno::Any(css::ucb::CertificateValidationRequest()), + cppu::UnoType::get(), HANDLE_CERTIFICATEREQUEST }, + { //intercept authentication request (WebDAV ucp provider) + css::uno::Any(css::ucb::AuthenticationRequest()), + cppu::UnoType::get(), HANDLE_AUTHENTICATIONREQUEST } + }; + + setInterceptedHandler(xHandler); + setInterceptions(std::move(lInterceptions)); +} + +SimpleFileAccessInteraction::~SimpleFileAccessInteraction() {} + +ucbhelper::InterceptedInteraction::EInterceptionState SimpleFileAccessInteraction::intercepted( + const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest, + const css::uno::Reference& xRequest) +{ + bool bAbort = false; + switch (aRequest.Handle) + { + case HANDLE_UNSUPPORTEDDATASINKEXCEPTION: + case HANDLE_INTERACTIVENETWORKEXCEPTION: + case HANDLE_INTERACTIVEIOEXCEPTION: + { + bAbort = true; + } + break; + + case HANDLE_CERTIFICATEREQUEST: + { + // use default internal handler. + if (m_xInterceptedHandler.is()) + { + m_xInterceptedHandler->handle(xRequest); + return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; + } + else + bAbort = true; + break; + } + + case HANDLE_AUTHENTICATIONREQUEST: + { + // use default internal handler. + if (m_xInterceptedHandler.is()) + { + m_xInterceptedHandler->handle(xRequest); + return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; + } + else //simply abort + bAbort = true; + } + break; + } + + // handle interaction by ourself, by not doing + // any selection... + if (bAbort) + { + css::uno::Reference xAbort + = ::ucbhelper::InterceptedInteraction::extractContinuation( + xRequest->getContinuations(), cppu::UnoType::get()); + if (!xAbort.is()) + return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND; + return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; + } + + return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3