2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#ifndef HTTPHANDLER_H
|
|
|
|
#define HTTPHANDLER_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
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"
|
2015-07-09 15:27:14 +02:00
|
|
|
#include "remote/apiuser.hpp"
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "base/registry.hpp"
|
|
|
|
#include <vector>
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2015-06-22 11:11:21 +02:00
|
|
|
* HTTP handler.
|
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
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class HttpHandler : public Object
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-06-22 11:11:21 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(HttpHandler);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2016-05-10 15:16:35 +02:00
|
|
|
virtual bool HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params) = 0;
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
static void Register(const Url::Ptr& url, const HttpHandler::Ptr& handler);
|
2015-07-09 15:27:14 +02:00
|
|
|
static void ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response);
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
private:
|
2015-06-22 11:11:21 +02:00
|
|
|
static Dictionary::Ptr m_UrlTree;
|
|
|
|
};
|
2015-02-26 12:41:47 +01:00
|
|
|
|
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);
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#define REGISTER_URLHANDLER(url, klass) \
|
2016-08-27 09:35:08 +02:00
|
|
|
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
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#endif /* HTTPHANDLER_H */
|