Skip to content

Commit 4648e75

Browse files
author
foobar
committed
- MFH: apache2handler sapi module
- Changed apache2filter to use --with-apxs2filter
1 parent 9dfd6c8 commit 4648e75

File tree

10 files changed

+1721
-2
lines changed

10 files changed

+1721
-2
lines changed

sapi/apache2filter/config.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ dnl $Id$
33
dnl
44

55
AC_MSG_CHECKING(for Apache 2.0 module support via DSO through APXS)
6-
AC_ARG_WITH(apxs2,
7-
[ --with-apxs2[=FILE] EXPERIMENTAL: Build shared Apache 2.0 module. FILE is the optional
6+
AC_ARG_WITH(apxs2filter,
7+
[ --with-apxs2filter[=FILE] EXPERIMENTAL: Build shared Apache 2.0 module. FILE is the optional
88
pathname to the Apache apxs tool; defaults to "apxs".],[
99
if test "$withval" = "yes"; then
1010
APXS=apxs

sapi/apache2handler/CREDITS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Apache 2.0 Handler
2+
Ian Holsman, Justin Erenkrantz (based on Apache 2.0 Filter code)

sapi/apache2handler/README

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
WHAT IS THIS?
2+
3+
This module exploits the layered I/O support in Apache 2.0.
4+
5+
HOW DOES IT WORK?
6+
7+
In Apache 2.0, you have handlers which generate content (like
8+
reading a script from disk). The content goes then through
9+
a chain of filters. PHP can be such a filter, so that it processes
10+
your script and hands the output to the next filter (which will
11+
usually cause a write to the network).
12+
13+
DOES IT WORK?
14+
15+
Currently the issues with the module are:
16+
* Thread safety of external PHP modules
17+
* The lack of re-entrancy of PHP. due to this I have disabled the 'virtual'
18+
function, and tried to stop any method where a php script can run another php
19+
script while it is being run.
20+
21+
22+
HOW TO INSTALL
23+
24+
This SAPI module is known to work with Apache 2.0.44.
25+
26+
$ cd apache-2.x
27+
$ cd src
28+
$ ./configure --enable-so
29+
$ make install
30+
31+
For testing purposes, you might want to use --with-mpm=prefork.
32+
(Albeit PHP also works with threaded MPMs. See Thread Safety note above)
33+
34+
Configure PHP 4:
35+
36+
$ cd php-4.x
37+
$ ./configure --with-apxs2=/path/to/apache-2.0/bin/apxs
38+
$ make install
39+
40+
At the end of conf/httpd.conf, add:
41+
42+
AddType application/x-httpd-php .php
43+
44+
If you would like to enable source code highlighting functionality add:
45+
46+
AddType application/x-httpd-php-source .phps
47+
48+
That's it. Now start bin/httpd.
49+
50+
HOW TO CONFIGURE
51+
52+
The Apache 2.0 PHP module supports a new configuration directive that
53+
allows an admin to override the php.ini search path. For example,
54+
place your php.ini file in Apache's ServerRoot/conf directory and
55+
add this to your httpd.conf file:
56+
57+
PHPINIDir "conf"
58+
59+
DEBUGGING APACHE AND PHP
60+
61+
To debug Apache, we recommened:
62+
63+
1. Use the Prefork MPM (Apache 1.3-like process model) by
64+
configuring Apache with '--with-mpm=prefork'.
65+
2. Start httpd using -DONE_PROCESS (e.g. (gdb) r -DONE_PROCESS).
66+
67+
If you want to debug a part of the PHP startup procedure, set a
68+
breakpoint on 'load_module'. Step through it until apr_dso_load() is
69+
done. Then you can set a breakpoint on any PHP-related symbol.
70+
71+
TODO
72+
73+
PHP functions like apache_sub_req (see php_functions.c)
74+
Source Code Highlighting
75+
Protocol handlers
76+
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 4 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2003 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.02 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available at through the world-wide-web at |
10+
| http://www.php.net/license/2_02.txt. |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@php.net so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: Sascha Schumann <sascha@schumann.cx> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#include "php.h"
22+
#include "php_ini.h"
23+
#include "php_apache.h"
24+
25+
#include "apr_strings.h"
26+
#include "ap_config.h"
27+
#include "util_filter.h"
28+
#include "httpd.h"
29+
#include "http_config.h"
30+
#include "http_request.h"
31+
#include "http_core.h"
32+
#include "http_protocol.h"
33+
#include "http_log.h"
34+
#include "http_main.h"
35+
#include "util_script.h"
36+
#include "http_core.h"
37+
38+
#ifdef PHP_AP_DEBUG
39+
#define phpapdebug(a) fprintf a
40+
#else
41+
#define phpapdebug(a)
42+
#endif
43+
44+
typedef struct {
45+
HashTable config;
46+
} php_conf_rec;
47+
48+
typedef struct {
49+
char *value;
50+
size_t value_len;
51+
char status;
52+
} php_dir_entry;
53+
54+
static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status)
55+
{
56+
php_conf_rec *d = dummy;
57+
php_dir_entry e;
58+
59+
phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config)));
60+
61+
if (!strncasecmp(value, "none", sizeof("none"))) {
62+
value = "";
63+
}
64+
65+
e.value = apr_pstrdup(cmd->pool, value);
66+
e.value_len = strlen(value);
67+
e.status = status;
68+
69+
zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL);
70+
return NULL;
71+
}
72+
73+
static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
74+
{
75+
return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
76+
}
77+
78+
static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
79+
{
80+
return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
81+
}
82+
83+
static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status)
84+
{
85+
char bool_val[2];
86+
87+
if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) {
88+
bool_val[0] = '1';
89+
} else {
90+
bool_val[0] = '0';
91+
}
92+
bool_val[1] = 0;
93+
94+
return real_value_hnd(cmd, dummy, arg1, bool_val, status);
95+
}
96+
97+
static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
98+
{
99+
return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
100+
}
101+
102+
static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
103+
{
104+
return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
105+
}
106+
107+
static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg)
108+
{
109+
if (apache2_php_ini_path_override) {
110+
return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored";
111+
}
112+
apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
113+
return NULL;
114+
}
115+
116+
117+
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
118+
{
119+
php_conf_rec *d = base_conf, *e = new_conf;
120+
php_dir_entry *pe;
121+
php_dir_entry *data;
122+
char *str;
123+
uint str_len;
124+
ulong num_index;
125+
126+
phpapdebug((stderr, "Merge dir (%p) (%p)\n", base_conf, new_conf));
127+
for (zend_hash_internal_pointer_reset(&d->config);
128+
zend_hash_get_current_key_ex(&d->config, &str, &str_len,
129+
&num_index, 0, NULL) == HASH_KEY_IS_STRING;
130+
zend_hash_move_forward(&d->config)) {
131+
pe = NULL;
132+
zend_hash_get_current_data(&d->config, (void **) &data);
133+
if (zend_hash_find(&e->config, str, str_len, (void **) &pe) == SUCCESS) {
134+
if (pe->status >= data->status) continue;
135+
}
136+
zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL);
137+
phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
138+
}
139+
return new_conf;
140+
}
141+
142+
char *get_php_config(void *conf, char *name, size_t name_len)
143+
{
144+
php_conf_rec *d = conf;
145+
php_dir_entry *pe;
146+
147+
if (zend_hash_find(&d->config, name, name_len, (void **) &pe) == SUCCESS) {
148+
return pe->value;
149+
}
150+
151+
return "";
152+
}
153+
154+
void apply_config(void *dummy)
155+
{
156+
php_conf_rec *d = dummy;
157+
char *str;
158+
uint str_len;
159+
php_dir_entry *data;
160+
161+
for (zend_hash_internal_pointer_reset(&d->config);
162+
zend_hash_get_current_key_ex(&d->config, &str, &str_len, NULL, 0,
163+
NULL) == HASH_KEY_IS_STRING;
164+
zend_hash_move_forward(&d->config)) {
165+
zend_hash_get_current_data(&d->config, (void **) &data);
166+
phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
167+
if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
168+
phpapdebug((stderr, "..FAILED\n"));
169+
}
170+
}
171+
}
172+
173+
const command_rec php_dir_cmds[] =
174+
{
175+
AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"),
176+
AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, "PHP Flag Modifier"),
177+
AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
178+
AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
179+
AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php.ini file"),
180+
{NULL}
181+
};
182+
183+
static apr_status_t destroy_php_config(void *data)
184+
{
185+
php_conf_rec *d = data;
186+
187+
phpapdebug((stderr, "Destroying config %p\n", data));
188+
zend_hash_destroy(&d->config);
189+
190+
return APR_SUCCESS;
191+
}
192+
193+
void *create_php_config(apr_pool_t *p, char *dummy)
194+
{
195+
php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
196+
197+
phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
198+
zend_hash_init(&newx->config, 0, NULL, NULL, 1);
199+
apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null);
200+
return (void *) newx;
201+
}
202+
203+
/*
204+
* Local variables:
205+
* tab-width: 4
206+
* c-basic-offset: 4
207+
* End:
208+
* vim600: sw=4 ts=4 fdm=marker
209+
* vim<600: sw=4 ts=4
210+
*/

0 commit comments

Comments
 (0)