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