xref: /php-src/ext/json/php_json_parser.h (revision 2e8699f6)
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   | Author: Jakub Zelenka <bukka@php.net>                                |
14   +----------------------------------------------------------------------+
15 */
16 
17 #ifndef PHP_JSON_PARSER_H
18 #define	PHP_JSON_PARSER_H
19 
20 #include "php.h"
21 #include "php_json_scanner.h"
22 
23 typedef struct _php_json_parser php_json_parser;
24 
25 typedef int (*php_json_parser_func_array_create_t)(
26 		php_json_parser *parser, zval *array);
27 typedef int (*php_json_parser_func_array_append_t)(
28 		php_json_parser *parser, zval *array, zval *zvalue);
29 typedef int (*php_json_parser_func_array_start_t)(
30 		php_json_parser *parser);
31 typedef int (*php_json_parser_func_array_end_t)(
32 		php_json_parser *parser, zval *object);
33 typedef int (*php_json_parser_func_object_create_t)(
34 		php_json_parser *parser, zval *object);
35 typedef int (*php_json_parser_func_object_update_t)(
36 		php_json_parser *parser, zval *object, zend_string *key, zval *zvalue);
37 typedef int (*php_json_parser_func_object_start_t)(
38 		php_json_parser *parser);
39 typedef int (*php_json_parser_func_object_end_t)(
40 		php_json_parser *parser, zval *object);
41 
42 typedef struct _php_json_parser_methods {
43 	php_json_parser_func_array_create_t array_create;
44 	php_json_parser_func_array_append_t array_append;
45 	php_json_parser_func_array_start_t array_start;
46 	php_json_parser_func_array_end_t array_end;
47 	php_json_parser_func_object_create_t object_create;
48 	php_json_parser_func_object_update_t object_update;
49 	php_json_parser_func_object_start_t object_start;
50 	php_json_parser_func_object_end_t object_end;
51 } php_json_parser_methods;
52 
53 struct _php_json_parser {
54 	php_json_scanner scanner;
55 	zval *return_value;
56 	int depth;
57 	int max_depth;
58 	php_json_parser_methods methods;
59 };
60 
61 PHP_JSON_API void php_json_parser_init_ex(
62 		php_json_parser *parser,
63 		zval *return_value,
64 		const char *str,
65 		size_t str_len,
66 		int options,
67 		int max_depth,
68 		const php_json_parser_methods *methods);
69 
70 PHP_JSON_API void php_json_parser_init(
71 		php_json_parser *parser,
72 		zval *return_value,
73 		const char *str,
74 		size_t str_len,
75 		int options,
76 		int max_depth);
77 
78 PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parser *parser);
79 
80 PHP_JSON_API int php_json_parse(php_json_parser *parser);
81 
82 int php_json_yyparse(php_json_parser *parser);
83 
84 const php_json_parser_methods* php_json_get_validate_methods(void);
85 
86 #endif	/* PHP_JSON_PARSER_H */
87