bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / common / jk_global.h
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 /***************************************************************************
19  * Description: Global definitions and include files that should exist     *
20  *              anywhere                                                   *
21  * Author:      Gal Shachor <shachor@il.ibm.com>                           *
22  * Version:     $Revision: 1126561 $                                               *
23  ***************************************************************************/
24
25 #ifndef JK_GLOBAL_H
26 #define JK_GLOBAL_H
27
28 #if defined(HAVE_CONFIG_H)
29 #include "config.h"
30 #endif
31
32 #if defined(WIN32)
33
34 /* Ignore most warnings (back down to /W3) for poorly constructed headers
35  */
36 #if defined(_MSC_VER) && _MSC_VER >= 1200
37 #pragma warning(push, 3)
38 #endif
39
40 /* disable or reduce the frequency of...
41  *   C4057: indirection to slightly different base types
42  *   C4075: slight indirection changes (unsigned short* vs short[])
43  *   C4100: unreferenced formal parameter
44  *   C4127: conditional expression is constant
45  *   C4163: '_rotl64' : not available as an intrinsic function
46  *   C4201: nonstandard extension nameless struct/unions
47  *   C4244: int to char/short - precision loss
48  *   C4514: unreferenced inline function removed
49  */
50 #pragma warning(disable: 4100 4127 4163 4201 4514; once: 4057 4075 4244)
51
52 /* Ignore Microsoft's interpretation of secure development
53  * and the POSIX string handling API
54  */
55 #if defined(_MSC_VER) && _MSC_VER >= 1400
56 #ifndef _CRT_SECURE_NO_DEPRECATE
57 #define _CRT_SECURE_NO_DEPRECATE
58 #endif
59 #pragma warning(disable: 4996)
60 #endif /* defined(_MSC_VER) && _MSC_VER >= 1400 */
61 #endif /* defined(WIN32) */
62
63 #include "jk_version.h"
64
65 #ifdef HAVE_APR
66 #include "apr_lib.h"
67 #include "apr_strings.h"
68 #endif
69
70 #include <stdio.h>
71 #include <stdlib.h>
72 #include <string.h>
73 #include <stdarg.h>
74 #include <errno.h>
75 #include <time.h>
76 #include <ctype.h>
77 #include <limits.h>
78
79 #ifdef _OSD_POSIX
80 #include "ap_config.h"
81 #endif
82
83 #ifdef AS400
84 #include "ap_config.h"
85 extern char *strdup(const char *str);
86 #endif
87
88 #include <sys/types.h>
89 #include <sys/stat.h>
90
91 #ifdef WIN32
92 #ifndef _WINDOWS_
93 #ifndef WIN32_LEAN_AND_MEAN
94 #define WIN32_LEAN_AND_MEAN
95 #endif
96 #ifndef _WIN32_WINNT
97
98 /* Restrict the server to a subset of Windows NT 4.0 header files by default
99  */
100 #define _WIN32_WINNT 0x0500
101 #endif
102 #ifndef NOUSER
103 #define NOUSER
104 #endif
105 #ifndef NOMCX
106 #define NOMCX
107 #endif
108 #ifndef NOIME
109 #define NOIME
110 #endif
111 #include <windows.h>
112 /*
113  * Add a _very_few_ declarations missing from the restricted set of headers
114  * (If this list becomes extensive, re-enable the required headers above!)
115  * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
116  */
117 #include <winsock2.h>
118 #include <mswsock.h>
119 #include <mstcpip.h>
120 #endif /* _WINDOWS_ */
121 #ifdef _WINDOWS_
122 #ifndef SIO_RCVALL
123 #include <mstcpip.h>
124 #endif
125 #endif
126 #include <sys/timeb.h>
127 #include <process.h>
128 #include <io.h>
129 #include <ws2tcpip.h>
130 #else /* WIN32 */
131 #include <unistd.h>
132 #if defined(NETWARE) && defined(__NOVELL_LIBC__)
133 #include <novsock2.h>
134 #define __sys_socket_h__
135 #define __netdb_h__
136 #define __netinet_in_h__
137 #define HAVE_VSNPRINTF
138 #define HAVE_SNPRINTF
139 #endif
140 #include <netdb.h>
141 #include <netinet/in.h>
142 #include <sys/socket.h>
143 #include <fcntl.h>
144 #ifdef NETWARE
145 #ifndef _SOCKLEN_T
146 #define _SOCKLEN_T
147 typedef int socklen_t;
148 #endif
149 #else
150 #include <netinet/tcp.h>
151 #include <arpa/inet.h>
152 #include <sys/un.h>
153 #if !defined(_OSD_POSIX) && !defined(AS400) && !defined(__CYGWIN__) && !defined(HPUX11)
154 #include <sys/socketvar.h>
155 #endif
156 #if !defined(HPUX11) && !defined(AS400)
157 #include <sys/select.h>
158 #endif
159 #endif /* NETWARE */
160
161 #include <sys/time.h>
162 #include <sys/ioctl.h>
163 #endif /* WIN32 */
164
165 #ifdef __cplusplus
166 extern "C"
167 {
168 #endif                          /* __cplusplus */
169
170 #define JK_WORKER_FILE_TAG      ("worker_file")
171 #define JK_MOUNT_FILE_TAG       ("worker_mount_file")
172 #define JK_LOG_LEVEL_TAG        ("log_level")
173 #define JK_LOG_FILE_TAG         ("log_file")
174 #define JK_SHM_FILE_TAG         ("shm_file")
175 #define JK_WORKER_NAME_TAG      ("worker")
176
177 #define JK_WORKER_FILE_DEF  ("workers.properties")
178
179 /* Urimap reload check time. Use 60 seconds by default.
180  */
181 #define JK_URIMAP_DEF_RELOAD    (60)
182
183 #define JK_TRUE  (1)
184 #define JK_FALSE (0)
185
186 #define JK_UNSET (-1)
187
188 #define JK_LF (10)
189 #define JK_CR (13)
190
191 #define JK_SESSION_IDENTIFIER "JSESSIONID"
192 #define JK_PATH_SESSION_IDENTIFIER ";jsessionid"
193
194 #if defined(WIN32) || defined(NETWARE)
195 #ifdef __GNUC__
196 #define JK_METHOD
197 #define C_LEVEL_TRY_START
198 #define C_LEVEL_TRY_END
199 #define C_LEVEL_FINALLY_START
200 #define C_LEVEL_FINALLY_END
201 #else
202 #define JK_METHOD __stdcall
203 #define C_LEVEL_TRY_START       __try {
204 #define C_LEVEL_TRY_END         }
205 #define C_LEVEL_FINALLY_START   __finally {
206 #define C_LEVEL_FINALLY_END     }
207 #endif
208 #define PATH_SEPERATOR          (';')
209 #define FILE_SEPERATOR          ('\\')
210 #define PATH_ENV_VARIABLE       ("PATH")
211
212     /* incompatible names... */
213 #ifndef strcasecmp
214 #define strcasecmp stricmp
215 #endif
216 #else /* defined(WIN32) || defined(NETWARE) */
217 #define JK_METHOD
218 #define C_LEVEL_TRY_START
219 #define C_LEVEL_TRY_END
220 #define C_LEVEL_FINALLY_START
221 #define C_LEVEL_FINALLY_END
222 #define PATH_SEPERATOR          (':')
223 #define FILE_SEPERATOR          ('/')
224 #define PATH_ENV_VARIABLE       ("LD_LIBRARY_PATH")
225 #endif /* defined(WIN32) || defined(NETWARE) */
226
227 /* HTTP Error codes
228  */
229
230 #define JK_HTTP_OK                200
231 #define JK_HTTP_BAD_REQUEST       400
232 #define JK_HTTP_UNAUTHORIZED      401
233 #define JK_HTTP_REQUEST_TOO_LARGE 413
234 #define JK_HTTP_SERVER_ERROR      500
235 #define JK_HTTP_NOT_IMPLEMENTED   501
236 #define JK_HTTP_BAD_GATEWAY       502
237 #define JK_HTTP_SERVER_BUSY       503
238 #define JK_HTTP_GATEWAY_TIME_OUT  504
239
240
241 /*
242  * RECO STATUS
243  */
244
245 #define RECO_NONE   0x00
246 #define RECO_INITED 0x01
247 #define RECO_FILLED 0x02
248
249 /*
250  * JK options
251  */
252
253 #define JK_OPT_FWDURIMASK           0x0007
254
255 #define JK_OPT_FWDURICOMPAT         0x0001
256 #define JK_OPT_FWDURICOMPATUNPARSED 0x0002
257 #define JK_OPT_FWDURIESCAPED        0x0003
258 #define JK_OPT_FWDURIPROXY          0x0004
259
260 #define JK_OPT_FWDURIDEFAULT        JK_OPT_FWDURIPROXY
261
262 #define JK_OPT_FWDDIRS              0x0008
263 /* Forward local instead remote address */
264 #define JK_OPT_FWDLOCAL             0x0010
265 #define JK_OPT_FLUSHPACKETS         0x0020
266 #define JK_OPT_FLUSHEADER           0x0040
267 #define JK_OPT_DISABLEREUSE         0x0080
268 #define JK_OPT_FWDCERTCHAIN         0x0100
269 #define JK_OPT_FWDKEYSIZE           0x0200
270 #define JK_OPT_REJECTUNSAFE         0x0400
271
272 #define JK_OPT_DEFAULT              (JK_OPT_FWDURIDEFAULT | JK_OPT_FWDKEYSIZE)
273
274 /* Check for EBCDIC systems */
275
276 /* Check for Apache 2.0 running on an EBCDIC system */
277 #if APR_CHARSET_EBCDIC
278
279 #include <util_ebcdic.h>
280
281 #define USE_CHARSET_EBCDIC
282 #define jk_xlate_to_ascii(b, l) ap_xlate_proto_to_ascii(b, l)
283 #define jk_xlate_from_ascii(b, l) ap_xlate_proto_from_ascii(b, l)
284
285 #else                           /* APR_CHARSET_EBCDIC */
286
287 /* Check for Apache 1.3 running on an EBCDIC system */
288 #ifdef CHARSET_EBCDIC
289
290 #define USE_CHARSET_EBCDIC
291 #define jk_xlate_to_ascii(b, l) ebcdic2ascii(b, b, l)
292 #define jk_xlate_from_ascii(b, l) ascii2ebcdic(b, b, l)
293
294 #else                           /* CHARSET_EBCDIC */
295
296 /* We're in on an ASCII system */
297
298 #define jk_xlate_to_ascii(b, l) /* NOOP */
299 #define jk_xlate_from_ascii(b, l)       /* NOOP */
300
301 #endif                          /* CHARSET_EBCDIC */
302
303 #endif                          /* APR_CHARSET_EBCDIC */
304
305 /* on i5/OS V5R4 HTTP/APR APIs and Datas are in UTF */
306 #if defined(AS400_UTF8)
307 #undef USE_CHARSET_EBCDIC
308 #define jk_xlate_to_ascii(b, l) /* NOOP */
309 #define jk_xlate_from_ascii(b, l)       /* NOOP */
310 #endif
311
312 /* jk_uint32_t defines a four byte word */
313 /* jk_uint64_t defines a eight byte word */
314 #if defined (WIN32)
315     typedef unsigned int jk_uint32_t;
316 #define JK_UINT32_T_FMT "u"
317 #define JK_UINT32_T_HEX_FMT "x"
318     typedef unsigned __int64 jk_uint64_t;
319 #define JK_UINT64_T_FMT "I64u"
320 #define JK_UINT64_T_HEX_FMT "I64x"
321 #define JK_PID_T_FMT "d"
322 #define JK_PTHREAD_T_FMT "d"
323 #elif defined(AS400) || defined(NETWARE)
324     typedef unsigned int jk_uint32_t;
325 #define JK_UINT32_T_FMT "u"
326 #define JK_UINT32_T_HEX_FMT "x"
327     typedef unsigned long long jk_uint64_t;
328 #define JK_UINT64_T_FMT "llu"
329 #define JK_UINT64_T_HEX_FMT "llx"
330 #define JK_PID_T_FMT "d"
331 #define JK_PTHREAD_T_FMT "d"
332 #else
333 #include "jk_types.h"
334 #endif
335
336 #define JK_UINT32_T_FMT_LEN  (sizeof(JK_UINT32_T_FMT) - 1)
337 #define JK_UINT32_T_HEX_FMT_LEN  (sizeof(JK_UINT32_T_HEX_FMT) - 1)
338 #define JK_UINT64_T_FMT_LEN  (sizeof(JK_UINT64_T_FMT) - 1)
339 #define JK_UINT64_T_HEX_FMT_LEN  (sizeof(JK_UINT64_T_HEX_FMT) - 1)
340
341 #ifdef WIN32
342 /* For WIN32, emulate gettimeofday() using _ftime() */
343 #define gettimeofday(tv, tz) { struct _timeb tb; _ftime(&tb); \
344                                (tv)->tv_sec = (long)tb.time;  \
345                                (tv)->tv_usec = tb.millitm * 1000; }
346 #define HAVE_VSNPRINTF
347 #define HAVE_SNPRINTF
348 #ifdef HAVE_APR
349 #define snprintf apr_snprintf
350 #define vsnprintf apr_vsnprintf
351 #else
352 /* define snprint to match windows version */
353 #define snprintf _snprintf
354 #define vsnprintf _vsnprintf
355 #endif
356 #endif /* WIN32" */
357
358 /* Use apr snprintf() and vsnprintf() when needed */
359 #if defined(HAVE_APR)
360 #if !defined(HAVE_SNPRINTF)
361 #define snprintf apr_snprintf
362 #endif
363 #if !defined(HAVE_VSNPRINTF)
364 #define vsnprintf apr_vsnprintf
365 #endif
366 #endif
367
368 /* Use ap snprintf() and vsnprintf() when needed */
369 #if !defined(HAVE_APR)
370 #if !defined(HAVE_SNPRINTF)
371 #define snprintf ap_snprintf
372 #endif
373 #if !defined(HAVE_VSNPRINTF)
374 #define vsnprintf ap_vsnprintf
375 #endif
376 #endif
377
378 #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
379 typedef SOCKET jk_sock_t;
380 #define IS_VALID_SOCKET(s) ((s) != INVALID_SOCKET)
381 #define JK_INVALID_SOCKET  INVALID_SOCKET
382 #else
383 typedef int jk_sock_t;
384 #define IS_VALID_SOCKET(s) ((s) > 0)
385 #define JK_INVALID_SOCKET  (-1)
386 #endif
387
388 #ifdef NETWARE
389 #ifdef __NOVELL_LIBC__
390 #define MAX_PATH 511
391 #else
392 #define MAX_PATH 255
393 #endif
394 #endif
395
396 #ifdef AS400_UTF8
397 #define strcasecmp(a,b) apr_strnatcasecmp(a,b)
398 #endif
399
400 #ifdef __cplusplus
401 }
402 #endif                          /* __cplusplus */
403
404 #endif                          /* JK_GLOBAL_H */
405