xref: /PHP-8.1/ext/dl_test/dl_test.c (revision a8c6c616)
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 /* {{{ INI */
56 PHP_INI_BEGIN()
57 	STD_PHP_INI_BOOLEAN("dl_test.long",      "0", PHP_INI_ALL, OnUpdateLong,       long_value,       zend_dl_test_globals, dl_test_globals)
58 	STD_PHP_INI_ENTRY("dl_test.string", "hello", PHP_INI_ALL, OnUpdateString,                           string_value, zend_dl_test_globals, dl_test_globals)
PHP_INI_END()59 PHP_INI_END()
60 /* }}} */
61 
62 /* {{{ PHP_MINIT_FUNCTION */
63 PHP_MINIT_FUNCTION(dl_test)
64 {
65 	/* Test backwards compatibility */
66 	if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
67 		zend_register_ini_entries(ini_entries, module_number);
68 	} else {
69 		REGISTER_INI_ENTRIES();
70 	}
71 
72 	if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
73 		fprintf(stderr, "DL TEST MINIT\n");
74 	}
75 
76 	return SUCCESS;
77 }
78 /* }}} */
79 
80 /* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(dl_test)81 static PHP_MSHUTDOWN_FUNCTION(dl_test)
82 {
83 	/* Test backwards compatibility */
84 	if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
85 		zend_unregister_ini_entries(module_number);
86 	} else {
87 		UNREGISTER_INI_ENTRIES();
88 	}
89 
90 	if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
91 		fprintf(stderr, "DL TEST MSHUTDOWN\n");
92 	}
93 
94 	return SUCCESS;
95 }
96 /* }}} */
97 
98 /* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(dl_test)99 PHP_RINIT_FUNCTION(dl_test)
100 {
101 #if defined(ZTS) && defined(COMPILE_DL_DL_TEST)
102 	ZEND_TSRMLS_CACHE_UPDATE();
103 #endif
104 
105 	if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
106 		fprintf(stderr, "DL TEST RINIT\n");
107 	}
108 
109 	return SUCCESS;
110 }
111 /* }}} */
112 
113 /* {{{ PHP_RSHUTDOWN_FUNCTION */
PHP_RSHUTDOWN_FUNCTION(dl_test)114 PHP_RSHUTDOWN_FUNCTION(dl_test)
115 {
116 	if (getenv("PHP_DL_TEST_MODULE_DEBUG")) {
117 		fprintf(stderr, "DL TEST RSHUTDOWN\n");
118 	}
119 
120 	return SUCCESS;
121 }
122 /* }}} */
123 
124 /* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(dl_test)125 PHP_MINFO_FUNCTION(dl_test)
126 {
127 	php_info_print_table_start();
128 	php_info_print_table_header(2, "dl_test support", "enabled");
129 	php_info_print_table_end();
130 
131 	DISPLAY_INI_ENTRIES();
132 }
133 /* }}} */
134 
135 /* {{{ PHP_GINIT_FUNCTION */
PHP_GINIT_FUNCTION(dl_test)136 static PHP_GINIT_FUNCTION(dl_test)
137 {
138 #if defined(COMPILE_DL_DL_TEST) && defined(ZTS)
139 	ZEND_TSRMLS_CACHE_UPDATE();
140 #endif
141 	memset(dl_test_globals, 0, sizeof(*dl_test_globals));
142 }
143 /* }}} */
144 
145 /* {{{ dl_test_module_entry */
146 zend_module_entry dl_test_module_entry = {
147 	STANDARD_MODULE_HEADER,
148 	"dl_test",
149 	ext_functions,
150 	PHP_MINIT(dl_test),
151 	PHP_MSHUTDOWN(dl_test),
152 	PHP_RINIT(dl_test),
153 	PHP_RSHUTDOWN(dl_test),
154 	PHP_MINFO(dl_test),
155 	PHP_DL_TEST_VERSION,
156 	PHP_MODULE_GLOBALS(dl_test),
157 	PHP_GINIT(dl_test),
158 	NULL,
159 	NULL,
160 	STANDARD_MODULE_PROPERTIES_EX
161 };
162 /* }}} */
163 
164 #ifdef COMPILE_DL_DL_TEST
165 # ifdef ZTS
166 ZEND_TSRMLS_CACHE_DEFINE()
167 # endif
168 ZEND_GET_MODULE(dl_test)
169 #endif
170