1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP 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.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Author: Wez Furlong <wez@thebrainroom.com>                           |
16    +----------------------------------------------------------------------+
17  */
18 
19 #ifndef PHP_COM_DOTNET_INTERNAL_H
20 #define PHP_COM_DOTNET_INTERNAL_H
21 
22 #define _WIN32_DCOM
23 #define COBJMACROS
24 #include <ocidl.h>
25 #include <oleauto.h>
26 #include <unknwn.h>
27 #include <dispex.h>
28 #include "win32/winutil.h"
29 
30 typedef struct _php_com_dotnet_object {
31 	zend_object zo;
32 
33 	VARIANT v;
34 	int modified;
35 
36 	int code_page;
37 
38 	ITypeInfo *typeinfo;
39 
40 	zend_class_entry *ce;
41 
42    	/* associated event sink */
43 	IDispatch *sink_dispatch;
44 	GUID sink_id;
45 	DWORD sink_cookie;
46 
47 	/* cache for method signatures */
48 	HashTable *method_cache;
49 	/* cache for name -> DISPID */
50 	HashTable *id_of_name_cache;
51 } php_com_dotnet_object;
52 
php_com_is_valid_object(zval * zv)53 static inline int php_com_is_valid_object(zval *zv)
54 {
55 	zend_class_entry *ce = Z_OBJCE_P(zv);
56 	return strcmp("com", ce->name->val) == 0 ||
57 		strcmp("dotnet", ce->name->val) == 0 ||
58 		strcmp("variant", ce->name->val) == 0;
59 }
60 
61 #define CDNO_FETCH(zv)			(php_com_dotnet_object*)Z_OBJ_P(zv)
62 #define CDNO_FETCH_VERIFY(obj, zv)	do { \
63 	if (!php_com_is_valid_object(zv)) { \
64 		php_com_throw_exception(E_UNEXPECTED, "expected a variant object"); \
65 		return; \
66 	} \
67 	obj = (php_com_dotnet_object*)Z_OBJ_P(zv); \
68 } while(0)
69 
70 /* com_extension.c */
71 zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_entry, *php_com_saproxy_class_entry;
72 
73 /* com_handlers.c */
74 zend_object* php_com_object_new(zend_class_entry *ce);
75 zend_object* php_com_object_clone(zval *object);
76 void php_com_object_free_storage(zend_object *object);
77 zend_object_handlers php_com_object_handlers;
78 void php_com_object_enable_event_sink(php_com_dotnet_object *obj, int enable);
79 
80 /* com_saproxy.c */
81 zend_object_iterator *php_com_saproxy_iter_get(zend_class_entry *ce, zval *object, int by_ref);
82 int php_com_saproxy_create(zval *com_object, zval *proxy_out, zval *index);
83 
84 /* com_olechar.c */
85 PHP_COM_DOTNET_API char *php_com_olestring_to_string(OLECHAR *olestring,
86 		size_t *string_len, int codepage);
87 PHP_COM_DOTNET_API OLECHAR *php_com_string_to_olestring(char *string,
88 		size_t string_len, int codepage);
89 BSTR php_com_string_to_bstr(zend_string *string, int codepage);
90 zend_string *php_com_bstr_to_string(BSTR bstr, int codepage);
91 
92 
93 /* com_com.c */
94 PHP_FUNCTION(com_create_instance);
95 PHP_FUNCTION(com_event_sink);
96 PHP_FUNCTION(com_create_guid);
97 PHP_FUNCTION(com_print_typeinfo);
98 PHP_FUNCTION(com_message_pump);
99 PHP_FUNCTION(com_load_typelib);
100 PHP_FUNCTION(com_get_active_object);
101 
102 HRESULT php_com_invoke_helper(php_com_dotnet_object *obj, DISPID id_member,
103 		WORD flags, DISPPARAMS *disp_params, VARIANT *v, int silent, int allow_noarg);
104 HRESULT php_com_get_id_of_name(php_com_dotnet_object *obj, char *name,
105 		size_t namelen, DISPID *dispid);
106 int php_com_do_invoke_by_id(php_com_dotnet_object *obj, DISPID dispid,
107 		WORD flags,	VARIANT *v, int nargs, zval *args, int silent, int allow_noarg);
108 int php_com_do_invoke(php_com_dotnet_object *obj, char *name, size_t namelen,
109 		WORD flags,	VARIANT *v, int nargs, zval *args, int allow_noarg);
110 int php_com_do_invoke_byref(php_com_dotnet_object *obj, zend_internal_function *f,
111 		WORD flags,	VARIANT *v, int nargs, zval *args);
112 
113 /* com_wrapper.c */
114 int php_com_wrapper_minit(INIT_FUNC_ARGS);
115 PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export_as_sink(zval *val, GUID *sinkid, HashTable *id_to_name);
116 PHP_COM_DOTNET_API IDispatch *php_com_wrapper_export(zval *val);
117 
118 /* com_persist.c */
119 int php_com_persist_minit(INIT_FUNC_ARGS);
120 
121 /* com_variant.c */
122 PHP_FUNCTION(com_variant_create_instance);
123 PHP_FUNCTION(variant_set);
124 PHP_FUNCTION(variant_add);
125 PHP_FUNCTION(variant_cat);
126 PHP_FUNCTION(variant_sub);
127 PHP_FUNCTION(variant_mul);
128 PHP_FUNCTION(variant_and);
129 PHP_FUNCTION(variant_div);
130 PHP_FUNCTION(variant_eqv);
131 PHP_FUNCTION(variant_idiv);
132 PHP_FUNCTION(variant_imp);
133 PHP_FUNCTION(variant_mod);
134 PHP_FUNCTION(variant_or);
135 PHP_FUNCTION(variant_pow);
136 PHP_FUNCTION(variant_xor);
137 PHP_FUNCTION(variant_abs);
138 PHP_FUNCTION(variant_fix);
139 PHP_FUNCTION(variant_int);
140 PHP_FUNCTION(variant_neg);
141 PHP_FUNCTION(variant_not);
142 PHP_FUNCTION(variant_round);
143 PHP_FUNCTION(variant_cmp);
144 PHP_FUNCTION(variant_date_to_timestamp);
145 PHP_FUNCTION(variant_date_from_timestamp);
146 PHP_FUNCTION(variant_get_type);
147 PHP_FUNCTION(variant_set_type);
148 PHP_FUNCTION(variant_cast);
149 
150 PHP_COM_DOTNET_API void php_com_variant_from_zval_with_type(VARIANT *v, zval *z, VARTYPE type, int codepage);
151 PHP_COM_DOTNET_API void php_com_variant_from_zval(VARIANT *v, zval *z, int codepage);
152 PHP_COM_DOTNET_API int php_com_zval_from_variant(zval *z, VARIANT *v, int codepage);
153 PHP_COM_DOTNET_API int php_com_copy_variant(VARIANT *dst, VARIANT *src);
154 
155 /* com_dotnet.c */
156 PHP_FUNCTION(com_dotnet_create_instance);
157 void php_com_dotnet_rshutdown(void);
158 void php_com_dotnet_mshutdown(void);
159 
160 /* com_misc.c */
161 void php_com_throw_exception(HRESULT code, char *message);
162 PHP_COM_DOTNET_API void php_com_wrap_dispatch(zval *z, IDispatch *disp,
163 		int codepage);
164 PHP_COM_DOTNET_API void php_com_wrap_variant(zval *z, VARIANT *v,
165 		int codepage);
166 PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest, LONG dim1);
167 
168 /* com_typeinfo.c */
169 PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib_via_cache(char *search_string,
170 		int codepage, int *cached);
171 PHP_COM_DOTNET_API ITypeLib *php_com_load_typelib(char *search_string, int codepage);
172 PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode,
173 		int codepage);
174 void php_com_typelibrary_dtor(zval *pDest);
175 ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj, char *dispname, int sink);
176 int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int printdef, GUID *guid, int codepage);
177 ITypeLib *php_com_cache_typelib(ITypeLib* TL, char *cache_key, zend_long cache_key_len);
178 PHP_MINIT_FUNCTION(com_typeinfo);
179 PHP_MSHUTDOWN_FUNCTION(com_typeinfo);
180 
181 /* com_iterator.c */
182 zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int by_ref);
183 
184 
185 #endif
186