]> git.pld-linux.org Git - packages/php.git/blob - php-config-file-scan-dir.patch
cleanups
[packages/php.git] / php-config-file-scan-dir.patch
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
3 @@ -349,7 +349,8 @@
4         char *open_basedir;
5         int free_ini_search_path = 0;
6         zend_file_handle fh;
7 -
8 +       static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
9 +       
10         if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) config_zval_dtor, 1) == FAILURE) {
11                 return FAILURE;
12         }
13 @@ -372,7 +373,6 @@
14                 char *default_location;
15                 char *env_location;
16                 char *binary_location;
17 -               static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
18  #ifdef PHP_WIN32
19                 char *reg_location;
20                 char phprc_path[MAXPATHLEN];
21 @@ -608,72 +608,86 @@
22  
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;
26                 int ndir, i;
27                 struct stat sb;
28                 char ini_file[MAXPATHLEN];
29 -               char *p;
30 +               char *p, *last, *path_copy, *ini_path = NULL;
31                 zend_file_handle fh2;
32                 zend_llist scanned_ini_list;
33                 zend_llist_element *element;
34                 int l, total_l = 0;
35  
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(&fh2, 0, sizeof(fh2));
39 -
40 -                       for (i = 0; i < ndir; i++) {
41 -
42 -                               /* check for any file with .ini extension */
43 -                               if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
44 -                                       free(namelist[i]);
45 -                                       continue;
46 -                               }
47 -                               /* Reset active ini section */
48 -                               RESET_ACTIVE_INI_HASH();
49 -
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);
52 -                               } else {
53 -                                       snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
54 -                               }
55 -                               if (VCWD_STAT(ini_file, &sb) == 0) {
56 -                                       if (S_ISREG(sb.st_mode)) {
57 -                                               if ((fh2.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
58 -                                                       fh2.filename = ini_file;
59 -                                                       fh2.type = ZEND_HANDLE_FP;
60 -
61 -                                                       if (zend_parse_ini_file(&fh2, 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);
64 -                                                               total_l += l + 2;
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);
69 +               
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);
73 +
74 +               while (ini_path != NULL) {
75 +                       struct dirent **namelist;
76 +                       int ini_path_len = strlen(ini_path);
77 +
78 +                       if ((ndir = php_scandir(ini_path, &namelist, 0, php_alphasort)) > 0) {
79 +                               memset(&fh2, 0, sizeof(fh2));
80 +
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"))) {
84 +                                               free(namelist[i]);
85 +                                               continue;
86 +                                       }
87 +                                       /* Reset active ini section */
88 +                                       RESET_ACTIVE_INI_HASH();
89 +
90 +                                       if (IS_SLASH(ini_path[ini_path_len - 1])) {
91 +                                               snprintf(ini_file, MAXPATHLEN, "%s%s", ini_path, namelist[i]->d_name);
92 +                                       } else {
93 +                                               snprintf(ini_file, MAXPATHLEN, "%s%c%s", ini_path, DEFAULT_SLASH, namelist[i]->d_name);
94 +                                       }                       
95 +                                       if (VCWD_STAT(ini_file, &sb) == 0) {
96 +                                               if (S_ISREG(sb.st_mode)) {
97 +                                                       if ((fh2.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
98 +                                                               fh2.filename = ini_file;
99 +                                                               fh2.type = ZEND_HANDLE_FP;
100 +                                                               
101 +                                                               /* Reset active ini section */
102 +                                                               RESET_ACTIVE_INI_HASH();
103 +
104 +                                                               if (zend_parse_ini_file(&fh2, 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);
107 +                                                                       total_l += l + 2;
108 +                                                                       p = estrndup(ini_file, l);
109 +                                                                       zend_llist_add_element(&scanned_ini_list, &p);
110 +                                                               }
111                                                         }
112                                                 }
113                                         }
114 +                                       free(namelist[i]);
115                                 }
116 -                               free(namelist[i]);
117 +                               free(namelist);
118                         }
119 -                       free(namelist);
120 -
121 -                       if (total_l) {
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';
126 -                               }
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);
131 -                                       }
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);
135 +               }
136 +                       
137 +               if (total_l) {
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';
142 +                       }
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);
147                                 }
148 +                               strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
149 +                               strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
150                         }
151 -                       zend_llist_destroy(&scanned_ini_list);
152                 }
153 +               efree(path_copy);
154 +               zend_llist_destroy(&scanned_ini_list);
155         } else {
156                 /* Make sure an empty php_ini_scanned_path ends up as NULL */
157                 php_ini_scanned_path = NULL;
This page took 0.058489 seconds and 3 git commands to generate.