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