cvs: php4(PHP_4_2_0) /main SAPI.c
| From: | Stefan Esser | Date: | Sun, 23 Jun 2002 17:15:07 +0000 |
| Subject: | cvs: php4(PHP_4_2_0) /main SAPI.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-12463@lists.php.net to get a copy of this message | ||
sesser Sun Jun 23 13:15:07 2002 EDT
Modified files: (Branch: PHP_4_2_0)
/php4/main SAPI.c
Log:
MFH: replace header fix, content-type header handling fix
Index: php4/main/SAPI.c
diff -u php4/main/SAPI.c:1.129 php4/main/SAPI.c:1.129.2.1
--- php4/main/SAPI.c:1.129 Mon Jan 14 08:36:54 2002
+++ php4/main/SAPI.c Sun Jun 23 13:15:07 2002
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.129 2002/01/14 13:36:54 sesser Exp $ */
+/* $Id: SAPI.c,v 1.129.2.1 2002/06/23 17:15:07 sesser Exp $ */
#include <ctype.h>
#include <sys/stat.h>
@@ -385,12 +385,17 @@
return code;
}
+static int sapi_find_matching_header(void *element1, void *element2)
+{
+ return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2,
strlen((char*)element2)) == 0;
+}
+
/* This function expects a *duplicated* string, that was previously emalloc()'d.
* Pointers sent to this functions will be automatically freed by the framework.
*/
SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate,
zend_bool replace TSRMLS_DC)
{
- int retval, free_header = 0;
+ int retval;
sapi_header_struct sapi_header;
char *colon_offset;
long myuid = 0L;
@@ -436,7 +441,7 @@
if (colon_offset) {
*colon_offset = 0;
if (!STRCASECMP(header_line, "Content-Type")) {
- char *ptr = colon_offset, *mimetype = NULL, *newheader;
+ char *ptr = colon_offset+1, *mimetype = NULL, *newheader;
size_t len = header_line_len - (ptr - header_line), newlen;
while (*ptr == ' ' && *ptr != '\0') {
ptr++;
@@ -452,7 +457,7 @@
sapi_header.header_len = newlen - 1;
colon_offset = strchr(newheader, ':');
*colon_offset = '\0';
- free_header = 1;
+ efree(header_line);
}
efree(mimetype);
SG(sapi_headers).send_default_content_type = 0;
@@ -551,10 +556,20 @@
zend_llist_clean(&SG(sapi_headers).headers);
}
if (retval & SAPI_HEADER_ADD) {
+ /* in replace mode first remove the header if it already exists in the headers llist */
+ if (replace) {
+ colon_offset = strchr(sapi_header.header, ':');
+ if (colon_offset) {
+ char sav;
+ colon_offset++;
+ sav = *colon_offset;
+ *colon_offset = 0;
+ zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*,
void*))sapi_find_matching_header);
+ *colon_offset = sav;
+ }
+ }
+
zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header);
- }
- if (free_header) {
- efree(sapi_header.header);
}
return SUCCESS;
}