mirror of https://github.com/Icinga/icinga2.git
Documentation updates.
Renamed classes to match style guide.
This commit is contained in:
parent
8b0c102cac
commit
ce60fbd6ba
|
@ -22,11 +22,11 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the TCPClient class.
|
* Constructor for the TcpClient class.
|
||||||
*
|
*
|
||||||
* @param role The role of the TCP client socket.
|
* @param role The role of the TCP client socket.
|
||||||
*/
|
*/
|
||||||
TCPClient::TCPClient(TCPClientRole role)
|
TcpClient::TcpClient(TcpClientRole role)
|
||||||
{
|
{
|
||||||
m_Role = role;
|
m_Role = role;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ TCPClient::TCPClient(TCPClientRole role)
|
||||||
*
|
*
|
||||||
* @returns The role.
|
* @returns The role.
|
||||||
*/
|
*/
|
||||||
TCPClientRole TCPClient::GetRole(void) const
|
TcpClientRole TcpClient::GetRole(void) const
|
||||||
{
|
{
|
||||||
return m_Role;
|
return m_Role;
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ TCPClientRole TCPClient::GetRole(void) const
|
||||||
/**
|
/**
|
||||||
* Registers the socket and starts processing events for it.
|
* Registers the socket and starts processing events for it.
|
||||||
*/
|
*/
|
||||||
void TCPClient::Start(void)
|
void TcpClient::Start(void)
|
||||||
{
|
{
|
||||||
TCPSocket::Start();
|
TcpSocket::Start();
|
||||||
|
|
||||||
OnReadable += bind_weak(&TCPClient::ReadableEventHandler, shared_from_this());
|
OnReadable += bind_weak(&TcpClient::ReadableEventHandler, shared_from_this());
|
||||||
OnWritable += bind_weak(&TCPClient::WritableEventHandler, shared_from_this());
|
OnWritable += bind_weak(&TcpClient::WritableEventHandler, shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,7 @@ void TCPClient::Start(void)
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @param service The service.
|
* @param service The service.
|
||||||
*/
|
*/
|
||||||
void TCPClient::Connect(const string& node, const string& service)
|
void TcpClient::Connect(const string& node, const string& service)
|
||||||
{
|
{
|
||||||
m_Role = RoleOutbound;
|
m_Role = RoleOutbound;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ void TCPClient::Connect(const string& node, const string& service)
|
||||||
*
|
*
|
||||||
* @returns The send queue.
|
* @returns The send queue.
|
||||||
*/
|
*/
|
||||||
FIFO::Ptr TCPClient::GetSendQueue(void)
|
FIFO::Ptr TcpClient::GetSendQueue(void)
|
||||||
{
|
{
|
||||||
return m_SendQueue;
|
return m_SendQueue;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ FIFO::Ptr TCPClient::GetSendQueue(void)
|
||||||
*
|
*
|
||||||
* @returns The recv queue.
|
* @returns The recv queue.
|
||||||
*/
|
*/
|
||||||
FIFO::Ptr TCPClient::GetRecvQueue(void)
|
FIFO::Ptr TcpClient::GetRecvQueue(void)
|
||||||
{
|
{
|
||||||
return m_RecvQueue;
|
return m_RecvQueue;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ FIFO::Ptr TCPClient::GetRecvQueue(void)
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int TCPClient::ReadableEventHandler(const EventArgs&)
|
int TcpClient::ReadableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ int TCPClient::ReadableEventHandler(const EventArgs&)
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int TCPClient::WritableEventHandler(const EventArgs&)
|
int TcpClient::WritableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ int TCPClient::WritableEventHandler(const EventArgs&)
|
||||||
*
|
*
|
||||||
* @returns true
|
* @returns true
|
||||||
*/
|
*/
|
||||||
bool TCPClient::WantsToRead(void) const
|
bool TcpClient::WantsToRead(void) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ bool TCPClient::WantsToRead(void) const
|
||||||
*
|
*
|
||||||
* @returns true if data should be written, false otherwise.
|
* @returns true if data should be written, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool TCPClient::WantsToWrite(void) const
|
bool TcpClient::WantsToWrite(void) const
|
||||||
{
|
{
|
||||||
return (m_SendQueue->GetSize() > 0);
|
return (m_SendQueue->GetSize() > 0);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ bool TCPClient::WantsToWrite(void) const
|
||||||
* @param role The role of the new client.
|
* @param role The role of the new client.
|
||||||
* @returns The new client.
|
* @returns The new client.
|
||||||
*/
|
*/
|
||||||
TCPClient::Ptr icinga::TCPClientFactory(TCPClientRole role)
|
TcpClient::Ptr icinga::TcpClientFactory(TcpClientRole role)
|
||||||
{
|
{
|
||||||
return make_shared<TCPClient>(role);
|
return make_shared<TcpClient>(role);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace icinga
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
enum TCPClientRole
|
enum TcpClientRole
|
||||||
{
|
{
|
||||||
RoleInbound, /**< Inbound socket, i.e. one that was returned
|
RoleInbound, /**< Inbound socket, i.e. one that was returned
|
||||||
from accept(). */
|
from accept(). */
|
||||||
|
@ -41,10 +41,10 @@ enum TCPClientRole
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API TCPClient : public TCPSocket
|
class I2_BASE_API TcpClient : public TcpSocket
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
TCPClientRole m_Role;
|
TcpClientRole m_Role;
|
||||||
|
|
||||||
FIFO::Ptr m_SendQueue;
|
FIFO::Ptr m_SendQueue;
|
||||||
FIFO::Ptr m_RecvQueue;
|
FIFO::Ptr m_RecvQueue;
|
||||||
|
@ -53,12 +53,12 @@ private:
|
||||||
virtual int WritableEventHandler(const EventArgs& ea);
|
virtual int WritableEventHandler(const EventArgs& ea);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<TCPClient> Ptr;
|
typedef shared_ptr<TcpClient> Ptr;
|
||||||
typedef weak_ptr<TCPClient> WeakPtr;
|
typedef weak_ptr<TcpClient> WeakPtr;
|
||||||
|
|
||||||
TCPClient(TCPClientRole role);
|
TcpClient(TcpClientRole role);
|
||||||
|
|
||||||
TCPClientRole GetRole(void) const;
|
TcpClientRole GetRole(void) const;
|
||||||
|
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
|
|
||||||
|
@ -74,13 +74,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new unconnected TCPClient object that has the specified
|
* Returns a new unconnected TcpClient object that has the specified
|
||||||
* connection role.
|
* connection role.
|
||||||
*
|
*
|
||||||
* @param role The role of the new object.
|
* @param role The role of the new object.
|
||||||
* @returns A new TCPClient object.
|
* @returns A new TcpClient object.
|
||||||
*/
|
*/
|
||||||
TCPClient::Ptr TCPClientFactory(TCPClientRole role);
|
TcpClient::Ptr TcpClientFactory(TcpClientRole role);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the TCPServer class.
|
* Constructor for the TcpServer class.
|
||||||
*/
|
*/
|
||||||
TCPServer::TCPServer(void)
|
TcpServer::TcpServer(void)
|
||||||
{
|
{
|
||||||
m_ClientFactory = bind(&TCPClientFactory, RoleInbound);
|
m_ClientFactory = bind(&TcpClientFactory, RoleInbound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ TCPServer::TCPServer(void)
|
||||||
*
|
*
|
||||||
* @param clientFactory The client factory function.
|
* @param clientFactory The client factory function.
|
||||||
*/
|
*/
|
||||||
void TCPServer::SetClientFactory(function<TCPClient::Ptr()> clientFactory)
|
void TcpServer::SetClientFactory(function<TcpClient::Ptr()> clientFactory)
|
||||||
{
|
{
|
||||||
m_ClientFactory = clientFactory;
|
m_ClientFactory = clientFactory;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ void TCPServer::SetClientFactory(function<TCPClient::Ptr()> clientFactory)
|
||||||
*
|
*
|
||||||
* @returns The client factory function.
|
* @returns The client factory function.
|
||||||
*/
|
*/
|
||||||
function<TCPClient::Ptr()> TCPServer::GetFactoryFunction(void) const
|
function<TcpClient::Ptr()> TcpServer::GetFactoryFunction(void) const
|
||||||
{
|
{
|
||||||
return m_ClientFactory;
|
return m_ClientFactory;
|
||||||
}
|
}
|
||||||
|
@ -52,17 +52,17 @@ function<TCPClient::Ptr()> TCPServer::GetFactoryFunction(void) const
|
||||||
/**
|
/**
|
||||||
* Registers the TCP server and starts processing events for it.
|
* Registers the TCP server and starts processing events for it.
|
||||||
*/
|
*/
|
||||||
void TCPServer::Start(void)
|
void TcpServer::Start(void)
|
||||||
{
|
{
|
||||||
TCPSocket::Start();
|
TcpSocket::Start();
|
||||||
|
|
||||||
OnReadable += bind_weak(&TCPServer::ReadableEventHandler, shared_from_this());
|
OnReadable += bind_weak(&TcpServer::ReadableEventHandler, shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts listening for incoming client connections.
|
* Starts listening for incoming client connections.
|
||||||
*/
|
*/
|
||||||
void TCPServer::Listen(void)
|
void TcpServer::Listen(void)
|
||||||
{
|
{
|
||||||
int rc = listen(GetFD(), SOMAXCONN);
|
int rc = listen(GetFD(), SOMAXCONN);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ void TCPServer::Listen(void)
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int TCPServer::ReadableEventHandler(const EventArgs&)
|
int TcpServer::ReadableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
sockaddr_storage addr;
|
sockaddr_storage addr;
|
||||||
|
@ -94,7 +94,7 @@ int TCPServer::ReadableEventHandler(const EventArgs&)
|
||||||
|
|
||||||
NewClientEventArgs nea;
|
NewClientEventArgs nea;
|
||||||
nea.Source = shared_from_this();
|
nea.Source = shared_from_this();
|
||||||
nea.Client = static_pointer_cast<TCPSocket>(m_ClientFactory());
|
nea.Client = static_pointer_cast<TcpSocket>(m_ClientFactory());
|
||||||
nea.Client->SetFD(fd);
|
nea.Client->SetFD(fd);
|
||||||
nea.Client->Start();
|
nea.Client->Start();
|
||||||
OnNewClient(nea);
|
OnNewClient(nea);
|
||||||
|
@ -107,7 +107,7 @@ int TCPServer::ReadableEventHandler(const EventArgs&)
|
||||||
*
|
*
|
||||||
* @returns true
|
* @returns true
|
||||||
*/
|
*/
|
||||||
bool TCPServer::WantsToRead(void) const
|
bool TcpServer::WantsToRead(void) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace icinga
|
||||||
*/
|
*/
|
||||||
struct I2_BASE_API NewClientEventArgs : public EventArgs
|
struct I2_BASE_API NewClientEventArgs : public EventArgs
|
||||||
{
|
{
|
||||||
TCPSocket::Ptr Client; /**< The new client object. */
|
TcpSocket::Ptr Client; /**< The new client object. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,21 +39,21 @@ struct I2_BASE_API NewClientEventArgs : public EventArgs
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API TCPServer : public TCPSocket
|
class I2_BASE_API TcpServer : public TcpSocket
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int ReadableEventHandler(const EventArgs& ea);
|
int ReadableEventHandler(const EventArgs& ea);
|
||||||
|
|
||||||
function<TCPClient::Ptr()> m_ClientFactory;
|
function<TcpClient::Ptr()> m_ClientFactory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<TCPServer> Ptr;
|
typedef shared_ptr<TcpServer> Ptr;
|
||||||
typedef weak_ptr<TCPServer> WeakPtr;
|
typedef weak_ptr<TcpServer> WeakPtr;
|
||||||
|
|
||||||
TCPServer(void);
|
TcpServer(void);
|
||||||
|
|
||||||
void SetClientFactory(function<TCPClient::Ptr()> function);
|
void SetClientFactory(function<TcpClient::Ptr()> function);
|
||||||
function<TCPClient::Ptr()> GetFactoryFunction(void) const;
|
function<TcpClient::Ptr()> GetFactoryFunction(void) const;
|
||||||
|
|
||||||
virtual void Start();
|
virtual void Start();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ using namespace icinga;
|
||||||
*
|
*
|
||||||
* @param family The socket family for the new socket.
|
* @param family The socket family for the new socket.
|
||||||
*/
|
*/
|
||||||
void TCPSocket::MakeSocket(int family)
|
void TcpSocket::MakeSocket(int family)
|
||||||
{
|
{
|
||||||
assert(GetFD() == INVALID_SOCKET);
|
assert(GetFD() == INVALID_SOCKET);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void TCPSocket::MakeSocket(int family)
|
||||||
* @param service The service.
|
* @param service The service.
|
||||||
* @param family The address family for the socket.
|
* @param family The address family for the socket.
|
||||||
*/
|
*/
|
||||||
void TCPSocket::Bind(string service, int family)
|
void TcpSocket::Bind(string service, int family)
|
||||||
{
|
{
|
||||||
Bind(string(), service, family);
|
Bind(string(), service, family);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ void TCPSocket::Bind(string service, int family)
|
||||||
* @param service The service.
|
* @param service The service.
|
||||||
* @param family The address family for the socket.
|
* @param family The address family for the socket.
|
||||||
*/
|
*/
|
||||||
void TCPSocket::Bind(string node, string service, int family)
|
void TcpSocket::Bind(string node, string service, int family)
|
||||||
{
|
{
|
||||||
addrinfo hints;
|
addrinfo hints;
|
||||||
addrinfo *result;
|
addrinfo *result;
|
||||||
|
|
|
@ -28,14 +28,14 @@ namespace icinga
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API TCPSocket : public Socket
|
class I2_BASE_API TcpSocket : public Socket
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void MakeSocket(int family);
|
void MakeSocket(int family);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<TCPSocket> Ptr;
|
typedef shared_ptr<TcpSocket> Ptr;
|
||||||
typedef weak_ptr<TCPSocket> WeakPtr;
|
typedef weak_ptr<TcpSocket> WeakPtr;
|
||||||
|
|
||||||
void Bind(string service, int family);
|
void Bind(string service, int family);
|
||||||
void Bind(string node, string service, int family);
|
void Bind(string node, string service, int family);
|
||||||
|
|
|
@ -21,16 +21,16 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
int I2_EXPORT TLSClient::m_SSLIndex;
|
int I2_EXPORT TlsClient::m_SSLIndex;
|
||||||
bool I2_EXPORT TLSClient::m_SSLIndexInitialized = false;
|
bool I2_EXPORT TlsClient::m_SSLIndexInitialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the TLSClient class.
|
* Constructor for the TlsClient class.
|
||||||
*
|
*
|
||||||
* @param role The role of the client.
|
* @param role The role of the client.
|
||||||
* @param sslContext The SSL context for the client.
|
* @param sslContext The SSL context for the client.
|
||||||
*/
|
*/
|
||||||
TLSClient::TLSClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext) : TCPClient(role)
|
TlsClient::TlsClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext) : TcpClient(role)
|
||||||
{
|
{
|
||||||
m_SSLContext = sslContext;
|
m_SSLContext = sslContext;
|
||||||
m_BlockRead = false;
|
m_BlockRead = false;
|
||||||
|
@ -42,7 +42,7 @@ TLSClient::TLSClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext) : TCPCl
|
||||||
*
|
*
|
||||||
* @param certificate An X509 certificate.
|
* @param certificate An X509 certificate.
|
||||||
*/
|
*/
|
||||||
void TLSClient::NullCertificateDeleter(X509 *certificate)
|
void TlsClient::NullCertificateDeleter(X509 *certificate)
|
||||||
{
|
{
|
||||||
/* Nothing to do here. */
|
/* Nothing to do here. */
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,9 @@ void TLSClient::NullCertificateDeleter(X509 *certificate)
|
||||||
*
|
*
|
||||||
* @returns The X509 certificate.
|
* @returns The X509 certificate.
|
||||||
*/
|
*/
|
||||||
shared_ptr<X509> TLSClient::GetClientCertificate(void) const
|
shared_ptr<X509> TlsClient::GetClientCertificate(void) const
|
||||||
{
|
{
|
||||||
return shared_ptr<X509>(SSL_get_certificate(m_SSL.get()), &TLSClient::NullCertificateDeleter);
|
return shared_ptr<X509>(SSL_get_certificate(m_SSL.get()), &TlsClient::NullCertificateDeleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ shared_ptr<X509> TLSClient::GetClientCertificate(void) const
|
||||||
*
|
*
|
||||||
* @returns The X509 certificate.
|
* @returns The X509 certificate.
|
||||||
*/
|
*/
|
||||||
shared_ptr<X509> TLSClient::GetPeerCertificate(void) const
|
shared_ptr<X509> TlsClient::GetPeerCertificate(void) const
|
||||||
{
|
{
|
||||||
return shared_ptr<X509>(SSL_get_peer_certificate(m_SSL.get()), X509_free);
|
return shared_ptr<X509>(SSL_get_peer_certificate(m_SSL.get()), X509_free);
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,9 @@ shared_ptr<X509> TLSClient::GetPeerCertificate(void) const
|
||||||
/**
|
/**
|
||||||
* Registers the TLS socket and starts processing events for it.
|
* Registers the TLS socket and starts processing events for it.
|
||||||
*/
|
*/
|
||||||
void TLSClient::Start(void)
|
void TlsClient::Start(void)
|
||||||
{
|
{
|
||||||
TCPClient::Start();
|
TcpClient::Start();
|
||||||
|
|
||||||
m_SSL = shared_ptr<SSL>(SSL_new(m_SSLContext.get()), SSL_free);
|
m_SSL = shared_ptr<SSL>(SSL_new(m_SSLContext.get()), SSL_free);
|
||||||
|
|
||||||
|
@ -83,14 +83,14 @@ void TLSClient::Start(void)
|
||||||
throw InvalidArgumentException("No X509 client certificate was specified.");
|
throw InvalidArgumentException("No X509 client certificate was specified.");
|
||||||
|
|
||||||
if (!m_SSLIndexInitialized) {
|
if (!m_SSLIndexInitialized) {
|
||||||
m_SSLIndex = SSL_get_ex_new_index(0, (void *)"TLSClient", NULL, NULL, NULL);
|
m_SSLIndex = SSL_get_ex_new_index(0, (void *)"TlsClient", NULL, NULL, NULL);
|
||||||
m_SSLIndexInitialized = true;
|
m_SSLIndexInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL_set_ex_data(m_SSL.get(), m_SSLIndex, this);
|
SSL_set_ex_data(m_SSL.get(), m_SSLIndex, this);
|
||||||
|
|
||||||
SSL_set_verify(m_SSL.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
SSL_set_verify(m_SSL.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
||||||
&TLSClient::SSLVerifyCertificate);
|
&TlsClient::SSLVerifyCertificate);
|
||||||
|
|
||||||
BIO *bio = BIO_new_socket(GetFD(), 0);
|
BIO *bio = BIO_new_socket(GetFD(), 0);
|
||||||
SSL_set_bio(m_SSL.get(), bio, bio);
|
SSL_set_bio(m_SSL.get(), bio, bio);
|
||||||
|
@ -109,7 +109,7 @@ void TLSClient::Start(void)
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int TLSClient::ReadableEventHandler(const EventArgs&)
|
int TlsClient::ReadableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ int TLSClient::ReadableEventHandler(const EventArgs&)
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int TLSClient::WritableEventHandler(const EventArgs&)
|
int TlsClient::WritableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ int TLSClient::WritableEventHandler(const EventArgs&)
|
||||||
*
|
*
|
||||||
* @returns true if data should be read, false otherwise.
|
* @returns true if data should be read, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool TLSClient::WantsToRead(void) const
|
bool TlsClient::WantsToRead(void) const
|
||||||
{
|
{
|
||||||
if (SSL_want_read(m_SSL.get()))
|
if (SSL_want_read(m_SSL.get()))
|
||||||
return true;
|
return true;
|
||||||
|
@ -198,7 +198,7 @@ bool TLSClient::WantsToRead(void) const
|
||||||
if (m_BlockRead)
|
if (m_BlockRead)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return TCPClient::WantsToRead();
|
return TcpClient::WantsToRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,7 +206,7 @@ bool TLSClient::WantsToRead(void) const
|
||||||
*
|
*
|
||||||
* @returns true if data should be written, false otherwise.
|
* @returns true if data should be written, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool TLSClient::WantsToWrite(void) const
|
bool TlsClient::WantsToWrite(void) const
|
||||||
{
|
{
|
||||||
if (SSL_want_write(m_SSL.get()))
|
if (SSL_want_write(m_SSL.get()))
|
||||||
return true;
|
return true;
|
||||||
|
@ -214,7 +214,7 @@ bool TLSClient::WantsToWrite(void) const
|
||||||
if (m_BlockWrite)
|
if (m_BlockWrite)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return TCPClient::WantsToWrite();
|
return TcpClient::WantsToWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,17 +222,17 @@ bool TLSClient::WantsToWrite(void) const
|
||||||
*
|
*
|
||||||
* @param from_dtor Whether this method was invoked from the destructor.
|
* @param from_dtor Whether this method was invoked from the destructor.
|
||||||
*/
|
*/
|
||||||
void TLSClient::CloseInternal(bool from_dtor)
|
void TlsClient::CloseInternal(bool from_dtor)
|
||||||
{
|
{
|
||||||
SSL_shutdown(m_SSL.get());
|
SSL_shutdown(m_SSL.get());
|
||||||
|
|
||||||
TCPClient::CloseInternal(from_dtor);
|
TcpClient::CloseInternal(from_dtor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles an OpenSSL error.
|
* Handles an OpenSSL error.
|
||||||
*/
|
*/
|
||||||
void TLSClient::HandleSSLError(void)
|
void TlsClient::HandleSSLError(void)
|
||||||
{
|
{
|
||||||
int code = ERR_get_error();
|
int code = ERR_get_error();
|
||||||
|
|
||||||
|
@ -248,15 +248,15 @@ void TLSClient::HandleSSLError(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory function for the TLSClient class.
|
* Factory function for the TlsClient class.
|
||||||
*
|
*
|
||||||
* @param role The role of the TLS socket.
|
* @param role The role of the TLS socket.
|
||||||
* @param sslContext The SSL context for the socket.
|
* @param sslContext The SSL context for the socket.
|
||||||
* @returns A new TLS socket.
|
* @returns A new TLS socket.
|
||||||
*/
|
*/
|
||||||
TCPClient::Ptr icinga::TLSClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext)
|
TcpClient::Ptr icinga::TlsClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
return make_shared<TLSClient>(role, sslContext);
|
return make_shared<TlsClient>(role, sslContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,10 +266,10 @@ TCPClient::Ptr icinga::TLSClientFactory(TCPClientRole role, shared_ptr<SSL_CTX>
|
||||||
* @param x509Context X509 context for the certificate.
|
* @param x509Context X509 context for the certificate.
|
||||||
* @returns 1 if the verification was successful, 0 otherwise.
|
* @returns 1 if the verification was successful, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int TLSClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
|
int TlsClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
|
||||||
{
|
{
|
||||||
SSL *ssl = (SSL *)X509_STORE_CTX_get_ex_data(x509Context, SSL_get_ex_data_X509_STORE_CTX_idx());
|
SSL *ssl = (SSL *)X509_STORE_CTX_get_ex_data(x509Context, SSL_get_ex_data_X509_STORE_CTX_idx());
|
||||||
TLSClient *client = (TLSClient *)SSL_get_ex_data(ssl, m_SSLIndex);
|
TlsClient *client = (TlsClient *)SSL_get_ex_data(ssl, m_SSLIndex);
|
||||||
|
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -278,7 +278,7 @@ int TLSClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
|
||||||
vcea.Source = client->shared_from_this();
|
vcea.Source = client->shared_from_this();
|
||||||
vcea.ValidCertificate = (ok != 0);
|
vcea.ValidCertificate = (ok != 0);
|
||||||
vcea.Context = x509Context;
|
vcea.Context = x509Context;
|
||||||
vcea.Certificate = shared_ptr<X509>(x509Context->cert, &TLSClient::NullCertificateDeleter);
|
vcea.Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
|
||||||
client->OnVerifyCertificate(vcea);
|
client->OnVerifyCertificate(vcea);
|
||||||
|
|
||||||
return (int)vcea.ValidCertificate;
|
return (int)vcea.ValidCertificate;
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct I2_BASE_API VerifyCertificateEventArgs : public EventArgs
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API TLSClient : public TCPClient
|
class I2_BASE_API TlsClient : public TcpClient
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
shared_ptr<SSL_CTX> m_SSLContext;
|
shared_ptr<SSL_CTX> m_SSLContext;
|
||||||
|
@ -67,7 +67,7 @@ protected:
|
||||||
void HandleSSLError(void);
|
void HandleSSLError(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TLSClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
|
TlsClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
|
||||||
shared_ptr<X509> GetClientCertificate(void) const;
|
shared_ptr<X509> GetClientCertificate(void) const;
|
||||||
shared_ptr<X509> GetPeerCertificate(void) const;
|
shared_ptr<X509> GetPeerCertificate(void) const;
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
Observable<VerifyCertificateEventArgs> OnVerifyCertificate;
|
Observable<VerifyCertificateEventArgs> OnVerifyCertificate;
|
||||||
};
|
};
|
||||||
|
|
||||||
TCPClient::Ptr TLSClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
|
TcpClient::Ptr TlsClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,6 @@ namespace icinga
|
||||||
*/
|
*/
|
||||||
struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
|
struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
|
||||||
{
|
{
|
||||||
typedef shared_ptr<NewRequestEventArgs> Ptr;
|
|
||||||
typedef weak_ptr<NewRequestEventArgs> WeakPtr;
|
|
||||||
|
|
||||||
Endpoint::Ptr Sender;
|
Endpoint::Ptr Sender;
|
||||||
RpcRequest Request;
|
RpcRequest Request;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,21 +21,38 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
JsonRpcClient::JsonRpcClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext)
|
/**
|
||||||
: TLSClient(role, sslContext) { }
|
* Constructor for the JsonRpcClient class.
|
||||||
|
*
|
||||||
|
* @param role The role of the underlying TCP client.
|
||||||
|
* @param sslContext SSL context for the TLS connection.
|
||||||
|
*/
|
||||||
|
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
|
: TlsClient(role, sslContext) { }
|
||||||
|
|
||||||
void JsonRpcClient::Start(void)
|
void JsonRpcClient::Start(void)
|
||||||
{
|
{
|
||||||
TLSClient::Start();
|
TlsClient::Start();
|
||||||
|
|
||||||
OnDataAvailable += bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this());
|
OnDataAvailable += bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to the connected peer.
|
||||||
|
*
|
||||||
|
* @param message The message.
|
||||||
|
*/
|
||||||
void JsonRpcClient::SendMessage(const MessagePart& message)
|
void JsonRpcClient::SendMessage(const MessagePart& message)
|
||||||
{
|
{
|
||||||
Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
|
Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes inbound data.
|
||||||
|
*
|
||||||
|
* @param - Event arguments for the event.
|
||||||
|
* @returns 0
|
||||||
|
*/
|
||||||
int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -56,14 +73,21 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
||||||
Application::Log("Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
Application::Log("Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPClient::Ptr icinga::JsonRpcClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext)
|
/**
|
||||||
|
* Factory function for JSON-RPC clients.
|
||||||
|
*
|
||||||
|
* @param role The role of the underlying TCP client.
|
||||||
|
* @param sslContext SSL context for the TLS connection.
|
||||||
|
* @returns A new JSON-RPC client.
|
||||||
|
*/
|
||||||
|
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
return make_shared<JsonRpcClient>(role, sslContext);
|
return make_shared<JsonRpcClient>(role, sslContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,6 @@ namespace icinga
|
||||||
*/
|
*/
|
||||||
struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
|
struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
|
||||||
{
|
{
|
||||||
typedef shared_ptr<NewMessageEventArgs> Ptr;
|
|
||||||
typedef weak_ptr<NewMessageEventArgs> WeakPtr;
|
|
||||||
|
|
||||||
icinga::MessagePart Message;
|
icinga::MessagePart Message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,16 +38,16 @@ struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
|
||||||
*
|
*
|
||||||
* @ingroup jsonrpc
|
* @ingroup jsonrpc
|
||||||
*/
|
*/
|
||||||
class I2_JSONRPC_API JsonRpcClient : public TLSClient
|
class I2_JSONRPC_API JsonRpcClient : public TlsClient
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int DataAvailableHandler(const EventArgs& ea);
|
int DataAvailableHandler(const EventArgs&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<JsonRpcClient> Ptr;
|
typedef shared_ptr<JsonRpcClient> Ptr;
|
||||||
typedef weak_ptr<JsonRpcClient> WeakPtr;
|
typedef weak_ptr<JsonRpcClient> WeakPtr;
|
||||||
|
|
||||||
JsonRpcClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
|
JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
|
||||||
void SendMessage(const MessagePart& message);
|
void SendMessage(const MessagePart& message);
|
||||||
|
|
||||||
|
@ -59,7 +56,7 @@ public:
|
||||||
Observable<NewMessageEventArgs> OnNewMessage;
|
Observable<NewMessageEventArgs> OnNewMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
TCPClient::Ptr JsonRpcClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
|
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the JsonRpcServer class.
|
||||||
|
*
|
||||||
|
* @param sslContext SSL context that should be used for client connections.
|
||||||
|
*/
|
||||||
JsonRpcServer::JsonRpcServer(shared_ptr<SSL_CTX> sslContext)
|
JsonRpcServer::JsonRpcServer(shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
SetClientFactory(bind(&JsonRpcClientFactory, RoleInbound, sslContext));
|
SetClientFactory(bind(&JsonRpcClientFactory, RoleInbound, sslContext));
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace icinga
|
||||||
*
|
*
|
||||||
* @ingroup jsonrpc
|
* @ingroup jsonrpc
|
||||||
*/
|
*/
|
||||||
class I2_JSONRPC_API JsonRpcServer : public TCPServer
|
class I2_JSONRPC_API JsonRpcServer : public TcpServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<JsonRpcServer> Ptr;
|
typedef shared_ptr<JsonRpcServer> Ptr;
|
||||||
|
|
|
@ -22,11 +22,20 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the MessagePart class.
|
||||||
|
*/
|
||||||
MessagePart::MessagePart(void)
|
MessagePart::MessagePart(void)
|
||||||
{
|
{
|
||||||
m_Dictionary = make_shared<Dictionary>();
|
m_Dictionary = make_shared<Dictionary>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the MessagePart class.
|
||||||
|
*
|
||||||
|
* @param jsonString The JSON string that should be used to initialize
|
||||||
|
* the message.
|
||||||
|
*/
|
||||||
MessagePart::MessagePart(string jsonString)
|
MessagePart::MessagePart(string jsonString)
|
||||||
{
|
{
|
||||||
json_t *json = cJSON_Parse(jsonString.c_str());
|
json_t *json = cJSON_Parse(jsonString.c_str());
|
||||||
|
@ -39,16 +48,32 @@ MessagePart::MessagePart(string jsonString)
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the MessagePart class.
|
||||||
|
*
|
||||||
|
* @param dictionary The dictionary that this MessagePart object should wrap.
|
||||||
|
*/
|
||||||
MessagePart::MessagePart(const Dictionary::Ptr& dictionary)
|
MessagePart::MessagePart(const Dictionary::Ptr& dictionary)
|
||||||
{
|
{
|
||||||
m_Dictionary = dictionary;
|
m_Dictionary = dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy-constructor for the MessagePart class.
|
||||||
|
*
|
||||||
|
* @param message The message that should be copied.
|
||||||
|
*/
|
||||||
MessagePart::MessagePart(const MessagePart& message)
|
MessagePart::MessagePart(const MessagePart& message)
|
||||||
{
|
{
|
||||||
m_Dictionary = message.GetDictionary();
|
m_Dictionary = message.GetDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a JSON object to a dictionary.
|
||||||
|
*
|
||||||
|
* @param json The JSON object.
|
||||||
|
* @returns A dictionary that is equivalent to the JSON object.
|
||||||
|
*/
|
||||||
Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
|
Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dictionary = make_shared<Dictionary>();
|
Dictionary::Ptr dictionary = make_shared<Dictionary>();
|
||||||
|
@ -72,6 +97,13 @@ Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
|
||||||
return dictionary;
|
return dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a dictionary to a JSON object.
|
||||||
|
*
|
||||||
|
* @param dictionary The dictionary.
|
||||||
|
* @returns A JSON object that is equivalent to the dictionary. Values that
|
||||||
|
* cannot be represented in JSON are omitted.
|
||||||
|
*/
|
||||||
json_t *MessagePart::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
|
json_t *MessagePart::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
|
||||||
{
|
{
|
||||||
cJSON *json;
|
cJSON *json;
|
||||||
|
@ -102,6 +134,11 @@ json_t *MessagePart::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a message into a JSON string.
|
||||||
|
*
|
||||||
|
* @returns A JSON string representing the message.
|
||||||
|
*/
|
||||||
string MessagePart::ToJsonString(void) const
|
string MessagePart::ToJsonString(void) const
|
||||||
{
|
{
|
||||||
json_t *json = GetJsonFromDictionary(m_Dictionary);
|
json_t *json = GetJsonFromDictionary(m_Dictionary);
|
||||||
|
@ -123,11 +160,23 @@ string MessagePart::ToJsonString(void) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the underlying dictionary for this message.
|
||||||
|
*
|
||||||
|
* @returns A dictionary.
|
||||||
|
*/
|
||||||
Dictionary::Ptr MessagePart::GetDictionary(void) const
|
Dictionary::Ptr MessagePart::GetDictionary(void) const
|
||||||
{
|
{
|
||||||
return m_Dictionary;
|
return m_Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a property's value.
|
||||||
|
*
|
||||||
|
* @param key The name of the property.
|
||||||
|
* @param[out] The value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool MessagePart::GetProperty(string key, MessagePart *value) const
|
bool MessagePart::GetProperty(string key, MessagePart *value) const
|
||||||
{
|
{
|
||||||
Object::Ptr object;
|
Object::Ptr object;
|
||||||
|
@ -142,27 +191,45 @@ bool MessagePart::GetProperty(string key, MessagePart *value) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a property's value.
|
||||||
|
*
|
||||||
|
* @param key The name of the property.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void MessagePart::SetProperty(string key, const MessagePart& value)
|
void MessagePart::SetProperty(string key, const MessagePart& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetProperty(key, value.GetDictionary());
|
GetDictionary()->SetProperty(key, value.GetDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to the message using an automatically generated property name.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
void MessagePart::AddUnnamedProperty(const MessagePart& value)
|
void MessagePart::AddUnnamedProperty(const MessagePart& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->AddUnnamedProperty(value.GetDictionary());
|
GetDictionary()->AddUnnamedProperty(value.GetDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator that points to the first element of the dictionary
|
||||||
|
* which holds the properties for the message.
|
||||||
|
*
|
||||||
|
* @returns An iterator.
|
||||||
|
*/
|
||||||
DictionaryIterator MessagePart::Begin(void)
|
DictionaryIterator MessagePart::Begin(void)
|
||||||
{
|
{
|
||||||
return GetDictionary()->Begin();
|
return GetDictionary()->Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an iterator that points past the last element of the dictionary
|
||||||
|
* which holds the properties for the message.
|
||||||
|
*
|
||||||
|
* @returns An iterator.
|
||||||
|
*/
|
||||||
DictionaryIterator MessagePart::End(void)
|
DictionaryIterator MessagePart::End(void)
|
||||||
{
|
{
|
||||||
return GetDictionary()->End();
|
return GetDictionary()->End();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePart::operator Dictionary::Ptr(void)
|
|
||||||
{
|
|
||||||
return GetDictionary();
|
|
||||||
}
|
|
||||||
|
|
|
@ -50,12 +50,25 @@ public:
|
||||||
|
|
||||||
Dictionary::Ptr GetDictionary(void) const;
|
Dictionary::Ptr GetDictionary(void) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a property's value.
|
||||||
|
*
|
||||||
|
* @param key The name of the property.
|
||||||
|
* @param[out] The value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool GetProperty(string key, T *value) const
|
bool GetProperty(string key, T *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetProperty(key, value);
|
return GetDictionary()->GetProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a property's value.
|
||||||
|
*
|
||||||
|
* @param key The name of the property.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SetProperty(string key, const T& value)
|
void SetProperty(string key, const T& value)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +78,11 @@ public:
|
||||||
bool GetProperty(string key, MessagePart *value) const;
|
bool GetProperty(string key, MessagePart *value) const;
|
||||||
void SetProperty(string key, const MessagePart& value);
|
void SetProperty(string key, const MessagePart& value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to the message using an automatically generated property name.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void AddUnnamedProperty(const T& value)
|
void AddUnnamedProperty(const T& value)
|
||||||
{
|
{
|
||||||
|
@ -75,8 +93,6 @@ public:
|
||||||
|
|
||||||
DictionaryIterator Begin(void);
|
DictionaryIterator Begin(void);
|
||||||
DictionaryIterator End(void);
|
DictionaryIterator End(void);
|
||||||
|
|
||||||
operator Dictionary::Ptr(void);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,49 +30,100 @@ namespace icinga
|
||||||
*/
|
*/
|
||||||
class I2_JSONRPC_API RpcRequest : public MessagePart
|
class I2_JSONRPC_API RpcRequest : public MessagePart
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor for the RpcRequest class.
|
||||||
|
*/
|
||||||
RpcRequest(void) : MessagePart() {
|
RpcRequest(void) : MessagePart() {
|
||||||
SetVersion("2.0");
|
SetVersion("2.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy-constructor for the RpcRequest class.
|
||||||
|
*
|
||||||
|
* @param message The message that is to be copied.
|
||||||
|
*/
|
||||||
RpcRequest(const MessagePart& message) : MessagePart(message) { }
|
RpcRequest(const MessagePart& message) : MessagePart(message) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the version of the JSON-RPC protocol.
|
||||||
|
*
|
||||||
|
* @param[out] value The value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
inline bool GetVersion(string *value) const
|
inline bool GetVersion(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("jsonrpc", value);
|
return GetProperty("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the version of the JSON-RPC protocol that should be used.
|
||||||
|
*
|
||||||
|
* @param value The version.
|
||||||
|
*/
|
||||||
inline void SetVersion(const string& value)
|
inline void SetVersion(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("jsonrpc", value);
|
SetProperty("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the method of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The method.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
inline bool GetMethod(string *value) const
|
inline bool GetMethod(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("method", value);
|
return GetProperty("method", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the method for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The method.
|
||||||
|
*/
|
||||||
inline void SetMethod(const string& value)
|
inline void SetMethod(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("method", value);
|
SetProperty("method", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the parameters of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The parameters.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
inline bool GetParams(MessagePart *value) const
|
inline bool GetParams(MessagePart *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("params", value);
|
return GetProperty("params", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the parameters for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The parameters.
|
||||||
|
*/
|
||||||
inline void SetParams(const MessagePart& value)
|
inline void SetParams(const MessagePart& value)
|
||||||
{
|
{
|
||||||
SetProperty("params", value);
|
SetProperty("params", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the ID of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The ID.
|
||||||
|
* @return true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
inline bool GetID(string *value) const
|
inline bool GetID(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("id", value);
|
return GetProperty("id", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ID for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The ID.
|
||||||
|
*/
|
||||||
inline void SetID(const string& value)
|
inline void SetID(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("id", value);
|
SetProperty("id", value);
|
||||||
|
|
|
@ -31,47 +31,99 @@ namespace icinga
|
||||||
class I2_JSONRPC_API RpcResponse : public MessagePart
|
class I2_JSONRPC_API RpcResponse : public MessagePart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor for the RpcResponse class.
|
||||||
|
*/
|
||||||
RpcResponse(void) : MessagePart() {
|
RpcResponse(void) : MessagePart() {
|
||||||
SetVersion("2.0");
|
SetVersion("2.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy-constructor for the RpcResponse class.
|
||||||
|
*
|
||||||
|
* @param message The message that should be copied.
|
||||||
|
*/
|
||||||
RpcResponse(const MessagePart& message) : MessagePart(message) { }
|
RpcResponse(const MessagePart& message) : MessagePart(message) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the version of the JSON-RPC protocol.
|
||||||
|
*
|
||||||
|
* @param[out] value The value.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
inline bool GetVersion(string *value) const
|
inline bool GetVersion(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("jsonrpc", value);
|
return GetProperty("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the version of the JSON-RPC protocol that should be used.
|
||||||
|
*
|
||||||
|
* @param value The version.
|
||||||
|
*/
|
||||||
inline void SetVersion(const string& value)
|
inline void SetVersion(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("jsonrpc", value);
|
SetProperty("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetResult(string *value) const
|
/**
|
||||||
|
* Retrieves the result of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The result.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
|
bool GetResult(MessagePart *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("result", value);
|
return GetProperty("result", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetResult(const string& value)
|
/**
|
||||||
|
* Sets the result for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The result.
|
||||||
|
*/
|
||||||
|
void SetResult(const MessagePart& value)
|
||||||
{
|
{
|
||||||
SetProperty("result", value);
|
SetProperty("result", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the error message of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The error message.
|
||||||
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool GetError(string *value) const
|
bool GetError(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("error", value);
|
return GetProperty("error", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the error message for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The error message.
|
||||||
|
*/
|
||||||
void SetError(const string& value)
|
void SetError(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("error", value);
|
SetProperty("error", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the ID of the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param[out] value The ID.
|
||||||
|
* @return true if the value was retrieved, false otherwise.
|
||||||
|
*/
|
||||||
bool GetID(string *value) const
|
bool GetID(string *value) const
|
||||||
{
|
{
|
||||||
return GetProperty("id", value);
|
return GetProperty("id", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ID for the JSON-RPC call.
|
||||||
|
*
|
||||||
|
* @param value The ID.
|
||||||
|
*/
|
||||||
void SetID(const string& value)
|
void SetID(const string& value)
|
||||||
{
|
{
|
||||||
SetProperty("id", value);
|
SetProperty("id", value);
|
||||||
|
|
Loading…
Reference in New Issue