| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
PHP_RINIT_FUNCTION(http_env)
{
- PHP_HTTP_G->env.request.time = sapi_get_request_time(TSRMLS_C);
-
/* populate form data on non-POST requests */
if (SG(request_info).request_method && strcasecmp(SG(request_info).request_method, "POST") && SG(request_info).content_type && *SG(request_info).content_type) {
uint ct_len = strlen(SG(request_info).content_type);
}
}
- STR_SET(SG(request_info).content_type_dup, NULL);
+ PTR_SET(SG(request_info).content_type_dup, NULL);
return SUCCESS;
}
return PHP_HTTP_RANGE_NO;
}
if (strncmp(range, "bytes=", lenof("bytes="))) {
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_NO;
}
switch (end) {
/* "0-" */
case -1:
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_NO;
/* "0-0" */
case -1:
/* "-", "-0" */
if (end == -1 || end == -10) {
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_ERR;
}
begin = length - end;
/* "12345-(NNN)" */
default:
if (length <= (size_t) begin) {
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_ERR;
}
switch (end) {
/* "12345-0" */
case -10:
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_ERR;
/* "12345-" */
if (length <= (size_t) end) {
end = length - 1;
} else if (end < begin) {
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_ERR;
}
break;
break;
default:
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_NO;
}
} while (c != 0);
- STR_FREE(range);
+ PTR_FREE(range);
return PHP_HTTP_RANGE_OK;
}
ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
zval_ptr_dtor(&data);
- STR_FREE(h.line);
+ PTR_FREE(h.line);
return ret;
}
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);
}
}
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);
+ PTR_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)