]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_testclient.cpp
pgsql should now work thx to added posibility to force a fd out of the socketengine...
[user/henk/code/inspircd.git] / src / modules / extra / m_testclient.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <string>
15
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19
20 #include "inspircd.h"
21 #include "configreader.h"
22 #include "m_sqlv2.h"
23
24
25
26 class ModuleTestClient : public Module
27 {
28 private:
29         
30
31 public:
32         ModuleTestClient(InspIRCd* Me)
33                 : Module::Module(Me)
34         {
35         }
36
37         void Implements(char* List)
38         {
39                 List[I_OnRequest] = List[I_OnBackgroundTimer] = 1;
40         }
41                 
42         virtual Version GetVersion()
43         {
44                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
45         }
46         
47         virtual void OnBackgroundTimer(time_t foo)
48         {
49                 Module* target = ServerInstance->FindFeature("SQL");
50                 
51                 if(target)
52                 {
53                         SQLrequest foo = SQLreq(this, target, "foo", "UPDATE rawr SET foo = '?' WHERE bar = 42", ConvToStr(time(NULL)));
54                         
55                         if(foo.Send())
56                         {
57                                 ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", foo.id);
58                         }
59                         else
60                         {
61                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", foo.error.Str());
62                         }
63                 }
64         }
65         
66         virtual char* OnRequest(Request* request)
67         {
68                 if(strcmp(SQLRESID, request->GetId()) == 0)
69                 {
70                         ServerInstance->Log(DEBUG, "Got SQL result (%s)", request->GetId());
71                 
72                         SQLresult* res = (SQLresult*)request;
73
74                         if (res->error.Id() == NO_ERROR)
75                         {
76                                 if(res->Cols())
77                                 {
78                                         ServerInstance->Log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
79
80                                         for (int r = 0; r < res->Rows(); r++)
81                                         {
82                                                 ServerInstance->Log(DEBUG, "Row %d:", r);
83                                                 
84                                                 for(int i = 0; i < res->Cols(); i++)
85                                                 {
86                                                         ServerInstance->Log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
87                                                 }
88                                         }
89                                 }
90                                 else
91                                 {
92                                         ServerInstance->Log(DEBUG, "%d rows affected in query", res->Rows());
93                                 }
94                         }
95                         else
96                         {
97                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", res->error.Str());
98                                 
99                         }
100                 
101                         return SQLSUCCESS;
102                 }
103                 
104                 ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
105                 
106                 return NULL;
107         }
108         
109         virtual ~ModuleTestClient()
110         {
111         }       
112 };
113
114 class ModuleTestClientFactory : public ModuleFactory
115 {
116  public:
117         ModuleTestClientFactory()
118         {
119         }
120         
121         ~ModuleTestClientFactory()
122         {
123         }
124         
125         virtual Module * CreateModule(InspIRCd* Me)
126         {
127                 return new ModuleTestClient(Me);
128         }
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleTestClientFactory;
135 }