X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fhttpd.h;h=b4b88bed5ace1bc3084dec33d401605f28a21d88;hb=79892a727e323dcc4bce7e9c0cf3c99c5fe61706;hp=d1746e862f99afc80fd598e68e54f6de40b3c4c6;hpb=d9d99cd02dadf34bfcc220734ba0c422f0acb3e6;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/httpd.h b/include/modules/httpd.h index d1746e862..b4b88bed5 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -24,6 +24,7 @@ #pragma once #include "base.h" +#include "event.h" #include #include @@ -107,7 +108,7 @@ class HttpServerSocket; /** This class represents a HTTP request. */ -class HTTPRequest : public Event +class HTTPRequest { protected: std::string type; @@ -134,9 +135,9 @@ class HTTPRequest : public Event * @param ip The IP address making the web request. * @param pdata The post data (content after headers) received with the request, up to Content-Length in size */ - HTTPRequest(Module* me, const std::string &eventid, const std::string &request_type, const std::string &uri, + HTTPRequest(const std::string& request_type, const std::string& uri, HTTPHeaders* hdr, HttpServerSocket* socket, const std::string &ip, const std::string &pdata) - : Event(me, eventid), type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket) + : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket) { } @@ -177,27 +178,85 @@ class HTTPRequest : public Event } }; -/** You must return a HTTPDocument to the httpd module by using the Request class. - * When you initialize this class you may initialize it with all components required to - * form a valid HTTP response, including document data, headers, and a response code. +/** If you want to reply to HTTP requests, you must return a HTTPDocumentResponse to + * the httpd module via the HTTPdAPI. + * When you initialize this class you initialize it with all components required to + * form a valid HTTP response: the document data and a response code. + * You can add additional HTTP headers, if you want. */ -class HTTPDocumentResponse : public Request +class HTTPDocumentResponse { public: + /** Module that generated this reply + */ + Module* const module; + std::stringstream* document; - int responsecode; + unsigned int responsecode; + + /** Any extra headers to include with the defaults + */ HTTPHeaders headers; + HTTPRequest& src; - /** Initialize a HTTPRequest ready for sending to m_httpd.so. - * @param opaque The socket pointer you obtained from the HTTPRequest at an earlier time + /** Initialize a HTTPDocumentResponse ready for sending to the httpd module. + * @param mod A pointer to the module who responded to the request + * @param req The request you obtained from the HTTPRequest at an earlier time * @param doc A stringstream containing the document body * @param response A valid HTTP/1.0 or HTTP/1.1 response code. The response text will be determined for you * based upon the response code. - * @param extra Any extra headers to include with the defaults, seperated by carriage return and linefeed. */ - HTTPDocumentResponse(Module* me, HTTPRequest& req, std::stringstream* doc, int response) - : Request(me, req.source, "HTTP-DOC"), document(doc), responsecode(response), src(req) + HTTPDocumentResponse(Module* mod, HTTPRequest& req, std::stringstream* doc, unsigned int response) + : module(mod), document(doc), responsecode(response), src(req) + { + } +}; + +class HTTPdAPIBase : public DataProvider +{ + public: + HTTPdAPIBase(Module* parent) + : DataProvider(parent, "m_httpd_api") + { + } + + /** Answer an incoming HTTP request with the provided document + * @param response The response created by your module that will be sent to the client + */ + virtual void SendResponse(HTTPDocumentResponse& response) = 0; +}; + +/** The API provided by the httpd module that allows other modules to respond to incoming + * HTTP requests + */ +class HTTPdAPI : public dynamic_reference +{ + public: + HTTPdAPI(Module* parent) + : dynamic_reference(parent, "m_httpd_api") + { + } +}; + +class HTTPACLEventListener : public Events::ModuleEventListener +{ + public: + HTTPACLEventListener(Module* mod) + : ModuleEventListener(mod, "event/http-acl") { } + + virtual ModResult OnHTTPACLCheck(HTTPRequest& req) = 0; +}; + +class HTTPRequestEventListener : public Events::ModuleEventListener +{ + public: + HTTPRequestEventListener(Module* mod) + : ModuleEventListener(mod, "event/http-request") + { + } + + virtual ModResult OnHTTPRequest(HTTPRequest& req) = 0; };