]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlauth.cpp
All of insp now builds with -pedantic (theres some warnings to squash in modules...
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlauth.cpp
index 8b8073f2d88aa3ada6f791d30a1f14cb1fb7c690..98b0227e5ad3157927e4dac3ace89fdab33c6bc3 100644 (file)
@@ -23,7 +23,6 @@
 
 class ModuleSQLAuth : public Module
 {
-       InspIRCd* Srv;
        Module* SQLutils;
        Module* SQLprovider;
 
@@ -39,16 +38,16 @@ class ModuleSQLAuth : public Module
        
 public:
        ModuleSQLAuth(InspIRCd* Me)
-       : Module::Module(Me), Srv(Me)
+       : Module::Module(Me)
        {
-               ServerInstance->UseInterface("SQLutils");
-               ServerInstance->UseInterface("SQL");
+               ServerInstance->Modules->UseInterface("SQLutils");
+               ServerInstance->Modules->UseInterface("SQL");
 
-               SQLutils = ServerInstance->FindModule("m_sqlutils.so");
+               SQLutils = ServerInstance->Modules->Find("m_sqlutils.so");
                if (!SQLutils)
                        throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqlauth.so.");
 
-               SQLprovider = Srv->FindFeature("SQL");
+               SQLprovider = ServerInstance->Modules->FindFeature("SQL");
                if (!SQLprovider)
                        throw ModuleException("Can't find an SQL provider module. Please load one before attempting to load m_sqlauth.");
 
@@ -57,8 +56,8 @@ public:
 
        virtual ~ModuleSQLAuth()
        {
-               ServerInstance->DoneWithInterface("SQL");
-               ServerInstance->DoneWithInterface("SQLutils");
+               ServerInstance->Modules->DoneWithInterface("SQL");
+               ServerInstance->Modules->DoneWithInterface("SQLutils");
        }
 
        void Implements(char* List)
@@ -66,9 +65,9 @@ public:
                List[I_OnUserDisconnect] = List[I_OnCheckReady] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = 1;
        }
 
-       virtual void OnRehash(userrec* user, const std::string &parameter)
+       virtual void OnRehash(User* user, const std::string &parameter)
        {
-               ConfigReader Conf(Srv);
+               ConfigReader Conf(ServerInstance);
                
                usertable       = Conf.ReadValue("sqlauth", "usertable", 0);    /* User table name */
                databaseid      = Conf.ReadValue("sqlauth", "dbid", 0);                 /* Database ID, given to the SQL service provider */
@@ -87,9 +86,9 @@ public:
                }
        }       
 
-       virtual int OnUserRegister(userrec* user)
+       virtual int OnUserRegister(User* user)
        {
-               if ((allowpattern != "") && (Srv->MatchText(user->nick,allowpattern)))
+               if ((!allowpattern.empty()) && (ServerInstance->MatchText(user->nick,allowpattern)))
                {
                        user->Extend("sqlauthed");
                        return 0;
@@ -97,20 +96,20 @@ public:
                
                if (!CheckCredentials(user))
                {
-                       userrec::QuitUser(Srv,user,killreason);
+                       User::QuitUser(ServerInstance,user,killreason);
                        return 1;
                }
                return 0;
        }
 
-       bool CheckCredentials(userrec* user)
+       bool CheckCredentials(User* user)
        {
                SQLrequest req = SQLreq(this, SQLprovider, databaseid, "SELECT ? FROM ? WHERE ? = '?' AND ? = ?'?')", userfield, usertable, userfield, user->nick, passfield, encryption, user->password);
                        
                if(req.Send())
                {
                        /* When we get the query response from the service provider we will be given an ID to play with,
-                        * just an ID number which is unique to this query. We need a way of associating that ID with a userrec
+                        * just an ID number which is unique to this query. We need a way of associating that ID with a User
                         * so we insert it into a map mapping the IDs to users.
                         * Thankfully m_sqlutils provides this, it will associate a ID with a user or channel, and if the user quits it removes the
                         * association. This means that if the user quits during a query we will just get a failed lookup from m_sqlutils - telling
@@ -123,7 +122,7 @@ public:
                else
                {
                        if (verbose)
-                               Srv->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, req.error.Str());
+                               ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, req.error.Str());
                        return false;
                }
        }
@@ -134,7 +133,7 @@ public:
                {
                        SQLresult* res = static_cast<SQLresult*>(request);
 
-                       userrec* user = GetAssocUser(this, SQLutils, res->id).S().user;
+                       User* user = GetAssocUser(this, SQLutils, res->id).S().user;
                        UnAssociate(this, SQLutils, res->id).S();
                        
                        if(user)
@@ -149,13 +148,13 @@ public:
                                        else if (verbose)
                                        {
                                                /* No rows in result, this means there was no record matching the user */
-                                               Srv->WriteOpers("Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick, user->ident, user->host);
+                                               ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick, user->ident, user->host);
                                                user->Extend("sqlauth_failed");
                                        }
                                }
                                else if (verbose)
                                {
-                                       Srv->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str());
+                                       ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str());
                                        user->Extend("sqlauth_failed");
                                }
                        }
@@ -166,20 +165,20 @@ public:
 
                        if (!user->GetExt("sqlauthed"))
                        {
-                               userrec::QuitUser(Srv,user,killreason);
+                               User::QuitUser(ServerInstance,user,killreason);
                        }
                        return SQLSUCCESS;
                }               
                return NULL;
        }
        
-       virtual void OnUserDisconnect(userrec* user)
+       virtual void OnUserDisconnect(User* user)
        {
                user->Shrink("sqlauthed");
                user->Shrink("sqlauth_failed");         
        }
        
-       virtual bool OnCheckReady(userrec* user)
+       virtual bool OnCheckReady(User* user)
        {
                return user->GetExt("sqlauthed");
        }
@@ -191,26 +190,4 @@ public:
        
 };
 
-class ModuleSQLAuthFactory : public ModuleFactory
-{
- public:
-       ModuleSQLAuthFactory()
-       {
-       }
-       
-       ~ModuleSQLAuthFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSQLAuth(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleSQLAuthFactory;
-}
+MODULE_INIT(ModuleSQLAuth)