summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Lerdorf <rasmus@php.net>2001-09-06 09:53:34 +0000
committerRasmus Lerdorf <rasmus@php.net>2001-09-06 09:53:34 +0000
commit2797cf132390f2efc5e70013bca793230dbd1adb (patch)
treef838016eb956e5ad09dd452472de01f1b3c9fc36
parent22f9e244084878e12e31ffb83a470b509a6e4c3b (diff)
downloadphp-git-2797cf132390f2efc5e70013bca793230dbd1adb.tar.gz
Apache request handler hook framework. So far only the uri hook is
implemented, but the others will be easy once I finish the uri translation example. The big things left to do is to create a proper $r request object to be manipulated in user-space and also to verify that the hooks don't steal the POST data such that it isn't available to the content handler once it is finally called. Or if we do steal it, make sure it is somehow available to the content handler later on. Comments and help with this stuff is more than welcome. Check out these files from the 'apache_hooks' branch to play along.
-rw-r--r--main/main.c101
-rw-r--r--main/php_main.h3
-rw-r--r--sapi/apache/mod_php4.c75
-rw-r--r--sapi/apache/mod_php4.h2
-rw-r--r--sapi/apache/php_apache.c2
5 files changed, 172 insertions, 11 deletions
diff --git a/main/main.c b/main/main.c
index 7a46bde331..e76fe84ef4 100644
--- a/main/main.c
+++ b/main/main.c
@@ -692,6 +692,35 @@ int php_request_startup(TSRMLS_D)
}
/* }}} */
+/* {{{ php_request_startup_for_hook
+ */
+int php_request_startup_for_hook(TSRMLS_D)
+{
+ int retval = SUCCESS;
+
+#if PHP_SIGCHILD
+ signal(SIGCHLD, sigchld_handler);
+#endif
+
+ zend_try {
+ PG(during_request_startup) = 1;
+ PG(modules_activated) = 0;
+ PG(header_is_being_sent) = 0;
+ PG(connection_status) = PHP_CONNECTION_NORMAL;
+ zend_activate(TSRMLS_C);
+ sapi_activate(TSRMLS_C);
+ zend_set_timeout(EG(timeout_seconds));
+ php_hash_environment(TSRMLS_C);
+ zend_activate_modules(TSRMLS_C);
+ PG(modules_activated)=1;
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
+
+ return retval;
+}
+/* }}} */
+
/* {{{ php_request_shutdown_for_exec
*/
void php_request_shutdown_for_exec(void *dummy)
@@ -702,6 +731,44 @@ void php_request_shutdown_for_exec(void *dummy)
}
/* }}} */
+/* {{{ php_request_shutdown_for_hook
+ */
+void php_request_shutdown_for_hook(void *dummy)
+{
+ TSRMLS_FETCH();
+
+ if (PG(modules_activated)) zend_try {
+ php_call_shutdown_functions();
+ } zend_end_try();
+
+ if (PG(modules_activated)) {
+ zend_deactivate_modules(TSRMLS_C);
+ }
+
+ zend_try {
+ int i;
+
+ for (i=0; i<NUM_TRACK_VARS; i++) {
+ zval_ptr_dtor(&PG(http_globals)[i]);
+ }
+ } zend_end_try();
+
+ zend_deactivate(TSRMLS_C);
+
+ zend_try {
+ sapi_deactivate(TSRMLS_C);
+ } zend_end_try();
+
+ zend_try {
+ shutdown_memory_manager(CG(unclean_shutdown), 0);
+ } zend_end_try();
+
+ zend_try {
+ zend_unset_timeout(TSRMLS_C);
+ } zend_end_try();
+}
+/* }}} */
+
/* {{{ php_request_shutdown
*/
void php_request_shutdown(void *dummy)
@@ -1318,6 +1385,40 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
}
/* }}} */
+/* {{{ php_execute_simple_script
+ */
+PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
+{
+ char *old_cwd;
+
+ EG(exit_status) = 0;
+#define OLD_CWD_SIZE 4096
+ old_cwd = do_alloca(OLD_CWD_SIZE);
+ old_cwd[0] = '\0';
+
+ zend_try {
+#ifdef PHP_WIN32
+ UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
+#endif
+
+ PG(during_request_startup) = 0;
+
+ if (primary_file->type == ZEND_HANDLE_FILENAME
+ && primary_file->filename) {
+ VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
+ VCWD_CHDIR_FILE(primary_file->filename);
+ }
+ zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
+ } zend_end_try();
+
+ if (old_cwd[0] != '\0') {
+ VCWD_CHDIR(old_cwd);
+ }
+ free_alloca(old_cwd);
+ return EG(exit_status);
+}
+/* }}} */
+
/* {{{ php_handle_aborted_connection
*/
PHPAPI void php_handle_aborted_connection(void)
diff --git a/main/php_main.h b/main/php_main.h
index 9595df11db..315c167c4b 100644
--- a/main/php_main.h
+++ b/main/php_main.h
@@ -29,7 +29,9 @@
#include "SAPI.h"
PHPAPI int php_request_startup(TSRMLS_D);
+PHPAPI int php_request_startup_for_hook(TSRMLS_D);
PHPAPI void php_request_shutdown(void *dummy);
+PHPAPI void php_request_shutdown_for_hook(void *dummy);
PHPAPI void php_request_shutdown_for_exec(void *dummy);
PHPAPI int php_module_startup(sapi_module_struct *sf);
PHPAPI void php_module_shutdown(TSRMLS_D);
@@ -39,6 +41,7 @@ PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals);
PHPAPI int php_startup_extensions(zend_module_entry **ptr, int count);
PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC);
+PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC);
PHPAPI int php_handle_special_queries(TSRMLS_D);
PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC);
diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c
index 6619bf4519..167178bf97 100644
--- a/sapi/apache/mod_php4.c
+++ b/sapi/apache/mod_php4.c
@@ -415,9 +415,8 @@ void php_restore_umask(void)
/* {{{ init_request_info
*/
-static void init_request_info(TSRMLS_D)
+static void init_request_info(request_rec *r TSRMLS_DC)
{
- request_rec *r = ((request_rec *) SG(server_context));
char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH");
const char *authorization=NULL;
char *tmp;
@@ -514,9 +513,12 @@ static int send_php(request_rec *r, int display_source_mode, char *filename)
return DECLINED;
}
- per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
- if (per_dir_conf) {
- zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ if(!AP(apache_config_loaded)) {
+ per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
+ if (per_dir_conf) {
+ zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ }
+ AP(apache_config_loaded) = 1;
}
/* If PHP parser engine has been turned off with an "engine off"
@@ -571,7 +573,7 @@ static int send_php(request_rec *r, int display_source_mode, char *filename)
add_common_vars(r);
add_cgi_vars(r);
- init_request_info(TSRMLS_C);
+ init_request_info(r TSRMLS_CC);
apache_php_module_main(r, display_source_mode TSRMLS_CC);
/* Done, restore umask, turn off timeout, close file and return */
@@ -771,14 +773,21 @@ CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf
*/
int php_xbithack_handler(request_rec * r)
{
- php_apache_info_struct *conf;
+ HashTable *conf;
+
+ if(!AP(apache_config_loaded)) {
+ conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
+ if (conf) {
+ zend_hash_apply((HashTable *)conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ }
+ AP(apache_config_loaded) = 1;
+ }
- conf = (php_apache_info_struct *) get_module_config(r->per_dir_config, &php4_module);
if (!(r->finfo.st_mode & S_IXUSR)) {
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
- if (conf->xbithack == 0) {
+ if (!AP(xbithack)) {
r->allowed |= (1 << METHODS) - 1;
return DECLINED;
}
@@ -868,7 +877,51 @@ command_rec php_commands[] =
};
/* }}} */
-/* {{{ odule MODULE_VAR_EXPORT php4_module
+static int php_uri_translation(request_rec *r)
+{
+ char *handler = NULL;
+ zval *ret = NULL;
+ HashTable *conf;
+ TSRMLS_FETCH();
+
+ if(!AP(apache_config_loaded)) {
+ conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
+ if (conf) {
+ zend_hash_apply((HashTable *)conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ }
+ AP(apache_config_loaded) = 1;
+ }
+
+ handler = AP(uri_handler);
+
+ if(handler) {
+ hard_timeout("send", r);
+ SG(server_context) = r;
+ php_save_umask();
+ add_common_vars(r);
+ add_cgi_vars(r);
+ init_request_info(r TSRMLS_CC);
+ apache_php_module_hook(r, handler, &ret TSRMLS_CC);
+ php_restore_umask();
+ kill_timeout(r);
+ convert_to_string(ret);
+ if(Z_STRLEN_P(ret)) {
+ if (strchr(Z_STRVAL_P(ret), ':')) {
+ ap_table_setn(r->headers_out, "Location", Z_STRVAL_P(ret));
+ return REDIRECT;
+ } else {
+ r->filename = ap_pstrdup(r->pool, Z_STRVAL_P(ret));
+ }
+ return OK;
+ } else {
+ return DECLINED;
+ }
+ } else {
+ return DECLINED;
+ }
+}
+
+/* {{{ module MODULE_VAR_EXPORT php4_module
*/
module MODULE_VAR_EXPORT php4_module =
{
@@ -880,7 +933,7 @@ module MODULE_VAR_EXPORT php4_module =
NULL, /* merge server config */
php_commands, /* command table */
php_handlers, /* handlers */
- NULL, /* filename translation */
+ php_uri_translation, /* filename translation */
NULL, /* check_user_id */
NULL, /* check auth */
NULL, /* check access */
diff --git a/sapi/apache/mod_php4.h b/sapi/apache/mod_php4.h
index cb9ce7701c..160ce3661b 100644
--- a/sapi/apache/mod_php4.h
+++ b/sapi/apache/mod_php4.h
@@ -32,6 +32,8 @@ typedef struct {
long xbithack;
long terminate_child;
zend_bool in_request;
+ zend_bool apache_config_loaded;
+ char *uri_handler;
} php_apache_info_struct;
extern zend_module_entry apache_module_entry;
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c
index 76bcb01ca8..606d9ad01d 100644
--- a/sapi/apache/php_apache.c
+++ b/sapi/apache/php_apache.c
@@ -86,6 +86,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateInt, engine, php_apache_info_struct, php_apache_info)
STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateInt, last_modified, php_apache_info_struct, php_apache_info)
STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateInt, terminate_child, php_apache_info_struct, php_apache_info)
+ STD_PHP_INI_ENTRY("uri_handler", NULL, PHP_INI_ALL, OnUpdateString, uri_handler, php_apache_info_struct, php_apache_info)
PHP_INI_END()
@@ -93,6 +94,7 @@ PHP_INI_END()
static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
{
apache_globals->in_request = 0;
+ apache_globals->apache_config_loaded = 0;
}