1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Arnaud Le Blanc <arnaud.lb@gmail.com> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
20
21 #include "php.h"
22 #include "ext/standard/info.h"
23 #include "php_dl_test.h"
24 #include "dl_test_arginfo.h"
25
26 ZEND_DECLARE_MODULE_GLOBALS(dl_test)
27
28 /* {{{ void dl_test_test1() */
PHP_FUNCTION(dl_test_test1)29 PHP_FUNCTION(dl_test_test1)
30 {
31 ZEND_PARSE_PARAMETERS_NONE();
32
33 php_printf("The extension %s is loaded and working!\r\n", "dl_test");
34 }
35 /* }}} */
36
37 /* {{{ string dl_test_test2( [ string $var ] ) */
PHP_FUNCTION(dl_test_test2)38 PHP_FUNCTION(dl_test_test2)
39 {
40 char *var = "World";
41 size_t var_len = sizeof("World") - 1;
42 zend_string *retval;
43
44 ZEND_PARSE_PARAMETERS_START(0, 1)
45 Z_PARAM_OPTIONAL
46 Z_PARAM_STRING(var, var_len)
47 ZEND_PARSE_PARAMETERS_END();
48
49 retval = strpprintf(0, "Hello %s", var);
50
51 RETURN_STR(retval);
52 }
53 /* }}}*/
54
55 /* {{{ PHP_DL_TEST_USE_REGISTER_FUNCTIONS_DIRECTLY */
56 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dl_test_use_register_functions_directly, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()57 ZEND_END_ARG_INFO()
58
59 PHP_FUNCTION(dl_test_use_register_functions_directly)
60 {
61 ZEND_PARSE_PARAMETERS_NONE();
62
63 RETURN_STRING("OK");
64 }
65
66 static const zend_function_entry php_dl_test_use_register_functions_directly_functions[] = {
67 ZEND_FENTRY(dl_test_use_register_functions_directly, ZEND_FN(dl_test_use_register_functions_directly), arginfo_dl_test_use_register_functions_directly, 0)
68 ZEND_FE_END
69 };
70 /* }}} */
71
72 /* {{{ INI */
73 PHP_INI_BEGIN()
74 STD_PHP_INI_ENTRY("dl_test.long", "0", PHP_INI_ALL, OnUpdateLong, long_value, zend_dl_test_globals, dl_test_globals)
75 STD_PHP_INI_ENTRY("dl_test.string", "hello", PHP_INI_ALL, OnUpdateString, string_value, zend_dl_test_globals, dl_test_globals)
PHP_INI_END()76 PHP_INI_END()
77 /* }}} */
78
79 PHP_METHOD(DlTest, test)
80 {
81 char *var = "World";
82 size_t var_len = sizeof("World") - 1;
83 zend_string *retval;
84
85 ZEND_PARSE_PARAMETERS_START(0, 1)
86 Z_PARAM_OPTIONAL
87 Z_PARAM_STRING(var, var_len)
88 ZEND_PARSE_PARAMETERS_END();
89
90 retval = strpprintf(0, "Hello %s", var);
91
92 RETURN_STR(retval);
93 }
94
95 /* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(dl_test)96 PHP_MINIT_FUNCTION(dl_test)
97 {
98 register_class_DlTest();
99
100 /* Test backwards compatibility */
101 if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
102 zend_register_ini_entries(ini_entries, module_number);
103 } else {
104 REGISTER_INI_ENTRIES();
105 }
106
107 if (getenv("PHP_DL_TEST_USE_REGISTER_FUNCTIONS_DIRECTLY")) {
108 zend_register_functions(NULL, php_dl_test_use_register_functions_directly_functions, NULL, type);
109 }
110
111 if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
112 fprintf(stderr, "DL TEST MINIT\n");
113 }
114
115 register_dl_test_symbols(module_number);
116
117 return SUCCESS;
118 }
119 /* }}} */
120
121 /* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(dl_test)122 static PHP_MSHUTDOWN_FUNCTION(dl_test)
123 {
124 /* Test backwards compatibility */
125 if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
126 zend_unregister_ini_entries(module_number);
127 } else {
128 UNREGISTER_INI_ENTRIES();
129 }
130
131 if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
132 fprintf(stderr, "DL TEST MSHUTDOWN\n");
133 }
134
135 return SUCCESS;
136 }
137 /* }}} */
138
139 /* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(dl_test)140 PHP_RINIT_FUNCTION(dl_test)
141 {
142 #if defined(ZTS) && defined(COMPILE_DL_DL_TEST)
143 ZEND_TSRMLS_CACHE_UPDATE();
144 #endif
145
146 if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
147 fprintf(stderr, "DL TEST RINIT\n");
148 }
149
150 return SUCCESS;
151 }
152 /* }}} */
153
154 /* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION(dl_test)155 PHP_RSHUTDOWN_FUNCTION(dl_test)
156 {
157 if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
158 fprintf(stderr, "DL TEST RSHUTDOWN\n");
159 }
160
161 return SUCCESS;
162 }
163 /* }}} */
164
165 /* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(dl_test)166 PHP_MINFO_FUNCTION(dl_test)
167 {
168 php_info_print_table_start();
169 php_info_print_table_row(2, "dl_test support", "enabled");
170 php_info_print_table_end();
171
172 DISPLAY_INI_ENTRIES();
173 }
174 /* }}} */
175
176 /* {{{ PHP_GINIT_FUNCTION */
PHP_GINIT_FUNCTION(dl_test)177 static PHP_GINIT_FUNCTION(dl_test)
178 {
179 #if defined(COMPILE_DL_DL_TEST) && defined(ZTS)
180 ZEND_TSRMLS_CACHE_UPDATE();
181 #endif
182 memset(dl_test_globals, 0, sizeof(*dl_test_globals));
183 }
184 /* }}} */
185
186 /* {{{ dl_test_module_entry */
187 zend_module_entry dl_test_module_entry = {
188 STANDARD_MODULE_HEADER,
189 "dl_test",
190 ext_functions,
191 PHP_MINIT(dl_test),
192 PHP_MSHUTDOWN(dl_test),
193 PHP_RINIT(dl_test),
194 PHP_RSHUTDOWN(dl_test),
195 PHP_MINFO(dl_test),
196 PHP_DL_TEST_VERSION,
197 PHP_MODULE_GLOBALS(dl_test),
198 PHP_GINIT(dl_test),
199 NULL,
200 NULL,
201 STANDARD_MODULE_PROPERTIES_EX
202 };
203 /* }}} */
204
205 #ifdef COMPILE_DL_DL_TEST
206 # ifdef ZTS
207 ZEND_TSRMLS_CACHE_DEFINE()
208 # endif
209 ZEND_GET_MODULE(dl_test)
210 #endif
211