1999-07-16 21:13:16 +08:00
|
|
|
/*
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2008-12-31 19:15:49 +08:00
|
|
|
| Copyright (c) 1997-2009 The PHP Group |
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-07-16 21:13:16 +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: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-07-16 21:13:16 +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. |
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-02-11 04:13:08 +08:00
|
|
|
| Original design: Shane Caraveo <shane@caraveo.com> |
|
1999-05-07 05:58:49 +08:00
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2001-11-25 07:38:08 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
1999-05-30 00:20:55 +08:00
|
|
|
#include <ctype.h>
|
2000-02-11 01:26:57 +08:00
|
|
|
#include <sys/stat.h>
|
1999-05-07 05:58:49 +08:00
|
|
|
|
1999-09-06 03:04:40 +08:00
|
|
|
#include "php.h"
|
1999-04-26 03:36:57 +08:00
|
|
|
#include "SAPI.h"
|
2006-05-11 05:19:32 +08:00
|
|
|
#include "php_variables.h"
|
2003-02-11 03:04:44 +08:00
|
|
|
#include "php_ini.h"
|
2001-10-21 06:01:56 +08:00
|
|
|
#include "ext/standard/php_string.h"
|
|
|
|
#include "ext/standard/pageinfo.h"
|
2002-07-13 08:15:22 +08:00
|
|
|
#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
|
2001-10-21 06:01:56 +08:00
|
|
|
#include "ext/pcre/php_pcre.h"
|
2001-10-22 01:41:15 +08:00
|
|
|
#endif
|
2003-02-11 03:04:44 +08:00
|
|
|
#if HAVE_ZLIB
|
2002-07-28 22:08:08 +08:00
|
|
|
#include "ext/zlib/php_zlib.h"
|
|
|
|
#endif
|
1999-04-26 22:00:49 +08:00
|
|
|
#ifdef ZTS
|
1999-04-26 03:36:57 +08:00
|
|
|
#include "TSRM.h"
|
1999-04-26 22:00:49 +08:00
|
|
|
#endif
|
2004-08-11 01:40:00 +08:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
1999-04-26 03:36:57 +08:00
|
|
|
|
1999-05-26 06:28:24 +08:00
|
|
|
#include "rfc1867.h"
|
|
|
|
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-05-06 02:25:20 +08:00
|
|
|
#define STRCASECMP stricmp
|
|
|
|
#else
|
|
|
|
#define STRCASECMP strcasecmp
|
|
|
|
#endif
|
|
|
|
|
2000-07-05 16:57:37 +08:00
|
|
|
#include "php_content_types.h"
|
1999-04-26 03:36:57 +08:00
|
|
|
|
|
|
|
#ifdef ZTS
|
1999-04-26 22:00:49 +08:00
|
|
|
SAPI_API int sapi_globals_id;
|
1999-04-27 01:26:37 +08:00
|
|
|
#else
|
|
|
|
sapi_globals_struct sapi_globals;
|
1999-04-26 03:36:57 +08:00
|
|
|
#endif
|
|
|
|
|
2001-07-27 18:16:41 +08:00
|
|
|
static void sapi_globals_ctor(sapi_globals_struct *sapi_globals TSRMLS_DC)
|
2000-03-06 05:37:47 +08:00
|
|
|
{
|
2001-07-28 19:36:37 +08:00
|
|
|
memset(sapi_globals, 0, sizeof(*sapi_globals));
|
2005-02-22 04:57:18 +08:00
|
|
|
zend_hash_init_ex(&sapi_globals->known_post_content_types, 5, NULL, NULL, 1, 0);
|
2005-03-06 00:41:13 +08:00
|
|
|
php_setup_sapi_content_types(TSRMLS_C);
|
2005-02-21 23:14:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sapi_globals_dtor(sapi_globals_struct *sapi_globals TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_hash_destroy(&sapi_globals->known_post_content_types);
|
2000-03-06 05:37:47 +08:00
|
|
|
}
|
|
|
|
|
1999-05-07 05:58:49 +08:00
|
|
|
/* True globals (no need for thread safety) */
|
2001-01-03 06:49:31 +08:00
|
|
|
SAPI_API sapi_module_struct sapi_module;
|
1999-04-26 03:36:57 +08:00
|
|
|
|
1999-05-06 02:25:20 +08:00
|
|
|
|
1999-05-03 02:07:41 +08:00
|
|
|
SAPI_API void sapi_startup(sapi_module_struct *sf)
|
1999-04-26 03:36:57 +08:00
|
|
|
{
|
2006-09-20 04:33:12 +08:00
|
|
|
sf->ini_entries = NULL;
|
1999-05-03 02:07:41 +08:00
|
|
|
sapi_module = *sf;
|
1999-09-17 07:18:15 +08:00
|
|
|
|
1999-04-26 03:36:57 +08:00
|
|
|
#ifdef ZTS
|
2005-02-21 23:14:02 +08:00
|
|
|
ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
|
2000-03-17 05:23:24 +08:00
|
|
|
#else
|
2005-02-22 04:57:18 +08:00
|
|
|
sapi_globals_ctor(&sapi_globals);
|
1999-04-26 03:36:57 +08:00
|
|
|
#endif
|
2000-03-17 05:23:24 +08:00
|
|
|
|
2000-04-03 03:04:59 +08:00
|
|
|
virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
|
|
|
|
|
2001-04-28 00:41:53 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
tsrm_win32_startup();
|
|
|
|
#endif
|
|
|
|
|
2000-01-06 03:25:19 +08:00
|
|
|
reentrancy_startup();
|
1999-09-04 01:46:39 +08:00
|
|
|
}
|
1999-05-06 02:25:20 +08:00
|
|
|
|
1999-12-06 00:25:32 +08:00
|
|
|
SAPI_API void sapi_shutdown(void)
|
1999-05-29 06:41:48 +08:00
|
|
|
{
|
2005-02-21 23:14:02 +08:00
|
|
|
#ifdef ZTS
|
2005-02-22 13:07:37 +08:00
|
|
|
ts_free_id(sapi_globals_id);
|
2005-02-21 23:14:02 +08:00
|
|
|
#else
|
2005-02-22 04:57:18 +08:00
|
|
|
sapi_globals_dtor(&sapi_globals);
|
2005-02-21 23:14:02 +08:00
|
|
|
#endif
|
|
|
|
|
2000-01-06 03:25:19 +08:00
|
|
|
reentrancy_shutdown();
|
2004-10-05 08:42:25 +08:00
|
|
|
|
2000-04-03 04:26:06 +08:00
|
|
|
virtual_cwd_shutdown();
|
2001-04-28 00:41:53 +08:00
|
|
|
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
tsrm_win32_shutdown();
|
|
|
|
#endif
|
1999-05-29 06:41:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-10 20:38:20 +08:00
|
|
|
SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
|
1999-05-06 02:25:20 +08:00
|
|
|
{
|
|
|
|
efree(sapi_header->header);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
|
2000-02-18 04:23:59 +08:00
|
|
|
{
|
2001-03-18 16:00:10 +08:00
|
|
|
if (SG(request_info).post_entry && SG(request_info).content_type_dup) {
|
2001-07-28 19:36:37 +08:00
|
|
|
SG(request_info).post_entry->post_handler(SG(request_info).content_type_dup, arg TSRMLS_CC);
|
2000-09-09 23:02:15 +08:00
|
|
|
if (SG(request_info).post_data) {
|
|
|
|
efree(SG(request_info).post_data);
|
|
|
|
SG(request_info).post_data = NULL;
|
|
|
|
}
|
2000-02-18 04:23:59 +08:00
|
|
|
efree(SG(request_info).content_type_dup);
|
|
|
|
SG(request_info).content_type_dup = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
static void sapi_read_post_data(TSRMLS_D)
|
1999-05-26 05:14:54 +08:00
|
|
|
{
|
2000-02-18 04:23:59 +08:00
|
|
|
sapi_post_entry *post_entry;
|
1999-05-26 05:14:54 +08:00
|
|
|
uint content_type_length = strlen(SG(request_info).content_type);
|
|
|
|
char *content_type = estrndup(SG(request_info).content_type, content_type_length);
|
1999-05-26 06:28:24 +08:00
|
|
|
char *p;
|
|
|
|
char oldchar=0;
|
2002-10-22 00:41:06 +08:00
|
|
|
void (*post_reader_func)(TSRMLS_D) = NULL;
|
1999-09-17 07:18:15 +08:00
|
|
|
|
1999-05-26 06:28:24 +08:00
|
|
|
|
|
|
|
/* dedicated implementation for increased performance:
|
|
|
|
* - Make the content type lowercase
|
|
|
|
* - Trim descriptive data, stay with the content-type only
|
|
|
|
*/
|
|
|
|
for (p=content_type; p<content_type+content_type_length; p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case ';':
|
|
|
|
case ',':
|
|
|
|
case ' ':
|
|
|
|
content_type_length = p-content_type;
|
|
|
|
oldchar = *p;
|
|
|
|
*p = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*p = tolower(*p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-05-26 05:14:54 +08:00
|
|
|
|
2002-11-08 16:41:52 +08:00
|
|
|
/* now try to find an appropriate POST content handler */
|
2005-02-21 23:14:02 +08:00
|
|
|
if (zend_hash_find(&SG(known_post_content_types), content_type,
|
|
|
|
content_type_length+1, (void **) &post_entry) == SUCCESS) {
|
2002-11-08 16:41:52 +08:00
|
|
|
/* found one, register it for use */
|
2000-02-18 04:23:59 +08:00
|
|
|
SG(request_info).post_entry = post_entry;
|
|
|
|
post_reader_func = post_entry->post_reader;
|
1999-09-17 07:18:15 +08:00
|
|
|
} else {
|
2002-11-08 16:41:52 +08:00
|
|
|
/* fallback */
|
|
|
|
SG(request_info).post_entry = NULL;
|
1999-09-17 07:18:15 +08:00
|
|
|
if (!sapi_module.default_post_reader) {
|
2002-11-08 16:41:52 +08:00
|
|
|
/* no default reader ? */
|
2003-11-23 05:10:47 +08:00
|
|
|
SG(request_info).content_type_dup = NULL;
|
2000-09-09 23:02:15 +08:00
|
|
|
sapi_module.sapi_error(E_WARNING, "Unsupported content type: '%s'", content_type);
|
1999-09-17 07:18:15 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-05-26 05:14:54 +08:00
|
|
|
}
|
1999-05-26 06:28:24 +08:00
|
|
|
if (oldchar) {
|
|
|
|
*(p-1) = oldchar;
|
|
|
|
}
|
2001-09-03 10:31:56 +08:00
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
SG(request_info).content_type_dup = content_type;
|
2001-09-03 10:31:56 +08:00
|
|
|
|
|
|
|
if(post_reader_func) {
|
|
|
|
post_reader_func(TSRMLS_C);
|
2002-10-22 00:41:06 +08:00
|
|
|
}
|
2001-09-03 10:31:56 +08:00
|
|
|
|
2002-11-13 02:29:11 +08:00
|
|
|
if(sapi_module.default_post_reader) {
|
2002-10-22 00:41:06 +08:00
|
|
|
sapi_module.default_post_reader(TSRMLS_C);
|
2001-07-18 00:46:07 +08:00
|
|
|
}
|
1999-05-26 05:14:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-16 02:01:48 +08:00
|
|
|
SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
|
1999-05-10 02:40:59 +08:00
|
|
|
{
|
2000-04-01 09:11:39 +08:00
|
|
|
int read_bytes;
|
1999-05-10 02:40:59 +08:00
|
|
|
int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
|
|
|
|
|
2000-09-09 23:02:15 +08:00
|
|
|
if (SG(request_info).content_length > SG(post_max_size)) {
|
2003-08-29 01:07:40 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",
|
2000-09-09 23:02:15 +08:00
|
|
|
SG(request_info).content_length, SG(post_max_size));
|
|
|
|
return;
|
|
|
|
}
|
1999-05-10 02:40:59 +08:00
|
|
|
SG(request_info).post_data = emalloc(allocated_bytes);
|
|
|
|
|
|
|
|
for (;;) {
|
2001-07-28 19:36:37 +08:00
|
|
|
read_bytes = sapi_module.read_post(SG(request_info).post_data+SG(read_post_bytes), SAPI_POST_BLOCK_SIZE TSRMLS_CC);
|
1999-05-10 02:40:59 +08:00
|
|
|
if (read_bytes<=0) {
|
|
|
|
break;
|
|
|
|
}
|
2000-04-01 09:11:39 +08:00
|
|
|
SG(read_post_bytes) += read_bytes;
|
2000-09-09 23:02:15 +08:00
|
|
|
if (SG(read_post_bytes) > SG(post_max_size)) {
|
2003-08-29 01:07:40 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size));
|
2004-05-26 06:12:40 +08:00
|
|
|
break;
|
2000-09-09 23:02:15 +08:00
|
|
|
}
|
1999-05-10 02:40:59 +08:00
|
|
|
if (read_bytes < SAPI_POST_BLOCK_SIZE) {
|
|
|
|
break;
|
|
|
|
}
|
2000-04-01 09:11:39 +08:00
|
|
|
if (SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE >= allocated_bytes) {
|
|
|
|
allocated_bytes = SG(read_post_bytes)+SAPI_POST_BLOCK_SIZE+1;
|
1999-05-10 02:40:59 +08:00
|
|
|
SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes);
|
|
|
|
}
|
|
|
|
}
|
2000-04-01 09:11:39 +08:00
|
|
|
SG(request_info).post_data[SG(read_post_bytes)] = 0; /* terminating NULL */
|
|
|
|
SG(request_info).post_data_length = SG(read_post_bytes);
|
1999-05-10 02:40:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API char *sapi_get_default_content_type(TSRMLS_D)
|
2000-02-26 05:27:03 +08:00
|
|
|
{
|
|
|
|
char *mimetype, *charset, *content_type;
|
|
|
|
|
|
|
|
mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
|
|
|
|
charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
|
|
|
|
|
2000-02-26 22:29:27 +08:00
|
|
|
if (strncasecmp(mimetype, "text/", 5) == 0 && *charset) {
|
2002-08-03 22:09:56 +08:00
|
|
|
int len = strlen(mimetype) + sizeof("; charset=") + strlen(charset); /* sizeof() includes \0 */
|
2000-02-26 05:27:03 +08:00
|
|
|
content_type = emalloc(len);
|
2000-02-26 13:03:41 +08:00
|
|
|
snprintf(content_type, len, "%s; charset=%s", mimetype, charset);
|
2000-02-26 05:27:03 +08:00
|
|
|
} else {
|
|
|
|
content_type = estrdup(mimetype);
|
|
|
|
}
|
|
|
|
return content_type;
|
|
|
|
}
|
|
|
|
|
2000-02-26 13:03:41 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header TSRMLS_DC)
|
2000-02-26 13:03:41 +08:00
|
|
|
{
|
2001-07-28 19:36:37 +08:00
|
|
|
char *default_content_type = sapi_get_default_content_type(TSRMLS_C);
|
2000-02-26 13:03:41 +08:00
|
|
|
int default_content_type_len = strlen(default_content_type);
|
|
|
|
|
|
|
|
default_header->header_len = (sizeof("Content-type: ")-1) + default_content_type_len;
|
|
|
|
default_header->header = emalloc(default_header->header_len+1);
|
|
|
|
memcpy(default_header->header, "Content-type: ", sizeof("Content-type: "));
|
|
|
|
memcpy(default_header->header+sizeof("Content-type: ")-1, default_content_type, default_content_type_len);
|
|
|
|
default_header->header[default_header->header_len] = 0;
|
2000-02-26 22:21:10 +08:00
|
|
|
efree(default_content_type);
|
2000-02-26 13:03:41 +08:00
|
|
|
}
|
|
|
|
|
2000-02-25 06:00:47 +08:00
|
|
|
/*
|
2000-02-26 05:27:03 +08:00
|
|
|
* Add charset on content-type header if the MIME type starts with
|
2000-02-26 22:29:27 +08:00
|
|
|
* "text/", the default_charset directive is not empty and
|
2000-02-26 05:27:03 +08:00
|
|
|
* there is not already a charset option in there.
|
|
|
|
*
|
|
|
|
* If "mimetype" is non-NULL, it should point to a pointer allocated
|
|
|
|
* with emalloc(). If a charset is added, the string will be
|
|
|
|
* re-allocated and the new length is returned. If mimetype is
|
|
|
|
* unchanged, 0 is returned.
|
|
|
|
*
|
2000-02-25 06:00:47 +08:00
|
|
|
*/
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC)
|
1999-05-06 02:25:20 +08:00
|
|
|
{
|
2000-02-26 05:27:03 +08:00
|
|
|
char *charset, *newtype;
|
2000-10-21 03:10:27 +08:00
|
|
|
size_t newlen;
|
2000-02-26 05:27:03 +08:00
|
|
|
charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
|
|
|
|
|
2002-08-06 02:32:05 +08:00
|
|
|
if (*mimetype != NULL) {
|
|
|
|
if (*charset && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) {
|
|
|
|
newlen = len + (sizeof(";charset=")-1) + strlen(charset);
|
|
|
|
newtype = emalloc(newlen + 1);
|
|
|
|
PHP_STRLCPY(newtype, *mimetype, newlen + 1, len);
|
|
|
|
strlcat(newtype, ";charset=", newlen + 1);
|
2002-09-08 09:06:29 +08:00
|
|
|
strlcat(newtype, charset, newlen + 1);
|
2000-02-26 05:27:03 +08:00
|
|
|
efree(*mimetype);
|
2002-08-06 02:32:05 +08:00
|
|
|
*mimetype = newtype;
|
|
|
|
return newlen;
|
2000-02-26 05:27:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-02-25 06:00:47 +08:00
|
|
|
|
2002-11-18 08:59:23 +08:00
|
|
|
SAPI_API void sapi_activate_headers_only(TSRMLS_D)
|
|
|
|
{
|
2003-01-15 19:30:39 +08:00
|
|
|
if (SG(request_info).headers_read == 1)
|
|
|
|
return;
|
|
|
|
SG(request_info).headers_read = 1;
|
|
|
|
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct),
|
|
|
|
(void (*)(void *)) sapi_free_header, 0);
|
|
|
|
SG(sapi_headers).send_default_content_type = 1;
|
|
|
|
|
|
|
|
/* SG(sapi_headers).http_response_code = 200; */
|
|
|
|
SG(sapi_headers).http_status_line = NULL;
|
2007-12-04 00:04:36 +08:00
|
|
|
SG(sapi_headers).mimetype = NULL;
|
2004-11-28 21:32:29 +08:00
|
|
|
SG(read_post_bytes) = 0;
|
|
|
|
SG(request_info).post_data = NULL;
|
|
|
|
SG(request_info).raw_post_data = NULL;
|
2003-01-15 19:30:39 +08:00
|
|
|
SG(request_info).current_user = NULL;
|
|
|
|
SG(request_info).current_user_length = 0;
|
|
|
|
SG(request_info).no_headers = 0;
|
2004-08-20 04:26:39 +08:00
|
|
|
SG(request_info).post_entry = NULL;
|
2004-11-28 21:32:29 +08:00
|
|
|
SG(global_request_time) = 0;
|
2003-01-15 19:30:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It's possible to override this general case in the activate() callback,
|
|
|
|
* if necessary.
|
|
|
|
*/
|
|
|
|
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
|
|
|
|
SG(request_info).headers_only = 1;
|
|
|
|
} else {
|
|
|
|
SG(request_info).headers_only = 0;
|
|
|
|
}
|
|
|
|
if (SG(server_context)) {
|
|
|
|
SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
|
|
|
|
if (sapi_module.activate) {
|
|
|
|
sapi_module.activate(TSRMLS_C);
|
|
|
|
}
|
|
|
|
}
|
2009-04-29 05:30:23 +08:00
|
|
|
if (sapi_module.input_filter_init ) {
|
|
|
|
sapi_module.input_filter_init(TSRMLS_C);
|
|
|
|
}
|
2002-11-18 08:59:23 +08:00
|
|
|
}
|
2000-02-26 05:27:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from php_request_startup() for every request.
|
|
|
|
*/
|
2002-11-18 08:59:23 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API void sapi_activate(TSRMLS_D)
|
2000-02-26 05:27:03 +08:00
|
|
|
{
|
1999-05-06 02:25:20 +08:00
|
|
|
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
|
1999-05-09 16:48:05 +08:00
|
|
|
SG(sapi_headers).send_default_content_type = 1;
|
2000-02-25 06:00:47 +08:00
|
|
|
|
2000-08-03 06:48:45 +08:00
|
|
|
/*
|
1999-05-06 02:25:20 +08:00
|
|
|
SG(sapi_headers).http_response_code = 200;
|
2000-08-03 06:48:45 +08:00
|
|
|
*/
|
2000-08-03 06:53:55 +08:00
|
|
|
SG(sapi_headers).http_status_line = NULL;
|
2007-12-04 00:04:36 +08:00
|
|
|
SG(sapi_headers).mimetype = NULL;
|
1999-05-06 03:53:15 +08:00
|
|
|
SG(headers_sent) = 0;
|
1999-05-10 02:40:59 +08:00
|
|
|
SG(read_post_bytes) = 0;
|
1999-05-12 04:38:16 +08:00
|
|
|
SG(request_info).post_data = NULL;
|
2002-11-13 02:29:11 +08:00
|
|
|
SG(request_info).raw_post_data = NULL;
|
2000-02-11 04:13:08 +08:00
|
|
|
SG(request_info).current_user = NULL;
|
|
|
|
SG(request_info).current_user_length = 0;
|
2000-11-14 02:54:37 +08:00
|
|
|
SG(request_info).no_headers = 0;
|
2004-11-28 21:32:29 +08:00
|
|
|
SG(request_info).post_entry = NULL;
|
2005-03-15 03:25:39 +08:00
|
|
|
SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */
|
2004-08-11 14:18:25 +08:00
|
|
|
SG(global_request_time) = 0;
|
1999-05-26 05:14:54 +08:00
|
|
|
|
2000-09-08 22:43:57 +08:00
|
|
|
/* It's possible to override this general case in the activate() callback, if
|
|
|
|
* necessary.
|
2000-08-03 06:48:45 +08:00
|
|
|
*/
|
1999-05-26 05:14:54 +08:00
|
|
|
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
|
|
|
|
SG(request_info).headers_only = 1;
|
|
|
|
} else {
|
|
|
|
SG(request_info).headers_only = 0;
|
|
|
|
}
|
2000-09-09 23:02:15 +08:00
|
|
|
SG(rfc1867_uploaded_files) = NULL;
|
1999-05-26 05:14:54 +08:00
|
|
|
|
2002-10-22 00:41:06 +08:00
|
|
|
/* handle request mehtod */
|
1999-05-09 16:48:05 +08:00
|
|
|
if (SG(server_context)) {
|
2002-10-22 00:41:06 +08:00
|
|
|
if ( SG(request_info).request_method) {
|
|
|
|
if(!strcmp(SG(request_info).request_method, "POST")
|
|
|
|
&& (SG(request_info).content_type)) {
|
|
|
|
/* HTTP POST -> may contain form data to be read into variables
|
|
|
|
depending on content type given
|
|
|
|
*/
|
|
|
|
sapi_read_post_data(TSRMLS_C);
|
|
|
|
} else {
|
|
|
|
/* any other method with content payload will fill
|
|
|
|
$HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data
|
|
|
|
it is up to the webserver to decide whether to allow a method or not
|
|
|
|
*/
|
2000-09-09 23:02:15 +08:00
|
|
|
SG(request_info).content_type_dup = NULL;
|
2002-10-22 02:44:50 +08:00
|
|
|
if(sapi_module.default_post_reader) {
|
|
|
|
sapi_module.default_post_reader(TSRMLS_C);
|
2001-10-24 04:48:30 +08:00
|
|
|
}
|
1999-05-29 06:41:48 +08:00
|
|
|
}
|
2000-02-18 09:52:11 +08:00
|
|
|
} else {
|
|
|
|
SG(request_info).content_type_dup = NULL;
|
1999-05-10 04:58:26 +08:00
|
|
|
}
|
2002-10-22 00:41:06 +08:00
|
|
|
|
|
|
|
/* Cookies */
|
2001-07-28 19:36:37 +08:00
|
|
|
SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
|
2000-02-11 03:22:36 +08:00
|
|
|
if (sapi_module.activate) {
|
2001-07-28 19:36:37 +08:00
|
|
|
sapi_module.activate(TSRMLS_C);
|
2000-02-11 03:22:36 +08:00
|
|
|
}
|
2000-02-11 00:44:59 +08:00
|
|
|
}
|
2009-04-29 05:30:23 +08:00
|
|
|
if (sapi_module.input_filter_init ) {
|
|
|
|
sapi_module.input_filter_init(TSRMLS_C);
|
|
|
|
}
|
1999-05-06 02:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-01 17:00:30 +08:00
|
|
|
static void sapi_send_headers_free(TSRMLS_D)
|
|
|
|
{
|
|
|
|
if (SG(sapi_headers).http_status_line) {
|
|
|
|
efree(SG(sapi_headers).http_status_line);
|
|
|
|
SG(sapi_headers).http_status_line = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API void sapi_deactivate(TSRMLS_D)
|
1999-05-06 02:25:20 +08:00
|
|
|
{
|
|
|
|
zend_llist_destroy(&SG(sapi_headers).headers);
|
1999-05-12 04:38:16 +08:00
|
|
|
if (SG(request_info).post_data) {
|
1999-05-09 16:48:05 +08:00
|
|
|
efree(SG(request_info).post_data);
|
2002-10-22 00:41:06 +08:00
|
|
|
} else if (SG(server_context)) {
|
|
|
|
if(sapi_module.read_post) {
|
2002-11-13 02:29:11 +08:00
|
|
|
/* make sure we've consumed all request input data */
|
2002-10-22 00:41:06 +08:00
|
|
|
char dummy[SAPI_POST_BLOCK_SIZE];
|
2002-11-21 18:29:11 +08:00
|
|
|
int read_bytes;
|
|
|
|
|
|
|
|
while((read_bytes = sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC)) > 0) {
|
|
|
|
SG(read_post_bytes) += read_bytes;
|
2002-10-22 00:41:06 +08:00
|
|
|
}
|
|
|
|
}
|
1999-05-06 05:29:26 +08:00
|
|
|
}
|
2002-11-13 02:29:11 +08:00
|
|
|
if (SG(request_info).raw_post_data) {
|
|
|
|
efree(SG(request_info).raw_post_data);
|
|
|
|
}
|
2000-02-16 07:31:10 +08:00
|
|
|
if (SG(request_info).auth_user) {
|
|
|
|
efree(SG(request_info).auth_user);
|
|
|
|
}
|
|
|
|
if (SG(request_info).auth_password) {
|
|
|
|
efree(SG(request_info).auth_password);
|
|
|
|
}
|
2005-04-04 23:06:36 +08:00
|
|
|
if (SG(request_info).auth_digest) {
|
|
|
|
efree(SG(request_info).auth_digest);
|
|
|
|
}
|
2000-02-18 04:23:59 +08:00
|
|
|
if (SG(request_info).content_type_dup) {
|
|
|
|
efree(SG(request_info).content_type_dup);
|
|
|
|
}
|
2000-02-11 04:13:08 +08:00
|
|
|
if (SG(request_info).current_user) {
|
|
|
|
efree(SG(request_info).current_user);
|
|
|
|
}
|
2000-02-11 00:44:59 +08:00
|
|
|
if (sapi_module.deactivate) {
|
2001-07-28 19:36:37 +08:00
|
|
|
sapi_module.deactivate(TSRMLS_C);
|
2000-02-11 00:44:59 +08:00
|
|
|
}
|
2000-09-09 05:56:47 +08:00
|
|
|
if (SG(rfc1867_uploaded_files)) {
|
2001-07-28 19:36:37 +08:00
|
|
|
destroy_uploaded_files_hash(TSRMLS_C);
|
2000-09-09 05:56:47 +08:00
|
|
|
}
|
2002-08-06 02:32:05 +08:00
|
|
|
if (SG(sapi_headers).mimetype) {
|
|
|
|
efree(SG(sapi_headers).mimetype);
|
|
|
|
SG(sapi_headers).mimetype = NULL;
|
|
|
|
}
|
2002-08-01 17:00:30 +08:00
|
|
|
sapi_send_headers_free(TSRMLS_C);
|
2003-01-15 19:30:39 +08:00
|
|
|
SG(sapi_started) = 0;
|
|
|
|
SG(headers_sent) = 0;
|
|
|
|
SG(request_info).headers_read = 0;
|
2004-08-11 14:18:25 +08:00
|
|
|
SG(global_request_time) = 0;
|
1999-05-06 02:25:20 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API void sapi_initialize_empty_request(TSRMLS_D)
|
2000-02-18 04:23:59 +08:00
|
|
|
{
|
|
|
|
SG(server_context) = NULL;
|
|
|
|
SG(request_info).request_method = NULL;
|
2005-07-13 00:53:30 +08:00
|
|
|
SG(request_info).auth_digest = SG(request_info).auth_user = SG(request_info).auth_password = NULL;
|
2000-02-18 04:23:59 +08:00
|
|
|
SG(request_info).content_type_dup = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-05 02:07:46 +08:00
|
|
|
static int sapi_extract_response_code(const char *header_line)
|
|
|
|
{
|
|
|
|
int code = 200;
|
|
|
|
const char *ptr;
|
|
|
|
|
|
|
|
for (ptr = header_line; *ptr; ptr++) {
|
|
|
|
if (*ptr == ' ' && *(ptr + 1) != ' ') {
|
|
|
|
code = atoi(ptr + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
1999-05-06 02:25:20 +08:00
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
|
2002-07-03 18:47:16 +08:00
|
|
|
static void sapi_update_response_code(int ncode TSRMLS_DC)
|
2002-07-03 18:42:31 +08:00
|
|
|
{
|
2003-06-03 18:06:45 +08:00
|
|
|
/* if the status code did not change, we do not want
|
|
|
|
to change the status line, and no need to change the code */
|
|
|
|
if (SG(sapi_headers).http_response_code == ncode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
if (SG(sapi_headers).http_status_line) {
|
|
|
|
efree(SG(sapi_headers).http_status_line);
|
|
|
|
SG(sapi_headers).http_status_line = NULL;
|
|
|
|
}
|
|
|
|
SG(sapi_headers).http_response_code = ncode;
|
|
|
|
}
|
|
|
|
|
2002-06-18 18:16:36 +08:00
|
|
|
static int sapi_find_matching_header(void *element1, void *element2)
|
|
|
|
{
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
int len = strlen((char*)element2);
|
|
|
|
return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, len) == 0 && ((sapi_header_struct*)element1)->header[len] == ':';
|
2002-06-18 18:16:36 +08:00
|
|
|
}
|
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC)
|
|
|
|
{
|
|
|
|
sapi_header_line ctr = {0};
|
|
|
|
int r;
|
|
|
|
|
|
|
|
ctr.line = header_line;
|
|
|
|
ctr.line_len = header_line_len;
|
|
|
|
|
|
|
|
r = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD,
|
|
|
|
&ctr TSRMLS_CC);
|
|
|
|
|
|
|
|
if (!duplicate)
|
|
|
|
efree(header_line);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
|
1999-05-06 02:25:20 +08:00
|
|
|
{
|
2002-06-18 23:04:58 +08:00
|
|
|
int retval;
|
1999-05-06 02:25:20 +08:00
|
|
|
sapi_header_struct sapi_header;
|
1999-05-12 02:36:35 +08:00
|
|
|
char *colon_offset;
|
2001-10-21 06:01:56 +08:00
|
|
|
long myuid = 0L;
|
2002-07-03 18:42:31 +08:00
|
|
|
char *header_line;
|
|
|
|
uint header_line_len;
|
|
|
|
int http_response_code;
|
|
|
|
|
2000-11-14 02:54:37 +08:00
|
|
|
if (SG(headers_sent) && !SG(request_info).no_headers) {
|
2001-08-05 23:29:47 +08:00
|
|
|
char *output_start_filename = php_get_output_start_filename(TSRMLS_C);
|
|
|
|
int output_start_lineno = php_get_output_start_lineno(TSRMLS_C);
|
2000-02-04 22:54:30 +08:00
|
|
|
|
|
|
|
if (output_start_filename) {
|
2002-07-03 18:42:31 +08:00
|
|
|
sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent by (output started at %s:%d)",
|
2000-02-04 22:54:30 +08:00
|
|
|
output_start_filename, output_start_lineno);
|
|
|
|
} else {
|
2002-07-03 18:42:31 +08:00
|
|
|
sapi_module.sapi_error(E_WARNING, "Cannot modify header information - headers already sent");
|
2000-04-28 21:03:13 +08:00
|
|
|
}
|
1999-05-07 05:58:49 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
switch (op) {
|
2006-12-18 20:32:08 +08:00
|
|
|
case SAPI_HEADER_SET_STATUS:
|
2007-04-16 16:09:56 +08:00
|
|
|
sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC);
|
2006-12-18 20:32:08 +08:00
|
|
|
return SUCCESS;
|
|
|
|
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
case SAPI_HEADER_ADD:
|
2006-12-18 20:32:08 +08:00
|
|
|
case SAPI_HEADER_REPLACE:
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
case SAPI_HEADER_DELETE: {
|
2006-12-18 20:32:08 +08:00
|
|
|
sapi_header_line *p = arg;
|
|
|
|
|
|
|
|
if (!p->line || !p->line_len) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
header_line = p->line;
|
|
|
|
header_line_len = p->line_len;
|
|
|
|
http_response_code = p->response_code;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
case SAPI_HEADER_DELETE_ALL:
|
|
|
|
if (sapi_module.header_handler) {
|
|
|
|
sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
|
|
|
|
}
|
|
|
|
zend_llist_clean(&SG(sapi_headers).headers);
|
|
|
|
return SUCCESS;
|
|
|
|
|
2006-12-18 20:32:08 +08:00
|
|
|
default:
|
2005-11-02 22:38:13 +08:00
|
|
|
return FAILURE;
|
2000-04-28 21:03:13 +08:00
|
|
|
}
|
2000-04-29 00:47:19 +08:00
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
header_line = estrndup(header_line, header_line_len);
|
|
|
|
|
2000-04-29 00:47:19 +08:00
|
|
|
/* cut of trailing spaces, linefeeds and carriage-returns */
|
2006-12-18 21:16:54 +08:00
|
|
|
while(header_line_len && isspace(header_line[header_line_len-1]))
|
2000-04-29 00:47:19 +08:00
|
|
|
header_line[--header_line_len]='\0';
|
|
|
|
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
if (op == SAPI_HEADER_DELETE) {
|
|
|
|
if (strchr(header_line, ':')) {
|
|
|
|
efree(header_line);
|
|
|
|
sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon.");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* new line safety check */
|
2005-12-06 11:39:45 +08:00
|
|
|
char *s = header_line, *e = header_line + header_line_len, *p;
|
|
|
|
while (s < e && (p = memchr(s, '\n', (e - s)))) {
|
|
|
|
if (*(p + 1) == ' ' || *(p + 1) == '\t') {
|
|
|
|
s = p + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
efree(header_line);
|
2005-12-30 13:40:43 +08:00
|
|
|
sapi_module.sapi_error(E_WARNING, "Header may not contain more than a single header, new line detected.");
|
2005-12-06 11:39:45 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-29 00:47:19 +08:00
|
|
|
|
1999-05-07 05:58:49 +08:00
|
|
|
sapi_header.header = header_line;
|
1999-05-06 02:25:20 +08:00
|
|
|
sapi_header.header_len = header_line_len;
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
|
|
|
|
if (op == SAPI_HEADER_DELETE) {
|
|
|
|
if (sapi_module.header_handler) {
|
|
|
|
sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
|
|
|
|
}
|
|
|
|
zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header);
|
|
|
|
sapi_free_header(&sapi_header);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-05-06 02:25:20 +08:00
|
|
|
|
1999-05-12 04:38:16 +08:00
|
|
|
/* Check the header for a few cases that we have special support for in SAPI */
|
1999-08-10 01:40:28 +08:00
|
|
|
if (header_line_len>=5
|
2000-07-02 02:06:11 +08:00
|
|
|
&& !strncasecmp(header_line, "HTTP/", 5)) {
|
1999-10-05 02:07:46 +08:00
|
|
|
/* filter out the response code */
|
2002-07-03 18:42:31 +08:00
|
|
|
sapi_update_response_code(sapi_extract_response_code(header_line) TSRMLS_CC);
|
2008-01-29 00:09:08 +08:00
|
|
|
/* sapi_update_response_code doesn't free the status line if the code didn't change */
|
|
|
|
if (SG(sapi_headers).http_status_line) {
|
|
|
|
efree(SG(sapi_headers).http_status_line);
|
|
|
|
}
|
1999-05-12 04:38:16 +08:00
|
|
|
SG(sapi_headers).http_status_line = header_line;
|
1999-08-10 01:40:28 +08:00
|
|
|
return SUCCESS;
|
1999-05-12 04:38:16 +08:00
|
|
|
} else {
|
|
|
|
colon_offset = strchr(header_line, ':');
|
|
|
|
if (colon_offset) {
|
|
|
|
*colon_offset = 0;
|
|
|
|
if (!STRCASECMP(header_line, "Content-Type")) {
|
2002-06-18 23:04:58 +08:00
|
|
|
char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
|
2000-02-26 05:27:03 +08:00
|
|
|
size_t len = header_line_len - (ptr - header_line), newlen;
|
2004-03-25 16:42:00 +08:00
|
|
|
while (*ptr == ' ') {
|
2002-08-02 05:12:09 +08:00
|
|
|
ptr++;
|
2004-03-25 16:42:00 +08:00
|
|
|
len--;
|
2002-08-02 05:12:09 +08:00
|
|
|
}
|
2003-02-11 03:04:44 +08:00
|
|
|
#if HAVE_ZLIB
|
2002-08-02 05:12:09 +08:00
|
|
|
if(!strncmp(ptr, "image/", sizeof("image/")-1)) {
|
2003-02-11 03:04:44 +08:00
|
|
|
zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
2002-07-28 22:08:08 +08:00
|
|
|
}
|
|
|
|
#endif
|
2000-02-26 05:27:03 +08:00
|
|
|
mimetype = estrdup(ptr);
|
2001-07-28 19:36:37 +08:00
|
|
|
newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC);
|
2002-07-27 21:58:16 +08:00
|
|
|
if (!SG(sapi_headers).mimetype){
|
|
|
|
SG(sapi_headers).mimetype = estrdup(mimetype);
|
|
|
|
}
|
|
|
|
|
2000-02-26 05:27:03 +08:00
|
|
|
if (newlen != 0) {
|
|
|
|
newlen += sizeof("Content-type: ");
|
|
|
|
newheader = emalloc(newlen);
|
2000-08-27 17:48:03 +08:00
|
|
|
PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1);
|
|
|
|
strlcat(newheader, mimetype, newlen);
|
2000-02-26 05:27:03 +08:00
|
|
|
sapi_header.header = newheader;
|
|
|
|
sapi_header.header_len = newlen - 1;
|
2002-06-18 23:04:58 +08:00
|
|
|
efree(header_line);
|
2000-02-26 05:27:03 +08:00
|
|
|
}
|
|
|
|
efree(mimetype);
|
1999-05-12 04:38:16 +08:00
|
|
|
SG(sapi_headers).send_default_content_type = 0;
|
|
|
|
} else if (!STRCASECMP(header_line, "Location")) {
|
2003-08-12 03:36:26 +08:00
|
|
|
if ((SG(sapi_headers).http_response_code < 300 ||
|
|
|
|
SG(sapi_headers).http_response_code > 307) &&
|
|
|
|
SG(sapi_headers).http_response_code != 201) {
|
2002-06-21 17:31:21 +08:00
|
|
|
/* Return a Found Redirect if one is not already specified */
|
2007-01-01 03:22:01 +08:00
|
|
|
if (http_response_code) { /* user specified redirect code */
|
|
|
|
sapi_update_response_code(http_response_code TSRMLS_CC);
|
|
|
|
} else if (SG(request_info).proto_num > 1000 &&
|
2005-03-15 03:25:39 +08:00
|
|
|
SG(request_info).request_method &&
|
|
|
|
strcmp(SG(request_info).request_method, "HEAD") &&
|
|
|
|
strcmp(SG(request_info).request_method, "GET")) {
|
|
|
|
sapi_update_response_code(303 TSRMLS_CC);
|
|
|
|
} else {
|
|
|
|
sapi_update_response_code(302 TSRMLS_CC);
|
|
|
|
}
|
2002-06-21 17:31:21 +08:00
|
|
|
}
|
1999-05-12 04:38:16 +08:00
|
|
|
} else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */
|
2001-10-21 06:01:56 +08:00
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
sapi_update_response_code(401 TSRMLS_CC); /* authentication-required */
|
2002-07-13 08:15:22 +08:00
|
|
|
|
|
|
|
if(PG(safe_mode))
|
|
|
|
#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
|
|
|
|
{
|
|
|
|
zval *repl_temp;
|
2005-02-22 05:00:04 +08:00
|
|
|
char *ptr = colon_offset+1, *result, *newheader;
|
|
|
|
int ptr_len=0, result_len = 0, newlen = 0;
|
2002-07-13 08:15:22 +08:00
|
|
|
|
2004-06-07 21:51:50 +08:00
|
|
|
/* skip white space */
|
|
|
|
while (isspace(*ptr)) {
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
2001-10-21 06:01:56 +08:00
|
|
|
myuid = php_getuid();
|
|
|
|
|
|
|
|
ptr_len = strlen(ptr);
|
|
|
|
MAKE_STD_ZVAL(repl_temp);
|
2002-01-14 21:36:54 +08:00
|
|
|
Z_TYPE_P(repl_temp) = IS_STRING;
|
2007-02-24 10:17:47 +08:00
|
|
|
Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\"\\1-%ld\"", myuid);
|
2001-10-21 06:01:56 +08:00
|
|
|
/* Modify quoted realm value */
|
|
|
|
result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
|
|
|
|
ptr, ptr_len,
|
|
|
|
repl_temp,
|
2005-03-12 20:03:50 +08:00
|
|
|
0, &result_len, -1, NULL TSRMLS_CC);
|
2001-10-21 06:01:56 +08:00
|
|
|
if(result_len==ptr_len) {
|
|
|
|
efree(result);
|
2007-02-24 10:17:47 +08:00
|
|
|
efree(Z_STRVAL_P(repl_temp));
|
|
|
|
Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\\1-%ld\\2", myuid);
|
2001-10-21 06:01:56 +08:00
|
|
|
/* modify unquoted realm value */
|
|
|
|
result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21,
|
|
|
|
ptr, ptr_len,
|
|
|
|
repl_temp,
|
2005-03-12 20:03:50 +08:00
|
|
|
0, &result_len, -1, NULL TSRMLS_CC);
|
2001-10-21 06:01:56 +08:00
|
|
|
if(result_len==ptr_len) {
|
|
|
|
char *lower_temp = estrdup(ptr);
|
2003-02-12 05:41:32 +08:00
|
|
|
char conv_temp[32];
|
2001-10-21 06:01:56 +08:00
|
|
|
int conv_len;
|
|
|
|
|
|
|
|
php_strtolower(lower_temp,strlen(lower_temp));
|
|
|
|
/* If there is no realm string at all, append one */
|
|
|
|
if(!strstr(lower_temp,"realm")) {
|
|
|
|
efree(result);
|
2007-02-27 11:28:17 +08:00
|
|
|
conv_len = slprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
|
2001-10-21 06:01:56 +08:00
|
|
|
result = emalloc(ptr_len+conv_len+1);
|
2001-12-16 22:47:18 +08:00
|
|
|
result_len = ptr_len+conv_len;
|
2001-10-21 06:01:56 +08:00
|
|
|
memcpy(result, ptr, ptr_len);
|
|
|
|
memcpy(result+ptr_len, conv_temp, conv_len);
|
|
|
|
*(result+ptr_len+conv_len) = '\0';
|
|
|
|
}
|
|
|
|
efree(lower_temp);
|
|
|
|
}
|
|
|
|
}
|
2007-02-24 10:17:47 +08:00
|
|
|
newlen = spprintf(&newheader, 0, "WWW-Authenticate: %s", result);
|
2001-10-21 06:01:56 +08:00
|
|
|
efree(header_line);
|
|
|
|
sapi_header.header = newheader;
|
|
|
|
sapi_header.header_len = newlen;
|
|
|
|
efree(result);
|
|
|
|
efree(Z_STRVAL_P(repl_temp));
|
|
|
|
efree(repl_temp);
|
2001-12-17 07:21:52 +08:00
|
|
|
}
|
2001-10-22 01:41:15 +08:00
|
|
|
#else
|
2002-07-13 08:15:22 +08:00
|
|
|
{
|
2001-10-22 01:41:15 +08:00
|
|
|
myuid = php_getuid();
|
|
|
|
efree(header_line);
|
2004-03-09 10:24:02 +08:00
|
|
|
sapi_header.header_len = spprintf(&sapi_header.header, 0, "WWW-Authenticate: Basic realm=\"%ld\"", myuid);
|
|
|
|
}
|
2001-10-22 01:41:15 +08:00
|
|
|
#endif
|
1999-05-12 04:38:16 +08:00
|
|
|
}
|
2001-12-17 07:21:52 +08:00
|
|
|
if (sapi_header.header==header_line) {
|
|
|
|
*colon_offset = ':';
|
|
|
|
}
|
1999-05-12 02:36:35 +08:00
|
|
|
}
|
|
|
|
}
|
2002-06-21 17:31:21 +08:00
|
|
|
if (http_response_code) {
|
2002-07-03 18:42:31 +08:00
|
|
|
sapi_update_response_code(http_response_code TSRMLS_CC);
|
2002-06-21 17:31:21 +08:00
|
|
|
}
|
1999-05-06 03:53:15 +08:00
|
|
|
if (sapi_module.header_handler) {
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
retval = sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC);
|
1999-05-06 03:53:15 +08:00
|
|
|
} else {
|
|
|
|
retval = SAPI_HEADER_ADD;
|
|
|
|
}
|
1999-05-06 02:25:20 +08:00
|
|
|
if (retval & SAPI_HEADER_ADD) {
|
2002-06-18 18:16:36 +08:00
|
|
|
/* in replace mode first remove the header if it already exists in the headers llist */
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
if (op == SAPI_HEADER_REPLACE) {
|
2002-06-18 20:57:09 +08:00
|
|
|
colon_offset = strchr(sapi_header.header, ':');
|
2002-06-18 18:16:36 +08:00
|
|
|
if (colon_offset) {
|
|
|
|
char sav;
|
|
|
|
sav = *colon_offset;
|
|
|
|
*colon_offset = 0;
|
2002-06-18 20:57:09 +08:00
|
|
|
zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header);
|
2002-06-18 18:16:36 +08:00
|
|
|
*colon_offset = sav;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-06 02:25:20 +08:00
|
|
|
zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header);
|
Added header_remove() (chsc at peytz dotdk, Arnaud)
[DOC] proto void header_remove([string header_name])
Removes an HTTP header previously set using header()
The header_name parameter is optionnal, all headers are
removed if it is not set
[SAPIs] The header_handler callback in sapi_module_struct has
been changed, it now take a new argument.
When it is set to SAPI_HEADER_DELETE, sapi_header->header is
the name of an header, header_handler has to delete it.
When it is set to SAPI_HEADER_DELETE_ALL, header_handler has
to delete all headers.
When sapi_header_op_enum is SAPI_HEADER_ADD or _REPLACE,
sapi_header->header is in the form "Name: value", header_handler
has to add or replace the given header.
In all cases, header_handler must not free sapi_header or
sapi_header->header. SAPI_HEADER_ADD must be returned if the
header has been added or replaced, or 0 in other cases.
2008-11-13 18:14:04 +08:00
|
|
|
} else {
|
|
|
|
sapi_free_header(&sapi_header);
|
1999-05-06 02:25:20 +08:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-31 14:28:05 +08:00
|
|
|
SAPI_API int sapi_send_headers(TSRMLS_D)
|
1999-05-06 02:25:20 +08:00
|
|
|
{
|
1999-05-06 03:53:15 +08:00
|
|
|
int retval;
|
1999-10-05 02:07:46 +08:00
|
|
|
int ret = FAILURE;
|
1999-05-06 02:25:20 +08:00
|
|
|
|
2000-11-14 02:54:37 +08:00
|
|
|
if (SG(headers_sent) || SG(request_info).no_headers) {
|
1999-05-06 03:53:15 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2003-02-11 03:04:44 +08:00
|
|
|
#if HAVE_ZLIB
|
2002-07-28 22:08:08 +08:00
|
|
|
/* Add output compression headers at this late stage in order to make
|
|
|
|
it possible to switch it off inside the script. */
|
2003-02-11 03:04:44 +08:00
|
|
|
|
2005-11-07 06:08:30 +08:00
|
|
|
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
|
2003-02-11 03:04:44 +08:00
|
|
|
zval nm_zlib_get_coding_type;
|
|
|
|
zval *uf_result = NULL;
|
|
|
|
|
|
|
|
ZVAL_STRINGL(&nm_zlib_get_coding_type, "zlib_get_coding_type", sizeof("zlib_get_coding_type") - 1, 0);
|
|
|
|
|
|
|
|
if (call_user_function_ex(CG(function_table), NULL, &nm_zlib_get_coding_type, &uf_result, 0, NULL, 1, NULL TSRMLS_CC) != FAILURE && uf_result != NULL && Z_TYPE_P(uf_result) == IS_STRING) {
|
|
|
|
char buf[128];
|
2003-02-11 04:18:08 +08:00
|
|
|
int len;
|
2003-02-11 03:04:44 +08:00
|
|
|
|
|
|
|
assert(Z_STRVAL_P(uf_result) != NULL);
|
|
|
|
|
2007-02-27 11:28:17 +08:00
|
|
|
len = slprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
|
2003-02-11 04:18:08 +08:00
|
|
|
if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) {
|
2003-02-11 03:04:44 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2003-09-10 16:47:37 +08:00
|
|
|
if (sapi_add_header_ex("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1, 0 TSRMLS_CC) == FAILURE) {
|
2003-02-11 03:04:44 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uf_result != NULL) {
|
|
|
|
zval_ptr_dtor(&uf_result);
|
2002-07-28 22:08:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-08-20 00:38:19 +08:00
|
|
|
/* Success-oriented. We set headers_sent to 1 here to avoid an infinite loop
|
|
|
|
* in case of an error situation.
|
|
|
|
*/
|
2005-10-20 04:33:33 +08:00
|
|
|
if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) {
|
|
|
|
sapi_header_struct default_header;
|
|
|
|
sapi_get_default_content_type_header(&default_header TSRMLS_CC);
|
|
|
|
sapi_add_header_ex(default_header.header, default_header.header_len, 0, 0 TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
2000-08-20 00:38:19 +08:00
|
|
|
SG(headers_sent) = 1;
|
|
|
|
|
1999-05-06 03:53:15 +08:00
|
|
|
if (sapi_module.send_headers) {
|
2001-07-28 19:36:37 +08:00
|
|
|
retval = sapi_module.send_headers(&SG(sapi_headers) TSRMLS_CC);
|
1999-05-06 03:53:15 +08:00
|
|
|
} else {
|
|
|
|
retval = SAPI_HEADER_DO_SEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (retval) {
|
1999-05-06 02:25:20 +08:00
|
|
|
case SAPI_HEADER_SENT_SUCCESSFULLY:
|
1999-10-05 20:06:35 +08:00
|
|
|
ret = SUCCESS;
|
1999-05-06 02:25:20 +08:00
|
|
|
break;
|
2002-07-03 18:42:31 +08:00
|
|
|
case SAPI_HEADER_DO_SEND: {
|
1999-05-12 04:38:16 +08:00
|
|
|
sapi_header_struct http_status_line;
|
2002-07-03 18:42:31 +08:00
|
|
|
char buf[255];
|
1999-05-12 04:38:16 +08:00
|
|
|
|
2002-07-03 18:42:31 +08:00
|
|
|
if (SG(sapi_headers).http_status_line) {
|
|
|
|
http_status_line.header = SG(sapi_headers).http_status_line;
|
|
|
|
http_status_line.header_len = strlen(SG(sapi_headers).http_status_line);
|
|
|
|
} else {
|
|
|
|
http_status_line.header = buf;
|
2007-02-27 11:28:17 +08:00
|
|
|
http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
|
2002-07-03 18:42:31 +08:00
|
|
|
}
|
2001-07-31 12:53:54 +08:00
|
|
|
sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC);
|
1999-05-12 04:38:16 +08:00
|
|
|
}
|
2001-07-31 12:53:54 +08:00
|
|
|
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) sapi_module.send_header, SG(server_context) TSRMLS_CC);
|
1999-12-19 10:04:20 +08:00
|
|
|
if(SG(sapi_headers).send_default_content_type) {
|
2000-02-26 13:03:41 +08:00
|
|
|
sapi_header_struct default_header;
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
sapi_get_default_content_type_header(&default_header TSRMLS_CC);
|
2001-07-31 12:53:54 +08:00
|
|
|
sapi_module.send_header(&default_header, SG(server_context) TSRMLS_CC);
|
2000-02-26 13:03:41 +08:00
|
|
|
sapi_free_header(&default_header);
|
1999-12-19 10:04:20 +08:00
|
|
|
}
|
2001-07-31 12:53:54 +08:00
|
|
|
sapi_module.send_header(NULL, SG(server_context) TSRMLS_CC);
|
1999-10-05 02:07:46 +08:00
|
|
|
ret = SUCCESS;
|
1999-05-06 02:25:20 +08:00
|
|
|
break;
|
|
|
|
case SAPI_HEADER_SEND_FAILED:
|
2000-08-20 00:38:19 +08:00
|
|
|
SG(headers_sent) = 0;
|
1999-10-05 02:07:46 +08:00
|
|
|
ret = FAILURE;
|
1999-05-06 02:25:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-08-01 01:55:15 +08:00
|
|
|
|
|
|
|
sapi_send_headers_free(TSRMLS_C);
|
|
|
|
|
1999-10-05 02:07:46 +08:00
|
|
|
return ret;
|
1999-05-06 02:25:20 +08:00
|
|
|
}
|
1999-05-26 05:14:54 +08:00
|
|
|
|
|
|
|
|
2005-02-21 23:14:02 +08:00
|
|
|
SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC)
|
1999-09-17 07:18:15 +08:00
|
|
|
{
|
2000-02-18 04:23:59 +08:00
|
|
|
sapi_post_entry *p=post_entries;
|
1999-09-17 07:18:15 +08:00
|
|
|
|
|
|
|
while (p->content_type) {
|
2005-02-21 23:14:02 +08:00
|
|
|
if (sapi_register_post_entry(p TSRMLS_CC) == FAILURE) {
|
1999-09-17 07:18:15 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-21 23:14:02 +08:00
|
|
|
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
|
1999-05-26 05:14:54 +08:00
|
|
|
{
|
2007-04-25 22:18:01 +08:00
|
|
|
if (SG(sapi_started) && EG(in_execution)) {
|
2007-04-25 16:40:07 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2005-02-21 23:14:02 +08:00
|
|
|
return zend_hash_add(&SG(known_post_content_types),
|
|
|
|
post_entry->content_type, post_entry->content_type_len+1,
|
|
|
|
(void *) post_entry, sizeof(sapi_post_entry), NULL);
|
1999-05-26 05:14:54 +08:00
|
|
|
}
|
1999-05-26 05:19:46 +08:00
|
|
|
|
2005-02-21 23:14:02 +08:00
|
|
|
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
|
1999-05-26 05:19:46 +08:00
|
|
|
{
|
2007-04-25 22:18:01 +08:00
|
|
|
if (SG(sapi_started) && EG(in_execution)) {
|
2007-04-25 16:40:07 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-02-21 23:14:02 +08:00
|
|
|
zend_hash_del(&SG(known_post_content_types), post_entry->content_type,
|
|
|
|
post_entry->content_type_len+1);
|
1999-05-29 06:41:48 +08:00
|
|
|
}
|
1999-09-17 07:18:15 +08:00
|
|
|
|
2000-10-13 20:13:35 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D))
|
1999-09-17 07:18:15 +08:00
|
|
|
{
|
2007-04-25 19:05:16 +08:00
|
|
|
TSRMLS_FETCH();
|
2007-04-25 22:18:01 +08:00
|
|
|
if (SG(sapi_started) && EG(in_execution)) {
|
2007-04-25 16:40:07 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
1999-09-17 07:18:15 +08:00
|
|
|
sapi_module.default_post_reader = default_post_reader;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-01-14 01:37:25 +08:00
|
|
|
|
2002-08-02 14:53:48 +08:00
|
|
|
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC))
|
|
|
|
{
|
2007-04-25 19:05:16 +08:00
|
|
|
TSRMLS_FETCH();
|
2007-04-25 22:18:01 +08:00
|
|
|
if (SG(sapi_started) && EG(in_execution)) {
|
2007-04-25 16:40:07 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2002-08-02 14:53:48 +08:00
|
|
|
sapi_module.treat_data = treat_data;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-04-29 05:30:23 +08:00
|
|
|
SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC), unsigned int (*input_filter_init)(TSRMLS_D))
|
2003-02-20 03:41:09 +08:00
|
|
|
{
|
2007-04-25 19:05:16 +08:00
|
|
|
TSRMLS_FETCH();
|
2007-04-25 22:18:01 +08:00
|
|
|
if (SG(sapi_started) && EG(in_execution)) {
|
2007-04-25 16:40:07 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2003-02-20 03:41:09 +08:00
|
|
|
sapi_module.input_filter = input_filter;
|
2009-04-29 05:30:23 +08:00
|
|
|
sapi_module.input_filter_init = input_filter_init;
|
2003-02-20 03:41:09 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2002-08-02 14:53:48 +08:00
|
|
|
|
2001-07-31 14:28:05 +08:00
|
|
|
SAPI_API int sapi_flush(TSRMLS_D)
|
2000-01-14 01:37:25 +08:00
|
|
|
{
|
|
|
|
if (sapi_module.flush) {
|
2000-02-11 03:29:21 +08:00
|
|
|
sapi_module.flush(SG(server_context));
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILURE;
|
2000-01-14 01:37:25 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-11 01:26:57 +08:00
|
|
|
|
2001-07-31 14:28:05 +08:00
|
|
|
SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
|
2000-02-11 01:26:57 +08:00
|
|
|
{
|
2000-02-11 02:19:04 +08:00
|
|
|
if (sapi_module.get_stat) {
|
2001-07-28 19:36:37 +08:00
|
|
|
return sapi_module.get_stat(TSRMLS_C);
|
2000-02-11 01:26:57 +08:00
|
|
|
} else {
|
2003-02-11 03:45:34 +08:00
|
|
|
if (!SG(request_info).path_translated || (VCWD_STAT(SG(request_info).path_translated, &SG(global_stat)) == -1)) {
|
2000-02-11 02:19:04 +08:00
|
|
|
return NULL;
|
2000-02-11 01:26:57 +08:00
|
|
|
}
|
2000-02-11 02:19:04 +08:00
|
|
|
return &SG(global_stat);
|
2000-02-11 01:26:57 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-11 01:55:01 +08:00
|
|
|
|
2001-07-31 14:28:05 +08:00
|
|
|
SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
|
2000-02-11 01:55:01 +08:00
|
|
|
{
|
2006-05-11 05:19:32 +08:00
|
|
|
if (sapi_module.getenv) {
|
|
|
|
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
|
2006-12-22 05:49:22 +08:00
|
|
|
if (tmp) {
|
|
|
|
value = estrdup(tmp);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-05-11 05:19:32 +08:00
|
|
|
sapi_module.input_filter(PARSE_ENV, name, &value, strlen(value), NULL TSRMLS_CC);
|
|
|
|
return value;
|
2006-12-22 05:49:22 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
2000-02-25 06:00:47 +08:00
|
|
|
}
|
2000-02-26 05:27:03 +08:00
|
|
|
|
2002-11-26 13:15:55 +08:00
|
|
|
SAPI_API int sapi_get_fd(int *fd TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (sapi_module.get_fd) {
|
|
|
|
return sapi_module.get_fd(fd TSRMLS_CC);
|
|
|
|
} else {
|
2003-02-10 05:15:55 +08:00
|
|
|
return FAILURE;
|
2002-11-26 13:15:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-01 11:28:21 +08:00
|
|
|
SAPI_API int sapi_force_http_10(TSRMLS_D)
|
|
|
|
{
|
|
|
|
if (sapi_module.force_http_10) {
|
|
|
|
return sapi_module.force_http_10(TSRMLS_C);
|
|
|
|
} else {
|
2003-02-10 05:15:55 +08:00
|
|
|
return FAILURE;
|
2002-12-01 11:28:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-21 19:03:58 +08:00
|
|
|
|
|
|
|
SAPI_API int sapi_get_target_uid(uid_t *obj TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (sapi_module.get_target_uid) {
|
|
|
|
return sapi_module.get_target_uid(obj TSRMLS_CC);
|
|
|
|
} else {
|
2003-02-10 05:15:55 +08:00
|
|
|
return FAILURE;
|
2003-01-21 19:03:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SAPI_API int sapi_get_target_gid(gid_t *obj TSRMLS_DC)
|
|
|
|
{
|
|
|
|
if (sapi_module.get_target_gid) {
|
|
|
|
return sapi_module.get_target_gid(obj TSRMLS_CC);
|
|
|
|
} else {
|
2003-02-10 05:15:55 +08:00
|
|
|
return FAILURE;
|
2003-01-21 19:03:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 01:40:00 +08:00
|
|
|
SAPI_API time_t sapi_get_request_time(TSRMLS_D)
|
|
|
|
{
|
2007-05-25 17:12:35 +08:00
|
|
|
if(SG(global_request_time)) return SG(global_request_time);
|
|
|
|
|
2007-05-25 17:20:01 +08:00
|
|
|
if (sapi_module.get_request_time && SG(server_context)) {
|
|
|
|
SG(global_request_time) = sapi_module.get_request_time(TSRMLS_C);
|
2004-08-11 01:40:00 +08:00
|
|
|
} else {
|
2007-05-25 17:12:35 +08:00
|
|
|
SG(global_request_time) = time(0);
|
2004-08-11 01:40:00 +08:00
|
|
|
}
|
2007-05-25 17:12:35 +08:00
|
|
|
return SG(global_request_time);
|
2004-08-11 01:40:00 +08:00
|
|
|
}
|
2003-01-21 19:03:58 +08:00
|
|
|
|
2008-03-19 05:42:50 +08:00
|
|
|
SAPI_API void sapi_terminate_process(TSRMLS_D) {
|
|
|
|
if (sapi_module.terminate_process) {
|
|
|
|
sapi_module.terminate_process(TSRMLS_C);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-26 05:27:03 +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-26 05:27:03 +08:00
|
|
|
*/
|