Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 922 lines (808 sloc) 27.256 kb
651e232f »
1999-04-09 Testing 123
1 /*
2 +----------------------------------------------------------------------+
dbeb4158 »
2004-01-08 - A belated happy holidays and PHP 5
3 | PHP Version 5 |
651e232f »
1999-04-09 Testing 123
4 +----------------------------------------------------------------------+
9ba1e816 »
2010-01-03 sed -i "s#1997-2009#1997-2010#g" **/*.c **/*.h **/*.php
5 | Copyright (c) 1997-2010 The PHP Group |
651e232f »
1999-04-09 Testing 123
6 +----------------------------------------------------------------------+
5bd93221 »
2006-01-01 bump year and license version
7 | This source file is subject to version 3.01 of the PHP license, |
9d1817ed »
2001-05-06 Fix bug: #10323. Every value outputted is now escaped.
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff2 »
2003-06-10 updating license information in the headers.
9 | available through the world-wide-web at the following url: |
5bd93221 »
2006-01-01 bump year and license version
10 | http://www.php.net/license/3_01.txt |
c5724cbd »
1999-07-16 License update
11 | If you did not receive a copy of the PHP license and are unable to |
9d1817ed »
2001-05-06 Fix bug: #10323. Every value outputted is now escaped.
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. |
651e232f »
1999-04-09 Testing 123
14 +----------------------------------------------------------------------+
9d1817ed »
2001-05-06 Fix bug: #10323. Every value outputted is now escaped.
15 | Author: Zeev Suraski <zeev@zend.com> |
651e232f »
1999-04-09 Testing 123
16 +----------------------------------------------------------------------+
17 */
18
46a7b0cf »
2002-03-05 Killing compiler warning on Win32
19 /* $Id$ */
651e232f »
1999-04-09 Testing 123
20
aceaabce »
1999-04-07 PHP 4.0
21 #include "php.h"
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
22 #include "ext/standard/info.h"
1fd09132 »
2000-10-29 Initial steps to move the INI mechanism to the Zend engine
23 #include "zend_ini.h"
09b6f37f »
2007-09-28 MFH:
24 #include "zend_ini_scanner.h"
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
25 #include "php_ini.h"
26 #include "ext/standard/dl.h"
27 #include "zend_extensions.h"
9d1817ed »
2001-05-06 Fix bug: #10323. Every value outputted is now escaped.
28 #include "zend_highlight.h"
ab256405 »
2002-02-28 Removed CWD from php_ini_search_path when using CLI SAPI.
29 #include "SAPI.h"
46a7b0cf »
2002-03-05 Killing compiler warning on Win32
30 #include "php_main.h"
ec11fe04 »
2003-02-19 Fix the possible conflicts with other libs (like libc-client)
31 #include "php_scandir.h"
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
32 #ifdef PHP_WIN32
33 #include "win32/php_registry.h"
34 #endif
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
35
ec11fe04 »
2003-02-19 Fix the possible conflicts with other libs (like libc-client)
36 #if HAVE_SCANDIR && HAVE_ALPHASORT && HAVE_DIRENT_H
37 #include <dirent.h>
82f6cef4 »
2003-01-26 Fix broken build by adding scandir and alphasort for win32
38 #endif
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
39
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
40 #ifndef S_ISREG
41 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
42 #endif
43
8e5a00e5 »
2009-10-09 - changed ini file directives [PATH=](on Win32) and [HOST=](on all) t…
44 #ifdef PHP_WIN32
4d63bd11 »
2009-10-11 - #48779, don't loop twice over the path chars
45 #define TRANSLATE_SLASHES_LOWER(path) \
8e5a00e5 »
2009-10-09 - changed ini file directives [PATH=](on Win32) and [HOST=](on all) t…
46 { \
47 char *tmp = path; \
48 while (*tmp) { \
49 if (*tmp == '\\') *tmp = '/'; \
e5d4b019 »
2009-10-12 - #48779, improve fix, drop usage of _tolower and use zend_strtolower
50 else *tmp = tolower(*tmp); \
4d63bd11 »
2009-10-11 - #48779, don't loop twice over the path chars
51 tmp++; \
8e5a00e5 »
2009-10-09 - changed ini file directives [PATH=](on Win32) and [HOST=](on all) t…
52 } \
53 }
54 #else
4d63bd11 »
2009-10-11 - #48779, don't loop twice over the path chars
55 #define TRANSLATE_SLASHES_LOWER(path)
8e5a00e5 »
2009-10-09 - changed ini file directives [PATH=](on Win32) and [HOST=](on all) t…
56 #endif
57
58
d294f46f »
2001-01-15 - Remove the ini_extension_list global
59 typedef struct _php_extension_lists {
42c82bb4 »
2002-05-09 Revert the last patches.
60 zend_llist engine;
61 zend_llist functions;
d294f46f »
2001-01-15 - Remove the ini_extension_list global
62 } php_extension_lists;
58e24ac1 »
1999-08-13 - Add PHP Modules workspace
63
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
64 /* True globals */
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
65 static int is_special_section = 0;
09b6f37f »
2007-09-28 MFH:
66 static HashTable *active_ini_hash;
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
67 static HashTable configuration_hash;
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
68 static int has_per_dir_config = 0;
69 static int has_per_host_config = 0;
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
70 PHPAPI char *php_ini_opened_path=NULL;
71 static php_extension_lists extension_lists;
e5e6f553 »
2008-08-13 MFH
72 PHPAPI char *php_ini_scanned_path=NULL;
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
73 PHPAPI char *php_ini_scanned_files=NULL;
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
74
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
75 /* {{{ php_ini_displayer_cb
76 */
09b6f37f »
2007-09-28 MFH:
77 static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type TSRMLS_DC)
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
78 {
42c82bb4 »
2002-05-09 Revert the last patches.
79 if (ini_entry->displayer) {
80 ini_entry->displayer(ini_entry, type);
81 } else {
82 char *display_string;
83 uint display_string_length, esc_html=0;
84
7e3b5089 »
2003-02-19 ws/style fixes
85 if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
42c82bb4 »
2002-05-09 Revert the last patches.
86 if (ini_entry->orig_value && ini_entry->orig_value[0]) {
87 display_string = ini_entry->orig_value;
88 display_string_length = ini_entry->orig_value_length;
b5c97d8d »
2003-03-29 fix phpinfo() & php -i
89 esc_html = !sapi_module.phpinfo_as_text;
42c82bb4 »
2002-05-09 Revert the last patches.
90 } else {
b5c97d8d »
2003-03-29 fix phpinfo() & php -i
91 if (!sapi_module.phpinfo_as_text) {
d6497fc9 »
2002-08-29 - reenable "no value" output. thanks to sebastian for pointing that …
92 display_string = "<i>no value</i>";
7e3b5089 »
2003-02-19 ws/style fixes
93 display_string_length = sizeof("<i>no value</i>") - 1;
d6497fc9 »
2002-08-29 - reenable "no value" output. thanks to sebastian for pointing that …
94 } else {
95 display_string = "no value";
7e3b5089 »
2003-02-19 ws/style fixes
96 display_string_length = sizeof("no value") - 1;
9be89ed6 »
2007-08-31 MFH: ws fixes
97 }
42c82bb4 »
2002-05-09 Revert the last patches.
98 }
99 } else if (ini_entry->value && ini_entry->value[0]) {
100 display_string = ini_entry->value;
101 display_string_length = ini_entry->value_length;
b5c97d8d »
2003-03-29 fix phpinfo() & php -i
102 esc_html = !sapi_module.phpinfo_as_text;
42c82bb4 »
2002-05-09 Revert the last patches.
103 } else {
b5c97d8d »
2003-03-29 fix phpinfo() & php -i
104 if (!sapi_module.phpinfo_as_text) {
d6497fc9 »
2002-08-29 - reenable "no value" output. thanks to sebastian for pointing that …
105 display_string = "<i>no value</i>";
7e3b5089 »
2003-02-19 ws/style fixes
106 display_string_length = sizeof("<i>no value</i>") - 1;
d6497fc9 »
2002-08-29 - reenable "no value" output. thanks to sebastian for pointing that …
107 } else {
108 display_string = "no value";
7e3b5089 »
2003-02-19 ws/style fixes
109 display_string_length = sizeof("no value") - 1;
9be89ed6 »
2007-08-31 MFH: ws fixes
110 }
42c82bb4 »
2002-05-09 Revert the last patches.
111 }
7e3b5089 »
2003-02-19 ws/style fixes
112
113 if (esc_html) {
a769454d »
2002-05-12 reenable php_html_puts
114 php_html_puts(display_string, display_string_length TSRMLS_CC);
42c82bb4 »
2002-05-09 Revert the last patches.
115 } else {
116 PHPWRITE(display_string, display_string_length);
117 }
118 }
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
119 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
120 /* }}} */
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
121
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
122 /* {{{ php_ini_displayer
123 */
d76cf1da »
2001-07-31 More TSRMLS_FETCH work
124 static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC)
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
125 {
42c82bb4 »
2002-05-09 Revert the last patches.
126 if (ini_entry->module_number != module_number) {
127 return 0;
128 }
b5c97d8d »
2003-03-29 fix phpinfo() & php -i
129 if (!sapi_module.phpinfo_as_text) {
14a6cc88 »
2002-09-19 Change phpinfo() to use CSS styling instead of HTML code.
130 PUTS("<tr>");
c7c275b7 »
2002-09-26 fix phpinfo() output for better browser BC
131 PUTS("<td class=\"e\">");
7e3b5089 »
2003-02-19 ws/style fixes
132 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
c7c275b7 »
2002-09-26 fix phpinfo() output for better browser BC
133 PUTS("</td><td class=\"v\">");
09b6f37f »
2007-09-28 MFH:
134 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC);
c7c275b7 »
2002-09-26 fix phpinfo() output for better browser BC
135 PUTS("</td><td class=\"v\">");
09b6f37f »
2007-09-28 MFH:
136 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG TSRMLS_CC);
66766176 »
2002-08-28 - add phpinfo() support for CLI.
137 PUTS("</td></tr>\n");
138 } else {
7e3b5089 »
2003-02-19 ws/style fixes
139 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
66766176 »
2002-08-28 - add phpinfo() support for CLI.
140 PUTS(" => ");
09b6f37f »
2007-09-28 MFH:
141 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC);
66766176 »
2002-08-28 - add phpinfo() support for CLI.
142 PUTS(" => ");
09b6f37f »
2007-09-28 MFH:
143 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG TSRMLS_CC);
66766176 »
2002-08-28 - add phpinfo() support for CLI.
144 PUTS("\n");
9be89ed6 »
2007-08-31 MFH: ws fixes
145 }
42c82bb4 »
2002-05-09 Revert the last patches.
146 return 0;
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
147 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
148 /* }}} */
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
149
d6d41215 »
2008-12-30 - MFH Do not show empty ini directive tables for modules without ini …
150 /* {{{ php_ini_available
151 */
152 static int php_ini_available(zend_ini_entry *ini_entry, int *module_number_available TSRMLS_DC)
153 {
154 if (ini_entry->module_number == *module_number_available) {
155 *module_number_available = -1;
156 return ZEND_HASH_APPLY_STOP;
157 } else {
158 return ZEND_HASH_APPLY_KEEP;
159 }
160 }
161 /* }}} */
162
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
163 /* {{{ display_ini_entries
164 */
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
165 PHPAPI void display_ini_entries(zend_module_entry *module)
166 {
d6d41215 »
2008-12-30 - MFH Do not show empty ini directive tables for modules without ini …
167 int module_number, module_number_available;
42c82bb4 »
2002-05-09 Revert the last patches.
168 TSRMLS_FETCH();
169
170 if (module) {
171 module_number = module->module_number;
9be89ed6 »
2007-08-31 MFH: ws fixes
172 } else {
42c82bb4 »
2002-05-09 Revert the last patches.
173 module_number = 0;
174 }
d6d41215 »
2008-12-30 - MFH Do not show empty ini directive tables for modules without ini …
175 module_number_available = module_number;
176 zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_available, &module_number_available TSRMLS_CC);
177 if (module_number_available == -1) {
178 php_info_print_table_start();
179 php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
180 zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (zend_intptr_t) module_number TSRMLS_CC);
181 php_info_print_table_end();
182 }
bc415d5a »
1999-05-09 * Finalizing the PHP version of SAPI. Support POST and cookies among …
183 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
184 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
185
186 /* php.ini support */
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
187 #define PHP_EXTENSION_TOKEN "extension"
d29d2442 »
2009-05-18 - MFH: Get rid of the four different versions of zend_extension* and …
188 #define ZEND_EXTENSION_TOKEN "zend_extension"
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
189
09b6f37f »
2007-09-28 MFH:
190 /* {{{ config_zval_dtor
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
191 */
16749763 »
2007-09-28 MFH: Fixed win32 build.
192 PHPAPI void config_zval_dtor(zval *zvalue)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
193 {
09b6f37f »
2007-09-28 MFH:
194 if (Z_TYPE_P(zvalue) == IS_ARRAY) {
195 zend_hash_destroy(Z_ARRVAL_P(zvalue));
196 free(Z_ARRVAL_P(zvalue));
197 } else if (Z_TYPE_P(zvalue) == IS_STRING) {
198 free(Z_STRVAL_P(zvalue));
199 }
200 }
201 /* Reset / free active_ini_sectin global */
202 #define RESET_ACTIVE_INI_HASH() do { \
203 active_ini_hash = NULL; \
204 } while (0)
205 /* }}} */
206
207 /* {{{ php_ini_parser_cb
208 */
209 static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, HashTable *target_hash)
210 {
211 zval *entry;
212 HashTable *active_hash;
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
213 char *extension_name;
09b6f37f »
2007-09-28 MFH:
214
215 if (active_ini_hash) {
216 active_hash = active_ini_hash;
217 } else {
218 active_hash = target_hash;
219 }
220
42c82bb4 »
2002-05-09 Revert the last patches.
221 switch (callback_type) {
222 case ZEND_INI_PARSER_ENTRY: {
223 if (!arg2) {
09b6f37f »
2007-09-28 MFH:
224 /* bare string - nothing to do */
42c82bb4 »
2002-05-09 Revert the last patches.
225 break;
226 }
09b6f37f »
2007-09-28 MFH:
227
228 /* PHP and Zend extensions are not added into configuration hash! */
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
229 if (!is_special_section && !strcasecmp(Z_STRVAL_P(arg1), PHP_EXTENSION_TOKEN)) { /* load PHP extension */
230 extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
231 zend_llist_add_element(&extension_lists.functions, &extension_name);
232 } else if (!is_special_section && !strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
233 extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
42c82bb4 »
2002-05-09 Revert the last patches.
234 zend_llist_add_element(&extension_lists.engine, &extension_name);
09b6f37f »
2007-09-28 MFH:
235
236 /* All other entries are added into either configuration_hash or active ini section array */
42c82bb4 »
2002-05-09 Revert the last patches.
237 } else {
09b6f37f »
2007-09-28 MFH:
238 /* Store in active hash */
239 zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
42c82bb4 »
2002-05-09 Revert the last patches.
240 Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
241 }
242 }
243 break;
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
244
245 case ZEND_INI_PARSER_POP_ENTRY: {
09b6f37f »
2007-09-28 MFH:
246 zval *option_arr;
247 zval *find_arr;
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
248
249 if (!arg2) {
250 /* bare string - nothing to do */
251 break;
252 }
253
09b6f37f »
2007-09-28 MFH:
254 /* fprintf(stdout, "ZEND_INI_PARSER_POP_ENTRY: %s[%s] = %s\n",Z_STRVAL_P(arg1), Z_STRVAL_P(arg3), Z_STRVAL_P(arg2)); */
255
256 /* If option not found in hash or is not an array -> create array, otherwise add to existing array */
257 if (zend_hash_find(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_arr) == FAILURE || Z_TYPE_P(find_arr) != IS_ARRAY) {
258 option_arr = (zval *) pemalloc(sizeof(zval), 1);
259 INIT_PZVAL(option_arr);
260 Z_TYPE_P(option_arr) = IS_ARRAY;
261 Z_ARRVAL_P(option_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1);
262 zend_hash_init(Z_ARRVAL_P(option_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1);
263 zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, option_arr, sizeof(zval), (void **) &find_arr);
264 free(option_arr);
265 }
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
266
09b6f37f »
2007-09-28 MFH:
267 /* arg3 is possible option offset name */
268 if (arg3 && Z_STRLEN_P(arg3) > 0) {
269 zend_symtable_update(Z_ARRVAL_P(find_arr), Z_STRVAL_P(arg3), Z_STRLEN_P(arg3) + 1, arg2, sizeof(zval), (void **) &entry);
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
270 } else {
09b6f37f »
2007-09-28 MFH:
271 zend_hash_next_index_insert(Z_ARRVAL_P(find_arr), arg2, sizeof(zval), (void **) &entry);
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
272 }
09b6f37f »
2007-09-28 MFH:
273 Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
b51b6f0f »
2003-01-19 ini patch to allow 'entry[] = value' entries
274 }
275 break;
276
09b6f37f »
2007-09-28 MFH:
277 case ZEND_INI_PARSER_SECTION: { /* Create an array of entries of each section */
278
279 /* fprintf(stdout, "ZEND_INI_PARSER_SECTION: %s\n",Z_STRVAL_P(arg1)); */
280
281 char *key = NULL;
282 uint key_len;
283
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
284 /* PATH sections */
09b6f37f »
2007-09-28 MFH:
285 if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", sizeof("PATH") - 1)) {
286 key = Z_STRVAL_P(arg1);
287 key = key + sizeof("PATH") - 1;
288 key_len = Z_STRLEN_P(arg1) - sizeof("PATH") + 1;
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
289 is_special_section = 1;
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
290 has_per_dir_config = 1;
8e5a00e5 »
2009-10-09 - changed ini file directives [PATH=](on Win32) and [HOST=](on all) t…
291
4d63bd11 »
2009-10-11 - #48779, don't loop twice over the path chars
292 /* make the path lowercase on Windows, for case insensitivty. Does nothign for other platforms */
293 TRANSLATE_SLASHES_LOWER(key);
09b6f37f »
2007-09-28 MFH:
294
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
295 /* HOST sections */
09b6f37f »
2007-09-28 MFH:
296 } else if (!strncasecmp(Z_STRVAL_P(arg1), "HOST", sizeof("HOST") - 1)) {
297 key = Z_STRVAL_P(arg1);
298 key = key + sizeof("HOST") - 1;
299 key_len = Z_STRLEN_P(arg1) - sizeof("HOST") + 1;
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
300 is_special_section = 1;
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
301 has_per_host_config = 1;
994307d4 »
2009-10-09 - Fixed build and comment-style
302 zend_str_tolower(key, key_len); /* host names are case-insensitive. */
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
303
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
304 } else {
305 is_special_section = 0;
09b6f37f »
2007-09-28 MFH:
306 }
307
308 if (key && key_len > 0) {
309 /* Strip any trailing slashes */
310 while (key_len > 0 && (key[key_len - 1] == '/' || key[key_len - 1] == '\\')) {
311 key_len--;
312 key[key_len] = 0;
313 }
314
315 /* Strip any leading whitespace and '=' */
316 while (*key && (
317 *key == '=' ||
318 *key == ' ' ||
319 *key == '\t'
320 )) {
321 key++;
322 key_len--;
323 }
324
325 /* Search for existing entry and if it does not exist create one */
326 if (zend_hash_find(target_hash, key, key_len + 1, (void **) &entry) == FAILURE) {
327 zval *section_arr;
328
329 section_arr = (zval *) pemalloc(sizeof(zval), 1);
330 INIT_PZVAL(section_arr);
331 Z_TYPE_P(section_arr) = IS_ARRAY;
332 Z_ARRVAL_P(section_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1);
333 zend_hash_init(Z_ARRVAL_P(section_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1);
334 zend_hash_update(target_hash, key, key_len + 1, section_arr, sizeof(zval), (void **) &entry);
335 free(section_arr);
336 }
337 active_ini_hash = Z_ARRVAL_P(entry);
338 }
339 }
42c82bb4 »
2002-05-09 Revert the last patches.
340 break;
341 }
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
342 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
343 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
344
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
345 /* {{{ php_load_php_extension_cb
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
346 */
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
347 static void php_load_php_extension_cb(void *arg TSRMLS_DC)
db0b8bc0 »
2001-01-15 Defer loading of extensions until all configuration entries have been
348 {
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
349 php_load_extension(*((char **) arg), MODULE_PERSISTENT, 0 TSRMLS_CC);
d294f46f »
2001-01-15 - Remove the ini_extension_list global
350 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
351 /* }}} */
d294f46f »
2001-01-15 - Remove the ini_extension_list global
352
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
353 /* {{{ php_load_zend_extension_cb
354 */
d76cf1da »
2001-07-31 More TSRMLS_FETCH work
355 static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
d294f46f »
2001-01-15 - Remove the ini_extension_list global
356 {
42c82bb4 »
2002-05-09 Revert the last patches.
357 zend_load_extension(*((char **) arg));
db0b8bc0 »
2001-01-15 Defer loading of extensions until all configuration entries have been
358 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
359 /* }}} */
db0b8bc0 »
2001-01-15 Defer loading of extensions until all configuration entries have been
360
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
361 /* {{{ php_init_config
362 */
64cfbf53 »
2005-09-01 MFH: - Fixed bug #34307 (OnUpdateStringUnempty INI options can be set…
363 int php_init_config(TSRMLS_D)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
364 {
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
365 char *php_ini_file_name = NULL;
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
366 char *php_ini_search_path = NULL;
1463a824 »
2008-08-13 - move declaration on top and fix build error
367 int php_ini_scanned_path_len;
42c82bb4 »
2002-05-09 Revert the last patches.
368 int safe_mode_state;
369 char *open_basedir;
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
370 int free_ini_search_path = 0;
42c82bb4 »
2002-05-09 Revert the last patches.
371 zend_file_handle fh;
372
09b6f37f »
2007-09-28 MFH:
373 if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) config_zval_dtor, 1) == FAILURE) {
1890173d »
2005-09-02 Revert
374 return FAILURE;
375 }
376
63739c7d »
2003-03-18 give sapi modules the possibility to overwrite default ini settings
377 if (sapi_module.ini_defaults) {
378 sapi_module.ini_defaults(&configuration_hash);
379 }
380
42c82bb4 »
2002-05-09 Revert the last patches.
381 zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
c75b8876 »
2007-11-26 MFH: No zval is stored here
382 zend_llist_init(&extension_lists.functions, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
9be89ed6 »
2007-08-31 MFH: ws fixes
383
42c82bb4 »
2002-05-09 Revert the last patches.
384 safe_mode_state = PG(safe_mode);
385 open_basedir = PG(open_basedir);
386
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
387 if (sapi_module.php_ini_path_override) {
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
388 php_ini_file_name = sapi_module.php_ini_path_override;
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
389 php_ini_search_path = sapi_module.php_ini_path_override;
390 free_ini_search_path = 0;
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
391 } else if (!sapi_module.php_ini_ignore) {
112462d1 »
2006-12-28 MFH
392 int search_path_size;
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
393 char *default_location;
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
394 char *env_location;
395 char *binary_location;
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
396 static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
24793840 »
2003-10-20 Fixed unused variable warning on *nix.
397 #ifdef PHP_WIN32
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
398 char *reg_location;
24793840 »
2003-10-20 Fixed unused variable warning on *nix.
399 #endif
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
400
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
401 env_location = getenv("PHPRC");
402 if (!env_location) {
403 env_location = "";
404 }
405
406 /*
407 * Prepare search path
408 */
409
112462d1 »
2006-12-28 MFH
410 search_path_size = MAXPATHLEN * 4 + strlen(env_location) + 3 + 1;
411 php_ini_search_path = (char *) emalloc(search_path_size);
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
412 free_ini_search_path = 1;
413 php_ini_search_path[0] = 0;
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
414
acb1e079 »
2006-07-04 Changed priority of PHPRC environment variable on win32 to be higher …
415 /* Add environment location */
416 if (env_location[0]) {
417 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
418 strlcat(php_ini_search_path, paths_separator, search_path_size);
acb1e079 »
2006-07-04 Changed priority of PHPRC environment variable on win32 to be higher …
419 }
112462d1 »
2006-12-28 MFH
420 strlcat(php_ini_search_path, env_location, search_path_size);
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
421 php_ini_file_name = env_location;
acb1e079 »
2006-07-04 Changed priority of PHPRC environment variable on win32 to be higher …
422 }
423
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
424 #ifdef PHP_WIN32
425 /* Add registry location */
426 reg_location = GetIniPathFromRegistry();
f66d5f0c »
2005-07-29 - Fixed few logic errors in php*.ini search path creation as document…
427 if (reg_location != NULL) {
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
428 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
429 strlcat(php_ini_search_path, paths_separator, search_path_size);
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
430 }
112462d1 »
2006-12-28 MFH
431 strlcat(php_ini_search_path, reg_location, search_path_size);
06aae4bd »
2003-10-19 Enable setting php.ini path via the registry
432 efree(reg_location);
433 }
434 #endif
42c82bb4 »
2002-05-09 Revert the last patches.
435
ef058cdd »
2006-09-05 Search for php.ini in CWD in all sapi's *but* CLI.
436 /* Add cwd (not with CLI) */
437 if (strcmp(sapi_module.name, "cli") != 0) {
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
438 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
439 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
440 }
112462d1 »
2006-12-28 MFH
441 strlcat(php_ini_search_path, ".", search_path_size);
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
442 }
42c82bb4 »
2002-05-09 Revert the last patches.
443
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
444 /* Add binary directory */
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
445 #ifdef PHP_WIN32
b9fd1078 »
2002-05-11 Use portable #define
446 binary_location = (char *) emalloc(MAXPATHLEN);
7e3b5089 »
2003-02-19 ws/style fixes
447 if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
448 efree(binary_location);
449 binary_location = NULL;
42c82bb4 »
2002-05-09 Revert the last patches.
450 }
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
451 #else
452 if (sapi_module.executable_location) {
0db4f06f »
2007-05-19 MFH
453 binary_location = (char *)emalloc(MAXPATHLEN);
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
454 if (!strchr(sapi_module.executable_location, '/')) {
90989468 »
2007-05-12 MFH: bug#41361 (shell_exec() does not find binaries)
455 char *envpath, *path;
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
456 int found = 0;
457
90989468 »
2007-05-12 MFH: bug#41361 (shell_exec() does not find binaries)
458 if ((envpath = getenv("PATH")) != NULL) {
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
459 char *search_dir, search_path[MAXPATHLEN];
63c11738 »
2007-05-10 use php_strtok_r() rather than strsep()
460 char *last;
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
461
d85fc29e »
2007-05-14 MFH
462 path = estrdup(envpath);
63c11738 »
2007-05-10 use php_strtok_r() rather than strsep()
463 search_dir = php_strtok_r(path, ":", &last);
d85fc29e »
2007-05-14 MFH
464
63c11738 »
2007-05-10 use php_strtok_r() rather than strsep()
465 while (search_dir) {
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
466 snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
467 if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
468 found = 1;
469 break;
470 }
63c11738 »
2007-05-10 use php_strtok_r() rather than strsep()
471 search_dir = php_strtok_r(NULL, ":", &last);
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
472 }
d85fc29e »
2007-05-14 MFH
473 efree(path);
448dbac8 »
2007-05-06 MFH: Fixed PHP CLI to use the php.ini from the binary location
474 }
475 if (!found) {
476 efree(binary_location);
477 binary_location = NULL;
478 }
479 } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
7e071d9a »
2005-07-27 php.ini search logic needs to use the absolute path of the running bi…
480 efree(binary_location);
9be89ed6 »
2007-08-31 MFH: ws fixes
481 binary_location = NULL;
98694f91 »
2005-07-27 ws fix
482 }
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
483 } else {
484 binary_location = NULL;
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
485 }
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
486 #endif
487 if (binary_location) {
488 char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
9be89ed6 »
2007-08-31 MFH: ws fixes
489
882cb200 »
2005-07-27 edge case: do not remove trailing slash for root directory (Bug #33882)
490 if (separator_location && separator_location != binary_location) {
7e071d9a »
2005-07-27 php.ini search logic needs to use the absolute path of the running bi…
491 *(separator_location) = 0;
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
492 }
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
493 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
494 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
495 }
112462d1 »
2006-12-28 MFH
496 strlcat(php_ini_search_path, binary_location, search_path_size);
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
497 efree(binary_location);
498 }
499
500 /* Add default location */
501 #ifdef PHP_WIN32
7e3b5089 »
2003-02-19 ws/style fixes
502 default_location = (char *) emalloc(MAXPATHLEN + 1);
9be89ed6 »
2007-08-31 MFH: ws fixes
503
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
504 if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
505 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
506 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
507 }
112462d1 »
2006-12-28 MFH
508 strlcat(php_ini_search_path, default_location, search_path_size);
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
509 }
fcdda2e8 »
2003-12-06 Fix a problem resolving the php.ini path under win32 terminal service…
510
112379ba »
2009-10-11 - fix possible issue in TS environment (we don't have to do that anym…
511 /* For people running under terminal services, GetWindowsDirectory will
512 * return their personal Windows directory, so lets add the system
513 * windows directory too */
514 if (0 < GetSystemWindowsDirectory(default_location, MAXPATHLEN)) {
515 if (*php_ini_search_path) {
516 strlcat(php_ini_search_path, paths_separator, search_path_size);
fcdda2e8 »
2003-12-06 Fix a problem resolving the php.ini path under win32 terminal service…
517 }
112379ba »
2009-10-11 - fix possible issue in TS environment (we don't have to do that anym…
518 strlcat(php_ini_search_path, default_location, search_path_size);
fcdda2e8 »
2003-12-06 Fix a problem resolving the php.ini path under win32 terminal service…
519 }
112379ba »
2009-10-11 - fix possible issue in TS environment (we don't have to do that anym…
520 efree(default_location);
521
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
522 #else
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
523 default_location = PHP_CONFIG_FILE_PATH;
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
524 if (*php_ini_search_path) {
112462d1 »
2006-12-28 MFH
525 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
526 }
112462d1 »
2006-12-28 MFH
527 strlcat(php_ini_search_path, default_location, search_path_size);
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
528 #endif
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
529 }
6de4f3a4 »
2002-05-09 Add check for php.ini in same directory as php.exe (or equivalent exe…
530
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
531 PG(safe_mode) = 0;
532 PG(open_basedir) = NULL;
533
e5e6f553 »
2008-08-13 MFH
534 /*
535 * Find and open actual ini file
536 */
537
e52aac94 »
2003-02-18 Implement simple stream support in the ZE scanners.
538 memset(&fh, 0, sizeof(fh));
e5e6f553 »
2008-08-13 MFH
539
540 /* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
541 * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
542 * load an optional ini file. */
543 if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
544
545 /* Check if php_ini_file_name is a file and can be opened */
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
546 if (php_ini_file_name && php_ini_file_name[0]) {
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
547 struct stat statbuf;
9be89ed6 »
2007-08-31 MFH: ws fixes
548
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
549 if (!VCWD_STAT(php_ini_file_name, &statbuf)) {
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
550 if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
c946b4d1 »
2006-08-03 In addtion to path to php.ini, PHPRC now may specify full file name
551 fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r");
552 if (fh.handle.fp) {
553 fh.filename = php_ini_opened_path = expand_filepath(php_ini_file_name, NULL TSRMLS_CC);
554 }
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
555 }
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
556 }
557 }
e5e6f553 »
2008-08-13 MFH
558
559 /* Otherwise search for php-%sapi-module-name%.ini file in search path */
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
560 if (!fh.handle.fp) {
561 const char *fmt = "php-%s.ini";
50ea2676 »
2007-02-24 - Avoid sprintf, even when checked copy'n'paste or changes lead to er…
562 char *ini_fname;
563 spprintf(&ini_fname, 0, fmt, sapi_module.name);
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
564 fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
565 efree(ini_fname);
566 if (fh.handle.fp) {
567 fh.filename = php_ini_opened_path;
568 }
e1658ed6 »
2002-08-12 Minor cleanups to path building and php*.ini search logic.
569 }
e5e6f553 »
2008-08-13 MFH
570
571 /* If still no ini file found, search for php.ini file in search path */
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
572 if (!fh.handle.fp) {
573 fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
574 if (fh.handle.fp) {
575 fh.filename = php_ini_opened_path;
576 }
8f94a8a7 »
2002-07-29 First try to open php-SAPI.ini and if it fails fall back to regular
577 }
751cd67c »
2002-05-19 get_cfg_var("get_file_path") didn't work correctly when an alternative
578 }
7e3b5089 »
2003-02-19 ws/style fixes
579
5af649ef »
2002-05-11 Revert to the old php_ini.c, and reimplement the binary-path searching.
580 if (free_ini_search_path) {
581 efree(php_ini_search_path);
582 }
7e3b5089 »
2003-02-19 ws/style fixes
583
42c82bb4 »
2002-05-09 Revert the last patches.
584 PG(safe_mode) = safe_mode_state;
585 PG(open_basedir) = open_basedir;
586
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
587 if (fh.handle.fp) {
588 fh.type = ZEND_HANDLE_FP;
09b6f37f »
2007-09-28 MFH:
589 RESET_ACTIVE_INI_HASH();
42c82bb4 »
2002-05-09 Revert the last patches.
590
09b6f37f »
2007-09-28 MFH:
591 zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
9be89ed6 »
2007-08-31 MFH: ws fixes
592
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
593 {
594 zval tmp;
9be89ed6 »
2007-08-31 MFH: ws fixes
595
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
596 Z_STRLEN(tmp) = strlen(fh.filename);
597 Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
598 Z_TYPE(tmp) = IS_STRING;
4b4d634c »
2007-10-07 MFH: Added macros for managing zval refcounts and is_ref statuses
599 Z_SET_REFCOUNT(tmp, 0);
09b6f37f »
2007-09-28 MFH:
600
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
601 zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
7e3b5089 »
2003-02-19 ws/style fixes
602 if (php_ini_opened_path) {
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
603 efree(php_ini_opened_path);
7e3b5089 »
2003-02-19 ws/style fixes
604 }
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
605 php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
606 }
cecb9dfc »
2002-11-12 Implemented -n switch to skip parsing ini at startup as suggested by …
607 }
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
608
e5e6f553 »
2008-08-13 MFH
609 /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
610 php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
611 if (!php_ini_scanned_path) {
612 /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
613 php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
614 }
1463a824 »
2008-08-13 - move declaration on top and fix build error
615 php_ini_scanned_path_len = strlen(php_ini_scanned_path);
e5e6f553 »
2008-08-13 MFH
616
617 /* Scan and parse any .ini files found in scan path if path not empty. */
618 if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
619 struct dirent **namelist;
620 int ndir, i;
09b6f37f »
2007-09-28 MFH:
621 struct stat sb;
622 char ini_file[MAXPATHLEN];
623 char *p;
624 zend_file_handle fh;
625 zend_llist scanned_ini_list;
626 zend_llist_element *element;
627 int l, total_l = 0;
628
629 /* Reset active ini section */
630 RESET_ACTIVE_INI_HASH();
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
631
e5e6f553 »
2008-08-13 MFH
632 if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
09b6f37f »
2007-09-28 MFH:
633 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
634 memset(&fh, 0, sizeof(fh));
635
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
636 for (i = 0; i < ndir; i++) {
09b6f37f »
2007-09-28 MFH:
637
638 /* check for any file with .ini extension */
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
639 if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
640 free(namelist[i]);
d454becd »
2002-12-30 - Whitespace
641 continue;
642 }
e5e6f553 »
2008-08-13 MFH
643 if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
644 snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
645 } else {
646 snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
647 }
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
648 if (VCWD_STAT(ini_file, &sb) == 0) {
649 if (S_ISREG(sb.st_mode)) {
650 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
651 fh.filename = ini_file;
1ad304c2 »
2003-02-28 MFB config-file-scan-dir crash fix
652 fh.type = ZEND_HANDLE_FP;
09b6f37f »
2007-09-28 MFH:
653
654 if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC) == SUCCESS) {
655 /* Here, add it to the list of ini files read */
656 l = strlen(ini_file);
657 total_l += l + 2;
658 p = estrndup(ini_file, l);
659 zend_llist_add_element(&scanned_ini_list, &p);
660 }
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
661 }
662 }
663 }
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
664 free(namelist[i]);
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
665 }
8d352d2d »
2003-01-25 Fixed bug #21625 (When scanning a directory for ini files, do so in
666 free(namelist);
667
3781af53 »
2004-02-14 - Fixed zero bytes memory allocation when no extra ini files are foun…
668 if (total_l) {
09b6f37f »
2007-09-28 MFH:
669 int php_ini_scanned_files_len = (php_ini_scanned_files) ? strlen(php_ini_scanned_files) + 1 : 0;
670 php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1);
671 if (!php_ini_scanned_files_len) {
672 *php_ini_scanned_files = '\0';
673 }
674 total_l += php_ini_scanned_files_len;
3781af53 »
2004-02-14 - Fixed zero bytes memory allocation when no extra ini files are foun…
675 for (element = scanned_ini_list.head; element; element = element->next) {
09b6f37f »
2007-09-28 MFH:
676 if (php_ini_scanned_files_len) {
677 strlcat(php_ini_scanned_files, ",\n", total_l);
678 }
112462d1 »
2006-12-28 MFH
679 strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
680 strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
9be89ed6 »
2007-08-31 MFH: ws fixes
681 }
3781af53 »
2004-02-14 - Fixed zero bytes memory allocation when no extra ini files are foun…
682 }
ac9f4cc2 »
2004-02-14 - We always need to destroy the llist though.
683 zend_llist_destroy(&scanned_ini_list);
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
684 }
e5e6f553 »
2008-08-13 MFH
685 } else {
686 /* Make sure an empty php_ini_scanned_path ends up as NULL */
687 php_ini_scanned_path = NULL;
42c82bb4 »
2002-05-09 Revert the last patches.
688 }
7d14dad0 »
2006-09-19 MFH: Fixed mess with CGI/CLI -d command line option (now it works wit…
689
690 if (sapi_module.ini_entries) {
09b6f37f »
2007-09-28 MFH:
691 /* Reset active ini section */
692 RESET_ACTIVE_INI_HASH();
693 zend_parse_ini_string(sapi_module.ini_entries, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
7d14dad0 »
2006-09-19 MFH: Fixed mess with CGI/CLI -d command line option (now it works wit…
694 }
695
42c82bb4 »
2002-05-09 Revert the last patches.
696 return SUCCESS;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
697 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
698 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
699
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
700 /* {{{ php_shutdown_config
701 */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
702 int php_shutdown_config(void)
703 {
42c82bb4 »
2002-05-09 Revert the last patches.
704 zend_hash_destroy(&configuration_hash);
705 if (php_ini_opened_path) {
706 free(php_ini_opened_path);
2a2d49b9 »
2004-09-17 Fixed bug #30050 (Possible crash inside php_shutdown_config()).
707 php_ini_opened_path = NULL;
42c82bb4 »
2002-05-09 Revert the last patches.
708 }
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
709 if (php_ini_scanned_files) {
710 free(php_ini_scanned_files);
2a2d49b9 »
2004-09-17 Fixed bug #30050 (Possible crash inside php_shutdown_config()).
711 php_ini_scanned_files = NULL;
989a61ed »
2002-10-04 As discussed, add --with-config-file-scan-dir compile-time switch def…
712 }
42c82bb4 »
2002-05-09 Revert the last patches.
713 return SUCCESS;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
714 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
715 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
716
f47c7848 »
2005-06-17 Improved PHP extension loading mechanism with support for module depe…
717 /* {{{ php_ini_register_extensions
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
718 */
f47c7848 »
2005-06-17 Improved PHP extension loading mechanism with support for module depe…
719 void php_ini_register_extensions(TSRMLS_D)
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
720 {
42c82bb4 »
2002-05-09 Revert the last patches.
721 zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
722 zend_llist_apply(&extension_lists.functions, php_load_php_extension_cb TSRMLS_CC);
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
723
42c82bb4 »
2002-05-09 Revert the last patches.
724 zend_llist_destroy(&extension_lists.engine);
725 zend_llist_destroy(&extension_lists.functions);
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
726 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
727 /* }}} */
9db55891 »
2001-03-17 Recode delayed loading in a much simpler way (switched back to php_in…
728
09b6f37f »
2007-09-28 MFH:
729 /* {{{ php_parse_user_ini_file
730 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
731 PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC)
09b6f37f »
2007-09-28 MFH:
732 {
733 struct stat sb;
734 char ini_file[MAXPATHLEN];
735 zend_file_handle fh;
736
737 snprintf(ini_file, MAXPATHLEN, "%s%c%s", dirname, DEFAULT_SLASH, ini_filename);
738
739 if (VCWD_STAT(ini_file, &sb) == 0) {
740 if (S_ISREG(sb.st_mode)) {
741 memset(&fh, 0, sizeof(fh));
742 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
743 fh.filename = ini_file;
744 fh.type = ZEND_HANDLE_FP;
745
746 /* Reset active ini section */
747 RESET_ACTIVE_INI_HASH();
748
749 if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, target_hash TSRMLS_CC) == SUCCESS) {
750 /* FIXME: Add parsed file to the list of user files read? */
751 return SUCCESS;
752 }
753 return FAILURE;
754 }
755 }
756 }
757 return FAILURE;
758 }
759 /* }}} */
760
761 /* {{{ php_ini_activate_config
762 */
763 PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC)
764 {
765 char *str;
766 zval *data;
767 uint str_len;
768 ulong num_index;
769
770 /* Walk through config hash and alter matching ini entries using the values found in the hash */
771 for (zend_hash_internal_pointer_reset(source_hash);
772 zend_hash_get_current_key_ex(source_hash, &str, &str_len, &num_index, 0, NULL) == HASH_KEY_IS_STRING;
773 zend_hash_move_forward(source_hash)
774 ) {
775 zend_hash_get_current_data(source_hash, (void **) &data);
776 zend_alter_ini_entry_ex(str, str_len, Z_STRVAL_P(data), Z_STRLEN_P(data), modify_type, stage, 0 TSRMLS_CC);
777 }
778 }
779 /* }}} */
780
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
781 /* {{{ php_ini_has_per_dir_config
782 */
783 PHPAPI int php_ini_has_per_dir_config(void)
784 {
785 return has_per_dir_config;
786 }
787 /* }}} */
788
09b6f37f »
2007-09-28 MFH:
789 /* {{{ php_ini_activate_per_dir_config
790 */
791 PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
792 {
793 zval *tmp;
794 char *ptr;
795
e4adfe4f »
2009-10-15 - #48779, fix another use case where / usage may differ
796 #if PHP_WIN32
797 char path_bak[MAXPATHLEN];
798 memcpy(path_bak, path, path_len);
799 path_bak[path_len] = 0;
800 TRANSLATE_SLASHES_LOWER(path_bak);
801 path = path_bak;
802 #endif
803
09b6f37f »
2007-09-28 MFH:
804 /* Walk through each directory in path and apply any found per-dir-system-configuration from configuration_hash */
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
805 if (has_per_dir_config && path && path_len) {
09b6f37f »
2007-09-28 MFH:
806 ptr = path + 1;
e4adfe4f »
2009-10-15 - #48779, fix another use case where / usage may differ
807 while ((ptr = strchr(ptr, '/')) != NULL) {
09b6f37f »
2007-09-28 MFH:
808 *ptr = 0;
809 /* Search for source array matching the path from configuration_hash */
e421bee7 »
2010-01-16 - Fixed bug #48811 (Directives in PATH section do not get applied to …
810 if (zend_hash_find(&configuration_hash, path, strlen(path) + 1, (void **) &tmp) == SUCCESS) {
09b6f37f »
2007-09-28 MFH:
811 php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
812 }
813 *ptr = '/';
814 ptr++;
815 }
816 }
817 }
818 /* }}} */
819
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
820 /* {{{ php_ini_has_per_host_config
821 */
822 PHPAPI int php_ini_has_per_host_config(void)
823 {
824 return has_per_host_config;
825 }
826 /* }}} */
827
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
828 /* {{{ php_ini_activate_per_host_config
829 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
830 PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSRMLS_DC)
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
831 {
832 zval *tmp;
833
ba8e3174 »
2008-04-15 Optimized request startup sequence for php.ini without per dir and pe…
834 if (has_per_host_config && host && host_len) {
02d966c2 »
2007-11-09 MFH:- Added support for [HOST=www.example.com] special sections
835 /* Search for source array matching the host from configuration_hash */
836 if (zend_hash_find(&configuration_hash, host, host_len, (void **) &tmp) == SUCCESS) {
837 php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
838 }
839 }
840 }
841 /* }}} */
842
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
843 /* {{{ cfg_get_entry
844 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
845 PHPAPI zval *cfg_get_entry(const char *name, uint name_length)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
846 {
42c82bb4 »
2002-05-09 Revert the last patches.
847 zval *tmp;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
848
7e3b5089 »
2003-02-19 ws/style fixes
849 if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
42c82bb4 »
2002-05-09 Revert the last patches.
850 return tmp;
851 } else {
852 return NULL;
853 }
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
854 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
855 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
856
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
857 /* {{{ cfg_get_long
858 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
859 PHPAPI int cfg_get_long(const char *varname, long *result)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
860 {
42c82bb4 »
2002-05-09 Revert the last patches.
861 zval *tmp, var;
b9ddb5cb »
2007-08-31 MFH
862
7e3b5089 »
2003-02-19 ws/style fixes
863 if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
e1814f0d »
2007-04-16 WIN64 support
864 *result = 0;
42c82bb4 »
2002-05-09 Revert the last patches.
865 return FAILURE;
866 }
867 var = *tmp;
868 zval_copy_ctor(&var);
869 convert_to_long(&var);
870 *result = Z_LVAL(var);
871 return SUCCESS;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
872 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
873 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
874
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
875 /* {{{ cfg_get_double
876 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
877 PHPAPI int cfg_get_double(const char *varname, double *result)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
878 {
42c82bb4 »
2002-05-09 Revert the last patches.
879 zval *tmp, var;
b9ddb5cb »
2007-08-31 MFH
880
7e3b5089 »
2003-02-19 ws/style fixes
881 if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
882 *result = (double) 0;
42c82bb4 »
2002-05-09 Revert the last patches.
883 return FAILURE;
884 }
885 var = *tmp;
886 zval_copy_ctor(&var);
887 convert_to_double(&var);
888 *result = Z_DVAL(var);
889 return SUCCESS;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
890 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
891 /* }}} */
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
892
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
893 /* {{{ cfg_get_string
894 */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
895 PHPAPI int cfg_get_string(const char *varname, char **result)
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
896 {
42c82bb4 »
2002-05-09 Revert the last patches.
897 zval *tmp;
898
7e3b5089 »
2003-02-19 ws/style fixes
899 if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
900 *result = NULL;
42c82bb4 »
2002-05-09 Revert the last patches.
901 return FAILURE;
902 }
903 *result = Z_STRVAL_P(tmp);
904 return SUCCESS;
78194a47 »
2000-10-30 - Complete the move to the new INI parser. (Side effect: at last, people
905 }
81e2cf03 »
2001-06-06 Fix folding and clean up some extensions
906 /* }}} */
2cf1b8d3 »
2001-04-22 * expanded the following constants and made them available in PHP:
907
fa94dabd »
2008-02-03 - MFH Rename dump_config_hash() to get_config_hash() as it doesn't dump
908 PHPAPI HashTable* php_ini_get_configuration_hash(void) /* {{{ */
09b6f37f »
2007-09-28 MFH:
909 {
fa94dabd »
2008-02-03 - MFH Rename dump_config_hash() to get_config_hash() as it doesn't dump
910 return &configuration_hash;
911 } /* }}} */
09b6f37f »
2007-09-28 MFH:
912
2cf1b8d3 »
2001-04-22 * expanded the following constants and made them available in PHP:
913 /*
914 * Local variables:
915 * tab-width: 4
916 * c-basic-offset: 4
917 * indent-tabs-mode: t
918 * End:
78747bd2 »
2001-09-09 - Don't wrap lines... this is annoying while coding.
919 * vim600: sw=4 ts=4 fdm=marker
920 * vim<600: sw=4 ts=4
2cf1b8d3 »
2001-04-22 * expanded the following constants and made them available in PHP:
921 */
Something went wrong with that request. Please try again.