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