]> granicus.if.org Git - php/commitdiff
MFH
authorEdin Kadribasic <edink@php.net>
Mon, 24 Jun 2002 09:34:06 +0000 (09:34 +0000)
committerEdin Kadribasic <edink@php.net>
Mon, 24 Jun 2002 09:34:06 +0000 (09:34 +0000)
# Tested build on Linux and Win32.
# Wanted: testers on other platforms.

sapi/apache2filter/CREDITS
sapi/apache2filter/README
sapi/apache2filter/apache_config.c
sapi/apache2filter/php_apache.h
sapi/apache2filter/php_functions.c
sapi/apache2filter/sapi_apache2.c

index 8fa27e83933e29d24e1c00bb8f55b8ce8aa20451..54e39b46f0addd8e23149ccdbb4f30d456cc210c 100644 (file)
@@ -1,2 +1,2 @@
 Apache 2.0
-Sascha Schumann
+Sascha Schumann, Aaron Bannert
index 7bc0bd03aec00cb393cc0171096894214e640a46..73498c1cc3cd93209933a75dca9c20f74d5fcee7 100644 (file)
@@ -40,6 +40,15 @@ HOW TO INSTALL
 
     That's it. Now start bin/httpd.
 
+HOW TO CONFIGURE
+
+    The Apache 2.0 PHP module supports a new configuration directive that
+    allows an admin to override the php.ini search path. For example,
+    place your php.ini file in Apache's ServerRoot/conf directory and
+    add this to your httpd.conf file:
+
+        PHPINIDir "conf"
+
 DEBUGGING APACHE AND PHP
     
     To debug Apache, we recommened:
index 178253d8251ad702d150b1244a9d4a4273b5dddf..90a544415fd2c779149da4a20448d5a9a20ac503 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "php.h"
 #include "php_ini.h"
+#include "php_apache.h"
 
 #include "apr_strings.h"
 #include "ap_config.h"
@@ -82,6 +83,40 @@ static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, c
        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)
+{
+       char bool_val[2];
+
+       if (!strcasecmp(arg2, "On")) {
+               bool_val[0] = '1';
+       } else {
+               bool_val[0] = '0';
+       }
+       bool_val[1] = 0;
+
+       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)
+{
+       return real_flag_hnd(cmd, dummy, name, value, PHP_INI_USER);
+}
+
+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)
+{
+       if (apache2_php_ini_path_override) {
+               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;
+}
+
+
 void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
 {
        php_conf_rec *d = base_conf, *e = new_conf;
@@ -128,8 +163,14 @@ 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_admin_value", php_apache_admin_value_handler, NULL, OR_NONE,
-                  "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,
+                  "PHP Value Modifier (Admin)"),
+       AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF,
+                  "PHP Flag Modifier (Admin)"),
+       AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
+                  "Directory containing the php.ini file"),
    {NULL}
 };
 
index 8cac0a0e37fa24a7322de7fbd62b6d01196a3771..e96fd404f1e5f0eefcbf1d254ca418103bef7e25 100644 (file)
 #ifndef PHP_APACHE_H
 #define PHP_APACHE_H
 
+#include "httpd.h"
+#include "http_config.h"
+#include "http_core.h"
+
+/* Declare this so we can get to it from outside the sapi_apache2.c file */
+extern module AP_MODULE_DECLARE_DATA php4_module;
+
+/* A way to specify the location of the php.ini dir in an apache directive */
+extern char *apache2_php_ini_path_override;
+
+/* The server_context used by PHP */
 typedef struct php_struct {
        int state;
        request_rec *r;
index ff9ce3821890095966474e5e829a8bf1b37ac7d2..c04e0b938eddcd53983429026402a727b74e30e4 100644 (file)
@@ -20,6 +20,7 @@
 #include "SAPI.h"
 
 #include "apr_strings.h"
+#include "apr_time.h"
 #include "ap_config.h"
 #include "util_filter.h"
 #include "httpd.h"
@@ -69,9 +70,11 @@ PHP_FUNCTION(virtual)
 }
 
 #define ADD_LONG(name) \
-               add_assoc_long(return_value, #name, rr->name)
+               add_property_long(return_value, #name, rr->name)
+#define ADD_TIME(name) \
+               add_property_long(return_value, #name, rr->name / APR_USEC_PER_SEC);
 #define ADD_STRING(name) \
-               if (rr->name) add_assoc_string(return_value, #name, (char *) rr->name, 1)
+               if (rr->name) add_property_string(return_value, #name, (char *) rr->name, 1)
 
 PHP_FUNCTION(apache_lookup_uri)
 {
@@ -82,13 +85,13 @@ PHP_FUNCTION(apache_lookup_uri)
                WRONG_PARAM_COUNT;
        
        if (rr->status == HTTP_OK) {
-               array_init(return_value);
+               object_init(return_value);
 
                ADD_LONG(status);
                ADD_STRING(the_request);
                ADD_STRING(status_line);
                ADD_STRING(method);
-               ADD_LONG(mtime);
+               ADD_TIME(mtime);
                ADD_LONG(clength);
 #if MODULE_MAGIC_NUMBER < 20020506
                ADD_STRING(boundary);
@@ -104,6 +107,12 @@ PHP_FUNCTION(apache_lookup_uri)
                ADD_STRING(filename);
                ADD_STRING(path_info);
                ADD_STRING(args);
+               ADD_LONG(allowed);
+               ADD_LONG(sent_bodyct);
+               ADD_LONG(bytes_sent);
+               ADD_LONG(request_time);
+               ADD_LONG(mtime);
+               ADD_TIME(request_time);
 
                ap_destroy_sub_req(rr);
                return;
index fe485d275aad5afa78ce2986a7744d54408ef966..d1253302e9d64266f5326f4f693e77885811c6bf 100644 (file)
@@ -42,6 +42,9 @@
 #include "http_core.h"                         
 
 #include "php_apache.h"
+/* A way to specify the location of the php.ini dir in an apache directive */
+char *apache2_php_ini_path_override = NULL;
 
 static int
 php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
@@ -63,13 +66,15 @@ php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
        b = apr_bucket_transient_create(str, str_length, ba);
        APR_BRIGADE_INSERT_TAIL(bb, b);
 
+#if 0
        /* Add a Flush bucket to the end of this brigade, so that
         * the transient buckets above are more likely to make it out
         * the end of the filter instead of having to be copied into
         * someone's setaside. */
        b = apr_bucket_flush_create(ba);
        APR_BRIGADE_INSERT_TAIL(bb, b);
-
+#endif
+       
        if (ap_pass_brigade(f->next, bb) != APR_SUCCESS) {
                php_handle_aborted_connection();
        }
@@ -225,38 +230,37 @@ static sapi_module_struct apache2_sapi_module = {
        "apache2filter",
        "Apache 2.0 Filter",
 
-       php_module_startup,                                                     /* startup */
+       php_module_startup,                                             /* startup */
        php_module_shutdown_wrapper,                    /* shutdown */
 
        NULL,                                                                   /* activate */
        NULL,                                                                   /* deactivate */
 
-       php_apache_sapi_ub_write,                                       /* unbuffered write */
+       php_apache_sapi_ub_write,                               /* unbuffered write */
        php_apache_sapi_flush,                                  /* flush */
        NULL,                                                                   /* get uid */
        NULL,                                                                   /* getenv */
 
        php_error,                                                              /* error handler */
 
-       php_apache_sapi_header_handler,                         /* header handler */
-       php_apache_sapi_send_headers,                           /* send headers handler */
+       php_apache_sapi_header_handler,                 /* header handler */
+       php_apache_sapi_send_headers,                   /* send headers handler */
        NULL,                                                                   /* send header handler */
 
-       php_apache_sapi_read_post,                                      /* read POST data */
-       php_apache_sapi_read_cookies,                           /* read Cookies */
+       php_apache_sapi_read_post,                              /* read POST data */
+       php_apache_sapi_read_cookies,                   /* read Cookies */
 
        php_apache_sapi_register_variables,
        php_apache_sapi_log_message,                    /* Log message */
 
+    NULL,                                                                      /* php_ini_path_override */
+
        NULL,                                                                   /* Block interruptions */
        NULL,                                                                   /* Unblock interruptions */
 
        STANDARD_SAPI_MODULE_PROPERTIES
 };
 
-
-AP_MODULE_DECLARE_DATA module php4_module;
-
 static int php_input_filter(ap_filter_t *f, apr_bucket_brigade *bb, 
                ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
 {
@@ -433,6 +437,14 @@ static void php_apache_add_version(apr_pool_t *p)
        }
 }
 
+static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
+{
+    /* When this is NULL, apache won't override the hard-coded default
+     * php.ini path setting. */
+    apache2_php_ini_path_override = NULL;
+    return OK;
+}
+
 static int
 php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
                           apr_pool_t *ptemp, server_rec *s)
@@ -454,6 +466,11 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog,
                return OK;
        }
 
+       /* Set up our overridden path. */
+       if (apache2_php_ini_path_override) {
+               apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
+       }
+
        tsrm_startup(1, 1, 0, NULL);
        sapi_startup(&apache2_sapi_module);
        apache2_sapi_module.startup(&apache2_sapi_module);
@@ -482,8 +499,7 @@ static void php_add_filter(request_rec *r, ap_filter_t *f)
 
        if (output) {
                ap_add_output_filter("PHP", NULL, r, r->connection);
-       }
-       else {
+       } else {
                ap_add_input_filter("PHP", NULL, r, r->connection);
        }
 }
@@ -528,21 +544,22 @@ static int php_post_read_request(request_rec *r)
 
 static void php_register_hook(apr_pool_t *p)
 {
+       ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_insert_filter(php_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE);
+       ap_hook_post_read_request(php_post_read_request, NULL, NULL, APR_HOOK_MIDDLE);
        ap_register_output_filter("PHP", php_output_filter, AP_FTYPE_RESOURCE);
        ap_register_input_filter("PHP", php_input_filter, AP_FTYPE_RESOURCE);
 }
 
 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 */
-    php_dir_cmds,                      /* command apr_table_t */
-    php_register_hook          /* register hooks */
+       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 */
+       php_dir_cmds,                   /* command apr_table_t */
+       php_register_hook               /* register hooks */
 };
 
 /*
@@ -553,5 +570,3 @@ AP_MODULE_DECLARE_DATA module php4_module = {
  * vim600: sw=4 ts=4 fdm=marker
  * vim<600: sw=4 ts=4
  */
-
-