dl_test.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifdef HAVE_CONFIG_H
  17. # include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "ext/standard/info.h"
  21. #include "php_dl_test.h"
  22. #include "dl_test_arginfo.h"
  23. ZEND_DECLARE_MODULE_GLOBALS(dl_test)
  24. /* {{{ void dl_test_test1() */
  25. PHP_FUNCTION(dl_test_test1)
  26. {
  27. ZEND_PARSE_PARAMETERS_NONE();
  28. php_printf("The extension %s is loaded and working!\r\n", "dl_test");
  29. }
  30. /* }}} */
  31. /* {{{ string dl_test_test2( [ string $var ] ) */
  32. PHP_FUNCTION(dl_test_test2)
  33. {
  34. char *var = "World";
  35. size_t var_len = sizeof("World") - 1;
  36. zend_string *retval;
  37. ZEND_PARSE_PARAMETERS_START(0, 1)
  38. Z_PARAM_OPTIONAL
  39. Z_PARAM_STRING(var, var_len)
  40. ZEND_PARSE_PARAMETERS_END();
  41. retval = strpprintf(0, "Hello %s", var);
  42. RETURN_STR(retval);
  43. }
  44. /* }}}*/
  45. /* {{{ INI */
  46. PHP_INI_BEGIN()
  47. STD_PHP_INI_BOOLEAN("dl_test.long", "0", PHP_INI_ALL, OnUpdateLong, long_value, zend_dl_test_globals, dl_test_globals)
  48. STD_PHP_INI_ENTRY("dl_test.string", "hello", PHP_INI_ALL, OnUpdateString, string_value, zend_dl_test_globals, dl_test_globals)
  49. PHP_INI_END()
  50. /* }}} */
  51. /* {{{ PHP_MINIT_FUNCTION */
  52. PHP_MINIT_FUNCTION(dl_test)
  53. {
  54. /* Test backwards compatibility */
  55. if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
  56. zend_register_ini_entries(ini_entries, module_number);
  57. } else {
  58. REGISTER_INI_ENTRIES();
  59. }
  60. return SUCCESS;
  61. }
  62. /* }}} */
  63. /* {{{ PHP_MSHUTDOWN_FUNCTION */
  64. static PHP_MSHUTDOWN_FUNCTION(dl_test)
  65. {
  66. /* Test backwards compatibility */
  67. if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
  68. zend_unregister_ini_entries(module_number);
  69. } else {
  70. UNREGISTER_INI_ENTRIES();
  71. }
  72. return SUCCESS;
  73. }
  74. /* }}} */
  75. /* {{{ PHP_RINIT_FUNCTION */
  76. PHP_RINIT_FUNCTION(dl_test)
  77. {
  78. #if defined(ZTS) && defined(COMPILE_DL_DL_TEST)
  79. ZEND_TSRMLS_CACHE_UPDATE();
  80. #endif
  81. return SUCCESS;
  82. }
  83. /* }}} */
  84. /* {{{ PHP_MINFO_FUNCTION */
  85. PHP_MINFO_FUNCTION(dl_test)
  86. {
  87. php_info_print_table_start();
  88. php_info_print_table_header(2, "dl_test support", "enabled");
  89. php_info_print_table_end();
  90. DISPLAY_INI_ENTRIES();
  91. }
  92. /* }}} */
  93. /* {{{ PHP_GINIT_FUNCTION */
  94. static PHP_GINIT_FUNCTION(dl_test)
  95. {
  96. #if defined(COMPILE_DL_DL_TEST) && defined(ZTS)
  97. ZEND_TSRMLS_CACHE_UPDATE();
  98. #endif
  99. memset(dl_test_globals, 0, sizeof(*dl_test_globals));
  100. }
  101. /* }}} */
  102. /* {{{ dl_test_module_entry */
  103. zend_module_entry dl_test_module_entry = {
  104. STANDARD_MODULE_HEADER,
  105. "dl_test",
  106. ext_functions,
  107. PHP_MINIT(dl_test),
  108. PHP_MSHUTDOWN(dl_test),
  109. PHP_RINIT(dl_test),
  110. NULL,
  111. PHP_MINFO(dl_test),
  112. PHP_DL_TEST_VERSION,
  113. PHP_MODULE_GLOBALS(dl_test),
  114. PHP_GINIT(dl_test),
  115. NULL,
  116. NULL,
  117. STANDARD_MODULE_PROPERTIES_EX
  118. };
  119. /* }}} */
  120. #ifdef COMPILE_DL_DL_TEST
  121. # ifdef ZTS
  122. ZEND_TSRMLS_CACHE_DEFINE()
  123. # endif
  124. ZEND_GET_MODULE(dl_test)
  125. #endif