icinga2/lib/remote/httpserverconnection.hpp
Yonas Habteab 91c7e60df8 Replace all existing copyright headers with SPDX headers
I've used the following command to replace the original copyright header
lines in a C-style comment block:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```

For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```

And for SQL files:

```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
2026-02-04 14:00:05 +01:00

74 lines
2 KiB
C++

// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef HTTPSERVERCONNECTION_H
#define HTTPSERVERCONNECTION_H
#include "remote/apiuser.hpp"
#include "base/string.hpp"
#include "base/tlsstream.hpp"
#include "base/wait-group.hpp"
#include <memory>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/spawn.hpp>
#include <chrono>
namespace icinga
{
using namespace std::chrono_literals;
/**
* An API client connection.
*
* @ingroup remote
*/
class HttpServerConnection final : public Object
{
public:
DECLARE_PTR_TYPEDEFS(HttpServerConnection);
HttpServerConnection(const WaitGroup::Ptr& waitGroup, const String& identity, bool authenticated,
const Shared<AsioTlsStream>::Ptr& stream);
void Start();
void StartDetectClientSideShutdown();
bool Disconnected();
/**
* Sets the liveness timeout.
*
* If we don't receive any data from the client in this time frame, we consider the connection
* dead and close it. The default is 10 seconds. This function should only be used for unit tests
* to speed them up.
*
* @param timeout The timeout duration.
*/
void SetLivenessTimeout(std::chrono::milliseconds timeout);
private:
WaitGroup::Ptr m_WaitGroup;
ApiUser::Ptr m_ApiUser;
Shared<AsioTlsStream>::Ptr m_Stream;
std::chrono::steady_clock::time_point m_Seen{std::chrono::steady_clock::now()};
std::chrono::milliseconds m_LivenessTimeout{10s};
String m_PeerAddress;
boost::asio::io_context::strand m_IoStrand;
bool m_ShuttingDown;
bool m_ConnectionReusable;
boost::asio::deadline_timer m_CheckLivenessTimer;
HttpServerConnection(const WaitGroup::Ptr& waitGroup, const String& identity, bool authenticated,
const Shared<AsioTlsStream>::Ptr& stream, boost::asio::io_context& io);
void Disconnect(boost::asio::yield_context yc);
void ProcessMessages(boost::asio::yield_context yc);
void CheckLiveness(boost::asio::yield_context yc);
};
}
#endif /* HTTPSERVERCONNECTION_H */