From b5ff856f47d8e54d12c568462a06351633c29610 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 Nov 2011 17:29:16 -0500 Subject: Windows --- CMakeLists.txt | 2 +- docs/WIN32.txt | 24 +---- include/access.h | 13 +-- include/account.h | 4 +- include/anope.h | 6 +- include/bots.h | 2 +- include/dns.h | 10 +- include/extensible.h | 2 +- include/hashcomp.h | 33 +++---- include/modules.h | 23 +---- include/oper.h | 4 +- include/regchannel.h | 18 ++-- include/serialize.h | 149 ++++++++++++++-------------- include/services.h | 55 ++--------- include/sockets.h | 6 -- include/threadengine.h | 17 +--- modules/commands/bs_kick.cpp | 2 +- modules/commands/cs_access.cpp | 43 +------- modules/commands/cs_entrymsg.cpp | 9 +- modules/commands/cs_flags.cpp | 41 +------- modules/commands/cs_seen.cpp | 11 ++- modules/commands/cs_set_misc.cpp | 9 +- modules/commands/cs_suspend.cpp | 11 ++- modules/commands/cs_xop.cpp | 39 +------- modules/commands/hs_request.cpp | 9 +- modules/commands/ns_ajoin.cpp | 9 +- modules/commands/ns_set_misc.cpp | 9 +- modules/commands/ns_suspend.cpp | 11 ++- modules/commands/os_forbid.cpp | 6 +- modules/commands/os_forbid.h | 10 +- modules/commands/os_ignore.cpp | 5 +- modules/commands/os_ignore.h | 7 +- modules/commands/os_news.cpp | 6 +- modules/commands/os_news.h | 7 +- modules/commands/os_oper.cpp | 9 +- modules/commands/os_session.cpp | 5 +- modules/commands/os_session.h | 10 +- modules/database/db_flatfile.cpp | 57 +++++------ modules/database/db_plain.cpp | 4 +- modules/database/db_sql.cpp | 42 ++++---- modules/database/db_sql_live_read.cpp | 110 ++++++++++----------- modules/database/db_sql_live_write.cpp | 2 +- modules/extra/m_mysql.cpp | 6 +- modules/extra/m_proxyscan.cpp | 4 +- modules/extra/m_sqlite.cpp | 6 +- modules/extra/sql.h | 2 +- modules/pseudoclients/operserv.cpp | 2 - src/CMakeLists.txt | 26 ++--- src/access.cpp | 36 ++++++- src/base.cpp | 19 ++-- src/bots.cpp | 8 +- src/encrypt.cpp | 2 +- src/hashcomp.cpp | 4 +- src/init.cpp | 8 +- src/logger.cpp | 2 +- src/main.cpp | 16 ++- src/memoserv.cpp | 6 +- src/misc.cpp | 29 ------ src/modulemanager.cpp | 63 ++++-------- src/nickalias.cpp | 6 +- src/nickcore.cpp | 4 +- src/operserv.cpp | 14 +-- src/regchannel.cpp | 42 +++++--- src/socketengines/pipeengine_pipe.cpp | 8 +- src/socketengines/pipeengine_win32.cpp | 53 ---------- src/socketengines/socketengine_select.cpp | 7 +- src/sockets.cpp | 22 +---- src/threadengine.cpp | 121 +++++++++++++++++++++++ src/threadengines/threadengine_pthread.cpp | 122 ----------------------- src/threadengines/threadengine_win32.cpp | 108 -------------------- src/win32/anope_windows.h | 146 +++++++++++++-------------- src/win32/dir/dir.cpp | 47 +++++++++ src/win32/dir/dir.h | 26 +++++ src/win32/dl/dl.cpp | 30 ++++++ src/win32/dl/dl.h | 13 +++ src/win32/pipe/pipe.cpp | 61 ++++++++++++ src/win32/pipe/pipe.h | 8 ++ src/win32/pthread/pthread.cpp | 117 ++++++++++++++++++++++ src/win32/pthread/pthread.h | 34 +++++++ src/win32/sigaction/sigaction.cpp | 60 ++++++------ src/win32/sigaction/sigaction.h | 56 +++++------ src/win32/socket.cpp | 152 +++++++++++++++++++++++++++++ src/win32/socket.h | 32 ++++++ src/win32/vsvars32.bat | 66 ------------- src/win32/windows.cpp | 104 ++++---------------- 85 files changed, 1274 insertions(+), 1275 deletions(-) delete mode 100644 src/socketengines/pipeengine_win32.cpp delete mode 100644 src/threadengines/threadengine_pthread.cpp delete mode 100644 src/threadengines/threadengine_win32.cpp create mode 100644 src/win32/dir/dir.cpp create mode 100644 src/win32/dir/dir.h create mode 100644 src/win32/dl/dl.cpp create mode 100644 src/win32/dl/dl.h create mode 100644 src/win32/pipe/pipe.cpp create mode 100644 src/win32/pipe/pipe.h create mode 100644 src/win32/pthread/pthread.cpp create mode 100644 src/win32/pthread/pthread.h create mode 100644 src/win32/socket.cpp create mode 100644 src/win32/socket.h delete mode 100644 src/win32/vsvars32.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index 774f8c2e7..770a7d1ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,7 @@ if(MSVC) string(REPLACE "/GX " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) string(REPLACE "/W3 " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Set the compile flags to have warnings on the max setting (but disable a few annoying ones), exception handling turned on, the proper defines - set(CXXFLAGS "${CXXFLAGS} /W4 /wd4100 /wd4251 /wd4706 /wd4800 /wd4996 /EHs") + set(CXXFLAGS "${CXXFLAGS} /W4 /wd4100 /wd4251 /wd4706 /wd4800 /wd4996 /wd4250 /EHs") add_definitions(-DMSVCPP -D_CRT_SECURE_NO_WARNINGS) # Otherwise, we're not using Visual Studio else(MSVC) diff --git a/docs/WIN32.txt b/docs/WIN32.txt index 54a95b230..17b4e38ab 100644 --- a/docs/WIN32.txt +++ b/docs/WIN32.txt @@ -26,36 +26,16 @@ Anope for Windows (NOTE: When installing, tell CMake to add itself to the PATH.) If you have Visual C++ 10 (2010) skip ahead to step 2, else you - need to download the following free components from Microsoft. Once + need to download the following free component from Microsoft. Once downloaded, install these packages. * Microsoft Visual C++ 2010 Express Edition: http://www.microsoft.com/express/vc/ - or - - then download and install: - - * Microsoft Windows 2008 SDK: - http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&displaylang=en - - (NOTE: Although they say for Windows Server 2003 or 2008, they do infact work on all supported - versions of Windows. When installing the 2003 SDK, you should select the Custom option, and only select - to have the Microsoft Windows Core SDK installed. When installing the 2008 SDK, you should select the - Custom option, and only select to have the Developer Tools installed, but also expand that and deselect - the Visual C++ Compilers as well as the Mobile Tools. Doing this will decrease the install time as well - as the space used by the SDK.) - 2) Unpack the Anope tarball with your favorite uncompression program (WinZip or WinRAR, etc). - 3) (Note before this step: If you fall under one of the situations at the end of Step 1 where it says that the - SDK will not work out of the box, do not bring up the Visual C++ Command Prompt by using the link in - the Windows Start Menu. Instead, edit vsvars32.bat in the directory where you unpacked the source code - in step 2, so the first line that says "@SET VSINSTALLDIR=" has the directory where you installed - Visual C++ Express to, if different from the default. Save the file and then run it instead.) - - Bring up the Visual C++ Command Prompt; This will launch a + 3) Bring up the Visual C++ Command Prompt; This will launch a DOS Command Prompt like window, which will set the environment properties needed to make Anope. diff --git a/include/access.h b/include/access.h index d86539d8f..1e5f6a496 100644 --- a/include/access.h +++ b/include/access.h @@ -1,7 +1,7 @@ #ifndef ACCESS_H #define ACCESS_H -struct Privilege +struct CoreExport Privilege { Anope::string name; Anope::string desc; @@ -10,7 +10,7 @@ struct Privilege bool operator==(const Privilege &other); }; -class PrivilegeManager +class CoreExport PrivilegeManager { static std::vector privs; public: @@ -31,7 +31,7 @@ class CoreExport AccessProvider : public Service virtual ChanAccess *Create() = 0; }; -class CoreExport ChanAccess +class CoreExport ChanAccess : public Serializable { public: AccessProvider *provider; @@ -41,11 +41,12 @@ class CoreExport ChanAccess time_t last_seen; time_t created; - virtual Anope::string serialize_name() = 0; - virtual SerializableBase::serialized_data serialize() = 0; - ChanAccess(AccessProvider *p); virtual ~ChanAccess(); + + serialized_data serialize(); + static void unserialize(serialized_data &); + virtual bool Matches(User *u, NickCore *nc) = 0; virtual bool HasPriv(const Anope::string &name) = 0; virtual Anope::string Serialize() = 0; diff --git a/include/account.h b/include/account.h index 395d883dc..2d12c99cb 100644 --- a/include/account.h +++ b/include/account.h @@ -93,7 +93,7 @@ const Anope::string NickCoreFlagStrings[] = { "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "FORBIDDEN", "UNCONFIRMED", "" }; -class CoreExport NickAlias : public Extensible, public Flags, public Serializable +class CoreExport NickAlias : public Extensible, public Flags, public Serializable { public: /** Default constructor @@ -132,7 +132,7 @@ class CoreExport NickAlias : public Extensible, public Flags, public Serializable +class CoreExport NickCore : public Extensible, public Flags, public Serializable { public: /** Default constructor diff --git a/include/anope.h b/include/anope.h index 60eb59775..837f0c82e 100644 --- a/include/anope.h +++ b/include/anope.h @@ -21,7 +21,7 @@ class Message; namespace Anope { template class map : public std::map { }; - template class insensitive_map : public std::map > { }; + template class insensitive_map : public std::map { }; /** * A wrapper string class around all the other string classes, this class will @@ -265,7 +265,7 @@ namespace Anope { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = tolower(new_string[i]); + new_string[i] = static_cast(tolower(new_string[i])); return new_string; } @@ -276,7 +276,7 @@ namespace Anope { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = toupper(new_string[i]); + new_string[i] = static_cast(toupper(new_string[i])); return new_string; } diff --git a/include/bots.h b/include/bots.h index 64d185840..00c0c87a1 100644 --- a/include/bots.h +++ b/include/bots.h @@ -32,7 +32,7 @@ enum BotFlag static const Anope::string BotFlagString[] = { "BEGIN", "CORE", "PRIVATE", "CONF", "" }; -class CoreExport BotInfo : public User, public Flags, public Serializable +class CoreExport BotInfo : public User, public Flags, public Serializable { public: uint32_t chancount; diff --git a/include/dns.h b/include/dns.h index d72cc08de..23e779b67 100644 --- a/include/dns.h +++ b/include/dns.h @@ -52,7 +52,7 @@ class Module; struct DNSQuery; class DNSPacket; -struct Question +struct CoreExport Question { Anope::string name; QueryType type; @@ -62,7 +62,7 @@ struct Question Question(const Anope::string &, QueryType, unsigned short = 1); }; -struct ResourceRecord : public Question +struct CoreExport ResourceRecord : public Question { unsigned int ttl; Anope::string rdata; @@ -72,7 +72,7 @@ struct ResourceRecord : public Question ResourceRecord(const Question &); }; -struct DNSQuery +struct CoreExport DNSQuery { std::vector questions; std::vector answers, authorities, additional; @@ -134,11 +134,11 @@ class DNSPacket : public DNSQuery unsigned short Pack(unsigned char *output, unsigned short output_size); }; -/** DNS manager, manages the connection and all requests +/** DNS manager, manages all requests */ class CoreExport DNSManager : public Timer, public Socket { - typedef std::multimap > cache_map; + typedef std::multimap cache_map; cache_map cache; sockaddrs addrs; public: diff --git a/include/extensible.h b/include/extensible.h index c5de2dae4..c4dd3a0f3 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -10,7 +10,7 @@ #include "anope.h" #include "hashcomp.h" -class ExtensibleItem +class CoreExport ExtensibleItem { public: ExtensibleItem(); diff --git a/include/hashcomp.h b/include/hashcomp.h index d78b01857..a4a86889f 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -139,6 +139,16 @@ namespace irc /** This typedef declares irc::string based upon irc_char_traits. */ typedef std::basic_string > string; + + struct CoreExport less + { + /** Compare two Anope::strings as irc::strings and find which one is less + * @param s1 The first string + * @param s2 The second string + * @return true if s1 < s2, else false + */ + bool operator()(const Anope::string &s1, const Anope::string &s2) const; + }; } /** The ci namespace contains a number of helper classes. @@ -193,16 +203,9 @@ namespace ci /** This typedef declares ci::string based upon ci_char_traits. */ typedef std::basic_string > string; -} -namespace std -{ - /** An overload for std::less that uses Anope::string, passed for the third template argument - * to std::map and std::multimap - */ - template<> struct CoreExport less + struct CoreExport less { - public: /** Compare two Anope::strings as ci::strings and find which one is less * @param s1 The first string * @param s2 The second string @@ -210,20 +213,6 @@ namespace std */ bool operator()(const Anope::string &s1, const Anope::string &s2) const; }; - - /** An overload for std;:less that uses Anope::string, passed for the third tempalte argument - * to std::map and std::multimap - */ - template<> struct CoreExport less - { - public: - /** Compare two Anope::strings as irc::strings and find which one is less - * @param s1 The first string - * @param s2 The second string - * @return true if s1 < s2, else false - */ - bool operator()(const Anope::string &s1, const Anope::string &s2) const; - }; } /* Define operators for + and == with irc::string to std::string for easy assignment diff --git a/include/modules.h b/include/modules.h index 695917dbf..d3a43cd8a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -18,27 +18,6 @@ #include "timers.h" #include "hashcomp.h" -/* Cross OS compatibility macros */ -#ifdef _WIN32 - typedef HMODULE ano_module_t; - -# define dlopen(file, unused) LoadLibrary(file) -# define dlsym(file, symbol) (HMODULE)GetProcAddress(file, symbol) -# define dlclose(file) FreeLibrary(file) ? 0 : 1 -# define ano_modclearerr() SetLastError(0) -# define ano_moderr() (Anope::LastError().empty() ? NULL : Anope::LastError().c_str()) -#else - typedef void * ano_module_t; - -/* We call dlerror() here because it clears the module error after being - * called. This previously read 'errno = 0', but that didn't work on - * all POSIX-compliant architectures. This way the error is guaranteed - * to be cleared, POSIX-wise. -GD - */ -# define ano_modclearerr() dlerror() -# define ano_moderr() dlerror() -#endif - /** Possible return types from events. */ enum EventReturn @@ -215,7 +194,7 @@ class CoreExport Module : public Extensible /** Handle for this module, obtained from dlopen() */ - ano_module_t handle; + void *handle; /** Time this module was created */ diff --git a/include/oper.h b/include/oper.h index 1537681a1..62f783282 100644 --- a/include/oper.h +++ b/include/oper.h @@ -11,7 +11,7 @@ class XLineManager; -class CoreExport XLine : public Serializable +class CoreExport XLine : public Serializable { protected: XLine(); @@ -42,7 +42,7 @@ class CoreExport XLineManager : public Service char type; /* List of XLines in this XLineManager */ std::vector XLines; - static std::map > XLinesByUID; + static std::map XLinesByUID; public: /* List of XLine managers we check users against in XLineManager::CheckAll */ static std::list XLineManagers; diff --git a/include/regchannel.h b/include/regchannel.h index e22d64e5f..3f6c29581 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -75,12 +75,13 @@ enum BadWordType }; /* Structure used to contain bad words. */ -struct BadWord : Serializable +struct CoreExport BadWord : Serializable { ChannelInfo *ci; Anope::string word; BadWordType type; + BadWord(); serialized_data serialize(); static void unserialize(serialized_data &); }; @@ -96,10 +97,10 @@ enum AutoKickFlag const Anope::string AutoKickFlagString[] = { "AK_ISNICK", "" }; /* AutoKick data. */ -class AutoKick : public Flags, public Serializable +class CoreExport AutoKick : public Flags, public Serializable { public: - AutoKick() : Flags(AutoKickFlagString) { } + AutoKick(); ChannelInfo *ci; /* Only one of these can be in use */ Anope::string mask; @@ -114,9 +115,9 @@ class AutoKick : public Flags, public Serializable static void unserialize(serialized_data &); }; -struct ModeLock : Serializable +struct CoreExport ModeLock : Serializable { - ModeLock() { } + ModeLock(); public: ChannelInfo *ci; bool set; @@ -125,13 +126,13 @@ struct ModeLock : Serializable Anope::string setter; time_t created; - ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime) : ci(ch), set(s), name(n), param(p), setter(se), created(c) { } + ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime); serialized_data serialize(); static void unserialize(serialized_data &); }; -struct LogSetting : Serializable +struct CoreExport LogSetting : Serializable { ChannelInfo *ci; /* Our service name of the command */ @@ -144,11 +145,12 @@ struct LogSetting : Serializable Anope::string creator; time_t created; + LogSetting(); serialized_data serialize(); static void unserialize(serialized_data &); }; -class CoreExport ChannelInfo : public Extensible, public Flags, public Serializable +class CoreExport ChannelInfo : public Extensible, public Flags, public Serializable { private: NickCore *founder; /* Channel founder */ diff --git a/include/serialize.h b/include/serialize.h index 7f12cf176..8bd26bfda 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -14,11 +14,11 @@ namespace Serialize private: DataType type; bool key; - unsigned max; + unsigned _max; public: - stringstream() : std::stringstream(), type(DT_TEXT), key(false), max(0) { } - stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(DT_TEXT), key(false), max(0) { } + stringstream() : std::stringstream(), type(DT_TEXT), key(false), _max(0) { } + stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(DT_TEXT), key(false), _max(0) { } Anope::string astr() const { return this->str(); } template std::istream &operator>>(T &val) { @@ -51,116 +51,117 @@ namespace Serialize } stringstream &setMax(unsigned m) { - this->max = m; + this->_max = m; return *this; } unsigned getMax() const { - return this->max; + return this->_max; } }; } -class SerializableBase; - -extern std::vector serialized_types; -extern std::list *serialized_items; extern void RegisterTypes(); -class SerializableBase +class CoreExport Serializable { - public: - typedef std::map serialized_data; + private: + static std::list serizliable_items; - virtual ~SerializableBase() { } - virtual Anope::string serialize_name() = 0; - virtual serialized_data serialize() = 0; - virtual void alloc(serialized_data &) = 0; -}; + Anope::string serizliable_name; + std::list::iterator s_iter; -template class Serializable : public SerializableBase -{ - public: - static class SerializableAllocator : public SerializableBase + Serializable() { - Anope::string name; + throw CoreException(); + } - public: - SerializableAllocator() - { - } + protected: + Serializable(const Anope::string &n) : serizliable_name(n) + { + serizliable_items.push_front(this); + this->s_iter = serizliable_items.begin(); + } - void Register(const Anope::string &n, int pos = -1) - { - this->name = n; - serialized_types.insert(serialized_types.begin() + (pos < 0 ? serialized_types.size() : pos), this); - } + Serializable(const Serializable &) + { + serizliable_items.push_front(this); + this->s_iter = serizliable_items.begin(); + } - void Unregister() - { - std::vector::iterator it = std::find(serialized_types.begin(), serialized_types.end(), this); - if (it != serialized_types.end()) - serialized_types.erase(it); - } + virtual ~Serializable() + { + serizliable_items.erase(this->s_iter); + } - Anope::string serialize_name() - { - if (this->name.empty()) - throw CoreException(); - return this->name; - } + Serializable &operator=(const Serializable &) + { + return *this; + } - serialized_data serialize() - { - throw CoreException(); - } + public: + typedef std::map serialized_data; - void alloc(serialized_data &data) - { - Type::unserialize(data); - } - } Alloc; + const Anope::string &GetSerializeName() + { + return this->serizliable_name; + } - private: - std::list::iterator s_iter; + virtual serialized_data serialize() = 0; - protected: - Serializable() + static const std::list &GetItems() { - if (serialized_items == NULL) - serialized_items = new std::list(); - serialized_items->push_front(this); - this->s_iter = serialized_items->begin(); + return serizliable_items; } +}; - Serializable(const Serializable &) +class CoreExport SerializeType +{ + typedef void (*unserialize_func)(Serializable::serialized_data &); + + static std::vector type_order; + static Anope::map types; + + Anope::string name; + unserialize_func unserialize; + + public: + SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f) { - serialized_items->push_front(this); - this->s_iter = serialized_items->begin(); + type_order.push_back(this->name); + types[this->name] = this; } - ~Serializable() + ~SerializeType() { - serialized_items->erase(this->s_iter); + std::vector::iterator it = std::find(type_order.begin(), type_order.end(), this->name); + if (it != type_order.end()) + type_order.erase(it); + types.erase(this->name); } - Serializable &operator=(const Serializable &) + const Anope::string &GetName() { - return *this; + return this->name; } - public: - Anope::string serialize_name() + void Create(Serializable::serialized_data &data) { - return Alloc.serialize_name(); + this->unserialize(data); } - void alloc(serialized_data &) + static SerializeType *Find(const Anope::string &name) { - throw CoreException(); + Anope::map::iterator it = types.find(name); + if (it != types.end()) + return it->second; + return NULL; } -}; -template typename Serializable::SerializableAllocator Serializable::Alloc; + static const std::vector &GetTypeOrder() + { + return type_order; + } +}; #endif // SERIALIZE_H diff --git a/include/services.h b/include/services.h index 3ce8ad86f..c6cb6aa57 100644 --- a/include/services.h +++ b/include/services.h @@ -20,19 +20,16 @@ #define BUFSIZE 1024 -/* Some SUN fixs */ -#ifdef __sun -# ifndef INADDR_NONE -# define INADDR_NONE (-1) -# endif -#endif - #include #include #include #include #include +#if HAVE_STRINGS_H +# include +#endif + #include #include #include @@ -40,9 +37,9 @@ #include /* for umask() on some systems */ #include -#include #include #include +#include #if GETTEXT_FOUND # include @@ -57,11 +54,12 @@ # include # include # include +# include # include +# include # define DllExport # define CoreExport # define MARK_DEPRECATED __attribute((deprecated)) -# define DeleteFile unlink #else # include "anope_windows.h" #endif @@ -73,35 +71,6 @@ # define FORMAT(type, fmt, start) #endif -#if HAVE_STRINGS_H -# include -#endif - -#ifdef _AIX -/* Some AIX boxes seem to have bogus includes that don't have these - * prototypes. */ -extern int strcasecmp(const char *, const char *); -extern int strncasecmp(const char *, const char *, size_t); -# undef FD_ZERO -# define FD_ZERO(p) memset((p), 0, sizeof(*(p))) -#endif /* _AIX */ - -/* Alias stricmp/strnicmp to strcasecmp/strncasecmp if we have the latter - * but not the former. */ -#if !HAVE_STRICMP && HAVE_STRCASECMP -# define stricmp strcasecmp -# define strnicmp strncasecmp -#endif - -/* We have our own versions of toupper()/tolower(). */ -#include -#undef tolower -#undef toupper -#define tolower tolower_ -#define toupper toupper_ -extern int toupper(char); -extern int tolower(char); - /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. * It defines the class factory and external AnopeInit and AnopeFini functions. @@ -115,12 +84,6 @@ extern int tolower(char); } \ BOOLEAN WINAPI DllMain(HINSTANCE, DWORD nReason, LPVOID) \ { \ - switch (nReason) \ - { \ - case DLL_PROCESS_ATTACH: \ - case DLL_PROCESS_DETACH: \ - break; \ - } \ return TRUE; \ } \ extern "C" DllExport void AnopeFini(x *); \ @@ -343,7 +306,7 @@ template class Flags class Module; -template class CoreExport Service : public Base +template class Service : public Base { static Anope::map services; public: @@ -538,7 +501,7 @@ const Anope::string MemoFlagStrings[] = { /* Memo info structures. Since both nicknames and channels can have memos, * we encapsulate memo data in a MemoList to make it easier to handle. */ -class CoreExport Memo : public Flags, public Serializable +class CoreExport Memo : public Flags, public Serializable { public: Memo(); diff --git a/include/sockets.h b/include/sockets.h index b8d6033ee..444daced7 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -16,12 +16,6 @@ #define NET_BUFSIZE 65535 -#ifdef _WIN32 -# define CloseSocket closesocket -#else -# define CloseSocket close -#endif - /** A sockaddr union used to combine IPv4 and IPv6 sockaddrs */ union CoreExport sockaddrs diff --git a/include/threadengine.h b/include/threadengine.h index 06c4900a4..b840092d4 100644 --- a/include/threadengine.h +++ b/include/threadengine.h @@ -1,17 +1,6 @@ #ifndef THREADENGINE_H #define THREADENGINE_H -#ifdef _WIN32 -typedef HANDLE ThreadHandle; -typedef CRITICAL_SECTION MutexHandle; -typedef HANDLE CondHandle; -#else -# include -typedef pthread_t ThreadHandle; -typedef pthread_mutex_t MutexHandle; -typedef pthread_cond_t CondHandle; -#endif - class Thread; class CoreExport Thread : public Pipe, public Extensible @@ -22,7 +11,7 @@ class CoreExport Thread : public Pipe, public Extensible public: /* Handle for this thread */ - ThreadHandle Handle; + pthread_t Handle; /** Threads constructor */ @@ -66,7 +55,7 @@ class CoreExport Mutex { protected: /* A mutex, used to keep threads in sync */ - MutexHandle mutex; + pthread_mutex_t mutex; public: /** Constructor @@ -96,7 +85,7 @@ class CoreExport Condition : public Mutex { private: /* A condition */ - CondHandle cond; + pthread_cond_t cond; public: /** Constructor diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index b53510c10..26ae934a7 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -599,7 +599,7 @@ struct BanData : public ExtensibleItem }; private: - typedef std::map > data_type; + typedef std::map data_type; data_type data_map; public: diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 7cfbb303d..7a9c3b9a5 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -19,16 +19,16 @@ enum ACCESS_FOUNDER = 10001 }; -static std::map > defaultLevels; +static std::map defaultLevels; static void reset_levels(ChannelInfo *ci) { ci->ClearLevels(); - for (std::map >::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) + for (std::map::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) ci->SetLevel(it->first, it->second); } -class AccessChanAccess : public ChanAccess, public Serializable +class AccessChanAccess : public ChanAccess { public: int level; @@ -86,41 +86,6 @@ class AccessChanAccess : public ChanAccess, public Serializableprovider->name; - data["ci"] << this->ci->name; - data["mask"] << this->mask; - data["creator"] << this->creator; - data["last_seen"].setType(Serialize::DT_INT) << this->last_seen; - data["created"].setType(Serialize::DT_INT) << this->created; - data["level"].setType(Serialize::DT_INT) << this->level; - - return data; - } - - static void unserialize(SerializableBase::serialized_data &data) - { - service_reference aprovider(data["provider"].astr()); - ChannelInfo *ci = cs_findchan(data["ci"].astr()); - if (!aprovider || !ci) - return; - - AccessChanAccess *access = new AccessChanAccess(aprovider); - access->provider = aprovider; - access->ci = ci; - data["mask"] >> access->mask; - data["creator"] >> access->creator; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - data["level"] >> access->level; - - ci->AddAccess(access); - } }; class AccessAccessProvider : public AccessProvider @@ -868,8 +833,6 @@ class CSAccess : public Module { this->SetAuthor("Anope"); - Serializable::Alloc.Register("AccessChanAccess"); - Implementation i[] = { I_OnReload, I_OnCreateChan, I_OnGroupCheckPriv }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index 7e927a343..d3fd7270c 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -13,14 +13,14 @@ #include "module.h" -struct EntryMsg : Serializable +struct EntryMsg : Serializable { ChannelInfo *ci; Anope::string creator; Anope::string message; time_t when; - EntryMsg(ChannelInfo *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) + EntryMsg(ChannelInfo *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) : Serializable("EntryMsg") { this->ci = c; @@ -195,16 +195,15 @@ class CommandEntryMessage : public Command class CSEntryMessage : public Module { + SerializeType entrymsg_type; CommandEntryMessage commandentrymsg; public: - CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), commandentrymsg(this) + CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), entrymsg_type("EntryMsg", EntryMsg::unserialize), commandentrymsg(this) { this->SetAuthor("Anope"); this->OnReload(); - - Serializable::Alloc.Register("EntryMsg"); } void OnJoinChannel(User *u, Channel *c) diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index 1b790b5f1..e81589968 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -15,7 +15,7 @@ static std::map defaultFlags; -class FlagsChanAccess : public ChanAccess, public Serializable +class FlagsChanAccess : public ChanAccess { public: std::set flags; @@ -65,41 +65,6 @@ class FlagsChanAccess : public ChanAccess, public Serializable return Anope::string(buffer.begin(), buffer.end()); } - - Anope::string serialize_name() { return "FlagsChanAccess"; } - serialized_data serialize() - { - serialized_data data; - - data["provider"] << this->provider->name; - data["ci"] << this->ci->name; - data["mask"] << this->mask; - data["creator"] << this->creator; - data["last_seen"].setType(Serialize::DT_INT) << this->last_seen; - data["created"].setType(Serialize::DT_INT) << this->created; - data["flags"] << this->Serialize(); - - return data; - } - - static void unserialize(SerializableBase::serialized_data &data) - { - service_reference aprovider(data["provider"].astr()); - ChannelInfo *ci = cs_findchan(data["ci"].astr()); - if (!aprovider || !ci) - return; - - FlagsChanAccess *access = new FlagsChanAccess(aprovider); - access->provider = aprovider; - access->ci = ci; - data["mask"] >> access->mask; - data["creator"] >> access->creator; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - access->Unserialize(data["flags"].astr()); - - ci->AddAccess(access); - } }; class FlagsAccessProvider : public AccessProvider @@ -387,7 +352,7 @@ class CommandCSFlags : public Command source.Reply(" "); source.Reply(_("The available flags are:")); - typedef std::multimap > reverse_map; + typedef std::multimap reverse_map; reverse_map reverse; for (std::map::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) reverse.insert(std::make_pair(it->second, it->first)); @@ -420,8 +385,6 @@ class CSFlags : public Module ModuleManager::Attach(i, this, 1); this->OnReload(); - - Serializable::Alloc.Register("FlagsChanAccess"); } void OnReload() diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index f828e181d..3c63e56ed 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -23,7 +23,7 @@ struct SeenInfo; typedef Anope::insensitive_map database_map; database_map database; -struct SeenInfo : Serializable +struct SeenInfo : Serializable { Anope::string nick; Anope::string vhost; @@ -33,6 +33,10 @@ struct SeenInfo : Serializable Anope::string message; // for part/kick/quit time_t last; // the time when the user was last seen + SeenInfo() : Serializable("SeenInfo") + { + } + serialized_data serialize() { serialized_data data; @@ -304,11 +308,12 @@ class DataBasePurger : public CallBack class CSSeen : public Module { + SerializeType seeninfo_type; CommandSeen commandseen; CommandOSSeen commandosseen; DataBasePurger purger; public: - CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), commandseen(this), commandosseen(this), purger(this) + CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), seeninfo_type("SeenInfo", SeenInfo::unserialize), commandseen(this), commandosseen(this), purger(this) { this->SetAuthor("Anope"); @@ -322,8 +327,6 @@ class CSSeen : public Module ModuleManager::Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); OnReload(); - - Serializable::Alloc.Register("SeenInfo"); } void OnReload() diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index e438210e3..3329d3aa2 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -12,13 +12,13 @@ #include "module.h" -struct CSMiscData : Anope::string, ExtensibleItem, Serializable +struct CSMiscData : Anope::string, ExtensibleItem, Serializable { ChannelInfo *ci; Anope::string name; Anope::string data; - CSMiscData(ChannelInfo *c, const Anope::string &n, const Anope::string &d) : ci(c), name(n), data(d) + CSMiscData(ChannelInfo *c, const Anope::string &n, const Anope::string &d) : Serializable("CSMiscData"), ci(c), name(n), data(d) { } @@ -96,19 +96,18 @@ class CommandCSSASetMisc : public CommandCSSetMisc class CSSetMisc : public Module { + SerializeType csmiscdata_type; CommandCSSetMisc commandcssetmisc; CommandCSSASetMisc commandcssasetmisc; public: CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandcssetmisc(this), commandcssasetmisc(this) + csmiscdata_type("CSMiscData", CSMiscData::unserialize), commandcssetmisc(this), commandcssasetmisc(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnChanInfo }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("CSMisc"); } void OnChanInfo(CommandSource &source, ChannelInfo *ci, bool ShowHidden) diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index f076ae361..48dcd4045 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -13,11 +13,15 @@ #include "module.h" -struct ChanSuspend : ExtensibleItem, Serializable +struct ChanSuspend : ExtensibleItem, Serializable { Anope::string chan; time_t when; + ChanSuspend() : Serializable("ChanSuspend") + { + } + serialized_data serialize() { serialized_data sd; @@ -195,19 +199,18 @@ class CommandCSUnSuspend : public Command class CSSuspend : public Module { + SerializeType chansuspend_type; CommandCSSuspend commandcssuspend; CommandCSUnSuspend commandcsunsuspend; public: CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandcssuspend(this), commandcsunsuspend(this) + chansuspend_type("ChanSuspend", ChanSuspend::unserialize), commandcssuspend(this), commandcsunsuspend(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnPreChanExpire }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("ChanSuspend"); } ~CSSuspend() diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index d23b24b81..9279688a6 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -90,7 +90,7 @@ static struct XOPAccess } }; -class XOPChanAccess : public ChanAccess, public Serializable +class XOPChanAccess : public ChanAccess { public: XOPType type; @@ -188,41 +188,6 @@ class XOPChanAccess : public ChanAccess, public Serializable return max; } } - - Anope::string serialize_name() { return "XOPChanAccess"; } - serialized_data serialize() - { - serialized_data data; - - data["provider"] << this->provider->name; - data["ci"] << this->ci->name; - data["mask"] << this->mask; - data["creator"] << this->creator; - data["last_seen"] << this->last_seen; - data["created"] << this->created; - data["type"] << this->Serialize(); - - return data; - } - - static void unserialize(SerializableBase::serialized_data &data) - { - service_reference aprovider(data["provider"].astr()); - ChannelInfo *ci = cs_findchan(data["ci"].astr()); - if (!aprovider || !ci) - return; - - XOPChanAccess *access = new XOPChanAccess(aprovider); - access->provider = aprovider; - access->ci = ci; - data["mask"] >> access->mask; - data["creator"] >> access->creator; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - access->Unserialize(data["type"].astr()); - - ci->AddAccess(access); - } }; class XOPAccessProvider : public AccessProvider @@ -902,8 +867,6 @@ class CSXOP : public Module accessprovider(this), commandcsqop(this), commandcssop(this), commandcsaop(this), commandcshop(this), commandcsvop(this) { this->SetAuthor("Anope"); - - Serializable::Alloc.Register("XOPChanAccess"); } }; diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 82bba1bbc..f7a904979 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -23,13 +23,17 @@ static bool HSRequestMemoOper = false; void req_send_memos(CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost); -struct HostRequest : ExtensibleItem, Serializable +struct HostRequest : ExtensibleItem, Serializable { Anope::string nick; Anope::string ident; Anope::string host; time_t time; + HostRequest() : Serializable("HostRequest") + { + } + serialized_data serialize() { serialized_data data; @@ -326,6 +330,7 @@ class CommandHSWaiting : public HSListBase class HSRequest : public Module { + SerializeType request_type; CommandHSRequest commandhsrequest; CommandHSActivate commandhsactive; CommandHSReject commandhsreject; @@ -333,7 +338,7 @@ class HSRequest : public Module public: HSRequest(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandhsrequest(this), commandhsactive(this), commandhsreject(this), commandhswaiting(this) + request_type("HSRequest", HostRequest::unserialize), commandhsrequest(this), commandhsactive(this), commandhsreject(this), commandhswaiting(this) { this->SetAuthor("Anope"); diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index d7bde685e..5e2a99aa0 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -13,11 +13,11 @@ #include "module.h" -struct AJoinList : std::vector >, ExtensibleItem, Serializable +struct AJoinList : std::vector >, ExtensibleItem, Serializable { NickCore *nc; - AJoinList(NickCore *n) : nc(n) { } + AJoinList(NickCore *n) : Serializable("AJoinList"), nc(n) { } serialized_data serialize() { @@ -159,18 +159,17 @@ class CommandNSAJoin : public Command class NSAJoin : public Module { + SerializeType ajoinlist_type; CommandNSAJoin commandnsajoin; public: NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandnsajoin(this) + ajoinlist_type("AJoinList", AJoinList::unserialize), commandnsajoin(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnNickIdentify }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("AJoinList"); } void OnNickIdentify(User *u) diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index adf63e9d7..1cfd4fad3 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -13,13 +13,13 @@ #include "module.h" -struct NSMiscData : Anope::string, ExtensibleItem, Serializable +struct NSMiscData : Anope::string, ExtensibleItem, Serializable { NickCore *nc; Anope::string name; Anope::string data; - NSMiscData(NickCore *ncore, const Anope::string &n, const Anope::string &d) : nc(ncore), name(n), data(d) + NSMiscData(NickCore *ncore, const Anope::string &n, const Anope::string &d) : Serializable("NSMiscdata"), nc(ncore), name(n), data(d) { } @@ -107,19 +107,18 @@ class CommandNSSASetMisc : public CommandNSSetMisc class NSSetMisc : public Module { + SerializeType nsmiscdata_type; CommandNSSetMisc commandnssetmisc; CommandNSSASetMisc commandnssasetmisc; public: NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandnssetmisc(this), commandnssasetmisc(this) + nsmiscdata_type("NSMiscData", NSMiscData::unserialize), commandnssetmisc(this), commandnssasetmisc(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnNickInfo }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("NSMisc"); } void OnNickInfo(CommandSource &source, NickAlias *na, bool ShowHidden) diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index bab14ad86..9f7e3a1b8 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -13,11 +13,15 @@ #include "module.h" -struct NickSuspend : ExtensibleItem, Serializable +struct NickSuspend : ExtensibleItem, Serializable { Anope::string nick; time_t when; + NickSuspend() : Serializable("NickSuspend") + { + } + serialized_data serialize() { serialized_data sd; @@ -196,19 +200,18 @@ class CommandNSUnSuspend : public Command class NSSuspend : public Module { + SerializeType nicksuspend_type; CommandNSSuspend commandnssuspend; CommandNSUnSuspend commandnsunsuspend; public: NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandnssuspend(this), commandnsunsuspend(this) + nicksuspend_type("NickSuspend", NickSuspend::unserialize), commandnssuspend(this), commandnsunsuspend(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnPreNickExpire }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("NickSuspend"); } ~NSSuspend() diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index 83b9829fa..4c6ead48f 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -210,20 +210,18 @@ class CommandOSForbid : public Command class OSForbid : public Module { + SerializeType forbiddata_type; MyForbidService forbidService; CommandOSForbid commandosforbid; public: OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - forbidService(this), commandosforbid(this) + forbiddata_type("ForbidData", ForbidData::unserialize), forbidService(this), commandosforbid(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnUserConnect, I_OnUserNickChange, I_OnJoinChannel, I_OnPreCommand }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - - Serializable::Alloc.Register("Forbid"); } void OnUserConnect(dynamic_reference &u, bool &exempt) diff --git a/modules/commands/os_forbid.h b/modules/commands/os_forbid.h index 1aac412a3..00e769919 100644 --- a/modules/commands/os_forbid.h +++ b/modules/commands/os_forbid.h @@ -9,7 +9,7 @@ enum ForbidType FT_EMAIL }; -struct ForbidData : Serializable +struct ForbidData : Serializable { Anope::string mask; Anope::string creator; @@ -18,6 +18,10 @@ struct ForbidData : Serializable time_t expires; ForbidType type; + ForbidData() : Serializable("ForbidData") + { + } + serialized_data serialize(); static void unserialize(serialized_data &data); }; @@ -38,7 +42,7 @@ class ForbidService : public Service static service_reference forbid_service("forbid"); -SerializableBase::serialized_data ForbidData::serialize() +Serializable::serialized_data ForbidData::serialize() { serialized_data data; @@ -52,7 +56,7 @@ SerializableBase::serialized_data ForbidData::serialize() return data; } -void ForbidData::unserialize(SerializableBase::serialized_data &data) +void ForbidData::unserialize(serialized_data &data) { if (!forbid_service) return; diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index 6462284f5..52edd04e9 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -278,20 +278,19 @@ class CommandOSIgnore : public Command class OSIgnore : public Module { + SerializeType ignoredata_type; OSIgnoreService osignoreservice; CommandOSIgnore commandosignore; public: OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - osignoreservice(this), commandosignore(this) + ignoredata_type("IgnoreData", IgnoreData::unserialize), osignoreservice(this), commandosignore(this) { this->SetAuthor("Anope"); Implementation i[] = { I_OnBotPrivmsg }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("Ignore"); } EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) diff --git a/modules/commands/os_ignore.h b/modules/commands/os_ignore.h index 753a4cfaf..84bf5442d 100644 --- a/modules/commands/os_ignore.h +++ b/modules/commands/os_ignore.h @@ -10,13 +10,14 @@ */ -struct IgnoreData : Serializable +struct IgnoreData : Serializable { Anope::string mask; Anope::string creator; Anope::string reason; time_t time; /* When do we stop ignoring them? */ + IgnoreData() : Serializable("IgnoreData") { } serialized_data serialize(); static void unserialize(serialized_data &data); }; @@ -42,7 +43,7 @@ class IgnoreService : public Service static service_reference ignore_service("ignore"); -SerializableBase::serialized_data IgnoreData::serialize() +Serializable::serialized_data IgnoreData::serialize() { serialized_data data; @@ -54,7 +55,7 @@ SerializableBase::serialized_data IgnoreData::serialize() return data; } -void IgnoreData::unserialize(SerializableBase::serialized_data &data) +void IgnoreData::unserialize(serialized_data &data) { if (!ignore_service) return; diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index b2537bbc9..cf127d284 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -318,6 +318,7 @@ class CommandOSRandomNews : public NewsBase class OSNews : public Module { + SerializeType newsitem_type; MyNewsService newsservice; CommandOSLogonNews commandoslogonnews; @@ -372,15 +373,12 @@ class OSNews : public Module public: OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - newsservice(this), commandoslogonnews(this), commandosopernews(this), commandosrandomnews(this) + newsitem_type("NewsItem", NewsItem::unserialize), newsservice(this), commandoslogonnews(this), commandosopernews(this), commandosrandomnews(this) { this->SetAuthor("Anope"); - Implementation i[] = { I_OnUserModeSet, I_OnUserConnect }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - - Serializable::Alloc.Register("NewsItem"); } void OnUserModeSet(User *u, UserModeName Name) diff --git a/modules/commands/os_news.h b/modules/commands/os_news.h index 9e41173d7..2b2fd7528 100644 --- a/modules/commands/os_news.h +++ b/modules/commands/os_news.h @@ -15,13 +15,14 @@ struct NewsMessages const char *msgs[10]; }; -struct NewsItem : Serializable +struct NewsItem : Serializable { NewsType type; Anope::string text; Anope::string who; time_t time; + NewsItem() : Serializable("NewsItem") { } serialized_data serialize(); static void unserialize(serialized_data &data); }; @@ -40,7 +41,7 @@ class NewsService : public Service static service_reference news_service("news"); -SerializableBase::serialized_data NewsItem::serialize() +Serializable::serialized_data NewsItem::serialize() { serialized_data data; @@ -52,7 +53,7 @@ SerializableBase::serialized_data NewsItem::serialize() return data; } -void NewsItem::unserialize(SerializableBase::serialized_data &data) +void NewsItem::unserialize(serialized_data &data) { if (!news_service) return; diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index 1d38a0279..18391e4ca 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -13,9 +13,9 @@ #include "module.h" -struct MyOper : Oper, Serializable +struct MyOper : Oper, Serializable { - MyOper(const Anope::string &n, OperType *o) : Oper(n, o) { } + MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { } serialized_data serialize() { @@ -196,15 +196,14 @@ class CommandOSOper : public Command class OSOper : public Module { + SerializeType myoper_type; CommandOSOper commandosoper; public: OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - commandosoper(this) + myoper_type("Oper", MyOper::unserialize), commandosoper(this) { this->SetAuthor("Anope"); - - Serializable::Alloc.Register("Oper"); } ~OSOper() diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 752fe8729..5417e83d7 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -628,6 +628,7 @@ class CommandOSException : public Command class OSSession : public Module { + SerializeType exception_type; MySessionService ss; ExpireTimer expiretimer; CommandOSSession commandossession; @@ -720,15 +721,13 @@ class OSSession : public Module public: OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - ss(this), commandossession(this), commandosexception(this), akills("xlinemanager/sgline") + exception_type("Exception", Exception::unserialize), ss(this), commandossession(this), commandosexception(this), akills("xlinemanager/sgline") { this->SetAuthor("Anope"); Implementation i[] = { I_OnUserConnect, I_OnUserLogoff }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); ModuleManager::SetPriority(this, PRIORITY_FIRST); - - Serializable::Alloc.Register("Exception"); } void OnUserConnect(dynamic_reference &user, bool &exempt) diff --git a/modules/commands/os_session.h b/modules/commands/os_session.h index 8a839318d..8d04e31c5 100644 --- a/modules/commands/os_session.h +++ b/modules/commands/os_session.h @@ -1,7 +1,7 @@ #ifndef OS_SESSION_H #define OS_SESSION_H -struct Exception : Serializable +struct Exception : Serializable { Anope::string mask; /* Hosts to which this exception applies */ unsigned limit; /* Session limit for exception */ @@ -10,6 +10,10 @@ struct Exception : Serializable time_t time; /* When this exception was added */ time_t expires; /* Time when it expires. 0 == no expiry */ + Exception() : Serializable("Exception") + { + } + serialized_data serialize(); static void unserialize(serialized_data &data); }; @@ -44,7 +48,7 @@ class SessionService : public Service static service_reference session_service("session"); -SerializableBase::serialized_data Exception::serialize() +Serializable::serialized_data Exception::serialize() { serialized_data data; @@ -58,7 +62,7 @@ SerializableBase::serialized_data Exception::serialize() return data; } -void Exception::unserialize(SerializableBase::serialized_data &data) +void Exception::unserialize(Serializable::serialized_data &data) { if (!session_service) return; diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 639d6e1e8..c3b8cbf75 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -21,14 +21,6 @@ class DBFlatFile : public Module /* Backup file names */ std::list Backups; - SerializableBase *find(const Anope::string &sname) - { - for (unsigned i = 0; i < serialized_types.size(); ++i) - if (serialized_types[i]->serialize_name() == sname) - return serialized_types[i]; - return NULL; - } - public: DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE) { @@ -75,7 +67,7 @@ class DBFlatFile : public Module if (Config->KeepBackups > 0 && Backups.size() > static_cast(Config->KeepBackups)) { - DeleteFile(Backups.front().c_str()); + unlink(Backups.front().c_str()); Backups.pop_front(); } } @@ -98,9 +90,9 @@ class DBFlatFile : public Module return EVENT_CONTINUE; } - SerializableBase *sb = NULL; - SerializableBase::serialized_data data; - std::multimap objects; + SerializeType *st = NULL; + Serializable::serialized_data data; + std::multimap objects; for (Anope::string buf, token; std::getline(db, buf.str());) { spacesepstream sep(buf); @@ -110,29 +102,30 @@ class DBFlatFile : public Module if (token == "OBJECT" && sep.GetToken(token)) { - sb = this->find(token); + st = SerializeType::Find(token); data.clear(); } - else if (token == "DATA" && sb != NULL && sep.GetToken(token)) + else if (token == "DATA" && st != NULL && sep.GetToken(token)) data[token] << sep.GetRemaining(); - else if (token == "END" && sb != NULL) + else if (token == "END" && st != NULL) { - objects.insert(std::make_pair(sb, data)); + objects.insert(std::make_pair(st, data)); - sb = NULL; + st = NULL; data.clear(); } } - for (unsigned i = 0; i < serialized_types.size(); ++i) + const std::vector type_order = SerializeType::GetTypeOrder(); + for (unsigned i = 0; i < type_order.size(); ++i) { - SerializableBase *stype = serialized_types[i]; + SerializeType *stype = SerializeType::Find(type_order[i]); - std::multimap::iterator it = objects.find(stype), it_end = objects.upper_bound(stype); + std::multimap::iterator it = objects.find(stype), it_end = objects.upper_bound(stype); if (it == objects.end()) continue; for (; it != it_end; ++it) - it->first->alloc(it->second); + it->first->Create(it->second); } db.close(); @@ -158,17 +151,17 @@ class DBFlatFile : public Module return EVENT_CONTINUE; } - if (serialized_items != NULL) - for (std::list::iterator it = serialized_items->begin(), it_end = serialized_items->end(); it != it_end; ++it) - { - SerializableBase *base = *it; - SerializableBase::serialized_data data = base->serialize(); + const std::list &items = Serializable::GetItems(); + for (std::list::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + { + Serializable *base = *it; + Serializable::serialized_data data = base->serialize(); - db << "OBJECT " << base->serialize_name() << "\n"; - for (SerializableBase::serialized_data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit) - db << "DATA " << dit->first << " " << dit->second.astr() << "\n"; - db << "END\n"; - } + db << "OBJECT " << base->GetSerializeName() << "\n"; + for (Serializable::serialized_data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit) + db << "DATA " << dit->first << " " << dit->second.astr() << "\n"; + db << "END\n"; + } db.close(); @@ -181,7 +174,7 @@ class DBFlatFile : public Module rename(tmp_db.c_str(), DatabaseFile.c_str()); } else - DeleteFile(tmp_db.c_str()); + unlink(tmp_db.c_str()); return EVENT_CONTINUE; } diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp index 387d5ca61..c28d064cd 100644 --- a/modules/database/db_plain.cpp +++ b/modules/database/db_plain.cpp @@ -596,7 +596,6 @@ class DBPlain : public Module OnReload(); LastDay = 0; - Serializable::Alloc.Register("Exception"); } ~DBPlain() @@ -637,7 +636,7 @@ class DBPlain : public Module unsigned KeepBackups = Config->KeepBackups; if (KeepBackups && Backups.size() > KeepBackups) { - DeleteFile(Backups.front().c_str()); + unlink(Backups.front().c_str()); Backups.pop_front(); } } @@ -655,7 +654,6 @@ class DBPlain : public Module /* No need to ever reload this again, although this should never be trigged again */ ModuleManager::Detach(I_OnLoadDatabase, this); - //ModuleManager::Detach(I_OnDatabaseReadMetadata, this); return EVENT_STOP; } diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 8b2b0e26d..e083204d4 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -60,9 +60,9 @@ class DBSQL : public Module } } - void AlterTable(const Anope::string &table, std::set &data, const SerializableBase::serialized_data &newd) + void AlterTable(const Anope::string &table, std::set &data, const Serializable::serialized_data &newd) { - for (SerializableBase::serialized_data::const_iterator it = newd.begin(), it_end = newd.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = newd.begin(), it_end = newd.end(); it != it_end; ++it) { if (data.count(it->first) > 0) continue; @@ -81,20 +81,20 @@ class DBSQL : public Module } } - void Insert(const Anope::string &table, const SerializableBase::serialized_data &data) + void Insert(const Anope::string &table, const Serializable::serialized_data &data) { Anope::string query_text = "INSERT INTO `" + table + "` ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "`" + it->first + "`,"; query_text.erase(query_text.end() - 1); query_text += ") VALUES ("; - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query_text += "@" + it->first + "@,"; query_text.erase(query_text.end() - 1); query_text += ")"; SQLQuery query(query_text); - for (SerializableBase::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) + for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) query.setValue(it->first, it->second.astr()); this->RunBackground(query); @@ -126,32 +126,33 @@ class DBSQL : public Module return