-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathphp_jsond.h
176 lines (146 loc) · 5.47 KB
/
php_jsond.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jakub Zelenka <bukka@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef PHP_JSOND_H
#define PHP_JSOND_H
#define PHP_JSOND_VERSION "1.5.0-dev"
extern zend_module_entry jsond_module_entry;
#define phpext_jsond_ptr &jsond_module_entry
#if defined(PHP_WIN32) && defined(JSOND_EXPORTS)
#define PHP_JSOND_API __declspec(dllexport)
#else
#define PHP_JSOND_API PHPAPI
#endif
#include "php.h"
#ifdef ZTS
#include "TSRM.h"
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef PHP_JSOND_WITH_JSON_PREFIX
#define PHP_JSOND_PREFIX json
#define PHP_JSOND_PREFIX_STRING "json"
#define PHP_JSOND_CONSTANT "JSON"
#define PHP_JSOND_SERIALIZABLE_INTERFACE JsonSerializable
#define PHP_JSOND_SERIALIZABLE_INTERFACE_STRING "JsonSerializable"
#define PHP_JSOND_SERIALIZABLE_INTERFACE_STRING_LC "jsonserializable"
#define PHP_JSOND_NAME(name) php_json_ ## name
#define PHP_JSOND_IDENT(name) json_ ## name
#define PHP_JSOND_FN(jname) ZEND_FN(json_ ## jname)
#else
#define PHP_JSOND_PREFIX jsond
#define PHP_JSOND_PREFIX_STRING "jsond"
#define PHP_JSOND_CONSTANT "JSOND"
#define PHP_JSOND_SERIALIZABLE_INTERFACE JsondSerializable
#define PHP_JSOND_SERIALIZABLE_INTERFACE_STRING "JsondSerializable"
#define PHP_JSOND_SERIALIZABLE_INTERFACE_STRING_LC "jsondserializable"
#define PHP_JSOND_NAME(jname) php_jsond_ ## jname
#define PHP_JSOND_IDENT(jname) jsond_ ## jname
#define PHP_JSOND_FN(jname) ZEND_FN(jsond_ ## jname)
#endif
#define PHP_JSOND_FUNCTION(jname) PHP_FUNCTION(PHP_JSOND_IDENT(jname))
#define PHP_JSOND_FE(jname, arginfo) PHP_FE(PHP_JSOND_IDENT(jname), arginfo)
#ifndef HASH_KEY_NON_EXISTENT
#define HASH_KEY_NON_EXISTENT HASH_KEY_NON_EXISTANT
#endif
#ifndef INIT_PZVAL_COPY
#define INIT_PZVAL_COPY(z, v) \
do { \
(z)->value = (v)->value; \
Z_TYPE_P(z) = Z_TYPE_P(v); \
INIT_PZVAL(z) \
} while (0)
#endif
/* This is important for the inline functions in debug mode as well
* which is not done zend_always_inline. Such function are not inlined in
* GCC 5 which results in a linking error */
#if defined(__GNUC__) && __GNUC__ >= 3
#define php_json_always_inline inline __attribute__((always_inline))
#else
#define php_json_always_inline inline
#endif
/* long limits */
#if SIZEOF_LONG == 4
#define PHP_JSON_INT_MAX_LENGTH 10
#define PHP_JSON_INT_MAX_DIGITS "2147483648"
#elif SIZEOF_LONG == 8
#define PHP_JSON_INT_MAX_LENGTH 19
#define PHP_JSON_INT_MAX_DIGITS "9223372036854775808"
#else
#error "Unknown SIZEOF_LONG"
#endif
typedef enum {
PHP_JSON_ERROR_NONE = 0,
PHP_JSON_ERROR_DEPTH,
PHP_JSON_ERROR_STATE_MISMATCH,
PHP_JSON_ERROR_CTRL_CHAR,
PHP_JSON_ERROR_SYNTAX,
PHP_JSON_ERROR_UTF8,
PHP_JSON_ERROR_RECURSION,
PHP_JSON_ERROR_INF_OR_NAN,
PHP_JSON_ERROR_UNSUPPORTED_TYPE,
PHP_JSON_ERROR_INVALID_PROPERTY_NAME,
PHP_JSON_ERROR_UTF16
} php_json_error_code;
/* json_encode() options */
#define PHP_JSON_HEX_TAG (1<<0)
#define PHP_JSON_HEX_AMP (1<<1)
#define PHP_JSON_HEX_APOS (1<<2)
#define PHP_JSON_HEX_QUOT (1<<3)
#define PHP_JSON_FORCE_OBJECT (1<<4)
#define PHP_JSON_NUMERIC_CHECK (1<<5)
#define PHP_JSON_UNESCAPED_SLASHES (1<<6)
#define PHP_JSON_PRETTY_PRINT (1<<7)
#define PHP_JSON_UNESCAPED_UNICODE (1<<8)
#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9)
#define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10)
#define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11)
/* Internal flags */
#define PHP_JSON_OUTPUT_ARRAY 0
#define PHP_JSON_OUTPUT_OBJECT 1
/* json_decode() options */
#define PHP_JSON_OBJECT_AS_ARRAY (1<<0)
#define PHP_JSON_BIGINT_AS_STRING (1<<1)
/* default depth */
#define PHP_JSON_PARSER_DEFAULT_DEPTH 512
ZEND_BEGIN_MODULE_GLOBALS(jsond)
int encoder_depth;
int encode_max_depth;
php_json_error_code error_code;
ZEND_END_MODULE_GLOBALS(jsond)
PHP_JSOND_API ZEND_EXTERN_MODULE_GLOBALS(jsond)
#define JSOND_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(jsond, v)
#if defined(ZTS) && defined(COMPILE_DL_JSOND)
ZEND_TSRMLS_CACHE_EXTERN();
#endif
#include "php_jsond_buffer.h"
PHP_JSOND_API int PHP_JSOND_NAME(encode)(php_json_buffer *buf, zval *val, int options);
PHP_JSOND_API int PHP_JSOND_NAME(decode_ex)(zval *return_value, char *str, size_t str_len, int options, int depth);
extern PHP_JSOND_API zend_class_entry *PHP_JSOND_NAME(serializable_ce);
static inline int PHP_JSOND_NAME(decode)(zval *return_value, char *str, size_t str_len, zend_bool assoc, int depth)
{
return PHP_JSOND_NAME(decode_ex)(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
}
#endif /* PHP_JSOND_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/