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