1 --- php-src/main/php_ini.c 2009/05/18 21:28:42 1.173
2 +++ php-src/main/php_ini.c 2009/06/27 15:22:06 1.174
5 int free_ini_search_path = 0;
8 + static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
10 if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) config_zval_dtor, 1) == FAILURE) {
14 char *default_location;
16 char *binary_location;
17 - static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
20 char phprc_path[MAXPATHLEN];
23 /* Scan and parse any .ini files found in scan path if path not empty. */
24 if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
25 - struct dirent **namelist;
28 char ini_file[MAXPATHLEN];
30 + char *p, *last, *path_copy, *ini_path = NULL;
32 zend_llist scanned_ini_list;
33 zend_llist_element *element;
36 - if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
37 - zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
38 - memset(&fh, 0, sizeof(fh));
40 - for (i = 0; i < ndir; i++) {
42 - /* check for any file with .ini extension */
43 - if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
47 - /* Reset active ini section */
48 - RESET_ACTIVE_INI_HASH();
50 - if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
51 - snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
53 - snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
55 - if (VCWD_STAT(ini_file, &sb) == 0) {
56 - if (S_ISREG(sb.st_mode)) {
57 - if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
58 - fh.filename = ini_file;
59 - fh.type = ZEND_HANDLE_FP;
61 - 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) {
62 - /* Here, add it to the list of ini files read */
63 - l = strlen(ini_file);
65 - p = estrndup(ini_file, l);
66 - zend_llist_add_element(&scanned_ini_list, &p);
67 + /* List of found ini files */
68 + zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
70 + /* Split by paths_separator and load ini-files from all paths */
71 + path_copy = estrdup(php_ini_scanned_path);
72 + ini_path = php_strtok_r(path_copy, paths_separator, &last);
74 + while (ini_path != NULL) {
75 + struct dirent **namelist;
76 + int ini_path_len = strlen(ini_path);
78 + if ((ndir = php_scandir(ini_path, &namelist, 0, php_alphasort)) > 0) {
79 + memset(&fh, 0, sizeof(fh));
81 + for (i = 0; i < ndir; i++) {
82 + /* check for any file with .ini extension */
83 + if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
87 + /* Reset active ini section */
88 + RESET_ACTIVE_INI_HASH();
90 + if (IS_SLASH(ini_path[ini_path_len - 1])) {
91 + snprintf(ini_file, MAXPATHLEN, "%s%s", ini_path, namelist[i]->d_name);
93 + snprintf(ini_file, MAXPATHLEN, "%s%c%s", ini_path, DEFAULT_SLASH, namelist[i]->d_name);
95 + if (VCWD_STAT(ini_file, &sb) == 0) {
96 + if (S_ISREG(sb.st_mode)) {
97 + if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
98 + fh.filename = ini_file;
99 + fh.type = ZEND_HANDLE_FP;
101 + /* Reset active ini section */
102 + RESET_ACTIVE_INI_HASH();
104 + 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) {
105 + /* Here, add it to the list of ini files read */
106 + l = strlen(ini_file);
108 + p = estrndup(ini_file, l);
109 + zend_llist_add_element(&scanned_ini_list, &p);
122 - int php_ini_scanned_files_len = (php_ini_scanned_files) ? strlen(php_ini_scanned_files) + 1 : 0;
123 - php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1);
124 - if (!php_ini_scanned_files_len) {
125 - *php_ini_scanned_files = '\0';
127 - total_l += php_ini_scanned_files_len;
128 - for (element = scanned_ini_list.head; element; element = element->next) {
129 - if (php_ini_scanned_files_len) {
130 - strlcat(php_ini_scanned_files, ",\n", total_l);
132 - strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
133 - strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
134 + ini_path = php_strtok_r(NULL, paths_separator, &last);
138 + int php_ini_scanned_files_len = (php_ini_scanned_files) ? strlen(php_ini_scanned_files) + 1 : 0;
139 + php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1);
140 + if (!php_ini_scanned_files_len) {
141 + *php_ini_scanned_files = '\0';
143 + total_l += php_ini_scanned_files_len;
144 + for (element = scanned_ini_list.head; element; element = element->next) {
145 + if (php_ini_scanned_files_len) {
146 + strlcat(php_ini_scanned_files, ",\n", total_l);
148 + strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
149 + strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
151 - zend_llist_destroy(&scanned_ini_list);
154 + zend_llist_destroy(&scanned_ini_list);
156 /* Make sure an empty php_ini_scanned_path ends up as NULL */
157 php_ini_scanned_path = NULL;