Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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