]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_win32wrapper.h
More changes from patch. Don't throttle opers due to server load.
[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 /* Remember file descriptors are treated differently on windows ;) */
83 __inline int close(int socket) { return closesocket(socket); }
84
85 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
86 CoreExport int inet_pton(int af, const char * src, void * dst);
87
88 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
89 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
90
91 /* Safe printf functions aren't defined in VC2003 */
92 #define snprintf _snprintf
93 #define vsnprintf _vsnprintf
94
95 /* Recursive token function doesn't exist in VC++ */
96 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
97
98 /* Unix-style sleep (argument is in seconds) */
99 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
100
101 /* IPV4 only convert string to address struct */
102 CoreExport int inet_aton(const char *, struct in_addr *);
103
104 /* Unix-style get running user id */
105 CoreExport int geteuid();
106
107 /* Handles colors in printf */
108 CoreExport int printf_c(const char * format, ...);
109
110 /* getopt() wrapper */
111 # define no_argument            0
112 # define required_argument      1
113 # define optional_argument      2
114 struct option
115 {
116         char *name;
117         int has_arg;
118         int *flag;
119         int val;
120 };
121 extern char optarg[514];
122 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
123
124 /* Accept Handlers */
125 struct udp_overlap;
126 CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent);
127 CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent);
128 CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov);
129
130 /* Module Loading */
131 #define dlopen(path, state) (void*)LoadLibrary(path)
132 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
133 #define dlclose(handle) FreeLibrary((HMODULE)handle)
134 const char * dlerror();
135
136 /* Unix-style directory searching functions */
137 #define chmod(filename, mode)  
138 struct dirent
139 {
140         char d_name[MAX_PATH];
141 };
142
143 struct DIR
144 {
145         dirent dirent_pointer;
146         HANDLE find_handle;
147         WIN32_FIND_DATA find_data;
148         bool first;
149 };
150
151 CoreExport DIR * opendir(const char * path);
152 CoreExport dirent * readdir(DIR * handle);
153 CoreExport void closedir(DIR * handle);
154
155 /* Disable these stupid warnings.. */
156 #pragma warning(disable:4800)
157 #pragma warning(disable:4251)
158 #pragma warning(disable:4275)
159 #pragma warning(disable:4244)           // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
160 #pragma warning(disable:4267)           // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
161 #pragma warning(disable:4805)           // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
162 #pragma warning(disable:4311)           // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
163 #pragma warning(disable:4312)           // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
164 #pragma warning(disable:4355)           // warning C4355: 'this' : used in base member initializer list
165 #pragma warning(disable:4996)           // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
166
167 /* Mehhhh... typedefs. */
168
169 typedef unsigned char uint8_t;
170 typedef unsigned long long uint64_t;
171 typedef signed char int8_t;
172 typedef signed long int32_t;
173 typedef signed long long int64_t;
174
175 /* Shared memory allocation functions */
176 void * ::operator new(size_t iSize);
177 void ::operator delete(void * ptr);
178
179 /* IPC Handlers */
180 class InspIRCd;
181 class ValueItem;
182 class ServerConfig;
183
184 class IPC
185 {
186  private:
187         InspIRCd* Instance;
188         HANDLE hIPCPipe;
189  public:
190         IPC(InspIRCd* Srv);
191         void Check();
192         ~IPC();
193 };
194
195 /* Look up the nameserver in use from the registry on windows */
196 std::string FindNameServerWin();
197
198 /* Clear a windows console */
199 void ClearConsole();
200
201 DWORD WindowsForkStart(InspIRCd* Instance);
202
203 void WindowsForkKillOwner(InspIRCd* Instance);
204
205 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
206
207 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
208
209 #endif
210