2014-04-12 04:21:09 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-04-12 04:21:09 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#ifndef JSONRPCCONNECTION_H
|
|
|
|
#define JSONRPCCONNECTION_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/endpoint.hpp"
|
2014-10-16 12:27:09 +02:00
|
|
|
#include "base/tlsstream.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/timer.hpp"
|
2014-07-01 09:38:22 +02:00
|
|
|
#include "base/workqueue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/i2-remote.hpp"
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
enum ClientRole
|
|
|
|
{
|
|
|
|
ClientInbound,
|
|
|
|
ClientOutbound
|
|
|
|
};
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
enum ClientType
|
|
|
|
{
|
|
|
|
ClientJsonRpc,
|
|
|
|
ClientHttp
|
|
|
|
};
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
class MessageOrigin;
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
/**
|
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
|
|
|
*/
|
2015-06-22 11:11:21 +02:00
|
|
|
class I2_REMOTE_API JsonRpcConnection : public Object
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-06-22 11:11:21 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(JsonRpcConnection);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
JsonRpcConnection(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
void Start(void);
|
|
|
|
|
2014-05-08 15:00:09 +02:00
|
|
|
String GetIdentity(void) const;
|
2014-10-16 09:01:18 +02:00
|
|
|
bool IsAuthenticated(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
Endpoint::Ptr GetEndpoint(void) const;
|
2014-10-16 12:27:09 +02:00
|
|
|
TlsStream::Ptr GetStream(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
ConnectionRole GetRole(void) const;
|
|
|
|
|
|
|
|
void Disconnect(void);
|
|
|
|
|
|
|
|
void SendMessage(const Dictionary::Ptr& request);
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2014-12-09 13:17:27 +01:00
|
|
|
static void HeartbeatTimerHandler(void);
|
2015-08-04 14:47:44 +02:00
|
|
|
static Value HeartbeatAPIHandler(const intrusive_ptr<MessageOrigin>& origin, const Dictionary::Ptr& params);
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
private:
|
2014-05-08 15:00:09 +02:00
|
|
|
String m_Identity;
|
2014-10-16 09:01:18 +02:00
|
|
|
bool m_Authenticated;
|
2014-05-03 20:02:22 +02:00
|
|
|
Endpoint::Ptr m_Endpoint;
|
2014-10-16 12:27:09 +02:00
|
|
|
TlsStream::Ptr m_Stream;
|
2014-05-03 20:02:22 +02:00
|
|
|
ConnectionRole m_Role;
|
|
|
|
double m_Seen;
|
2014-12-09 13:17:27 +01:00
|
|
|
double m_NextHeartbeat;
|
2015-03-11 12:53:43 +01:00
|
|
|
double m_HeartbeatTimeout;
|
2015-06-24 09:44:59 +02:00
|
|
|
boost::mutex m_DataHandlerMutex;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-02-14 16:34:36 +01:00
|
|
|
StreamReadContext m_Context;
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
bool ProcessMessage(void);
|
2015-02-14 16:34:36 +01:00
|
|
|
void DataAvailableHandler(void);
|
2015-02-26 12:41:47 +01:00
|
|
|
|
2015-02-27 20:18:20 +01:00
|
|
|
static void StaticInitialize(void);
|
|
|
|
static void TimeoutTimerHandler(void);
|
|
|
|
void CheckLiveness(void);
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#endif /* JSONRPCCONNECTION_H */
|