summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Schlossnagle <gschlossnagle@php.net>2002-08-29 20:23:07 +0000
committerGeorge Schlossnagle <gschlossnagle@php.net>2002-08-29 20:23:07 +0000
commitb0e2b8604ff95e44f2f9e4093c281fb1b6247868 (patch)
tree28ae19c420b93bb1e3c386fc10126eaef5dbffce
parentd44619a811a6c4301b285109ee7c7d159d6eeff4 (diff)
downloadphp-git-b0e2b8604ff95e44f2f9e4093c281fb1b6247868.tar.gz
added the ability to set handlers as class methods (classes will need to be
declared in a phpRequire statemenet, of course, or be otherwise available at the hook run-time (builtins)). This is currently only implemented for the uri trans handler it is usable as: phpUriHandlerCodeRef MyClass::MyMethod This can be greatly robustified from whre it stands now, but is a good proof of concept (hopefully!)
-rw-r--r--sapi/apache/mod_php4.c55
-rw-r--r--sapi/apache/sapi_apache.c55
2 files changed, 109 insertions, 1 deletions
diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c
index 7a1ef095e1..1798800aab 100644
--- a/sapi/apache/mod_php4.c
+++ b/sapi/apache/mod_php4.c
@@ -77,6 +77,7 @@ typedef struct _php_per_dir_config {
typedef struct _php_per_server_config {
sapi_stack uri_handlers;
+ sapi_stack uri_handlers_code;
sapi_stack requires;
} php_per_server_config;
@@ -800,6 +801,7 @@ static void php_destroy_per_server_info(php_per_server_config *conf)
{
sapi_stack_destroy(&conf->requires);
sapi_stack_destroy(&conf->uri_handlers);
+ sapi_stack_destroy(&conf->uri_handlers_code);
}
/* }}} */
@@ -830,6 +832,7 @@ static void *php_create_server(pool *p, char *dummy)
sapi_stack_init_ex(&conf->requires, 1);
sapi_stack_init_ex(&conf->uri_handlers, 1);
+ sapi_stack_init_ex(&conf->uri_handlers_code, 1);
return conf;
}
@@ -918,6 +921,16 @@ static CONST_PREFIX char *php_set_uri_handler(cmd_parms *cmd, void *dummy, char
}
/* }}} */
+/* {{{ php_set_uri_handler_code */
+static CONST_PREFIX char *php_set_uri_handler_code(cmd_parms *cmd, void *dummy, char *arg1)
+{
+ php_per_server_config *conf;
+ conf = get_module_config(cmd->server->module_config, &php4_module);
+ sapi_stack_push(&conf->uri_handlers_code, arg1, strlen(arg1) + 1);
+ return NULL;
+}
+/* }}} */
+
/* {{{ php_set_header_handler
*/
static CONST_PREFIX char *php_set_header_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
@@ -1179,6 +1192,40 @@ static int php_run_hook(char *handler, request_rec *r)
}
+static int php_run_hook_code(char *handler, request_rec *r)
+{
+ zval *ret = NULL;
+ php_per_dir_config *conf;
+
+ TSRMLS_FETCH();
+ fprintf(stderr, "php_run_hook_code\n");
+ if(!AP(apache_config_loaded)) {
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php4_module);
+ if (conf)
+ zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ AP(apache_config_loaded) = 1;
+ }
+ if (!handler)
+ return DECLINED;
+ fprintf(stderr, "\trunning code: %s\n", handler);
+ hard_timeout("send", r);
+ SG(server_context) = r;
+ php_save_umask();
+ if (!AP(setup_env)) {
+ add_common_vars(r);
+ add_cgi_vars(r);
+ AP(setup_env) = 1;
+ }
+ init_request_info(TSRMLS_C);
+ apache_php_module_hook_code(r, handler, &ret TSRMLS_CC);
+ php_restore_umask();
+ kill_timeout(r);
+ if (ret) {
+ convert_to_long(ret);
+ return Z_LVAL_P(ret);
+ }
+ return HTTP_INTERNAL_SERVER_ERROR;
+}
static int php_uri_translation(request_rec *r)
{
@@ -1186,6 +1233,9 @@ static int php_uri_translation(request_rec *r)
fprintf(stderr,"HOOK: uri_translation\n");
AP(current_hook) = AP_URI_TRANS;
conf = (php_per_server_config *) get_module_config(r->server->module_config, &php4_module);
+ if(sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers_code, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook_code, r, OK) == OK) {
+ return OK;
+ }
return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r, OK);
}
@@ -1269,7 +1319,9 @@ static int php_post_read_hook(request_rec *r)
fprintf(stderr,"HOOK: post-read\n");
AP(current_hook) = AP_POST_READ;
svr = get_module_config(r->server->module_config, &php4_module);
- sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r);
+ if(ap_is_initial_req(r)) {
+ sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r);
+ }
conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php4_module);
return sapi_stack_apply_with_argument_stop_if_http_error(&conf->post_read_handlers,
ZEND_STACK_APPLY_BOTTOMUP,
@@ -1302,6 +1354,7 @@ command_rec php_commands[] =
{
{"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
{"phpUriHandler", php_set_uri_handler, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
+ {"phpUriHandlerCodeRef", php_set_uri_handler_code, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
#if MODULE_MAGIC_NUMBER >= 19970103
{"phpHeaderHandler", php_set_header_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
#endif
diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c
index 2e6c61d45d..117472c76d 100644
--- a/sapi/apache/sapi_apache.c
+++ b/sapi/apache/sapi_apache.c
@@ -104,6 +104,61 @@ int apache_php_module_hook(request_rec *r, char *filename, zval **ret TSRMLS_DC)
/* }}} */
+/* {{{ apache_php_module_hook_code
+ */
+int apache_php_module_hook_code(request_rec *r, char *filename, zval **ret TSRMLS_DC)
+{
+ zend_file_handle file_handle;
+ zval *req;
+ char *tmp;
+
+#if PHP_SIGCHILD
+ signal(SIGCHLD, sigchld_handler);
+#endif
+ if(AP(current_hook) == AP_RESPONSE) {
+ fprintf(stderr, "in Response\n");
+ if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
+ return FAILURE;
+ }
+ else {
+ if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
+ return FAILURE;
+ }
+
+ /* Add PHP_SELF_HOOK - Absolute path */
+ php_register_variable("PHP_SELF_HOOK", filename, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
+
+ req = php_apache_request_new(r);
+ if(PG(register_globals)) {
+ php_register_variable_ex("request", req, NULL TSRMLS_CC);
+ }
+ else {
+ php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
+ }
+ if( (tmp = strstr(filename, "::")) != NULL && *(tmp+2) != '\0' ) {
+ zval *class;
+ zval *method;
+ *tmp = '\0';
+ ALLOC_ZVAL(class);
+ ZVAL_STRING(class, filename, 1);
+ ALLOC_ZVAL(method);
+ ZVAL_STRING(method, tmp +2, 1);
+ fprintf(stderr, "calling coderef %s::%s\n", filename, tmp +2);
+ *tmp = ':';
+ call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
+ zval_dtor(&class);
+ zval_dtor(&method);
+ }
+ else {
+ /* not a class::method */
+ }
+ zval_dtor(&req);
+ AP(in_request) = 0;
+
+ return OK;
+}
+
+/* }}} */
/*
* Local variables:
* tab-width: 4