X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fhttpd.h;h=a8b0bafcdc81f2c26307d27c8972e67d0c508eac;hb=7c197db72eab03321e4f3e847054e13126520504;hp=3f8ee215cdff88a723923ad7bc8601220edfb6b1;hpb=1ce6fe7525c8213682d6cfca2acd9420d4e72f36;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/httpd.h b/src/modules/httpd.h index 3f8ee215c..a8b0bafcd 100644 --- a/src/modules/httpd.h +++ b/src/modules/httpd.h @@ -1,3 +1,16 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + #include "base.h" #ifndef __HTTPD_H__ @@ -6,6 +19,10 @@ #include #include +/** This class represents a HTTP request. + * It will be sent to all modules as the data section of + * an Event. + */ class HTTPRequest : public classbase { protected: @@ -13,66 +30,137 @@ class HTTPRequest : public classbase std::string type; std::string document; std::string ipaddr; + std::string postdata; std::stringstream* headers; public: + /** A socket pointer, which you must return in your HTTPDocument class + * if you reply to this request. + */ void* sock; - HTTPRequest(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip) - : type(request_type), document(uri), ipaddr(ip), headers(hdr), sock(opaque) + /** 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(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip, const std::string &pdata) + : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(opaque) { } + /** Get headers. + * All the headers for the web request are returned, as a pointer to a stringstream. + * @return The header information + */ std::stringstream* GetHeaders() { return headers; } + /** Get the post data (request content). + * All post data will be returned, including carriage returns and linefeeds. + * @return The postdata + */ + std::string& GetPostData() + { + return postdata; + } + + /** Get the request type. + * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec. + * @return The request type, e.g. GET, POST, HEAD + */ std::string& GetType() { 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() { return document; } + /** Get IP address of requester. + * The requesting system's ip address will be returned. + * @return The IP address as a string + */ std::string& GetIP() { return ipaddr; } }; +/** 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. + */ class HTTPDocument : public classbase { protected: + std::stringstream* document; int responsecode; + std::string extraheaders; public: - HTTPDocument(std::stringstream* doc, int response) : document(doc), responsecode(response) + + /** The socket pointer from an earlier HTTPRequest + */ + void* sock; + + /** Initialize a HTTPRequest ready for sending to m_httpd.so. + * @param opaque The socket pointer 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. + */ + HTTPDocument(void* opaque, std::stringstream* doc, int response, const std::string &extra) : document(doc), responsecode(response), extraheaders(extra), sock(opaque) { } + /** Get the document text. + * @return The document text + */ std::stringstream* GetDocument() { return this->document; } - std::stringstream* GetDocumentSize() + /** Get the document size. + * @return the size of the document text in bytes + */ + unsigned long GetDocumentSize() { - return this->document.size(); + return this->document->str().length(); } + /** Get the response code. + * @return The response code + */ int GetResponseCode() { return this->responsecode; } + + /** Get the headers. + * @return The header text, headers seperated by carriage return and linefeed. + */ + std::string& GetExtraHeaders() + { + return this->extraheaders; + } }; #endif -//httpr(request_type,uri,headers,this,this->GetIP()); -