]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_win32wrapper.h
Win32ThreadEngine makes sense now. No gaurantees it compiles yet.
[user/henk/code/inspircd.git] / win / inspircd_win32wrapper.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* Windows Port
15    Wrapper Functions/Definitions
16    By Burlex */
17
18 #ifndef INSPIRCD_WIN32WRAPPER_H
19 #define INSPIRCD_WIN32WRAPPER_H
20
21 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
22    I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
23 #define WINDOWS 1
24 #define ENABLE_CRASHDUMPS 0
25
26 /* This defaults to 64, way too small for an ircd! */
27 #define FD_SETSIZE 12000
28
29 /* Make builds smaller, leaner and faster */
30 #define VC_EXTRALEAN
31 #define WIN32_LEAN_AND_MEAN
32
33 /* Not defined in windows */
34 #define SIGHUP 1
35
36 /* Not defined in windows, parameter to shutdown() */
37 #define SHUT_WR 2
38
39 /* They just have to be *different*, don't they. */
40 #define PATH_MAX MAX_PATH
41
42 /* Begone shitty 'safe STL' warnings */
43 #define _SCL_SECURE_NO_WARNINGS
44 #define _CRT_SECURE_NO_WARNINGS
45 #define _AFX_SECURE_NO_WARNINGS
46 #define _ATL_SECURE_NO_WARNINGS
47
48 /* Macros for exporting symbols - dependant on what is being compiled */
49
50 #ifdef DLL_BUILD
51 #define CoreExport __declspec(dllimport)
52 #define DllExport __declspec(dllexport)
53 #else
54 #define CoreExport __declspec(dllexport)
55 #define DllExport __declspec(dllimport)
56 #endif
57
58 /* Disable the deprecation warnings.. it spams :P */
59 #define _CRT_SECURE_NO_DEPRECATE
60 #define _SCL_SECURE_NO_DEPRECATE
61
62 #include <string>
63
64 /* Say we're building on windows 2000. Anyone running something older than this
65  * reeeeeeeally needs to upgrade! */
66
67 #define _WIN32_WINNT 0x500
68
69 /* Normal windows (platform-specific) includes */
70 #include <winsock2.h>
71 #include <windows.h>
72 #include <ws2tcpip.h>
73 #include <sys/types.h>
74 #include <sys/stat.h>
75 #include <direct.h>
76 #include <process.h>
77 #include <stdio.h>
78 #include <algorithm>
79
80 #ifdef ENABLE_CRASHDUMPS
81 #include <DbgHelp.h>
82 #endif
83
84 /* strcasecmp is not defined on windows by default */
85 #define strcasecmp _stricmp
86
87 /* Error macros need to be redirected to winsock error codes */
88 #define ETIMEDOUT WSAETIMEDOUT
89 #define ECONNREFUSED WSAECONNREFUSED
90 #define EADDRINUSE WSAEADDRINUSE
91 #define EINPROGRESS WSAEWOULDBLOCK
92
93 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
94 CoreExport int inet_pton(int af, const char * src, void * dst);
95
96 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
97 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
98
99 /* Safe printf functions aren't defined in VC2003 */
100 #define snprintf _snprintf
101 #define vsnprintf _vsnprintf
102
103 /* Recursive token function doesn't exist in VC++ */
104 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
105
106 /* Unix-style sleep (argument is in seconds) */
107 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
108
109 /* IPV4 only convert string to address struct */
110 CoreExport int inet_aton(const char *, struct in_addr *);
111
112 /* Unix-style get running user id */
113 CoreExport int geteuid();
114
115 /* Handles colors in printf */
116 CoreExport int printf_c(const char * format, ...);
117
118 /* getopt() wrapper */
119 # define no_argument            0
120 # define required_argument      1
121 # define optional_argument      2
122 struct option
123 {
124         char *name;
125         int has_arg;
126         int *flag;
127         int val;
128 };
129 extern char optarg[514];
130 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
131
132 /* Module Loading */
133 #define dlopen(path, state) (void*)LoadLibrary(path)
134 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
135 #define dlclose(handle) FreeLibrary((HMODULE)handle)
136 const char * dlerror();
137
138 /* Unix-style directory searching functions */
139 #define chmod(filename, mode)  
140 struct dirent
141 {
142         char d_name[MAX_PATH];
143 };
144
145 struct DIR
146 {
147         dirent dirent_pointer;
148         HANDLE find_handle;
149         WIN32_FIND_DATA find_data;
150         bool first;
151 };
152
153 CoreExport DIR * opendir(const char * path);
154 CoreExport dirent * readdir(DIR * handle);
155 CoreExport void closedir(DIR * handle);
156
157 CoreExport int gettimeofday(struct timeval * tv, void * tz);
158
159 /* Disable these stupid warnings.. */
160 #pragma warning(disable:4800)
161 #pragma warning(disable:4251)
162 #pragma warning(disable:4275)
163 #pragma warning(disable:4244)           // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
164 #pragma warning(disable:4267)           // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
165 #pragma warning(disable:4805)           // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
166 #pragma warning(disable:4311)           // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
167 #pragma warning(disable:4312)           // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
168 #pragma warning(disable:4355)           // warning C4355: 'this' : used in base member initializer list
169 #pragma warning(disable:4996)           // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
170
171 /* Mehhhh... typedefs. */
172
173 typedef unsigned char uint8_t;
174 typedef unsigned long long uint64_t;
175 typedef signed char int8_t;
176 typedef signed long int32_t;
177 typedef signed long long int64_t;
178
179 /* Shared memory allocation functions */
180 void * ::operator new(size_t iSize);
181 void ::operator delete(void * ptr);
182
183 /* IPC Handlers */
184 class InspIRCd;
185 class ValueItem;
186 class ServerConfig;
187
188 class IPC
189 {
190  private:
191         InspIRCd* Instance;
192         HANDLE hIPCPipe;
193  public:
194         IPC(InspIRCd* Srv);
195         void Check();
196         ~IPC();
197 };
198
199 /* Look up the nameserver in use from the registry on windows */
200 std::string FindNameServerWin();
201
202 /* Clear a windows console */
203 void ClearConsole();
204
205 DWORD WindowsForkStart(InspIRCd* Instance);
206
207 void WindowsForkKillOwner(InspIRCd* Instance);
208
209 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
210
211 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
212
213 #endif
214