]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Change the SQLutils and SQL providers to also use interfaces for proper unload order...
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 28 Dec 2006 22:42:38 +0000 (22:42 +0000)
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 28 Dec 2006 22:42:38 +0000 (22:42 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6149 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/extra/m_mysql.cpp
src/modules/extra/m_pgsql.cpp
src/modules/extra/m_sqlauth.cpp
src/modules/extra/m_sqloper.cpp
src/modules/extra/m_sqlutils.cpp

index 63ed7d54038ab6e23d8aa0bafef783d1ccffb083..2449b523866292ff0fa606216b37dca05db07b91 100644 (file)
@@ -725,6 +725,47 @@ class ModuleSQL : public Module
        pthread_t Dispatcher;
        int currid;
 
+       ModuleSQL(InspIRCd* Me)
+       : Module::Module(Me)
+       {
+               ServerInstance->UseInterface("SQLutils");
+
+               Conf = new ConfigReader(ServerInstance);
+               PublicServerInstance = ServerInstance;
+               currid = 0;
+               SQLModule = this;
+
+               MessagePipe = new Notifier(ServerInstance);
+               ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",MessagePipe->GetPort());
+               
+               pthread_attr_t attribs;
+               pthread_attr_init(&attribs);
+               pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
+               if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0)
+               {
+                       throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno)));
+               }
+
+               if (!ServerInstance->PublishFeature("SQL", this))
+               {
+                       /* Tell worker thread to exit NOW */
+                       giveup = true;
+                       throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
+               }
+
+               ServerInstance->PublishInterface("SQL", this);
+       }
+
+       virtual ~ModuleSQL()
+       {
+               giveup = true;
+               ClearDatabases();
+               DELETE(Conf);
+               ServerInstance->UnpublishInterface("SQL", this);
+               ServerInstance->DoneWithInterface("SQLutils");
+       }
+
+
        void Implements(char* List)
        {
                List[I_OnRehash] = List[I_OnRequest] = 1;
@@ -774,40 +815,6 @@ class ModuleSQL : public Module
                return NULL;
        }
 
-       ModuleSQL(InspIRCd* Me)
-               : Module::Module(Me)
-       {
-               
-               Conf = new ConfigReader(ServerInstance);
-               PublicServerInstance = ServerInstance;
-               currid = 0;
-               SQLModule = this;
-
-               MessagePipe = new Notifier(ServerInstance);
-               ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",MessagePipe->GetPort());
-               
-               pthread_attr_t attribs;
-               pthread_attr_init(&attribs);
-               pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
-               if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0)
-               {
-                       throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno)));
-               }
-               if (!ServerInstance->PublishFeature("SQL", this))
-               {
-                       /* Tell worker thread to exit NOW */
-                       giveup = true;
-                       throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
-               }
-       }
-       
-       virtual ~ModuleSQL()
-       {
-               giveup = true;
-               ClearDatabases();
-               DELETE(Conf);
-       }
-       
        virtual void OnRehash(const std::string &parameter)
        {
                /* TODO: set rehash bool here, which makes the dispatcher thread rehash at next opportunity */
index 7e782c277a2ecacc5f68ecb49f1ba133bd0d964a..dedb6a2c3414a8fd4ecb498c303850d5f9ca560f 100644 (file)
@@ -518,15 +518,30 @@ public:
        ModulePgSQL(InspIRCd* Me)
        : Module::Module(Me), currid(0)
        {
-               ServerInstance->Log(DEBUG, "%s 'SQL' feature", ServerInstance->PublishFeature("SQL", this) ? "Published" : "Couldn't publish");
-               
+               ServerInstance->UseInterface("SQLutils");
+
                sqlsuccess = new char[strlen(SQLSUCCESS)+1];
                
                strlcpy(sqlsuccess, SQLSUCCESS, strlen(SQLSUCCESS)+1);
 
+               if (!ServerInstance->PublishFeature("SQL", this))
+               {
+                       throw ModuleException("m_pgsql: Unable to publish feature 'SQL'");
+               }
+
                OnRehash("");
+
+               ServerInstance->PublishInterface("SQL", this);
        }
 
+       virtual ~ModulePgSQL()
+       {
+               DELETE(sqlsuccess);
+               ServerInstance->UnpublishInterface("SQL", this);
+               ServerInstance->DoneWithInterface("SQLutils");
+       }       
+
+
        void Implements(char* List)
        {
                List[I_OnUnloadModule] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = 1;
@@ -658,11 +673,7 @@ public:
        {
                return Version(1, 1, 0, 0, VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION);
        }
-       
-       virtual ~ModulePgSQL()
-       {
-               DELETE(sqlsuccess);
-       }       
+
 };
 
 SQLConn::SQLConn(InspIRCd* SI, ModulePgSQL* self, const SQLhost& hi)
index 8b02bed69a9bdebe2b7f0cab1b2360f12c9e2f1b..b2b7c9044a854da8fe5e45f355df846f75c77df9 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include <string>
-
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
@@ -28,6 +27,7 @@ class ModuleSQLAuth : public Module
 {
        InspIRCd* Srv;
        Module* SQLutils;
+       Module* SQLprovider;
 
        std::string usertable;
        std::string userfield;
@@ -43,21 +43,22 @@ public:
        ModuleSQLAuth(InspIRCd* Me)
        : Module::Module(Me), Srv(Me)
        {
-               SQLutils = Srv->FindFeature("SQLutils");
-               
-               if(SQLutils)
-               {
-                       ServerInstance->Log(DEBUG, "Successfully got SQLutils pointer");
-               }
-               else
-               {
-                       ServerInstance->Log(DEFAULT, "ERROR: This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
-                       throw ModuleException("This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
-               }
-                               
+               ServerInstance->UseInterface("SQLutils");
+               ServerInstance->UseInterface("SQL");
+
+               SQLutils = ServerInstance->FindModule("m_sqlutils.so");
+               if (!SQLutils)
+                       throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqlauth.so.");
+
                OnRehash("");
        }
 
+       virtual ~ModuleSQLAuth()
+       {
+               ServerInstance->DoneWithInterface("SQL");
+               ServerInstance->DoneWithInterface("SQLutils");
+       }
+
        void Implements(char* List)
        {
                List[I_OnUserDisconnect] = List[I_OnCheckReady] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = 1;
@@ -210,10 +211,6 @@ public:
                return user->GetExt("sqlauthed");
        }
 
-       virtual ~ModuleSQLAuth()
-       {
-       }
-       
        virtual Version GetVersion()
        {
                return Version(1,1,1,0,VF_VENDOR,API_VERSION);
index f548c15eea3f6c4df2949fe59d6a285da17ad691..b7a45af45d0f1b968f8a03b6a1fb5ac8287ae9c2 100644 (file)
@@ -35,26 +35,20 @@ public:
        ModuleSQLOper(InspIRCd* Me)
        : Module::Module(Me), Srv(Me)
        {
-               SQLutils = Srv->FindFeature("SQLutils");
-               
-               if (SQLutils)
-               {
-                       ServerInstance->Log(DEBUG, "Successfully got SQLutils pointer");
-               }
-               else
-               {
-                       ServerInstance->Log(DEFAULT, "ERROR: This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
-                       throw ModuleException("This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
-               }
-               
+               ServerInstance->UseInterface("SQLutils");
+               ServerInstance->UseInterface("SQL");
+
+               SQLutils = ServerInstance->FindModule("m_sqlutils.so");
+               if (!SQLutils)
+                       throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so.");
+
                OnRehash("");
        }
 
-       virtual void OnRehash(const std::string &parameter)
+       virtual ~ModuleSQLOper()
        {
-               ConfigReader Conf(Srv);
-               
-               databaseid = Conf.ReadValue("sqloper", "dbid", 0); /* Database ID of a database configured for the service provider module */
+               ServerInstance->DoneWithInterface("SQL");
+               ServerInstance->DoneWithInterface("SQLutils");
        }
 
        void Implements(char* List)
@@ -62,6 +56,13 @@ public:
                List[I_OnRequest] = List[I_OnRehash] = List[I_OnPreCommand] = 1;
        }
 
+       virtual void OnRehash(const std::string &parameter)
+       {
+               ConfigReader Conf(Srv);
+               
+               databaseid = Conf.ReadValue("sqloper", "dbid", 0); /* Database ID of a database configured for the service provider module */
+       }
+
        virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
        {
                if ((validated) && (command == "OPER"))
@@ -272,10 +273,6 @@ public:
                return false;
        }
 
-       virtual ~ModuleSQLOper()
-       {
-       }
-       
        virtual Version GetVersion()
        {
                return Version(1,1,1,0,VF_VENDOR,API_VERSION);
index c423246cced8d9a4f053cd068a3853acc65c803c..bec8a4450bfee013e6523647b98e903afd643cb8 100644 (file)
@@ -35,8 +35,6 @@ typedef std::list<unsigned long> AssocIdList;
 class ModuleSQLutils : public Module
 {
 private:
-       
-
        IdUserMap iduser;
        IdChanMap idchan;
 
@@ -44,9 +42,14 @@ public:
        ModuleSQLutils(InspIRCd* Me)
        : Module::Module(Me)
        {
-               ServerInstance->Log(DEBUG, "%s 'SQLutils' feature", ServerInstance->PublishFeature("SQLutils", this) ? "Published" : "Couldn't publish");
+               ServerInstance->PublishInterface("SQLutils", this);
        }
 
+       virtual ~ModuleSQLutils()
+       {
+               ServerInstance->UnpublishInterface("SQLutils", this);
+       }       
+
        void Implements(char* List)
        {
                List[I_OnChannelDelete] = List[I_OnUnloadModule] = List[I_OnRequest] =  List[I_OnUserDisconnect] = 1;
@@ -263,12 +266,9 @@ public:
                        
        virtual Version GetVersion()
        {
-               return Version(1, 1, 0, 0, VF_STATIC|VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION);
+               return Version(1, 1, 0, 0, VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION);
        }
        
-       virtual ~ModuleSQLutils()
-       {
-       }       
 };
 
 class ModuleSQLutilsFactory : public ModuleFactory