no message

This commit is contained in:
Harald Radi 2001-09-25 23:39:50 +00:00
parent 6cfba2a3ea
commit 23c65b60a0
2 changed files with 278 additions and 64 deletions

View file

@ -69,6 +69,7 @@ static int php_COM_load_typelib(ITypeLib *TypeLib, int mode TSRMLS_DC);
static int do_COM_offget(VARIANT *result, comval *array, pval *property, int cleanup TSRMLS_DC);
static int do_COM_propget(VARIANT *var_result, comval *obj, pval *arg_property, int cleanup TSRMLS_DC);
static void php_register_COM_class(TSRMLS_D);
static void php_COM_init(int module_number TSRMLS_DC);
static int le_comval;
static int codepage;
@ -441,7 +442,7 @@ PHP_INI_END()
Loads a COM module */
PHP_FUNCTION(com_load)
{
pval *module_name, *code_page, *typelib = NULL, *server_name = NULL;
pval *module_name, *code_page, *typelib = NULL, *server_name = NULL, *user_name=NULL, *password=NULL, *domain=NULL;
CLSID clsid;
HRESULT hr;
OLECHAR *ProgID;
@ -450,7 +451,7 @@ PHP_FUNCTION(com_load)
char *clsid_str;
int mode = 0;
ITypeLib *pTL;
CLSCTX flags = CLSCTX_SERVER;
codepage = CP_ACP;
@ -483,8 +484,75 @@ PHP_FUNCTION(com_load)
ZEND_WRONG_PARAM_COUNT();
}
if (server_name != NULL)
{
if (server_name != NULL) {
/* if a server is passed, one obviously wants to instanciate a
* remote server
*/
flags = CTX_REMOTE_SERVER;
/* What is server name? A String or an array? */
if (Z_TYPE_P(server_name) == IS_ARRAY) {
pval **tmp;
/* DAB: 22 Sept 2001 */
/* Aha - we have a number of possible */
/* arguments. They are in the hash */
/* By name: Server, Domain, Username, Password */
/* Flags. */
/* This has been crafted to maintian maximum backward */
/* compatability, If the server name is specified as a */
/* string, then the function shoule behave as before */
/* by defaulting username and password and using the */
/* (I believe) incorrect CLSCTX_SERVER instantiation */
/* paramter. However if server is specified in this array */
/* then we use either CLSCTX_REMOTE_SERVER or whatever */
/* flags are specified in the array */
HashTable *ht = Z_ARRVAL(*server_name);
if (FAILURE == zend_hash_find(ht, "Server", 7, (void **) &tmp)) {
server_name = NULL;
} else {
server_name = *tmp;
convert_to_string_ex(&server_name);
/* CLSCTX_SERVER includes INPROC and LOCAL */
/* SERVER. This means that any local server */
/* will be instantiated BEFORE even looking */
/* on a remote server. Thus if we have a */
/* server name, probably we want to access */
/* a remote machine or we would not have */
/* bothered specifying it. So it would be */
/* wrong to to connect locally. Futher, */
/* unless the name passed is a GUID, there has */
/* to be something to map the Prog.Id to GUID */
/* and unless that has been modified to remove */
/* the information about local instantiation */
/* CLSCTX_SERVER would force a local instantiation */
/* This setting can be overridden below if the user */
/* specifies a flags element */
flags = CLSCTX_REMOTE_SERVER;
}
if (FAILURE == zend_hash_find(ht, "Username", 9, (void **) &tmp)) {
user_name = NULL;
} else {
user_name = *tmp;
convert_to_string_ex(&user_name);
}
if (FAILURE == zend_hash_find(ht, "Domain", 7, (void **) &tmp)) {
domain = NULL;
} else {
domain = *tmp;
convert_to_string_ex(&domain);
}
if (FAILURE == zend_hash_find(ht, "Password", 9, (void **) &tmp)) {
password=NULL;
} else {
password = *tmp;
convert_to_string_ex(&password);
}
if (SUCCESS == zend_hash_find(ht, "Flags", 6, (void **) &tmp)) {
convert_to_long_ex(tmp);
flags = (CLSCTX) Z_LVAL_P(tmp);
}
}
if (Z_TYPE_P(server_name) == IS_NULL) {
server_name = NULL;
} else {
@ -541,20 +609,46 @@ PHP_FUNCTION(com_load)
efree(ProgID);
/* obtain IDispatch */
if (!server_name) {
hr = CoCreateInstance(&clsid, NULL, CLSCTX_SERVER, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj));
hr = CoCreateInstance(&clsid, NULL, flags, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj));
} else {
COSERVERINFO server_info;
MULTI_QI pResults;
COAUTHIDENTITY authid;
COAUTHINFO authinfo = {RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, &authid, EOAC_NONE};
server_info.dwReserved1=0;
server_info.dwReserved2=0;
server_info.pwszName = php_char_to_OLECHAR(Z_STRVAL_P(server_name), Z_STRLEN_P(server_name), codepage TSRMLS_CC);
if (user_name) {
/* Z_STRVAL_P(user_name); */
/* Parse Username into domain\username */
authid.User = (WCHAR *) Z_STRVAL_P(user_name);
authid.UserLength = Z_STRLEN_P(user_name);
if (password) {
authid.Password = (USHORT *) Z_STRVAL_P(password);
authid.PasswordLength = Z_STRLEN_P(password);
} else {
authid.Password = (USHORT *) "";
authid.PasswordLength = 0;
}
if (domain) {
authid.Domain = (USHORT *) Z_STRVAL_P(domain);
authid.DomainLength = Z_STRLEN_P(domain);
} else {
authid.Domain = (USHORT *) "";
authid.DomainLength = 0;
}
authid.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
server_info.pAuthInfo=&authinfo;
} else {
server_info.pAuthInfo=NULL;
}
pResults.pIID = &IID_IDispatch;
pResults.pItf = NULL;
pResults.hr = S_OK;
hr = CoCreateInstanceEx(&clsid, NULL, CLSCTX_REMOTE_SERVER, &server_info, 1, &pResults);
hr=CoCreateInstanceEx(&clsid, NULL, flags, &server_info, 1, &pResults);
if (SUCCEEDED(hr)) {
hr = pResults.hr;
C_DISPATCH(obj) = (IDispatch *) pResults.pItf;
@ -1682,14 +1776,27 @@ static void php_register_COM_class(TSRMLS_D)
}
PHP_MINIT_FUNCTION(COM)
static void php_COM_init(int module_number TSRMLS_DC)
{
le_comval = zend_register_list_destructors_ex(php_comval_destructor, NULL, "COM", module_number);
php_register_COM_class(TSRMLS_C);
}
php_VARIANT_init(module_number, TSRMLS_C);
PHP_MINIT_FUNCTION(COM)
{
php_COM_init(module_number TSRMLS_CC);
php_VARIANT_init(module_number TSRMLS_CC);
REGISTER_LONG_CONSTANT("CLSCTX_INPROC_SERVER", CLSCTX_INPROC_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_INPROC_HANDLER", CLSCTX_INPROC_HANDLER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_LOCAL_SERVER", CLSCTX_LOCAL_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_REMOTE_SERVER", CLSCTX_REMOTE_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_SERVER", CLSCTX_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_ALL", CLSCTX_ALL, CONST_CS | CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
return SUCCESS;
}

View file

@ -69,6 +69,7 @@ static int php_COM_load_typelib(ITypeLib *TypeLib, int mode TSRMLS_DC);
static int do_COM_offget(VARIANT *result, comval *array, pval *property, int cleanup TSRMLS_DC);
static int do_COM_propget(VARIANT *var_result, comval *obj, pval *arg_property, int cleanup TSRMLS_DC);
static void php_register_COM_class(TSRMLS_D);
static void php_COM_init(int module_number TSRMLS_DC);
static int le_comval;
static int codepage;
@ -441,7 +442,7 @@ PHP_INI_END()
Loads a COM module */
PHP_FUNCTION(com_load)
{
pval *module_name, *code_page, *typelib = NULL, *server_name = NULL;
pval *module_name, *code_page, *typelib = NULL, *server_name = NULL, *user_name=NULL, *password=NULL, *domain=NULL;
CLSID clsid;
HRESULT hr;
OLECHAR *ProgID;
@ -450,7 +451,7 @@ PHP_FUNCTION(com_load)
char *clsid_str;
int mode = 0;
ITypeLib *pTL;
CLSCTX flags = CLSCTX_SERVER;
codepage = CP_ACP;
@ -483,8 +484,75 @@ PHP_FUNCTION(com_load)
ZEND_WRONG_PARAM_COUNT();
}
if (server_name != NULL)
{
if (server_name != NULL) {
/* if a server is passed, one obviously wants to instanciate a
* remote server
*/
flags = CTX_REMOTE_SERVER;
/* What is server name? A String or an array? */
if (Z_TYPE_P(server_name) == IS_ARRAY) {
pval **tmp;
/* DAB: 22 Sept 2001 */
/* Aha - we have a number of possible */
/* arguments. They are in the hash */
/* By name: Server, Domain, Username, Password */
/* Flags. */
/* This has been crafted to maintian maximum backward */
/* compatability, If the server name is specified as a */
/* string, then the function shoule behave as before */
/* by defaulting username and password and using the */
/* (I believe) incorrect CLSCTX_SERVER instantiation */
/* paramter. However if server is specified in this array */
/* then we use either CLSCTX_REMOTE_SERVER or whatever */
/* flags are specified in the array */
HashTable *ht = Z_ARRVAL(*server_name);
if (FAILURE == zend_hash_find(ht, "Server", 7, (void **) &tmp)) {
server_name = NULL;
} else {
server_name = *tmp;
convert_to_string_ex(&server_name);
/* CLSCTX_SERVER includes INPROC and LOCAL */
/* SERVER. This means that any local server */
/* will be instantiated BEFORE even looking */
/* on a remote server. Thus if we have a */
/* server name, probably we want to access */
/* a remote machine or we would not have */
/* bothered specifying it. So it would be */
/* wrong to to connect locally. Futher, */
/* unless the name passed is a GUID, there has */
/* to be something to map the Prog.Id to GUID */
/* and unless that has been modified to remove */
/* the information about local instantiation */
/* CLSCTX_SERVER would force a local instantiation */
/* This setting can be overridden below if the user */
/* specifies a flags element */
flags = CLSCTX_REMOTE_SERVER;
}
if (FAILURE == zend_hash_find(ht, "Username", 9, (void **) &tmp)) {
user_name = NULL;
} else {
user_name = *tmp;
convert_to_string_ex(&user_name);
}
if (FAILURE == zend_hash_find(ht, "Domain", 7, (void **) &tmp)) {
domain = NULL;
} else {
domain = *tmp;
convert_to_string_ex(&domain);
}
if (FAILURE == zend_hash_find(ht, "Password", 9, (void **) &tmp)) {
password=NULL;
} else {
password = *tmp;
convert_to_string_ex(&password);
}
if (SUCCESS == zend_hash_find(ht, "Flags", 6, (void **) &tmp)) {
convert_to_long_ex(tmp);
flags = (CLSCTX) Z_LVAL_P(tmp);
}
}
if (Z_TYPE_P(server_name) == IS_NULL) {
server_name = NULL;
} else {
@ -541,20 +609,46 @@ PHP_FUNCTION(com_load)
efree(ProgID);
/* obtain IDispatch */
if (!server_name) {
hr = CoCreateInstance(&clsid, NULL, CLSCTX_SERVER, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj));
hr = CoCreateInstance(&clsid, NULL, flags, &IID_IDispatch, (LPVOID *) &C_DISPATCH(obj));
} else {
COSERVERINFO server_info;
MULTI_QI pResults;
COAUTHIDENTITY authid;
COAUTHINFO authinfo = {RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, &authid, EOAC_NONE};
server_info.dwReserved1=0;
server_info.dwReserved2=0;
server_info.pwszName = php_char_to_OLECHAR(Z_STRVAL_P(server_name), Z_STRLEN_P(server_name), codepage TSRMLS_CC);
if (user_name) {
/* Z_STRVAL_P(user_name); */
/* Parse Username into domain\username */
authid.User = (WCHAR *) Z_STRVAL_P(user_name);
authid.UserLength = Z_STRLEN_P(user_name);
if (password) {
authid.Password = (USHORT *) Z_STRVAL_P(password);
authid.PasswordLength = Z_STRLEN_P(password);
} else {
authid.Password = (USHORT *) "";
authid.PasswordLength = 0;
}
if (domain) {
authid.Domain = (USHORT *) Z_STRVAL_P(domain);
authid.DomainLength = Z_STRLEN_P(domain);
} else {
authid.Domain = (USHORT *) "";
authid.DomainLength = 0;
}
authid.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
server_info.pAuthInfo=&authinfo;
} else {
server_info.pAuthInfo=NULL;
}
pResults.pIID = &IID_IDispatch;
pResults.pItf = NULL;
pResults.hr = S_OK;
hr = CoCreateInstanceEx(&clsid, NULL, CLSCTX_REMOTE_SERVER, &server_info, 1, &pResults);
hr=CoCreateInstanceEx(&clsid, NULL, flags, &server_info, 1, &pResults);
if (SUCCEEDED(hr)) {
hr = pResults.hr;
C_DISPATCH(obj) = (IDispatch *) pResults.pItf;
@ -1682,14 +1776,27 @@ static void php_register_COM_class(TSRMLS_D)
}
PHP_MINIT_FUNCTION(COM)
static void php_COM_init(int module_number TSRMLS_DC)
{
le_comval = zend_register_list_destructors_ex(php_comval_destructor, NULL, "COM", module_number);
php_register_COM_class(TSRMLS_C);
}
php_VARIANT_init(module_number, TSRMLS_C);
PHP_MINIT_FUNCTION(COM)
{
php_COM_init(module_number TSRMLS_CC);
php_VARIANT_init(module_number TSRMLS_CC);
REGISTER_LONG_CONSTANT("CLSCTX_INPROC_SERVER", CLSCTX_INPROC_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_INPROC_HANDLER", CLSCTX_INPROC_HANDLER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_LOCAL_SERVER", CLSCTX_LOCAL_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_REMOTE_SERVER", CLSCTX_REMOTE_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_SERVER", CLSCTX_SERVER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLSCTX_ALL", CLSCTX_ALL, CONST_CS | CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
return SUCCESS;
}