]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_win32wrapper.h
6008828393eacccd5fa17e2459ba846846cbdb96
[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 24000
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 /* this standard function is nonstarard. go figure. */
88 #define popen _popen
89 #define pclose _pclose
90
91 /* Error macros need to be redirected to winsock error codes */
92 #define ETIMEDOUT WSAETIMEDOUT
93 #define ECONNREFUSED WSAECONNREFUSED
94 #define EADDRINUSE WSAEADDRINUSE
95 #define EINPROGRESS WSAEWOULDBLOCK
96
97 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
98 CoreExport int inet_pton(int af, const char * src, void * dst);
99
100 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
101 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
102
103 /* Safe printf functions aren't defined in VC2003 */
104 #define snprintf _snprintf
105 #define vsnprintf _vsnprintf
106
107 /* Since when does the ISO C++ standard *remove* C functions?! */
108 #define mkdir(file,mode) _mkdir(file)
109
110 /* Recursive token function doesn't exist in VC++ */
111 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
112
113 /* Unix-style sleep (argument is in seconds) */
114 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
115
116 /* IPV4 only convert string to address struct */
117 CoreExport int inet_aton(const char *, struct in_addr *);
118
119 /* Unix-style get running user id */
120 CoreExport int geteuid();
121
122 /* Handles colors in printf */
123 CoreExport int printf_c(const char * format, ...);
124
125 /* getopt() wrapper */
126 # define no_argument            0
127 # define required_argument      1
128 # define optional_argument      2
129 struct option
130 {
131         char *name;
132         int has_arg;
133         int *flag;
134         int val;
135 };
136 extern char optarg[514];
137 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
138
139 /* Module Loading */
140 #define dlopen(path, state) (void*)LoadLibrary(path)
141 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
142 #define dlclose(handle) FreeLibrary((HMODULE)handle)
143 const char * dlerror();
144
145 /* Unix-style directory searching functions */
146 #define chmod(filename, mode)  
147
148 struct dirent
149 {
150         char d_name[MAX_PATH];
151 };
152
153 struct DIR
154 {
155         dirent dirent_pointer;
156         HANDLE find_handle;
157         WIN32_FIND_DATA find_data;
158         bool first;
159 };
160
161 CoreExport DIR * opendir(const char * path);
162 CoreExport dirent * readdir(DIR * handle);
163 CoreExport void closedir(DIR * handle);
164
165 CoreExport int gettimeofday(struct timeval * tv, void * tz);
166
167 /* Disable these stupid warnings.. */
168 #pragma warning(disable:4800)
169 #pragma warning(disable:4251)
170 #pragma warning(disable:4275)
171 #pragma warning(disable:4244)           // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
172 #pragma warning(disable:4267)           // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
173 #pragma warning(disable:4805)           // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
174 #pragma warning(disable:4311)           // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
175 #pragma warning(disable:4312)           // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
176 #pragma warning(disable:4355)           // warning C4355: 'this' : used in base member initializer list
177 #pragma warning(disable:4996)           // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
178 #pragma warning(disable:4706)           // warning C4706: assignment within conditional expression
179 #pragma warning(disable:4201)           // mmsystem.h generates this warning
180
181 /* Mehhhh... typedefs. */
182
183 typedef unsigned char uint8_t;
184 typedef unsigned long long uint64_t;
185 typedef signed char int8_t;
186 typedef signed long int32_t;
187 typedef signed long long int64_t;
188
189 /* Shared memory allocation functions */
190 void * ::operator new(size_t iSize);
191 void ::operator delete(void * ptr);
192
193 /* IPC Handlers */
194 class InspIRCd;
195 class ValueItem;
196 class ServerConfig;
197
198 /* Look up the nameserver in use from the registry on windows */
199 CoreExport std::string FindNameServerWin();
200
201 /* Clear a windows console */
202 CoreExport void ClearConsole();
203
204 CoreExport DWORD WindowsForkStart(InspIRCd* Instance);
205
206 CoreExport void WindowsForkKillOwner(InspIRCd* Instance);
207
208 CoreExport void ChangeWindowsSpecificPointers(InspIRCd* Instance);
209
210 CoreExport bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
211
212 CoreExport bool initwmi();
213 CoreExport void donewmi();
214 CoreExport int getcpu();
215
216
217 #endif
218