2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2015, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
20 #include "ext/standard/info.h"
21 #include "ext/json/php_json.h"
22 #include "php_json_post.h"
25 ZEND_DECLARE_MODULE_GLOBALS(json_post
);
28 STD_PHP_INI_ENTRY("json_post.flags", "1", PHP_INI_PERDIR
, OnUpdateLong
, flags
, zend_json_post_globals
, json_post_globals
)
31 static void php_json_post_init_globals(zend_json_post_globals
*json_post_globals
)
33 json_post_globals
->flags
= PHP_JSON_OBJECT_AS_ARRAY
;
36 PHP_MINFO_FUNCTION(json_post
)
38 php_info_print_table_start();
39 php_info_print_table_header(2, "json_post support", "enabled");
40 php_info_print_table_end();
42 DISPLAY_INI_ENTRIES();
45 static SAPI_POST_HANDLER_FUNC(php_json_post_handler
)
48 char *json_str
= NULL
;
51 #if PHP_VERSION_ID >= 50600
52 if (SG(request_info
).request_body
) {
53 /* FG(stream_wrappers) not initialized yet, so we cannot use php://input */
54 php_stream_rewind(SG(request_info
).request_body
);
55 json_len
= php_stream_copy_to_mem(SG(request_info
).request_body
, &json_str
, PHP_STREAM_COPY_ALL
, 0);
58 json_str
= SG(request_info
).raw_post_data
;
59 json_len
= SG(request_info
).raw_post_data_length
;
66 php_json_decode_ex(&zjson
, json_str
, json_len
, JSON_POST_G(flags
), PG(max_input_nesting_level
) TSRMLS_CC
);
67 if (Z_TYPE(zjson
) != IS_NULL
) {
69 ZVAL_COPY_VALUE(zarg
, (&zjson
));
72 #if PHP_VERSION_ID >= 50600
79 PHP_MINIT_FUNCTION(json_post
)
81 sapi_post_entry entry
= {NULL
, 0, NULL
, NULL
};
83 entry
.post_reader
= sapi_read_standard_form_data
;
84 entry
.post_handler
= php_json_post_handler
;
86 entry
.content_type
= "text/json";
87 entry
.content_type_len
= sizeof("text/json")-1;
88 sapi_register_post_entry(&entry TSRMLS_CC
);
90 ZEND_INIT_MODULE_GLOBALS(json_post
, php_json_post_init_globals
, NULL
);
91 REGISTER_INI_ENTRIES();
95 PHP_MSHUTDOWN_FUNCTION(json_post
)
97 UNREGISTER_INI_ENTRIES();
102 zend_function_entry json_post_functions
[] = {
106 static zend_module_dep json_post_module_deps
[] = {
107 ZEND_MOD_REQUIRED("json")
108 {NULL
, NULL
, NULL
, 0}
111 zend_module_entry json_post_module_entry
= {
112 STANDARD_MODULE_HEADER_EX
,
114 json_post_module_deps
,
117 PHP_MINIT(json_post
),
118 PHP_MSHUTDOWN(json_post
),
121 PHP_MINFO(json_post
),
122 PHP_JSON_POST_VERSION
,
123 STANDARD_MODULE_PROPERTIES
127 #ifdef COMPILE_DL_JSON_POST
128 ZEND_GET_MODULE(json_post
)
136 * vim600: noet sw=4 ts=4 fdm=marker
137 * vim<600: noet sw=4 ts=4