mirror of
https://github.com/anope/anope.git
synced 2026-06-28 08:36:37 +02:00
Automatically determine SQL column type from the field.
Also add more column types to ensure we are storing data in the best format in the database.
This commit is contained in:
@@ -755,7 +755,7 @@ module { name = "sasl" }
|
||||
name = "sqlite/main"
|
||||
|
||||
/* The database name, it will be created if it does not exist. */
|
||||
database = "anope.db"
|
||||
database = "anope.sqlite"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
|
||||
{
|
||||
T *t = this->Get(e);
|
||||
data[this->name] << *t;
|
||||
data.Store(this->name, *t);
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
@@ -194,8 +194,7 @@ public:
|
||||
|
||||
void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override
|
||||
{
|
||||
data.SetType(this->name, Serialize::Data::DT_INT);
|
||||
data[this->name] << true;
|
||||
data.Store(this->name, true);
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
|
||||
@@ -16,8 +16,8 @@ struct MyOper final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["name"] << this->name;
|
||||
data["type"] << this->ot->GetName();
|
||||
data.Store("name", this->name);
|
||||
data.Store("type", this->ot->GetName());
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -62,12 +62,12 @@ static ServiceReference<SessionService> session_service("SessionService", "sessi
|
||||
|
||||
void Exception::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["mask"] << this->mask;
|
||||
data["limit"] << this->limit;
|
||||
data["who"] << this->who;
|
||||
data["reason"] << this->reason;
|
||||
data["time"] << this->time;
|
||||
data["expires"] << this->expires;
|
||||
data.Store("mask", this->mask);
|
||||
data.Store("limit", this->limit);
|
||||
data.Store("who", this->who);
|
||||
data.Store("reason", this->reason);
|
||||
data.Store("time", this->time);
|
||||
data.Store("expires", this->expires);
|
||||
}
|
||||
|
||||
Serializable *Exception::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SQL
|
||||
public:
|
||||
typedef std::map<Anope::string, std::stringstream *> Map;
|
||||
Map data;
|
||||
std::map<Anope::string, Type> types;
|
||||
std::map<Anope::string, Serialize::DataType> types;
|
||||
|
||||
~Data()
|
||||
{
|
||||
@@ -60,17 +60,17 @@ namespace SQL
|
||||
this->data.clear();
|
||||
}
|
||||
|
||||
void SetType(const Anope::string &key, Type t) override
|
||||
void SetType(const Anope::string &key, Serialize::DataType dt) override
|
||||
{
|
||||
this->types[key] = t;
|
||||
this->types[key] = dt;
|
||||
}
|
||||
|
||||
Type GetType(const Anope::string &key) const override
|
||||
Serialize::DataType GetType(const Anope::string &key) const override
|
||||
{
|
||||
std::map<Anope::string, Type>::const_iterator it = this->types.find(key);
|
||||
auto it = this->types.find(key);
|
||||
if (it != this->types.end())
|
||||
return it->second;
|
||||
return DT_TEXT;
|
||||
return Serialize::DataType::TEXT;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+30
-8
@@ -18,22 +18,44 @@
|
||||
|
||||
namespace Serialize
|
||||
{
|
||||
enum class DataType
|
||||
: uint8_t
|
||||
{
|
||||
BOOL,
|
||||
FLOAT,
|
||||
INT,
|
||||
TEXT,
|
||||
UINT,
|
||||
};
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
DT_TEXT,
|
||||
DT_INT
|
||||
};
|
||||
|
||||
virtual ~Data() = default;
|
||||
|
||||
virtual std::iostream &operator[](const Anope::string &key) = 0;
|
||||
|
||||
template <typename T>
|
||||
void Store(const Anope::string &key, const T &value)
|
||||
{
|
||||
using Type = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
|
||||
if constexpr (std::is_same_v<Type, bool>)
|
||||
SetType(key, DataType::BOOL);
|
||||
else if constexpr (std::is_floating_point_v<Type>)
|
||||
SetType(key, DataType::FLOAT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
|
||||
SetType(key, DataType::INT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
|
||||
SetType(key, DataType::UINT);
|
||||
|
||||
this->operator[](key) << value;
|
||||
}
|
||||
|
||||
virtual size_t Hash() const { throw CoreException("Not supported"); }
|
||||
|
||||
virtual void SetType(const Anope::string &key, Type t) { }
|
||||
virtual Type GetType(const Anope::string &key) const { return DT_TEXT; }
|
||||
virtual void SetType(const Anope::string &key, DataType dt) { }
|
||||
virtual DataType GetType(const Anope::string &key) const { return DataType::TEXT; }
|
||||
};
|
||||
|
||||
extern void RegisterTypes();
|
||||
|
||||
@@ -21,9 +21,9 @@ struct BadWordImpl final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["ci"] << this->chan;
|
||||
data["word"] << this->word;
|
||||
data.SetType("type", Serialize::Data::DT_INT); data["type"] << this->type;
|
||||
data.Store("ci", this->chan);
|
||||
data.Store("word", this->word);
|
||||
data.Store("type", this->type);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
|
||||
|
||||
+21
-18
@@ -53,25 +53,28 @@ struct KickerDataImpl final
|
||||
if (kd == NULL)
|
||||
return;
|
||||
|
||||
data.SetType("kickerdata:amsgs", Serialize::Data::DT_INT); data["kickerdata:amsgs"] << kd->amsgs;
|
||||
data.SetType("kickerdata:badwords", Serialize::Data::DT_INT); data["kickerdata:badwords"] << kd->badwords;
|
||||
data.SetType("kickerdata:bolds", Serialize::Data::DT_INT); data["kickerdata:bolds"] << kd->bolds;
|
||||
data.SetType("kickerdata:caps", Serialize::Data::DT_INT); data["kickerdata:caps"] << kd->caps;
|
||||
data.SetType("kickerdata:colors", Serialize::Data::DT_INT); data["kickerdata:colors"] << kd->colors;
|
||||
data.SetType("kickerdata:flood", Serialize::Data::DT_INT); data["kickerdata:flood"] << kd->flood;
|
||||
data.SetType("kickerdata:italics", Serialize::Data::DT_INT); data["kickerdata:italics"] << kd->italics;
|
||||
data.SetType("kickerdata:repeat", Serialize::Data::DT_INT); data["kickerdata:repeat"] << kd->repeat;
|
||||
data.SetType("kickerdata:reverses", Serialize::Data::DT_INT); data["kickerdata:reverses"] << kd->reverses;
|
||||
data.SetType("kickerdata:underlines", Serialize::Data::DT_INT); data["kickerdata:underlines"] << kd->underlines;
|
||||
data.SetType("capsmin", Serialize::Data::DT_INT); data["capsmin"] << kd->capsmin;
|
||||
data.SetType("capspercent", Serialize::Data::DT_INT); data["capspercent"] << kd->capspercent;
|
||||
data.SetType("floodlines", Serialize::Data::DT_INT); data["floodlines"] << kd->floodlines;
|
||||
data.SetType("floodsecs", Serialize::Data::DT_INT); data["floodsecs"] << kd->floodsecs;
|
||||
data.SetType("repeattimes", Serialize::Data::DT_INT); data["repeattimes"] << kd->repeattimes;
|
||||
data.SetType("dontkickops", Serialize::Data::DT_INT); data["dontkickops"] << kd->dontkickops;
|
||||
data.SetType("dontkickvoices", Serialize::Data::DT_INT); data["dontkickvoices"] << kd->dontkickvoices;
|
||||
data.Store("kickerdata:amsgs", kd->amsgs);
|
||||
data.Store("kickerdata:badwords", kd->badwords);
|
||||
data.Store("kickerdata:bolds", kd->bolds);
|
||||
data.Store("kickerdata:caps", kd->caps);
|
||||
data.Store("kickerdata:colors", kd->colors);
|
||||
data.Store("kickerdata:flood", kd->flood);
|
||||
data.Store("kickerdata:italics", kd->italics);
|
||||
data.Store("kickerdata:repeat", kd->repeat);
|
||||
data.Store("kickerdata:reverses", kd->reverses);
|
||||
data.Store("kickerdata:underlines", kd->underlines);
|
||||
data.Store("capsmin", kd->capsmin);
|
||||
data.Store("capspercent", kd->capspercent);
|
||||
data.Store("floodlines", kd->floodlines);
|
||||
data.Store("floodsecs", kd->floodsecs);
|
||||
data.Store("repeattimes", kd->repeattimes);
|
||||
data.Store("dontkickops", kd->dontkickops);
|
||||
data.Store("dontkickvoices", kd->dontkickvoices);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (auto ttbtype : kd->ttb)
|
||||
data["ttb"] << ttbtype << " ";
|
||||
oss << ttbtype << " ";
|
||||
data.Store("ttb", oss.str());
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
|
||||
@@ -32,10 +32,10 @@ struct EntryMsgImpl final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["ci"] << this->chan;
|
||||
data["creator"] << this->creator;
|
||||
data["message"] << this->message;
|
||||
data.SetType("when", Serialize::Data::DT_INT); data["when"] << this->when;
|
||||
data.Store("ci", this->chan);
|
||||
data.Store("creator", this->creator);
|
||||
data.Store("message", this->message);
|
||||
data.Store("when", this->when);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
|
||||
|
||||
@@ -37,14 +37,14 @@ struct LogSettingImpl final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["ci"] << chan;
|
||||
data["service_name"] << service_name;
|
||||
data["command_service"] << command_service;
|
||||
data["command_name"] << command_name;
|
||||
data["method"] << method;
|
||||
data["extra"] << extra;
|
||||
data["creator"] << creator;
|
||||
data.SetType("created", Serialize::Data::DT_INT); data["created"] << created;
|
||||
data.Store("ci", chan);
|
||||
data.Store("service_name", service_name);
|
||||
data.Store("command_service", command_service);
|
||||
data.Store("command_name", command_name);
|
||||
data.Store("method", method);
|
||||
data.Store("extra", extra);
|
||||
data.Store("creator", creator);
|
||||
data.Store("created", created);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -205,12 +205,12 @@ struct ModeLocksImpl final
|
||||
|
||||
void ModeLockImpl::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["ci"] << this->ci;
|
||||
data["set"] << this->set;
|
||||
data["name"] << this->name;
|
||||
data["param"] << this->param;
|
||||
data["setter"] << this->setter;
|
||||
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
|
||||
data.Store("ci", this->ci);
|
||||
data.Store("set", this->set);
|
||||
data.Store("name", this->name);
|
||||
data.Store("param", this->param);
|
||||
data.Store("setter", this->setter);
|
||||
data.Store("created", this->created);
|
||||
}
|
||||
|
||||
Serializable *ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -46,13 +46,13 @@ struct SeenInfo final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["nick"] << nick;
|
||||
data["vhost"] << vhost;
|
||||
data["type"] << type;
|
||||
data["nick2"] << nick2;
|
||||
data["channel"] << channel;
|
||||
data["message"] << message;
|
||||
data.SetType("last", Serialize::Data::DT_INT); data["last"] << last;
|
||||
data.Store("nick", nick);
|
||||
data.Store("vhost", vhost);
|
||||
data.Store("type", type);
|
||||
data.Store("nick2", nick2);
|
||||
data.Store("channel", channel);
|
||||
data.Store("message", message);
|
||||
data.Store("last", last);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -1068,7 +1068,7 @@ class CSSet final
|
||||
if (!last_value.empty())
|
||||
modes += "," + last_value;
|
||||
}
|
||||
data["last_modes"] << modes;
|
||||
data.Store("last_modes", modes);
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
|
||||
@@ -46,9 +46,9 @@ struct CSMiscData final
|
||||
|
||||
void Serialize(Serialize::Data &sdata) const override
|
||||
{
|
||||
sdata["ci"] << this->object;
|
||||
sdata["name"] << this->name;
|
||||
sdata["data"] << this->data;
|
||||
sdata.Store("ci", this->object);
|
||||
sdata.Store("name", this->name);
|
||||
sdata.Store("data", this->data);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -20,11 +20,11 @@ struct CSSuspendInfo final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["chan"] << what;
|
||||
data["by"] << by;
|
||||
data["reason"] << reason;
|
||||
data["time"] << when;
|
||||
data["expires"] << expires;
|
||||
data.Store("chan", what);
|
||||
data.Store("by", by);
|
||||
data.Store("reason", reason);
|
||||
data.Store("time", when);
|
||||
data.Store("expires", expires);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
+48
-15
@@ -158,6 +158,29 @@ public:
|
||||
Anope::string BuildQuery(const Query &q);
|
||||
|
||||
Anope::string FromUnixtime(time_t) override;
|
||||
|
||||
Anope::string GetColumnType(Serialize::DataType dt)
|
||||
{
|
||||
switch (dt)
|
||||
{
|
||||
case Serialize::DataType::BOOL:
|
||||
return "TINYINT NOT NULL";
|
||||
|
||||
case Serialize::DataType::FLOAT:
|
||||
return "DOUBLE PRECISION NOT NULL";
|
||||
|
||||
case Serialize::DataType::INT:
|
||||
return "BIGINT NOT NULL";
|
||||
|
||||
case Serialize::DataType::TEXT:
|
||||
return "TEXT";
|
||||
|
||||
case Serialize::DataType::UINT:
|
||||
return "BIGINT UNSIGNED NOT NULL";
|
||||
}
|
||||
|
||||
return "TEXT"; // Should never be reached
|
||||
}
|
||||
};
|
||||
|
||||
/** The SQL thread used to execute queries
|
||||
@@ -410,17 +433,13 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
|
||||
|
||||
if (known_cols.empty())
|
||||
{
|
||||
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
|
||||
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,"
|
||||
" `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
|
||||
for (const auto &[column, _] : data.data)
|
||||
{
|
||||
known_cols.insert(column);
|
||||
|
||||
query_text += ", `" + column + "` ";
|
||||
if (data.GetType(column) == Serialize::Data::DT_INT)
|
||||
query_text += "int";
|
||||
else
|
||||
query_text += "text";
|
||||
query_text += ", `" + column + "` " + GetColumnType(data.GetType(column));
|
||||
}
|
||||
query_text += ", PRIMARY KEY (`id`), KEY `timestamp_idx` (`timestamp`)) ROW_FORMAT=DYNAMIC";
|
||||
queries.push_back(query_text);
|
||||
@@ -434,11 +453,7 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
|
||||
|
||||
known_cols.insert(column);
|
||||
|
||||
Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` ";
|
||||
if (data.GetType(column) == Serialize::Data::DT_INT)
|
||||
query_text += "int";
|
||||
else
|
||||
query_text += "text";
|
||||
Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` " + GetColumnType(data.GetType(column));
|
||||
|
||||
queries.push_back(query_text);
|
||||
}
|
||||
@@ -474,11 +489,29 @@ Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Dat
|
||||
Anope::string buf;
|
||||
*value >> buf;
|
||||
|
||||
bool escape = true;
|
||||
if (buf.empty())
|
||||
auto escape = true;
|
||||
switch (data.GetType(field))
|
||||
{
|
||||
buf = "NULL";
|
||||
escape = false;
|
||||
case Serialize::DataType::BOOL:
|
||||
case Serialize::DataType::FLOAT:
|
||||
case Serialize::DataType::INT:
|
||||
case Serialize::DataType::UINT:
|
||||
{
|
||||
if (buf.empty())
|
||||
buf = "0";
|
||||
escape = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case Serialize::DataType::TEXT:
|
||||
{
|
||||
if (buf.empty())
|
||||
{
|
||||
buf = "NULL";
|
||||
escape = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
query.SetValue(field, buf, escape);
|
||||
|
||||
+54
-11
@@ -68,6 +68,31 @@ public:
|
||||
Anope::string BuildQuery(const Query &q);
|
||||
|
||||
Anope::string FromUnixtime(time_t) override;
|
||||
|
||||
Anope::string GetColumnType(Serialize::DataType dt)
|
||||
{
|
||||
switch (dt)
|
||||
{
|
||||
case Serialize::DataType::BOOL:
|
||||
return "INTEGER";
|
||||
|
||||
case Serialize::DataType::FLOAT:
|
||||
return "REAL";
|
||||
|
||||
case Serialize::DataType::INT:
|
||||
return "INTEGER";
|
||||
|
||||
case Serialize::DataType::TEXT:
|
||||
return "TEXT";
|
||||
|
||||
// SQLite lacks support for 64-bit unsigned integers so we have to
|
||||
// store them as text columns instead.
|
||||
case Serialize::DataType::UINT:
|
||||
return "TEXT";
|
||||
}
|
||||
|
||||
return "TEXT"; // Should never be reached
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleSQLite final
|
||||
@@ -237,11 +262,7 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
|
||||
{
|
||||
known_cols.insert(column);
|
||||
|
||||
query_text += ", `" + column + "` ";
|
||||
if (data.GetType(column) == Serialize::Data::DT_INT)
|
||||
query_text += "int(11)";
|
||||
else
|
||||
query_text += "text";
|
||||
query_text += ", `" + column + "` " + GetColumnType(data.GetType(column));
|
||||
}
|
||||
|
||||
query_text += ")";
|
||||
@@ -266,11 +287,7 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
|
||||
|
||||
known_cols.insert(column);
|
||||
|
||||
Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` ";
|
||||
if (data.GetType(column) == Serialize::Data::DT_INT)
|
||||
query_text += "int(11)";
|
||||
else
|
||||
query_text += "text";
|
||||
Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` " + GetColumnType(data.GetType(column));;
|
||||
|
||||
queries.push_back(query_text);
|
||||
}
|
||||
@@ -307,7 +324,33 @@ Query SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, Da
|
||||
{
|
||||
Anope::string buf;
|
||||
*value >> buf;
|
||||
query.SetValue(field, buf);
|
||||
|
||||
auto escape = true;
|
||||
switch (data.GetType(field))
|
||||
{
|
||||
case Serialize::DataType::BOOL:
|
||||
case Serialize::DataType::FLOAT:
|
||||
case Serialize::DataType::INT:
|
||||
{
|
||||
if (buf.empty())
|
||||
buf = "0";
|
||||
escape = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case Serialize::DataType::TEXT:
|
||||
case Serialize::DataType::UINT:
|
||||
{
|
||||
if (buf.empty())
|
||||
{
|
||||
buf = "NULL";
|
||||
escape = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
query.SetValue(field, buf, escape);
|
||||
}
|
||||
|
||||
return query;
|
||||
|
||||
@@ -32,10 +32,10 @@ struct HostRequestImpl final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["nick"] << this->nick;
|
||||
data["ident"] << this->ident;
|
||||
data["host"] << this->host;
|
||||
data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
|
||||
data.Store("nick", this->nick);
|
||||
data.Store("ident", this->ident);
|
||||
data.Store("host", this->host);
|
||||
data.Store("time", this->time);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -40,14 +40,14 @@ struct AJoinEntry final
|
||||
}
|
||||
}
|
||||
|
||||
void Serialize(Serialize::Data &sd) const override
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
if (!this->owner)
|
||||
return;
|
||||
|
||||
sd["owner"] << this->owner->display;
|
||||
sd["channel"] << this->channel;
|
||||
sd["key"] << this->key;
|
||||
data.Store("owner", this->owner->display);
|
||||
data.Store("channel", this->channel);
|
||||
data.Store("key", this->key);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &sd)
|
||||
|
||||
@@ -168,8 +168,10 @@ public:
|
||||
if (c == NULL || !c->GetCertCount())
|
||||
return;
|
||||
|
||||
std::ostringstream oss;
|
||||
for (unsigned i = 0; i < c->GetCertCount(); ++i)
|
||||
data["cert"] << c->GetCert(i) << " ";
|
||||
oss << c->GetCert(i) << " ";
|
||||
data.Store("cert", oss.str());
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
|
||||
@@ -1108,7 +1108,7 @@ class NSSet final
|
||||
if (!last_value.empty())
|
||||
modes += "," + last_value;
|
||||
}
|
||||
data["last_modes"] << modes;
|
||||
data.Store("last_modes", modes);
|
||||
}
|
||||
|
||||
void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override
|
||||
|
||||
@@ -46,9 +46,9 @@ struct NSMiscData final
|
||||
|
||||
void Serialize(Serialize::Data &sdata) const override
|
||||
{
|
||||
sdata["nc"] << this->object;
|
||||
sdata["name"] << this->name;
|
||||
sdata["data"] << this->data;
|
||||
sdata.Store("nc", this->object);
|
||||
sdata.Store("name", this->name);
|
||||
sdata.Store("data", this->data);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -22,11 +22,11 @@ struct NSSuspendInfo final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["nick"] << what;
|
||||
data["by"] << by;
|
||||
data["reason"] << reason;
|
||||
data["time"] << when;
|
||||
data["expires"] << expires;
|
||||
data.Store("nick", what);
|
||||
data.Store("by", by);
|
||||
data.Store("reason", reason);
|
||||
data.Store("time", when);
|
||||
data.Store("expires", expires);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -39,10 +39,10 @@ struct DNSZone final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["name"] << name;
|
||||
data.Store("name", name);
|
||||
unsigned count = 0;
|
||||
for (const auto &server : servers)
|
||||
data["server" + Anope::ToString(count++)] << server;
|
||||
data.Store("server" + Anope::ToString(count++), server);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
@@ -144,14 +144,14 @@ public:
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["server_name"] << server_name;
|
||||
data.Store("server_name", server_name);
|
||||
for (unsigned i = 0; i < ips.size(); ++i)
|
||||
data["ip" + Anope::ToString(i)] << ips[i];
|
||||
data["limit"] << limit;
|
||||
data["pooled"] << pooled;
|
||||
data.Store("ip" + Anope::ToString(i), ips[i]);
|
||||
data.Store("limit", limit);
|
||||
data.Store("pooled", pooled);
|
||||
unsigned count = 0;
|
||||
for (const auto &zone : zones)
|
||||
data["zone" + Anope::ToString(count++)] << zone;
|
||||
data.Store("zone" + Anope::ToString(count++), zone);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -25,12 +25,12 @@ struct ForbidDataImpl final
|
||||
|
||||
void ForbidDataImpl::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["mask"] << this->mask;
|
||||
data["creator"] << this->creator;
|
||||
data["reason"] << this->reason;
|
||||
data["created"] << this->created;
|
||||
data["expires"] << this->expires;
|
||||
data["type"] << this->type;
|
||||
data.Store("mask", this->mask);
|
||||
data.Store("creator", this->creator);
|
||||
data.Store("reason", this->reason);
|
||||
data.Store("created", this->created);
|
||||
data.Store("expires", this->expires);
|
||||
data.Store("type", this->type);
|
||||
}
|
||||
|
||||
Serializable *ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -30,10 +30,10 @@ IgnoreDataImpl::~IgnoreDataImpl()
|
||||
|
||||
void IgnoreDataImpl::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["mask"] << this->mask;
|
||||
data["creator"] << this->creator;
|
||||
data["reason"] << this->reason;
|
||||
data["time"] << this->time;
|
||||
data.Store("mask", this->mask);
|
||||
data.Store("creator", this->creator);
|
||||
data.Store("reason", this->reason);
|
||||
data.Store("time", this->time);
|
||||
}
|
||||
|
||||
Serializable *IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -28,10 +28,10 @@ struct OperInfoImpl final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["target"] << target;
|
||||
data["info"] << info;
|
||||
data["adder"] << adder;
|
||||
data["created"] << created;
|
||||
data.Store("target", target);
|
||||
data.Store("info", info);
|
||||
data.Store("adder", adder);
|
||||
data.Store("created", created);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
|
||||
|
||||
@@ -69,10 +69,10 @@ struct MyNewsItem final
|
||||
{
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["type"] << this->type;
|
||||
data["text"] << this->text;
|
||||
data["who"] << this->who;
|
||||
data["time"] << this->time;
|
||||
data.Store("type", this->type);
|
||||
data.Store("text", this->text);
|
||||
data.Store("who", this->who);
|
||||
data.Store("time", this->time);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
@@ -24,8 +24,8 @@ struct Stats final
|
||||
|
||||
void Serialize(Serialize::Data &data) const override
|
||||
{
|
||||
data["maxusercnt"] << MaxUserCount;
|
||||
data["maxusertime"] << MaxUserTime;
|
||||
data.Store("maxusercnt", MaxUserCount);
|
||||
data.Store("maxusertime", MaxUserTime);
|
||||
}
|
||||
|
||||
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
+8
-8
@@ -160,14 +160,14 @@ NickCore *ChanAccess::GetAccount() const
|
||||
|
||||
void ChanAccess::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["provider"] << this->provider->name;
|
||||
data["ci"] << this->ci->name;
|
||||
data["mask"] << this->Mask();
|
||||
data["creator"] << this->creator;
|
||||
data["description"] << this->description;
|
||||
data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
|
||||
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
|
||||
data["data"] << this->AccessSerialize();
|
||||
data.Store("provider", this->provider->name);
|
||||
data.Store("ci", this->ci->name);
|
||||
data.Store("mask", this->Mask());
|
||||
data.Store("creator", this->creator);
|
||||
data.Store("description", this->description);
|
||||
data.Store("last_seen", this->last_seen);
|
||||
data.Store("created", this->created);
|
||||
data.Store("data", this->AccessSerialize());
|
||||
}
|
||||
|
||||
Serializable *ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
+6
-6
@@ -75,12 +75,12 @@ BotInfo::~BotInfo()
|
||||
|
||||
void BotInfo::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["nick"] << this->nick;
|
||||
data["user"] << this->ident;
|
||||
data["host"] << this->host;
|
||||
data["realname"] << this->realname;
|
||||
data["created"] << this->created;
|
||||
data["oper_only"] << this->oper_only;
|
||||
data.Store("nick", this->nick);
|
||||
data.Store("user", this->ident);
|
||||
data.Store("host", this->host);
|
||||
data.Store("realname", this->realname);
|
||||
data.Store("created", this->created);
|
||||
data.Store("oper_only", this->oper_only);
|
||||
|
||||
Extensible::ExtensibleSerialize(this, this, data);
|
||||
}
|
||||
|
||||
+6
-6
@@ -36,12 +36,12 @@ Memo::~Memo()
|
||||
|
||||
void Memo::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["owner"] << this->owner;
|
||||
data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
|
||||
data["sender"] << this->sender;
|
||||
data["text"] << this->text;
|
||||
data["unread"] << this->unread;
|
||||
data["receipt"] << this->receipt;
|
||||
data.Store("owner", this->owner);
|
||||
data.Store("time", this->time);
|
||||
data.Store("sender", this->sender);
|
||||
data.Store("text", this->text);
|
||||
data.Store("unread", this->unread);
|
||||
data.Store("receipt", this->receipt);
|
||||
}
|
||||
|
||||
Serializable *Memo::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
+12
-12
@@ -141,21 +141,21 @@ NickAlias *NickAlias::Find(const Anope::string &nick)
|
||||
|
||||
void NickAlias::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["nick"] << this->nick;
|
||||
data["last_quit"] << this->last_quit;
|
||||
data["last_realname"] << this->last_realname;
|
||||
data["last_usermask"] << this->last_usermask;
|
||||
data["last_realhost"] << this->last_realhost;
|
||||
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
|
||||
data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
|
||||
data["nc"] << this->nc->display;
|
||||
data.Store("nick", this->nick);
|
||||
data.Store("last_quit", this->last_quit);
|
||||
data.Store("last_realname", this->last_realname);
|
||||
data.Store("last_usermask", this->last_usermask);
|
||||
data.Store("last_realhost", this->last_realhost);
|
||||
data.Store("time_registered", this->time_registered);
|
||||
data.Store("last_seen", this->last_seen);
|
||||
data.Store("nc", this->nc->display);
|
||||
|
||||
if (this->HasVHost())
|
||||
{
|
||||
data["vhost_ident"] << this->GetVHostIdent();
|
||||
data["vhost_host"] << this->GetVHostHost();
|
||||
data["vhost_creator"] << this->GetVHostCreator();
|
||||
data["vhost_time"] << this->GetVHostCreated();
|
||||
data.Store("vhost_ident", this->GetVHostIdent());
|
||||
data.Store("vhost_host", this->GetVHostHost());
|
||||
data.Store("vhost_creator", this->GetVHostCreator());
|
||||
data.Store("vhost_time", this->GetVHostCreated());
|
||||
}
|
||||
|
||||
Extensible::ExtensibleSerialize(this, this, data);
|
||||
|
||||
+12
-9
@@ -68,17 +68,20 @@ NickCore::~NickCore()
|
||||
|
||||
void NickCore::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["display"] << this->display;
|
||||
data["uniqueid"] << this->id;
|
||||
data["pass"] << this->pass;
|
||||
data["email"] << this->email;
|
||||
data["language"] << this->language;
|
||||
data.SetType("lastmail", Serialize::Data::DT_INT); data["lastmail"] << this->lastmail;
|
||||
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
|
||||
data.Store("display", this->display);
|
||||
data.Store("uniqueid", this->id);
|
||||
data.Store("pass", this->pass);
|
||||
data.Store("email", this->email);
|
||||
data.Store("language", this->language);
|
||||
data.Store("lastmail", this->lastmail);
|
||||
data.Store("time_registered", this->time_registered);
|
||||
data.Store("memomax", this->memos.memomax);
|
||||
|
||||
data["memomax"] << this->memos.memomax;
|
||||
std::ostringstream oss;
|
||||
for (const auto &ignore : this->memos.ignores)
|
||||
data["memoignores"] << ignore << " ";
|
||||
oss << ignore << " ";
|
||||
data.Store("memoignores", oss.str());
|
||||
|
||||
Extensible::ExtensibleSerialize(this, this, data);
|
||||
}
|
||||
|
||||
|
||||
+25
-22
@@ -40,15 +40,15 @@ AutoKick::~AutoKick()
|
||||
|
||||
void AutoKick::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["ci"] << this->ci->name;
|
||||
data.Store("ci", this->ci->name);
|
||||
if (this->nc)
|
||||
data["nc"] << this->nc->display;
|
||||
data.Store("nc", this->nc->display);
|
||||
else
|
||||
data["mask"] << this->mask;
|
||||
data["reason"] << this->reason;
|
||||
data["creator"] << this->creator;
|
||||
data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime;
|
||||
data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used;
|
||||
data.Store("mask", this->mask);
|
||||
data.Store("reason", this->reason);
|
||||
data.Store("creator", this->creator);
|
||||
data.Store("addtime", this->addtime);
|
||||
data.Store("last_used", this->last_used);
|
||||
}
|
||||
|
||||
Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
@@ -180,30 +180,33 @@ ChannelInfo::~ChannelInfo()
|
||||
|
||||
void ChannelInfo::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["name"] << this->name;
|
||||
data.Store("name", this->name);
|
||||
if (this->founder)
|
||||
data["founder"] << this->founder->display;
|
||||
data.Store("founder", this->founder->display);
|
||||
if (this->successor)
|
||||
data["successor"] << this->successor->display;
|
||||
data["description"] << this->desc;
|
||||
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
|
||||
data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used;
|
||||
data["last_topic"] << this->last_topic;
|
||||
data["last_topic_setter"] << this->last_topic_setter;
|
||||
data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time;
|
||||
data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype;
|
||||
data.Store("successor", this->successor->display);
|
||||
data.Store("description", this->desc);
|
||||
data.Store("time_registered", this->time_registered);
|
||||
data.Store("last_used", this->last_used);
|
||||
data.Store("last_topic", this->last_topic);
|
||||
data.Store("last_topic_setter", this->last_topic_setter);
|
||||
data.Store("last_topic_time", this->last_topic_time);
|
||||
data.Store("bantype", this->bantype);
|
||||
{
|
||||
Anope::string levels_buffer;
|
||||
for (const auto &[name, level] : this->levels)
|
||||
levels_buffer += name + " " + Anope::ToString(level) + " ";
|
||||
data["levels"] << levels_buffer;
|
||||
data.Store("levels", levels_buffer);
|
||||
}
|
||||
if (this->bi)
|
||||
data["bi"] << this->bi->nick;
|
||||
data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire;
|
||||
data["memomax"] << this->memos.memomax;
|
||||
data.Store("bi", this->bi->nick);
|
||||
data.Store("banexpire", this->banexpire);
|
||||
data.Store("memomax", this->memos.memomax);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (const auto &ignore : this->memos.ignores)
|
||||
data["memoignores"] << ignore << " ";
|
||||
oss << ignore << " ";
|
||||
data.Store("memoignores", oss.str());
|
||||
|
||||
Extensible::ExtensibleSerialize(this, this, data);
|
||||
}
|
||||
|
||||
+7
-7
@@ -153,14 +153,14 @@ bool XLine::IsRegex() const
|
||||
|
||||
void XLine::Serialize(Serialize::Data &data) const
|
||||
{
|
||||
data["mask"] << this->mask;
|
||||
data["by"] << this->by;
|
||||
data["created"] << this->created;
|
||||
data["expires"] << this->expires;
|
||||
data["reason"] << this->reason;
|
||||
data["uid"] << this->id;
|
||||
data.Store("mask", this->mask);
|
||||
data.Store("by", this->by);
|
||||
data.Store("created", this->created);
|
||||
data.Store("expires", this->expires);
|
||||
data.Store("reason", this->reason);
|
||||
data.Store("uid", this->id);
|
||||
if (this->manager)
|
||||
data["manager"] << this->manager->name;
|
||||
data.Store("manager", this->manager->name);
|
||||
}
|
||||
|
||||
Serializable *XLine::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
|
||||
Reference in New Issue
Block a user