From e80a1296a096ff2c495b3cd2a3913d5e5f6ec450 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 14 Oct 2009 18:39:38 +0000 Subject: Move static map of extensions into ServerInstance, add const-correctness git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11873 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/extensible.h | 52 ++++++++++++------------- include/inspircd.h | 2 + src/base.cpp | 69 +++++++++++++++++---------------- src/commands/cmd_who.cpp | 8 +++- src/inspircd.cpp | 4 +- src/modules.cpp | 3 +- src/modules/account.h | 7 ++++ src/modules/m_antibear.cpp | 2 +- src/modules/m_banredirect.cpp | 2 +- src/modules/m_blockamsg.cpp | 2 +- src/modules/m_callerid.cpp | 4 +- src/modules/m_cap.cpp | 2 +- src/modules/m_cap.h | 2 +- src/modules/m_cgiirc.cpp | 8 ++-- src/modules/m_check.cpp | 8 ++-- src/modules/m_cloaking.cpp | 2 +- src/modules/m_customtitle.cpp | 2 +- src/modules/m_dccallow.cpp | 2 +- src/modules/m_delaymsg.cpp | 2 +- src/modules/m_joinflood.cpp | 2 +- src/modules/m_kicknorejoin.cpp | 2 +- src/modules/m_messageflood.cpp | 2 +- src/modules/m_nickflood.cpp | 2 +- src/modules/m_nicklock.cpp | 2 +- src/modules/m_regonlycreate.cpp | 30 +++++++------- src/modules/m_sasl.cpp | 2 +- src/modules/m_services_account.cpp | 4 +- src/modules/m_spanningtree/metadata.cpp | 5 +-- src/modules/m_spanningtree/netburst.cpp | 16 +++----- src/modules/m_sslinfo.cpp | 6 +-- src/modules/m_swhois.cpp | 2 +- src/modules/m_watch.cpp | 2 +- src/modules/u_listmode.h | 2 +- 33 files changed, 134 insertions(+), 128 deletions(-) diff --git a/include/extensible.h b/include/extensible.h index 3e6bd4c99..ff7bce477 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -28,7 +28,7 @@ class CoreExport ExtensionItem * @param container The object containing this item * @param item The item itself */ - virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) = 0; + virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const = 0; /** Convert the string form back into an item * @param format The format to serialize from (not FORMAT_USER) * @param container The object that this item applies to @@ -40,16 +40,13 @@ class CoreExport ExtensionItem protected: /** Get the item from the internal map */ - void* get_raw(const Extensible* container); + void* get_raw(const Extensible* container) const; /** Set the item in the internal map; returns old value */ void* set_raw(Extensible* container, void* value); /** Remove the item from the internal map; returns old value */ void* unset_raw(Extensible* container); }; -/** A private data store for an Extensible class */ -CoreExport typedef std::map ExtensibleStore; - /** class Extensible is the parent class of many classes such as User and Channel. * class Extensible implements a system which allows modules to 'extend' the class by attaching data within * a map associated with the object. In this way modules can store their own custom information within user @@ -59,34 +56,33 @@ CoreExport typedef std::map ExtensibleStore; */ class CoreExport Extensible : public classbase { + public: + typedef std::map ExtensibleStore; + + // Friend access for the protected getter/setter + friend class ExtensionItem; + private: /** Private data store. * Holds all extensible metadata for the class. */ ExtensibleStore extensions; - typedef std::map ExtensibleTypes; - static ExtensibleTypes extension_types; public: /** * Get the extension items for iteraton (i.e. for metadata sync during netburst) */ inline const ExtensibleStore& GetExtList() const { return extensions; } - static inline const ExtensibleTypes& GetTypeList() { return extension_types; } - static inline ExtensionItem* GetItem(const std::string& name) - { - ExtensibleTypes::iterator i = extension_types.find(name); - if (i == extension_types.end()) - return NULL; - return i->second; - } virtual ~Extensible(); - - static bool Register(ExtensionItem* item); - static std::vector BeginUnregister(Module* module); void doUnhookExtensions(const std::vector& toRemove); +}; - // Friend access for the protected getter/setter - friend class ExtensionItem; +class CoreExport ExtensionManager +{ + std::map types; + public: + void Register(ExtensionItem* item); + void BeginUnregister(Module* module, std::vector& list); + ExtensionItem* GetItem(const std::string& name); }; /** Base class for items that are NOT synchronized between servers */ @@ -95,7 +91,7 @@ class CoreExport LocalExtItem : public ExtensionItem public: LocalExtItem(const std::string& key, Module* owner); virtual ~LocalExtItem(); - virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item); + virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const; virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value); virtual void free(void* item) = 0; }; @@ -112,12 +108,12 @@ class SimpleExtItem : public LocalExtItem { } - inline T* get(const Extensible* container) + inline T* get(const Extensible* container) const { return static_cast(get_raw(container)); } - inline T* getNew(Extensible* container) + inline T* getNew(Extensible* container) const { T* ptr = get(container); if (!ptr) @@ -158,7 +154,7 @@ class CoreExport LocalStringExt : public SimpleExtItem public: LocalStringExt(const std::string& key, Module* owner); virtual ~LocalStringExt(); - std::string serialize(SerializeFormat format, const Extensible* container, void* item); + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const; }; class CoreExport LocalIntExt : public LocalExtItem @@ -166,8 +162,8 @@ class CoreExport LocalIntExt : public LocalExtItem public: LocalIntExt(const std::string& key, Module* owner); virtual ~LocalIntExt(); - std::string serialize(SerializeFormat format, const Extensible* container, void* item); - intptr_t get(const Extensible* container); + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const; + intptr_t get(const Extensible* container) const; intptr_t set(Extensible* container, intptr_t value); void free(void* item); }; @@ -177,8 +173,8 @@ class CoreExport StringExtItem : public ExtensionItem public: StringExtItem(const std::string& key, Module* owner); virtual ~StringExtItem(); - std::string* get(const Extensible* container); - std::string serialize(SerializeFormat format, const Extensible* container, void* item); + std::string* get(const Extensible* container) const; + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const; void unserialize(SerializeFormat format, Extensible* container, const std::string& value); void set(Extensible* container, const std::string& value); void unset(Extensible* container); diff --git a/include/inspircd.h b/include/inspircd.h index 700624892..df80ba4bf 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -429,6 +429,8 @@ class CoreExport InspIRCd : public classbase */ std::string ConfigFileName; + ExtensionManager Extensions; + /** Mode handler, handles mode setting and removal */ ModeParser* Modes; diff --git a/src/base.cpp b/src/base.cpp index 930792854..1b01da707 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -18,10 +18,6 @@ #include #include "inspircd.h" -const int bitfields[] = {1,2,4,8,16,32,64,128}; -const int inverted_bitfields[] = {~1,~2,~4,~8,~16,~32,~64,~128}; -std::map Extensible::extension_types; - classbase::classbase() { } @@ -56,9 +52,10 @@ ExtensionItem::~ExtensionItem() { } -void* ExtensionItem::get_raw(const Extensible* container) +void* ExtensionItem::get_raw(const Extensible* container) const { - ExtensibleStore::const_iterator i = container->extensions.find(key); + Extensible::ExtensibleStore::const_iterator i = + container->extensions.find(const_cast(this)); if (i == container->extensions.end()) return NULL; return i->second; @@ -66,8 +63,8 @@ void* ExtensionItem::get_raw(const Extensible* container) void* ExtensionItem::set_raw(Extensible* container, void* value) { - std::pair rv = - container->extensions.insert(std::make_pair(key, value)); + std::pair rv = + container->extensions.insert(std::make_pair(this, value)); if (rv.second) { return NULL; @@ -82,7 +79,7 @@ void* ExtensionItem::set_raw(Extensible* container, void* value) void* ExtensionItem::unset_raw(Extensible* container) { - ExtensibleStore::iterator i = container->extensions.find(key); + Extensible::ExtensibleStore::iterator i = container->extensions.find(this); if (i == container->extensions.end()) return NULL; void* rv = i->second; @@ -90,35 +87,43 @@ void* ExtensionItem::unset_raw(Extensible* container) return rv; } -bool Extensible::Register(ExtensionItem* item) +void ExtensionManager::Register(ExtensionItem* item) { - return Extensible::extension_types.insert(std::make_pair(item->key, item)).second; + types.insert(std::make_pair(item->key, item)); } -std::vector Extensible::BeginUnregister(Module* module) +void ExtensionManager::BeginUnregister(Module* module, std::vector& list) { - std::vector rv; - ExtensibleTypes::iterator i = extension_types.begin(); - while (i != extension_types.end()) + std::map::iterator i = types.begin(); + while (i != types.end()) { - ExtensibleTypes::iterator c = i++; - if (c->second->owner == module) + std::map::iterator me = i++; + ExtensionItem* item = me->second; + if (item->owner == module) { - rv.push_back(c->second); - extension_types.erase(c); + list.push_back(item); + types.erase(me); } } - return rv; +} + +ExtensionItem* ExtensionManager::GetItem(const std::string& name) +{ + std::map::iterator i = types.find(name); + if (i == types.end()) + return NULL; + return i->second; } void Extensible::doUnhookExtensions(const std::vector& toRemove) { - for(std::vector::const_iterator i = toRemove.begin(); i != toRemove.end(); i++) + for(std::vector::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) { - ExtensibleStore::iterator e = extensions.find((**i).key); + ExtensionItem* item = *i; + ExtensibleStore::iterator e = extensions.find(item); if (e != extensions.end()) { - (**i).free(e->second); + item->free(e->second); extensions.erase(e); } } @@ -128,11 +133,7 @@ Extensible::~Extensible() { for(ExtensibleStore::iterator i = extensions.begin(); i != extensions.end(); ++i) { - ExtensionItem* type = GetItem(i->first); - if (type) - type->free(i->second); - else if (ServerInstance && ServerInstance->Logs) - ServerInstance->Logs->Log("BASE", ERROR, "Extension type %s is not registered", i->first.c_str()); + i->first->free(i->second); } } @@ -144,7 +145,7 @@ LocalExtItem::~LocalExtItem() { } -std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) +std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const { return ""; } @@ -160,7 +161,7 @@ LocalStringExt::~LocalStringExt() { } -std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) +std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) const { if (item && format == FORMAT_USER) return *static_cast(item); @@ -175,14 +176,14 @@ LocalIntExt::~LocalIntExt() { } -std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) +std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) const { if (format != FORMAT_USER) return ""; return ConvToStr(reinterpret_cast(item)); } -intptr_t LocalIntExt::get(const Extensible* container) +intptr_t LocalIntExt::get(const Extensible* container) const { return reinterpret_cast(get_raw(container)); } @@ -207,12 +208,12 @@ StringExtItem::~StringExtItem() { } -std::string* StringExtItem::get(const Extensible* container) +std::string* StringExtItem::get(const Extensible* container) const { return static_cast(get_raw(container)); } -std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) +std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const { return item ? *static_cast(item) : ""; } diff --git a/src/commands/cmd_who.cpp b/src/commands/cmd_who.cpp index 49fb26a2f..a0eeaac3d 100644 --- a/src/commands/cmd_who.cpp +++ b/src/commands/cmd_who.cpp @@ -105,7 +105,13 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) * -- w00t */ if (opt_metadata) - match = user->GetExtList().find(matchtext) != user->GetExtList().end(); + { + match = false; + const Extensible::ExtensibleStore& list = user->GetExtList(); + for(Extensible::ExtensibleStore::const_iterator i = list.begin(); i != list.end(); ++i) + if (InspIRCd::Match(i->first->key, matchtext)) + match = true; + } else if (opt_realname) match = InspIRCd::Match(user->fullname, matchtext); else if (opt_showrealhost) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index b8b51d2cd..a1273d651 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -328,8 +328,8 @@ InspIRCd::InspIRCd(int argc, char** argv) : ServerInstance = this; - Extensible::Register(&NICKForced); - Extensible::Register(&OperQuit); + Extensions.Register(&NICKForced); + Extensions.Register(&OperQuit); FailedPortList pl; int do_version = 0, do_nofork = 0, do_debug = 0, diff --git a/src/modules.cpp b/src/modules.cpp index 71363ae9d..8c0fccba6 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -451,7 +451,8 @@ bool ModuleManager::Unload(const char* filename) return false; } - std::vector items = Extensible::BeginUnregister(modfind->second); + std::vector items; + ServerInstance->Extensions.BeginUnregister(modfind->second, items); /* Give the module a chance to tidy out all its metadata */ for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) { diff --git a/src/modules/account.h b/src/modules/account.h index 9182d7ca6..a5cc49591 100644 --- a/src/modules/account.h +++ b/src/modules/account.h @@ -28,4 +28,11 @@ class AccountEvent : public Event } }; +typedef StringExtItem AccountExtItem; + +inline const AccountExtItem* GetAccountExtItem() +{ + return static_cast(ServerInstance->Extensions.GetItem("accountname")); +} + #endif diff --git a/src/modules/m_antibear.cpp b/src/modules/m_antibear.cpp index 5f53b5fbb..b7a6f0663 100644 --- a/src/modules/m_antibear.cpp +++ b/src/modules/m_antibear.cpp @@ -22,7 +22,7 @@ class ModuleAntiBear : public Module public: ModuleAntiBear() : bearExt("antibear_timewait", this) { - Extensible::Register(&bearExt); + ServerInstance->Extensions.Register(&bearExt); Implementation eventlist[] = { I_OnUserRegister, I_OnPreCommand }; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 540155b81..a7b94b23e 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -212,7 +212,7 @@ class ModuleBanRedirect : public Module OnRehash(NULL); - Extensible::Register(&re.extItem); + ServerInstance->Extensions.Register(&re.extItem); Implementation list[] = { I_OnRehash, I_OnUserPreJoin, I_OnChannelDelete }; ServerInstance->Modules->Attach(list, this, 3); } diff --git a/src/modules/m_blockamsg.cpp b/src/modules/m_blockamsg.cpp index 7c4d63419..ffdbb65c0 100644 --- a/src/modules/m_blockamsg.cpp +++ b/src/modules/m_blockamsg.cpp @@ -48,7 +48,7 @@ class ModuleBlockAmsg : public Module ModuleBlockAmsg() : blockamsg("blockamsg", this) { this->OnRehash(NULL); - Extensible::Register(&blockamsg); + ServerInstance->Extensions.Register(&blockamsg); Implementation eventlist[] = { I_OnRehash, I_OnPreCommand }; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index ae3ec1450..94dd009c3 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -78,7 +78,7 @@ struct CallerIDExtInfo : public ExtensionItem { } - std::string serialize(SerializeFormat format, const Extensible* container, void* item) + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const { callerid_data* dat = static_cast(item); return dat->ToString(format); @@ -350,7 +350,7 @@ public: throw ModuleException("Could not add usermode +g"); ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.extInfo); + ServerInstance->Extensions.Register(&cmd.extInfo); Implementation eventlist[] = { I_OnRehash, I_OnUserPreNick, I_OnUserQuit, I_On005Numeric, I_OnUserPreNotice, I_OnUserPreMessage }; ServerInstance->Modules->Attach(eventlist, this, 6); diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index 3373f7c3f..2c7e58e6a 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -136,7 +136,7 @@ class ModuleCAP : public Module : cmd(this) { ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.reghold); + ServerInstance->Extensions.Register(&cmd.reghold); Implementation eventlist[] = { I_OnCheckReady }; ServerInstance->Modules->Attach(eventlist, this, 1); diff --git a/src/modules/m_cap.h b/src/modules/m_cap.h index 809b0f4cf..f880ab924 100644 --- a/src/modules/m_cap.h +++ b/src/modules/m_cap.h @@ -35,7 +35,7 @@ class GenericCap const std::string cap; GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap) { - Extensible::Register(&ext); + ServerInstance->Extensions.Register(&ext); } void HandleEvent(Event& ev) diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index d36a1d92a..a2c8e1c0e 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -150,10 +150,10 @@ public: { OnRehash(NULL); ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.realhost); - Extensible::Register(&cmd.realip); - Extensible::Register(&cmd.webirc_hostname); - Extensible::Register(&cmd.webirc_ip); + ServerInstance->Extensions.Register(&cmd.realhost); + ServerInstance->Extensions.Register(&cmd.realip); + ServerInstance->Extensions.Register(&cmd.webirc_hostname); + ServerInstance->Extensions.Register(&cmd.webirc_ip); Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnSyncUser, I_OnDecodeMetaData, I_OnUserDisconnect, I_OnUserConnect }; ServerInstance->Modules->Attach(eventlist, this, 6); diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 309499ff5..729667fa8 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -38,14 +38,12 @@ class CommandCheck : public Command std::stringstream dumpkeys; for(ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++) { - ExtensionItem* item = Extensible::GetItem(i->first); - std::string value; - if (item) - value = item->serialize(FORMAT_USER, ext, i->second); + ExtensionItem* item = i->first; + std::string value = item->serialize(FORMAT_USER, ext, i->second); if (value.empty()) dumpkeys << " " << i->first; else - ServerInstance->DumpText(user, checkstr + " meta:" + i->first + " " + value); + ServerInstance->DumpText(user, checkstr + " meta:" + item->key + " " + value); } if (!dumpkeys.str().empty()) ServerInstance->DumpText(user,checkstr + " metadata", dumpkeys); diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index 2dfc449ae..0aee306a3 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -133,7 +133,7 @@ class ModuleCloaking : public Module throw ModuleException("Could not add new modes!"); ServerInstance->Modules->UseInterface("HashRequest"); - Extensible::Register(&cu.ext); + ServerInstance->Extensions.Register(&cu.ext); Implementation eventlist[] = { I_OnRehash, I_OnCheckBan, I_OnUserConnect }; ServerInstance->Modules->Attach(eventlist, this, 3); diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 9ff250cd6..c89535a3c 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -89,7 +89,7 @@ class ModuleCustomTitle : public Module ModuleCustomTitle() : cmd(this) { ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.ctitle); + ServerInstance->Extensions.Register(&cmd.ctitle); ServerInstance->Modules->Attach(I_OnWhoisLine, this); } diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index 10a8d9310..b66fa436e 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -244,7 +244,7 @@ class ModuleDCCAllow : public Module { Conf = new ConfigReader; ext = new SimpleExtItem("dccallow", this); - Extensible::Register(ext); + ServerInstance->Extensions.Register(ext); ServerInstance->AddCommand(&cmd); ReadFileConf(); Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserQuit, I_OnUserPreNick, I_OnRehash }; diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index 75a1df19a..7489f6dfa 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -58,7 +58,7 @@ class ModuleDelayMsg : public Module { if (!ServerInstance->Modes->AddMode(&djm)) throw ModuleException("Could not add new modes!"); - Extensible::Register(&djm.jointime); + ServerInstance->Extensions.Register(&djm.jointime); Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage}; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index 2d15fee68..8dcd99405 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -200,7 +200,7 @@ class ModuleJoinFlood : public Module if (!ServerInstance->Modes->AddMode(&jf)) throw ModuleException("Could not add new modes!"); - Extensible::Register(&jf.ext); + ServerInstance->Extensions.Register(&jf.ext); Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreJoin, I_OnUserJoin }; ServerInstance->Modules->Attach(eventlist, this, 3); } diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 5a8233a8f..9d5fe3b62 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -109,7 +109,7 @@ public: { if (!ServerInstance->Modes->AddMode(&kr)) throw ModuleException("Could not add new modes!"); - Extensible::Register(&kr.ext); + ServerInstance->Extensions.Register(&kr.ext); Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick }; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index bf79babb2..96f504492 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -200,7 +200,7 @@ class ModuleMsgFlood : public Module { if (!ServerInstance->Modes->AddMode(&mf)) throw ModuleException("Could not add new modes!"); - Extensible::Register(&mf.ext); + ServerInstance->Extensions.Register(&mf.ext); Implementation eventlist[] = { I_OnUserPreNotice, I_OnUserPreMessage }; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index f6a808ffd..7f67b8d08 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -200,7 +200,7 @@ class ModuleNickFlood : public Module { if (!ServerInstance->Modes->AddMode(&nf)) throw ModuleException("Could not add new modes!"); - Extensible::Register(&nf.ext); + ServerInstance->Extensions.Register(&nf.ext); Implementation eventlist[] = { I_OnUserPreNick, I_OnUserPostNick }; ServerInstance->Modules->Attach(eventlist, this, 2); } diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index 0ca0a9bac..bfbda003f 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -156,7 +156,7 @@ class ModuleNickLock : public Module { ServerInstance->AddCommand(&cmd1); ServerInstance->AddCommand(&cmd2); - Extensible::Register(&locked); + ServerInstance->Extensions.Register(&locked); ServerInstance->Modules->Attach(I_OnUserPreNick, this); } diff --git a/src/modules/m_regonlycreate.cpp b/src/modules/m_regonlycreate.cpp index 3354c1132..a25ba8edc 100644 --- a/src/modules/m_regonlycreate.cpp +++ b/src/modules/m_regonlycreate.cpp @@ -12,20 +12,20 @@ */ #include "inspircd.h" +#include "account.h" -/* $ModDesc: Prevents users who's nicks are not registered from creating new channels */ +/* $ModDesc: Prevents users whose nicks are not registered from creating new channels */ class ModuleRegOnlyCreate : public Module { public: ModuleRegOnlyCreate() - { + { Implementation eventlist[] = { I_OnUserPreJoin }; ServerInstance->Modules->Attach(eventlist, this, 1); } - - virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) + ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) { if (chan) return MOD_RES_PASSTHRU; @@ -33,23 +33,25 @@ class ModuleRegOnlyCreate : public Module if (IS_OPER(user)) return MOD_RES_PASSTHRU; - if (user->GetExtList().find("accountname") == user->GetExtList().end() && !user->IsModeSet('r')) - { - // XXX. there may be a better numeric for this.. - user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have a registered nickname to create a new channel", user->nick.c_str(), cname); - return MOD_RES_DENY; - } + if (user->IsModeSet('r')) + return MOD_RES_PASSTHRU; + + const AccountExtItem* ext = GetAccountExtItem(); + if (ext && ext->get(user)) + return MOD_RES_PASSTHRU; - return MOD_RES_PASSTHRU; + // XXX. there may be a better numeric for this.. + user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have a registered nickname to create a new channel", user->nick.c_str(), cname); + return MOD_RES_DENY; } - virtual ~ModuleRegOnlyCreate() + ~ModuleRegOnlyCreate() { } - virtual Version GetVersion() + Version GetVersion() { - return Version("Prevents users who's nicks are not registered from creating new channels", VF_VENDOR, API_VERSION); + return Version("Prevents users whose nicks are not registered from creating new channels", VF_VENDOR); } }; diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 938449bbb..42d908467 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -232,7 +232,7 @@ class ModuleSASL : public Module ServerInstance->AddCommand(&auth); ServerInstance->AddCommand(&sasl); - Extensible::Register(&authExt); + ServerInstance->Extensions.Register(&authExt); if (!ServerInstance->Modules->Find("m_services_account.so") || !ServerInstance->Modules->Find("m_cap.so")) ServerInstance->Logs->Log("m_sasl", DEFAULT, "WARNING: m_services_account.so and m_cap.so are not loaded! m_sasl.so will NOT function correctly until these two modules are loaded!"); } diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 5987b70c9..a040e77e5 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -104,7 +104,7 @@ class ModuleServicesAccount : public Module AUser_R m3; Channel_r m4; User_r m5; - StringExtItem accountname; + AccountExtItem accountname; public: ModuleServicesAccount() : m1(this), m2(this), m3(this), m4(this), m5(this), accountname("accountname", this) @@ -115,7 +115,7 @@ class ModuleServicesAccount : public Module !ServerInstance->Modes->AddMode(&m5)) throw ModuleException("Some other module has claimed our modes!"); - Extensible::Register(&accountname); + ServerInstance->Extensions.Register(&accountname); Implementation eventlist[] = { I_OnWhois, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin, I_OnCheckBan, I_OnSyncUser, I_OnUserQuit, I_OnDecodeMetaData, I_On005Numeric, I_OnUserPostNick }; diff --git a/src/modules/m_spanningtree/metadata.cpp b/src/modules/m_spanningtree/metadata.cpp index ee26f0c73..4e87dae00 100644 --- a/src/modules/m_spanningtree/metadata.cpp +++ b/src/modules/m_spanningtree/metadata.cpp @@ -18,9 +18,6 @@ #include "treeserver.h" #include "utils.h" -/* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */ - - bool TreeSocket::MetaData(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 2) @@ -28,7 +25,7 @@ bool TreeSocket::MetaData(const std::string &prefix, parameterlist ¶ms) else if (params.size() < 3) params.push_back(""); TreeServer* ServerSource = Utils->FindServer(prefix); - ExtensionItem* item = Extensible::GetItem(params[1]); + ExtensionItem* item = ServerInstance->Extensions.GetItem(params[1]); if (ServerSource) { if (params[0] == "*") diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index b8d8c93ee..5f47c690b 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -222,12 +222,10 @@ void TreeSocket::SendChannelModes(TreeServer* Current) for(ExtensibleStore::const_iterator i = c->second->GetExtList().begin(); i != c->second->GetExtList().end(); i++) { - ExtensionItem* item = Extensible::GetItem(i->first); - std::string value; - if (item) - value = item->serialize(FORMAT_NETWORK, c->second, i->second); + ExtensionItem* item = i->first; + std::string value = item->serialize(FORMAT_NETWORK, c->second, i->second); if (!value.empty()) - Utils->Creator->ProtoSendMetaData(this, c->second, i->first, value); + Utils->Creator->ProtoSendMetaData(this, c->second, item->key, value); } FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(c->second,Utils->Creator,this)); @@ -273,12 +271,10 @@ void TreeSocket::SendUsers(TreeServer* Current) for(ExtensibleStore::const_iterator i = u->second->GetExtList().begin(); i != u->second->GetExtList().end(); i++) { - ExtensionItem* item = Extensible::GetItem(i->first); - std::string value; - if (item) - value = item->serialize(FORMAT_NETWORK, u->second, i->second); + ExtensionItem* item = i->first; + std::string value = item->serialize(FORMAT_NETWORK, u->second, i->second); if (!value.empty()) - Utils->Creator->ProtoSendMetaData(this, u->second, i->first, value); + Utils->Creator->ProtoSendMetaData(this, u->second, item->key, value); } FOREACH_MOD(I_OnSyncUser,OnSyncUser(u->second,Utils->Creator,this)); diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index a1178f917..31a209d4e 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -19,7 +19,7 @@ class SSLCertExt : public ExtensionItem { public: SSLCertExt(Module* parent) : ExtensionItem("ssl_cert", parent) {} - ssl_cert* get(const Extensible* item) + ssl_cert* get(const Extensible* item) const { return static_cast(get_raw(item)); } @@ -29,7 +29,7 @@ class SSLCertExt : public ExtensionItem { delete old; } - std::string serialize(SerializeFormat format, const Extensible* container, void* item) + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const { return static_cast(item)->GetMetaLine(); } @@ -121,7 +121,7 @@ class ModuleSSLInfo : public Module { ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.CertExt); + ServerInstance->Extensions.Register(&cmd.CertExt); Implementation eventlist[] = { I_OnWhois, I_OnPreCommand }; ServerInstance->Modules->Attach(eventlist, this, 2); diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp index 6d74e9d39..a15d81aec 100644 --- a/src/modules/m_swhois.cpp +++ b/src/modules/m_swhois.cpp @@ -24,7 +24,7 @@ class CommandSwhois : public Command CommandSwhois(Module* Creator) : Command(Creator,"SWHOIS", 2,2), swhois("swhois", Creator) { flags_needed = 'o'; syntax = " :"; - Extensible::Register(&swhois); + ServerInstance->Extensions.Register(&swhois); TRANSLATE3(TR_NICK, TR_TEXT, TR_END); } diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index 9030c1788..1d2073972 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -374,7 +374,7 @@ class Modulewatch : public Module whos_watching_me = new watchentries(); ServerInstance->AddCommand(&cmdw); ServerInstance->AddCommand(&sw); - Extensible::Register(&cmdw.ext); + ServerInstance->Extensions.Register(&cmdw.ext); Implementation eventlist[] = { I_OnRehash, I_OnGarbageCollect, I_OnUserQuit, I_OnPostConnect, I_OnUserPostNick, I_On005Numeric, I_OnSetAway }; ServerInstance->Modules->Attach(eventlist, this, 7); } diff --git a/src/modules/u_listmode.h b/src/modules/u_listmode.h index 981e2a369..1516b724c 100644 --- a/src/modules/u_listmode.h +++ b/src/modules/u_listmode.h @@ -95,7 +95,7 @@ class ListModeBase : public ModeHandler { list = true; this->DoRehash(); - Extensible::Register(&extItem); + ServerInstance->Extensions.Register(&extItem); } /** See mode.h -- cgit v1.2.3