From a59d08fffd3dc8a9850ce34c9928fb6382b9b37f Mon Sep 17 00:00:00 2001 From: danieldg Date: Sun, 18 Oct 2009 16:01:33 +0000 Subject: Remove VF_SERVICEPROVIDER, prevent heap allocation of ConfigReader git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11904 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_mysql.cpp | 56 ++++++++++++++++++------------------- src/modules/extra/m_pgsql.cpp | 2 +- src/modules/extra/m_regex_pcre.cpp | 2 +- src/modules/extra/m_regex_posix.cpp | 2 +- src/modules/extra/m_regex_tre.cpp | 2 +- src/modules/extra/m_sqlite3.cpp | 2 +- 6 files changed, 32 insertions(+), 34 deletions(-) (limited to 'src/modules/extra') diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 90a2d95dc..47de25ee4 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -87,8 +87,6 @@ unsigned long count(const char * const str, char a) class ModuleSQL : public Module { public: - - ConfigReader *Conf; int currid; bool rehashing; DispatcherThread* Dispatcher; @@ -549,30 +547,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 +610,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; @@ -683,7 +683,6 @@ ModuleSQL::ModuleSQL() : rehashing(false) { ServerInstance->Modules->UseInterface("SQLutils"); - Conf = new ConfigReader; currid = 0; Dispatcher = new DispatcherThread(this); @@ -706,7 +705,6 @@ ModuleSQL::~ModuleSQL() { delete Dispatcher; ClearAllConnections(); - delete Conf; ServerInstance->Modules->UnpublishInterface("SQL", this); ServerInstance->Modules->UnpublishFeature("SQL"); ServerInstance->Modules->DoneWithInterface("SQLutils"); @@ -756,12 +754,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 +769,7 @@ void DispatcherThread::Run() if (Parent->rehashing) { Parent->rehashing = false; - LoadDatabases(Parent->Conf, Parent); + LoadDatabases(Parent); } conn = NULL; diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 5d2fe106b..b5beea0b0 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -954,7 +954,7 @@ class ModulePgSQL : public Module virtual Version GetVersion() { - return Version("PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API", VF_VENDOR|VF_SERVICEPROVIDER); + return Version("PostgreSQL Service Provider module for all other m_sql* modules, uses v2 of the SQL API", VF_VENDOR); } }; diff --git a/src/modules/extra/m_regex_pcre.cpp b/src/modules/extra/m_regex_pcre.cpp index 8f2284ce6..9e8aff159 100644 --- a/src/modules/extra/m_regex_pcre.cpp +++ b/src/modules/extra/m_regex_pcre.cpp @@ -76,7 +76,7 @@ public: virtual Version GetVersion() { - return Version("Regex Provider Module for PCRE", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER); + return Version("Regex Provider Module for PCRE", VF_COMMON | VF_VENDOR); } virtual ~ModuleRegexPCRE() diff --git a/src/modules/extra/m_regex_posix.cpp b/src/modules/extra/m_regex_posix.cpp index 1bcd32187..ea016ae64 100644 --- a/src/modules/extra/m_regex_posix.cpp +++ b/src/modules/extra/m_regex_posix.cpp @@ -85,7 +85,7 @@ public: virtual Version GetVersion() { - return Version("Regex Provider Module for POSIX Regular Expressions", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER); + return Version("Regex Provider Module for POSIX Regular Expressions", VF_COMMON | VF_VENDOR); } virtual ~ModuleRegexPOSIX() diff --git a/src/modules/extra/m_regex_tre.cpp b/src/modules/extra/m_regex_tre.cpp index ef0ed91a4..01c6ebf4a 100644 --- a/src/modules/extra/m_regex_tre.cpp +++ b/src/modules/extra/m_regex_tre.cpp @@ -82,7 +82,7 @@ public: virtual Version GetVersion() { - return Version("Regex Provider Module for TRE Regular Expressions", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER); + return Version("Regex Provider Module for TRE Regular Expressions", VF_COMMON | VF_VENDOR); } virtual ~ModuleRegexTRE() diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index aba3c0930..234f89ea2 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -723,7 +723,7 @@ class ModuleSQLite3 : public Module virtual Version GetVersion() { - return Version("sqlite3 provider", VF_VENDOR | VF_SERVICEPROVIDER); + return Version("sqlite3 provider", VF_VENDOR); } }; -- cgit v1.2.3