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 
34 namespace comphelper{
35 
36 StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
37  const css::uno::Reference< css::task::XInteractionHandler >& xAuxiliaryHandler)
38  : m_bUsed (false)
39  , m_bHandledByMySelf (false)
40  , m_xAuxiliaryHandler(xAuxiliaryHandler)
41 {
42  std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
43  lInterceptions.reserve(4);
45 
46  aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
47  aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
49  lInterceptions.push_back(aInterceptedRequest);
50 
51  aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
52  aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
54  lInterceptions.push_back(aInterceptedRequest);
55 
56  aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
57  aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
59  lInterceptions.push_back(aInterceptedRequest);
60 
61  aInterceptedRequest.Handle = HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION;
62  aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
64  lInterceptions.push_back(aInterceptedRequest);
65 
66  setInterceptedHandler(xHandler);
67  setInterceptions(std::move(lInterceptions));
68 }
69 
70 void StillReadWriteInteraction::resetInterceptions()
71 {
72  setInterceptions(std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
73 }
74 
75 void StillReadWriteInteraction::resetErrorStates()
76 {
77  m_bUsed = false;
78  m_bHandledByMySelf = false;
79 }
80 
81 
82 ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
83  const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
84 {
85  // we are used!
86  m_bUsed = true;
87 
88  // check if it's a real interception - might some parameters are not the right ones ...
89  bool bAbort = false;
90  switch(aRequest.Handle)
91  {
93  {
94  css::ucb::InteractiveIOException exIO;
95  xRequest->getRequest() >>= exIO;
96  bAbort = (
97  (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
98  || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
99  || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
100  // At least on Linux, a request to open some fuse-mounted file O_RDWR may fail with
101  // EOPNOTSUPP (mapped to osl_File_E_NOSYS to IOErrorCode_NOT_SUPPORTED) when opening
102  // it O_RDONLY would succeed:
103  || (exIO.Code == css::ucb::IOErrorCode_NOT_SUPPORTED )
104 #ifdef MACOSX
105  // this is a workaround for MAC, on this platform if the file is locked
106  // the returned error code looks to be wrong
107  || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
108 #endif
109  );
110  }
111  break;
112 
114  {
115  bAbort = true;
116  }
117  break;
118  case HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION:
119  case HANDLE_AUTHENTICATIONREQUESTEXCEPTION:
120  {
121 //use internal auxiliary handler and return
122  if (m_xAuxiliaryHandler.is())
123  {
124  m_xAuxiliaryHandler->handle(xRequest);
125  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
126  }
127  else //simply abort
128  bAbort = true;
129  }
130  break;
131  }
132 
133  // handle interaction by ourself
134  if (bAbort)
135  {
136  m_bHandledByMySelf = true;
137  css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
138  xRequest->getContinuations(),
140  if (!xAbort.is())
141  return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
142  xAbort->select();
143  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
144  }
145 
146  // Otherwise use internal handler.
147  if (m_xInterceptedHandler.is())
148  {
149  m_xInterceptedHandler->handle(xRequest);
150  }
151  return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
152 }
153 }
154 
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION
Will handle com::sun::star::ucb::UnsupportedDataSinkException.
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.
css::uno::Type const & get()
bool m_bDetectedRangeSegmentation false