On Wed, Feb 13, 2002 at 12:36:49PM +0100, Lukas Schroeder wrote:
> On Wed, Feb 13, 2002 at 08:13:42AM +0100, Markus Fischer wrote:
> > Patches should always be against latest CVS.
>
> here it is. against latest CVS.
how does this compare the the work rasmnus has done some time
ago - see attached mail?
re,
tc
>
>
>
> regards,
> -lukas
>
> Index: sapi/apache/mod_php4.c
> ===================================================================
> RCS file: /repository/php4/sapi/apache/mod_php4.c,v
> retrieving revision 1.127
> diff -u -r1.127 mod_php4.c
> --- sapi/apache/mod_php4.c 11 Dec 2001 15:31:53 -0000 1.127
> +++ sapi/apache/mod_php4.c 13 Feb 2002 11:20:58 -0000
> @@ -483,6 +483,39 @@
> }
> /* }}} */
>
> +/* {{{ php_get_request_handler
> + */
> +static int php_get_request_handler(request_rec *r, char **target)
> +{
> + HashTable *per_dir_conf;
> + php_per_dir_entry *per_dir_entry;
> + char *filename;
> +
> + if (!(per_dir_conf = get_module_config(r->per_dir_config, &php4_module)))
> + return 0;
> +
> + if (zend_hash_find(per_dir_conf, "request_handler",
>sizeof("request_handler")-1,
> + (void **)&per_dir_entry) == SUCCESS) {
> +
> + if (!ap_os_is_path_absolute(per_dir_entry->value)) {
> + char *dirnam = ap_pstrdup(r->pool, r->filename);
> + char *x = strrchr(dirnam, '/');
> +
> + if (x != NULL)
> + *x = 0;
> + filename = ap_make_full_path(r->pool, dirnam,
>per_dir_entry->value);
> + }
> + else
> + filename = ap_pstrdup(r->pool, per_dir_entry->value);
> +
> + *target = filename;
> + return 1;
> + }
> +
> + return 0;
> +}
> +/* }}} */
> +
> /* {{{ send_php
> */
> static int send_php(request_rec *r, int display_source_mode, char *filename)
> @@ -502,6 +535,9 @@
> return OK;
> }
>
> + if (php_get_request_handler(r, &filename))
> + r->filename = filename;
> +
> zend_first_try {
> /* We don't accept OPTIONS requests, but take everything else */
> if (r->method_number == M_OPTIONS) {
> @@ -846,6 +882,26 @@
> }
> /* }}} */
>
> +/* {{{ php_type_checker
> + */
> +static int php_type_checker(request_rec *r)
> +{
> + char *filename;
> +
> + /* if a request_handler has been registered, the type checker tells
> + * apache to invoke our send_php handler; otherwise we deny responsibility
> + * for this request
> + */
> +
> + if (php_get_request_handler(r, &filename)) {
> + r->handler = "application/x-httpd-php";
> + return OK;
> + }
> +
> + return DECLINED;
> +}
> +/* }}} */
> +
> /* {{{ handler_rec php_handlers[]
> */
> handler_rec php_handlers[] =
> @@ -885,7 +941,7 @@
> NULL, /* check_user_id */
> NULL, /* check auth */
> NULL, /* check access */
> - NULL, /* type_checker */
> + php_type_checker, /* type_checker */
> NULL, /* fixups */
> NULL /* logger */
> #if MODULE_MAGIC_NUMBER >= 19970103
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
--- Begin Message ---
rasmus Thu Sep 6 05:53:34 2001 EDT
Modified files: (Branch: apache_hooks)
/php4/main main.c php_main.h
/php4/sapi/apache mod_php4.c mod_php4.h php_apache.c
Log:
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.
Index: php4/main/main.c
diff -u php4/main/main.c:1.407 php4/main/main.c:1.407.2.1
--- php4/main/main.c:1.407 Fri Aug 31 10:34:40 2001
+++ php4/main/main.c Thu Sep 6 05:53:33 2001
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.407 2001/08/31 14:34:40 zeev Exp $ */
+/* $Id: main.c,v 1.407.2.1 2001/09/06 09:53:33 rasmus Exp $ */
/* {{{ includes
*/
@@ -692,6 +692,35 @@
}
/* }}} */
+/* {{{ 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 @@
}
/* }}} */
+/* {{{ 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)
@@ -1308,6 +1375,40 @@
append_file_p = NULL;
}
zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p,
primary_file, append_file_p);
+ } zend_end_try();
+
+ if (old_cwd[0] != '\0') {
+ VCWD_CHDIR(old_cwd);
+ }
+ free_alloca(old_cwd);
+ return EG(exit_status);
+}
+/* }}} */
+
+/* {{{ 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') {
Index: php4/main/php_main.h
diff -u php4/main/php_main.h:1.15 php4/main/php_main.h:1.15.4.1
--- php4/main/php_main.h:1.15 Sun Aug 5 12:21:33 2001
+++ php4/main/php_main.h Thu Sep 6 05:53:33 2001
@@ -18,7 +18,7 @@
*/
-/* $Id: php_main.h,v 1.15 2001/08/05 16:21:33 sas Exp $ */
+/* $Id: php_main.h,v 1.15.4.1 2001/09/06 09:53:33 rasmus Exp $ */
#ifndef 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_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);
Index: php4/sapi/apache/mod_php4.c
diff -u php4/sapi/apache/mod_php4.c:1.120 php4/sapi/apache/mod_php4.c:1.120.2.1
--- php4/sapi/apache/mod_php4.c:1.120 Fri Aug 31 10:34:40 2001
+++ php4/sapi/apache/mod_php4.c Thu Sep 6 05:53:34 2001
@@ -17,7 +17,7 @@
| PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php4.c,v 1.120 2001/08/31 14:34:40 zeev Exp $ */
+/* $Id: mod_php4.c,v 1.120.2.1 2001/09/06 09:53:34 rasmus Exp $ */
#define NO_REGEX_EXTRA_H
#ifdef WIN32
@@ -415,9 +415,8 @@
/* {{{ 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 @@
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 @@
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 @@
*/
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 @@
};
/* }}} */
-/* {{{ 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 @@
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 */
Index: php4/sapi/apache/mod_php4.h
diff -u php4/sapi/apache/mod_php4.h:1.14 php4/sapi/apache/mod_php4.h:1.14.2.1
--- php4/sapi/apache/mod_php4.h:1.14 Fri Aug 31 18:03:24 2001
+++ php4/sapi/apache/mod_php4.h Thu Sep 6 05:53:34 2001
@@ -15,7 +15,7 @@
| Authors: Rasmus Lerdorf <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php4.h,v 1.14 2001/08/31 22:03:24 sniper Exp $ */
+/* $Id: mod_php4.h,v 1.14.2.1 2001/09/06 09:53:34 rasmus Exp $ */
#ifndef MOD_PHP4_H
#define MOD_PHP4_H
@@ -32,6 +32,8 @@
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;
Index: php4/sapi/apache/php_apache.c
diff -u php4/sapi/apache/php_apache.c:1.45 php4/sapi/apache/php_apache.c:1.45.4.1
--- php4/sapi/apache/php_apache.c:1.45 Tue Aug 14 13:05:53 2001
+++ php4/sapi/apache/php_apache.c Thu Sep 6 05:53:34 2001
@@ -17,7 +17,7 @@
| David Sklar <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_apache.c,v 1.45 2001/08/14 17:05:53 dbeu Exp $ */
+/* $Id: php_apache.c,v 1.45.4.1 2001/09/06 09:53:34 rasmus Exp $ */
#define NO_REGEX_EXTRA_H
@@ -86,6 +86,7 @@
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 @@
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;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
--- End Message ---
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php