summaryrefslogtreecommitdiff
path: root/src/modules
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/modules
parent85182d727c0d549b9cf6659ad36dec70fcf02278 (diff)
Convert all core ExtensionItem code away from {un,}serialize.
Diffstat (limited to 'src/modules')
-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
6 files changed, 67 insertions, 62 deletions
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);