1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #ifndef HTTPCLIENT_H__
17 #define HTTPCLIENT_H__
22 typedef std::map<std::string,std::string> HeaderMap;
24 const char* HTTP_CLIENT_RESPONSE = "HTTPCLIENT_RESPONSE";
25 const char* HTTP_CLIENT_REQUEST = "HTTPCLIENT_REQUEST";
26 const char* HTTP_CLIENT_ERROR = "HTTPCLIENT_ERROR";
28 /** This class represents an outgoing HTTP request
30 class HTTPClientRequest : public Request
38 HTTPClientRequest(InspIRCd *SI, Module *m, Module* target, const std::string &surl)
39 : Request(m, target, HTTP_CLIENT_REQUEST), url(surl), Instance(SI), src(m)
41 Headers["User-Agent"] = "InspIRCd (m_http_client.so)";
42 Headers["Connection"] = "Close";
43 Headers["Accept"] = "*/*";
46 HTTPClientRequest() : Request(NULL, NULL, HTTP_CLIENT_REQUEST)
50 const std::string &GetURL()
55 void AddHeader(std::string &header, std::string &sdata)
57 Headers[header] = sdata;
60 void DeleteHeader(std::string &header)
62 Headers.erase(header);
65 HeaderMap GetHeaders()
71 class HTTPClientError : public Request
74 friend class HTTPSocket;
77 std::string responsestr;
80 HTTPClientError(Module* src, Module* target, const std::string &surl, int iresponse)
81 : Request(src, target, HTTP_CLIENT_ERROR), url(surl), response(iresponse)
85 const std::string &GetURL()
91 class HTTPClientResponse : public Request
94 friend class HTTPSocket;
99 std::string responsestr;
102 HTTPClientResponse(Module* src, Module* target, std::string &surl, int iresponse, std::string sresponsestr)
103 : Request(src, target, HTTP_CLIENT_RESPONSE), url(surl), response(iresponse), responsestr(sresponsestr)
107 HTTPClientResponse() : Request(NULL, NULL, HTTP_CLIENT_RESPONSE)
111 void SetData(const std::string &ndata)
116 void AddHeader(const std::string &header, const std::string &sdata)
118 Headers[header] = sdata;
121 const std::string &GetURL()
126 const std::string &GetData()
131 int GetResponse(std::string &str)
137 void SetResponse(const std::string &str)
140 response = atoi(responsestr.c_str());
143 std::string GetHeader(const std::string &header)
145 HeaderMap::iterator i = Headers.find(header);
147 if (i != Headers.end())