modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / Windows / vlmcsd_old_vancepym / libkms.c
blob58501311f6dc3a5e12bc61bb1a877f9717bc8fc3
1 /*
2 * libkms.c
3 */
5 #ifndef CONFIG
6 #define CONFIG "config.h"
7 #endif // CONFIG
8 #include CONFIG
10 #define EXTERNAL dllexport
12 #define DLLVERSION 0x30000
14 #include "libkms.h"
15 #include "shared_globals.h"
16 #include "network.h"
17 #include "helpers.h"
19 #ifndef _WIN32
20 #include <signal.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <errno.h>
24 #include <netinet/in.h>
25 #endif // WIN32
27 static int_fast8_t IsServerStarted = FALSE;
30 EXTERNC __declspec(EXTERNAL) DWORD __cdecl SendActivationRequest
32 const char* const hostname,
33 const int port,
34 RESPONSE* baseResponse,
35 const REQUEST* const baseRequest,
36 RESPONSE_RESULT* result, BYTE *hwid
39 return !0; // not yet implemented
43 EXTERNC __declspec(EXTERNAL) DWORD __cdecl StartKmsServer(const int port, RequestCallback_t requestCallback)
45 char listenAddress[64];
47 if (IsServerStarted) return !0;
49 # ifdef _WIN32
50 # ifndef USE_MSRPC
51 // Windows Sockets must be initialized
52 WSADATA wsadata;
53 int error;
55 if ((error = WSAStartup(0x0202, &wsadata)))
57 return error;
59 # endif // USE_MSRPC
60 # endif // _WIN32
62 CreateResponseBase = requestCallback;
64 int maxsockets = 0;
65 int_fast8_t haveIPv4 = FALSE;
66 int_fast8_t haveIPv6 = FALSE;
68 if (checkProtocolStack(AF_INET)) { haveIPv4 = TRUE; maxsockets++; }
69 if (checkProtocolStack(AF_INET6)) { haveIPv6 = TRUE; maxsockets++; }
71 if(!maxsockets) return !0;
73 SocketList = (SOCKET*)vlmcsd_malloc(sizeof(SOCKET) * (size_t)maxsockets);
74 numsockets = 0;
76 if (haveIPv4)
78 snprintf(listenAddress, 64, "0.0.0.0:%u", (unsigned int)port);
79 addListeningSocket(listenAddress);
82 if (haveIPv6)
84 snprintf(listenAddress, 64, "[::]:%u", (unsigned int)port);
85 addListeningSocket(listenAddress);
88 if (!numsockets)
90 free(SocketList);
91 return !0;
94 IsServerStarted = TRUE;
96 runServer();
98 IsServerStarted = FALSE;
99 return 0;
103 EXTERNC __declspec(EXTERNAL) DWORD __cdecl StopKmsServer()
105 if (!IsServerStarted) return !0;
107 closeAllListeningSockets();
108 if (SocketList) free(SocketList);
109 return 0;
113 EXTERNC __declspec(EXTERNAL) int __cdecl GetLibKmsVersion()
115 return DLLVERSION;