From b5ff856f47d8e54d12c568462a06351633c29610 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 Nov 2011 17:29:16 -0500 Subject: Windows --- 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 +----- 14 files changed, 130 insertions(+), 212 deletions(-) (limited to 'include') 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 -- cgit