diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-13 20:32:03 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-13 20:32:03 +0000 |
commit | 0ed3ef9dee2cb8f4b0c37da218a2fd1eee8c31f6 (patch) | |
tree | 933fa0ba26a0113b0404ca52796440bc297a614c /src | |
parent | d9e3bb8d4343643504ab7ee6ab943a000065cc8a (diff) |
Add SerializeFormat for easier metadata formatting
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11704 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/base.cpp | 25 | ||||
-rw-r--r-- | src/modules.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_callerid.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_check.cpp | 13 | ||||
-rw-r--r-- | src/modules/m_invisible.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.h | 1 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_sslinfo.cpp | 4 |
9 files changed, 33 insertions, 39 deletions
diff --git a/src/base.cpp b/src/base.cpp index 4d0c17077..1e4f746af 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -147,19 +147,36 @@ LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem( { } -std::string LocalExtItem::serialize(Module* requestor, const Extensible* container, void* item) +std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) { return ""; } -void LocalExtItem::unserialize(Module* requestor, Extensible* container, const std::string& value) +void LocalExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { } +LocalStringExt::LocalStringExt(const std::string& Key, Module* Owner) + : SimpleExtItem<std::string>(Key, Owner) { } + +std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) +{ + if (item && format == FORMAT_USER) + return *static_cast<std::string*>(item); + return ""; +} + LocalIntExt::LocalIntExt(const std::string& Key, Module* mod) : LocalExtItem(Key, mod) { } +std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) +{ + if (format != FORMAT_USER) + return ""; + return ConvToStr(reinterpret_cast<intptr_t>(item)); +} + intptr_t LocalIntExt::get(const Extensible* container) { return reinterpret_cast<intptr_t>(get_raw(container)); @@ -186,12 +203,12 @@ std::string* StringExtItem::get(const Extensible* container) return static_cast<std::string*>(get_raw(container)); } -std::string StringExtItem::serialize(Module* requestor, const Extensible* container, void* item) +std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) { return item ? *static_cast<std::string*>(item) : ""; } -void StringExtItem::unserialize(Module* requestor, Extensible* container, const std::string& value) +void StringExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { if (value.empty()) unset(container); diff --git a/src/modules.cpp b/src/modules.cpp index 9664e817f..32d75f60e 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -176,7 +176,6 @@ void Module::OnSyncNetwork(Module*, void*) { } void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector<std::string>&, const std::vector<TranslateType>&) { } void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { } void Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { } -std::string Module::ProtoTranslate(Extensible*) { return "?"; } void Module::OnWallops(User*, const std::string&) { } void Module::OnChangeHost(User*, const std::string&) { } void Module::OnChangeName(User*, const std::string&) { } diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index b84ee2c9c..dab0d3d43 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -56,14 +56,15 @@ class callerid_data : public classbase } } - std::string ToString(Module* proto) const + std::string ToString(SerializeFormat format) const { std::ostringstream oss; oss << lastnotify; for (std::set<User*>::const_iterator i = accepting.begin(); i != accepting.end(); ++i) { + User* u = *i; // Encode UIDs. - oss << "," << proto->ProtoTranslate(*i); + oss << "," << (format == FORMAT_USER ? u->nick : u->uuid); } oss << std::ends; return oss.str(); @@ -77,13 +78,13 @@ struct CallerIDExtInfo : public ExtensionItem { } - std::string serialize(Module* requestor, const Extensible* container, void* item) + std::string serialize(SerializeFormat format, const Extensible* container, void* item) { callerid_data* dat = static_cast<callerid_data*>(item); - return dat->ToString(requestor); + return dat->ToString(format); } - void unserialize(Module* requestor, Extensible* container, const std::string& value) + void unserialize(SerializeFormat format, Extensible* container, const std::string& value) { callerid_data* dat = new callerid_data(value); set_raw(container, dat); diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 33f950b4c..847e9d5c9 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -41,7 +41,7 @@ class CommandCheck : public Command ExtensionItem* item = Extensible::GetItem(i->first); std::string value; if (item) - value = item->serialize(creator, ext, i->second); + value = item->serialize(FORMAT_USER, ext, i->second); if (value.empty()) dumpkeys << " " << i->first; else @@ -211,17 +211,6 @@ class ModuleCheck : public Module { return Version("CHECK command, view user/channel details", VF_VENDOR|VF_OPTCOMMON); } - - std::string ProtoTranslate(Extensible* item) - { - User* u = dynamic_cast<User*>(item); - Channel* c = dynamic_cast<Channel*>(item); - if (u) - return u->nick; - if (c) - return c->name; - return "?"; - } }; MODULE_INIT(ModuleCheck) diff --git a/src/modules/m_invisible.cpp b/src/modules/m_invisible.cpp index ae54fa96b..068e6d666 100644 --- a/src/modules/m_invisible.cpp +++ b/src/modules/m_invisible.cpp @@ -53,7 +53,7 @@ class InvisibleMode : public ModeHandler snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost().c_str(), adding ? "PART" : "JOIN", (*f)->name.c_str()); std::string out = tb; - std::string n = this->ServerInstance->Modes->ModeString(dest, (*f)); + std::string n = ServerInstance->Modes->ModeString(dest, (*f)); for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++) { diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 3877daf42..ee8c82c8b 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -932,17 +932,6 @@ void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, con s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata); } -std::string ModuleSpanningTree::ProtoTranslate(Extensible* item) -{ - User* u = dynamic_cast<User*>(item); - Channel* c = dynamic_cast<Channel*>(item); - if (u) - return u->uuid; - if (c) - return c->name; - return "*"; -} - void ModuleSpanningTree::OnEvent(Event* event) { if ((event->GetEventID() == "send_encap") || (event->GetEventID() == "send_metadata") || (event->GetEventID() == "send_topic") || (event->GetEventID() == "send_mode") || (event->GetEventID() == "send_mode_explicit") || (event->GetEventID() == "send_opers") diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 1d3ec9d39..0144eb4a3 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -187,7 +187,6 @@ class ModuleSpanningTree : public Module ModResult OnSetAway(User* user, const std::string &awaymsg); void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::vector<std::string> &modeline, const std::vector<TranslateType> &translate); void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata); - std::string ProtoTranslate(Extensible* item); void OnEvent(Event* event); void OnLoadModule(Module* mod,const std::string &name); void OnUnloadModule(Module* mod,const std::string &name); diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index 3ed85ea1e..ada10e6a1 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -225,7 +225,7 @@ void TreeSocket::SendChannelModes(TreeServer* Current) ExtensionItem* item = Extensible::GetItem(i->first); std::string value; if (item) - value = item->serialize(Utils->Creator, c->second, i->second); + value = item->serialize(FORMAT_NETWORK, c->second, i->second); if (!value.empty()) Utils->Creator->ProtoSendMetaData(this, c->second, i->first, value); } @@ -276,7 +276,7 @@ void TreeSocket::SendUsers(TreeServer* Current) ExtensionItem* item = Extensible::GetItem(i->first); std::string value; if (item) - value = item->serialize(Utils->Creator, u->second, i->second); + value = item->serialize(FORMAT_NETWORK, u->second, i->second); if (!value.empty()) Utils->Creator->ProtoSendMetaData(this, u->second, i->first, value); } diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index bf02ed879..952fcf4a1 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -29,12 +29,12 @@ class SSLCertExt : public ExtensionItem { delete old; } - std::string serialize(Module* requestor, const Extensible* container, void* item) + std::string serialize(SerializeFormat format, const Extensible* container, void* item) { return static_cast<ssl_cert*>(item)->GetMetaLine(); } - void unserialize(Module* requestor, Extensible* container, const std::string& value) + void unserialize(SerializeFormat format, Extensible* container, const std::string& value) { ssl_cert* cert = new ssl_cert; set(container, cert); |