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