iliaa           Fri Mar  7 08:45:34 2003 EDT

  Modified files:              
    /php4/sapi/apache2handler   apache_config.c php_apache.h 
                                php_functions.c sapi_apache2.c 
  Log:
  CS Fixes.
  Fixed a bug with 404 handling.
  Added more detailed Apache info for phpinfo().
  Added the support for last_modified.
  
  
Index: php4/sapi/apache2handler/apache_config.c
diff -u php4/sapi/apache2handler/apache_config.c:1.1 
php4/sapi/apache2handler/apache_config.c:1.2
--- php4/sapi/apache2handler/apache_config.c:1.1        Tue Feb 11 12:40:11 2003
+++ php4/sapi/apache2handler/apache_config.c    Fri Mar  7 08:45:33 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: apache_config.c,v 1.1 2003/02/11 17:40:11 ianh Exp $ */
+/* $Id: apache_config.c,v 1.2 2003/03/07 13:45:33 iliaa Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -51,14 +51,12 @@
        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 @@
        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 @@
        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 @@
                        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 @@
                        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 @@
 
 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 @@
 
 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: php4/sapi/apache2handler/php_apache.h
diff -u php4/sapi/apache2handler/php_apache.h:1.2 
php4/sapi/apache2handler/php_apache.h:1.3
--- php4/sapi/apache2handler/php_apache.h:1.2   Thu Feb 20 13:20:03 2003
+++ php4/sapi/apache2handler/php_apache.h       Fri Mar  7 08:45:33 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_apache.h,v 1.2 2003/02/20 18:20:03 jerenkrantz Exp $ */
+/* $Id: php_apache.h,v 1.3 2003/03/07 13:45:33 iliaa Exp $ */
 
 #ifndef PHP_APACHE_H
 #define PHP_APACHE_H
@@ -62,5 +62,22 @@
                val = elts[i].val;
 
 #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: php4/sapi/apache2handler/php_functions.c
diff -u php4/sapi/apache2handler/php_functions.c:1.2 
php4/sapi/apache2handler/php_functions.c:1.3
--- php4/sapi/apache2handler/php_functions.c:1.2        Thu Feb 20 13:20:03 2003
+++ php4/sapi/apache2handler/php_functions.c    Fri Mar  7 08:45:33 2003
@@ -16,11 +16,13 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_functions.c,v 1.2 2003/02/20 18:20:03 jerenkrantz Exp $ */
+/* $Id: php_functions.c,v 1.3 2003/03/07 13:45:33 iliaa Exp $ */
 
 #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
@@ -37,9 +39,20 @@
 #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 @@
        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 @@
        ap_destroy_sub_req(rr);
        RETURN_TRUE;
 }
-/*  */
+/* }}} */
 
 #define ADD_LONG(name) \
                add_property_long(return_value, #name, rr->name)
@@ -153,7 +166,7 @@
        RETURN_FALSE;
 }
 
-/*  proto array getallheaders(void)
+/* {{{ proto array getallheaders(void)
    Fetch all HTTP request headers */
 PHP_FUNCTION(apache_request_headers)
 {
@@ -171,7 +184,7 @@
                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_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 @@
        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 @@
 
        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 @@
 {
        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 @@
        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 @@
        {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: php4/sapi/apache2handler/sapi_apache2.c
diff -u php4/sapi/apache2handler/sapi_apache2.c:1.4 
php4/sapi/apache2handler/sapi_apache2.c:1.5
--- php4/sapi/apache2handler/sapi_apache2.c:1.4 Wed Mar  5 11:12:23 2003
+++ php4/sapi/apache2handler/sapi_apache2.c     Fri Mar  7 08:45:33 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sapi_apache2.c,v 1.4 2003/03/05 16:12:23 sniper Exp $ */
+/* $Id: sapi_apache2.c,v 1.5 2003/03/07 13:45:33 iliaa Exp $ */
 
 #include <fcntl.h>
 
@@ -125,11 +125,9 @@
        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 @@
 
        if (rv == APR_SUCCESS) {
                apr_brigade_flatten(brigade, buf, &len);
-       }
-       else {
+       } else {
                len = 0;
        }
 
@@ -285,8 +282,7 @@
        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 @@
        "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_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 @@
                 * 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 @@
        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 @@
        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 @@
 {
        php_struct *ctx;
        void *conf;
-       char *enabled;
        apr_bucket_brigade *brigade;
        apr_bucket *bucket;
        apr_status_t rv;
@@ -486,25 +454,15 @@
        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 @@
 
        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 @@
 
                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 @@
                        php_handle_aborted_connection();
                }
                apr_brigade_cleanup(brigade);
-       }
-       else {
+       } else {
                ctx->r = parent_req;
        }
 
@@ -599,8 +562,8 @@
        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 */
 };

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to