summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/extensible.h50
-rw-r--r--src/base.cpp65
-rw-r--r--src/coremods/core_reloadmodule.cpp4
-rw-r--r--src/modules/m_check.cpp2
-rw-r--r--src/modules/m_httpd_stats.cpp2
-rw-r--r--src/modules/m_spanningtree/main.cpp2
-rw-r--r--src/modules/m_spanningtree/metadata.cpp4
-rw-r--r--src/modules/m_spanningtree/netburst.cpp4
8 files changed, 109 insertions, 24 deletions
diff --git a/include/extensible.h b/include/extensible.h
index e4266cb08..588f882b4 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -19,15 +19,12 @@
#pragma once
+/** DEPRECATED: use {To,From}{Human,Internal,Network} instead. */
enum SerializeFormat
{
- /** Shown to a human (does not need to be unserializable) */
FORMAT_USER,
- /** Passed internally to this process (i.e. for /RELOADMODULE) */
FORMAT_INTERNAL,
- /** Passed to other servers on the network (i.e. METADATA s2s command) */
FORMAT_NETWORK,
- /** Stored on disk (i.e. permchannel database) */
FORMAT_PERSIST
};
@@ -61,20 +58,37 @@ class CoreExport ExtensionItem : public ServiceProvider, public usecountbase
/** Destroys an instance of the ExtensionItem class. */
virtual ~ExtensionItem();
- /** Serialize this item into a string
- *
- * @param format The format to serialize to
- * @param container The object containing this item
- * @param item The item itself
+ /** Sets an ExtensionItem using a value in the internal format.
+ * @param container A container the ExtensionItem should be set on.
+ * @param value A value in the internal format.
*/
- virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const = 0;
+ virtual void FromInternal(Extensible* container, const std::string& value);
- /** 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
- * @param value The return from a serialize() call that was run elsewhere with this key
+ /** Sets an ExtensionItem using a value in the network format.
+ * @param container A container the ExtensionItem should be set on.
+ * @param value A value in the network format.
+ */
+ virtual void FromNetwork(Extensible* container, const std::string& value);
+
+ /** Gets an ExtensionItem's value in a human-readable format.
+ * @param container The container the ExtensionItem is set on.
+ * @param item The value to convert to a human-readable format.
+ * @return The value specified in \p item in a human readable format.
+ */
+ virtual std::string ToHuman(const Extensible* container, void* item) const;
+ /** Gets an ExtensionItem's value in the internal format.
+ * @param container The container the ExtensionItem is set on.
+ * @param item The value to convert to the internal format.
+ * @return The value specified in \p item in the internal format.
*/
- virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value) = 0;
+ virtual std::string ToInternal(const Extensible* container, void* item) const ;
+
+ /** Gets an ExtensionItem's value in the network format.
+ * @param container The container the ExtensionItem is set on.
+ * @param item The value to convert to the network format.
+ * @return The value specified in \p item in the network format.
+ */
+ virtual std::string ToNetwork(const Extensible* container, void* item) const;
/** Deallocates the specified ExtensionItem value.
* @param container The container that the ExtensionItem is set on.
@@ -85,6 +99,12 @@ class CoreExport ExtensionItem : public ServiceProvider, public usecountbase
/** Registers this object with the ExtensionManager. */
void RegisterService() CXX11_OVERRIDE;
+ /** DEPRECATED: use To{Human,Internal,Network} instead. */
+ DEPRECATED_METHOD(virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const);
+
+ /** DEPRECATED: use From{Internal,Network} instead. */
+ DEPRECATED_METHOD(virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value));
+
protected:
/** Retrieves the value for this ExtensionItem from the internal map.
* @param container The container that the ExtensionItem is set on.
diff --git a/src/base.cpp b/src/base.cpp
index 8749aee8e..8cb336985 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -219,6 +219,71 @@ Extensible::~Extensible()
ServerInstance->Logs->Log("CULLLIST", LOG_DEBUG, "Extensible destructor called without cull @%p", (void*)this);
}
+void ExtensionItem::FromInternal(Extensible* container, const std::string& value)
+{
+ FromNetwork(container, value);
+}
+
+void ExtensionItem::FromNetwork(Extensible* container, const std::string& value)
+{
+}
+
+std::string ExtensionItem::ToHuman(const Extensible* container, void* item) const
+{
+ // Try to use the network form by default.
+ std::string ret = ToNetwork(container, item);
+
+ // If there's no network form then fall back to the internal form.
+ if (ret.empty())
+ ret = ToInternal(container, item);
+
+ return ret;
+}
+
+std::string ExtensionItem::ToInternal(const Extensible* container, void* item) const
+{
+ return ToNetwork(container, item);
+}
+
+std::string ExtensionItem::ToNetwork(const Extensible* container, void* item) const
+{
+ return std::string();
+}
+
+std::string ExtensionItem::serialize(SerializeFormat format, const Extensible* container, void* item) const
+{
+ // Wrap the deprecated API with the new API.
+ switch (format)
+ {
+ case FORMAT_USER:
+ return ToHuman(container, item);
+ case FORMAT_INTERNAL:
+ case FORMAT_PERSIST:
+ return ToInternal(container, item);
+ case FORMAT_NETWORK:
+ return ToNetwork(container, item);
+ }
+ return "";
+}
+
+
+void ExtensionItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+{
+ // Wrap the deprecated API with the new API.
+ switch (format)
+ {
+ case FORMAT_USER:
+ break;
+ case FORMAT_INTERNAL:
+ case FORMAT_PERSIST:
+ FromInternal(container, value);
+ break;
+ case FORMAT_NETWORK:
+ FromNetwork(container, value);
+ break;
+ }
+}
+
LocalExtItem::LocalExtItem(const std::string& Key, ExtensibleType exttype, Module* mod)
: ExtensionItem(Key, exttype, mod)
{
diff --git a/src/coremods/core_reloadmodule.cpp b/src/coremods/core_reloadmodule.cpp
index ea5d40abd..06648fcb2 100644
--- a/src/coremods/core_reloadmodule.cpp
+++ b/src/coremods/core_reloadmodule.cpp
@@ -379,7 +379,7 @@ void DataKeeper::SaveExtensions(Extensible* extensible, std::vector<InstanceData
if (it == setexts.end())
continue;
- std::string value = item->serialize(FORMAT_INTERNAL, extensible, it->second);
+ std::string value = item->ToInternal(extensible, it->second);
// If the serialized value is empty the extension won't be saved and restored
if (!value.empty())
extdata.push_back(InstanceData(index, value));
@@ -597,7 +597,7 @@ void DataKeeper::RestoreExtensions(const std::vector<InstanceData>& list, Extens
for (std::vector<InstanceData>::const_iterator i = list.begin(); i != list.end(); ++i)
{
const InstanceData& id = *i;
- handledexts[id.index].extitem->unserialize(FORMAT_INTERNAL, extensible, id.serialized);
+ handledexts[id.index].extitem->FromInternal(extensible, id.serialized);
}
}
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index abbaaab8d..404f20999 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -90,7 +90,7 @@ class CheckContext
for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); ++i)
{
ExtensionItem* item = i->first;
- std::string value = item->serialize(FORMAT_USER, ext, i->second);
+ std::string value = item->ToHuman(ext, i->second);
if (!value.empty())
Write("meta:" + item->name, value);
else if (!item->name.empty())
diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp
index 3be8ec970..bb4080fd2 100644
--- a/src/modules/m_httpd_stats.cpp
+++ b/src/modules/m_httpd_stats.cpp
@@ -86,7 +86,7 @@ namespace Stats
for (Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++)
{
ExtensionItem* item = i->first;
- std::string value = item->serialize(FORMAT_USER, ext, i->second);
+ std::string value = item->ToHuman(ext, i->second);
if (!value.empty())
data << "<meta name=\"" << item->name << "\">" << Sanitize(value) << "</meta>";
else if (!item->name.empty())
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 484d72e6d..43417bc3c 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -486,7 +486,7 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
for(Extensible::ExtensibleStore::const_iterator i = user->GetExtList().begin(); i != user->GetExtList().end(); i++)
{
ExtensionItem* item = i->first;
- std::string value = item->serialize(FORMAT_NETWORK, user, i->second);
+ std::string value = item->ToNetwork(user, i->second);
if (!value.empty())
ServerInstance->PI->SendMetaData(user, item->name, value);
}
diff --git a/src/modules/m_spanningtree/metadata.cpp b/src/modules/m_spanningtree/metadata.cpp
index 52267c522..816d0758a 100644
--- a/src/modules/m_spanningtree/metadata.cpp
+++ b/src/modules/m_spanningtree/metadata.cpp
@@ -50,7 +50,7 @@ CmdResult CommandMetadata::Handle(User* srcuser, Params& params)
ExtensionItem* item = ServerInstance->Extensions.GetItem(params[2]);
if ((item) && (item->type == ExtensionItem::EXT_CHANNEL))
- item->unserialize(FORMAT_NETWORK, c, value);
+ item->FromNetwork(c, value);
FOREACH_MOD(OnDecodeMetaData, (c,params[2],value));
}
else
@@ -62,7 +62,7 @@ CmdResult CommandMetadata::Handle(User* srcuser, Params& params)
std::string value = params.size() < 3 ? "" : params[2];
if ((item) && (item->type == ExtensionItem::EXT_USER))
- item->unserialize(FORMAT_NETWORK, u, value);
+ item->FromNetwork(u, value);
FOREACH_MOD(OnDecodeMetaData, (u,params[1],value));
}
}
diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp
index f3f2ea7ac..6d6ada9a5 100644
--- a/src/modules/m_spanningtree/netburst.cpp
+++ b/src/modules/m_spanningtree/netburst.cpp
@@ -259,7 +259,7 @@ void TreeSocket::SyncChannel(Channel* chan, BurstState& bs)
for (Extensible::ExtensibleStore::const_iterator i = chan->GetExtList().begin(); i != chan->GetExtList().end(); i++)
{
ExtensionItem* item = i->first;
- std::string value = item->serialize(FORMAT_NETWORK, chan, i->second);
+ std::string value = item->ToNetwork(chan, i->second);
if (!value.empty())
this->WriteLine(CommandMetadata::Builder(chan, item->name, value));
}
@@ -295,7 +295,7 @@ void TreeSocket::SendUsers(BurstState& bs)
for (Extensible::ExtensibleStore::const_iterator i = exts.begin(); i != exts.end(); ++i)
{
ExtensionItem* item = i->first;
- std::string value = item->serialize(FORMAT_NETWORK, u->second, i->second);
+ std::string value = item->ToNetwork(u->second, i->second);
if (!value.empty())
this->WriteLine(CommandMetadata::Builder(user, item->name, value));
}