diff options
| author | Adam <Adam@anope.org> | 2012-04-23 05:08:26 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2012-04-23 05:08:26 -0400 |
| commit | 573e49a7ead331219eb6f0d3ca9cf83e793a5c9c (patch) | |
| tree | e145e04fa3d041cf92ce46da4ac790b63231059c /include | |
| parent | 63c639e108a00d7dbb0d7ac9891684fc83a3b207 (diff) | |
Reworked live SQL support yet again
Diffstat (limited to 'include')
| -rw-r--r-- | include/access.h | 18 | ||||
| -rw-r--r-- | include/account.h | 28 | ||||
| -rw-r--r-- | include/anope.h | 4 | ||||
| -rw-r--r-- | include/base.h | 50 | ||||
| -rw-r--r-- | include/bots.h | 14 | ||||
| -rw-r--r-- | include/channels.h | 24 | ||||
| -rw-r--r-- | include/defs.h | 1 | ||||
| -rw-r--r-- | include/extensible.h | 16 | ||||
| -rw-r--r-- | include/extern.h | 14 | ||||
| -rw-r--r-- | include/logger.h | 18 | ||||
| -rw-r--r-- | include/mail.h | 4 | ||||
| -rw-r--r-- | include/memo.h | 10 | ||||
| -rw-r--r-- | include/modes.h | 14 | ||||
| -rw-r--r-- | include/modules.h | 56 | ||||
| -rw-r--r-- | include/oper.h | 18 | ||||
| -rw-r--r-- | include/protocol.h | 2 | ||||
| -rw-r--r-- | include/regchannel.h | 92 | ||||
| -rw-r--r-- | include/serialize.h | 189 | ||||
| -rw-r--r-- | include/servers.h | 2 | ||||
| -rw-r--r-- | include/service.h | 4 | ||||
| -rw-r--r-- | include/users.h | 27 |
21 files changed, 383 insertions, 222 deletions
diff --git a/include/access.h b/include/access.h index e19c15a76..18499b602 100644 --- a/include/access.h +++ b/include/access.h @@ -59,7 +59,7 @@ class CoreExport ChanAccess : public Serializable { public: AccessProvider *provider; - ChannelInfo *ci; + serialize_obj<ChannelInfo> ci; Anope::string mask; Anope::string creator; time_t last_seen; @@ -68,13 +68,13 @@ class CoreExport ChanAccess : public Serializable ChanAccess(AccessProvider *p); virtual ~ChanAccess(); - Anope::string serialize_name() const; - serialized_data serialize(); - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); - virtual bool Matches(User *u, NickCore *nc); + virtual bool Matches(const User *u, const NickCore *nc) const; virtual bool HasPriv(const Anope::string &name) const = 0; - virtual Anope::string Serialize() = 0; + virtual Anope::string Serialize() const = 0; virtual void Unserialize(const Anope::string &data) = 0; bool operator>(const ChanAccess &other) const; @@ -86,12 +86,12 @@ class CoreExport ChanAccess : public Serializable class CoreExport AccessGroup : public std::vector<ChanAccess *> { public: - ChannelInfo *ci; - NickCore *nc; + const ChannelInfo *ci; + const NickCore *nc; bool SuperAdmin, Founder; AccessGroup(); bool HasPriv(const Anope::string &priv) const; - ChanAccess *Highest() const; + const ChanAccess *Highest() const; bool operator>(const AccessGroup &other) const; bool operator<(const AccessGroup &other) const; bool operator>=(const AccessGroup &other) const; diff --git a/include/account.h b/include/account.h index 18bdcc876..756c97348 100644 --- a/include/account.h +++ b/include/account.h @@ -23,8 +23,8 @@ typedef Anope::insensitive_map<NickAlias *> nickalias_map; typedef Anope::insensitive_map<NickCore *> nickcore_map; -extern CoreExport nickalias_map NickAliasList; -extern CoreExport nickcore_map NickCoreList; +extern serialize_checker<nickalias_map> NickAliasList; +extern serialize_checker<nickcore_map> NickCoreList; /* NickServ nickname structures. */ @@ -109,7 +109,7 @@ const Anope::string NickCoreFlagStrings[] = { "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "FORBIDDEN", "UNCONFIRMED", "STATS", "" }; -class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNameFlag, NS_END>, public Serializable +class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_END>, public Serializable { Anope::string vhost_ident, vhost_host, vhost_creator; time_t vhost_created; @@ -117,7 +117,7 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa public: /** Default constructor * @param nickname The nick - * @param nickcore The nickcofe for this nick + * @param nickcore The nickcore for this nick */ NickAlias(const Anope::string &nickname, NickCore *nickcore); @@ -132,11 +132,11 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa Anope::string last_realhost; /* Last uncloaked usermask, requires nickserv/auspex to see */ time_t time_registered; /* When the nick was registered */ time_t last_seen; /* When it was seen online for the last time */ - NickCore *nc; /* I'm an alias of this */ + serialize_obj<NickCore> nc; /* I'm an alias of this */ - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); /** Release a nick * See the comment in users.cpp @@ -188,7 +188,7 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa time_t GetVhostCreated() const; }; -class CoreExport NickCore : public Base, public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable +class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable { public: /** Default constructor @@ -216,11 +216,11 @@ class CoreExport NickCore : public Base, public Extensible, public Flags<NickCor /* Unsaved data */ uint16_t channelcount; /* Number of channels currently registered */ time_t lastmail; /* Last time this nick record got a mail */ - std::list<NickAlias *> aliases; /* List of aliases */ + std::list<serialize_obj<NickAlias> > aliases; /* List of aliases */ - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); /** Checks whether this account is a services oper or not. * @return True if this account is a services oper, false otherwise. @@ -291,7 +291,7 @@ class CoreExport NickCore : public Base, public Extensible, public Flags<NickCor * * Search for an fingerprint within the cert list. */ - bool FindCert(const Anope::string &entry); + bool FindCert(const Anope::string &entry) const; /** Erase a fingerprint from the nick's certificate list * diff --git a/include/anope.h b/include/anope.h index b286d0fb6..c67b1decb 100644 --- a/include/anope.h +++ b/include/anope.h @@ -670,7 +670,7 @@ template<typename T, size_t Size = 32> class Flags Flag_Values.reset(); } - Anope::string ToString() + Anope::string ToString() const { std::vector<Anope::string> v = ToVector(); Anope::string flag_buf; @@ -692,7 +692,7 @@ template<typename T, size_t Size = 32> class Flags FromVector(v); } - std::vector<Anope::string> ToVector() + std::vector<Anope::string> ToVector() const { std::vector<Anope::string> ret; for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i) diff --git a/include/base.h b/include/base.h index 2a7cb5147..cc0e84bf9 100644 --- a/include/base.h +++ b/include/base.h @@ -30,6 +30,7 @@ class dynamic_reference_base bool invalid; public: dynamic_reference_base() : invalid(false) { } + dynamic_reference_base(const dynamic_reference_base &other) : invalid(other.invalid) { } virtual ~dynamic_reference_base() { } inline void Invalidate() { this->invalid = true; } }; @@ -40,66 +41,67 @@ class dynamic_reference : public dynamic_reference_base protected: T *ref; public: + dynamic_reference() : ref(NULL) + { + } + dynamic_reference(T *obj) : ref(obj) { if (ref) ref->AddReference(this); } - dynamic_reference(const dynamic_reference<T> &obj) : ref(obj.ref) + dynamic_reference(const dynamic_reference<T> &other) : dynamic_reference_base(other), ref(other.ref) { - if (ref) + if (*this) ref->AddReference(this); } virtual ~dynamic_reference() { - if (this->invalid) + if (*this) { - this->invalid = false; - this->ref = NULL; - } - else if (this->operator bool()) ref->DelReference(this); + } } virtual operator bool() { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - return this->ref != NULL; + if (!this->invalid) + return this->ref != NULL; + return false; } - virtual inline operator T*() + virtual inline operator T*() const { - if (this->operator bool()) + if (!this->invalid) return this->ref; return NULL; } - virtual inline T *operator->() + virtual inline T* operator->() { - if (this->operator bool()) + if (!this->invalid) return this->ref; return NULL; } virtual inline void operator=(T *newref) { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - else if (this->operator bool()) + if (*this) this->ref->DelReference(this); this->ref = newref; - if (this->operator bool()) + this->invalid = false; + if (*this) this->ref->AddReference(this); } + + virtual inline bool operator==(const dynamic_reference<T> &other) const + { + if (!this->invalid) + return this->ref == other; + return false; + } }; #endif // BASE_H diff --git a/include/bots.h b/include/bots.h index 8d39cd0b3..749e4c92d 100644 --- a/include/bots.h +++ b/include/bots.h @@ -14,9 +14,11 @@ #include "commands.h" -extern CoreExport Anope::insensitive_map<BotInfo *> BotListByNick; -extern CoreExport Anope::map<BotInfo *> BotListByUID; typedef Anope::insensitive_map<BotInfo *> botinfo_map; +typedef Anope::map<BotInfo *> botinfouid_map; + +extern serialize_checker<botinfo_map> BotListByNick; +extern serialize_checker<botinfouid_map> BotListByUID; /** Flags settable on a bot */ @@ -60,9 +62,9 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se */ virtual ~BotInfo(); - Anope::string serialize_name() const; - serialized_data serialize(); - static void unserialize(serialized_data &); + const Anope::string serialize_name() const; + Serialize::Data serialize() const; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); void GenerateUID(); @@ -90,7 +92,7 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se /** Get the number of channels this bot is assigned to */ - unsigned GetChannelCount(); + unsigned GetChannelCount() const; /** Join this bot to a channel * @param c The channel diff --git a/include/channels.h b/include/channels.h index 43da37f51..a738f5b8b 100644 --- a/include/channels.h +++ b/include/channels.h @@ -12,7 +12,7 @@ #include "anope.h" #include "extensible.h" #include "modes.h" - +#include "serialize.h" typedef Anope::insensitive_map<Channel *> channel_map; extern CoreExport channel_map ChannelList; @@ -40,7 +40,7 @@ enum ChannelFlag const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" }; -class CoreExport Channel : public Base, public Extensible, public Flags<ChannelFlag, 3> +class CoreExport Channel : public virtual Base, public Extensible, public Flags<ChannelFlag, 3> { public: typedef std::multimap<ChannelModeName, Anope::string> ModeList; @@ -61,7 +61,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF ~Channel(); Anope::string name; /* Channel name */ - ChannelInfo *ci; /* Corresponding ChannelInfo */ + serialize_obj<ChannelInfo> ci; /* Corresponding ChannelInfo */ time_t creation_time; /* When channel was created */ /* List of users in the channel */ @@ -104,14 +104,14 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param u The user * @return A user container if found, else NULL */ - UserContainer *FindUser(User *u); + UserContainer *FindUser(const User *u) const; /** Check if a user has a status on a channel * @param u The user * @param cms The status mode, or NULL to represent no status * @return true or false */ - bool HasUserStatus(User *u, ChannelModeStatus *cms) const; + bool HasUserStatus(const User *u, ChannelModeStatus *cms) const; /** Check if a user has a status on a channel * Use the overloaded function for ChannelModeStatus* to check for no status @@ -119,7 +119,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param Name The Mode name, eg CMODE_OP, CMODE_VOICE * @return true or false */ - bool HasUserStatus(User *u, ChannelModeName Name) const; + bool HasUserStatus(const User *u, ChannelModeName Name) const; /** See if a channel has a mode * @param Name The mode name @@ -156,7 +156,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void SetMode(const BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Set a mode on a channel @@ -165,7 +165,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); + void SetMode(const BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); /** Remove a mode from a channel * @param bi The client setting the modes @@ -173,7 +173,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(const BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool EnforceMLock = true); /** * Remove a mode from a channel @@ -182,7 +182,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); + void RemoveMode(const BotInfo *bi, ChannelModeName Name, const Anope::string ¶m = "", bool EnforceMLock = true); /** Get a param from the channel * @param Name The mode @@ -196,7 +196,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF * @param EnforceMLock Should mlock be enforced on this mode change * @param cmodes The modes to set */ - void SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...); + void SetModes(const BotInfo *bi, bool EnforceMLock, const char *cmodes, ...); /** Set a string of modes internally on a channel * @param setter the setter (if it is a user) @@ -255,6 +255,6 @@ extern void do_join(const Anope::string &source, const Anope::string &channels, extern void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason); extern void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason); -extern void chan_set_correct_modes(User *user, Channel *c, int give_modes); +extern void chan_set_correct_modes(const User *user, Channel *c, int give_modes); #endif // CHANNELS_H diff --git a/include/defs.h b/include/defs.h index 098f48edd..db3c801ed 100644 --- a/include/defs.h +++ b/include/defs.h @@ -36,6 +36,7 @@ class NickAlias; class NickCore; class OperType; class Regex; +class Serializable; class Server; class ServerConfig; class Socket; diff --git a/include/extensible.h b/include/extensible.h index 1416e1983..e0281c197 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -17,12 +17,6 @@ class CoreExport ExtensibleItem virtual void OnDelete(); }; -class ExtensibleString : public Anope::string, public ExtensibleItem -{ - public: - ExtensibleString(const Anope::string &s) : Anope::string(s), ExtensibleItem() { } -}; - class CoreExport Extensible { private: @@ -92,9 +86,9 @@ class CoreExport Extensible * @param key The key parameter is an arbitary string which identifies the extension data * @return The item found */ - template<typename T> T GetExt(const Anope::string &key) + template<typename T> T GetExt(const Anope::string &key) const { - extensible_map::iterator it = this->extension_items.find(key); + extensible_map::const_iterator it = this->extension_items.find(key); if (it != this->extension_items.end()) return debug_cast<T>(it->second); @@ -106,7 +100,7 @@ class CoreExport Extensible * @param key The key parameter is an arbitary string which identifies the extension data * @return True if the item was found. */ - bool HasExt(const Anope::string &key) + bool HasExt(const Anope::string &key) const { return this->extension_items.count(key) > 0; } @@ -116,9 +110,9 @@ class CoreExport Extensible * @return This function writes a list of all extension items stored * in this object by name into the given deque and returns void. */ - void GetExtList(std::deque<Anope::string> &list) + void GetExtList(std::deque<Anope::string> &list) const { - for (extensible_map::iterator it = extension_items.begin(), it_end = extension_items.end(); it != it_end; ++it) + for (extensible_map::const_iterator it = extension_items.begin(), it_end = extension_items.end(); it != it_end; ++it) list.push_back(it->first); } }; diff --git a/include/extern.h b/include/extern.h index aff091913..09d8e69ee 100644 --- a/include/extern.h +++ b/include/extern.h @@ -21,7 +21,7 @@ /**** actions.c ****/ E bool bad_password(User *u); -E void common_unban(ChannelInfo *ci, User *u, bool full = false); +E void common_unban(const ChannelInfo *ci, User *u, bool full = false); /**** channels.c ****/ @@ -34,7 +34,7 @@ E void do_join(const Anope::string &source, const Anope::string &channels, const E void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason); E void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason); -E void chan_set_correct_modes(User *user, Channel *c, int give_modes); +E void chan_set_correct_modes(const User *user, Channel *c, int give_modes); /**** encrypt.c ****/ @@ -57,7 +57,7 @@ E std::vector<Anope::string> domains; E void InitLanguages(); E const char *translate(const char *string); E const char *translate(User *u, const char *string); -E const char *translate(NickCore *nc, const char *string); +E const char *translate(const NickCore *nc, const char *string); E const char *anope_gettext(const char *lang, const char *string); /**** main.c ****/ @@ -115,9 +115,9 @@ E bool OnError(const Anope::string &, const std::vector<Anope::string> &); E bool IsFile(const Anope::string &filename); E time_t dotime(const Anope::string &s); -E Anope::string duration(const time_t &seconds, NickCore *nc = NULL); -E Anope::string expire_left(NickCore *nc, time_t expires); -E Anope::string do_strftime(const time_t &t, NickCore *nc = NULL, bool short_output = false); +E Anope::string duration(const time_t &seconds, const NickCore *nc = NULL); +E Anope::string expire_left(const NickCore *nc, time_t expires); +E Anope::string do_strftime(const time_t &t, const NickCore *nc = NULL, bool short_output = false); E bool IsValidIdent(const Anope::string &ident); E bool IsValidHost(const Anope::string &host); @@ -137,7 +137,7 @@ E Anope::string normalizeBuffer(const Anope::string &); /* Number of generic modes we support */ E unsigned GenericChannelModes, GenericUserModes; -E std::multimap<ChannelModeName, ModeLock> def_mode_locks; +E std::multimap<ChannelModeName, ModeLock *> def_mode_locks; E void SetDefaultMLock(ServerConfig *config); /**** process.c ****/ diff --git a/include/logger.h b/include/logger.h index a6e3ca113..8cb54a754 100644 --- a/include/logger.h +++ b/include/logger.h @@ -48,11 +48,11 @@ struct LogFile class CoreExport Log { public: - BotInfo *bi; - User *u; + const BotInfo *bi; + const User *u; Command *c; Channel *chan; - ChannelInfo *ci; + const ChannelInfo *ci; Server *s; LogType Type; Anope::string Category; @@ -60,21 +60,21 @@ class CoreExport Log std::stringstream buf; - Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = NULL); + Log(LogType type = LOG_NORMAL, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_COMMAND/OVERRIDE/ADMIN */ - Log(LogType type, User *u, Command *c, ChannelInfo *ci = NULL); + Log(LogType type, const User *u, Command *c, const ChannelInfo *ci = NULL); /* LOG_CHANNEL */ - Log(User *u, Channel *c, const Anope::string &category = ""); + Log(const User *u, Channel *c, const Anope::string &category = ""); /* LOG_USER */ - explicit Log(User *u, const Anope::string &category = "", BotInfo *bi = NULL); + explicit Log(const User *u, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_SERVER */ - explicit Log(Server *s, const Anope::string &category = "", BotInfo *bi = NULL); + explicit Log(Server *s, const Anope::string &category = "", const BotInfo *bi = NULL); - explicit Log(BotInfo *b, const Anope::string &category = ""); + explicit Log(const BotInfo *b, const Anope::string &category = ""); ~Log(); diff --git a/include/mail.h b/include/mail.h index 06cfe4b39..baef45589 100644 --- a/include/mail.h +++ b/include/mail.h @@ -16,9 +16,9 @@ #include "anope.h" #include "threadengine.h" +#include "serialize.h" - -extern CoreExport bool Mail(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message); +extern CoreExport bool Mail(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message); extern CoreExport bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message); extern CoreExport bool MailValidate(const Anope::string &email); diff --git a/include/memo.h b/include/memo.h index 420def504..8ece00d6a 100644 --- a/include/memo.h +++ b/include/memo.h @@ -38,9 +38,9 @@ class CoreExport Memo : public Flags<MemoFlag>, public Serializable public: Memo(); - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); Anope::string owner; time_t time; /* When it was sent */ @@ -51,9 +51,11 @@ class CoreExport Memo : public Flags<MemoFlag>, public Serializable struct CoreExport MemoInfo { int16_t memomax; - std::vector<Memo *> memos; + serialize_checker<std::vector<Memo *> > memos; std::vector<Anope::string> ignores; + MemoInfo(); + Memo *GetMemo(unsigned index) const; unsigned GetIndex(Memo *m) const; void Del(unsigned index); void Del(Memo *m); diff --git a/include/modes.h b/include/modes.h index c8ef794bd..0fb822b7e 100644 --- a/include/modes.h +++ b/include/modes.h @@ -113,7 +113,7 @@ enum ModeClass /** This class is the basis of all modes in Anope */ -class CoreExport Mode : public Base +class CoreExport Mode : public virtual Base { public: /* Class of mode this is */ @@ -231,7 +231,7 @@ class CoreExport ChannelModeList : public ChannelMode * @param e The entry to match against * @return true on match */ - virtual bool Matches(User *u, const Entry *e) { return false; } + virtual bool Matches(const User *u, const Entry *e) { return false; } /** Called when a mask is added to a channel * @param chan The channel @@ -359,7 +359,7 @@ class StackerInfo /* The type of object this stacker info is for */ StackerType Type; /* Bot this is sent from */ - BotInfo *bi; + const BotInfo *bi; /** Add a mode to this object * @param mode The mode @@ -401,7 +401,7 @@ class CoreExport ModeManager * @param Param A param, if there is one * @param Type The type this is, user or channel */ - static void StackerAddInternal(BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type); + static void StackerAddInternal(const BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type); public: /* List of all modes Anope knows about */ @@ -469,7 +469,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param Param The param, if there is one */ - static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = ""); + static void StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from @@ -478,7 +478,7 @@ class CoreExport ModeManager * @param Set true for setting, false for removing * @param param The param, if there is one */ - static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = ""); + static void StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = ""); /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users */ @@ -531,7 +531,7 @@ class CoreExport Entry : public Flags<EntryType> * @param full True to match against a users real host and IP * @return true on match */ - bool Matches(User *u, bool full = false) const; + bool Matches(const User *u, bool full = false) const; }; #endif // MODES_H diff --git a/include/modules.h b/include/modules.h index 78ab24486..d44cbf8d9 100644 --- a/include/modules.h +++ b/include/modules.h @@ -9,14 +9,16 @@ * Based on the original code of Services by Andy Church. */ +#include "serialize.h" + #ifndef MODULES_H #define MODULES_H -#include "extensible.h" #include "base.h" #include "modes.h" #include "timers.h" #include "logger.h" +#include "extensible.h" /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. @@ -381,18 +383,13 @@ class CoreExport Module : public Extensible * @param ci The channel * @param bw The badword */ - virtual void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) { } + virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) { } /** Called before a badword is deleted from a channel * @param ci The channel * @param bw The badword */ - virtual void OnBadWordDel(ChannelInfo *ci, BadWord *bw) { } - - /** Called in findbot() - * @param nick The nick being looked up - */ - virtual void OnFindBot(const Anope::string &nick) { } + virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) { } /** Called before a bot kicks a user * @param bi The bot sending the kick @@ -513,14 +510,14 @@ class CoreExport Module : public Extensible * @param xlm The xline manager it was added to * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnAddXLine(User *u, XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; } + virtual EventReturn OnAddXLine(User *u, const XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; } /** Called before a XLine is deleted * @param u The user deleting the XLine * @param x The XLine * @param xlm The xline manager it was deleted from */ - virtual void OnDelXLine(User *u, XLine *x, XLineManager *xlm) { } + virtual void OnDelXLine(User *u, const XLine *x, XLineManager *xlm) { } /** Called when a user is checked for whether they are a services oper * @param u The user @@ -632,14 +629,14 @@ class CoreExport Module : public Extensible * @param ci The channel * @param ak The akick */ - virtual void OnAkickAdd(User *u, ChannelInfo *ci, AutoKick *ak) { } + virtual void OnAkickAdd(User *u, ChannelInfo *ci, const AutoKick *ak) { } /** Called before removing an akick from a channel * @param u The user removing the akick * @param ci The channel * @param ak The akick */ - virtual void OnAkickDel(User *u, ChannelInfo *ci, AutoKick *ak) { } + virtual void OnAkickDel(User *u, ChannelInfo *ci, const AutoKick *ak) { } /** Called after a user join a channel when we decide whether to kick them or not * @param u The user @@ -657,11 +654,6 @@ class CoreExport Module : public Extensible */ virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool ShowHidden) { } - /** Called on cs_findchan() - * @param chname The name being looked up - */ - virtual void OnFindChan(const Anope::string &chname) { } - /** Checks if access has the channel privilege 'priv'. * @param access THe access struct * @param priv The privilege being checked for @@ -776,18 +768,6 @@ class CoreExport Module : public Extensible */ virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool ShowHidden) { } - /** Called in findnick() - * Useful to modify the na returned by findnick() - * @param nick The nick being looked up - */ - virtual void OnFindNick(const Anope::string &nick) { } - - /** Called in findcore() - * Useful to modify the nc returned by findcore() - * @param nick The nick being looked up - */ - virtual void OnFindCore(const Anope::string &nick) { } - /** Check whether a users password is correct. * @param u The user * @param command The command the user is doing @@ -837,14 +817,14 @@ class CoreExport Module : public Extensible * @param mi The memo info * @param m The memo */ - virtual void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) { } + virtual void OnMemoDel(NickCore *nc, MemoInfo *mi, const Memo *m) { } /** Called when a memo is deleted * @param ci The channel of the memo being deleted * @param mi The memo info * @param m The memo */ - virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) { } + virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, const Memo *m) { } /** Called when a mode is set on a channel * @param c The channel @@ -948,6 +928,12 @@ class CoreExport Module : public Extensible * @return EVENT_STOP to stop checking modes */ virtual EventReturn OnCheckModes(Channel *c) { return EVENT_CONTINUE; } + + virtual void OnSerializeCheck(SerializeType *) { } + virtual void OnSerializableConstruct(Serializable *) { } + virtual void OnSerializableDestruct(Serializable *) { } + virtual void OnSerializePtrAssign(Serializable *) { } + virtual void OnSerializableUpdate(Serializable *) { } }; /** Implementation-specific flags which may be set in ModuleManager::Attach() @@ -961,18 +947,18 @@ enum Implementation I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert, I_OnNickAddCert, I_OnNickEraseCert, - I_OnNickInfo, I_OnFindNick, I_OnFindCore, I_OnCheckAuthentication, + I_OnNickInfo, I_OnCheckAuthentication, I_OnNickUpdate, /* ChanServ */ I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd, I_OnAccessDel, I_OnAccessClear, I_OnLevelChange, I_OnChanRegistered, I_OnChanUnsuspend, I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick, I_OnCheckModes, - I_OnChanInfo, I_OnFindChan, I_OnCheckPriv, I_OnGroupCheckPriv, + I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, /* BotServ */ I_OnBotJoin, I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign, - I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel, I_OnFindBot, + I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel, /* HostServ */ I_OnSetVhost, I_OnDeleteVhost, @@ -1001,6 +987,8 @@ enum Implementation I_OnEncrypt, I_OnDecrypt, I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd, I_OnMLock, I_OnUnMLock, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnPrivmsg, I_OnLog, + + I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializePtrAssign, I_OnSerializableUpdate, I_END }; diff --git a/include/oper.h b/include/oper.h index b3034b7c5..d388c4339 100644 --- a/include/oper.h +++ b/include/oper.h @@ -40,18 +40,18 @@ class CoreExport XLine : public Serializable bool HasNickOrReal() const; bool IsRegex() const; - Anope::string serialize_name() const; - serialized_data serialize(); - static void unserialize(serialized_data &data); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &data); }; class CoreExport XLineManager : public Service { char type; /* List of XLines in this XLineManager */ - std::vector<XLine *> XLines; + serialize_checker<std::vector<XLine *> > XLines; /* Akills can have the same IDs, sometimes */ - static std::multimap<Anope::string, XLine *, ci::less> XLinesByUID; + static serialize_checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID; public: /* List of XLine managers we check users against in XLineManager::CheckAll */ static std::list<XLineManager *> XLineManagers; @@ -118,7 +118,7 @@ class CoreExport XLineManager : public Service * @param index The index * @return The XLine, or NULL if the index is out of bounds */ - XLine *GetEntry(unsigned index); + XLine* GetEntry(unsigned index); /** Clear the XLine vector * Note: This does not remove the XLines from the IRCd @@ -138,7 +138,7 @@ class CoreExport XLineManager : public Service * @param mask The mask * @return The XLine the user matches, or NULL */ - XLine *HasEntry(const Anope::string &mask); + XLine* HasEntry(const Anope::string &mask); /** Check a user against all of the xlines in this XLineManager * @param u The user @@ -150,7 +150,7 @@ class CoreExport XLineManager : public Service * @param u The user * @param x The xline */ - virtual bool Check(User *u, XLine *x) = 0; + virtual bool Check(User *u, const XLine *x) = 0; /** Called when a user matches a xline in this XLineManager * @param u The user @@ -161,7 +161,7 @@ class CoreExport XLineManager : public Service /** Called when an XLine expires * @param x The xline */ - virtual void OnExpire(XLine *x); + virtual void OnExpire(const XLine *x); /** Called to send an XLine to the IRCd * @param u The user, if we know it diff --git a/include/protocol.h b/include/protocol.h index edfc5bd53..b471ce23f 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -84,7 +84,7 @@ class CoreExport IRCDProto virtual void SendQuit(const User *u, const char *fmt, ...); virtual void SendPing(const Anope::string &servname, const Anope::string &who); virtual void SendPong(const Anope::string &servname, const Anope::string &who); - virtual void SendJoin(User *, Channel *, const ChannelStatus *) = 0; + virtual void SendJoin(const User *, Channel *, const ChannelStatus *) = 0; virtual void SendSQLineDel(const XLine *x) { } virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u); virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...); diff --git a/include/regchannel.h b/include/regchannel.h index cc7246097..255bcc200 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -15,9 +15,11 @@ #include "extensible.h" #include "logger.h" #include "modules.h" +#include "serialize.h" typedef Anope::insensitive_map<ChannelInfo *> registered_channel_map; -extern CoreExport registered_channel_map RegisteredChannelList; + +extern serialize_checker<registered_channel_map> RegisteredChannelList; /** Flags used for the ChannelInfo class */ @@ -90,9 +92,9 @@ struct CoreExport BadWord : Serializable Anope::string word; BadWordType type; - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); }; /** Flags for auto kick @@ -110,25 +112,25 @@ class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable { public: AutoKick(); - ChannelInfo *ci; + serialize_obj<ChannelInfo> ci; /* Only one of these can be in use */ Anope::string mask; - NickCore *nc; + serialize_obj<NickCore> nc; Anope::string reason; Anope::string creator; time_t addtime; time_t last_used; - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); }; struct CoreExport ModeLock : Serializable { public: - ChannelInfo *ci; + serialize_obj<ChannelInfo> ci; bool set; ChannelModeName name; Anope::string param; @@ -137,14 +139,14 @@ struct CoreExport ModeLock : Serializable ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime); - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); }; struct CoreExport LogSetting : Serializable { - ChannelInfo *ci; + serialize_obj<ChannelInfo> ci; /* Our service name of the command */ Anope::string service_name; /* The name of the client the command is on */ @@ -155,24 +157,24 @@ struct CoreExport LogSetting : Serializable Anope::string creator; time_t created; - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); }; class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END>, public Serializable { private: - NickCore *founder; /* Channel founder */ - std::vector<ChanAccess *> access; /* List of authorized users */ - std::vector<AutoKick *> akick; /* List of users to kickban */ - std::vector<BadWord *> badwords; /* List of badwords */ + serialize_obj<NickCore> founder; /* Channel founder */ + serialize_checker<std::vector<ChanAccess *> > access; /* List of authorized users */ + serialize_checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ + serialize_checker<std::vector<BadWord *> > badwords; /* List of badwords */ std::map<Anope::string, int16_t> levels; public: - typedef std::multimap<ChannelModeName, ModeLock> ModeList; - ModeList mode_locks; - std::vector<LogSetting> log_settings; + typedef std::multimap<ChannelModeName, ModeLock *> ModeList; + serialize_checker<ModeList> mode_locks; + serialize_checker<std::vector<LogSetting *> > log_settings; /** Default constructor * @param chname The channel name @@ -182,14 +184,14 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, /** Copy constructor * @param ci The ChannelInfo to copy settings to */ - ChannelInfo(ChannelInfo &ci); + ChannelInfo(const ChannelInfo &ci); /** Default destructor */ ~ChannelInfo(); Anope::string name; /* Channel name */ - NickCore *successor; /* Who gets the channel if the founder nick is dropped or expires */ + serialize_obj<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ Anope::string desc; time_t time_registered; @@ -206,7 +208,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, Channel *c; /* Pointer to channel record (if channel is currently in use) */ /* For BotServ */ - BotInfo *bi; /* Bot used on this channel */ + serialize_obj<BotInfo> bi; /* Bot used on this channel */ Flags<BotServFlag> botflags; int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */ @@ -214,9 +216,9 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, int16_t floodlines, floodsecs; /* For FLOOD kicker */ int16_t repeattimes; /* For REPEAT kicker */ - Anope::string serialize_name() const anope_override; - serialized_data serialize() anope_override; - static void unserialize(serialized_data &); + const Anope::string serialize_name() const anope_override; + Serialize::Data serialize() const anope_override; + static Serializable* unserialize(Serializable *obj, Serialize::Data &); /** Change the founder of the channek * @params nc The new founder @@ -231,7 +233,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, /** Find which bot should send mode/topic/etc changes for this channel * @return The bot */ - BotInfo *WhoSends(); + BotInfo *WhoSends() const; /** Add an entry to the channel access list * @param access The entry @@ -245,13 +247,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * * Retrieves an entry from the access list that matches the given index. */ - ChanAccess *GetAccess(unsigned index); + ChanAccess *GetAccess(unsigned index) const; /** Retrieve the access for a user or group in the form of a vector of access entries * (as multiple entries can affect a single user). */ - AccessGroup AccessFor(User *u); - AccessGroup AccessFor(NickCore *nc); + AccessGroup AccessFor(const User *u); + AccessGroup AccessFor(const NickCore *nc); /** Get the size of the accss vector for this channel * @return The access vector size @@ -272,7 +274,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * * Clears the memory used by the given access entry and removes it from the vector. */ - void EraseAccess(ChanAccess *taccess); + void EraseAccess(const ChanAccess *taccess); /** Clear the entire channel access list * @@ -287,7 +289,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); + AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); /** Add an akick entry to the channel by reason * @param user The user who added the akick @@ -296,13 +298,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); + AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); /** Get an entry from the channel akick list * @param index The index in the akick vector * @return The akick structure, or NULL if not found */ - AutoKick *GetAkick(unsigned index); + AutoKick* GetAkick(unsigned index) const; /** Get the size of the akick vector for this channel * @return The akick vector size @@ -323,13 +325,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param type The type (SINGLE START END) * @return The badword */ - BadWord *AddBadWord(const Anope::string &word, BadWordType type); + BadWord* AddBadWord(const Anope::string &word, BadWordType type); /** Get a badword structure by index * @param index The index * @return The badword */ - BadWord *GetBadWord(unsigned index); + BadWord* GetBadWord(unsigned index) const; /** Get how many badwords are on this channel * @return The number of badwords in the vector @@ -378,7 +380,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, /** Get all of the mlocks for this channel * @return The mlocks */ - const std::multimap<ChannelModeName, ModeLock> &GetMLock() const; + const ModeList &GetMLock() const; /** Get a list of modes on a channel * @param Name The mode name to get a list of @@ -391,7 +393,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param An optional param to match with * @return The MLock, if any */ - ModeLock *GetMLock(ChannelModeName mname, const Anope::string ¶m = ""); + const ModeLock *GetMLock(ChannelModeName mname, const Anope::string ¶m = ""); /** Get the current mode locks as a string * @param complete True to show mlock parameters aswell @@ -421,7 +423,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @return the level * @throws CoreException if priv is not a valid privilege */ - int16_t GetLevel(const Anope::string &priv); + int16_t GetLevel(const Anope::string &priv) const; /** Set the level for a privilege * @param priv The privilege priv @@ -440,8 +442,8 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, }; extern ChannelInfo *cs_findchan(const Anope::string &chan); -extern bool IsFounder(User *user, ChannelInfo *ci); +extern bool IsFounder(const User *user, const ChannelInfo *ci); extern void update_cs_lastseen(User *user, ChannelInfo *ci); -extern int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret); +extern int get_idealban(const ChannelInfo *ci, User *u, Anope::string &ret); #endif // REGCHANNEL_H diff --git a/include/serialize.h b/include/serialize.h index 891af726f..82287d5ab 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -16,6 +16,7 @@ #include <sstream> #include "anope.h" +#include "base.h" namespace Serialize { @@ -30,13 +31,13 @@ class stringstream : public std::stringstream { private: Serialize::DataType type; - bool key; unsigned _max; public: stringstream(); stringstream(const stringstream &ss); Anope::string astr() const; + template<typename T> std::istream &operator>>(T &val) { std::istringstream is(this->str()); @@ -44,23 +45,31 @@ class stringstream : public std::stringstream return *this; } std::istream &operator>>(Anope::string &val); + + bool operator==(const stringstream &other) const; + bool operator!=(const stringstream &other) const; + stringstream &setType(Serialize::DataType t); Serialize::DataType getType() const; - stringstream &setKey(); - bool getKey() const; stringstream &setMax(unsigned m); unsigned getMax() const; }; +namespace Serialize +{ + typedef std::map<Anope::string, stringstream> Data; +} extern void RegisterTypes(); -class CoreExport Serializable +class CoreExport Serializable : public virtual Base { private: - static std::list<Serializable *> *serizliable_items; + static std::list<Serializable *> *serializable_items; + private: std::list<Serializable *>::iterator s_iter; + Serialize::Data last_commit; protected: Serializable(); @@ -71,35 +80,195 @@ class CoreExport Serializable Serializable &operator=(const Serializable &); public: - typedef std::map<Anope::string, stringstream> serialized_data; + unsigned int id; + + void destroy(); + + void QueueUpdate(); - virtual Anope::string serialize_name() const = 0; - virtual serialized_data serialize() = 0; + bool IsCached(); + void UpdateCache(); + + virtual const Anope::string serialize_name() const = 0; + virtual Serialize::Data serialize() const = 0; static const std::list<Serializable *> &GetItems(); }; class CoreExport SerializeType { - typedef void (*unserialize_func)(Serializable::serialized_data &); + typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &); static std::vector<Anope::string> type_order; static Anope::map<SerializeType *> types; Anope::string name; unserialize_func unserialize; + time_t timestamp; public: + std::map<unsigned int, Serializable *> objects; + SerializeType(const Anope::string &n, unserialize_func f); ~SerializeType(); const Anope::string &GetName(); - void Create(Serializable::serialized_data &data); + Serializable *Unserialize(Serializable *obj, Serialize::Data &data); + + void Check(); + + time_t GetTimestamp() const; + void UpdateTimestamp(); static SerializeType *Find(const Anope::string &name); static const std::vector<Anope::string> &GetTypeOrder(); }; +template<typename T> +class serialize_checker +{ + Anope::string name; + T obj; + + public: + serialize_checker(const Anope::string &n) : name(n) { } + + inline const T* operator->() const + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return &this->obj; + } + inline T* operator->() + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return &this->obj; + } + + inline const T& operator*() const + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return this->obj; + } + inline T& operator*() + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return this->obj; + } + + inline operator const T&() const + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return this->obj; + } + inline operator T&() + { + static SerializeType *type = SerializeType::Find(this->name); + if (type) + type->Check(); + return this->obj; + } +}; + +#include "modules.h" + +template<typename T> +class serialize_obj : public dynamic_reference_base +{ + protected: + T *ref; + + public: + serialize_obj() : ref(NULL) + { + } + + serialize_obj(T *obj) : ref(obj) + { + if (obj) + obj->AddReference(this); + } + + serialize_obj(const serialize_obj<T> &other) : ref(other.ref) + { + if (*this) + this->ref->AddReference(this); + } + + ~serialize_obj() + { + if (*this) + this->ref->DelReference(this); + } + + virtual operator bool() const + { + if (!this->invalid) + return this->ref != NULL; + return NULL; + } + + inline void operator=(T *newref) + { + if (*this) + this->ref->DelReference(this); + + this->ref = newref; + this->invalid = false; + + if (newref) + this->ref->AddReference(this); + } + + virtual inline operator T*() const + { + if (!this->invalid) + { + if (this->ref) + { + FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref)); + } + return this->ref; + } + return NULL; + } + + virtual inline T* operator*() const + { + if (!this->invalid) + { + if (this->ref) + { + FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref)); + } + return this->ref; + } + return NULL; + } + + virtual inline T* operator->() const + { + if (!this->invalid) + { + if (this->ref) + { + FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref)); + } + return this->ref; + } + return NULL; + } +}; + #endif // SERIALIZE_H diff --git a/include/servers.h b/include/servers.h index c2e56dbde..7b85a182a 100644 --- a/include/servers.h +++ b/include/servers.h @@ -137,7 +137,7 @@ class CoreExport Server : public Flags<ServerFlag> * @param source The source of the message * @param message The message */ - void Notice(BotInfo *source, const Anope::string &message); + void Notice(const BotInfo *source, const Anope::string &message); /** Find a server * @param name The name or SID/numeric diff --git a/include/service.h b/include/service.h index f9e36ff40..949e7b1a1 100644 --- a/include/service.h +++ b/include/service.h @@ -15,7 +15,7 @@ #include "anope.h" #include "modules.h" -class CoreExport Service : public Base +class CoreExport Service : public virtual Base { static Anope::map<Anope::map<Service *> > services; public: @@ -89,7 +89,7 @@ class service_reference : public dynamic_reference<T> this->name = n; } - operator bool() + operator bool() anope_override { if (this->invalid) { diff --git a/include/users.h b/include/users.h index a6510235f..e69c9d30b 100644 --- a/include/users.h +++ b/include/users.h @@ -11,6 +11,7 @@ #include "anope.h" #include "modes.h" #include "extensible.h" +#include "serialize.h" extern CoreExport Anope::insensitive_map<User *> UserListByNick; extern CoreExport Anope::map<User *> UserListByUID; @@ -36,7 +37,7 @@ typedef std::list<ChannelContainer *> UChannelList; /* Online user and channel data. */ -class CoreExport User : public Base, public Extensible +class CoreExport User : public virtual Base, public Extensible { protected: Anope::string vident; @@ -45,7 +46,7 @@ class CoreExport User : public Base, public Extensible bool OnAccess; /* If the user is on the access list of the nick theyre on */ Flags<UserModeName, UMODE_END * 2> modes; /* Bitset of mode names the user has set on them */ std::map<UserModeName, Anope::string> Params; /* Map of user modes and the params this user has */ - NickCore *nc; /* NickCore account the user is currently loggged in as */ + serialize_obj<NickCore> nc; /* NickCore account the user is currently loggged in as */ public: // XXX: exposing a tiny bit too much Anope::string nick; /* User's current nick */ @@ -159,8 +160,8 @@ class CoreExport User : public Base, public Extensible * @param fmt Format of the Message * @param ... any number of parameters */ - void SendMessage(BotInfo *source, const char *fmt, ...); - virtual void SendMessage(BotInfo *source, Anope::string msg); + void SendMessage(const BotInfo *source, const char *fmt, ...); + virtual void SendMessage(const BotInfo *source, Anope::string msg); /** Collide a nick * See the comment in users.cpp @@ -187,19 +188,19 @@ class CoreExport User : public Base, public Extensible /** Get the account the user is logged in using * @return The account or NULL */ - virtual NickCore *Account(); + virtual NickCore *Account() const; /** Check if the user is identified for their nick * @param CheckNick True to check if the user is identified to the nickname they are on too * @return true or false */ - virtual bool IsIdentified(bool CheckNick = false); + virtual bool IsIdentified(bool CheckNick = false) const; /** Check if the user is recognized for their nick (on the nicks access list) * @param CheckSecure Only returns true if the user has secure off * @return true or false */ - virtual bool IsRecognized(bool CheckSecure = true); + virtual bool IsRecognized(bool CheckSecure = true) const; /** Check if the user is a services oper * @return true if they are an oper @@ -244,32 +245,32 @@ class CoreExport User : public Base, public Extensible * @param um The user mode * @param Param Optional param for the mode */ - void SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param = ""); + void SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param = ""); /** Set a mode on the user * @param bi The client setting the mode * @param Name The mode name * @param Param Optional param for the mode */ - void SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param = ""); + void SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param = ""); /** Remove a mode on the user * @param bi The client setting the mode * @param um The user mode */ - void RemoveMode(BotInfo *bi, UserMode *um); + void RemoveMode(const BotInfo *bi, UserMode *um); /** Remove a mode from the user * @param bi The client setting the mode * @param Name The mode name */ - void RemoveMode(BotInfo *bi, UserModeName Name); + void RemoveMode(const BotInfo *bi, UserModeName Name); /** Set a string of modes on a user * @param bi The client setting the modes * @param umodes The modes */ - void SetModes(BotInfo *bi, const char *umodes, ...); + void SetModes(const BotInfo *bi, const char *umodes, ...); /** Set a string of modes on a user internally * @param umodes The modes @@ -287,7 +288,7 @@ class CoreExport User : public Base, public Extensible * @param c The channel * @return The channel container, or NULL */ - ChannelContainer *FindChannel(const Channel *c); + ChannelContainer *FindChannel(const Channel *c) const; /** Check if the user is protected from kicks and negative mode changes * @return true or false |
