2002-10-11 01:36:52 +02:00
|
|
|
/*
|
|
|
|
* COM proxy/stub factory (CStdPSFactory) implementation
|
|
|
|
*
|
2008-10-18 19:20:44 +02:00
|
|
|
* Copyright 2001 Ove Kåven, TransGaming Technologies
|
2002-10-11 01:36:52 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-11 01:36:52 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-11 01:36:52 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-10-11 01:36:52 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2002-10-11 01:36:52 +02:00
|
|
|
|
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "cpsf.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
2008-11-29 13:01:29 +01:00
|
|
|
static void format_clsid( WCHAR *buffer, const CLSID *clsid )
|
|
|
|
{
|
2020-11-28 23:07:22 +01:00
|
|
|
swprintf( buffer, 39, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
|
|
|
|
clsid->Data1, clsid->Data2, clsid->Data3,
|
2008-11-29 13:01:29 +01:00
|
|
|
clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
|
|
|
|
clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-10-11 01:36:52 +02:00
|
|
|
static BOOL FindProxyInfo(const ProxyFileInfo **pProxyFileList, REFIID riid, const ProxyFileInfo **pProxyInfo, int *pIndex)
|
|
|
|
{
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
if ((*pProxyFileList)->pIIDLookupRtn(riid, pIndex)) {
|
|
|
|
*pProxyInfo = *pProxyFileList;
|
|
|
|
TRACE("found: ProxyInfo %p Index %d\n", *pProxyInfo, *pIndex);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
pProxyFileList++;
|
|
|
|
}
|
|
|
|
TRACE("not found\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_QueryInterface(LPPSFACTORYBUFFER iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *obj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-11 01:36:52 +02:00
|
|
|
TRACE("(%p)->QueryInterface(%s,%p)\n",iface,debugstr_guid(riid),obj);
|
|
|
|
if (IsEqualGUID(&IID_IUnknown,riid) ||
|
|
|
|
IsEqualGUID(&IID_IPSFactoryBuffer,riid)) {
|
|
|
|
*obj = This;
|
2008-07-07 12:09:45 +02:00
|
|
|
InterlockedIncrement( &This->RefCount );
|
2002-10-11 01:36:52 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CStdPSFactory_AddRef(LPPSFACTORYBUFFER iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-11 01:36:52 +02:00
|
|
|
TRACE("(%p)->AddRef()\n",iface);
|
2008-07-07 12:09:45 +02:00
|
|
|
return InterlockedIncrement( &This->RefCount );
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CStdPSFactory_Release(LPPSFACTORYBUFFER iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-11 01:36:52 +02:00
|
|
|
TRACE("(%p)->Release()\n",iface);
|
2008-07-07 12:09:45 +02:00
|
|
|
return InterlockedDecrement( &This->RefCount );
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_CreateProxy(LPPSFACTORYBUFFER iface,
|
|
|
|
LPUNKNOWN pUnkOuter,
|
|
|
|
REFIID riid,
|
|
|
|
LPRPCPROXYBUFFER *ppProxy,
|
|
|
|
LPVOID *ppv)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-11 01:36:52 +02:00
|
|
|
const ProxyFileInfo *ProxyInfo;
|
|
|
|
int Index;
|
|
|
|
TRACE("(%p)->CreateProxy(%p,%s,%p,%p)\n",iface,pUnkOuter,
|
|
|
|
debugstr_guid(riid),ppProxy,ppv);
|
|
|
|
if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
|
|
|
|
return E_NOINTERFACE;
|
2006-01-20 16:15:25 +01:00
|
|
|
return StdProxy_Construct(riid, pUnkOuter, ProxyInfo, Index, iface, ppProxy, ppv);
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CStdPSFactory_CreateStub(LPPSFACTORYBUFFER iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPUNKNOWN pUnkServer,
|
|
|
|
LPRPCSTUBBUFFER *ppStub)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdPSFactoryBuffer *This = (CStdPSFactoryBuffer *)iface;
|
2002-10-11 01:36:52 +02:00
|
|
|
const ProxyFileInfo *ProxyInfo;
|
|
|
|
int Index;
|
|
|
|
TRACE("(%p)->CreateStub(%s,%p,%p)\n",iface,debugstr_guid(riid),
|
|
|
|
pUnkServer,ppStub);
|
|
|
|
if (!FindProxyInfo(This->pProxyFileList,riid,&ProxyInfo,&Index))
|
|
|
|
return E_NOINTERFACE;
|
2006-08-31 16:40:05 +02:00
|
|
|
|
|
|
|
if(ProxyInfo->pDelegatedIIDs && ProxyInfo->pDelegatedIIDs[Index])
|
|
|
|
return CStdStubBuffer_Delegating_Construct(riid, pUnkServer, ProxyInfo->pNamesArray[Index],
|
|
|
|
ProxyInfo->pStubVtblList[Index], ProxyInfo->pDelegatedIIDs[Index],
|
|
|
|
iface, ppStub);
|
|
|
|
|
2003-05-20 06:13:44 +02:00
|
|
|
return CStdStubBuffer_Construct(riid, pUnkServer, ProxyInfo->pNamesArray[Index],
|
|
|
|
ProxyInfo->pStubVtblList[Index], iface, ppStub);
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPSFactoryBufferVtbl CStdPSFactory_Vtbl =
|
2002-10-11 01:36:52 +02:00
|
|
|
{
|
|
|
|
CStdPSFactory_QueryInterface,
|
|
|
|
CStdPSFactory_AddRef,
|
|
|
|
CStdPSFactory_Release,
|
|
|
|
CStdPSFactory_CreateProxy,
|
|
|
|
CStdPSFactory_CreateStub
|
|
|
|
};
|
|
|
|
|
2009-06-03 16:39:25 +02:00
|
|
|
|
|
|
|
static void init_psfactory( CStdPSFactoryBuffer *psfac, const ProxyFileInfo **file_list )
|
|
|
|
{
|
|
|
|
DWORD i, j, k;
|
|
|
|
|
|
|
|
psfac->lpVtbl = &CStdPSFactory_Vtbl;
|
|
|
|
psfac->RefCount = 0;
|
|
|
|
psfac->pProxyFileList = file_list;
|
|
|
|
for (i = 0; file_list[i]; i++)
|
|
|
|
{
|
2009-06-03 16:42:50 +02:00
|
|
|
const PCInterfaceProxyVtblList *proxies = file_list[i]->pProxyVtblList;
|
2009-06-03 16:39:25 +02:00
|
|
|
const PCInterfaceStubVtblList *stubs = file_list[i]->pStubVtblList;
|
|
|
|
|
|
|
|
for (j = 0; j < file_list[i]->TableSize; j++)
|
|
|
|
{
|
|
|
|
/* FIXME: i think that different vtables should be copied for
|
|
|
|
* async interfaces */
|
|
|
|
void * const *pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Vtbl;
|
|
|
|
void **pRpcStubVtbl = (void **)&stubs[j]->Vtbl;
|
|
|
|
|
|
|
|
if (file_list[i]->pDelegatedIIDs && file_list[i]->pDelegatedIIDs[j])
|
2009-06-03 16:42:50 +02:00
|
|
|
{
|
2009-06-10 16:54:30 +02:00
|
|
|
void **vtbl = proxies[j]->Vtbl;
|
|
|
|
if (file_list[i]->TableVersion > 1) vtbl++;
|
|
|
|
fill_delegated_proxy_table( (IUnknownVtbl *)vtbl, stubs[j]->header.DispatchTableCount );
|
2009-06-03 16:39:25 +02:00
|
|
|
pSrcRpcStubVtbl = (void * const *)&CStdStubBuffer_Delegating_Vtbl;
|
2009-06-03 16:42:50 +02:00
|
|
|
}
|
2009-06-03 16:39:25 +02:00
|
|
|
|
|
|
|
for (k = 0; k < sizeof(IRpcStubBufferVtbl)/sizeof(void *); k++)
|
|
|
|
if (!pRpcStubVtbl[k]) pRpcStubVtbl[k] = pSrcRpcStubVtbl[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-11 01:36:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NdrDllGetClassObject [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI NdrDllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv,
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
const CLSID *pclsid,
|
|
|
|
CStdPSFactoryBuffer *pPSFactoryBuffer)
|
|
|
|
{
|
2005-11-29 10:41:55 +01:00
|
|
|
TRACE("(%s, %s, %p, %p, %s, %p)\n", debugstr_guid(rclsid),
|
|
|
|
debugstr_guid(iid), ppv, pProxyFileList, debugstr_guid(pclsid),
|
|
|
|
pPSFactoryBuffer);
|
|
|
|
|
2002-10-11 01:36:52 +02:00
|
|
|
*ppv = NULL;
|
2009-06-03 16:39:25 +02:00
|
|
|
if (!pPSFactoryBuffer->lpVtbl) init_psfactory( pPSFactoryBuffer, pProxyFileList );
|
|
|
|
|
2008-09-12 13:59:43 +02:00
|
|
|
if (pclsid && IsEqualGUID(rclsid, pclsid))
|
2002-10-11 01:36:52 +02:00
|
|
|
return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
|
2005-11-29 10:41:55 +01:00
|
|
|
else {
|
|
|
|
const ProxyFileInfo *info;
|
|
|
|
int index;
|
|
|
|
/* otherwise, the dll may be using the iid as the clsid, so
|
|
|
|
* search for it in the proxy file list */
|
|
|
|
if (FindProxyInfo(pProxyFileList, rclsid, &info, &index))
|
|
|
|
return IPSFactoryBuffer_QueryInterface((LPPSFACTORYBUFFER)pPSFactoryBuffer, iid, ppv);
|
|
|
|
|
|
|
|
WARN("class %s not available\n", debugstr_guid(rclsid));
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrDllCanUnloadNow [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
|
|
|
|
{
|
2009-04-20 11:58:45 +02:00
|
|
|
return pPSFactoryBuffer->RefCount != 0 ? S_FALSE : S_OK;
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
2008-11-29 13:01:29 +01:00
|
|
|
|
2002-10-11 01:36:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NdrDllRegisterProxy [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
const CLSID *pclsid)
|
|
|
|
{
|
2008-11-29 13:01:29 +01:00
|
|
|
WCHAR clsid[39], keyname[50], module[MAX_PATH];
|
2002-10-11 01:36:52 +02:00
|
|
|
HKEY key, subkey;
|
2004-05-19 05:22:55 +02:00
|
|
|
DWORD len;
|
2002-10-11 01:36:52 +02:00
|
|
|
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
|
2010-04-07 18:53:12 +02:00
|
|
|
|
|
|
|
if (!hDll) return E_HANDLE;
|
|
|
|
if (!*pProxyFileList) return E_NOINTERFACE;
|
|
|
|
|
2010-04-07 18:53:05 +02:00
|
|
|
if (pclsid)
|
|
|
|
format_clsid( clsid, pclsid );
|
|
|
|
else if ((*pProxyFileList)->TableSize > 0)
|
|
|
|
format_clsid( clsid,(*pProxyFileList)->pStubVtblList[0]->header.piid);
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2002-10-11 01:36:52 +02:00
|
|
|
|
|
|
|
/* register interfaces to point to clsid */
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
unsigned u;
|
|
|
|
for (u=0; u<(*pProxyFileList)->TableSize; u++) {
|
2003-02-17 02:47:54 +01:00
|
|
|
CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
|
2002-10-11 01:36:52 +02:00
|
|
|
PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
|
|
|
|
|
2008-11-29 13:01:29 +01:00
|
|
|
TRACE("registering %s %s => %s\n",
|
|
|
|
debugstr_a(name), debugstr_guid(proxy->header.piid), debugstr_w(clsid));
|
2002-10-11 01:36:52 +02:00
|
|
|
|
2020-11-28 23:07:22 +01:00
|
|
|
lstrcpyW( keyname, L"Interface\\" );
|
2019-06-19 10:32:06 +02:00
|
|
|
format_clsid( keyname + lstrlenW(keyname), proxy->header.piid );
|
2008-11-29 13:01:29 +01:00
|
|
|
if (RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key) == ERROR_SUCCESS) {
|
2008-11-29 13:05:11 +01:00
|
|
|
WCHAR num[10];
|
2002-10-11 01:36:52 +02:00
|
|
|
if (name)
|
2008-11-29 13:01:29 +01:00
|
|
|
RegSetValueExA(key, NULL, 0, REG_SZ, (const BYTE *)name, strlen(name)+1);
|
2020-11-28 23:07:22 +01:00
|
|
|
RegSetValueW( key, L"ProxyStubClsid32", REG_SZ, clsid, 0 );
|
|
|
|
swprintf(num, ARRAY_SIZE(num), L"%u", proxy->header.DispatchTableCount);
|
|
|
|
RegSetValueW( key, L"NumMethods", REG_SZ, num, 0 );
|
2002-10-11 01:36:52 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pProxyFileList++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register clsid to point to module */
|
2020-11-28 23:07:22 +01:00
|
|
|
lstrcpyW( keyname, L"CLSID\\" );
|
2019-06-19 10:32:06 +02:00
|
|
|
lstrcatW( keyname, clsid );
|
2018-10-19 22:11:34 +02:00
|
|
|
len = GetModuleFileNameW(hDll, module, ARRAY_SIZE(module));
|
2004-05-19 05:22:55 +02:00
|
|
|
if (len && len < sizeof(module)) {
|
2008-11-29 13:01:29 +01:00
|
|
|
TRACE("registering CLSID %s => %s\n", debugstr_w(clsid), debugstr_w(module));
|
|
|
|
if (RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key) == ERROR_SUCCESS) {
|
2020-11-28 23:07:22 +01:00
|
|
|
RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE *)L"PSFactoryBuffer", sizeof(L"PSFactoryBuffer"));
|
|
|
|
if (RegCreateKeyW(key, L"InProcServer32", &subkey) == ERROR_SUCCESS) {
|
2019-06-19 10:32:06 +02:00
|
|
|
RegSetValueExW(subkey, NULL, 0, REG_SZ, (LPBYTE)module, (lstrlenW(module)+1)*sizeof(WCHAR));
|
2020-11-28 23:07:22 +01:00
|
|
|
RegSetValueExW(subkey, L"ThreadingModel", 0, REG_SZ, (const BYTE *)L"Both", sizeof(L"Both"));
|
2008-11-29 13:01:29 +01:00
|
|
|
RegCloseKey(subkey);
|
|
|
|
}
|
|
|
|
RegCloseKey(key);
|
2004-05-19 05:22:55 +02:00
|
|
|
}
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrDllUnregisterProxy [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
|
|
|
|
const ProxyFileInfo **pProxyFileList,
|
|
|
|
const CLSID *pclsid)
|
|
|
|
{
|
2008-11-29 13:01:29 +01:00
|
|
|
WCHAR keyname[50];
|
2010-04-07 18:53:05 +02:00
|
|
|
WCHAR clsid[39];
|
2002-10-11 01:36:52 +02:00
|
|
|
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
|
2010-04-07 18:53:05 +02:00
|
|
|
if (pclsid)
|
|
|
|
format_clsid( clsid, pclsid );
|
|
|
|
else if ((*pProxyFileList)->TableSize > 0)
|
|
|
|
format_clsid( clsid,(*pProxyFileList)->pStubVtblList[0]->header.piid);
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2002-10-11 01:36:52 +02:00
|
|
|
|
|
|
|
/* unregister interfaces */
|
|
|
|
while (*pProxyFileList) {
|
|
|
|
unsigned u;
|
|
|
|
for (u=0; u<(*pProxyFileList)->TableSize; u++) {
|
2003-02-17 02:47:54 +01:00
|
|
|
CInterfaceStubVtbl *proxy = (*pProxyFileList)->pStubVtblList[u];
|
2002-10-11 01:36:52 +02:00
|
|
|
PCInterfaceName name = (*pProxyFileList)->pNamesArray[u];
|
|
|
|
|
2008-11-29 13:01:29 +01:00
|
|
|
TRACE("unregistering %s %s\n", debugstr_a(name), debugstr_guid(proxy->header.piid));
|
2002-10-11 01:36:52 +02:00
|
|
|
|
2020-11-28 23:07:22 +01:00
|
|
|
lstrcpyW( keyname, L"Interface\\" );
|
2019-06-19 10:32:06 +02:00
|
|
|
format_clsid( keyname + lstrlenW(keyname), proxy->header.piid );
|
2008-11-29 13:02:08 +01:00
|
|
|
RegDeleteTreeW(HKEY_CLASSES_ROOT, keyname);
|
2002-10-11 01:36:52 +02:00
|
|
|
}
|
|
|
|
pProxyFileList++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unregister clsid */
|
2020-11-28 23:07:22 +01:00
|
|
|
lstrcpyW( keyname, L"CLSID\\" );
|
2019-06-19 10:32:06 +02:00
|
|
|
lstrcatW( keyname, clsid );
|
2008-11-29 13:02:08 +01:00
|
|
|
RegDeleteTreeW(HKEY_CLASSES_ROOT, keyname);
|
2002-10-11 01:36:52 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|