X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=inline;f=win%2Finspircd_win32wrapper.cpp;h=43ca87240bff0f477cc4863fb1e73e4f12779a7b;hb=46a39046196f55b52336e19662bb7bac85b731ac;hp=1008cb83874b2ead07b7b66beb13b2c9fabce635;hpb=0036e3a70cabea02e9ec2103ed1dfdf5c799289f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 1008cb838..43ca87240 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -1,16 +1,28 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2011 Adam + * Copyright (C) 2007, 2009 Dennis Friis + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007-2009 Craig Edwards + * Copyright (C) 2008 John Brooks + * Copyright (C) 2007 Burlex + * Copyright (C) 2007 Robin Burchell * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd_win32wrapper.h" #include "inspircd.h" #include "configreader.h" @@ -238,7 +250,7 @@ int printf_c(const char * format, ...) int optind = 1; char optarg[514]; -int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) +int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) { // burlex todo: handle the shortops, at the moment it only works with longopts. @@ -354,7 +366,7 @@ bool GetInterface(HKEY regkey, const char *key, char* &output) std::string FindNameServerWin() { - std::string returnval = "127.0.0.1"; + std::string returnval; HKEY top, key; char* dns = NULL; @@ -413,12 +425,12 @@ void ClearConsole() /* Many inspircd classes contain function pointers/functors which can be changed to point at platform specific implementations * of code. This function repoints these pointers and functors so that calls are windows specific. */ -void ChangeWindowsSpecificPointers(InspIRCd* Instance) +void ChangeWindowsSpecificPointers() { - Instance->Logs->Log("win32",DEBUG,"Changing to windows specific pointer and functor set"); + ServerInstance->Logs->Log("win32",DEBUG,"Changing to windows specific pointer and functor set"); } -DWORD WindowsForkStart(InspIRCd* Instance) +DWORD WindowsForkStart() { /* Windows implementation of fork() :P */ if (owner_processid) @@ -498,56 +510,65 @@ DWORD WindowsForkStart(InspIRCd* Instance) return ExitCode; } -void WindowsForkKillOwner(InspIRCd * Instance) +void WindowsForkKillOwner() { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, owner_processid); if(!hProcess || !owner_processid) { printf("Could not open process id %u: %s.\n", owner_processid, dlerror()); - Instance->Exit(14); + ServerInstance->Exit(14); } // die die die if(!TerminateProcess(hProcess, 0)) { printf("Could not TerminateProcess(): %s\n", dlerror()); - Instance->Exit(14); + ServerInstance->Exit(14); } CloseHandle(hProcess); } -bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data) +void FindDNS(std::string& server) { - if (!*(data.GetString())) + if (!server.empty()) + return; + + ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: not defined, attempting to find working server in the registry..."); + std::string nameserver = FindNameServerWin(); + + /* If empty use default to 127.0.0.1 */ + if (nameserver.empty()) { - std::string nameserver; - conf->GetInstance()->Logs->Log("win32",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(',')); - /* Just to be FUCKING AKWARD, windows fister... err i mean vista... - * seperates the nameservers with spaces instead. - */ - if (nameserver.find(' ') != std::string::npos) - nameserver = nameserver.substr(0, nameserver.find(' ')); - data.Set(nameserver.c_str()); - conf->GetInstance()->Logs->Log("win32",DEFAULT," set to '%s' as first active resolver in registry.", nameserver.c_str()); + ServerInstance->Logs->Log("CONFIG",DEFAULT,"No viable nameserver found in registry! Defaulting to nameserver '127.0.0.1'!"); + server = "127.0.0.1"; + return; } - return true; + + /* 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(',')); + + /* Just to be FUCKING AKWARD, windows fister... err i mean vista... + * seperates the nameservers with spaces instead. + */ + if (nameserver.find(' ') != std::string::npos) + nameserver = nameserver.substr(0, nameserver.find(' ')); + + server = nameserver; + ServerInstance->Logs->Log("CONFIG",DEFAULT," set to '%s' as first active resolver in registry.", nameserver.c_str()); } -int gettimeofday(struct timeval * tv, void * tz) +int clock_gettime(int clock, struct timespec * tv) { if(tv == NULL) return -1; DWORD mstime = timeGetTime(); tv->tv_sec = time(NULL); - tv->tv_usec = (mstime - (tv->tv_sec * 1000)) * 1000; + tv->tv_nsec = (mstime - (tv->tv_sec * 1000)) * 1000000; return 0; } @@ -643,6 +664,7 @@ int getcpu() while (pEnumerator) { VARIANT vtProp; + VariantInit(&vtProp); /* Next item */ HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); @@ -655,9 +677,10 @@ int getcpu() if (!FAILED(hr)) { /* Matches our process ID? */ - if (vtProp.uintVal == GetCurrentProcessId()) - { - VariantClear(&vtProp); + UINT pid = vtProp.uintVal; + VariantClear(&vtProp); + if (pid == GetCurrentProcessId()) + { /* Get CPU percentage for this process */ hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0); if (!FAILED(hr)) @@ -665,18 +688,19 @@ int getcpu() /* Deal with wide string ickyness. Who in their right * mind puts a number in a bstrVal wide string item?! */ - VariantClear(&vtProp); cpu = 0; std::wstringstream out(vtProp.bstrVal); out >> cpu; - break; + VariantClear(&vtProp); } + pclsObj->Release(); + break; } + pclsObj->Release(); } } pEnumerator->Release(); - pclsObj->Release(); } SysFreeString(Language); @@ -684,3 +708,57 @@ int getcpu() return cpu; } + +int random() +{ + return rand(); +} + +void srandom(unsigned int seed) +{ + srand(seed); +} + +int gettimeofday(timeval *tv, void *) +{ + SYSTEMTIME st; + GetSystemTime(&st); + + tv->tv_sec = time(NULL); + tv->tv_usec = st.wMilliseconds; + + return 0; +} + +/* World's largest hack to make reference<> work */ +#include "../src/modules/m_spanningtree/link.h" +#include "../src/modules/ssl.h" +static void unused_function() +{ + reference unused_Link; + reference unused_Autoconnect; + reference unused_Cert; + + if (unused_Link) + unused_Link->Port = -1; + if (unused_Autoconnect) + unused_Autoconnect->NextConnectTime = -1; + if (unused_Cert) + unused_Cert->dn = ""; + + Autoconnect *a = unused_Autoconnect; + Link *l = unused_Link; + ssl_cert *s = unused_Cert; + + unused_Link = reference(unused_Link); + unused_Autoconnect = reference(unused_Autoconnect); + unused_Cert = reference(unused_Cert); + + unused_Link = reference(l); + unused_Autoconnect = reference(a); + unused_Cert = reference(s); + + delete unused_Link; + delete unused_Autoconnect; + delete unused_Cert; +}