Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

@- Implemented default_charset and default_mimetype config directives…

… (Stig)

Implemented default_charset and default_mimetype configuration directives.
Started implementing ticks in PHP.
  • Loading branch information...
commit d23e5d837add8aa68b4376ff6c4b3ba6b201b894 1 parent 1170876
authored February 25, 2000
6  Makefile.in
@@ -8,13 +8,13 @@ ZEND_DIR = $(srcdir)/Zend
8 8
 SUBDIRS = Zend ext sapi $(TSRM_DIR) $(REGEX_DIR) . $(PEAR_DIR)
9 9
 
10 10
 LTLIBRARY_NAME = libphp4.la
11  
-	
  11
+
12 12
 LTLIBRARY_SOURCES = \
13 13
        main.c internal_functions.c snprintf.c php_sprintf.c \
14 14
        configuration-parser.c configuration-scanner.c \
15 15
        safe_mode.c fopen-wrappers.c php_realpath.c alloca.c \
16 16
        php_ini.c SAPI.c rfc1867.c dlist.c php_content_types.c strlcpy.c \
17  
-       strlcat.c mergesort.c reentrancy.c php_variables.c
  17
+       strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c
18 18
 
19 19
 LTLIBRARY_DEPENDENCIES = \
20 20
 		Zend/libZend.la \
@@ -35,7 +35,7 @@ PROGRAM_DEPENDENCIES = $(PROGRAM_LDADD)
35 35
 targets = $(LTLIBRARY_NAME) $(PROGRAM_NAME)
36 36
 
37 37
 install_targets = install-local install-modules
38  
-	
  38
+
39 39
 include $(topsrcdir)/build/rules.mk
40 40
 include $(topsrcdir)/build/library.mk
41 41
 include $(topsrcdir)/build/program.mk
2  build/rules.mk
@@ -116,7 +116,7 @@ install-modules:
116 116
 	echo "installing shared modules into $(moduledir)" && \
117 117
 	rm -f modules/*.la && \
118 118
 	cp modules/* $(moduledir) || true
119  
-	
  119
+
120 120
 include $(srcdir)/.deps
121 121
 
122 122
 .PHONY: all-recursive clean-recursive install-recursive \
2  build/rules_pear.mk
@@ -120,7 +120,7 @@ install-modules:
120 120
 	echo "installing shared modules into $(moduledir)" && \
121 121
 	rm -f modules/*.la && \
122 122
 	cp modules/* $(moduledir) || true
123  
-	
  123
+
124 124
 include $(srcdir)/.deps
125 125
 
126 126
 .PHONY: all-recursive clean-recursive install-recursive \
20  configure.in
@@ -68,14 +68,16 @@ fi
68 68
 
69 69
 AM_CONFIG_HEADER(php_config.h)
70 70
 AM_MAINTAINER_MODE
  71
+AC_CANONICAL_HOST
71 72
 
72 73
 dnl We want this one before the checks, so the checks can modify CFLAGS.
73 74
 test -z "$CFLAGS" && auto_cflags=1
74 75
 
75  
-dnl If we're using cc on HP-UX, add -Ae -D_HPUX_SOURCE [obsolete]
76  
-dnl if test -n "$auto_cflags" && test "`uname -s 2>/dev/null`" = "HP-UX"; then
77  
-dnl   test -n "$GCC" || CFLAGS="-Ae $CFLAGS -D_HPUX_SOURCE"
78  
-dnl fi
  76
+dnl ## If we're using cc on HP-UX, add -Ae -D_HPUX_SOURCE [obsolete]
  77
+dnl ## if test -n "$auto_cflags" && test "`uname -s 2>/dev/null`" = "HP-UX"
  78
+dnl ## then
  79
+dnl ##	 test -n "$GCC" || CFLAGS="-Ae $CFLAGS -D_HPUX_SOURCE"
  80
+dnl ## fi
79 81
 
80 82
 dnl Checks for programs.
81 83
 AC_PROG_YACC
@@ -93,10 +95,10 @@ else
93 95
 fi
94 96
 
95 97
 dnl ## there has to be a better way...
96  
-dnl## OLDLIBS=$LIBS; LIBS=""
  98
+dnl ## OLDLIBS=$LIBS; LIBS=""
97 99
 AC_PROG_CC
98 100
 AC_AIX
99  
-dnl## LIBS=$OLDLIBS
  101
+dnl ## LIBS=$OLDLIBS
100 102
 
101 103
 AM_PROG_CC_STDC
102 104
 
@@ -106,9 +108,9 @@ AC_PROG_LN_S
106 108
 
107 109
 AM_PROG_LEX
108 110
 
109  
-dnl Make flex scanners use const if they can, even if __STDC__ is not
110  
-dnl true, for compilers like Sun's that only set __STDC__ true in
111  
-dnl "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
  111
+dnl ## Make flex scanners use const if they can, even if __STDC__ is not
  112
+dnl ## true, for compilers like Sun's that only set __STDC__ true in
  113
+dnl ## "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
112 114
 AC_C_CONST
113 115
 if test "$ac_cv_c_const" = "yes" ; then
114 116
   LEX_CFLAGS="-DYY_USE_CONST"
7  ext/standard/array.c
@@ -2135,3 +2135,10 @@ PHP_FUNCTION(array_multisort)
2135 2135
 	efree(args);
2136 2136
 	RETURN_TRUE;
2137 2137
 }
  2138
+
  2139
+/*
  2140
+ * Local variables:
  2141
+ * tab-width: 4
  2142
+ * c-basic-offset: 4
  2143
+ * End:
  2144
+ */
106  main/SAPI.c
@@ -177,36 +177,65 @@ SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
177 177
 }
178 178
 
179 179
 
  180
+SAPI_API char *sapi_get_default_content_type(SLS_D)
  181
+{
  182
+	char *mimetype, *charset, *content_type;
  183
+
  184
+	mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
  185
+	charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
  186
+
  187
+	if (strncasecmp(mimetype, "text/", 5) == 0 && strcasecmp(charset, "none") != 0) {
  188
+		int len = strlen(mimetype) + sizeof(";charset=") + strlen(charset);
  189
+		content_type = emalloc(len);
  190
+		strlcpy(content_type, mimetype, len);
  191
+		strlcat(content_type, ";charset=", len);
  192
+		strlcat(content_type, charset, len);
  193
+	} else {
  194
+		content_type = estrdup(mimetype);
  195
+	}
  196
+	return content_type;
  197
+}
  198
+
180 199
 /*
181  
- * Called from php_request_startup() for every request.
  200
+ * Add charset on content-type header if the MIME type starts with
  201
+ * "text/", the default_charset directive is not set to "none" and
  202
+ * there is not already a charset option in there.
  203
+ *
  204
+ * If "mimetype" is non-NULL, it should point to a pointer allocated
  205
+ * with emalloc().  If a charset is added, the string will be
  206
+ * re-allocated and the new length is returned.  If mimetype is
  207
+ * unchanged, 0 is returned.
  208
+ *
182 209
  */
183  
-SAPI_API void sapi_activate(SLS_D PLS_DC)
  210
+SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len SLS_DC)
184 211
 {
185  
-	int len;
  212
+	char *charset, *newtype;
  213
+	int newlen;
  214
+	charset = SG(default_charset) ? SG(default_charset) : SAPI_DEFAULT_CHARSET;
  215
+
  216
+	if (strcasecmp(charset, "none") != 0 && strncmp(*mimetype, "text/", 5) == 0 && strstr(*mimetype, "charset=") == NULL) {
  217
+		newlen = len + (sizeof(";charset=")-1) + strlen(charset);
  218
+		newtype = emalloc(newlen + 1);
  219
+		strlcpy(newtype, *mimetype, len);
  220
+		strlcat(newtype, ";charset=", len);
  221
+		if (*mimetype != NULL) {
  222
+			efree(*mimetype);
  223
+		}
  224
+		*mimetype = newtype;
  225
+		return newlen;
  226
+	}
  227
+	return 0;
  228
+}
186 229
 
  230
+
  231
+/*
  232
+ * Called from php_request_startup() for every request.
  233
+ */
  234
+SAPI_API void sapi_activate(SLS_D)
  235
+{
187 236
 	zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
188 237
 	SG(sapi_headers).send_default_content_type = 1;
189 238
 
190  
-	if (PG(default_mimetype) != NULL) {
191  
-		if (strncasecmp(PG(default_mimetype), "text/", 5) == 0) {
192  
-			len = strlen(PG(default_mimetype)) + sizeof(";charset=") + strlen(PG(default_charset));
193  
-			/* add charset for text output */
194  
-			SG(sapi_headers).default_content_type = emalloc(len);
195  
-			strcpy(SG(sapi_headers).default_content_type, PG(default_mimetype));
196  
-			strlcat(SG(sapi_headers).default_content_type, ";charset=", len);
197  
-			strlcat(SG(sapi_headers).default_content_type, PG(default_charset), len);
198  
-		} else {
199  
-			/* don't add charset */
200  
-			len = strlen(PG(default_mimetype)) + 1;
201  
-			SG(sapi_headers).default_content_type = emalloc(len);
202  
-			strcpy(SG(sapi_headers).default_content_type, PG(default_mimetype));
203  
-		}
204  
-		SG(sapi_headers).default_content_type[len - 1] = '\0';
205  
-		SG(sapi_headers).default_content_type_size = len;
206  
-	} else {
207  
-		SG(sapi_headers).default_content_type = NULL;
208  
-		SG(sapi_headers).default_content_type_size = 0;
209  
-	}
210 239
 	SG(sapi_headers).http_response_code = 200;
211 240
 	SG(sapi_headers).http_status_line = NULL;
212 241
 	SG(headers_sent) = 0;
@@ -295,7 +324,7 @@ static int sapi_extract_response_code(const char *header_line)
295 324
  */
296 325
 SAPI_API int sapi_add_header(char *header_line, uint header_line_len)
297 326
 {
298  
-	int retval;
  327
+	int retval, free_header = 0;
299 328
 	sapi_header_struct sapi_header;
300 329
 	char *colon_offset;
301 330
 	SLS_FETCH();
@@ -329,6 +358,25 @@ SAPI_API int sapi_add_header(char *header_line, uint header_line_len)
329 358
 		if (colon_offset) {
330 359
 			*colon_offset = 0;
331 360
 			if (!STRCASECMP(header_line, "Content-Type")) {
  361
+				char *ptr = colon_offset, *mimetype = NULL, *newheader;
  362
+				size_t len = header_line_len - (ptr - header_line), newlen;
  363
+				while (*ptr == ' ' && *ptr != '\0') {
  364
+					ptr++;
  365
+				}
  366
+				mimetype = estrdup(ptr);
  367
+				newlen = sapi_apply_default_charset(&mimetype, len);
  368
+				if (newlen != 0) {
  369
+					newlen += sizeof("Content-type: ");
  370
+					newheader = emalloc(newlen);
  371
+					strlcpy(newheader, "Content-type: ", newlen);
  372
+					strlcpy(newheader, mimetype, newlen);
  373
+					sapi_header.header = newheader;
  374
+					sapi_header.header_len = newlen - 1;
  375
+					colon_offset = strchr(newheader, ':');
  376
+					*colon_offset = '\0';
  377
+					free_header = 1;
  378
+				}
  379
+				efree(mimetype);
332 380
 				SG(sapi_headers).send_default_content_type = 0;
333 381
 			} else if (!STRCASECMP(header_line, "Location")) {
334 382
 				SG(sapi_headers).http_response_code = 302; /* redirect */
@@ -350,6 +398,9 @@ SAPI_API int sapi_add_header(char *header_line, uint header_line_len)
350 398
 	if (retval & SAPI_HEADER_ADD) {
351 399
 		zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header);
352 400
 	}
  401
+	if (free_header) {
  402
+		efree(sapi_header.header);
  403
+	}
353 404
 	return SUCCESS;
354 405
 }
355 406
 
@@ -488,3 +539,10 @@ SAPI_API char *sapi_getenv(char *name, int name_len)
488 539
 		return NULL;
489 540
 	}
490 541
 }
  542
+
  543
+/*
  544
+ * Local variables:
  545
+ * tab-width: 4
  546
+ * c-basic-offset: 4
  547
+ * End:
  548
+ */
5  main/SAPI.h
@@ -100,6 +100,8 @@ typedef struct {
100 100
 	uint read_post_bytes;
101 101
 	unsigned char headers_sent;
102 102
 	struct stat global_stat;
  103
+	char *default_mimetype;
  104
+	char *default_charset;
103 105
 } sapi_globals_struct;
104 106
 
105 107
 
@@ -142,6 +144,9 @@ SAPI_API int sapi_flush();
142 144
 SAPI_API struct stat *sapi_get_stat();
143 145
 SAPI_API char *sapi_getenv(char *name, int name_len);
144 146
 
  147
+SAPI_API char *sapi_get_default_content_type(SLS_D);
  148
+SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len SLS_DC);
  149
+
145 150
 struct _sapi_module_struct {
146 151
 	char *name;
147 152
 
14  main/main.c
@@ -66,6 +66,7 @@
66 66
 #include "zend_indent.h"
67 67
 
68 68
 #include "php_content_types.h"
  69
+#include "php_ticks.h"
69 70
 
70 71
 #include "SAPI.h"
71 72
 
@@ -202,8 +203,8 @@ PHP_INI_BEGIN()
202 203
 	STD_PHP_INI_ENTRY("auto_append_file",		NULL,		PHP_INI_ALL,		OnUpdateString,			auto_append_file,		php_core_globals,	core_globals)
203 204
 	STD_PHP_INI_ENTRY("auto_prepend_file",		NULL,		PHP_INI_ALL,		OnUpdateString,			auto_prepend_file,		php_core_globals,	core_globals)
204 205
 	STD_PHP_INI_ENTRY("doc_root",				NULL,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	doc_root,				php_core_globals,	core_globals)
205  
-	STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_MIMETYPE,	PHP_INI_ALL,	OnUpdateStringUnempty,	default_charset,		php_core_globals,	core_globals)
206  
-	STD_PHP_INI_ENTRY("default_mimetype",SAPI_DEFAULT_CHARSET,	PHP_INI_ALL,	OnUpdateStringUnempty,	default_mimetype,		php_core_globals,	core_globals)
  206
+	STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET,	PHP_INI_ALL,	OnUpdateStringUnempty,	default_charset,		sapi_globals_struct,sapi_globals)
  207
+	STD_PHP_INI_ENTRY("default_mimetype",SAPI_DEFAULT_MIMETYPE,	PHP_INI_ALL,	OnUpdateStringUnempty,	default_mimetype,		sapi_globals_struct,sapi_globals)
207 208
 	STD_PHP_INI_ENTRY("error_log",				NULL,		PHP_INI_ALL,		OnUpdateString,			error_log,				php_core_globals,	core_globals)
208 209
 	STD_PHP_INI_ENTRY("extension_dir",			NULL,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	extension_dir,			php_core_globals,	core_globals)
209 210
 	STD_PHP_INI_ENTRY("gpc_order",				"GPC",		PHP_INI_ALL,		OnUpdateStringUnempty,	gpc_order,				php_core_globals,	core_globals)
@@ -801,7 +802,7 @@ int php_module_startup(sapi_module_struct *sf)
801 802
 	zuf.block_interruptions = sapi_module.block_interruptions;
802 803
 	zuf.unblock_interruptions = sapi_module.unblock_interruptions;
803 804
 	zuf.get_ini_entry = php_get_ini_entry_for_zend;
804  
-	zuf.ticks_function = NULL;
  805
+	zuf.ticks_function = php_run_ticks;
805 806
 	zend_startup(&zuf, NULL);
806 807
 
807 808
 #ifdef ZTS
@@ -851,6 +852,11 @@ int php_module_startup(sapi_module_struct *sf)
851 852
     REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
852 853
     REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
853 854
 
  855
+	if (php_startup_ticks(PLS_C) == FAILURE) {
  856
+		php_printf("Unable to start PHP ticks\n");
  857
+		return FAILURE;
  858
+	}
  859
+
854 860
 	if (php_startup_internal_extensions() == FAILURE) {
855 861
 		php_printf("Unable to start builtin modules\n");
856 862
 		return FAILURE;
@@ -878,6 +884,7 @@ int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
878 884
 void php_module_shutdown()
879 885
 {
880 886
 	int module_number=0;	/* for UNREGISTER_INI_ENTRIES() */
  887
+	PLS_FETCH();
881 888
 
882 889
 	if (!module_initialized) {
883 890
 		return;
@@ -891,6 +898,7 @@ void php_module_shutdown()
891 898
 	WSACleanup();
892 899
 #endif
893 900
 
  901
+	php_shutdown_ticks(PLS_C);
894 902
 	sapi_flush();
895 903
 
896 904
 	global_lock_destroy();
6  main/php_globals.h
@@ -42,6 +42,7 @@ extern PHPAPI int core_globals_id;
42 42
 extern ZEND_API struct _php_core_globals core_globals;
43 43
 #endif
44 44
 
  45
+struct _php_tick_function_entry;
45 46
 
46 47
 struct _php_core_globals {
47 48
 	zend_bool magic_quotes_gpc;
@@ -83,9 +84,6 @@ struct _php_core_globals {
83 84
 	char *gpc_order;
84 85
 	char *variables_order;
85 86
 
86  
-	char *default_mimetype;
87  
-	char *default_charset;
88  
-
89 87
 	zend_bool expose_php;
90 88
 
91 89
 	zend_bool track_vars;
@@ -100,6 +98,8 @@ struct _php_core_globals {
100 98
 	long max_execution_time;
101 99
 
102 100
 	unsigned char header_is_being_sent;
  101
+
  102
+	zend_llist tick_functions;
103 103
 };
104 104
 
105 105
 
77  main/php_ticks.c
... ...
@@ -0,0 +1,77 @@
  1
+/*
  2
+   +----------------------------------------------------------------------+
  3
+   | PHP version 4.0                                                      |
  4
+   +----------------------------------------------------------------------+
  5
+   | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  6
+   +----------------------------------------------------------------------+
  7
+   | This source file is subject to version 2.0 of the PHP license,       |
  8
+   | that is bundled with this package in the file LICENSE, and is        |
  9
+   | available at through the world-wide-web at                           |
  10
+   | http://www.php.net/license/2_0.txt.                                  |
  11
+   | If you did not receive a copy of the PHP license and are unable to   |
  12
+   | obtain it through the world-wide-web, please send a note to          |
  13
+   | license@php.net so we can mail you a copy immediately.               |
  14
+   +----------------------------------------------------------------------+
  15
+   | Authors: Stig Bakken <ssb@fast.no>                                   |
  16
+   |                                                                      |
  17
+   +----------------------------------------------------------------------+
  18
+ */
  19
+
  20
+#include "php.h"
  21
+#include "php_ticks.h"
  22
+
  23
+int php_startup_ticks(PLS_D)
  24
+{
  25
+	zend_llist_init(&PG(tick_functions), sizeof(PG(tick_functions)), NULL, 1);
  26
+	return SUCCESS;
  27
+}
  28
+
  29
+void php_shutdown_ticks(PLS_D)
  30
+{
  31
+	zend_llist_destroy(&PG(tick_functions));
  32
+}
  33
+
  34
+static int php_compare_tick_functions(void *elem1, void *elem2)
  35
+{
  36
+	return ((void (*)(int))elem1 == (void (*)(int))elem2);
  37
+}
  38
+
  39
+PHPAPI int php_add_tick_function(void (*func)(int))
  40
+{
  41
+	PLS_FETCH();
  42
+
  43
+	zend_llist_add_element(&PG(tick_functions), func);
  44
+
  45
+	return SUCCESS;
  46
+}
  47
+
  48
+PHPAPI int php_remove_tick_function(void (*func)(int))
  49
+{
  50
+	PLS_FETCH();
  51
+
  52
+	zend_llist_del_element(&PG(tick_functions), func,
  53
+						   (int(*)(void*,void*))php_compare_tick_functions);
  54
+	return SUCCESS;
  55
+}
  56
+
  57
+void php_tick_iterator(void *data, void *arg)
  58
+{
  59
+	void (*func)(int);
  60
+	func = (void(*)(int))data;
  61
+	func(*((int *)arg));
  62
+}
  63
+
  64
+void php_run_ticks(int count)
  65
+{
  66
+	PLS_FETCH();
  67
+
  68
+	zend_llist_apply_with_argument(&PG(tick_functions), (void(*)(void*,void*))php_tick_iterator, &count);
  69
+}
  70
+
  71
+
  72
+/*
  73
+ * Local variables:
  74
+ * tab-width: 4
  75
+ * c-basic-offset: 4
  76
+ * End:
  77
+ */
41  main/php_ticks.h
... ...
@@ -0,0 +1,41 @@
  1
+/*
  2
+   +----------------------------------------------------------------------+
  3
+   | PHP version 4.0                                                      |
  4
+   +----------------------------------------------------------------------+
  5
+   | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  6
+   +----------------------------------------------------------------------+
  7
+   | This source file is subject to version 2.0 of the PHP license,       |
  8
+   | that is bundled with this package in the file LICENSE, and is        |
  9
+   | available at through the world-wide-web at                           |
  10
+   | http://www.php.net/license/2_0.txt.                                  |
  11
+   | If you did not receive a copy of the PHP license and are unable to   |
  12
+   | obtain it through the world-wide-web, please send a note to          |
  13
+   | license@php.net so we can mail you a copy immediately.               |
  14
+   +----------------------------------------------------------------------+
  15
+   | Authors: Stig Bakken <ssb@fast.no>                                   |
  16
+   |                                                                      |
  17
+   +----------------------------------------------------------------------+
  18
+ */
  19
+
  20
+#ifndef _PHP_TICKS_H
  21
+#define _PHP_TICKS_H
  22
+
  23
+struct _php_tick_function_entry {
  24
+	void (*func)(int count);
  25
+	struct _php_tick_function_entry *next;
  26
+};
  27
+
  28
+int php_startup_ticks(PLS_D);
  29
+void php_shutdown_ticks(PLS_D);
  30
+void php_run_ticks(int count);
  31
+PHPAPI int php_add_tick_function(void (*func)(int count));
  32
+PHPAPI int php_remove_tick_function(void (*func)(int count));
  33
+
  34
+#endif
  35
+
  36
+/*
  37
+ * Local variables:
  38
+ * tab-width: 4
  39
+ * c-basic-offset: 4
  40
+ * End:
  41
+ */
4  main/php_version.h
... ...
@@ -1,3 +1,3 @@
1 1
 /* automatically generated by configure */
2  
-/* edit configure.in to change version number */
3  
-#define PHP_VERSION "4.0b5-dev"
  2
+/* edit configure.in.in to change version number */
  3
+#define PHP_VERSION "4.0b4-dev"
9  php.ini-dist
@@ -183,6 +183,12 @@ magic_quotes_sybase	=	Off		; Use Sybase-style magic quotes (escape ' with '' ins
183 183
 auto_prepend_file	=
184 184
 auto_append_file	=
185 185
 
  186
+; As of 4.0b4, PHP always outputs a character encoding by default in
  187
+; the Content-type: header.  Set default_charset to "none" to disable
  188
+; this.  PHP's built-in default is text/html with the iso-8859-1
  189
+; charset.
  190
+;default_mimetype = "text/html"
  191
+;default_charset = "iso-8859-1"
186 192
 
187 193
 ;;;;;;;;;;;;;;;;;;;;;;;;;
188 194
 ; Paths and Directories ;
@@ -386,3 +392,6 @@ mssql.compatability_mode	= Off	; compatability mode with old versions of PHP 3.0
386 392
 ;assert.callback			=	0	; user-function to be called if an assertion fails.
387 393
 ;assert.quiet_eval			=	0	; eval the expression with current error_reporting(). set to true if you want error_reporting(0) around the eval().
388 394
 
  395
+; Local Variables:
  396
+; tab-width: 4
  397
+; End:
24  sapi/apache/mod_php4.c
@@ -399,6 +399,22 @@ static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry)
399 399
 	return 0;
400 400
 }
401 401
 
  402
+static char *php_apache_get_default_mimetype(request_rec *r SLS_DC)
  403
+{
  404
+	
  405
+	char *mimetype;
  406
+	if (SG(default_mimetype) || SG(default_charset)) {
  407
+		/* Assume output will be of the default MIME type.  Individual
  408
+		   scripts may change this later. */
  409
+		char *tmpmimetype;
  410
+		tmpmimetype = sapi_get_default_content_type(SLS_C);
  411
+		mimetype = pstrdup(r->pool, tmpmimetype);
  412
+		efree(tmpmimetype);
  413
+	} else {
  414
+		mimetype = SAPI_DEFAULT_CONTENT_TYPE;
  415
+	}
  416
+	return mimetype;
  417
+}
402 418
 
403 419
 int send_php(request_rec *r, int display_source_mode, char *filename)
404 420
 {
@@ -428,7 +444,7 @@ int send_php(request_rec *r, int display_source_mode, char *filename)
428 444
 	 * directive, then decline to handle this request
429 445
 	 */
430 446
 	if (!php_apache_info.engine) {
431  
-		r->content_type = SAPI_DEFAULT_CONTENT_TYPE; /* XXX FIXME use default_{mimetype|charset} directives */
  447
+		r->content_type = php_apache_get_default_mimetype(r SLS_CC);
432 448
 		r->allowed |= (1 << METHODS) - 1;
433 449
 		return DECLINED;
434 450
 	}
@@ -458,9 +474,9 @@ int send_php(request_rec *r, int display_source_mode, char *filename)
458 474
 		set_etag(r);
459 475
 #endif
460 476
 	}
461  
-	/* Assume output will be HTML.  Individual scripts may change this 
462  
-	   further down the line */
463  
-	r->content_type = SAPI_DEFAULT_CONTENT_TYPE; /* XXX FIXME use default_{mimetype|charset} directives */
  477
+	/* Assume output will be of the default MIME type.  Individual
  478
+	   scripts may change this later in the request. */
  479
+	r->content_type = php_apache_get_default_mimetype(r SLS_CC);
464 480
 
465 481
 	/* Init timeout */
466 482
 	hard_timeout("send", r);

0 notes on commit d23e5d8

Please sign in to comment.
Something went wrong with that request. Please try again.