summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorGiuseppe Castagno <giuseppe.castagno@acca-esse.eu>2016-04-19 08:23:23 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-04-22 07:11:31 +0000
commitbbe51f039dffca2506ea542feb78571b6358b981 (patch)
treed85e031db6c9ff34e67c9d06f947d2d441545cd2 /comphelper
parent608b8cc54e4e1728dec97fc7c27beb587cfbabcf (diff)
Add an interaction handler wrapper for simple file access.
This wrapper is to be used when you want to avoid the error messages displayed when accessing a file (the messages activated by ucphelper::cancelCommandExecution), especially when accessing a Web/DAV connection to enable https certificate validation and optionally enabling the authentication dialog that may be needed in these operations. Change-Id: I19f3072b91b6c4f453a54b56a3d9883b3383dfa5 Reviewed-on: https://gerrit.libreoffice.org/24274 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/Library_comphelper.mk1
-rw-r--r--comphelper/source/misc/simplefileaccessinteraction.cxx140
2 files changed, 141 insertions, 0 deletions
diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index 7047d8a37e36..4d4e7345298d 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -111,6 +111,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/misc/servicedecl \
comphelper/source/misc/serviceinfohelper \
comphelper/source/misc/sharedmutex \
+ comphelper/source/misc/simplefileaccessinteraction \
comphelper/source/misc/solarmutex \
comphelper/source/misc/stillreadwriteinteraction \
comphelper/source/misc/anycompare \
diff --git a/comphelper/source/misc/simplefileaccessinteraction.cxx b/comphelper/source/misc/simplefileaccessinteraction.cxx
new file mode 100644
index 000000000000..c513d4912a8e
--- /dev/null
+++ b/comphelper/source/misc/simplefileaccessinteraction.cxx
@@ -0,0 +1,140 @@
+/* -*- 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 <comphelper/simplefileaccessinteraction.hxx>
+#include <com/sun/star/task/XInteractionAbort.hpp>
+#include <com/sun/star/task/XInteractionApprove.hpp>
+#include <com/sun/star/ucb/AuthenticationRequest.hpp>
+#include <com/sun/star/ucb/CertificateValidationRequest.hpp>
+#include <com/sun/star/ucb/InteractiveIOException.hpp>
+#include <com/sun/star/ucb/InteractiveNetworkException.hpp>
+#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
+
+namespace comphelper {
+
+/// Will handle com::sun::star::ucb::InteractiveIOException and derived classes
+static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION = 0;
+/// Will handle com::sun::star::ucb::UnsupportedDataSinkException
+static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
+/// Will handle com::sun::star::ucb::InteractiveNetworkException
+static const sal_Int32 HANDLE_INTERACTIVENETWORKEXCEPTION = 2;
+/// Will handle com::sun::star::ucb::CertificateValidationRequest
+static const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
+/// Will handle com::sun::star::ucb::AuthenticationRequest
+static const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4;
+
+SimpleFileAccessInteraction::SimpleFileAccessInteraction(
+ const css::uno::Reference< css::task::XInteractionHandler >& xHandler )
+{
+ ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
+ ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
+
+ //intercept standard IO error exception (local file and WebDAV)
+ aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
+ aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
+ aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+ aInterceptedRequest.MatchExact = false;
+ lInterceptions.push_back(aInterceptedRequest);
+
+ //intercept internal error
+ aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
+ aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
+ aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+ aInterceptedRequest.MatchExact = false;
+ lInterceptions.push_back(aInterceptedRequest);
+
+ //intercept network error exception (WebDAV ucp provider)
+ aInterceptedRequest.Handle = HANDLE_INTERACTIVENETWORKEXCEPTION;
+ aInterceptedRequest.Request <<= css::ucb::InteractiveNetworkException();
+ aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+ aInterceptedRequest.MatchExact = false;
+ lInterceptions.push_back(aInterceptedRequest);
+
+ //intercept certificate validation request (WebDAV ucp provider)
+ aInterceptedRequest.Handle = HANDLE_CERTIFICATEREQUEST;
+ aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
+ aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionAbort>::get();
+ aInterceptedRequest.MatchExact = false;
+ lInterceptions.push_back(aInterceptedRequest);
+
+ //intercept authentication request (WebDAV ucp provider)
+ aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUEST;
+ aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
+ aInterceptedRequest.Continuation = cppu::UnoType<css::task::XInteractionApprove>::get();
+ aInterceptedRequest.MatchExact = false;
+ lInterceptions.push_back(aInterceptedRequest);
+
+ setInterceptedHandler(xHandler);
+ setInterceptions(lInterceptions);
+}
+
+SimpleFileAccessInteraction::~SimpleFileAccessInteraction()
+{
+}
+
+ucbhelper::InterceptedInteraction::EInterceptionState SimpleFileAccessInteraction::intercepted(
+ const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
+ const css::uno::Reference< css::task::XInteractionRequest >& 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< css::task::XInteractionContinuation > xAbort =
+ ::ucbhelper::InterceptedInteraction::extractContinuation(
+ xRequest->getContinuations(),
+ cppu::UnoType<css::task::XInteractionAbort>::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: */