xref: /PHP-7.2/Zend/zend_ini.h (revision 7a7ec01a)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Author: Zeev Suraski <zeev@zend.com>                                 |
16    +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 #ifndef ZEND_INI_H
22 #define ZEND_INI_H
23 
24 #define ZEND_INI_USER	(1<<0)
25 #define ZEND_INI_PERDIR	(1<<1)
26 #define ZEND_INI_SYSTEM	(1<<2)
27 
28 #define ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
29 
30 #define ZEND_INI_MH(name) int name(zend_ini_entry *entry, zend_string *new_value, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage)
31 #define ZEND_INI_DISP(name) void name(zend_ini_entry *ini_entry, int type)
32 
33 typedef struct _zend_ini_entry_def {
34 	const char *name;
35 	ZEND_INI_MH((*on_modify));
36 	void *mh_arg1;
37 	void *mh_arg2;
38 	void *mh_arg3;
39 	const char *value;
40 	void (*displayer)(zend_ini_entry *ini_entry, int type);
41 	int modifiable;
42 
43 	uint32_t name_length;
44 	uint32_t value_length;
45 } zend_ini_entry_def;
46 
47 struct _zend_ini_entry {
48 	zend_string *name;
49 	ZEND_INI_MH((*on_modify));
50 	void *mh_arg1;
51 	void *mh_arg2;
52 	void *mh_arg3;
53 	zend_string *value;
54 	zend_string *orig_value;
55 	void (*displayer)(zend_ini_entry *ini_entry, int type);
56 	int modifiable;
57 
58 	int orig_modifiable;
59 	int modified;
60 	int module_number;
61 };
62 
63 BEGIN_EXTERN_C()
64 ZEND_API int zend_ini_startup(void);
65 ZEND_API int zend_ini_shutdown(void);
66 ZEND_API int zend_ini_global_shutdown(void);
67 ZEND_API int zend_ini_deactivate(void);
68 ZEND_API void zend_ini_dtor(HashTable *ini_directives);
69 
70 ZEND_API int zend_copy_ini_directives(void);
71 
72 ZEND_API void zend_ini_sort_entries(void);
73 
74 ZEND_API int zend_register_ini_entries(const zend_ini_entry_def *ini_entry, int module_number);
75 ZEND_API void zend_unregister_ini_entries(int module_number);
76 ZEND_API void zend_ini_refresh_caches(int stage);
77 ZEND_API int zend_alter_ini_entry(zend_string *name, zend_string *new_value, int modify_type, int stage);
78 ZEND_API int zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, int force_change);
79 ZEND_API int zend_alter_ini_entry_chars(zend_string *name, const char *value, size_t value_length, int modify_type, int stage);
80 ZEND_API int zend_alter_ini_entry_chars_ex(zend_string *name, const char *value, size_t value_length, int modify_type, int stage, int force_change);
81 ZEND_API int zend_restore_ini_entry(zend_string *name, int stage);
82 ZEND_API void display_ini_entries(zend_module_entry *module);
83 
84 ZEND_API zend_long zend_ini_long(char *name, uint32_t name_length, int orig);
85 ZEND_API double zend_ini_double(char *name, uint32_t name_length, int orig);
86 ZEND_API char *zend_ini_string(char *name, uint32_t name_length, int orig);
87 ZEND_API char *zend_ini_string_ex(char *name, uint32_t name_length, int orig, zend_bool *exists);
88 
89 ZEND_API int zend_ini_register_displayer(char *name, uint32_t name_length, void (*displayer)(zend_ini_entry *ini_entry, int type));
90 
91 ZEND_API ZEND_INI_DISP(zend_ini_boolean_displayer_cb);
92 ZEND_API ZEND_INI_DISP(zend_ini_color_displayer_cb);
93 ZEND_API ZEND_INI_DISP(display_link_numbers);
94 END_EXTERN_C()
95 
96 #define ZEND_INI_BEGIN()		static const zend_ini_entry_def ini_entries[] = {
97 #define ZEND_INI_END()		{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0} };
98 
99 #define ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, arg1, arg2, arg3, displayer) \
100 	{ name, on_modify, arg1, arg2, arg3, default_value, displayer, modifiable, sizeof(name)-1, sizeof(default_value)-1 },
101 
102 #define ZEND_INI_ENTRY3(name, default_value, modifiable, on_modify, arg1, arg2, arg3) \
103 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, arg1, arg2, arg3, NULL)
104 
105 #define ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, arg1, arg2, displayer) \
106 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, arg1, arg2, NULL, displayer)
107 
108 #define ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, arg1, arg2) \
109 	ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, arg1, arg2, NULL)
110 
111 #define ZEND_INI_ENTRY1_EX(name, default_value, modifiable, on_modify, arg1, displayer) \
112 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, arg1, NULL, NULL, displayer)
113 
114 #define ZEND_INI_ENTRY1(name, default_value, modifiable, on_modify, arg1) \
115 	ZEND_INI_ENTRY1_EX(name, default_value, modifiable, on_modify, arg1, NULL)
116 
117 #define ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, displayer) \
118 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, NULL, NULL, NULL, displayer)
119 
120 #define ZEND_INI_ENTRY(name, default_value, modifiable, on_modify) \
121 	ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, NULL)
122 
123 #ifdef ZTS
124 #define STD_ZEND_INI_ENTRY(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
125 	ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id)
126 #define STD_ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr, displayer) \
127 	ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, displayer)
128 #define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
129 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr##_id, NULL, zend_ini_boolean_displayer_cb)
130 #else
131 #define STD_ZEND_INI_ENTRY(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
132 	ZEND_INI_ENTRY2(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr)
133 #define STD_ZEND_INI_ENTRY_EX(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr, displayer) \
134 	ZEND_INI_ENTRY2_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, displayer)
135 #define STD_ZEND_INI_BOOLEAN(name, default_value, modifiable, on_modify, property_name, struct_type, struct_ptr) \
136 	ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)
137 #endif
138 
139 #define INI_INT(name) zend_ini_long((name), sizeof(name)-1, 0)
140 #define INI_FLT(name) zend_ini_double((name), sizeof(name)-1, 0)
141 #define INI_STR(name) zend_ini_string_ex((name), sizeof(name)-1, 0, NULL)
142 #define INI_BOOL(name) ((zend_bool) INI_INT(name))
143 
144 #define INI_ORIG_INT(name)	zend_ini_long((name), sizeof(name)-1, 1)
145 #define INI_ORIG_FLT(name)	zend_ini_double((name), sizeof(name)-1, 1)
146 #define INI_ORIG_STR(name)	zend_ini_string((name), sizeof(name)-1, 1)
147 #define INI_ORIG_BOOL(name) ((zend_bool) INI_ORIG_INT(name))
148 
149 #define REGISTER_INI_ENTRIES() zend_register_ini_entries(ini_entries, module_number)
150 #define UNREGISTER_INI_ENTRIES() zend_unregister_ini_entries(module_number)
151 #define DISPLAY_INI_ENTRIES() display_ini_entries(zend_module)
152 
153 #define REGISTER_INI_DISPLAYER(name, displayer) zend_ini_register_displayer((name), sizeof(name)-1, displayer)
154 #define REGISTER_INI_BOOLEAN(name) REGISTER_INI_DISPLAYER(name, zend_ini_boolean_displayer_cb)
155 
156 /* Standard message handlers */
157 BEGIN_EXTERN_C()
158 ZEND_API ZEND_INI_MH(OnUpdateBool);
159 ZEND_API ZEND_INI_MH(OnUpdateLong);
160 ZEND_API ZEND_INI_MH(OnUpdateLongGEZero);
161 ZEND_API ZEND_INI_MH(OnUpdateReal);
162 ZEND_API ZEND_INI_MH(OnUpdateString);
163 ZEND_API ZEND_INI_MH(OnUpdateStringUnempty);
164 END_EXTERN_C()
165 
166 #define ZEND_INI_DISPLAY_ORIG	1
167 #define ZEND_INI_DISPLAY_ACTIVE	2
168 
169 #define ZEND_INI_STAGE_STARTUP		(1<<0)
170 #define ZEND_INI_STAGE_SHUTDOWN		(1<<1)
171 #define ZEND_INI_STAGE_ACTIVATE		(1<<2)
172 #define ZEND_INI_STAGE_DEACTIVATE	(1<<3)
173 #define ZEND_INI_STAGE_RUNTIME		(1<<4)
174 #define ZEND_INI_STAGE_HTACCESS		(1<<5)
175 
176 /* INI parsing engine */
177 typedef void (*zend_ini_parser_cb_t)(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg);
178 BEGIN_EXTERN_C()
179 ZEND_API int zend_parse_ini_file(zend_file_handle *fh, zend_bool unbuffered_errors, int scanner_mode, zend_ini_parser_cb_t ini_parser_cb, void *arg);
180 ZEND_API int zend_parse_ini_string(char *str, zend_bool unbuffered_errors, int scanner_mode, zend_ini_parser_cb_t ini_parser_cb, void *arg);
181 END_EXTERN_C()
182 
183 /* INI entries */
184 #define ZEND_INI_PARSER_ENTRY     1 /* Normal entry: foo = bar */
185 #define ZEND_INI_PARSER_SECTION	  2 /* Section: [foobar] */
186 #define ZEND_INI_PARSER_POP_ENTRY 3 /* Offset entry: foo[] = bar */
187 
188 typedef struct _zend_ini_parser_param {
189 	zend_ini_parser_cb_t ini_parser_cb;
190 	void *arg;
191 } zend_ini_parser_param;
192 
193 #endif /* ZEND_INI_H */
194 
195 /*
196  * Local variables:
197  * tab-width: 4
198  * c-basic-offset: 4
199  * indent-tabs-mode: t
200  * End:
201  * vim600: sw=4 ts=4 fdm=marker
202  * vim<600: sw=4 ts=4
203  */
204