diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/modules.h | 72 | ||||
-rw-r--r-- | include/modules/chanserv.h | 141 |
2 files changed, 68 insertions, 145 deletions
diff --git a/include/modules.h b/include/modules.h index 5daaed613..87051704b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -19,37 +19,62 @@ #include "logger.h" #include "extensible.h" +class ModuleDef; + +struct AnopeModule +{ + ModuleDef* (*init)(); + void (*fini)(ModuleDef *); +}; + +class ModuleDef +{ + std::vector<Anope::string> dependencies; + + public: + virtual ~ModuleDef() = default; + virtual Module *Create(const Anope::string &modname, const Anope::string &creator) anope_abstract; + virtual void Destroy(Module *) anope_abstract; + virtual void BuildModuleInfo() anope_abstract; + + void Depends(const Anope::string &modname); + const std::vector<Anope::string> &GetDependencies(); +}; + +template<class ModuleClass> void ModuleInfo(ModuleDef *moddef) { } + /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. - * It defines the class factory and external AnopeInit and AnopeFini functions. */ -#ifdef _WIN32 -# define MODULE_INIT(x) \ - extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \ - extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ +#define MODULE_INIT(ModuleClass) \ + class ModuleClass ## ModuleDef : public ModuleDef \ { \ - return new x(modname, creator); \ - } \ - BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \ + Module *Create(const Anope::string &modname, const Anope::string &creator) override \ + { \ + return new ModuleClass(modname, creator); \ + } \ + void Destroy(Module *module) override \ + { \ + delete module; \ + } \ + void BuildModuleInfo() override \ + { \ + ModuleInfo<ModuleClass>(this); \ + } \ + }; \ + static ModuleDef *CreateModuleDef() \ { \ - return TRUE; \ + return new ModuleClass ## ModuleDef(); \ } \ - extern "C" DllExport void AnopeFini(x *); \ - extern "C" void AnopeFini(x *m) \ - { \ - delete m; \ - } -#else -# define MODULE_INIT(x) \ - extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ + static void DeleteModuleDef(ModuleDef *def) \ { \ - return new x(modname, creator); \ + delete def; \ } \ - extern "C" DllExport void AnopeFini(x *m) \ + extern "C" DllExport struct AnopeModule AnopeMod = \ { \ - delete m; \ - } -#endif + CreateModuleDef, \ + DeleteModuleDef \ + }; enum ModuleReturn { @@ -145,6 +170,9 @@ class CoreExport Module : public Extensible */ void *handle; + ModuleDef *def = nullptr; + AnopeModule *module = nullptr; + /** Time this module was created */ time_t created; diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h index a6f741c1b..f0c396d39 100644 --- a/include/modules/chanserv.h +++ b/include/modules/chanserv.h @@ -141,11 +141,6 @@ namespace ChanServ virtual Privilege *FindPrivilege(const Anope::string &name) anope_abstract; virtual std::vector<Privilege> &GetPrivileges() anope_abstract; virtual void ClearPrivileges() anope_abstract; - - //XXX - typedef std::multimap<ChanAccess *, ChanAccess *> Set; - typedef std::pair<Set, Set> Path; - virtual bool Matches(ChanAccess *, const User *u, NickServ::Account *acc, Path &p) anope_abstract; }; static ServiceReference<ChanServService> service("ChanServService", "ChanServ"); @@ -377,36 +372,33 @@ namespace ChanServ ChanAccess(Serialize::TypeBase *type) : Serialize::Object(type) { } ChanAccess(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } - inline Channel *GetChannel(); - inline void SetChannel(Channel *ci); + virtual Channel *GetChannel() anope_abstract; + virtual void SetChannel(Channel *ci) anope_abstract; - inline Anope::string GetCreator(); - inline void SetCreator(const Anope::string &c); + virtual Anope::string GetCreator() anope_abstract; + virtual void SetCreator(const Anope::string &c) anope_abstract; - inline time_t GetLastSeen(); - inline void SetLastSeen(const time_t &t); + virtual time_t GetLastSeen() anope_abstract; + virtual void SetLastSeen(const time_t &t) anope_abstract; - inline time_t GetCreated(); - inline void SetCreated(const time_t &t); + virtual time_t GetCreated() anope_abstract; + virtual void SetCreated(const time_t &t) anope_abstract; - inline Anope::string GetMask(); - inline void SetMask(const Anope::string &); + virtual Anope::string GetMask() anope_abstract; + virtual void SetMask(const Anope::string &) anope_abstract; - inline Serialize::Object *GetObj(); - inline void SetObj(Serialize::Object *); + virtual Serialize::Object *GetObj() anope_abstract; + virtual void SetObj(Serialize::Object *) anope_abstract; - inline Anope::string Mask(); - inline NickServ::Account *GetAccount(); + virtual Anope::string Mask() anope_abstract; + virtual NickServ::Account *GetAccount() anope_abstract; /** Check if this access entry matches the given user or account * @param u The user - * @param nc The account + * @param acc The account * @param p The path to the access object which matches will be put here */ - virtual bool Matches(const User *u, NickServ::Account *acc, Path &p) - { - return service->Matches(this, u, acc, p); - } + virtual bool Matches(const User *u, NickServ::Account *acc, Path &p) anope_abstract; /** Check if this access entry has the given privilege. * @param name The privilege name @@ -425,7 +417,7 @@ namespace ChanServ virtual void AccessUnserialize(const Anope::string &data) anope_abstract; /* Comparison operators to other Access entries */ - virtual bool operator>(ChanAccess &other) + bool operator>(ChanAccess &other) { const std::vector<Privilege> &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -442,7 +434,7 @@ namespace ChanServ return false; } - virtual bool operator<(ChanAccess &other) + bool operator<(ChanAccess &other) { const std::vector<Privilege> &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -470,103 +462,6 @@ namespace ChanServ } }; - class ChanAccessType : public Serialize::AbstractType - { - public: - Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci; - Serialize::Field<ChanServ::ChanAccess, Anope::string> mask; - Serialize::ObjectField<ChanServ::ChanAccess, Serialize::Object *> obj; - Serialize::Field<ChanServ::ChanAccess, Anope::string> creator; - Serialize::Field<ChanServ::ChanAccess, time_t> last_seen; - Serialize::Field<ChanServ::ChanAccess, time_t> created; - - ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name) - , ci(this, "ci", true) - , mask(this, "mask") - , obj(this, "obj", true) - , creator(this, "creator") - , last_seen(this, "last_seen") - , created(this, "created") - { - } - }; - - ChanServ::Channel *ChanAccess::GetChannel() - { - return Get(&ChanAccessType::ci); - } - - void ChanAccess::SetChannel(ChanServ::Channel *ci) - { - Object::Set(&ChanAccessType::ci, ci); - } - - Anope::string ChanAccess::GetCreator() - { - return Get(&ChanAccessType::creator); - } - - void ChanAccess::SetCreator(const Anope::string &c) - { - Object::Set(&ChanAccessType::creator, c); - } - - time_t ChanAccess::GetLastSeen() - { - return Get(&ChanAccessType::last_seen); - } - - void ChanAccess::SetLastSeen(const time_t &t) - { - Object::Set(&ChanAccessType::last_seen, t); - } - - time_t ChanAccess::GetCreated() - { - return Get(&ChanAccessType::created); - } - - void ChanAccess::SetCreated(const time_t &t) - { - Object::Set(&ChanAccessType::created, t); - } - - Anope::string ChanAccess::GetMask() - { - return Get(&ChanAccessType::mask); - } - - void ChanAccess::SetMask(const Anope::string &n) - { - Object::Set(&ChanAccessType::mask, n); - } - - Serialize::Object *ChanAccess::GetObj() - { - return Get(&ChanAccessType::obj); - } - - void ChanAccess::SetObj(Serialize::Object *o) - { - Object::Set(&ChanAccessType::obj, o); - } - - Anope::string ChanAccess::Mask() - { - if (NickServ::Account *acc = GetAccount()) - return acc->GetDisplay(); - - return GetMask(); - } - - NickServ::Account *ChanAccess::GetAccount() - { - if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account) - return nullptr; - - return anope_dynamic_static_cast<NickServ::Account *>(GetObj()); - } - static Serialize::TypeReference<ChanAccess> chanaccess("ChanAccess"); /* A group of access entries. This is used commonly, for example with ChanServ::Channel::AccessFor, |