2000-02-02 22:29:27 +08:00
|
|
|
|
/*
|
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
|
| PHP Version 5 |
|
2000-02-02 22:29:27 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
|
| Copyright (c) 1997-2004 The PHP Group |
|
2000-02-02 22:29:27 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
2000-02-02 22:29:27 +08:00
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
2000-02-02 22:29:27 +08:00
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
2003-03-18 20:06:09 +08:00
|
|
|
|
| Stig S<EFBFBD>ther Bakken <ssb@php.net> |
|
2000-02-02 22:29:27 +08:00
|
|
|
|
| David Sklar <sklar@student.net> |
|
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
/* $Id$ */
|
2000-02-17 01:46:14 +08:00
|
|
|
|
|
2000-02-11 04:24:28 +08:00
|
|
|
|
#include "php_apache_http.h"
|
2000-12-11 06:06:07 +08:00
|
|
|
|
|
2002-06-01 07:52:07 +08:00
|
|
|
|
#if defined(PHP_WIN32) || defined(NETWARE)
|
2000-04-30 12:15:26 +08:00
|
|
|
|
#include "zend.h"
|
|
|
|
|
#include "ap_compat.h"
|
|
|
|
|
#endif
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
2002-04-23 11:01:30 +08:00
|
|
|
|
#ifdef ZTS
|
|
|
|
|
int php_apache_info_id;
|
|
|
|
|
#else
|
|
|
|
|
php_apache_info_struct php_apache_info;
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-09-27 01:54:54 +08:00
|
|
|
|
#define SECTION(name) PUTS("<h2>" name "</h2>\n")
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
extern module *top_module;
|
2002-12-28 06:47:06 +08:00
|
|
|
|
extern module **ap_loaded_modules;
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(virtual);
|
2002-06-01 07:49:49 +08:00
|
|
|
|
PHP_FUNCTION(apache_request_headers);
|
|
|
|
|
PHP_FUNCTION(apache_response_headers);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
PHP_FUNCTION(apachelog);
|
|
|
|
|
PHP_FUNCTION(apache_note);
|
|
|
|
|
PHP_FUNCTION(apache_lookup_uri);
|
2000-12-13 21:19:56 +08:00
|
|
|
|
PHP_FUNCTION(apache_child_terminate);
|
2001-09-22 18:11:53 +08:00
|
|
|
|
PHP_FUNCTION(apache_setenv);
|
2002-12-28 06:47:06 +08:00
|
|
|
|
PHP_FUNCTION(apache_get_version);
|
|
|
|
|
PHP_FUNCTION(apache_get_modules);
|
2004-12-04 15:16:44 +08:00
|
|
|
|
PHP_FUNCTION(apache_reset_timeout);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
PHP_MINFO_FUNCTION(apache);
|
|
|
|
|
|
|
|
|
|
function_entry apache_functions[] = {
|
|
|
|
|
PHP_FE(virtual, NULL)
|
2002-06-01 07:49:49 +08:00
|
|
|
|
PHP_FE(apache_request_headers, NULL)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
PHP_FE(apache_note, NULL)
|
|
|
|
|
PHP_FE(apache_lookup_uri, NULL)
|
2000-12-13 21:19:56 +08:00
|
|
|
|
PHP_FE(apache_child_terminate, NULL)
|
2001-09-22 18:11:53 +08:00
|
|
|
|
PHP_FE(apache_setenv, NULL)
|
2002-06-01 07:49:49 +08:00
|
|
|
|
PHP_FE(apache_response_headers, NULL)
|
2002-12-28 06:47:06 +08:00
|
|
|
|
PHP_FE(apache_get_version, NULL)
|
|
|
|
|
PHP_FE(apache_get_modules, NULL)
|
2002-06-01 07:49:49 +08:00
|
|
|
|
PHP_FALIAS(getallheaders, apache_request_headers, NULL)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
2000-12-11 07:22:20 +08:00
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
PHP_INI_BEGIN()
|
2003-03-07 13:15:28 +08:00
|
|
|
|
STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info)
|
|
|
|
|
STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info)
|
|
|
|
|
STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info)
|
|
|
|
|
STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
PHP_INI_END()
|
|
|
|
|
|
2000-12-11 07:22:20 +08:00
|
|
|
|
|
2001-05-13 17:03:46 +08:00
|
|
|
|
|
2001-07-28 20:05:15 +08:00
|
|
|
|
static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
|
2001-05-13 17:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
apache_globals->in_request = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
static PHP_MINIT_FUNCTION(apache)
|
|
|
|
|
{
|
2000-12-11 07:22:20 +08:00
|
|
|
|
#ifdef ZTS
|
2002-06-01 18:27:51 +08:00
|
|
|
|
ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
|
2001-05-13 17:03:46 +08:00
|
|
|
|
#else
|
2001-07-27 18:16:41 +08:00
|
|
|
|
php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
|
2000-12-11 07:22:20 +08:00
|
|
|
|
#endif
|
2000-02-02 22:29:27 +08:00
|
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-11 07:22:20 +08:00
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
static PHP_MSHUTDOWN_FUNCTION(apache)
|
|
|
|
|
{
|
|
|
|
|
UNREGISTER_INI_ENTRIES();
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zend_module_entry apache_module_entry = {
|
2001-10-12 15:50:52 +08:00
|
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
|
"apache",
|
|
|
|
|
apache_functions,
|
|
|
|
|
PHP_MINIT(apache),
|
|
|
|
|
PHP_MSHUTDOWN(apache),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
PHP_MINFO(apache),
|
|
|
|
|
NO_VERSION_YET,
|
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
2000-02-02 22:29:27 +08:00
|
|
|
|
};
|
|
|
|
|
|
2002-08-13 12:03:20 +08:00
|
|
|
|
/* {{{ proto bool apache_child_terminate(void)
|
2001-12-15 22:23:07 +08:00
|
|
|
|
Terminate apache process after this request */
|
2000-12-13 21:19:56 +08:00
|
|
|
|
PHP_FUNCTION(apache_child_terminate)
|
|
|
|
|
{
|
2001-07-28 22:01:24 +08:00
|
|
|
|
#ifndef MULTITHREAD
|
2000-12-13 21:19:56 +08:00
|
|
|
|
if (AP(terminate_child)) {
|
|
|
|
|
ap_child_terminate( ((request_rec *)SG(server_context)) );
|
2002-04-23 19:40:19 +08:00
|
|
|
|
RETURN_TRUE;
|
2000-12-13 21:19:56 +08:00
|
|
|
|
} else { /* tell them to get lost! */
|
2003-01-04 05:33:31 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled");
|
2002-04-23 19:40:19 +08:00
|
|
|
|
RETURN_FALSE;
|
2000-12-13 21:19:56 +08:00
|
|
|
|
}
|
2001-01-06 01:00:07 +08:00
|
|
|
|
#else
|
2003-01-04 05:33:31 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build");
|
2002-04-23 19:40:19 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-01-06 01:00:07 +08:00
|
|
|
|
#endif
|
2000-12-13 21:19:56 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
/* {{{ proto string apache_note(string note_name [, string note_value])
|
|
|
|
|
Get and set Apache request notes */
|
|
|
|
|
PHP_FUNCTION(apache_note)
|
|
|
|
|
{
|
2001-08-05 09:43:02 +08:00
|
|
|
|
pval **arg_name, **arg_val;
|
2000-02-02 22:29:27 +08:00
|
|
|
|
char *note_val;
|
2003-01-21 22:56:40 +08:00
|
|
|
|
int arg_count = ZEND_NUM_ARGS();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
if (arg_count<1 || arg_count>2 ||
|
2001-08-05 09:43:02 +08:00
|
|
|
|
zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
convert_to_string_ex(arg_name);
|
2001-09-28 04:01:23 +08:00
|
|
|
|
note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
if (arg_count == 2) {
|
|
|
|
|
convert_to_string_ex(arg_val);
|
2001-09-28 04:01:23 +08:00
|
|
|
|
table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (note_val) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
RETURN_STRING(note_val, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
|
*/
|
2000-02-02 22:29:27 +08:00
|
|
|
|
PHP_MINFO_FUNCTION(apache)
|
|
|
|
|
{
|
2003-09-10 05:38:31 +08:00
|
|
|
|
char *apv = (char *) ap_get_server_version();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
module *modp = NULL;
|
|
|
|
|
char output_buf[128];
|
|
|
|
|
#if !defined(WIN32) && !defined(WINNT)
|
|
|
|
|
char name[64];
|
2000-04-08 00:41:19 +08:00
|
|
|
|
char modulenames[1024];
|
2000-02-02 22:29:27 +08:00
|
|
|
|
char *p;
|
|
|
|
|
#endif
|
|
|
|
|
server_rec *serv;
|
|
|
|
|
extern char server_root[MAX_STRING_LEN];
|
|
|
|
|
extern uid_t user_id;
|
|
|
|
|
extern char *user_name;
|
|
|
|
|
extern gid_t group_id;
|
|
|
|
|
extern int max_requests_per_child;
|
|
|
|
|
|
|
|
|
|
serv = ((request_rec *) SG(server_context))->server;
|
|
|
|
|
|
2001-05-17 21:31:45 +08:00
|
|
|
|
|
2000-10-14 03:08:05 +08:00
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
|
2000-06-16 07:45:05 +08:00
|
|
|
|
#ifdef PHP_WIN32
|
2000-10-14 03:08:05 +08:00
|
|
|
|
php_info_print_table_row(1, "Apache for Windows 95/NT");
|
|
|
|
|
php_info_print_table_end();
|
2000-04-08 00:41:19 +08:00
|
|
|
|
php_info_print_table_start();
|
2002-06-02 01:38:23 +08:00
|
|
|
|
#elif defined(NETWARE)
|
2002-06-01 17:54:28 +08:00
|
|
|
|
php_info_print_table_row(1, "Apache for NetWare");
|
|
|
|
|
php_info_print_table_end();
|
|
|
|
|
php_info_print_table_start();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
#else
|
|
|
|
|
php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
|
|
|
|
|
php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
|
|
|
|
|
#endif
|
2000-04-08 00:41:19 +08:00
|
|
|
|
|
2003-09-10 05:30:48 +08:00
|
|
|
|
if (apv && *apv) {
|
|
|
|
|
php_info_print_table_row(2, "Apache Version", apv);
|
|
|
|
|
}
|
2000-04-08 00:41:19 +08:00
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
#ifdef APACHE_RELEASE
|
|
|
|
|
sprintf(output_buf, "%d", APACHE_RELEASE);
|
|
|
|
|
php_info_print_table_row(2, "Apache Release", output_buf);
|
|
|
|
|
#endif
|
|
|
|
|
sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
|
|
|
|
|
php_info_print_table_row(2, "Apache API Version", output_buf);
|
2001-08-05 09:43:02 +08:00
|
|
|
|
sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port);
|
2000-04-08 00:41:19 +08:00
|
|
|
|
php_info_print_table_row(2, "Hostname:Port", output_buf);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
#if !defined(WIN32) && !defined(WINNT)
|
2001-08-05 09:43:02 +08:00
|
|
|
|
sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, "User/Group", output_buf);
|
2001-10-09 17:41:10 +08:00
|
|
|
|
sprintf(output_buf, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, "Max Requests", output_buf);
|
|
|
|
|
#endif
|
2001-10-09 17:41:10 +08:00
|
|
|
|
sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, "Timeouts", output_buf);
|
|
|
|
|
#if !defined(WIN32) && !defined(WINNT)
|
2002-06-01 17:54:28 +08:00
|
|
|
|
/*
|
|
|
|
|
This block seems to be working on NetWare; But it seems to be showing
|
|
|
|
|
all modules instead of just the loaded ones
|
|
|
|
|
*/
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, "Server Root", server_root);
|
|
|
|
|
|
2000-04-08 01:09:18 +08:00
|
|
|
|
strcpy(modulenames, "");
|
2000-02-02 22:29:27 +08:00
|
|
|
|
for(modp = top_module; modp; modp = modp->next) {
|
|
|
|
|
strlcpy(name, modp->name, sizeof(name));
|
|
|
|
|
if ((p = strrchr(name, '.'))) {
|
|
|
|
|
*p='\0'; /* Cut off ugly .c extensions on module names */
|
|
|
|
|
}
|
2000-04-08 01:04:57 +08:00
|
|
|
|
strcat(modulenames, name);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
if (modp->next) {
|
2000-04-08 01:04:57 +08:00
|
|
|
|
strcat(modulenames, ", ");
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-08 00:41:19 +08:00
|
|
|
|
php_info_print_table_row(2, "Loaded Modules", modulenames);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
#endif
|
2000-04-08 00:41:19 +08:00
|
|
|
|
|
|
|
|
|
php_info_print_table_end();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
2001-05-17 21:31:45 +08:00
|
|
|
|
DISPLAY_INI_ENTRIES();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
register int i;
|
|
|
|
|
array_header *arr;
|
|
|
|
|
table_entry *elts;
|
|
|
|
|
request_rec *r;
|
|
|
|
|
|
|
|
|
|
r = ((request_rec *) SG(server_context));
|
|
|
|
|
arr = table_elts(r->subprocess_env);
|
|
|
|
|
elts = (table_entry *)arr->elts;
|
|
|
|
|
|
2000-04-08 00:41:19 +08:00
|
|
|
|
SECTION("Apache Environment");
|
|
|
|
|
php_info_print_table_start();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_header(2, "Variable", "Value");
|
|
|
|
|
for (i=0; i < arr->nelts; i++) {
|
|
|
|
|
php_info_print_table_row(2, elts[i].key, elts[i].val);
|
|
|
|
|
}
|
2000-04-08 00:41:19 +08:00
|
|
|
|
php_info_print_table_end();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
array_header *env_arr;
|
|
|
|
|
table_entry *env;
|
|
|
|
|
int i;
|
|
|
|
|
request_rec *r;
|
|
|
|
|
|
|
|
|
|
r = ((request_rec *) SG(server_context));
|
|
|
|
|
SECTION("HTTP Headers Information");
|
2000-04-08 00:46:59 +08:00
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_colspan_header(2, "HTTP Request Headers");
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, "HTTP Request", r->the_request);
|
|
|
|
|
env_arr = table_elts(r->headers_in);
|
|
|
|
|
env = (table_entry *)env_arr->elts;
|
|
|
|
|
for (i = 0; i < env_arr->nelts; ++i) {
|
2001-10-21 08:03:55 +08:00
|
|
|
|
if (env[i].key && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
php_info_print_table_row(2, env[i].key, env[i].val);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-08 00:46:59 +08:00
|
|
|
|
php_info_print_table_colspan_header(2, "HTTP Response Headers");
|
2000-02-02 22:29:27 +08:00
|
|
|
|
env_arr = table_elts(r->headers_out);
|
|
|
|
|
env = (table_entry *)env_arr->elts;
|
|
|
|
|
for(i = 0; i < env_arr->nelts; ++i) {
|
|
|
|
|
if (env[i].key) {
|
|
|
|
|
php_info_print_table_row(2, env[i].key, env[i].val);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-08 00:41:19 +08:00
|
|
|
|
php_info_print_table_end();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
|
/* }}} */
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
2002-04-23 19:40:19 +08:00
|
|
|
|
/* {{{ proto bool virtual(string filename)
|
2001-06-06 21:06:12 +08:00
|
|
|
|
Perform an Apache sub-request */
|
2000-02-02 22:29:27 +08:00
|
|
|
|
/* This function is equivalent to <!--#include virtual...-->
|
|
|
|
|
* in mod_include. It does an Apache sub-request. It is useful
|
|
|
|
|
* for including CGI scripts or .shtml files, or anything else
|
|
|
|
|
* that you'd parse through Apache (for .phtml files, you'd probably
|
|
|
|
|
* want to use <?Include>. This only works when PHP is compiled
|
|
|
|
|
* as an Apache module, since it uses the Apache API for doing
|
|
|
|
|
* sub requests.
|
|
|
|
|
*/
|
|
|
|
|
PHP_FUNCTION(virtual)
|
|
|
|
|
{
|
|
|
|
|
pval **filename;
|
|
|
|
|
request_rec *rr = NULL;
|
|
|
|
|
|
2003-01-21 22:56:40 +08:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
|
2001-09-28 04:01:23 +08:00
|
|
|
|
if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
|
2002-12-06 07:18:28 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
if (rr) destroy_sub_req (rr);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rr->status != 200) {
|
2002-12-06 07:18:28 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
if (rr) destroy_sub_req (rr);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-05 23:29:47 +08:00
|
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
2003-03-25 16:07:13 +08:00
|
|
|
|
php_header(TSRMLS_C);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
if (run_sub_req(rr)) {
|
2002-12-06 07:18:28 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
if (rr) destroy_sub_req (rr);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
if (rr) destroy_sub_req (rr);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto array getallheaders(void)
|
2002-06-01 07:49:49 +08:00
|
|
|
|
Alias for apache_request_headers() */
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ proto array apache_request_headers(void)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
Fetch all HTTP request headers */
|
2002-06-01 07:49:49 +08:00
|
|
|
|
PHP_FUNCTION(apache_request_headers)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
{
|
|
|
|
|
array_header *env_arr;
|
|
|
|
|
table_entry *tenv;
|
|
|
|
|
int i;
|
|
|
|
|
|
2003-01-19 04:27:05 +08:00
|
|
|
|
array_init(return_value);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
|
|
|
|
|
tenv = (table_entry *)env_arr->elts;
|
|
|
|
|
for (i = 0; i < env_arr->nelts; ++i) {
|
|
|
|
|
if (!tenv[i].key ||
|
|
|
|
|
(PG(safe_mode) &&
|
|
|
|
|
!strncasecmp(tenv[i].key, "authorization", 13))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2001-08-05 09:43:02 +08:00
|
|
|
|
if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-06-01 07:49:49 +08:00
|
|
|
|
/* {{{ proto array apache_response_headers(void)
|
|
|
|
|
Fetch all HTTP response headers */
|
|
|
|
|
PHP_FUNCTION(apache_response_headers)
|
|
|
|
|
{
|
|
|
|
|
array_header *env_arr;
|
|
|
|
|
table_entry *tenv;
|
|
|
|
|
int i;
|
|
|
|
|
|
2003-01-19 04:27:05 +08:00
|
|
|
|
array_init(return_value);
|
2002-06-01 07:49:49 +08:00
|
|
|
|
env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
|
|
|
|
|
tenv = (table_entry *)env_arr->elts;
|
|
|
|
|
for (i = 0; i < env_arr->nelts; ++i) {
|
|
|
|
|
if (!tenv[i].key) continue;
|
|
|
|
|
if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-04-23 19:40:19 +08:00
|
|
|
|
/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
|
2001-09-22 18:11:53 +08:00
|
|
|
|
Set an Apache subprocess_env variable */
|
|
|
|
|
PHP_FUNCTION(apache_setenv)
|
|
|
|
|
{
|
|
|
|
|
int var_len, val_len, top=0;
|
|
|
|
|
char *var = NULL, *val = NULL;
|
|
|
|
|
request_rec *r = (request_rec *) SG(server_context);
|
|
|
|
|
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(top) {
|
|
|
|
|
if(r->prev) r = r->prev;
|
|
|
|
|
else break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len));
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2002-04-23 19:40:19 +08:00
|
|
|
|
/* {{{ proto object apache_lookup_uri(string URI)
|
2000-02-02 22:29:27 +08:00
|
|
|
|
Perform a partial request of the given URI to obtain information about it */
|
|
|
|
|
PHP_FUNCTION(apache_lookup_uri)
|
|
|
|
|
{
|
|
|
|
|
pval **filename;
|
|
|
|
|
request_rec *rr=NULL;
|
|
|
|
|
|
2003-01-21 22:56:40 +08:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
|
2001-09-28 04:01:23 +08:00
|
|
|
|
if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
|
2003-08-29 01:48:58 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", (*filename)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
object_init(return_value);
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_long(return_value,"status", rr->status);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
if (rr->the_request) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"the_request", rr->the_request, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->status_line) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->method) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"method", (char *)rr->method, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->content_type) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->handler) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"handler", (char *)rr->handler, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->uri) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"uri", rr->uri, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->filename) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"filename", rr->filename, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->path_info) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"path_info", rr->path_info, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->args) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"args", rr->args, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (rr->boundary) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"boundary", rr->boundary, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_long(return_value,"no_cache", rr->no_cache);
|
|
|
|
|
add_property_long(return_value,"no_local_copy", rr->no_local_copy);
|
|
|
|
|
add_property_long(return_value,"allowed", rr->allowed);
|
|
|
|
|
add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
|
|
|
|
|
add_property_long(return_value,"bytes_sent", rr->bytes_sent);
|
|
|
|
|
add_property_long(return_value,"byterange", rr->byterange);
|
|
|
|
|
add_property_long(return_value,"clength", rr->clength);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
|
|
|
|
#if MODULE_MAGIC_NUMBER >= 19980324
|
|
|
|
|
if (rr->unparsed_uri) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
if(rr->mtime) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_long(return_value,"mtime", rr->mtime);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if(rr->request_time) {
|
2001-08-05 09:43:02 +08:00
|
|
|
|
add_property_long(return_value,"request_time", rr->request_time);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
destroy_sub_req(rr);
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
This function is most likely a bad idea. Just playing with it for now.
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(apache_exec_uri)
|
|
|
|
|
{
|
|
|
|
|
pval **filename;
|
|
|
|
|
request_rec *rr=NULL;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
2000-02-02 22:29:27 +08:00
|
|
|
|
|
2003-01-21 22:56:40 +08:00
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
|
2000-02-02 22:29:27 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
|
2001-09-28 04:01:23 +08:00
|
|
|
|
if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
|
2002-12-06 07:18:28 +08:00
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", (*filename)->value.str.val);
|
2000-02-02 22:29:27 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETVAL_LONG(ap_run_sub_req(rr));
|
|
|
|
|
ap_destroy_sub_req(rr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-12-28 06:47:06 +08:00
|
|
|
|
/* {{{ proto string apache_get_version(void)
|
|
|
|
|
Fetch Apache version */
|
|
|
|
|
PHP_FUNCTION(apache_get_version)
|
|
|
|
|
{
|
2002-12-28 07:05:15 +08:00
|
|
|
|
char *apv = (char *) ap_get_server_version();
|
|
|
|
|
|
|
|
|
|
if (apv && *apv) {
|
|
|
|
|
RETURN_STRING(apv, 1);
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2002-12-28 06:47:06 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto array apache_get_modules(void)
|
|
|
|
|
Get a list of loaded Apache modules */
|
|
|
|
|
PHP_FUNCTION(apache_get_modules)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
|
|
|
|
|
for (n = 0; ap_loaded_modules[n]; ++n) {
|
|
|
|
|
char *s = (char *) ap_loaded_modules[n]->name;
|
|
|
|
|
if ((p = strchr(s, '.'))) {
|
|
|
|
|
add_next_index_stringl(return_value, s, (p - s), 1);
|
|
|
|
|
} else {
|
|
|
|
|
add_next_index_string(return_value, s, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2004-12-04 15:16:44 +08:00
|
|
|
|
/* {{{ proto array apache_reset_timeout(void)
|
|
|
|
|
Reset the Apache write timer */
|
|
|
|
|
PHP_FUNCTION(apache_reset_timeout)
|
|
|
|
|
{
|
|
|
|
|
if (PG(safe_mode)) {
|
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot reset the Apache timeout in safe mode");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ap_reset_timeout((request_rec *)SG(server_context));
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2000-02-02 22:29:27 +08:00
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
|
* vim<600: sw=4 ts=4
|
2000-02-02 22:29:27 +08:00
|
|
|
|
*/
|