2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
#ifndef HTTPSERVERCONNECTION_H
|
|
|
|
#define HTTPSERVERCONNECTION_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "remote/httprequest.hpp"
|
2018-02-08 14:54:52 +01:00
|
|
|
#include "remote/httpresponse.hpp"
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "remote/apiuser.hpp"
|
2014-10-16 12:27:09 +02:00
|
|
|
#include "base/tlsstream.hpp"
|
2014-07-01 09:38:22 +02:00
|
|
|
#include "base/workqueue.hpp"
|
2018-07-09 14:40:32 +02:00
|
|
|
#include <boost/thread/recursive_mutex.hpp>
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2014-05-03 20:02:22 +02:00
|
|
|
* An API client connection.
|
2014-04-12 04:21:09 +02:00
|
|
|
*
|
2014-05-03 20:02:22 +02:00
|
|
|
* @ingroup remote
|
2014-04-12 04:21:09 +02:00
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class HttpServerConnection final : public Object
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-08-29 01:16:16 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(HttpServerConnection);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
HttpServerConnection(const String& identity, bool authenticated, const TlsStream::Ptr& stream);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Start();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ApiUser::Ptr GetApiUser() const;
|
|
|
|
bool IsAuthenticated() const;
|
|
|
|
TlsStream::Ptr GetStream() const;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Disconnect();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
private:
|
2015-06-22 11:11:21 +02:00
|
|
|
ApiUser::Ptr m_ApiUser;
|
2018-02-08 14:54:52 +01:00
|
|
|
ApiUser::Ptr m_AuthenticatedUser;
|
2014-10-16 12:27:09 +02:00
|
|
|
TlsStream::Ptr m_Stream;
|
2014-05-03 20:02:22 +02:00
|
|
|
double m_Seen;
|
2015-06-22 11:11:21 +02:00
|
|
|
HttpRequest m_CurrentRequest;
|
2018-07-09 14:40:32 +02:00
|
|
|
boost::recursive_mutex m_DataHandlerMutex;
|
2015-06-22 11:11:21 +02:00
|
|
|
WorkQueue m_RequestQueue;
|
|
|
|
int m_PendingRequests;
|
2018-10-09 15:40:16 +02:00
|
|
|
String m_PeerAddress;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-02-14 16:34:36 +01:00
|
|
|
StreamReadContext m_Context;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool ProcessMessage();
|
|
|
|
void DataAvailableHandler();
|
2015-02-26 12:41:47 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void StaticInitialize();
|
|
|
|
static void TimeoutTimerHandler();
|
|
|
|
void CheckLiveness();
|
2015-06-22 11:11:21 +02:00
|
|
|
|
2018-02-08 14:54:52 +01:00
|
|
|
bool ManageHeaders(HttpResponse& response);
|
|
|
|
|
|
|
|
void ProcessMessageAsync(HttpRequest& request, HttpResponse& response, const ApiUser::Ptr&);
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-29 01:16:16 +02:00
|
|
|
#endif /* HTTPSERVERCONNECTION_H */
|