1
0
mirror of https://github.com/anope/anope.git synced 2026-07-05 22:13:13 +02:00

Move serialization from Serializable to a Serialize::Type child.

This commit is contained in:
Sadie Powell
2025-03-12 10:29:11 +00:00
parent 718f2e922a
commit cdcf0e2f9a
40 changed files with 778 additions and 452 deletions
+10 -3
View File
@@ -74,6 +74,16 @@ public:
class CoreExport ChanAccess
: public Serializable
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
Anope::string mask;
/* account this access entry is for, if any */
Serialize::Reference<NickCore> nc;
@@ -97,9 +107,6 @@ public:
const Anope::string &Mask() const;
NickCore *GetAccount() const;
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
static const unsigned int MAX_DEPTH = 4;
/** Check if this access entry matches the given user or account
+20 -6
View File
@@ -32,6 +32,16 @@ class CoreExport NickAlias final
: public Serializable
, public Extensible
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
Anope::string vhost_ident, vhost_host, vhost_creator;
time_t vhost_created = 0;
@@ -56,9 +66,6 @@ public:
NickAlias(const Anope::string &nickname, NickCore *nickcore);
~NickAlias();
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Set a vhost for the user
* @param ident The ident
* @param host The host
@@ -116,6 +123,16 @@ class CoreExport NickCore final
: public Serializable
, public Extensible
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
/* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */
Serialize::Checker<std::map<ChannelInfo *, int> > chanaccess;
/* Unique identifier for the account. */
@@ -159,9 +176,6 @@ public:
NickCore(const Anope::string &nickdisplay, uint64_t nickid = 0);
~NickCore();
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Changes the display for this account
* @param na The new display, must be grouped to this account.
*/
+10
View File
@@ -23,6 +23,16 @@ class CoreExport BotInfo final
: public User
, public Serializable
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
/* Channels this bot is assigned to */
Serialize::Checker<std::set<ChannelInfo *> > channels;
public:
+8 -3
View File
@@ -18,15 +18,20 @@ class CoreExport Memo final
: public Serializable
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
MemoInfo *mi;
bool unread;
bool receipt;
Memo();
~Memo();
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
Anope::string owner;
/* When it was sent */
time_t time;
-30
View File
@@ -13,34 +13,4 @@ struct MyOper final
, Serializable
{
MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
void Serialize(Serialize::Data &data) const override
{
data.Store("name", this->name);
data.Store("type", this->ot->GetName());
}
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
{
Anope::string stype, sname;
data["type"] >> stype;
data["name"] >> sname;
OperType *ot = OperType::Find(stype);
if (ot == NULL)
return NULL;
NickCore *nc = NickCore::Find(sname);
if (nc == NULL)
return NULL;
MyOper *myo;
if (obj)
myo = anope_dynamic_static_cast<MyOper *>(obj);
else
myo = new MyOper(nc->display, ot);
nc->o = myo;
Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
return myo;
}
};
-34
View File
@@ -28,8 +28,6 @@ struct Exception final
time_t expires; /* Time when it expires. 0 == no expiry */
Exception() : Serializable("Exception") { }
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
class SessionService
@@ -59,35 +57,3 @@ public:
};
static ServiceReference<SessionService> session_service("SessionService", "session");
void Exception::Serialize(Serialize::Data &data) const
{
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)
{
if (!session_service)
return NULL;
Exception *ex;
if (obj)
ex = anope_dynamic_static_cast<Exception *>(obj);
else
ex = new Exception;
data["mask"] >> ex->mask;
data["limit"] >> ex->limit;
data["who"] >> ex->who;
data["reason"] >> ex->reason;
data["time"] >> ex->time;
data["expires"] >> ex->expires;
if (!obj)
session_service->AddException(ex);
return ex;
}
+18 -6
View File
@@ -25,6 +25,14 @@ class CoreExport AutoKick final
: public Serializable
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
/* Channel this autokick is on */
Serialize::Reference<ChannelInfo> ci;
@@ -38,8 +46,6 @@ public:
AutoKick();
~AutoKick();
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
};
/* It matters that Base is here before Extensible (it is inherited by Serializable)
@@ -48,9 +54,18 @@ class CoreExport ChannelInfo final
: public Serializable
, public Extensible
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
/* channels who reference this one */
Anope::map<int> references;
private:
Serialize::Reference<NickCore> founder; /* Channel founder */
Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */
Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */
@@ -97,9 +112,6 @@ public:
~ChannelInfo();
ChannelInfo &operator=(const ChannelInfo &) = default;
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &);
/** Change the founder of the channel
* @params nc The new founder
*/
+4 -9
View File
@@ -123,8 +123,6 @@ public:
*/
Serialize::Type *GetSerializableType() const { return this->s_type; }
virtual void Serialize(Serialize::Data &data) const = 0;
static const std::list<Serializable *> &GetItems();
};
@@ -132,17 +130,14 @@ public:
* of class that inherits from Serializable. Used for unserializing objects
* of this type, as it requires a function pointer to a static member function.
*/
class CoreExport Serialize::Type final
class CoreExport Serialize::Type
: public Base
{
typedef Serializable *(*unserialize_func)(Serializable *obj, Serialize::Data &);
static std::vector<Anope::string> TypeOrder;
static std::map<Anope::string, Serialize::Type *> Types;
/* The name of this type, should be a class name */
Anope::string name;
unserialize_func unserialize;
/* Owner of this type. Used for placing objects of this type in separate databases
* based on what module, if any, owns it.
*/
@@ -160,10 +155,9 @@ public:
/** Creates a new serializable type
* @param n Type name
* @param f Func to unserialize objects
* @param owner Owner of this type. Leave NULL for the core.
*/
Type(const Anope::string &n, unserialize_func f, Module *owner = NULL);
Type(const Anope::string &n, Module *owner = NULL);
~Type();
/** Gets the name for this type
@@ -177,7 +171,8 @@ public:
* @param data The data to unserialize
* @return The unserialized object. If obj != NULL this should be obj.
*/
Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
virtual void Serialize(const Serializable *obj, Serialize::Data &data) const = 0;
virtual Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const = 0;
/** Check if this object type has any pending changes and update them.
*/
+10 -3
View File
@@ -16,6 +16,16 @@
class CoreExport XLine final
: public Serializable
{
public:
struct Type final
: public Serialize::Type
{
Type();
void Serialize(const Serializable *obj, Serialize::Data &data) const override;
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
private:
void Init();
Anope::string nick, user, host, real;
public:
@@ -43,9 +53,6 @@ public:
bool HasNickOrReal() const;
bool IsRegex() const;
void Serialize(Serialize::Data &data) const override;
static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
/* Managers XLines. There is one XLineManager per type of XLine. */