The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ModuleSQLLog Class Reference

Inheritance diagram for ModuleSQLLog:

Inheritance graph
[legend]
Collaboration diagram for ModuleSQLLog:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ModuleSQLLog (InspIRCd *Me)
virtual ~ModuleSQLLog ()
void Implements (char *List)
 The Implements function specifies which methods a module should receive events for.
void ReadConfig ()
virtual void OnRehash (userrec *user, const std::string &parameter)
 Called on rehash.
virtual char * OnRequest (Request *request)
 Called whenever a Request class is sent to your module by another module.
void AddLogEntry (int category, const std::string &nick, const std::string &host, const std::string &source)
virtual void OnOper (userrec *user, const std::string &opertype)
 Called whenever a user opers locally.
virtual void OnGlobalOper (userrec *user)
 Called whenever a user is given usermode +o, anywhere on the network.
virtual int OnKill (userrec *source, userrec *dest, const std::string &reason)
 Called when a client is disconnected by KILL.
virtual int OnPreCommand (const std::string &command, const char **parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
 Called whenever any command is about to be executed.
virtual void OnUserConnect (userrec *user)
 Called when a user connects.
virtual void OnUserQuit (userrec *user, const std::string &reason, const std::string &oper_message)
 Called when a user quits.
virtual void OnLoadModule (Module *mod, const std::string &name)
 Called whenever a module is loaded.
virtual Version GetVersion ()
 Returns the version number of a Module.

Private Attributes

ConfigReaderConf

Detailed Description

Definition at line 182 of file m_sqllog.cpp.


Constructor & Destructor Documentation

ModuleSQLLog::ModuleSQLLog InspIRCd Me  )  [inline]
 

Definition at line 187 of file m_sqllog.cpp.

References active_queries, InspIRCd::FindFeature(), InspIRCd::FindModule(), OnRehash(), Module::ServerInstance, and InspIRCd::UseInterface().

00188         : Module::Module(Me)
00189         {
00190                 ServerInstance->UseInterface("SQLutils");
00191                 ServerInstance->UseInterface("SQL");
00192 
00193                 Module* SQLutils = ServerInstance->FindModule("m_sqlutils.so");
00194                 if (!SQLutils)
00195                         throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqlauth.so.");
00196 
00197                 SQLModule = ServerInstance->FindFeature("SQL");
00198 
00199                 OnRehash(NULL,"");
00200                 MyMod = this;
00201                 active_queries.clear();
00202         }

virtual ModuleSQLLog::~ModuleSQLLog  )  [inline, virtual]
 

Definition at line 204 of file m_sqllog.cpp.

References InspIRCd::DoneWithInterface(), and Module::ServerInstance.

00205         {
00206                 ServerInstance->DoneWithInterface("SQL");
00207                 ServerInstance->DoneWithInterface("SQLutils");
00208         }


Member Function Documentation

void ModuleSQLLog::AddLogEntry int  category,
const std::string nick,
const std::string host,
const std::string source
[inline]
 

Definition at line 251 of file m_sqllog.cpp.

References active_queries, dbid, FIND_SOURCE, SQLrequest::id, QueryInfo::qs, Request::Send(), and SQLreq.

Referenced by OnGlobalOper(), OnKill(), OnLoadModule(), OnOper(), OnPreCommand(), OnUserConnect(), and OnUserQuit().

00252         {
00253                 // is the sql module loaded? If not, we don't attempt to do anything.
00254                 if (!SQLModule)
00255                         return;
00256 
00257                 SQLrequest req = SQLreq(this, SQLModule, dbid, "SELECT id,actor FROM ircd_log_actors WHERE actor='?'", source);
00258                 if(req.Send())
00259                 {
00260                         QueryInfo* i = new QueryInfo(nick, source, host, req.id, category);
00261                         i->qs = FIND_SOURCE;
00262                         active_queries[req.id] = i;
00263                 }
00264         }

virtual Version ModuleSQLLog::GetVersion  )  [inline, virtual]
 

Returns the version number of a Module.

The method should return a Version object with its version information assigned via Version::Version

Reimplemented from Module.

Definition at line 306 of file m_sqllog.cpp.

References API_VERSION, and VF_VENDOR.

00307         {
00308                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
00309         }

void ModuleSQLLog::Implements char *  List  )  [inline, virtual]
 

The Implements function specifies which methods a module should receive events for.

The char* parameter passed to this function contains a set of true or false values (1 or 0) which indicate wether each function is implemented. You must use the Iimplementation enum (documented elsewhere on this page) to mark functions as active. For example, to receive events for OnUserJoin():

Implements[I_OnUserJoin] = 1;

Parameters:
The implement list

Reimplemented from Module.

Definition at line 210 of file m_sqllog.cpp.

References I_OnGlobalOper, I_OnKill, I_OnLoadModule, I_OnOper, I_OnPreCommand, I_OnRehash, I_OnRequest, I_OnUserConnect, and I_OnUserQuit.

00211         {
00212                 List[I_OnRehash] = List[I_OnOper] = List[I_OnGlobalOper] = List[I_OnKill] = 1;
00213                 List[I_OnPreCommand] = List[I_OnUserConnect] = 1;
00214                 List[I_OnUserQuit] = List[I_OnLoadModule] = List[I_OnRequest] = 1;
00215         }

virtual void ModuleSQLLog::OnGlobalOper userrec user  )  [inline, virtual]
 

Called whenever a user is given usermode +o, anywhere on the network.

You cannot override this and prevent it from happening as it is already happened and such a task must be performed by another server. You can however bounce modes by sending servermodes out to reverse mode changes.

Parameters:
user The user who is opering

Reimplemented from Module.

Definition at line 271 of file m_sqllog.cpp.

References AddLogEntry(), connection::host, LT_OPER, userrec::nick, and userrec::server.

00272         {
00273                 AddLogEntry(LT_OPER,user->nick,user->host,user->server);
00274         }

virtual int ModuleSQLLog::OnKill userrec source,
userrec dest,
const std::string reason
[inline, virtual]
 

Called when a client is disconnected by KILL.

If a client is killed by a server, e.g. a nickname collision or protocol error, source is NULL. Return 1 from this function to prevent the kill, and 0 from this function to allow it as normal. If you prevent the kill no output will be sent to the client, it is down to your module to generate this information. NOTE: It is NOT advisable to stop kills which originate from servers or remote users. If you do so youre risking race conditions, desyncs and worse!

Parameters:
source The user sending the KILL
dest The user being killed
reason The kill reason
Returns:
1 to prevent the kill, 0 to allow

Reimplemented from Module.

Definition at line 276 of file m_sqllog.cpp.

References AddLogEntry(), connection::host, LT_KILL, and userrec::nick.

00277         {
00278                 AddLogEntry(LT_KILL,dest->nick,dest->host,source->nick);
00279                 return 0;
00280         }

virtual void ModuleSQLLog::OnLoadModule Module mod,
const std::string name
[inline, virtual]
 

Called whenever a module is loaded.

mod will contain a pointer to the module, and string will contain its name, for example m_widgets.so. This function is primary for dependency checking, your module may decide to enable some extra features if it sees that you have for example loaded "m_killwidgets.so" with "m_makewidgets.so". It is highly recommended that modules do *NOT* bail if they cannot satisfy dependencies, but instead operate under reduced functionality, unless the dependency is absolutely neccessary (e.g. a module that extends the features of another module).

Parameters:
mod A pointer to the new module
name The new module's filename

Reimplemented from Module.

Definition at line 301 of file m_sqllog.cpp.

References AddLogEntry(), InspIRCd::Config, LT_LOADMODULE, Module::ServerInstance, and ServerConfig::ServerName.

virtual void ModuleSQLLog::OnOper userrec user,
const std::string opertype
[inline, virtual]
 

Called whenever a user opers locally.

The userrec will contain the oper mode 'o' as this function is called after any modifications are made to the user's structure by the core.

Parameters:
user The user who is opering up
opertype The opers type name

Reimplemented from Module.

Definition at line 266 of file m_sqllog.cpp.

References AddLogEntry(), connection::host, LT_OPER, userrec::nick, and userrec::server.

00267         {
00268                 AddLogEntry(LT_OPER,user->nick,user->host,user->server);
00269         }

virtual int ModuleSQLLog::OnPreCommand const std::string command,
const char **  parameters,
int  pcnt,
userrec user,
bool  validated,
const std::string original_line
[inline, virtual]
 

Called whenever any command is about to be executed.

This event occurs for all registered commands, wether they are registered in the core, or another module, and for invalid commands. Invalid commands may only be sent to this function when the value of validated is false. By returning 1 from this method you may prevent the command being executed. If you do this, no output is created by the core, and it is down to your module to produce any output neccessary. Note that unless you return 1, you should not destroy any structures (e.g. by using InspIRCd::QuitUser) otherwise when the command's handler function executes after your method returns, it will be passed an invalid pointer to the user object and crash!)

Parameters:
command The command being executed
parameters An array of array of characters containing the parameters for the command
pcnt The nuimber of parameters passed to the command
user the user issuing the command
validated True if the command has passed all checks, e.g. it is recognised, has enough parameters, the user has permission to execute it, etc.
original_line The entire original line as passed to the parser from the user
Returns:
1 to block the command, 0 to allow

Reimplemented from Module.

Definition at line 282 of file m_sqllog.cpp.

References AddLogEntry(), LT_XLINE, userrec::nick, and userrec::server.

00283         {
00284                 if ((command == "GLINE" || command == "KLINE" || command == "ELINE" || command == "ZLINE") && validated)
00285                 {
00286                         AddLogEntry(LT_XLINE,user->nick,command[0]+std::string(":")+std::string(parameters[0]),user->server);
00287                 }
00288                 return 0;
00289         }

virtual void ModuleSQLLog::OnRehash userrec user,
const std::string parameter
[inline, virtual]
 

Called on rehash.

This method is called prior to a /REHASH or when a SIGHUP is received from the operating system. You should use it to reload any files so that your module keeps in step with the rest of the application. If a parameter is given, the core has done nothing. The module receiving the event can decide if this parameter has any relevence to it.

Parameters:
user The user performing the rehash, if any -- if this is server initiated, the value of this variable will be NULL.
parameter The (optional) parameter given to REHASH from the user.

Reimplemented from Module.

Definition at line 223 of file m_sqllog.cpp.

References ReadConfig().

Referenced by ModuleSQLLog().

00224         {
00225                 ReadConfig();
00226         }

virtual char* ModuleSQLLog::OnRequest Request request  )  [inline, virtual]
 

Called whenever a Request class is sent to your module by another module.

Please see the documentation of Request::Send() for further information. The Request sent can always be assumed to be non-NULL, you should not change the request object or its data. Your method may return arbitary data in the char* result which the requesting module may be able to use for pre-determined purposes (e.g. the results of an SQL query, etc).

Parameters:
request The Request class being received

Reimplemented from Module.

Definition at line 228 of file m_sqllog.cpp.

References active_queries, Request::GetId(), SQLresult::id, SQLRESID, and SQLSUCCESS.

00229         {
00230                 if(strcmp(SQLRESID, request->GetId()) == 0)
00231                 {
00232                         SQLresult* res;
00233                         std::map<unsigned long, QueryInfo*>::iterator n;
00234 
00235                         res = static_cast<SQLresult*>(request);
00236                         n = active_queries.find(res->id);
00237 
00238                         if (n != active_queries.end())
00239                         {
00240                                 n->second->Go(res);
00241                                 std::map<unsigned long, QueryInfo*>::iterator n = active_queries.find(res->id);
00242                                 active_queries.erase(n);
00243                         }
00244 
00245                         return SQLSUCCESS;
00246                 }
00247 
00248                 return NULL;
00249         }

virtual void ModuleSQLLog::OnUserConnect userrec user  )  [inline, virtual]
 

Called when a user connects.

The details of the connecting user are available to you in the parameter userrec *user

Parameters:
user The user who is connecting

Reimplemented from Module.

Definition at line 291 of file m_sqllog.cpp.

References AddLogEntry(), connection::host, LT_CONNECT, userrec::nick, and userrec::server.

00292         {
00293                 AddLogEntry(LT_CONNECT,user->nick,user->host,user->server);
00294         }

virtual void ModuleSQLLog::OnUserQuit userrec user,
const std::string reason,
const std::string oper_message
[inline, virtual]
 

Called when a user quits.

The details of the exiting user are available to you in the parameter userrec *user This event is only called when the user is fully registered when they quit. To catch raw disconnections, use the OnUserDisconnect method.

Parameters:
user The user who is quitting
message The user's quit message (as seen by non-opers)
oper_message The user's quit message (as seen by opers)

Reimplemented from Module.

Definition at line 296 of file m_sqllog.cpp.

References AddLogEntry(), connection::host, LT_DISCONNECT, userrec::nick, and userrec::server.

00297         {
00298                 AddLogEntry(LT_DISCONNECT,user->nick,user->host,user->server);
00299         }

void ModuleSQLLog::ReadConfig  )  [inline]
 

Definition at line 217 of file m_sqllog.cpp.

References Conf, dbid, ConfigReader::ReadValue(), and Module::ServerInstance.

Referenced by OnRehash().

00218         {
00219                 ConfigReader Conf(ServerInstance);
00220                 dbid = Conf.ReadValue("sqllog","dbid",0);       // database id of a database configured in sql module
00221         }


Member Data Documentation

ConfigReader* ModuleSQLLog::Conf [private]
 

Definition at line 184 of file m_sqllog.cpp.

Referenced by ReadConfig().


The documentation for this class was generated from the following file: