From 72ccfda25aadf7eb225d7f899475e7d274bd1e72 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 28 Feb 2016 17:45:53 +0000 Subject: Add method hooking support to json parser This commit is just a slight modification (renaming and some small changes) of the patch that has been provided by Andrey Hristov. It adds support for hooking of the json parser operations and allows re-using of modified JSON parsing outside of json ext. --- ext/json/php_json_parser.h | 64 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'ext/json/php_json_parser.h') diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h index 6964ef8e8e..9a3f206667 100644 --- a/ext/json/php_json_parser.h +++ b/ext/json/php_json_parser.h @@ -22,18 +22,70 @@ #include "php.h" #include "php_json_scanner.h" -typedef struct _php_json_parser { +typedef struct _php_json_parser php_json_parser; + +typedef int (*php_json_parser_func_array_create_t)( + php_json_parser *parser, zval *array); +typedef int (*php_json_parser_func_array_append_t)( + php_json_parser *parser, zval *array, zval *zvalue); +typedef int (*php_json_parser_func_array_start_t)( + php_json_parser *parser); +typedef int (*php_json_parser_func_array_end_t)( + php_json_parser *parser, zval *object); +typedef int (*php_json_parser_func_object_create_t)( + php_json_parser *parser, zval *object); +typedef int (*php_json_parser_func_object_update_t)( + php_json_parser *parser, zval *object, zend_string *key, zval *zvalue); +typedef int (*php_json_parser_func_object_start_t)( + php_json_parser *parser); +typedef int (*php_json_parser_func_object_end_t)( + php_json_parser *parser, zval *object); +typedef int (*php_json_parser_func_depth_increase_t)( + php_json_parser *parser); +typedef int (*php_json_parser_func_depth_decrease_t)( + php_json_parser *parser); + +typedef struct _php_json_parser_methods { + php_json_parser_func_array_create_t array_create; + php_json_parser_func_array_append_t array_append; + php_json_parser_func_array_start_t array_start; + php_json_parser_func_array_end_t array_end; + php_json_parser_func_object_create_t object_create; + php_json_parser_func_object_update_t object_update; + php_json_parser_func_object_start_t object_start; + php_json_parser_func_object_end_t object_end; + php_json_parser_func_depth_increase_t depth_increase; + php_json_parser_func_depth_decrease_t depth_decrease; +} php_json_parser_methods; + +struct _php_json_parser { php_json_scanner scanner; zval *return_value; - int depth; + unsigned int depth; int max_depth; -} php_json_parser; + const php_json_parser_methods *methods; +}; + +PHP_JSON_API void php_json_parser_init_ex( + php_json_parser *parser, + zval *return_value, + char *str, + size_t str_len, + int options, + int max_depth, + const php_json_parser_methods *methods); -void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, size_t str_len, int options, int max_depth); +PHP_JSON_API void php_json_parser_init( + php_json_parser *parser, + zval *return_value, + char *str, + size_t str_len, + int options, + int max_depth); -php_json_error_code php_json_parser_error_code(php_json_parser *parser); +PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parser *parser); -int php_json_yyparse(php_json_parser *parser); +PHP_JSON_API int php_json_yyparse(php_json_parser *parser); #endif /* PHP_JSON_PARSER_H */ -- cgit v1.2.1 From 93b67dd511fdf890931e2b18846886368798ca5a Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 10 Apr 2016 16:10:26 +0100 Subject: Remove json parser depth methods and tidy it up --- ext/json/php_json_parser.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'ext/json/php_json_parser.h') diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h index 9a3f206667..edc6c4ee41 100644 --- a/ext/json/php_json_parser.h +++ b/ext/json/php_json_parser.h @@ -40,10 +40,6 @@ typedef int (*php_json_parser_func_object_start_t)( php_json_parser *parser); typedef int (*php_json_parser_func_object_end_t)( php_json_parser *parser, zval *object); -typedef int (*php_json_parser_func_depth_increase_t)( - php_json_parser *parser); -typedef int (*php_json_parser_func_depth_decrease_t)( - php_json_parser *parser); typedef struct _php_json_parser_methods { php_json_parser_func_array_create_t array_create; @@ -54,8 +50,6 @@ typedef struct _php_json_parser_methods { php_json_parser_func_object_update_t object_update; php_json_parser_func_object_start_t object_start; php_json_parser_func_object_end_t object_end; - php_json_parser_func_depth_increase_t depth_increase; - php_json_parser_func_depth_decrease_t depth_decrease; } php_json_parser_methods; struct _php_json_parser { -- cgit v1.2.1 From 37048c0f6cef53b015c04c8370f94e6597588fdc Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Mon, 2 May 2016 13:02:40 +0100 Subject: Use embedded json parser method structure --- ext/json/php_json_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/json/php_json_parser.h') diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h index edc6c4ee41..997213f42e 100644 --- a/ext/json/php_json_parser.h +++ b/ext/json/php_json_parser.h @@ -57,7 +57,7 @@ struct _php_json_parser { zval *return_value; unsigned int depth; int max_depth; - const php_json_parser_methods *methods; + php_json_parser_methods methods; }; PHP_JSON_API void php_json_parser_init_ex( -- cgit v1.2.1 From b91c05ea1411778876d7afd85461864cbde0d67a Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Wed, 11 May 2016 20:54:42 +0100 Subject: Fix and clean up exporting of json parser --- ext/json/php_json_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/json/php_json_parser.h') diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h index 997213f42e..0eb9da3073 100644 --- a/ext/json/php_json_parser.h +++ b/ext/json/php_json_parser.h @@ -79,7 +79,7 @@ PHP_JSON_API void php_json_parser_init( PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parser *parser); -PHP_JSON_API int php_json_yyparse(php_json_parser *parser); +PHP_JSON_API int php_json_parse(php_json_parser *parser); #endif /* PHP_JSON_PARSER_H */ -- cgit v1.2.1 From 0a0e42d1f5867ae273198092b0eecc2e5edc25bd Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Wed, 11 May 2016 21:11:47 +0100 Subject: Add php_json_yyparse for direct use in json ext --- ext/json/php_json_parser.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ext/json/php_json_parser.h') diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h index 0eb9da3073..f817a2da70 100644 --- a/ext/json/php_json_parser.h +++ b/ext/json/php_json_parser.h @@ -81,5 +81,7 @@ PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parse PHP_JSON_API int php_json_parse(php_json_parser *parser); +int php_json_yyparse(php_json_parser *parser); + #endif /* PHP_JSON_PARSER_H */ -- cgit v1.2.1