Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / update / check / download.hxx
blob12a11ddde091ed1e1d436b1f1bc09d93d41ec4d8
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
26 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <rtl/ref.hxx>
29 #include <rtl/ustring.hxx>
30 #include <osl/conditn.hxx>
31 #include <salhelper/simplereferenceobject.hxx>
33 struct DownloadInteractionHandler : public virtual salhelper::SimpleReferenceObject
35 virtual bool checkDownloadDestination(const OUString& rFileName) = 0;
37 // called if the destination file already exists, but resume is false
38 virtual bool downloadTargetExists(const OUString& rFileName) = 0;
40 // called when curl reports an error
41 virtual void downloadStalled(const OUString& rErrorMessage) = 0;
43 // progress handler
44 virtual void downloadProgressAt(sal_Int8 nPercent) = 0;
46 // called on first progress notification
47 virtual void downloadStarted(const OUString& rFileName, sal_Int64 nFileSize) = 0;
49 // called when download has been finished
50 virtual void downloadFinished(const OUString& rFileName) = 0;
52 protected:
53 virtual ~DownloadInteractionHandler() override {}
56 class Download
58 public:
59 Download(const css::uno::Reference<css::uno::XComponentContext>& xContext,
60 const rtl::Reference<DownloadInteractionHandler>& rHandler)
61 : m_xContext(xContext)
62 , m_aHandler(rHandler){};
64 // returns true when the content of rURL was successfully written to rLocalFile
65 bool start(const OUString& rURL, const OUString& rFile, const OUString& rDestinationDir);
67 // stops the download after the next write operation
68 void stop();
70 protected:
71 // Determines the appropriate proxy settings for the given URL. Returns true if a proxy should be used
72 void getProxyForURL(std::u16string_view rURL, OString& rHost, sal_Int32& rPort) const;
74 private:
75 osl::Condition m_aCondition;
76 const css::uno::Reference<css::uno::XComponentContext>& m_xContext;
77 const rtl::Reference<DownloadInteractionHandler> m_aHandler;
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */