X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fhttpd.h;h=f3402c8d84ab64e632cec4c050305e69e9e24ce1;hb=e94b673532f7833aaa4789f834e61d68e0b4fc56;hp=b4b88bed5ace1bc3084dec33d401605f28a21d88;hpb=35b70631f0532a5828b04a8e0c02092a285f331a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/httpd.h b/include/modules/httpd.h index b4b88bed5..f3402c8d8 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -1,11 +1,14 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2019 linuxdaemon + * Copyright (C) 2013, 2021 Sadie Powell + * Copyright (C) 2013, 2015 Attila Molnar + * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2008 Pippijn van Steenhoven - * Copyright (C) 2007 John Brooks + * Copyright (C) 2007 John Brooks * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2006 Craig Edwards + * Copyright (C) 2006, 2008, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -30,6 +33,60 @@ #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 @@ -112,9 +169,9 @@ class HTTPRequest { protected: std::string type; - std::string document; std::string ipaddr; std::string postdata; + HTTPRequestURI parseduri; public: @@ -129,15 +186,20 @@ class HTTPRequest /** 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 parsed_uri The URI which was requested by the client. * @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 socket The server socket which this request came in via. * @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(const std::string& request_type, const std::string& uri, - HTTPHeaders* hdr, HttpServerSocket* socket, const std::string &ip, const std::string &pdata) - : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(socket) + HTTPRequest(const std::string& request_type, const HTTPRequestURI& parsed_uri, HTTPHeaders* hdr, + HttpServerSocket* socket, const std::string& ip, const std::string& pdata) + : type(request_type) + , ipaddr(ip) + , postdata(pdata) + , parseduri(parsed_uri) + , headers(hdr) + , sock(socket) { } @@ -159,13 +221,14 @@ class HTTPRequest 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 parseduri; + } + + std::string& GetPath() { - return document; + return GetParsedURI().path; } /** Get IP address of requester.