X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_env.c;h=10d54fe4019a5a0472ffc95b1c6bfe1758964279;hp=c98701b253ae71f0aa6bd22cb3460ee62032f385;hb=refs%2Fheads%2Fv2.1.x;hpb=8b8cdb96032f50d57dbdad74ae45336d01a7f0c5 diff --git a/php_http_env.c b/php_http_env.c index c98701b..10d54fe 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2013, Michael Wallner | + | Copyright (c) 2004-2014, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -715,6 +715,7 @@ static PHP_METHOD(HttpEnv, getRequestBody) body = php_http_env_get_request_body(TSRMLS_C); if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body, NULL TSRMLS_CC)) { + php_http_message_body_addref(body); RETVAL_OBJVAL(ov, 0); } } @@ -957,26 +958,29 @@ static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler) size_t json_len = 0; #if PHP_VERSION_ID >= 50600 - php_http_message_body_to_string(php_http_env_get_request_body(TSRMLS_C), - &json_str, &json_len, 0, -1); + if (SG(request_info).request_body) { + /* FG(stream_wrappers) not initialized yet, so we cannot use php://input */ + php_stream_rewind(SG(request_info).request_body); + json_len = php_stream_copy_to_mem(SG(request_info).request_body, &json_str, PHP_STREAM_COPY_ALL, 0); + } #else json_str = SG(request_info).raw_post_data; json_len = SG(request_info).raw_post_data_length; #endif if (json_len) { - zval_dtor(zarg); - ZVAL_NULL(zarg); - php_json_decode(zarg, json_str, json_len, 1, PG(max_input_nesting_level) TSRMLS_CC); + zval zjson; + + INIT_ZVAL(zjson); + php_json_decode(&zjson, json_str, json_len, 1, PG(max_input_nesting_level) TSRMLS_CC); + if (Z_TYPE(zjson) != IS_NULL) { + zval_dtor(zarg); + ZVAL_COPY_VALUE(zarg, (&zjson)); + } } #if PHP_VERSION_ID >= 50600 STR_FREE(json_str); #endif - - /* always let $_POST be array() */ - if (Z_TYPE_P(zarg) == IS_NULL) { - array_init(zarg); - } } static void php_http_env_register_json_handler(TSRMLS_D)