-/* +------------------------------------+\r * | Inspire Internet Relay Chat Daemon |\r * +------------------------------------+\r *\r * InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r * the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "base.h"\r\r#ifndef HTTPCLIENT_H__\r#define HTTPCLIENT_H__\r\r#include <string>\r#include <map>\r\rtypedef std::map<std::string,std::string> HeaderMap;\r\rconst char* HTTP_CLIENT_RESPONSE = "HTTPCLIENT_RESPONSE";\rconst char* HTTP_CLIENT_REQUEST = "HTTPCLIENT_REQUEST";\r\r/** This class represents an outgoing HTTP request\r */\rclass HTTPClientRequest : public Request\r{\r protected:\r std::string url;\r InspIRCd *Instance;\r Module *src;\r HeaderMap Headers;\r public:\r HTTPClientRequest(InspIRCd *Instance, Module *src, Module* target, const std::string &url)\r : Request(src, target, HTTP_CLIENT_REQUEST), url(url), Instance(Instance), src(src)\r {\r Headers["User-Agent"] = "InspIRCd (m_http_client.so)";\r Headers["Connection"] = "Close";\r Headers["Accept"] = "*/*";\r }\r\r HTTPClientRequest() : Request(NULL, NULL, HTTP_CLIENT_REQUEST)\r {\r }\r\r const std::string &GetURL()\r {\r return url;\r }\r\r void AddHeader(std::string &header, std::string &data)\r {\r Headers[header] = data;\r }\r \r void DeleteHeader(std::string &header)\r {\r Headers.erase(header);\r }\r\r HeaderMap GetHeaders()\r {\r return Headers;\r }\r};\r\rclass HTTPClientResponse : public Request\r{\r protected:\r friend class HTTPSocket;\r \r std::string url;\r std::string data;\r int response;\r std::string responsestr;\r HeaderMap Headers;\r public:\r HTTPClientResponse(Module* src, Module* target, std::string &url, int response, std::string responsestr)\r : Request(src, target, HTTP_CLIENT_RESPONSE), url(url), response(response), responsestr(responsestr)\r {\r }\r\r HTTPClientResponse() : Request(NULL, NULL, HTTP_CLIENT_RESPONSE)\r {\r }\r\r void SetData(const std::string &ndata)\r {\r data = ndata;\r }\r \r void AddHeader(const std::string &header, const std::string &data)\r {\r Headers[header] = data;\r }\r \r const std::string &GetURL()\r {\r return url;\r }\r \r const std::string &GetData()\r {\r return data;\r }\r \r int GetResponse(std::string &str)\r {\r str = responsestr;\r return response;\r }\r \r std::string GetHeader(const std::string &header)\r {\r HeaderMap::iterator i = Headers.find(header);\r \r if (i != Headers.end())\r return i->second;\r else\r return "";\r }\r};\r\r#endif\r
\ No newline at end of file
+/* +------------------------------------+
+ * | 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 HTTPCLIENT_H__
+#define HTTPCLIENT_H__
+
+#include <string>
+#include <map>
+
+typedef std::map<std::string,std::string> HeaderMap;
+
+const char* HTTP_CLIENT_RESPONSE = "HTTPCLIENT_RESPONSE";
+const char* HTTP_CLIENT_REQUEST = "HTTPCLIENT_REQUEST";
+
+/** This class represents an outgoing HTTP request
+ */
+class HTTPClientRequest : public Request
+{
+ protected:
+ std::string url;
+ InspIRCd *Instance;
+ Module *src;
+ HeaderMap Headers;
+ public:
+ HTTPClientRequest(InspIRCd *Instance, Module *src, Module* target, const std::string &url)
+ : Request(src, target, HTTP_CLIENT_REQUEST), url(url), Instance(Instance), src(src)
+ {
+ Headers["User-Agent"] = "InspIRCd (m_http_client.so)";
+ Headers["Connection"] = "Close";
+ Headers["Accept"] = "*/*";
+ }
+
+ HTTPClientRequest() : Request(NULL, NULL, HTTP_CLIENT_REQUEST)
+ {
+ }
+
+ const std::string &GetURL()
+ {
+ return url;
+ }
+
+ void AddHeader(std::string &header, std::string &data)
+ {
+ Headers[header] = data;
+ }
+
+ void DeleteHeader(std::string &header)
+ {
+ Headers.erase(header);
+ }
+
+ HeaderMap GetHeaders()
+ {
+ return Headers;
+ }
+};
+
+class HTTPClientResponse : public Request
+{
+ protected:
+ friend class HTTPSocket;
+
+ std::string url;
+ std::string data;
+ int response;
+ std::string responsestr;
+ HeaderMap Headers;
+ public:
+ HTTPClientResponse(Module* src, Module* target, std::string &url, int response, std::string responsestr)
+ : Request(src, target, HTTP_CLIENT_RESPONSE), url(url), response(response), responsestr(responsestr)
+ {
+ }
+
+ HTTPClientResponse() : Request(NULL, NULL, HTTP_CLIENT_RESPONSE)
+ {
+ }
+
+ void SetData(const std::string &ndata)
+ {
+ data = ndata;
+ }
+
+ void AddHeader(const std::string &header, const std::string &data)
+ {
+ Headers[header] = data;
+ }
+
+ const std::string &GetURL()
+ {
+ return url;
+ }
+
+ const std::string &GetData()
+ {
+ return data;
+ }
+
+ int GetResponse(std::string &str)
+ {
+ str = responsestr;
+ return response;
+ }
+
+ std::string GetHeader(const std::string &header)
+ {
+ HeaderMap::iterator i = Headers.find(header);
+
+ if (i != Headers.end())
+ return i->second;
+ else
+ return "";
+ }
+};
+
+#endif