]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_win32wrapper.h
Fix problem where in certain cases a \0 would be sent out. Thx to network Hak5IRC...
[user/henk/code/inspircd.git] / win / inspircd_win32wrapper.h
1 /*       +------------------------------------+\r
2  *       | Inspire Internet Relay Chat Daemon |\r
3  *       +------------------------------------+\r
4  *\r
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r
6  * See: http://www.inspircd.org/wiki/index.php/Credits\r
7  *\r
8  * This program is free but copyrighted software; see\r
9  *            the file COPYING for details.\r
10  *\r
11  * ---------------------------------------------------\r
12  */\r
13 \r
14 /* Windows Port\r
15    Wrapper Functions/Definitions\r
16    By Burlex */\r
17 \r
18 #ifndef INSPIRCD_WIN32WRAPPER_H\r
19 #define INSPIRCD_WIN32WRAPPER_H\r
20 \r
21 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.\r
22    I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */\r
23 #define WINDOWS 1\r
24 \r
25 /* Make builds smaller, leaner and faster */\r
26 #define VC_EXTRALEAN\r
27 \r
28 /* They just have to be *different*, don't they. */\r
29 #define PATH_MAX MAX_PATH\r
30 \r
31 /* Begone shitty 'safe STL' warnings */\r
32 #define _SCL_SECURE_NO_WARNINGS\r
33 #define _CRT_SECURE_NO_WARNINGS\r
34 #define _AFX_SECURE_NO_WARNINGS\r
35 #define _ATL_SECURE_NO_WARNINGS\r
36 \r
37 /* Macros for exporting symbols - dependant on what is being compiled */\r
38 \r
39 #ifdef DLL_BUILD\r
40 #define CoreExport __declspec(dllimport)\r
41 #define DllExport __declspec(dllexport)\r
42 #else\r
43 #define CoreExport __declspec(dllexport)\r
44 #define DllExport __declspec(dllimport)\r
45 #endif\r
46 \r
47 /* Disable the deprecation warnings.. it spams :P */\r
48 #define _CRT_SECURE_NO_DEPRECATE\r
49 #define _SCL_SECURE_NO_DEPRECATE\r
50 \r
51 #include <string>\r
52 \r
53 /* Say we're building on windows 2000. Anyone running something older than this\r
54  * reeeeeeeally needs to upgrade! */\r
55 \r
56 #define _WIN32_WINNT 0x500\r
57 \r
58 /* Normal windows (platform-specific) includes */\r
59 #include <winsock2.h>\r
60 #include <windows.h>\r
61 #include <ws2tcpip.h>\r
62 #include <sys/types.h>\r
63 #include <sys/stat.h>\r
64 #include <direct.h>\r
65 #include <process.h>\r
66 #include <stdio.h>\r
67 #include <algorithm>\r
68 \r
69 /* strcasecmp is not defined on windows by default */\r
70 #define strcasecmp _stricmp\r
71 \r
72 /* Error macros need to be redirected to winsock error codes */\r
73 #define ETIMEDOUT WSAETIMEDOUT\r
74 #define ECONNREFUSED WSAECONNREFUSED\r
75 #define EADDRINUSE WSAEADDRINUSE\r
76 #define EINPROGRESS WSAEWOULDBLOCK\r
77 \r
78 /* Remember file descriptors are treated differently on windows ;) */\r
79 __inline int close(int socket) { return closesocket(socket); }\r
80 \r
81 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */\r
82 CoreExport int inet_pton(int af, const char * src, void * dst);\r
83 \r
84 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */\r
85 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);\r
86 \r
87 /* Safe printf functions aren't defined in VC2003 */\r
88 #define snprintf _snprintf\r
89 #define vsnprintf _vsnprintf\r
90 \r
91 /* Recursive token function doesn't exist in VC++ */\r
92 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);\r
93 \r
94 /* Unix-style sleep (argument is in seconds) */\r
95 __inline void sleep(int seconds) { Sleep(seconds * 1000); }\r
96 \r
97 /* IPV4 only convert string to address struct */\r
98 CoreExport int inet_aton(const char *, struct in_addr *);\r
99 \r
100 /* Unix-style get running user id */\r
101 CoreExport int geteuid();\r
102 \r
103 /* Handles colors in printf */\r
104 CoreExport int printf_c(const char * format, ...);\r
105 \r
106 /* getopt() wrapper */\r
107 # define no_argument            0\r
108 # define required_argument      1\r
109 # define optional_argument      2\r
110 struct option\r
111 {\r
112         char *name;\r
113         int has_arg;\r
114         int *flag;\r
115         int val;\r
116 };\r
117 extern char optarg[514];\r
118 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);\r
119 \r
120 /* Accept Handlers */\r
121 struct udp_overlap;\r
122 CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent);\r
123 CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent);\r
124 CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov);\r
125 \r
126 /* Module Loading */\r
127 #define dlopen(path, state) (void*)LoadLibrary(path)\r
128 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)\r
129 #define dlclose(handle) FreeLibrary((HMODULE)handle)\r
130 const char * dlerror();\r
131 \r
132 /* Unix-style directory searching functions */\r
133 #define chmod(filename, mode)  \r
134 struct dirent\r
135 {\r
136         char d_name[MAX_PATH];\r
137 };\r
138 \r
139 struct DIR\r
140 {\r
141         dirent dirent_pointer;\r
142         HANDLE find_handle;\r
143         WIN32_FIND_DATA find_data;\r
144         bool first;\r
145 };\r
146 \r
147 CoreExport DIR * opendir(const char * path);\r
148 CoreExport dirent * readdir(DIR * handle);\r
149 CoreExport void closedir(DIR * handle);\r
150 \r
151 /* Disable these stupid warnings.. */\r
152 #pragma warning(disable:4800)\r
153 #pragma warning(disable:4251)\r
154 #pragma warning(disable:4275)\r
155 #pragma warning(disable:4244)           // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data\r
156 #pragma warning(disable:4267)           // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data\r
157 #pragma warning(disable:4805)           // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation\r
158 #pragma warning(disable:4311)           // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'\r
159 #pragma warning(disable:4312)           // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size\r
160 #pragma warning(disable:4355)           // warning C4355: 'this' : used in base member initializer list\r
161 #pragma warning(disable:4996)           // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated\r
162 \r
163 /* Mehhhh... typedefs. */\r
164 \r
165 typedef unsigned char uint8_t;\r
166 typedef unsigned long long uint64_t;\r
167 typedef signed char int8_t;\r
168 typedef signed long int32_t;\r
169 typedef signed long long int64_t;\r
170 \r
171 /* Shared memory allocation functions */\r
172 void * ::operator new(size_t iSize);\r
173 void ::operator delete(void * ptr);\r
174 \r
175 /* IPC Handlers */\r
176 class InspIRCd;\r
177 \r
178 void InitIPC();\r
179 void CheckIPC(InspIRCd * Instance);\r
180 void CloseIPC();\r
181 \r
182 /* Look up the nameserver in use from the registry on windows */\r
183 std::string FindNameServerWin();\r
184 \r
185 /* Clear a windows console */\r
186 void ClearConsole();\r
187 \r
188 #endif\r
189 \r