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