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