cid#1607171 Data race condition
[LibreOffice.git] / forms / source / xforms / submission / submission_get.cxx
blob4ee8140b21721eceeee211121bbd872fa4be2c69
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "submission_get.hxx"
22 #include "serialization_urlencoded.hxx"
24 #include <rtl/strbuf.hxx>
25 #include <osl/diagnose.h>
26 #include <ucbhelper/content.hxx>
27 #include <com/sun/star/task/InteractionHandler.hpp>
28 #include <comphelper/diagnose_ex.hxx>
30 using namespace css::uno;
31 using namespace css::ucb;
32 using namespace css::task;
33 using namespace css::io;
34 using namespace ucbhelper;
37 CSubmissionGet::CSubmissionGet(std::u16string_view aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment >& aFragment)
38 : CSubmission(aURL, aFragment)
42 CSubmission::SubmissionResult CSubmissionGet::submit(const css::uno::Reference< css::task::XInteractionHandler >& aInteractionHandler)
44 // GET always uses application/x-www-formurlencoded
45 CSerializationURLEncoded aSerialization;
46 aSerialization.setSource(m_aFragment);
47 aSerialization.serialize();
49 css::uno::Reference< XInputStream > aInStream = aSerialization.getInputStream();
51 // create a commandEnvironment and use the default interaction handler
52 rtl::Reference<CCommandEnvironmentHelper> pHelper = new CCommandEnvironmentHelper;
53 if( aInteractionHandler.is() )
54 pHelper->m_aInteractionHandler = aInteractionHandler;
55 else
56 pHelper->m_aInteractionHandler.set(
57 css::task::InteractionHandler::createWithParent(m_xContext, nullptr), UNO_QUERY_THROW);
58 rtl::Reference<CProgressHandlerHelper> pProgressHelper = new CProgressHandlerHelper;
59 pHelper->m_aProgressHandler.set(pProgressHelper);
61 // UCB has ownership of environment...
62 css::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
64 // append query string to the URL
65 try {
66 OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE),
67 RTL_TEXTENCODING_UTF8));
68 OStringBuffer aQueryString;
70 const sal_Int32 size = 1024;
71 sal_Int32 n = 0;
72 Sequence< sal_Int8 > aByteBuffer(size);
73 while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
74 aQueryString.append(reinterpret_cast<char const *>(aByteBuffer.getConstArray()), n);
75 if (!aQueryString.isEmpty() && m_aURLObj.GetProtocol() != INetProtocol::File)
77 aUTF8QueryURL.append("?" + aQueryString);
79 OUString aQueryURL = OStringToOUString(aUTF8QueryURL, RTL_TEXTENCODING_UTF8);
80 ucbhelper::Content aContent(aQueryURL, aEnvironment, m_xContext);
81 // get reply
82 try {
83 m_aResultStream = aContent.openStream();
84 } catch (const Exception&) {
85 OSL_FAIL("Cannot open reply stream from content");
87 } catch (const Exception&)
89 // XXX
90 TOOLS_WARN_EXCEPTION( "forms.misc", "Exception during UCB operation.");
91 return UNKNOWN_ERROR;
94 return SUCCESS;
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */