summaryrefslogtreecommitdiff
path: root/src/modules/m_remoteinclude.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-11 19:58:13 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-11 19:58:13 +0000
commit8bc6254a5912f544c99623f0473d6f025f61b7b9 (patch)
tree9533014e97efe9c3f8e738cd7f71f9f876e858ff /src/modules/m_remoteinclude.cpp
parent845a4d1e604d41977558938e5f62d0190d9ff39f (diff)
m_http_client is crashy. will fix.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8578 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_remoteinclude.cpp')
-rw-r--r--src/modules/m_remoteinclude.cpp60
1 files changed, 44 insertions, 16 deletions
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;
}
};