]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_testclient.cpp
6aec581aee179d7e26d6102ece6eee1af81d0ff7
[user/henk/code/inspircd.git] / src / modules / extra / m_testclient.cpp
1 #include <string>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6 #include "helperfuncs.h"
7 #include "inspircd.h"
8 #include "configreader.h"
9 #include "m_sqlv2.h"
10
11 class ModuleTestClient : public Module
12 {
13 private:
14         Server* Srv;
15
16 public:
17         ModuleTestClient(Server* Me)
18         : Module::Module(Me), Srv(Me)
19         {
20         }
21
22         void Implements(char* List)
23         {
24                 List[I_OnRequest] = List[I_OnBackgroundTimer] = 1;
25         }
26                 
27         virtual Version GetVersion()
28         {
29                 return Version(1, 0, 0, 0, VF_VENDOR);
30         }
31         
32         virtual void OnBackgroundTimer(time_t foo)
33         {
34                 Module* target = Srv->FindFeature("SQL");
35                 
36                 if(target)
37                 {
38                         SQLrequest foo = SQLreq(this, target, "foo", "UPDATE rawr SET foo = '?' WHERE bar = 42", ConvToStr(time(NULL)));
39                         
40                         if(foo.Send())
41                         {
42                                 log(DEBUG, "Sent query, got given ID %lu", foo.id);
43                         }
44                         else
45                         {
46                                 log(DEBUG, "SQLrequest failed: %s", foo.error.Str());
47                         }
48                 }
49         }
50         
51         virtual char* OnRequest(Request* request)
52         {
53                 if(strcmp(SQLRESID, request->GetId()) == 0)
54                 {
55                         log(DEBUG, "Got SQL result (%s)", request->GetId());
56                 
57                         SQLresult* res = (SQLresult*)request;
58
59                         if (res->error.Id() == NO_ERROR)
60                         {
61                                 if(res->Cols())
62                                 {
63                                         log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
64
65                                         for (int r = 0; r < res->Rows(); r++)
66                                         {
67                                                 log(DEBUG, "Row %d:", r);
68                                                 
69                                                 for(int i = 0; i < res->Cols(); i++)
70                                                 {
71                                                         log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
72                                                 }
73                                         }
74                                 }
75                                 else
76                                 {
77                                         log(DEBUG, "%d rows affected in query", res->Rows());
78                                 }
79                         }
80                         else
81                         {
82                                 log(DEBUG, "SQLrequest failed: %s", res->error.Str());
83                                 
84                         }
85                 
86                         return SQLSUCCESS;
87                 }
88                 
89                 log(DEBUG, "Got unsupported API version string: %s", request->GetId());
90                 
91                 return NULL;
92         }
93         
94         virtual ~ModuleTestClient()
95         {
96         }       
97 };
98
99 class ModuleTestClientFactory : public ModuleFactory
100 {
101  public:
102         ModuleTestClientFactory()
103         {
104         }
105         
106         ~ModuleTestClientFactory()
107         {
108         }
109         
110         virtual Module * CreateModule(Server* Me)
111         {
112                 return new ModuleTestClient(Me);
113         }
114 };
115
116
117 extern "C" void * init_module( void )
118 {
119         return new ModuleTestClientFactory;
120 }