]> granicus.if.org Git - php/commitdiff
- From CODING_STANDARDS:
authorZeev Suraski <zeev@php.net>
Sat, 26 Feb 2000 05:03:41 +0000 (05:03 +0000)
committerZeev Suraski <zeev@php.net>
Sat, 26 Feb 2000 05:03:41 +0000 (05:03 +0000)
  [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

main/SAPI.c
main/SAPI.h
sapi/apache/mod_php4.c
sapi/isapi/php4isapi.c

index b5d4a5408090b58ca2a7b62817cbdfd0e6bdb785..1cd3c432230a4b1b8616c804ef5321ed139d7c87 100644 (file)
@@ -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;
index 71b25104b7d18457932bfa17aff2ad8546975a7e..28d12a80b92da94106f7ff870df545139caae9ba 100644 (file)
@@ -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)
index bbdbc8b0b7f820098db0ca142440fc34b889cc95..e411604720bb273544ae9cc21b9f67877f1efce6 100644 (file)
@@ -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;
 }
index 8bcb3b06dd506af4db4b0f1d554eadd378d63157..3c2e049b00f3871cd3eb3f54eb631e3c8fbe1aae 100644 (file)
@@ -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';