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