diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_http_client.cpp | 14 | ||||
-rw-r--r-- | src/modules/m_remoteinclude.cpp | 60 |
2 files changed, 55 insertions, 19 deletions
diff --git a/src/modules/m_http_client.cpp b/src/modules/m_http_client.cpp index 4a5af15d2..d7722caff 100644 --- a/src/modules/m_http_client.cpp +++ b/src/modules/m_http_client.cpp @@ -54,6 +54,7 @@ class HTTPResolver : public Resolver 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,"HTTPResolver::HTTPResolver"); } void OnLookupComplete(const string &result, unsigned int ttl, bool cached, int resultnum = 0) @@ -64,8 +65,9 @@ class HTTPResolver : public Resolver void OnError(ResolverError e, const string &errmsg) { - if (ServerInstance->SocketCull.find(socket) == ServerInstance->SocketCull.end()) - ServerInstance->SocketCull[socket] = socket; + ServerInstance->Log(DEBUG,"HTTPResolver::OnError"); + /*if (ServerInstance->SocketCull.find(socket) == ServerInstance->SocketCull.end()) + ServerInstance->SocketCull[socket] = socket;*/ } }; @@ -111,7 +113,7 @@ class ModuleHTTPClient : public Module HTTPSocket::HTTPSocket(InspIRCd *Instance, ModuleHTTPClient *Mod) : BufferedSocket(Instance), Server(Instance), Mod(Mod), status(HTTP_CLOSED) { - this->ClosePending = false; + Instance->Log(DEBUG,"HTTPSocket::HTTPSocket"); this->port = 80; } @@ -130,6 +132,7 @@ HTTPSocket::~HTTPSocket() 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 @@ -166,6 +169,7 @@ bool HTTPSocket::DoRequest(HTTPClientRequest *req) bool HTTPSocket::ParseURL(const std::string &iurl) { + Instance->Log(DEBUG,"HTTPSocket::ParseURL"); url.url = iurl; url.port = 80; url.protocol = "http"; @@ -248,6 +252,7 @@ bool HTTPSocket::ParseURL(const std::string &iurl) void HTTPSocket::Connect(const string &ip) { + Instance->Log(DEBUG,"HTTPSocket::Connect"); strlcpy(this->IP, ip.c_str(), MAXBUF); if (!this->DoConnect()) @@ -280,6 +285,7 @@ bool HTTPSocket::OnConnected() bool HTTPSocket::OnDataReady() { + Instance->Log(DEBUG,"HTTPSocket::OnDataReady()"); char *data = this->Read(); if (!data) @@ -335,6 +341,7 @@ bool HTTPSocket::OnDataReady() void HTTPSocket::OnClose() { + Instance->Log(DEBUG,"HTTPSocket::OnClose"); if (data.empty()) return; // notification that request failed? @@ -344,3 +351,4 @@ void HTTPSocket::OnClose() } MODULE_INIT(ModuleHTTPClient) + diff --git a/src/modules/m_remoteinclude.cpp b/src/modules/m_remoteinclude.cpp index dd5b0f48b..7bf01ff55 100644 --- a/src/modules/m_remoteinclude.cpp +++ b/src/modules/m_remoteinclude.cpp @@ -12,21 +12,20 @@ */ #include "inspircd.h" +#include "httpclient.h" -/* $ModDesc: A dummy module for testing */ - -// Class ModuleRemoteInclude inherits from Module -// It just outputs simple debug strings to show its methods are working. +/* $ModDesc: The base module for remote includes */ class ModuleRemoteInclude : public Module { - private: - + std::map<std::string, std::stringstream*> assoc; + public: ModuleRemoteInclude(InspIRCd* Me) : Module(Me) { ServerInstance->Modules->Attach(I_OnDownloadFile, this); + ServerInstance->Modules->Attach(I_OnRequest, this); } virtual ~ModuleRemoteInclude() @@ -41,21 +40,50 @@ class ModuleRemoteInclude : public Module return Version(1,1,0,1,VF_VENDOR,API_VERSION); } + char* OnRequest(Request* req) + { + HTTPClientResponse* resp = (HTTPClientResponse*)req; + if(!strcmp(resp->GetId(), HTTP_CLIENT_RESPONSE)) + { + ServerInstance->Log(DEBUG, "Got http file for %s", resp->GetURL().c_str()); + + std::map<std::string, std::stringstream*>::iterator n = assoc.find(resp->GetURL()); + + if (n == assoc.end()) + ServerInstance->Config->Complete(resp->GetURL(), true); + + *(n->second) << resp->GetData(); + + ServerInstance->Log(DEBUG, "Got data: %s", resp->GetData().c_str()); + + ServerInstance->Log(DEBUG, "Flag file complete without error"); + ServerInstance->Config->Complete(resp->GetURL(), false); + } + + return NULL; + } + int OnDownloadFile(const std::string &name, std::istream* &filedata) { - /* Dummy code */ - std::stringstream* ss = new std::stringstream(); - (*ss) << "<test tag="">"; + if (name.substr(0, 7) == "http://") + { + Module* target = ServerInstance->Modules->Find("m_http_client.so"); + if (target) + { + ServerInstance->Log(DEBUG,"Claiming schema http://, making fetch request"); + + HTTPClientRequest req(ServerInstance, this, target, name); + req.Send(); - delete filedata; - filedata = ss; + assoc[name] = new std::stringstream(); + delete filedata; + filedata = assoc[name]; - /* for this test module, we claim all schemes, and we return dummy data. - * Because the loading is instant we mark the file completed immediately. - */ - ServerInstance->Config->Complete(name, false); + return true; + } + } - return true; + return false; } }; |