/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 | | typedef struct php_json_error_details { |
56 | | php_json_error_code code; |
57 | | uint64_t line; |
58 | | uint64_t column; |
59 | | } php_json_error_details; |
60 | | |
61 | 300k | static inline void php_json_error_details_clear(php_json_error_details *out) { |
62 | 300k | out->code = PHP_JSON_ERROR_NONE; |
63 | 300k | out->line = 0; |
64 | 300k | out->column = 0; |
65 | 300k | } Unexecuted instantiation: json_encoder.c:php_json_error_details_clear Unexecuted instantiation: json_parser.tab.c:php_json_error_details_clear Unexecuted instantiation: json_scanner.c:php_json_error_details_clear json.c:php_json_error_details_clear Line | Count | Source | 61 | 300k | static inline void php_json_error_details_clear(php_json_error_details *out) { | 62 | 300k | out->code = PHP_JSON_ERROR_NONE; | 63 | 300k | out->line = 0; | 64 | 300k | out->column = 0; | 65 | 300k | } |
Unexecuted instantiation: spl_fixedarray.c:php_json_error_details_clear Unexecuted instantiation: internal_functions_cli.c:php_json_error_details_clear Unexecuted instantiation: fuzzer-json.c:php_json_error_details_clear |
66 | | |
67 | | /* json_decode() options */ |
68 | 3.33M | #define PHP_JSON_OBJECT_AS_ARRAY (1<<0) |
69 | 2.23k | #define PHP_JSON_BIGINT_AS_STRING (1<<1) |
70 | | |
71 | | /* json_encode() options */ |
72 | 15.7k | #define PHP_JSON_HEX_TAG (1<<0) |
73 | 65 | #define PHP_JSON_HEX_AMP (1<<1) |
74 | 6 | #define PHP_JSON_HEX_APOS (1<<2) |
75 | 469 | #define PHP_JSON_HEX_QUOT (1<<3) |
76 | 392 | #define PHP_JSON_FORCE_OBJECT (1<<4) |
77 | 2.12k | #define PHP_JSON_NUMERIC_CHECK (1<<5) |
78 | 189 | #define PHP_JSON_UNESCAPED_SLASHES (1<<6) |
79 | 5.05k | #define PHP_JSON_PRETTY_PRINT (1<<7) |
80 | 186 | #define PHP_JSON_UNESCAPED_UNICODE (1<<8) |
81 | 263 | #define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9) |
82 | 382 | #define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10) |
83 | 186 | #define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11) |
84 | | |
85 | | /* json_validate(), json_decode() and json_encode() common options */ |
86 | 22.1k | #define PHP_JSON_INVALID_UTF8_IGNORE (1<<20) |
87 | | |
88 | | /* json_decode() and json_encode() common options */ |
89 | 489 | #define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21) |
90 | 3.26k | #define PHP_JSON_THROW_ON_ERROR (1<<22) |
91 | | |
92 | | /* default depth */ |
93 | 3.28k | #define PHP_JSON_PARSER_DEFAULT_DEPTH 512 |
94 | | |
95 | | ZEND_BEGIN_MODULE_GLOBALS(json) |
96 | | int encoder_depth; |
97 | | int encode_max_depth; |
98 | | php_json_error_details error_details; |
99 | | ZEND_END_MODULE_GLOBALS(json) |
100 | | |
101 | | PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json) |
102 | 304k | #define JSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(json, v) |
103 | | |
104 | | #if defined(ZTS) && defined(COMPILE_DL_JSON) |
105 | | ZEND_TSRMLS_CACHE_EXTERN() |
106 | | #endif |
107 | | |
108 | | PHP_JSON_API zend_string *php_json_encode_string(const char *s, size_t len, int options); |
109 | | |
110 | | PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth); |
111 | | PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options); |
112 | | 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); |
113 | | PHP_JSON_API bool php_json_validate_ex(const char *str, size_t str_len, zend_long options, zend_long depth); |
114 | | |
115 | | static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth) |
116 | 0 | { |
117 | 0 | return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth); |
118 | 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 Unexecuted instantiation: fuzzer-json.c:php_json_decode |
119 | | |
120 | | #endif /* PHP_JSON_H */ |