int port;
};
-class HTTPSocket : public InspSocket
+class HTTPSocket : public BufferedSocket
{
private:
InspIRCd *Server;
{
}
- void OnLookupComplete(const string &result, unsigned int ttl, bool cached)
+ void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0)
{
- socket->Connect(result);
+ if (!resultnum)
+ socket->Connect(result);
}
void OnError(ResolverError e, const string &errmsg)
{
- delete socket;
+ 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()
};
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;
this->port = 80;
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:')
{
this->status = HTTP_DATA;
this->data += this->buffer;
- this->buffer = "";
+ this->buffer.clear();
break;
}
delete response;
}
-class ModuleHTTPClientFactory : public ModuleFactory
-{
- public:
- ModuleHTTPClientFactory()
- {
- }
-
- ~ModuleHTTPClientFactory()
- {
- }
-
- Module *CreateModule(InspIRCd* Me)
- {
- return new ModuleHTTPClient(Me);
- }
-};
-
-extern "C" void *init_module(void)
-{
- return new ModuleHTTPClientFactory;
-}
+MODULE_INIT(ModuleHTTPClient)