{
SendHeaders(n->str().length(), response, *hheaders);
WriteData(n->str());
+ Close();
}
+
+ void AddToCull()
+ {
+ if (waitingcull)
+ return;
+
+ waitingcull = true;
+ Close();
+ ServerInstance->GlobalCulls.AddItem(this);
+ }
};
-class ModuleHttpServer : public Module
+class HTTPdAPIImpl : public HTTPdAPIBase
{
- unsigned int timeoutsec;
-
public:
+ HTTPdAPIImpl(Module* parent)
+ : HTTPdAPIBase(parent)
+ {
+ }
- void init()
+ void SendResponse(HTTPDocumentResponse& resp) CXX11_OVERRIDE
{
- HttpModule = this;
- Implementation eventlist[] = { I_OnAcceptConnection, I_OnBackgroundTimer, I_OnRehash, I_OnUnloadModule };
- ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
- OnRehash(NULL);
+ resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers);
}
+};
- void OnRehash(User* user)
+class ModuleHttpServer : public Module
+{
+ HTTPdAPIImpl APIImpl;
+ unsigned int timeoutsec;
+ Events::ModuleEventProvider acleventprov;
+ Events::ModuleEventProvider reqeventprov;
+
+ public:
+ ModuleHttpServer()
+ : APIImpl(this)
+ , acleventprov(this, "event/http-acl")
+ , reqeventprov(this, "event/http-request")
{
- ConfigTag* tag = ServerInstance->Config->ConfValue("httpd");
- timeoutsec = tag->getInt("timeout");
+ aclevprov = &acleventprov;
+ reqevprov = &reqeventprov;
}
- void OnRequest(Request& request)
+ void init() CXX11_OVERRIDE
{
- if (strcmp(request.id, "HTTP-DOC") != 0)
- return;
- HTTPDocumentResponse& resp = static_cast<HTTPDocumentResponse&>(request);
- claimed = true;
- resp.src.sock->Page(resp.document, resp.responsecode, &resp.headers);
+ HttpModule = this;
}
- ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
+ void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
- if (from->bind_tag->getString("type") != "httpd")
- return MOD_RES_PASSTHRU;
- int port;
- std::string incomingip;
- irc::sockets::satoap(*client, incomingip, port);
- sockets.insert(new HttpServerSocket(nfd, incomingip, from, client, server));
- return MOD_RES_ALLOW;
+ ConfigTag* tag = ServerInstance->Config->ConfValue("httpd");
+ timeoutsec = tag->getDuration("timeout", 10, 1);
}
- void OnBackgroundTimer(time_t curtime)
+ ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE
{
- if (!timeoutsec)
- return;
+ if (!stdalgo::string::equalsci(from->bind_tag->getString("type"), "httpd"))
+ return MOD_RES_PASSTHRU;
- time_t oldest_allowed = curtime - timeoutsec;
- for (std::set<HttpServerSocket*>::const_iterator i = sockets.begin(); i != sockets.end(); )
- {
- HttpServerSocket* sock = *i;
- ++i;
- if (sock->createtime < oldest_allowed)
- {
- sock->cull();
- delete sock;
- }
- }
+ sockets.push_front(new HttpServerSocket(nfd, client->addr(), from, client, server, timeoutsec));
+ return MOD_RES_ALLOW;
}
- void OnUnloadModule(Module* mod)
+ void OnUnloadModule(Module* mod) CXX11_OVERRIDE
{
- for (std::set<HttpServerSocket*>::const_iterator i = sockets.begin(); i != sockets.end(); )
+ for (insp::intrusive_list<HttpServerSocket>::const_iterator i = sockets.begin(); i != sockets.end(); )
{
HttpServerSocket* sock = *i;
++i;