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