]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - win/inspircd_win32wrapper.cpp
Move static map of extensions into ServerInstance, add const-correctness
[user/henk/code/inspircd.git] / win / inspircd_win32wrapper.cpp
index cece563441a455134ad5eee3ba55ed992adc7781..1309e60643ba1d693511248f513e6a07e621a191 100644 (file)
@@ -46,8 +46,7 @@ int inet_aton(const char *cp, struct in_addr *addr)
        return (addr->s_addr == INADDR_NONE) ? 0 : 1;
 }
 
-#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
-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)
@@ -70,15 +69,13 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
        }
        return NULL;
 }
-#endif
 
 int geteuid()
 {
        return 1;
 }
 
-#if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_LONGHORN)
-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);
@@ -93,7 +90,6 @@ int inet_pton(int af, const char *src, void *dst)
        memcpy(dst, &sa.sin_addr, sizeof(struct in_addr));
        return rv;
 }
-#endif
 
 void setcolor(int color_code)
 {
@@ -240,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)
@@ -266,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)
@@ -416,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;
+       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)
@@ -502,31 +498,31 @@ 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 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()))
        {
                std::string nameserver;
-               conf->GetInstance()->Logs->Log("win32",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in the registry...");
+               ServerInstance->Logs->Log("win32",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.
@@ -539,7 +535,7 @@ bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* v
                if (nameserver.find(' ') != std::string::npos)
                        nameserver = nameserver.substr(0, nameserver.find(' '));
                data.Set(nameserver.c_str());
-               conf->GetInstance()->Logs->Log("win32",DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
+               ServerInstance->Logs->Log("win32",DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
        }
        return true;
 }