diff options
Diffstat (limited to 'main/SAPI.c')
| -rw-r--r-- | main/SAPI.c | 77 |
1 files changed, 65 insertions, 12 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 6216fd8176..afb0c77276 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -13,13 +13,11 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Original design: Shane Caraveo <shane@caraveo.com> | - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | + | Authors: Andi Gutmans <andi@php.net> | + | Zeev Suraski <zeev@php.net> | +----------------------------------------------------------------------+ */ -/* $Id$ */ - #include <ctype.h> #include <sys/stat.h> @@ -780,7 +778,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) if (!strncmp(ptr, "image/", sizeof("image/")-1)) { zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - zend_string_release(key); + zend_string_release_ex(key, 0); } mimetype = estrdup(ptr); @@ -809,7 +807,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) zend_string *key = zend_string_init("zlib.output_compression", sizeof("zlib.output_compression")-1, 0); zend_alter_ini_entry_chars(key, "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - zend_string_release(key); + zend_string_release_ex(key, 0); } else if (!strcasecmp(header_line, "Location")) { if ((SG(sapi_headers).http_response_code < 300 || SG(sapi_headers).http_response_code > 399) && @@ -932,9 +930,9 @@ SAPI_API int sapi_send_headers(void) } -SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries) +SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entries) { - sapi_post_entry *p=post_entries; + const sapi_post_entry *p=post_entries; while (p->content_type) { if (sapi_register_post_entry(p) == FAILURE) { @@ -946,17 +944,22 @@ SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entries) } -SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry) +SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry) { + int ret; + zend_string *key; if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } - return zend_hash_str_add_mem(&SG(known_post_content_types), - post_entry->content_type, post_entry->content_type_len, + key = zend_string_init(post_entry->content_type, post_entry->content_type_len, 1); + GC_MAKE_PERSISTENT_LOCAL(key); + ret = zend_hash_add_mem(&SG(known_post_content_types), key, (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE; + zend_string_release_ex(key, 1); + return ret; } -SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry) +SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry) { if (SG(sapi_started) && EG(current_execute_data)) { return; @@ -1104,6 +1107,56 @@ SAPI_API void sapi_terminate_process(void) { } } +SAPI_API void sapi_add_request_header(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg) /* {{{ */ +{ + zval *return_value = (zval*)arg; + char *str = NULL; + + ALLOCA_FLAG(use_heap) + + if (var_len > 5 && + var[0] == 'H' && + var[1] == 'T' && + var[2] == 'T' && + var[3] == 'P' && + var[4] == '_') { + + char *p; + + var_len -= 5; + p = var + 5; + var = str = do_alloca(var_len + 1, use_heap); + *str++ = *p++; + while (*p) { + if (*p == '_') { + *str++ = '-'; + p++; + if (*p) { + *str++ = *p++; + } + } else if (*p >= 'A' && *p <= 'Z') { + *str++ = (*p++ - 'A' + 'a'); + } else { + *str++ = *p++; + } + } + *str = 0; + } else if (var_len == sizeof("CONTENT_TYPE")-1 && + memcmp(var, "CONTENT_TYPE", sizeof("CONTENT_TYPE")-1) == 0) { + var = "Content-Type"; + } else if (var_len == sizeof("CONTENT_LENGTH")-1 && + memcmp(var, "CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1) == 0) { + var = "Content-Length"; + } else { + return; + } + add_assoc_stringl_ex(return_value, var, var_len, val, val_len); + if (str) { + free_alloca(var, use_heap); + } +} +/* }}} */ + /* * Local variables: * tab-width: 4 |
