cvs: php4(apache_hooks) /sapi/apache mod_php4.c sapi_apache.c

From: Date: Thu, 29 Aug 2002 20:23:07 +0000
Subject: cvs: php4(apache_hooks) /sapi/apache mod_php4.c sapi_apache.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-13763@lists.php.net to get a copy of this message
gschlossnagle Thu Aug 29 16:23:07 2002 EDT Modified files: (Branch: apache_hooks) /php4/sapi/apache mod_php4.c sapi_apache.c Log: 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!) Index: php4/sapi/apache/mod_php4.c diff -u php4/sapi/apache/mod_php4.c:1.120.2.7 php4/sapi/apache/mod_php4.c:1.120.2.8 --- php4/sapi/apache/mod_php4.c:1.120.2.7 Wed Aug 28 14:56:51 2002 +++ php4/sapi/apache/mod_php4.c Thu Aug 29 16:23:07 2002 @@ -17,7 +17,7 @@ | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: mod_php4.c,v 1.120.2.7 2002/08/28 18:56:51 gschlossnagle Exp $ */ +/* $Id: mod_php4.c,v 1.120.2.8 2002/08/29 20:23:07 gschlossnagle Exp $ */ #include "php_apache_http.h" @@ -77,6 +77,7 @@ 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 @@ { sapi_stack_destroy(&conf->requires); sapi_stack_destroy(&conf->uri_handlers); + sapi_stack_destroy(&conf->uri_handlers_code); } /* }}} */ @@ -830,6 +832,7 @@ 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 @@ } /* }}} */ +/* {{{ 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_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 @@ 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 @@ 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 @@ { {"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 Index: php4/sapi/apache/sapi_apache.c diff -u php4/sapi/apache/sapi_apache.c:1.33.4.4 php4/sapi/apache/sapi_apache.c:1.33.4.5 --- php4/sapi/apache/sapi_apache.c:1.33.4.4 Wed Aug 28 14:56:51 2002 +++ php4/sapi/apache/sapi_apache.c Thu Aug 29 16:23:07 2002 @@ -19,7 +19,7 @@ | Stig Bakken <ssb@fast.no> | +----------------------------------------------------------------------+ */ -/* $Id: sapi_apache.c,v 1.33.4.4 2002/08/28 18:56:51 gschlossnagle Exp $ */ +/* $Id: sapi_apache.c,v 1.33.4.5 2002/08/29 20:23:07 gschlossnagle Exp $ */ #include "php_apache_http.h" @@ -104,6 +104,61 @@ /* }}} */ +/* {{{ 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

« previous php.cvs (#13763) next »