]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_httpd_stats.cpp
Make it not b0rk on empty headers
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "inspsocket.h"
24 #include "helperfuncs.h"
25 #include "httpd.h"
26
27 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
28
29 class ModuleHttpStats : public Module
30 {
31         Server* Srv;
32
33  public:
34
35         void ReadConfig()
36         {
37         }
38
39         ModuleHttpStats(Server* Me) : Module::Module(Me)
40         {
41                 Srv = Me;
42                 ReadConfig();
43         }
44
45         void OnEvent(Event* event)
46         {
47                 std::stringstream data("");
48
49                 if (event->GetEventID() == "httpd_url")
50                 {
51                         log(DEBUG,"HTTP URL!");
52
53                         data << "<html><h1>Chickens</h1></html>";
54
55                         HTTPRequest* http = (HTTPRequest*)event->GetData();
56                         HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\n");
57                         Request req((char*)&response, (Module*)this, event->GetSource());
58                         req.Send();
59
60                         log(DEBUG,"Sent");
61                 }
62         }
63
64         char* OnRequest(Request* request)
65         {
66                 return NULL;
67         }
68
69         void Implements(char* List)
70         {
71                 List[I_OnEvent] = List[I_OnRequest] = 1;
72         }
73
74         virtual ~ModuleHttpStats()
75         {
76         }
77
78         virtual Version GetVersion()
79         {
80                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
81         }
82 };
83
84
85 class ModuleHttpStatsFactory : public ModuleFactory
86 {
87  public:
88         ModuleHttpStatsFactory()
89         {
90         }
91         
92         ~ModuleHttpStatsFactory()
93         {
94         }
95         
96         virtual Module * CreateModule(Server* Me)
97         {
98                 return new ModuleHttpStats(Me);
99         }
100 };
101
102
103 extern "C" void * init_module( void )
104 {
105         return new ModuleHttpStatsFactory;
106 }