summaryrefslogtreecommitdiff
path: root/sapi/apache2handler/sapi_apache2.c
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/apache2handler/sapi_apache2.c')
-rw-r--r--sapi/apache2handler/sapi_apache2.c138
1 files changed, 76 insertions, 62 deletions
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
index 6fa2521c38..456b9719fa 100644
--- a/sapi/apache2handler/sapi_apache2.c
+++ b/sapi/apache2handler/sapi_apache2.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
@@ -30,7 +30,7 @@
#include <fcntl.h>
-#include "ext/standard/php_smart_str.h"
+#include "zend_smart_str.h"
#ifndef NETWARE
#include "ext/standard/php_standard.h"
#else
@@ -53,12 +53,6 @@
#include "php_apache.h"
-#ifdef PHP_WIN32
-# if _MSC_VER <= 1300
-# include "win32/php_strtoi64.h"
-# endif
-#endif
-
/* UnixWare and Netware define shutdown to _shutdown, which causes problems later
* on when using a structure member named shutdown. Since this source
* file does not use the system call shutdown, it is safe to #undef it.K
@@ -67,13 +61,16 @@
#define PHP_MAGIC_TYPE "application/x-httpd-php"
#define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source"
-#define PHP_SCRIPT "php5-script"
+#define PHP_SCRIPT "php7-script"
/* A way to specify the location of the php.ini dir in an apache directive */
char *apache2_php_ini_path_override = NULL;
+#if defined(PHP_WIN32) && defined(ZTS)
+ZEND_TSRMLS_CACHE_DEFINE()
+#endif
-static int
-php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
+static size_t
+php_apache_sapi_ub_write(const char *str, size_t str_length)
{
request_rec *r;
php_struct *ctx;
@@ -89,7 +86,7 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
}
static int
-php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
+php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers)
{
php_struct *ctx;
char *val, *ptr;
@@ -151,7 +148,7 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e
}
static int
-php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
+php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers)
{
php_struct *ctx = SG(server_context);
const char *sline = SG(sapi_headers).http_status_line;
@@ -171,7 +168,7 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
/* call ap_set_content_type only once, else each time we call it,
configured output filters for that content type will be added */
if (!ctx->content_type) {
- ctx->content_type = sapi_get_default_content_type(TSRMLS_C);
+ ctx->content_type = sapi_get_default_content_type();
}
ap_set_content_type(ctx->r, apr_pstrdup(ctx->r->pool, ctx->content_type));
efree(ctx->content_type);
@@ -180,8 +177,8 @@ php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
-static int
-php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
+static apr_size_t
+php_apache_sapi_read_post(char *buf, size_t count_bytes)
{
apr_size_t len, tlen=0;
php_struct *ctx = SG(server_context);
@@ -212,13 +209,18 @@ php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
return tlen;
}
-static struct stat*
-php_apache_sapi_get_stat(TSRMLS_D)
+static zend_stat_t*
+php_apache_sapi_get_stat(void)
{
php_struct *ctx = SG(server_context);
+#ifdef PHP_WIN32
+ ctx->finfo.st_uid = 0;
+ ctx->finfo.st_gid = 0;
+#else
ctx->finfo.st_uid = ctx->r->finfo.user;
ctx->finfo.st_gid = ctx->r->finfo.group;
+#endif
ctx->finfo.st_dev = ctx->r->finfo.device;
ctx->finfo.st_ino = ctx->r->finfo.inode;
#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
@@ -238,7 +240,7 @@ php_apache_sapi_get_stat(TSRMLS_D)
}
static char *
-php_apache_sapi_read_cookies(TSRMLS_D)
+php_apache_sapi_read_cookies(void)
{
php_struct *ctx = SG(server_context);
const char *http_cookie;
@@ -250,7 +252,7 @@ php_apache_sapi_read_cookies(TSRMLS_D)
}
static char *
-php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC)
+php_apache_sapi_getenv(char *name, size_t name_len)
{
php_struct *ctx = SG(server_context);
const char *env_var;
@@ -265,24 +267,24 @@ php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC)
}
static void
-php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
+php_apache_sapi_register_variables(zval *track_vars_array)
{
php_struct *ctx = SG(server_context);
const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env);
char *key, *val;
- int new_val_len;
+ size_t new_val_len;
APR_ARRAY_FOREACH_OPEN(arr, key, val)
if (!val) {
val = "";
}
- if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), (unsigned int *)&new_val_len TSRMLS_CC)) {
- php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len)) {
+ php_register_variable_safe(key, val, new_val_len, track_vars_array);
}
APR_ARRAY_FOREACH_CLOSE()
- if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), (unsigned int *)&new_val_len TSRMLS_CC)) {
- php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len)) {
+ php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array);
}
}
@@ -291,7 +293,6 @@ php_apache_sapi_flush(void *server_context)
{
php_struct *ctx;
request_rec *r;
- TSRMLS_FETCH();
ctx = server_context;
@@ -303,7 +304,7 @@ php_apache_sapi_flush(void *server_context)
r = ctx->r;
- sapi_send_headers(TSRMLS_C);
+ sapi_send_headers();
r->status = SG(sapi_headers).http_response_code;
SG(headers_sent) = 1;
@@ -313,7 +314,7 @@ php_apache_sapi_flush(void *server_context)
}
}
-static void php_apache_sapi_log_message(char *msg TSRMLS_DC)
+static void php_apache_sapi_log_message(char *msg)
{
php_struct *ctx;
@@ -326,16 +327,16 @@ static void php_apache_sapi_log_message(char *msg TSRMLS_DC)
}
}
-static void php_apache_sapi_log_message_ex(char *msg, request_rec *r TSRMLS_DC)
+static void php_apache_sapi_log_message_ex(char *msg, request_rec *r)
{
if (r) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, msg, r->filename);
} else {
- php_apache_sapi_log_message(msg TSRMLS_CC);
+ php_apache_sapi_log_message(msg);
}
}
-static double php_apache_sapi_get_request_time(TSRMLS_D)
+static double php_apache_sapi_get_request_time(void)
{
php_struct *ctx = SG(server_context);
return ((double) apr_time_as_msec(ctx->r->request_time)) / 1000.0;
@@ -404,7 +405,6 @@ static apr_status_t php_apache_child_shutdown(void *tmp)
static void php_apache_add_version(apr_pool_t *p)
{
- TSRMLS_FETCH();
if (PG(expose_php)) {
ap_add_version_component(p, "PHP/" PHP_VERSION);
}
@@ -452,7 +452,14 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
}
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
+ (void)ts_resource(0);
+ ZEND_TSRMLS_CACHE_UPDATE();
#endif
+
+#ifdef ZEND_SIGNALS
+ zend_signal_startup();
+#endif
+
sapi_startup(&apache2_sapi_module);
apache2_sapi_module.startup(&apache2_sapi_module);
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
@@ -468,7 +475,7 @@ static apr_status_t php_server_context_cleanup(void *data_)
return APR_SUCCESS;
}
-static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
+static int php_apache_request_ctor(request_rec *r, php_struct *ctx)
{
char *content_length;
const char *auth;
@@ -483,7 +490,11 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
r->no_local_copy = 1;
content_length = (char *) apr_table_get(r->headers_in, "Content-Length");
- SG(request_info).content_length = (content_length ? atol(content_length) : 0);
+ if (content_length) {
+ ZEND_ATOL(SG(request_info).content_length, content_length);
+ } else {
+ SG(request_info).content_length = 0;
+ }
apr_table_unset(r->headers_out, "Content-Length");
apr_table_unset(r->headers_out, "Last-Modified");
@@ -491,7 +502,7 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
apr_table_unset(r->headers_out, "ETag");
auth = apr_table_get(r->headers_in, "Authorization");
- php_handle_auth_data(auth TSRMLS_CC);
+ php_handle_auth_data(auth);
if (SG(request_info).auth_user == NULL && r->user) {
SG(request_info).auth_user = estrdup(r->user);
@@ -499,32 +510,28 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user);
- return php_request_startup(TSRMLS_C);
+ return php_request_startup();
}
-static void php_apache_request_dtor(request_rec *r TSRMLS_DC)
+static void php_apache_request_dtor(request_rec *r)
{
php_request_shutdown(NULL);
}
-static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC)
+static void php_apache_ini_dtor(request_rec *r, request_rec *p)
{
if (strcmp(r->protocol, "INCLUDED")) {
- zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try();
+ zend_try { zend_ini_deactivate(); } zend_end_try();
} else {
typedef struct {
HashTable config;
} php_conf_rec;
- char *str;
- uint str_len;
- php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php5_module);
-
- for (zend_hash_internal_pointer_reset(&c->config);
- zend_hash_get_current_key_ex(&c->config, &str, &str_len, NULL, 0, NULL) == HASH_KEY_IS_STRING;
- zend_hash_move_forward(&c->config)
- ) {
- zend_restore_ini_entry(str, str_len, ZEND_INI_STAGE_SHUTDOWN);
- }
+ zend_string *str;
+ php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php7_module);
+
+ ZEND_HASH_FOREACH_STR_KEY(&c->config, str) {
+ zend_restore_ini_entry(str, ZEND_INI_STAGE_SHUTDOWN);
+ } ZEND_HASH_FOREACH_END();
}
if (p) {
((php_struct *)SG(server_context))->r = p;
@@ -541,11 +548,15 @@ static int php_handler(request_rec *r)
apr_bucket *bucket;
apr_status_t rv;
request_rec * volatile parent_req = NULL;
- TSRMLS_FETCH();
+#ifdef ZTS
+ /* initial resource fetch */
+ (void)ts_resource(0);
+ ZEND_TSRMLS_CACHE_UPDATE();
+#endif
-#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);
+#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req);
- conf = ap_get_module_config(r->per_dir_config, &php5_module);
+ conf = ap_get_module_config(r->per_dir_config, &php7_module);
/* apply_config() needs r in some cases, so allocate server_context early */
ctx = SG(server_context);
@@ -588,12 +599,12 @@ normal:
}
if (r->finfo.filetype == 0) {
- php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r TSRMLS_CC);
+ php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r);
PHPAP_INI_OFF;
return HTTP_NOT_FOUND;
}
if (r->finfo.filetype == APR_DIR) {
- php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r TSRMLS_CC);
+ php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r);
PHPAP_INI_OFF;
return HTTP_FORBIDDEN;
}
@@ -615,7 +626,7 @@ zend_first_try {
ctx = SG(server_context);
ctx->brigade = brigade;
- if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
+ if (php_apache_request_ctor(r, ctx)!=SUCCESS) {
zend_bailout();
}
} else {
@@ -626,7 +637,7 @@ zend_first_try {
strcmp(parent_req->handler, PHP_MAGIC_TYPE) &&
strcmp(parent_req->handler, PHP_SOURCE_MAGIC_TYPE) &&
strcmp(parent_req->handler, PHP_SCRIPT)) {
- if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
+ if (php_apache_request_ctor(r, ctx)!=SUCCESS) {
zend_bailout();
}
}
@@ -654,7 +665,7 @@ zend_first_try {
if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE, sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {
zend_syntax_highlighter_ini syntax_highlighter_ini;
php_get_highlight_struct(&syntax_highlighter_ini);
- highlight_file((char *)r->filename, &syntax_highlighter_ini TSRMLS_CC);
+ highlight_file((char *)r->filename, &syntax_highlighter_ini);
} else {
zend_file_handle zfd;
@@ -664,19 +675,19 @@ zend_first_try {
zfd.opened_path = NULL;
if (!parent_req) {
- php_execute_script(&zfd TSRMLS_CC);
+ php_execute_script(&zfd);
} else {
- zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);
+ zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &zfd);
}
apr_table_set(r->notes, "mod_php_memory_usage",
- apr_psprintf(ctx->r->pool, "%" APR_SIZE_T_FMT, zend_memory_peak_usage(1 TSRMLS_CC)));
+ apr_psprintf(ctx->r->pool, "%" APR_SIZE_T_FMT, zend_memory_peak_usage(1)));
}
} zend_end_try();
if (!parent_req) {
- php_apache_request_dtor(r TSRMLS_CC);
+ php_apache_request_dtor(r);
ctx->request_processed = 1;
bucket = apr_bucket_eos_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(brigade, bucket);
@@ -706,6 +717,9 @@ void php_ap2_register_hook(apr_pool_t *p)
ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);
+#ifdef ZEND_SIGNALS
+ ap_hook_child_init(zend_signal_init, NULL, NULL, APR_HOOK_MIDDLE);
+#endif
ap_hook_child_init(php_apache_child_init, NULL, NULL, APR_HOOK_MIDDLE);
}