Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 541 lines (485 sloc) 14.783 kb
651e232 @zsuraski Testing 123
zsuraski authored
1 /*
2 +----------------------------------------------------------------------+
3893351 Update headers.
Sebastian Bergmann authored
3 | PHP Version 4 |
651e232 @zsuraski Testing 123
zsuraski authored
4 +----------------------------------------------------------------------+
3893351 Update headers.
Sebastian Bergmann authored
5 | Copyright (c) 1997-2002 The PHP Group |
651e232 @zsuraski Testing 123
zsuraski authored
6 +----------------------------------------------------------------------+
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
7 | This source file is subject to version 2.02 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_02.txt. |
c5724cb @zsuraski License update
zsuraski authored
11 | If you did not receive a copy of the PHP license and are unable to |
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
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. |
651e232 @zsuraski Testing 123
zsuraski authored
14 +----------------------------------------------------------------------+
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
15 | Author: Zeev Suraski <zeev@zend.com> |
651e232 @zsuraski Testing 123
zsuraski authored
16 +----------------------------------------------------------------------+
17 */
18
46a7b0c @fmk Killing compiler warning on Win32
fmk authored
19 /* $Id$ */
651e232 @zsuraski Testing 123
zsuraski authored
20
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
21 /* Check CWD for php.ini */
22 #define INI_CHECK_CWD
23
aceaabc @zsuraski PHP 4.0
zsuraski authored
24 #include "php.h"
3798528 NetWare related changes/modifications
Anantha Kesari H Y authored
25 #if !defined(PHP_WIN32) && !defined(NETWARE)
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
26 #include "build-defs.h"
0be5cca @fmk Fix build on WIn32
fmk authored
27 #endif
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
28 #include "ext/standard/info.h"
1fd0913 @zsuraski Initial steps to move the INI mechanism to the Zend engine
zsuraski authored
29 #include "zend_ini.h"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
30 #include "php_ini.h"
31 #include "ext/standard/dl.h"
32 #include "zend_extensions.h"
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
33 #include "zend_highlight.h"
ab25640 Removed CWD from php_ini_search_path when using CLI SAPI.
Edin Kadribasic authored
34 #include "SAPI.h"
46a7b0c @fmk Killing compiler warning on Win32
fmk authored
35 #include "php_main.h"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
36
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
37 #ifndef S_ISREG
38 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
39 #endif
40
d294f46 @zsuraski - Remove the ini_extension_list global
zsuraski authored
41 typedef struct _php_extension_lists {
42c82bb Revert the last patches.
foobar authored
42 zend_llist engine;
43 zend_llist functions;
d294f46 @zsuraski - Remove the ini_extension_list global
zsuraski authored
44 } php_extension_lists;
58e24ac @zsuraski - Add PHP Modules workspace
zsuraski authored
45
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
46
47 /* True globals */
48 static HashTable configuration_hash;
49 PHPAPI char *php_ini_opened_path=NULL;
50 static php_extension_lists extension_lists;
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
51 PHPAPI char *php_ini_scanned_files=NULL;
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
52
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
53 /* {{{ php_ini_displayer_cb
54 */
1fd0913 @zsuraski Initial steps to move the INI mechanism to the Zend engine
zsuraski authored
55 static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
56 {
42c82bb Revert the last patches.
foobar authored
57 if (ini_entry->displayer) {
58 ini_entry->displayer(ini_entry, type);
59 } else {
60 char *display_string;
61 uint display_string_length, esc_html=0;
62 TSRMLS_FETCH();
63
64 if (type==ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
65 if (ini_entry->orig_value && ini_entry->orig_value[0]) {
66 display_string = ini_entry->orig_value;
67 display_string_length = ini_entry->orig_value_length;
68 esc_html=1;
69 } else {
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
70 if (PG(html_errors)) {
71 display_string = "<i>no value</i>";
72 display_string_length = sizeof("<i>no value</i>")-1;
73 } else {
74 display_string = "no value";
75 display_string_length = sizeof("no value")-1;
76 }
42c82bb Revert the last patches.
foobar authored
77 }
78 } else if (ini_entry->value && ini_entry->value[0]) {
79 display_string = ini_entry->value;
80 display_string_length = ini_entry->value_length;
81 esc_html=1;
82 } else {
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
83 if (PG(html_errors)) {
84 display_string = "<i>no value</i>";
85 display_string_length = sizeof("<i>no value</i>")-1;
86 } else {
87 display_string = "no value";
88 display_string_length = sizeof("no value")-1;
89 }
42c82bb Revert the last patches.
foobar authored
90 }
91 if(esc_html) {
a769454 reenable php_html_puts
Sascha Schumann authored
92 php_html_puts(display_string, display_string_length TSRMLS_CC);
42c82bb Revert the last patches.
foobar authored
93 } else {
94 PHPWRITE(display_string, display_string_length);
95 }
96 }
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
97 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
98 /* }}} */
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
99
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
100 /* {{{ php_ini_displayer
101 */
d76cf1d @zsuraski More TSRMLS_FETCH work
zsuraski authored
102 static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC)
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
103 {
42c82bb Revert the last patches.
foobar authored
104 if (ini_entry->module_number != module_number) {
105 return 0;
106 }
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
107 if (PG(html_errors)) {
14a6cc8 Change phpinfo() to use CSS styling instead of HTML code.
Colin Viebrock authored
108 PUTS("<tr>");
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
109 PUTS("<td class=\"e\">");
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
110 PHPWRITE(ini_entry->name, ini_entry->name_length-1);
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
111 PUTS("</td><td class=\"v\">");
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
112 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
113 PUTS("</td><td class=\"v\">");
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
114 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
115 PUTS("</td></tr>\n");
116 } else {
117 PHPWRITE(ini_entry->name, ini_entry->name_length-1);
118 PUTS(" => ");
119 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
120 PUTS(" => ");
121 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
122 PUTS("\n");
123 }
42c82bb Revert the last patches.
foobar authored
124 return 0;
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
125 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
126 /* }}} */
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
127
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
128 /* {{{ display_ini_entries
129 */
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
130 PHPAPI void display_ini_entries(zend_module_entry *module)
131 {
42c82bb Revert the last patches.
foobar authored
132 int module_number;
133 TSRMLS_FETCH();
134
135 if (module) {
136 module_number = module->module_number;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
137 } else {
42c82bb Revert the last patches.
foobar authored
138 module_number = 0;
139 }
140 php_info_print_table_start();
141 php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
2f4ed25 @zsuraski Compat fix
zsuraski authored
142 zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC);
42c82bb Revert the last patches.
foobar authored
143 php_info_print_table_end();
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
144 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
145 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
146
147 /* php.ini support */
148
149 #ifdef ZTS
150 # if (ZEND_DEBUG)
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
151 # define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
152 # else
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
153 # define ZEND_EXTENSION_TOKEN "zend_extension_ts"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
154 # endif
155 #else
156 # if (ZEND_DEBUG)
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
157 # define ZEND_EXTENSION_TOKEN "zend_extension_debug"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
158 # else
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
159 # define ZEND_EXTENSION_TOKEN "zend_extension"
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
160 # endif
161 #endif
162
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
163 /* {{{ pvalue_config_destructor
164 */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
165 static void pvalue_config_destructor(zval *pvalue)
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
166 {
167 if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
168 free(Z_STRVAL_P(pvalue));
169 }
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
170 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
171 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
172
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
173 /* {{{ php_config_ini_parser_cb
174 */
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
175 static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
176 {
42c82bb Revert the last patches.
foobar authored
177 switch (callback_type) {
178 case ZEND_INI_PARSER_ENTRY: {
179 zval *entry;
180
181 if (!arg2) {
182 break;
183 }
184 if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
185 zval copy;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
186
42c82bb Revert the last patches.
foobar authored
187 copy = *arg2;
188 zval_copy_ctor(&copy);
189 copy.refcount = 0;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
190 zend_llist_add_element(&extension_lists.functions, &copy);
42c82bb Revert the last patches.
foobar authored
191 } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
192 char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
193
42c82bb Revert the last patches.
foobar authored
194 zend_llist_add_element(&extension_lists.engine, &extension_name);
195 } else {
196 zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry);
197 Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
198 }
199 }
200 break;
201 case ZEND_INI_PARSER_SECTION:
202 break;
203 }
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
204 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
205 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
206
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
207 /* {{{ php_load_function_extension_cb
208 */
d76cf1d @zsuraski More TSRMLS_FETCH work
zsuraski authored
209 static void php_load_function_extension_cb(void *arg TSRMLS_DC)
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
210 {
42c82bb Revert the last patches.
foobar authored
211 zval *extension = (zval *) arg;
212 zval zval;
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
213
42c82bb Revert the last patches.
foobar authored
214 php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC);
d294f46 @zsuraski - Remove the ini_extension_list global
zsuraski authored
215 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
216 /* }}} */
d294f46 @zsuraski - Remove the ini_extension_list global
zsuraski authored
217
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
218 /* {{{ php_load_zend_extension_cb
219 */
d76cf1d @zsuraski More TSRMLS_FETCH work
zsuraski authored
220 static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
d294f46 @zsuraski - Remove the ini_extension_list global
zsuraski authored
221 {
42c82bb Revert the last patches.
foobar authored
222 zend_load_extension(*((char **) arg));
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
223 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
224 /* }}} */
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
225
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
226 /* {{{ php_init_config
227 */
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
228 int php_init_config()
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
229 {
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
230 char *env_location, *php_ini_search_path;
231 char *binary_location;
42c82bb Revert the last patches.
foobar authored
232 int safe_mode_state;
233 char *open_basedir;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
234 int free_ini_search_path=0;
42c82bb Revert the last patches.
foobar authored
235 zend_file_handle fh;
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
236 DIR *dirp = NULL;
237 struct dirent *dir_entry;
238 struct stat sb;
239 char ini_file[MAXPATHLEN];
240 char *p;
241 zend_llist scanned_ini_list;
242 int l, total_l=0;
243 zend_llist_element *element;
42c82bb Revert the last patches.
foobar authored
244 TSRMLS_FETCH();
245
246 if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
247 return FAILURE;
248 }
249
250 zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
251 zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
252 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
253
42c82bb Revert the last patches.
foobar authored
254 safe_mode_state = PG(safe_mode);
255 open_basedir = PG(open_basedir);
256
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
257 env_location = getenv("PHPRC");
258 if (!env_location) {
259 env_location="";
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
260 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
261 if (sapi_module.php_ini_path_override) {
262 php_ini_search_path = sapi_module.php_ini_path_override;
263 free_ini_search_path = 0;
264 } else {
265 char *default_location;
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
266 static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
267
b9fd107 @zsuraski Use portable #define
zsuraski authored
268 php_ini_search_path = (char *) emalloc(MAXPATHLEN*3+strlen(env_location)+3+1);
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
269 free_ini_search_path = 1;
270 php_ini_search_path[0] = 0;
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
271
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
272 /*
273 * Prepare search path
274 */
42c82bb Revert the last patches.
foobar authored
275
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
276 /* Add cwd */
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
277 #ifdef INI_CHECK_CWD
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
278 if (strcmp(sapi_module.name, "cli")!=0) {
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
279 if (*php_ini_search_path) {
280 strcat(php_ini_search_path, paths_separator);
281 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
282 strcat(php_ini_search_path, ".");
283 }
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
284 #endif
42c82bb Revert the last patches.
foobar authored
285
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
286 /* Add binary directory */
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
287 #ifdef PHP_WIN32
b9fd107 @zsuraski Use portable #define
zsuraski authored
288 binary_location = (char *) emalloc(MAXPATHLEN);
289 if (GetModuleFileName(0, binary_location, MAXPATHLEN)==0) {
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
290 efree(binary_location);
291 binary_location = NULL;
42c82bb Revert the last patches.
foobar authored
292 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
293 #else
294 if (sapi_module.executable_location) {
295 binary_location = estrdup(sapi_module.executable_location);
296 } else {
297 binary_location = NULL;
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
298 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
299 #endif
300 if (binary_location) {
301 char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
302
303 if (separator_location) {
304 *(separator_location+1) = 0;
305 }
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
306 if (*php_ini_search_path) {
307 strcat(php_ini_search_path, paths_separator);
308 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
309 strcat(php_ini_search_path, binary_location);
310 efree(binary_location);
311 }
312
313 /* Add environment location */
314 if (env_location[0]) {
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
315 if (*php_ini_search_path) {
316 strcat(php_ini_search_path, paths_separator);
317 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
318 strcat(php_ini_search_path, env_location);
319 }
320
321 /* Add default location */
322 #ifdef PHP_WIN32
b9fd107 @zsuraski Use portable #define
zsuraski authored
323 default_location = (char *) emalloc(MAXPATHLEN+1);
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
324
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
325 if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
326 if (*php_ini_search_path) {
327 strcat(php_ini_search_path, paths_separator);
328 }
329 strcat(php_ini_search_path, default_location);
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
330 }
331 efree(default_location);
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
332 #else
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
333 default_location = PHP_CONFIG_FILE_PATH;
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
334 if (*php_ini_search_path) {
335 strcat(php_ini_search_path, paths_separator);
336 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
337 strcat(php_ini_search_path, default_location);
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
338 #endif
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
339 }
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
340
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
341 PG(safe_mode) = 0;
342 PG(open_basedir) = NULL;
343
344 fh.handle.fp = NULL;
345 /* Check if php_ini_path_override is a file */
346 if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
347 struct stat statbuf;
348
349 if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) {
350 if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
351 fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r");
751cd67 get_cfg_var("get_file_path") didn't work correctly when an alternative
Sander Roobol authored
352 fh.filename = sapi_module.php_ini_path_override;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
353 }
354 }
355 }
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
356 /* Search php-%sapi-module-name%.ini file in search path */
357 if (!fh.handle.fp) {
358 const char *fmt = "php-%s.ini";
359 char *ini_fname=emalloc(strlen(fmt)+strlen(sapi_module.name));
360 sprintf(ini_fname, fmt, sapi_module.name);
361 fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
362 efree(ini_fname);
363 if (fh.handle.fp) {
364 fh.filename = php_ini_opened_path;
365 }
366 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
367 /* Search php.ini file in search path */
751cd67 get_cfg_var("get_file_path") didn't work correctly when an alternative
Sander Roobol authored
368 if (!fh.handle.fp) {
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
369 fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
370 if (fh.handle.fp) {
371 fh.filename = php_ini_opened_path;
8f94a8a First try to open php-SAPI.ini and if it fails fall back to regular
Edin Kadribasic authored
372 }
751cd67 get_cfg_var("get_file_path") didn't work correctly when an alternative
Sander Roobol authored
373 }
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
374 if (free_ini_search_path) {
375 efree(php_ini_search_path);
376 }
42c82bb Revert the last patches.
foobar authored
377 PG(safe_mode) = safe_mode_state;
378 PG(open_basedir) = open_basedir;
379
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
380 if (fh.handle.fp) {
381 fh.type = ZEND_HANDLE_FP;
42c82bb Revert the last patches.
foobar authored
382
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
383 zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
384
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
385 {
386 zval tmp;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
387
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
388 Z_STRLEN(tmp) = strlen(fh.filename);
389 Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
390 Z_TYPE(tmp) = IS_STRING;
391 zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
392 if(php_ini_opened_path)
393 efree(php_ini_opened_path);
394 php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
395 }
396 }
397
398 /* If the config_file_scan_dir is set at compile-time, go and scan this directory and
399 * parse any .ini files found in this directory. */
400 if(strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
401 dirp = VCWD_OPENDIR(PHP_CONFIG_FILE_SCAN_DIR);
402 if (dirp) {
403 fh.type = ZEND_HANDLE_FP;
404 while ((dir_entry = readdir(dirp)) != NULL) {
405 /* check for a .ini extension */
406 if ((p = strrchr(dir_entry->d_name,'.')) && strcmp(p,".ini")) continue;
407 snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, dir_entry->d_name);
408 if (VCWD_STAT(ini_file, &sb) == 0) {
409 if (S_ISREG(sb.st_mode)) {
410 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
411 fh.filename = ini_file;
412 zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
413 /* Here, add it to the list of ini files read */
414 l = strlen(ini_file);
415 total_l += l+2;
416 p = estrndup(ini_file,l);
417 zend_llist_add_element(&scanned_ini_list, &p);
418 }
419 }
420 }
421 }
422 closedir(dirp);
423 /*
424 * Don't need an extra byte for the \0 in this malloc as the last
425 * element will not get a trailing , which gives us the byte for the \0
426 */
427 php_ini_scanned_files = (char *)malloc(total_l);
428 *php_ini_scanned_files = '\0';
429 for (element=scanned_ini_list.head; element; element=element->next) {
430 strcat(php_ini_scanned_files,*(char **)element->data);
431 strcat(php_ini_scanned_files,element->next ? ",\n":"\n");
432 }
433 zend_llist_destroy(&scanned_ini_list);
434 }
42c82bb Revert the last patches.
foobar authored
435 }
436 return SUCCESS;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
437 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
438 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
439
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
440 /* {{{ php_shutdown_config
441 */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
442 int php_shutdown_config(void)
443 {
42c82bb Revert the last patches.
foobar authored
444 zend_hash_destroy(&configuration_hash);
445 if (php_ini_opened_path) {
446 free(php_ini_opened_path);
447 }
989a61e @rlerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
448 if (php_ini_scanned_files) {
449 free(php_ini_scanned_files);
450 }
42c82bb Revert the last patches.
foobar authored
451 return SUCCESS;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
452 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
453 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
454
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
455 /* {{{ php_ini_delayed_modules_startup
456 */
d76cf1d @zsuraski More TSRMLS_FETCH work
zsuraski authored
457 void php_ini_delayed_modules_startup(TSRMLS_D)
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
458 {
42c82bb Revert the last patches.
foobar authored
459 zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
460 zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC);
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
461
42c82bb Revert the last patches.
foobar authored
462 zend_llist_destroy(&extension_lists.engine);
463 zend_llist_destroy(&extension_lists.functions);
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
464 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
465 /* }}} */
9db5589 @zsuraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
466
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
467 /* {{{ cfg_get_entry
468 */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
469 zval *cfg_get_entry(char *name, uint name_length)
470 {
42c82bb Revert the last patches.
foobar authored
471 zval *tmp;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
472
42c82bb Revert the last patches.
foobar authored
473 if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) {
474 return tmp;
475 } else {
476 return NULL;
477 }
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
478 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
479 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
480
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
481 /* {{{ cfg_get_long
482 */
1159c84 @zsuraski - TSRMLS_FETCH work
zsuraski authored
483 PHPAPI int cfg_get_long(char *varname, long *result)
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
484 {
42c82bb Revert the last patches.
foobar authored
485 zval *tmp, var;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
486
42c82bb Revert the last patches.
foobar authored
487 if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
488 *result=(long)NULL;
489 return FAILURE;
490 }
491 var = *tmp;
492 zval_copy_ctor(&var);
493 convert_to_long(&var);
494 *result = Z_LVAL(var);
495 return SUCCESS;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
496 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
497 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
498
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
499 /* {{{ cfg_get_double
500 */
1159c84 @zsuraski - TSRMLS_FETCH work
zsuraski authored
501 PHPAPI int cfg_get_double(char *varname, double *result)
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
502 {
42c82bb Revert the last patches.
foobar authored
503 zval *tmp, var;
5af649e @zsuraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
504
42c82bb Revert the last patches.
foobar authored
505 if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
506 *result=(double)0;
507 return FAILURE;
508 }
509 var = *tmp;
510 zval_copy_ctor(&var);
511 convert_to_double(&var);
512 *result = Z_DVAL(var);
513 return SUCCESS;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
514 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
515 /* }}} */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
516
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
517 /* {{{ cfg_get_string
518 */
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
519 PHPAPI int cfg_get_string(char *varname, char **result)
520 {
42c82bb Revert the last patches.
foobar authored
521 zval *tmp;
522
523 if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) {
524 *result=NULL;
525 return FAILURE;
526 }
527 *result = Z_STRVAL_P(tmp);
528 return SUCCESS;
78194a4 @zsuraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
529 }
81e2cf0 @rlerdorf Fix folding and clean up some extensions
rlerdorf authored
530 /* }}} */
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
531
532 /*
533 * Local variables:
534 * tab-width: 4
535 * c-basic-offset: 4
536 * indent-tabs-mode: t
537 * End:
78747bd - Don't wrap lines... this is annoying while coding.
Derick Rethans authored
538 * vim600: sw=4 ts=4 fdm=marker
539 * vim<600: sw=4 ts=4
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
540 */
Something went wrong with that request. Please try again.