]> granicus.if.org Git - php/commitdiff
CS Fixes.
authorIlia Alshanetsky <iliaa@php.net>
Fri, 7 Mar 2003 13:45:33 +0000 (13:45 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 7 Mar 2003 13:45:33 +0000 (13:45 +0000)
Fixed a bug with 404 handling.
Added more detailed Apache info for phpinfo().
Added the support for last_modified.

sapi/apache2handler/apache_config.c
sapi/apache2handler/php_apache.h
sapi/apache2handler/php_functions.c
sapi/apache2handler/sapi_apache2.c

index 3859653ce84d6b7d6474748e4e128d0334423396..ee37a9df19dc2e6f4c80b8cc75bd50ef240df72f 100644 (file)
@@ -51,14 +51,12 @@ typedef struct {
        char status;
 } php_dir_entry;
 
-static const char *real_value_hnd(cmd_parms *cmd, void *dummy, 
-               const char *name, const char *value, int status)
+static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status)
 {
        php_conf_rec *d = dummy;
        php_dir_entry e;
 
-       phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, 
-                               zend_hash_num_elements(&d->config)));
+       phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config)));
        
        if (!strncasecmp(value, "none", sizeof("none"))) {
                value = "";
@@ -68,25 +66,21 @@ static const char *real_value_hnd(cmd_parms *cmd, void *dummy,
        e.value_len = strlen(value);
        e.status = status;
        
-       zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, 
-                       sizeof(e), NULL);
+       zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL);
        return NULL;
 }
 
-static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, 
-               const char *name, const char *value)
+static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
 {
        return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
 }
 
-static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, 
-               const char *name, const char *value)
+static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
 {
        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)
+static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status)
 {
        char bool_val[2];
 
@@ -100,24 +94,20 @@ static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1,
        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)
+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_PERDIR);
 }
 
-static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, 
-               const char *name, const char *value)
+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)
+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";
+               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;
@@ -144,8 +134,7 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
                        if (pe->status >= data->status) continue;
                }
                zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL);
-               phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, 
-                                       data->status, pe?pe->status:-1));
+               phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
        }
        return new_conf;
 }
@@ -175,8 +164,7 @@ void apply_config(void *dummy)
                        zend_hash_move_forward(&d->config)) {
                zend_hash_get_current_data(&d->config, (void **) &data);
                phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
-               if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, 
-                                       data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
+               if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
                        phpapdebug((stderr, "..FAILED\n"));
                }       
        }
@@ -184,17 +172,12 @@ void apply_config(void *dummy)
 
 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_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|RSRC_CONF, "PHP Value Modifier (Admin)"),
-       AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, 
-                       ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
-       AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
-                  "Directory containing the php.ini file"),
-   {NULL}
+       AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "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|RSRC_CONF, "PHP Value Modifier (Admin)"),
+       AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
+       AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"),
+       {NULL}
 };
 
 static apr_status_t destroy_php_config(void *data)
@@ -209,8 +192,7 @@ static apr_status_t destroy_php_config(void *data)
 
 void *create_php_config(apr_pool_t *p, char *dummy)
 {
-    php_conf_rec *newx =
-    (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
+       php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
 
        phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
        zend_hash_init(&newx->config, 0, NULL, NULL, 1);
index edd76e6fa318f6429d1a5ddeb1fc7eab6d4d9b3d..febbe4fa0dfb87c9b93c51217637c25bfeab8fc5 100644 (file)
@@ -63,4 +63,21 @@ extern const command_rec php_dir_cmds[];
 
 #define APR_ARRAY_FOREACH_CLOSE() }}
 
+typedef struct {
+       long engine;
+       long xbithack;
+       long last_modified;
+} php_apache2_info_struct;
+
+extern zend_module_entry apache2_module_entry;
+
+#ifdef ZTS
+extern int php_apache2_info_id;
+#define AP2(v) TSRMG(php_apache2_info_id, php_apache2_info_struct *, v)
+#else
+extern php_apache2_info_struct php_apache2_info;
+#define AP2(v) (php_apache2_info.v)
+#endif
+
+
 #endif /* PHP_APACHE_H */
index 20547424bed2de11d6003afe08d58ecf3f1b9119..6015d2ba777d18cf1e10c9f6b65e1e5571406bea 100644 (file)
@@ -21,6 +21,8 @@
 #include "php.h"
 #include "ext/standard/php_smart_str.h"
 #include "ext/standard/info.h"
+#include "ext/standard/head.h"
+#include "php_ini.h"
 #include "SAPI.h"
 
 #define CORE_PRIVATE
 #include "http_main.h"
 #include "util_script.h"
 #include "http_core.h"
+#if !defined(WIN32) && !defined(WINNT)
+#include "unixd.h"
+#endif
 
 #include "php_apache.h"
 
+#ifdef ZTS
+int php_apache2_info_id;
+#else
+php_apache2_info_struct php_apache2_info;
+#endif
+
+#define SECTION(name)  PUTS("<h2>" name "</h2>\n")
+
 static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
 {
        php_struct *ctx;
@@ -52,7 +65,7 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
        return ap_sub_req_lookup_uri(filename, ctx->r, ctx->r->output_filters);
 }
 
-/*  proto bool virtual(string uri)
+/* {{{ proto bool virtual(string uri)
  Perform an apache sub-request */
 PHP_FUNCTION(virtual)
 {
@@ -89,7 +102,7 @@ PHP_FUNCTION(virtual)
        ap_destroy_sub_req(rr);
        RETURN_TRUE;
 }
-/*  */
+/* }}} */
 
 #define ADD_LONG(name) \
                add_property_long(return_value, #name, rr->name)
@@ -153,7 +166,7 @@ PHP_FUNCTION(apache_lookup_uri)
        RETURN_FALSE;
 }
 
-/*  proto array getallheaders(void)
+/* {{{ proto array getallheaders(void)
    Fetch all HTTP request headers */
 PHP_FUNCTION(apache_request_headers)
 {
@@ -171,7 +184,7 @@ PHP_FUNCTION(apache_request_headers)
                add_assoc_string(return_value, key, val, 1);
        APR_ARRAY_FOREACH_CLOSE()
 }
-/*  */
+/* }}} */
 
 /* {{{ proto array apache_response_headers(void)
    Fetch all HTTP response headers */
@@ -236,7 +249,7 @@ PHP_FUNCTION(apache_setenv)
        php_struct *ctx;
        zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
        int arg_count = ZEND_NUM_ARGS();
-    request_rec *r;
+       request_rec *r;
 
        if (arg_count<1 || arg_count>3 ||
                zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
@@ -272,7 +285,7 @@ PHP_FUNCTION(apache_getenv)
        zval **variable=NULL, **walk_to_top=NULL;
        int arg_count = ZEND_NUM_ARGS();
        char *env_val=NULL;
-    request_rec *r;
+       request_rec *r;
 
        if (arg_count<1 || arg_count>2 ||
                zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
@@ -281,7 +294,7 @@ PHP_FUNCTION(apache_getenv)
 
        ctx = SG(server_context);
 
-    r = ctx->r;
+       r = ctx->r;
        if (arg_count == 2 && Z_STRVAL_PP(walk_to_top)) {
                while(r->prev) {
                        r = r->prev;
@@ -342,8 +355,15 @@ PHP_MINFO_FUNCTION(apache)
 {
        char *apv = php_apache_get_version();
        smart_str tmp1 = {0};
+       char tmp[1024];
        int n;
        char *p;
+       server_rec *serv = ((php_struct *) SG(server_context))->r->server;
+#if !defined(WIN32) && !defined(WINNT)
+       AP_DECLARE_DATA extern unixd_config_rec unixd_config;
+#endif
+       extern int ap_max_requests_per_child;
+       AP_DECLARE_DATA extern const char *ap_server_root;
        
        for (n = 0; ap_loaded_modules[n]; ++n) {
                char *s = (char *) ap_loaded_modules[n]->name;
@@ -362,9 +382,76 @@ PHP_MINFO_FUNCTION(apache)
        if (apv && *apv) {
                php_info_print_table_row(2, "Apache Version", apv);
        }
+       sprintf(tmp, "%d", MODULE_MAGIC_NUMBER);
+       php_info_print_table_row(2, "Apache API Version", tmp);
+       
+       if (serv->server_admin && *(serv->server_admin)) {
+               php_info_print_table_row(2, "Servert Administrator", serv->server_admin);
+       }
+       
+       sprintf(tmp, "%s:%u", serv->server_hostname, serv->port);
+       php_info_print_table_row(2, "Hostname:Port", tmp);
+       
+#if !defined(WIN32) && !defined(WINNT)
+       sprintf(tmp, "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);
+       php_info_print_table_row(2, "User/Group", tmp);
+#endif 
+
+       sprintf(tmp, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", ap_max_requests_per_child, (serv->keep_alive ? "on":"off"), serv->keep_alive_max);
+       php_info_print_table_row(2, "Max Requests", tmp);
+
+       sprintf(tmp, "Connection: %lld - Keep-Alive: %lld", (serv->timeout / 1000000), (serv->keep_alive_timeout / 1000000));
+       php_info_print_table_row(2, "Timeouts", tmp);
+       
+       php_info_print_table_row(2, "Virtual Server", (serv->is_virtual ? "Yes" : "No"));
+       php_info_print_table_row(2, "Server Root", ap_server_root);
        php_info_print_table_row(2, "Loaded Modules", tmp1.c);
+
        smart_str_free(&tmp1);
        php_info_print_table_end();
+       
+       DISPLAY_INI_ENTRIES();
+
+       {
+               const apr_array_header_t *arr = apr_table_elts(((php_struct *) SG(server_context))->r->subprocess_env);
+               char *key, *val;
+               
+               SECTION("Apache Environment");
+               php_info_print_table_start();   
+               php_info_print_table_header(2, "Variable", "Value");
+               APR_ARRAY_FOREACH_OPEN(arr, key, val)
+                       if (!val) {
+                               val = empty_string;
+                       }
+                       php_info_print_table_row(2, key, val);
+               APR_ARRAY_FOREACH_CLOSE()
+                                                               
+               php_info_print_table_end();     
+               
+               SECTION("HTTP Headers Information");
+               php_info_print_table_start();
+               php_info_print_table_colspan_header(2, "HTTP Request Headers");
+               php_info_print_table_row(2, "HTTP Request", ((php_struct *) SG(server_context))->r->the_request);
+               
+               arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_in);
+               APR_ARRAY_FOREACH_OPEN(arr, key, val)
+                       if (!val) {
+                               val = empty_string;
+                       }
+                       php_info_print_table_row(2, key, val);
+               APR_ARRAY_FOREACH_CLOSE()
+
+               php_info_print_table_colspan_header(2, "HTTP Response Headers");
+               arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_out);
+               APR_ARRAY_FOREACH_OPEN(arr, key, val)
+                       if (!val) {
+                               val = empty_string;
+                       }
+                       php_info_print_table_row(2, key, val);
+               APR_ARRAY_FOREACH_CLOSE()
+               
+               php_info_print_table_end();
+       }
 }
 
 static function_entry apache_functions[] = {
@@ -381,14 +468,32 @@ static function_entry apache_functions[] = {
        {NULL, NULL, NULL}
 };
 
+PHP_INI_BEGIN()
+       STD_PHP_INI_ENTRY("xbithack",           "0",    PHP_INI_ALL,    OnUpdateInt,    xbithack,       php_apache2_info_struct, php_apache2_info)
+       STD_PHP_INI_ENTRY("engine",             "1",    PHP_INI_ALL,    OnUpdateInt,    engine,         php_apache2_info_struct, php_apache2_info)
+       STD_PHP_INI_ENTRY("last_modified",      "0",    PHP_INI_ALL,    OnUpdateInt,    last_modified,  php_apache2_info_struct, php_apache2_info)
+PHP_INI_END()
+
+static PHP_MINIT_FUNCTION(apache)
+{
+       REGISTER_INI_ENTRIES();
+       return SUCCESS;
+}
+
+static PHP_MSHUTDOWN_FUNCTION(apache)
+{
+       UNREGISTER_INI_ENTRIES();
+       return SUCCESS;
+}
+
 zend_module_entry php_apache_module = {
        STANDARD_MODULE_HEADER,
        "Apache 2.0",
        apache_functions,
+       PHP_MINIT(apache),
+       PHP_MSHUTDOWN(apache),
        NULL,
-       NULL,
-       NULL,
-       NULL,
+       NULL, 
        PHP_MINFO(apache),
        NULL,
        STANDARD_MODULE_PROPERTIES
index e7e1bbdda9c5563b8f27091887cbca829e82341d..77cd1e5f9e00c355be0a352a3f1b50a900303106 100644 (file)
@@ -125,11 +125,9 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_stru
        if (!strcasecmp(sapi_header->header, "content-type")) {
                val = apr_pstrdup(ctx->r->pool, val);
                ap_set_content_type(ctx->r, val);
-       }
-       else if (sapi_header->replace) {
+       } else if (sapi_header->replace) {
                apr_table_set(ctx->r->headers_out, sapi_header->header, val);
-       }
-       else {
+       } else {
                apr_table_add(ctx->r->headers_out, sapi_header->header, val);
        }
        
@@ -166,8 +164,7 @@ php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
 
        if (rv == APR_SUCCESS) {
                apr_brigade_flatten(brigade, buf, &len);
-       }
-       else {
+       } else {
                len = 0;
        }
 
@@ -285,8 +282,7 @@ static void php_apache_sapi_log_message(char *msg)
        if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
                ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
                                         0, NULL, "%s", msg);
-       }
-       else {
+       } else {
                ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO | APLOG_STARTUP,
                                         0, ctx->r, "%s", msg);
        }
@@ -306,24 +302,24 @@ static sapi_module_struct apache2_sapi_module = {
        "apache2handler",
        "Apache 2.0 Handler",
 
-       php_apache2_startup,                                            /* startup */
+       php_apache2_startup,                            /* startup */
        php_module_shutdown_wrapper,                    /* shutdown */
 
-       NULL,                                                                   /* activate */
-       NULL,                                                                   /* deactivate */
+       NULL,                                           /* activate */
+       NULL,                                           /* deactivate */
 
-       php_apache_sapi_ub_write,                               /* unbuffered write */
-       php_apache_sapi_flush,                                  /* flush */
-       php_apache_sapi_get_stat,                                               /* get uid */
-       php_apache_sapi_getenv,                                 /* getenv */
+       php_apache_sapi_ub_write,                       /* unbuffered write */
+       php_apache_sapi_flush,                          /* flush */
+       php_apache_sapi_get_stat,                       /* get uid */
+       php_apache_sapi_getenv,                         /* getenv */
 
-       php_error,                                                              /* error handler */
+       php_error,                                      /* error handler */
 
        php_apache_sapi_header_handler,                 /* header handler */
        php_apache_sapi_send_headers,                   /* send headers handler */
-       NULL,                                                                   /* send header handler */
+       NULL,                                           /* send header handler */
 
-       php_apache_sapi_read_post,                              /* read POST data */
+       php_apache_sapi_read_post,                      /* read POST data */
        php_apache_sapi_read_cookies,                   /* read Cookies */
 
        php_apache_sapi_register_variables,
@@ -369,8 +365,7 @@ static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
 }
 
 static int
-php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
-                                 apr_pool_t *ptemp, server_rec *s)
+php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 {
        void *data = NULL;
        const char *userdata_key = "apache2hook_post_config";
@@ -384,8 +379,7 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
                 * to a different location when the DSO is reloaded and the
                 * pointers won't match, causing get() to return NULL when
                 * we expected it to return non-NULL. */
-               apr_pool_userdata_set((const void *)1, userdata_key,
-                                                         apr_pool_cleanup_null, s->process->pool);
+               apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
                return OK;
        }
 
@@ -404,29 +398,6 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
        return OK;
 }
 
-static void php_add_filter(request_rec *r, ap_filter_t *f)
-{
-       int output = (f == r->output_filters);
-
-       /* for those who still have Set*Filter PHP configured */
-       while (f) {
-               if (strcmp(f->frec->name, "PHP") == 0) {
-                       ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO,
-                                        0, r->server,
-                                        "\"Set%sFilter PHP\" already configured for %s",
-                                        output ? "Output" : "Input", r->uri);
-                       return;
-               }
-               f = f->next;
-       }
-
-       if (output) {
-               ap_add_output_filter("PHP", NULL, r, r->connection);
-       } else {
-               ap_add_input_filter("PHP", NULL, r, r->connection);
-       }
-}
-
 static apr_status_t php_server_context_cleanup(void *data_)
 {
        void **data = data_;
@@ -440,16 +411,14 @@ static void php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
        const char *auth;
 
        SG(sapi_headers).http_response_code = 200;
-       SG(request_info).content_type = apr_table_get(r->headers_in,
-                                                                                                 "Content-Type");
+       SG(request_info).content_type = apr_table_get(r->headers_in, "Content-Type");
        SG(request_info).query_string = apr_pstrdup(r->pool, r->args);
        SG(request_info).request_method = r->method;
        SG(request_info).request_uri = apr_pstrdup(r->pool, r->uri);
        r->no_local_copy = 1;
 
        content_type = sapi_get_default_content_type(TSRMLS_C);
-       ap_set_content_type(r, apr_pstrdup(r->pool,
-                                                                       sapi_get_default_content_type(TSRMLS_C)));
+       ap_set_content_type(r, apr_pstrdup(r->pool, sapi_get_default_content_type(TSRMLS_C)));
        efree(content_type);
 
        apr_table_unset(r->headers_out, "Content-Length");
@@ -476,7 +445,6 @@ static int php_handler(request_rec *r)
 {
        php_struct *ctx;
        void *conf;
-       char *enabled;
        apr_bucket_brigade *brigade;
        apr_bucket *bucket;
        apr_status_t rv;
@@ -486,25 +454,15 @@ static int php_handler(request_rec *r)
        conf = ap_get_module_config(r->per_dir_config, &php4_module);
        apply_config(conf);
 
-       if (strcmp(r->handler, PHP_MAGIC_TYPE) &&
-               strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) &&
-               strcmp(r->handler, PHP_SCRIPT)) {
-               char *xbithack;
+       if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) {
                /* Check for xbithack in this case. */
-               if (strcmp(r->handler, "text/html")) {
-                       return DECLINED;
-               }
-               xbithack = get_php_config(conf, "xbithack", sizeof("xbithack"));
-               if (*xbithack == '\0' || *xbithack == '0'
-                       || !(r->finfo.protection & APR_UEXECUTE)) {
+               if (!AP2(xbithack) || strcmp(r->handler, "text/html") || !(r->finfo.protection & APR_UEXECUTE)) {
                        return DECLINED;
                }
        }
 
-       enabled = get_php_config(conf, "engine", sizeof("engine"));
-
        /* handle situations where user turns the engine off */
-       if (*enabled == '0') {
+       if (!AP2(engine)) {
                return DECLINED;
        }
 
@@ -514,36 +472,44 @@ static int php_handler(request_rec *r)
 
        ctx = SG(server_context);
        if (ctx == NULL) {
-               ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));;
+               ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));
                /* register a cleanup so we clear out the SG(server_context)
                 * after each request. Note: We pass in the pointer to the
                 * server_context in case this is handled by a different thread.
                 */
-               apr_pool_cleanup_register(r->pool, (void *)&SG(server_context),
-                                                                 php_server_context_cleanup,
-                                                                 apr_pool_cleanup_null);
+               apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);
 
                ctx->r = r;
                brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
                ctx->brigade = brigade;
 
                php_apache_request_ctor(r, ctx TSRMLS_CC);
-       }
-       else {
+       } else {
                parent_req = ctx->r;
                ctx->r = r;
                brigade = ctx->brigade;
        }
 
+       if (r->finfo.filetype == 0) {
+               php_apache_sapi_log_message("script not found or unable to stat");
+               return HTTP_NOT_FOUND;
+       }
+       if (r->finfo.filetype == APR_DIR) {
+               php_apache_sapi_log_message("attempt to invoke directory as script");
+               return HTTP_FORBIDDEN;
+       }
+
+       if (AP2(last_modified)) {
+               ap_update_mtime(r, r->finfo.mtime);
+               ap_set_last_modified(r);
+       }
+
        /* Determine if we need to parse the file or show the source */
-       if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE,
-                               sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {
+       if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE, sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {
                zend_syntax_highlighter_ini syntax_highlighter_ini;
                php_get_highlight_struct(&syntax_highlighter_ini);
-               highlight_file((char *)r->filename,
-                                          &syntax_highlighter_ini TSRMLS_CC);
-       }
-       else {
+               highlight_file((char *)r->filename, &syntax_highlighter_ini TSRMLS_CC);
+       } else {
                zend_file_handle zfd;
 
                zfd.type = ZEND_HANDLE_FILENAME;
@@ -553,16 +519,14 @@ static int php_handler(request_rec *r)
 
                if (!parent_req) {
                        php_execute_script(&zfd TSRMLS_CC);
-               }
-               else {
+               } else {
                        zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);
                }
 #if MEMORY_LIMIT
                {
                        char *mem_usage;
 
-                       mem_usage = apr_psprintf(ctx->r->pool, "%u",
-                                                                        AG(allocated_memory_peak));
+                       mem_usage = apr_psprintf(ctx->r->pool, "%u", AG(allocated_memory_peak));
                        AG(allocated_memory_peak) = 0;
                        apr_table_set(r->notes, "mod_php_memory_usage", mem_usage);
                }
@@ -580,8 +544,7 @@ static int php_handler(request_rec *r)
                        php_handle_aborted_connection();
                }
                apr_brigade_cleanup(brigade);
-       }
-       else {
+       } else {
                ctx->r = parent_req;
        }
 
@@ -599,8 +562,8 @@ 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 */
+       NULL,                           /* create per-server config structure */
+       NULL,                           /* merge per-server config structures */
        php_dir_cmds,                   /* command apr_table_t */
        php_register_hook               /* register hooks */
 };