xref: /trunk/main/ucbhelper/source/provider/handleinteractionrequest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
30*cdf0e10cSrcweir #include "ucbhelper/handleinteractionrequest.hxx"
31*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
32*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp"
33*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionRetry.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/ucb/CommandFailedException.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
37*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
38*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
39*cdf0e10cSrcweir #include "osl/diagnose.h"
40*cdf0e10cSrcweir #include "rtl/ustring.hxx"
41*cdf0e10cSrcweir #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
42*cdf0e10cSrcweir #include "ucbhelper/interactionrequest.hxx"
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include "ucbhelper/simpleauthenticationrequest.hxx"
45*cdf0e10cSrcweir #include "ucbhelper/simpleinteractionrequest.hxx"
46*cdf0e10cSrcweir #include "ucbhelper/simplecertificatevalidationrequest.hxx"
47*cdf0e10cSrcweir #ifndef INCLUDED_UTILITY
48*cdf0e10cSrcweir #include <utility>
49*cdf0e10cSrcweir #define INCLUDED_UTILITY
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace com::sun::star;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace {
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir void
57*cdf0e10cSrcweir handle(uno::Reference< task::XInteractionRequest > const & rRequest,
58*cdf0e10cSrcweir        uno::Reference< ucb::XCommandEnvironment > const & rEnvironment)
59*cdf0e10cSrcweir     SAL_THROW((uno::Exception))
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     OSL_ENSURE(rRequest.is(), "specification violation");
62*cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > xHandler;
63*cdf0e10cSrcweir     if (rEnvironment.is())
64*cdf0e10cSrcweir         xHandler = rEnvironment->getInteractionHandler();
65*cdf0e10cSrcweir     if (!xHandler.is())
66*cdf0e10cSrcweir         cppu::throwException(rRequest->getRequest());
67*cdf0e10cSrcweir     xHandler->handle(rRequest.get());
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir namespace ucbhelper {
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir sal_Int32
75*cdf0e10cSrcweir handleInteractionRequest(
76*cdf0e10cSrcweir     rtl::Reference< ucbhelper::SimpleInteractionRequest > const & rRequest,
77*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
78*cdf0e10cSrcweir     bool bThrowOnAbort)
79*cdf0e10cSrcweir     SAL_THROW((uno::Exception))
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     handle(rRequest.get(), rEnvironment);
82*cdf0e10cSrcweir     sal_Int32 nResponse = rRequest->getResponse();
83*cdf0e10cSrcweir     switch (nResponse)
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir     case ucbhelper::CONTINUATION_UNKNOWN:
86*cdf0e10cSrcweir         cppu::throwException(rRequest->getRequest());
87*cdf0e10cSrcweir         break;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     case ucbhelper::CONTINUATION_ABORT:
90*cdf0e10cSrcweir         if (bThrowOnAbort)
91*cdf0e10cSrcweir             throw ucb::CommandFailedException(
92*cdf0e10cSrcweir                       rtl::OUString(), 0, rRequest->getRequest());
93*cdf0e10cSrcweir         break;
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir     return nResponse;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir std::pair< sal_Int32,
99*cdf0e10cSrcweir            rtl::Reference< ucbhelper::InteractionSupplyAuthentication > >
100*cdf0e10cSrcweir handleInteractionRequest(
101*cdf0e10cSrcweir     rtl::Reference< ucbhelper::SimpleAuthenticationRequest > const & rRequest,
102*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
103*cdf0e10cSrcweir     bool bThrowOnAbort)
104*cdf0e10cSrcweir     SAL_THROW((uno::Exception))
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     handle(rRequest.get(), rEnvironment);
107*cdf0e10cSrcweir     rtl::Reference< ucbhelper::InteractionContinuation >
108*cdf0e10cSrcweir         xContinuation(rRequest->getSelection());
109*cdf0e10cSrcweir     if (uno::Reference< task::XInteractionAbort >(
110*cdf0e10cSrcweir                 xContinuation.get(), uno::UNO_QUERY).
111*cdf0e10cSrcweir             is())
112*cdf0e10cSrcweir         if (bThrowOnAbort)
113*cdf0e10cSrcweir             throw ucb::CommandFailedException(
114*cdf0e10cSrcweir                       rtl::OUString(), 0, rRequest->getRequest());
115*cdf0e10cSrcweir         else
116*cdf0e10cSrcweir             return std::make_pair(
117*cdf0e10cSrcweir                        ucbhelper::CONTINUATION_ABORT,
118*cdf0e10cSrcweir                        rtl::Reference<
119*cdf0e10cSrcweir                            ucbhelper::InteractionSupplyAuthentication >());
120*cdf0e10cSrcweir     else if (uno::Reference< task::XInteractionRetry >(
121*cdf0e10cSrcweir                      xContinuation.get(), uno::UNO_QUERY).
122*cdf0e10cSrcweir                  is())
123*cdf0e10cSrcweir         return std::make_pair(
124*cdf0e10cSrcweir                    ucbhelper::CONTINUATION_ABORT,
125*cdf0e10cSrcweir                    rtl::Reference<
126*cdf0e10cSrcweir                        ucbhelper::InteractionSupplyAuthentication >());
127*cdf0e10cSrcweir     else
128*cdf0e10cSrcweir         return std::make_pair(
129*cdf0e10cSrcweir                    ucbhelper::CONTINUATION_UNKNOWN,
130*cdf0e10cSrcweir                    rtl::Reference<
131*cdf0e10cSrcweir                        ucbhelper::InteractionSupplyAuthentication >(
132*cdf0e10cSrcweir                            rRequest->getAuthenticationSupplier()));
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir namespace ucbhelper {
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir sal_Int32
140*cdf0e10cSrcweir handleInteractionRequest(
141*cdf0e10cSrcweir     rtl::Reference< ucbhelper::SimpleCertificateValidationRequest > const & rRequest,
142*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > const & rEnvironment,
143*cdf0e10cSrcweir     bool bThrowOnAbort)
144*cdf0e10cSrcweir     SAL_THROW((uno::Exception))
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     handle(rRequest.get(), rEnvironment);
147*cdf0e10cSrcweir     sal_Int32 nResponse = rRequest->getResponse();
148*cdf0e10cSrcweir     switch (nResponse)
149*cdf0e10cSrcweir     {
150*cdf0e10cSrcweir     case ucbhelper::CONTINUATION_UNKNOWN:
151*cdf0e10cSrcweir         cppu::throwException(rRequest->getRequest());
152*cdf0e10cSrcweir         break;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     case ucbhelper::CONTINUATION_ABORT:
155*cdf0e10cSrcweir         if (bThrowOnAbort)
156*cdf0e10cSrcweir             throw ucb::CommandFailedException(
157*cdf0e10cSrcweir                       rtl::OUString(), 0, rRequest->getRequest());
158*cdf0e10cSrcweir         break;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir     return nResponse;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165