1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2015 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 20121113
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 # if PHP_WIN32
146 typedef int socklen_t;
147 # else
148 typedef unsigned int socklen_t;
149 # endif
150 #endif
151
152 #define CREATE_MUTEX(a, b)
153 #define SET_MUTEX(a)
154 #define FREE_MUTEX(a)
155
156 /*
157 * Then the ODBC support can use both iodbc and Solid,
158 * uncomment this.
159 * #define HAVE_ODBC (HAVE_IODBC|HAVE_SOLID)
160 */
161
162 #include <stdlib.h>
163 #include <ctype.h>
164 #if HAVE_UNISTD_H
165 #include <unistd.h>
166 #endif
167 #if HAVE_STDARG_H
168 #include <stdarg.h>
169 #else
170 # if HAVE_SYS_VARARGS_H
171 # include <sys/varargs.h>
172 # endif
173 #endif
174
175 #ifndef va_copy
176 # ifdef __va_copy
177 # define va_copy(ap1, ap2) __va_copy((ap1), (ap2))
178 # else
179 # define va_copy(ap1, ap2) memcpy((&ap1), (&ap2), sizeof(va_list))
180 # endif
181 #endif
182
183 #include "zend_hash.h"
184 #include "zend_alloc.h"
185 #include "zend_stack.h"
186
187 #if STDC_HEADERS
188 # include <string.h>
189 #else
190 # ifndef HAVE_MEMCPY
191 # define memcpy(d, s, n) bcopy((s), (d), (n))
192 # endif
193 # ifndef HAVE_MEMMOVE
194 # define memmove(d, s, n) bcopy ((s), (d), (n))
195 # endif
196 #endif
197
198 #ifndef HAVE_STRERROR
199 char *strerror(int);
200 #endif
201
202 #if HAVE_PWD_H
203 # ifdef PHP_WIN32
204 #include "win32/param.h"
205 # else
206 #include <pwd.h>
207 #include <sys/param.h>
208 # endif
209 #endif
210
211 #if HAVE_LIMITS_H
212 #include <limits.h>
213 #endif
214
215 #ifndef LONG_MAX
216 #define LONG_MAX 2147483647L
217 #endif
218
219 #ifndef LONG_MIN
220 #define LONG_MIN (- LONG_MAX - 1)
221 #endif
222
223 #ifndef INT_MAX
224 #define INT_MAX 2147483647
225 #endif
226
227 #ifndef INT_MIN
228 #define INT_MIN (- INT_MAX - 1)
229 #endif
230
231 #define PHP_GCC_VERSION ZEND_GCC_VERSION
232 #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
233 #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
234
235 BEGIN_EXTERN_C()
236 #include "snprintf.h"
237 END_EXTERN_C()
238 #include "spprintf.h"
239
240 #define EXEC_INPUT_BUF 4096
241
242 #define PHP_MIME_TYPE "application/x-httpd-php"
243
244 /* macros */
245 #define STR_PRINT(str) ((str)?(str):"")
246
247 #ifndef MAXPATHLEN
248 # ifdef PATH_MAX
249 # define MAXPATHLEN PATH_MAX
250 # elif defined(MAX_PATH)
251 # define MAXPATHLEN MAX_PATH
252 # else
253 # define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */
254 # endif
255 #endif
256
257 #if defined(__GNUC__) && __GNUC__ >= 4
258 # define php_ignore_value(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
259 #else
260 # define php_ignore_value(x) ((void) (x))
261 #endif
262
263 /* global variables */
264 #if !defined(PHP_WIN32)
265 #define PHP_SLEEP_NON_VOID
266 #define php_sleep sleep
267 extern char **environ;
268 #endif /* !defined(PHP_WIN32) */
269
270 #ifdef PHP_PWRITE_64
271 ssize_t pwrite(int, void *, size_t, off64_t);
272 #endif
273
274 #ifdef PHP_PREAD_64
275 ssize_t pread(int, void *, size_t, off64_t);
276 #endif
277
278 BEGIN_EXTERN_C()
279 void phperror(char *error);
280 PHPAPI int php_write(void *buf, uint size TSRMLS_DC);
281 PHPAPI int php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1,
282 2);
283 PHPAPI int php_get_module_initialized(void);
284 PHPAPI void php_log_err(char *log_message TSRMLS_DC);
285 int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
286 int cfgparse(void);
287 END_EXTERN_C()
288
289 #define php_error zend_error
290 #define error_handling_t zend_error_handling_t
291
BEGIN_EXTERN_C()292 BEGIN_EXTERN_C()
293 static inline ZEND_ATTRIBUTE_DEPRECATED void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
294 {
295 zend_replace_error_handling(error_handling, exception_class, NULL TSRMLS_CC);
296 }
php_std_error_handling()297 static inline ZEND_ATTRIBUTE_DEPRECATED void php_std_error_handling() {}
298
299 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);
300
301 #ifdef ZTS
302 #define PHP_ATTR_FMT_OFFSET 1
303 #else
304 #define PHP_ATTR_FMT_OFFSET 0
305 #endif
306
307 /* PHPAPI void php_error(int type, const char *format, ...); */
308 PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
309 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 3, PHP_ATTR_FMT_OFFSET + 4);
310 PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
311 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 4, PHP_ATTR_FMT_OFFSET + 5);
312 PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
313 PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 5, PHP_ATTR_FMT_OFFSET + 6);
314 #ifdef PHP_WIN32
315 PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC);
316 #endif
317 END_EXTERN_C()
318
319 #define php_error_docref php_error_docref0
320
321 #define zenderror phperror
322 #define zendlex phplex
323
324 #define phpparse zendparse
325 #define phprestart zendrestart
326 #define phpin zendin
327
328 #define php_memnstr zend_memnstr
329
330 /* functions */
331 BEGIN_EXTERN_C()
332 PHPAPI extern int (*php_register_internal_extensions_func)(TSRMLS_D);
333 PHPAPI int php_register_internal_extensions(TSRMLS_D);
334 PHPAPI int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC);
335 PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
336 PHPAPI void php_com_initialize(TSRMLS_D);
337 PHPAPI char *php_get_current_user(TSRMLS_D);
338 END_EXTERN_C()
339
340 /* PHP-named Zend macro wrappers */
341 #define PHP_FN ZEND_FN
342 #define PHP_MN ZEND_MN
343 #define PHP_NAMED_FUNCTION ZEND_NAMED_FUNCTION
344 #define PHP_FUNCTION ZEND_FUNCTION
345 #define PHP_METHOD ZEND_METHOD
346
347 #define PHP_RAW_NAMED_FE ZEND_RAW_NAMED_FE
348 #define PHP_NAMED_FE ZEND_NAMED_FE
349 #define PHP_FE ZEND_FE
350 #define PHP_DEP_FE ZEND_DEP_FE
351 #define PHP_FALIAS ZEND_FALIAS
352 #define PHP_DEP_FALIAS ZEND_DEP_FALIAS
353 #define PHP_ME ZEND_ME
354 #define PHP_MALIAS ZEND_MALIAS
355 #define PHP_ABSTRACT_ME ZEND_ABSTRACT_ME
356 #define PHP_ME_MAPPING ZEND_ME_MAPPING
357 #define PHP_FE_END ZEND_FE_END
358
359 #define PHP_MODULE_STARTUP_N ZEND_MODULE_STARTUP_N
360 #define PHP_MODULE_SHUTDOWN_N ZEND_MODULE_SHUTDOWN_N
361 #define PHP_MODULE_ACTIVATE_N ZEND_MODULE_ACTIVATE_N
362 #define PHP_MODULE_DEACTIVATE_N ZEND_MODULE_DEACTIVATE_N
363 #define PHP_MODULE_INFO_N ZEND_MODULE_INFO_N
364
365 #define PHP_MODULE_STARTUP_D ZEND_MODULE_STARTUP_D
366 #define PHP_MODULE_SHUTDOWN_D ZEND_MODULE_SHUTDOWN_D
367 #define PHP_MODULE_ACTIVATE_D ZEND_MODULE_ACTIVATE_D
368 #define PHP_MODULE_DEACTIVATE_D ZEND_MODULE_DEACTIVATE_D
369 #define PHP_MODULE_INFO_D ZEND_MODULE_INFO_D
370
371 /* Compatibility macros */
372 #define PHP_MINIT ZEND_MODULE_STARTUP_N
373 #define PHP_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N
374 #define PHP_RINIT ZEND_MODULE_ACTIVATE_N
375 #define PHP_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N
376 #define PHP_MINFO ZEND_MODULE_INFO_N
377 #define PHP_GINIT ZEND_GINIT
378 #define PHP_GSHUTDOWN ZEND_GSHUTDOWN
379
380 #define PHP_MINIT_FUNCTION ZEND_MODULE_STARTUP_D
381 #define PHP_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D
382 #define PHP_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D
383 #define PHP_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D
384 #define PHP_MINFO_FUNCTION ZEND_MODULE_INFO_D
385 #define PHP_GINIT_FUNCTION ZEND_GINIT_FUNCTION
386 #define PHP_GSHUTDOWN_FUNCTION ZEND_GSHUTDOWN_FUNCTION
387
388 #define PHP_MODULE_GLOBALS ZEND_MODULE_GLOBALS
389
390
391 /* Output support */
392 #include "main/php_output.h"
393
394
395 #include "php_streams.h"
396 #include "php_memory_streams.h"
397 #include "fopen_wrappers.h"
398
399
400 /* Virtual current working directory support */
401 #include "tsrm_virtual_cwd.h"
402
403 #include "zend_constants.h"
404
405 /* connection status states */
406 #define PHP_CONNECTION_NORMAL 0
407 #define PHP_CONNECTION_ABORTED 1
408 #define PHP_CONNECTION_TIMEOUT 2
409
410 #include "php_reentrancy.h"
411
412 /* Finding offsets of elements within structures.
413 * Taken from the Apache code, which in turn, was taken from X code...
414 */
415
416 #ifndef XtOffset
417 #if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__riscos__)))
418 #ifdef __STDC__
419 #define XtOffset(p_type, field) _Offsetof(p_type, field)
420 #else
421 #ifdef CRAY2
422 #define XtOffset(p_type, field) \
423 (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
424
425 #else /* !CRAY2 */
426
427 #define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
428
429 #endif /* !CRAY2 */
430 #endif /* __STDC__ */
431 #else /* ! (CRAY || __arm) */
432
433 #define XtOffset(p_type, field) \
434 ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
435
436 #endif /* !CRAY */
437 #endif /* ! XtOffset */
438
439 #ifndef XtOffsetOf
440 #ifdef offsetof
441 #define XtOffsetOf(s_type, field) offsetof(s_type, field)
442 #else
443 #define XtOffsetOf(s_type, field) XtOffset(s_type*, field)
444 #endif
445 #endif /* !XtOffsetOf */
446
447 #endif
448
449 /*
450 * Local variables:
451 * tab-width: 4
452 * c-basic-offset: 4
453 * End:
454 * vim600: sw=4 ts=4 fdm=marker
455 * vim<600: sw=4 ts=4
456 */
457