summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-11-08 17:29:16 -0500
committerAdam <Adam@anope.org>2011-11-08 17:29:16 -0500
commitb5ff856f47d8e54d12c568462a06351633c29610 (patch)
treea4e2f96c59ee49aa5e6cacdfd30db6155151ad36
parent97b9055f92f21cd91af44a3d5dacce0024536cff (diff)
Windows
-rw-r--r--CMakeLists.txt2
-rw-r--r--docs/WIN32.txt24
-rw-r--r--include/access.h13
-rw-r--r--include/account.h4
-rw-r--r--include/anope.h6
-rw-r--r--include/bots.h2
-rw-r--r--include/dns.h10
-rw-r--r--include/extensible.h2
-rw-r--r--include/hashcomp.h33
-rw-r--r--include/modules.h23
-rw-r--r--include/oper.h4
-rw-r--r--include/regchannel.h18
-rw-r--r--include/serialize.h149
-rw-r--r--include/services.h55
-rw-r--r--include/sockets.h6
-rw-r--r--include/threadengine.h17
-rw-r--r--modules/commands/bs_kick.cpp2
-rw-r--r--modules/commands/cs_access.cpp43
-rw-r--r--modules/commands/cs_entrymsg.cpp9
-rw-r--r--modules/commands/cs_flags.cpp41
-rw-r--r--modules/commands/cs_seen.cpp11
-rw-r--r--modules/commands/cs_set_misc.cpp9
-rw-r--r--modules/commands/cs_suspend.cpp11
-rw-r--r--modules/commands/cs_xop.cpp39
-rw-r--r--modules/commands/hs_request.cpp9
-rw-r--r--modules/commands/ns_ajoin.cpp9
-rw-r--r--modules/commands/ns_set_misc.cpp9
-rw-r--r--modules/commands/ns_suspend.cpp11
-rw-r--r--modules/commands/os_forbid.cpp6
-rw-r--r--modules/commands/os_forbid.h10
-rw-r--r--modules/commands/os_ignore.cpp5
-rw-r--r--modules/commands/os_ignore.h7
-rw-r--r--modules/commands/os_news.cpp6
-rw-r--r--modules/commands/os_news.h7
-rw-r--r--modules/commands/os_oper.cpp9
-rw-r--r--modules/commands/os_session.cpp5
-rw-r--r--modules/commands/os_session.h10
-rw-r--r--modules/database/db_flatfile.cpp57
-rw-r--r--modules/database/db_plain.cpp4
-rw-r--r--modules/database/db_sql.cpp42
-rw-r--r--modules/database/db_sql_live_read.cpp110
-rw-r--r--modules/database/db_sql_live_write.cpp2
-rw-r--r--modules/extra/m_mysql.cpp6
-rw-r--r--modules/extra/m_proxyscan.cpp4
-rw-r--r--modules/extra/m_sqlite.cpp6
-rw-r--r--modules/extra/sql.h2
-rw-r--r--modules/pseudoclients/operserv.cpp2
-rw-r--r--src/CMakeLists.txt26
-rw-r--r--src/access.cpp36
-rw-r--r--src/base.cpp19
-rw-r--r--src/bots.cpp8
-rw-r--r--src/encrypt.cpp2
-rw-r--r--src/hashcomp.cpp4
-rw-r--r--src/init.cpp8
-rw-r--r--src/logger.cpp2
-rw-r--r--src/main.cpp16
-rw-r--r--src/memoserv.cpp6
-rw-r--r--src/misc.cpp29
-rw-r--r--src/modulemanager.cpp63
-rw-r--r--src/nickalias.cpp6
-rw-r--r--src/nickcore.cpp4
-rw-r--r--src/operserv.cpp14
-rw-r--r--src/regchannel.cpp42
-rw-r--r--src/socketengines/pipeengine_pipe.cpp8
-rw-r--r--src/socketengines/pipeengine_win32.cpp53
-rw-r--r--src/socketengines/socketengine_select.cpp7
-rw-r--r--src/sockets.cpp22
-rw-r--r--src/threadengine.cpp121
-rw-r--r--src/threadengines/threadengine_pthread.cpp122
-rw-r--r--src/threadengines/threadengine_win32.cpp108
-rw-r--r--src/win32/anope_windows.h146
-rw-r--r--src/win32/dir/dir.cpp47
-rw-r--r--src/win32/dir/dir.h26
-rw-r--r--src/win32/dl/dl.cpp30
-rw-r--r--src/win32/dl/dl.h13
-rw-r--r--src/win32/pipe/pipe.cpp61
-rw-r--r--src/win32/pipe/pipe.h8
-rw-r--r--src/win32/pthread/pthread.cpp117
-rw-r--r--src/win32/pthread/pthread.h34
-rw-r--r--src/win32/sigaction/sigaction.cpp60
-rw-r--r--src/win32/sigaction/sigaction.h56
-rw-r--r--src/win32/socket.cpp152
-rw-r--r--src/win32/socket.h32
-rw-r--r--src/win32/vsvars32.bat66
-rw-r--r--src/win32/windows.cpp104
85 files changed, 1274 insertions, 1275 deletions
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=<whatever>" 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<Privilege> privs;
public:
@@ -31,7 +31,7 @@ class CoreExport AccessProvider : public Service<AccessProvider>
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<NickNameFlag, NS_END>, public Serializable<NickAlias>
+class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_END>, public Serializable
{
public:
/** Default constructor
@@ -132,7 +132,7 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_EN
void OnCancel(User *u);
};
-class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable<NickCore>
+class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END>, 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<typename T> class map : public std::map<string, T> { };
- template<typename T> class insensitive_map : public std::map<string, T, std::less<ci::string> > { };
+ template<typename T> class insensitive_map : public std::map<string, T, ci::less> { };
/**
* 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<char>(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<char>(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<BotFlag, BI_END>, public Serializable<BotInfo>
+class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, 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<Question> questions;
std::vector<ResourceRecord> 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<Anope::string, ResourceRecord, std::less<ci::string> > cache_map;
+ typedef std::multimap<Anope::string, ResourceRecord, ci::less> 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<char, irc_char_traits, std::allocator<char> > 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<char, ci_char_traits, std::allocator<char> > string;
-}
-namespace std
-{
- /** An overload for std::less<ci::string> that uses Anope::string, passed for the third template argument
- * to std::map and std::multimap
- */
- template<> struct CoreExport less<ci::string>
+ 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<irc::string> that uses Anope::string, passed for the third tempalte argument
- * to std::map and std::multimap
- */
- template<> struct CoreExport less<irc::string>
- {
- 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<XLine>
+class CoreExport XLine : public Serializable
{
protected:
XLine();
@@ -42,7 +42,7 @@ class CoreExport XLineManager : public Service<XLineManager>
char type;
/* List of XLines in this XLineManager */
std::vector<XLine *> XLines;
- static std::map<Anope::string, XLine *, std::less<ci::string> > XLinesByUID;
+ static std::map<Anope::string, XLine *, ci::less> XLinesByUID;
public:
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::list<XLineManager *> 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<BadWord>
+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<AutoKickFlag>, public Serializable<AutoKick>
+class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable
{
public:
- AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString) { }
+ AutoKick();
ChannelInfo *ci;
/* Only one of these can be in use */
Anope::string mask;
@@ -114,9 +115,9 @@ class AutoKick : public Flags<AutoKickFlag>, public Serializable<AutoKick>
static void unserialize(serialized_data &);
};
-struct ModeLock : Serializable<ModeLock>
+struct CoreExport ModeLock : Serializable
{
- ModeLock() { }
+ ModeLock();
public:
ChannelInfo *ci;
bool set;
@@ -125,13 +126,13 @@ struct ModeLock : Serializable<ModeLock>
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<LogSetting>
+struct CoreExport LogSetting : Serializable
{
ChannelInfo *ci;
/* Our service name of the command */
@@ -144,11 +145,12 @@ struct LogSetting : Serializable<LogSetting>
Anope::string creator;
time_t created;
+ LogSetting();
serialized_data serialize();
static void unserialize(serialized_data &);
};
-class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END>, public Serializable<ChannelInfo>
+class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END>, 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<typename T> 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<SerializableBase *> serialized_types;
-extern std::list<SerializableBase *> *serialized_items;
extern void RegisterTypes();
-class SerializableBase
+class CoreExport Serializable
{
- public:
- typedef std::map<Anope::string, Serialize::stringstream> serialized_data;
+ private:
+ static std::list<Serializable *> 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<Serializable *>::iterator s_iter;
-template<typename Type> 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<SerializableBase *>::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<Anope::string, Serialize::stringstream> serialized_data;
- void alloc(serialized_data &data)
- {
- Type::unserialize(data);
- }
- } Alloc;
+ const Anope::string &GetSerializeName()
+ {
+ return this->serizliable_name;
+ }
- private:
- std::list<SerializableBase *>::iterator s_iter;
+ virtual serialized_data serialize() = 0;
- protected:
- Serializable()
+ static const std::list<Serializable *> &GetItems()
{
- if (serialized_items == NULL)
- serialized_items = new std::list<SerializableBase *>();
- 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<Anope::string> type_order;
+ static Anope::map<SerializeType *> 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<Anope::string>::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<SerializeType *>::iterator it = types.find(name);
+ if (it != types.end())
+ return it->second;
+ return NULL;
}
-};
-template<typename T> typename Serializable<T>::SerializableAllocator Serializable<T>::Alloc;
+ static const std::vector<Anope::string> &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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdexcept>
#include <string.h>
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
#include <signal.h>
#include <time.h>
#include <errno.h>
@@ -40,9 +37,9 @@
#include <sys/stat.h> /* for umask() on some systems */
#include <sys/types.h>
-#include <sys/wait.h>
#include <fcntl.h>
#include <typeinfo>
+#include <ctype.h>
#if GETTEXT_FOUND
# include <libintl.h>
@@ -57,11 +54,12 @@
# include <arpa/inet.h>
# include <sys/socket.h>
# include <sys/time.h>
+# include <sys/wait.h>
# include <dirent.h>
+# include <pthread.h>
# 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 <strings.h>
-#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 <ctype.h>
-#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<typename T, size_t Size = 32> class Flags
class Module;
-template<typename T> class CoreExport Service : public Base
+template<typename T> class Service : public Base
{
static Anope::map<T *> 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<MemoFlag>, public Serializable<Memo>
+class CoreExport Memo : public Flags<MemoFlag>, 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 <pthread.h>
-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<Anope::string, Data, std::less<ci::string> > data_type;
+ typedef std::map<Anope::string, Data, ci::less> 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<Anope::string, int16_t, std::less<ci::string> > defaultLevels;
+static std::map<Anope::string, int16_t, ci::less> defaultLevels;
static void reset_levels(ChannelInfo *ci)
{
ci->ClearLevels();
- for (std::map<Anope::string, int16_t, std::less<ci::string> >::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it)
+ for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it)
ci->SetLevel(it->first, it->second);
}
-class AccessChanAccess : public ChanAccess, public Serializable<AccessChanAccess>
+class AccessChanAccess : public ChanAccess
{
public:
int level;
@@ -86,41 +86,6 @@ class AccessChanAccess : public ChanAccess, public Serializable<AccessChanAccess
return highest;
}
}
-
- Anope::string serialize_name() { return "AccessChanAccess"; }
- 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["level"].setType(Serialize::DT_INT) << this->level;
-
- return data;
- }
-
- static void unserialize(SerializableBase::serialized_data &data)
- {
- service_reference<AccessProvider> 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<AccessChanAccess>::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<EntryMsg>
+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<EntryMsg>::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<Anope::string, char> defaultFlags;
-class FlagsChanAccess : public ChanAccess, public Serializable<FlagsChanAccess>
+class FlagsChanAccess : public ChanAccess
{
public:
std::set<char> flags;
@@ -65,41 +65,6 @@ class FlagsChanAccess : public ChanAccess, public Serializable<FlagsChanAccess>
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<AccessProvider> 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<char, Anope::string, std::less<ci::string> > reverse_map;
+ typedef std::multimap<char, Anope::string, ci::less> reverse_map;
reverse_map reverse;
for (std::map<Anope::string, char>::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<FlagsChanAccess>::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<SeenInfo *> database_map;
database_map database;
-struct SeenInfo : Serializable<SeenInfo>
+struct SeenInfo : Serializable
{
Anope::string nick;
Anope::string vhost;
@@ -33,6 +33,10 @@ struct SeenInfo : Serializable<SeenInfo>
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<SeenInfo>::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<CSMiscData>
+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<CSMiscData>::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<ChanSuspend>
+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<ChanSuspend>::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<XOPChanAccess>
+class XOPChanAccess : public ChanAccess
{
public:
XOPType type;
@@ -188,41 +188,6 @@ class XOPChanAccess : public ChanAccess, public Serializable<XOPChanAccess>
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<AccessProvider> 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<XOPChanAccess>::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<HostRequest>
+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<std::pair<Anope::string, Anope::string> >, ExtensibleItem, Serializable<AJoinList>
+struct AJoinList : std::vector<std::pair<Anope::string, Anope::string> >, 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<AJoinList>::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<NSMiscData>
+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<NSMiscData>::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<NickSuspend>
+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<NickSuspend>::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<ForbidData>::Alloc.Register("Forbid");
}
void OnUserConnect(dynamic_reference<User> &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<ForbidData>
+struct ForbidData : Serializable
{
Anope::string mask;
Anope::string creator;
@@ -18,6 +18,10 @@ struct ForbidData : Serializable<ForbidData>
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<Base>
static service_reference<ForbidService, Base> 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<IgnoreData>::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<IgnoreData>
+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<Base>
static service_reference<IgnoreService, Base> 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<NewsItem>::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<NewsItem>
+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<Base>
static service_reference<NewsService, Base> 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<MyOper>
+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<MyOper>::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<Exception>::Alloc.Register("Exception");
}
void OnUserConnect(dynamic_reference<User> &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<Exception>
+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<Exception>
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<Base>
static service_reference<SessionService, Base> 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<Anope::string> 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<unsigned>(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<SerializableBase *, SerializableBase::serialized_data> objects;
+ SerializeType *st = NULL;
+ Serializable::serialized_data data;
+ std::multimap<SerializeType *, Serializable::serialized_data> 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<Anope::string> 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<SerializableBase *, SerializableBase::serialized_data>::iterator it = objects.find(stype), it_end = objects.upper_bound(stype);
+ std::multimap<SerializeType *, Serializable::serialized_data>::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<SerializableBase *>::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<Serializable *> &items = Serializable::GetItems();
+ for (std::list<Serializable *>::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<Exception>::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<Anope::string> &data, const SerializableBase::serialized_data &newd)
+ void AlterTable(const Anope::string &table, std::set<Anope::string> &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 EVENT_CONTINUE;
}
- if (serialized_items == NULL)
+ const std::list<Serializable *> &items = Serializable::GetItems();
+ if (items.empty())
return EVENT_CONTINUE;
this->DropAll();
std::map<Anope::string, std::set<Anope::string> > table_layout;
- for (std::list<SerializableBase *>::iterator it = serialized_items->begin(), it_end = serialized_items->end(); it != it_end; ++it)
+ for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
{
- SerializableBase *base = *it;
- SerializableBase::serialized_data data = base->serialize();
+ Serializable *base = *it;
+ Serializable::serialized_data data = base->serialize();
if (data.empty())
continue;
- std::set<Anope::string> &layout = table_layout[base->serialize_name()];
+ std::set<Anope::string> &layout = table_layout[base->GetSerializeName()];
if (layout.empty())
{
- this->RunBackground(this->sql->CreateTable(base->serialize_name(), data));
+ this->RunBackground(this->sql->CreateTable(base->GetSerializeName(), data));
- for (SerializableBase::serialized_data::iterator it2 = data.begin(), it2_end = data.end(); it2 != it2_end; ++it2)
+ for (Serializable::serialized_data::iterator it2 = data.begin(), it2_end = data.end(); it2 != it2_end; ++it2)
layout.insert(it2->first);
}
else
- this->AlterTable(base->serialize_name(), layout, data);
+ this->AlterTable(base->GetSerializeName(), layout, data);
- this->Insert(base->serialize_name(), data);
+ this->Insert(base->GetSerializeName(), data);
}
return EVENT_CONTINUE;
}
@@ -164,20 +165,21 @@ class DBSQL : public Module
return EVENT_CONTINUE;
}
- for (std::vector<SerializableBase *>::iterator it = serialized_types.begin(), it_end = serialized_types.end(); it != it_end; ++it)
+ const std::vector<Anope::string> type_order = SerializeType::GetTypeOrder();
+ for (unsigned i = 0; i < type_order.size(); ++i)
{
- SerializableBase *sb = *it;
+ SerializeType *sb = SerializeType::Find(type_order[i]);
- SQLQuery query("SELECT * FROM `" + sb->serialize_name() + "`");
+ SQLQuery query("SELECT * FROM `" + sb->GetName() + "`");
SQLResult res = this->sql->RunQuery(query);
for (int i = 0; i < res.Rows(); ++i)
{
- SerializableBase::serialized_data data;
+ Serializable::serialized_data data;
const std::map<Anope::string, Anope::string> &row = res.Row(i);
for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
data[rit->first] << rit->second;
- sb->alloc(data);
+ sb->Create(data);
}
}
diff --git a/modules/database/db_sql_live_read.cpp b/modules/database/db_sql_live_read.cpp
index b908949ab..9dfc68c69 100644
--- a/modules/database/db_sql_live_read.cpp
+++ b/modules/database/db_sql_live_read.cpp
@@ -55,7 +55,7 @@ class DBMySQL : public Module
}
}
- void Insert(const Anope::string &table, const SerializableBase::serialized_data &data)
+ void Insert(const Anope::string &table, const Serializable::serialized_data &data)
{
if (tables.count(table) == 0 && SQL)
{
@@ -64,33 +64,33 @@ class DBMySQL : public Module
}
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 += ") ON DUPLICATE KEY UPDATE ";
- 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 + "=VALUES(" + it->first + "),";
query_text.erase(query_text.end() - 1);
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->RunQuery(query);
}
- void Delete(const Anope::string &table, const SerializableBase::serialized_data &data)
+ void Delete(const Anope::string &table, const Serializable::serialized_data &data)
{
Anope::string query_text = "DELETE FROM `" + table + "` WHERE ";
- 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 + "` = @" + it->first + "@";
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->RunQuery(query);
@@ -158,20 +158,20 @@ class DBMySQL : public Module
{
NickAlias *na = findnick(source.u->nick);
if (!na)
- this->Insert(na->nc->serialize_name(), na->nc->serialize());
+ this->Insert(na->nc->GetSerializeName(), na->nc->serialize());
}
else if (command->name.find("nickserv/saset/") == 0)
{
NickAlias *na = findnick(params[1]);
if (!na)
- this->Insert(na->nc->serialize_name(), na->nc->serialize());
+ this->Insert(na->nc->GetSerializeName(), na->nc->serialize());
}
else if (command->name.find("chanserv/set") == 0 || command->name.find("chanserv/saset") == 0)
{
ChannelInfo *ci = params.size() > 0 ? cs_findchan(params[0]) : NULL;
if (!ci)
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
else if (command->name == "botserv/kick" && params.size() > 2)
{
@@ -180,7 +180,7 @@ class DBMySQL : public Module
return;
if (!ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration"))
return;
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
else if (command->name == "botserv/set" && params.size() > 1)
{
@@ -189,9 +189,9 @@ class DBMySQL : public Module
if (!ci)
bi = findbot(params[0]);
if (bi && params[1].equals_ci("PRIVATE") && u->HasPriv("botserv/set/private"))
- this->Insert(bi->serialize_name(), bi->serialize());
+ this->Insert(bi->GetSerializeName(), bi->serialize());
else if (ci && !ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration"))
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
else if (command->name == "memoserv/ignore" && params.size() > 0)
{
@@ -200,40 +200,40 @@ class DBMySQL : public Module
{
NickCore *nc = u->Account();
if (nc)
- this->Insert(nc->serialize_name(), nc->serialize());
+ this->Insert(nc->GetSerializeName(), nc->serialize());
}
else
{
ChannelInfo *ci = cs_findchan(target);
if (ci && ci->AccessFor(u).HasPriv("MEMO"))
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
}
}
void OnNickAddAccess(NickCore *nc, const Anope::string &entry)
{
- this->Insert(nc->serialize_name(), nc->serialize());
+ this->Insert(nc->GetSerializeName(), nc->serialize());
}
void OnNickEraseAccess(NickCore *nc, const Anope::string &entry)
{
- this->Insert(nc->serialize_name(), nc->serialize());
+ this->Insert(nc->GetSerializeName(), nc->serialize());
}
void OnNickClearAccess(NickCore *nc)
{
- this->Insert(nc->serialize_name(), nc->serialize());
+ this->Insert(nc->GetSerializeName(), nc->serialize());
}
void OnDelCore(NickCore *nc)
{
- this->Delete(nc->serialize_name(), nc->serialize());
+ this->Delete(nc->GetSerializeName(), nc->serialize());
}
void OnNickForbidden(NickAlias *na)
{
- this->Insert(na->serialize_name(), na->serialize());
+ this->Insert(na->GetSerializeName(), na->serialize());
}
void OnNickGroup(User *u, NickAlias *)
@@ -243,12 +243,12 @@ class DBMySQL : public Module
void InsertAlias(NickAlias *na)
{
- this->Insert(na->serialize_name(), na->serialize());
+ this->Insert(na->GetSerializeName(), na->serialize());
}
void InsertCore(NickCore *nc)
{
- this->Insert(nc->serialize_name(), nc->serialize());
+ this->Insert(nc->GetSerializeName(), nc->serialize());
}
void OnNickRegister(NickAlias *na)
@@ -259,42 +259,42 @@ class DBMySQL : public Module
void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay)
{
- SerializableBase::serialized_data data = nc->serialize();
- this->Delete(nc->serialize_name(), data);
+ Serializable::serialized_data data = nc->serialize();
+ this->Delete(nc->GetSerializeName(), data);
data.erase("display");
data["display"] << newdisplay;
- this->Insert(nc->serialize_name(), data);
+ this->Insert(nc->GetSerializeName(), data);
for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
{
NickAlias *na = *it;
data = na->serialize();
- this->Delete(na->serialize_name(), data);
+ this->Delete(na->GetSerializeName(), data);
data.erase("nc");
data["nc"] << newdisplay;
- this->Insert(na->serialize_name(), data);
+ this->Insert(na->GetSerializeName(), data);
}
}
void OnNickSuspend(NickAlias *na)
{
- this->Insert(na->serialize_name(), na->serialize());
+ this->Insert(na->GetSerializeName(), na->serialize());
}
void OnDelNick(NickAlias *na)
{
- this->Delete(na->serialize_name(), na->serialize());
+ this->Delete(na->GetSerializeName(), na->serialize());
}
void OnAccessAdd(ChannelInfo *ci, User *, ChanAccess *access)
{
- this->Insert(access->serialize_name(), access->serialize());
+ this->Insert(access->GetSerializeName(), access->serialize());
}
void OnAccessDel(ChannelInfo *ci, User *u, ChanAccess *access)
{
- this->Delete(access->serialize_name(), access->serialize());
+ this->Delete(access->GetSerializeName(), access->serialize());
}
void OnAccessClear(ChannelInfo *ci, User *u)
@@ -305,49 +305,49 @@ class DBMySQL : public Module
void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16_t what)
{
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
void OnDelChan(ChannelInfo *ci)
{
- this->Delete(ci->serialize_name(), ci->serialize());
+ this->Delete(ci->GetSerializeName(), ci->serialize());
}
void OnChanRegistered(ChannelInfo *ci)
{
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
void OnChanSuspend(ChannelInfo *ci)
{
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
}
void OnAkickAdd(ChannelInfo *ci, AutoKick *ak)
{
- this->Insert(ak->serialize_name(), ak->serialize());
+ this->Insert(ak->GetSerializeName(), ak->serialize());
}
void OnAkickDel(ChannelInfo *ci, AutoKick *ak)
{
- this->Delete(ak->serialize_name(), ak->serialize());
+ this->Delete(ak->GetSerializeName(), ak->serialize());
}
EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock)
{
- this->Insert(lock->serialize_name(), lock->serialize());
+ this->Insert(lock->GetSerializeName(), lock->serialize());
return EVENT_CONTINUE;
}
EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock)
{
- this->Delete(lock->serialize_name(), lock->serialize());
+ this->Delete(lock->GetSerializeName(), lock->serialize());
return EVENT_CONTINUE;
}
void OnBotCreate(BotInfo *bi)
{
- this->Insert(bi->serialize_name(), bi->serialize());
+ this->Insert(bi->GetSerializeName(), bi->serialize());
}
void OnBotChange(BotInfo *bi)
@@ -357,76 +357,76 @@ class DBMySQL : public Module
void OnBotDelete(BotInfo *bi)
{
- this->Delete(bi->serialize_name(), bi->serialize());
+ this->Delete(bi->GetSerializeName(), bi->serialize());
}
EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi)
{
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
return EVENT_CONTINUE;
}
EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci)
{
- this->Insert(ci->serialize_name(), ci->serialize());
+ this->Insert(ci->GetSerializeName(), ci->serialize());
return EVENT_CONTINUE;
}
void OnBadWordAdd(ChannelInfo *ci, BadWord *bw)
{
- this->Insert(bw->serialize_name(), bw->serialize());
+ this->Insert(bw->GetSerializeName(), bw->serialize());
}
void OnBadWordDel(ChannelInfo *ci, BadWord *bw)
{
- this->Delete(bw->serialize_name(), bw->serialize());
+ this->Delete(bw->GetSerializeName(), bw->serialize());
}
void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m)
{
- this->Insert(m->serialize_name(), m->serialize());
+ this->Insert(m->GetSerializeName(), m->serialize());
}
void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m)
{
- this->Delete(m->serialize_name(), m->serialize());
+ this->Delete(m->GetSerializeName(), m->serialize());
}
void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m)
{
- this->Delete(m->serialize_name(), m->serialize());
+ this->Delete(m->GetSerializeName(), m->serialize());
}
EventReturn OnExceptionAdd(Exception *ex)
{
- this->Insert(ex->serialize_name(), ex->serialize());
+ this->Insert(ex->GetSerializeName(), ex->serialize());
return EVENT_CONTINUE;
}
void OnExceptionDel(User *, Exception *ex)
{
- this->Delete(ex->serialize_name(), ex->serialize());
+ this->Delete(ex->GetSerializeName(), ex->serialize());
}
EventReturn OnAddXLine(XLine *x, XLineManager *xlm)
{
- this->Insert(x->serialize_name(), x->serialize());
+ this->Insert(x->GetSerializeName(), x->serialize());
return EVENT_CONTINUE;
}
void OnDelXLine(User *, XLine *x, XLineManager *xlm)
{
- this->Delete(x->serialize_name(), x->serialize());
+ this->Delete(x->GetSerializeName(), x->serialize());
}
void OnDeleteVhost(NickAlias *na)
{
- this->Insert(na->serialize_name(), na->serialize());
+ this->Insert(na->GetSerializeName(), na->serialize());
}
void OnSetVhost(NickAlias *na)
{
- this->Insert(na->serialize_name(), na->serialize());
+ this->Insert(na->GetSerializeName(), na->serialize());
}
};
diff --git a/modules/database/db_sql_live_write.cpp b/modules/database/db_sql_live_write.cpp
index 5d15d14d3..21b45bdb4 100644
--- a/modules/database/db_sql_live_write.cpp
+++ b/modules/database/db_sql_live_write.cpp
@@ -3,7 +3,7 @@
class SQLCache : public Timer
{
- typedef std::map<Anope::string, time_t, std::less<ci::string> > cache_map;
+ typedef std::map<Anope::string, time_t, ci::less> cache_map;
cache_map cache;
public:
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index 61e6c39c9..189a950d8 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -123,7 +123,7 @@ class MySQLService : public SQLProvider
SQLResult RunQuery(const SQLQuery &query);
- SQLQuery CreateTable(const Anope::string &table, const SerializableBase::serialized_data &data);
+ SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data);
SQLQuery GetTables();
@@ -342,10 +342,10 @@ SQLResult MySQLService::RunQuery(const SQLQuery &query)
}
}
-SQLQuery MySQLService::CreateTable(const Anope::string &table, const SerializableBase::serialized_data &data)
+SQLQuery MySQLService::CreateTable(const Anope::string &table, const Serializable::serialized_data &data)
{
Anope::string query_text = "CREATE TABLE `" + table + "` (", key_buf;
- 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 + "` ";
if (it->second.getType() == Serialize::DT_INT)
diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp
index 685d984b0..36d9544ec 100644
--- a/modules/extra/m_proxyscan.cpp
+++ b/modules/extra/m_proxyscan.cpp
@@ -9,7 +9,7 @@
struct ProxyCheck
{
- std::set<Anope::string, std::less<ci::string> > types;
+ std::set<Anope::string, ci::less> types;
std::vector<unsigned short> ports;
time_t duration;
Anope::string reason;
@@ -361,7 +361,7 @@ class ModuleProxyScan : public Module
{
ProxyCheck &p = this->proxyscans[i - 1];
- for (std::set<Anope::string, std::less<ci::string> >::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it)
+ for (std::set<Anope::string, ci::less>::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it)
{
for (unsigned k = 0; k < p.ports.size(); ++k)
{
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp
index 2411f843f..e81bca8ab 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/m_sqlite.cpp
@@ -44,7 +44,7 @@ class SQLiteService : public SQLProvider
SQLResult RunQuery(const SQLQuery &query);
- SQLQuery CreateTable(const Anope::string &table, const SerializableBase::serialized_data &data);
+ SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data);
SQLQuery GetTables();
@@ -181,10 +181,10 @@ SQLResult SQLiteService::RunQuery(const SQLQuery &query)
return result;
}
-SQLQuery SQLiteService::CreateTable(const Anope::string &table, const SerializableBase::serialized_data &data)
+SQLQuery SQLiteService::CreateTable(const Anope::string &table, const Serializable::serialized_data &data)
{
Anope::string query_text = "CREATE TABLE `" + table + "` (", key_buf;
- 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 + "` ";
if (it->second.getType() == Serialize::DT_INT)
diff --git a/modules/extra/sql.h b/modules/extra/sql.h
index 21b311014..14272ed90 100644
--- a/modules/extra/sql.h
+++ b/modules/extra/sql.h
@@ -117,7 +117,7 @@ class SQLProvider : public Service<Base>
virtual SQLResult RunQuery(const SQLQuery &query) = 0;
- virtual SQLQuery CreateTable(const Anope::string &table, const SerializableBase::serialized_data &data) = 0;
+ virtual SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data) = 0;
virtual SQLQuery GetTables() = 0;
};
diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp
index d29c2c66e..de24fbfbf 100644
--- a/modules/pseudoclients/operserv.cpp
+++ b/modules/pseudoclients/operserv.cpp
@@ -188,8 +188,6 @@ class OperServCore : public Module
XLineManager::RegisterXLineManager(&sglines);
XLineManager::RegisterXLineManager(&sqlines);
XLineManager::RegisterXLineManager(&snlines);
-
- Serializable<XLine>::Alloc.Register("XLine");
}
~OperServCore()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3c21ba477..a51bc3057 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,24 +1,24 @@
# Find all the *.cpp files within the current source directory, and sort the list
file(GLOB SRC_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
-# If using Windows, add the windows.cpp, the win32 threading engine, and the socket engine to the list
if(WIN32)
+ append_to_list(SRC_SRCS win32/dir/dir.cpp)
+ append_to_list(SRC_SRCS win32/socket.cpp)
append_to_list(SRC_SRCS win32/windows.cpp)
+ append_to_list(SRC_SRCS win32/dl/dl.cpp)
+ append_to_list(SRC_SRCS win32/pipe/pipe.cpp)
+ append_to_list(SRC_SRCS win32/pthread/pthread.cpp)
append_to_list(SRC_SRCS win32/sigaction/sigaction.cpp)
- append_to_list(SRC_SRCS threadengines/threadengine_win32.cpp)
- append_to_list(SRC_SRCS socketengines/pipeengine_win32.cpp)
-# If not using Windows, add the pthread threading engine to the list
-else(WIN32)
- append_to_list(SRC_SRCS threadengines/threadengine_pthread.cpp)
- # If we have eventfd, use it
- if(HAVE_EVENTFD)
- append_to_list(SRC_SRCS socketengines/pipeengine_eventfd.cpp)
- # Else fall back to pipe
- else(HAVE_EVENTFD)
- append_to_list(SRC_SRCS socketengines/pipeengine_pipe.cpp)
- endif(HAVE_EVENTFD)
endif(WIN32)
+# If we have eventfd, use it
+if(HAVE_EVENTFD)
+ append_to_list(SRC_SRCS socketengines/pipeengine_eventfd.cpp)
+# Else fall back to pipe
+else(HAVE_EVENTFD)
+ append_to_list(SRC_SRCS socketengines/pipeengine_pipe.cpp)
+endif(HAVE_EVENTFD)
+
if(HAVE_EPOLL)
append_to_list(SRC_SRCS socketengines/socketengine_epoll.cpp)
else(HAVE_EPOLL)
diff --git a/src/access.cpp b/src/access.cpp
index 74a376b3d..626176e7b 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -71,7 +71,7 @@ AccessProvider::~AccessProvider()
{
}
-ChanAccess::ChanAccess(AccessProvider *p) : provider(p)
+ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p)
{
}
@@ -79,6 +79,40 @@ ChanAccess::~ChanAccess()
{
}
+Serializable::serialized_data ChanAccess::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["data"] << this->Serialize();
+
+ return data;
+}
+
+void ChanAccess::unserialize(serialized_data &data)
+{
+ service_reference<AccessProvider> aprovider(data["provider"].astr());
+ ChannelInfo *ci = cs_findchan(data["ci"].astr());
+ if (!aprovider || !ci)
+ return;
+
+ ChanAccess *access = aprovider->Create();
+ 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["data"].astr());
+
+ ci->AddAccess(access);
+}
+
bool ChanAccess::operator>(ChanAccess &other)
{
const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
diff --git a/src/base.cpp b/src/base.cpp
index e45e6365c..08d5c6e63 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -1,20 +1,17 @@
#include "services.h"
#include "modules.h"
+#include "oper.h"
-std::vector<SerializableBase *> serialized_types;
-std::list<SerializableBase *> *serialized_items;
+std::vector<Anope::string> SerializeType::type_order;
+Anope::map<SerializeType *> SerializeType::types;
+std::list<Serializable *> Serializable::serizliable_items;
void RegisterTypes()
{
- Serializable<NickCore>::Alloc.Register("NickCore");
- Serializable<NickAlias>::Alloc.Register("NickAlias");
- Serializable<BotInfo>::Alloc.Register("BotInfo");
- Serializable<ChannelInfo>::Alloc.Register("ChannelInfo");
- Serializable<LogSetting>::Alloc.Register("LogSetting");
- Serializable<ModeLock>::Alloc.Register("ModeLock");
- Serializable<AutoKick>::Alloc.Register("AutoKick");
- Serializable<BadWord>::Alloc.Register("BadWord");
- Serializable<Memo>::Alloc.Register("Memo");
+ static SerializeType nc("NickCore", NickCore::unserialize), na("NickAlias", NickAlias::unserialize), bi("BotInfo", BotInfo::unserialize),
+ ci("ChannelInfo", ChannelInfo::unserialize), access("ChanAccess", ChanAccess::unserialize), logsetting("LogSetting", LogSetting::unserialize),
+ modelock("ModeLock", ModeLock::unserialize), akick("AutoKick", AutoKick::unserialize), badword("BadWord", BadWord::unserialize),
+ memo("Memo", Memo::unserialize), xline("XLine", XLine::unserialize);
}
Base::Base()
diff --git a/src/bots.cpp b/src/bots.cpp
index a10b7b147..864201f8c 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -13,7 +13,7 @@
Anope::insensitive_map<BotInfo *> BotListByNick;
Anope::map<BotInfo *> BotListByUID;
-BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), botmodes(bmodes)
+BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), Serializable("BotInfo"), botmodes(bmodes)
{
this->realname = nreal;
this->server = Me;
@@ -64,9 +64,9 @@ BotInfo::~BotInfo()
BotListByUID.erase(this->uid);
}
-SerializableBase::serialized_data BotInfo::serialize()
+Serializable::serialized_data BotInfo::serialize()
{
- SerializableBase::serialized_data data;
+ serialized_data data;
data["nick"] << this->nick;
data["user"] << this->ident;
@@ -79,7 +79,7 @@ SerializableBase::serialized_data BotInfo::serialize()
return data;
}
-void BotInfo::unserialize(SerializableBase::serialized_data &data)
+void BotInfo::unserialize(serialized_data &data)
{
BotInfo *bi = findbot(data["nick"].astr());
if (bi == NULL)
diff --git a/src/encrypt.cpp b/src/encrypt.cpp
index 0f3bd3d79..2f052be4e 100644
--- a/src/encrypt.cpp
+++ b/src/encrypt.cpp
@@ -35,7 +35,7 @@ bool enc_decrypt(const Anope::string &src, Anope::string &dest)
if (pos == Anope::string::npos)
{
Log() << "Error: enc_decrypt() called with invalid password string (" << src << ")";
- return -1;
+ return false;
}
Anope::string hashm(src.begin(), src.begin() + pos);
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index cfffd5a10..0095ec74b 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -113,7 +113,7 @@ const char *ci::ci_char_traits::find(const char *s1, int n, char c)
* @param s2 The second string
* @return true if s1 < s2, else false
*/
-bool std::less<ci::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
+bool ci::less::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.ci_str().compare(s2.ci_str()) < 0;
}
@@ -123,7 +123,7 @@ bool std::less<ci::string>::operator()(const Anope::string &s1, const Anope::str
* @param s2 The second string
* @return true if s1 < s2, else false
*/
-bool std::less<irc::string>::operator()(const Anope::string &s1, const Anope::string &s2) const
+bool irc::less::operator()(const Anope::string &s1, const Anope::string &s2) const
{
return s1.irc_str().compare(s2.irc_str()) < 0;
}
diff --git a/src/init.cpp b/src/init.cpp
index 4c4d3f93e..d54ad7fa5 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -161,7 +161,11 @@ static void write_pidfile()
FILE *pidfile = fopen(Config->PIDFilename.c_str(), "w");
if (pidfile)
{
+#ifdef _WIN32
+ fprintf(pidfile, "%d\n", static_cast<int>(GetCurrentProcessId()));
+#else
fprintf(pidfile, "%d\n", static_cast<int>(getpid()));
+#endif
fclose(pidfile);
atexit(remove_pidfile);
}
@@ -458,10 +462,6 @@ void Init(int ac, char **av)
rand_init();
add_entropy_userkeys();
-#ifdef _WIN32
- OnStartup();
-#endif
-
/* load modules */
Log() << "Loading modules...";
for (std::list<Anope::string>::iterator it = Config->ModulesAutoLoad.begin(), it_end = Config->ModulesAutoLoad.end(); it != it_end; ++it)
diff --git a/src/logger.cpp b/src/logger.cpp
index d8aed5ee7..9792c9be2 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -380,7 +380,7 @@ void LogInfo::ProcessMessage(const Log *l)
Anope::string oldlog = CreateLogName(target, Anope::CurTime - 86400 * this->LogAge);
if (IsFile(oldlog))
{
- DeleteFile(oldlog.c_str());
+ unlink(oldlog.c_str());
Log(LOG_DEBUG) << "Deleted old logfile " << oldlog;
}
}
diff --git a/src/main.cpp b/src/main.cpp
index b115137ea..03920424a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,10 +27,9 @@
#include "timers.h"
#include "modules.h"
-// getrlimit.
-#ifndef _WIN32
-# include <sys/time.h>
-# include <sys/resource.h>
+#ifdef _WIN32
+# include <process.h>
+# define execve _execve
#endif
/******** Global variables! ********/
@@ -47,11 +46,6 @@ bool noexpire = false; /* -noexpire */
bool protocoldebug = false; /* -protocoldebug */
Anope::string binary_dir; /* Used to store base path for Anope */
-#ifdef _WIN32
-# include <process.h>
-# define execve _execve
-#endif
-
/* Set to 1 if we are to quit */
bool quitting = false;
int return_code = 0;
@@ -316,6 +310,10 @@ int main(int ac, char **av, char **envp)
/* Clean out the module runtime directory prior to running, just in case files were left behind during a previous run */
ModuleManager::CleanupRuntimeDirectory();
+#ifdef _WIN32
+ OnStartup();
+#endif
+
try
{
/* General initialization first */
diff --git a/src/memoserv.cpp b/src/memoserv.cpp
index 602db9897..8db4f0170 100644
--- a/src/memoserv.cpp
+++ b/src/memoserv.cpp
@@ -13,9 +13,9 @@
#include "modules.h"
#include "memoserv.h"
-Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings) { }
+Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings), Serializable("Memo") { }
-SerializableBase::serialized_data Memo::serialize()
+Serializable::serialized_data Memo::serialize()
{
serialized_data data;
@@ -28,7 +28,7 @@ SerializableBase::serialized_data Memo::serialize()
return data;
}
-void Memo::unserialize(SerializableBase::serialized_data &data)
+void Memo::unserialize(serialized_data &data)
{
if (!memoserv)
return;
diff --git a/src/misc.cpp b/src/misc.cpp
index 5e899effd..0941c9bbc 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -49,35 +49,6 @@ bool IsFile(const Anope::string &filename)
return false;
}
-/**
- * toupper: Like the ANSI functions, but make sure we return an
- * int instead of a (signed) char.
- * @param c Char
- * @return int
- */
-int toupper(char c)
-{
- if (islower(c))
- return static_cast<int>(c) - ('a' - 'A');
- else
- return static_cast<int>(c);
-}
-
-/*************************************************************************/
-
-/**
- * tolower: Like the ANSI functions, but make sure we return an
- * int instead of a (signed) char.
- * @param c Char
- * @return int
- */
-int tolower(char c)
-{
- if (isupper(c))
- return static_cast<int>(c) + ('a' - 'A');
- else
- return static_cast<int>(c);
-}
/*************************************************************************/
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 978a5b929..17cc08a53 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -17,52 +17,24 @@ void ModuleManager::CleanupRuntimeDirectory()
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
-#ifndef _WIN32
DIR *dirp = opendir(dirbuf.c_str());
if (!dirp)
{
Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
return;
}
- struct dirent *dp;
- while ((dp = readdir(dirp)))
+
+ for (dirent *dp; (dp = readdir(dirp));)
{
if (!dp->d_ino)
continue;
if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
continue;
Anope::string filebuf = dirbuf + "/" + dp->d_name;
- DeleteFile(filebuf.c_str());
- }
- closedir(dirp);
-#else
- Anope::string szDir = dirbuf + "/*";
-
- WIN32_FIND_DATA FileData;
- HANDLE hList = FindFirstFile(szDir.c_str(), &FileData);
- if (hList != INVALID_HANDLE_VALUE)
- {
- bool fFinished = false;
- while (!fFinished)
- {
- if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- Anope::string filebuf = dirbuf + "/" + FileData.cFileName;
- if (!DeleteFile(filebuf.c_str()))
- Log(LOG_DEBUG) << "Error deleting file " << filebuf << " - GetLastError() reports " << Anope::LastError();
- }
- if (!FindNextFile(hList, &FileData))
- {
- if (GetLastError() == ERROR_NO_MORE_FILES)
- fFinished = true;
- }
- }
+ unlink(filebuf.c_str());
}
- else
- Log(LOG_DEBUG) << "Invalid File Handle. GetLastError() reports "<< static_cast<int>(GetLastError());
- FindClose(hList);
-#endif
+ closedir(dirp);
}
/**
@@ -131,11 +103,11 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out
* This function will take a pointer from either dlsym or GetProcAddress and cast it in
* a way that won't cause C++ warnings/errors to come up.
*/
-template <class TYPE> TYPE function_cast(ano_module_t symbol)
+template <class TYPE> TYPE function_cast(void *symbol)
{
union
{
- ano_module_t symbol;
+ void *symbol;
TYPE function;
} cast;
cast.symbol = symbol;
@@ -160,19 +132,18 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
if (ret != MOD_ERR_OK)
return ret;
- ano_modclearerr();
-
- ano_module_t handle = dlopen(pbuf.c_str(), RTLD_LAZY);
- const char *err = ano_moderr();
+ dlerror();
+ void *handle = dlopen(pbuf.c_str(), RTLD_LAZY);
+ const char *err = dlerror();
if (!handle && err && *err)
{
Log() << err;
return MOD_ERR_NOLOAD;
}
- ano_modclearerr();
+ dlerror();
Module *(*func)(const Anope::string &, const Anope::string &) = function_cast<Module *(*)(const Anope::string &, const Anope::string &)>(dlsym(handle, "AnopeInit"));
- err = ano_moderr();
+ err = dlerror();
if (!func && err && *err)
{
Log() << "No init function found, not an Anope module";
@@ -305,15 +276,15 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
if (!m || !m->handle)
return MOD_ERR_PARAMS;
- ano_module_t handle = m->handle;
+ void *handle = m->handle;
Anope::string filename = m->filename;
Log(LOG_DEBUG) << "Unloading module " << m->name;
- ano_modclearerr();
+ dlerror();
void (*destroy_func)(Module *m) = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
- const char *err = ano_moderr();
- if (!destroy_func || err)
+ const char *err = dlerror();
+ if (!destroy_func || (err && *err))
{
Log() << "No destroy function found for " << m->name << ", chancing delete...";
delete m; /* we just have to chance they haven't overwrote the delete operator then... */
@@ -322,10 +293,10 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
destroy_func(m); /* Let the module delete it self, just in case */
if (dlclose(handle))
- Log() << ano_moderr();
+ Log() << dlerror();
if (!filename.empty())
- DeleteFile(filename.c_str());
+ unlink(filename.c_str());
return MOD_ERR_OK;
}
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index ed739653b..1ef03bb2b 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -5,7 +5,7 @@
* @param nick The nick
* @param nickcore The nickcofe for this nick
*/
-NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings)
+NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings), Serializable("NickAlias")
{
if (nickname.empty())
throw CoreException("Empty nick passed to NickAlias constructor");
@@ -103,7 +103,7 @@ void NickAlias::OnCancel(User *)
}
}
-SerializableBase::serialized_data NickAlias::serialize()
+Serializable::serialized_data NickAlias::serialize()
{
serialized_data data;
@@ -128,7 +128,7 @@ SerializableBase::serialized_data NickAlias::serialize()
return data;
}
-void NickAlias::unserialize(SerializableBase::serialized_data &data)
+void NickAlias::unserialize(serialized_data &data)
{
NickCore *core = findcore(data["nc"].astr());
if (core == NULL)
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 6c533fb61..05d627529 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -4,7 +4,7 @@
/** Default constructor
* @param display The display nick
*/
-NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_END>(NickCoreFlagStrings)
+NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_END>(NickCoreFlagStrings), Serializable("NickCore")
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
@@ -45,7 +45,7 @@ NickCore::~NickCore()
}
}
-SerializableBase::serialized_data NickCore::serialize()
+Serializable::serialized_data NickCore::serialize()
{
serialized_data data;
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 05d27d6ca..54230d6ab 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -15,18 +15,18 @@
/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;
-std::map<Anope::string, XLine *, std::less<ci::string> > XLineManager::XLinesByUID;
+std::map<Anope::string, XLine *, ci::less> XLineManager::XLinesByUID;
-XLine::XLine()
+XLine::XLine() : Serializable("XLine")
{
}
-XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope::string &uid) : Mask(mask), Created(0), Expires(0), Reason(reason), UID(uid)
+XLine::XLine(const Anope::string &mask, const Anope::string &reason, const Anope::string &uid) : Serializable("XLine"), Mask(mask), Created(0), Expires(0), Reason(reason), UID(uid)
{
manager = NULL;
}
-XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid) : Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason), UID(uid)
+XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid) : Serializable("XLine"), Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason), UID(uid)
{
manager = NULL;
}
@@ -73,7 +73,7 @@ sockaddrs XLine::GetIP() const
return addr;
}
-SerializableBase::serialized_data XLine::serialize()
+Serializable::serialized_data XLine::serialize()
{
serialized_data data;
@@ -89,7 +89,7 @@ SerializableBase::serialized_data XLine::serialize()
return data;
}
-void XLine::unserialize(SerializableBase::serialized_data &data)
+void XLine::unserialize(serialized_data &data)
{
service_reference<XLineManager> xlm(data["manager"].astr());
if (!xlm)
@@ -327,7 +327,7 @@ std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t e
*/
XLine *XLineManager::HasEntry(const Anope::string &mask)
{
- std::map<Anope::string, XLine *, std::less<ci::string> >::iterator it = XLinesByUID.find(mask);
+ std::map<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID.find(mask);
if (it != XLinesByUID.end() && (it->second->manager == NULL || it->second->manager == this))
return it->second;
for (unsigned i = 0, end = this->XLines.size(); i < end; ++i)
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index be1562793..a7a2e2c22 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -12,7 +12,11 @@
#include "services.h"
#include "modules.h"
-SerializableBase::serialized_data BadWord::serialize()
+BadWord::BadWord() : Serializable("BadWord")
+{
+}
+
+Serializable::serialized_data BadWord::serialize()
{
serialized_data data;
@@ -23,7 +27,7 @@ SerializableBase::serialized_data BadWord::serialize()
return data;
}
-void BadWord::unserialize(SerializableBase::serialized_data &data)
+void BadWord::unserialize(serialized_data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (!ci)
@@ -35,7 +39,11 @@ void BadWord::unserialize(SerializableBase::serialized_data &data)
ci->AddBadWord(data["word"].astr(), static_cast<BadWordType>(n));
}
-SerializableBase::serialized_data AutoKick::serialize()
+AutoKick::AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString), Serializable("AutoKick")
+{
+}
+
+Serializable::serialized_data AutoKick::serialize()
{
serialized_data data;
@@ -53,7 +61,7 @@ SerializableBase::serialized_data AutoKick::serialize()
return data;
}
-void AutoKick::unserialize(SerializableBase::serialized_data &data)
+void AutoKick::unserialize(serialized_data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (ci == NULL)
@@ -70,7 +78,15 @@ void AutoKick::unserialize(SerializableBase::serialized_data &data)
ci->AddAkick(data["creator"].astr(), data["mask"].astr(), data["reason"].astr(), addtime, lastused);
}
-SerializableBase::serialized_data ModeLock::serialize()
+ModeLock::ModeLock() : Serializable("ModeLock")
+{
+}
+
+ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : Serializable("ModeLock"), ci(ch), set(s), name(n), param(p), setter(se), created(c)
+{
+}
+
+Serializable::serialized_data ModeLock::serialize()
{
serialized_data data;
@@ -87,7 +103,7 @@ SerializableBase::serialized_data ModeLock::serialize()
return data;
}
-void ModeLock::unserialize(SerializableBase::serialized_data &data)
+void ModeLock::unserialize(serialized_data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (ci == NULL)
@@ -113,7 +129,11 @@ void ModeLock::unserialize(SerializableBase::serialized_data &data)
ci->mode_locks.insert(std::make_pair(ml.name, ml));
}
-SerializableBase::serialized_data LogSetting::serialize()
+LogSetting::LogSetting() : Serializable("LogSetting")
+{
+}
+
+Serializable::serialized_data LogSetting::serialize()
{
serialized_data data;
@@ -152,7 +172,7 @@ void LogSetting::unserialize(serialized_data &data)
/** Default constructor
* @param chname The channel name
*/
-ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), Serializable("ChannelInfo"), botflags(BotServFlagStrings)
{
if (chname.empty())
throw CoreException("Empty channel passed to ChannelInfo constructor");
@@ -197,7 +217,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, C
/** Copy constructor
* @param ci The ChannelInfo to copy settings to
*/
-ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), Serializable("ChannelInfo"), botflags(BotServFlagStrings)
{
*this = ci;
@@ -279,7 +299,7 @@ ChannelInfo::~ChannelInfo()
--this->founder->channelcount;
}
-SerializableBase::serialized_data ChannelInfo::serialize()
+Serializable::serialized_data ChannelInfo::serialize()
{
serialized_data data;
@@ -319,7 +339,7 @@ SerializableBase::serialized_data ChannelInfo::serialize()
return data;
}
-void ChannelInfo::unserialize(SerializableBase::serialized_data &data)
+void ChannelInfo::unserialize(serialized_data &data)
{
ChannelInfo *ci = new ChannelInfo(data["name"].astr());
if (data.count("founder") > 0)
diff --git a/src/socketengines/pipeengine_pipe.cpp b/src/socketengines/pipeengine_pipe.cpp
index f2fa0876a..7901931c8 100644
--- a/src/socketengines/pipeengine_pipe.cpp
+++ b/src/socketengines/pipeengine_pipe.cpp
@@ -10,7 +10,7 @@ Pipe::Pipe() : Socket(-1), WritePipe(-1)
flags = fcntl(fds[1], F_GETFL, 0);
fcntl(fds[1], F_SETFL, flags | O_NONBLOCK);
- this->~Socket();
+ this->~Pipe();
this->Sock = fds[0];
this->WritePipe = fds[1];
@@ -20,13 +20,14 @@ Pipe::Pipe() : Socket(-1), WritePipe(-1)
Pipe::~Pipe()
{
- CloseSocket(this->WritePipe);
+ if (this->WritePipe >= 0)
+ close(this->WritePipe);
}
bool Pipe::ProcessRead()
{
char dummy[512];
- while (read(this->GetFD(), &dummy, 512) == 512);
+ while (read(this->GetFD(), dummy, 512) == 512);
this->OnNotify();
return true;
}
@@ -40,4 +41,3 @@ void Pipe::Notify()
void Pipe::OnNotify()
{
}
-
diff --git a/src/socketengines/pipeengine_win32.cpp b/src/socketengines/pipeengine_win32.cpp
deleted file mode 100644
index f34472870..000000000
--- a/src/socketengines/pipeengine_win32.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "services.h"
-
-Pipe::Pipe() : Socket(-1)
-{
- sockaddrs localhost;
-
- localhost.pton(AF_INET, "127.0.0.1");
-
- int cfd = socket(AF_INET, SOCK_STREAM, 0), lfd = socket(AF_INET, SOCK_STREAM, 0);
- if (cfd == -1)
- throw CoreException("Error accepting new socket for Pipe");
-
- if (bind(lfd, &localhost.sa, localhost.size()) == -1)
- throw CoreException("Error accepting new socket for Pipe");
- if (listen(lfd, 1) == -1)
- throw CoreException("Error accepting new socket for Pipe");
-
- sockaddrs lfd_addr;
- socklen_t sz = sizeof(lfd_addr);
- getsockname(lfd, &lfd_addr.sa, &sz);
-
- if (connect(cfd, &lfd_addr.sa, lfd_addr.size()))
- throw CoreException("Error accepting new socket for Pipe");
- CloseSocket(lfd);
-
- this->WritePipe = cfd;
-
- SocketEngine::AddSocket(this);
-}
-
-Pipe::~Pipe()
-{
- CloseSocket(this->WritePipe);
-}
-
-bool Pipe::ProcessRead()
-{
- char dummy[512];
- while (recv(this->GetFD(), dummy, 512, 0) == 512);
- this->OnNotify();
- return true;
-}
-
-void Pipe::Notify()
-{
- const char dummy = '*';
- send(this->WritePipe, &dummy, 1, 0);
-}
-
-void Pipe::OnNotify()
-{
-}
-
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp
index 663cdd9ca..89a5c47c3 100644
--- a/src/socketengines/socketengine_select.cpp
+++ b/src/socketengines/socketengine_select.cpp
@@ -1,5 +1,10 @@
#include "module.h"
+#ifdef _AIX
+# undef FD_ZERO
+# define FD_ZERO(p) memset((p), 0, sizeof(*(p)))
+#endif /* _AIX */
+
static int MaxFD;
static unsigned FDCount;
static fd_set ReadFDs;
@@ -77,7 +82,7 @@ void SocketEngine::Process()
*/
if (FDCount == 0)
{
- sleep(Config->ReadTimeout);
+ sleep(tval.tv_sec);
return;
}
#endif
diff --git a/src/sockets.cpp b/src/sockets.cpp
index fa79d32f2..5e65a521c 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -285,11 +285,7 @@ ClientSocket *SocketIO::Accept(ListenSocket *s)
socklen_t size = sizeof(conaddr);
int newsock = accept(s->GetFD(), &conaddr.sa, &size);
-#ifndef INVALID_SOCKET
- static const int INVALID_SOCKET = -1;
-#endif
-
- if (newsock >= 0 && newsock != INVALID_SOCKET)
+ if (newsock >= 0)
{
ClientSocket *ns = s->OnAccept(newsock, conaddr);
ns->SetFlag(SF_ACCEPTED);
@@ -406,7 +402,7 @@ Socket::Socket(int sock, bool ipv6, int type) : Flags<SocketFlag>(SocketFlagStri
Socket::~Socket()
{
SocketEngine::DelSocket(this);
- CloseSocket(this->Sock);
+ close(this->Sock);
this->IO->Destroy();
}
@@ -431,13 +427,8 @@ bool Socket::IsIPv6() const
*/
bool Socket::SetBlocking()
{
-#ifdef _WIN32
- unsigned long opt = 0;
- return !ioctlsocket(this->GetFD(), FIONBIO, &opt);
-#else
int flags = fcntl(this->GetFD(), F_GETFL, 0);
return !fcntl(this->GetFD(), F_SETFL, flags & ~O_NONBLOCK);
-#endif
}
/** Mark a socket as non-blocking
@@ -445,13 +436,8 @@ bool Socket::SetBlocking()
*/
bool Socket::SetNonBlocking()
{
-#ifdef _WIN32
- unsigned long opt = 1;
- return !ioctlsocket(this->GetFD(), FIONBIO, &opt);
-#else
int flags = fcntl(this->GetFD(), F_GETFL, 0);
return !fcntl(this->GetFD(), F_SETFL, flags | O_NONBLOCK);
-#endif
}
/** Bind the socket to an ip and port
@@ -503,10 +489,8 @@ ListenSocket::ListenSocket(const Anope::string &bindip, int port, bool ipv6) : S
{
this->SetNonBlocking();
-#ifndef _WIN32
- int op = 1;
+ const char op = 1;
setsockopt(this->GetFD(), SOL_SOCKET, SO_REUSEADDR, &op, sizeof(op));
-#endif
this->bindaddr.pton(IPv6 ? AF_INET6 : AF_INET, bindip, port);
this->IO->Bind(this, bindip, port);
diff --git a/src/threadengine.cpp b/src/threadengine.cpp
index e11b065ea..c186e49a2 100644
--- a/src/threadengine.cpp
+++ b/src/threadengine.cpp
@@ -1,5 +1,35 @@
#include "services.h"
+static inline pthread_attr_t *get_engine_attr()
+{
+ /* Threadengine attributes used by this thread engine */
+ static pthread_attr_t attr;
+ static bool inited = false;
+
+ if (inited == false)
+ {
+ if (pthread_attr_init(&attr))
+ throw CoreException("Error calling pthread_attr_init");
+ if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE))
+ throw CoreException("Unable to mark threads as joinable");
+ inited = true;
+ }
+
+ return &attr;
+}
+
+/** Entry point used for the threads
+ * @param parameter A Thread* cast to a void*
+ */
+static void *entry_point(void *parameter)
+{
+ Thread *thread = static_cast<Thread *>(parameter);
+ thread->Run();
+ thread->SetExitState();
+ pthread_exit(0);
+ return NULL;
+}
+
/** Threads constructor
*/
Thread::Thread() : exit(false)
@@ -12,6 +42,14 @@ Thread::~Thread()
{
}
+/** Join to the thread, sets the exit state to true
+ */
+void Thread::Join()
+{
+ this->SetExitState();
+ pthread_join(Handle, NULL);
+}
+
/** Sets the exit state as true informing the thread we want it to shut down
*/
void Thread::SetExitState()
@@ -20,6 +58,25 @@ void Thread::SetExitState()
exit = true;
}
+/** Exit the thread. Note that the thread still must be joined to free resources!
+ */
+void Thread::Exit()
+{
+ this->SetExitState();
+ pthread_exit(0);
+}
+
+/** Launch the thread
+ */
+void Thread::Start()
+{
+ if (pthread_create(&this->Handle, get_engine_attr(), entry_point, this))
+ {
+ this->SetFlag(SF_DEAD);
+ throw CoreException("Unable to create thread: " + Anope::LastError());
+ }
+}
+
/** Returns the exit state of the thread
* @return true if we want to exit
*/
@@ -36,3 +93,67 @@ void Thread::OnNotify()
this->SetFlag(SF_DEAD);
}
+/** Constructor
+ */
+Mutex::Mutex()
+{
+ pthread_mutex_init(&mutex, NULL);
+}
+
+/** Destructor
+ */
+Mutex::~Mutex()
+{
+ pthread_mutex_destroy(&mutex);
+}
+
+/** Attempt to lock the mutex, will hang until a lock can be achieved
+ */
+void Mutex::Lock()
+{
+ pthread_mutex_lock(&mutex);
+}
+
+/** Unlock the mutex, it must be locked first
+ */
+void Mutex::Unlock()
+{
+ pthread_mutex_unlock(&mutex);
+}
+
+/** Attempt to lock the mutex, will return true on success and false on fail
+ * Does not block
+ * @return true or false
+ */
+bool Mutex::TryLock()
+{
+ return pthread_mutex_trylock(&mutex) == 0;
+}
+
+/** Constructor
+ */
+Condition::Condition() : Mutex()
+{
+ pthread_cond_init(&cond, NULL);
+}
+
+/** Destructor
+ */
+Condition::~Condition()
+{
+ pthread_cond_destroy(&cond);
+}
+
+/** Called to wakeup the waiter
+ */
+void Condition::Wakeup()
+{
+ pthread_cond_signal(&cond);
+}
+
+/** Called to wait for a Wakeup() call
+ */
+void Condition::Wait()
+{
+ pthread_cond_wait(&cond, &mutex);
+}
diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp
deleted file mode 100644
index 987b8bc61..000000000
--- a/src/threadengines/threadengine_pthread.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "services.h"
-
-static inline pthread_attr_t *get_engine_attr()
-{
- /* Threadengine attributes used by this thread engine */
- static pthread_attr_t attr;
- static bool inited = false;
-
- if (inited == false)
- {
- if (pthread_attr_init(&attr))
- throw CoreException("Error calling pthread_attr_init");
- if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE))
- throw CoreException("Unable to mark threads as joinable");
- inited = true;
- }
-
- return &attr;
-}
-
-/** Entry point used for the threads
- * @param parameter A Thread* cast to a void*
- */
-static void *entry_point(void *parameter)
-{
- Thread *thread = static_cast<Thread *>(parameter);
- thread->Run();
- thread->SetExitState();
- pthread_exit(0);
-}
-
-/** Join to the thread, sets the exit state to true
- */
-void Thread::Join()
-{
- this->SetExitState();
- pthread_join(Handle, NULL);
-}
-
-/** Exit the thread. Note that the thread still must be joined to free resources!
- */
-void Thread::Exit()
-{
- this->SetExitState();
- pthread_exit(0);
-}
-
-/** Launch the thread
- */
-void Thread::Start()
-{
- if (pthread_create(&this->Handle, get_engine_attr(), entry_point, this))
- {
- this->SetFlag(SF_DEAD);
- throw CoreException("Unable to create thread: " + Anope::LastError());
- }
-}
-
-/** Constructor
- */
-Mutex::Mutex()
-{
- pthread_mutex_init(&mutex, NULL);
-}
-
-/** Destructor
- */
-Mutex::~Mutex()
-{
- pthread_mutex_destroy(&mutex);
-}
-
-/** Attempt to lock the mutex, will hang until a lock can be achieved
- */
-void Mutex::Lock()
-{
- pthread_mutex_lock(&mutex);
-}
-
-/** Unlock the mutex, it must be locked first
- */
-void Mutex::Unlock()
-{
- pthread_mutex_unlock(&mutex);
-}
-
-/** Attempt to lock the mutex, will return true on success and false on fail
- * Does not block
- * @return true or false
- */
-bool Mutex::TryLock()
-{
- return pthread_mutex_trylock(&mutex) == 0;
-}
-
-/** Constructor
- */
-Condition::Condition() : Mutex()
-{
- pthread_cond_init(&cond, NULL);
-}
-
-/** Destructor
- */
-Condition::~Condition()
-{
- pthread_cond_destroy(&cond);
-}
-
-/** Called to wakeup the waiter
- */
-void Condition::Wakeup()
-{
- pthread_cond_signal(&cond);
-}
-
-/** Called to wait for a Wakeup() call
- */
-void Condition::Wait()
-{
- pthread_cond_wait(&cond, &mutex);
-}
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
deleted file mode 100644
index 5b6739c52..000000000
--- a/src/threadengines/threadengine_win32.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-#include "services.h"
-
-/** Entry point for the thread
- * @param paramter A Thread* cast to a void*
- */
-static DWORD WINAPI entry_point(void *parameter)
-{
- Thread *thread = static_cast<Thread *>(parameter);
- thread->Run();
- thread->SetExitState();
- return 0;
-}
-
-/** Join to the thread, sets the exit state to true
- */
-void Thread::Join()
-{
- this->SetExitState();
- WaitForSingleObject(Handle, INFINITE);
-}
-
-/** Exit the thread. Note that the thread still must be joined to free resources!
- */
-void Thread::Exit()
-{
- this->SetExitState();
- ExitThread(0);
-}
-
-/** Launch the thread
- */
-void Thread::Start()
-{
- this->Handle = CreateThread(NULL, 0, entry_point, this, 0, NULL);
-
- if (!this->Handle)
- {
- this->SetFlag(SF_DEAD);
- throw CoreException("Unable to create thread: " + Anope::LastError());
- }
-}
-
-/** Constructor
- */
-Mutex::Mutex()
-{
- InitializeCriticalSection(&mutex);
-}
-
-/** Destructor
- */
-Mutex::~Mutex()
-{
- DeleteCriticalSection(&mutex);
-}
-
-/** Attempt to lock the mutex, will hang until a lock can be achieved
- */
-void Mutex::Lock()
-{
- EnterCriticalSection(&mutex);
-}
-
-/** Unlock the mutex, it must be locked first
- */
-void Mutex::Unlock()
-{
- LeaveCriticalSection(&mutex);
-}
-
-/** Attempt to lock the mutex, will return true on success and false on fail
- * Does not block
- * @return true or false
- */
-bool Mutex::TryLock()
-{
- return TryEnterCriticalSection(&mutex);
-}
-
-/** Constructor
- */
-Condition::Condition() : Mutex()
-{
- cond = CreateEvent(NULL, false, false, NULL);
-}
-
-/** Destructor
- */
-Condition::~Condition()
-{
- CloseHandle(cond);
-}
-
-/** Called to wakeup the waiter
- */
-void Condition::Wakeup()
-{
- PulseEvent(cond);
-}
-
-/** Called to wait for a Wakeup() call
- */
-void Condition::Wait()
-{
- LeaveCriticalSection(&mutex);
- WaitForSingleObject(cond, INFINITE);
- EnterCriticalSection(&mutex);
-}
diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h
index a631a4a70..cd5215298 100644
--- a/src/win32/anope_windows.h
+++ b/src/win32/anope_windows.h
@@ -1,71 +1,75 @@
- /* POSIX emulation layer for Windows.
- *
- * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
- * Copyright (C) 2008-2011 Anope Team <info@anope.org>
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
- #ifndef WINDOWS_H
- #define WINDOWS_H
- #ifdef _WIN32
-
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <windows.h>
-#include <sys/timeb.h>
-#include <direct.h>
-#include <io.h>
-#ifdef MODULE_COMPILE
-# define CoreExport __declspec(dllimport)
-# define DllExport __declspec(dllexport)
-#else
-# define CoreExport __declspec(dllexport)
-# define DllExport __declspec(dllimport)
-#endif
-/* We have our own inet_pton and inet_ntop (Windows XP doesn't have its own) */
-#define inet_pton inet_pton_
-#define inet_ntop inet_ntop_
-#define setenv(x, y, z) SetEnvironmentVariable(x, y)
-#define unsetenv(x) SetEnvironmentVariable(x, NULL)
-#define MARK_DEPRECATED
-#if GETTEXT_FOUND
-/* Undefine some functions libintl defines */
-# undef snprintf
-# undef vsnprintf
-# undef printf
-#endif
-#define snprintf _snprintf
-/* VS2008 hates having this define before its own */
-#define vsnprintf _vsnprintf
-#define stat _stat
-#define getcwd(x, y) GetCurrentDirectory(y, x)
-#define getpid GetCurrentProcessId
-#define S_ISREG(x) ((x) & _S_IFREG)
-#ifdef EINPROGRESS
-# undef EINPROGRESS
-#endif
-#define EINPROGRESS WSAEWOULDBLOCK
-
-#include "sigaction/sigaction.h"
-
-namespace Anope
-{
- class string;
-}
-
-extern CoreExport void OnStartup();
-extern CoreExport void OnShutdown();
-extern CoreExport USHORT WindowsGetLanguage(const char *lang);
-extern CoreExport int inet_pton(int af, const char *src, void *dst);
-extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size_t size);
-extern CoreExport int gettimeofday(timeval *tv, void *);
-extern CoreExport Anope::string GetWindowsVersion();
-extern CoreExport bool SupportedWindowsVersion();
-extern int mkstemp(char *input);
-
- #endif // _WIN32
- #endif // WINDOWS_H
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
+ * Copyright (C) 2008-2011 Anope Team <info@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+ #ifndef WINDOWS_H
+ #define WINDOWS_H
+ #ifdef _WIN32
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#include <sys/timeb.h>
+#include <direct.h>
+
+#ifdef MODULE_COMPILE
+# define CoreExport __declspec(dllimport)
+# define DllExport __declspec(dllexport)
+#else
+# define CoreExport __declspec(dllexport)
+# define DllExport __declspec(dllimport)
+#endif
+
+#define MARK_DEPRECATED
+
+#if GETTEXT_FOUND
+/* Undefine some functions libintl defines */
+# undef snprintf
+# undef vsnprintf
+# undef printf
+#endif
+
+#define snprintf _snprintf
+/* VS2008 hates having this define before its own */
+#define vsnprintf _vsnprintf
+
+#define stat _stat
+#define S_ISREG(x) ((x) & _S_IFREG)
+
+#ifdef EINPROGRESS
+# undef EINPROGRESS
+#endif
+#define EINPROGRESS WSAEWOULDBLOCK
+
+#include "socket.h"
+#include "dir/dir.h"
+#include "dl/dl.h"
+#include "pipe/pipe.h"
+#include "pthread/pthread.h"
+#include "sigaction/sigaction.h"
+
+namespace Anope
+{
+ class string;
+}
+
+extern CoreExport void OnStartup();
+extern CoreExport void OnShutdown();
+extern CoreExport USHORT WindowsGetLanguage(const char *lang);
+extern CoreExport int gettimeofday(timeval *tv, void *);
+extern CoreExport Anope::string GetWindowsVersion();
+extern CoreExport bool SupportedWindowsVersion();
+extern int setenv(const char *name, const char *value, int overwrite);
+extern int unsetenv(const char *name);
+extern int mkstemp(char *input);
+extern void getcwd(char *buf, size_t sz);
+
+#endif // _WIN32
+#endif // WINDOWS_H
diff --git a/src/win32/dir/dir.cpp b/src/win32/dir/dir.cpp
new file mode 100644
index 000000000..28a54be98
--- /dev/null
+++ b/src/win32/dir/dir.cpp
@@ -0,0 +1,47 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "dir.h"
+#include <stdio.h>
+
+DIR *opendir(const char *path)
+{
+ char real_path[MAX_PATH];
+ _snprintf(real_path, sizeof(real_path), "%s/*", path);
+
+ DIR *d = new DIR();
+ d->handle = FindFirstFile(real_path, &d->data);
+ d->read_first = false;
+
+ if (d->handle == INVALID_HANDLE_VALUE)
+ {
+ delete d;
+ return NULL;
+ }
+
+ return d;
+}
+
+dirent *readdir(DIR *d)
+{
+ if (d->read_first == false)
+ d->read_first = true;
+ else if (!FindNextFile(d->handle, &d->data))
+ return NULL;
+
+ d->ent.d_ino = 1;
+ d->ent.d_name = d->data.cFileName;
+
+ return &d->ent;
+}
+
+int closedir(DIR *d)
+{
+ FindClose(d->handle);
+ delete d;
+ return 0;
+}
diff --git a/src/win32/dir/dir.h b/src/win32/dir/dir.h
new file mode 100644
index 000000000..8e04c01cc
--- /dev/null
+++ b/src/win32/dir/dir.h
@@ -0,0 +1,26 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include <windows.h>
+
+struct dirent
+{
+ int d_ino;
+ char *d_name;
+};
+
+struct DIR
+{
+ dirent ent;
+ HANDLE handle;
+ WIN32_FIND_DATA data;
+ bool read_first;
+};
+
+DIR *opendir(const char *);
+dirent *readdir(DIR *);
+int closedir(DIR *);
diff --git a/src/win32/dl/dl.cpp b/src/win32/dl/dl.cpp
new file mode 100644
index 000000000..8d76e1f0d
--- /dev/null
+++ b/src/win32/dl/dl.cpp
@@ -0,0 +1,30 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "services.h"
+
+void *dlopen(const char *filename, int)
+{
+ return LoadLibrary(filename);
+}
+
+char *dlerror(void)
+{
+ static Anope::string err = Anope::LastError();
+ SetLastError(0);
+ return err.empty() ? NULL : const_cast<char *>(err.c_str());
+}
+
+void *dlsym(void *handle, const char *symbol)
+{
+ return GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol);
+}
+
+int dlclose(void *handle)
+{
+ return !FreeLibrary(reinterpret_cast<HMODULE>(handle));
+}
diff --git a/src/win32/dl/dl.h b/src/win32/dl/dl.h
new file mode 100644
index 000000000..686611594
--- /dev/null
+++ b/src/win32/dl/dl.h
@@ -0,0 +1,13 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#define RTLD_LAZY 0
+
+extern void *dlopen(const char *filename, int);
+extern char *dlerror(void);
+extern void *dlsym(void *handle, const char *symbol);
+extern int dlclose(void *handle);
diff --git a/src/win32/pipe/pipe.cpp b/src/win32/pipe/pipe.cpp
new file mode 100644
index 000000000..94e204d9a
--- /dev/null
+++ b/src/win32/pipe/pipe.cpp
@@ -0,0 +1,61 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "services.h"
+
+int pipe(int fds[2])
+{
+ sockaddrs localhost;
+
+ localhost.pton(AF_INET, "127.0.0.1");
+
+ int cfd = socket(AF_INET, SOCK_STREAM, 0), lfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (cfd == -1 || lfd == -1)
+ {
+ close(cfd);
+ close(lfd);
+ return -1;
+ }
+
+ if (bind(lfd, &localhost.sa, localhost.size()) == -1)
+ {
+ close(cfd);
+ close(lfd);
+ return -1;
+ }
+
+ if (listen(lfd, 1) == -1)
+ {
+ close(cfd);
+ close(lfd);
+ return -1;
+ }
+
+ sockaddrs lfd_addr;
+ socklen_t sz = sizeof(lfd_addr);
+ getsockname(lfd, &lfd_addr.sa, &sz);
+
+ if (connect(cfd, &lfd_addr.sa, lfd_addr.size()))
+ {
+ close(cfd);
+ close(lfd);
+ return -1;
+ }
+
+ int afd = accept(lfd, NULL, NULL);
+ if (afd == -1)
+ {
+ close(cfd);
+ return -1;
+ }
+
+ fds[0] = cfd;
+ fds[1] = afd;
+
+ return 0;
+}
+
diff --git a/src/win32/pipe/pipe.h b/src/win32/pipe/pipe.h
new file mode 100644
index 000000000..1e8538cfb
--- /dev/null
+++ b/src/win32/pipe/pipe.h
@@ -0,0 +1,8 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+extern int pipe(int fds[2]);
diff --git a/src/win32/pthread/pthread.cpp b/src/win32/pthread/pthread.cpp
new file mode 100644
index 000000000..8c1da7555
--- /dev/null
+++ b/src/win32/pthread/pthread.cpp
@@ -0,0 +1,117 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "pthread.h"
+
+struct ThreadInfo
+{
+ void *(*entry)(void *);
+ void *param;
+};
+
+static DWORD WINAPI entry_point(void *parameter)
+{
+ ThreadInfo *ti = static_cast<ThreadInfo *>(parameter);
+ ti->entry(ti->param);
+ delete ti;
+ return 0;
+}
+
+int pthread_attr_init(pthread_attr_t *)
+{
+ /* No need for this */
+ return 0;
+}
+
+int pthread_attr_setdetachstate(pthread_attr_t *, int)
+{
+ /* No need for this */
+ return 0;
+}
+
+int pthread_create(pthread_t *thread, const pthread_attr_t *, void *(*entry)(void *), void *param)
+{
+ ThreadInfo *ti = new ThreadInfo;
+ ti->entry = entry;
+ ti->param = param;
+
+ *thread = CreateThread(NULL, 0, entry_point, ti, 0, NULL);
+ if (!*thread)
+ {
+ delete ti;
+ return -1;
+ }
+
+ return 0;
+}
+
+int pthread_join(pthread_t thread, void **)
+{
+ if (WaitForSingleObject(thread, INFINITE) == WAIT_FAILED)
+ return -1;
+ return 0;
+}
+
+void pthread_exit(int i)
+{
+ ExitThread(i);
+}
+
+int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *)
+{
+ InitializeCriticalSection(mutex);
+ return 0;
+}
+
+int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ DeleteCriticalSection(mutex);
+ return 0;
+}
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ EnterCriticalSection(mutex);
+ return 0;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+ return !TryEnterCriticalSection(mutex);
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ LeaveCriticalSection(mutex);
+ return 0;
+}
+
+int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *)
+{
+ *cond = CreateEvent(NULL, false, false, NULL);
+ if (*cond == NULL)
+ return -1;
+ return 0;
+}
+
+int pthread_cond_destroy(pthread_cond_t *cond)
+{
+ return !CloseHandle(*cond);
+}
+
+int pthread_cond_signal(pthread_cond_t *cond)
+{
+ return !PulseEvent(*cond);
+}
+
+int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
+{
+ LeaveCriticalSection(mutex);
+ WaitForSingleObject(*cond, INFINITE);
+ EnterCriticalSection(mutex);
+ return 0;
+}
diff --git a/src/win32/pthread/pthread.h b/src/win32/pthread/pthread.h
new file mode 100644
index 000000000..5ec0775ea
--- /dev/null
+++ b/src/win32/pthread/pthread.h
@@ -0,0 +1,34 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include <Windows.h>
+
+typedef HANDLE pthread_t;
+typedef CRITICAL_SECTION pthread_mutex_t;
+typedef HANDLE pthread_cond_t;
+typedef int pthread_attr_t;
+typedef void pthread_mutexattr_t;
+typedef void pthread_condattr_t;
+
+#define PTHREAD_CREATE_JOINABLE 0
+
+extern int pthread_attr_init(pthread_attr_t *);
+extern int pthread_attr_setdetachstate(pthread_attr_t *, int);
+extern int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
+extern int pthread_join(pthread_t, void **);
+extern void pthread_exit(int);
+
+extern int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
+extern int pthread_mutex_destroy(pthread_mutex_t *);
+extern int pthread_mutex_lock(pthread_mutex_t *);
+extern int pthread_mutex_trylock(pthread_mutex_t *);
+extern int pthread_mutex_unlock(pthread_mutex_t *);
+
+extern int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
+extern int pthread_cond_destroy(pthread_cond_t *);
+extern int pthread_cond_signal(pthread_cond_t *);
+extern int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
diff --git a/src/win32/sigaction/sigaction.cpp b/src/win32/sigaction/sigaction.cpp
index f65ffaa84..e79187461 100644
--- a/src/win32/sigaction/sigaction.cpp
+++ b/src/win32/sigaction/sigaction.cpp
@@ -1,31 +1,31 @@
- /* POSIX emulation layer for Windows.
- *
- * Copyright (C) 2008-2011 Anope Team <team@anope.org>
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
- #include <windows.h>
- #include "sigaction.h"
- #include <signal.h>
-
- int sigaction(int sig, struct sigaction *action, struct sigaction *old)
- {
- if (sig == -1)
- return 0;
- if (old == NULL)
- {
- if (signal(sig, SIG_DFL) == SIG_ERR)
- return -1;
- }
- else
- {
- if (signal(sig, action->sa_handler) == SIG_ERR)
- return -1;
- }
- return 0;
- }
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+ #include <windows.h>
+ #include "sigaction.h"
+ #include <signal.h>
+
+ int sigaction(int sig, struct sigaction *action, struct sigaction *old)
+ {
+ if (sig == -1)
+ return 0;
+ if (old == NULL)
+ {
+ if (signal(sig, SIG_DFL) == SIG_ERR)
+ return -1;
+ }
+ else
+ {
+ if (signal(sig, action->sa_handler) == SIG_ERR)
+ return -1;
+ }
+ return 0;
+ }
\ No newline at end of file
diff --git a/src/win32/sigaction/sigaction.h b/src/win32/sigaction/sigaction.h
index 366965f8b..96d67e8e9 100644
--- a/src/win32/sigaction/sigaction.h
+++ b/src/win32/sigaction/sigaction.h
@@ -1,28 +1,28 @@
- /* POSIX emulation layer for Windows.
- *
- * Copyright (C) 2008-2011 Anope Team <team@anope.org>
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
- #define sigemptyset(x) memset((x), 0, sizeof(*(x)))
-
- #ifndef SIGHUP
- # define SIGHUP -1
- #endif
- #ifndef SIGPIPE
- # define SIGPIPE -1
- #endif
-
- struct sigaction
- {
- void (*sa_handler)(int);
- int sa_flags;
- int sa_mask;
- };
-
- extern int sigaction(int, struct sigaction *, struct sigaction *);
-
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+ #define sigemptyset(x) memset((x), 0, sizeof(*(x)))
+
+ #ifndef SIGHUP
+ # define SIGHUP -1
+ #endif
+ #ifndef SIGPIPE
+ # define SIGPIPE -1
+ #endif
+
+ struct sigaction
+ {
+ void (*sa_handler)(int);
+ int sa_flags;
+ int sa_mask;
+ };
+
+ extern int sigaction(int, struct sigaction *, struct sigaction *);
+
diff --git a/src/win32/socket.cpp b/src/win32/socket.cpp
new file mode 100644
index 000000000..42140ed8b
--- /dev/null
+++ b/src/win32/socket.cpp
@@ -0,0 +1,152 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#define WIN32_NO_OVERRIDE
+#include "services.h"
+
+inline static bool is_socket(int fd)
+{
+ int optval;
+ socklen_t optlen = sizeof(optval);
+ return getsockopt(fd, SOL_SOCKET, SO_TYPE, reinterpret_cast<char *>(&optval), &optlen) == 0;
+}
+
+int read(int fd, char *buf, size_t count)
+{
+ if (is_socket(fd))
+ return recv(fd, buf, count, 0);
+ else
+ return _read(fd, buf, count);
+}
+
+int write(int fd, const char *buf, size_t count)
+{
+ if (is_socket(fd))
+ return send(fd, buf, count, 0);
+ else
+ return _write(fd, buf, count);
+}
+
+int windows_close(int fd)
+{
+ if (is_socket(fd))
+ return closesocket(fd);
+ else
+ return close(fd);
+}
+
+int windows_accept(int fd, struct sockaddr *addr, int *addrlen)
+{
+ int i = accept(fd, addr, addrlen);
+ if (i == INVALID_SOCKET)
+ return -1;
+ return i;
+}
+
+/** This is inet_pton, but it works on Windows
+ * @param af The protocol type, AF_INET or AF_INET6
+ * @param src The address
+ * @param dst Struct to put results in
+ * @return 1 on sucess, -1 on error
+ */
+int windows_inet_pton(int af, const char *src, void *dst)
+{
+ int address_length;
+ sockaddr_storage sa;
+ sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa);
+ sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa);
+
+ switch (af)
+ {
+ case AF_INET:
+ address_length = sizeof(sockaddr_in);
+ break;
+ case AF_INET6:
+ address_length = sizeof(sockaddr_in6);
+ break;
+ default:
+ return -1;
+ }
+
+ if (!WSAStringToAddress(static_cast<LPSTR>(const_cast<char *>(src)), af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length))
+ {
+ switch (af)
+ {
+ case AF_INET:
+ memcpy(dst, &sin->sin_addr, sizeof(in_addr));
+ break;
+ case AF_INET6:
+ memcpy(dst, &sin6->sin6_addr, sizeof(in6_addr));
+ break;
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
+/** This is inet_ntop, but it works on Windows
+ * @param af The protocol type, AF_INET or AF_INET6
+ * @param src Network address structure
+ * @param dst After converting put it here
+ * @param size sizeof the dest
+ * @return dst
+ */
+const char *windows_inet_ntop(int af, const void *src, char *dst, size_t size)
+{
+ int address_length;
+ DWORD string_length = size;
+ sockaddr_storage sa;
+ sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa);
+ sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa);
+
+ memset(&sa, 0, sizeof(sa));
+
+ switch (af)
+ {
+ case AF_INET:
+ address_length = sizeof(sockaddr_in);
+ sin->sin_family = af;
+ memcpy(&sin->sin_addr, src, sizeof(in_addr));
+ break;
+ case AF_INET6:
+ address_length = sizeof(sockaddr_in6);
+ sin6->sin6_family = af;
+ memcpy(&sin6->sin6_addr, src, sizeof(in6_addr));
+ break;
+ default:
+ return NULL;
+ }
+
+ if (!WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&sa), address_length, NULL, dst, &string_length))
+ return dst;
+
+ return NULL;
+}
+
+int fcntl(int fd, int cmd, int arg)
+{
+ if (cmd == F_GETFL)
+ {
+ return 0;
+ }
+ else if (cmd == F_SETFL)
+ {
+ if (arg & O_NONBLOCK)
+ {
+ unsigned long opt = 1;
+ return ioctlsocket(fd, FIONBIO, &opt);
+ }
+ else
+ {
+ unsigned long opt = 0;
+ return ioctlsocket(fd, FIONBIO, &opt);
+ }
+ }
+
+ return -1;
+}
diff --git a/src/win32/socket.h b/src/win32/socket.h
new file mode 100644
index 000000000..106b9310e
--- /dev/null
+++ b/src/win32/socket.h
@@ -0,0 +1,32 @@
+ /* POSIX emulation layer for Windows.
+ *
+ * Copyright (C) 2008-2011 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#define read read_not_used
+#define write write_not_used
+#include <io.h>
+#undef read
+#undef write
+
+#define F_GETFL 0
+#define F_SETFL 1
+
+#define O_NONBLOCK 1
+
+extern CoreExport int read(int fd, char *buf, size_t count);
+extern CoreExport int write(int fd, const char *buf, size_t count);
+extern CoreExport int windows_close(int fd);
+extern CoreExport int windows_accept(int fd, struct sockaddr *addr, int *addrlen);
+extern CoreExport int windows_inet_pton(int af, const char *src, void *dst);
+extern CoreExport const char *windows_inet_ntop(int af, const void *src, char *dst, size_t size);
+extern CoreExport int fcntl(int fd, int cmd, int arg);
+
+#ifndef WIN32_NO_OVERRIDE
+# define close windows_close
+# define accept windows_accept
+# define inet_pton windows_inet_pton
+# define inet_ntop windows_inet_ntop
+#endif
diff --git a/src/win32/vsvars32.bat b/src/win32/vsvars32.bat
deleted file mode 100644
index f1aee215e..000000000
--- a/src/win32/vsvars32.bat
+++ /dev/null
@@ -1,66 +0,0 @@
-@SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8
-@SET VCINSTALLDIR=%VSINSTALLDIR%\VC
-@SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
-@SET FrameworkVersion=v2.0.50727
-@SET FrameworkSDKDir=%VSINSTALLDIR%\SDK\v2.0
-@SET Framework35Version=v3.5
-@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR
-@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR
-
-@echo Setting environment for using Microsoft Visual Studio 2005 x86 tools.
-
-@call :GetWindowsSdkDir
-
-@if not "%WindowsSdkDir%" == "" (
- set "PATH=%WindowsSdkDir%bin;%PATH%"
- set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
- set "LIB=%WindowsSdkDir%lib;%LIB%"
-)
-
-@rem
-@rem Root of Visual Studio IDE installed files.
-@rem
-@set DevEnvDir=%VSINSTALLDIR%\Common7\IDE
-
-@set PATH=%VSINSTALLDIR%\Common7\IDE;%VCINSTALLDIR%\BIN;%VSINSTALLDIR%\Common7\Tools;C:\WINDOWS\Microsoft.NET\Framework\v3.5;%VSINSTALLDIR%\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;%VCINSTALLDIR%\VCPackages;%PATH%
-@set INCLUDE=%VCINSTALLDIR%\INCLUDE;%INCLUDE%
-@set LIB=%VCINSTALLDIR%\LIB;%VSINSTALLDIR%\SDK\v2.0\lib;%LIB%
-@set LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v3.5;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;%VCINSTALLDIR%\LIB;%LIBPATH%
-
-@goto end
-
-:GetWindowsSdkDir
-@call :GetWindowsSdk2008DirHelper HKLM > nul 2>&1
-@if errorlevel 1 call :GetWindowsSdk2003DirHelper HKLM > nul 2>&1
-@if errorlevel 1 call :GetWindowsSdk2008DirHelper HKCU > nul 2>&1
-@if errorlevel 1 call :GetWindowsSdk2003DirHelper HKCU > nul 2>&1
-@if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\
-@exit /B 0
-
-:GetWindowsSdk2008DirHelper
-@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
- if "%%i"=="CurrentInstallFolder" (
- SET "WindowsSdkDir=%%k"
- )
-)
-@if "%WindowsSdkDir%"=="" exit /B 1
-@exit /B 0
-
-:GetWindowsSdk2003DirHelper
-@for /F "tokens=1,2,3*" %%i in ('reg query "%1\SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1" /v "Install Dir"') DO (
- if "%%i %%j"=="Install Dir" (
- SET "WindowsSdkDir=%%l"
- )
-)
-@if "%WindowsSdkDir%"=="" exit /B 1
-@exit /B 0
-
-:error_no_VSINSTALLDIR
-@echo ERROR: VSINSTALLDIR variable is not set.
-@goto end
-
-:error_no_VCINSTALLDIR
-@echo ERROR: VCINSTALLDIR variable is not set.
-@goto end
-
-:end
diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp
index 60edaffbc..139a17736 100644
--- a/src/win32/windows.cpp
+++ b/src/win32/windows.cpp
@@ -12,13 +12,11 @@
#ifdef _WIN32
#include "services.h"
-struct WindowsLanguage
+static struct WindowsLanguage
{
const char *languageName;
USHORT windowsLanguageName;
-};
-
-WindowsLanguage WindowsLanguages[] = {
+} WindowsLanguages[] = {
{"ca_ES", LANG_CATALAN},
{"de_DE", LANG_GERMAN},
{"el_GR", LANG_GREEK},
@@ -34,7 +32,7 @@ WindowsLanguage WindowsLanguages[] = {
{NULL, 0}
};
-WSADATA wsa;
+static WSADATA wsa;
void OnStartup()
{
@@ -55,87 +53,6 @@ USHORT WindowsGetLanguage(const char *lang)
return LANG_NEUTRAL;
}
-/** This is inet_pton, but it works on Windows
- * @param af The protocol type, AF_INET or AF_INET6
- * @param src The address
- * @param dst Struct to put results in
- * @return 1 on sucess, -1 on error
- */
-int inet_pton(int af, const char *src, void *dst)
-{
- int address_length;
- sockaddr_storage sa;
- sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa);
- sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa);
-
- switch (af)
- {
- case AF_INET:
- address_length = sizeof(sockaddr_in);
- break;
- case AF_INET6:
- address_length = sizeof(sockaddr_in6);
- break;
- default:
- return -1;
- }
-
- if (!WSAStringToAddress(static_cast<LPSTR>(const_cast<char *>(src)), af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length))
- {
- switch (af)
- {
- case AF_INET:
- memcpy(dst, &sin->sin_addr, sizeof(in_addr));
- break;
- case AF_INET6:
- memcpy(dst, &sin6->sin6_addr, sizeof(in6_addr));
- break;
- }
- return 1;
- }
-
- return 0;
-}
-
-/** This is inet_ntop, but it works on Windows
- * @param af The protocol type, AF_INET or AF_INET6
- * @param src Network address structure
- * @param dst After converting put it here
- * @param size sizeof the dest
- * @return dst
- */
-const char *inet_ntop(int af, const void *src, char *dst, size_t size)
-{
- int address_length;
- DWORD string_length = size;
- sockaddr_storage sa;
- sockaddr_in *sin = reinterpret_cast<sockaddr_in *>(&sa);
- sockaddr_in6 *sin6 = reinterpret_cast<sockaddr_in6 *>(&sa);
-
- memset(&sa, 0, sizeof(sa));
-
- switch (af)
- {
- case AF_INET:
- address_length = sizeof(sockaddr_in);
- sin->sin_family = af;
- memcpy(&sin->sin_addr, src, sizeof(in_addr));
- break;
- case AF_INET6:
- address_length = sizeof(sockaddr_in6);
- sin6->sin6_family = af;
- memcpy(&sin6->sin6_addr, src, sizeof(in6_addr));
- break;
- default:
- return NULL;
- }
-
- if (!WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&sa), address_length, NULL, dst, &string_length))
- return dst;
-
- return NULL;
-}
-
/** Like gettimeofday(), but it works on Windows.
* @param tv A timeval struct
* @param tz Should be NULL, it is not used
@@ -302,6 +219,16 @@ bool SupportedWindowsVersion()
return false;
}
+int setenv(const char *name, const char *value, int overwrite)
+{
+ return SetEnvironmentVariable(name, value);
+}
+
+int unsetenv(const char *name)
+{
+ return SetEnvironmentVariable(name, NULL);
+}
+
int mkstemp(char *input)
{
input = _mktemp(input);
@@ -315,4 +242,9 @@ int mkstemp(char *input)
return fd;
}
+void getcwd(char *buf, size_t sz)
+{
+ GetCurrentDirectory(sz, buf);
+}
+
#endif