]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mysql.cpp
Remove spanningtree override of /LUSERS
[user/henk/code/inspircd.git] / src / modules / extra / m_mysql.cpp
index 90a2d95dce0e4cf56d36e97622a9efbef241edcd..c294befdc09eeb24545cff49f2399008d6d415cf 100644 (file)
@@ -70,7 +70,7 @@ class DispatcherThread;
 typedef std::map<std::string, SQLConnection*> ConnMap;
 typedef std::deque<SQLresult*> ResultQueue;
 
-unsigned long count(const char * const str, char a)
+static unsigned long count(const char * const str, char a)
 {
        unsigned long n = 0;
        for (const char *p = str; *p; ++p)
@@ -87,14 +87,13 @@ unsigned long count(const char * const str, char a)
 class ModuleSQL : public Module
 {
  public:
-
-        ConfigReader *Conf;
         int currid;
         bool rehashing;
         DispatcherThread* Dispatcher;
         Mutex ResultsMutex;
         Mutex LoggingMutex;
         Mutex ConnMutex;
+        ServiceProvider sqlserv;
 
         ModuleSQL();
         ~ModuleSQL();
@@ -549,30 +548,31 @@ bool HasHost(const SQLhost &host)
        return false;
 }
 
-bool HostInConf(ConfigReader* conf, const SQLhost &h)
+bool HostInConf(const SQLhost &h)
 {
-       for(int i = 0; i < conf->Enumerate("database"); i++)
+       ConfigReader conf;
+       for(int i = 0; i < conf.Enumerate("database"); i++)
        {
                SQLhost host;
-               host.id         = conf->ReadValue("database", "id", i);
-               host.host       = conf->ReadValue("database", "hostname", i);
-               host.port       = conf->ReadInteger("database", "port", i, true);
-               host.name       = conf->ReadValue("database", "name", i);
-               host.user       = conf->ReadValue("database", "username", i);
-               host.pass       = conf->ReadValue("database", "password", i);
-               host.ssl        = conf->ReadFlag("database", "ssl", i);
+               host.id         = conf.ReadValue("database", "id", i);
+               host.host       = conf.ReadValue("database", "hostname", i);
+               host.port       = conf.ReadInteger("database", "port", i, true);
+               host.name       = conf.ReadValue("database", "name", i);
+               host.user       = conf.ReadValue("database", "username", i);
+               host.pass       = conf.ReadValue("database", "password", i);
+               host.ssl        = conf.ReadFlag("database", "ssl", i);
                if (h == host)
                        return true;
        }
        return false;
 }
 
-void ClearOldConnections(ConfigReader* conf)
+void ClearOldConnections()
 {
        ConnMap::iterator i,safei;
        for (i = Connections.begin(); i != Connections.end(); i++)
        {
-               if (!HostInConf(conf, i->second->GetConfHost()))
+               if (!HostInConf(i->second->GetConfHost()))
                {
                        delete i->second;
                        safei = i;
@@ -611,21 +611,22 @@ void ConnectDatabases(ModuleSQL* Parent)
        }
 }
 
-void LoadDatabases(ConfigReader* conf, ModuleSQL* Parent)
+void LoadDatabases(ModuleSQL* Parent)
 {
+       ConfigReader conf;
        Parent->ConnMutex.Lock();
-       ClearOldConnections(conf);
-       for (int j =0; j < conf->Enumerate("database"); j++)
+       ClearOldConnections();
+       for (int j =0; j < conf.Enumerate("database"); j++)
        {
                SQLhost host;
-               host.id         = conf->ReadValue("database", "id", j);
-               host.host       = conf->ReadValue("database", "hostname", j);
-               host.port       = conf->ReadInteger("database", "port", j, true);
-               host.name       = conf->ReadValue("database", "name", j);
-               host.user       = conf->ReadValue("database", "username", j);
-               host.pass       = conf->ReadValue("database", "password", j);
-               host.ssl        = conf->ReadFlag("database", "ssl", j);
-               std::string initquery = conf->ReadValue("database", "initialquery", j);
+               host.id         = conf.ReadValue("database", "id", j);
+               host.host       = conf.ReadValue("database", "hostname", j);
+               host.port       = conf.ReadInteger("database", "port", j, true);
+               host.name       = conf.ReadValue("database", "name", j);
+               host.user       = conf.ReadValue("database", "username", j);
+               host.pass       = conf.ReadValue("database", "password", j);
+               host.ssl        = conf.ReadFlag("database", "ssl", j);
+               std::string initquery = conf.ReadValue("database", "initialquery", j);
 
                if (HasHost(host))
                        continue;
@@ -666,8 +667,6 @@ ConnMap::iterator GetCharId(char id)
        return Connections.end();
 }
 
-class ModuleSQL;
-
 class DispatcherThread : public SocketThread
 {
  private:
@@ -679,25 +678,13 @@ class DispatcherThread : public SocketThread
        virtual void OnNotify();
 };
 
-ModuleSQL::ModuleSQL() : rehashing(false)
+ModuleSQL::ModuleSQL() : rehashing(false), sqlserv(this, "SQL/mysql", SERVICE_DATA)
 {
-       ServerInstance->Modules->UseInterface("SQLutils");
-
-       Conf = new ConfigReader;
        currid = 0;
 
        Dispatcher = new DispatcherThread(this);
        ServerInstance->Threads->Start(Dispatcher);
 
-       if (!ServerInstance->Modules->PublishFeature("SQL", this))
-       {
-               Dispatcher->join();
-               delete Dispatcher;
-               ServerInstance->Modules->DoneWithInterface("SQLutils");
-               throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
-       }
-
-       ServerInstance->Modules->PublishInterface("SQL", this);
        Implementation eventlist[] = { I_OnRehash };
        ServerInstance->Modules->Attach(eventlist, this, 1);
 }
@@ -706,10 +693,6 @@ ModuleSQL::~ModuleSQL()
 {
        delete Dispatcher;
        ClearAllConnections();
-       delete Conf;
-       ServerInstance->Modules->UnpublishInterface("SQL", this);
-       ServerInstance->Modules->UnpublishFeature("SQL");
-       ServerInstance->Modules->DoneWithInterface("SQLutils");
 }
 
 unsigned long ModuleSQL::NewID()
@@ -756,12 +739,12 @@ void ModuleSQL::OnRehash(User* user)
 
 Version ModuleSQL::GetVersion()
 {
-       return Version("SQL Service Provider module for all other m_sql* modules", VF_VENDOR | VF_SERVICEPROVIDER);
+       return Version("SQL Service Provider module for all other m_sql* modules", VF_VENDOR);
 }
 
 void DispatcherThread::Run()
 {
-       LoadDatabases(Parent->Conf, Parent);
+       LoadDatabases(Parent);
 
        SQLConnection* conn = NULL;
 
@@ -771,7 +754,7 @@ void DispatcherThread::Run()
                if (Parent->rehashing)
                {
                        Parent->rehashing = false;
-                       LoadDatabases(Parent->Conf, Parent);
+                       LoadDatabases(Parent);
                }
 
                conn = NULL;