1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucbhelper.hxx"
26 #include "ucbhelper/handleinteractionrequest.hxx"
27 #include "com/sun/star/task/XInteractionAbort.hpp"
28 #include "com/sun/star/task/XInteractionHandler.hpp"
29 #include "com/sun/star/task/XInteractionRetry.hpp"
30 #include "com/sun/star/ucb/CommandFailedException.hpp"
31 #include "com/sun/star/ucb/XCommandEnvironment.hpp"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 #include "cppuhelper/exc_hlp.hxx"
35 #include "osl/diagnose.h"
36 #include "rtl/ustring.hxx"
37 #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
38 #include "ucbhelper/interactionrequest.hxx"
39 #endif
40 #include "ucbhelper/simpleauthenticationrequest.hxx"
41 #include "ucbhelper/simpleinteractionrequest.hxx"
42 #include "ucbhelper/simplecertificatevalidationrequest.hxx"
43 #ifndef INCLUDED_UTILITY
44 #include <utility>
45 #define INCLUDED_UTILITY
46 #endif
47
48 using namespace com::sun::star;
49
50 namespace {
51
52 void
handle(uno::Reference<task::XInteractionRequest> const & rRequest,uno::Reference<ucb::XCommandEnvironment> const & rEnvironment)53 handle(uno::Reference< task::XInteractionRequest > const & rRequest,
54 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment)
55 SAL_THROW((uno::Exception))
56 {
57 OSL_ENSURE(rRequest.is(), "specification violation");
58 uno::Reference< task::XInteractionHandler > xHandler;
59 if (rEnvironment.is())
60 xHandler = rEnvironment->getInteractionHandler();
61 if (!xHandler.is())
62 cppu::throwException(rRequest->getRequest());
63 xHandler->handle(rRequest.get());
64 }
65
66 }
67
68 namespace ucbhelper {
69
70 sal_Int32
handleInteractionRequest(rtl::Reference<ucbhelper::SimpleInteractionRequest> const & rRequest,uno::Reference<ucb::XCommandEnvironment> const & rEnvironment,bool bThrowOnAbort)71 handleInteractionRequest(
72 rtl::Reference< ucbhelper::SimpleInteractionRequest > const & rRequest,
73 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
74 bool bThrowOnAbort)
75 SAL_THROW((uno::Exception))
76 {
77 handle(rRequest.get(), rEnvironment);
78 sal_Int32 nResponse = rRequest->getResponse();
79 switch (nResponse)
80 {
81 case ucbhelper::CONTINUATION_UNKNOWN:
82 cppu::throwException(rRequest->getRequest());
83 break;
84
85 case ucbhelper::CONTINUATION_ABORT:
86 if (bThrowOnAbort)
87 throw ucb::CommandFailedException(
88 rtl::OUString(), 0, rRequest->getRequest());
89 break;
90 }
91 return nResponse;
92 }
93
94 std::pair< sal_Int32,
95 rtl::Reference< ucbhelper::InteractionSupplyAuthentication > >
handleInteractionRequest(rtl::Reference<ucbhelper::SimpleAuthenticationRequest> const & rRequest,uno::Reference<ucb::XCommandEnvironment> const & rEnvironment,bool bThrowOnAbort)96 handleInteractionRequest(
97 rtl::Reference< ucbhelper::SimpleAuthenticationRequest > const & rRequest,
98 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
99 bool bThrowOnAbort)
100 SAL_THROW((uno::Exception))
101 {
102 handle(rRequest.get(), rEnvironment);
103 rtl::Reference< ucbhelper::InteractionContinuation >
104 xContinuation(rRequest->getSelection());
105 if (uno::Reference< task::XInteractionAbort >(
106 xContinuation.get(), uno::UNO_QUERY).
107 is())
108 if (bThrowOnAbort)
109 throw ucb::CommandFailedException(
110 rtl::OUString(), 0, rRequest->getRequest());
111 else
112 return std::make_pair(
113 ucbhelper::CONTINUATION_ABORT,
114 rtl::Reference<
115 ucbhelper::InteractionSupplyAuthentication >());
116 else if (uno::Reference< task::XInteractionRetry >(
117 xContinuation.get(), uno::UNO_QUERY).
118 is())
119 return std::make_pair(
120 ucbhelper::CONTINUATION_ABORT,
121 rtl::Reference<
122 ucbhelper::InteractionSupplyAuthentication >());
123 else
124 return std::make_pair(
125 ucbhelper::CONTINUATION_UNKNOWN,
126 rtl::Reference<
127 ucbhelper::InteractionSupplyAuthentication >(
128 rRequest->getAuthenticationSupplier()));
129 }
130
131 }
132
133 namespace ucbhelper {
134
135 sal_Int32
handleInteractionRequest(rtl::Reference<ucbhelper::SimpleCertificateValidationRequest> const & rRequest,uno::Reference<ucb::XCommandEnvironment> const & rEnvironment,bool bThrowOnAbort)136 handleInteractionRequest(
137 rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > const & rRequest,
138 uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
139 bool bThrowOnAbort)
140 SAL_THROW((uno::Exception))
141 {
142 handle(rRequest.get(), rEnvironment);
143 sal_Int32 nResponse = rRequest->getResponse();
144 switch (nResponse)
145 {
146 case ucbhelper::CONTINUATION_UNKNOWN:
147 cppu::throwException(rRequest->getRequest());
148 break;
149
150 case ucbhelper::CONTINUATION_ABORT:
151 if (bThrowOnAbort)
152 throw ucb::CommandFailedException(
153 rtl::OUString(), 0, rRequest->getRequest());
154 break;
155 }
156 return nResponse;
157 }
158
159 }
160
161