diff options
Diffstat (limited to 'ext/rpc/com')
-rw-r--r-- | ext/rpc/com/CREDITS | 2 | ||||
-rw-r--r-- | ext/rpc/com/TODO | 28 | ||||
-rw-r--r-- | ext/rpc/com/com.c | 1360 | ||||
-rw-r--r-- | ext/rpc/com/com.dsp | 167 | ||||
-rw-r--r-- | ext/rpc/com/com.h | 43 | ||||
-rw-r--r-- | ext/rpc/com/com_wrapper.c | 930 | ||||
-rw-r--r-- | ext/rpc/com/com_wrapper.h | 107 | ||||
-rw-r--r-- | ext/rpc/com/conversion.c | 855 | ||||
-rw-r--r-- | ext/rpc/com/conversion.h | 42 | ||||
-rw-r--r-- | ext/rpc/com/dispatch.c | 632 | ||||
-rw-r--r-- | ext/rpc/com/php_com.h | 25 | ||||
-rw-r--r-- | ext/rpc/com/variant.c | 324 | ||||
-rw-r--r-- | ext/rpc/com/variant.h | 64 |
13 files changed, 0 insertions, 4579 deletions
diff --git a/ext/rpc/com/CREDITS b/ext/rpc/com/CREDITS deleted file mode 100644 index b713bdc50b..0000000000 --- a/ext/rpc/com/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Win32 COM -Alan Brown, Wez Furlong, Harald Radi, Zeev Suraski
\ No newline at end of file diff --git a/ext/rpc/com/TODO b/ext/rpc/com/TODO deleted file mode 100644 index 05ac41167a..0000000000 --- a/ext/rpc/com/TODO +++ /dev/null @@ -1,28 +0,0 @@ -1) Multi-dimenstional array support -4) Documentation (internal and user) and howtos -5) IEnumVariant::All() which would be like IEnumVariant::Next(IDispatch::Count) -7) Test component (goes with the docs) -8) Test suite (Needs test component) -10) lets try if we are able to call non IDispatch - only Typelib components - --- delayed till PHP5: 3) WithEvents --- delayed till PHP5: 9) reduce the need for VARIANT() - -ad 6.) check vbsample.php (new VARIANT(*, *|VT_BYREF)) GPs - --- done 2) IErrorInfo --- done 6) Look for memory leaks and AdRef/Release problems - I KNOW there are some... --- done 11) IEnumVariant::Next() without parameter should only return an object, not an array with one element --- done 12) VARIANT->value as lvalue --- done 13) export VARIANT through the COM module --- done 14) trap exceptions and errors - --- donne ad 4.) faq (i've collected a few questions from various lists) - variant attributes !! - -to be discussed: - -- mts support (getcontext) -- adsi support (ads* functions) - --- delayed till PHP 5: try serialisation support (if component implements IPersist) diff --git a/ext/rpc/com/com.c b/ext/rpc/com/com.c deleted file mode 100644 index 7e53392917..0000000000 --- a/ext/rpc/com/com.c +++ /dev/null @@ -1,1360 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - +----------------------------------------------------------------------+ - */ - -#define _WIN32_DCOM -#define COBJMACROS - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "../rpc.h" -#include "../handler.h" - -#include "com.h" -#include "com_wrapper.h" -#include "conversion.h" -#include "variant.h" -#include "ext/standard/php_smart_str.h" -#include <oleauto.h> -#include <ocidl.h> - - -static ZEND_FUNCTION(com_indexed_prop_set); -static ZEND_FUNCTION(com_create_guid); - -/* protos */ -static int com_hash(rpc_string, rpc_string *, void *, int, char *, int); -static int com_name(rpc_string, rpc_string *, void *, int); -static int com_ctor(rpc_string, void **, int , zval ***); -static int com_dtor(void *); -static int com_describe(rpc_string, void *, char **, unsigned char **); -static int com_call(rpc_string, void *, zval *, int, zval ***); -static int com_get(rpc_string, zval *, void *); -static int com_set(rpc_string, zval *, void *); -static int com_compare(void *, void *); -static int com_has_property(rpc_string, void *); -static int com_unset_property(rpc_string, void *); -static int com_get_properties(HashTable **, void *); - -static ZEND_INI_MH(com_typelib_file_change); - -/* globals */ -static IBindCtx *pBindCtx; -static unsigned char arg1and2_force_ref[] = { 2, BYREF_FORCE, BYREF_FORCE }; - -/* register rpc callback function */ -RPC_REGISTER_HANDLERS_BEGIN(com) -TRUE, /* poolable */ -HASH_AS_INT_WITH_SIGNATURE, -com_hash, -com_name, -com_ctor, -com_dtor, -com_describe, -com_call, -com_get, -com_set, -com_compare, -com_has_property, -com_unset_property, -com_get_properties -RPC_REGISTER_HANDLERS_END() - -/* register ini settings */ -PHP_INI_BEGIN() -PHP_INI_ENTRY_EX("com.allow_dcom", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb) -PHP_INI_ENTRY_EX("com.autoregister_typelib", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb) -PHP_INI_ENTRY_EX("com.autoregister_verbose", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb) -PHP_INI_ENTRY_EX("com.autoregister_casesensitive", "1", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb) -PHP_INI_ENTRY("com.typelib_file", "", PHP_INI_SYSTEM, com_typelib_file_change) -PHP_INI_END() - -/* register userspace functions */ -RPC_FUNCTION_ENTRY_BEGIN(com) - ZEND_FALIAS(com_invoke, rpc_call, NULL) - ZEND_FE(com_addref, NULL) - ZEND_FE(com_release, NULL) - ZEND_FE(com_next, NULL) - ZEND_FE(com_all, NULL) - ZEND_FE(com_reset, NULL) - ZEND_FE(com_skip, NULL) - ZEND_FE(com_event_sink, arg1and2_force_ref) - ZEND_FE(com_message_pump, NULL) - ZEND_FE(com_load_typelib, NULL) - ZEND_FE(com_print_typeinfo, NULL) - ZEND_FE(com_indexed_prop_set, NULL) - ZEND_FE(com_create_guid, NULL) -RPC_FUNCTION_ENTRY_END() - -zend_module_entry com_module_entry = { - ZE2_STANDARD_MODULE_HEADER, - "com", - RPC_FUNCTION_ENTRY(com), - ZEND_MINIT(com), - ZEND_MSHUTDOWN(com), - NULL, - NULL, - ZEND_MINFO(com), - "0.1a", - STANDARD_MODULE_PROPERTIES -}; - -/* register class methods */ -RPC_METHOD_ENTRY_BEGIN(com) - ZEND_FALIAS(addref, com_addref, NULL) - ZEND_FALIAS(release, com_release, NULL) - ZEND_FALIAS(next, com_next, NULL) - ZEND_FALIAS(all, com_all, NULL) - ZEND_FALIAS(reset, com_reset, NULL) - ZEND_FALIAS(skip, com_skip, NULL) -RPC_METHOD_ENTRY_END() - - -ZEND_MINIT_FUNCTION(com) -{ - CreateBindCtx(0, &pBindCtx); - php_variant_init(module_number TSRMLS_CC); - - RPC_REGISTER_LAYER(com); - REGISTER_INI_ENTRIES(); - - return SUCCESS; -} - -ZEND_MSHUTDOWN_FUNCTION(com) -{ - php_variant_shutdown(TSRMLS_C); - pBindCtx->lpVtbl->Release(pBindCtx); - - UNREGISTER_INI_ENTRIES(); - - return SUCCESS; -} - -ZEND_MINFO_FUNCTION(com) -{ - DISPLAY_INI_ENTRIES(); -} - -#ifdef COMPILE_DL_COM -ZEND_GET_MODULE(com); -#endif - -/* rpc handler functions */ - -static int com_hash(rpc_string name, rpc_string *hash, void *data, int num_args, char *arg_types, int type) -{ - switch (type) { - case CLASS: - { - CLSID *clsid = malloc(sizeof(CLSID)); - - /* if name is {NULL, 0} then the corresponding hash value has to be figured out - * of the *data struct. this might be not a trivial task. - */ - if (name.str) { - OLECHAR *olestr = php_char_to_OLECHAR(name.str, name.len, CP_ACP, FALSE); - - if (FAILED(CLSIDFromString(olestr, clsid))) { - /* Perhaps this is a Moniker? */ - free(clsid); - efree(olestr); - - hash->str = strdup(name.str); - hash->len = name.len; - - return SUCCESS; - } - - efree(olestr); - } else { - comval *obj = (comval *)data; - IProvideClassInfo2 *pci2; - - if (SUCCEEDED(C_DISPATCH_VT(obj)->QueryInterface(C_DISPATCH(obj), &IID_IProvideClassInfo2, (void**)&pci2))) { - if (FAILED(pci2->lpVtbl->GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, clsid))) { - free(clsid); - - return FAILURE; - } - pci2->lpVtbl->Release(pci2); - } else if (C_HASTLIB(obj)) { - TYPEATTR *typeattrib; - - if (FAILED(C_TYPEINFO_VT(obj)->GetTypeAttr(C_TYPEINFO(obj), &typeattrib))) { - free(clsid); - - return FAILURE; - } - - *clsid = (typeattrib->guid); - C_TYPEINFO_VT(obj)->ReleaseTypeAttr(C_TYPEINFO(obj), typeattrib); - } - } - - hash->str = (char *) clsid; - /* str is actually not a string but a CLSID struct, thus set len to 0. - * nevertheless clsid is freed by the rpc_string_dtor - */ - hash->len = 0; - - return SUCCESS; - } - - case METHOD: - case PROPERTY: - { - DISPID *dispid = malloc(sizeof(DISPID)); - OLECHAR *olestr = php_char_to_OLECHAR(name.str, name.len, CP_ACP, FALSE); - - if(SUCCEEDED(php_COM_get_ids_of_names((comval *) data, olestr, dispid))) { - hash->str = (char *) dispid; - /* str is actually not a string but a DISPID struct, thus set len to 0. - * nevertheless dispid is freed by the rpc_string_dtor - */ - hash->len = 0; - - efree(olestr); - - return SUCCESS; - } else { - free(dispid); - efree(olestr); - - return FAILURE; - } - } - } - - return FAILURE; -} - -static int com_name(rpc_string hash, rpc_string *name, void *data, int type) -{ - if (hash.len != 0) { - /* not a GUID, perhaps a Moniker */ - name->str = strdup(hash.str); - name->len = hash.len; - - return SUCCESS; - } else { - switch (type) { - case CLASS: - { - CLSID clsid; - OLECHAR *olestr; - - clsid = *((CLSID *) hash.str); - - ProgIDFromCLSID(&clsid, &olestr); - if (olestr == NULL) { - StringFromCLSID(&clsid, &olestr); - } - - if (olestr == NULL) { - return FAILURE; - } - - name->str = php_OLECHAR_to_char(olestr, &(name->len), CP_ACP, TRUE); - CoTaskMemFree(olestr); - - return SUCCESS; - } - - case METHOD: - case PROPERTY: - /* not used yet */ - break; - } - } - - return FAILURE; -} - -static int com_ctor(rpc_string class_name, void **data, int num_args, zval **args[]) -{ - zval **server_name = NULL; - zval **code_page = NULL; - zval **typelib = NULL; - zval **user_name=NULL; - zval **password=NULL; - zval **domain=NULL; - int mode = 0; - comval *obj; - HRESULT hr; - CLSCTX flags = CLSCTX_SERVER; - - switch (num_args) { - case 3: - typelib = args[2]; - convert_to_string_ex(typelib); - /* break missing intentionally */ - case 2: - code_page = args[1]; - convert_to_long_ex(code_page); - /* break missing intentionally */ - case 1: - server_name = args[0]; - /* break missing intentionally */ - break; - - case 0: - /* nothing to do */ - break; - - default: - /* exception */ - return FAILURE; - } - - if (server_name != NULL) { - /* What is server name? A String or an array? */ - if (Z_TYPE_PP(server_name) == IS_NULL) { - server_name = NULL; - } else if (Z_TYPE_PP(server_name) == IS_ARRAY) { - zval **tmp; - /* Aha - we have a number of possible arguments. - * They are in the hash By name: Server, Domain, Username, Password - * Flags. - * This has been crafted to maintian maximum backward compatability. - * If the server name is specified as a string, then the function - * should behave as before by defaulting username and password and - * using the (I believe) incorrect CLSCTX_SERVER instantiation - * paramter. However if server is specified in this array then we - * use either CLSCTX_REMOTE_SERVER or whatever flags are specified - * in the array - */ - HashTable *ht = Z_ARRVAL_PP(server_name); - if (FAILURE == zend_hash_find(ht, "Server", 7, (void **) &tmp)) { - server_name = NULL; - } else { - server_name = tmp; - convert_to_string_ex(server_name); - /* CLSCTX_SERVER includes INPROC and LOCAL SERVER. This means - * that any local server will be instantiated BEFORE even - * looking on a remote server. Thus if we have a server name, - * probably we want to access a remote machine or we would not - * have bothered specifying it. So it would be wrong to to - * connect locally. Futher, unless the name passed is a GUID, - * there has to be something to map the Prog.Id to GUID and - * unless that has been modified to remove the information - * about local instantiation CLSCTX_SERVER would force a local - * instantiation This setting can be overridden below if the - * user specifies a flags element */ - flags = CLSCTX_REMOTE_SERVER; - } - if (FAILURE == zend_hash_find(ht, "username", 9, (void **) &tmp)) { - user_name = NULL; - } else { - user_name = tmp; - convert_to_string_ex(user_name); - } - if (FAILURE == zend_hash_find(ht, "domain", 7, (void **) &tmp)) { - domain = NULL; - } else { - domain = tmp; - convert_to_string_ex(domain); - } - if (FAILURE == zend_hash_find(ht, "password", 9, (void **) &tmp)) { - password=NULL; - } else { - password = tmp; - convert_to_string_ex(password); - } - if (SUCCESS == zend_hash_find(ht, "flags", 6, (void **) &tmp)) { - convert_to_long_ex(tmp); - flags = (CLSCTX) Z_LVAL_PP(tmp); - } - } - - if (server_name != NULL) { - if (!INI_INT("com.allow_dcom")) { - rpc_error(E_WARNING, "DCOM is disabled"); - return FAILURE; - } else { - flags = CLSCTX_REMOTE_SERVER; - convert_to_string_ex(server_name); - } - } - } - - ALLOC_COM(obj); - *data = obj; - - if (code_page != NULL) { - C_CODEPAGE(obj) = Z_LVAL_PP(code_page); - } - - if (class_name.len) { - /* Perhaps this is a Moniker? */ - IMoniker *pMoniker; - ULONG ulEaten; - - if (server_name) { - hr = MK_E_SYNTAX; - } else { - OLECHAR *olestr = php_char_to_OLECHAR(class_name.str, class_name.len, C_CODEPAGE(obj), FALSE); - - if (SUCCEEDED(hr = MkParseDisplayNameEx(pBindCtx, olestr, &ulEaten, &pMoniker))) { - hr = pMoniker->lpVtbl->BindToObject(pMoniker, pBindCtx, NULL, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj)); - pMoniker->lpVtbl->Release(pMoniker); - } - - efree(olestr); - } - - if (FAILED(hr)) { - char *error_message; - - php_COM_destruct(obj); - error_message = php_COM_error_message(hr); - rpc_error(E_WARNING,"Invalid ProgID, GUID string, or Moniker: %s", error_message); - LocalFree(error_message); - - return FAILURE; - } - } else { - /* obtain IDispatch */ - if (!server_name) { - hr = CoCreateInstance((CLSID *) class_name.str, NULL, flags, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj)); - } else { - COSERVERINFO server_info; - MULTI_QI pResults; - COAUTHIDENTITY authid; - COAUTHINFO authinfo = {RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, &authid, EOAC_NONE}; - - server_info.dwReserved1=0; - server_info.dwReserved2=0; - server_info.pwszName = php_char_to_OLECHAR(Z_STRVAL_PP(server_name), Z_STRLEN_PP(server_name), C_CODEPAGE(obj), FALSE); - if (user_name) { - /* Parse Username into domain\username */ - authid.User = (WCHAR *) Z_STRVAL_PP(user_name); - authid.UserLength = Z_STRLEN_PP(user_name); - if (password) { - authid.Password = (USHORT *) Z_STRVAL_PP(password); - authid.PasswordLength = Z_STRLEN_PP(password); - } else { - authid.Password = (USHORT *) ""; - authid.PasswordLength = 0; - } - if (domain) { - authid.Domain = (USHORT *) Z_STRVAL_PP(domain); - authid.DomainLength = Z_STRLEN_PP(domain); - } else { - authid.Domain = (USHORT *) ""; - authid.DomainLength = 0; - } - authid.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI; - - server_info.pAuthInfo=&authinfo; - } else { - server_info.pAuthInfo=NULL; - } - - pResults.pIID = &IID_IDispatch; - pResults.pItf = NULL; - pResults.hr = S_OK; - hr=CoCreateInstanceEx((CLSID *) class_name.str, NULL, flags, &server_info, 1, &pResults); - if (SUCCEEDED(hr)) { - hr = pResults.hr; - C_DISPATCH(obj) = (IDispatch *) pResults.pItf; - } - efree(server_info.pwszName); - } - - if (FAILED(hr)) { - char *error_message, *clsid; - - php_COM_destruct(obj); - error_message = php_COM_error_message(hr); - clsid = php_COM_string_from_CLSID((CLSID *)class_name.str); - rpc_error(E_WARNING,"Unable to obtain IDispatch interface for CLSID %s: %s", clsid, error_message); - LocalFree(error_message); - efree(clsid); - - return FAILURE; - } - } - - php_COM_set(obj, &C_DISPATCH(obj), TRUE); - - if (INI_INT("com.autoregister_casesensitive")) { - mode |= CONST_CS; - } - - if (C_HASTLIB(obj)) { - if (INI_INT("com.autoregister_typelib")) { - ITypeLib *pTL; - unsigned int idx; - - /* @todo check if typlib isn't already loaded */ - if (C_TYPEINFO_VT(obj)->GetContainingTypeLib(C_TYPEINFO(obj), &pTL, &idx) == S_OK) { - php_COM_load_typelib(pTL, mode); - pTL->lpVtbl->Release(pTL); - } - } - } else { - if (typelib != NULL) { - ITypeLib *pTL; - - if ((pTL = php_COM_find_typelib(Z_STRVAL_PP(typelib), mode)) != NULL) { - C_HASTLIB(obj) = SUCCEEDED(pTL->lpVtbl->GetTypeInfo(pTL, 0, &C_TYPEINFO(obj))); - /* idx 0 should deliver the ITypeInfo for the IDispatch Interface */ - if (INI_INT("com.autoregister_typelib")) { - php_COM_load_typelib(pTL, mode); - } - pTL->lpVtbl->Release(pTL); - } - } - } - - return SUCCESS; -} - -static int com_dtor(void *data) -{ - php_COM_destruct((comval *) data); - - return SUCCESS; -} - -static inline void vt_type_to_zpp_string(ELEMDESC *elem, smart_str *argtypes_str, unsigned char *argflags) -{ - int ref = 0; - int nullable = 0; - char zppflag = 'z'; - WORD vt, flags; - - vt = elem->tdesc.vt; - flags = elem->paramdesc.wParamFlags; - - if (vt == VT_PTR) { - nullable = 1; - ref = 0; - vt = elem->tdesc.lptdesc->vt; - } else { - ref = vt & VT_BYREF; - } - - if (vt & VT_ARRAY) { - zppflag = 'a'; - } else { - switch(vt & ~(VT_BYREF | VT_ARRAY)) { - case VT_UI1: - case VT_UI2: - case VT_UI4: - case VT_I1: - case VT_I2: - case VT_I4: - zppflag = 'l'; - break; - - case VT_R8: - case VT_CY: - case VT_DATE: - zppflag = 'd'; - break; - - case VT_BSTR: - zppflag = 's'; - break; - - case VT_BOOL: - zppflag = 'b'; - break; - - case VT_DISPATCH: - case VT_UNKNOWN: - zppflag = 'o'; - break; - - case VT_VARIANT: - default: - zppflag = 'z'; - - } - } - - if (ref) { - smart_str_appendl(argtypes_str, "z/", 2); - *argflags = BYREF_FORCE; - } else { - *argflags = BYREF_NONE; - if (nullable) { - smart_str_appendl(argtypes_str, "!", 1); - } - } -} - -static int com_describe(rpc_string method_name, void *data, char **arg_types, unsigned char **ref_types) -{ - rpc_internal *intern; - comval *obj; - ITypeInfo *typeinfo; - FUNCDESC *funcdesc; - MEMBERID fid; - OLECHAR *olename; - int retval = FAILURE, arg_count; - int i, type_len = 0; - smart_str argtypes_str = {0}; - unsigned char *func_arg_types; - TSRMLS_FETCH(); - - GET_INTERNAL_EX(intern, data); - obj = (comval*)data; - - if (!C_HASTLIB(obj)) { - return FAILURE; - } - - olename = php_char_to_OLECHAR(method_name.str, method_name.len, CP_ACP, FALSE); - typeinfo = C_TYPEINFO(obj); - - if (SUCCEEDED(ITypeInfo_GetIDsOfNames(typeinfo, &olename, 1, &fid)) && SUCCEEDED(ITypeInfo_GetFuncDesc(typeinfo, fid, &funcdesc))) { - - arg_count = funcdesc->cParams + (funcdesc->cParamsOpt == -1 ? 1 : funcdesc->cParamsOpt); - - func_arg_types = (unsigned char*)malloc((1 + arg_count) * sizeof(unsigned char)); - - func_arg_types[0] = arg_count; - - /* required parameters first */ - for (i = 0; i < funcdesc->cParams; i++) { - ELEMDESC *elem = &funcdesc->lprgelemdescParam[i]; - - vt_type_to_zpp_string(elem, &argtypes_str, &func_arg_types[i+1]); - } - - if (funcdesc->cParamsOpt == -1) { - /* needs to be a SAFEARRAY of VARIANTS */ - smart_str_appendl(&argtypes_str, "|z", 2); - func_arg_types[funcdesc->cParams+1] = BYREF_NONE; - } else if (funcdesc->cParamsOpt > 0) { - smart_str_appendl(&argtypes_str, "|", 1); - - for (i = funcdesc->cParams; i < funcdesc->cParams + funcdesc->cParamsOpt; i++) { - ELEMDESC *elem = &funcdesc->lprgelemdescParam[i]; - - vt_type_to_zpp_string(elem, &argtypes_str, &func_arg_types[i+1]); - } - } - - *ref_types = func_arg_types; - smart_str_0(&argtypes_str); - *arg_types = strdup(argtypes_str.c); - smart_str_free(&argtypes_str); - - retval = SUCCESS; - ITypeInfo_ReleaseFuncDesc(typeinfo, funcdesc); - } - - efree(olename); - - return retval; -} - -static int com_call(rpc_string method_name, void *data, zval *return_value, int num_args, zval **args[]) -{ - DISPPARAMS dispparams; - HRESULT hr; - OLECHAR *funcname = NULL; - VARIANT *variant_args; - VARIANT result; - int current_arg, current_variant; - char *ErrString = NULL; - - /* if the length of the name is 0, we are dealing with a pointer to a dispid */ - assert(method_name.len == 0); - - variant_args = num_args ? (VARIANT *) emalloc(sizeof(VARIANT) * num_args) : NULL; - - for (current_arg = 0; current_arg < num_args; current_arg++) { - current_variant = num_args - current_arg - 1; - php_zval_to_variant(*args[current_arg], &variant_args[current_variant], C_CODEPAGE((comval *) data)); - } - - dispparams.rgvarg = variant_args; - dispparams.rgdispidNamedArgs = NULL; - dispparams.cArgs = num_args; - dispparams.cNamedArgs = 0; - - VariantInit(&result); - - hr = php_COM_invoke((comval *) data, *(DISPID*)method_name.str, DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dispparams, &result, &ErrString); - - for (current_arg=0;current_arg<num_args;current_arg++) { - /* don't release IDispatch pointers as they are used afterwards */ - if (V_VT(&variant_args[current_arg]) != VT_DISPATCH) { - /* @todo review this: what happens to an array of IDispatchs or a VARIANT->IDispatch */ - VariantClear(&variant_args[current_arg]); - } - } - - if (variant_args) { - efree(variant_args); - variant_args = NULL; - } - - if (FAILED(hr)) { - char *error_message; - - error_message = php_COM_error_message(hr); - if (ErrString) { - rpc_error(E_WARNING,"Invoke() failed: %s %s", error_message, ErrString); - efree(ErrString); - } else { - rpc_error(E_WARNING,"Invoke() failed: %s", error_message); - } - LocalFree(error_message); - return FAILURE; - } - - RETVAL_VARIANT(&result, C_CODEPAGE((comval *) data)); - - return SUCCESS; -} - -static int com_get(rpc_string property_name, zval *return_value, void *data) -{ - char *ErrString = NULL; - VARIANT *result; - DISPPARAMS dispparams; - HRESULT hr; - - result = (VARIANT *) emalloc(sizeof(VARIANT)); - VariantInit(result); - - dispparams.cArgs = 0; - dispparams.cNamedArgs = 0; - - if (FAILED(hr = php_COM_invoke((comval *) data, *((DISPID *) property_name.str), DISPATCH_PROPERTYGET, &dispparams, result, &ErrString))) { - char *error_message; - - efree(result); - error_message = php_COM_error_message(hr); - if (ErrString != NULL) { - rpc_error(E_WARNING,"PropGet() failed: %s %s", error_message, ErrString); - efree(ErrString); - } else { - rpc_error(E_WARNING,"PropGet() failed: %s", error_message); - } - LocalFree(error_message); - - return FAILURE; - } - - if (V_VT(result) == VT_DISPATCH) { - RETVAL_VARIANT(result, C_CODEPAGE((comval *) data)); - } else { - comval *foo = (comval *) data; - php_variant_to_zval(result, return_value, C_CODEPAGE(foo)); - VariantClear(result); - } - - efree(result); - - return SUCCESS; -} - -static int com_set(rpc_string property_name, zval *value, void *data) -{ - HRESULT hr; - DISPID mydispid = DISPID_PROPERTYPUT; - DISPPARAMS dispparams; - VARIANT *var; - char *error_message, *ErrString = NULL; - - var = (VARIANT *) emalloc(sizeof(VARIANT)); - VariantInit(var); - - php_zval_to_variant(value, var, C_CODEPAGE((comval *) data)); - dispparams.rgvarg = var; - dispparams.rgdispidNamedArgs = &mydispid; - dispparams.cArgs = 1; - dispparams.cNamedArgs = 1; - - if (FAILED(hr = php_COM_invoke((comval *) data, *(DISPID*)property_name.str, DISPATCH_PROPERTYPUT, &dispparams, NULL, &ErrString))) { - error_message = php_COM_error_message(hr); - if (ErrString) { - rpc_error(E_WARNING,"PropPut() failed: %s %s", error_message, ErrString); - efree(ErrString); - } else { - rpc_error(E_WARNING,"PropPut() failed: %s", error_message); - } - LocalFree(error_message); - VariantClear(var); - efree(var); - - return FAILURE; - } - - - VariantClear(var); - efree(var); - - return SUCCESS; -} - -static int com_compare(void *data1, void *data2) -{ - return SUCCESS; -} - -static int com_has_property(rpc_string property_name, void *data) -{ - return SUCCESS; -} - -static int com_unset_property(rpc_string property_name, void *data) -{ - return SUCCESS; -} - -static int com_get_properties(HashTable **properties, void *data) -{ - return SUCCESS; -} - - -/* custom functions */ - -static ZEND_FUNCTION(com_create_guid) -{ - GUID retval; - OLECHAR *guid_string; - - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (CoCreateGuid(&retval) == S_OK && StringFromCLSID(&retval, &guid_string) == S_OK) { - Z_TYPE_P(return_value) = IS_STRING; - Z_STRVAL_P(return_value) = php_OLECHAR_to_char(guid_string, &Z_STRLEN_P(return_value), CP_ACP, 0); - - CoTaskMemFree(guid_string); - } else { - RETURN_FALSE; - } -} - - - -static ZEND_FUNCTION(com_indexed_prop_set) -{ - zval *object; - rpc_internal *intern; - char *propname; - long propname_len; - zval **arguments; - int arg_count = ZEND_NUM_ARGS(); - DISPPARAMS dispparams; - DISPID dispid, altdispid; - VARIANT *variant_args; - VARIANT result; - int current_arg, current_variant; - char *ErrString = NULL; - OLECHAR *olestr; - - if (zend_parse_method_parameters(2 TSRMLS_CC, getThis(), "Os", &object, com_class_entry, - &propname, &propname_len) != SUCCESS) { - return; - } - - if (ZEND_NUM_ARGS() < 3) { - ZEND_WRONG_PARAM_COUNT(); - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - arguments = (zval **) emalloc(sizeof(zval *) * ZEND_NUM_ARGS()); - if (zend_get_parameters_array(ht, arg_count, arguments) == FAILURE) { - RETURN_NULL(); - } - - olestr = php_char_to_OLECHAR(propname, propname_len, CP_ACP, FALSE); - - if (FAILED(php_COM_get_ids_of_names((comval *) intern->data, olestr, &dispid))) { - RETURN_NULL(); - } - variant_args = (VARIANT *) emalloc(sizeof(VARIANT) * (arg_count - 2)); - - for (current_arg = 2; current_arg < arg_count; current_arg++) { - current_variant = arg_count - current_arg - 1; - php_zval_to_variant(arguments[current_arg], &variant_args[current_variant], - C_CODEPAGE((comval *)intern->data)); - } - - dispparams.rgvarg = variant_args; - dispparams.rgdispidNamedArgs = NULL; - dispparams.cArgs = arg_count - 2; - dispparams.cNamedArgs = 0; - altdispid = DISPID_PROPERTYPUT; - dispparams.rgdispidNamedArgs = &altdispid; - dispparams.cNamedArgs = 1; - - VariantInit(&result); - - if (php_COM_invoke((comval*)intern->data, dispid, DISPATCH_PROPERTYPUT, &dispparams, &result, &ErrString)==FAILURE) { - VariantClear(&result); - RETVAL_NULL(); - } else { - RETVAL_VARIANT(&result, C_CODEPAGE((comval*)intern->data)); - } - - efree(variant_args); - efree(arguments); - efree(olestr); - -} - -/* {{{ proto mixed com_addref(int module) - Increases the reference counter on a COM object */ -ZEND_FUNCTION(com_addref) -{ - zval *object; - rpc_internal *intern; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, com_class_entry) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - RETURN_LONG(php_COM_addref((comval *) intern->data)); -} -/* }}} */ - -/* {{{ proto mixed com_release(int module) - Releases a COM object */ -ZEND_FUNCTION(com_release) -{ - zval *object; - rpc_internal *intern; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, com_class_entry) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - RETURN_LONG(php_COM_release((comval *) intern->data)); -} -/* }}} */ - -ZEND_FUNCTION(com_next) -{ - zval *object; - rpc_internal *intern; - comval *obj; - unsigned long count = 1; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &object, com_class_entry, &count) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - - if (C_HASENUM(obj)) { - SAFEARRAY *pSA; - SAFEARRAYBOUND rgsabound[1]; - VARIANT *result; - HRESULT hr; - - /* Grab one argument off the stack, allocate enough - * VARIANTs - * Get the IEnumVariant interface and call ->Next(); - */ - - rgsabound[0].lLbound = 0; - rgsabound[0].cElements = count; - - result = (VARIANT *) emalloc(sizeof(VARIANT)); - VariantInit(result); - - if ((pSA = SafeArrayCreate(VT_VARIANT, 1, rgsabound)) == NULL) { - efree(result); - /* @todo exception */ - - RETURN_NULL(); - } else { - V_ARRAY(result) = pSA; - V_VT(result) = VT_VARIANT|VT_ARRAY; - } - - if (FAILED(hr = C_ENUMVARIANT_VT(obj)->Next(C_ENUMVARIANT(obj), count, pSA->pvData, &count))) { - char *error_message; - - efree(result); - error_message = php_COM_error_message(hr); - rpc_error(E_WARNING,"IEnumVariant::Next() failed: %s", error_message); - efree(error_message); - - RETURN_NULL(); - } - - if (count != rgsabound[0].cElements) { - rgsabound[0].cElements = count; - if (FAILED(SafeArrayRedim(pSA, rgsabound))) { - char *error_message; - - efree(result); - error_message = php_COM_error_message(hr); - rpc_error(E_WARNING,"IEnumVariant::Next() failed: %s", error_message); - efree(error_message); - - RETURN_NULL(); - } - } - - /* return a single element if next() was called without count */ - if ((ZEND_NUM_ARGS() == 0) && (count == 1)) { - long index[] = {0}; - - SafeArrayGetElement(pSA, index, result); - SafeArrayDestroy(pSA); - } - - RETURN_VARIANT(result, C_CODEPAGE(obj)); - } - - /* @todo exception */ - RETURN_NULL(); -} - -ZEND_FUNCTION(com_all) -{ -#if 0 - } else if (C_HASENUM(obj) && strstr(Z_STRVAL_P(function_name), "all")) { -#define FETCH_BLOCKSIZE 10 /* fetch blocks of 10 elements */ - - count = FETCH_BLOCKSIZE; - - rgsabound[0].lLbound = 0; - rgsabound[0].cElements = count; - - if ((pSA = SafeArrayCreate(VT_VARIANT, 1, rgsabound)) == NULL) { - VariantInit(var_result); - return FAILURE; - } else { - V_ARRAY(var_result) = pSA; - V_VT(var_result) = VT_VARIANT|VT_ARRAY; - } - - /* blah*/ -#endif -} - -ZEND_FUNCTION(com_reset) -{ - zval *object; - rpc_internal *intern; - comval *obj; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, com_class_entry) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - - if (C_HASENUM(obj)) { - HRESULT hr; - - if (FAILED(hr = C_ENUMVARIANT_VT(obj)->Reset(C_ENUMVARIANT(obj)))) { - char *error_message = php_COM_error_message(hr); - rpc_error(E_WARNING,"IEnumVariant::Next() failed: %s", error_message); - efree(error_message); - - RETURN_FALSE; - } - - RETURN_TRUE; - } - - /* @todo exception */ - RETURN_FALSE; -} - -ZEND_FUNCTION(com_skip) -{ - zval *object; - rpc_internal *intern; - comval *obj; - unsigned long count = 1; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &object, com_class_entry, &count) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - - if (C_HASENUM(obj)) { - HRESULT hr; - - if (FAILED(hr = C_ENUMVARIANT_VT(obj)->Skip(C_ENUMVARIANT(obj), count))) { - char *error_message = php_COM_error_message(hr); - rpc_error(E_WARNING,"IEnumVariant::Next() failed: %s", error_message); - efree(error_message); - RETURN_FALSE; - } - - RETURN_TRUE; - } - - /* @todo exception */ - RETURN_FALSE; -} - -/* {{{ proto bool com_isenum(object com_module) - Grabs an IEnumVariant */ -ZEND_FUNCTION(com_isenum) -{ - zval *object; - rpc_internal *intern; - - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, com_class_entry) != SUCCESS) { - return; - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - RETURN_BOOL(C_HASENUM((comval *) intern->data)); -} -/* }}} */ - -/* {{{ proto bool com_load_typelib(string typelib_name [, int case_insensitive]) - Loads a Typelib */ -ZEND_FUNCTION(com_load_typelib) -{ - char *typelib; - int len, cis = FALSE; - int mode = CONST_CS; - ITypeLib *pTL; - - zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &typelib, &len, &cis); - - if (cis) { - mode &= ~CONST_CS; - } - - pTL = php_COM_find_typelib(typelib, mode); - if (php_COM_load_typelib(pTL, mode) == SUCCESS) { - pTL->lpVtbl->Release(pTL); - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool com_print_typeinfo(mixed comobject | string typelib, string dispinterface, bool wantsink) - Print out a PHP class definition for a dispatchable interface */ -ZEND_FUNCTION(com_print_typeinfo) -{ - zval *object; - char *ifacename = NULL; - char *typelibname = NULL; - int typeliblen, ifacelen; - zend_bool wantsink = 0; - comval *obj = NULL; - rpc_internal *intern; - ITypeInfo *typeinfo; - - if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s/s!b", - &typelibname, &typeliblen, &ifacename, &ifacelen, &wantsink)) { - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O/s!b", - &object, com_class_entry, &ifacename, &ifacelen, &wantsink)) { - RETURN_FALSE; - } else { - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - } - } - - typeinfo = php_COM_locate_typeinfo(typelibname, obj, ifacename, wantsink); - if (typeinfo) { - php_COM_process_typeinfo(typeinfo, NULL, 1, NULL); - typeinfo->lpVtbl->Release(typeinfo); - - RETURN_TRUE; - } else { - rpc_error(E_WARNING, "Unable to find typeinfo using the parameters supplied"); - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool com_event_sink(mixed comobject, object sinkobject [, mixed sinkinterface]) - Connect events from a COM object to a PHP object */ -ZEND_FUNCTION(com_event_sink) -{ - zval *object, *sinkobject, *sink=NULL; - char *dispname = NULL, *typelibname = NULL; - zend_bool gotguid = 0; - comval *obj; - rpc_internal *intern; - ITypeInfo *typeinfo = NULL; - - RETVAL_FALSE; - - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oz|z/", &object, com_class_entry, &sinkobject, &sink)) { - RETURN_FALSE; - } - - if (sink && Z_TYPE_P(sink) == IS_ARRAY) { - /* 0 => typelibname, 1 => dispname */ - zval **tmp; - - if (zend_hash_index_find(Z_ARRVAL_P(sink), 0, (void**)&tmp) == SUCCESS) - typelibname = Z_STRVAL_PP(tmp); - if (zend_hash_index_find(Z_ARRVAL_P(sink), 1, (void**)&tmp) == SUCCESS) - dispname = Z_STRVAL_PP(tmp); - } else if (sink != NULL) { - convert_to_string_ex(&sink); - dispname = Z_STRVAL_P(sink); - } - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - - typeinfo = php_COM_locate_typeinfo(typelibname, obj, dispname, 1); - - if (typeinfo) { - HashTable *id_to_name; - - ALLOC_HASHTABLE(id_to_name); - - if (php_COM_process_typeinfo(typeinfo, id_to_name, 0, &obj->sinkid)) { - - /* Create the COM wrapper for this sink */ - obj->sinkdispatch = php_COM_export_as_sink(sinkobject, &obj->sinkid, id_to_name); - - /* Now hook it up to the source */ - php_COM_enable_events(obj, TRUE); - - RETVAL_TRUE; - - } else { - FREE_HASHTABLE(id_to_name); - } - } - - if (typeinfo) - typeinfo->lpVtbl->Release(typeinfo); - -} -/* }}} */ - - - -/* ini callbacks */ - -static ZEND_INI_MH(com_typelib_file_change) -{ - FILE *typelib_file; - char *typelib_name_buffer; - char *strtok_buf = NULL; - int interactive; - interactive = CG(interactive); - - if (!new_value || (typelib_file = VCWD_FOPEN(new_value, "r"))==NULL) { - return FAILURE; - } - - if (interactive) { - printf("Loading type libraries..."); - fflush(stdout); - } - - typelib_name_buffer = (char *) emalloc(sizeof(char)*1024); - - while (fgets(typelib_name_buffer, 1024, typelib_file)) { - ITypeLib *pTL; - char *typelib_name; - char *modifier, *ptr; - int mode = CONST_CS | CONST_PERSISTENT; /* CONST_PERSISTENT is ok here */ - - if (typelib_name_buffer[0]==';') { - continue; - } - typelib_name = php_strtok_r(typelib_name_buffer, "\r\n", &strtok_buf); /* get rid of newlines */ - if (typelib_name == NULL) { - continue; - } - typelib_name = php_strtok_r(typelib_name, "#", &strtok_buf); - modifier = php_strtok_r(NULL, "#", &strtok_buf); - if (modifier != NULL) { - if (!strcmp(modifier, "cis") || !strcmp(modifier, "case_insensitive")) { - mode &= ~CONST_CS; - } - } - - /* Remove leading/training white spaces on search_string */ - while (isspace(*typelib_name)) {/* Ends on '\0' in worst case */ - typelib_name ++; - } - ptr = typelib_name + strlen(typelib_name) - 1; - while ((ptr != typelib_name) && isspace(*ptr)) { - *ptr = '\0'; - ptr--; - } - - if (interactive) { - printf("\rLoading %-60s\r", typelib_name); - } - - if ((pTL = php_COM_find_typelib(typelib_name, mode)) != NULL) { - php_COM_load_typelib(pTL, mode); - pTL->lpVtbl->Release(pTL); - } - } - - efree(typelib_name_buffer); - fclose(typelib_file); - - if (interactive) { - printf("\r%70s\r", ""); - } - - return SUCCESS; -}
\ No newline at end of file diff --git a/ext/rpc/com/com.dsp b/ext/rpc/com/com.dsp deleted file mode 100644 index ae933eecc7..0000000000 --- a/ext/rpc/com/com.dsp +++ /dev/null @@ -1,167 +0,0 @@ -# Microsoft Developer Studio Project File - Name="com" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=com - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "com.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "com.mak" CFG="com - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "com - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "com - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "com - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "com - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "com - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "..\..\Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_JAVA" /D HAVE_JAVA=1 /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release/php_rpc_com.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release"
-
-!ELSEIF "$(CFG)" == "com - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "..\..\Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_JAVA" /D HAVE_JAVA=1 /FR /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug/php_rpc_com.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug"
-
-!ELSEIF "$(CFG)" == "com - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "..\..\Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_JAVA" /FR /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\\" /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FR /YX /FD /D /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts_debug.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_rpc_com.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "com - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "..\..\Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_JAVA" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\\" /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /D "PHP_WIN32" /D "ZEND_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_rpc_com.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "com - Win32 Release"
-# Name "com - Win32 Debug"
-# Name "com - Win32 Debug_TS"
-# Name "com - Win32 Release_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\com.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_com.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\README
-# End Source File
-# End Target
-# End Project
diff --git a/ext/rpc/com/com.h b/ext/rpc/com/com.h deleted file mode 100644 index 68eb58ce00..0000000000 --- a/ext/rpc/com/com.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - +----------------------------------------------------------------------+ - */ - -#ifndef COM_H -#define COM_H - -#include "../handler.h" -#include "../php_rpc.h" - -RPC_DECLARE_HANDLER(com); - -ZEND_MINIT_FUNCTION(com); -ZEND_MSHUTDOWN_FUNCTION(com); -ZEND_MINFO_FUNCTION(com); - -ZEND_FUNCTION(com_addref); -ZEND_FUNCTION(com_release); -ZEND_FUNCTION(com_isenum); -ZEND_FUNCTION(com_next); -ZEND_FUNCTION(com_all); -ZEND_FUNCTION(com_reset); -ZEND_FUNCTION(com_skip); -ZEND_FUNCTION(com_event_sink); -ZEND_FUNCTION(com_message_pump); -ZEND_FUNCTION(com_load_typelib); -ZEND_FUNCTION(com_print_typeinfo); - -#endif
\ No newline at end of file diff --git a/ext/rpc/com/com_wrapper.c b/ext/rpc/com/com_wrapper.c deleted file mode 100644 index 04e9a74f08..0000000000 --- a/ext/rpc/com/com_wrapper.c +++ /dev/null @@ -1,930 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - | Harald Radi <h.radi@nme.at> | - | Alan Brown <abrown@pobox.com> | - | Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ -/* - * This module implements support for COM components that support the IDispatch - * interface. Both local (COM) and remote (DCOM) components can be accessed. - * - * Type libraries can be loaded (in order for PHP to recognize automation constants) - * by specifying a typelib_file in the PHP .ini file. That file should contain - * paths to type libraries, one in every line. By default, constants are registered - * as case-sensitive. If you want them to be defined as case-insensitive, add - * #case_insensitive or #cis at the end of the type library path. - * - * This is also the first module to demonstrate Zend's OO syntax overloading - * capabilities. CORBA coders are invited to write a CORBA module as well! - * - * Zeev - */ - -/* - * 28.12.2000 - * unicode conversion fixed by Harald Radi <h.radi@nme.at> - * - * now all these strange '?'s should be disapeared - */ - -/* - * 28.1.2001 - * VARIANT datatype and pass_by_reference support - */ - -/* - * 03.6.2001 - * Enhanced Typelib support to include a search by name - */ - -#ifdef PHP_WIN32 - -#define _WIN32_DCOM - -#include "php.h" -#include "php_ini.h" - -#include <iostream.h> -#include <math.h> -#include <ocidl.h> - -#include "../rpc.h" -#include "../php_rpc.h" -#include "../handler.h" - -#include "com.h" -#include "com_wrapper.h" -#include "conversion.h" -#include "variant.h" - -#ifdef _DEBUG -int resourcecounter = 1; -#endif - -ZEND_API HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, - DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, char **ErrString) -{ - HRESULT hr; - int failed = FALSE; - unsigned int ArgErr = 0; - EXCEPINFO ExceptInfo; - - *ErrString = NULL; - /* @todo use DispInvoke here ? */ - if (C_HASTLIB(obj)) { - hr = C_TYPEINFO_VT(obj)->Invoke(C_TYPEINFO(obj), C_DISPATCH(obj), - dispIdMember, wFlags, pDispParams, pVarResult, &ExceptInfo, &ArgErr); - if (FAILED(hr)) { - hr = C_DISPATCH_VT(obj)->Invoke(C_DISPATCH(obj), dispIdMember, &IID_NULL, - LOCALE_SYSTEM_DEFAULT, wFlags, pDispParams, pVarResult, &ExceptInfo, &ArgErr); - if (SUCCEEDED(hr)) { - /* - * ITypLib doesn't work - * Release ITypeLib and fall back to IDispatch - */ - - C_TYPEINFO_VT(obj)->Release(C_TYPEINFO(obj)); - C_HASTLIB(obj) = FALSE; - } - } - } else { - hr = C_DISPATCH_VT(obj)->Invoke(C_DISPATCH(obj), dispIdMember, &IID_NULL, - LOCALE_SYSTEM_DEFAULT, wFlags, pDispParams, pVarResult, &ExceptInfo, &ArgErr); - } - - if (FAILED(hr)) { - switch (hr) { - case DISP_E_EXCEPTION: { - - char *src=estrdup("Unavailable"); - int srclen=strlen(src); - char *desc=estrdup("Unavailable"); - int desclen=strlen(desc); - - if (ExceptInfo.bstrSource) - { - efree(src); - src = php_OLECHAR_to_char(ExceptInfo.bstrSource, &srclen, C_CODEPAGE(obj), FALSE); - SysFreeString(ExceptInfo.bstrSource); - } - if (ExceptInfo.bstrDescription) - { - efree(desc); - desc = php_OLECHAR_to_char(ExceptInfo.bstrDescription, &desclen, C_CODEPAGE(obj), FALSE); - SysFreeString(ExceptInfo.bstrDescription); - } - - spprintf(ErrString, 0, "<b>Source</b>: %s <b>Description</b>: %s", src, desc); - efree(src); - efree(desc); - - if (ExceptInfo.bstrHelpFile) - { - SysFreeString(ExceptInfo.bstrHelpFile); - } - } - break; - case DISP_E_PARAMNOTFOUND: - case DISP_E_TYPEMISMATCH: - spprintf(ErrString, 0, "<b>Argument</b>: %d", pDispParams->cArgs - ArgErr); - break; - } - } - - if (pVarResult && (V_VT(pVarResult) == VT_EMPTY)) { - V_VT(pVarResult) = VT_I4; - V_I4(pVarResult) = hr; - } - - return hr; -} - - -ZEND_API HRESULT php_COM_get_ids_of_names(comval *obj, OLECHAR FAR* rgszNames, DISPID FAR* rgDispId) -{ - HRESULT hr; - - if (C_HASTLIB(obj)) { - hr = C_TYPEINFO_VT(obj)->GetIDsOfNames(C_TYPEINFO(obj), &rgszNames, 1, rgDispId); - - if (FAILED(hr)) { - hr = C_DISPATCH_VT(obj)->GetIDsOfNames(C_DISPATCH(obj), &IID_NULL, &rgszNames, 1, LOCALE_SYSTEM_DEFAULT, rgDispId); - - if (SUCCEEDED(hr)) { - /* - * ITypLib doesn't work - * Release ITypeLib and fall back to IDispatch - */ - - C_TYPEINFO_VT(obj)->Release(C_TYPEINFO(obj)); - C_HASTLIB(obj) = FALSE; - } - } - } else { - hr = C_DISPATCH_VT(obj)->GetIDsOfNames(C_DISPATCH(obj), &IID_NULL, &rgszNames, 1, LOCALE_SYSTEM_DEFAULT, rgDispId); - } - - return hr; -} - - -ZEND_API HRESULT php_COM_release(comval *obj) -{ - return C_DISPATCH_VT(obj)->Release(C_DISPATCH(obj)); -} - - -ZEND_API HRESULT php_COM_addref(comval *obj) -{ - return C_DISPATCH_VT(obj)->AddRef(C_DISPATCH(obj)); -} - - -ZEND_API HRESULT php_COM_set(comval *obj, IDispatch FAR* FAR* ppDisp, int cleanup) -{ - HRESULT hr = 1; - DISPPARAMS dispparams; - VARIANT *result; - IDispatch FAR* pDisp; - - pDisp = *ppDisp; - if (cleanup) { - *ppDisp = NULL; - } - - C_DISPATCH(obj) = pDisp; - C_HASTLIB(obj) = SUCCEEDED(C_DISPATCH_VT(obj)->GetTypeInfo(C_DISPATCH(obj), 0, LANG_NEUTRAL, &C_TYPEINFO(obj))); - - dispparams.rgvarg = NULL; - dispparams.rgdispidNamedArgs = NULL; - dispparams.cArgs = 0; - dispparams.cNamedArgs = 0; - - result = (VARIANT *) emalloc(sizeof(VARIANT)); - VariantInit(result); - - if (C_HASENUM(obj) = SUCCEEDED(C_DISPATCH_VT(obj)->Invoke(C_DISPATCH(obj), DISPID_NEWENUM, &IID_NULL, LOCALE_SYSTEM_DEFAULT, - DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dispparams, result, NULL, NULL))) { - if (V_VT(result) == VT_UNKNOWN) { - V_UNKNOWN(result)->lpVtbl->AddRef(V_UNKNOWN(result)); - C_HASENUM(obj) = SUCCEEDED(V_UNKNOWN(result)->lpVtbl->QueryInterface(V_UNKNOWN(result), &IID_IEnumVARIANT, - (void**)&C_ENUMVARIANT(obj))); - } else if (V_VT(result) == VT_DISPATCH) { - V_DISPATCH(result)->lpVtbl->AddRef(V_DISPATCH(result)); - C_HASENUM(obj) = SUCCEEDED(V_DISPATCH(result)->lpVtbl->QueryInterface(V_DISPATCH(result), &IID_IEnumVARIANT, - (void**)&C_ENUMVARIANT(obj))); - } - } - - efree(result); - - if (!cleanup) { - hr = C_DISPATCH_VT(obj)->AddRef(C_DISPATCH(obj)); - } - -#ifdef _DEBUG - obj->resourceindex = resourcecounter++; -#endif - - return hr; -} - - - - -ZEND_API char *php_COM_error_message(HRESULT hr) -{ - void *pMsgBuf = NULL; - - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, - hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &pMsgBuf, 0, NULL)) { - char error_string[] = "No description available"; - - pMsgBuf = LocalAlloc(LMEM_FIXED, sizeof(error_string)); - memcpy(pMsgBuf, error_string, sizeof(error_string)); - } - - return pMsgBuf; -} - - -ZEND_API char *php_COM_string_from_CLSID(const CLSID *clsid) -{ - LPOLESTR ole_clsid; - char *clsid_str; - - StringFromCLSID(clsid, &ole_clsid); - clsid_str = php_OLECHAR_to_char(ole_clsid, NULL, CP_ACP, FALSE); - CoTaskMemFree(ole_clsid); - - return clsid_str; -} - - -ZEND_API HRESULT php_COM_destruct(comval *obj) -{ - HRESULT hr = S_OK; - - php_COM_enable_events(obj, FALSE); - if (obj->sinkdispatch) - obj->sinkdispatch->lpVtbl->Release(obj->sinkdispatch); - - if (C_HASTLIB(obj)) { - C_TYPEINFO_VT(obj)->Release(C_TYPEINFO(obj)); - } - if (C_HASENUM(obj)) { - C_ENUMVARIANT_VT(obj)->Release(C_ENUMVARIANT(obj)); - } - - if (C_DISPATCH(obj)) { - hr = C_DISPATCH_VT(obj)->Release(C_DISPATCH(obj)); - } - efree(obj); - - return hr; -} - - - - - - - - -/* {{{ proto bool com_message_pump([int timeoutms]) - Process COM messages, sleeping for up to timeoutms milliseconds */ -PHP_FUNCTION(com_message_pump) -{ - long timeoutms = 0; - MSG msg; - DWORD result; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timeoutms) == FAILURE) - RETURN_FALSE; - - result = MsgWaitForMultipleObjects(0, NULL, FALSE, timeoutms, QS_ALLINPUT); - - if (result == WAIT_OBJECT_0) { - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - /* we processed messages */ - RETVAL_TRUE; - } else { - /* we did not process messages (timed out) */ - RETVAL_FALSE; - } -} -/* }}} */ - -ZEND_API HRESULT php_COM_enable_events(comval *obj, int enable) -{ - if (obj->sinkdispatch) { - IConnectionPointContainer *cont; - IConnectionPoint *point; - - if (SUCCEEDED(C_DISPATCH_VT(obj)->QueryInterface(C_DISPATCH(obj), &IID_IConnectionPointContainer, (void**)&cont))) { - if (SUCCEEDED(cont->lpVtbl->FindConnectionPoint(cont, &obj->sinkid, &point))) { - if (enable) { - point->lpVtbl->Advise(point, (IUnknown*)obj->sinkdispatch, &obj->sinkcookie); - } else { - point->lpVtbl->Unadvise(point, obj->sinkcookie); - } - point->lpVtbl->Release(point); - } - cont->lpVtbl->Release(cont); - } - } - - return S_OK; -} - -static const struct { - VARTYPE vt; - const char *name; -} vt_names[] = { - { VT_NULL, "VT_NULL" }, - { VT_EMPTY, "VT_EMPTY" }, - { VT_UI1, "VT_UI1" }, - { VT_I2, "VT_I2" }, - { VT_I4, "VT_I4" }, - { VT_R4, "VT_R4" }, - { VT_R8, "VT_R8" }, - { VT_BOOL, "VT_BOOL" }, - { VT_ERROR, "VT_ERROR" }, - { VT_CY, "VT_CY" }, - { VT_DATE, "VT_DATE" }, - { VT_BSTR, "VT_BSTR" }, - { VT_DECIMAL, "VT_DECIMAL" }, - { VT_UNKNOWN, "VT_UNKNOWN" }, - { VT_DISPATCH, "VT_DISPATCH" }, - { VT_VARIANT, "VT_VARIANT" }, - { VT_I1, "VT_I1" }, - { VT_UI2, "VT_UI2" }, - { VT_UI4, "VT_UI4" }, - { VT_INT, "VT_INT" }, - { VT_UINT, "VT_UINT" }, - { VT_ARRAY, "VT_ARRAY" }, - { VT_BYREF, "VT_BYREF" }, - { VT_VOID, "VT_VOID" }, - { VT_PTR, "VT_PTR" }, - { VT_HRESULT, "VT_HRESULT" }, - { 0, NULL } -}; - -static inline const char *vt_to_string(VARTYPE vt) -{ - int i; - for (i = 0; vt_names[i].name != NULL; i++) { - if (vt_names[i].vt == vt) - return vt_names[i].name; - } - return "?"; -} - -ZEND_API int php_COM_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int printdef, GUID *guid) -{ - TYPEATTR *attr; - FUNCDESC *func; - int i; - OLECHAR *olename; - char *ansiname = NULL; - unsigned int ansinamelen; - int ret = 0; - - if (FAILED(typeinfo->lpVtbl->GetTypeAttr(typeinfo, &attr))) - return 0; - - /* verify that it is suitable */ - if (id_to_name == NULL || attr->typekind == TKIND_DISPATCH) { - - if (guid) - memcpy(guid, &attr->guid, sizeof(GUID)); - - if (printdef) { - char *guidstring; - - typeinfo->lpVtbl->GetDocumentation(typeinfo, MEMBERID_NIL, &olename, NULL, NULL, NULL); - ansiname = php_OLECHAR_to_char(olename, &ansinamelen, CP_ACP, FALSE); - SysFreeString(olename); - - guidstring = php_COM_string_from_CLSID(&attr->guid); - php_printf("class %s { /* GUID=%s */\n", ansiname, guidstring); - efree(guidstring); - - efree(ansiname); - } - - if (id_to_name) - zend_hash_init(id_to_name, 0, NULL, ZVAL_PTR_DTOR, 0); - - /* So we've got the dispatch interface; lets list the event methods */ - for (i = 0; i < attr->cFuncs; i++) { - zval *tmp; - DISPID lastid = 0; /* for props */ - int isprop; - - if (FAILED(typeinfo->lpVtbl->GetFuncDesc(typeinfo, i, &func))) - break; - - isprop = (func->invkind & DISPATCH_PROPERTYGET || func->invkind & DISPATCH_PROPERTYPUT); - - if (!isprop || lastid != func->memid) { - - lastid = func->memid; - - typeinfo->lpVtbl->GetDocumentation(typeinfo, func->memid, &olename, NULL, NULL, NULL); - ansiname = php_OLECHAR_to_char(olename, &ansinamelen, CP_ACP, FALSE); - SysFreeString(olename); - - if (printdef) { - int j; - char *funcdesc; - unsigned int funcdesclen, cnames = 0; - BSTR *names; - - names = (BSTR*)emalloc((func->cParams + 1) * sizeof(BSTR)); - - typeinfo->lpVtbl->GetNames(typeinfo, func->memid, names, func->cParams + 1, &cnames); - /* first element is the function name */ - SysFreeString(names[0]); - - php_printf("\t/* DISPID=%d */\n", func->memid); - - if (func->elemdescFunc.tdesc.vt != VT_VOID) { - php_printf("\t/* %s [%d] */\n", - vt_to_string(func->elemdescFunc.tdesc.vt), - func->elemdescFunc.tdesc.vt - ); - } - - if (isprop) { - - typeinfo->lpVtbl->GetDocumentation(typeinfo, func->memid, NULL, &olename, NULL, NULL); - if (olename) { - funcdesc = php_OLECHAR_to_char(olename, &funcdesclen, CP_ACP, FALSE); - SysFreeString(olename); - php_printf("\t/* %s */\n", funcdesc); - efree(funcdesc); - } - - php_printf("\tvar $%s;\n\n", ansiname); - - } else { - /* a function */ - - php_printf("\tfunction %s(\n", ansiname); - - for (j = 0; j < func->cParams; j++) { - ELEMDESC *elem = &func->lprgelemdescParam[j]; - - php_printf("\t\t/* %s [%d] ", vt_to_string(elem->tdesc.vt), elem->tdesc.vt); - - if (elem->paramdesc.wParamFlags & PARAMFLAG_FIN) - php_printf("[in]"); - if (elem->paramdesc.wParamFlags & PARAMFLAG_FOUT) - php_printf("[out]"); - - if (elem->tdesc.vt == VT_PTR) { - /* what does it point to ? */ - php_printf(" --> %s [%d] ", - vt_to_string(elem->tdesc.lptdesc->vt), - elem->tdesc.lptdesc->vt - ); - } - - /* when we handle prop put and get, this will look nicer */ - if (j+1 < (int)cnames) { - funcdesc = php_OLECHAR_to_char(names[j+1], &funcdesclen, CP_ACP, FALSE); - SysFreeString(names[j+1]); - } else { - funcdesc = "???"; - } - - php_printf(" */ %s%s%c\n", - elem->tdesc.vt == VT_PTR ? "&$" : "$", - funcdesc, - j == func->cParams - 1 ? ' ' : ',' - ); - - if (j+1 < (int)cnames) - efree(funcdesc); - } - - php_printf("\t\t)\n\t{\n"); - - typeinfo->lpVtbl->GetDocumentation(typeinfo, func->memid, NULL, &olename, NULL, NULL); - if (olename) { - funcdesc = php_OLECHAR_to_char(olename, &funcdesclen, CP_ACP, FALSE); - SysFreeString(olename); - php_printf("\t\t/* %s */\n", funcdesc); - efree(funcdesc); - } - - php_printf("\t}\n"); - } - - efree(names); - } - - if (id_to_name) { - zend_str_tolower(ansiname, ansinamelen); - MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, ansiname, ansinamelen, 0); - zend_hash_index_update(id_to_name, func->memid, (void*)&tmp, sizeof(zval *), NULL); - } - } - typeinfo->lpVtbl->ReleaseFuncDesc(typeinfo, func); - - } - - if (printdef) - php_printf("}\n"); - - ret = 1; - } else { - zend_error(E_WARNING, "That's not a dispatchable interface!! type kind = %08x", attr->typekind); - } - - typeinfo->lpVtbl->ReleaseTypeAttr(typeinfo, attr); - - return ret; -} - -ZEND_API ITypeInfo *php_COM_locate_typeinfo(char *typelibname, comval *obj, char *dispname, int sink) -{ - ITypeInfo *typeinfo = NULL; - ITypeLib *typelib = NULL; - int gotguid = 0; - GUID iid; - - if (obj) { - if (dispname == NULL && sink) { - IProvideClassInfo2 *pci2; - IProvideClassInfo *pci; - - if (SUCCEEDED(C_DISPATCH_VT(obj)->QueryInterface(C_DISPATCH(obj), &IID_IProvideClassInfo2, (void**)&pci2))) { - gotguid = SUCCEEDED(pci2->lpVtbl->GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid)); - pci2->lpVtbl->Release(pci2); - } - if (!gotguid && SUCCEEDED(C_DISPATCH_VT(obj)->QueryInterface(C_DISPATCH(obj), &IID_IProvideClassInfo, (void**)&pci))) { - /* examine the available interfaces */ - /* TODO: write some code here */ - pci->lpVtbl->Release(pci); - } - } else if (dispname && C_HASTLIB(obj)) { - unsigned int idx; - /* get the library from the object; the rest will be dealt with later */ - C_TYPEINFO_VT(obj)->GetContainingTypeLib(C_TYPEINFO(obj), &typelib, &idx); - } else if (typelibname == NULL) { - C_DISPATCH_VT(obj)->GetTypeInfo(C_DISPATCH(obj), 0, LANG_NEUTRAL, &typeinfo); - } - } else if (typelibname) { - /* Fetch the typelibrary and use that to look things up */ - typelib = php_COM_find_typelib(typelibname, CONST_CS); - } - - if (!gotguid && dispname && typelib) { - unsigned short cfound; - MEMBERID memid; - OLECHAR *olename = php_char_to_OLECHAR(dispname, strlen(dispname), CP_ACP, FALSE); - - cfound = 1; - if (FAILED(typelib->lpVtbl->FindName(typelib, olename, 0, &typeinfo, &memid, &cfound)) || cfound == 0) { - CLSID coclass; - ITypeInfo *coinfo; - - /* assume that it might be a progid instead */ - if (SUCCEEDED(CLSIDFromProgID(olename, &coclass)) && - SUCCEEDED(typelib->lpVtbl->GetTypeInfoOfGuid(typelib, &coclass, &coinfo))) { - - /* enumerate implemented interfaces and pick the one as indicated by sink */ - TYPEATTR *attr; - int i; - - coinfo->lpVtbl->GetTypeAttr(coinfo, &attr); - - for (i = 0; i < attr->cImplTypes; i++) { - HREFTYPE rt; - int tf; - - if (FAILED(coinfo->lpVtbl->GetImplTypeFlags(coinfo, i, &tf))) - continue; - - if ((sink && tf == (IMPLTYPEFLAG_FSOURCE|IMPLTYPEFLAG_FDEFAULT)) || - (!sink && (tf & IMPLTYPEFLAG_FSOURCE) == 0)) { - - /* flags match what we are looking for */ - - if (SUCCEEDED(coinfo->lpVtbl->GetRefTypeOfImplType(coinfo, i, &rt))) - if (SUCCEEDED(coinfo->lpVtbl->GetRefTypeInfo(coinfo, rt, &typeinfo))) - break; - - } - } - - coinfo->lpVtbl->ReleaseTypeAttr(coinfo, attr); - coinfo->lpVtbl->Release(coinfo); - } - } - - - efree(olename); - } else if (gotguid) { - typelib->lpVtbl->GetTypeInfoOfGuid(typelib, &iid, &typeinfo); - } - - if (typelib) - typelib->lpVtbl->Release(typelib); - - return typeinfo; -} - -static ITypeLib *php_COM_find_typelib(char *search_string, int mode) -{ - ITypeLib *TypeLib = NULL; - char *strtok_buf, *major, *minor; - CLSID clsid; - OLECHAR *p; - - /* Type Libraries: - * The string we have is either: - * a) a file name - * b) a CLSID, major, minor e.g. "{00000200-0000-0010-8000-00AA006D2EA4},2,0" - * c) a Type Library name e.g. "Microsoft OLE DB ActiveX Data Objects 1.0 Library" - * Searching for the name will be more expensive that the - * other two, so we will do that when both other attempts - * fail. - */ - - search_string = php_strtok_r(search_string, ",", &strtok_buf); - - if (search_string == NULL) - return NULL; - - major = php_strtok_r(NULL, ",", &strtok_buf); - minor = php_strtok_r(NULL, ",", &strtok_buf); - - p = php_char_to_OLECHAR(search_string, strlen(search_string), CP_ACP, FALSE); - /* Is the string a GUID ? */ - - if (!FAILED(CLSIDFromString(p, &clsid))) { - HRESULT hr; - WORD major_i = 1; - WORD minor_i = 0; - - /* We have a valid GUID, check to see if a major/minor */ - /* version was specified otherwise assume 1,0 */ - if ((major != NULL) && (minor != NULL)) { - major_i = (WORD) atoi(major); - minor_i = (WORD) atoi(minor); - } - - /* The GUID will either be a typelibrary or a CLSID */ - hr = LoadRegTypeLib((REFGUID) &clsid, major_i, minor_i, LANG_NEUTRAL, &TypeLib); - - /* If the LoadRegTypeLib fails, let's try to instantiate */ - /* the class itself and then QI for the TypeInfo and */ - /* retrieve the type info from that interface */ - if (FAILED(hr) && (!major || !minor)) { - IDispatch *Dispatch; - ITypeInfo *TypeInfo; - int idx; - - if (FAILED(CoCreateInstance(&clsid, NULL, CLSCTX_SERVER, &IID_IDispatch, (LPVOID *) &Dispatch))) { - efree(p); - return NULL; - } - if (FAILED(Dispatch->lpVtbl->GetTypeInfo(Dispatch, 0, LANG_NEUTRAL, &TypeInfo))) { - Dispatch->lpVtbl->Release(Dispatch); - efree(p); - return NULL; - } - Dispatch->lpVtbl->Release(Dispatch); - if (FAILED(TypeInfo->lpVtbl->GetContainingTypeLib(TypeInfo, &TypeLib, &idx))) { - TypeInfo->lpVtbl->Release(TypeInfo); - efree(p); - return NULL; - } - TypeInfo->lpVtbl->Release(TypeInfo); - } - } else { - if (FAILED(LoadTypeLib(p, &TypeLib))) { - /* Walk HKCR/TypeLib looking for the string */ - /* If that succeeds, call ourself recursively */ - /* using the CLSID found, else give up and bail */ - HKEY hkey, hsubkey; - DWORD SubKeys, MaxSubKeyLength; - char *keyname; - register unsigned int ii, jj; - DWORD VersionCount; - char version[20]; /* All the version keys are 1.0, 4.6, ... */ - char *libname; - DWORD libnamelen; - - /* No Need for Unicode version any more */ - efree(p); - - /* Starting at HKEY_CLASSES_ROOT/TypeLib */ - /* Walk all subkeys (Typelib GUIDs) looking */ - /* at each version for a string match to the */ - /* supplied argument */ - - if (ERROR_SUCCESS != RegOpenKey(HKEY_CLASSES_ROOT, "TypeLib",&hkey)) { - /* This is pretty bad - better bail */ - return NULL; - } - if (ERROR_SUCCESS != RegQueryInfoKey(hkey, NULL, NULL, NULL, &SubKeys, &MaxSubKeyLength, NULL, NULL, NULL, NULL, NULL, NULL)) { - RegCloseKey(hkey); - return NULL; - } - MaxSubKeyLength++; /* \0 is not counted */ - keyname = emalloc(MaxSubKeyLength); - libname = emalloc(strlen(search_string)+1); - for (ii=0;ii<SubKeys;ii++) { - if (ERROR_SUCCESS != RegEnumKey(hkey, ii, keyname, MaxSubKeyLength)) { - /* Failed - who cares */ - continue; - } - if (ERROR_SUCCESS != RegOpenKey(hkey, keyname, &hsubkey)) { - /* Failed - who cares */ - continue; - } - if (ERROR_SUCCESS != RegQueryInfoKey(hsubkey, NULL, NULL, NULL, &VersionCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { - /* Failed - who cares */ - RegCloseKey(hsubkey); - continue; - } - for (jj=0;jj<VersionCount;jj++) { - if (ERROR_SUCCESS != RegEnumKey(hsubkey, jj, version, sizeof(version))) { - /* Failed - who cares */ - continue; - } - /* OK we just need to retrieve the default */ - /* value for this key and see if it matches */ - libnamelen = strlen(search_string)+1; - if (ERROR_SUCCESS == RegQueryValue(hsubkey, version, libname, &libnamelen)) { - if ((mode & CONST_CS) ? (strcmp(libname, search_string) == 0) : (stricmp(libname, search_string) == 0)) { - char *str; - int major, minor; - - /* Found it */ - RegCloseKey(hkey); - RegCloseKey(hsubkey); - - efree(libname); - /* We can either open up the "win32" key and find the DLL name */ - /* Or just parse the version string and pass that in */ - /* The version string seems like a more portable solution */ - /* Given that there is a COM on Unix */ - if (2 != sscanf(version, "%d.%d", &major, &minor)) { - major = 1; - minor = 0; - } - str = emalloc(strlen(keyname)+strlen(version)+20); /* 18 == safety, 2 == extra comma and \0 */ - sprintf(str, "%s,%d,%d", keyname, major, minor); - efree(keyname); - TypeLib = php_COM_find_typelib(str, mode); - efree(str); - /* This is probbaly much harder to read and follow */ - /* But it is MUCH more effiecient than trying to */ - /* test for errors and leave through a single "return" */ - return TypeLib; - } - } else { - /* Failed - perhaps too small abuffer */ - /* But if too small, then the name does not match */ - } - } - RegCloseKey(hsubkey); - } - efree(keyname); - efree(libname); - return NULL; - } - } - efree(p); - return TypeLib; -} - - -ZEND_API int php_COM_load_typelib(ITypeLib *TypeLib, int mode) -{ - ITypeComp *TypeComp; - int i; - int interfaces; - TSRMLS_FETCH(); - - if (NULL == TypeLib) { - return FAILURE; - } - - interfaces = TypeLib->lpVtbl->GetTypeInfoCount(TypeLib); - - TypeLib->lpVtbl->GetTypeComp(TypeLib, &TypeComp); - for (i=0; i<interfaces; i++) { - TYPEKIND pTKind; - - TypeLib->lpVtbl->GetTypeInfoType(TypeLib, i, &pTKind); - if (pTKind==TKIND_ENUM) { - ITypeInfo *TypeInfo; - VARDESC *pVarDesc; - UINT NameCount; - int j; - BSTR bstr_EnumId; - char *EnumId; - - TypeLib->lpVtbl->GetDocumentation(TypeLib, i, &bstr_EnumId, NULL, NULL, NULL); - EnumId = php_OLECHAR_to_char(bstr_EnumId, NULL, CP_ACP, FALSE); - printf("Enumeration %d - %s:\n", i, EnumId); - efree(EnumId); - - TypeLib->lpVtbl->GetTypeInfo(TypeLib, i, &TypeInfo); - - j=0; - while (SUCCEEDED(TypeInfo->lpVtbl->GetVarDesc(TypeInfo, j, &pVarDesc))) { - BSTR bstr_ids; - zend_constant c; - zval exists, results, value; - char *const_name; - - TypeInfo->lpVtbl->GetNames(TypeInfo, pVarDesc->memid, &bstr_ids, 1, &NameCount); - if (NameCount!=1) { - j++; - continue; - } - const_name = php_OLECHAR_to_char(bstr_ids, &c.name_len, CP_ACP, FALSE); - c.name = zend_strndup(const_name, c.name_len); - efree(const_name); - c.name_len++; /* length should include the NULL */ - SysFreeString(bstr_ids); - - /* Before registering the contsnt, let's see if we can find it */ - if (zend_get_constant(c.name, c.name_len-1, &exists TSRMLS_CC)) { - /* Oops, it already exists. No problem if it is defined as the same value */ - /* Check to see if they are the same */ - if (!compare_function(&results, &c.value, &exists TSRMLS_CC) && INI_INT("com.autoregister_verbose")) { - rpc_error(E_WARNING, "Type library value %s is already defined and has a different value", c.name); - } - free(c.name); - j++; - continue; - } - - php_variant_to_zval(pVarDesc->lpvarValue, &value, CP_ACP); - /* we only import enumerations (=int) */ - if (Z_TYPE(value) == IS_LONG) { - c.flags = mode; - c.value.type = IS_LONG; - c.value.value.lval = Z_LVAL(value); - c.module_number = 0; /* the module number is not available here */ - - zend_register_constant(&c TSRMLS_CC); - } - - j++; - } - TypeInfo->lpVtbl->Release(TypeInfo); - } - } - - return SUCCESS; -} - - -/* create an overloaded COM object from a dispatch pointer */ -PHPAPI zval *php_COM_object_from_dispatch(IDispatch *disp) -{ - comval *obj; - - ALLOC_COM(obj); - php_COM_set(obj, &disp, FALSE); - - return rpc_object_from_data(com, obj); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * indent-tabs-mode: t - * End: - */ diff --git a/ext/rpc/com/com_wrapper.h b/ext/rpc/com/com_wrapper.h deleted file mode 100644 index c751df4931..0000000000 --- a/ext/rpc/com/com_wrapper.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - | Harald Radi <h.radi@nme.at> | - | Alan Brown <abrown@pobox.com> | - | Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -#ifndef COM_WRAPPER_H -#define COM_WRAPPER_H - -#if PHP_WIN32 - -BEGIN_EXTERN_C() - -typedef struct comval_ { - BOOL typelib; - BOOL enumeration; - int refcount; - int codepage; - struct { - IDispatch *dispatch; - ITypeInfo *typeinfo; - IEnumVARIANT *enumvariant; - } i; - -#if 1 - IDispatch *sinkdispatch; - GUID sinkid; - DWORD sinkcookie; -#endif - -#ifdef _DEBUG - int resourceindex; -#endif - -} comval; - -ZEND_API HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, char **ErrString); -ZEND_API HRESULT php_COM_get_ids_of_names(comval *obj, OLECHAR FAR* rgszNames, DISPID FAR* rgDispId); -ZEND_API HRESULT php_COM_release(comval *obj); -ZEND_API HRESULT php_COM_addref(comval *obj); -ZEND_API HRESULT php_COM_destruct(comval *obj); -ZEND_API HRESULT php_COM_set(comval *obj, IDispatch FAR* FAR* pDisp, int cleanup); -ZEND_API HRESULT php_COM_enable_events(comval *obj, int enable); - -ZEND_API char* php_COM_string_from_CLSID(const CLSID *clsid); -ZEND_API char* php_COM_error_message(HRESULT hr); -ZEND_API int php_COM_load_typelib(ITypeLib *TypeLib, int mode); -ZEND_API int php_COM_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int printdef, GUID *guid); -ZEND_API ITypeInfo* php_COM_locate_typeinfo(char *typelibname, comval *obj, char *dispname, int sink); -ZEND_API ITypeLib* php_COM_find_typelib(char *search_string, int mode); - -ZEND_API IDispatch* php_COM_export_as_sink(zval *val, GUID *sinkid, HashTable *id_to_name); -ZEND_API IDispatch* php_COM_export_object(zval *val); -ZEND_API zval* php_COM_object_from_dispatch(IDispatch *disp); - -END_EXTERN_C() - -#define ZVAL_COM(z,o) { \ - rpc_internal *intern; \ - Z_TYPE_P(z) = IS_OBJECT; \ - (z)->value.obj = rpc_objects_new(com_class_entry TSRMLS_CC); \ - if (GET_INTERNAL_EX(intern, (z)) != SUCCESS) { \ - /* TODO: exception */ \ - } \ - intern->data = (o); \ - } - -#define RETVAL_COM(o) ZVAL_COM(&return_value, o); -#define RETURN_COM(o) RETVAL_COM(o) \ - return; - -#define ALLOC_COM(z) (z) = (comval *) ecalloc(1, sizeof(comval)); \ - C_CODEPAGE(z) = CP_ACP; - -#define FREE_COM(z) php_COM_destruct(z); - -#define C_CODEPAGE(x) ((x)->codepage) - -#define C_HASTLIB(x) ((x)->typelib) -#define C_HASENUM(x) ((x)->enumeration) - -#define C_DISPATCH(x) ((x)->i.dispatch) -#define C_TYPEINFO(x) ((x)->i.typeinfo) -#define C_ENUMVARIANT(x) ((x)->i.enumvariant) - -#define C_DISPATCH_VT(x) (C_DISPATCH(x)->lpVtbl) -#define C_TYPEINFO_VT(x) (C_TYPEINFO(x)->lpVtbl) -#define C_ENUMVARIANT_VT(x) (C_ENUMVARIANT(x)->lpVtbl) - -#endif /* PHP_WIN32 */ - -#endif /* COM_H */ diff --git a/ext/rpc/com/conversion.c b/ext/rpc/com/conversion.c deleted file mode 100644 index acdd6cef40..0000000000 --- a/ext/rpc/com/conversion.c +++ /dev/null @@ -1,855 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - | Alan Brown <abrown@pobox.com> | - | Paul Shortis <pshortis@dataworx.com.au> | - +----------------------------------------------------------------------+ - */ - -/* - * 03.6.2001 - * Added SafeArray ==> Hash support - */ - -/* - * Paul Shortis June 7, 2001 <pshortis@dataworx.com.au> - Added code to support SafeArray passing - * to COM objects. Support includes passing arrays of variants as well - * as typed arrays. - */ - -#ifdef PHP_WIN32 - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" - -#include "../rpc.h" -#include "../handler.h" - -#include "com.h" -#include "com_wrapper.h" -#include "conversion.h" -#include "variant.h" - -/* prototypes */ - -static int comval_to_variant(zval *zval_arg, VARIANT *var_arg); - -/* implementations */ -PHPAPI void php_zval_to_variant(zval *zval_arg, VARIANT *var_arg, int codepage) -{ - int type = VT_EMPTY; /* default variant type */ - - switch (Z_TYPE_P(zval_arg)) { - case IS_NULL: - type = VT_NULL; - break; - - case IS_BOOL: - type = VT_BOOL; - break; - - case IS_OBJECT: - if (!strcmp(Z_OBJCE_P(zval_arg)->name, "VARIANT")) { - type = VT_VARIANT|VT_BYREF; - } else { - type = VT_DISPATCH; - } - break; - - case IS_ARRAY: - type = VT_ARRAY; - break; - - case IS_RESOURCE: - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - /* ?? */ - break; - - case IS_LONG: - type = VT_I4; /* assuming 32-bit platform */ - break; - - case IS_DOUBLE: - type = VT_R8; /* assuming 64-bit double precision */ - break; - - case IS_STRING: - type = VT_BSTR; - break; - } - - php_zval_to_variant_ex(zval_arg, var_arg, type, codepage); -} - - -PHPAPI void php_zval_to_variant_ex(zval *zval_arg, VARIANT *var_arg, int type, int codepage) -{ - OLECHAR *unicode_str = NULL; - - VariantInit(var_arg); - V_VT(var_arg) = type; - - if (V_VT(var_arg) & VT_ARRAY) { - /* For now we'll just handle single dimension arrays, we'll use the data type of the first element for the - output data type */ - HashTable *ht = Z_ARRVAL(*zval_arg); - int numberOfElements = zend_hash_num_elements(ht); - SAFEARRAY *safeArray; - SAFEARRAYBOUND bounds[1]; - VARIANT *v; - zval **entry; /* An entry in the input array */ - - type &= ~VT_ARRAY; - - if (V_VT(var_arg) == (VT_ARRAY|VT_BYREF)) { /* == is intended, because VT_*|VT_BYREF|VT_ARRAY means something diffrent */ - type &= ~VT_BYREF; - V_VARIANTREF(var_arg) = (VARIANT *) emalloc(sizeof(VARIANT)); - var_arg = V_VARIANTREF(var_arg); /* put the array in that VARIANT */ - } - - bounds[0].lLbound = 0; - bounds[0].cElements = numberOfElements; - safeArray = SafeArrayCreate(VT_VARIANT, 1, bounds); - - if (NULL == safeArray) { - rpc_error(E_WARNING, "Unable to convert php array to VARIANT array - %s", numberOfElements ? "" : "(Empty input array)"); - ZVAL_FALSE(zval_arg); - } else { - V_ARRAY(var_arg) = safeArray; - V_VT(var_arg) = VT_ARRAY|VT_VARIANT; /* Now have a valid safe array allocated */ - if (SUCCEEDED(SafeArrayLock(safeArray))) { - ulong i; - - zend_hash_internal_pointer_reset(ht); - for (i = 0; i < (ulong)numberOfElements; ++i) { - if ((zend_hash_get_current_data(ht, (void **)&entry) == SUCCESS) && (entry != NULL)) { /* Get a pointer to the php array element */ - /* Add another value to the safe array */ - if (SUCCEEDED(SafeArrayPtrOfIndex( safeArray, &i, &v))) { /* Pointer to output element entry retrieved successfully */ - if (type) { /* explicit type */ - php_zval_to_variant_ex(*entry, v, type, codepage); /* Do the required conversion */ - } else { - php_zval_to_variant(*entry, v, codepage); /* Do the required conversion */ - } - } else { - rpc_error(E_WARNING, "phpArrayToSafeArray() - Unable to retrieve pointer to output element number (%d)", i); - } - } - zend_hash_move_forward(ht); - } - SafeArrayUnlock( safeArray); - } else { - rpc_error(E_WARNING, "phpArrayToSafeArray() - Unable to lock safeArray"); - } - } - } else { - switch (V_VT(var_arg)) { - - case VT_NULL: - case VT_VOID: - ZVAL_NULL(zval_arg); - break; - - case VT_UI1: - convert_to_long_ex(&zval_arg); - V_UI1(var_arg) = (unsigned char) Z_LVAL_P(zval_arg); - break; - - case VT_I2: - convert_to_long_ex(&zval_arg); - V_I2(var_arg) = (short) Z_LVAL_P(zval_arg); - break; - - case VT_I4: - convert_to_long_ex(&zval_arg); - V_I4(var_arg) = Z_LVAL_P(zval_arg); - break; - - case VT_R4: - convert_to_double_ex(&zval_arg); - V_R4(var_arg) = (float) Z_DVAL_P(zval_arg); - break; - - case VT_R8: - convert_to_double_ex(&zval_arg); - V_R8(var_arg) = Z_DVAL_P(zval_arg); - break; - - case VT_BOOL: - convert_to_boolean_ex(&zval_arg); - if (Z_LVAL_P(zval_arg)) { - V_BOOL(var_arg) = VT_TRUE; - } else { - V_BOOL(var_arg) = VT_FALSE; - } - break; - - case VT_ERROR: - convert_to_long_ex(&zval_arg); - V_ERROR(var_arg) = Z_LVAL_P(zval_arg); - break; - - case VT_CY: - convert_to_double_ex(&zval_arg); - VarCyFromR8(Z_DVAL_P(zval_arg), &V_CY(var_arg)); - break; - - case VT_DATE: { - SYSTEMTIME wintime; - struct tm *phptime; - - switch (Z_TYPE_P(zval_arg)) { - case IS_DOUBLE: - /* already a VariantTime value */ - V_DATE(var_arg) = Z_DVAL_P(zval_arg); - break; - - /** @todo - case IS_STRING: - */ - /* string representation of a time value */ - - default: - /* a PHP time value ? */ - convert_to_long_ex(&zval_arg); - phptime = gmtime(&(Z_LVAL_P(zval_arg))); - memset(&wintime, 0, sizeof(wintime)); - - wintime.wYear = phptime->tm_year + 1900; - wintime.wMonth = phptime->tm_mon + 1; - wintime.wDay = phptime->tm_mday; - wintime.wHour = phptime->tm_hour; - wintime.wMinute = phptime->tm_min; - wintime.wSecond = phptime->tm_sec; - - SystemTimeToVariantTime(&wintime, &V_DATE(var_arg)); - break; - } - } - break; - - case VT_BSTR: - convert_to_string_ex(&zval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(zval_arg), Z_STRLEN_P(zval_arg), codepage, FALSE); - V_BSTR(var_arg) = SysAllocStringByteLen((char *) unicode_str, Z_STRLEN_P(zval_arg) * sizeof(OLECHAR)); - break; - - case VT_DECIMAL: - convert_to_string_ex(&zval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(zval_arg), Z_STRLEN_P(zval_arg), codepage, FALSE); - VarDecFromStr(unicode_str, LOCALE_SYSTEM_DEFAULT, 0, &V_DECIMAL(var_arg)); - break; - - case VT_DECIMAL|VT_BYREF: - convert_to_string_ex(&zval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(zval_arg), Z_STRLEN_P(zval_arg), codepage, FALSE); - VarDecFromStr(unicode_str, LOCALE_SYSTEM_DEFAULT, 0, V_DECIMALREF(var_arg)); - break; - - case VT_UNKNOWN: - if (comval_to_variant(zval_arg, var_arg) == SUCCESS) { - V_VT(var_arg) = VT_UNKNOWN; - V_UNKNOWN(var_arg) = (IUnknown *) V_DISPATCH(var_arg); - } - break; - - case VT_DISPATCH: - if (Z_OBJCE_P(zval_arg) == com_class_entry) { - comval_to_variant(zval_arg, var_arg); - } else { - V_DISPATCH(var_arg) = php_COM_export_object(zval_arg); - - if (V_DISPATCH(var_arg)) { - V_VT(var_arg) = VT_DISPATCH; - } - } - if (V_VT(var_arg) != VT_DISPATCH) { - VariantInit(var_arg); - } - break; - - case VT_UI1|VT_BYREF: - convert_to_long(zval_arg); - V_UI1REF(var_arg) = (unsigned char FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_I2|VT_BYREF: - convert_to_long(zval_arg); - V_I2REF(var_arg) = (short FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_I4|VT_BYREF: - convert_to_long(zval_arg); - V_I4REF(var_arg) = (long FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_R4|VT_BYREF: - convert_to_double(zval_arg); - V_R4REF(var_arg) = (float FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_R8|VT_BYREF: - convert_to_double(zval_arg); - V_R8REF(var_arg) = (double FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_BOOL|VT_BYREF: - convert_to_boolean(zval_arg); - /* emalloc or malloc ? */ - V_BOOLREF(var_arg) = (short FAR*) pemalloc(sizeof(short), 1); - if (Z_LVAL_P(zval_arg)) { - *V_BOOLREF(var_arg) = VT_TRUE; - } else { - *V_BOOLREF(var_arg) = VT_FALSE; - } - break; - - case VT_ERROR|VT_BYREF: - convert_to_long(zval_arg); - V_ERRORREF(var_arg) = (long FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_CY|VT_BYREF: - convert_to_double_ex(&zval_arg); - VarCyFromR8(Z_DVAL_P(zval_arg), var_arg->pcyVal); - break; - - case VT_DATE|VT_BYREF: { - SYSTEMTIME wintime; - struct tm *phptime; - - phptime = gmtime(&(Z_LVAL_P(zval_arg))); - memset(&wintime, 0, sizeof(wintime)); - - wintime.wYear = phptime->tm_year + 1900; - wintime.wMonth = phptime->tm_mon + 1; - wintime.wDay = phptime->tm_mday; - wintime.wHour = phptime->tm_hour; - wintime.wMinute = phptime->tm_min; - wintime.wSecond = phptime->tm_sec; - - SystemTimeToVariantTime(&wintime, var_arg->pdate); - } - break; - - case VT_BSTR|VT_BYREF: - convert_to_string(zval_arg); - V_BSTRREF(var_arg) = (BSTR FAR*) emalloc(sizeof(BSTR FAR*)); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(zval_arg), Z_STRLEN_P(zval_arg), codepage, FALSE); - *V_BSTRREF(var_arg) = SysAllocString(unicode_str); - break; - - case VT_UNKNOWN|VT_BYREF: - if (comval_to_variant(zval_arg, var_arg) == SUCCESS) { - V_VT(var_arg) = VT_UNKNOWN|VT_BYREF; - V_UNKNOWNREF(var_arg) = (IUnknown **) &V_DISPATCH(var_arg); - } - break; - - case VT_DISPATCH|VT_BYREF: - if (comval_to_variant(zval_arg, var_arg) == SUCCESS) { - V_VT(var_arg) = VT_DISPATCH|VT_BYREF; - V_DISPATCHREF(var_arg) = &V_DISPATCH(var_arg); - } - break; - - case VT_VARIANT: - rpc_error(E_WARNING, "VT_VARIANT is invalid. Use VT_VARIANT|VT_BYREF instead."); - /* break missing intentionally */ - case VT_VARIANT|VT_BYREF: { - variantval *var; - TSRMLS_FETCH(); - - if ((var = zend_object_store_get_object(zval_arg TSRMLS_CC)) == NULL) { - /* TODO exception */ - } - - V_VARIANTREF(var_arg) = var->var; - } - break; - - case VT_I1: - convert_to_long_ex(&zval_arg); - V_I1(var_arg) = (char)Z_LVAL_P(zval_arg); - break; - - case VT_UI2: - convert_to_long_ex(&zval_arg); - V_UI2(var_arg) = (unsigned short)Z_LVAL_P(zval_arg); - break; - - case VT_UI4: - convert_to_long_ex(&zval_arg); - V_UI4(var_arg) = (unsigned long)Z_LVAL_P(zval_arg); - break; - - case VT_INT: - convert_to_long_ex(&zval_arg); - V_INT(var_arg) = (int)Z_LVAL_P(zval_arg); - break; - - case VT_UINT: - convert_to_long_ex(&zval_arg); - V_UINT(var_arg) = (unsigned int)Z_LVAL_P(zval_arg); - break; - - case VT_I1|VT_BYREF: - convert_to_long(zval_arg); - V_I1REF(var_arg) = (char FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_UI2|VT_BYREF: - convert_to_long(zval_arg); - V_UI2REF(var_arg) = (unsigned short FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_UI4|VT_BYREF: - convert_to_long(zval_arg); - V_UI4REF(var_arg) = (unsigned long FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_INT|VT_BYREF: - convert_to_long(zval_arg); - V_INTREF(var_arg) = (int FAR*) &Z_LVAL_P(zval_arg); - break; - - case VT_UINT|VT_BYREF: - convert_to_long(zval_arg); - V_UINTREF(var_arg) = (unsigned int FAR*) &Z_LVAL_P(zval_arg); - break; - - default: - rpc_error(E_WARNING, "Unsupported variant type: %d (0x%X)", V_VT(var_arg), V_VT(var_arg)); - } - - if (unicode_str != NULL) { - efree(unicode_str); - } - } -} - -PHPAPI int php_variant_to_zval(VARIANT *var_arg, zval *zval_arg, int codepage) -{ - /* Changed the function to return a value for recursive error testing */ - /* Existing calls will be unaffected by the change - so it */ - /* seemed like the smallest impact on unfamiliar code */ - int ret = SUCCESS; - - INIT_PZVAL(zval_arg); - - /* Add SafeArray support */ - if (V_ISARRAY(var_arg)) { - SAFEARRAY *array = V_ARRAY(var_arg); - LONG indices[1]; - LONG lbound=0, ubound; - VARTYPE vartype; - register int ii; - UINT Dims; - VARIANT vv; - zval *element; - HRESULT hr; - - /* TODO: Add support for multi-dimensional SafeArrays */ - /* For now just validate that the SafeArray has one dimension */ - if (1 != (Dims = SafeArrayGetDim(array))) { - rpc_error(E_WARNING, "Unsupported: multi-dimensional (%d) SafeArrays", Dims); - ZVAL_NULL(zval_arg); - return FAILURE; - } - SafeArrayLock(array); - - /* This call has failed for everything I have tried */ - /* But best leave it to be on the safe side */ - if (FAILED(SafeArrayGetVartype(array, &vartype)) || (vartype == VT_EMPTY)) { - /* Fall back to what we do know */ - /* Mask off the array bit and assume */ - /* what is left is the type of the array */ - /* elements */ - vartype = V_VT(var_arg) & ~VT_ARRAY; - } - SafeArrayGetUBound(array, 1, &ubound); - SafeArrayGetLBound(array, 1, &lbound); - - /* Since COM returned an array we set up the php */ - /* return value to be an array */ - array_init(zval_arg); - - /* Walk the safe array */ - for (ii=lbound;ii<=ubound;ii++) { - indices[0] = ii; - VariantInit(&vv); /* Docs say this just set the vt field, but you never know */ - /* Set up a variant to pass to a recursive call */ - /* So that we do not need to have two copies */ - /* of the code */ - if (VT_VARIANT == vartype) { - hr = SafeArrayGetElement(array, indices, (VOID *) &(vv)); - } else { - V_VT(&vv) = vartype; - hr = SafeArrayGetElement(array, indices, (VOID *) &(vv.lVal)); - } - if (FAILED(hr)) { - /* Failure to retieve an element probably means the array is sparse */ - /* So leave the php array sparse too */ - continue; - } - /* Create an element to be added to the array */ - ALLOC_ZVAL(element); - /* Call ourself again to handle the base type conversion */ - /* If SafeArrayGetElement proclaims to allocate */ - /* memory for a BSTR, so the recursive call frees */ - /* the string correctly */ - if (FAILURE == php_variant_to_zval(&vv, element, codepage)) { - /* Error occurred setting up array element */ - /* Error was displayed by the recursive call */ - FREE_ZVAL(element); - /* TODO: Do we stop here, or go on and */ - /* try to make sense of the rest of the array */ - /* Going on leads to multiple errors displayed */ - /* for the same conversion. For large arrays that */ - /* could be very annoying */ - /* And if we don't go on - what to do about */ - /* the parts of the array that are OK? */ - /* break; */ - } else { - /* Just insert the element into our return array */ - add_index_zval(zval_arg, ii, element); - } - } - SafeArrayUnlock(array); - } else switch (var_arg->vt & ~VT_BYREF) { - case VT_EMPTY: - ZVAL_NULL(zval_arg); - break; - - case VT_UI1: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_UI1REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_UI1(var_arg)); - } - break; - - case VT_I2: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long )*V_I2REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_I2(var_arg)); - } - break; - - case VT_I4: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, *V_I4REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, V_I4(var_arg)); - } - break; - - case VT_R4: - if (V_ISBYREF(var_arg)) { - ZVAL_DOUBLE(zval_arg, (double)*V_R4REF(var_arg)); - } else { - ZVAL_DOUBLE(zval_arg, (double)V_R4(var_arg)); - } - break; - - case VT_R8: - if (V_ISBYREF(var_arg)) { - ZVAL_DOUBLE(zval_arg, *V_R8REF(var_arg)); - } else { - ZVAL_DOUBLE(zval_arg, V_R8(var_arg)); - } - break; - - /* 96bit uint */ - case VT_DECIMAL: { - OLECHAR *unicode_str; - switch (VarBstrFromDec(&V_DECIMAL(var_arg), LOCALE_SYSTEM_DEFAULT, 0, &unicode_str)) { - case S_OK: - Z_STRVAL_P(zval_arg) = php_OLECHAR_to_char(unicode_str, &Z_STRLEN_P(zval_arg), codepage, FALSE); - Z_TYPE_P(zval_arg) = IS_STRING; - break; - - default: - ZVAL_NULL(zval_arg); - ret = FAILURE; - rpc_error(E_WARNING, "Error converting DECIMAL value to PHP string"); - break; - } - } - break; - - /* Currency */ - case VT_CY: - if (V_ISBYREF(var_arg)) { - VarR8FromCy(*V_CYREF(var_arg), &Z_DVAL_P(zval_arg)); - } else { - VarR8FromCy(V_CY(var_arg), &Z_DVAL_P(zval_arg)); - } - Z_TYPE_P(zval_arg) = IS_DOUBLE; - break; - - case VT_BOOL: - if (V_ISBYREF(var_arg)) { - if (*V_BOOLREF(var_arg)) { - ZVAL_BOOL(zval_arg, Z_TRUE); - } else { - ZVAL_BOOL(zval_arg, Z_FALSE); - } - } else { - if (V_BOOL(var_arg)) { - ZVAL_BOOL(zval_arg, Z_TRUE); - } else { - ZVAL_BOOL(zval_arg, Z_FALSE); - } - } - break; - - case VT_NULL: - case VT_VOID: - ZVAL_NULL(zval_arg); - break; - - case VT_VARIANT: - php_variant_to_zval(V_VARIANTREF(var_arg), zval_arg, codepage); - break; - - case VT_BSTR: - Z_TYPE_P(zval_arg) = IS_STRING; - - if (V_ISBYREF(var_arg)) { - if (*V_BSTR(var_arg)) { - Z_STRVAL_P(zval_arg) = php_OLECHAR_to_char(*V_BSTRREF(var_arg), &Z_STRLEN_P(zval_arg), codepage, FALSE); - } else { - ZVAL_NULL(zval_arg); - } - efree(V_BSTRREF(var_arg)); - } else { - if (V_BSTR(var_arg)) { - Z_STRVAL_P(zval_arg) = php_OLECHAR_to_char(V_BSTR(var_arg), &Z_STRLEN_P(zval_arg), codepage, FALSE); - } else { - ZVAL_NULL(zval_arg); - } - } - - break; - - case VT_DATE: { - BOOL success; - SYSTEMTIME wintime; - struct tm phptime; - - if (V_ISBYREF(var_arg)) { - success = VariantTimeToSystemTime(*V_DATEREF(var_arg), &wintime); - } else { - success = VariantTimeToSystemTime(V_DATE(var_arg), &wintime); - } - - if (success) { - memset(&phptime, 0, sizeof(phptime)); - - phptime.tm_year = wintime.wYear - 1900; - phptime.tm_mon = wintime.wMonth - 1; - phptime.tm_mday = wintime.wDay; - phptime.tm_hour = wintime.wHour; - phptime.tm_min = wintime.wMinute; - phptime.tm_sec = wintime.wSecond; - phptime.tm_isdst = -1; - - tzset(); - ZVAL_LONG(zval_arg, mktime(&phptime)); - } else { - ret = FAILURE; - } - } - break; - - case VT_UNKNOWN: - if (V_UNKNOWN(var_arg) == NULL) { - V_DISPATCH(var_arg) = NULL; - } else { - HRESULT hr; - - hr = V_UNKNOWN(var_arg)->lpVtbl->QueryInterface(var_arg->punkVal, &IID_IDispatch, &V_DISPATCH(var_arg)); - - if (FAILED(hr)) { - char *error_message; - - error_message = php_COM_error_message(hr); - rpc_error(E_WARNING, "Unable to obtain IDispatch interface: %s", error_message); - LocalFree(error_message); - - V_DISPATCH(var_arg) = NULL; - } - } - /* break missing intentionaly */ - case VT_DISPATCH: { - comval *obj; - - if (V_DISPATCH(var_arg) == NULL) { - ret = FAILURE; - ZVAL_NULL(zval_arg); - } else { - TSRMLS_FETCH(); - - ALLOC_COM(obj); - php_COM_set(obj, &V_DISPATCH(var_arg), FALSE); - - ZVAL_COM(zval_arg, obj); - VariantInit(var_arg); /* to protect C_DISPATCH(obj) from being freed when var_result is destructed */ - } - } - break; - - case VT_I1: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_I1REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_I1(var_arg)); - } - break; - - case VT_UI2: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_UI2REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_UI2(var_arg)); - } - break; - - case VT_UI4: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_UI4REF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_UI4(var_arg)); - } - break; - - case VT_INT: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_INTREF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_INT(var_arg)); - } - break; - - case VT_UINT: - if (V_ISBYREF(var_arg)) { - ZVAL_LONG(zval_arg, (long)*V_UINTREF(var_arg)); - } else { - ZVAL_LONG(zval_arg, (long)V_UINT(var_arg)); - } - break; - - default: - rpc_error(E_WARNING, "Unsupported variant type: %d (0x%X)", V_VT(var_arg), V_VT(var_arg)); - ZVAL_NULL(zval_arg); - ret = FAILURE; - break; - } - return ret; -} - - -PHPAPI OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage, int persist) -{ - BOOL error = FALSE; - OLECHAR *unicode_str; - - if (strlen == -1) { - /* request needed buffersize */ - strlen = MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, -1, NULL, 0); - } else { - /* \0 terminator */ - strlen++; - } - - if (strlen >= 0) { - unicode_str = (OLECHAR *) pemalloc(sizeof(OLECHAR) * strlen, persist); - - /* convert string */ - error = !MultiByteToWideChar(codepage, (codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS), C_str, strlen, unicode_str, strlen); - } else { - /* return a zero-length string */ - unicode_str = (OLECHAR *) pemalloc(sizeof(OLECHAR), persist); - *unicode_str = 0; - - error = TRUE; - } - - if (error) { - switch (GetLastError()) { - case ERROR_NO_UNICODE_TRANSLATION: - rpc_error(E_WARNING, "No unicode translation available for the specified string"); - break; - case ERROR_INSUFFICIENT_BUFFER: - rpc_error(E_WARNING, "Internal Error: Insufficient Buffer"); - break; - default: - rpc_error(E_WARNING, "Unknown error in php_char_to_OLECHAR()"); - } - } - - return unicode_str; -} - - -PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int codepage, int persist) -{ - char *C_str; - uint length = 0; - - /* request needed buffersize */ - uint reqSize = WideCharToMultiByte(codepage, codepage == CP_UTF8 ? 0 : WC_COMPOSITECHECK, unicode_str, -1, NULL, 0, NULL, NULL); - - if (reqSize) { - C_str = (char *) pemalloc(sizeof(char) * reqSize, persist); - - /* convert string */ - length = WideCharToMultiByte(codepage, codepage == CP_UTF8 ? 0 : WC_COMPOSITECHECK, unicode_str, -1, C_str, reqSize, NULL, NULL) - 1; - } else { - C_str = (char *) pemalloc(sizeof(char), persist); - *C_str = 0; - - rpc_error(E_WARNING, "Error in php_OLECHAR_to_char()"); - } - - if (out_length) { - *out_length = length; - } - - return C_str; -} - -static int comval_to_variant(zval *object, VARIANT *var_arg) -{ - rpc_internal *intern; - TSRMLS_FETCH(); - - if (GET_INTERNAL_EX(intern, object) != SUCCESS) { - /* TODO exception */ - VariantInit(var_arg); - - return FAILURE; - } else { - V_VT(var_arg) = VT_DISPATCH; - V_DISPATCH(var_arg) = C_DISPATCH((comval *) intern->data); - - return SUCCESS; - } -} - -#endif /* PHP_WIN32 */ diff --git a/ext/rpc/com/conversion.h b/ext/rpc/com/conversion.h deleted file mode 100644 index 0f99063967..0000000000 --- a/ext/rpc/com/conversion.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - | Alan Brown <abrown@pobox.com> | - +----------------------------------------------------------------------+ - */ - -#ifndef CONVERSION_H -#define CONVERSION_H - -/* isn't this defined somewhere else ? */ - -#define Z_TRUE 1 -#define Z_FALSE 0 - -#define VT_TRUE -1 -#define VT_FALSE 0 - -BEGIN_EXTERN_C() - -ZEND_API void php_zval_to_variant(zval *zval_arg, VARIANT *var_arg, int codepage); -ZEND_API void php_zval_to_variant_ex(zval *zval_arg, VARIANT *var_arg, int type, int codepage); -ZEND_API int php_variant_to_zval(VARIANT *var_arg, zval *zval_arg, int codepage); - -ZEND_API OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage, int persist); -ZEND_API char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int codepage, int persist); - -END_EXTERN_C() - -#endif
\ No newline at end of file diff --git a/ext/rpc/com/dispatch.c b/ext/rpc/com/dispatch.c deleted file mode 100644 index dab24d63f9..0000000000 --- a/ext/rpc/com/dispatch.c +++ /dev/null @@ -1,632 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* - * This module is used to export PHP objects to COM and DOTNET by exposing - * them as objects implementing IDispatch. - * */ - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "../rpc.h" - -#include "php.h" -#include "com.h" -#include "com_wrapper.h" -#include "conversion.h" -#include "variant.h" - -#define COBJMACROS -#include <unknwn.h> /* IDispatch */ -#include <dispex.h> /* IDispatchEx */ - - -typedef struct { - /* This first part MUST match the declaration - * of interface IDispatchEx */ - CONST_VTBL struct IDispatchExVtbl *lpVtbl; - - /* now the PHP stuff */ - - THREAD_T engine_thread; /* for sanity checking */ - zval *object; /* the object exported */ - LONG refcount; /* COM reference count */ - - HashTable *dispid_to_name; /* keep track of dispid -> name mappings */ - HashTable *name_to_dispid; /* keep track of name -> dispid mappings */ - - GUID sinkid; /* iid that we "implement" for event sinking */ - - int id; -} php_dispatchex; - -static void disp_destructor(php_dispatchex *disp); - -static void dispatch_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - php_dispatchex *disp = (php_dispatchex *)rsrc->ptr; - disp_destructor(disp); -} - -static int le_dispatch; -int php_COM_dispatch_init(int module_number TSRMLS_DC) -{ - le_dispatch = zend_register_list_destructors_ex(dispatch_dtor, NULL, "COM:Dispatch", module_number); - return le_dispatch; -} - - -/* {{{ trace */ -static inline void trace(char *fmt, ...) -{ - va_list ap; - char buf[4096]; - - sprintf(buf, "T=%08x ", tsrm_thread_id()); - OutputDebugString(buf); - - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - - OutputDebugString(buf); - - va_end(ap); -} -/* }}} */ - -#define FETCH_DISP(methname) \ - php_dispatchex *disp = (php_dispatchex*)This; \ - trace(" PHP:%s %s\n", Z_OBJCE_P(disp->object)->name, methname); \ - if (tsrm_thread_id() != disp->engine_thread) \ - return E_UNEXPECTED; - - -static HRESULT STDMETHODCALLTYPE disp_queryinterface( - IDispatchEx *This, - /* [in] */ REFIID riid, - /* [iid_is][out] */ void **ppvObject) -{ - FETCH_DISP("QueryInterface"); - - if (IsEqualGUID(&IID_IUnknown, riid) || - IsEqualGUID(&IID_IDispatch, riid) || - IsEqualGUID(&IID_IDispatchEx, riid) || - IsEqualGUID(&disp->sinkid, riid)) { - *ppvObject = This; - InterlockedIncrement(&disp->refcount); - return S_OK; - } - - *ppvObject = NULL; - return E_NOINTERFACE; -} - -static ULONG STDMETHODCALLTYPE disp_addref(IDispatchEx *This) -{ - FETCH_DISP("AddRef"); - - return InterlockedIncrement(&disp->refcount); -} - -static ULONG STDMETHODCALLTYPE disp_release(IDispatchEx *This) -{ - ULONG ret; - TSRMLS_FETCH(); - FETCH_DISP("Release"); - - ret = InterlockedDecrement(&disp->refcount); - trace("-- refcount now %d\n", ret); - if (ret == 0) { - /* destroy it */ - if (disp->id) - zend_list_delete(disp->id); - } - return ret; -} - -static HRESULT STDMETHODCALLTYPE disp_gettypeinfocount( - IDispatchEx *This, - /* [out] */ UINT *pctinfo) -{ - FETCH_DISP("GetTypeInfoCount"); - - *pctinfo = 0; - return S_OK; -} - -static HRESULT STDMETHODCALLTYPE disp_gettypeinfo( - IDispatchEx *This, - /* [in] */ UINT iTInfo, - /* [in] */ LCID lcid, - /* [out] */ ITypeInfo **ppTInfo) -{ - FETCH_DISP("GetTypeInfo"); - - *ppTInfo = NULL; - return DISP_E_BADINDEX; -} - -static HRESULT STDMETHODCALLTYPE disp_getidsofnames( - IDispatchEx *This, - /* [in] */ REFIID riid, - /* [size_is][in] */ LPOLESTR *rgszNames, - /* [in] */ UINT cNames, - /* [in] */ LCID lcid, - /* [size_is][out] */ DISPID *rgDispId) -{ - UINT i; - HRESULT ret = S_OK; - TSRMLS_FETCH(); - FETCH_DISP("GetIDsOfNames"); - - for (i = 0; i < cNames; i++) { - char *name; - unsigned int namelen; - zval **tmp; - - name = php_OLECHAR_to_char(rgszNames[i], &namelen, CP_ACP, FALSE); - - /* Lookup the name in the hash */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == FAILURE) { - ret = DISP_E_UNKNOWNNAME; - rgDispId[i] = 0; - } else { - rgDispId[i] = Z_LVAL_PP(tmp); - } - - efree(name); - - } - - return ret; -} - -static HRESULT STDMETHODCALLTYPE disp_invoke( - IDispatchEx *This, - /* [in] */ DISPID dispIdMember, - /* [in] */ REFIID riid, - /* [in] */ LCID lcid, - /* [in] */ WORD wFlags, - /* [out][in] */ DISPPARAMS *pDispParams, - /* [out] */ VARIANT *pVarResult, - /* [out] */ EXCEPINFO *pExcepInfo, - /* [out] */ UINT *puArgErr) -{ - return This->lpVtbl->InvokeEx(This, dispIdMember, - lcid, wFlags, pDispParams, - pVarResult, pExcepInfo, NULL); -} - -static HRESULT STDMETHODCALLTYPE disp_getdispid( - IDispatchEx *This, - /* [in] */ BSTR bstrName, - /* [in] */ DWORD grfdex, - /* [out] */ DISPID *pid) -{ - HRESULT ret = DISP_E_UNKNOWNNAME; - char *name; - unsigned int namelen; - zval **tmp; - TSRMLS_FETCH(); - FETCH_DISP("GetDispID"); - - name = php_OLECHAR_to_char(bstrName, &namelen, CP_ACP, FALSE); - - /* Lookup the name in the hash */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) { - *pid = Z_LVAL_PP(tmp); - ret = S_OK; - } - - efree(name); - - return ret; -} - -static HRESULT STDMETHODCALLTYPE disp_invokeex( - IDispatchEx *This, - /* [in] */ DISPID id, - /* [in] */ LCID lcid, - /* [in] */ WORD wFlags, - /* [in] */ DISPPARAMS *pdp, - /* [out] */ VARIANT *pvarRes, - /* [out] */ EXCEPINFO *pei, - /* [unique][in] */ IServiceProvider *pspCaller) -{ - zval **name; - UINT i; - int codepage = CP_ACP; - zval *retval = NULL; - zval ***params = NULL; - HRESULT ret = DISP_E_MEMBERNOTFOUND; - TSRMLS_FETCH(); - FETCH_DISP("InvokeEx"); - - if (SUCCESS == zend_hash_index_find(disp->dispid_to_name, id, (void**)&name)) { - /* TODO: add support for overloaded objects */ - - trace("-- Invoke: %d %20s flags=%08x args=%d\n", id, Z_STRVAL_PP(name), wFlags, pdp->cArgs); - - /* convert args into zvals. - * Args are in reverse order */ - params = (zval ***)emalloc(sizeof(zval **) * pdp->cArgs); - for (i = 0; i < pdp->cArgs; i++) { - VARIANT *arg; - zval *zarg; - - arg = &pdp->rgvarg[ pdp->cArgs - 1 - i]; - - trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg)); - - ALLOC_INIT_ZVAL(zarg); - - if (V_VT(arg) == VT_DISPATCH) { - trace("arg %d is dispatchable\n", i); - if ((zarg = php_COM_object_from_dispatch(V_DISPATCH(arg))) == NULL) { - trace("failed to convert arg %d to zval\n", i); - ZVAL_NULL(zarg); - } - } else { - /* arg can't be an idispatch, so we don't care for the implicit AddRef() call here */ - if (FAILURE == php_variant_to_zval(arg, zarg, codepage)) { - trace("failed to convert arg %d to zval\n", i); - ZVAL_NULL(zarg); - } - } - - params[i] = &zarg; - } - - trace("arguments processed, prepare to do some work\n"); - - if (wFlags & DISPATCH_PROPERTYGET) { - trace("trying to get a property\n"); - zend_hash_find(Z_OBJPROP_P(disp->object), Z_STRVAL_PP(name), Z_STRLEN_PP(name)+1, (void**)&retval); - } else if (wFlags & DISPATCH_PROPERTYPUT) { - trace("trying to set a property\n"); - add_property_zval(disp->object, Z_STRVAL_PP(name), *params[0]); - } else if (wFlags & DISPATCH_METHOD) { - trace("Trying to call user function\n"); - if (SUCCESS == call_user_function_ex(EG(function_table), &disp->object, *name, - &retval, pdp->cArgs, params, 1, NULL TSRMLS_CC)) { - ret = S_OK; - } else { - ret = DISP_E_EXCEPTION; - } - } else { - trace("Don't know how to handle this invocation %08x\n", wFlags); - } - - /* release arguments */ - for (i = 0; i < pdp->cArgs; i++) - zval_ptr_dtor(params[i]); - efree(params); - - /* return value */ - if (retval) { - if (pvarRes) { - if (Z_TYPE_P(retval) == IS_OBJECT) { - /* export the object using a dispatch like ourselves */ - VariantInit(pvarRes); - V_VT(pvarRes) = VT_DISPATCH; - V_DISPATCH(pvarRes) = php_COM_export_object(retval); - } else { - php_zval_to_variant(retval, pvarRes, codepage); - } - } - zval_ptr_dtor(&retval); - } else if (pvarRes) { - VariantInit(pvarRes); - } - - } else { - trace("InvokeEx: I don't support DISPID=%d\n", id); - } - - return ret; -} - -static HRESULT STDMETHODCALLTYPE disp_deletememberbyname( - IDispatchEx *This, - /* [in] */ BSTR bstrName, - /* [in] */ DWORD grfdex) -{ - FETCH_DISP("DeleteMemberByName"); - - return S_FALSE; -} - -static HRESULT STDMETHODCALLTYPE disp_deletememberbydispid( - IDispatchEx *This, - /* [in] */ DISPID id) -{ - FETCH_DISP("DeleteMemberByDispID"); - - return S_FALSE; -} - -static HRESULT STDMETHODCALLTYPE disp_getmemberproperties( - IDispatchEx *This, - /* [in] */ DISPID id, - /* [in] */ DWORD grfdexFetch, - /* [out] */ DWORD *pgrfdex) -{ - FETCH_DISP("GetMemberProperties"); - - return DISP_E_UNKNOWNNAME; -} - -static HRESULT STDMETHODCALLTYPE disp_getmembername( - IDispatchEx *This, - /* [in] */ DISPID id, - /* [out] */ BSTR *pbstrName) -{ - zval *name; - TSRMLS_FETCH(); - FETCH_DISP("GetMemberName"); - - if (SUCCESS == zend_hash_index_find(disp->dispid_to_name, id, (void**)&name)) { - OLECHAR *olestr = php_char_to_OLECHAR(Z_STRVAL_P(name), Z_STRLEN_P(name), CP_ACP, FALSE); - *pbstrName = SysAllocString(olestr); - efree(olestr); - return S_OK; - } else { - return DISP_E_UNKNOWNNAME; - } -} - -static HRESULT STDMETHODCALLTYPE disp_getnextdispid( - IDispatchEx *This, - /* [in] */ DWORD grfdex, - /* [in] */ DISPID id, - /* [out] */ DISPID *pid) -{ - ulong next = id+1; - FETCH_DISP("GetNextDispID"); - - while(!zend_hash_index_exists(disp->dispid_to_name, next)) - next++; - - if (zend_hash_index_exists(disp->dispid_to_name, next)) { - *pid = next; - return S_OK; - } - return S_FALSE; -} - -static HRESULT STDMETHODCALLTYPE disp_getnamespaceparent( - IDispatchEx *This, - /* [out] */ IUnknown **ppunk) -{ - FETCH_DISP("GetNameSpaceParent"); - - *ppunk = NULL; - return E_NOTIMPL; -} - -static struct IDispatchExVtbl php_dispatch_vtbl = { - disp_queryinterface, - disp_addref, - disp_release, - disp_gettypeinfocount, - disp_gettypeinfo, - disp_getidsofnames, - disp_invoke, - disp_getdispid, - disp_invokeex, - disp_deletememberbyname, - disp_deletememberbydispid, - disp_getmemberproperties, - disp_getmembername, - disp_getnextdispid, - disp_getnamespaceparent -}; - - -/* enumerate functions and properties of the object and assign - * dispatch ids */ -static void generate_dispids(php_dispatchex *disp TSRMLS_DC) -{ - HashPosition pos; - char *name = NULL; - zval *tmp; - int namelen; - int keytype; - ulong pid; - - if (disp->dispid_to_name == NULL) { - ALLOC_HASHTABLE(disp->dispid_to_name); - ALLOC_HASHTABLE(disp->name_to_dispid); - zend_hash_init(disp->name_to_dispid, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_init(disp->dispid_to_name, 0, NULL, ZVAL_PTR_DTOR, 0); - } - - /* properties */ - zend_hash_internal_pointer_reset_ex(Z_OBJPROP_PP(&disp->object), &pos); - while (HASH_KEY_NON_EXISTANT != (keytype = - zend_hash_get_current_key_ex(Z_OBJPROP_PP(&disp->object), &name, &namelen, &pid, 0, &pos))) { - char namebuf[32]; - if (keytype == HASH_KEY_IS_LONG) { - sprintf(namebuf, "%d", pid); - name = namebuf; - namelen = strlen(namebuf); - } - - zend_hash_move_forward_ex(Z_OBJPROP_PP(&disp->object), &pos); - - /* Find the existing id */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) - continue; - - /* add the mappings */ - MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, name, namelen, 1); - zend_hash_index_update(disp->dispid_to_name, pid, (void*)&tmp, sizeof(zval *), NULL); - - MAKE_STD_ZVAL(tmp); - ZVAL_LONG(tmp, pid); - zend_hash_update(disp->name_to_dispid, name, namelen+1, (void*)&tmp, sizeof(zval *), NULL); - - } - - /* functions */ - zend_hash_internal_pointer_reset_ex(&Z_OBJCE_PP(&disp->object)->function_table, &pos); - while (HASH_KEY_NON_EXISTANT != (keytype = - zend_hash_get_current_key_ex(&Z_OBJCE_PP(&disp->object)->function_table, &name, &namelen, &pid, 0, &pos))) { - - char namebuf[32]; - if (keytype == HASH_KEY_IS_LONG) { - sprintf(namebuf, "%d", pid); - name = namebuf; - namelen = strlen(namebuf); - } - - zend_hash_move_forward_ex(Z_OBJPROP_PP(&disp->object), &pos); - - /* Find the existing id */ - if (zend_hash_find(disp->name_to_dispid, name, namelen+1, (void**)&tmp) == SUCCESS) - continue; - - /* add the mappings */ - MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, name, namelen, 1); - zend_hash_index_update(disp->dispid_to_name, pid, (void*)&tmp, sizeof(zval *), NULL); - - MAKE_STD_ZVAL(tmp); - ZVAL_LONG(tmp, pid); - zend_hash_update(disp->name_to_dispid, name, namelen+1, (void*)&tmp, sizeof(zval *), NULL); - } -} - -static php_dispatchex *disp_constructor(zval *object) -{ - php_dispatchex *disp = (php_dispatchex*)CoTaskMemAlloc(sizeof(php_dispatchex)); - - trace("constructing a COM proxy\n"); - - if (disp == NULL) - return NULL; - - memset(disp, 0, sizeof(php_dispatchex)); - - disp->engine_thread = tsrm_thread_id(); - disp->lpVtbl = &php_dispatch_vtbl; - disp->refcount = 1; - - - if (object) - ZVAL_ADDREF(object); - disp->object = object; - - disp->id = zend_list_insert(disp, le_dispatch); - - return disp; -} - -static void disp_destructor(php_dispatchex *disp) -{ - TSRMLS_FETCH(); - - trace("destroying COM wrapper for PHP object %s\n", Z_OBJCE_P(disp->object)->name); - - disp->id = 0; - - if (disp->refcount > 0) - CoDisconnectObject((IUnknown*)disp, 0); - - zend_hash_destroy(disp->dispid_to_name); - zend_hash_destroy(disp->name_to_dispid); - FREE_HASHTABLE(disp->dispid_to_name); - FREE_HASHTABLE(disp->name_to_dispid); - - if (disp->object) - zval_ptr_dtor(&disp->object); - - - CoTaskMemFree(disp); -} - -PHPAPI IDispatch *php_COM_export_as_sink(zval *val, GUID *sinkid, HashTable *id_to_name) -{ - php_dispatchex *disp = disp_constructor(val); - HashPosition pos; - char *name = NULL; - zval *tmp, **ntmp; - int namelen; - int keytype; - ulong pid; - - disp->dispid_to_name = id_to_name; - - memcpy(&disp->sinkid, sinkid, sizeof(disp->sinkid)); - - /* build up the reverse mapping */ - ALLOC_HASHTABLE(disp->name_to_dispid); - zend_hash_init(disp->name_to_dispid, 0, NULL, ZVAL_PTR_DTOR, 0); - - zend_hash_internal_pointer_reset_ex(id_to_name, &pos); - while (HASH_KEY_NON_EXISTANT != (keytype = - zend_hash_get_current_key_ex(id_to_name, &name, &namelen, &pid, 0, &pos))) { - - if (keytype == HASH_KEY_IS_LONG) { - - zend_hash_get_current_data_ex(id_to_name, (void**)&ntmp, &pos); - - MAKE_STD_ZVAL(tmp); - ZVAL_LONG(tmp, pid); - zend_hash_update(disp->name_to_dispid, Z_STRVAL_PP(ntmp), Z_STRLEN_PP(ntmp)+1, (void*)&tmp, sizeof(zval *), NULL); - } - - zend_hash_move_forward_ex(id_to_name, &pos); - } - - return (IDispatch*)disp; -} - -PHPAPI IDispatch *php_COM_export_object(zval *val) -{ - php_dispatchex *disp = NULL; - TSRMLS_FETCH(); - - if (Z_TYPE_P(val) != IS_OBJECT) - return NULL; - - if (Z_OBJCE_P(val) == com_class_entry) { - /* pass back it's IDispatch directly */ - comval *obj; - rpc_internal *intern; - - if (GET_INTERNAL_EX(intern, val) != SUCCESS) { - /* TODO: exception */ - } - - obj = (comval *) intern->data; - - C_DISPATCH(obj)->lpVtbl->AddRef(C_DISPATCH(obj)); - return C_DISPATCH(obj); - } - - disp = disp_constructor(val); - generate_dispids(disp TSRMLS_CC); - - return (IDispatch*)disp; -} - - diff --git a/ext/rpc/com/php_com.h b/ext/rpc/com/php_com.h deleted file mode 100644 index 6a3fb61d7b..0000000000 --- a/ext/rpc/com/php_com.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_COM_H -#define PHP_COM_H - -extern zend_module_entry com_module_entry; -#define phpext_com_ptr &com_module_entry - -#endif /* PHP_COM_H */
\ No newline at end of file diff --git a/ext/rpc/com/variant.c b/ext/rpc/com/variant.c deleted file mode 100644 index 7810049b7a..0000000000 --- a/ext/rpc/com/variant.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - | Alan Brown <abrown@pobox.com> | - +----------------------------------------------------------------------+ - */ - - -/* - * This module maps the VARIANT datastructure into PHP so that it can be used to - * pass values to COM and DOTNET Objects by reference and not only by value. - * - * harald - */ - -#ifdef PHP_WIN32 - -#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "conversion.h" -#include "variant.h" - -#include "../php_rpc.h" - -#include <unknwn.h> - -static zend_object_value variant_objects_new(zend_class_entry * TSRMLS_DC); -static void variant_objects_delete(void *, zend_object_handle TSRMLS_DC); - -/* object handler */ -static zval* variant_read(zval *, zval * TSRMLS_DC); -static void variant_write(zval *, zval *, zval * TSRMLS_DC); -static union _zend_function* variant_get_constructor(zval * TSRMLS_DC); -static zend_class_entry* variant_get_class_entry(zval * TSRMLS_DC); -/**/ - -static HashTable types; -static zend_class_entry *variant_class_entry; -static zend_function *variant_ctor; -static zend_object_handlers variant_handlers = { - ZEND_OBJECTS_STORE_HANDLERS, - - variant_read, - variant_write, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - variant_get_constructor, - variant_get_class_entry, - NULL, - NULL -}; - -/**/ -void php_variant_init(int module_number TSRMLS_DC) -{ - zend_internal_function *zif; - zend_class_entry ce; - int type; - - /* variant datatypes */ - REGISTER_LONG_CONSTANT("VT_NULL", VT_NULL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_EMPTY", VT_EMPTY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_UI1", VT_UI1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_I2", VT_I2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_I4", VT_I4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_R4", VT_R4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_R8", VT_R8, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_BOOL", VT_BOOL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_ERROR", VT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_CY", VT_CY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_DATE", VT_DATE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_BSTR", VT_BSTR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_DECIMAL", VT_DECIMAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_UNKNOWN", VT_UNKNOWN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_DISPATCH", VT_DISPATCH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_VARIANT", VT_VARIANT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_I1", VT_I1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_UI2", VT_UI2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_UI4", VT_UI4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_INT", VT_INT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_UINT", VT_UINT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_ARRAY", VT_ARRAY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VT_BYREF", VT_BYREF, CONST_CS | CONST_PERSISTENT); - - /* codepages */ - REGISTER_LONG_CONSTANT("CP_ACP", CP_ACP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CP_MACCP", CP_MACCP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CP_OEMCP", CP_OEMCP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CP_UTF7", CP_UTF7, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CP_UTF8", CP_UTF8, CONST_CS | CONST_PERSISTENT); - -#ifdef CP_SYMBOL - REGISTER_LONG_CONSTANT("CP_SYMBOL", CP_SYMBOL, CONST_CS | CONST_PERSISTENT); -#else -#error "CP_SYMBOL undefined" -#endif -#ifdef CP_THREAD_ACP - REGISTER_LONG_CONSTANT("CP_THREAD_ACP", CP_THREAD_ACP, CONST_CS | CONST_PERSISTENT); -#else -#error "CP_THREAD_ACP undefined" -#endif - - INIT_CLASS_ENTRY(ce, "variant", NULL); - ce.create_object = variant_objects_new; - variant_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - - zif = (zend_internal_function *) emalloc(sizeof(zend_internal_function)); - - zif->type = ZEND_INTERNAL_FUNCTION; - zif->function_name = variant_class_entry->name; - zif->scope = variant_class_entry; - zif->arg_types = NULL; - zif->handler = ZEND_FN(variant_load); - - /* add new constructor to the method table */ - zend_hash_add(&(variant_class_entry->function_table), variant_class_entry->name, - variant_class_entry->name_length + 1, zif, sizeof(zend_function), &variant_ctor); - efree(zif); - - zend_hash_init(&types, 0, NULL, NULL, TRUE); - - type = VT_UI1; - zend_hash_add(&types, "bVal", 5, (void *) &type, sizeof(int), NULL); - type = VT_UI2; - zend_hash_add(&types, "uiVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_UI4; - zend_hash_add(&types, "ulVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_UINT; - zend_hash_add(&types, "uintVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_I1; - zend_hash_add(&types, "cVal", 5, (void *) &type, sizeof(int), NULL); - type = VT_I2; - zend_hash_add(&types, "iVal", 5, (void *) &type, sizeof(int), NULL); - type = VT_I4; - zend_hash_add(&types, "lVal", 5, (void *) &type, sizeof(int), NULL); - type = VT_INT; - zend_hash_add(&types, "intVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_R4; - zend_hash_add(&types, "fltVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_R8; - zend_hash_add(&types, "dblVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_BOOL; - zend_hash_add(&types, "boolVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_ERROR; - zend_hash_add(&types, "scode", 6, (void *) &type, sizeof(int), NULL); - type = VT_CY; - zend_hash_add(&types, "cyVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_DATE; - zend_hash_add(&types, "date", 5, (void *) &type, sizeof(int), NULL); - type = VT_BSTR; - zend_hash_add(&types, "bstrVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_UNKNOWN; - zend_hash_add(&types, "punkVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_DISPATCH; - zend_hash_add(&types, "pdispVal", 9, (void *) &type, sizeof(int), NULL); - type = VT_ARRAY; - zend_hash_add(&types, "parray", 7, (void *) &type, sizeof(int), NULL); - type = VT_BYREF; - zend_hash_add(&types, "byref", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_UI1; - zend_hash_add(&types, "pbVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_UI2; - zend_hash_add(&types, "puiVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_UI4; - zend_hash_add(&types, "pulVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_UINT; - zend_hash_add(&types, "puintVal", 9, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_I1; - zend_hash_add(&types, "pcVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_I2; - zend_hash_add(&types, "piVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_I4; - zend_hash_add(&types, "plVal", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_INT; - zend_hash_add(&types, "pintVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_R4; - zend_hash_add(&types, "pfltVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_R8; - zend_hash_add(&types, "pdblVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_BOOL; - zend_hash_add(&types, "pboolVal", 9, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_ERROR; - zend_hash_add(&types, "pscode", 7, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_CY; - zend_hash_add(&types, "pcyVal", 7, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_DATE; - zend_hash_add(&types, "pdate", 6, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_BSTR; - zend_hash_add(&types, "pbstrVal", 9, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_DECIMAL; - zend_hash_add(&types, "pdecVal", 8, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_UNKNOWN; - zend_hash_add(&types, "ppunkVal", 9, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_DISPATCH; - zend_hash_add(&types, "ppdispVal", 10, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_ARRAY; - zend_hash_add(&types, "pparray", 8, (void *) &type, sizeof(int), NULL); - type = VT_BYREF|VT_VARIANT; - zend_hash_add(&types, "pvarVal", 8, (void *) &type, sizeof(int), NULL); -} - -void php_variant_shutdown(TSRMLS_D) -{ - zend_hash_destroy(&types); -} - -static zend_object_value variant_objects_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value *zov; - variantval *var; - - ALLOC_VARIANT(var); - - /* set up the object value struct */ - zov = (zend_object_value*) emalloc(sizeof(zend_object_value)); - zov->handlers = &variant_handlers; - zov->handle = zend_objects_store_put(var, variant_objects_delete, NULL TSRMLS_CC); - - return *zov; -} - -static void variant_objects_delete(void *object, zend_object_handle handle TSRMLS_DC) -{ - FREE_VARIANT((variantval *)object); -} - -static zval* variant_read(zval *object, zval *member TSRMLS_DC) -{ - variantval *var; - zval *result; - - ALLOC_ZVAL(result); - - if ((var = zend_object_store_get_object(object TSRMLS_CC)) == NULL) { - /* exception */ - } - - if (!strcmp(Z_STRVAL_P(member), "value")) { - /* var_arg can't be an idispatch, so we don't care for the implicit AddRef() call here */ - php_variant_to_zval(var->var, result, var->codepage); - } else if (!strcmp(Z_STRVAL_P(member), "type")) { - ZVAL_LONG(result, V_VT(var->var)); - } else { - ZVAL_FALSE(result); - rpc_error(E_WARNING, "Unknown member."); - } - - return result; -} - -static void variant_write(zval *object, zval *member, zval *value TSRMLS_DC) -{ - int *type; - variantval *var; - - if ((var = zend_object_store_get_object(object TSRMLS_CC)) == NULL) { - /* exception */ - } - - if (!strcmp(Z_STRVAL_P(member), "value")) { - php_zval_to_variant(value, var->var, var->codepage); - } else if (zend_hash_find(&types, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **) &type) == SUCCESS) { - php_zval_to_variant_ex(value, var->var, *type, var->codepage); - } else { - rpc_error(E_WARNING, "Unknown member."); - } -} - -static union _zend_function* variant_get_constructor(zval *object TSRMLS_DC) -{ - return variant_ctor; -} - -static zend_class_entry* variant_get_class_entry(zval *object TSRMLS_DC) -{ - return variant_class_entry; -} - -/**/ -/* constructor */ -ZEND_FUNCTION(variant_load) -{ - zval *value = NULL, *object = getThis(); - variantval *var; - long type = 0; - - if (!object || ((var = zend_object_store_get_object(object TSRMLS_CC)) == NULL)) { - /*TODO exception */ - } - - zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zll", &value, &type, &(var->codepage)); - - if (value) { - if (type) { - php_zval_to_variant_ex(value, var->var, type, var->codepage); - } else { - php_zval_to_variant(value, var->var, var->codepage); - } - } -} - -#endif /* PHP_WIN32 */ diff --git a/ext/rpc/com/variant.h b/ext/rpc/com/variant.h deleted file mode 100644 index e8c3539572..0000000000 --- a/ext/rpc/com/variant.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Harald Radi <h.radi@nme.at> | - +----------------------------------------------------------------------+ - */ - - -#ifndef VARIANT_H -#define VARIANT_H - -#if PHP_WIN32 - -#define ALLOC_VARIANT(v) (v) = (variantval *) emalloc(sizeof(variantval)); \ - (v)->var = (VARIANT *) emalloc(sizeof(VARIANT)); \ - (v)->codepage = CP_ACP; \ - VariantInit((v)->var); - -#define FREE_VARIANT(v) VariantClear((v)->var); \ - efree((v)->var); \ - efree((v)); - -#define ZVAL_VARIANT(z, v, cp) \ - if (V_VT(v) == VT_DISPATCH && V_DISPATCH(v) == NULL) { \ - V_VT(v) = VT_NULL; \ - } \ - if (V_VT(v) == VT_DISPATCH) { \ - comval *obj; \ - ALLOC_COM(obj); \ - php_COM_set(obj, &V_DISPATCH(v), TRUE); \ - rpc_object_from_data_ex(z, com, obj, NULL); \ - } else { \ - php_variant_to_zval((v), (z), cp); \ - VariantClear(v); \ - } - -#define RETVAL_VARIANT(v, cp) ZVAL_VARIANT(return_value, v, cp) -#define RETURN_VARIANT(v, cp) RETVAL_VARIANT(v, cp) \ - return; - -typedef struct variantval_ { - VARIANT* var; - long codepage; -} variantval; - -void php_variant_init(int module_number TSRMLS_DC); -void php_variant_shutdown(TSRMLS_D); - -ZEND_FUNCTION(variant_load); - -#endif /* PHP_WIN32 */ - -#endif /* VARIANT_H */ |