mirror of
https://github.com/anope/anope.git
synced 2026-06-12 15:44:46 +02:00
Rework the interface for service references.
This commit is contained in:
+17
-7
@@ -138,20 +138,30 @@ class ServiceReference
|
||||
Anope::string name;
|
||||
|
||||
public:
|
||||
ServiceReference() = default;
|
||||
|
||||
ServiceReference(const Anope::string &t, const Anope::string &n) : type(t), name(n)
|
||||
ServiceReference(const Anope::string &t, const Anope::string &n = "")
|
||||
: type(t)
|
||||
, name(n)
|
||||
{
|
||||
}
|
||||
|
||||
const Anope::string &GetServiceName() const { return name; }
|
||||
/** Retrieves the name of the service (e.g. mysql/main). */
|
||||
const auto &GetServiceName() const { return name; }
|
||||
|
||||
const Anope::string &GetServiceType() const { return type; }
|
||||
/** Retrieves the type of the service (e.g. SQL::Provider). */
|
||||
const auto &GetServiceType() const { return type; }
|
||||
|
||||
inline void operator=(const Anope::string &n)
|
||||
/** Invalidates the reference and changes the name of the referenced service. */
|
||||
void SetServiceName(const Anope::string& newname)
|
||||
{
|
||||
this->name = n;
|
||||
this->invalid = true;
|
||||
this->name = newname;
|
||||
}
|
||||
|
||||
/** Invalidates the reference and changes the type of the referenced service. */
|
||||
void SetServiceType(const Anope::string& newtype)
|
||||
{
|
||||
this->invalid = true;
|
||||
this->type = newtype;
|
||||
}
|
||||
|
||||
operator bool() override
|
||||
|
||||
@@ -73,17 +73,21 @@ class CSStats final
|
||||
MySQLInterface sqlinterface;
|
||||
Anope::string prefix;
|
||||
public:
|
||||
CSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
|
||||
commandcsstats(this), commandcsgstats(this), sql("", ""), sqlinterface(this)
|
||||
CSStats(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, VENDOR)
|
||||
, commandcsstats(this)
|
||||
, commandcsgstats(this)
|
||||
, sql("SQL::Provider")
|
||||
, sqlinterface(this)
|
||||
{
|
||||
me = this;
|
||||
|
||||
}
|
||||
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
prefix = conf.GetModule("chanstats").Get<const Anope::string>("prefix", "anope_");
|
||||
this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf.GetModule("chanstats").Get<const Anope::string>("engine"));
|
||||
const auto &block = conf.GetModule("chanstats");
|
||||
prefix = block.Get<const Anope::string>("prefix", "anope_");
|
||||
this->sql.SetServiceName(block.Get<const Anope::string>("engine"));
|
||||
}
|
||||
|
||||
SQL::Result RunQuery(const SQL::Query &query)
|
||||
|
||||
@@ -99,18 +99,23 @@ class CSTop final
|
||||
Anope::string prefix;
|
||||
|
||||
public:
|
||||
CSTop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
|
||||
commandcstop(this), commandcsgtop(this), commandcstop10(this), commandcsgtop10(this), sql("", ""),
|
||||
sqlinterface(this)
|
||||
CSTop(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, VENDOR)
|
||||
, commandcstop(this)
|
||||
, commandcsgtop(this)
|
||||
, commandcstop10(this)
|
||||
, commandcsgtop10(this)
|
||||
, sql("SQL::Provider")
|
||||
, sqlinterface(this)
|
||||
{
|
||||
me = this;
|
||||
|
||||
}
|
||||
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
prefix = conf.GetModule("chanstats").Get<const Anope::string>("prefix", "anope_");
|
||||
this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf.GetModule("chanstats").Get<const Anope::string>("engine"));
|
||||
const auto &block = conf.GetModule("chanstats");
|
||||
prefix = block.Get<const Anope::string>("prefix", "anope_");
|
||||
this->sql.SetServiceName(block.Get<const Anope::string>("engine"));
|
||||
}
|
||||
|
||||
SQL::Result RunQuery(const SQL::Query &query)
|
||||
|
||||
+11
-8
@@ -494,11 +494,15 @@ class MChanstats final
|
||||
|
||||
|
||||
public:
|
||||
MChanstats(const Anope::string &modname, const Anope::string &creator) :
|
||||
Module(modname, creator, EXTRA | VENDOR),
|
||||
cs_stats(this, "CS_STATS"), ns_stats(this, "NS_STATS"),
|
||||
commandcssetchanstats(this), commandnssetchanstats(this), commandnssasetchanstats(this),
|
||||
sqlinterface(this)
|
||||
MChanstats(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, cs_stats(this, "CS_STATS")
|
||||
, ns_stats(this, "NS_STATS")
|
||||
, commandcssetchanstats(this)
|
||||
, commandnssetchanstats(this)
|
||||
, commandnssasetchanstats(this)
|
||||
, sql("SQL::Provider")
|
||||
, sqlinterface(this)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -509,12 +513,11 @@ public:
|
||||
SmileysHappy = block.Get<const Anope::string>("SmileysHappy");
|
||||
SmileysSad = block.Get<const Anope::string>("SmileysSad");
|
||||
SmileysOther = block.Get<const Anope::string>("SmileysOther");
|
||||
Anope::string engine = block.Get<const Anope::string>("engine");
|
||||
this->sql = ServiceReference<SQL::Provider>("SQL::Provider", engine);
|
||||
this->sql.SetServiceName(block.Get<const Anope::string>("engine"));
|
||||
if (sql)
|
||||
this->CheckTables();
|
||||
else
|
||||
Log(this) << "no database connection to " << engine;
|
||||
Log(this) << "no database connection to " << this->sql.GetServiceName();
|
||||
}
|
||||
|
||||
void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override
|
||||
|
||||
@@ -134,7 +134,10 @@ class DatabaseRedis final
|
||||
public:
|
||||
ServiceReference<Provider> redis;
|
||||
|
||||
DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sl(this)
|
||||
DatabaseRedis(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, DATABASE | VENDOR)
|
||||
, sl(this)
|
||||
, redis("Redis::Provider")
|
||||
{
|
||||
me = this;
|
||||
|
||||
@@ -180,7 +183,7 @@ public:
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
const auto &block = conf.GetModule(this);
|
||||
this->redis = ServiceReference<Provider>("Redis::Provider", block.Get<const Anope::string>("engine", "redis/main"));
|
||||
this->redis.SetServiceName(block.Get<const Anope::string>("engine", "redis/main"));
|
||||
}
|
||||
|
||||
EventReturn OnLoadDatabase() override
|
||||
|
||||
@@ -102,10 +102,11 @@ class DBSQL final
|
||||
}
|
||||
|
||||
public:
|
||||
DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sql("", ""), sqlinterface(this)
|
||||
DBSQL(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, DATABASE | VENDOR)
|
||||
, sql("SQL::Provider")
|
||||
, sqlinterface(this)
|
||||
{
|
||||
|
||||
|
||||
if (ModuleManager::FindModule("db_sql_live") != NULL)
|
||||
throw ModuleException("db_sql can not be loaded after db_sql_live");
|
||||
}
|
||||
@@ -166,7 +167,7 @@ public:
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
const auto &block = conf.GetModule(this);
|
||||
this->sql = ServiceReference<Provider>("SQL::Provider", block.Get<const Anope::string>("engine"));
|
||||
this->sql.SetServiceName(block.Get<const Anope::string>("engine"));
|
||||
this->prefix = block.Get<const Anope::string>("prefix", "anope_db_");
|
||||
this->import = block.Get<bool>("import");
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), SQL("", "")
|
||||
DBMySQL(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, DATABASE | VENDOR)
|
||||
, SQL("SQL::Provider")
|
||||
{
|
||||
this->lastwarn = 0;
|
||||
this->ro = false;
|
||||
@@ -148,7 +150,8 @@ public:
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
const auto &block = conf.GetModule(this);
|
||||
this->SQL = ServiceReference<Provider>("SQL::Provider", block.Get<const Anope::string>("engine"));
|
||||
|
||||
this->SQL.SetServiceName(block.Get<const Anope::string>("engine"));
|
||||
this->prefix = block.Get<const Anope::string>("prefix", "anope_db_");
|
||||
}
|
||||
|
||||
|
||||
@@ -291,6 +291,7 @@ private:
|
||||
public:
|
||||
ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, httpref(HTTP_PROVIDER)
|
||||
, xmlrpcinterface(this)
|
||||
{
|
||||
xmlrpc_env env;
|
||||
@@ -325,7 +326,7 @@ public:
|
||||
XMLRPCServiceInterface::enable_i8 = modconf.Get<bool>("enable_i8", "yes");
|
||||
XMLRPCServiceInterface::enable_nil = modconf.Get<bool>("enable_nil", "yes");
|
||||
|
||||
this->httpref = ServiceReference<HTTP::Provider>(HTTP_PROVIDER, modconf.Get<const Anope::string>("server", "httpd/main"));
|
||||
this->httpref.SetServiceName(modconf.Get<const Anope::string>("server", "httpd/main"));
|
||||
if (!httpref)
|
||||
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
||||
|
||||
|
||||
@@ -289,6 +289,7 @@ private:
|
||||
public:
|
||||
ModuleJSONRPC(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, httpref(HTTP_PROVIDER)
|
||||
, jsonrpcinterface(this)
|
||||
{
|
||||
}
|
||||
@@ -307,7 +308,7 @@ public:
|
||||
const auto &modconf = conf.GetModule(this);
|
||||
JSONRPCServiceInterface::integer_bits = modconf.Get<unsigned>("integer_bits", "64");
|
||||
|
||||
this->httpref = ServiceReference<HTTP::Provider>(HTTP_PROVIDER, modconf.Get<const Anope::string>("server", "httpd/main"));
|
||||
this->httpref.SetServiceName(modconf.Get<const Anope::string>("server", "httpd/main"));
|
||||
if (!httpref)
|
||||
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
||||
|
||||
|
||||
@@ -117,7 +117,6 @@ class ModuleRPCSystem final
|
||||
: public Module
|
||||
{
|
||||
private:
|
||||
ServiceReference<RPC::ServiceInterface> rpc;
|
||||
MessageNetworkRPCEvent messagenetworkrpcevent;
|
||||
MessageServerRPCEvent messageserverrpcevent;
|
||||
MessageUserRPCEvent messageuserrpcevent;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace
|
||||
{
|
||||
Module *me;
|
||||
|
||||
ServiceReference<Encryption::Provider> encryption;
|
||||
ServiceReference<Encryption::Provider> encryption("Encryption::Provider");
|
||||
Anope::string password_hash, password_field;
|
||||
}
|
||||
class SQLAuthenticationResult final
|
||||
@@ -110,34 +110,32 @@ public:
|
||||
class ModuleSQLAuthentication final
|
||||
: public Module
|
||||
{
|
||||
Anope::string engine;
|
||||
Anope::string query;
|
||||
Anope::string disable_reason, disable_email_reason;
|
||||
|
||||
ServiceReference<SQL::Provider> SQL;
|
||||
|
||||
public:
|
||||
ModuleSQLAuthentication(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
|
||||
ModuleSQLAuthentication(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, SQL("SQL::Provider")
|
||||
{
|
||||
me = this;
|
||||
|
||||
}
|
||||
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
const auto &config = conf.GetModule(this);
|
||||
this->engine = config.Get<const Anope::string>("engine");
|
||||
this->query = config.Get<const Anope::string>("query");
|
||||
this->disable_reason = config.Get<const Anope::string>("disable_reason");
|
||||
this->disable_email_reason = config.Get<Anope::string>("disable_email_reason");
|
||||
|
||||
this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine);
|
||||
this->SQL.SetServiceName(config.Get<const Anope::string>("engine"));
|
||||
|
||||
password_hash = config.Get<const Anope::string>("password_hash");
|
||||
if (!password_hash.empty())
|
||||
{
|
||||
password_field = config.Get<const Anope::string>("password_field", "password");
|
||||
encryption = ServiceReference<Encryption::Provider>("Encryption::Provider", password_hash);
|
||||
encryption.SetServiceName(password_hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ public:
|
||||
void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) override
|
||||
{
|
||||
Anope::string ref_name;
|
||||
ServiceReference<SQL::Provider> SQL;
|
||||
ServiceReference<SQL::Provider> SQL("SQL::Provider");
|
||||
|
||||
for (const auto &target : li->targets)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
if (!sz)
|
||||
{
|
||||
ref_name = target.substr(8);
|
||||
SQL = ServiceReference<SQL::Provider>("SQL::Provider", ref_name);
|
||||
SQL.SetServiceName(ref_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,14 @@ public:
|
||||
class ModuleSQLOper final
|
||||
: public Module
|
||||
{
|
||||
Anope::string engine;
|
||||
Anope::string query;
|
||||
|
||||
ServiceReference<SQL::Provider> SQL;
|
||||
|
||||
public:
|
||||
ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
|
||||
ModuleSQLOper(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, SQL("SQL::Provider")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -159,11 +160,8 @@ public:
|
||||
void OnReload(Configuration::Conf &conf) override
|
||||
{
|
||||
const auto &config = conf.GetModule(this);
|
||||
|
||||
this->engine = config.Get<const Anope::string>("engine");
|
||||
this->query = config.Get<const Anope::string>("query");
|
||||
|
||||
this->SQL = ServiceReference<SQL::Provider>("SQL::Provider", this->engine);
|
||||
this->SQL.SetServiceName(config.Get<const Anope::string>("engine"));
|
||||
}
|
||||
|
||||
void OnNickIdentify(User *u) override
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "webcpanel.h"
|
||||
|
||||
Module *me;
|
||||
Anope::string provider_name, template_base, page_title;
|
||||
Anope::string template_base, page_title;
|
||||
|
||||
class ModuleWebCPanel final
|
||||
: public Module
|
||||
@@ -53,6 +53,7 @@ class ModuleWebCPanel final
|
||||
|
||||
public:
|
||||
ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
|
||||
provider(HTTP_PROVIDER),
|
||||
panel(this, "webcpanel"),
|
||||
id(this, "webcpanel_id"), ip(this, "webcpanel_ip"), last_login(this, "webcpanel_last_login"),
|
||||
style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), cubes_png("cubes.png", "/static/cubes.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"),
|
||||
@@ -70,7 +71,7 @@ public:
|
||||
template_base = Anope::ExpandData(block.Get<const Anope::string>("template_dir", "webcpanel/templates/default"));
|
||||
page_title = block.Get<const Anope::string>("title", "Anope IRC Services");
|
||||
|
||||
provider = ServiceReference<HTTP::Provider>(HTTP_PROVIDER, provider_name);
|
||||
provider.SetServiceName(block.Get<const Anope::string>("server", "httpd/main"));
|
||||
if (!provider)
|
||||
throw ModuleException("Unable to find HTTPD provider. Is httpd loaded?");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user