diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-27 17:02:24 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-27 17:02:24 +0000 |
commit | f3624af468d769f0cb05cf17cd18111f5faa9ec3 (patch) | |
tree | 2bf808da542a75b61f448937f76cbfdd76c27803 | |
parent | ac3af8b61e9601d9585510d99891e993eb3a2722 (diff) |
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
-rw-r--r-- | include/configreader.h | 3 | ||||
-rw-r--r-- | src/configreader.cpp | 18 | ||||
-rw-r--r-- | win/inspircd_win32wrapper.cpp | 34 | ||||
-rw-r--r-- | win/inspircd_win32wrapper.h | 4 |
4 files changed, 45 insertions, 14 deletions
diff --git a/include/configreader.h b/include/configreader.h index 8a719f77e..022978766 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -239,6 +239,9 @@ class CoreExport ServerConfig : public Extensible public: + /* Pointer to function that validates dns server addresses (can be changed depending on platform) */ + Validator DNSServerValidator; + InspIRCd* GetInstance(); /** This holds all the information in the config file, diff --git a/src/configreader.cpp b/src/configreader.cpp index fc6bdc200..b5680bd73 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -21,6 +21,9 @@ std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules; +/* Needs forward declaration */ +bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data); + ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance) { this->ClearStack(); @@ -43,6 +46,7 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance) OperMaxChans = 30; LogLevel = DEFAULT; maxbans.clear(); + DNSServerValidator = &ValidateDnsServer; } void ServerConfig::ClearStack() @@ -222,17 +226,6 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V if (!*(data.GetString())) { std::string nameserver; -#ifdef WINDOWS - conf->GetInstance()->Log(DEFAULT,"WARNING: <dns:server> 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,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str()); -#else // attempt to look up their nameserver from /etc/resolv.conf conf->GetInstance()->Log(DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf..."); ifstream resolv("/etc/resolv.conf"); @@ -262,7 +255,6 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V conf->GetInstance()->Log(DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!"); data.Set("127.0.0.1"); } -#endif } return true; } @@ -617,7 +609,7 @@ void ServerConfig::Read(bool bail, userrec* user) {"options", "netbuffersize","10240", new ValueContainerInt (&this->NetBufferSize), DT_INTEGER, ValidateNetBufferSize}, {"options", "maxwho", "128", new ValueContainerInt (&this->MaxWhoResults), DT_INTEGER, ValidateMaxWho}, {"options", "allowhalfop", "0", new ValueContainerBool (&this->AllowHalfop), DT_BOOLEAN, NoValidation}, - {"dns", "server", "", new ValueContainerChar (this->DNSServer), DT_CHARPTR, ValidateDnsServer}, + {"dns", "server", "", new ValueContainerChar (this->DNSServer), DT_CHARPTR, DNSServerValidator}, {"dns", "timeout", "5", new ValueContainerInt (&this->dns_timeout), DT_INTEGER, NoValidation}, {"options", "moduledir", MOD_PATH, new ValueContainerChar (this->ModPath), DT_CHARPTR, NoValidation}, {"disabled", "commands", "", new ValueContainerChar (this->DisabledCommands), DT_CHARPTR, NoValidation}, 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 <string> #include <errno.h> #include <assert.h> @@ -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: <dns:server> 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,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str()); + } + return true; +} + +#else diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index 73969e6b5..dcb0b1d39 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -174,6 +174,8 @@ void ::operator delete(void * ptr); /* IPC Handlers */ class InspIRCd; +class ConfigReader; +class ValueItem; class IPC { @@ -196,5 +198,7 @@ DWORD WindowsForkStart(InspIRCd* Instance); void WindowsForkKillOwner(InspIRCd* Instance); +bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data); + #endif |