diff options
author | SVN Migration <svn@php.net> | 2001-08-08 15:06:09 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2001-08-08 15:06:09 +0000 |
commit | 22909a77ef3489ef6be3c860d0002ea66c4436f0 (patch) | |
tree | 480ca7c565161cc36eddc9f8eee073ef10be3019 /ext/rpc | |
parent | 2f6cd308f9a8c53e0ce359603f4746b27bc32356 (diff) | |
download | php-git-PRE_METHOD_DEREFERENCE_PATCH.tar.gz |
This commit was manufactured by cvs2svn to create tagPRE_METHOD_DEREFERENCE_PATCH
'PRE_METHOD_DEREFERENCE_PATCH'.
Diffstat (limited to 'ext/rpc')
-rw-r--r-- | ext/rpc/CREDITS | 2 | ||||
-rw-r--r-- | ext/rpc/Makefile.in | 25 | ||||
-rw-r--r-- | ext/rpc/com/CREDITS | 2 | ||||
-rw-r--r-- | ext/rpc/com/com_wrapper.c | 1726 | ||||
-rw-r--r-- | ext/rpc/com/com_wrapper.h | 65 | ||||
-rw-r--r-- | ext/rpc/com/conversion.c | 916 | ||||
-rw-r--r-- | ext/rpc/com/conversion.h | 14 | ||||
-rw-r--r-- | ext/rpc/com/php_com.h | 44 | ||||
-rw-r--r-- | ext/rpc/com/php_variant.h | 25 | ||||
-rw-r--r-- | ext/rpc/com/variant.c | 438 | ||||
-rw-r--r-- | ext/rpc/com/variant.h | 11 | ||||
-rw-r--r-- | ext/rpc/dotnet/CREDITS | 2 | ||||
-rw-r--r-- | ext/rpc/dotnet/EXPERIMENTAL | 5 | ||||
-rw-r--r-- | ext/rpc/dotnet/README | 32 | ||||
-rw-r--r-- | ext/rpc/dotnet/dotnet.cpp | 239 | ||||
-rw-r--r-- | ext/rpc/dotnet/dotnet.dsp | 171 | ||||
-rw-r--r-- | ext/rpc/dotnet/dotnet.php | 8 | ||||
-rw-r--r-- | ext/rpc/dotnet/php_dotnet.h | 21 | ||||
-rw-r--r-- | ext/rpc/java/CREDITS | 2 | ||||
-rw-r--r-- | ext/rpc/java/Makefile.in | 25 | ||||
-rw-r--r-- | ext/rpc/java/README | 243 | ||||
-rw-r--r-- | ext/rpc/java/config.m4 | 118 | ||||
-rw-r--r-- | ext/rpc/java/except.php | 23 | ||||
-rw-r--r-- | ext/rpc/java/java.c | 774 | ||||
-rw-r--r-- | ext/rpc/java/java.dsp | 258 | ||||
-rw-r--r-- | ext/rpc/java/jawt.php | 27 | ||||
-rw-r--r-- | ext/rpc/java/jver.php | 17 | ||||
-rw-r--r-- | ext/rpc/java/reflect.java | 419 |
28 files changed, 0 insertions, 5652 deletions
diff --git a/ext/rpc/CREDITS b/ext/rpc/CREDITS deleted file mode 100644 index f49489bcf8..0000000000 --- a/ext/rpc/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Java -Sam Ruby diff --git a/ext/rpc/Makefile.in b/ext/rpc/Makefile.in deleted file mode 100644 index 2a980157d2..0000000000 --- a/ext/rpc/Makefile.in +++ /dev/null @@ -1,25 +0,0 @@ - -LTLIBRARY_SHARED_NAME = libphp_java.la -LTLIBRARY_SOURCES = java.c -LTLIBRARY_DEPENDENCIES = php_java.jar - -LTLIBRARY_LDFLAGS = $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) -LTLIBRARY_SHARED_LIBADD = $(LTLIBRARY_DEPENDENCIES) $(EXTRA_LIBS) - -EXTRA_CFLAGS = $(JAVA_CFLAGS) -EXTRA_INCLUDES = $(JAVA_INCLUDE) - -make_shared = yes - -include $(top_srcdir)/build/dynlib.mk - -php_java.jar : reflect.java - $(mkinstalldirs) net/php - @cp $(srcdir)/reflect.java net/php - @echo library=php_java>net/php/reflect.properties - javac net/php/reflect.java - @test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac - $(JAVA_JAR) php_java.jar net/php/*.class net/php/*.properties - @rm net/php/reflect.* - @rmdir net/php - @rmdir net diff --git a/ext/rpc/com/CREDITS b/ext/rpc/com/CREDITS deleted file mode 100644 index 27bb7a0b21..0000000000 --- a/ext/rpc/com/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Win32 COM -Zeev Suraski, Harald Radi, Alan Brown
\ 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 9d6648044b..0000000000 --- a/ext/rpc/com/com_wrapper.c +++ /dev/null @@ -1,1726 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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> | - +----------------------------------------------------------------------+ - */ - -/* - * 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 <iostream.h> -#include <math.h> - -#include "php.h" -#include "php_ini.h" - -#include "com.h" -#include "conversion.h" -#include "php_VARIANT.h" - -zend_class_entry com_class_entry; - -PHP_FUNCTION(com_load); -PHP_FUNCTION(com_invoke); -PHP_FUNCTION(com_addref); -PHP_FUNCTION(com_release); -PHP_FUNCTION(com_propget); -PHP_FUNCTION(com_propput); -PHP_FUNCTION(com_load_typelib); -PHP_FUNCTION(com_isenum); - -PHPAPI HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult); -PHPAPI HRESULT php_COM_get_ids_of_names(comval *obj, OLECHAR FAR* FAR* rgszNames, DISPID FAR* rgDispId); -PHPAPI HRESULT php_COM_release(comval *obj); -PHPAPI HRESULT php_COM_addref(comval *obj); -PHPAPI HRESULT php_COM_set(comval *obj, IDispatch FAR* pDisp, int cleanup); -PHPAPI HRESULT php_COM_clone(comval *obj, comval *clone, int cleanup); - -PHPAPI int php_COM_get_le_comval(); -static ITypeLib *php_COM_find_typelib(char *search_string, int mode); -static int php_COM_load_typelib(ITypeLib *TypeLib, int mode TSRMLS_DC); - -static int le_comval; -static int codepage; - -#ifdef _DEBUG -int resourcecounter = 1; -#endif - -function_entry COM_functions[] = { - PHP_FE(com_load, NULL) - PHP_FE(com_invoke, NULL) - PHP_FE(com_addref, NULL) - PHP_FE(com_release, NULL) - PHP_FE(com_propget, NULL) - PHP_FE(com_propput, NULL) - PHP_FE(com_load_typelib, NULL) - PHP_FE(com_isenum, NULL) - - PHP_FALIAS(com_get, com_propget, NULL) - PHP_FALIAS(com_propset, com_propput, NULL) - PHP_FALIAS(com_set, com_propput, NULL) - - - { - NULL, NULL, NULL - } -}; - -static PHP_MINFO_FUNCTION(COM) -{ - DISPLAY_INI_ENTRIES(); -} - -PHPAPI HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult) -{ - HRESULT hr; - int failed = FALSE; - - if(C_ISREFD(obj)) - { - if(C_HASTLIB(obj)) - { - hr = C_TYPEINFO_VT(obj)->Invoke(C_TYPEINFO(obj), C_DISPATCH(obj), dispIdMember, wFlags, pDispParams, pVarResult, NULL, NULL); - if(FAILED(hr)) - { - hr = C_DISPATCH_VT(obj)->Invoke(C_DISPATCH(obj), dispIdMember, &IID_NULL, LOCALE_SYSTEM_DEFAULT, wFlags, pDispParams, pVarResult, NULL, NULL); - 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, NULL, NULL); - } - - return hr; - } - else - { - return DISP_E_UNKNOWNINTERFACE; - } -} - -PHPAPI HRESULT php_COM_get_ids_of_names(comval *obj, OLECHAR FAR* FAR* rgszNames, DISPID FAR* rgDispId) -{ - HRESULT hr; - - if(C_ISREFD(obj)) - { - 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; - } - else - { - return DISP_E_UNKNOWNINTERFACE; - } -} - -PHPAPI HRESULT php_COM_release(comval *obj) -{ - if(obj->refcount > 1) - { - C_RELEASE(obj); - } - else if(obj->refcount == 1) - { - if(C_HASTLIB(obj)) - { - C_TYPEINFO_VT(obj)->Release(C_TYPEINFO(obj)); - } - if(C_HASENUM(obj)) - { - C_ENUMVARIANT_VT(obj)->Release(C_ENUMVARIANT(obj)); - } - C_DISPATCH_VT(obj)->Release(C_DISPATCH(obj)); - C_RELEASE(obj); - } - - return obj->refcount; -} - -PHPAPI HRESULT php_COM_addref(comval *obj) -{ - if(C_ISREFD(obj)) - { - C_ADDREF(obj); - } - - return obj->refcount; -} - -PHPAPI HRESULT php_COM_set(comval *obj, IDispatch FAR* pDisp, int cleanup) -{ - HRESULT hr = 1; - DISPPARAMS dispparams; - VARIANT var_result; - - VariantInit(&var_result); - C_REFCOUNT(obj) = 1; - 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; - - 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, &var_result, NULL, NULL))) - { - if (V_VT(&var_result) == VT_UNKNOWN) - { - C_HASENUM(obj) = SUCCEEDED(V_UNKNOWN(&var_result)->lpVtbl->QueryInterface(V_UNKNOWN(&var_result), &IID_IEnumVARIANT, - (void**)&C_ENUMVARIANT(obj))); - } - else if (V_VT(&var_result) == VT_DISPATCH) - { - C_HASENUM(obj) = SUCCEEDED(V_DISPATCH(&var_result)->lpVtbl->QueryInterface(V_DISPATCH(&var_result), &IID_IEnumVARIANT, - (void**)&C_ENUMVARIANT(obj))); - } - - } - - if(!cleanup) - { - hr = C_DISPATCH_VT(obj)->AddRef(C_DISPATCH(obj)); - } - -#ifdef _DEBUG - obj->resourceindex = resourcecounter++; -#endif - - return hr; -} - -PHPAPI HRESULT php_COM_clone(comval *obj, comval *clone, int cleanup) -{ - HRESULT hr; - - C_HASTLIB(obj) = C_HASTLIB(clone); - C_HASENUM(obj) = C_HASENUM(obj); - C_DISPATCH(obj) = C_DISPATCH(clone); - C_TYPEINFO(obj) = C_TYPEINFO(clone); - - if(cleanup || !C_ISREFD(obj)) - { - obj->refcount = clone->refcount; - clone->refcount = 0; - } - else - { - if(C_HASTLIB(obj)) - { - C_TYPEINFO_VT(obj)->AddRef(C_TYPEINFO(obj)); - } - if(C_HASENUM(obj)) - { - C_ENUMVARIANT_VT(obj)->AddRef(C_ENUMVARIANT(obj)); - } - hr = C_DISPATCH_VT(obj)->AddRef(C_DISPATCH(obj)); - obj->refcount = 1; - } - -#ifdef _DEBUG - obj->resourceindex = resourcecounter++; -#endif - - return hr; -} - -PHPAPI char *php_COM_error_message(HRESULT hr) -{ - void *pMsgBuf; - - 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; -} - -static char *php_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, 0, codepage); - LocalFree(ole_clsid); - - return clsid_str; -} - -static void php_comval_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - comval *obj = (comval *)rsrc->ptr; - - if(C_ISREFD(obj)) - { - C_REFCOUNT(obj) = 1; - php_COM_release(obj); - } - efree(obj); -} - -static PHP_INI_MH(OnTypelibFileChange) -{ - 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_PERSISTENT|CONST_CS; - - 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 TSRMLS_CC); - pTL->lpVtbl->Release(pTL); - } - } - - efree(typelib_name_buffer); - fclose(typelib_file); - - if(interactive) - { - printf("\r%70s\r", ""); - } - - return SUCCESS; -} - - -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, OnTypelibFileChange) -PHP_INI_END() - - -/* {{{ proto int com_load(string module_name [, string remote_host [, int codepage[, string typelib]]]) - Loads a COM module */ -PHP_FUNCTION(com_load) -{ - pval *module_name, *code_page, *typelib = NULL, *server_name = NULL; - CLSID clsid; - HRESULT hr; - OLECHAR *ProgID; - comval *obj; - char *error_message; - char *clsid_str; - int mode = CONST_PERSISTENT; - ITypeLib *pTL; - - - codepage = CP_ACP; - - switch(ZEND_NUM_ARGS()) - { - case 1: - getParameters(ht, 1, &module_name); - break; - - case 2: - getParameters(ht, 2, &module_name, &server_name); - break; - - case 3: - getParameters(ht, 3, &module_name, &server_name, &code_page); - - convert_to_long_ex(&code_page); - codepage = code_page->value.lval; - break; - - case 4: - getParameters(ht, 4, &module_name, &server_name, &code_page, &typelib); - - convert_to_string_ex(&typelib); - convert_to_long_ex(&code_page); - codepage = Z_LVAL_P(code_page); - - break; - - default: - WRONG_PARAM_COUNT; - } - - if(server_name != NULL) - { - if(Z_TYPE_P(server_name) == IS_NULL) - { - server_name = NULL; - } - else - { - if(!INI_INT("com.allow_dcom")) - { - php_error(E_WARNING, "DCOM is disabled"); - RETURN_FALSE; - } - else - { - convert_to_string_ex(&server_name); - } - } - } - - convert_to_string_ex(&module_name); - ProgID = php_char_to_OLECHAR(Z_STRVAL_P(module_name), Z_STRLEN_P(module_name), codepage); - obj = (comval *) emalloc(sizeof(comval)); - - /* obtain CLSID */ - if(FAILED(CLSIDFromString(ProgID, &clsid))) - { - /* Perhaps this is a Moniker? */ - IBindCtx *pBindCtx; - IMoniker *pMoniker; - ULONG ulEaten; - - /* TODO: if(server_name) */ - - if(!server_name) - { - if(SUCCEEDED(hr = CreateBindCtx(0, &pBindCtx))) - { - if(SUCCEEDED(hr = MkParseDisplayName(pBindCtx, ProgID, &ulEaten, &pMoniker))) - { - hr = pMoniker->lpVtbl->BindToObject(pMoniker, pBindCtx, NULL, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj)); - pMoniker->lpVtbl->Release(pMoniker); - } - pBindCtx->lpVtbl->Release(pBindCtx); - } - } - else - { - hr = MK_E_SYNTAX; - } - - efree(ProgID); - - if(FAILED(hr)) - { - efree(obj); - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"Invalid ProgID or Moniker: %s\n", error_message); - LocalFree(error_message); - RETURN_FALSE; - } - } - else - { - efree(ProgID); - /* obtain IDispatch */ - if(!server_name) - { - hr = CoCreateInstance(&clsid, NULL, CLSCTX_SERVER, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj)); - } - else - { - COSERVERINFO server_info; - MULTI_QI pResults; - - server_info.dwReserved1=0; - server_info.dwReserved2=0; - server_info.pwszName = php_char_to_OLECHAR(Z_STRVAL_P(server_name), Z_STRLEN_P(server_name), codepage); - server_info.pAuthInfo=NULL; - - pResults.pIID = &IID_IDispatch; - pResults.pItf = NULL; - pResults.hr = S_OK; - hr=CoCreateInstanceEx(&clsid, NULL, CLSCTX_SERVER, &server_info, 1, &pResults); - if(SUCCEEDED(hr)) - { - hr = pResults.hr; - C_DISPATCH(obj) = (IDispatch *) pResults.pItf; - } - efree(server_info.pwszName); - } - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - clsid_str = php_string_from_clsid(&clsid); - php_error(E_WARNING,"Unable to obtain IDispatch interface for CLSID %s: %s",clsid_str,error_message); - LocalFree(error_message); - efree(clsid_str); - efree(obj); - RETURN_FALSE; - } - } - - 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")) - { - unsigned int idx; - - if(C_TYPEINFO_VT(obj)->GetContainingTypeLib(C_TYPEINFO(obj), &pTL, &idx) == S_OK) - { - php_COM_load_typelib(pTL, mode TSRMLS_CC); - pTL->lpVtbl->Release(pTL); - } - } - } - else - { - if(typelib != NULL) - { - ITypeLib *pTL; - - if((pTL = php_COM_find_typelib(Z_STRVAL_P(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 TSRMLS_CC); - } - pTL->lpVtbl->Release(pTL); - } - } - } - - RETURN_LONG(zend_list_insert(obj, IS_COM)); -} -/* }}} */ - - -int do_COM_invoke(comval *obj, pval *function_name, VARIANT *var_result, pval **arguments, int arg_count) -{ - DISPID dispid; - HRESULT hr; - OLECHAR *funcname; - char *error_message; - VARIANT *variant_args; - int current_arg, current_variant; - DISPPARAMS dispparams; - SAFEARRAY *pSA; - - if(C_HASENUM(obj) && strstr(Z_STRVAL_P(function_name), "next")) - { - /* Grab one argument off the stack, allocate enough - * VARIANTs - * Get the IEnumVariant interface and call ->Next(); - */ - SAFEARRAYBOUND rgsabound[1]; - unsigned long count; - - switch(arg_count) - { - case 0: - count = 1; - break; - - case 1: - convert_to_long_ex(&arguments[0]); - count = Z_LVAL_P(arguments[0]); - break; - - default: - /* TODO: complain about wrong arg count */ - php_error(E_WARNING,"Wrong argument count to IEnumVariant::Next()\n"); - - return FAILURE; - } - - 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; - } - - if(FAILED(hr = C_ENUMVARIANT_VT(obj)->Next(C_ENUMVARIANT(obj), count, pSA->pvData, &count))) - { - char *error_message = php_COM_error_message(hr); - php_error(E_WARNING,"IEnumVariant::Next() failed: %s\n", error_message); - efree(error_message); - SafeArrayDestroy(pSA); - VariantInit(var_result); - return FAILURE; - } - - if(count != rgsabound[0].cElements) - { - rgsabound[0].cElements = count; - if(FAILED(SafeArrayRedim(pSA, rgsabound))) - { - char *error_message = php_COM_error_message(hr); - php_error(E_WARNING,"IEnumVariant::Next() failed: %s\n", error_message); - efree(error_message); - SafeArrayDestroy(pSA); - VariantInit(var_result); - return FAILURE; - } - } - - return SUCCESS; - } - else if(C_HASENUM(obj) && strstr(Z_STRVAL_P(function_name), "reset")) - { - if(FAILED(hr = C_ENUMVARIANT_VT(obj)->Reset(C_ENUMVARIANT(obj)))) - { - char *error_message = php_COM_error_message(hr); - php_error(E_WARNING,"IEnumVariant::Next() failed: %s\n", error_message); - efree(error_message); - return FAILURE; - } - return SUCCESS; - } - else if(C_HASENUM(obj) && strstr(Z_STRVAL_P(function_name), "skip")) - { - unsigned long count; - - switch(arg_count) - { - case 0: - count = 1; - break; - - case 1: - convert_to_long_ex(&arguments[0]); - count = Z_LVAL_P(arguments[0]); - break; - - default: - php_error(E_WARNING,"Wrong argument count to IEnumVariant::Skip()\n"); - return FAILURE; - } - if(FAILED(hr = C_ENUMVARIANT_VT(obj)->Skip(C_ENUMVARIANT(obj), count))) - { - char *error_message = php_COM_error_message(hr); - php_error(E_WARNING,"IEnumVariant::Next() failed: %s\n", error_message); - efree(error_message); - return FAILURE; - } - return SUCCESS; - - } - else - { - funcname = php_char_to_OLECHAR(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name), codepage); - - hr = php_COM_get_ids_of_names(obj, &funcname, &dispid); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"Unable to lookup %s: %s\n", Z_STRVAL_P(function_name), error_message); - LocalFree(error_message); - efree(funcname); - return FAILURE; - } - - variant_args = (VARIANT *) emalloc(sizeof(VARIANT) * arg_count); - - for(current_arg=0; current_arg<arg_count; current_arg++) - { - current_variant = arg_count - current_arg - 1; - php_pval_to_variant(arguments[current_arg], &variant_args[current_variant], codepage); - } - - dispparams.rgvarg = variant_args; - dispparams.rgdispidNamedArgs = NULL; - dispparams.cArgs = arg_count; - dispparams.cNamedArgs = 0; - - hr = php_COM_invoke(obj, dispid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dispparams, var_result); - - efree(funcname); - efree(variant_args); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"Invoke() failed: %s\n", error_message); - LocalFree(error_message); - return FAILURE; - } - } - return SUCCESS; -} - - -/* {{{ proto mixed com_invoke(int module, string handler_name [, mixed arg [, ...]]) - Invokes a COM module */ -PHP_FUNCTION(com_invoke) -{ - pval **arguments; - pval *object, *function_name; - comval *obj; - int type; - int arg_count = ZEND_NUM_ARGS(); - VARIANT var_result; - - if(arg_count<2) - { - WRONG_PARAM_COUNT; - } - arguments = (pval **) emalloc(sizeof(pval *)*arg_count); - if(getParametersArray(ht, arg_count, arguments)==FAILURE) - { - RETURN_FALSE; - } - - object = arguments[0]; - function_name = arguments[1]; - - /* obtain IDispatch interface */ - convert_to_long(object); - obj = (comval *)zend_list_find(Z_LVAL_P(object), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%d is not a COM object handler", Z_STRVAL_P(function_name)); - RETURN_FALSE; - } - - /* obtain property/method handler */ - convert_to_string_ex(&function_name); - - if(do_COM_invoke(obj, function_name, &var_result, arguments+2, arg_count-2)==FAILURE) - { - RETURN_FALSE; - } - efree(arguments); - - php_variant_to_pval(&var_result, return_value, 0, codepage); -} -/* }}} */ - -/* {{{ proto mixed com_invoke(int module) - Releases a COM object */ -PHP_FUNCTION(com_release) -{ - pval *object; - comval *obj; - int type; - int arg_count = ZEND_NUM_ARGS(); - - if(arg_count != 1) - { - WRONG_PARAM_COUNT; - } - - if(getParameters(ht, 1, &object)==FAILURE) - { - RETURN_FALSE; - } - - /* obtain IDispatch interface */ - convert_to_long_ex(&object); - obj = (comval *)zend_list_find(Z_LVAL_P(object), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%d is not a COM object handler"); - RETURN_FALSE; - } - - RETURN_LONG(php_COM_release(obj)) -} -/* }}} */ - -/* {{{ proto mixed com_addref(int module) - Increases the reference counter on a COM object */ -PHP_FUNCTION(com_addref) -{ - pval *object; - comval *obj; - int type; - int arg_count = ZEND_NUM_ARGS(); - - if(arg_count != 1) - { - WRONG_PARAM_COUNT; - } - - if(getParameters(ht, 1, &object)==FAILURE) - { - RETURN_FALSE; - } - - /* obtain IDispatch interface */ - convert_to_long_ex(&object); - obj = (comval *)zend_list_find(Z_LVAL_P(object), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%d is not a COM object handler"); - RETURN_FALSE; - } - - RETURN_LONG(php_COM_addref(obj)); -} -/* }}} */ - -static int do_COM_offget(VARIANT *result, comval *array, pval *property, int cleanup) -{ - pval function_name; - int retval; - - ZVAL_STRINGL(&function_name, "Item", 4, 0); - retval = do_COM_invoke(array, &function_name, result, &property, 1); - if(cleanup) - { - php_COM_release(array); - efree(array); - } - - return retval; -} - -static int do_COM_propget(VARIANT *var_result, comval *obj, pval *arg_property, int cleanup) -{ - DISPID dispid; - HRESULT hr; - OLECHAR *propname; - char *error_message; - DISPPARAMS dispparams; - - - /* obtain property handler */ - propname = php_char_to_OLECHAR(Z_STRVAL_P(arg_property), Z_STRLEN_P(arg_property), codepage); - - hr = php_COM_get_ids_of_names(obj, &propname, &dispid); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"Unable to lookup %s: %s\n", Z_STRVAL_P(arg_property), error_message); - LocalFree(error_message); - efree(propname); - if(cleanup) - { - php_COM_release(obj); - } - return FAILURE; - } - - dispparams.cArgs = 0; - dispparams.cNamedArgs = 0; - - hr = php_COM_invoke(obj, dispid, DISPATCH_PROPERTYGET, &dispparams, var_result); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"PropGet() failed: %s\n", error_message); - LocalFree(error_message); - efree(propname); - if(cleanup) - { - php_COM_release(obj); - } - return FAILURE; - } - - efree(propname); - if(cleanup) - { - php_COM_release(obj); - } - return SUCCESS; -} - - -static void do_COM_propput(pval *return_value, comval *obj, pval *arg_property, pval *value) -{ - DISPID dispid; - HRESULT hr; - OLECHAR *propname; - char *error_message; - VARIANT *var_result; - DISPPARAMS dispparams; - VARIANT new_value; - DISPID mydispid = DISPID_PROPERTYPUT; - - - ALLOC_VARIANT(var_result); - - /* obtain property handler */ - propname = php_char_to_OLECHAR(Z_STRVAL_P(arg_property), Z_STRLEN_P(arg_property), codepage); - - hr = php_COM_get_ids_of_names(obj, &propname, &dispid); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"Unable to lookup %s: %s\n", Z_STRVAL_P(arg_property), error_message); - LocalFree(error_message); - efree(propname); - RETURN_FALSE; - } - - php_pval_to_variant(value, &new_value, codepage); - dispparams.rgvarg = &new_value; - dispparams.rgdispidNamedArgs = &mydispid; - dispparams.cArgs = 1; - dispparams.cNamedArgs = 1; - - hr = php_COM_invoke(obj, dispid, DISPATCH_PROPERTYPUT, &dispparams, NULL); - - if(FAILED(hr)) - { - error_message = php_COM_error_message(hr); - php_error(E_WARNING,"PropPut() failed: %s\n", error_message); - LocalFree(error_message); - efree(propname); - RETURN_FALSE; - } - - dispparams.cArgs = 0; - dispparams.cNamedArgs = 0; - - hr = php_COM_invoke(obj, dispid, DISPATCH_PROPERTYGET, &dispparams, var_result); - - if(SUCCEEDED(hr)) - { - php_variant_to_pval(var_result, return_value, 0, codepage); - } - else - { - *return_value = *value; - zval_copy_ctor(return_value); - } - - efree(var_result); - efree(propname); -} - - -/* {{{ proto mixed com_propget(int module, string property_name) - Gets properties from a COM module */ -PHP_FUNCTION(com_propget) -{ - pval *arg_comval, *arg_property; - int type; - comval *obj; - VARIANT var_result; - - if(ZEND_NUM_ARGS()!=2 || getParameters(ht, 2, &arg_comval, &arg_property)==FAILURE) - { - WRONG_PARAM_COUNT; - } - - /* obtain IDispatch interface */ - convert_to_long(arg_comval); - obj = (comval *)zend_list_find(Z_LVAL_P(arg_comval), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%d is not a COM object handler", Z_LVAL_P(arg_comval)); - } - convert_to_string_ex(&arg_property); - - if(do_COM_propget(&var_result, obj, arg_property, 0)==FAILURE) - { - RETURN_FALSE; - } - php_variant_to_pval(&var_result, return_value, 0, codepage); -} -/* }}} */ - - -/* {{{ proto bool com_propput(int module, string property_name, mixed value) - Puts the properties for a module */ -PHP_FUNCTION(com_propput) -{ - pval *arg_comval, *arg_property, *arg_value; - int type; - comval *obj; - - if(ZEND_NUM_ARGS()!=3 || getParameters(ht, 3, &arg_comval, &arg_property, &arg_value)==FAILURE) - { - WRONG_PARAM_COUNT; - } - - /* obtain comval interface */ - convert_to_long(arg_comval); - /* obtain comval interface */ - obj = (comval *)zend_list_find(Z_LVAL_P(arg_comval), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%d is not a COM object handler", Z_LVAL_P(arg_comval)); - } - convert_to_string_ex(&arg_property); - - do_COM_propput(return_value, obj, arg_property, arg_value); -} -/* }}} */ - -/* {{{ proto bool com_load_typelib(string typelib_name[, int case_insensitiv]) */ -PHP_FUNCTION(com_load_typelib) -{ - pval *arg_typelib, *arg_cis; - ITypeLib *pTL; - int mode; - - switch(ZEND_NUM_ARGS()) - { - case 1: - getParameters(ht, 1, &arg_typelib); - mode = CONST_PERSISTENT|CONST_CS; - break; - case 2: - getParameters(ht, 2, &arg_typelib, &arg_cis); - convert_to_boolean_ex(&arg_cis); - if(arg_cis->value.lval) - { - mode &= ~CONST_CS; - } - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(&arg_typelib); - pTL = php_COM_find_typelib(Z_STRVAL_P(arg_typelib), mode); - if(php_COM_load_typelib(pTL, mode TSRMLS_CC) == SUCCESS) - { - pTL->lpVtbl->Release(pTL); - RETURN_TRUE; - } - else - { - RETURN_FALSE; - } -} -/* }}} */ - -PHPAPI pval php_COM_get_property_handler(zend_property_reference *property_reference) -{ - zend_overloaded_element *overloaded_property; - zend_llist_element *element; - pval return_value; - pval **comval_handle; - pval *object = property_reference->object; - int type; - comval *obj, *obj_prop; - VARIANT *var_result; - TSRMLS_FETCH(); - - INIT_ZVAL(return_value); - ZVAL_NULL(&return_value); - - /* fetch the IDispatch interface */ - zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &comval_handle); - obj = (comval *) zend_list_find(Z_LVAL_P(*comval_handle), &type); - if(!obj || (type != IS_COM)) - { - return return_value; - } - - ALLOC_COM(obj_prop); - ALLOC_VARIANT(var_result); - - for(element=property_reference->elements_list->head; element; element=element->next) - { - overloaded_property = (zend_overloaded_element *) element->data; - VariantInit(var_result); - switch(overloaded_property->type) - { - case OE_IS_ARRAY: - if(do_COM_offget(var_result, obj, &overloaded_property->element, FALSE) == FAILURE) - { - efree(var_result); - efree(obj_prop); - return return_value; - } - break; - - case OE_IS_OBJECT: - if(do_COM_propget(var_result, obj, &overloaded_property->element, FALSE) == FAILURE) - { - efree(var_result); - efree(obj_prop); - return return_value; - } - break; - - case OE_IS_METHOD: - { - if(obj != obj_prop) - { - efree(obj_prop); - return_value = *object; - ZVAL_ADDREF(&return_value); - } - - efree(var_result); - - return return_value; - } - break; - } - - if(V_VT(var_result) == VT_DISPATCH) - { - if(V_DISPATCH(var_result) == NULL) - { - efree(var_result); - efree(obj_prop); - return return_value; - } - - obj = obj_prop; - php_COM_set(obj, V_DISPATCH(var_result), TRUE); - - RETVAL_COM(obj); - } - else - { - efree(obj_prop); - obj_prop = NULL; - php_variant_to_pval(var_result, &return_value, FALSE, codepage); - } - - pval_destructor(&overloaded_property->element); - } - efree(var_result); - - return return_value; -} - -PHPAPI int php_COM_set_property_handler(zend_property_reference *property_reference, pval *value) -{ - pval result; - zend_overloaded_element *overloaded_property; - zend_llist_element *element; - pval **comval_handle; - pval *object = property_reference->object; - comval *obj; - int type; - VARIANT var_result; - TSRMLS_FETCH(); - - /* fetch the IDispatch interface */ - zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &comval_handle); - obj = (comval *)zend_list_find(Z_LVAL_P(*comval_handle), &type); - if(!obj || (type != IS_COM)) - { - return FAILURE; - } - var_result.vt = VT_DISPATCH; - var_result.pdispVal = C_DISPATCH(obj); - - for(element=property_reference->elements_list->head; element && element!=property_reference->elements_list->tail; element=element->next) - { - overloaded_property = (zend_overloaded_element *) element->data; - switch(overloaded_property->type) - { - case OE_IS_ARRAY: - break; - case OE_IS_OBJECT: - if(V_VT(&var_result) != VT_DISPATCH) - { - return FAILURE; - } - else - { - do_COM_propget(&var_result, obj, &overloaded_property->element, element!=property_reference->elements_list->head); - } - break; - case OE_IS_METHOD: - /* this shouldn't happen */ - return FAILURE; - } - - pval_destructor(&overloaded_property->element); - } - - if(V_VT(&var_result) != VT_DISPATCH) - { - return FAILURE; - } - obj = (comval *) emalloc(sizeof(comval)); - C_HASTLIB(obj) = FALSE; - C_DISPATCH(obj) = V_DISPATCH(&var_result); - - overloaded_property = (zend_overloaded_element *) element->data; - do_COM_propput(&result, obj, &overloaded_property->element, value); - pval_destructor(&overloaded_property->element); - efree(obj); - - return SUCCESS; -} - -PHPAPI void php_COM_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - pval property, **handle; - pval *object = property_reference->object; - zend_overloaded_element *function_name = (zend_overloaded_element *) property_reference->elements_list->tail->data; - comval *obj; - int type; - - if(zend_llist_count(property_reference->elements_list)==1 - && !strcmp(Z_STRVAL(function_name->element), "com")) - { /* constructor */ - pval *object_handle; - - PHP_FN(com_load)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if(!zend_is_true(return_value)) - { - ZVAL_FALSE(object); - return; - } - ALLOC_ZVAL(object_handle); - *object_handle = *return_value; - pval_copy_constructor(object_handle); - INIT_PZVAL(object_handle); - zend_hash_index_update(Z_OBJPROP_P(object), 0, &object_handle, sizeof(pval *), NULL); - pval_destructor(&function_name->element); - - return; - } - - property = php_COM_get_property_handler(property_reference); - if(property.type == IS_NULL) - { - if(property.refcount == 1) - { - pval_destructor(&property); - } - pval_destructor(&function_name->element); - return; - } - zend_hash_index_find(Z_OBJPROP(property), 0, (void **) &handle); - obj = (comval *)zend_list_find(Z_LVAL_PP(handle), &type); - - if(!obj || (type != IS_COM)) - { - pval_destructor(&property); - pval_destructor(&function_name->element); - return; - } - - if(zend_llist_count(property_reference->elements_list)==1 - && !strcmp(Z_STRVAL_P(&function_name->element), "release")) - { - RETVAL_LONG(php_COM_release(obj)); - } - else if(zend_llist_count(property_reference->elements_list)==1 - && !strcmp(Z_STRVAL_P(&function_name->element), "addref")) - { - RETVAL_LONG(php_COM_addref(obj)); - } - else - { - pval **arguments; - VARIANT *var_result; - int arg_count = ZEND_NUM_ARGS(); - - ALLOC_VARIANT(var_result); - VariantInit(var_result); - - arguments = (pval **) emalloc(sizeof(pval *)*arg_count); - getParametersArray(ht, arg_count, arguments); - - if(do_COM_invoke(obj , &function_name->element, var_result, arguments, arg_count)==FAILURE) - { - RETVAL_FALSE; - } - else - { - php_variant_to_pval(var_result, return_value, 0, codepage); - } - - efree(arguments); - efree(var_result); - } - - if(property.refcount == 1) - { - pval_destructor(&property); - } - pval_destructor(&function_name->element); -} - -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); - major = php_strtok_r(NULL, ",", &strtok_buf); - minor = php_strtok_r(NULL, ",", &strtok_buf); - - p = php_char_to_OLECHAR(search_string, strlen(search_string), codepage); - /* 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; -} - -static int php_COM_load_typelib(ITypeLib *TypeLib, int mode TSRMLS_DC) -{ - ITypeComp *TypeComp; - int i; - int interfaces; - - 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; -#if 0 - BSTR bstr_EnumId; - char *EnumId; - - TypeLib->lpVtbl->GetDocumentation(TypeLib, i, &bstr_EnumId, NULL, NULL, NULL); - EnumId = php_OLECHAR_to_char(bstr_EnumId, NULL, 0, codepage); - printf("Enumeration %d - %s:\n", i, EnumId); - efree(EnumId); -#endif - - TypeLib->lpVtbl->GetTypeInfo(TypeLib, i, &TypeInfo); - - j=0; - while(TypeInfo->lpVtbl->GetVarDesc(TypeInfo, j, &pVarDesc)==S_OK) - { - BSTR bstr_ids; - char *ids; - zend_constant c; - zval exists, results; - - TypeInfo->lpVtbl->GetNames(TypeInfo, pVarDesc->memid, &bstr_ids, 1, &NameCount); - if(NameCount!=1) - { - j++; - continue; - } - ids = php_OLECHAR_to_char(bstr_ids, NULL, 1, codepage); - SysFreeString(bstr_ids); - c.name_len = strlen(ids)+1; - c.name = ids; - 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")) - { - php_error(E_WARNING,"Type library value %s is already defined and has a different value", c.name); - } - free(ids); - j++; - continue; - } - - php_variant_to_pval(pVarDesc->lpvarValue, &c.value, FALSE, codepage); - c.flags = mode; - - /* Before registering the contsnt, let's see if we can find it */ - { - zend_register_constant(&c TSRMLS_CC); - } - j++; - } - TypeInfo->lpVtbl->Release(TypeInfo); - } - } - - return SUCCESS; -} - -/* {{{ proto bool com_isenum(com_module obj) - Grabs an IEnumVariant */ -PHP_FUNCTION(com_isenum) -{ - pval *object; - pval **comval_handle; - comval *obj; - int type; - - if(ZEND_NUM_ARGS() != 1) - { - WRONG_PARAM_COUNT; - } - - getParameters(ht, 1, &object); - - /* obtain IDispatch interface */ - zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &comval_handle); - obj = (comval *) zend_list_find(Z_LVAL_PP(comval_handle), &type); - if(!obj || (type != IS_COM)) - { - php_error(E_WARNING,"%s is not a COM object handler", ""); - RETURN_FALSE; - } - - RETURN_BOOL(C_HASENUM(obj)); -} -/* }}} */ - -void php_register_COM_class(TSRMLS_D) -{ - INIT_OVERLOADED_CLASS_ENTRY(com_class_entry, "COM", NULL, - php_COM_call_function_handler, - php_COM_get_property_handler, - php_COM_set_property_handler); - - zend_register_internal_class(&com_class_entry TSRMLS_CC); -} - -PHP_MINIT_FUNCTION(COM) -{ - CoInitialize(NULL); - le_comval = zend_register_list_destructors_ex(php_comval_destructor, NULL, "COM", module_number); - php_register_COM_class(TSRMLS_C); - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(COM) -{ - CoUninitialize(); - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} - -/* exports for external object creation */ - -zend_module_entry COM_module_entry = { - "com", COM_functions, PHP_MINIT(COM), PHP_MSHUTDOWN(COM), NULL, NULL, PHP_MINFO(COM), STANDARD_MODULE_PROPERTIES -}; - -PHPAPI int php_COM_get_le_comval() -{ - return le_comval; -} - -#endif diff --git a/ext/rpc/com/com_wrapper.h b/ext/rpc/com/com_wrapper.h deleted file mode 100644 index e1f04c75c7..0000000000 --- a/ext/rpc/com/com_wrapper.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef COM_H -#define COM_H - -#if PHP_WIN32 - -#include "oleauto.h" - -typedef struct comval_ { -#ifdef _DEBUG - int resourceindex; -#endif - BOOL typelib; - BOOL enumeration; - int refcount; - struct { - IDispatch *dispatch; - ITypeInfo *typeinfo; - IEnumVARIANT *enumvariant; - } i; -} comval; - -#define ZVAL_COM(z,o) { \ - zval *handle; \ - \ - /* OBJECTS_FIXME */ \ - Z_TYPE_P(z) = IS_OBJECT; \ - Z_OBJCE_P(z) = &com_class_entry; \ - \ - ALLOC_HASHTABLE(Z_OBJPROP_P(z)); \ - zend_hash_init(Z_OBJPROP_P(z), 0, NULL, ZVAL_PTR_DTOR, 0); \ - \ - ALLOC_ZVAL(handle); \ - INIT_PZVAL(handle); \ - ZVAL_LONG(handle, zend_list_insert((o), IS_COM)); \ - \ - zval_copy_ctor(handle); \ - zend_hash_index_update(Z_OBJPROP_P(z), 0, &handle, sizeof(zval *), NULL); \ - } - -#define RETVAL_COM(o) ZVAL_COM(&return_value, o) -#define RETURN_COM(o) RETVAL_COM(o) \ - return; - -#define ALLOC_COM(z) (z) = (comval *) emalloc(sizeof(comval)) -#define IS_COM php_COM_get_le_comval() - -#define C_HASTLIB(x) ((x)->typelib) -#define C_HASENUM(x) ((x)->enumeration) -#define C_REFCOUNT(x) ((x)->refcount) -#define C_ISREFD(x) C_REFCOUNT(x) - -#define C_ADDREF(x) (++((x)->refcount)) -#define C_RELEASE(x) (--((x)->refcount)) - -#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 8f7e80a9c6..0000000000 --- a/ext/rpc/com/conversion.c +++ /dev/null @@ -1,916 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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 - -#include "php.h" -#include "php_COM.h" -#include "php_VARIANT.h" - -/* prototypes */ - -PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC); -PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC); -PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, int codepage); -PHPAPI OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage); -PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int persistent, int codepage); - -static void pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC); -static void comval_to_variant(pval *pval_arg, VARIANT *var_arg TSRMLS_DC); - -/* implementations */ -PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC) -{ - int type = VT_EMPTY; /* default variant type */ - - switch(Z_TYPE_P(pval_arg)) - { - case IS_NULL: - type = VT_NULL; - break; - - case IS_BOOL: - type = VT_BOOL; - break; - - case IS_OBJECT: - if(!strcmp(Z_OBJCE_P(pval_arg)->name, "VARIANT")) - { - type = VT_VARIANT; - } - else if(!strcmp(Z_OBJCE_P(pval_arg)->name, "COM")) - { - 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; - } - - if(pval_arg->is_ref) /* deprecated, implemented for downwards compatiblity */ - { - type |= VT_BYREF; - } - - pval_to_variant_ex(pval_arg, var_arg, type, codepage TSRMLS_CC); -} - -PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC) -{ - pval_to_variant_ex(pval_arg, var_arg, Z_LVAL_P(pval_type), codepage TSRMLS_CC); -} - -static void pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC) -{ - OLECHAR *unicode_str; - - 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(*pval_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; - ALLOC_VARIANT(V_VARIANTREF(var_arg)); - 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) - { - php_error( E_WARNING,"Unable to convert php array to VARIANT array - %s", numberOfElements ? "" : "(Empty input array)"); - ZVAL_FALSE(pval_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 */ - { - pval_to_variant_ex(*entry, v, type, codepage TSRMLS_CC); /* Do the required conversion */ - } - else - { - php_pval_to_variant(*entry, v, codepage TSRMLS_CC); /* Do the required conversion */ - } - } - else - { - php_error( E_WARNING,"phpArrayToSafeArray() - Unable to retrieve pointer to output element number (%d)", i); - } - } - zend_hash_move_forward(ht); - } - SafeArrayUnlock( safeArray); - } - else - { - php_error( E_WARNING,"phpArrayToSafeArray() - Unable to lock safeArray"); - } - } - } - else - { - switch(V_VT(var_arg)) - { - case VT_UI1: - convert_to_long_ex(&pval_arg); - V_UI1(var_arg) = (unsigned char)Z_LVAL_P(pval_arg); - break; - - case VT_I2: - convert_to_long_ex(&pval_arg); - V_I2(var_arg) = (short)Z_LVAL_P(pval_arg); - break; - - case VT_I4: - convert_to_long_ex(&pval_arg); - V_I4(var_arg) = Z_LVAL_P(pval_arg); - break; - - case VT_R4: - convert_to_double_ex(&pval_arg); - V_R4(var_arg) = (float)Z_DVAL_P(pval_arg); - break; - - case VT_R8: - convert_to_double_ex(&pval_arg); - V_R8(var_arg) = Z_DVAL_P(pval_arg); - break; - - case VT_BOOL: - convert_to_boolean_ex(&pval_arg); - V_BOOL(var_arg) = (short)Z_LVAL_P(pval_arg); - break; - - case VT_ERROR: - convert_to_long_ex(&pval_arg); - V_ERROR(var_arg) = Z_LVAL_P(pval_arg); - break; - - case VT_CY: - convert_to_double_ex(&pval_arg); - VarCyFromR8(Z_DVAL_P(pval_arg), &V_CY(var_arg)); - break; - - case VT_DATE: - { - SYSTEMTIME wintime; - struct tm *phptime; - - phptime = gmtime(&(pval_arg->value.lval)); - 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; - - case VT_BSTR: - convert_to_string_ex(&pval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage); - V_BSTR(var_arg) = SysAllocString(unicode_str); - efree(unicode_str); - break; - - case VT_DECIMAL: - convert_to_string_ex(&pval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage); - VarDecFromStr(unicode_str, LOCALE_SYSTEM_DEFAULT, 0, &V_DECIMAL(var_arg)); - break; - - case VT_DECIMAL|VT_BYREF: - convert_to_string_ex(&pval_arg); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage); - VarDecFromStr(unicode_str, LOCALE_SYSTEM_DEFAULT, 0, V_DECIMALREF(var_arg)); - break; - - case VT_UNKNOWN: - comval_to_variant(pval_arg, var_arg TSRMLS_CC); - if(V_VT(var_arg) != VT_DISPATCH) - { - VariantInit(var_arg); - } - else - { - V_VT(var_arg) = VT_UNKNOWN; - V_UNKNOWN(var_arg) = (IUnknown *) V_DISPATCH(var_arg); - } - break; - - case VT_DISPATCH: - comval_to_variant(pval_arg, var_arg TSRMLS_CC); - if(V_VT(var_arg) != VT_DISPATCH) - { - VariantInit(var_arg); - } - break; - - case VT_UI1|VT_BYREF: - convert_to_long(pval_arg); - V_UI1REF(var_arg) = (unsigned char FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_I2|VT_BYREF: - convert_to_long(pval_arg); - V_I2REF(var_arg) = (short FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_I4|VT_BYREF: - convert_to_long(pval_arg); - V_I4REF(var_arg) = (long FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_R4|VT_BYREF: - convert_to_double(pval_arg); - V_R4REF(var_arg) = (float FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_R8|VT_BYREF: - convert_to_double(pval_arg); - V_R8REF(var_arg) = (double FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_BOOL|VT_BYREF: - convert_to_boolean(pval_arg); - V_BOOLREF(var_arg) = (short FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_ERROR|VT_BYREF: - convert_to_long(pval_arg); - V_ERRORREF(var_arg) = (long FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_CY|VT_BYREF: - convert_to_double_ex(&pval_arg); - VarCyFromR8(pval_arg->value.dval, var_arg->pcyVal); - break; - - case VT_DATE|VT_BYREF: - { - SYSTEMTIME wintime; - struct tm *phptime; - - phptime = gmtime(&(pval_arg->value.lval)); - 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(pval_arg); - V_BSTRREF(var_arg) = (BSTR FAR*) emalloc(sizeof(BSTR FAR*)); - unicode_str = php_char_to_OLECHAR(Z_STRVAL_P(pval_arg), Z_STRLEN_P(pval_arg), codepage); - *V_BSTRREF(var_arg) = SysAllocString(unicode_str); - efree(unicode_str); - break; - - case VT_UNKNOWN|VT_BYREF: - comval_to_variant(pval_arg, var_arg TSRMLS_CC); - if(V_VT(var_arg) != VT_DISPATCH) - { - VariantInit(var_arg); - } - else - { - V_VT(var_arg) = VT_UNKNOWN|VT_BYREF; - V_UNKNOWNREF(var_arg) = (IUnknown **) &V_DISPATCH(var_arg); - } - break; - - case VT_DISPATCH|VT_BYREF: - comval_to_variant(pval_arg, var_arg TSRMLS_CC); - if(V_VT(var_arg) != VT_DISPATCH) - { - VariantInit(var_arg); - } - else - { - V_VT(var_arg) = VT_DISPATCH|VT_BYREF; - V_DISPATCHREF(var_arg) = &V_DISPATCH(var_arg); - } - break; - - case VT_VARIANT|VT_BYREF: - { - int tp; - pval **var_handle; - - /* fetch the VARIANT structure */ - zend_hash_index_find(Z_OBJPROP_P(pval_arg), 0, (void **) &var_handle); - - V_VT(var_arg) = VT_VARIANT|VT_BYREF; - V_VARIANTREF(var_arg) = (VARIANT FAR*) zend_list_find(Z_LVAL_P(*var_handle), &tp); - - if(!V_VARIANTREF(var_arg) && (tp != IS_VARIANT)) - { - VariantInit(var_arg); - } - } - /* - should be, but isn't :) - - if(V_VT(var_arg) != (VT_VARIANT|VT_BYREF)) - { - VariantInit(var_arg); - } - */ - break; - - case VT_I1: - convert_to_long_ex(&pval_arg); - V_I1(var_arg) = (char)Z_LVAL_P(pval_arg); - break; - - case VT_UI2: - convert_to_long_ex(&pval_arg); - V_UI2(var_arg) = (unsigned short)Z_LVAL_P(pval_arg); - break; - - case VT_UI4: - convert_to_long_ex(&pval_arg); - V_UI4(var_arg) = (unsigned long)Z_LVAL_P(pval_arg); - break; - - case VT_INT: - convert_to_long_ex(&pval_arg); - V_INT(var_arg) = (int)Z_LVAL_P(pval_arg); - break; - - case VT_UINT: - convert_to_long_ex(&pval_arg); - V_UINT(var_arg) = (unsigned int)Z_LVAL_P(pval_arg); - break; - - case VT_I1|VT_BYREF: - convert_to_long(pval_arg); - V_I1REF(var_arg) = (char FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_UI2|VT_BYREF: - convert_to_long(pval_arg); - V_UI2REF(var_arg) = (unsigned short FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_UI4|VT_BYREF: - convert_to_long(pval_arg); - V_UI4REF(var_arg) = (unsigned long FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_INT|VT_BYREF: - convert_to_long(pval_arg); - V_INTREF(var_arg) = (int FAR*) &Z_LVAL_P(pval_arg); - break; - - case VT_UINT|VT_BYREF: - convert_to_long(pval_arg); - V_UINTREF(var_arg) = (unsigned int FAR*) &Z_LVAL_P(pval_arg); - break; - - default: - php_error(E_WARNING, "Type not supported or not yet implemented."); - } - } -} - -PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, 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(pval_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; - pval *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))) - { - php_error(E_WARNING,"Unsupported: multi-dimensional (%d) SafeArrays", Dims); - ZVAL_NULL(pval_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))) - { - /* 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(pval_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_pval(&vv, element, persistent, 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(pval_arg, ii, element); - } - } - SafeArrayUnlock(array); - /* Clean up the SafeArray since that is our responsibility */ - SafeArrayDestroyData(array); - SafeArrayDestroyDescriptor(array); - } - else switch(var_arg->vt & ~VT_BYREF) - { - case VT_EMPTY: - ZVAL_NULL(pval_arg); - break; - - case VT_UI1: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_UI4REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_UI4(var_arg)); - } - break; - - case VT_I2: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long )*V_I2REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_I2(var_arg)); - } - break; - - case VT_I4: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, *V_I4REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, V_I4(var_arg)); - } - break; - - case VT_R4: - if(V_ISBYREF(var_arg)) - { - ZVAL_DOUBLE(pval_arg, (double)*V_R4REF(var_arg)); - } - else - { - ZVAL_DOUBLE(pval_arg, (double)V_R4(var_arg)); - } - break; - - case VT_R8: - if(V_ISBYREF(var_arg)) - { - ZVAL_DOUBLE(pval_arg, *V_R8REF(var_arg)); - } - else - { - ZVAL_DOUBLE(pval_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(pval_arg) = php_OLECHAR_to_char(unicode_str, &Z_STRLEN_P(pval_arg), persistent, codepage); - Z_TYPE_P(pval_arg) = IS_STRING; - break; - - default: - ZVAL_NULL(pval_arg); - ret = FAILURE; - php_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(pval_arg)); - } - else - { - VarR8FromCy(V_CY(var_arg), &Z_DVAL_P(pval_arg)); - } - Z_TYPE_P(pval_arg) = IS_DOUBLE; - break; - - case VT_BOOL: - if(V_ISBYREF(var_arg)) - { - ZVAL_BOOL(pval_arg, *V_BOOLREF(var_arg)); - } - else - { - ZVAL_BOOL(pval_arg, V_BOOL(var_arg)); - } - break; - - case VT_NULL: - case VT_VOID: - ZVAL_NULL(pval_arg); - break; - - case VT_VARIANT: - php_variant_to_pval(V_VARIANTREF(var_arg), pval_arg, persistent, codepage); - break; - - case VT_BSTR: - if(V_ISBYREF(var_arg)) - { - Z_STRVAL_P(pval_arg) = php_OLECHAR_to_char(*V_BSTRREF(var_arg), &Z_STRLEN_P(pval_arg), persistent, codepage); - SysFreeString(*V_BSTRREF(var_arg)); - efree(V_BSTRREF(var_arg)); - } - else - { - Z_STRVAL_P(pval_arg) = php_OLECHAR_to_char(V_BSTR(var_arg), &Z_STRLEN_P(pval_arg), persistent, codepage); - SysFreeString(V_BSTR(var_arg)); - } - - Z_TYPE_P(pval_arg) = IS_STRING; - break; - - case VT_DATE: - { - SYSTEMTIME wintime; - struct tm phptime; - - if(V_ISBYREF(var_arg)) - { - VariantTimeToSystemTime(*V_DATEREF(var_arg), &wintime); - } - else - { - VariantTimeToSystemTime(V_DATE(var_arg), &wintime); - } - - 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(pval_arg, mktime(&phptime)); - } - 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); - php_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(pval_arg); - } - else - { - ALLOC_COM(obj); - php_COM_set(obj, V_DISPATCH(var_arg), TRUE); - - ZVAL_COM(pval_arg, obj); - } - } - break; - - case VT_I1: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_I1REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_I1(var_arg)); - } - break; - - case VT_UI2: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_UI2REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_UI2(var_arg)); - } - break; - - case VT_UI4: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_UI4REF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_UI4(var_arg)); - } - break; - - case VT_INT: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_INTREF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_INT(var_arg)); - } - break; - - case VT_UINT: - if(V_ISBYREF(var_arg)) - { - ZVAL_LONG(pval_arg, (long)*V_UINTREF(var_arg)); - } - else - { - ZVAL_LONG(pval_arg, (long)V_UINT(var_arg)); - } - break; - - default: - php_error(E_WARNING,"Unsupported variant type: %d (0x%X)", V_VT(var_arg), V_VT(var_arg)); - ZVAL_NULL(pval_arg); - ret = FAILURE; - break; - } - return ret; -} - -PHPAPI OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage) -{ - OLECHAR *unicode_str; - - /* request needed buffersize */ - uint reqSize = MultiByteToWideChar(codepage, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, C_str, -1, NULL, 0); - - if(reqSize) - { - unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR) * reqSize); - - /* convert string */ - MultiByteToWideChar(codepage, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, C_str, -1, unicode_str, reqSize); - } - else - { - unicode_str = (OLECHAR *) emalloc(sizeof(OLECHAR)); - *unicode_str = 0; - - switch(GetLastError()) - { - case ERROR_NO_UNICODE_TRANSLATION: - php_error(E_WARNING,"No unicode translation available for the specified string"); - break; - default: - php_error(E_WARNING,"Error in php_char_to_OLECHAR()"); - } - } - - return unicode_str; -} - -PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int persistent, int codepage) -{ - char *C_str; - uint length = 0; - - /* request needed buffersize */ - uint reqSize = WideCharToMultiByte(codepage, WC_COMPOSITECHECK, unicode_str, -1, NULL, 0, NULL, NULL); - - if(reqSize) - { - C_str = (char *) pemalloc(sizeof(char) * reqSize, persistent); - - /* convert string */ - length = WideCharToMultiByte(codepage, WC_COMPOSITECHECK, unicode_str, -1, C_str, reqSize, NULL, NULL) - 1; - } - else - { - C_str = (char *) pemalloc(sizeof(char), persistent); - *C_str = 0; - - php_error(E_WARNING,"Error in php_OLECHAR_to_char()"); - } - - if(out_length) - { - *out_length = length; - } - - return C_str; -} - -static void comval_to_variant(pval *pval_arg, VARIANT *var_arg TSRMLS_DC) -{ - pval **comval_handle; - comval *obj; - int type; - - /* fetch the comval structure */ - zend_hash_index_find(Z_OBJPROP_P(pval_arg), 0, (void **) &comval_handle); - obj = (comval *) zend_list_find(Z_LVAL_P(*comval_handle), &type); - if(!obj || (type != IS_COM) || !C_ISREFD(obj)) - { - VariantInit(var_arg); - } - else - { - V_VT(var_arg) = VT_DISPATCH; - V_DISPATCH(var_arg) = C_DISPATCH(obj); - } -} - -#endif /* PHP_WIN32 */ diff --git a/ext/rpc/com/conversion.h b/ext/rpc/com/conversion.h deleted file mode 100644 index 53d19a21de..0000000000 --- a/ext/rpc/com/conversion.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef CONVERSION_H -#define CONVERSION_H - -BEGIN_EXTERN_C() - -extern void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage); -extern void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage); -extern int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, int codepage); -extern OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage); -extern char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int persistent, int codepage); - -END_EXTERN_C() - -#endif
\ No newline at end of file diff --git a/ext/rpc/com/php_com.h b/ext/rpc/com/php_com.h deleted file mode 100644 index 3a2108f415..0000000000 --- a/ext/rpc/com/php_com.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef PHP_COM_H -#define PHP_COM_H - -#if PHP_WIN32 - -#include "com.h" - -BEGIN_EXTERN_C() - -PHP_MINIT_FUNCTION(COM); -PHP_MSHUTDOWN_FUNCTION(COM); - -PHPAPI HRESULT php_COM_invoke(comval *obj, DISPID dispIdMember, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult); -PHPAPI HRESULT php_COM_get_ids_of_names(comval *obj, OLECHAR FAR* FAR* rgszNames, DISPID FAR* rgDispId); -PHPAPI HRESULT php_COM_release(comval *obj); -PHPAPI HRESULT php_COM_addref(comval *obj); -PHPAPI HRESULT php_COM_set(comval *obj, IDispatch FAR* pDisp, int cleanup); -PHPAPI HRESULT php_COM_clone(comval *obj, comval *clone, int cleanup); - -int php_COM_get_le_comval(); - -zend_module_entry COM_module_entry; -zend_class_entry com_class_entry; - -pval php_COM_get_property_handler(zend_property_reference *property_reference); -int php_COM_set_property_handler(zend_property_reference *property_reference, pval *value); -char *php_COM_error_message(HRESULT hr); -void php_COM_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference); - -#ifdef DEBUG - extern int resourcecounter; -#endif - -END_EXTERN_C() - -#define COM_module_ptr &COM_module_entry - -#else - -#define COM_module_ptr NULL - -#endif /* PHP_WIN32 */ - -#endif /* PHP_COM_H */ diff --git a/ext/rpc/com/php_variant.h b/ext/rpc/com/php_variant.h deleted file mode 100644 index 5e6d51f821..0000000000 --- a/ext/rpc/com/php_variant.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef PHP_TYPEDEF_VARIANT_H -#define PHP_TYPEDEF_VARIANT_H - -#if PHP_WIN32 - -#include "variant.h" - -extern int php_VARIANT_get_le_variant(); - -PHP_MINIT_FUNCTION(VARIANT); -PHP_MSHUTDOWN_FUNCTION(VARIANT); - -extern zend_module_entry VARIANT_module_entry; - -#define VARIANT_module_ptr &VARIANT_module_entry - -#else - -#define VARIANT_module_ptr NULL - -#endif /* PHP_WIN32 */ - -#define phpext_VARIANT_ptr VARIANT_module_ptr - -#endif /* PHP_TYPEDEF_VARIANT_H */ diff --git a/ext/rpc/com/variant.c b/ext/rpc/com/variant.c deleted file mode 100644 index 5d61100d64..0000000000 --- a/ext/rpc/com/variant.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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> | - +----------------------------------------------------------------------+ - */ - - -/* - * 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 - -#include "php.h" -#include "php_ini.h" -#include "variant.h" -#include "conversion.h" -#include "ext/standard/info.h" - -#include <unknwn.h> - -PHP_MINIT_FUNCTION(VARIANT); -PHP_MSHUTDOWN_FUNCTION(VARIANT); - -int php_VARIANT_get_le_variant(); -void php_VARIANT_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference); -pval php_VARIANT_get_property_handler(zend_property_reference *property_reference); -static int do_VARIANT_propset(VARIANT *var_arg, pval *arg_property, pval *value); -void php_register_VARIANT_class(TSRMLS_D); -static void php_variant_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC); - -static int le_variant; -static int codepage; - -static zend_class_entry VARIANT_class_entry; - -function_entry VARIANT_functions[] = { - {NULL, NULL, NULL} -}; - -static PHP_MINFO_FUNCTION(VARIANT) -{ - php_info_print_table_start(); - php_info_print_table_row(2, "VARIANT support", "enabled"); - php_info_print_table_end(); -} - -zend_module_entry VARIANT_module_entry = { - "variant", VARIANT_functions, PHP_MINIT(VARIANT), PHP_MSHUTDOWN(VARIANT), NULL, NULL, PHP_MINFO(VARIANT), STANDARD_MODULE_PROPERTIES -}; - -PHP_MINIT_FUNCTION(VARIANT) -{ - le_variant = zend_register_list_destructors_ex(php_variant_destructor, NULL, "VARIANT", module_number); - - /* 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_CY, 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_SYMBOL", CP_SYMBOL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CP_THREAD_ACP", CP_THREAD_ACP, 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); - - php_register_VARIANT_class(TSRMLS_C); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(VARIANT) -{ - return SUCCESS; -} - -int php_VARIANT_get_le_variant() -{ - return le_variant; -} - -void php_VARIANT_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - pval *object = property_reference->object; - zend_overloaded_element *function_name = (zend_overloaded_element *) property_reference->elements_list->tail->data; - VARIANT *pVar; - - if((zend_llist_count(property_reference->elements_list)==1) && !strcmp(Z_STRVAL(function_name->element), "variant")) - { - /* constructor */ - pval *object_handle, *data, *type, *code_page; - - ALLOC_VARIANT(pVar); - VariantInit(pVar); - - switch(ZEND_NUM_ARGS()) - { - case 0: - /* nothing to do */ - break; - case 1: - getParameters(ht, 1, &data); - php_pval_to_variant(data, pVar, codepage); - codepage = CP_ACP; - break; - case 2: - getParameters(ht, 2, &data, &type); - php_pval_to_variant_ex(data, pVar, type, codepage); - codepage = CP_ACP; - break; - case 3: - getParameters(ht, 3, &data, &type, &code_page); - php_pval_to_variant_ex(data, pVar, type, codepage); - convert_to_long(code_page); - codepage = code_page->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - RETVAL_LONG(zend_list_insert(pVar, IS_VARIANT)); - - if(!zend_is_true(return_value)) - { - ZVAL_FALSE(object); - return; - } - - ALLOC_ZVAL(object_handle); - *object_handle = *return_value; - pval_copy_constructor(object_handle); - INIT_PZVAL(object_handle); - zend_hash_index_update(Z_OBJPROP_P(object), 0, &object_handle, sizeof(pval *), NULL); - zval_dtor(&function_name->element); - } -} - - -pval php_VARIANT_get_property_handler(zend_property_reference *property_reference) -{ - zend_overloaded_element *overloaded_property; - int type; - pval result, **var_handle, *object = property_reference->object; - VARIANT *var_arg; - TSRMLS_FETCH(); - - /* fetch the VARIANT structure */ - zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &var_handle); - var_arg = zend_list_find(Z_LVAL_PP(var_handle), &type); - - if(!var_arg || (type != IS_VARIANT)) - { - ZVAL_FALSE(&result); - } - else - { - overloaded_property = (zend_overloaded_element *) property_reference->elements_list->head->data; - switch(overloaded_property->type) - { - case OE_IS_ARRAY: - ZVAL_FALSE(&result); - break; - - case OE_IS_OBJECT: - if(!strcmp(overloaded_property->element.value.str.val, "value")) - { - php_variant_to_pval(var_arg, &result, 0, codepage); - } - else if(!strcmp(Z_STRVAL(overloaded_property->element), "type")) - { - ZVAL_LONG(&result, V_VT(var_arg)) - } - else - { - ZVAL_FALSE(&result); - php_error(E_WARNING, "Unknown member."); - } - break; - case OE_IS_METHOD: - ZVAL_FALSE(&result); - php_error(E_WARNING, "Unknown method."); - break; - - zval_dtor(&overloaded_property->element); - } - } - - return result; -} - -int php_VARIANT_set_property_handler(zend_property_reference *property_reference, pval *value) -{ - zend_overloaded_element *overloaded_property; - int type; - pval **var_handle, *object = property_reference->object; - VARIANT *var_arg; - TSRMLS_FETCH(); - - /* fetch the VARIANT structure */ - zend_hash_index_find(Z_OBJPROP_P(object), 0, (void **) &var_handle); - var_arg = zend_list_find(Z_LVAL_PP(var_handle), &type); - - if(!var_arg || (type != IS_VARIANT)) - return FAILURE; - - overloaded_property = (zend_overloaded_element *) property_reference->elements_list->head->data; - do_VARIANT_propset(var_arg, &overloaded_property->element, value); - zval_dtor(&overloaded_property->element); - return SUCCESS; -} - -static int do_VARIANT_propset(VARIANT *var_arg, pval *arg_property, pval *value) -{ - pval type; - - Z_TYPE(type) = IS_STRING; - - if(!strcmp(Z_STRVAL_P(arg_property), "bVal")) - { - Z_LVAL(type) = VT_UI1; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "iVal")) - { - Z_LVAL(type) = VT_I2; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "lVal")) - { - Z_LVAL(type) = VT_I4; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "fltVal")) - { - Z_LVAL(type) = VT_R4; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "dblVal")) - { - Z_LVAL(type) = VT_R8; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "boolVal")) - { - Z_LVAL(type) = VT_BOOL; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "scode")) - { - Z_LVAL(type) = VT_ERROR; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "cyVal")) - { - Z_LVAL(type) = VT_CY; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "date")) - { - Z_LVAL(type) = VT_DATE; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "bstrVal")) - { - Z_LVAL(type) = VT_BSTR; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pdecVal")) - { - Z_LVAL(type) = VT_DECIMAL|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "punkVal")) - { - Z_LVAL(type) = VT_UNKNOWN; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pdispVal")) - { - Z_LVAL(type) = VT_DISPATCH; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "parray")) - { - Z_LVAL(type) = VT_ARRAY; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pbVal")) - { - Z_LVAL(type) = VT_UI1|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "piVal")) - { - Z_LVAL(type) = VT_I2|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "plVal")) - { - Z_LVAL(type) = VT_I4|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pfltVal")) - { - Z_LVAL(type) = VT_R4|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pdblVal")) - { - Z_LVAL(type) = VT_R8|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pboolVal")) - { - Z_LVAL(type) = VT_BOOL|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pscode")) - { - Z_LVAL(type) = VT_ERROR|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pcyVal")) - { - Z_LVAL(type) = VT_CY|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pdate")) - { - Z_LVAL(type) = VT_DATE|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pbstrVal")) - { - Z_LVAL(type) = VT_BSTR|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "ppunkVal")) - { - Z_LVAL(type) = VT_UNKNOWN|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "ppdispVal")) - { - Z_LVAL(type) = VT_DISPATCH|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pparray")) - { - Z_LVAL(type) = VT_ARRAY|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pvarVal")) - { - Z_LVAL(type) = VT_VARIANT|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "byref")) - { - Z_LVAL(type) = VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "cVal")) - { - Z_LVAL(type) = VT_I1; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "uiVal")) - { - Z_LVAL(type) = VT_UI2; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "ulVal")) - { - Z_LVAL(type) = VT_UI4; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "intVal")) - { - Z_LVAL(type) = VT_INT; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "uintVal")) - { - Z_LVAL(type) = VT_UINT|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pcVal")) - { - Z_LVAL(type) = VT_I1|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "puiVal")) - { - Z_LVAL(type) = VT_UI2|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pulVal")) - { - Z_LVAL(type) = VT_UI4|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "pintVal")) - { - Z_LVAL(type) = VT_INT|VT_BYREF; - } - else if(!strcmp(Z_STRVAL_P(arg_property), "puintVal")) - { - Z_LVAL(type) = VT_UINT|VT_BYREF; - } - else - { - php_error(E_WARNING, "Unknown member."); - return FAILURE; - } - - php_pval_to_variant_ex(value, var_arg, &type, codepage); - - return SUCCESS; -} - -static void php_variant_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - efree(rsrc); -} - -void php_register_VARIANT_class(TSRMLS_D) -{ - INIT_OVERLOADED_CLASS_ENTRY(VARIANT_class_entry, "VARIANT", NULL, - php_VARIANT_call_function_handler, - php_VARIANT_get_property_handler, - php_VARIANT_set_property_handler); - - zend_register_internal_class(&VARIANT_class_entry TSRMLS_CC); -} - -#endif /* PHP_WIN32 */ diff --git a/ext/rpc/com/variant.h b/ext/rpc/com/variant.h deleted file mode 100644 index ec25ee4e4b..0000000000 --- a/ext/rpc/com/variant.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef VARIANT_H -#define VARIANT_H - -#if PHP_WIN32 - -#define ALLOC_VARIANT(v) (v) = (VARIANT *) emalloc(sizeof(VARIANT)) -#define IS_VARIANT php_VARIANT_get_le_variant() - -#endif /* PHP_WIN32 */ - -#endif /* VARIANT_H */ diff --git a/ext/rpc/dotnet/CREDITS b/ext/rpc/dotnet/CREDITS deleted file mode 100644 index 154522c6f8..0000000000 --- a/ext/rpc/dotnet/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -dotnet -Sam Ruby diff --git a/ext/rpc/dotnet/EXPERIMENTAL b/ext/rpc/dotnet/EXPERIMENTAL deleted file mode 100644 index 6443e99646..0000000000 --- a/ext/rpc/dotnet/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this extension is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/ext/rpc/dotnet/README b/ext/rpc/dotnet/README deleted file mode 100644 index 8cad7bab8f..0000000000 --- a/ext/rpc/dotnet/README +++ /dev/null @@ -1,32 +0,0 @@ -Warning -======= - -This support is EXPERIMENTAL. In fact, it integrates code that -Microsoft labels as pre-beta. Use at your own risk. - -Build instructions -================== - -Download and install the .NET Framework SDK Technology Preview from -http://msdn.microsoft.com/net/#sdk. Once installed, copy Mscoree.h -(typically found in C:\Program Files\NGWSSDK\Include to ext\dotnet). -Do not simply add the NGWSSDK\Include directory to the include path -as this will cause compilation failures. - -Download and unzip the source to the dm.net COM Moniker from -http://staff.develop.com/jasonw/clr/readme.htm. Copy mscorlib.h -to ext\dotnet. There is no need to register the clrmonsrv.dll as -it is not used. - -At this point, the dotnet project can be built like any other -project, from either VisualStudio 6's GUI or from the command line. -Example command line invocation: - - msdev dotnet.dsp /MAKE "dotnet - Win32 Debug_TS" - -Execution instructions: -======================= - -Add "extension=php_dotnet.dll" into php.ini. - -Sample program can be found at dotnet.php diff --git a/ext/rpc/dotnet/dotnet.cpp b/ext/rpc/dotnet/dotnet.cpp deleted file mode 100644 index d0376bd87f..0000000000 --- a/ext/rpc/dotnet/dotnet.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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: Sam Ruby <rubys@us.ibm.com> | - | Harald Radi <h.radi@nme.at> | - +----------------------------------------------------------------------+ - */ - -/* - * This module implements support for Microsoft .Net components. - */ - -/* - * 28.1.2001 - * use external unicode conversion functions - * - * harald radi <h.radi@nme.at> - */ - -#ifdef PHP_WIN32 - -#include <iostream.h> -#include <math.h> -#include <comdef.h> - -extern "C" -{ -#include "php.h" -#include "ext/standard/info.h" -} - -#include "ext/com/conversion.h" -#include "ext/com/php_COM.h" - -#include "Mscoree.h" -#include "mscorlib.h" - -using namespace mscorlib; - -static ICorRuntimeHost *pHost; -static mscorlib::_AppDomain *pDomain; - -static zend_class_entry dotnet_class_entry; -static int codepage; - -HRESULT dotnet_init() { - HRESULT hr; - - hr = CoCreateInstance(CLSID_CorRuntimeHost, NULL, CLSCTX_ALL, - IID_ICorRuntimeHost, (void **)&pHost); - if (FAILED(hr)) return hr; - - hr = pHost->Start(); - if (FAILED(hr)) return hr; - - IUnknown *uDomain; - hr = pHost->GetDefaultDomain(&uDomain); - if (FAILED(hr)) return hr; - - hr = uDomain->QueryInterface(__uuidof(_AppDomain), (void**) &pDomain); - if (FAILED(hr)) return -1; - - uDomain->Release(); - - return ERROR_SUCCESS; -} - -HRESULT dotnet_create(OLECHAR *assembly, OLECHAR *datatype, comval *obj TSRMLS_DC) { - HRESULT hr; - - _ObjectHandle *pHandle; - hr = pDomain->CreateInstance(_bstr_t(assembly), _bstr_t(datatype), &pHandle); - if (FAILED(hr)) return hr; - if (!pHandle) return hr; - - _variant_t unwrapped; - hr = pHandle->Unwrap(&unwrapped); - pHandle->Release(); - if (FAILED(hr)) return hr; - - php_COM_set(obj, &unwrapped.pdispVal, TRUE TSRMLS_CC); - return ERROR_SUCCESS; -} - -void dotnet_term() { - if (pHost) pHost->Stop(); - if (pHost) pHost->Release(); - if (pDomain) pDomain->Release(); - - pHost = 0; - pDomain = 0; -} - -/* {{{ proto int dotnet_load(string assembly_name [, string datatype_name, int codepage]) - Loads a DOTNET module */ -PHP_FUNCTION(dotnet_load) -{ - HRESULT hr; - pval *assembly_name, *datatype_name, *code_page; - OLECHAR *assembly, *datatype; - comval *obj; - - switch(ZEND_NUM_ARGS()) - { - case 2: - getParameters(ht, 2, &assembly_name, &datatype_name); - codepage = CP_ACP; - break; - case 3: - getParameters(ht, 3, &assembly_name, &datatype_name, &code_page); - - convert_to_long(code_page); - codepage = Z_LVAL_P(code_page); - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string(assembly_name); - assembly = php_char_to_OLECHAR(Z_STRVAL_P(assembly_name), Z_STRLEN_P(assembly_name), codepage TSRMLS_CC); - - convert_to_string(datatype_name); - datatype = php_char_to_OLECHAR(Z_STRVAL_P(datatype_name), Z_STRLEN_P(datatype_name), codepage TSRMLS_CC); - - ALLOC_COM(obj); - - /* obtain IDispatch */ - hr = dotnet_create(assembly, datatype, obj TSRMLS_CC); - efree(assembly); - efree(datatype); - if (FAILED(hr)) { - char *error_message; - error_message = php_COM_error_message(hr TSRMLS_CC); - php_error(E_WARNING,"Error obtaining .Net class for %s in assembly %s: %s",datatype_name->value.str.val,assembly_name->value.str.val,error_message); - LocalFree(error_message); - efree(obj); - RETURN_FALSE; - } - if (C_DISPATCH(obj) == NULL) { - php_error(E_WARNING,"Unable to locate %s in assembly %s",datatype_name->value.str.val,assembly_name->value.str.val); - efree(obj); - RETURN_FALSE; - } - - RETURN_LONG(zend_list_insert(obj, IS_COM)); -} -/* }}} */ - - -void php_DOTNET_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - pval *object = property_reference->object; - zend_overloaded_element *function_name = (zend_overloaded_element *) property_reference->elements_list->tail->data; - - if (zend_llist_count(property_reference->elements_list)==1 - && !strcmp(Z_STRVAL(function_name->element), "dotnet")) { /* constructor */ - pval *object_handle; - - PHP_FN(dotnet_load)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (!Z_LVAL_P(return_value)) { - ZVAL_FALSE(object); - return; - } - ALLOC_ZVAL(object_handle); - *object_handle = *return_value; - pval_copy_constructor(object_handle); - INIT_PZVAL(object_handle); - zend_hash_index_update(object->value.obj.properties, 0, &object_handle, sizeof(pval *), NULL); - pval_destructor(&function_name->element); - } else { - php_COM_call_function_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, property_reference); - } -} - -void php_register_DOTNET_class(TSRMLS_D) -{ - INIT_OVERLOADED_CLASS_ENTRY(dotnet_class_entry, "DOTNET", NULL, - php_DOTNET_call_function_handler, - php_COM_get_property_handler, - php_COM_set_property_handler); - - zend_register_internal_class(&dotnet_class_entry TSRMLS_CC); -} - -function_entry DOTNET_functions[] = { - {NULL, NULL, NULL} -}; - -static PHP_MINFO_FUNCTION(DOTNET) -{ - php_info_print_table_start(); - php_info_print_table_row(2, ".NET support", "enabled"); - php_info_print_table_end(); -} - -PHP_MINIT_FUNCTION(DOTNET) -{ - HRESULT hr; - - CoInitialize(0); - hr = dotnet_init(); - if (FAILED(hr)) { - return hr; - } - - php_register_DOTNET_class(TSRMLS_C); - return SUCCESS; -} - - -PHP_MSHUTDOWN_FUNCTION(DOTNET) -{ - dotnet_term(); - CoUninitialize(); - return SUCCESS; -} - - -zend_module_entry dotnet_module_entry = { - "dotnet", DOTNET_functions, PHP_MINIT(DOTNET), PHP_MSHUTDOWN(DOTNET), NULL, NULL, PHP_MINFO(DOTNET), STANDARD_MODULE_PROPERTIES -}; - -BEGIN_EXTERN_C() -ZEND_GET_MODULE(dotnet) -END_EXTERN_C() - -#endif diff --git a/ext/rpc/dotnet/dotnet.dsp b/ext/rpc/dotnet/dotnet.dsp deleted file mode 100644 index a0b151f68a..0000000000 --- a/ext/rpc/dotnet/dotnet.dsp +++ /dev/null @@ -1,171 +0,0 @@ -# Microsoft Developer Studio Project File - Name="dotnet" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=dotnet - 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 "dotnet.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 "dotnet.mak" CFG="dotnet - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "dotnet - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "dotnet - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "dotnet - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "dotnet - 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)" == "dotnet - 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_dotnet.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release"
-
-!ELSEIF "$(CFG)" == "dotnet - 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_dotnet.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug"
-
-!ELSEIF "$(CFG)" == "dotnet - 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_dotnet.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "dotnet - 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_dotnet.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "dotnet - Win32 Release"
-# Name "dotnet - Win32 Debug"
-# Name "dotnet - Win32 Debug_TS"
-# Name "dotnet - Win32 Release_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\dotnet.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\..\..\win32\winutil.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_dotnet.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\README
-# End Source File
-# End Target
-# End Project
diff --git a/ext/rpc/dotnet/dotnet.php b/ext/rpc/dotnet/dotnet.php deleted file mode 100644 index 3b0b67c02f..0000000000 --- a/ext/rpc/dotnet/dotnet.php +++ /dev/null @@ -1,8 +0,0 @@ -<? - $stack = new DOTNET("mscorlib","System.Collections.Stack"); - - $stack->Push(".Net"); - $stack->Push("Hello "); - - echo $stack->Pop() . $stack->Pop(); -?> diff --git a/ext/rpc/dotnet/php_dotnet.h b/ext/rpc/dotnet/php_dotnet.h deleted file mode 100644 index b56af145e2..0000000000 --- a/ext/rpc/dotnet/php_dotnet.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef PHP_DOTNET_H -#define PHP_DOTNET_H - -#if WIN32|WINNT - -PHP_MINIT_FUNCTION(DOTNET); -PHP_MSHUTDOWN_FUNCTION(DOTNET); -PHP_FUNCTION(DOTNET_load); - -extern zend_module_entry DOTNET_module_entry; -#define DOTNET_module_ptr &DOTNET_module_entry - -#else - -#define DOTNET_module_ptr NULL - -#endif /* Win32|WINNT */ - -#define phpext_DOTNET_ptr DOTNET_module_ptr - -#endif /* PHP_DOTNET_H */ diff --git a/ext/rpc/java/CREDITS b/ext/rpc/java/CREDITS deleted file mode 100644 index f49489bcf8..0000000000 --- a/ext/rpc/java/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -Java -Sam Ruby diff --git a/ext/rpc/java/Makefile.in b/ext/rpc/java/Makefile.in deleted file mode 100644 index 2a980157d2..0000000000 --- a/ext/rpc/java/Makefile.in +++ /dev/null @@ -1,25 +0,0 @@ - -LTLIBRARY_SHARED_NAME = libphp_java.la -LTLIBRARY_SOURCES = java.c -LTLIBRARY_DEPENDENCIES = php_java.jar - -LTLIBRARY_LDFLAGS = $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) -LTLIBRARY_SHARED_LIBADD = $(LTLIBRARY_DEPENDENCIES) $(EXTRA_LIBS) - -EXTRA_CFLAGS = $(JAVA_CFLAGS) -EXTRA_INCLUDES = $(JAVA_INCLUDE) - -make_shared = yes - -include $(top_srcdir)/build/dynlib.mk - -php_java.jar : reflect.java - $(mkinstalldirs) net/php - @cp $(srcdir)/reflect.java net/php - @echo library=php_java>net/php/reflect.properties - javac net/php/reflect.java - @test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac - $(JAVA_JAR) php_java.jar net/php/*.class net/php/*.properties - @rm net/php/reflect.* - @rmdir net/php - @rmdir net diff --git a/ext/rpc/java/README b/ext/rpc/java/README deleted file mode 100644 index 1cfdc113eb..0000000000 --- a/ext/rpc/java/README +++ /dev/null @@ -1,243 +0,0 @@ -What is PHP4 ext/java? - - PHP4 ext/java provides a simple and effective means for creating and - invoking methods on Java objects from PHP. The JVM is created using JNI, - and everything runs in-process. - - Two examples are provided, jver and jawt, to illustrate usage of this - extension. A few things to note: - - 1) new Java() will create an instance of a class if a suitable constructor - is available. If no parameters are passed and the default constructor - is useful as it provides access to classes like "java.lang.System" - which expose most of their functionallity through static methods. - - 2) Accessing a member of an instance will first look for bean properties - then public fields. In other words, "print $date.time" will first - attempt to be resolved as "$date.getTime()", then as "$date.time"; - - 3) Both static and instance members can be accessed on an object with - the same syntax. Furthermore, if the java object is of type - "java.lang.Class", then static members of the class (fields and - methods) can be accessed. - - 4) Exceptions raised result in PHP warnings, and null results. The - warnings may be eliminated by prefixing the method call with an - "@" sign. The following APIs may be used to retrieve and reset - the last error: - - java_last_exception_get() - java_last_exception_clear() - - 5) Overload resolution is in general a hard problem given the - differences in types between the two languages. The PHP Java - extension employs a simple, but fairly effective, metric for - determining which overload is the best match. - - Additionally, method names in PHP are not case sensitive, potentially - increasing the number of overloads to select from. - - Once a method is selected, the parameters are cooerced if necessary, - possibly with a loss of data (example: double precision floating point - numbers will be converted to boolean). - - 6) In the tradition of PHP, arrays and hashtables may pretty much - be used interchangably. Note that hashtables in PHP may only be - indexed by integers or strings; and that arrays of primitive types - in Java can not be sparse. Also note that these constructs are - passed by value, so may be expensive in terms of memory and time. - -Build and execution instructions: - - Given the number of platforms and providers of JVMs, no single set of - instructions will be able to cover all cases. So in place of hard and - fast instructions, below are a working examples for a number of free and - commercial implementations and platforms. Please adjust the paths to - suit your installation. Also, if you happen to get this to work on - another JVM/platform combination, please let me know, particularly if - a unique build or execution setup was required. - - Note for Windows users: semi-colons (";") mark the beginning of - comments in php.ini files, so if you wish to add to the classpath, - make sure that the entire string is in quotes. See the JDK 1.1.8 - instructions below for an example. - - This function has been tested in both CGI and Apache (apxs) modes. As - the current design requires shared libraries, this support can not be - linked statically into Apache. - - With ext/java, no Java Virtual Machines are created until the first - Java call is made. This not only eliminates unnecessary overhead if - the extension is never used, it also provides error messages directly - back to the user instead of being burried in a log some place. - - For people interested in robustness, performance, and more complete - integration with Java, consider using the sapi/servlet interface which - is built upon the Java extension. Running PHP as a servlet enables PHP - to utilize the existing JVM and threads from the servlet engine, and - provides direct access to the servlet request and response objects. - - Finally, the bottom of this readme contains some guidance for how to - approach situations in which these instructions don't work on your - machine. - -======================================================================== -=== JVM=Kaffe 1.0.4 (as delivered with OS), OS=Redhat Linux 6.1 === -======================================================================== - -build instructions: - - ./configure --with-java - -php.ini: - - [java] - java.library.path=/usr/lib/kaffe:/home/rubys/php4/modules - java.class.path=/usr/share/kaffe/Klasses.jar:/home/rubys/php4/modules/php_java.jar - extension_dir=/home/rubys/php4/modules - extension=libphp_java.so - -======================================================================== -=== JVM=Kaffe 1.0.5 (built from source), OS=Redhat Linux 6.1 === -======================================================================== - -build instructions: - - ./configure --with-java - -php.ini: - - [java] - java.library.path=/usr/local/lib/kaffe:/home/rubys/php4/modules - java.class.path=/usr/local/share/kaffe/Klasses.jar:/home/rubys/php4/modules/php_java.jar - extension_dir=/home/rubys/php4/modules - extension=libphp_java.so - -======================================================================== -=== JVM=IBM 1.1.8, OS=Redhat Linux 6.1 === -======================================================================== - -build instructions: - - ./configure --with-java - -php.ini: - - [java] - java.class.path=/home/jdk118/lib/classes.zip:/home/rubys/php4/modules/php_java.jar - extension_dir=/home/rubys/php4/modules - extension=libphp_java.so - -======================================================================== -=== JVM=Blackdown 1.2.2 RC4, OS=Redhat Linux 6.1 === -======================================================================== - -build instructions: - - ./configure --with-java - -php.ini: - - [java] - java.class.path=/home/rubys/php4/lib/php_java.jar - extension_dir=/home/rubys/php4/modules - extension=libphp_java.so - -======================================================================== -=== JVM=Sun JDK 1.2.2, OS=Linux === -======================================================================== - -build instructions: - - ./configure --with-java - -php.ini: - - [java] - java.class.path=/home/rubys/php4/lib/php_java.jar - java.library.path=/home/rubys/php4/modules - extension_dir=/home/rubys/php4/modules - extension=libphp_java.so - -======================================================================== -=== JVM=Sun JDK 1.1.8, OS=Windows NT 4 === -======================================================================== - -build instructions: - - SET JAVA_HOME=D:\jdk1.1.8 - msdev ext\java\java.dsp /MAKE "java - Win32 Debug_TS" - -php.ini: - - [java] - java.class.path="D:\jdk1.1.8\lib\classes.zip;F:\PHP4\Debug_TS\php_java.jar" - extension=php_java.dll - -======================================================================== -=== JVM=Sun JDK 1.2.2, OS=Windows NT 4 === -======================================================================== - -build instructions: - - SET JAVA_HOME=D:\jdk1.2.2 - msdev ext\java\java.dsp /MAKE "java - Win32 Debug_TS" - -php.ini: - - [java] - java.class.path=F:\PHP4\Debug_TS\php_java.jar - extension=php_java.dll - -========================================================================= - -Guidance for when these instructions don't work. - - JDK vendors don't typically document their internal workings, and are - typically very reliant on code inside of the JAVA main program and the - installation directory structure. For this reason, running PHP as a - servlet is typically much easier to get working. But if for some reason - this is not appropriate for you, and the instructions above don't work, - then read on. - - The first thing to realize is that the directory structure of the JDK is - very important. Some users (particularly on Windows) get a message about - a DLL or shared library not being available and proceed to find that file - and copy it into a system directory. This typically just gets you to the - next problem - for example, it appears that many JDKs attempt to locate - the runtime Java classes (rt.jar) in a directory relative to these system - libraries. So unless you are inclined to copy your entire Java - installation, you are much better adjusting your PATHs. - - Not documented above, but useful for many JDK's is ability to specify the - library path via java.library.path in the php.ini. On many Unix machines, - determining the initial value for this can be done by changing directory - to where you find a shared library that can't be loaded (example: - libjava.so), and executing "ld libjava.so". If you see some modules - listed as "not found", add the necessary directories to LD_LIBRARY_PATH - and repeat until successful. On my system, I require the following - two directories. - - /home/jdk1.2.2/jre/lib/i386/native_threads - /home/jdk1.2.2/jre/lib/i386/classic - - Note: this only determines the statically loaded libraries. Additional - libraries (such as libzip.so) may be loaded dynamically. On my system, - libzip.so is located in - - /home/jdk1.2.2/jre/lib/i386 - - Another php.ini variable which may be helpful is java.home. - - If java.library.path doesn't work for you (it won't on any JDK 1.1 - implementations, for example), then try setting the system PATH or the - LD_LIBRARY_PATH before starting your web server. For Apache on Linux - systems, this can be accomplished by editing the Root's .bashrc and - adding the necessary export LD_LIBRARY_PATH statement. - - If that doesn't work, try dividing an (hopefully) conquering by temporarily - eliminating items such as Apache from the process by adjusting the - arguments passed to the ./configure command (i.e., removing --with-apxs). - - If all else fails, "man dlopen" on Unix systems will give more insight on - what the system is trying to do internally. diff --git a/ext/rpc/java/config.m4 b/ext/rpc/java/config.m4 deleted file mode 100644 index 34aa68a27f..0000000000 --- a/ext/rpc/java/config.m4 +++ /dev/null @@ -1,118 +0,0 @@ -# $Id$ -# config.m4 for extension java - -AC_MSG_CHECKING(for Java support) -AC_ARG_WITH(java, -[ --with-java[=DIR] Include Java support. DIR is the base install - directory for the JDK. This extension can only - be built as a shared dl.], -[ - if test "$withval" != "no"; then - JAVA_SHARED=libphp_java.la - - pltform=`uname -s 2>/dev/null` - java_libext=libjava.so - case $pltform in - AIX) java_libext=libjava.a ;; - HP-UX) java_libext=libjava.sl ;; - esac - # substitute zip for systems which don't have jar in the PATH - if JAVA_JAR=`which jar 2>/dev/null`; then - JAVA_JAR="$JAVA_JAR cf" - else - JAVA_JAR='zip -q0' - fi - - if test "$withval" = "yes"; then - withval=`cd \`dirname \\\`which javac\\\`\`/..;pwd` - fi - - if test -d $withval/lib/kaffe; then - PHP_ADD_LIBPATH($withval/lib) - PHP_ADD_LIBPATH($withval/lib/kaffe) - - JAVA_CFLAGS=-DKAFFE - JAVA_INCLUDE=-I$withval/include/kaffe - JAVA_CLASSPATH=$withval/share/kaffe/Klasses.jar - JAVA_LIB=kaffevm - java_libext=kaffevm - - test -f $withval/lib/$JAVA_LIB && JAVA_LIBPATH=$withval/lib - test -f $withval/lib/kaffe/$JAVA_LIB && JAVA_LIBPATH=$withval/lib/kaffe - - # accomodate old versions of kaffe which don't support jar - if kaffe -version 2>&1 | grep 1.0b > /dev/null; then - JAVA_JAR='zip -q0' - fi - - elif test -f $withval/lib/$java_libext; then - JAVA_LIB=java - JAVA_LIBPATH=$withval/lib - JAVA_INCLUDE=-I$withval/include - test -f $withval/lib/classes.zip && JAVA_CFLAGS=-DJNI_11 - test -f $withval/lib/jvm.jar && JAVA_CFLAGS=-DJNI_12 - test -f $withval/lib/classes.zip && JAVA_CLASSPATH=$withval/lib/classes.zip - test -f $withval/lib/jvm.jar && JAVA_CLASSPATH=$withval/lib/jvm.jar - for i in $JAVA_INCLUDE/*; do - test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE $i" - done - - else - - for i in `find $withval/include -type d`; do - test -f $i/jni.h && JAVA_INCLUDE=-I$i - test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE -I$i" - done - - for i in `find $withval -type d`; do - test -f $i/classes.zip && JAVA_CFLAGS=-DJNI_11 - test -f $i/rt.jar && JAVA_CFLAGS=-DJNI_12 - test -f $i/classes.zip && JAVA_CLASSPATH=$i/classes.zip - test -f $i/rt.jar && JAVA_CLASSPATH=$i/rt.jar - - if test -f $i/$java_libext; then - JAVA_LIB=java - JAVA_LIBPATH=$i - test -d $i/hotspot && PHP_ADD_LIBPATH($i/hotspot) - test -d $i/classic && PHP_ADD_LIBPATH($i/classic) - test -d $i/server && PHP_ADD_LIBPATH($i/server) - test -d $i/native_threads && PHP_ADD_LIBPATH($i/native_threads) - fi - done - - if test -z "$JAVA_INCLUDE"; then - AC_MSG_RESULT(no) - AC_MSG_ERROR(unable to find Java VM libraries) - fi - - JAVA_CFLAGS="$JAVA_CFLAGS -D_REENTRANT" - fi - - AC_DEFINE(HAVE_JAVA,1,[ ]) - PHP_ADD_LIBPATH($JAVA_LIBPATH) - JAVA_CFLAGS="$JAVA_CFLAGS '-DJAVALIB=\"$JAVA_LIBPATH/$java_libext\"'" - - if test "$PHP_SAPI" != "servlet"; then - PHP_EXTENSION(java, shared) - - if test "$PHP_SAPI" = "cgi"; then - PHP_ADD_LIBRARY($JAVA_LIB) - fi - - INSTALL_IT="$INSTALL_IT; \$(srcdir)/build/shtool mkdir -p -f -m 0755 \$(INSTALL_ROOT)\$(libdir)" - INSTALL_IT="$INSTALL_IT; \$(INSTALL) -m 0755 \$(srcdir)/ext/java/php_java.jar \$(INSTALL_ROOT)\$(libdir)" - fi - - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi -],[ - AC_MSG_RESULT(no) -]) - -PHP_SUBST(JAVA_CFLAGS) -PHP_SUBST(JAVA_CLASSPATH) -PHP_SUBST(JAVA_INCLUDE) -PHP_SUBST(JAVA_SHARED) -PHP_SUBST(JAVA_JAR) diff --git a/ext/rpc/java/except.php b/ext/rpc/java/except.php deleted file mode 100644 index a7e6a79c08..0000000000 --- a/ext/rpc/java/except.php +++ /dev/null @@ -1,23 +0,0 @@ -<? - $stack=new Java("java.util.Stack"); - $stack->push(1); - - # - # Should succeed and print out "1" - # - $result = $stack->pop(); - $ex = java_last_exception_get(); - if (!$ex) print "$result\n"; - - # - # Should fail - note the "@" eliminates the warning - # - $result=@$stack->pop(); - $ex=java_last_exception_get(); - if ($ex) print $ex->toString(); - - # - # Reset last exception - # - java_last_exception_clear(); -?> diff --git a/ext/rpc/java/java.c b/ext/rpc/java/java.c deleted file mode 100644 index 896388162c..0000000000 --- a/ext/rpc/java/java.c +++ /dev/null @@ -1,774 +0,0 @@ - /* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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: Sam Ruby (rubys@us.ibm.com) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - * This module implements Zend OO syntax overloading support for Java - * components using JNI and reflection. - */ - - -#include "php.h" -#include "zend_compile.h" -#include "php_ini.h" -#include "php_globals.h" - -#ifdef PHP_WIN32 - #include "win32/winutil.h" - #define DL_ERROR php_win_err() -#else - #define DL_ERROR dlerror() -#endif - -#include <jni.h> - -#include <stdio.h> - -#define IS_EXCEPTION 86 - -/***************************************************************************/ - -#ifndef KAFFE -#ifndef JNI_11 -#ifndef JNI_12 - -#ifdef JNI_VERSION_1_2 -#define JNI_12 -#else -#define JNI_11 -#endif - -#endif -#endif -#endif - -#ifdef PHP_WIN32 -#ifdef JNI_12 -#define JAVALIB "jvm.dll" -#else -#define JAVALIB "javai.dll" -#endif -#else -#endif - -/***************************************************************************/ - -static int le_jobject = 0; - -static char *classpath = 0; -static char *libpath = 0; -static char *javahome = 0; -static char *javalib = 0; - -static int iniUpdated = 0; -static void *dl_handle = 0; - -ZEND_BEGIN_MODULE_GLOBALS(java) - JavaVM *jvm; - JNIEnv *jenv; - jobject php_reflect; - jclass reflect_class; -ZEND_END_MODULE_GLOBALS(java) - -#ifdef ZTS -# define JG(v) TSRMG(java_globals_id, zend_java_globals *, v) -#else -# define JG(v) (java_globals.v) -#endif - -ZEND_DECLARE_MODULE_GLOBALS(java) - -static zend_class_entry java_class_entry; - -static PHP_INI_MH(OnIniUpdate) -{ - if (new_value) *(char**)mh_arg1 = new_value; - iniUpdated=1; - return SUCCESS; -} - -PHP_INI_BEGIN() - PHP_INI_ENTRY1("java.class.path", NULL, PHP_INI_ALL, OnIniUpdate, &classpath) -#ifndef JNI_11 - PHP_INI_ENTRY1("java.home", NULL, PHP_INI_ALL, OnIniUpdate, &javahome) - PHP_INI_ENTRY1("java.library.path", NULL, PHP_INI_ALL, OnIniUpdate, &libpath) -#endif -#ifdef JAVALIB - PHP_INI_ENTRY1("java.library", JAVALIB, PHP_INI_ALL, OnIniUpdate, &javalib) -#else - PHP_INI_ENTRY1("java.library", NULL, PHP_INI_ALL, OnIniUpdate, &javalib) -#endif -PHP_INI_END() - -/***************************************************************************/ - -/* - * Destroy a Java Virtual Machine. - */ -void jvm_destroy(TSRMLS_D) -{ - if (JG(php_reflect)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), JG(php_reflect)); - if (JG(jvm)) { - (*JG(jvm))->DetachCurrentThread(JG(jvm)); - (*JG(jvm))->DestroyJavaVM(JG(jvm)); - JG(jvm) = 0; - } - if (dl_handle) DL_UNLOAD(dl_handle); - JG(php_reflect) = 0; - JG(jenv) = 0; -} - -/* - * Create a Java Virtual Machine. - * - class.path, home, and library.path are read out of the INI file - * - appropriate (pre 1.1, JDK 1.1, and JDK 1.2) initialization is performed - * - net.php.reflect class file is located - */ - -#ifdef JNI_12 -static void addJVMOption(JavaVMInitArgs *vm_args, char *name, char *value) -{ - char *option = (char*) malloc(strlen(name) + strlen(value) + 1); - strcpy(option, name); - strcat(option, value); - vm_args->options[vm_args->nOptions++].optionString = option; -} -#endif - -static int jvm_create(TSRMLS_D) -{ - int rc; - jobject local_php_reflect; - jthrowable error; - - jint (JNICALL *JNI_CreateVM)(const void*,const void*,void*); -#ifndef JNI_12 - jint (JNICALL *JNI_DefaultArgs)(void*); -#endif - -#ifdef JNI_11 - JDK1_1InitArgs vm_args; -#else - JavaVMInitArgs vm_args; -#ifdef JNI_12 - JavaVMOption options[3]; -#endif -#endif - - iniUpdated=0; - - if (javalib) { - dl_handle = DL_LOAD(javalib); - - if (!dl_handle) { - php_error(E_ERROR, "Unable to load Java Library %s, error: %s", - javalib, DL_ERROR); - return -1; - } - } - -#ifndef JAVALIB - if (!dl_handle) - JNI_CreateVM = &JNI_CreateJavaVM; - else -#endif - - JNI_CreateVM = (jint (JNICALL *)(const void*,const void*,void*)) - DL_FETCH_SYMBOL(dl_handle, "JNI_CreateJavaVM"); - - if (!JNI_CreateVM) { - php_error(E_ERROR, "Unable to locate CreateJavaVM function"); - return -1; - } - -#ifdef JNI_12 - - vm_args.version = JNI_VERSION_1_2; - vm_args.ignoreUnrecognized = JNI_FALSE; - vm_args.options = options; - vm_args.nOptions = 0; - - if (classpath) addJVMOption(&vm_args, "-Djava.class.path=", classpath); - if (javahome) addJVMOption(&vm_args, "-Djava.home=", javahome); - if (libpath) addJVMOption(&vm_args, "-Djava.library.path=", libpath); - -#else - -#ifndef JAVALIB - if (!dl_handle) - JNI_DefaultArgs = &JNI_GetDefaultJavaVMInitArgs; - else -#endif - - JNI_DefaultArgs = (jint (JNICALL *)(void*)) - DL_FETCH_SYMBOL(dl_handle, "JNI_GetDefaultJavaVMInitArgs"); - - if (!JNI_DefaultArgs) { - php_error(E_ERROR, "Unable to locate GetDefaultJavaVMInitArgs function"); - return -1; - } - - vm_args.version=0x00010001; - (*JNI_DefaultArgs)(&vm_args); - - if (!classpath) classpath = ""; - vm_args.classpath = classpath; -#ifdef KAFFE - vm_args.classhome = javahome; - vm_args.libraryhome = libpath; -#endif - -#endif - - rc = (*JNI_CreateVM)(&JG(jvm), &JG(jenv), &vm_args); - - if (rc) { - php_error(E_ERROR, "Unable to create Java Virtual Machine"); - return rc; - } - - JG(reflect_class) = (*JG(jenv))->FindClass(JG(jenv), "net/php/reflect"); - error = (*JG(jenv))->ExceptionOccurred(JG(jenv)); - if (error) { - jclass errClass; - jmethodID toString; - jobject errString; - const char *errAsUTF; - jboolean isCopy; - JNIEnv *jenv = JG(jenv); - (*jenv)->ExceptionClear(jenv); - errClass = (*jenv)->GetObjectClass(jenv, error); - toString = (*jenv)->GetMethodID(jenv, errClass, "toString", - "()Ljava/lang/String;"); - errString = (*jenv)->CallObjectMethod(jenv, error, toString); - errAsUTF = (*jenv)->GetStringUTFChars(jenv, errString, &isCopy); - php_error(E_ERROR, "%s", errAsUTF); - if (isCopy) (*jenv)->ReleaseStringUTFChars(jenv, error, errAsUTF); - jvm_destroy(TSRMLS_C); - return -1; - } - - local_php_reflect = (*JG(jenv))->AllocObject(JG(jenv), JG(reflect_class)); - JG(php_reflect) = (*JG(jenv))->NewGlobalRef(JG(jenv), local_php_reflect); - return rc; -} - -/***************************************************************************/ - -static jobject _java_makeObject(pval* arg TSRMLS_DC) -{ - JNIEnv *jenv = JG(jenv); - jobject result; - pval **handle; - int type; - jmethodID makeArg; - jclass hashClass; - - switch (arg->type) { - case IS_STRING: - result=(*jenv)->NewByteArray(jenv,arg->value.str.len); - (*jenv)->SetByteArrayRegion(jenv,(jbyteArray)result,0, - arg->value.str.len, arg->value.str.val); - break; - - case IS_OBJECT: - zend_hash_index_find(arg->value.obj.properties, 0, (void*)&handle); - result = zend_list_find((*handle)->value.lval, &type); - break; - - case IS_BOOL: - makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg", - "(Z)Ljava/lang/Object;"); - result = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg, - (jboolean)(arg->value.lval)); - break; - - case IS_LONG: - makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg", - "(J)Ljava/lang/Object;"); - result = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg, - (jlong)(arg->value.lval)); - break; - - case IS_DOUBLE: - makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg", - "(D)Ljava/lang/Object;"); - result = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg, - (jdouble)(arg->value.dval)); - break; - - case IS_ARRAY: - { - jobject jkey, jval; - zval **value; - zval key; - char *string_key; - ulong num_key; - jobject jold; - jmethodID put, init; - - hashClass = (*jenv)->FindClass(jenv, "java/util/Hashtable"); - init = (*jenv)->GetMethodID(jenv, hashClass, "<init>", "()V"); - result = (*jenv)->NewObject(jenv, hashClass, init); - - put = (*jenv)->GetMethodID(jenv, hashClass, "put", - "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - - /* Iterate through hash */ - zend_hash_internal_pointer_reset(arg->value.ht); - while(zend_hash_get_current_data(arg->value.ht, (void**)&value) == SUCCESS) { - jval = _java_makeObject(*value TSRMLS_CC); - - switch (zend_hash_get_current_key(arg->value.ht, &string_key, &num_key, 0)) { - case HASH_KEY_IS_STRING: - key.type = IS_STRING; - key.value.str.val = string_key; - key.value.str.len = strlen(string_key); - jkey = _java_makeObject(&key TSRMLS_CC); - break; - case HASH_KEY_IS_LONG: - key.type = IS_LONG; - key.value.lval = num_key; - jkey = _java_makeObject(&key TSRMLS_CC); - break; - default: /* HASH_KEY_NON_EXISTANT */ - jkey = 0; - } - jold = (*jenv)->CallObjectMethod(jenv, result, put, jkey, jval); - if ((*value)->type != IS_OBJECT) (*jenv)->DeleteLocalRef(jenv, jval); - zend_hash_move_forward(arg->value.ht); - } - - break; - } - - default: - result=0; - } - - return result; -} - -/***************************************************************************/ - -static jobjectArray _java_makeArray(int argc, pval** argv TSRMLS_DC) -{ - JNIEnv *jenv = JG(jenv); - - jclass objectClass = (*jenv)->FindClass(jenv, "java/lang/Object"); - jobjectArray result = (*jenv)->NewObjectArray(jenv, argc, objectClass, 0); - jobject arg; - int i; - - for (i=0; i<argc; i++) { - arg = _java_makeObject(argv[i] TSRMLS_CC); - (*jenv)->SetObjectArrayElement(jenv, result, i, arg); - if (argv[i]->type != IS_OBJECT) (*jenv)->DeleteLocalRef(jenv, arg); - } - return result; -} - - -static int checkError(pval *value) -{ - if (value->type == IS_EXCEPTION) { - php_error(E_WARNING, "%s", value->value.str.val); - efree(value->value.str.val); - ZVAL_FALSE(value); - return 1; - }; - return 0; -} - - -/***************************************************************************/ - -/* - * Invoke a method on an object. If method name is "java", create a new - * object instead. - */ -void java_call_function_handler(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - JNIEnv *jenv; - - pval *object = property_reference->object; - zend_overloaded_element *function_name = (zend_overloaded_element *) - property_reference->elements_list->tail->data; - - int arg_count = ZEND_NUM_ARGS(); - jlong result = 0; - pval **arguments = (pval **) emalloc(sizeof(pval *)*arg_count); - - getParametersArray(ht, arg_count, arguments); - - if (iniUpdated && JG(jenv)) jvm_destroy(TSRMLS_C); - if (!JG(jenv)) jvm_create(TSRMLS_C); - if (!JG(jenv)) return; - jenv = JG(jenv); - - if (!strcmp("java",function_name->element.value.str.val)) { - - /* construct a Java object: - First argument is the class name. Any additional arguments will - be treated as constructor parameters. */ - - jmethodID co = (*jenv)->GetMethodID(jenv, JG(reflect_class), "CreateObject", - "(Ljava/lang/String;[Ljava/lang/Object;J)V"); - jstring className; - result = (jlong)(long)object; - - if (ZEND_NUM_ARGS() < 1) { - php_error(E_ERROR, "Missing classname in new Java() call"); - return; - } - - className=(*jenv)->NewStringUTF(jenv, arguments[0]->value.str.val); - (*jenv)->CallVoidMethod(jenv, JG(php_reflect), co, - className, _java_makeArray(arg_count-1, arguments+1 TSRMLS_CC), result); - - (*jenv)->DeleteLocalRef(jenv, className); - - } else { - - pval **handle; - int type; - jobject obj; - jstring method; - - /* invoke a method on the given object */ - - jmethodID invoke = (*jenv)->GetMethodID(jenv, JG(reflect_class), "Invoke", - "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;J)V"); - zend_hash_index_find(object->value.obj.properties, 0, (void**) &handle); - obj = zend_list_find((*handle)->value.lval, &type); - method = (*jenv)->NewStringUTF(jenv, function_name->element.value.str.val); - result = (jlong)(long)return_value; - - (*jenv)->CallVoidMethod(jenv, JG(php_reflect), invoke, - obj, method, _java_makeArray(arg_count, arguments TSRMLS_CC), result); - - (*jenv)->DeleteLocalRef(jenv, method); - - } - - efree(arguments); - pval_destructor(&function_name->element); - - checkError((pval*)(long)result); -} - -/***************************************************************************/ - -PHP_FUNCTION(java_last_exception_get) -{ - jlong result = 0; - jmethodID lastEx; - - if (ZEND_NUM_ARGS()!=0) WRONG_PARAM_COUNT; - - result = (jlong)(long)return_value; - - lastEx = (*JG(jenv))->GetMethodID(JG(jenv), JG(reflect_class), - "lastException", "(J)V"); - - (*JG(jenv))->CallVoidMethod(JG(jenv), JG(php_reflect), lastEx, result); -} - -/***************************************************************************/ - -PHP_FUNCTION(java_last_exception_clear) -{ - jlong result = 0; - jmethodID clearEx; - - if (ZEND_NUM_ARGS()!=0) WRONG_PARAM_COUNT; - - result = (jlong)(long)return_value; - - clearEx = (*JG(jenv))->GetMethodID(JG(jenv), JG(reflect_class), - "clearException", "()V"); - - (*JG(jenv))->CallVoidMethod(JG(jenv), JG(php_reflect), clearEx); -} - -/***************************************************************************/ - -static pval _java_getset_property - (zend_property_reference *property_reference, jobjectArray value TSRMLS_DC) -{ - pval presult; - jlong result = 0; - pval **pobject; - jobject obj; - int type; - - /* get the property name */ - zend_llist_element *element = property_reference->elements_list->head; - zend_overloaded_element *property=(zend_overloaded_element *)element->data; - jstring propName; - - JNIEnv *jenv; - jenv = JG(jenv); - - propName = (*jenv)->NewStringUTF(jenv, property->element.value.str.val); - - /* get the object */ - zend_hash_index_find(property_reference->object->value.obj.properties, - 0, (void **) &pobject); - obj = zend_list_find((*pobject)->value.lval,&type); - result = (jlong)(long) &presult; - presult.type = IS_NULL; - - if (!obj || (type!=le_jobject)) { - php_error(E_ERROR, - "Attempt to access a Java property on a non-Java object"); - } else { - /* invoke the method */ - jmethodID gsp = (*jenv)->GetMethodID(jenv, JG(reflect_class), "GetSetProp", - "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;J)V"); - (*jenv)->CallVoidMethod - (jenv, JG(php_reflect), gsp, obj, propName, value, result); - } - - (*jenv)->DeleteLocalRef(jenv, propName); - pval_destructor(&property->element); - return presult; -} - - -pval java_get_property_handler(zend_property_reference *property_reference) -{ - pval presult; - TSRMLS_FETCH(); - - presult = _java_getset_property(property_reference, 0 TSRMLS_CC); - checkError(&presult); - return presult; -} - - -int java_set_property_handler(zend_property_reference *property_reference, pval *value) -{ - pval presult; - TSRMLS_FETCH(); - - presult = _java_getset_property(property_reference, _java_makeArray(1, &value TSRMLS_CC) TSRMLS_CC); - return checkError(&presult) ? FAILURE : SUCCESS; -} - -/***************************************************************************/ - -static void _php_java_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - void *jobject = (void *)rsrc->ptr; - - if (JG(jenv)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), jobject); -} - -static void alloc_java_globals_ctor(zend_java_globals *java_globals TSRMLS_DC) -{ - memset(java_globals, 0, sizeof(zend_java_globals)); -} - -PHP_MINIT_FUNCTION(java) -{ - INIT_OVERLOADED_CLASS_ENTRY(java_class_entry, "java", NULL, - java_call_function_handler, - java_get_property_handler, - java_set_property_handler); - - zend_register_internal_class(&java_class_entry TSRMLS_CC); - - le_jobject = zend_register_list_destructors_ex(_php_java_destructor, NULL, "java", module_number); - - REGISTER_INI_ENTRIES(); - - if (!classpath) classpath = getenv("CLASSPATH"); - - if (!libpath) { - libpath=PG(extension_dir); - } - - ZEND_INIT_MODULE_GLOBALS(java, alloc_java_globals_ctor, NULL); - - return SUCCESS; -} - - -PHP_MSHUTDOWN_FUNCTION(java) -{ - UNREGISTER_INI_ENTRIES(); - if (JG(jvm)) jvm_destroy(TSRMLS_C); - return SUCCESS; -} - - -function_entry java_functions[] = { - PHP_FE(java_last_exception_get, NULL) - PHP_FE(java_last_exception_clear, NULL) - {NULL, NULL, NULL} -}; - - -static PHP_MINFO_FUNCTION(java) { - DISPLAY_INI_ENTRIES(); -} - -zend_module_entry java_module_entry = { - "java", - java_functions, - PHP_MINIT(java), - PHP_MSHUTDOWN(java), - NULL, - NULL, - PHP_MINFO(java), - STANDARD_MODULE_PROPERTIES -}; - -ZEND_GET_MODULE(java) - -/***************************************************************************/ - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromString - (JNIEnv *jenv, jclass self, jlong result, jbyteArray jvalue) -{ - jboolean isCopy; - jbyte *value = (*jenv)->GetByteArrayElements(jenv, jvalue, &isCopy); - pval *presult = (pval*)(long)result; - presult->type=IS_STRING; - presult->value.str.len=(*jenv)->GetArrayLength(jenv, jvalue); - presult->value.str.val=emalloc(presult->value.str.len+1); - memcpy(presult->value.str.val, value, presult->value.str.len); - presult->value.str.val[presult->value.str.len]=0; - if (isCopy) (*jenv)->ReleaseByteArrayElements(jenv, jvalue, value, 0); -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromLong - (JNIEnv *jenv, jclass self, jlong result, jlong value) -{ - pval *presult = (pval*)(long)result; - presult->type=IS_LONG; - presult->value.lval=(long)value; -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromDouble - (JNIEnv *jenv, jclass self, jlong result, jdouble value) -{ - pval *presult = (pval*)(long)result; - presult->type=IS_DOUBLE; - presult->value.dval=value; -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromBoolean - (JNIEnv *jenv, jclass self, jlong result, jboolean value) -{ - pval *presult = (pval*)(long)result; - presult->type=IS_BOOL; - presult->value.lval=value; -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject - (JNIEnv *jenv, jclass self, jlong result, jobject value) -{ - /* wrapper the java object in a pval object */ - pval *presult = (pval*)(long)result; - pval *handle; - - if (presult->type != IS_OBJECT) { - presult->type=IS_OBJECT; - presult->value.obj.ce=&java_class_entry; - ALLOC_HASHTABLE(presult->value.obj.properties); - presult->is_ref=1; - presult->refcount=1; - zend_hash_init(presult->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - }; - - ALLOC_ZVAL(handle); - handle->type = IS_LONG; - handle->value.lval = - zend_list_insert((*jenv)->NewGlobalRef(jenv,value), le_jobject); - pval_copy_constructor(handle); - INIT_PZVAL(handle); - zend_hash_index_update(presult->value.obj.properties, 0, - &handle, sizeof(pval *), NULL); -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromArray - (JNIEnv *jenv, jclass self, jlong result) -{ - array_init( (pval*)(long)result ); -} - -JNIEXPORT jlong JNICALL Java_net_php_reflect_nextElement - (JNIEnv *jenv, jclass self, jlong array) -{ - pval *result; - pval *handle = (pval*)(long)array; - ALLOC_ZVAL(result); - zend_hash_next_index_insert(handle->value.ht, &result, sizeof(zval *), NULL); - return (jlong)(long)result; -} - -JNIEXPORT jlong JNICALL Java_net_php_reflect_hashIndexUpdate - (JNIEnv *jenv, jclass self, jlong array, jlong key) -{ - pval *result; - pval *handle = (pval*)(long)array; - ALLOC_ZVAL(result); - zend_hash_index_update(handle->value.ht, (unsigned long)key, - &result, sizeof(zval *), NULL); - return (jlong)(long)result; -} - -JNIEXPORT jlong JNICALL Java_net_php_reflect_hashUpdate - (JNIEnv *jenv, jclass self, jlong array, jbyteArray key) -{ - pval *result; - pval pkey; - pval *handle = (pval*)(long)array; - ALLOC_ZVAL(result); - Java_net_php_reflect_setResultFromString(jenv, self, (jlong)(long)&pkey, key); - zend_hash_update(handle->value.ht, pkey.value.str.val, pkey.value.str.len+1, - &result, sizeof(zval *), NULL); - return (jlong)(long)result; -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setException - (JNIEnv *jenv, jclass self, jlong result, jbyteArray value) -{ - pval *presult = (pval*)(long)result; - Java_net_php_reflect_setResultFromString(jenv, self, result, value); - presult->type=IS_EXCEPTION; -} - -JNIEXPORT void JNICALL Java_net_php_reflect_setEnv - (JNIEnv *newJenv, jclass self TSRMLS_DC) -{ - jobject local_php_reflect; - - iniUpdated=0; - JG(jenv)=newJenv; - - if (!self) self = (*JG(jenv))->FindClass(JG(jenv), "net/php/reflect"); - JG(reflect_class) = self; - - if (JG(php_reflect)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), JG(php_reflect)); - local_php_reflect = (*JG(jenv))->AllocObject(JG(jenv), JG(reflect_class)); - JG(php_reflect) = (*JG(jenv))->NewGlobalRef(JG(jenv), local_php_reflect); -} diff --git a/ext/rpc/java/java.dsp b/ext/rpc/java/java.dsp deleted file mode 100644 index 603f685439..0000000000 --- a/ext/rpc/java/java.dsp +++ /dev/null @@ -1,258 +0,0 @@ -# Microsoft Developer Studio Project File - Name="java" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=java - 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 "java.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 "java.mak" CFG="java - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "java - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "java - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "java - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "java - 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)" == "java - 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 "..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /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_java.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release"
-
-!ELSEIF "$(CFG)" == "java - 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 "..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /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_java.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug"
-
-!ELSEIF "$(CFG)" == "java - 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 "..\..\TSRM" /I "..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /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 php4ts_debug.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_java.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug_TS"
-
-!ELSEIF "$(CFG)" == "java - 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 "..\..\TSRM" /I "..\..\Zend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D ZEND_DEBUG=0 /D "ZTS" /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 php4ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_java.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ENDIF
-
-# Begin Target
-
-# Name "java - Win32 Release"
-# Name "java - Win32 Debug"
-# Name "java - Win32 Debug_TS"
-# Name "java - Win32 Release_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\java.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\..\..\win32\winutil.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_java.h
-# End Source File
-# End Group
-# Begin Group "Java Files"
-
-# PROP Default_Filter "java"
-# Begin Source File
-
-SOURCE=.\reflect.java
-
-!IF "$(CFG)" == "java - Win32 Release"
-
-# Begin Custom Build
-OutDir=.\..\..\Release
-InputPath=.\reflect.java
-
-"$(OutDir)\php_java.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy $(InputPath) net\php > nul
- echo library=php_java>net\php\reflect.properties
- $(JAVA_HOME)\bin\javac net\php\reflect.java
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "java - Win32 Debug"
-
-# Begin Custom Build
-OutDir=.\..\..\Debug
-InputPath=.\reflect.java
-
-"$(OutDir)\php_java.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy $(InputPath) net\php > nul
- echo library=php_java>net\php\reflect.properties
- $(JAVA_HOME)\bin\javac -g net\php\reflect.java
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "java - Win32 Debug_TS"
-
-# Begin Custom Build
-OutDir=.\..\..\Debug_TS
-InputPath=.\reflect.java
-
-"$(OutDir)\php_java.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy $(InputPath) net\php > nul
- echo library=php_java>net\php\reflect.properties
- $(JAVA_HOME)\bin\javac -g net\php\reflect.java
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ELSEIF "$(CFG)" == "java - Win32 Release_TS"
-
-# Begin Custom Build
-OutDir=.\..\..\Release_TS
-InputPath=.\reflect.java
-
-"$(OutDir)\php_java.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
- if not exist net mkdir net
- if not exist net\php mkdir net\php
- copy $(InputPath) net\php > nul
- echo library=php_java>net\php\reflect.properties
- $(JAVA_HOME)\bin\javac net\php\reflect.java
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties
- erase net\php\reflect.*
- rmdir net\php
- rmdir net
-
-# End Custom Build
-
-!ENDIF
-
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\jtest.php
-# End Source File
-# End Target
-# End Project
diff --git a/ext/rpc/java/jawt.php b/ext/rpc/java/jawt.php deleted file mode 100644 index 30f2235611..0000000000 --- a/ext/rpc/java/jawt.php +++ /dev/null @@ -1,27 +0,0 @@ -<? - - // This example is only intented to be run as a CGI. - - $frame = new Java("java.awt.Frame", "Zend"); - $button = new Java("java.awt.Button", "Hello Java world!"); - $frame->add("North", $button); - $frame->validate(); - $frame->pack(); - $frame->visible = True; - - $thread = new Java("java.lang.Thread"); - $thread->sleep(10000); - - $frame->dispose(); - - // Odd behavior noted with Sun JVMs: - // - // 1) $thread->destroy() will fail with a NoSuchMethodError exception. - // 2) The call to (*jvm)->DestroyJVM(jvm) made when PHP terminates - // will hang, unless _BOTH_ the calls to pack and setVisible above - // are removed. - // - // Even more odd: both effects are seen with a 100% Java implementation - // of the above! - -?> diff --git a/ext/rpc/java/jver.php b/ext/rpc/java/jver.php deleted file mode 100644 index 7015944101..0000000000 --- a/ext/rpc/java/jver.php +++ /dev/null @@ -1,17 +0,0 @@ -<html> -<? - - $system = new Java("java.lang.System"); - print "Java version=".$system->getProperty("java.version")." <br>\n"; - print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n"; - print "OS=".$system->getProperty("os.name")." ". - $system->getProperty("os.version")." on ". - $system->getProperty("os.arch")." <br>\n"; - - $formatter = new Java("java.text.SimpleDateFormat", - "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); - - print $formatter->format(new Java("java.util.Date"))."\n"; - -?> -</html> diff --git a/ext/rpc/java/reflect.java b/ext/rpc/java/reflect.java deleted file mode 100644 index 3e924d975b..0000000000 --- a/ext/rpc/java/reflect.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 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: Sam Ruby (rubys@us.ibm.com) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -package net.php; - -import java.lang.reflect.*; -import java.util.*; -import java.beans.*; - -public class reflect { - - static { loadLibrary("reflect"); } - - protected static void loadLibrary(String property) { - try { - ResourceBundle bundle = ResourceBundle.getBundle("net.php."+property); - System.loadLibrary(bundle.getString("library")); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // - // Native methods - // - private static native void setResultFromString(long result, byte value[]); - private static native void setResultFromLong(long result, long value); - private static native void setResultFromDouble(long result, double value); - private static native void setResultFromBoolean(long result, boolean value); - private static native void setResultFromObject(long result, Object value); - private static native void setResultFromArray(long result); - private static native long nextElement(long array); - private static native long hashUpdate(long array, byte key[]); - private static native long hashIndexUpdate(long array, long key); - private static native void setException(long result, byte value[]); - public static native void setEnv(); - - // - // Helper routines which encapsulate the native methods - // - public static void setResult(long result, Object value) { - if (value == null) return; - - if (value instanceof java.lang.String) { - - setResultFromString(result, ((String)value).getBytes()); - - } else if (value instanceof java.lang.Number) { - - if (value instanceof java.lang.Integer || - value instanceof java.lang.Short || - value instanceof java.lang.Byte) { - setResultFromLong(result, ((Number)value).longValue()); - } else { - /* Float, Double, BigDecimal, BigInteger, Double, Long, ... */ - setResultFromDouble(result, ((Number)value).doubleValue()); - } - - } else if (value instanceof java.lang.Boolean) { - - setResultFromBoolean(result, ((Boolean)value).booleanValue()); - - } else if (value.getClass().isArray()) { - - long length = Array.getLength(value); - setResultFromArray(result); - for (int i=0; i<length; i++) { - setResult(nextElement(result), Array.get(value, i)); - } - - } else if (value instanceof java.util.Hashtable) { - - Hashtable ht = (Hashtable) value; - setResultFromArray(result); - for (Enumeration e = ht.keys(); e.hasMoreElements(); ) { - Object key = e.nextElement(); - long slot; - if (key instanceof Number && - !(key instanceof Double || key instanceof Float)) - slot = hashIndexUpdate(result, ((Number)key).longValue()); - else - slot = hashUpdate(result, key.toString().getBytes()); - setResult(slot, ht.get(key)); - } - - } else { - - setResultFromObject(result, value); - - } - } - - Throwable lastException = null; - - void lastException(long result) { - setResult(result, lastException); - } - - void clearException() { - lastException = null; - } - - void setException(long result, Throwable e) { - if (e instanceof InvocationTargetException) { - Throwable t = ((InvocationTargetException)e).getTargetException(); - if (t!=null) e=t; - } - - lastException = e; - setException(result, e.toString().getBytes()); - } - - // - // Create an new instance of a given class - // - public void CreateObject(String name, Object args[], long result) { - try { - Vector matches = new Vector(); - - Constructor cons[] = Class.forName(name).getConstructors(); - for (int i=0; i<cons.length; i++) { - if (cons[i].getParameterTypes().length == args.length) { - matches.addElement(cons[i]); - } - } - - Constructor selected = (Constructor)select(matches, args); - - if (selected == null) { - if (args.length > 0) { - throw new InstantiationException("No matching constructor found"); - } else { - // for classes which have no visible constructor, return the class - // useful for classes like java.lang.System and java.util.Calendar. - setResult(result, Class.forName(name)); - return; - } - } - - Object coercedArgs[] = coerce(selected.getParameterTypes(), args); - setResultFromObject(result, selected.newInstance(coercedArgs)); - - } catch (Exception e) { - setException(result, e); - } - } - - // - // Select the best match from a list of methods - // - private static Object select(Vector methods, Object args[]) { - if (methods.size() == 1) return methods.firstElement(); - - Object selected = null; - int best = Integer.MAX_VALUE; - - for (Enumeration e = methods.elements(); e.hasMoreElements(); ) { - Object element = e.nextElement(); - int weight=0; - - Class parms[] = (element instanceof Method) ? - ((Method)element).getParameterTypes() : - ((Constructor)element).getParameterTypes(); - - for (int i=0; i<parms.length; i++) { - if (parms[i].isInstance(args[i])) { - for (Class c=parms[i]; (c=c.getSuperclass()) != null; ) { - if (!c.isInstance(args[i])) break; - weight++; - } - } else if (parms[i].isAssignableFrom(java.lang.String.class)) { - if (!(args[i] instanceof byte[]) && !(args[i] instanceof String)) - weight+=9999; - } else if (parms[i].isArray()) { - if (args[i] instanceof java.util.Hashtable) - weight+=256; - else - weight+=9999; - } else if (parms[i].isPrimitive()) { - Class c=parms[i]; - if (args[i] instanceof Number) { - if (c==Boolean.TYPE) weight+=5; - if (c==Character.TYPE) weight+=4; - if (c==Byte.TYPE) weight+=3; - if (c==Short.TYPE) weight+=2; - if (c==Integer.TYPE) weight++; - if (c==Float.TYPE) weight++; - } else if (args[i] instanceof Boolean) { - if (c!=Boolean.TYPE) weight+=9999; - } else if (args[i] instanceof String) { - if (c== Character.TYPE || ((String)args[i]).length()>0) - weight+=((String)args[i]).length(); - else - weight+=64; - } else { - weight+=9999; - } - } else { - weight+=9999; - } - } - - if (weight < best) { - if (weight == 0) return element; - best = weight; - selected = element; - } - } - - return selected; - } - - // - // Coerce arguments when possible to conform to the argument list. - // Java's reflection will automatically do widening conversions, - // unfortunately PHP only supports wide formats, so to be practical - // some (possibly lossy) conversions are required. - // - private static Object[] coerce(Class parms[], Object args[]) { - Object result[] = args; - for (int i=0; i<args.length; i++) { - if (args[i] instanceof byte[] && !parms[i].isArray()) { - Class c = parms[i]; - String s = new String((byte[])args[i]); - result[i] = s; - try { - if (c == Boolean.TYPE) result[i]=new Boolean(s); - if (c == Byte.TYPE) result[i]=new Byte(s); - if (c == Short.TYPE) result[i]=new Short(s); - if (c == Integer.TYPE) result[i]=new Integer(s); - if (c == Float.TYPE) result[i]=new Float(s); - if (c == Long.TYPE) result[i]=new Long(s); - if (c == Character.TYPE && s.length()>0) - result[i]=new Character(s.charAt(0)); - } catch (NumberFormatException n) { - // oh well, we tried! - } - } else if (args[i] instanceof Number && parms[i].isPrimitive()) { - if (result==args) result=(Object[])result.clone(); - Class c = parms[i]; - Number n = (Number)args[i]; - if (c == Boolean.TYPE) result[i]=new Boolean(0.0!=n.floatValue()); - if (c == Byte.TYPE) result[i]=new Byte(n.byteValue()); - if (c == Short.TYPE) result[i]=new Short(n.shortValue()); - if (c == Integer.TYPE) result[i]=new Integer(n.intValue()); - if (c == Float.TYPE) result[i]=new Float(n.floatValue()); - if (c == Long.TYPE && !(n instanceof Long)) - result[i]=new Long(n.longValue()); - } else if (args[i] instanceof Hashtable && parms[i].isArray()) { - try { - Hashtable ht = (Hashtable)args[i]; - int size = ht.size(); - - // Verify that the keys are Long, and determine maximum - for (Enumeration e = ht.keys(); e.hasMoreElements(); ) { - int index = ((Long)e.nextElement()).intValue(); - if (index >= size) size = index+1; - } - - Object tempArray[] = new Object[size]; - Class tempTarget[] = new Class[size]; - Class targetType = parms[i].getComponentType(); - - // flatten the hash table into an array - for (int j=0; j<size; j++) { - tempArray[j] = ht.get(new Long(j)); - if (tempArray[j] == null && targetType.isPrimitive()) - throw new Exception("bail"); - tempTarget[j] = targetType; - } - - // coerce individual elements into the target type - Object coercedArray[] = coerce(tempTarget, tempArray); - - // copy the results into the desired array type - Object array = Array.newInstance(targetType,size); - for (int j=0; j<size; j++) { - Array.set(array, j, coercedArray[j]); - } - - result[i]=array; - } catch (Exception e) { - // leave result[i] alone... - } - } - } - return result; - } - - // - // Invoke a method on a given object - // - public void Invoke - (Object object, String method, Object args[], long result) - { - try { - Vector matches = new Vector(); - - // gather - for (Class jclass = object.getClass();;jclass=(Class)object) { - while (!Modifier.isPublic(jclass.getModifiers())) { - // OK, some joker gave us an instance of a non-public class - // This often occurs in the case of enumerators - // Substitute the first public interface in its place, - // and barring that, try the superclass - Class interfaces[] = jclass.getInterfaces(); - jclass=jclass.getSuperclass(); - for (int i=interfaces.length; i-->0;) { - if (Modifier.isPublic(interfaces[i].getModifiers())) { - jclass=interfaces[i]; - } - } - } - Method methods[] = jclass.getMethods(); - for (int i=0; i<methods.length; i++) { - if (methods[i].getName().equalsIgnoreCase(method) && - methods[i].getParameterTypes().length == args.length) { - matches.addElement(methods[i]); - } - } - - // try a second time with the object itself, if it is of type Class - if (!(object instanceof Class) || (jclass==object)) break; - } - - Method selected = (Method)select(matches, args); - if (selected == null) throw new NoSuchMethodException(method); - - Object coercedArgs[] = coerce(selected.getParameterTypes(), args); - setResult(result, selected.invoke(object, coercedArgs)); - - } catch (Exception e) { - setException(result, e); - } - } - - // - // Get or Set a property - // - public void GetSetProp - (Object object, String prop, Object args[], long result) - { - try { - - for (Class jclass = object.getClass();;jclass=(Class)object) { - while (!Modifier.isPublic(jclass.getModifiers())) { - // OK, some joker gave us an instance of a non-public class - // Substitute the first public interface in its place, - // and barring that, try the superclass - Class interfaces[] = jclass.getInterfaces(); - jclass=jclass.getSuperclass(); - for (int i=interfaces.length; i-->0;) { - if (Modifier.isPublic(interfaces[i].getModifiers())) { - jclass=interfaces[i]; - } - } - } - BeanInfo beanInfo = Introspector.getBeanInfo(jclass); - PropertyDescriptor props[] = beanInfo.getPropertyDescriptors(); - for (int i=0; i<props.length; i++) { - if (props[i].getName().equalsIgnoreCase(prop)) { - Method method; - if (args!=null && args.length>0) { - method=props[i].getWriteMethod(); - args = coerce(method.getParameterTypes(), args); - } else { - method=props[i].getReadMethod(); - } - setResult(result, method.invoke(object, args)); - return; - } - } - - Field jfields[] = jclass.getFields(); - for (int i=0; i<jfields.length; i++) { - if (jfields[i].getName().equalsIgnoreCase(prop)) { - if (args!=null && args.length>0) { - args = coerce(new Class[] {jfields[i].getType()}, args); - jfields[i].set(object, args[0]); - } else { - setResult(result, jfields[i].get(object)); - } - return; - } - } - - // try a second time with the object itself, if it is of type Class - if (!(object instanceof Class) || (jclass==object)) break; - } - - } catch (Exception e) { - setException(result, e); - } - } - - // - // Helper routines for the C implementation - // - public Object MakeArg(boolean b) { return new Boolean(b); } - public Object MakeArg(long l) { return new Long(l); } - public Object MakeArg(double d) { return new Double(d); } -} |