1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2013 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
20 /* $Id$ */
21
22 #ifndef PHP_H
23 #define PHP_H
24
25 #ifdef HAVE_DMALLOC
26 #include <dmalloc.h>
27 #endif
28
29 #define PHP_API_VERSION 20090626
30 #define PHP_HAVE_STREAMS
31 #define YYDEBUG 0
32
33 #include "php_version.h"
34 #include "zend.h"
35 #include "zend_qsort.h"
36 #include "php_compat.h"
37
38 #include "zend_API.h"
39
40 #undef sprintf
41 #define sprintf php_sprintf
42
43 /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */
44 #undef PHP_DEBUG
45 #define PHP_DEBUG ZEND_DEBUG
46
47 #ifdef PHP_WIN32
48 # include "tsrm_win32.h"
49 # include "win95nt.h"
50 # ifdef PHP_EXPORTS
51 # define PHPAPI __declspec(dllexport)
52 # else
53 # define PHPAPI __declspec(dllimport)
54 # endif
55 # define PHP_DIR_SEPARATOR '\\'
56 # define PHP_EOL "\r\n"
57 #else
58 # if defined(__GNUC__) && __GNUC__ >= 4
59 # define PHPAPI __attribute__ ((visibility("default")))
60 # else
61 # define PHPAPI
62 # endif
63 # define THREAD_LS
64 # define PHP_DIR_SEPARATOR '/'
65 # define PHP_EOL "\n"
66 #endif
67
68 #ifdef NETWARE
69 /* For php_get_uname() function */
70 #define PHP_UNAME "NetWare"
71 #define PHP_OS PHP_UNAME
72 #endif
73
74 #if HAVE_ASSERT_H
75 #if PHP_DEBUG
76 #undef NDEBUG
77 #else
78 #ifndef NDEBUG
79 #define NDEBUG
80 #endif
81 #endif
82 #include <assert.h>
83 #else /* HAVE_ASSERT_H */
84 #define assert(expr) ((void) (0))
85 #endif /* HAVE_ASSERT_H */
86
87 #define APACHE 0
88
89 #if HAVE_UNIX_H
90 #include <unix.h>
91 #endif
92
93 #if HAVE_ALLOCA_H
94 #include <alloca.h>
95 #endif
96
97 #if HAVE_BUILD_DEFS_H
98 #include <build-defs.h>
99 #endif
100
101 /*
102 * This is a fast version of strlcpy which should be used, if you
103 * know the size of the destination buffer and if you know
104 * the length of the source string.
105 *
106 * size is the allocated number of bytes of dst
107 * src_size is the number of bytes excluding the NUL of src
108 */
109
110 #define PHP_STRLCPY(dst, src, size, src_size) \
111 { \
112 size_t php_str_len; \
113 \
114 if (src_size >= size) \
115 php_str_len = size - 1; \
116 else \
117 php_str_len = src_size; \
118 memcpy(dst, src, php_str_len); \
119 dst[php_str_len] = '\0'; \
120 }
121
122 #ifndef HAVE_STRLCPY
123 BEGIN_EXTERN_C()
124 PHPAPI size_t php_strlcpy(char *dst, const char *src, size_t siz);
125 END_EXTERN_C()
126 #undef strlcpy
127 #define strlcpy php_strlcpy
128 #endif
129
130 #ifndef HAVE_STRLCAT
131 BEGIN_EXTERN_C()
132 PHPAPI size_t php_strlcat(char *dst, const char *src, size_t siz);
133 END_EXTERN_C()
134 #undef strlcat
135 #define strlcat php_strlcat
136 #endif
137
138 #ifndef HAVE_STRTOK_R
139 BEGIN_EXTERN_C()
140 char *strtok_r(char *s, const char *delim, char **last);
141 END_EXTERN_C()
142 #endif
143
144 #ifndef HAVE_SOCKLEN_T
145 typedef unsigned int socklen_t;
146 #endif
147
148 #define CREATE_MUTEX(a, b)
149 #define SET_MUTEX(a)
150 #define FREE_MUTEX(a)
151
152 /*
153 * Then the ODBC support can use both iodbc and Solid,
154 * uncomment this.
155 * #define HAVE_ODBC (HAVE_IODBC|HAVE_SOLID)
156 */
157
158 #include <stdlib.h>
159 #include <ctype.h>
160 #if HAVE_UNISTD_H
161 #include <unistd.h>
162 #endif
163 #if HAVE_STDARG_H
164 #include <stdarg.h>
165 #else
166 # if HAVE_SYS_VARARGS_H
167 # include <sys/varargs.h>
168 # endif
169 #endif
170
171 #ifndef va_copy
172 # ifdef __va_copy
173 # define va_copy(ap1, ap2) __va_copy((ap1), (ap2))
174 # else
175 # define va_copy(ap1, ap2) memcpy((&ap1), (&ap2), sizeof(va_list))
176 # endif
177 #endif
178
179 #include "zend_hash.h"
180 #include "php3_compat.h"
181 #include "zend_alloc.h"
182 #include "zend_stack.h"
183
184 #if STDC_HEADERS
185 # include <string.h>
186 #else
187 # ifndef HAVE_MEMCPY
188 # define memcpy(d, s, n) bcopy((s), (d), (n))
189 # endif
190 # ifndef HAVE_MEMMOVE
191 # define memmove(d, s, n) bcopy ((s), (d), (n))
192 # endif
193 #endif
194
195 #include "safe_mode.h"
196
197 #ifndef HAVE_STRERROR
198 char *strerror(int);
199 #endif
200
201 #if HAVE_PWD_H
202 # ifdef PHP_WIN32
203 #include "win32/param.h"
204 # else
205 #include <pwd.h>
206 #include <sys/param.h>
207 # endif
208 #endif
209
210 #if HAVE_LIMITS_H
211 #include <limits.h>
212 #endif
213
214 #ifndef LONG_MAX
215 #define LONG_MAX 2147483647L
216 #endif
217
218 #ifndef LONG_MIN
219 #define LONG_MIN (- LONG_MAX - 1)
220 #endif
221
222 #ifndef INT_MAX
223 #define INT_MAX 2147483647
224 #endif
225
226 #ifndef INT_MIN
227 #define INT_MIN (- INT_MAX - 1)
228 #endif
229
230 #define PHP_GCC_VERSION ZEND_GCC_VERSION
231 #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
232 #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
233
234 BEGIN_EXTERN_C()
235 #include "snprintf.h"
236 END_EXTERN_C()
237 #include "spprintf.h"
238
239 #define EXEC_INPUT_BUF 4096
240
241 #define PHP_MIME_TYPE "application/x-httpd-php"
242
243 /* macros */
244 #define STR_PRINT(str) ((str)?(str):"")
245
246 #ifndef MAXPATHLEN
247 # ifdef PATH_MAX
248 # define MAXPATHLEN PATH_MAX
249 # elif defined(MAX_PATH)
250 # define MAXPATHLEN MAX_PATH
251 # else
252 # define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */
253 # endif
254 #endif
255
256
257 /* global variables */
258 #if !defined(PHP_WIN32)
259 #define PHP_SLEEP_NON_VOID
260 #define php_sleep sleep
261 extern char **environ;
262 #endif /* !defined(PHP_WIN32) */
263
264 #ifdef PHP_PWRITE_64
265 ssize_t pwrite(int, void *, size_t, off64_t);
266 #endif
267
268 #ifdef PHP_PREAD_64
269 ssize_t pread(int, void *, size_t, off64_t);
270 #endif
271
272 BEGIN_EXTERN_C()
273 void phperror(char *error);
274 PHPAPI int php_write(void *buf, uint size TSRMLS_DC);
275 PHPAPI int php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1,
276 2);
277 PHPAPI void php_log_err(char *log_message TSRMLS_DC);
278 int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
279 int cfgparse(void);
280 END_EXTERN_C()
281
282 #define php_error zend_error
283 #define error_handling_t zend_error_handling_t
284
BEGIN_EXTERN_C()285 BEGIN_EXTERN_C()
286 static inline ZEND_ATTRIBUTE_DEPRECATED void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
287 {
288 zend_replace_error_handling(error_handling, exception_class, NULL TSRMLS_CC);
289 }
php_std_error_handling()290 static inline ZEND_ATTRIBUTE_DEPRECATED void php_std_error_handling() {}
291
292 PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) PHP_ATTRIBUTE_FORMAT(printf, 4, 0);
293
294 #ifdef ZTS
295 #define PHP_ATTR_FMT_OFFSET 1
296 #else
297 #define PHP_ATTR_FMT_OFFSET 0
298 #endif
299
300 /* PHPAPI void php_error(int type, const char *format, ...); */
301 PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
302 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 3, PHP_ATTR_FMT_OFFSET + 4);
303 PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
304 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 4, PHP_ATTR_FMT_OFFSET + 5);
305 PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
306 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 5, PHP_ATTR_FMT_OFFSET + 6);
307 #ifdef PHP_WIN32
308 PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC);
309 #endif
310 END_EXTERN_C()
311
312 #define php_error_docref php_error_docref0
313
314 #define zenderror phperror
315 #define zendlex phplex
316
317 #define phpparse zendparse
318 #define phprestart zendrestart
319 #define phpin zendin
320
321 #define php_memnstr zend_memnstr
322
323 /* functions */
324 BEGIN_EXTERN_C()
325 PHPAPI extern int (*php_register_internal_extensions_func)(TSRMLS_D);
326 PHPAPI int php_register_internal_extensions(TSRMLS_D);
327 PHPAPI int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC);
328 PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
329 PHPAPI void php_com_initialize(TSRMLS_D);
330 END_EXTERN_C()
331
332 /* PHP-named Zend macro wrappers */
333 #define PHP_FN ZEND_FN
334 #define PHP_MN ZEND_MN
335 #define PHP_NAMED_FUNCTION ZEND_NAMED_FUNCTION
336 #define PHP_FUNCTION ZEND_FUNCTION
337 #define PHP_METHOD ZEND_METHOD
338
339 #define PHP_RAW_NAMED_FE ZEND_RAW_NAMED_FE
340 #define PHP_NAMED_FE ZEND_NAMED_FE
341 #define PHP_FE ZEND_FE
342 #define PHP_DEP_FE ZEND_DEP_FE
343 #define PHP_FALIAS ZEND_FALIAS
344 #define PHP_DEP_FALIAS ZEND_DEP_FALIAS
345 #define PHP_ME ZEND_ME
346 #define PHP_MALIAS ZEND_MALIAS
347 #define PHP_ABSTRACT_ME ZEND_ABSTRACT_ME
348 #define PHP_ME_MAPPING ZEND_ME_MAPPING
349 #define PHP_FE_END ZEND_FE_END
350
351 #define PHP_MODULE_STARTUP_N ZEND_MODULE_STARTUP_N
352 #define PHP_MODULE_SHUTDOWN_N ZEND_MODULE_SHUTDOWN_N
353 #define PHP_MODULE_ACTIVATE_N ZEND_MODULE_ACTIVATE_N
354 #define PHP_MODULE_DEACTIVATE_N ZEND_MODULE_DEACTIVATE_N
355 #define PHP_MODULE_INFO_N ZEND_MODULE_INFO_N
356
357 #define PHP_MODULE_STARTUP_D ZEND_MODULE_STARTUP_D
358 #define PHP_MODULE_SHUTDOWN_D ZEND_MODULE_SHUTDOWN_D
359 #define PHP_MODULE_ACTIVATE_D ZEND_MODULE_ACTIVATE_D
360 #define PHP_MODULE_DEACTIVATE_D ZEND_MODULE_DEACTIVATE_D
361 #define PHP_MODULE_INFO_D ZEND_MODULE_INFO_D
362
363 /* Compatibility macros */
364 #define PHP_MINIT ZEND_MODULE_STARTUP_N
365 #define PHP_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N
366 #define PHP_RINIT ZEND_MODULE_ACTIVATE_N
367 #define PHP_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N
368 #define PHP_MINFO ZEND_MODULE_INFO_N
369 #define PHP_GINIT ZEND_GINIT
370 #define PHP_GSHUTDOWN ZEND_GSHUTDOWN
371
372 #define PHP_MINIT_FUNCTION ZEND_MODULE_STARTUP_D
373 #define PHP_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D
374 #define PHP_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D
375 #define PHP_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D
376 #define PHP_MINFO_FUNCTION ZEND_MODULE_INFO_D
377 #define PHP_GINIT_FUNCTION ZEND_GINIT_FUNCTION
378 #define PHP_GSHUTDOWN_FUNCTION ZEND_GSHUTDOWN_FUNCTION
379
380 #define PHP_MODULE_GLOBALS ZEND_MODULE_GLOBALS
381
382
383 /* Output support */
384 #include "main/php_output.h"
385 #define PHPWRITE(str, str_len) php_body_write((str), (str_len) TSRMLS_CC)
386 #define PUTS(str) do { \
387 const char *__str = (str); \
388 php_body_write(__str, strlen(__str) TSRMLS_CC); \
389 } while (0)
390
391 #define PUTC(c) (php_body_write(&(c), 1 TSRMLS_CC), (c))
392 #define PHPWRITE_H(str, str_len) php_header_write((str), (str_len) TSRMLS_CC)
393 #define PUTS_H(str) do { \
394 const char *__str = (str); \
395 php_header_write(__str, strlen(__str) TSRMLS_CC); \
396 } while (0)
397
398 #define PUTC_H(c) (php_header_write(&(c), 1 TSRMLS_CC), (c))
399
400 #include "php_streams.h"
401 #include "php_memory_streams.h"
402 #include "fopen_wrappers.h"
403
404
405 /* Virtual current working directory support */
406 #include "tsrm_virtual_cwd.h"
407
408 #include "zend_constants.h"
409
410 /* connection status states */
411 #define PHP_CONNECTION_NORMAL 0
412 #define PHP_CONNECTION_ABORTED 1
413 #define PHP_CONNECTION_TIMEOUT 2
414
415 #include "php_reentrancy.h"
416
417 /* Finding offsets of elements within structures.
418 * Taken from the Apache code, which in turn, was taken from X code...
419 */
420
421 #ifndef XtOffset
422 #if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__riscos__)))
423 #ifdef __STDC__
424 #define XtOffset(p_type, field) _Offsetof(p_type, field)
425 #else
426 #ifdef CRAY2
427 #define XtOffset(p_type, field) \
428 (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
429
430 #else /* !CRAY2 */
431
432 #define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
433
434 #endif /* !CRAY2 */
435 #endif /* __STDC__ */
436 #else /* ! (CRAY || __arm) */
437
438 #define XtOffset(p_type, field) \
439 ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
440
441 #endif /* !CRAY */
442 #endif /* ! XtOffset */
443
444 #ifndef XtOffsetOf
445 #ifdef offsetof
446 #define XtOffsetOf(s_type, field) offsetof(s_type, field)
447 #else
448 #define XtOffsetOf(s_type, field) XtOffset(s_type*, field)
449 #endif
450 #endif /* !XtOffsetOf */
451
452 #endif
453
454 /*
455 * Local variables:
456 * tab-width: 4
457 * c-basic-offset: 4
458 * End:
459 * vim600: sw=4 ts=4 fdm=marker
460 * vim<600: sw=4 ts=4
461 */
462