php.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Andi Gutmans <andi@php.net> |
  14. | Zeev Suraski <zeev@php.net> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef PHP_H
  18. #define PHP_H
  19. #ifdef HAVE_DMALLOC
  20. #include <dmalloc.h>
  21. #endif
  22. #define PHP_API_VERSION 20210902
  23. #define PHP_HAVE_STREAMS
  24. #define YYDEBUG 0
  25. #define PHP_DEFAULT_CHARSET "UTF-8"
  26. #include "php_version.h"
  27. #include "zend.h"
  28. #include "zend_sort.h"
  29. #include "php_compat.h"
  30. #include "zend_API.h"
  31. #define php_sprintf sprintf
  32. /* Operating system family definition */
  33. #ifdef PHP_WIN32
  34. # define PHP_OS_FAMILY "Windows"
  35. #elif defined(BSD) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
  36. # define PHP_OS_FAMILY "BSD"
  37. #elif defined(__APPLE__) || defined(__MACH__)
  38. # define PHP_OS_FAMILY "Darwin"
  39. #elif defined(__sun__)
  40. # define PHP_OS_FAMILY "Solaris"
  41. #elif defined(__linux__)
  42. # define PHP_OS_FAMILY "Linux"
  43. #else
  44. # define PHP_OS_FAMILY "Unknown"
  45. #endif
  46. /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */
  47. #undef PHP_DEBUG
  48. #define PHP_DEBUG ZEND_DEBUG
  49. #ifdef PHP_WIN32
  50. # include "tsrm_win32.h"
  51. # ifdef PHP_EXPORTS
  52. # define PHPAPI __declspec(dllexport)
  53. # else
  54. # define PHPAPI __declspec(dllimport)
  55. # endif
  56. # define PHP_DIR_SEPARATOR '\\'
  57. # define PHP_EOL "\r\n"
  58. #else
  59. # if defined(__GNUC__) && __GNUC__ >= 4
  60. # define PHPAPI __attribute__ ((visibility("default")))
  61. # else
  62. # define PHPAPI
  63. # endif
  64. # define PHP_DIR_SEPARATOR '/'
  65. # define PHP_EOL "\n"
  66. #endif
  67. /* Windows specific defines */
  68. #ifdef PHP_WIN32
  69. # define PHP_PROG_SENDMAIL "Built in mailer"
  70. # define WIN32_LEAN_AND_MEAN
  71. # define NOOPENFILE
  72. # include <io.h>
  73. # include <malloc.h>
  74. # include <direct.h>
  75. # include <stdlib.h>
  76. # include <stdio.h>
  77. # include <stdarg.h>
  78. # include <sys/types.h>
  79. # include <process.h>
  80. typedef int uid_t;
  81. typedef int gid_t;
  82. typedef char * caddr_t;
  83. typedef int pid_t;
  84. # define M_TWOPI (M_PI * 2.0)
  85. # define off_t _off_t
  86. # define lstat(x, y) php_sys_lstat(x, y)
  87. # define chdir(path) _chdir(path)
  88. # define mkdir(a, b) _mkdir(a)
  89. # define rmdir(a) _rmdir(a)
  90. # define getpid _getpid
  91. # define php_sleep(t) SleepEx(t*1000, TRUE)
  92. # ifndef getcwd
  93. # define getcwd(a, b) _getcwd(a, b)
  94. # endif
  95. #endif
  96. #if PHP_DEBUG
  97. #undef NDEBUG
  98. #else
  99. #ifndef NDEBUG
  100. #define NDEBUG
  101. #endif
  102. #endif
  103. #include <assert.h>
  104. #ifdef HAVE_UNIX_H
  105. #include <unix.h>
  106. #endif
  107. #if HAVE_ALLOCA_H
  108. #include <alloca.h>
  109. #endif
  110. #if HAVE_BUILD_DEFS_H
  111. #include <build-defs.h>
  112. #endif
  113. /*
  114. * This is a fast version of strlcpy which should be used, if you
  115. * know the size of the destination buffer and if you know
  116. * the length of the source string.
  117. *
  118. * size is the allocated number of bytes of dst
  119. * src_size is the number of bytes excluding the NUL of src
  120. */
  121. #define PHP_STRLCPY(dst, src, size, src_size) \
  122. { \
  123. size_t php_str_len; \
  124. \
  125. if (src_size >= size) \
  126. php_str_len = size - 1; \
  127. else \
  128. php_str_len = src_size; \
  129. memcpy(dst, src, php_str_len); \
  130. dst[php_str_len] = '\0'; \
  131. }
  132. #ifndef HAVE_STRLCPY
  133. BEGIN_EXTERN_C()
  134. PHPAPI size_t php_strlcpy(char *dst, const char *src, size_t siz);
  135. END_EXTERN_C()
  136. #undef strlcpy
  137. #define strlcpy php_strlcpy
  138. #define HAVE_STRLCPY 1
  139. #define USE_STRLCPY_PHP_IMPL 1
  140. #endif
  141. #ifndef HAVE_STRLCAT
  142. BEGIN_EXTERN_C()
  143. PHPAPI size_t php_strlcat(char *dst, const char *src, size_t siz);
  144. END_EXTERN_C()
  145. #undef strlcat
  146. #define strlcat php_strlcat
  147. #define HAVE_STRLCAT 1
  148. #define USE_STRLCAT_PHP_IMPL 1
  149. #endif
  150. #ifndef HAVE_EXPLICIT_BZERO
  151. BEGIN_EXTERN_C()
  152. PHPAPI void php_explicit_bzero(void *dst, size_t siz);
  153. END_EXTERN_C()
  154. #undef explicit_bzero
  155. #define explicit_bzero php_explicit_bzero
  156. #endif
  157. #ifndef HAVE_STRTOK_R
  158. BEGIN_EXTERN_C()
  159. char *strtok_r(char *s, const char *delim, char **last);
  160. END_EXTERN_C()
  161. #endif
  162. #ifndef HAVE_SOCKLEN_T
  163. # ifdef PHP_WIN32
  164. typedef int socklen_t;
  165. # else
  166. typedef unsigned int socklen_t;
  167. # endif
  168. #endif
  169. #define CREATE_MUTEX(a, b)
  170. #define SET_MUTEX(a)
  171. #define FREE_MUTEX(a)
  172. /*
  173. * Then the ODBC support can use both iodbc and Solid,
  174. * uncomment this.
  175. * #define HAVE_ODBC (HAVE_IODBC|HAVE_SOLID)
  176. */
  177. #include <stdlib.h>
  178. #include <ctype.h>
  179. #if HAVE_UNISTD_H
  180. #include <unistd.h>
  181. #endif
  182. #include <stdarg.h>
  183. #include "php_stdint.h"
  184. #include "zend_hash.h"
  185. #include "zend_alloc.h"
  186. #include "zend_stack.h"
  187. #include <string.h>
  188. #if HAVE_PWD_H
  189. # ifdef PHP_WIN32
  190. #include "win32/param.h"
  191. # else
  192. #include <pwd.h>
  193. #include <sys/param.h>
  194. # endif
  195. #endif
  196. #include <limits.h>
  197. #ifndef LONG_MAX
  198. #define LONG_MAX 2147483647L
  199. #endif
  200. #ifndef LONG_MIN
  201. #define LONG_MIN (- LONG_MAX - 1)
  202. #endif
  203. #ifndef INT_MAX
  204. #define INT_MAX 2147483647
  205. #endif
  206. #ifndef INT_MIN
  207. #define INT_MIN (- INT_MAX - 1)
  208. #endif
  209. #define PHP_DOUBLE_MAX_LENGTH ZEND_DOUBLE_MAX_LENGTH
  210. #define PHP_GCC_VERSION ZEND_GCC_VERSION
  211. #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
  212. #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
  213. BEGIN_EXTERN_C()
  214. #include "snprintf.h"
  215. END_EXTERN_C()
  216. #include "spprintf.h"
  217. #define EXEC_INPUT_BUF 4096
  218. #define PHP_MIME_TYPE "application/x-httpd-php"
  219. /* macros */
  220. #define STR_PRINT(str) ((str)?(str):"")
  221. #ifndef MAXPATHLEN
  222. # ifdef PHP_WIN32
  223. # include "win32/ioutil.h"
  224. # define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
  225. # elif PATH_MAX
  226. # define MAXPATHLEN PATH_MAX
  227. # elif defined(MAX_PATH)
  228. # define MAXPATHLEN MAX_PATH
  229. # else
  230. # define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */
  231. # endif
  232. #endif
  233. #define php_ignore_value(x) ZEND_IGNORE_VALUE(x)
  234. /* global variables */
  235. #ifndef PHP_WIN32
  236. #define php_sleep sleep
  237. extern char **environ;
  238. #endif /* ifndef PHP_WIN32 */
  239. #ifdef PHP_PWRITE_64
  240. ssize_t pwrite(int, void *, size_t, off64_t);
  241. #endif
  242. #ifdef PHP_PREAD_64
  243. ssize_t pread(int, void *, size_t, off64_t);
  244. #endif
  245. BEGIN_EXTERN_C()
  246. void phperror(char *error);
  247. PHPAPI size_t php_write(void *buf, size_t size);
  248. PHPAPI size_t php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
  249. PHPAPI size_t php_printf_unchecked(const char *format, ...);
  250. PHPAPI int php_during_module_startup(void);
  251. PHPAPI int php_during_module_shutdown(void);
  252. PHPAPI int php_get_module_initialized(void);
  253. #ifdef HAVE_SYSLOG_H
  254. #include "php_syslog.h"
  255. #define php_log_err(msg) php_log_err_with_severity(msg, LOG_NOTICE)
  256. #else
  257. #define php_log_err(msg) php_log_err_with_severity(msg, 5)
  258. #endif
  259. PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int syslog_type_int);
  260. int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
  261. int cfgparse(void);
  262. END_EXTERN_C()
  263. #define php_error zend_error
  264. #define error_handling_t zend_error_handling_t
  265. BEGIN_EXTERN_C()
  266. static inline ZEND_ATTRIBUTE_DEPRECATED void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class)
  267. {
  268. zend_replace_error_handling(error_handling, exception_class, NULL);
  269. }
  270. static inline ZEND_ATTRIBUTE_DEPRECATED void php_std_error_handling(void) {}
  271. PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args) PHP_ATTRIBUTE_FORMAT(printf, 4, 0);
  272. /* PHPAPI void php_error(int type, const char *format, ...); */
  273. PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format, ...)
  274. PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
  275. PHPAPI ZEND_COLD void php_error_docref1(const char *docref, const char *param1, int type, const char *format, ...)
  276. PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
  277. PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
  278. PHP_ATTRIBUTE_FORMAT(printf, 5, 6);
  279. #ifdef PHP_WIN32
  280. PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1);
  281. PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2);
  282. #endif
  283. END_EXTERN_C()
  284. #define zenderror phperror
  285. #define zendlex phplex
  286. #define phpparse zendparse
  287. #define phprestart zendrestart
  288. #define phpin zendin
  289. #define php_memnstr zend_memnstr
  290. /* functions */
  291. BEGIN_EXTERN_C()
  292. PHPAPI extern int (*php_register_internal_extensions_func)(void);
  293. PHPAPI int php_register_internal_extensions(void);
  294. PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
  295. PHPAPI void php_com_initialize(void);
  296. PHPAPI char *php_get_current_user(void);
  297. PHPAPI const char *php_get_internal_encoding(void);
  298. PHPAPI const char *php_get_input_encoding(void);
  299. PHPAPI const char *php_get_output_encoding(void);
  300. PHPAPI extern void (*php_internal_encoding_changed)(void);
  301. END_EXTERN_C()
  302. /* PHP-named Zend macro wrappers */
  303. #define PHP_FN ZEND_FN
  304. #define PHP_MN ZEND_MN
  305. #define PHP_NAMED_FUNCTION ZEND_NAMED_FUNCTION
  306. #define PHP_FUNCTION ZEND_FUNCTION
  307. #define PHP_METHOD ZEND_METHOD
  308. #define PHP_RAW_NAMED_FE ZEND_RAW_NAMED_FE
  309. #define PHP_NAMED_FE ZEND_NAMED_FE
  310. #define PHP_FE ZEND_FE
  311. #define PHP_DEP_FE ZEND_DEP_FE
  312. #define PHP_FALIAS ZEND_FALIAS
  313. #define PHP_DEP_FALIAS ZEND_DEP_FALIAS
  314. #define PHP_ME ZEND_ME
  315. #define PHP_MALIAS ZEND_MALIAS
  316. #define PHP_ABSTRACT_ME ZEND_ABSTRACT_ME
  317. #define PHP_ME_MAPPING ZEND_ME_MAPPING
  318. #define PHP_FE_END ZEND_FE_END
  319. #define PHP_MODULE_STARTUP_N ZEND_MODULE_STARTUP_N
  320. #define PHP_MODULE_SHUTDOWN_N ZEND_MODULE_SHUTDOWN_N
  321. #define PHP_MODULE_ACTIVATE_N ZEND_MODULE_ACTIVATE_N
  322. #define PHP_MODULE_DEACTIVATE_N ZEND_MODULE_DEACTIVATE_N
  323. #define PHP_MODULE_INFO_N ZEND_MODULE_INFO_N
  324. #define PHP_MODULE_STARTUP_D ZEND_MODULE_STARTUP_D
  325. #define PHP_MODULE_SHUTDOWN_D ZEND_MODULE_SHUTDOWN_D
  326. #define PHP_MODULE_ACTIVATE_D ZEND_MODULE_ACTIVATE_D
  327. #define PHP_MODULE_DEACTIVATE_D ZEND_MODULE_DEACTIVATE_D
  328. #define PHP_MODULE_INFO_D ZEND_MODULE_INFO_D
  329. /* Compatibility macros */
  330. #define PHP_MINIT ZEND_MODULE_STARTUP_N
  331. #define PHP_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N
  332. #define PHP_RINIT ZEND_MODULE_ACTIVATE_N
  333. #define PHP_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N
  334. #define PHP_MINFO ZEND_MODULE_INFO_N
  335. #define PHP_GINIT ZEND_GINIT
  336. #define PHP_GSHUTDOWN ZEND_GSHUTDOWN
  337. #define PHP_MINIT_FUNCTION ZEND_MODULE_STARTUP_D
  338. #define PHP_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D
  339. #define PHP_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D
  340. #define PHP_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D
  341. #define PHP_MINFO_FUNCTION ZEND_MODULE_INFO_D
  342. #define PHP_GINIT_FUNCTION ZEND_GINIT_FUNCTION
  343. #define PHP_GSHUTDOWN_FUNCTION ZEND_GSHUTDOWN_FUNCTION
  344. #define PHP_MODULE_GLOBALS ZEND_MODULE_GLOBALS
  345. /* Output support */
  346. #include "main/php_output.h"
  347. #include "php_streams.h"
  348. #include "php_memory_streams.h"
  349. #include "fopen_wrappers.h"
  350. /* Virtual current working directory support */
  351. #include "zend_virtual_cwd.h"
  352. #include "zend_constants.h"
  353. /* connection status states */
  354. #define PHP_CONNECTION_NORMAL 0
  355. #define PHP_CONNECTION_ABORTED 1
  356. #define PHP_CONNECTION_TIMEOUT 2
  357. #include "php_reentrancy.h"
  358. #endif