From 34f4ee851c1822696612dadd4a46194f9ed28987 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 7 Jan 2007 17:16:30 +0000 Subject: Make this use the newer format of class Request (this module was still using the old cast-data-to-char*-and-use-getdata-method) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6245 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/httpclient.h | 33 +++++++++------------------------ src/modules/m_http_client.cpp | 26 ++++++++++++-------------- 2 files changed, 21 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/modules/httpclient.h b/src/modules/httpclient.h index 8e1a314dd..181c58b6b 100644 --- a/src/modules/httpclient.h +++ b/src/modules/httpclient.h @@ -8,9 +8,12 @@ typedef std::map 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 classbase +class HTTPClientRequest : public Request { protected: std::string url; @@ -18,8 +21,8 @@ class HTTPClientRequest : public classbase Module *src; HeaderMap Headers; public: - HTTPClientRequest(InspIRCd *Instance, Module *src, const std::string &url) - : url(url), Instance(Instance), src(src) + 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"; @@ -30,11 +33,6 @@ class HTTPClientRequest : public classbase { return url; } - - Module *GetSrc() - { - return src; - } void AddHeader(std::string &header, std::string &data) { @@ -50,22 +48,9 @@ class HTTPClientRequest : public classbase { 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 +class HTTPClientResponse : public Request { protected: friend class HTTPSocket; @@ -76,8 +61,8 @@ class HTTPClientResponse : public classbase std::string responsestr; HeaderMap Headers; public: - HTTPClientResponse(std::string &url, int response, std::string responsestr) - : url(url), response(response), responsestr(responsestr) + 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) { } diff --git a/src/modules/m_http_client.cpp b/src/modules/m_http_client.cpp index 962ecfc17..9004b202b 100644 --- a/src/modules/m_http_client.cpp +++ b/src/modules/m_http_client.cpp @@ -98,21 +98,18 @@ class ModuleHTTPClient : public Module { List[I_OnRequest] = 1; } - - char *OnRequest(Request *req) + + char* OnRequest(Request *req) { - HTTPClientRequest *httpreq = (HTTPClientRequest *) req->GetData(); - HTTPSocket *sock = new HTTPSocket(ServerInstance, this); - sock->DoRequest(httpreq); - // No return value + HTTPClientRequest *httpreq = (HTTPClientRequest *)req; + if (!strcmp(httpreq->GetId(), HTTP_CLIENT_REQUEST)) + { + HTTPSocket *sock = new HTTPSocket(ServerInstance, this); + sock->DoRequest(httpreq); + // No return value + } return NULL; } - - void SendReply(Module *to, HTTPClientResponse *data) - { - Request req((char *) data, this, to); - req.Send(); - } }; HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod) @@ -283,7 +280,7 @@ bool HTTPSocket::OnDataReady() { // HTTP reply (HTTP/1.1 200 msg) data += 9; - response = new HTTPClientResponse(url.url, atoi(data), data + 4); + response = new HTTPClientResponse((Module*)Mod, req->GetSource() , url.url, atoi(data), data + 4); this->status = HTTP_HEADERS; continue; } @@ -314,7 +311,8 @@ void HTTPSocket::OnClose() } Server->Log(DEBUG, "Got file from HTTP successfully"); response->data = data; - Mod->SendReply(req->GetSrc(), response); + response->Send(); + delete response; } class ModuleHTTPClientFactory : public ModuleFactory -- cgit v1.2.3