/src/php-src/ext/json/php_json.h
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright © The PHP Group and Contributors. | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to the Modified BSD License that is | |
6 | | | bundled with this package in the file LICENSE, and is available | |
7 | | | through the World Wide Web at <https://www.php.net/license/>. | |
8 | | | | |
9 | | | SPDX-License-Identifier: BSD-3-Clause | |
10 | | +----------------------------------------------------------------------+ |
11 | | | Author: Omar Kilani <omar@php.net> | |
12 | | | Jakub Zelenka <bukka@php.net> | |
13 | | +----------------------------------------------------------------------+ |
14 | | */ |
15 | | |
16 | | #ifndef PHP_JSON_H |
17 | | #define PHP_JSON_H |
18 | | |
19 | | #include "php_version.h" |
20 | | #include "zend_smart_str_public.h" |
21 | | |
22 | | #define PHP_JSON_VERSION PHP_VERSION |
23 | | |
24 | | extern zend_module_entry json_module_entry; |
25 | | #define phpext_json_ptr &json_module_entry |
26 | | |
27 | | #if defined(PHP_WIN32) && defined(JSON_EXPORTS) |
28 | | #define PHP_JSON_API __declspec(dllexport) |
29 | | #else |
30 | | #define PHP_JSON_API PHPAPI |
31 | | #endif |
32 | | |
33 | | #ifdef ZTS |
34 | | #include "TSRM.h" |
35 | | #endif |
36 | | |
37 | | extern PHP_JSON_API zend_class_entry *php_json_serializable_ce; |
38 | | |
39 | | /* error codes */ |
40 | | typedef enum { |
41 | | PHP_JSON_ERROR_NONE = 0, |
42 | | PHP_JSON_ERROR_DEPTH, |
43 | | PHP_JSON_ERROR_STATE_MISMATCH, |
44 | | PHP_JSON_ERROR_CTRL_CHAR, |
45 | | PHP_JSON_ERROR_SYNTAX, |
46 | | PHP_JSON_ERROR_UTF8, |
47 | | PHP_JSON_ERROR_RECURSION, |
48 | | PHP_JSON_ERROR_INF_OR_NAN, |
49 | | PHP_JSON_ERROR_UNSUPPORTED_TYPE, |
50 | | PHP_JSON_ERROR_INVALID_PROPERTY_NAME, |
51 | | PHP_JSON_ERROR_UTF16, |
52 | | PHP_JSON_ERROR_NON_BACKED_ENUM, |
53 | | } php_json_error_code; |
54 | | |
55 | | /* json_decode() options */ |
56 | 18 | #define PHP_JSON_OBJECT_AS_ARRAY (1<<0) |
57 | 0 | #define PHP_JSON_BIGINT_AS_STRING (1<<1) |
58 | | |
59 | | /* json_encode() options */ |
60 | 0 | #define PHP_JSON_HEX_TAG (1<<0) |
61 | 0 | #define PHP_JSON_HEX_AMP (1<<1) |
62 | 0 | #define PHP_JSON_HEX_APOS (1<<2) |
63 | 3 | #define PHP_JSON_HEX_QUOT (1<<3) |
64 | 189 | #define PHP_JSON_FORCE_OBJECT (1<<4) |
65 | 974 | #define PHP_JSON_NUMERIC_CHECK (1<<5) |
66 | 0 | #define PHP_JSON_UNESCAPED_SLASHES (1<<6) |
67 | 1.82k | #define PHP_JSON_PRETTY_PRINT (1<<7) |
68 | 0 | #define PHP_JSON_UNESCAPED_UNICODE (1<<8) |
69 | 65 | #define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9) |
70 | 136 | #define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10) |
71 | 0 | #define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11) |
72 | | |
73 | | /* json_validate(), json_decode() and json_encode() common options */ |
74 | 13 | #define PHP_JSON_INVALID_UTF8_IGNORE (1<<20) |
75 | | |
76 | | /* json_decode() and json_encode() common options */ |
77 | 13 | #define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21) |
78 | 1.10k | #define PHP_JSON_THROW_ON_ERROR (1<<22) |
79 | | |
80 | | /* default depth */ |
81 | 1.10k | #define PHP_JSON_PARSER_DEFAULT_DEPTH 512 |
82 | | |
83 | | ZEND_BEGIN_MODULE_GLOBALS(json) |
84 | | int encoder_depth; |
85 | | int encode_max_depth; |
86 | | php_json_error_code error_code; |
87 | | size_t error_line; |
88 | | size_t error_column; |
89 | | ZEND_END_MODULE_GLOBALS(json) |
90 | | |
91 | | PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json) |
92 | 134k | #define JSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(json, v) |
93 | | |
94 | | #if defined(ZTS) && defined(COMPILE_DL_JSON) |
95 | | ZEND_TSRMLS_CACHE_EXTERN() |
96 | | #endif |
97 | | |
98 | | PHP_JSON_API zend_string *php_json_encode_string(const char *s, size_t len, int options); |
99 | | |
100 | | PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth); |
101 | | PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options); |
102 | | PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth); |
103 | | PHP_JSON_API bool php_json_validate_ex(const char *str, size_t str_len, zend_long options, zend_long depth); |
104 | | |
105 | | static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth) |
106 | 0 | { |
107 | 0 | return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth); |
108 | 0 | } Unexecuted instantiation: json_encoder.c:php_json_decode Unexecuted instantiation: json_parser.tab.c:php_json_decode Unexecuted instantiation: json_scanner.c:php_json_decode Unexecuted instantiation: json.c:php_json_decode Unexecuted instantiation: spl_fixedarray.c:php_json_decode Unexecuted instantiation: internal_functions_cli.c:php_json_decode |
109 | | |
110 | | #endif /* PHP_JSON_H */ |