From cac83f87a0d597885566519aaae3b0eaca3b1e25 Mon Sep 17 00:00:00 2001 From: Edin Kadribasic Date: Mon, 24 Jun 2002 09:34:06 +0000 Subject: [PATCH] MFH # Tested build on Linux and Win32. # Wanted: testers on other platforms. --- sapi/apache2filter/CREDITS | 2 +- sapi/apache2filter/README | 9 +++++ sapi/apache2filter/apache_config.c | 45 ++++++++++++++++++++++- sapi/apache2filter/php_apache.h | 11 ++++++ sapi/apache2filter/php_functions.c | 17 +++++++-- sapi/apache2filter/sapi_apache2.c | 59 +++++++++++++++++++----------- 6 files changed, 114 insertions(+), 29 deletions(-) diff --git a/sapi/apache2filter/CREDITS b/sapi/apache2filter/CREDITS index 8fa27e8393..54e39b46f0 100644 --- a/sapi/apache2filter/CREDITS +++ b/sapi/apache2filter/CREDITS @@ -1,2 +1,2 @@ Apache 2.0 -Sascha Schumann +Sascha Schumann, Aaron Bannert diff --git a/sapi/apache2filter/README b/sapi/apache2filter/README index 7bc0bd03ae..73498c1cc3 100644 --- a/sapi/apache2filter/README +++ b/sapi/apache2filter/README @@ -40,6 +40,15 @@ HOW TO INSTALL That's it. Now start bin/httpd. +HOW TO CONFIGURE + + The Apache 2.0 PHP module supports a new configuration directive that + allows an admin to override the php.ini search path. For example, + place your php.ini file in Apache's ServerRoot/conf directory and + add this to your httpd.conf file: + + PHPINIDir "conf" + DEBUGGING APACHE AND PHP To debug Apache, we recommened: diff --git a/sapi/apache2filter/apache_config.c b/sapi/apache2filter/apache_config.c index 178253d825..90a544415f 100644 --- a/sapi/apache2filter/apache_config.c +++ b/sapi/apache2filter/apache_config.c @@ -18,6 +18,7 @@ #include "php.h" #include "php_ini.h" +#include "php_apache.h" #include "apr_strings.h" #include "ap_config.h" @@ -82,6 +83,40 @@ static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, c return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); } +static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status) +{ + char bool_val[2]; + + if (!strcasecmp(arg2, "On")) { + bool_val[0] = '1'; + } else { + bool_val[0] = '0'; + } + bool_val[1] = 0; + + return real_value_hnd(cmd, dummy, arg1, bool_val, status); +} + +static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) +{ + return real_flag_hnd(cmd, dummy, name, value, PHP_INI_USER); +} + +static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value) +{ + return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM); +} + +static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg) +{ + if (apache2_php_ini_path_override) { + return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; + } + apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg); + return NULL; +} + + void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) { php_conf_rec *d = base_conf, *e = new_conf; @@ -128,8 +163,14 @@ const command_rec php_dir_cmds[] = { AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"), - AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, OR_NONE, - "PHP Value Modifier"), + AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, + "PHP Flag Modifier"), + AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF, + "PHP Value Modifier (Admin)"), + AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF, + "PHP Flag Modifier (Admin)"), + AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, + "Directory containing the php.ini file"), {NULL} }; diff --git a/sapi/apache2filter/php_apache.h b/sapi/apache2filter/php_apache.h index 8cac0a0e37..e96fd404f1 100644 --- a/sapi/apache2filter/php_apache.h +++ b/sapi/apache2filter/php_apache.h @@ -19,6 +19,17 @@ #ifndef PHP_APACHE_H #define PHP_APACHE_H +#include "httpd.h" +#include "http_config.h" +#include "http_core.h" + +/* Declare this so we can get to it from outside the sapi_apache2.c file */ +extern module AP_MODULE_DECLARE_DATA php4_module; + +/* A way to specify the location of the php.ini dir in an apache directive */ +extern char *apache2_php_ini_path_override; + +/* The server_context used by PHP */ typedef struct php_struct { int state; request_rec *r; diff --git a/sapi/apache2filter/php_functions.c b/sapi/apache2filter/php_functions.c index ff9ce38218..c04e0b938e 100644 --- a/sapi/apache2filter/php_functions.c +++ b/sapi/apache2filter/php_functions.c @@ -20,6 +20,7 @@ #include "SAPI.h" #include "apr_strings.h" +#include "apr_time.h" #include "ap_config.h" #include "util_filter.h" #include "httpd.h" @@ -69,9 +70,11 @@ PHP_FUNCTION(virtual) } #define ADD_LONG(name) \ - add_assoc_long(return_value, #name, rr->name) + add_property_long(return_value, #name, rr->name) +#define ADD_TIME(name) \ + add_property_long(return_value, #name, rr->name / APR_USEC_PER_SEC); #define ADD_STRING(name) \ - if (rr->name) add_assoc_string(return_value, #name, (char *) rr->name, 1) + if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1) PHP_FUNCTION(apache_lookup_uri) { @@ -82,13 +85,13 @@ PHP_FUNCTION(apache_lookup_uri) WRONG_PARAM_COUNT; if (rr->status == HTTP_OK) { - array_init(return_value); + object_init(return_value); ADD_LONG(status); ADD_STRING(the_request); ADD_STRING(status_line); ADD_STRING(method); - ADD_LONG(mtime); + ADD_TIME(mtime); ADD_LONG(clength); #if MODULE_MAGIC_NUMBER < 20020506 ADD_STRING(boundary); @@ -104,6 +107,12 @@ PHP_FUNCTION(apache_lookup_uri) ADD_STRING(filename); ADD_STRING(path_info); ADD_STRING(args); + ADD_LONG(allowed); + ADD_LONG(sent_bodyct); + ADD_LONG(bytes_sent); + ADD_LONG(request_time); + ADD_LONG(mtime); + ADD_TIME(request_time); ap_destroy_sub_req(rr); return; diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index fe485d275a..d1253302e9 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -42,6 +42,9 @@ #include "http_core.h" #include "php_apache.h" + +/* A way to specify the location of the php.ini dir in an apache directive */ +char *apache2_php_ini_path_override = NULL; static int php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) @@ -63,13 +66,15 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) b = apr_bucket_transient_create(str, str_length, ba); APR_BRIGADE_INSERT_TAIL(bb, b); +#if 0 /* Add a Flush bucket to the end of this brigade, so that * the transient buckets above are more likely to make it out * the end of the filter instead of having to be copied into * someone's setaside. */ b = apr_bucket_flush_create(ba); APR_BRIGADE_INSERT_TAIL(bb, b); - +#endif + if (ap_pass_brigade(f->next, bb) != APR_SUCCESS) { php_handle_aborted_connection(); } @@ -225,38 +230,37 @@ static sapi_module_struct apache2_sapi_module = { "apache2filter", "Apache 2.0 Filter", - php_module_startup, /* startup */ + php_module_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ NULL, /* activate */ NULL, /* deactivate */ - php_apache_sapi_ub_write, /* unbuffered write */ + php_apache_sapi_ub_write, /* unbuffered write */ php_apache_sapi_flush, /* flush */ NULL, /* get uid */ NULL, /* getenv */ php_error, /* error handler */ - php_apache_sapi_header_handler, /* header handler */ - php_apache_sapi_send_headers, /* send headers handler */ + php_apache_sapi_header_handler, /* header handler */ + php_apache_sapi_send_headers, /* send headers handler */ NULL, /* send header handler */ - php_apache_sapi_read_post, /* read POST data */ - php_apache_sapi_read_cookies, /* read Cookies */ + php_apache_sapi_read_post, /* read POST data */ + php_apache_sapi_read_cookies, /* read Cookies */ php_apache_sapi_register_variables, php_apache_sapi_log_message, /* Log message */ + NULL, /* php_ini_path_override */ + NULL, /* Block interruptions */ NULL, /* Unblock interruptions */ STANDARD_SAPI_MODULE_PROPERTIES }; - -AP_MODULE_DECLARE_DATA module php4_module; - static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) { @@ -433,6 +437,14 @@ static void php_apache_add_version(apr_pool_t *p) } } +static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) +{ + /* When this is NULL, apache won't override the hard-coded default + * php.ini path setting. */ + apache2_php_ini_path_override = NULL; + return OK; +} + static int php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) @@ -454,6 +466,11 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, return OK; } + /* Set up our overridden path. */ + if (apache2_php_ini_path_override) { + apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override; + } + tsrm_startup(1, 1, 0, NULL); sapi_startup(&apache2_sapi_module); apache2_sapi_module.startup(&apache2_sapi_module); @@ -482,8 +499,7 @@ static void php_add_filter(request_rec *r, ap_filter_t *f) if (output) { ap_add_output_filter("PHP", NULL, r, r->connection); - } - else { + } else { ap_add_input_filter("PHP", NULL, r, r->connection); } } @@ -528,21 +544,22 @@ static int php_post_read_request(request_rec *r) static void php_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_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE); ap_register_output_filter("PHP", php_output_filter, AP_FTYPE_RESOURCE); ap_register_input_filter("PHP", php_input_filter, AP_FTYPE_RESOURCE); } AP_MODULE_DECLARE_DATA module php4_module = { - STANDARD20_MODULE_STUFF, - create_php_config, /* create per-directory config structure */ - merge_php_config, /* merge per-directory config structures */ - NULL, /* create per-server config structure */ - NULL, /* merge per-server config structures */ - php_dir_cmds, /* command apr_table_t */ - php_register_hook /* register hooks */ + STANDARD20_MODULE_STUFF, + create_php_config, /* create per-directory config structure */ + merge_php_config, /* merge per-directory config structures */ + NULL, /* create per-server config structure */ + NULL, /* merge per-server config structures */ + php_dir_cmds, /* command apr_table_t */ + php_register_hook /* register hooks */ }; /* @@ -553,5 +570,3 @@ AP_MODULE_DECLARE_DATA module php4_module = { * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */ - - -- 2.40.0