Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 426 lines (339 sloc) 10.982 kb
651e232 @zsuraski Testing 123
zsuraski authored
1 /*
2 +----------------------------------------------------------------------+
3 | PHP HTML Embedded Scripting Language Version 4.0 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
6 +----------------------------------------------------------------------+
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of one of the following licenses: |
9 | |
10 | A) the GNU General Public License as published by the Free Software |
11 | Foundation; either version 2 of the License, or (at your option) |
12 | any later version. |
13 | |
14 | B) the PHP License as published by the PHP Development Team and |
15 | included in the distribution in the file: LICENSE |
16 | |
17 | This program is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | GNU General Public License for more details. |
21 | |
22 | You should have received a copy of both licenses referred to here. |
23 | If you did not, or have any questions about PHP licensing, please |
24 | contact core@php.net. |
25 +----------------------------------------------------------------------+
26 | Author: Zeev Suraski <zeev@zend.com> |
27 +----------------------------------------------------------------------+
28 */
29
30
aceaabc @zsuraski PHP 4.0
zsuraski authored
31 #include <stdlib.h>
32
33 #include "php.h"
34 #include "php_ini.h"
35 #include "zend_alloc.h"
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
36 #include "php_globals.h"
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
37 #include "ext/standard/info.h"
38
39 #define ENTRY_NAME_COLOR "#999999"
40 #define CONTENTS_COLOR "#DDDDDD"
aceaabc @zsuraski PHP 4.0
zsuraski authored
41
42 static HashTable known_directives;
43
44
45 /*
46 * hash_apply functions
47 */
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
48 static int php_remove_ini_entries(php_ini_entry *ini_entry, int *module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
49 {
50 if (ini_entry->module_number == *module_number) {
51 return 1;
52 } else {
53 return 0;
54 }
55 }
56
57
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
58 static int php_restore_ini_entry_cb(php_ini_entry *ini_entry)
aceaabc @zsuraski PHP 4.0
zsuraski authored
59 {
60 if (ini_entry->modified) {
61 efree(ini_entry->value);
62 ini_entry->value = ini_entry->orig_value;
63 ini_entry->value_length = ini_entry->orig_value_length;
64 ini_entry->modified = 0;
d40e88a @zsuraski Apache php_ini support
zsuraski authored
65 ini_entry->orig_value = NULL;
66 ini_entry->orig_value_length = 0;
aceaabc @zsuraski PHP 4.0
zsuraski authored
67 }
68 return 0;
69 }
70
71 /*
72 * Startup / shutdown
73 */
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
74 int php_ini_mstartup()
aceaabc @zsuraski PHP 4.0
zsuraski authored
75 {
76 if (_php3_hash_init(&known_directives, 100, NULL, NULL, 1)==FAILURE) {
77 return FAILURE;
78 }
79 return SUCCESS;
80 }
81
82
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
83 int php_ini_mshutdown()
aceaabc @zsuraski PHP 4.0
zsuraski authored
84 {
85 _php3_hash_destroy(&known_directives);
86 return SUCCESS;
87 }
88
89
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
90 int php_ini_rshutdown()
aceaabc @zsuraski PHP 4.0
zsuraski authored
91 {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
92 _php3_hash_apply(&known_directives, (int (*)(void *)) php_restore_ini_entry_cb);
aceaabc @zsuraski PHP 4.0
zsuraski authored
93 return SUCCESS;
94 }
95
96 /*
97 * Registration / unregistration
98 */
99
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
100 PHPAPI int php_register_ini_entries(php_ini_entry *ini_entry, int module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
101 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
102 php_ini_entry *p = ini_entry;
103 php_ini_entry *hashed_ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
104 pval *default_value;
105
106 while (p->name) {
107 p->module_number = module_number;
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
108 if (_php3_hash_add(&known_directives, p->name, p->name_length, p, sizeof(php_ini_entry), (void **) &hashed_ini_entry)==FAILURE) {
109 php_unregister_ini_entries(module_number);
aceaabc @zsuraski PHP 4.0
zsuraski authored
110 return FAILURE;
111 }
7aad231 @zsuraski Thread safety patch. It works now with just-in-time resource initial…
zsuraski authored
112 if (hashed_ini_entry->on_modify) {
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
113 hashed_ini_entry->on_modify(hashed_ini_entry, hashed_ini_entry->value, hashed_ini_entry->value_length, hashed_ini_entry->mh_arg1, hashed_ini_entry->mh_arg2, hashed_ini_entry->mh_arg3);
7aad231 @zsuraski Thread safety patch. It works now with just-in-time resource initial…
zsuraski authored
114 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
115 if ((default_value=cfg_get_entry(p->name, p->name_length))) {
3edb99e @zsuraski Type library support in COM module
zsuraski authored
116 if (!hashed_ini_entry->on_modify
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
117 || hashed_ini_entry->on_modify(hashed_ini_entry, default_value->value.str.val, default_value->value.str.len, hashed_ini_entry->mh_arg1, hashed_ini_entry->mh_arg2, hashed_ini_entry->mh_arg3)==SUCCESS) {
3edb99e @zsuraski Type library support in COM module
zsuraski authored
118 hashed_ini_entry->value = default_value->value.str.val;
119 hashed_ini_entry->value_length = default_value->value.str.len;
120 }
d40e88a @zsuraski Apache php_ini support
zsuraski authored
121 } else {
122 if (hashed_ini_entry->on_modify) {
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
123 hashed_ini_entry->on_modify(hashed_ini_entry, hashed_ini_entry->value, hashed_ini_entry->value_length, hashed_ini_entry->mh_arg1, hashed_ini_entry->mh_arg2, hashed_ini_entry->mh_arg3);
d40e88a @zsuraski Apache php_ini support
zsuraski authored
124 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
125 }
126 hashed_ini_entry->modified = 0;
127 p++;
128 }
129 return SUCCESS;
130 }
131
132
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
133 PHPAPI void php_unregister_ini_entries(int module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
134 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
135 _php3_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) php_remove_ini_entries, (void *) &module_number);
aceaabc @zsuraski PHP 4.0
zsuraski authored
136 }
137
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
138
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
139 PHPAPI int php_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type)
aceaabc @zsuraski PHP 4.0
zsuraski authored
140 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
141 php_ini_entry *ini_entry;
4fd1d5b @zsuraski * php_ini fixes
zsuraski authored
142 char *duplicate;
aceaabc @zsuraski PHP 4.0
zsuraski authored
143
144 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
145 return FAILURE;
146 }
147
148 if (!(ini_entry->modifyable & modify_type)) {
149 return FAILURE;
150 }
151
4fd1d5b @zsuraski * php_ini fixes
zsuraski authored
152 duplicate = estrndup(new_value, new_value_length);
153
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
154 if (!ini_entry->on_modify
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
155 || ini_entry->on_modify(ini_entry, duplicate, new_value_length, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3)==SUCCESS) {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
156 if (!ini_entry->orig_value) {
157 ini_entry->orig_value = ini_entry->value;
158 ini_entry->orig_value_length = ini_entry->value_length;
159 } else { /* we already changed the value, free the changed value */
160 efree(ini_entry->value);
161 }
4fd1d5b @zsuraski * php_ini fixes
zsuraski authored
162 ini_entry->value = duplicate;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
163 ini_entry->value_length = new_value_length;
164 ini_entry->modified = 1;
4fd1d5b @zsuraski * php_ini fixes
zsuraski authored
165 } else {
166 efree(duplicate);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
167 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
168
169 return SUCCESS;
170 }
171
172
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
173 PHPAPI int php_restore_ini_entry(char *name, uint name_length)
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
174 {
175 php_ini_entry *ini_entry;
176
177 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
178 return FAILURE;
179 }
180
181 if (ini_entry->orig_value) {
182 ini_entry->value = ini_entry->orig_value;
183 ini_entry->value_length = ini_entry->orig_value_length;
184 }
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
185 return SUCCESS;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
186 }
187
188
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
189 PHPAPI int php_ini_register_displayer(char *name, uint name_length, void (*displayer)(php_ini_entry *ini_entry, int type))
190 {
191 php_ini_entry *ini_entry;
192
193 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
194 return FAILURE;
195 }
196
197 ini_entry->displayer = displayer;
198 return SUCCESS;
199 }
200
201
202
aceaabc @zsuraski PHP 4.0
zsuraski authored
203 /*
204 * Data retrieval
205 */
206
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
207 PHPAPI long php_ini_long(char *name, uint name_length, int orig)
aceaabc @zsuraski PHP 4.0
zsuraski authored
208 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
209 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
210
211 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
212 if (orig && ini_entry->orig_value) {
4213b5d tolerate uninitialized ini settings in php_ini_{long,double,string}()
Stig Bakken authored
213 return strtol(ini_entry->orig_value, NULL, 0);
214 } else if (ini_entry->value) {
215 return strtol(ini_entry->value, NULL, 0);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
216 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
217 }
218
219 return 0;
220 }
221
222
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
223 PHPAPI double php_ini_double(char *name, uint name_length, int orig)
aceaabc @zsuraski PHP 4.0
zsuraski authored
224 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
225 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
226
227 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
228 if (orig && ini_entry->orig_value) {
229 return (double) strtod(ini_entry->orig_value, NULL);
4213b5d tolerate uninitialized ini settings in php_ini_{long,double,string}()
Stig Bakken authored
230 } else if (ini_entry->value) {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
231 return (double) strtod(ini_entry->value, NULL);
232 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
233 }
234
235 return 0.0;
236 }
237
238
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
239 PHPAPI char *php_ini_string(char *name, uint name_length, int orig)
aceaabc @zsuraski PHP 4.0
zsuraski authored
240 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
241 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
242
243 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
244 if (orig && ini_entry->orig_value) {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
245 return ini_entry->orig_value;
0666083 @zsuraski NULL's should remain NULLs (at least in strings)
zsuraski authored
246 } else {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
247 return ini_entry->value;
248 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
249 }
250
251 return "";
252 }
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
253
254
255
bc415d5 @zsuraski * Finalizing the PHP version of SAPI. Support POST and cookies among…
zsuraski authored
256 static void php_ini_displayer_cb(php_ini_entry *ini_entry, int type)
257 {
258 if (ini_entry->displayer) {
259 ini_entry->displayer(ini_entry, type);
260 } else {
261 char *display_string;
262 uint display_string_length;
263
264 if (type==PHP_INI_DISPLAY_ORIG && ini_entry->orig_value) {
265 display_string = ini_entry->orig_value;
266 display_string_length = ini_entry->orig_value_length;
267 } else if (ini_entry->value && ini_entry->value[0]) {
268 display_string = ini_entry->value;
269 display_string_length = ini_entry->value_length;
270 } else {
271 display_string = "<i>no value</i>";
272 display_string_length = sizeof("<i>no value</i>")-1;
273 }
274 PHPWRITE(display_string, display_string_length);
275 }
276 }
277
278
279 PHP_INI_DISP(php_ini_boolean_displayer_cb)
280 {
281 int value;
282
283 if (type==PHP_INI_DISPLAY_ORIG && ini_entry->orig_value) {
284 value = atoi(ini_entry->orig_value);
285 } else if (ini_entry->value) {
286 value = atoi(ini_entry->value);
287 } else {
288 value = 0;
289 }
290 if (value) {
291 PUTS("On");
292 } else {
293 PUTS("Off");
294 }
295 }
296
297
298 PHP_INI_DISP(php_ini_color_displayer_cb)
299 {
300 char *value;
301
302 if (type==PHP_INI_DISPLAY_ORIG && ini_entry->orig_value) {
303 value = ini_entry->orig_value;
304 } else if (ini_entry->value) {
305 value = ini_entry->value;
306 } else {
307 value = NULL;
308 }
309 if (value) {
310 php3_printf("<font color=\"%s\">%s</font>", value, value);
311 } else {
312 PUTS("<i>no value</i>;");
313 }
314 }
315
316
317 static int php_ini_displayer(php_ini_entry *ini_entry, int module_number)
318 {
319 if (ini_entry->module_number != module_number) {
320 return 0;
321 }
322
323 PUTS("<tr><td align=\"center\" bgcolor=\"" ENTRY_NAME_COLOR "\">");
324 PHPWRITE(ini_entry->name, ini_entry->name_length-1);
325 PUTS("<td align=\"center\" bgcolor=\"" CONTENTS_COLOR "\">");
326 php_ini_displayer_cb(ini_entry, PHP_INI_DISPLAY_ACTIVE);
327 PUTS("</td><td align=\"center\" bgcolor=\"" CONTENTS_COLOR "\">");
328 php_ini_displayer_cb(ini_entry, PHP_INI_DISPLAY_ORIG);
329 PUTS("</td></tr>\n");
330 return 0;
331 }
332
333
334 PHPAPI void display_ini_entries(zend_module_entry *module)
335 {
336 int module_number;
337
338 if (module) {
339 module_number = module->module_number;
340 } else {
341 module_number = 0;
342 }
343 PUTS("<table border=5 width=\"600\">\n");
344 php_info_print_table_header(3, "Directive", "Master Value", "Local Value");
345 zend_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) php_ini_displayer, (void *) module_number);
346 PUTS("</table>\n");
347 }
348
349
350 /* Standard message handlers */
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
351
352 PHP_INI_MH(OnUpdateInt)
353 {
354 long *p;
355 #ifndef ZTS
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
356 char *base = (char *) mh_arg2;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
357 #else
358 char *base;
359
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
360 base = (char *) ts_resource(*((int *) mh_arg2));
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
361 #endif
362
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
363 p = (long *) (base+(size_t) mh_arg1);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
364
365 *p = atoi(new_value);
366 return SUCCESS;
367 }
368
369
370 PHP_INI_MH(OnUpdateReal)
371 {
372 double *p;
373 #ifndef ZTS
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
374 char *base = (char *) mh_arg2;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
375 #else
376 char *base;
377
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
378 base = (char *) ts_resource(*((int *) mh_arg2));
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
379 #endif
380
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
381 p = (double *) (base+(size_t) mh_arg1);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
382
383 *p = strtod(new_value, NULL);
384 return SUCCESS;
385 }
386
387
388 PHP_INI_MH(OnUpdateString)
389 {
390 char **p;
391 #ifndef ZTS
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
392 char *base = (char *) mh_arg2;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
393 #else
394 char *base;
395
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
396 base = (char *) ts_resource(*((int *) mh_arg2));
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
397 #endif
398
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
399 p = (char **) (base+(size_t) mh_arg1);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
400
401 *p = new_value;
402 return SUCCESS;
403 }
bb6dff9 @zsuraski Buh-bye php3_ini
zsuraski authored
404
405
406 PHP_INI_MH(OnUpdateStringUnempty)
407 {
408 char **p;
409 #ifndef ZTS
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
410 char *base = (char *) mh_arg2;
bb6dff9 @zsuraski Buh-bye php3_ini
zsuraski authored
411 #else
412 char *base;
413
a877f6d @zsuraski Additional generalization of the INI mechanism. Avoid needing specia…
zsuraski authored
414 base = (char *) ts_resource(*((int *) mh_arg2));
bb6dff9 @zsuraski Buh-bye php3_ini
zsuraski authored
415 #endif
416
417 if (new_value && !new_value[0]) {
418 return FAILURE;
419 }
420
6647601 @zsuraski A step towards generalizing the INI mechanism even more
zsuraski authored
421 p = (char **) (base+(size_t) mh_arg1);
bb6dff9 @zsuraski Buh-bye php3_ini
zsuraski authored
422
423 *p = new_value;
424 return SUCCESS;
425 }
Something went wrong with that request. Please try again.