icinga2/lib/remote/httphandler.hpp

55 lines
1.1 KiB
C++
Raw Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2015-06-22 11:11:21 +02:00
#ifndef HTTPHANDLER_H
#define HTTPHANDLER_H
2014-05-25 16:23:35 +02:00
#include "remote/i2-remote.hpp"
2015-06-22 11:11:21 +02:00
#include "remote/httpresponse.hpp"
#include "remote/apiuser.hpp"
2015-06-22 11:11:21 +02:00
#include "base/registry.hpp"
#include <vector>
namespace icinga
{
/**
2015-06-22 11:11:21 +02:00
* HTTP handler.
*
* @ingroup remote
*/
2017-12-31 07:22:16 +01:00
class HttpHandler : public Object
{
public:
2015-06-22 11:11:21 +02:00
DECLARE_PTR_TYPEDEFS(HttpHandler);
virtual bool HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params) = 0;
2015-06-22 11:11:21 +02:00
static void Register(const Url::Ptr& url, const HttpHandler::Ptr& handler);
static void ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response);
private:
2015-06-22 11:11:21 +02:00
static Dictionary::Ptr m_UrlTree;
};
2015-06-22 11:11:21 +02:00
/**
* Helper class for registering HTTP handlers.
*
* @ingroup remote
*/
2017-12-31 07:22:16 +01:00
class RegisterHttpHandler
2015-06-22 11:11:21 +02:00
{
public:
RegisterHttpHandler(const String& url, const HttpHandler& function);
};
2015-06-22 11:11:21 +02:00
#define REGISTER_URLHANDLER(url, klass) \
INITIALIZE_ONCE([]() { \
Url::Ptr uurl = new Url(url); \
HttpHandler::Ptr handler = new klass(); \
HttpHandler::Register(uurl, handler); \
})
2015-06-22 11:11:21 +02:00
}
2015-06-22 11:11:21 +02:00
#endif /* HTTPHANDLER_H */