]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_httpd_stats.cpp
This works now, m_httpd_stats.so prints 'chickens' on all pages except the index
[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         std::stringstream data;
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                 if (event->GetEventID() == "httpd_url")
48                 {
49                         log(DEBUG,"HTTP URL!");
50
51                         data.clear();
52                         data << "<html><h1>Chickens</h1></html>";
53
54                         HTTPRequest* http = (HTTPRequest*)event->GetData();
55                         HTTPDocument response(http->sock, &data, 200);
56                         Request req((char*)&response, (Module*)this, event->GetSource());
57                         req.Send();
58
59                         log(DEBUG,"Sent");
60                 }
61         }
62
63         char* OnRequest(Request* request)
64         {
65                 return NULL;
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnEvent] = List[I_OnRequest] = 1;
71         }
72
73         virtual ~ModuleHttpStats()
74         {
75         }
76
77         virtual Version GetVersion()
78         {
79                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
80         }
81 };
82
83
84 class ModuleHttpStatsFactory : public ModuleFactory
85 {
86  public:
87         ModuleHttpStatsFactory()
88         {
89         }
90         
91         ~ModuleHttpStatsFactory()
92         {
93         }
94         
95         virtual Module * CreateModule(Server* Me)
96         {
97                 return new ModuleHttpStats(Me);
98         }
99 };
100
101
102 extern "C" void * init_module( void )
103 {
104         return new ModuleHttpStatsFactory;
105 }