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