1 /************************************************************************
2 * Unreal Internet Relay Chat Daemon, include/common.h
3 * Copyright (C) 1990 Armin Gruner
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * $Id$
20 */
21
22 #ifndef __common_include__
23 #define __common_include__
24
25 #include <time.h>
26 #ifdef _WIN32
27 #include <malloc.h>
28 #ifdef INET6
29 #include <winsock2.h>
30 #include <ws2tcpip.h>
31 #endif
32 #include <windows.h>
33 #ifndef INET6
34 #include <winsock.h>
35 #endif
36 #include <process.h>
37 #include <io.h>
38 #endif
39 #include "types.h"
40 #include "config.h"
41 #ifdef PARAMH
42 #include <sys/param.h>
43 #endif
44
45 #if !defined(IN_ADDR)
46 #include "sys.h"
47 #endif
48
49 #include "ircsprintf.h"
50
51
52 #ifdef DEVELOP_CVS
53 #define ID_Copyright(x) static char id_copyright[] = x
54 #define ID_Notes(x) static char id_notes[] = x
55 #else
56 #define ID_Copyright(x)
57 #define ID_Notes(x)
58 #endif
59
60 #define BMAGIC 0x4675636B596F754661736369737473
61
62 #define BASE_VERSION "Unreal"
63 #ifndef _WIN32
64 #define FDwrite(x,y,z) write(x, y, z)
65 #else
66 #define FDwrite(x,y,z) send(x, y, z, 0)
67 #endif
68 #ifndef NULL
69 #define NULL 0
70 #endif
71
72 #ifdef TRUE
73 #undef TRUE
74 #endif
75
76 #ifdef FALSE
77 #undef FALSE
78 #endif
79
80 #define FALSE (0)
81 #define TRUE (!FALSE)
82
83 #ifndef UNSURE
84 #define UNSURE (2)
85 #endif
86
87 #if 0
88 #ifndef MALLOCH
89 char *malloc(), *calloc();
90 void free();
91 #else
92 #include MALLOCH
93 #endif
94 #endif
95
96 #define TS time_t
97
98
99 extern int match(const char *, const char *);
100 #define mycmp(a,b) \
101 ( (toupper(a[0])!=toupper(b[0])) || smycmp((a)+1,(b)+1) )
102 extern int smycmp(const char *, const char *);
103 #ifndef GLIBC2_x
104 extern int myncmp(const char *, const char *, int);
105 #endif
106
107 #ifdef NEED_STRTOK
108 extern char *strtok2(char *, char *);
109 #endif
110 #ifdef NEED_STRTOKEN
111 extern char *strtoken(char **, char *, char *);
112 #endif
113 #ifdef NEED_INET_ADDR
114 extern unsigned long inet_addr(char *);
115 #endif
116
117 #if defined(NEED_INET_NTOA) || defined(NEED_INET_NETOF) && !defined(_WIN32)
118 #include <netinet/in.h>
119 #endif
120 #ifdef NEED_INET_NTOA
121 extern char *inet_ntoa(struct IN_ADDR);
122 #endif
123
124 #ifdef NEED_INET_NETOF
125 extern int inet_netof(struct IN_ADDR);
126 #endif
127
128 #ifndef HAVE_INET_NTOP
129 const char *inet_ntop(int, const void *, char *, size_t);
130 #endif
131
132 #ifndef HAVE_INET_PTON
133 int inet_pton(int af, const char *src, void *dst);
134 #endif
135
136 MODVAR int global_count, max_global_count;
137 extern char *myctime(time_t);
138 extern char *strtoken(char **, char *, char *);
139
140 #define PRECISE_CHECK
141
142 #ifndef MAX
143 #define MAX(a, b) ((a) > (b) ? (a) : (b))
144 #endif
145 #ifndef MIN
146 #define MIN(a, b) ((a) < (b) ? (a) : (b))
147 #endif
148
149 #define DupString(x,y) do{int l=strlen(y);x=MyMalloc(l+1);(void)memcpy(x,y, l+1);}while(0)
150
151 extern MODVAR u_char tolowertab[], touppertab[];
152
153 #if defined(NICK_GB2312) || defined(NICK_GBK) || defined(NICK_GBK_JAP)
154 #define USE_LOCALE
155 #include <ctype.h>
156 #endif
157
158 #ifndef USE_LOCALE
159 #undef tolower
160 #define tolower(c) (tolowertab[(u_char)(c)])
161
162 #undef toupper
163 #define toupper(c) (touppertab[(u_char)(c)])
164
165 #undef isalpha
166 #undef isdigit
167 #undef isxdigit
168 #undef isalnum
169 #undef isprint
170 #undef isascii
171 #undef isgraph
172 #undef ispunct
173 #undef islower
174 #undef isupper
175 #undef isspace
176 #undef iscntrl
177 #endif
178 extern MODVAR unsigned char char_atribs[];
179
180 #define PRINT 1
181 #define CNTRL 2
182 #define ALPHA 4
183 #define PUNCT 8
184 #define DIGIT 16
185 #define SPACE 32
186 #define ALLOW 64
187 #define ALLOWN 128
188
189 #ifndef KLINE_TEMP
190 #define KLINE_PERM 0
191 #define KLINE_TEMP 1
192 #define KLINE_AKILL 2
193 #define KLINE_EXCEPT 3
194 #endif
195
196 #define isallowed(c) (char_atribs[(u_char)(c)]&ALLOW)
197 #ifndef USE_LOCALE
198 #define iscntrl(c) (char_atribs[(u_char)(c)]&CNTRL)
199 #define isalpha(c) (char_atribs[(u_char)(c)]&ALPHA)
200 #define isspace(c) (char_atribs[(u_char)(c)]&SPACE)
201 #define islower(c) ((char_atribs[(u_char)(c)]&ALPHA) && ((u_char)(c) > 0x5f))
202 #define isupper(c) ((char_atribs[(u_char)(c)]&ALPHA) && ((u_char)(c) < 0x60))
203 #define isdigit(c) (char_atribs[(u_char)(c)]&DIGIT)
204 #define isxdigit(c) (isdigit(c) || ('a' <= (c) && (c) <= 'f') || \
205 ('A' <= (c) && (c) <= 'F'))
206 #define isalnum(c) (char_atribs[(u_char)(c)]&(DIGIT|ALPHA))
207 #define isprint(c) (char_atribs[(u_char)(c)]&PRINT)
208 #define isascii(c) ((u_char)(c) >= 0 && (u_char)(c) <= 0x7f)
209 #define isgraph(c) ((char_atribs[(u_char)(c)]&PRINT) && ((u_char)(c) != 0x32))
210 #define ispunct(c) (!(char_atribs[(u_char)(c)]&(CNTRL|ALPHA|DIGIT)))
211 #endif
212 #define iswseperator(c) (!isalnum(c) && !((u_char)c >= 128))
213
214 #ifndef MALLOCD
215 #define MyFree free
216 #define MyMalloc malloc
217 #define MyRealloc realloc
218 #else
219 #define MyFree(x) do {debug(DEBUG_MALLOC, "%s:%i: free %02x", __FILE__, __LINE__, x); free(x); } while(0)
220 #define MyMalloc(x) StsMalloc(x, __FILE__, __LINE__)
221 #define MyRealloc realloc
StsMalloc(size_t size,char * file,long line)222 static char *StsMalloc(size_t size, char *file, long line)
223 {
224 void *x;
225
226 x = malloc(size);
227 debug(DEBUG_MALLOC, "%s:%i: malloc %02x", file, line, x);
228 return x;
229 }
230
231 #endif
232
233 extern struct SLink *find_user_link( /* struct SLink *, struct Client * */ );
234
235 /*
236 * Protocol support text. DO NO CHANGE THIS unless you know what
237 * you are doing.
238 */
239
240 /* IRCu/Hybrid/Unreal way now :) -Stskeeps */
241
242 #ifdef EXTCMODE
243 #define EXPAR1 extchmstr[0]
244 #define EXPAR2 extchmstr[1]
245 #define EXPAR3 extchmstr[2]
246 #define EXPAR4 extchmstr[3]
247 #else
248 #define EXPAR1 ""
249 #define EXPAR2 ""
250 #define EXPAR3 ""
251 #define EXPAR4 ""
252 #endif /* EXTCMODE */
253
254 #ifdef PREFIX_AQ
255 #define CHPFIX "(qaohv)~&@%+"
256 #define CHPAR1 "beI"
257 #else
258 #define CHPFIX "(ohv)@%+"
259 #define CHPAR1 "beIqa"
260 #endif /* PREFIX_AQ */
261
262 #define CHPAR2 "kfL"
263 #define CHPAR3 "l"
264 #define CHPAR4 "psmntirRcOAQKVCuzNSM"
265
266
267 /* Server-Server PROTOCTL -Stskeeps
268 * This is the FIRST line only, please check send_proto() for more. -- Syzop
269 * Also take MAXPARA into account !
270 */
271 #define PROTOCTL_SERVER "NOQUIT" \
272 " TOKEN" \
273 " NICKv2" \
274 " SJOIN" \
275 " SJOIN2" \
276 " UMODE2" \
277 " VL" \
278 " SJ3" \
279 " NS" \
280 " SJB64" \
281 " TKLEXT" \
282 " NICKIP" \
283 " ESVID"
284
285 #ifdef _WIN32
286 /*
287 * Used to display a string to the GUI interface.
288 * Windows' internal strerror() function doesn't work with socket errors.
289 */
290 extern int DisplayString(HWND hWnd, char *InBuf, ...);
291 #else
292 typedef int SOCKET;
293 #define INVALID_SOCKET -1
294 #endif
295
296 #if defined(__FreeBSD__) || defined(__APPLE__)
297 extern char *malloc_options;
298 #endif
299
300 extern int lu_noninv, lu_inv, lu_serv, lu_oper,
301 lu_unknown, lu_channel, lu_lu, lu_lulocal, lu_lserv,
302 lu_clu, lu_mlu, lu_cglobalu, lu_mglobalu;
303
304 MODVAR TS now;
305
306 #ifndef _WIN32
307 #if defined(__STDC__)
308 #define __const const
309 #define __signed signed
310 #define __volatile volatile
311 #ifndef __GNUC__
312 #define __inline
313 #endif
314
315 #else
316 #ifndef __GNUC__
317 #define __const
318 #define __inline
319 #define __signed
320 #define __volatile
321 #ifndef NO_ANSI_KEYWORDS
322 #define const /* delete ANSI C keywords */
323 #define inline
324 #define signed
325 #define volatile
326 #endif
327 #endif
328 #endif
329 #else
330 #define inline __inline
331 #endif
332
333 #define READBUF_SIZE 8192
334
335 #endif /* __common_include__ */
336