diff options
| author | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
| commit | 42238034490fb5479d787bd1695750387d508200 (patch) | |
| tree | c93c62e0e1c936e656ae5b9ee1b62380ce2a194c /include/modules/os_session.h | |
| parent | d492923610d9c9146b2a2b63de38deab2cfd4ca7 (diff) | |
Rewrite serializable to have field level granularity
Represent serializable objects in a digraph, and as a result made most
object relationships implicitly defined, and use the graph to trace
references between objects to determine relationships. Edges may
also be marked as having a dependency of the object they point to,
which allows for automatic cleanup and deletion of most objects when
no longer needed.
Additionally, this allows not having to require in-memory copies of
everything when using external databases. db_sql has been rewritten
for this and now always requires a database to function. db_sql with
MySQL now requires InnoDB to make use of transactions and foreign
key constraints.
Diffstat (limited to 'include/modules/os_session.h')
| -rw-r--r-- | include/modules/os_session.h | 89 |
1 files changed, 30 insertions, 59 deletions
diff --git a/include/modules/os_session.h b/include/modules/os_session.h index 89b063104..c6af4fb03 100644 --- a/include/modules/os_session.h +++ b/include/modules/os_session.h @@ -1,49 +1,54 @@ -#ifndef OS_SESSION_H -#define OS_SESSION_H + +#pragma once struct Session { cidr addr; /* A cidr (sockaddrs + len) representing this session */ - unsigned count; /* Number of clients with this host */ - unsigned hits; /* Number of subsequent kills for a host */ + unsigned int count = 1; /* Number of clients with this host */ + unsigned int hits = 0; /* Number of subsequent kills for a host */ - Session(const sockaddrs &ip, int len) : addr(ip, len), count(1), hits(0) { } + Session(const sockaddrs &ip, int len) : addr(ip, len) { } }; -struct Exception : Serializable +class Exception : public Serialize::Object { - Anope::string mask; /* Hosts to which this exception applies */ - unsigned limit; /* Session limit for exception */ - Anope::string who; /* Nick of person who added the exception */ - Anope::string reason; /* Reason for exception's addition */ - time_t time; /* When this exception was added */ - 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); + protected: + using Serialize::Object::Object; + + public: + + virtual Anope::string GetMask() anope_abstract; + virtual void SetMask(const Anope::string &) anope_abstract; + + virtual unsigned int GetLimit() anope_abstract; + virtual void SetLimit(unsigned int) anope_abstract; + + virtual Anope::string GetWho() anope_abstract; + virtual void SetWho(const Anope::string &) anope_abstract; + + virtual Anope::string GetReason() anope_abstract; + virtual void SetReason(const Anope::string &) anope_abstract; + + virtual time_t GetTime() anope_abstract; + virtual void SetTime(const time_t &) anope_abstract; + + virtual time_t GetExpires() anope_abstract; + virtual void SetExpires(const time_t &) anope_abstract; }; +static Serialize::TypeReference<Exception> exception("Exception"); + class SessionService : public Service { public: typedef std::unordered_map<cidr, Session *, cidr::hash> SessionMap; - typedef std::vector<Exception *> ExceptionVector; SessionService(Module *m) : Service(m, "SessionService", "session") { } - virtual Exception *CreateException() anope_abstract; - - virtual void AddException(Exception *e) anope_abstract; - - virtual void DelException(Exception *e) anope_abstract; - virtual Exception *FindException(User *u) anope_abstract; virtual Exception *FindException(const Anope::string &host) anope_abstract; - virtual ExceptionVector &GetExceptions() anope_abstract; - virtual Session *FindSession(const Anope::string &ip) anope_abstract; virtual SessionMap &GetSessions() anope_abstract; @@ -69,37 +74,3 @@ namespace Event }; } -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; -} - -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; -} - -#endif - |
