1999-07-16 21:13:16 +08:00
|
|
|
/*
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-12-31 23:59:15 +08:00
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
1999-05-07 05:58:49 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.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"
|
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
|
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
|
|
|
|
1999-05-26 05:14:54 +08:00
|
|
|
static HashTable known_post_content_types;
|
|
|
|
|
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));
|
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
|
|
|
{
|
1999-05-03 02:07:41 +08:00
|
|
|
sapi_module = *sf;
|
2000-07-11 22:29:38 +08:00
|
|
|
zend_hash_init_ex(&known_post_content_types, 5, NULL, NULL, 1, 0);
|
1999-09-17 07:18:15 +08:00
|
|
|
|
1999-04-26 03:36:57 +08:00
|
|
|
#ifdef ZTS
|
2001-07-27 18:16:41 +08:00
|
|
|
ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, NULL);
|
2000-03-17 05:23:24 +08:00
|
|
|
#else
|
2001-07-27 18:16:41 +08:00
|
|
|
sapi_globals_ctor(&sapi_globals TSRMLS_CC);
|
1999-04-26 03:36:57 +08:00
|
|
|
#endif
|
2000-03-17 05:23:24 +08:00
|
|
|
|
2000-09-04 12:22:47 +08:00
|
|
|
#ifdef VIRTUAL_DIR
|
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 */
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
{
|
2000-01-06 03:25:19 +08:00
|
|
|
reentrancy_shutdown();
|
2000-09-04 12:22:47 +08:00
|
|
|
#ifdef VIRTUAL_DIR
|
2000-04-03 04:26:06 +08:00
|
|
|
virtual_cwd_shutdown();
|
|
|
|
#endif
|
2001-04-28 00:41:53 +08:00
|
|
|
|
|
|
|
#ifdef PHP_WIN32
|
|
|
|
tsrm_win32_shutdown();
|
|
|
|
#endif
|
|
|
|
|
1999-05-29 06:41:48 +08:00
|
|
|
zend_hash_destroy(&known_post_content_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|
2003-02-11 03:45:34 +08:00
|
|
|
if (zend_hash_find(&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 ? */
|
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)) {
|
2002-12-06 05:46:08 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %d bytes exceeds the limit of %d 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)) {
|
2002-12-06 05:46:08 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %d bytes", SG(post_max_size));
|
2000-09-09 23:02:15 +08:00
|
|
|
return;
|
|
|
|
}
|
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;
|
|
|
|
SG(request_info).current_user = NULL;
|
|
|
|
SG(request_info).current_user_length = 0;
|
|
|
|
SG(request_info).no_headers = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
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;
|
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;
|
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
|
|
|
}
|
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);
|
|
|
|
}
|
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;
|
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;
|
|
|
|
SG(request_info).auth_user = SG(request_info).auth_password = NULL;
|
|
|
|
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
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, strlen((char*)element2)) == 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
zend_bool replace;
|
|
|
|
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) {
|
|
|
|
case SAPI_HEADER_SET_STATUS:
|
|
|
|
sapi_update_response_code((int) arg TSRMLS_CC);
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case SAPI_HEADER_REPLACE:
|
|
|
|
case SAPI_HEADER_ADD: {
|
|
|
|
sapi_header_line *p = arg;
|
|
|
|
header_line = p->line;
|
|
|
|
header_line_len = p->line_len;
|
|
|
|
http_response_code = p->response_code;
|
|
|
|
replace = (op == SAPI_HEADER_REPLACE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
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 */
|
|
|
|
while(isspace(header_line[header_line_len-1]))
|
|
|
|
header_line[--header_line_len]='\0';
|
|
|
|
|
|
|
|
|
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;
|
2000-10-27 02:18:21 +08:00
|
|
|
sapi_header.replace = replace;
|
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);
|
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;
|
2002-08-02 05:12:09 +08:00
|
|
|
while (*ptr == ' ' && *ptr != '\0') {
|
|
|
|
ptr++;
|
|
|
|
}
|
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")) {
|
2002-06-21 17:31:21 +08:00
|
|
|
if (SG(sapi_headers).http_response_code < 300 ||
|
|
|
|
SG(sapi_headers).http_response_code > 307) {
|
|
|
|
/* Return a Found Redirect if one is not already specified */
|
2002-07-03 18:42:31 +08:00
|
|
|
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-22 01:41:15 +08:00
|
|
|
int newlen;
|
|
|
|
char *result, *newheader;
|
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;
|
|
|
|
char *ptr = colon_offset+1;
|
|
|
|
int ptr_len=0, result_len = 0;
|
|
|
|
|
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;
|
2001-10-21 06:01:56 +08:00
|
|
|
Z_STRVAL_P(repl_temp) = emalloc(32);
|
|
|
|
Z_STRLEN_P(repl_temp) = sprintf(Z_STRVAL_P(repl_temp), "realm=\"\\1-%ld\"", myuid);
|
|
|
|
/* Modify quoted realm value */
|
|
|
|
result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
|
|
|
|
ptr, ptr_len,
|
|
|
|
repl_temp,
|
|
|
|
0, &result_len, -1 TSRMLS_CC);
|
|
|
|
if(result_len==ptr_len) {
|
|
|
|
efree(result);
|
|
|
|
sprintf(Z_STRVAL_P(repl_temp), "realm=\\1-%ld\\2", myuid);
|
|
|
|
/* modify unquoted realm value */
|
|
|
|
result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21,
|
|
|
|
ptr, ptr_len,
|
|
|
|
repl_temp,
|
|
|
|
0, &result_len, -1 TSRMLS_CC);
|
|
|
|
if(result_len==ptr_len) {
|
|
|
|
char *lower_temp = estrdup(ptr);
|
2003-02-11 04:11:10 +08:00
|
|
|
char conv_temp[64];
|
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);
|
2003-02-11 04:11:10 +08:00
|
|
|
conv_len = snprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
|
|
|
|
/* some broken snprintf() impls may return a negative value on failure */
|
|
|
|
if (conv_len < 0) {
|
|
|
|
conv_len = 0;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newlen = sizeof("WWW-Authenticate: ") + result_len;
|
|
|
|
newheader = emalloc(newlen+1);
|
|
|
|
sprintf(newheader,"WWW-Authenticate: %s", result);
|
|
|
|
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();
|
|
|
|
result = emalloc(32);
|
|
|
|
newlen = sprintf(result, "WWW-Authenticate: %ld", myuid);
|
|
|
|
newheader = estrndup(result,newlen);
|
|
|
|
efree(header_line);
|
|
|
|
sapi_header.header = newheader;
|
|
|
|
sapi_header.header_len = newlen;
|
|
|
|
efree(result);
|
2001-12-17 07:21:52 +08:00
|
|
|
}
|
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) {
|
2001-07-28 19:36:37 +08:00
|
|
|
retval = sapi_module.header_handler(&sapi_header, &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_DELETE_ALL) {
|
|
|
|
zend_llist_clean(&SG(sapi_headers).headers);
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
if (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;
|
|
|
|
colon_offset++;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
|
|
|
|
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];
|
|
|
|
uint len;
|
|
|
|
|
|
|
|
assert(Z_STRVAL_P(uf_result) != NULL);
|
|
|
|
|
|
|
|
len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
|
|
|
|
if (sapi_add_header(buf, len, 1)==FAILURE) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2003-02-11 03:45:34 +08:00
|
|
|
if (sapi_add_header("Vary: Accept-Encoding", sizeof("Vary: Accept-Encoding") - 1, 1) == 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.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
http_status_line.header_len = sprintf(buf, "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries)
|
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) {
|
2003-02-11 03:45:34 +08:00
|
|
|
if (sapi_register_post_entry(p) == FAILURE) {
|
1999-09-17 07:18:15 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry)
|
1999-05-26 05:14:54 +08:00
|
|
|
{
|
2000-02-18 04:23:59 +08:00
|
|
|
return zend_hash_add(&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
|
|
|
|
2000-02-18 04:23:59 +08:00
|
|
|
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry)
|
1999-05-26 05:19:46 +08:00
|
|
|
{
|
2000-02-18 04:23:59 +08:00
|
|
|
zend_hash_del(&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
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
sapi_module.treat_data = treat_data;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (sapi_module.getenv) {
|
2001-07-28 19:36:37 +08:00
|
|
|
return sapi_module.getenv(name, name_len TSRMLS_CC);
|
2000-02-11 01:55:01 +08:00
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|