X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=win%2Finspircd_win32wrapper.cpp;h=223fb648ebba170bf7c91a2891c7d32f15ed095e;hb=6d03943426dcce76ba66567a9b18425a5ebb4c0c;hp=03d89a7aa5a8f0b932d7cf77e61dadf009f027a7;hpb=1b290edc9cfba6ed94e04257035c37c4df5e5c2d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 03d89a7aa..223fb648e 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -46,7 +46,7 @@ int inet_aton(const char *cp, struct in_addr *addr) return (addr->s_addr == INADDR_NONE) ? 0 : 1; } -const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +const char *insp_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { if (af == AF_INET) @@ -75,7 +75,7 @@ int geteuid() return 1; } -int inet_pton(int af, const char *src, void *dst) +int insp_inet_pton(int af, const char *src, void *dst) { sockaddr_in sa; int len = sizeof(SOCKADDR); @@ -236,16 +236,17 @@ int printf_c(const char * format, ...) return c; } -int arg_counter = 1; +int optind = 1; char optarg[514]; int getopt_long_only(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. - if (___argc == 1 || arg_counter == ___argc) // No arguments (apart from filename) + if (___argc == 1 || optind == ___argc) // No arguments (apart from filename) return -1; - const char * opt = ___argv[arg_counter]; + const char * opt = ___argv[optind]; + optind++; // if we're not an option, return an error. if (strnicmp(opt, "--", 2) != 0) @@ -262,18 +263,18 @@ int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, { // woot, found a valid argument =) char * par = 0; - if ((arg_counter + 1) != ___argc) + if ((optind) != ___argc) { // grab the parameter from the next argument (if its not another argument) - if (strnicmp(___argv[arg_counter+1], "--", 2) != 0) + if (strnicmp(___argv[optind], "--", 2) != 0) { - arg_counter++; // Trash this next argument, we won't be needing it. - par = ___argv[arg_counter]; +// optind++; // Trash this next argument, we won't be needing it. + par = ___argv[optind-1]; } } // increment the argument for next time - arg_counter++; +// optind++; // determine action based on type if (__longopts[i].has_arg == required_argument && !par) @@ -307,39 +308,6 @@ int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, return 1; } -/*void IPC::Check() -{ - if (hIPCPipe == INVALID_HANDLE_VALUE) - return; - - DWORD bytes; - DWORD action; - - BOOL res = ReadFile(hIPCPipe, &action, sizeof(DWORD), &bytes, 0); - if (!res) - { - if (GetLastError() != ERROR_SEM_TIMEOUT) - Instance->Logs->Log("win32",DEFAULT, "IPC Pipe Error %u: %s", GetLastError(), dlerror()); - return; - } - - switch (action) - { - case IPC_MESSAGE_REHASH: - Instance->Rehash("due to IPC message"); - break; - - case IPC_MESSAGE_DIE: - Instance->Exit(0); - break; - - case IPC_MESSAGE_RESTART: - Instance->Restart("IPC_MESSAGE_RESTART received by mailslot."); - break; - } -}*/ - - /* These three functions were created from looking at how ares does it * (...and they look far tidier in C++) */ @@ -445,13 +413,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"); - Instance->Config->DNSServerValidator = &ValidateWindowsDnsServer; } -DWORD WindowsForkStart(InspIRCd* Instance) +DWORD WindowsForkStart() { /* Windows implementation of fork() :P */ if (owner_processid) @@ -531,7 +498,7 @@ DWORD WindowsForkStart(InspIRCd* Instance) return ExitCode; } -void WindowsForkKillOwner(InspIRCd * Instance) +void WindowsForkKillOwner() { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, owner_processid); if(!hProcess || !owner_processid) @@ -550,7 +517,7 @@ void WindowsForkKillOwner(InspIRCd * Instance) CloseHandle(hProcess); } -bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data) +bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data) { if (!*(data.GetString())) { @@ -656,67 +623,64 @@ void donewmi() int getcpu() { HRESULT hres; + int cpu = -1; /* Use WQL, similar to SQL, to construct a query that lists the cpu usage and pid of all processes */ IEnumWbemClassObject* pEnumerator = NULL; - hres = pSvc->ExecQuery(bstr_t("WQL"), - bstr_t("Select PercentProcessorTime,IDProcess from Win32_PerfFormattedData_PerfProc_Process"), - WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); - - /* Query didn't work */ - if (FAILED(hres)) - return -1; - IWbemClassObject *pclsObj = NULL; - ULONG uReturn = 0; - - /* Iterate the query results */ - while (pEnumerator) - { - VARIANT vtProp; - /* Next item */ - HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + BSTR Language = SysAllocString(L"WQL"); + BSTR Query = SysAllocString(L"Select PercentProcessorTime,IDProcess from Win32_PerfFormattedData_PerfProc_Process"); - /* No more items left */ - if (uReturn == 0) - break; + hres = pSvc->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + + /* Query didn't work */ + if (!FAILED(hres)) + { + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; - /* Find process ID */ - hr = pclsObj->Get(L"IDProcess", 0, &vtProp, 0, 0); - if (!FAILED(hr)) + /* Iterate the query results */ + while (pEnumerator) { - /* Matches our process ID? */ - if (vtProp.uintVal == GetCurrentProcessId()) + VARIANT vtProp; + /* Next item */ + HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + /* No more items left */ + if (uReturn == 0) + break; + + /* Find process ID */ + hr = pclsObj->Get(L"IDProcess", 0, &vtProp, 0, 0); + if (!FAILED(hr)) { - VariantClear(&vtProp); - /* Get CPU percentage for this process */ - hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0); - if (!FAILED(hr)) + /* Matches our process ID? */ + if (vtProp.uintVal == GetCurrentProcessId()) { - /* Deal with wide string ickyness. Who in their right - * mind puts a number in a bstrVal wide string item?! - */ VariantClear(&vtProp); - int cpu = 0; - std::wstringstream out(vtProp.bstrVal); - out >> cpu; - pEnumerator->Release(); - pclsObj->Release(); - return cpu; + /* Get CPU percentage for this process */ + hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0); + if (!FAILED(hr)) + { + /* 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; + } } } } - } - pEnumerator->Release(); - pclsObj->Release(); - return -1; -} -void usleep(unsigned long usecs) -{ - if (usecs > 0UL) - { - unsigned long millis = ((usecs + 999UL) / 1000UL); - SleepEx(millis, false); + pEnumerator->Release(); + pclsObj->Release(); } + + SysFreeString(Language); + SysFreeString(Query); + + return cpu; }