X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fhttpd.h;h=e1921cdb486f5ee08c344b5b965c8c76e78c7011;hb=51b9b4c9b404bd801be194644133be47bd035b58;hp=86234d53faddfcf697379681fb52712fe7a98c17;hpb=f62654a6859998f9d63eb22702c572d5ebcff15c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/httpd.h b/include/modules/httpd.h index 86234d53f..e1921cdb4 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -24,11 +24,66 @@ #pragma once #include "base.h" +#include "event.h" #include #include #include +class HTTPQueryParameters : public insp::flat_multimap +{ + public: + bool get(const std::string& key, std::string& value) const + { + const_iterator it = find(key); + if (it == end()) + return false; + + value = it->second; + return true; + } + + std::string getString(const std::string& key, const std::string& def = "") const + { + std::string value; + if (!get(key, value)) + return def; + + return value; + } + + template + T getNum(const std::string& key, T def = 0) const + { + std::string value; + if (!get(key, value)) + return def; + + return ConvToNum(value); + } + + unsigned long getDuration(const std::string& key, unsigned long def = 0) const + { + unsigned long value; + if (!InspIRCd::Duration(getString(key, "0"), value)) + return def; + + return value; + } + + bool getBool(const std::string& key, bool def = false) const + { + return getNum(key, def); + } +}; + +struct HTTPRequestURI +{ + std::string path; + HTTPQueryParameters query_params; + std::string fragment; +}; + /** A modifyable list of HTTP header fields */ class HTTPHeaders @@ -107,13 +162,13 @@ class HttpServerSocket; /** This class represents a HTTP request. */ -class HTTPRequest : public Event +class HTTPRequest { protected: std::string type; - std::string document; std::string ipaddr; std::string postdata; + HTTPRequestURI parseduri; public: @@ -128,15 +183,19 @@ class HTTPRequest : public Event /** Initialize HTTPRequest. * This constructor is called by m_httpd.so to initialize the class. * @param request_type The request type, e.g. GET, POST, HEAD - * @param uri The URI, e.g. /page * @param hdr The headers sent with the request * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply. * @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 HTTPRequestURI& Parseduri, 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) + , ipaddr(ip) + , postdata(pdata) + , parseduri(Parseduri) + , headers(hdr) + , sock(socket) { } @@ -158,13 +217,14 @@ class HTTPRequest : public Event return type; } - /** Get URI. - * The URI string (URL minus hostname and scheme) will be provided by this function. - * @return The URI being requested - */ - std::string& GetURI() + HTTPRequestURI& GetParsedURI() { - return document; + return parseduri; + } + + std::string& GetPath() + { + return GetParsedURI().path; } /** Get IP address of requester. @@ -237,3 +297,25 @@ class HTTPdAPI : public dynamic_reference { } }; + +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; +};