summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-08-07 19:37:27 +0100
committerPeter Powell <petpow@saberuk.com>2019-08-07 19:37:27 +0100
commit714284aa306f2912eaca0c28d779d227db62a96b (patch)
treea559faf3cfb5b986255ad8b40adf8af1a3866654 /src
parent85182d727c0d549b9cf6659ad36dec70fcf02278 (diff)
Convert all core ExtensionItem code away from {un,}serialize.
Diffstat (limited to 'src')
-rw-r--r--src/base.cpp35
-rw-r--r--src/coremods/core_channel/invite.cpp4
-rw-r--r--src/coremods/core_channel/invite.h38
-rw-r--r--src/modules/m_callerid.cpp24
-rw-r--r--src/modules/m_cap.cpp62
-rw-r--r--src/modules/m_monitor.cpp13
-rw-r--r--src/modules/m_services_account.cpp14
-rw-r--r--src/modules/m_sslinfo.cpp4
-rw-r--r--src/modules/m_topiclock.cpp12
9 files changed, 102 insertions, 104 deletions
diff --git a/src/base.cpp b/src/base.cpp
index 8cb336985..afd561ff2 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -293,15 +293,6 @@ LocalExtItem::~LocalExtItem()
{
}
-std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const
-{
- return "";
-}
-
-void LocalExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
-{
-}
-
LocalStringExt::LocalStringExt(const std::string& Key, ExtensibleType exttype, Module* Owner)
: SimpleExtItem<std::string>(Key, exttype, Owner)
{
@@ -311,17 +302,14 @@ LocalStringExt::~LocalStringExt()
{
}
-std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) const
+std::string LocalStringExt::ToInternal(const Extensible* container, void* item) const
{
- if ((item) && (format != FORMAT_NETWORK))
- return *static_cast<std::string*>(item);
- return "";
+ return item ? *static_cast<std::string*>(item) : std::string();
}
-void LocalStringExt::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+void LocalStringExt::FromInternal(Extensible* container, const std::string& value)
{
- if (format != FORMAT_NETWORK)
- set(container, value);
+ set(container, value);
}
LocalIntExt::LocalIntExt(const std::string& Key, ExtensibleType exttype, Module* mod)
@@ -333,17 +321,14 @@ LocalIntExt::~LocalIntExt()
{
}
-std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) const
+std::string LocalIntExt::ToInternal(const Extensible* container, void* item) const
{
- if (format == FORMAT_NETWORK)
- return "";
return ConvToStr(reinterpret_cast<intptr_t>(item));
}
-void LocalIntExt::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+void LocalIntExt::FromInternal(Extensible* container, const std::string& value)
{
- if (format != FORMAT_NETWORK)
- set(container, ConvToNum<intptr_t>(value));
+ set(container, ConvToNum<intptr_t>(value));
}
intptr_t LocalIntExt::get(const Extensible* container) const
@@ -377,12 +362,12 @@ std::string* StringExtItem::get(const Extensible* container) const
return static_cast<std::string*>(get_raw(container));
}
-std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const
+std::string StringExtItem::ToNetwork(const Extensible* container, void* item) const
{
- return item ? *static_cast<std::string*>(item) : "";
+ return item ? *static_cast<std::string*>(item) : std::string();
}
-void StringExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+void StringExtItem::FromNetwork(Extensible* container, const std::string& value)
{
if (value.empty())
unset(container);
diff --git a/src/coremods/core_channel/invite.cpp b/src/coremods/core_channel/invite.cpp
index 51fb638f8..d96045fc4 100644
--- a/src/coremods/core_channel/invite.cpp
+++ b/src/coremods/core_channel/invite.cpp
@@ -179,12 +179,12 @@ Invite::Invite::~Invite()
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Invite::~ %p", (void*) this);
}
-void Invite::Invite::Serialize(SerializeFormat format, bool show_chans, std::string& out)
+void Invite::Invite::Serialize(bool human, bool show_chans, std::string& out)
{
if (show_chans)
out.append(this->chan->name);
else
- out.append((format == FORMAT_USER) ? user->nick : user->uuid);
+ out.append(human ? user->nick : user->uuid);
out.push_back(' ');
if (expiretimer)
diff --git a/src/coremods/core_channel/invite.h b/src/coremods/core_channel/invite.h
index 19e3861f8..357acd846 100644
--- a/src/coremods/core_channel/invite.h
+++ b/src/coremods/core_channel/invite.h
@@ -45,6 +45,21 @@ extern void UnserializeInvite(LocalUser* user, const std::string& value);
template<typename T, ExtensionItem::ExtensibleType ExtType>
class Invite::ExtItem : public ExtensionItem
{
+ private:
+ static std::string ToString(void* item, bool human)
+ {
+ std::string ret;
+ Store<T>* store = static_cast<Store<T>*>(item);
+ for (typename insp::intrusive_list<Invite, T>::iterator i = store->invites.begin(); i != store->invites.end(); ++i)
+ {
+ Invite* inv = *i;
+ inv->Serialize(human, (ExtType == ExtensionItem::EXT_USER), ret);
+ }
+ if (!ret.empty())
+ ret.erase(ret.length()-1);
+ return ret;
+ }
+
public:
ExtItem(Module* owner, const char* extname)
: ExtensionItem(extname, ExtType, owner)
@@ -83,26 +98,19 @@ class Invite::ExtItem : public ExtensionItem
delete store;
}
- std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
+ std::string ToHuman(const Extensible* container, void* item) const CXX11_OVERRIDE
{
- if (format == FORMAT_NETWORK)
- return std::string();
+ return ToString(item, true);
+ }
- std::string ret;
- Store<T>* store = static_cast<Store<T>*>(item);
- for (typename insp::intrusive_list<Invite, T>::iterator i = store->invites.begin(); i != store->invites.end(); ++i)
- {
- Invite* inv = *i;
- inv->Serialize(format, (ExtType == ExtensionItem::EXT_USER), ret);
- }
- if (!ret.empty())
- ret.erase(ret.length()-1);
- return ret;
+ std::string ToInternal(const Extensible* container, void* item) const CXX11_OVERRIDE
+ {
+ return ToString(item, false);
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
+ void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE
{
- if ((ExtType != ExtensionItem::EXT_CHANNEL) && (format != FORMAT_NETWORK))
+ if (ExtType != ExtensionItem::EXT_CHANNEL)
UnserializeInvite(static_cast<LocalUser*>(container), value);
}
};
diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp
index a13d4d613..d772b4c68 100644
--- a/src/modules/m_callerid.cpp
+++ b/src/modules/m_callerid.cpp
@@ -54,7 +54,7 @@ class callerid_data
callerid_data() : lastnotify(0) { }
- std::string ToString(SerializeFormat format) const
+ std::string ToString(bool human) const
{
std::ostringstream oss;
oss << lastnotify;
@@ -62,7 +62,7 @@ class callerid_data
{
User* u = *i;
// Encode UIDs.
- oss << "," << (format == FORMAT_USER ? u->nick : u->uuid);
+ oss << "," << (human ? u->nick : u->uuid);
}
return oss.str();
}
@@ -75,22 +75,20 @@ struct CallerIDExtInfo : public ExtensionItem
{
}
- std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
+ std::string ToHuman(const Extensible* container, void* item) const CXX11_OVERRIDE
{
- std::string ret;
- if (format != FORMAT_NETWORK)
- {
- callerid_data* dat = static_cast<callerid_data*>(item);
- ret = dat->ToString(format);
- }
- return ret;
+ callerid_data* dat = static_cast<callerid_data*>(item);
+ return dat->ToString(true);
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
+ std::string ToInternal(const Extensible* container, void* item) const CXX11_OVERRIDE
{
- if (format == FORMAT_NETWORK)
- return;
+ callerid_data* dat = static_cast<callerid_data*>(item);
+ return dat->ToString(false);
+ }
+ void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE
+ {
void* old = get_raw(container);
if (old)
this->free(NULL, old);
diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp
index 6e3033bf2..8829d5ef3 100644
--- a/src/modules/m_cap.cpp
+++ b/src/modules/m_cap.cpp
@@ -291,42 +291,52 @@ class Cap::ManagerImpl : public Cap::Manager, public ReloadModule::EventListener
}
};
+namespace
+{
+ std::string SerializeCaps(const Extensible* container, void* item, bool human)
+ {
+ // XXX: Cast away the const because IS_LOCAL() doesn't handle it
+ LocalUser* user = IS_LOCAL(const_cast<User*>(static_cast<const User*>(container)));
+ if (!user)
+ return std::string();
+
+ // List requested caps
+ std::string ret;
+ managerimpl->HandleList(ret, user, false, false);
+
+ // Serialize cap protocol version. If building a human-readable string append a new token, otherwise append only a single character indicating the version.
+ Cap::Protocol protocol = managerimpl->GetProtocol(user);
+ if (human)
+ ret.append("capversion=3.");
+ else if (!ret.empty())
+ ret.erase(ret.length()-1);
+
+ if (protocol == Cap::CAP_302)
+ ret.push_back('2');
+ else
+ ret.push_back('1');
+
+ return ret;
+ }
+}
+
Cap::ExtItem::ExtItem(Module* mod)
: LocalIntExt("caps", ExtensionItem::EXT_USER, mod)
{
}
-std::string Cap::ExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) const
+std::string Cap::ExtItem::ToHuman(const Extensible* container, void* item) const
{
- std::string ret;
- // XXX: Cast away the const because IS_LOCAL() doesn't handle it
- LocalUser* user = IS_LOCAL(const_cast<User*>(static_cast<const User*>(container)));
- if ((format == FORMAT_NETWORK) || (!user))
- return ret;
-
- // List requested caps
- managerimpl->HandleList(ret, user, false, false);
-
- // Serialize cap protocol version. If building a human-readable string append a new token, otherwise append only a single character indicating the version.
- Protocol protocol = managerimpl->GetProtocol(user);
- if (format == FORMAT_USER)
- ret.append("capversion=3.");
- else if (!ret.empty())
- ret.erase(ret.length()-1);
-
- if (protocol == CAP_302)
- ret.push_back('2');
- else
- ret.push_back('1');
-
- return ret;
+ return SerializeCaps(container, item, true);
}
-void Cap::ExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+std::string Cap::ExtItem::ToInternal(const Extensible* container, void* item) const
{
- if (format == FORMAT_NETWORK)
- return;
+ return SerializeCaps(container, item, false);
+}
+void Cap::ExtItem::FromInternal(Extensible* container, const std::string& value)
+{
LocalUser* user = IS_LOCAL(static_cast<User*>(container));
if (!user)
return; // Can't happen
diff --git a/src/modules/m_monitor.cpp b/src/modules/m_monitor.cpp
index b82dbcc7d..cebd69fc2 100644
--- a/src/modules/m_monitor.cpp
+++ b/src/modules/m_monitor.cpp
@@ -82,12 +82,9 @@ class IRCv3::Monitor::Manager
free(container, unset_raw(container));
}
- std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
+ std::string ToInternal(const Extensible* container, void* item) const CXX11_OVERRIDE
{
std::string ret;
- if (format == FORMAT_NETWORK)
- return ret;
-
const ExtData* extdata = static_cast<ExtData*>(item);
for (WatchedList::const_iterator i = extdata->list.begin(); i != extdata->list.end(); ++i)
{
@@ -99,7 +96,7 @@ class IRCv3::Monitor::Manager
return ret;
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE;
+ void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE;
void free(Extensible* container, void* item) CXX11_OVERRIDE
{
@@ -245,12 +242,8 @@ class IRCv3::Monitor::Manager
WatchedList emptywatchedlist;
};
-// inline is needed in static builds to support m_watch including the Manager code from this file
-inline void IRCv3::Monitor::Manager::ExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value)
+void IRCv3::Monitor::Manager::ExtItem::FromInternal(Extensible* container, const std::string& value)
{
- if (format == FORMAT_NETWORK)
- return;
-
irc::spacesepstream ss(value);
for (std::string nick; ss.GetToken(nick); )
manager.Watch(static_cast<LocalUser*>(container), nick, UINT_MAX);
diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp
index 72cd925ab..78d20a6e9 100644
--- a/src/modules/m_services_account.cpp
+++ b/src/modules/m_services_account.cpp
@@ -109,16 +109,16 @@ class AccountExtItemImpl : public AccountExtItem
{
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
+ void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE
{
- User* user = static_cast<User*>(container);
-
- StringExtItem::unserialize(format, container, value);
+ StringExtItem::FromInternal(container, value);
+ }
- // If we are being reloaded then don't send the numeric or run the event
- if (format == FORMAT_INTERNAL)
- return;
+ void FromNetwork(Extensible* container, const std::string& value) CXX11_OVERRIDE
+ {
+ StringExtItem::FromNetwork(container, value);
+ User* user = static_cast<User*>(container);
if (IS_LOCAL(user))
{
if (value.empty())
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index a759718e6..548f4c552 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -58,12 +58,12 @@ class SSLCertExt : public ExtensionItem
free(container, unset_raw(container));
}
- std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
+ std::string ToNetwork(const Extensible* container, void* item) const CXX11_OVERRIDE
{
return static_cast<ssl_cert*>(item)->GetMetaLine();
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
+ void FromNetwork(Extensible* container, const std::string& value) CXX11_OVERRIDE
{
ssl_cert* cert = new ssl_cert;
set(container, cert);
diff --git a/src/modules/m_topiclock.cpp b/src/modules/m_topiclock.cpp
index b0d004b1c..b4fc8dedc 100644
--- a/src/modules/m_topiclock.cpp
+++ b/src/modules/m_topiclock.cpp
@@ -73,6 +73,7 @@ class CommandSVSTOPIC : public Command
}
};
+// TODO: add a BoolExtItem to replace this.
class FlagExtItem : public ExtensionItem
{
public:
@@ -86,15 +87,18 @@ class FlagExtItem : public ExtensionItem
return (get_raw(container) != NULL);
}
- std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE
+ std::string ToHuman(const Extensible* container, void* item) const CXX11_OVERRIDE
{
- if (format == FORMAT_USER)
- return "true";
+ // Make the human version more readable.
+ return "true";
+ }
+ std::string ToNetwork(const Extensible* container, void* item) const CXX11_OVERRIDE
+ {
return "1";
}
- void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE
+ void FromNetwork(Extensible* container, const std::string& value) CXX11_OVERRIDE
{
if (value == "1")
set_raw(container, this);