From f3624af468d769f0cb05cf17cd18111f5faa9ec3 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 27 Jul 2007 17:02:24 +0000 Subject: Needs testbuilding in windows. I will probably do this in a minute. More clever tricks to eliminate ifdefs. With a bit of function pointer and functor magic we may be able to eliminate all ifdefs git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7590 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/inspircd_win32wrapper.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'win/inspircd_win32wrapper.cpp') diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index ee1d54c25..37d071459 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -13,6 +13,7 @@ #include "inspircd_win32wrapper.h" #include "inspircd.h" +#include "configreader.h" #include #include #include @@ -514,8 +515,20 @@ void ClearConsole() return; } -DWORD WindowsForkStart(InspIRCd * Instance) +/* Many inspircd classes contain function pointers/functors which can be changed to point at platform specific implementations + * of code. This function, called from WindowsForkStart, repoints these pointers and functors so that calls are windows + * specific. + */ +void ChangeWindowsSpecificPointers(InspIRCd* Instance) +{ + Instance->Config->DNSServerValidator = &ValidateWindowsDnsServer; +} + +DWORD WindowsForkStart(InspIRCd* Instance) { + /* See the function declaration above */ + ChangeWindowsSpecificPointers(Instance); + /* Windows implementation of fork() :P */ if (owner_processid) return 0; @@ -613,4 +626,23 @@ void WindowsForkKillOwner(InspIRCd * Instance) CloseHandle(hProcess); } +bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data) +{ + if (!*(data.GetString())) + { + std::string nameserver; + conf->GetInstance()->Log(DEFAULT,"WARNING: not defined, attempting to find working server in the registry..."); + nameserver = FindNameServerWin(); + /* Windows stacks multiple nameservers in one registry key, seperated by commas. + * Spotted by Cataclysm. + */ + if (nameserver.find(',') != std::string::npos) + nameserver = nameserver.substr(0, nameserver.find(',')); + data.Set(nameserver.c_str()); + conf->GetInstance()->Log(DEFAULT," set to '%s' as first active resolver in registry.", nameserver.c_str()); + } + return true; +} + +#else -- cgit v1.2.3