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