diff options
-rw-r--r-- | main/SAPI.c | 44 | ||||
-rw-r--r-- | main/SAPI.h | 5 | ||||
-rw-r--r-- | sapi/apache/mod_php4.c | 2 | ||||
-rw-r--r-- | sapi/isapi/php4isapi.c | 4 |
4 files changed, 27 insertions, 28 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index b5d4a54080..1cd3c43223 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -185,17 +185,28 @@ SAPI_API char *sapi_get_default_content_type(SLS_D) charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET; if (strncasecmp(mimetype, "text/", 5) == 0 && strcasecmp(charset, "none") != 0) { - int len = strlen(mimetype) + sizeof(";charset=") + strlen(charset); + int len = strlen(mimetype) + sizeof("; charset=") + strlen(charset); content_type = emalloc(len); - strlcpy(content_type, mimetype, len); - strlcat(content_type, ";charset=", len); - strlcat(content_type, charset, len); + snprintf(content_type, len, "%s; charset=%s", mimetype, charset); } else { content_type = estrdup(mimetype); } return content_type; } + +SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header SLS_DC) +{ + char *default_content_type = sapi_get_default_content_type(SLS_C); + 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; +} + /* * Add charset on content-type header if the MIME type starts with * "text/", the default_charset directive is not set to "none" and @@ -286,9 +297,6 @@ SAPI_API void sapi_deactivate(SLS_D) if (SG(request_info).current_user) { efree(SG(request_info).current_user); } - if (SG(sapi_headers).default_content_type) { - efree(SG(sapi_headers).default_content_type); - } if (sapi_module.deactivate) { sapi_module.deactivate(SLS_C); } @@ -436,21 +444,13 @@ SAPI_API int sapi_send_headers() } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) sapi_module.send_header, SG(server_context)); if(SG(sapi_headers).send_default_content_type) { - if (SG(sapi_headers).default_content_type != NULL) { - sapi_header_struct default_header; - int len = SG(sapi_headers).default_content_type_size + sizeof("Content-type: "); - - default_header.header = emalloc(len); - strcpy(default_header.header, "Content-type: "); - strlcat(default_header.header, SG(sapi_headers).default_content_type, len); - default_header.header[len - 1] = '\0'; - default_header.header_len = len - 1; - sapi_module.send_header(&default_header,SG(server_context)); - efree(default_header.header); - } else { - sapi_header_struct default_header = { SAPI_DEFAULT_CONTENT_TYPE_HEADER, sizeof(SAPI_DEFAULT_CONTENT_TYPE_HEADER) - 1 }; - sapi_module.send_header(&default_header,SG(server_context)); - } + char *default_content_type = sapi_get_default_content_type(SLS_C); + int default_content_type_len = strlen(default_content_type); + sapi_header_struct default_header; + + sapi_get_default_content_type_header(&default_header SLS_CC); + sapi_module.send_header(&default_header, SG(server_context)); + sapi_free_header(&default_header); } sapi_module.send_header(NULL, SG(server_context)); SG(headers_sent) = 1; diff --git a/main/SAPI.h b/main/SAPI.h index 71b25104b7..28d12a80b9 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -47,8 +47,6 @@ typedef struct { typedef struct { zend_llist headers; int http_response_code; - char *default_content_type; - size_t default_content_type_size; unsigned char send_default_content_type; char *http_status_line; } sapi_headers_struct; @@ -145,6 +143,7 @@ SAPI_API struct stat *sapi_get_stat(); SAPI_API char *sapi_getenv(char *name, int name_len); SAPI_API char *sapi_get_default_content_type(SLS_D); +SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header SLS_DC); SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len SLS_DC); struct _sapi_module_struct { @@ -199,8 +198,6 @@ struct _sapi_post_entry { #define SAPI_DEFAULT_MIMETYPE "text/html" #define SAPI_DEFAULT_CHARSET "iso-8859-1" -#define SAPI_DEFAULT_CONTENT_TYPE SAPI_DEFAULT_MIMETYPE ";charset=" SAPI_DEFAULT_CHARSET -#define SAPI_DEFAULT_CONTENT_TYPE_HEADER "Content-type: " SAPI_DEFAULT_CONTENT_TYPE #define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION #define SAPI_POST_READER_FUNC(post_reader) void post_reader(SLS_D) diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c index bbdbc8b0b7..e411604720 100644 --- a/sapi/apache/mod_php4.c +++ b/sapi/apache/mod_php4.c @@ -411,7 +411,7 @@ static char *php_apache_get_default_mimetype(request_rec *r SLS_DC) mimetype = pstrdup(r->pool, tmpmimetype); efree(tmpmimetype); } else { - mimetype = SAPI_DEFAULT_CONTENT_TYPE; + mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET; } return mimetype; } diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index 8bcb3b06dd..3c2e049b00 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -183,11 +183,12 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC) LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); HSE_SEND_HEADER_EX_INFO header_info; char status_buf[MAX_STATUS_LENGTH]; - sapi_header_struct default_content_type = { SAPI_DEFAULT_CONTENT_TYPE, sizeof(SAPI_DEFAULT_CONTENT_TYPE)-1 }; + sapi_header_struct default_content_type; PLS_FETCH(); /* Obtain headers length */ if (SG(sapi_headers).send_default_content_type) { + sapi_get_default_content_type_header(&default_content_type SLS_CC); accumulate_header_length(&default_content_type, (void *) &total_length); } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) accumulate_header_length, (void *) &total_length); @@ -197,6 +198,7 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC) combined_headers_ptr = combined_headers; if (SG(sapi_headers).send_default_content_type) { concat_header(&default_content_type, (void *) &combined_headers_ptr); + sapi_free_header(&default_content_type); /* we no longer need it */ } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) concat_header, (void *) &combined_headers_ptr); *combined_headers_ptr++ = '\r'; |