1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 Wrapper Functions/Definitions
18 #ifndef INSPIRCD_WIN32WRAPPER_H
19 #define INSPIRCD_WIN32WRAPPER_H
21 #ifndef CONFIGURE_BUILD
22 #include "win32service.h"
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 */
28 #define ENABLE_CRASHDUMPS 0
30 /* This defaults to 64, way too small for an ircd! */
31 /* CRT memory debugging */
33 #define _CRTDBG_MAP_ALLOC
38 #define FD_SETSIZE 24000
40 typedef unsigned __int16 uint16_t;
41 typedef unsigned __int32 uint32_t;
43 /* Make builds smaller, leaner and faster */
45 #define WIN32_LEAN_AND_MEAN
47 /* Not defined in windows */
50 /* Not defined in windows, parameter to shutdown() */
53 /* They just have to be *different*, don't they. */
54 #define PATH_MAX MAX_PATH
56 /* Begone shitty 'safe STL' warnings */
57 #define _SCL_SECURE_NO_WARNINGS
58 #define _CRT_SECURE_NO_WARNINGS
59 #define _AFX_SECURE_NO_WARNINGS
60 #define _ATL_SECURE_NO_WARNINGS
62 /* Macros for exporting symbols - dependant on what is being compiled */
65 #define CoreExport __declspec(dllimport)
66 #define DllExport __declspec(dllexport)
68 #define CoreExport __declspec(dllexport)
69 #define DllExport __declspec(dllimport)
72 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
73 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
75 /* Disable the deprecation warnings.. it spams :P */
76 #define _CRT_SECURE_NO_DEPRECATE
77 #define _SCL_SECURE_NO_DEPRECATE
81 /* Say we're building on windows 2000. Anyone running something older than this
82 * reeeeeeeally needs to upgrade! */
84 /* Normal windows (platform-specific) includes */
88 #include <sys/types.h>
95 #ifdef ENABLE_CRASHDUMPS
99 /* strcasecmp is not defined on windows by default */
100 #define strcasecmp _stricmp
102 /* this standard function is nonstarard. go figure. */
104 #define pclose _pclose
106 /* Error macros need to be redirected to winsock error codes, apart from on VS2010 *SIGH* */
108 #define ETIMEDOUT WSAETIMEDOUT
109 #define ECONNREFUSED WSAECONNREFUSED
110 #define EADDRINUSE WSAEADDRINUSE
111 #define EINPROGRESS WSAEWOULDBLOCK
112 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
115 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
116 CoreExport int insp_inet_pton(int af, const char * src, void * dst);
118 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
119 CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
121 /* we don't want to use windows' broken inet_pton and ntop */
122 #define inet_pton insp_inet_pton
123 #define inet_ntop insp_inet_ntop
125 /* Safe printf functions aren't defined in VC2003 */
126 #define snprintf _snprintf
127 #define vsnprintf _vsnprintf
129 /* Since when does the ISO C++ standard *remove* C functions?! */
130 #define mkdir(file,mode) _mkdir(file)
132 /* Unix-style sleep (argument is in seconds) */
133 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
135 /* IPV4 only convert string to address struct */
136 CoreExport int inet_aton(const char *, struct in_addr *);
138 /* Unix-style get running user id */
139 CoreExport int geteuid();
141 /* Handles colors in printf */
142 CoreExport int printf_c(const char * format, ...);
144 /* getopt() wrapper */
145 # define no_argument 0
146 # define required_argument 1
147 # define optional_argument 2
156 extern char optarg[514];
157 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
160 #define dlopen(path, state) (void*)LoadLibrary(path)
161 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
162 #define dlclose(handle) FreeLibrary((HMODULE)handle)
163 const char * dlerror();
165 /* Unix-style directory searching functions */
166 #define chmod(filename, mode)
170 char d_name[MAX_PATH];
175 dirent dirent_pointer;
177 WIN32_FIND_DATA find_data;
181 CoreExport DIR * opendir(const char * path);
182 CoreExport dirent * readdir(DIR * handle);
183 CoreExport void closedir(DIR * handle);
185 CoreExport int gettimeofday(struct timeval * tv, void * tz);
187 /* Disable these stupid warnings.. */
188 #pragma warning(disable:4800)
189 #pragma warning(disable:4251)
190 #pragma warning(disable:4275)
191 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
192 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
193 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
194 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
195 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
196 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
197 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
198 #pragma warning(disable:4706) // warning C4706: assignment within conditional expression
199 #pragma warning(disable:4201) // mmsystem.h generates this warning
201 /* Mehhhh... typedefs. */
203 typedef unsigned char uint8_t;
204 typedef unsigned long long uint64_t;
205 typedef signed char int8_t;
206 typedef signed long int32_t;
207 typedef signed long long int64_t;
209 /* Shared memory allocation functions */
210 void * ::operator new(size_t iSize);
211 void ::operator delete(void * ptr);
218 /* Look up the nameserver in use from the registry on windows */
219 CoreExport std::string FindNameServerWin();
221 /* Clear a windows console */
222 CoreExport void ClearConsole();
224 CoreExport DWORD WindowsForkStart(InspIRCd* Instance);
226 CoreExport void WindowsForkKillOwner(InspIRCd* Instance);
228 CoreExport void ChangeWindowsSpecificPointers(InspIRCd* Instance);
230 CoreExport bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
232 CoreExport bool initwmi();
233 CoreExport void donewmi();
234 CoreExport int getcpu();