diff options
Diffstat (limited to 'sapi/apache2handler/php_functions.c')
-rw-r--r-- | sapi/apache2handler/php_functions.c | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index 1969cd9248..9ba09da66e 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -21,7 +21,7 @@ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h" -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "ext/standard/info.h" #include "ext/standard/head.h" #include "php_ini.h" @@ -56,10 +56,10 @@ php_apache2_info_struct php_apache2_info; #define SECTION(name) PUTS("<h2>" name "</h2>\n") -static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) +static request_rec *php_apache_lookup_uri(char *filename) { php_struct *ctx = SG(server_context); - + if (!filename || !ctx || !ctx->r) { return NULL; } @@ -72,34 +72,34 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC) PHP_FUNCTION(virtual) { char *filename; - int filename_len; + size_t filename_len; request_rec *rr; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } if (rr->status != HTTP_OK) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } /* Flush everything. */ - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); /* Ensure that the ap_r* layer for the main request is flushed, to * work around http://issues.apache.org/bugzilla/show_bug.cgi?id=17629 */ ap_rflush(rr->main); if (ap_run_sub_req(rr)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename); + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -113,23 +113,23 @@ PHP_FUNCTION(virtual) #define ADD_TIME(name) \ add_property_long(return_value, #name, apr_time_sec(rr->name)); #define ADD_STRING(name) \ - if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1) + if (rr->name) add_property_string(return_value, #name, (char *) rr->name) PHP_FUNCTION(apache_lookup_uri) { request_rec *rr; char *filename; - int filename_len; + size_t filename_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { return; } - if (!(rr = php_apache_lookup_uri(filename TSRMLS_CC))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (!(rr = php_apache_lookup_uri(filename))) { + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); RETURN_FALSE; } - + if (rr->status == HTTP_OK) { object_init(return_value); @@ -162,8 +162,8 @@ PHP_FUNCTION(apache_lookup_uri) ap_destroy_sub_req(rr); return; } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + + php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename); ap_destroy_sub_req(rr); RETURN_FALSE; } @@ -181,13 +181,13 @@ PHP_FUNCTION(apache_request_headers) } array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->r->headers_in); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -205,13 +205,13 @@ PHP_FUNCTION(apache_response_headers) } array_init(return_value); - + ctx = SG(server_context); arr = apr_table_elts(ctx->r->headers_out); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) val = ""; - add_assoc_string(return_value, key, val, 1); + add_assoc_string(return_value, key, val); APR_ARRAY_FOREACH_CLOSE() } /* }}} */ @@ -222,10 +222,10 @@ PHP_FUNCTION(apache_note) { php_struct *ctx; char *note_name, *note_val = NULL; - int note_name_len, note_val_len; + size_t note_name_len, note_val_len; char *old_note_val=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { return; } @@ -238,7 +238,7 @@ PHP_FUNCTION(apache_note) } if (old_note_val) { - RETURN_STRING(old_note_val, 1); + RETURN_STRING(old_note_val); } RETURN_FALSE; @@ -254,12 +254,12 @@ PHP_FUNCTION(apache_setenv) { php_struct *ctx; char *variable=NULL, *string_val=NULL; - int variable_len, string_val_len; + size_t variable_len, string_val_len; zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); request_rec *r; - if (zend_parse_parameters(arg_count TSRMLS_CC, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "ss|b", &variable, &variable_len, &string_val, &string_val_len, &walk_to_top) == FAILURE) { return; } @@ -288,14 +288,14 @@ PHP_FUNCTION(apache_setenv) PHP_FUNCTION(apache_getenv) { php_struct *ctx; - char *variable=NULL; - int variable_len; + char *variable; + size_t variable_len; zend_bool walk_to_top = 0; int arg_count = ZEND_NUM_ARGS(); char *env_val=NULL; request_rec *r; - if (zend_parse_parameters(arg_count TSRMLS_CC, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { + if (zend_parse_parameters(arg_count, "s|b", &variable, &variable_len, &walk_to_top) == FAILURE) { return; } @@ -313,7 +313,7 @@ PHP_FUNCTION(apache_getenv) env_val = (char*) apr_table_get(r->subprocess_env, variable); if (env_val != NULL) { - RETURN_STRING(env_val, 1); + RETURN_STRING(env_val); } RETURN_FALSE; @@ -336,7 +336,7 @@ PHP_FUNCTION(apache_get_version) char *apv = php_apache_get_version(); if (apv && *apv) { - RETURN_STRING(apv, 1); + RETURN_STRING(apv); } else { RETURN_FALSE; } @@ -349,15 +349,15 @@ PHP_FUNCTION(apache_get_modules) { int n; char *p; - + array_init(return_value); - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { - add_next_index_stringl(return_value, s, (p - s), 1); + add_next_index_stringl(return_value, s, (p - s)); } else { - add_next_index_string(return_value, s, 1); + add_next_index_string(return_value, s); } } } @@ -378,7 +378,7 @@ PHP_MINFO_FUNCTION(apache) AP_DECLARE_DATA extern unixd_config_rec unixd_config; #endif #endif - + for (n = 0; ap_loaded_modules[n]; ++n) { char *s = (char *) ap_loaded_modules[n]->name; if ((p = strchr(s, '.'))) { @@ -388,24 +388,28 @@ PHP_MINFO_FUNCTION(apache) } smart_str_appendc(&tmp1, ' '); } - if ((tmp1.len - 1) >= 0) { - tmp1.c[tmp1.len - 1] = '\0'; + if (tmp1.s) { + if (tmp1.s->len > 0) { + tmp1.s->val[tmp1.s->len - 1] = '\0'; + } else { + tmp1.s->val[0] = '\0'; + } } - + php_info_print_table_start(); if (apv && *apv) { php_info_print_table_row(2, "Apache Version", apv); } snprintf(tmp, sizeof(tmp), "%d", MODULE_MAGIC_NUMBER); php_info_print_table_row(2, "Apache API Version", tmp); - + if (serv->server_admin && *(serv->server_admin)) { php_info_print_table_row(2, "Server Administrator", serv->server_admin); } - + snprintf(tmp, sizeof(tmp), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", tmp); - + #if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) #if MODULE_MAGIC_NUMBER_MAJOR >= 20081201 snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id); @@ -420,25 +424,25 @@ PHP_MINFO_FUNCTION(apache) php_info_print_table_row(2, "Max Requests", tmp); apr_snprintf(tmp, sizeof tmp, - "Connection: %" APR_TIME_T_FMT " - Keep-Alive: %" APR_TIME_T_FMT, + "Connection: %" APR_TIME_T_FMT " - Keep-Alive: %" APR_TIME_T_FMT, apr_time_sec(serv->timeout), apr_time_sec(serv->keep_alive_timeout)); php_info_print_table_row(2, "Timeouts", tmp); - + php_info_print_table_row(2, "Virtual Server", (serv->is_virtual ? "Yes" : "No")); php_info_print_table_row(2, "Server Root", ap_server_root); - php_info_print_table_row(2, "Loaded Modules", tmp1.c); + php_info_print_table_row(2, "Loaded Modules", tmp1.s->val); smart_str_free(&tmp1); php_info_print_table_end(); - + DISPLAY_INI_ENTRIES(); { const apr_array_header_t *arr = apr_table_elts(((php_struct *) SG(server_context))->r->subprocess_env); char *key, *val; - + SECTION("Apache Environment"); - php_info_print_table_start(); + php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { @@ -446,14 +450,14 @@ PHP_MINFO_FUNCTION(apache) } php_info_print_table_row(2, key, val); APR_ARRAY_FOREACH_CLOSE() - - php_info_print_table_end(); - + + php_info_print_table_end(); + SECTION("HTTP Headers Information"); php_info_print_table_start(); php_info_print_table_colspan_header(2, "HTTP Request Headers"); php_info_print_table_row(2, "HTTP Request", ((php_struct *) SG(server_context))->r->the_request); - + arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_in); APR_ARRAY_FOREACH_OPEN(arr, key, val) if (!val) { @@ -470,7 +474,7 @@ PHP_MINFO_FUNCTION(apache) } php_info_print_table_row(2, key, val); APR_ARRAY_FOREACH_CLOSE() - + php_info_print_table_end(); } } @@ -515,7 +519,7 @@ ZEND_END_ARG_INFO() static const zend_function_entry apache_functions[] = { PHP_FE(apache_lookup_uri, arginfo_apache2handler_lookup_uri) - PHP_FE(virtual, arginfo_apache2handler_virtual) + PHP_FE(virtual, arginfo_apache2handler_virtual) PHP_FE(apache_request_headers, arginfo_apache2handler_getallheaders) PHP_FE(apache_response_headers, arginfo_apache2handler_response_headers) PHP_FE(apache_setenv, arginfo_apache2handler_setenv) @@ -528,9 +532,9 @@ static const zend_function_entry apache_functions[] = { }; PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache2_info_struct, php_apache2_info) - STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache2_info_struct, php_apache2_info) - STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateBool, xbithack, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateBool, engine, php_apache2_info_struct, php_apache2_info) + STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateBool, last_modified, php_apache2_info_struct, php_apache2_info) PHP_INI_END() static PHP_MINIT_FUNCTION(apache) @@ -555,7 +559,7 @@ zend_module_entry php_apache_module = { PHP_MINIT(apache), PHP_MSHUTDOWN(apache), NULL, - NULL, + NULL, PHP_MINFO(apache), NULL, STANDARD_MODULE_PROPERTIES |