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