summaryrefslogtreecommitdiff
path: root/src/modules/httpclient.h
diff options
context:
space:
mode:
authorspecial <special@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 03:50:18 +0000
committerspecial <special@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-07 03:50:18 +0000
commite513c4c3f99154e2a98f7564600183323e5dffaf (patch)
tree6ba08f322069bdfeaef8af0025eee9eb3a325f12 /src/modules/httpclient.h
parentdab57ed68a554f1d0bb23dd5fa583c330a68214a (diff)
Added m_http_client - this is incomplete and won't work at all, don't try to use it
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6243 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/httpclient.h')
-rw-r--r--src/modules/httpclient.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/modules/httpclient.h b/src/modules/httpclient.h
new file mode 100644
index 000000000..8e1a314dd
--- /dev/null
+++ b/src/modules/httpclient.h
@@ -0,0 +1,121 @@
+#include "base.h"
+
+#ifndef HTTPCLIENT_H__
+#define HTTPCLIENT_H__
+
+#include <string>
+#include <map>
+
+typedef std::map<std::string,std::string> HeaderMap;
+
+/** This class represents an outgoing HTTP request
+ */
+class HTTPClientRequest : public classbase
+{
+ protected:
+ std::string url;
+ InspIRCd *Instance;
+ Module *src;
+ HeaderMap Headers;
+ public:
+ HTTPClientRequest(InspIRCd *Instance, Module *src, const std::string &url)
+ : url(url), Instance(Instance), src(src)
+ {
+ Headers["User-Agent"] = "InspIRCd (m_http_client.so)";
+ Headers["Connection"] = "Close";
+ Headers["Accept"] = "*/*";
+ }
+
+ const std::string &GetURL()
+ {
+ return url;
+ }
+
+ Module *GetSrc()
+ {
+ return src;
+ }
+
+ void AddHeader(std::string &header, std::string &data)
+ {
+ Headers[header] = data;
+ }
+
+ void DeleteHeader(std::string &header)
+ {
+ Headers.erase(header);
+ }
+
+ HeaderMap GetHeaders()
+ {
+ return Headers;
+ }
+
+ void SendRequest()
+ {
+ Module *HTTPModule = Instance->FindModule("m_http_client.so");
+ if (!HTTPModule)
+ {
+ Instance->Log(DEFAULT, "HTTP module not loaded!");
+ return;
+ }
+
+ Request req((char *)this, src, HTTPModule);
+ req.Send();
+ }
+};
+
+class HTTPClientResponse : public classbase
+{
+ protected:
+ friend class HTTPSocket;
+
+ std::string url;
+ std::string data;
+ int response;
+ std::string responsestr;
+ HeaderMap Headers;
+ public:
+ HTTPClientResponse(std::string &url, int response, std::string responsestr)
+ : url(url), response(response), responsestr(responsestr)
+ {
+ }
+
+ 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