xref: /PHP-5.5/ext/json/JSON_parser.h (revision b7903f97)
1 /* JSON_parser.h */
2 
3 #ifndef JSON_PARSER_H
4 #define JSON_PARSER_H
5 
6 #include "php.h"
7 #include "ext/standard/php_smart_str.h"
8 #include "php_json.h"
9 
10 #define JSON_PARSER_DEFAULT_DEPTH 512
11 
12 typedef struct JSON_parser_struct {
13     int state;
14     int depth;
15     int top;
16 	int error_code;
17     int* stack;
18     zval **the_zstack;
19     zval *the_static_zstack[JSON_PARSER_DEFAULT_DEPTH];
20 } * JSON_parser;
21 
22 enum error_codes {
23 	PHP_JSON_ERROR_NONE = 0,
24     PHP_JSON_ERROR_DEPTH,
25     PHP_JSON_ERROR_STATE_MISMATCH,
26     PHP_JSON_ERROR_CTRL_CHAR,
27     PHP_JSON_ERROR_SYNTAX,
28     PHP_JSON_ERROR_UTF8,
29     PHP_JSON_ERROR_RECURSION,
30     PHP_JSON_ERROR_INF_OR_NAN,
31     PHP_JSON_ERROR_UNSUPPORTED_TYPE
32 };
33 
34 extern JSON_parser new_JSON_parser(int depth);
35 extern int parse_JSON_ex(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int options TSRMLS_DC);
36 extern int free_JSON_parser(JSON_parser jp);
37 
parse_JSON(JSON_parser jp,zval * z,unsigned short utf16_json[],int length,int assoc TSRMLS_DC)38 static inline int parse_JSON(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int assoc TSRMLS_DC)
39 {
40 	return parse_JSON_ex(jp, z, utf16_json, length, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0 TSRMLS_CC);
41 }
42 
43 #endif
44