LibreOffice Module comphelper (master) 1
stillreadwriteinteraction.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21
22#include <com/sun/star/ucb/InteractiveIOException.hpp>
23
24#include <com/sun/star/task/XInteractionAbort.hpp>
25
26#include <com/sun/star/task/XInteractionApprove.hpp>
27
28#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
29
30#include <com/sun/star/ucb/AuthenticationRequest.hpp>
31
32#include <com/sun/star/ucb/CertificateValidationRequest.hpp>
33#include <utility>
34
35namespace comphelper{
36
37StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
38 css::uno::Reference< css::task::XInteractionHandler > xAuxiliaryHandler)
39 : m_bUsed (false)
40 , m_bHandledByMySelf (false)
41 , m_xAuxiliaryHandler(std::move(xAuxiliaryHandler))
42{
43 std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
44 lInterceptions.reserve(4);
46
47 aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
48 aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
50 lInterceptions.push_back(aInterceptedRequest);
51
52 aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
53 aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
55 lInterceptions.push_back(aInterceptedRequest);
56
57 aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
58 aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
60 lInterceptions.push_back(aInterceptedRequest);
61
62 aInterceptedRequest.Handle = HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION;
63 aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
65 lInterceptions.push_back(aInterceptedRequest);
66
67 setInterceptedHandler(xHandler);
68 setInterceptions(std::move(lInterceptions));
69}
70
71void StillReadWriteInteraction::resetInterceptions()
72{
73 setInterceptions(std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
74}
75
76void StillReadWriteInteraction::resetErrorStates()
77{
78 m_bUsed = false;
79 m_bHandledByMySelf = false;
80}
81
82
83ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
84 const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
85{
86 // we are used!
87 m_bUsed = true;
88
89 // check if it's a real interception - might some parameters are not the right ones ...
90 bool bAbort = false;
91 switch(aRequest.Handle)
92 {
94 {
95 css::ucb::InteractiveIOException exIO;
96 xRequest->getRequest() >>= exIO;
97 bAbort = (
98 (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
99 || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
100 || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
101 // At least on Linux, a request to open some fuse-mounted file O_RDWR may fail with
102 // EOPNOTSUPP (mapped to osl_File_E_NOSYS to IOErrorCode_NOT_SUPPORTED) when opening
103 // it O_RDONLY would succeed:
104 || (exIO.Code == css::ucb::IOErrorCode_NOT_SUPPORTED )
105#ifdef MACOSX
106 // this is a workaround for MAC, on this platform if the file is locked
107 // the returned error code looks to be wrong
108 || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
109#endif
110 );
111 }
112 break;
113
115 {
116 bAbort = true;
117 }
118 break;
119 case HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION:
120 case HANDLE_AUTHENTICATIONREQUESTEXCEPTION:
121 {
122//use internal auxiliary handler and return
123 if (m_xAuxiliaryHandler.is())
124 {
125 m_xAuxiliaryHandler->handle(xRequest);
126 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
127 }
128 else //simply abort
129 bAbort = true;
130 }
131 break;
132 }
133
134 // handle interaction by ourself
135 if (bAbort)
136 {
137 m_bHandledByMySelf = true;
138 css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
139 xRequest->getContinuations(),
141 if (!xAbort.is())
142 return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
143 xAbort->select();
144 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
145 }
146
147 // Otherwise use internal handler.
148 if (m_xInterceptedHandler.is())
149 {
150 m_xInterceptedHandler->handle(xRequest);
151 }
152 return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
153}
154}
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Type const & get()
static css::uno::Reference< css::task::XInteractionContinuation > extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > &lContinuations, const css::uno::Type &aType)
const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION
Will handle com::sun::star::ucb::InteractiveIOException and derived classes.
const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION
Will handle com::sun::star::ucb::UnsupportedDataSinkException.