icinga2/lib/remote/httphandler.hpp

67 lines
1.4 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"
#include "remote/url.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>
#include <boost/beast/http.hpp>
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,
boost::beast::http::request<boost::beast::http::string_body>& request,
const Url::Ptr& url,
boost::beast::http::response<boost::beast::http::string_body>& 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,
boost::beast::http::request<boost::beast::http::string_body>& request,
boost::beast::http::response<boost::beast::http::string_body>& 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 */