Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 281 lines (222 sloc) 7.123 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"
aceaabc @zsuraski PHP 4.0
zsuraski authored
37
38 static HashTable known_directives;
39
40
41 /*
42 * hash_apply functions
43 */
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
44 static int php_remove_ini_entries(php_ini_entry *ini_entry, int *module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
45 {
46 if (ini_entry->module_number == *module_number) {
47 return 1;
48 } else {
49 return 0;
50 }
51 }
52
53
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
54 static int php_restore_ini_entry_cb(php_ini_entry *ini_entry)
aceaabc @zsuraski PHP 4.0
zsuraski authored
55 {
56 if (ini_entry->modified) {
57 efree(ini_entry->value);
58 ini_entry->value = ini_entry->orig_value;
59 ini_entry->value_length = ini_entry->orig_value_length;
60 ini_entry->modified = 0;
61 }
62 return 0;
63 }
64
65 /*
66 * Startup / shutdown
67 */
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
68 int php_ini_mstartup()
aceaabc @zsuraski PHP 4.0
zsuraski authored
69 {
70 if (_php3_hash_init(&known_directives, 100, NULL, NULL, 1)==FAILURE) {
71 return FAILURE;
72 }
73 return SUCCESS;
74 }
75
76
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
77 int php_ini_mshutdown()
aceaabc @zsuraski PHP 4.0
zsuraski authored
78 {
79 _php3_hash_destroy(&known_directives);
80 return SUCCESS;
81 }
82
83
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
84 int php_ini_rshutdown()
aceaabc @zsuraski PHP 4.0
zsuraski authored
85 {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
86 _php3_hash_apply(&known_directives, (int (*)(void *)) php_restore_ini_entry_cb);
aceaabc @zsuraski PHP 4.0
zsuraski authored
87 return SUCCESS;
88 }
89
90 /*
91 * Registration / unregistration
92 */
93
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
94 int php_register_ini_entries(php_ini_entry *ini_entry, int module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
95 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
96 php_ini_entry *p = ini_entry;
97 php_ini_entry *hashed_ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
98 pval *default_value;
99
100 while (p->name) {
101 p->module_number = module_number;
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
102 if (_php3_hash_add(&known_directives, p->name, p->name_length, p, sizeof(php_ini_entry), (void **) &hashed_ini_entry)==FAILURE) {
103 php_unregister_ini_entries(module_number);
aceaabc @zsuraski PHP 4.0
zsuraski authored
104 return FAILURE;
105 }
106 if ((default_value=cfg_get_entry(p->name, p->name_length))) {
3edb99e @zsuraski Type library support in COM module
zsuraski authored
107 if (!hashed_ini_entry->on_modify
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
108 || hashed_ini_entry->on_modify(hashed_ini_entry, default_value->value.str.val, default_value->value.str.len, hashed_ini_entry->mh_arg)==SUCCESS) {
3edb99e @zsuraski Type library support in COM module
zsuraski authored
109 hashed_ini_entry->value = default_value->value.str.val;
110 hashed_ini_entry->value_length = default_value->value.str.len;
111 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
112 }
113 hashed_ini_entry->modified = 0;
114 p++;
115 }
116 return SUCCESS;
117 }
118
119
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
120 void php_unregister_ini_entries(int module_number)
aceaabc @zsuraski PHP 4.0
zsuraski authored
121 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
122 _php3_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) php_remove_ini_entries, (void *) &module_number);
aceaabc @zsuraski PHP 4.0
zsuraski authored
123 }
124
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
125
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
126 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
127 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
128 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
129
130 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
131 return FAILURE;
132 }
133
134 if (!(ini_entry->modifyable & modify_type)) {
135 return FAILURE;
136 }
137
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
138 if (!ini_entry->on_modify
139 || ini_entry->on_modify(ini_entry, new_value, new_value_length, ini_entry->mh_arg)==SUCCESS) {
140 if (!ini_entry->orig_value) {
141 ini_entry->orig_value = ini_entry->value;
142 ini_entry->orig_value_length = ini_entry->value_length;
143 } else { /* we already changed the value, free the changed value */
144 efree(ini_entry->value);
145 }
146 ini_entry->value = estrndup(new_value, new_value_length);
147 ini_entry->value_length = new_value_length;
148 ini_entry->modified = 1;
149 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
150
151 return SUCCESS;
152 }
153
154
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
155 int php_restore_ini_entry(char *name, uint name_length)
156 {
157 php_ini_entry *ini_entry;
158
159 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
160 return FAILURE;
161 }
162
163 if (ini_entry->orig_value) {
164 ini_entry->value = ini_entry->orig_value;
165 ini_entry->value_length = ini_entry->orig_value_length;
166 }
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
167 return SUCCESS;
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
168 }
169
170
aceaabc @zsuraski PHP 4.0
zsuraski authored
171 /*
172 * Data retrieval
173 */
174
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
175 long php_ini_long(char *name, uint name_length, int orig)
aceaabc @zsuraski PHP 4.0
zsuraski authored
176 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
177 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
178
179 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
180 if (orig && ini_entry->orig_value) {
181 return (long) atoi(ini_entry->orig_value);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
182 } else {
183 return (long) atoi(ini_entry->value);
184 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
185 }
186
187 return 0;
188 }
189
190
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
191 double php_ini_double(char *name, uint name_length, int orig)
aceaabc @zsuraski PHP 4.0
zsuraski authored
192 {
6a97e16 @zsuraski * Add arguments to shutdown function
zsuraski authored
193 php_ini_entry *ini_entry;
aceaabc @zsuraski PHP 4.0
zsuraski authored
194
195 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
f8ef66d @zsuraski *** empty log message ***
zsuraski authored
196 if (orig && ini_entry->orig_value) {
197 return (double) strtod(ini_entry->orig_value, NULL);
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
198 } else {
199 return (double) strtod(ini_entry->value, NULL);
200 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
201 }
202
203 return 0.0;
204 }
205
206
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
207 char *php_ini_string(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) {
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
213 return ini_entry->orig_value;
214 } else {
215 return ini_entry->value;
216 }
aceaabc @zsuraski PHP 4.0
zsuraski authored
217 }
218
219 return "";
220 }
3e58450 @zsuraski * A lot of work on php_ini stuff
zsuraski authored
221
222
223
224 /* Standard message handlers for core_globals */
225
226 PHP_INI_MH(OnUpdateInt)
227 {
228 long *p;
229 #ifndef ZTS
230 char *base = (char *) &core_globals;
231 #else
232 char *base;
233 PLS_FETCH();
234
235 base = (char *) core_globals;
236 #endif
237
238 p = (long *) (base+(size_t) mh_arg);
239
240 *p = atoi(new_value);
241 return SUCCESS;
242 }
243
244
245 PHP_INI_MH(OnUpdateReal)
246 {
247 double *p;
248 #ifndef ZTS
249 char *base = (char *) &core_globals;
250 #else
251 char *base;
252 PLS_FETCH();
253
254 base = (char *) core_globals;
255 #endif
256
257 p = (double *) (base+(size_t) mh_arg);
258
259 *p = strtod(new_value, NULL);
260 return SUCCESS;
261 }
262
263
264 PHP_INI_MH(OnUpdateString)
265 {
266 char **p;
267 #ifndef ZTS
268 char *base = (char *) &core_globals;
269 #else
270 char *base;
271 PLS_FETCH();
272
273 base = (char *) core_globals;
274 #endif
275
276 p = (char **) (base+(size_t) mh_arg);
277
278 *p = new_value;
279 return SUCCESS;
280 }
Something went wrong with that request. Please try again.