summaryrefslogtreecommitdiff
path: root/main/SAPI.c
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
commit2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch)
tree41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /main/SAPI.c
parentd29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff)
downloadphp-upstream/5.2.2.tar.gz
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'main/SAPI.c')
-rw-r--r--main/SAPI.c92
1 files changed, 56 insertions, 36 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 0dda75c65..f2ba51ac6 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.202.2.7.2.2 2006/09/19 20:33:11 dmitry Exp $ */
+/* $Id: SAPI.c,v 1.202.2.7.2.13 2007/04/25 14:18:01 dmitry Exp $ */
#include <ctype.h>
#include <sys/stat.h>
@@ -540,32 +540,32 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
}
switch (op) {
- case SAPI_HEADER_SET_STATUS:
- sapi_update_response_code((long) arg TSRMLS_CC);
- return SUCCESS;
+ case SAPI_HEADER_SET_STATUS:
+ sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC);
+ return SUCCESS;
+
+ case SAPI_HEADER_REPLACE:
+ case SAPI_HEADER_ADD: {
+ sapi_header_line *p = arg;
- case SAPI_HEADER_REPLACE:
- case SAPI_HEADER_ADD: {
- sapi_header_line *p = arg;
-
- if (!p->line || !p->line_len) {
+ if (!p->line || !p->line_len) {
+ return FAILURE;
+ }
+ 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;
- }
- 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;
}
header_line = estrndup(header_line, header_line_len);
/* cut of trailing spaces, linefeeds and carriage-returns */
- while(isspace(header_line[header_line_len-1]))
+ while(header_line_len && isspace(header_line[header_line_len-1]))
header_line[--header_line_len]='\0';
/* new line safety check */
@@ -631,7 +631,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
SG(sapi_headers).http_response_code > 307) &&
SG(sapi_headers).http_response_code != 201) {
/* Return a Found Redirect if one is not already specified */
- if(SG(request_info).proto_num > 1000 &&
+ 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 &&
SG(request_info).request_method &&
strcmp(SG(request_info).request_method, "HEAD") &&
strcmp(SG(request_info).request_method, "GET")) {
@@ -661,8 +663,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
ptr_len = strlen(ptr);
MAKE_STD_ZVAL(repl_temp);
Z_TYPE_P(repl_temp) = IS_STRING;
- Z_STRVAL_P(repl_temp) = emalloc(32);
- Z_STRLEN_P(repl_temp) = sprintf(Z_STRVAL_P(repl_temp), "realm=\"\\1-%ld\"", myuid);
+ Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\"\\1-%ld\"", myuid);
/* Modify quoted realm value */
result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
ptr, ptr_len,
@@ -670,7 +671,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
0, &result_len, -1, NULL TSRMLS_CC);
if(result_len==ptr_len) {
efree(result);
- sprintf(Z_STRVAL_P(repl_temp), "realm=\\1-%ld\\2", myuid);
+ efree(Z_STRVAL_P(repl_temp));
+ Z_STRLEN_P(repl_temp) = spprintf(&Z_STRVAL_P(repl_temp), 0, "realm=\\1-%ld\\2", myuid);
/* modify unquoted realm value */
result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21,
ptr, ptr_len,
@@ -685,7 +687,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
/* If there is no realm string at all, append one */
if(!strstr(lower_temp,"realm")) {
efree(result);
- conv_len = sprintf(conv_temp, " realm=\"%ld\"",myuid);
+ conv_len = slprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
result = emalloc(ptr_len+conv_len+1);
result_len = ptr_len+conv_len;
memcpy(result, ptr, ptr_len);
@@ -695,9 +697,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
efree(lower_temp);
}
}
- newlen = sizeof("WWW-Authenticate: ") - 1 + result_len;
- newheader = emalloc(newlen+1);
- sprintf(newheader,"WWW-Authenticate: %s", result);
+ newlen = spprintf(&newheader, 0, "WWW-Authenticate: %s", result);
efree(header_line);
sapi_header.header = newheader;
sapi_header.header_len = newlen;
@@ -774,7 +774,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
assert(Z_STRVAL_P(uf_result) != NULL);
- len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
+ len = slprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) {
return FAILURE;
}
@@ -818,7 +818,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
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);
+ http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
}
sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC);
}
@@ -861,6 +861,9 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries TSRMLS_DC)
SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
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);
@@ -868,6 +871,9 @@ SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
{
+ if (SG(sapi_started) && EG(in_execution)) {
+ return;
+ }
zend_hash_del(&SG(known_post_content_types), post_entry->content_type,
post_entry->content_type_len+1);
}
@@ -875,6 +881,10 @@ SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry TSRMLS_DC)
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.default_post_reader = default_post_reader;
return SUCCESS;
}
@@ -882,12 +892,20 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRML
SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.treat_data = treat_data;
return SUCCESS;
}
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))
{
+ TSRMLS_FETCH();
+ if (SG(sapi_started) && EG(in_execution)) {
+ return FAILURE;
+ }
sapi_module.input_filter = input_filter;
return SUCCESS;
}
@@ -918,13 +936,15 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
{
if (sapi_module.getenv) {
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
- if(tmp) value = estrdup(tmp);
- else return NULL;
+ if (tmp) {
+ value = estrdup(tmp);
+ } else {
+ return NULL;
+ }
sapi_module.input_filter(PARSE_ENV, name, &value, strlen(value), NULL TSRMLS_CC);
return value;
- } else {
- return NULL;
- }
+ }
+ return NULL;
}
SAPI_API int sapi_get_fd(int *fd TSRMLS_DC)