");
115 | PUTS("| ");
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 | } else {
123 | PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
124 | PUTS(" => ");
125 | php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
126 | PUTS(" => ");
127 | php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
128 | PUTS("\n");
129 | }
130 | return 0;
131 | }
132 | /* }}} */
133 |
134 | /* {{{ display_ini_entries
135 | */
136 | PHPAPI void display_ini_entries(zend_module_entry *module)
137 | {
138 | int module_number;
139 | TSRMLS_FETCH();
140 |
141 | if (module) {
142 | module_number = module->module_number;
143 | } else {
144 | module_number = 0;
145 | }
146 | php_info_print_table_start();
147 | php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
148 | zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC);
149 | php_info_print_table_end();
150 | }
151 | /* }}} */
152 |
153 | /* php.ini support */
154 |
155 | #ifdef ZTS
156 | # if (ZEND_DEBUG)
157 | # define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts"
158 | # else
159 | # define ZEND_EXTENSION_TOKEN "zend_extension_ts"
160 | # endif
161 | #else
162 | # if (ZEND_DEBUG)
163 | # define ZEND_EXTENSION_TOKEN "zend_extension_debug"
164 | # else
165 | # define ZEND_EXTENSION_TOKEN "zend_extension"
166 | # endif
167 | #endif
168 |
169 | /* {{{ pvalue_config_destructor
170 | */
171 | static void pvalue_config_destructor(zval *pvalue)
172 | {
173 | if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
174 | free(Z_STRVAL_P(pvalue));
175 | }
176 | }
177 | /* }}} */
178 |
179 | /* {{{ php_config_ini_parser_cb
180 | */
181 | static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
182 | {
183 | switch (callback_type) {
184 | case ZEND_INI_PARSER_ENTRY: {
185 | zval *entry;
186 |
187 | if (!arg2) {
188 | break;
189 | }
190 | if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
191 | zval copy;
192 |
193 | copy = *arg2;
194 | zval_copy_ctor(©);
195 | copy.refcount = 0;
196 | zend_llist_add_element(&extension_lists.functions, ©);
197 | } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
198 | char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
199 |
200 | zend_llist_add_element(&extension_lists.engine, &extension_name);
201 | } else {
202 | zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
203 | Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
204 | }
205 | }
206 | break;
207 |
208 | case ZEND_INI_PARSER_SECTION:
209 | break;
210 | }
211 | }
212 | /* }}} */
213 |
214 | /* {{{ php_load_function_extension_cb
215 | */
216 | static void php_load_function_extension_cb(void *arg TSRMLS_DC)
217 | {
218 | zval *extension = (zval *) arg;
219 | zval zval;
220 |
221 | php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC);
222 | }
223 | /* }}} */
224 |
225 | /* {{{ php_load_zend_extension_cb
226 | */
227 | static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
228 | {
229 | zend_load_extension(*((char **) arg));
230 | }
231 | /* }}} */
232 |
233 | #ifdef PHP_WIN32
234 | #define NUM_INI_SEARCH_LOCATIONS 4
235 | #else
236 | #define NUM_INI_SEARCH_LOCATIONS 3
237 | #endif
238 |
239 | /* {{{ php_init_config
240 | */
241 | int php_init_config()
242 | {
243 | char *env_location, *php_ini_search_path;
244 | #ifdef PHP_WIN32
245 | char *registry_location;
246 | #endif
247 | char *binary_location;
248 | int safe_mode_state;
249 | char *open_basedir;
250 | int free_ini_search_path=0;
251 | zend_file_handle fh = {0};
252 | struct stat sb;
253 | char ini_file[MAXPATHLEN];
254 | char *p;
255 | zend_llist scanned_ini_list;
256 | int l, total_l=0;
257 | zend_llist_element *element;
258 | TSRMLS_FETCH();
259 |
260 | if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1) == FAILURE) {
261 | return FAILURE;
262 | }
263 |
264 | if (sapi_module.ini_defaults) {
265 | sapi_module.ini_defaults(&configuration_hash);
266 | }
267 |
268 | zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
269 | zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
270 | zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
271 |
272 | safe_mode_state = PG(safe_mode);
273 | open_basedir = PG(open_basedir);
274 |
275 | env_location = getenv("PHPRC");
276 | if (!env_location) {
277 | env_location = "";
278 | }
279 | if (sapi_module.php_ini_path_override) {
280 | php_ini_search_path = sapi_module.php_ini_path_override;
281 | free_ini_search_path = 0;
282 | } else {
283 | int search_path_size;
284 | char *default_location;
285 | static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
286 |
287 | search_path_size = MAXPATHLEN * NUM_INI_SEARCH_LOCATIONS + strlen(env_location) + NUM_INI_SEARCH_LOCATIONS + 1;
288 | php_ini_search_path = (char *) emalloc(search_path_size);
289 | free_ini_search_path = 1;
290 | php_ini_search_path[0] = 0;
291 |
292 | /*
293 | * Prepare search path
294 | */
295 |
296 | /*//Add environment location
297 | if (env_location[0]) {
298 | if (*php_ini_search_path) {
299 | strlcat(php_ini_search_path, paths_separator, search_path_size);
300 | }
301 | strlcat(php_ini_search_path, env_location, search_path_size);
302 | }
303 |
304 | #ifdef PHP_WIN32
305 | registry_location = GetIniPathFromRegistry();
306 | if (registry_location) {
307 | if (*php_ini_search_path) {
308 | strlcat(php_ini_search_path, paths_separator, search_path_size);
309 | }
310 | strlcat(php_ini_search_path, registry_location, search_path_size);
311 | efree(registry_location);
312 | }
313 | #endif
314 |
315 | // Add cwd
316 | #ifdef INI_CHECK_CWD
317 | if (strcmp(sapi_module.name, "cli") != 0) {
318 | if (*php_ini_search_path) {
319 | strlcat(php_ini_search_path, paths_separator, search_path_size);
320 | }
321 | strlcat(php_ini_search_path, ".", search_path_size);
322 | }
323 | #endif
324 |
325 | // Add binary directory
326 | #ifdef PHP_WIN32
327 | binary_location = (char *) emalloc(MAXPATHLEN);
328 | if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
329 | efree(binary_location);
330 | binary_location = NULL;
331 | }
332 | #else
333 | if (sapi_module.executable_location) {
334 | binary_location = estrdup(sapi_module.executable_location);
335 | } else {
336 | binary_location = NULL;
337 | }
338 | #endif
339 | if (binary_location) {
340 | char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
341 |
342 | if (separator_location) {
343 | *(separator_location+1) = 0;
344 | }
345 | if (*php_ini_search_path) {
346 | strlcat(php_ini_search_path, paths_separator, search_path_size);
347 | }
348 | strlcat(php_ini_search_path, binary_location, search_path_size);
349 | efree(binary_location);
350 | }
351 |
352 | // Add default location
353 | #ifdef PHP_WIN32
354 | default_location = (char *) emalloc(MAXPATHLEN + 1);
355 |
356 | if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
357 | if (*php_ini_search_path) {
358 | strlcat(php_ini_search_path, paths_separator, search_path_size);
359 | }
360 | strlcat(php_ini_search_path, default_location, search_path_size);
361 | }
362 | efree(default_location);
363 | #else
364 | default_location = PHP_CONFIG_FILE_PATH;
365 | if (*php_ini_search_path) {
366 | strlcat(php_ini_search_path, paths_separator, search_path_size);
367 | }
368 | strlcat(php_ini_search_path, default_location, search_path_size);
369 | #endif
370 | }
371 |
372 | PG(safe_mode) = 0;
373 | PG(open_basedir) = NULL;
374 |
375 | /* Check if php_ini_path_override is a file */
376 | if (!sapi_module.php_ini_ignore) {
377 | if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
378 | struct stat statbuf;
379 |
380 | if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) {
381 | if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
382 | fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r");
383 | fh.filename = sapi_module.php_ini_path_override;
384 | }
385 | }
386 | }
387 |
388 | /* Search for the temporary phpini.bam file -- bambalam */
389 |
390 | if (!fh.handle.fp) {
391 | fh.handle.fp = php_fopen_with_path("phpini.bam", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
392 | if (fh.handle.fp) {
393 | fh.filename = php_ini_opened_path;
394 | }
395 | }
396 |
397 | /* Search php-%sapi-module-name%.ini file in search path */
398 | /*if (!fh.handle.fp) {
399 | const char *fmt = "php-%s.ini";
400 | char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name));
401 | sprintf(ini_fname, fmt, sapi_module.name);
402 | fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
403 | efree(ini_fname);
404 | if (fh.handle.fp) {
405 | fh.filename = php_ini_opened_path;
406 | }
407 | }
408 | /* Search php.ini file in search path */
409 | /*if (!fh.handle.fp) {
410 | fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
411 | if (fh.handle.fp) {
412 | fh.filename = php_ini_opened_path;
413 | }
414 | }*/
415 | }
416 |
417 | if (free_ini_search_path) {
418 | efree(php_ini_search_path);
419 | }
420 |
421 | PG(safe_mode) = safe_mode_state;
422 | PG(open_basedir) = open_basedir;
423 |
424 | if (fh.handle.fp) {
425 | fh.type = ZEND_HANDLE_FP;
426 |
427 | zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
428 |
429 | {
430 | zval tmp;
431 |
432 | Z_STRLEN(tmp) = strlen(fh.filename);
433 | Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
434 | Z_TYPE(tmp) = IS_STRING;
435 | zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
436 | if (php_ini_opened_path) {
437 | efree(php_ini_opened_path);
438 | }
439 | php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
440 | }
441 | }
442 |
443 | /* If the config_file_scan_dir is set at compile-time, go and scan this directory and
444 | * parse any .ini files found in this directory. */
445 | if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
446 | struct dirent **namelist;
447 | int ndir, i;
448 |
449 | if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
450 | for (i = 0; i < ndir; i++) {
451 | /* check for a .ini extension */
452 | if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
453 | free(namelist[i]);
454 | continue;
455 | }
456 | snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
457 | if (VCWD_STAT(ini_file, &sb) == 0) {
458 | if (S_ISREG(sb.st_mode)) {
459 | if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
460 | fh.filename = ini_file;
461 | fh.type = ZEND_HANDLE_FP;
462 | zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
463 | /* Here, add it to the list of ini files read */
464 | l = strlen(ini_file);
465 | total_l += l + 2;
466 | p = estrndup(ini_file, l);
467 | zend_llist_add_element(&scanned_ini_list, &p);
468 | }
469 | }
470 | }
471 | free(namelist[i]);
472 | }
473 | free(namelist);
474 |
475 | /*
476 | * Don't need an extra byte for the \0 in this malloc as the last
477 | * element will not get a trailing , which gives us the byte for the \0
478 | */
479 | if (total_l) {
480 | php_ini_scanned_files = (char *) malloc(total_l);
481 | *php_ini_scanned_files = '\0';
482 | for (element = scanned_ini_list.head; element; element = element->next) {
483 | strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
484 | strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
485 | }
486 | }
487 | zend_llist_destroy(&scanned_ini_list);
488 | }
489 | }
490 | return SUCCESS;
491 | }
492 | /* }}} */
493 |
494 | /* {{{ php_shutdown_config
495 | */
496 | int php_shutdown_config(void)
497 | {
498 | zend_hash_destroy(&configuration_hash);
499 | if (php_ini_opened_path) {
500 | free(php_ini_opened_path);
501 | php_ini_opened_path = NULL;
502 | }
503 | if (php_ini_scanned_files) {
504 | free(php_ini_scanned_files);
505 | php_ini_scanned_files = NULL;
506 | }
507 | return SUCCESS;
508 | }
509 | /* }}} */
510 |
511 | /* {{{ php_ini_delayed_modules_startup
512 | */
513 | void php_ini_delayed_modules_startup(TSRMLS_D)
514 | {
515 | zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
516 | zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC);
517 |
518 | zend_llist_destroy(&extension_lists.engine);
519 | zend_llist_destroy(&extension_lists.functions);
520 | }
521 | /* }}} */
522 |
523 | /* {{{ cfg_get_entry
524 | */
525 | zval *cfg_get_entry(char *name, uint name_length)
526 | {
527 | zval *tmp;
528 |
529 | if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
530 | return tmp;
531 | } else {
532 | return NULL;
533 | }
534 | }
535 | /* }}} */
536 |
537 | /* {{{ cfg_get_long
538 | */
539 | PHPAPI int cfg_get_long(char *varname, long *result)
540 | {
541 | zval *tmp, var;
542 |
543 | if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
544 | *result = (long) NULL;
545 | return FAILURE;
546 | }
547 | var = *tmp;
548 | zval_copy_ctor(&var);
549 | convert_to_long(&var);
550 | *result = Z_LVAL(var);
551 | return SUCCESS;
552 | }
553 | /* }}} */
554 |
555 | /* {{{ cfg_get_double
556 | */
557 | PHPAPI int cfg_get_double(char *varname, double *result)
558 | {
559 | zval *tmp, var;
560 |
561 | if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
562 | *result = (double) 0;
563 | return FAILURE;
564 | }
565 | var = *tmp;
566 | zval_copy_ctor(&var);
567 | convert_to_double(&var);
568 | *result = Z_DVAL(var);
569 | return SUCCESS;
570 | }
571 | /* }}} */
572 |
573 | /* {{{ cfg_get_string
574 | */
575 | PHPAPI int cfg_get_string(char *varname, char **result)
576 | {
577 | zval *tmp;
578 |
579 | if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
580 | *result = NULL;
581 | return FAILURE;
582 | }
583 | *result = Z_STRVAL_P(tmp);
584 | return SUCCESS;
585 | }
586 | /* }}} */
587 |
588 | /*
589 | * Local variables:
590 | * tab-width: 4
591 | * c-basic-offset: 4
592 | * indent-tabs-mode: t
593 | * End:
594 | * vim600: sw=4 ts=4 fdm=marker
595 | * vim<600: sw=4 ts=4
596 | */
597 |
--------------------------------------------------------------------------------
/src/php_hacks/php_src/main/streams.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | PHP Version 4 |
4 | +----------------------------------------------------------------------+
5 | | Copyright (c) 1997-2008 The PHP Group |
6 | +----------------------------------------------------------------------+
7 | | This source file is subject to version 3.01 of the PHP license, |
8 | | that is bundled with this package in the file LICENSE, and is |
9 | | available through the world-wide-web at the following url: |
10 | | http://www.php.net/license/3_01.txt |
11 | | If you did not receive a copy of the PHP license and are unable to |
12 | | obtain it through the world-wide-web, please send a note to |
13 | | license@php.net so we can mail you a copy immediately. |
14 | +----------------------------------------------------------------------+
15 | | Authors: |
16 | | Wez Furlong (wez@thebrainroom.com) |
17 | | Borrowed code from: |
18 | | Rasmus Lerdorf