Skip to content

Commit 97418f5

Browse files
committed
CS Fixes.
Fixed a bug with 404 handling. Added more detailed Apache info for phpinfo(). Added the support for last_modified.
1 parent ba18cd1 commit 97418f5

4 files changed

Lines changed: 197 additions & 130 deletions

File tree

sapi/apache2handler/apache_config.c

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ typedef struct {
5151
char status;
5252
} php_dir_entry;
5353

54-
static const char *real_value_hnd(cmd_parms *cmd, void *dummy,
55-
const char *name, const char *value, int status)
54+
static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status)
5655
{
5756
php_conf_rec *d = dummy;
5857
php_dir_entry e;
5958

60-
phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy,
61-
zend_hash_num_elements(&d->config)));
59+
phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config)));
6260

6361
if (!strncasecmp(value, "none", sizeof("none"))) {
6462
value = "";
@@ -68,25 +66,21 @@ static const char *real_value_hnd(cmd_parms *cmd, void *dummy,
6866
e.value_len = strlen(value);
6967
e.status = status;
7068

71-
zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e,
72-
sizeof(e), NULL);
69+
zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL);
7370
return NULL;
7471
}
7572

76-
static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy,
77-
const char *name, const char *value)
73+
static const char *php_apache_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
7874
{
7975
return real_value_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
8076
}
8177

82-
static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy,
83-
const char *name, const char *value)
78+
static const char *php_apache_admin_value_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
8479
{
8580
return real_value_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
8681
}
8782

88-
static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1,
89-
const char *arg2, int status)
83+
static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1, const char *arg2, int status)
9084
{
9185
char bool_val[2];
9286

@@ -100,24 +94,20 @@ static const char *real_flag_hnd(cmd_parms *cmd, void *dummy, const char *arg1,
10094
return real_value_hnd(cmd, dummy, arg1, bool_val, status);
10195
}
10296

103-
static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy,
104-
const char *name, const char *value)
97+
static const char *php_apache_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
10598
{
10699
return real_flag_hnd(cmd, dummy, name, value, PHP_INI_PERDIR);
107100
}
108101

109-
static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy,
110-
const char *name, const char *value)
102+
static const char *php_apache_admin_flag_handler(cmd_parms *cmd, void *dummy, const char *name, const char *value)
111103
{
112104
return real_flag_hnd(cmd, dummy, name, value, PHP_INI_SYSTEM);
113105
}
114106

115-
static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig,
116-
const char *arg)
107+
static const char *php_apache_phpini_set(cmd_parms *cmd, void *mconfig, const char *arg)
117108
{
118109
if (apache2_php_ini_path_override) {
119-
return "Only first PHPINIDir directive honored per configuration tree "
120-
"- subsequent ones ignored";
110+
return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored";
121111
}
122112
apache2_php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
123113
return NULL;
@@ -144,8 +134,7 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
144134
if (pe->status >= data->status) continue;
145135
}
146136
zend_hash_update(&e->config, str, str_len, data, sizeof(*data), NULL);
147-
phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str,
148-
data->status, pe?pe->status:-1));
137+
phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
149138
}
150139
return new_conf;
151140
}
@@ -175,26 +164,20 @@ void apply_config(void *dummy)
175164
zend_hash_move_forward(&d->config)) {
176165
zend_hash_get_current_data(&d->config, (void **) &data);
177166
phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
178-
if (zend_alter_ini_entry(str, str_len, data->value, data->value_len,
179-
data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
167+
if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, PHP_INI_STAGE_RUNTIME) == FAILURE) {
180168
phpapdebug((stderr, "..FAILED\n"));
181169
}
182170
}
183171
}
184172

185173
const command_rec php_dir_cmds[] =
186174
{
187-
AP_INIT_TAKE2("php_value", php_apache_value_handler, NULL, OR_OPTIONS,
188-
"PHP Value Modifier"),
189-
AP_INIT_TAKE2("php_flag", php_apache_flag_handler, NULL, OR_OPTIONS,
190-
"PHP Flag Modifier"),
191-
AP_INIT_TAKE2("php_admin_value", php_apache_admin_value_handler, NULL,
192-
ACCESS_CONF|RSRC_CONF, "PHP Value Modifier (Admin)"),
193-
AP_INIT_TAKE2("php_admin_flag", php_apache_admin_flag_handler, NULL,
194-
ACCESS_CONF|RSRC_CONF, "PHP Flag Modifier (Admin)"),
195-
AP_INIT_TAKE1("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF,
196-
"Directory containing the php.ini file"),
197-
{NULL}
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}
198181
};
199182

200183
static apr_status_t destroy_php_config(void *data)
@@ -209,8 +192,7 @@ static apr_status_t destroy_php_config(void *data)
209192

210193
void *create_php_config(apr_pool_t *p, char *dummy)
211194
{
212-
php_conf_rec *newx =
213-
(php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
195+
php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
214196

215197
phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
216198
zend_hash_init(&newx->config, 0, NULL, NULL, 1);

sapi/apache2handler/php_apache.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ extern const command_rec php_dir_cmds[];
6363

6464
#define APR_ARRAY_FOREACH_CLOSE() }}
6565

66+
typedef struct {
67+
long engine;
68+
long xbithack;
69+
long last_modified;
70+
} php_apache2_info_struct;
71+
72+
extern zend_module_entry apache2_module_entry;
73+
74+
#ifdef ZTS
75+
extern int php_apache2_info_id;
76+
#define AP2(v) TSRMG(php_apache2_info_id, php_apache2_info_struct *, v)
77+
#else
78+
extern php_apache2_info_struct php_apache2_info;
79+
#define AP2(v) (php_apache2_info.v)
80+
#endif
81+
82+
6683
#endif /* PHP_APACHE_H */

sapi/apache2handler/php_functions.c

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "php.h"
2222
#include "ext/standard/php_smart_str.h"
2323
#include "ext/standard/info.h"
24+
#include "ext/standard/head.h"
25+
#include "php_ini.h"
2426
#include "SAPI.h"
2527

2628
#define CORE_PRIVATE
@@ -37,9 +39,20 @@
3739
#include "http_main.h"
3840
#include "util_script.h"
3941
#include "http_core.h"
42+
#if !defined(WIN32) && !defined(WINNT)
43+
#include "unixd.h"
44+
#endif
4045

4146
#include "php_apache.h"
4247

48+
#ifdef ZTS
49+
int php_apache2_info_id;
50+
#else
51+
php_apache2_info_struct php_apache2_info;
52+
#endif
53+
54+
#define SECTION(name) PUTS("<h2>" name "</h2>\n")
55+
4356
static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
4457
{
4558
php_struct *ctx;
@@ -52,7 +65,7 @@ static request_rec *php_apache_lookup_uri(char *filename TSRMLS_DC)
5265
return ap_sub_req_lookup_uri(filename, ctx->r, ctx->r->output_filters);
5366
}
5467

55-
/* proto bool virtual(string uri)
68+
/* {{{ proto bool virtual(string uri)
5669
Perform an apache sub-request */
5770
PHP_FUNCTION(virtual)
5871
{
@@ -89,7 +102,7 @@ PHP_FUNCTION(virtual)
89102
ap_destroy_sub_req(rr);
90103
RETURN_TRUE;
91104
}
92-
/* */
105+
/* }}} */
93106

94107
#define ADD_LONG(name) \
95108
add_property_long(return_value, #name, rr->name)
@@ -153,7 +166,7 @@ PHP_FUNCTION(apache_lookup_uri)
153166
RETURN_FALSE;
154167
}
155168

156-
/* proto array getallheaders(void)
169+
/* {{{ proto array getallheaders(void)
157170
Fetch all HTTP request headers */
158171
PHP_FUNCTION(apache_request_headers)
159172
{
@@ -171,7 +184,7 @@ PHP_FUNCTION(apache_request_headers)
171184
add_assoc_string(return_value, key, val, 1);
172185
APR_ARRAY_FOREACH_CLOSE()
173186
}
174-
/* */
187+
/* }}} */
175188

176189
/* {{{ proto array apache_response_headers(void)
177190
Fetch all HTTP response headers */
@@ -236,7 +249,7 @@ PHP_FUNCTION(apache_setenv)
236249
php_struct *ctx;
237250
zval **variable=NULL, **string_val=NULL, **walk_to_top=NULL;
238251
int arg_count = ZEND_NUM_ARGS();
239-
request_rec *r;
252+
request_rec *r;
240253

241254
if (arg_count<1 || arg_count>3 ||
242255
zend_get_parameters_ex(arg_count, &variable, &string_val, &walk_to_top) == FAILURE) {
@@ -272,7 +285,7 @@ PHP_FUNCTION(apache_getenv)
272285
zval **variable=NULL, **walk_to_top=NULL;
273286
int arg_count = ZEND_NUM_ARGS();
274287
char *env_val=NULL;
275-
request_rec *r;
288+
request_rec *r;
276289

277290
if (arg_count<1 || arg_count>2 ||
278291
zend_get_parameters_ex(arg_count, &variable, &walk_to_top) == FAILURE) {
@@ -281,7 +294,7 @@ PHP_FUNCTION(apache_getenv)
281294

282295
ctx = SG(server_context);
283296

284-
r = ctx->r;
297+
r = ctx->r;
285298
if (arg_count == 2 && Z_STRVAL_PP(walk_to_top)) {
286299
while(r->prev) {
287300
r = r->prev;
@@ -342,8 +355,15 @@ PHP_MINFO_FUNCTION(apache)
342355
{
343356
char *apv = php_apache_get_version();
344357
smart_str tmp1 = {0};
358+
char tmp[1024];
345359
int n;
346360
char *p;
361+
server_rec *serv = ((php_struct *) SG(server_context))->r->server;
362+
#if !defined(WIN32) && !defined(WINNT)
363+
AP_DECLARE_DATA extern unixd_config_rec unixd_config;
364+
#endif
365+
extern int ap_max_requests_per_child;
366+
AP_DECLARE_DATA extern const char *ap_server_root;
347367

348368
for (n = 0; ap_loaded_modules[n]; ++n) {
349369
char *s = (char *) ap_loaded_modules[n]->name;
@@ -362,9 +382,76 @@ PHP_MINFO_FUNCTION(apache)
362382
if (apv && *apv) {
363383
php_info_print_table_row(2, "Apache Version", apv);
364384
}
385+
sprintf(tmp, "%d", MODULE_MAGIC_NUMBER);
386+
php_info_print_table_row(2, "Apache API Version", tmp);
387+
388+
if (serv->server_admin && *(serv->server_admin)) {
389+
php_info_print_table_row(2, "Servert Administrator", serv->server_admin);
390+
}
391+
392+
sprintf(tmp, "%s:%u", serv->server_hostname, serv->port);
393+
php_info_print_table_row(2, "Hostname:Port", tmp);
394+
395+
#if !defined(WIN32) && !defined(WINNT)
396+
sprintf(tmp, "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);
397+
php_info_print_table_row(2, "User/Group", tmp);
398+
#endif
399+
400+
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);
401+
php_info_print_table_row(2, "Max Requests", tmp);
402+
403+
sprintf(tmp, "Connection: %lld - Keep-Alive: %lld", (serv->timeout / 1000000), (serv->keep_alive_timeout / 1000000));
404+
php_info_print_table_row(2, "Timeouts", tmp);
405+
406+
php_info_print_table_row(2, "Virtual Server", (serv->is_virtual ? "Yes" : "No"));
407+
php_info_print_table_row(2, "Server Root", ap_server_root);
365408
php_info_print_table_row(2, "Loaded Modules", tmp1.c);
409+
366410
smart_str_free(&tmp1);
367411
php_info_print_table_end();
412+
413+
DISPLAY_INI_ENTRIES();
414+
415+
{
416+
const apr_array_header_t *arr = apr_table_elts(((php_struct *) SG(server_context))->r->subprocess_env);
417+
char *key, *val;
418+
419+
SECTION("Apache Environment");
420+
php_info_print_table_start();
421+
php_info_print_table_header(2, "Variable", "Value");
422+
APR_ARRAY_FOREACH_OPEN(arr, key, val)
423+
if (!val) {
424+
val = empty_string;
425+
}
426+
php_info_print_table_row(2, key, val);
427+
APR_ARRAY_FOREACH_CLOSE()
428+
429+
php_info_print_table_end();
430+
431+
SECTION("HTTP Headers Information");
432+
php_info_print_table_start();
433+
php_info_print_table_colspan_header(2, "HTTP Request Headers");
434+
php_info_print_table_row(2, "HTTP Request", ((php_struct *) SG(server_context))->r->the_request);
435+
436+
arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_in);
437+
APR_ARRAY_FOREACH_OPEN(arr, key, val)
438+
if (!val) {
439+
val = empty_string;
440+
}
441+
php_info_print_table_row(2, key, val);
442+
APR_ARRAY_FOREACH_CLOSE()
443+
444+
php_info_print_table_colspan_header(2, "HTTP Response Headers");
445+
arr = apr_table_elts(((php_struct *) SG(server_context))->r->headers_out);
446+
APR_ARRAY_FOREACH_OPEN(arr, key, val)
447+
if (!val) {
448+
val = empty_string;
449+
}
450+
php_info_print_table_row(2, key, val);
451+
APR_ARRAY_FOREACH_CLOSE()
452+
453+
php_info_print_table_end();
454+
}
368455
}
369456

370457
static function_entry apache_functions[] = {
@@ -381,14 +468,32 @@ static function_entry apache_functions[] = {
381468
{NULL, NULL, NULL}
382469
};
383470

471+
PHP_INI_BEGIN()
472+
STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateInt, xbithack, php_apache2_info_struct, php_apache2_info)
473+
STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateInt, engine, php_apache2_info_struct, php_apache2_info)
474+
STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateInt, last_modified, php_apache2_info_struct, php_apache2_info)
475+
PHP_INI_END()
476+
477+
static PHP_MINIT_FUNCTION(apache)
478+
{
479+
REGISTER_INI_ENTRIES();
480+
return SUCCESS;
481+
}
482+
483+
static PHP_MSHUTDOWN_FUNCTION(apache)
484+
{
485+
UNREGISTER_INI_ENTRIES();
486+
return SUCCESS;
487+
}
488+
384489
zend_module_entry php_apache_module = {
385490
STANDARD_MODULE_HEADER,
386491
"Apache 2.0",
387492
apache_functions,
493+
PHP_MINIT(apache),
494+
PHP_MSHUTDOWN(apache),
388495
NULL,
389-
NULL,
390-
NULL,
391-
NULL,
496+
NULL,
392497
PHP_MINFO(apache),
393498
NULL,
394499
STANDARD_MODULE_PROPERTIES

0 commit comments

Comments
 (0)