]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/extra/m_testclient.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / extra / m_testclient.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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                 
35         virtual Version GetVersion()
36         {
37                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
38         }
39         
40         virtual void OnBackgroundTimer(time_t foo)
41         {
42                 Module* target = ServerInstance->Modules->FindFeature("SQL");
43                 
44                 if(target)
45                 {
46                         SQLrequest foo = SQLrequest(this, target, "foo",
47                                         SQLquery("UPDATE rawr SET foo = '?' WHERE bar = 42") % time(NULL));
48                         
49                         if(foo.Send())
50                         {
51                                 ServerInstance->Log(DEBUG, "Sent query, got given ID %lu", foo.id);
52                         }
53                         else
54                         {
55                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", foo.error.Str());
56                         }
57                 }
58         }
59         
60         virtual char* OnRequest(Request* request)
61         {
62                 if(strcmp(SQLRESID, request->GetId()) == 0)
63                 {
64                         ServerInstance->Log(DEBUG, "Got SQL result (%s)", request->GetId());
65                 
66                         SQLresult* res = (SQLresult*)request;
67
68                         if (res->error.Id() == NO_ERROR)
69                         {
70                                 if(res->Cols())
71                                 {
72                                         ServerInstance->Log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
73
74                                         for (int r = 0; r < res->Rows(); r++)
75                                         {
76                                                 ServerInstance->Log(DEBUG, "Row %d:", r);
77                                                 
78                                                 for(int i = 0; i < res->Cols(); i++)
79                                                 {
80                                                         ServerInstance->Log(DEBUG, "\t[%s]: %s", res->ColName(i).c_str(), res->GetValue(r, i).d.c_str());
81                                                 }
82                                         }
83                                 }
84                                 else
85                                 {
86                                         ServerInstance->Log(DEBUG, "%d rows affected in query", res->Rows());
87                                 }
88                         }
89                         else
90                         {
91                                 ServerInstance->Log(DEBUG, "SQLrequest failed: %s", res->error.Str());
92                                 
93                         }
94                 
95                         return SQLSUCCESS;
96                 }
97                 
98                 ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId());
99                 
100                 return NULL;
101         }
102         
103         virtual ~ModuleTestClient()
104         {
105         }       
106 };
107
108 MODULE_INIT(ModuleTestClient)
109