int port;
};
-class HTTPSocket : public InspSocket
+class HTTPSocket : public BufferedSocket
{
private:
InspIRCd *Server;
public:
HTTPResolver(HTTPSocket *socket, InspIRCd *Instance, const string &hostname, bool &cached, Module* me) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), socket(socket)
{
- ServerInstance->Log(DEBUG,"Resolving "+hostname);
+ ServerInstance->Log(DEBUG,"HTTPResolver::HTTPResolver");
}
- void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
+ void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
{
- ServerInstance->Log(DEBUG,"Resolver done");
- socket->Connect(result);
+ if (!resultnum)
+ socket->Connect(result);
}
void OnError(ResolverError e, const string &errmsg)
{
- ServerInstance->Log(DEBUG,"Resolver error");
- delete socket;
+ ServerInstance->Log(DEBUG,"HTTPResolver::OnError");
+ /*if (ServerInstance->SocketCull.find(socket) == ServerInstance->SocketCull.end())
+ ServerInstance->SocketCull[socket] = socket;*/
}
};
HTTPList sockets;
ModuleHTTPClient(InspIRCd *Me)
- : Module::Module(Me)
+ : Module(Me)
{
+ Implementation eventlist[] = { I_OnRequest };
+ ServerInstance->Modules->Attach(eventlist, this, 1);
}
virtual ~ModuleHTTPClient()
return Version(1, 0, 0, 0, VF_SERVICEPROVIDER | VF_VENDOR, API_VERSION);
}
- void Implements(char* List)
- {
- List[I_OnRequest] = 1;
- }
char* OnRequest(Request *req)
{
};
HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod)
- : InspSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED)
+ : BufferedSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED)
{
- this->ClosePending = false;
+ Instance->Log(DEBUG,"HTTPSocket::HTTPSocket");
this->port = 80;
}
bool HTTPSocket::DoRequest(HTTPClientRequest *req)
{
+ Instance->Log(DEBUG,"HTTPSocket::DoRequest");
/* Tweak by brain - we take a copy of this,
* so that the caller doesnt need to leave
* pointers knocking around, less chance of
*/
this->req = *req;
- Instance->Log(DEBUG,"Request in progress");
-
if (!ParseURL(this->req.GetURL()))
- {
- Instance->Log(DEBUG,"Parse failed");
return false;
- }
this->port = url.port;
strlcpy(this->host, url.domain.c_str(), MAXBUF);
bool HTTPSocket::ParseURL(const std::string &iurl)
{
+ Instance->Log(DEBUG,"HTTPSocket::ParseURL");
url.url = iurl;
url.port = 80;
url.protocol = "http";
for (int p = 0;; p++)
{
- std::string part = tokenizer.GetToken();
- if (part.empty() && tokenizer.StreamEnd())
+ std::string part;
+ if (!tokenizer.GetToken(part))
break;
-
+
if ((p == 0) && (part[part.length() - 1] == ':'))
{
// Protocol ('http:')
void HTTPSocket::Connect(const string &ip)
{
+ Instance->Log(DEBUG,"HTTPSocket::Connect");
strlcpy(this->IP, ip.c_str(), MAXBUF);
if (!this->DoConnect())
bool HTTPSocket::OnDataReady()
{
+ Instance->Log(DEBUG,"HTTPSocket::OnDataReady()");
char *data = this->Read();
if (!data)
{
this->status = HTTP_DATA;
this->data += this->buffer;
- this->buffer = "";
+ this->buffer.clear();
break;
}
void HTTPSocket::OnClose()
{
+ Instance->Log(DEBUG,"HTTPSocket::OnClose");
if (data.empty())
return; // notification that request failed?
delete response;
}
-class ModuleHTTPClientFactory : public ModuleFactory
-{
- public:
- ModuleHTTPClientFactory()
- {
- }
-
- ~ModuleHTTPClientFactory()
- {
- }
-
- Module *CreateModule(InspIRCd* Me)
- {
- return new ModuleHTTPClient(Me);
- }
-};
+MODULE_INIT(ModuleHTTPClient)
-extern "C" void *init_module(void)
-{
- return new ModuleHTTPClientFactory;
-}