summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_stats.cpp34
-rw-r--r--src/configreader.cpp40
-rw-r--r--src/dns.cpp2
-rw-r--r--src/dynamic.cpp24
-rw-r--r--src/hashcomp.cpp17
-rw-r--r--src/helperfuncs.cpp17
-rw-r--r--src/inspircd.cpp107
-rw-r--r--src/modmanager_dynamic.cpp2
-rw-r--r--src/modules.cpp4
-rw-r--r--src/modules/extra/m_geoip.cpp2
-rw-r--r--src/modules/extra/m_ldapauth.cpp2
-rw-r--r--src/modules/extra/m_ldapoper.cpp2
-rw-r--r--src/modules/extra/m_mysql.cpp2
-rw-r--r--src/modules/extra/m_regex_pcre.cpp2
-rw-r--r--src/modules/extra/m_sqlite3.cpp2
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp2
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp2
-rw-r--r--src/modules/m_spanningtree/main.cpp2
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp4
-rw-r--r--src/modules/m_spanningtree/utils.cpp2
-rw-r--r--src/modules/m_spanningtree/utils.h10
-rw-r--r--src/modules/m_watch.cpp7
-rw-r--r--src/modules/ssl.h2
-rw-r--r--src/server.cpp8
-rw-r--r--src/socketengine.cpp12
-rw-r--r--src/socketengines/socketengine_poll.cpp2
-rw-r--r--src/socketengines/socketengine_select.cpp4
-rw-r--r--src/threadengines/threadengine_win32.cpp11
28 files changed, 212 insertions, 115 deletions
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp
index 3b0507175..1d3130bd4 100644
--- a/src/commands/cmd_stats.cpp
+++ b/src/commands/cmd_stats.cpp
@@ -23,8 +23,9 @@
#include "xline.h"
#include "commands/cmd_whowas.h"
-#ifdef WINDOWS
-# pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
+#ifdef _WIN32
+#include <psapi.h>
+#pragma comment(lib, "psapi.lib") // For GetProcessMemoryInfo()
#endif
/** Handle /STATS. These command handlers can be reloaded by the core,
@@ -240,7 +241,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
results.push_back(sn+" 249 "+user->nick+" :Bandwidth out: "+ConvToStr(kbitpersec_out_s)+" kilobits/sec");
results.push_back(sn+" 249 "+user->nick+" :Bandwidth in: "+ConvToStr(kbitpersec_in_s)+" kilobits/sec");
-#ifndef WIN32
+#ifndef _WIN32
/* Moved this down here so all the not-windows stuff (look w00tie, I didn't say win32!) is in one ifndef.
* Also cuts out some identical code in both branches of the ifndef. -- Om
*/
@@ -278,7 +279,32 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
results.push_back(sn+" 249 "+user->nick+" :Total allocation: "+ConvToStr((MemCounters.WorkingSetSize + MemCounters.PagefileUsage) / 1024)+"K");
results.push_back(sn+" 249 "+user->nick+" :Pagefile usage: "+ConvToStr(MemCounters.PagefileUsage / 1024)+"K");
results.push_back(sn+" 249 "+user->nick+" :Page faults: "+ConvToStr(MemCounters.PageFaultCount));
- results.push_back(sn+" 249 "+user->nick+" :CPU Usage: " + ConvToStr(getcpu()) + "%");
+ }
+
+ FILETIME CreationTime;
+ FILETIME ExitTime;
+ FILETIME KernelTime;
+ FILETIME UserTime;
+ LARGE_INTEGER ThisSample;
+ if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) &&
+ QueryPerformanceCounter(&ThisSample))
+ {
+ KernelTime.dwHighDateTime += UserTime.dwHighDateTime;
+ KernelTime.dwLowDateTime += UserTime.dwLowDateTime;
+ double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
+ double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
+ double per = (n_eaten/n_elapsed);
+
+ char percent[30];
+
+ snprintf(percent, 30, "%03.5f%%", per);
+ results.push_back(sn+" 249 "+user->nick+" :CPU Use (now): "+percent);
+
+ n_elapsed = ServerInstance->Time() - ServerInstance->startup_time;
+ n_eaten = (double)(( (uint64_t)(KernelTime.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime))/100000;
+ per = (n_eaten / n_elapsed);
+ snprintf(percent, 30, "%03.5f%%", per);
+ results.push_back(sn+" 249 "+user->nick+" :CPU Use (total): "+percent);
}
#endif
}
diff --git a/src/configreader.cpp b/src/configreader.cpp
index c62f2446c..660df77d7 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -28,6 +28,10 @@
#include "exitcodes.h"
#include "commands/cmd_whowas.h"
#include "configparser.h"
+#ifdef _WIN32
+#include <Iphlpapi.h>
+#pragma comment(lib, "Iphlpapi.lib")
+#endif
ServerConfig::ServerConfig()
{
@@ -140,15 +144,41 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data)
return true;
}
-#ifdef WINDOWS
-// Note: the windows validator is in win32wrapper.cpp
-void FindDNS(std::string& server);
-#else
static void FindDNS(std::string& server)
{
if (!server.empty())
return;
+#ifdef _WIN32
+ // attempt to look up their nameserver from the system
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find a working server in the system settings...");
+
+ PFIXED_INFO pFixedInfo;
+ DWORD dwBufferSize = sizeof(FIXED_INFO);
+ pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, sizeof(FIXED_INFO));
+
+ if(pFixedInfo)
+ {
+ if (GetNetworkParams(pFixedInfo, &dwBufferSize) == ERROR_BUFFER_OVERFLOW) {
+ HeapFree(GetProcessHeap(), 0, pFixedInfo);
+ pFixedInfo = (PFIXED_INFO) HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
+ }
+
+ if(pFixedInfo) {
+ if (GetNetworkParams(pFixedInfo, &dwBufferSize) == NO_ERROR)
+ server = pFixedInfo->DnsServerList.IpAddress.String;
+
+ HeapFree(GetProcessHeap(), 0, pFixedInfo);
+ }
+
+ if(!server.empty())
+ {
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first active resolver in the system settings.", server.c_str());
+ return;
+ }
+ }
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found! Defaulting to nameserver '127.0.0.1'!");
+#else
// attempt to look up their nameserver from /etc/resolv.conf
ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
@@ -168,9 +198,9 @@ static void FindDNS(std::string& server)
}
ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
+#endif
server = "127.0.0.1";
}
-#endif
static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
{
diff --git a/src/dns.cpp b/src/dns.cpp
index 1c23710a4..ced8b637f 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -34,7 +34,7 @@ Please do not assume that firedns works like this,
looks like this, walks like this or tastes like this.
*/
-#ifndef WIN32
+#ifndef _WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
diff --git a/src/dynamic.cpp b/src/dynamic.cpp
index 27662a351..1470dff0c 100644
--- a/src/dynamic.cpp
+++ b/src/dynamic.cpp
@@ -23,8 +23,12 @@
#include "inspircd.h"
#include "dynamic.h"
-#ifndef WIN32
+#ifndef _WIN32
#include <dlfcn.h>
+#else
+#define dlopen(path, state) (void*)LoadLibraryA(path)
+#define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
+#define dlclose(handle) FreeLibrary((HMODULE)handle)
#endif
DLLManager::DLLManager(const char *fname)
@@ -39,7 +43,11 @@ DLLManager::DLLManager(const char *fname)
h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
if (!h)
{
+#ifdef _WIN32
+ RetrieveLastError();
+#else
err = dlerror();
+#endif
}
}
@@ -64,7 +72,11 @@ Module* DLLManager::CallInit()
initfn.vptr = dlsym(h, MODULE_INIT_STR);
if (!initfn.vptr)
{
+#ifdef _WIN32
+ RetrieveLastError();
+#else
err = dlerror();
+#endif
return NULL;
}
@@ -81,3 +93,13 @@ std::string DLLManager::GetVersion()
return srcver;
return "Unversioned module";
}
+
+#ifdef _WIN32
+void DLLManager::RetrieveLastError()
+{
+ CHAR errmsg[100];
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errmsg, 100, 0);
+ SetLastError(ERROR_SUCCESS);
+ err = errmsg;
+}
+#endif
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 2cb6fb972..8a7f8987b 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -127,15 +127,12 @@ void nspace::strlower(char *n)
}
}
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
- size_t nspace::hash_compare<std::string, std::less<std::string> >::operator()(const std::string &s) const
+#ifdef HASHMAP_DEPRECATED
+ size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
#else
- #ifdef HASHMAP_DEPRECATED
- size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
- #else
- size_t nspace::hash<std::string>::operator()(const std::string &s) const
- #endif
+ size_t nspace::hash<std::string>::operator()(const std::string &s) const
#endif
+
{
/* XXX: NO DATA COPIES! :)
* The hash function here is practically
@@ -150,11 +147,7 @@ void nspace::strlower(char *n)
}
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
- size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(const irc::string &s) const
-#else
- size_t CoreExport irc::hash::operator()(const irc::string &s) const
-#endif
+size_t CoreExport irc::hash::operator()(const irc::string &s) const
{
register size_t t = 0;
for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 4605092a1..7351a07de 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -24,6 +24,11 @@
/* $Core */
+#ifdef _WIN32
+#define _CRT_RAND_S
+#include <stdlib.h>
+#endif
+
#include "inspircd.h"
#include "xline.h"
#include "exitcodes.h"
@@ -311,12 +316,14 @@ bool InspIRCd::OpenLog(char**, int)
void InspIRCd::CheckRoot()
{
+#ifndef _WIN32
if (geteuid() == 0)
{
printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
this->Logs->Log("STARTUP",DEFAULT,"Cant start as root");
Exit(EXIT_STATUS_ROOT);
}
+#endif
}
void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::string &text)
@@ -451,7 +458,17 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
void GenRandomHandler::Call(char *output, size_t max)
{
for(unsigned int i=0; i < max; i++)
+#ifdef _WIN32
+ {
+ unsigned int uTemp;
+ if(rand_s(&uTemp) != 0)
+ output[i] = rand();
+ else
+ output[i] = uTemp;
+ }
+#else
output[i] = random();
+#endif
}
ModResult OnCheckExemptionHandler::Call(User* user, Channel* chan, const std::string& restriction)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index d154c3600..42047ce11 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -31,7 +31,7 @@
#include "inspircd_version.h"
#include <signal.h>
-#ifndef WIN32
+#ifndef _WIN32
#include <dirent.h>
#include <unistd.h>
#include <sys/resource.h>
@@ -163,9 +163,9 @@ void InspIRCd::Restart(const std::string &reason)
char** argv = Config->cmdline.argv;
-#ifdef WINDOWS
+#ifdef _WIN32
char module[MAX_PATH];
- if (GetModuleFileName(NULL, module, MAX_PATH))
+ if (GetModuleFileNameA(NULL, module, MAX_PATH))
me = module;
#else
me = argv[0];
@@ -223,7 +223,7 @@ void InspIRCd::RehashUsersAndChans()
void InspIRCd::SetSignals()
{
-#ifndef WIN32
+#ifndef _WIN32
signal(SIGALRM, SIG_IGN);
signal(SIGHUP, InspIRCd::SetSignal);
signal(SIGPIPE, SIG_IGN);
@@ -241,7 +241,7 @@ void InspIRCd::QuickExit(int status)
bool InspIRCd::DaemonSeed()
{
-#ifdef WINDOWS
+#ifdef _WIN32
printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
return true;
#else
@@ -285,6 +285,7 @@ bool InspIRCd::DaemonSeed()
void InspIRCd::WritePID(const std::string &filename)
{
+#ifndef _WIN32
std::string fname(filename);
if (fname.empty())
fname = DATA_PATH "/inspircd.pid";
@@ -300,6 +301,7 @@ void InspIRCd::WritePID(const std::string &filename)
this->Logs->Log("STARTUP",DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
Exit(EXIT_STATUS_PID);
}
+#endif
}
InspIRCd::InspIRCd(int argc, char** argv) :
@@ -321,14 +323,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
FloodQuitUser(&HandleFloodQuitUser),
OnCheckExemption(&HandleOnCheckExemption)
{
-#ifdef WIN32
- // Strict, frequent checking of memory on debug builds
- _CrtSetDbgFlag ( _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
-
- // Avoid erroneous frees on early exit
- WindowsIPC = 0;
-#endif
-
ServerInstance = this;
Extensions.Register(&NICKForced);
@@ -393,7 +387,11 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->Config->cmdline.argv = argv;
this->Config->cmdline.argc = argc;
+#ifdef _WIN32
+ srand(TIME.tv_nsec ^ TIME.tv_sec);
+#else
srandom(TIME.tv_nsec ^ TIME.tv_sec);
+#endif
struct option longopts[] =
{
@@ -444,27 +442,17 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Exit(EXIT_STATUS_NOERROR);
}
-#ifdef WIN32
-
- // Handle forking
- if(!do_nofork)
- {
- DWORD ExitCode = WindowsForkStart();
- if(ExitCode)
- exit(ExitCode);
- }
-
+#ifdef _WIN32
// Set up winsock
WSADATA wsadata;
- WSAStartup(MAKEWORD(2,0), &wsadata);
- ChangeWindowsSpecificPointers();
+ WSAStartup(MAKEWORD(2,2), &wsadata);
#endif
/* Set the finished argument values */
- Config->cmdline.nofork = do_nofork;
- Config->cmdline.forcedebug = do_debug;
- Config->cmdline.writelog = !do_nolog;
- Config->cmdline.TestSuite = do_testsuite;
+ Config->cmdline.nofork = (do_nofork != 0);
+ Config->cmdline.forcedebug = (do_debug != 0);
+ Config->cmdline.writelog = (!do_nolog != 0);
+ Config->cmdline.TestSuite = (do_testsuite != 0);
if (do_debug)
{
@@ -480,7 +468,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
if (!ServerConfig::FileExists(ConfigFileName.c_str()))
{
-#ifdef WIN32
+#ifdef _WIN32
/* Windows can (and defaults to) hide file extensions, so let's play a bit nice for windows users. */
std::string txtconf = this->ConfigFileName;
txtconf.append(".txt");
@@ -507,6 +495,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->Modes = new ModeParser;
+#ifndef _WIN32
if (!do_root)
this->CheckRoot();
else
@@ -521,6 +510,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
sleep(20);
}
+#endif
this->SetSignals();
@@ -598,7 +588,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n",
Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
-#ifndef WINDOWS
+#ifndef _WIN32
if (!Config->cmdline.nofork)
{
if (kill(getppid(), SIGTERM) == -1)
@@ -640,19 +630,21 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Logs->Log("STARTUP", DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
}
#else
- WindowsIPC = new IPC;
- if(!Config->cmdline.nofork)
+ /* Set win32 service as running, if we are running as a service */
+ SetServiceRunning();
+
+ // Handle forking
+ if(!do_nofork)
{
- WindowsForkKillOwner();
FreeConsole();
}
- /* Set win32 service as running, if we are running as a service */
- SetServiceRunning();
+
+ QueryPerformanceFrequency(&stats->QPFrequency);
#endif
Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName.c_str(),Config->GetSID().c_str(), SE->GetMaxFds());
-#ifndef WIN32
+#ifndef _WIN32
std::string SetUser = Config->ConfValue("security")->getString("runasuser");
std::string SetGroup = Config->ConfValue("security")->getString("runasgroup");
if (!SetGroup.empty())
@@ -711,20 +703,28 @@ InspIRCd::InspIRCd(int argc, char** argv) :
this->QuickExit(0);
}
}
-#endif
this->WritePID(Config->PID);
+#endif
}
void InspIRCd::UpdateTime()
{
-#ifdef HAS_CLOCK_GETTIME
- clock_gettime(CLOCK_REALTIME, &TIME);
+#ifdef _WIN32
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+
+ TIME.tv_sec = time(NULL);
+ TIME.tv_nsec = st.wMilliseconds;
#else
- struct timeval tv;
- gettimeofday(&tv, NULL);
- TIME.tv_sec = tv.tv_sec;
- TIME.tv_nsec = tv.tv_usec * 1000;
+ #ifdef HAS_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &TIME);
+ #else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ TIME.tv_sec = tv.tv_sec;
+ TIME.tv_nsec = tv.tv_usec * 1000;
+ #endif
#endif
}
@@ -743,12 +743,8 @@ int InspIRCd::Run()
while (true)
{
-#ifndef WIN32
+#ifndef _WIN32
static rusage ru;
-#else
- static time_t uptime;
- static struct tm * stime;
- static char window_title[100];
#endif
/* Check if there is a config thread which has finished executing but has not yet been freed */
@@ -774,12 +770,21 @@ int InspIRCd::Run()
if (TIME.tv_sec != OLDTIME)
{
OLDTIME = TIME.tv_sec;
-#ifndef WIN32
+#ifndef _WIN32
getrusage(RUSAGE_SELF, &ru);
stats->LastSampled = TIME;
stats->LastCPU = ru.ru_utime;
#else
- WindowsIPC->Check();
+ if(QueryPerformanceCounter(&stats->LastSampled))
+ {
+ FILETIME CreationTime;
+ FILETIME ExitTime;
+ FILETIME KernelTime;
+ FILETIME UserTime;
+ GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
+ stats->LastCPU.dwHighDateTime = KernelTime.dwHighDateTime + UserTime.dwHighDateTime;
+ stats->LastCPU.dwLowDateTime = KernelTime.dwLowDateTime + UserTime.dwLowDateTime;
+ }
#endif
/* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */
diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp
index e0d744b3a..0e90a9ae5 100644
--- a/src/modmanager_dynamic.cpp
+++ b/src/modmanager_dynamic.cpp
@@ -25,7 +25,7 @@
#include "dns.h"
#include "exitcodes.h"
-#ifndef WIN32
+#ifndef _WIN32
#include <dirent.h>
#endif
diff --git a/src/modules.cpp b/src/modules.cpp
index 075bbf85b..1f135176c 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -32,7 +32,7 @@
#include "dns.h"
#include "exitcodes.h"
-#ifndef WIN32
+#ifndef _WIN32
#include <dirent.h>
#endif
@@ -558,7 +558,7 @@ dynamic_reference_base::operator bool()
if (i != ServerInstance->Modules->DataProviders.end())
value = static_cast<DataProvider*>(i->second);
}
- return value;
+ return (value != NULL);
}
void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
diff --git a/src/modules/extra/m_geoip.cpp b/src/modules/extra/m_geoip.cpp
index cf87de51e..ffb4c1922 100644
--- a/src/modules/extra/m_geoip.cpp
+++ b/src/modules/extra/m_geoip.cpp
@@ -23,7 +23,7 @@
#include <GeoIP.h>
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "GeoIP.lib")
#endif
diff --git a/src/modules/extra/m_ldapauth.cpp b/src/modules/extra/m_ldapauth.cpp
index 5d71e7389..c4e937b9f 100644
--- a/src/modules/extra/m_ldapauth.cpp
+++ b/src/modules/extra/m_ldapauth.cpp
@@ -30,7 +30,7 @@
#include <ldap.h>
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "ldap.lib")
# pragma comment(lib, "lber.lib")
#endif
diff --git a/src/modules/extra/m_ldapoper.cpp b/src/modules/extra/m_ldapoper.cpp
index 6eade1fbd..2166b0823 100644
--- a/src/modules/extra/m_ldapoper.cpp
+++ b/src/modules/extra/m_ldapoper.cpp
@@ -27,7 +27,7 @@
#include <ldap.h>
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "ldap.lib")
# pragma comment(lib, "lber.lib")
#endif
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 4173d654a..08ec93cf2 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -27,7 +27,7 @@
#include <mysql.h>
#include "sql.h"
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "mysqlclient.lib")
# pragma comment(lib, "advapi32.lib")
# pragma comment(linker, "/NODEFAULTLIB:LIBCMT")
diff --git a/src/modules/extra/m_regex_pcre.cpp b/src/modules/extra/m_regex_pcre.cpp
index ebd2213b2..cba234c8c 100644
--- a/src/modules/extra/m_regex_pcre.cpp
+++ b/src/modules/extra/m_regex_pcre.cpp
@@ -27,7 +27,7 @@
/* $CompileFlags: exec("pcre-config --cflags") */
/* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "libpcre.lib")
#endif
diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp
index 8a4a66657..c10f62bd2 100644
--- a/src/modules/extra/m_sqlite3.cpp
+++ b/src/modules/extra/m_sqlite3.cpp
@@ -24,7 +24,7 @@
#include <sqlite3.h>
#include "sql.h"
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "sqlite3.lib")
#endif
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 6616295b9..dabdfbfb3 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -28,7 +28,7 @@
#include "ssl.h"
#include "m_cap.h"
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "libgnutls.lib")
# pragma comment(lib, "libgcrypt.lib")
# pragma comment(lib, "libgpg-error.lib")
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 36fe2941e..413f891c9 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -27,7 +27,7 @@
#include <openssl/err.h>
#include "ssl.h"
-#ifdef WINDOWS
+#ifdef _WIN32
# pragma comment(lib, "libcrypto.lib")
# pragma comment(lib, "libssl.lib")
# pragma comment(lib, "user32.lib")
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 761343bb1..b8540cf27 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -306,7 +306,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
{
try
{
- bool cached;
+ bool cached = false;
ServernameResolver* snr = new ServernameResolver(Utils, x->IPAddr, x, cached, start_type, y);
ServerInstance->AddResolver(snr, cached);
}
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index b69c5c29e..d7c4c5227 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -71,7 +71,7 @@ void ServernameResolver::OnError(ResolverError e, const std::string &errormessag
/* Ooops! */
if (query == DNS_QUERY_AAAA)
{
- bool cached;
+ bool cached = false;
ServernameResolver* snr = new ServernameResolver(Utils, host, MyLink, cached, DNS_QUERY_A, myautoconnect);
ServerInstance->AddResolver(snr, cached);
return;
@@ -102,7 +102,7 @@ void SecurityIPResolver::OnError(ResolverError e, const std::string &errormessag
{
if (query == DNS_QUERY_AAAA)
{
- bool cached;
+ bool cached = false;
SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, host, MyLink, cached, DNS_QUERY_A);
ServerInstance->AddResolver(res, cached);
return;
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 8b078220c..471026887 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -314,7 +314,7 @@ void SpanningTreeUtilities::RefreshIPCache()
{
try
{
- bool cached;
+ bool cached = false;
SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, DNS_QUERY_AAAA);
ServerInstance->AddResolver(sr, cached);
}
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index ace33ad3b..7d5ffa216 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -36,14 +36,10 @@ class SpanningTreeUtilities;
/* This hash_map holds the hash equivalent of the server
* tree, used for rapid linear lookups.
*/
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
- typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
+#ifdef HASHMAP_DEPRECATED
+ typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
#else
- #ifdef HASHCOMP_DEPRECATED
- typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
- #else
- typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
- #endif
+ typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
#endif
typedef std::map<TreeServer*,TreeServer*> TreeServerList;
diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp
index 7e98f2fbd..6aa12b4e7 100644
--- a/src/modules/m_watch.cpp
+++ b/src/modules/m_watch.cpp
@@ -96,11 +96,8 @@
* Before you start screaming, this definition is only used here, so moving it to a header is pointless.
* Yes, it's horrid. Blame cl for being different. -- w00t
*/
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
- typedef nspace::hash_map<irc::string, std::deque<User*>, nspace::hash_compare<irc::string, std::less<irc::string> > > watchentries;
-#else
- typedef nspace::hash_map<irc::string, std::deque<User*>, irc::hash> watchentries;
-#endif
+
+typedef nspace::hash_map<irc::string, std::deque<User*>, irc::hash> watchentries;
typedef std::map<irc::string, std::string> watchlist;
/* Who's watching each nickname.
diff --git a/src/modules/ssl.h b/src/modules/ssl.h
index 8792d6ebc..9deafb830 100644
--- a/src/modules/ssl.h
+++ b/src/modules/ssl.h
@@ -121,7 +121,7 @@ class ssl_cert : public refcountbase
std::string GetMetaLine()
{
std::stringstream value;
- bool hasError = error.length();
+ bool hasError = !error.empty();
value << (IsInvalid() ? "v" : "V") << (IsTrusted() ? "T" : "t") << (IsRevoked() ? "R" : "r")
<< (IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
if (hasError)
diff --git a/src/server.cpp b/src/server.cpp
index 30d204aa4..4741f942d 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -27,11 +27,15 @@
void InspIRCd::SignalHandler(int signal)
{
+#ifdef _WIN32
+ if (signal == SIGTERM)
+#else
if (signal == SIGHUP)
{
Rehash("Caught SIGHUP");
}
else if (signal == SIGTERM)
+#endif
{
Exit(signal);
}
@@ -39,9 +43,7 @@ void InspIRCd::SignalHandler(int signal)
void InspIRCd::Exit(int status)
{
-#ifdef WINDOWS
- if (WindowsIPC)
- delete WindowsIPC;
+#ifdef _WIN32
SetServiceStopped(status);
#endif
if (this)
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index ccaa71aed..27abd0ad6 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -98,7 +98,7 @@ bool SocketEngine::HasFd(int fd)
{
if ((fd < 0) || (fd > GetMaxFds()))
return false;
- return ref[fd];
+ return (ref[fd] != NULL);
}
EventHandler* SocketEngine::GetRef(int fd)
@@ -125,7 +125,7 @@ int SocketEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
int SocketEngine::Close(EventHandler* fd)
{
-#ifdef WINDOWS
+#ifdef _WIN32
return closesocket(fd->GetFd());
#else
return close(fd->GetFd());
@@ -134,7 +134,7 @@ int SocketEngine::Close(EventHandler* fd)
int SocketEngine::Close(int fd)
{
-#ifdef WINDOWS
+#ifdef _WIN32
return closesocket(fd);
#else
return close(fd);
@@ -143,7 +143,7 @@ int SocketEngine::Close(int fd)
int SocketEngine::Blocking(int fd)
{
-#ifdef WINDOWS
+#ifdef _WIN32
unsigned long opt = 0;
return ioctlsocket(fd, FIONBIO, &opt);
#else
@@ -154,7 +154,7 @@ int SocketEngine::Blocking(int fd)
int SocketEngine::NonBlocking(int fd)
{
-#ifdef WINDOWS
+#ifdef _WIN32
unsigned long opt = 1;
return ioctlsocket(fd, FIONBIO, &opt);
#else
@@ -209,7 +209,7 @@ int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flag
int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen)
{
int ret = connect(fd->GetFd(), serv_addr, addrlen);
-#ifdef WINDOWS
+#ifdef _WIN32
if ((ret == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK))
errno = EINPROGRESS;
#endif
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index 7a026891b..dd38c32b9 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -33,7 +33,7 @@
#include "inspircd.h"
#include "socketengine.h"
-#ifndef WINDOWS
+#ifndef _WIN32
#ifndef __USE_XOPEN
#define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/
#endif
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp
index 441fe494a..9d4461193 100644
--- a/src/socketengines/socketengine_select.cpp
+++ b/src/socketengines/socketengine_select.cpp
@@ -23,9 +23,9 @@
#include "inspircd.h"
#include "socketengine.h"
-#ifndef WINDOWS
+#ifndef _WIN32
#include <sys/select.h>
-#endif // WINDOWS
+#endif // _WIN32
/** A specialisation of the SocketEngine class, designed to use traditional select().
*/
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
index 3e643c6f5..637a3e010 100644
--- a/src/threadengines/threadengine_win32.cpp
+++ b/src/threadengines/threadengine_win32.cpp
@@ -37,7 +37,16 @@ void ThreadEngine::Start(Thread* thread)
{
thread->state = NULL;
delete data;
- throw CoreException(std::string("Unable to create new thread: ") + dlerror());
+ std::string err = "Unable to create new thread: ";
+#ifdef _WIN32
+ CHAR errdetail[100];
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errdetail, 100, 0);
+ SetLastError(ERROR_SUCCESS);
+ err += errdetail;
+#else
+ err += dlerror();
+#endif
+ throw CoreException(err);
}
}