summaryrefslogtreecommitdiff
path: root/main/SAPI.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/SAPI.c')
-rw-r--r--main/SAPI.c121
1 files changed, 61 insertions, 60 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 8ee7649648..50ea8c0a16 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -1,8 +1,8 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -57,10 +57,15 @@ SAPI_API int sapi_globals_id;
sapi_globals_struct sapi_globals;
#endif
+static void _type_dtor(zval *zv)
+{
+ free(Z_PTR_P(zv));
+}
+
static void sapi_globals_ctor(sapi_globals_struct *sapi_globals TSRMLS_DC)
{
memset(sapi_globals, 0, sizeof(*sapi_globals));
- zend_hash_init_ex(&sapi_globals->known_post_content_types, 5, NULL, NULL, 1, 0);
+ zend_hash_init_ex(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1, 0);
php_setup_sapi_content_types(TSRMLS_C);
}
@@ -91,8 +96,6 @@ SAPI_API void sapi_startup(sapi_module_struct *sf)
sapi_globals_ctor(&sapi_globals);
#endif
- virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
-
#ifdef PHP_WIN32
tsrm_win32_startup();
#endif
@@ -110,8 +113,6 @@ SAPI_API void sapi_shutdown(void)
reentrancy_shutdown();
- virtual_cwd_shutdown();
-
#ifdef PHP_WIN32
tsrm_win32_shutdown();
#endif
@@ -128,26 +129,22 @@ SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
PHP_FUNCTION(header_register_callback)
{
zval *callback_func;
- char *callback_name;
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callback_func) == FAILURE) {
return;
}
- if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
- efree(callback_name);
+ if (!zend_is_callable(callback_func, 0, NULL TSRMLS_CC)) {
RETURN_FALSE;
}
- efree(callback_name);
- if (SG(callback_func)) {
+ if (Z_TYPE(SG(callback_func)) != IS_UNDEF) {
zval_ptr_dtor(&SG(callback_func));
SG(fci_cache) = empty_fcall_info_cache;
}
- Z_ADDREF_P(callback_func);
+ ZVAL_COPY(&SG(callback_func), callback_func);
- SG(callback_func) = callback_func;
-
RETURN_TRUE;
}
/* }}} */
@@ -156,24 +153,26 @@ static void sapi_run_header_callback(TSRMLS_D)
{
int error;
zend_fcall_info fci;
- zval *retval_ptr = NULL;
-
- fci.size = sizeof(fci);
- fci.function_table = EG(function_table);
- fci.object_ptr = NULL;
- fci.function_name = SG(callback_func);
- fci.retval_ptr_ptr = &retval_ptr;
- fci.param_count = 0;
- fci.params = NULL;
- fci.no_separation = 0;
- fci.symbol_table = NULL;
-
- error = zend_call_function(&fci, &SG(fci_cache) TSRMLS_CC);
- if (error == FAILURE) {
+ char *callback_error = NULL;
+ zval retval;
+
+ if (zend_fcall_info_init(&SG(callback_func), 0, &fci, &SG(fci_cache), NULL, &callback_error TSRMLS_CC) == SUCCESS) {
+ fci.retval = &retval;
+
+ error = zend_call_function(&fci, &SG(fci_cache) TSRMLS_CC);
+ if (error == FAILURE) {
+ goto callback_failed;
+ } else {
+ zval_ptr_dtor(&retval);
+ }
+ } else {
+callback_failed:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the sapi_header_callback");
- } else if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
}
+
+ if (callback_error) {
+ efree(callback_error);
+ }
}
SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
@@ -215,8 +214,8 @@ static void sapi_read_post_data(TSRMLS_D)
}
/* now try to find an appropriate POST content handler */
- if (zend_hash_find(&SG(known_post_content_types), content_type,
- content_type_length+1, (void **) &post_entry) == SUCCESS) {
+ if ((post_entry = zend_hash_str_find_ptr(&SG(known_post_content_types), content_type,
+ content_type_length)) != NULL) {
/* found one, register it for use */
SG(request_info).post_entry = post_entry;
post_reader_func = post_entry->post_reader;
@@ -270,13 +269,13 @@ SAPI_API int sapi_read_post_block(char *buffer, size_t buflen TSRMLS_DC)
SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
{
if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %pd bytes exceeds the limit of %pd bytes",
SG(request_info).content_length, SG(post_max_size));
return;
}
- SG(request_info).request_body = php_stream_temp_create(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE);
+ SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir));
if (sapi_module.read_post) {
int read_bytes;
@@ -291,7 +290,7 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
}
if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds " ZEND_LONG_FMT " bytes", SG(post_max_size));
break;
}
@@ -450,7 +449,7 @@ SAPI_API void sapi_activate(TSRMLS_D)
SG(sapi_headers).mimetype = NULL;
SG(headers_sent) = 0;
SG(callback_run) = 0;
- SG(callback_func) = NULL;
+ ZVAL_UNDEF(&SG(callback_func));
SG(read_post_bytes) = 0;
SG(request_info).request_body = NULL;
SG(request_info).current_user = NULL;
@@ -459,7 +458,7 @@ SAPI_API void sapi_activate(TSRMLS_D)
SG(request_info).post_entry = NULL;
SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
SG(global_request_time) = 0;
-
+ SG(post_read) = 0;
/* It's possible to override this general case in the activate() callback, if necessary. */
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
SG(request_info).headers_only = 1;
@@ -547,9 +546,7 @@ SAPI_API void sapi_deactivate(TSRMLS_D)
SG(sapi_started) = 0;
SG(headers_sent) = 0;
SG(callback_run) = 0;
- if (SG(callback_func)) {
- zval_ptr_dtor(&SG(callback_func));
- }
+ zval_ptr_dtor(&SG(callback_func));
SG(request_info).headers_read = 0;
SG(global_request_time) = 0;
}
@@ -718,7 +715,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
header_line = estrndup(header_line, header_line_len);
- /* cut of trailing spaces, linefeeds and carriage-returns */
+ /* cut off trailing spaces, linefeeds and carriage-returns */
if (header_line_len && isspace(header_line[header_line_len-1])) {
do {
header_line_len--;
@@ -742,7 +739,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
return SUCCESS;
} else {
/* new line/NUL character safety check */
- int i;
+ uint i;
for (i = 0; i < header_line_len; i++) {
/* RFC 2616 allows new lines if followed by SP or HT */
int illegal_break =
@@ -792,7 +789,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
/* Disable possible output compression for images */
if (!strncmp(ptr, "image/", sizeof("image/")-1)) {
- zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
+ zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
+ zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
+ zend_string_release(key);
}
mimetype = estrdup(ptr);
@@ -818,11 +817,13 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
* do disable compression altogether. This contributes to making scripts
* portable between setups that have and don't have zlib compression
* enabled globally. See req #44164 */
- zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"),
+ zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0);
+ zend_alter_ini_entry_chars(key,
"0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
+ zend_string_release(key);
} else if (!STRCASECMP(header_line, "Location")) {
if ((SG(sapi_headers).http_response_code < 300 ||
- SG(sapi_headers).http_response_code > 307) &&
+ SG(sapi_headers).http_response_code > 399) &&
SG(sapi_headers).http_response_code != 201) {
/* Return a Found Redirect if one is not already specified */
if (http_response_code) { /* user specified redirect code */
@@ -877,7 +878,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
SG(sapi_headers).send_default_content_type = 0;
}
- if (SG(callback_func) && !SG(callback_run)) {
+ if (Z_TYPE(SG(callback_func)) != IS_UNDEF && !SG(callback_run)) {
SG(callback_run) = 1;
sapi_run_header_callback(TSRMLS_C);
}
@@ -946,27 +947,27 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC)
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
- if (SG(sapi_started) && EG(in_execution)) {
+ if (SG(sapi_started) && EG(current_execute_data)) {
return FAILURE;
}
- return zend_hash_add(&SG(known_post_content_types),
- post_entry->content_type, post_entry->content_type_len+1,
- (void *) post_entry, sizeof(sapi_post_entry), NULL);
+ return zend_hash_str_add_mem(&SG(known_post_content_types),
+ post_entry->content_type, post_entry->content_type_len,
+ (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE;
}
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
- if (SG(sapi_started) && EG(in_execution)) {
+ if (SG(sapi_started) && EG(current_execute_data)) {
return;
}
- zend_hash_del(&SG(known_post_content_types), post_entry->content_type,
- post_entry->content_type_len+1);
+ zend_hash_str_del(&SG(known_post_content_types), post_entry->content_type,
+ post_entry->content_type_len);
}
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC)
{
- if (SG(sapi_started) && EG(in_execution)) {
+ if (SG(sapi_started) && EG(current_execute_data)) {
return FAILURE;
}
sapi_module.default_post_reader = default_post_reader;
@@ -976,16 +977,16 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRML
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC) TSRMLS_DC)
{
- if (SG(sapi_started) && EG(in_execution)) {
+ if (SG(sapi_started) && EG(current_execute_data)) {
return FAILURE;
}
sapi_module.treat_data = treat_data;
return SUCCESS;
}
-SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC)
+SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, size_t val_len, size_t *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D) TSRMLS_DC)
{
- if (SG(sapi_started) && EG(in_execution)) {
+ if (SG(sapi_started) && EG(current_execute_data)) {
return FAILURE;
}
sapi_module.input_filter = input_filter;
@@ -996,14 +997,14 @@ SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, ch
SAPI_API int sapi_flush(TSRMLS_D)
{
if (sapi_module.flush) {
- sapi_module.flush(SG(server_context));
+ sapi_module.flush(SG(server_context) TSRMLS_CC);
return SUCCESS;
} else {
return FAILURE;
}
}
-SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
+SAPI_API zend_stat_t *sapi_get_stat(TSRMLS_D)
{
if (sapi_module.get_stat) {
return sapi_module.get_stat(TSRMLS_C);