com_extension.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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: Wez Furlong <wez@thebrainroom.com> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include <intsafe.h>
  20. #include "php.h"
  21. #include "php_ini.h"
  22. #include "ext/standard/info.h"
  23. #include "php_com_dotnet.h"
  24. #include "php_com_dotnet_internal.h"
  25. #include "Zend/zend_exceptions.h"
  26. #include "Zend/zend_interfaces.h"
  27. #include "com_extension_arginfo.h"
  28. ZEND_DECLARE_MODULE_GLOBALS(com_dotnet)
  29. static PHP_GINIT_FUNCTION(com_dotnet);
  30. zend_class_entry
  31. *php_com_variant_class_entry,
  32. *php_com_exception_class_entry,
  33. *php_com_saproxy_class_entry;
  34. /* {{{ com_dotnet_module_entry */
  35. zend_module_entry com_dotnet_module_entry = {
  36. STANDARD_MODULE_HEADER,
  37. "com_dotnet",
  38. ext_functions,
  39. PHP_MINIT(com_dotnet),
  40. PHP_MSHUTDOWN(com_dotnet),
  41. PHP_RINIT(com_dotnet),
  42. PHP_RSHUTDOWN(com_dotnet),
  43. PHP_MINFO(com_dotnet),
  44. PHP_COM_DOTNET_VERSION,
  45. PHP_MODULE_GLOBALS(com_dotnet),
  46. PHP_GINIT(com_dotnet),
  47. NULL,
  48. NULL,
  49. STANDARD_MODULE_PROPERTIES_EX
  50. };
  51. /* }}} */
  52. #ifdef COMPILE_DL_COM_DOTNET
  53. #ifdef ZTS
  54. ZEND_TSRMLS_CACHE_DEFINE()
  55. #endif
  56. ZEND_GET_MODULE(com_dotnet)
  57. #endif
  58. /* {{{ PHP_INI */
  59. /* com.typelib_file is the path to a file containing a
  60. * list of typelibraries to register *persistently*.
  61. * lines starting with ; are comments
  62. * append #cis to end of typelib name to cause its constants
  63. * to be loaded case insensitively */
  64. static PHP_INI_MH(OnTypeLibFileUpdate)
  65. {
  66. FILE *typelib_file;
  67. char *typelib_name_buffer;
  68. char *strtok_buf = NULL;
  69. if (NULL == new_value || !new_value->val[0] || (typelib_file = VCWD_FOPEN(new_value->val, "r"))==NULL) {
  70. return FAILURE;
  71. }
  72. typelib_name_buffer = (char *) emalloc(sizeof(char)*1024);
  73. while (fgets(typelib_name_buffer, 1024, typelib_file)) {
  74. ITypeLib *pTL;
  75. char *typelib_name;
  76. char *modifier, *ptr;
  77. int mode = CONST_CS | CONST_PERSISTENT; /* CONST_PERSISTENT is ok here */
  78. if (typelib_name_buffer[0]==';') {
  79. continue;
  80. }
  81. typelib_name = php_strtok_r(typelib_name_buffer, "\r\n", &strtok_buf); /* get rid of newlines */
  82. if (typelib_name == NULL) {
  83. continue;
  84. }
  85. typelib_name = php_strtok_r(typelib_name, "#", &strtok_buf);
  86. modifier = php_strtok_r(NULL, "#", &strtok_buf);
  87. if (modifier != NULL) {
  88. if (!strcmp(modifier, "cis") || !strcmp(modifier, "case_insensitive")) {
  89. php_error_docref("com.configuration", E_WARNING, "Declaration of case-insensitive constants is no longer supported; #cis modifier ignored");
  90. }
  91. }
  92. /* Remove leading/training white spaces on search_string */
  93. while (isspace(*typelib_name)) {/* Ends on '\0' in worst case */
  94. typelib_name ++;
  95. }
  96. ptr = typelib_name + strlen(typelib_name) - 1;
  97. while ((ptr != typelib_name) && isspace(*ptr)) {
  98. *ptr = '\0';
  99. ptr--;
  100. }
  101. if ((pTL = php_com_load_typelib_via_cache(typelib_name, COMG(code_page))) != NULL) {
  102. php_com_import_typelib(pTL, mode, COMG(code_page));
  103. ITypeLib_Release(pTL);
  104. }
  105. }
  106. efree(typelib_name_buffer);
  107. fclose(typelib_file);
  108. return SUCCESS;
  109. }
  110. static ZEND_INI_MH(OnAutoregisterCasesensitive)
  111. {
  112. if (!zend_ini_parse_bool(new_value)) {
  113. php_error_docref("com.configuration", E_WARNING, "Declaration of case-insensitive constants is no longer supported");
  114. return FAILURE;
  115. }
  116. return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
  117. }
  118. PHP_INI_BEGIN()
  119. STD_PHP_INI_BOOLEAN("com.allow_dcom", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_dcom, zend_com_dotnet_globals, com_dotnet_globals)
  120. STD_PHP_INI_BOOLEAN("com.autoregister_verbose", "0", PHP_INI_ALL, OnUpdateBool, autoreg_verbose, zend_com_dotnet_globals, com_dotnet_globals)
  121. STD_PHP_INI_BOOLEAN("com.autoregister_typelib", "0", PHP_INI_ALL, OnUpdateBool, autoreg_on, zend_com_dotnet_globals, com_dotnet_globals)
  122. STD_PHP_INI_ENTRY("com.autoregister_casesensitive", "1", PHP_INI_ALL, OnAutoregisterCasesensitive, autoreg_case_sensitive, zend_com_dotnet_globals, com_dotnet_globals)
  123. STD_PHP_INI_ENTRY("com.code_page", "", PHP_INI_ALL, OnUpdateLong, code_page, zend_com_dotnet_globals, com_dotnet_globals)
  124. PHP_INI_ENTRY("com.typelib_file", "", PHP_INI_SYSTEM, OnTypeLibFileUpdate)
  125. PHP_INI_ENTRY("com.dotnet_version", NULL, PHP_INI_SYSTEM, NULL)
  126. PHP_INI_END()
  127. /* }}} */
  128. /* {{{ PHP_GINIT_FUNCTION */
  129. static PHP_GINIT_FUNCTION(com_dotnet)
  130. {
  131. #if defined(COMPILE_DL_COM_DOTNET) && defined(ZTS)
  132. ZEND_TSRMLS_CACHE_UPDATE();
  133. #endif
  134. memset(com_dotnet_globals, 0, sizeof(*com_dotnet_globals));
  135. com_dotnet_globals->code_page = CP_ACP;
  136. }
  137. /* }}} */
  138. /* {{{ PHP_MINIT_FUNCTION */
  139. PHP_MINIT_FUNCTION(com_dotnet)
  140. {
  141. zend_class_entry *tmp;
  142. php_com_wrapper_minit(INIT_FUNC_ARGS_PASSTHRU);
  143. php_com_persist_minit(INIT_FUNC_ARGS_PASSTHRU);
  144. php_com_exception_class_entry = register_class_com_exception(zend_ce_exception);
  145. /* php_com_exception_class_entry->constructor->common.fn_flags |= ZEND_ACC_PROTECTED; */
  146. php_com_saproxy_class_entry = register_class_com_safearray_proxy();
  147. /* php_com_saproxy_class_entry->constructor->common.fn_flags |= ZEND_ACC_PROTECTED; */
  148. php_com_saproxy_class_entry->get_iterator = php_com_saproxy_iter_get;
  149. php_com_variant_class_entry = register_class_variant();
  150. php_com_variant_class_entry->create_object = php_com_object_new;
  151. php_com_variant_class_entry->get_iterator = php_com_iter_get;
  152. tmp = register_class_com(php_com_variant_class_entry);
  153. tmp->create_object = php_com_object_new;
  154. tmp->get_iterator = php_com_iter_get;
  155. #if HAVE_MSCOREE_H
  156. tmp = register_class_dotnet(php_com_variant_class_entry);
  157. tmp->create_object = php_com_object_new;
  158. tmp->get_iterator = php_com_iter_get;
  159. #endif
  160. REGISTER_INI_ENTRIES();
  161. #define COM_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS|CONST_PERSISTENT)
  162. #if SIZEOF_ZEND_LONG == 8
  163. # define COM_ERR_CONST(x) REGISTER_LONG_CONSTANT(#x, (zend_long) (ULONG) (x), CONST_CS|CONST_PERSISTENT)
  164. #else
  165. # define COM_ERR_CONST COM_CONST
  166. #endif
  167. COM_CONST(CLSCTX_INPROC_SERVER);
  168. COM_CONST(CLSCTX_INPROC_HANDLER);
  169. COM_CONST(CLSCTX_LOCAL_SERVER);
  170. COM_CONST(CLSCTX_REMOTE_SERVER);
  171. COM_CONST(CLSCTX_SERVER);
  172. COM_CONST(CLSCTX_ALL);
  173. #if 0
  174. COM_CONST(DISPATCH_METHOD);
  175. COM_CONST(DISPATCH_PROPERTYGET);
  176. COM_CONST(DISPATCH_PROPERTYPUT);
  177. #endif
  178. COM_CONST(VT_NULL);
  179. COM_CONST(VT_EMPTY);
  180. COM_CONST(VT_UI1);
  181. COM_CONST(VT_I1);
  182. COM_CONST(VT_UI2);
  183. COM_CONST(VT_I2);
  184. COM_CONST(VT_UI4);
  185. COM_CONST(VT_I4);
  186. COM_CONST(VT_R4);
  187. COM_CONST(VT_R8);
  188. COM_CONST(VT_BOOL);
  189. COM_CONST(VT_ERROR);
  190. COM_CONST(VT_CY);
  191. COM_CONST(VT_DATE);
  192. COM_CONST(VT_BSTR);
  193. COM_CONST(VT_DECIMAL);
  194. COM_CONST(VT_UNKNOWN);
  195. COM_CONST(VT_DISPATCH);
  196. COM_CONST(VT_VARIANT);
  197. COM_CONST(VT_INT);
  198. COM_CONST(VT_UINT);
  199. COM_CONST(VT_ARRAY);
  200. COM_CONST(VT_BYREF);
  201. COM_CONST(CP_ACP);
  202. COM_CONST(CP_MACCP);
  203. COM_CONST(CP_OEMCP);
  204. COM_CONST(CP_UTF7);
  205. COM_CONST(CP_UTF8);
  206. COM_CONST(CP_SYMBOL);
  207. COM_CONST(CP_THREAD_ACP);
  208. COM_CONST(VARCMP_LT);
  209. COM_CONST(VARCMP_EQ);
  210. COM_CONST(VARCMP_GT);
  211. COM_CONST(VARCMP_NULL);
  212. COM_CONST(LOCALE_SYSTEM_DEFAULT);
  213. COM_CONST(NORM_IGNORECASE);
  214. COM_CONST(NORM_IGNORENONSPACE);
  215. COM_CONST(NORM_IGNORESYMBOLS);
  216. COM_CONST(NORM_IGNOREWIDTH);
  217. COM_CONST(NORM_IGNOREKANATYPE);
  218. #ifdef NORM_IGNOREKASHIDA
  219. COM_CONST(NORM_IGNOREKASHIDA);
  220. #endif
  221. COM_ERR_CONST(DISP_E_DIVBYZERO);
  222. COM_ERR_CONST(DISP_E_OVERFLOW);
  223. COM_ERR_CONST(DISP_E_BADINDEX);
  224. COM_ERR_CONST(MK_E_UNAVAILABLE);
  225. #if SIZEOF_ZEND_LONG == 8
  226. COM_CONST(VT_UI8);
  227. COM_CONST(VT_I8);
  228. #endif
  229. PHP_MINIT(com_typeinfo)(INIT_FUNC_ARGS_PASSTHRU);
  230. return SUCCESS;
  231. }
  232. /* }}} */
  233. /* {{{ PHP_MSHUTDOWN_FUNCTION */
  234. PHP_MSHUTDOWN_FUNCTION(com_dotnet)
  235. {
  236. UNREGISTER_INI_ENTRIES();
  237. #if HAVE_MSCOREE_H
  238. if (COMG(dotnet_runtime_stuff)) {
  239. php_com_dotnet_mshutdown();
  240. }
  241. #endif
  242. PHP_MSHUTDOWN(com_typeinfo)(INIT_FUNC_ARGS_PASSTHRU);
  243. return SUCCESS;
  244. }
  245. /* }}} */
  246. /* {{{ PHP_RINIT_FUNCTION */
  247. PHP_RINIT_FUNCTION(com_dotnet)
  248. {
  249. COMG(rshutdown_started) = 0;
  250. return SUCCESS;
  251. }
  252. /* }}} */
  253. /* {{{ PHP_RSHUTDOWN_FUNCTION */
  254. PHP_RSHUTDOWN_FUNCTION(com_dotnet)
  255. {
  256. #if HAVE_MSCOREE_H
  257. if (COMG(dotnet_runtime_stuff)) {
  258. php_com_dotnet_rshutdown();
  259. }
  260. #endif
  261. COMG(rshutdown_started) = 1;
  262. return SUCCESS;
  263. }
  264. /* }}} */
  265. /* {{{ PHP_MINFO_FUNCTION */
  266. PHP_MINFO_FUNCTION(com_dotnet)
  267. {
  268. php_info_print_table_start();
  269. php_info_print_table_header(2, "COM support", "enabled");
  270. php_info_print_table_header(2, "DCOM support", COMG(allow_dcom) ? "enabled" : "disabled");
  271. #if HAVE_MSCOREE_H
  272. php_info_print_table_header(2, ".Net support", "enabled");
  273. #else
  274. php_info_print_table_header(2, ".Net support", "not present in this build");
  275. #endif
  276. php_info_print_table_end();
  277. DISPLAY_INI_ENTRIES();
  278. }
  279. /* }}} */