Skip to content
Newer
Older
100644 149 lines (114 sloc) 3.02 KB
aceaabc @zsuraski PHP 4.0
zsuraski authored Apr 7, 1999
1 #include <stdlib.h>
2
3 #include "php.h"
4 #include "php_ini.h"
5 #include "zend_alloc.h"
6
7 static HashTable known_directives;
8
9
10 /*
11 * hash_apply functions
12 */
13 static int zend_remove_ini_entries(zend_ini_entry *ini_entry, int *module_number)
14 {
15 if (ini_entry->module_number == *module_number) {
16 return 1;
17 } else {
18 return 0;
19 }
20 }
21
22
23 static int zend_restore_ini_entry(zend_ini_entry *ini_entry)
24 {
25 if (ini_entry->modified) {
26 efree(ini_entry->value);
27 ini_entry->value = ini_entry->orig_value;
28 ini_entry->value_length = ini_entry->orig_value_length;
29 ini_entry->modified = 0;
30 }
31 return 0;
32 }
33
34 /*
35 * Startup / shutdown
36 */
37 int zend_ini_mstartup()
38 {
39 if (_php3_hash_init(&known_directives, 100, NULL, NULL, 1)==FAILURE) {
40 return FAILURE;
41 }
42 return SUCCESS;
43 }
44
45
46 int zend_ini_mshutdown()
47 {
48 _php3_hash_destroy(&known_directives);
49 return SUCCESS;
50 }
51
52
53 int zend_ini_rshutdown()
54 {
55 _php3_hash_apply(&known_directives, (int (*)(void *)) zend_restore_ini_entry);
56 return SUCCESS;
57 }
58
59 /*
60 * Registration / unregistration
61 */
62
63 int zend_register_ini_entries(zend_ini_entry *ini_entry, int module_number)
64 {
65 zend_ini_entry *p = ini_entry;
66 zend_ini_entry *hashed_ini_entry;
67 pval *default_value;
68
69 while (p->name) {
70 p->module_number = module_number;
71 if (_php3_hash_add(&known_directives, p->name, p->name_length, p, sizeof(zend_ini_entry), (void **) &hashed_ini_entry)==FAILURE) {
72 zend_unregister_ini_entries(module_number);
73 return FAILURE;
74 }
75 if ((default_value=cfg_get_entry(p->name, p->name_length))) {
76 hashed_ini_entry->value = default_value->value.str.val;
77 hashed_ini_entry->value_length = default_value->value.str.len;
78 }
79 hashed_ini_entry->modified = 0;
80 p++;
81 }
82 return SUCCESS;
83 }
84
85
86 void zend_unregister_ini_entries(int module_number)
87 {
88 _php3_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) zend_remove_ini_entries, (void *) &module_number);
89 }
90
91 int zend_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type)
92 {
93 zend_ini_entry *ini_entry;
94
95 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
96 return FAILURE;
97 }
98
99 if (!(ini_entry->modifyable & modify_type)) {
100 return FAILURE;
101 }
102
103 ini_entry->value = estrndup(new_value, new_value_length);
104 ini_entry->value_length = new_value_length;
105 ini_entry->modified = 1;
106
107 return SUCCESS;
108 }
109
110
111 /*
112 * Data retrieval
113 */
114
115 long zend_ini_long(char *name, uint name_length)
116 {
117 zend_ini_entry *ini_entry;
118
119 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
120 return (long) atoi(ini_entry->value);
121 }
122
123 return 0;
124 }
125
126
127 double zend_ini_double(char *name, uint name_length)
128 {
129 zend_ini_entry *ini_entry;
130
131 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
132 return (double) strtod(ini_entry->value, NULL);
133 }
134
135 return 0.0;
136 }
137
138
139 char *zend_ini_string(char *name, uint name_length)
140 {
141 zend_ini_entry *ini_entry;
142
143 if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
144 return ini_entry->value;
145 }
146
147 return "";
148 }
Something went wrong with that request. Please try again.