private:
InspIRCd *Server;
class ModuleHTTPClient *Mod;
- HTTPClientRequest *req;
+ HTTPClientRequest req;
HTTPClientResponse *response;
URL url;
enum { HTTP_CLOSED, HTTP_REQSENT, HTTP_HEADERS, HTTP_DATA } status;
private:
HTTPSocket *socket;
public:
- HTTPResolver(HTTPSocket *socket, InspIRCd *Instance, const string &hostname) : Resolver(Instance, hostname, DNS_QUERY_FORWARD), socket(socket)
+ HTTPResolver(HTTPSocket *socket, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(socket)
{
}
- void OnLookupComplete(const string &result)
+ void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
{
socket->Connect(result);
}
{
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)
bool HTTPSocket::DoRequest(HTTPClientRequest *req)
{
- this->req = req;
-
- if (!ParseURL(req->GetURL()))
+ /* Tweak by brain - we take a copy of this,
+ * so that the caller doesnt need to leave
+ * pointers knocking around, less chance of
+ * a memory leak.
+ */
+ this->req = *req;
+
+ if (!ParseURL(this->req.GetURL()))
return false;
this->port = url.port;
strlcpy(this->host, url.domain.c_str(), MAXBUF);
- if (!inet_aton(this->host, &this->addy))
+ if (!insp_aton(this->host, &this->addy))
{
- new HTTPResolver(this, Server, url.domain);
+ bool cached;
+ HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
+ Instance->AddResolver(r, cached);
return true;
}
else
std::string request = "GET " + url.request + " HTTP/1.1\r\n";
// Dump headers into the request
- HeaderMap headers = req->GetHeaders();
+ HeaderMap headers = req.GetHeaders();
for (HeaderMap::iterator i = headers.begin(); i != headers.end(); i++)
request += i->first + ": " + i->second + "\r\n";
{
// 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;
}
}
Server->Log(DEBUG, "Got file from HTTP successfully");
response->data = data;
- Mod->SendReply(req->GetSrc(), response);
+ response->Send();
+ delete response;
}
class ModuleHTTPClientFactory : public ModuleFactory
{
return new ModuleHTTPClientFactory;
}
-
-