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