cvs: /php4 SAPI.c SAPI.h /php4/sapi/apache mod_php4.c /php4/sapi/isapi php4isapi.c
| From: | Zeev Suraski | Date: | Sat, 26 Feb 2000 05:04:11 +0000 |
| Subject: | cvs: /php4 SAPI.c SAPI.h /php4/sapi/apache mod_php4.c /php4/sapi/isapi php4isapi.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11025@lists.php.net to get a copy of this message | ||
zeev Fri Feb 25 21:04:11 2000 EDT
Modified files:
/php4 SAPI.c SAPI.h
/php4/sapi/apache mod_php4.c
/php4/sapi/isapi php4isapi.c
Log:
- From CODING_STANDARDS:
[6] NEVER USE strncat(). If you're absolutely sure you know what you're doing,
check its man page again, and only then, consider using it, and even then,
try avoiding it.
strncat() is your enemy!
- Fix several SAPI services, get rid of the default_content_type (it's always
composed of the mime type and charset now).
- Win32 works again
Index: php4/SAPI.c
diff -u php4/SAPI.c:1.62 php4/SAPI.c:1.63
--- php4/SAPI.c:1.62 Fri Feb 25 15:12:51 2000
+++ php4/SAPI.c Fri Feb 25 21:03:41 2000
@@ -185,17 +185,28 @@
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 @@
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 @@
}
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;
Index: php4/SAPI.h
diff -u php4/SAPI.h:1.41 php4/SAPI.h:1.42
--- php4/SAPI.h:1.41 Fri Feb 25 13:27:02 2000
+++ php4/SAPI.h Fri Feb 25 21:03:41 2000
@@ -47,8 +47,6 @@
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 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 @@
#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)
Index: php4/sapi/apache/mod_php4.c
diff -u php4/sapi/apache/mod_php4.c:1.36 php4/sapi/apache/mod_php4.c:1.37
--- php4/sapi/apache/mod_php4.c:1.36 Fri Feb 25 13:27:03 2000
+++ php4/sapi/apache/mod_php4.c Fri Feb 25 21:03:41 2000
@@ -17,7 +17,7 @@
| PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php4.c,v 1.36 2000/02/25 21:27:03 ssb Exp $ */
+/* $Id: mod_php4.c,v 1.37 2000/02/26 05:03:41 zeev Exp $ */
#define NO_REGEX_EXTRA_H
@@ -411,7 +411,7 @@
mimetype = pstrdup(r->pool, tmpmimetype);
efree(tmpmimetype);
} else {
- mimetype = SAPI_DEFAULT_CONTENT_TYPE;
+ mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET;
}
return mimetype;
}
Index: php4/sapi/isapi/php4isapi.c
diff -u php4/sapi/isapi/php4isapi.c:1.29 php4/sapi/isapi/php4isapi.c:1.30
--- php4/sapi/isapi/php4isapi.c:1.29 Sat Feb 19 15:41:25 2000
+++ php4/sapi/isapi/php4isapi.c Fri Feb 25 21:03:41 2000
@@ -183,11 +183,12 @@
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 @@
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';