2002-02-05 19:11:17 +01:00
|
|
|
/*
|
2003-05-13 02:41:57 +02:00
|
|
|
* Marshalling library
|
2002-02-05 19:11:17 +01:00
|
|
|
*
|
2004-12-27 20:21:47 +01:00
|
|
|
* Copyright 2002 Marcus Meissner
|
|
|
|
* Copyright 2004 Mike Hearn, for CodeWeavers
|
|
|
|
* Copyright 2004 Rob Shearman, for CodeWeavers
|
2002-03-10 00:29:33 +01: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-02-05 19:11:17 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-02-05 19:11:17 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/unicode.h"
|
2004-12-14 16:28:58 +01:00
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
#include "compobj_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2002-12-19 23:16:35 +01:00
|
|
|
extern const CLSID CLSID_DfMarshal;
|
|
|
|
|
2005-01-20 11:35:46 +01:00
|
|
|
/* number of refs given out for normal marshaling */
|
2006-03-01 13:18:33 +01:00
|
|
|
#define NORMALEXTREFS 5
|
2005-01-20 11:35:46 +01:00
|
|
|
|
2008-04-28 20:42:51 +02:00
|
|
|
|
|
|
|
/* private flag indicating that the object was marshaled as table-weak */
|
|
|
|
#define SORFP_TABLEWEAK SORF_OXRES1
|
2005-01-24 12:24:08 +01:00
|
|
|
/* private flag indicating that the caller does not want to notify the stub
|
|
|
|
* when the proxy disconnects or is destroyed */
|
2008-04-28 20:42:51 +02:00
|
|
|
#define SORFP_NOLIFETIMEMGMT SORF_OXRES2
|
2005-01-24 12:24:08 +01:00
|
|
|
|
2006-03-05 14:37:22 +01:00
|
|
|
static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
|
|
|
|
MSHCTX dest_context, void *dest_context_data,
|
2007-03-26 19:23:16 +02:00
|
|
|
REFIID riid, const OXID_INFO *oxid_info,
|
|
|
|
void **object);
|
2005-01-25 11:57:24 +01:00
|
|
|
|
2003-05-13 02:41:57 +02:00
|
|
|
/* Marshalling just passes a unique identifier to the remote client,
|
2002-02-05 19:11:17 +01:00
|
|
|
* that makes it possible to find the passed interface again.
|
|
|
|
*
|
|
|
|
* So basically we need a set of values that make it unique.
|
|
|
|
*
|
|
|
|
* Note that the IUnknown_QI(ob,xiid,&ppv) always returns the SAME ppv value!
|
2004-12-27 20:21:47 +01:00
|
|
|
*
|
2005-05-19 14:04:58 +02:00
|
|
|
* A triple is used: OXID (apt id), OID (stub manager id),
|
|
|
|
* IPID (interface ptr/stub id).
|
2004-12-27 20:21:47 +01:00
|
|
|
*
|
|
|
|
* OXIDs identify an apartment and are network scoped
|
|
|
|
* OIDs identify a stub manager and are apartment scoped
|
|
|
|
* IPIDs identify an interface stub and are apartment scoped
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-22 19:24:53 +01:00
|
|
|
static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
|
2005-05-19 14:04:58 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
CLSID clsid;
|
2004-07-23 01:44:54 +02:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
if ((hr = CoGetPSClsid(riid, &clsid)))
|
|
|
|
return hr;
|
2007-11-30 19:08:08 +01:00
|
|
|
return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER | WINE_CLSCTX_DONT_HOST,
|
|
|
|
NULL, &IID_IPSFactoryBuffer, (LPVOID*)facbuf);
|
2004-07-23 01:44:54 +02:00
|
|
|
}
|
|
|
|
|
2005-09-02 13:18:45 +02:00
|
|
|
/* marshals an object into a STDOBJREF structure */
|
2005-07-19 21:59:41 +02:00
|
|
|
HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *object, MSHLFLAGS mshlflags)
|
2004-12-27 20:21:47 +01:00
|
|
|
{
|
2005-02-08 15:26:19 +01:00
|
|
|
struct stub_manager *manager;
|
2004-12-27 20:21:47 +01:00
|
|
|
struct ifstub *ifstub;
|
2005-01-17 14:39:40 +01:00
|
|
|
BOOL tablemarshal;
|
2005-06-09 11:45:59 +02:00
|
|
|
IRpcStubBuffer *stub = NULL;
|
2005-01-20 11:35:46 +01:00
|
|
|
HRESULT hr;
|
2005-07-19 21:59:41 +02:00
|
|
|
IUnknown *iobject = NULL; /* object of type riid */
|
2005-01-14 17:48:34 +01:00
|
|
|
|
2005-03-11 11:19:10 +01:00
|
|
|
hr = apartment_getoxid(apt, &stdobjref->oxid);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2006-01-10 20:09:08 +01:00
|
|
|
hr = apartment_createwindowifneeded(apt);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2005-07-19 21:59:41 +02:00
|
|
|
hr = IUnknown_QueryInterface(object, riid, (void **)&iobject);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("object doesn't expose interface %s, failing with error 0x%08x\n",
|
2005-07-19 21:59:41 +02:00
|
|
|
debugstr_guid(riid), hr);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2005-06-09 11:45:59 +02:00
|
|
|
/* IUnknown doesn't require a stub buffer, because it never goes out on
|
|
|
|
* the wire */
|
|
|
|
if (!IsEqualIID(riid, &IID_IUnknown))
|
2005-01-14 17:48:34 +01:00
|
|
|
{
|
2005-06-09 11:45:59 +02:00
|
|
|
IPSFactoryBuffer *psfb;
|
2004-07-22 22:34:14 +02:00
|
|
|
|
2005-06-09 11:45:59 +02:00
|
|
|
hr = get_facbuf_for_iid(riid, &psfb);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
ERR("couldn't get IPSFactory buffer for interface %s\n", debugstr_guid(riid));
|
2005-07-19 21:59:41 +02:00
|
|
|
IUnknown_Release(iobject);
|
2005-06-09 11:45:59 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-07-19 21:59:41 +02:00
|
|
|
hr = IPSFactoryBuffer_CreateStub(psfb, riid, iobject, &stub);
|
2005-06-09 11:45:59 +02:00
|
|
|
IPSFactoryBuffer_Release(psfb);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
2007-02-19 16:11:32 +01:00
|
|
|
ERR("Failed to create an IRpcStubBuffer from IPSFactory for %s with error 0x%08x\n",
|
|
|
|
debugstr_guid(riid), hr);
|
2005-07-19 21:59:41 +02:00
|
|
|
IUnknown_Release(iobject);
|
2005-06-09 11:45:59 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2005-01-20 11:35:46 +01:00
|
|
|
}
|
|
|
|
|
2008-04-28 20:42:51 +02:00
|
|
|
stdobjref->flags = SORF_NULL;
|
|
|
|
if (mshlflags & MSHLFLAGS_TABLEWEAK)
|
|
|
|
stdobjref->flags |= SORFP_TABLEWEAK;
|
2005-01-20 11:35:46 +01:00
|
|
|
if (mshlflags & MSHLFLAGS_NOPING)
|
2008-04-28 20:42:51 +02:00
|
|
|
stdobjref->flags |= SORF_NOPING;
|
2005-01-20 11:35:46 +01:00
|
|
|
|
2005-07-19 21:59:41 +02:00
|
|
|
if ((manager = get_stub_manager_from_object(apt, object)))
|
2004-12-27 20:21:47 +01:00
|
|
|
TRACE("registering new ifstub on pre-existing manager\n");
|
|
|
|
else
|
|
|
|
{
|
2005-01-05 18:14:33 +01:00
|
|
|
TRACE("constructing new stub manager\n");
|
|
|
|
|
2005-09-02 13:18:45 +02:00
|
|
|
manager = new_stub_manager(apt, object);
|
2005-01-14 17:48:34 +01:00
|
|
|
if (!manager)
|
2005-03-11 11:19:10 +01:00
|
|
|
{
|
2005-06-09 11:45:59 +02:00
|
|
|
if (stub) IRpcStubBuffer_Release(stub);
|
2005-07-19 21:59:41 +02:00
|
|
|
IUnknown_Release(iobject);
|
2005-01-14 17:48:34 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2005-03-11 11:19:10 +01:00
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2005-02-08 15:26:19 +01:00
|
|
|
stdobjref->oid = manager->oid;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-01-17 14:39:40 +01:00
|
|
|
tablemarshal = ((mshlflags & MSHLFLAGS_TABLESTRONG) || (mshlflags & MSHLFLAGS_TABLEWEAK));
|
|
|
|
|
2005-09-02 13:18:45 +02:00
|
|
|
/* make sure ifstub that we are creating is unique */
|
|
|
|
ifstub = stub_manager_find_ifstub(manager, riid, mshlflags);
|
2005-01-07 16:33:41 +01:00
|
|
|
if (!ifstub)
|
2005-09-02 13:18:45 +02:00
|
|
|
ifstub = stub_manager_new_ifstub(manager, stub, iobject, riid, mshlflags);
|
2007-02-06 20:21:40 +01:00
|
|
|
|
|
|
|
if (stub) IRpcStubBuffer_Release(stub);
|
|
|
|
IUnknown_Release(iobject);
|
|
|
|
|
|
|
|
if (!ifstub)
|
|
|
|
{
|
|
|
|
stub_manager_int_release(manager);
|
|
|
|
/* destroy the stub manager if it has no ifstubs by releasing
|
|
|
|
* zero external references */
|
2008-04-28 20:42:51 +02:00
|
|
|
stub_manager_ext_release(manager, 0, FALSE, TRUE);
|
2007-02-06 20:21:40 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2005-01-11 11:45:34 +01:00
|
|
|
}
|
|
|
|
|
2005-01-17 14:39:40 +01:00
|
|
|
if (!tablemarshal)
|
2005-01-20 11:35:46 +01:00
|
|
|
{
|
|
|
|
stdobjref->cPublicRefs = NORMALEXTREFS;
|
2008-04-28 20:42:51 +02:00
|
|
|
stub_manager_ext_addref(manager, stdobjref->cPublicRefs, FALSE);
|
2005-01-20 11:35:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stdobjref->cPublicRefs = 0;
|
|
|
|
if (mshlflags & MSHLFLAGS_TABLESTRONG)
|
2008-04-28 20:42:51 +02:00
|
|
|
stub_manager_ext_addref(manager, 1, FALSE);
|
|
|
|
else
|
|
|
|
stub_manager_ext_addref(manager, 0, TRUE);
|
2005-01-20 11:35:46 +01:00
|
|
|
}
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-02-15 16:02:49 +01:00
|
|
|
/* FIXME: check return value */
|
|
|
|
RPC_RegisterInterface(riid);
|
|
|
|
|
2005-01-20 11:35:46 +01:00
|
|
|
stdobjref->ipid = ifstub->ipid;
|
2005-01-11 11:45:34 +01:00
|
|
|
|
|
|
|
stub_manager_int_release(manager);
|
2005-01-07 16:33:41 +01:00
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:28:29 +02:00
|
|
|
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
/* Client-side identity of the server object */
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
static HRESULT proxy_manager_get_remunknown(struct proxy_manager * This, IRemUnknown **remunk);
|
2005-01-04 12:58:23 +01:00
|
|
|
static void proxy_manager_destroy(struct proxy_manager * This);
|
|
|
|
static HRESULT proxy_manager_find_ifproxy(struct proxy_manager * This, REFIID riid, struct ifproxy ** ifproxy_found);
|
2005-01-26 22:07:05 +01:00
|
|
|
static HRESULT proxy_manager_query_local_interface(struct proxy_manager * This, REFIID riid, void ** ppv);
|
2005-01-04 12:58:23 +01:00
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static HRESULT WINAPI ClientIdentity_QueryInterface(IMultiQI * iface, REFIID riid, void ** ppv)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2005-01-26 22:07:05 +01:00
|
|
|
MULTI_QI mqi;
|
2005-01-04 12:58:23 +01:00
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_guid(riid));
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
mqi.pIID = riid;
|
|
|
|
hr = IMultiQI_QueryMultipleInterfaces(iface, 1, &mqi);
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppv = mqi.pItf;
|
2005-01-19 18:00:20 +01:00
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
return hr;
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static ULONG WINAPI ClientIdentity_AddRef(IMultiQI * iface)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
struct proxy_manager * This = (struct proxy_manager *)iface;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%p - before %d\n", iface, This->refs);
|
2005-01-04 12:58:23 +01:00
|
|
|
return InterlockedIncrement(&This->refs);
|
|
|
|
}
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static ULONG WINAPI ClientIdentity_Release(IMultiQI * iface)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
struct proxy_manager * This = (struct proxy_manager *)iface;
|
|
|
|
ULONG refs = InterlockedDecrement(&This->refs);
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%p - after %d\n", iface, refs);
|
2005-01-04 12:58:23 +01:00
|
|
|
if (!refs)
|
|
|
|
proxy_manager_destroy(This);
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static HRESULT WINAPI ClientIdentity_QueryMultipleInterfaces(IMultiQI *iface, ULONG cMQIs, MULTI_QI *pMQIs)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
2005-01-26 22:07:05 +01:00
|
|
|
struct proxy_manager * This = (struct proxy_manager *)iface;
|
|
|
|
REMQIRESULT *qiresults = NULL;
|
|
|
|
ULONG nonlocal_mqis = 0;
|
|
|
|
ULONG i;
|
|
|
|
ULONG successful_mqis = 0;
|
|
|
|
IID *iids = HeapAlloc(GetProcessHeap(), 0, cMQIs * sizeof(*iids));
|
|
|
|
/* mapping of RemQueryInterface index to QueryMultipleInterfaces index */
|
|
|
|
ULONG *mapping = HeapAlloc(GetProcessHeap(), 0, cMQIs * sizeof(*mapping));
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("cMQIs: %d\n", cMQIs);
|
2005-01-26 22:07:05 +01:00
|
|
|
|
|
|
|
/* try to get a local interface - this includes already active proxy
|
|
|
|
* interfaces and also interfaces exposed by the proxy manager */
|
|
|
|
for (i = 0; i < cMQIs; i++)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("iid[%d] = %s\n", i, debugstr_guid(pMQIs[i].pIID));
|
2005-01-26 22:07:05 +01:00
|
|
|
pMQIs[i].hr = proxy_manager_query_local_interface(This, pMQIs[i].pIID, (void **)&pMQIs[i].pItf);
|
|
|
|
if (pMQIs[i].hr == S_OK)
|
|
|
|
successful_mqis++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iids[nonlocal_mqis] = *pMQIs[i].pIID;
|
|
|
|
mapping[nonlocal_mqis] = i;
|
|
|
|
nonlocal_mqis++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%d interfaces not found locally\n", nonlocal_mqis);
|
2005-01-26 22:07:05 +01:00
|
|
|
|
|
|
|
/* if we have more than one interface not found locally then we must try
|
|
|
|
* to query the remote object for it */
|
|
|
|
if (nonlocal_mqis != 0)
|
|
|
|
{
|
|
|
|
IRemUnknown *remunk;
|
|
|
|
HRESULT hr;
|
|
|
|
IPID *ipid;
|
|
|
|
|
|
|
|
/* get the ipid of the first entry */
|
|
|
|
/* FIXME: should we implement ClientIdentity on the ifproxies instead
|
|
|
|
* of the proxy_manager so we use the correct ipid here? */
|
2005-08-27 11:25:16 +02:00
|
|
|
ipid = &LIST_ENTRY(list_head(&This->interfaces), struct ifproxy, entry)->stdobjref.ipid;
|
2005-01-26 22:07:05 +01:00
|
|
|
|
|
|
|
/* get IRemUnknown proxy so we can communicate with the remote object */
|
|
|
|
hr = proxy_manager_get_remunknown(This, &remunk);
|
|
|
|
|
2008-02-13 13:35:13 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2005-01-26 22:07:05 +01:00
|
|
|
{
|
|
|
|
hr = IRemUnknown_RemQueryInterface(remunk, ipid, NORMALEXTREFS,
|
|
|
|
nonlocal_mqis, iids, &qiresults);
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_Release(remunk);
|
2005-01-26 22:07:05 +01:00
|
|
|
if (FAILED(hr))
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IRemUnknown_RemQueryInterface failed with error 0x%08x\n", hr);
|
2005-01-26 22:07:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IRemUnknown_RemQueryInterface can return S_FALSE if only some of
|
|
|
|
* the interfaces were returned */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
/* try to unmarshal each object returned to us */
|
|
|
|
for (i = 0; i < nonlocal_mqis; i++)
|
|
|
|
{
|
|
|
|
ULONG index = mapping[i];
|
|
|
|
HRESULT hrobj = qiresults[i].hResult;
|
|
|
|
if (hrobj == S_OK)
|
2007-05-21 17:45:17 +02:00
|
|
|
hrobj = unmarshal_object(&qiresults[i].std, COM_CurrentApt(),
|
2006-03-05 14:37:22 +01:00
|
|
|
This->dest_context,
|
|
|
|
This->dest_context_data,
|
2007-03-26 19:23:16 +02:00
|
|
|
pMQIs[index].pIID, &This->oxid_info,
|
2005-01-26 22:07:05 +01:00
|
|
|
(void **)&pMQIs[index].pItf);
|
|
|
|
|
|
|
|
if (hrobj == S_OK)
|
|
|
|
successful_mqis++;
|
|
|
|
else
|
|
|
|
ERR("Failed to get pointer to interface %s\n", debugstr_guid(pMQIs[index].pIID));
|
|
|
|
pMQIs[index].hr = hrobj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free the memory allocated by the proxy */
|
|
|
|
CoTaskMemFree(qiresults);
|
|
|
|
}
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%d/%d successfully queried\n", successful_mqis, cMQIs);
|
2005-01-26 22:07:05 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, iids);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mapping);
|
|
|
|
|
|
|
|
if (successful_mqis == cMQIs)
|
|
|
|
return S_OK; /* we got all requested interfaces */
|
|
|
|
else if (successful_mqis == 0)
|
|
|
|
return E_NOINTERFACE; /* we didn't get any interfaces */
|
|
|
|
else
|
|
|
|
return S_FALSE; /* we got some interfaces */
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static const IMultiQIVtbl ClientIdentity_Vtbl =
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
ClientIdentity_QueryInterface,
|
|
|
|
ClientIdentity_AddRef,
|
|
|
|
ClientIdentity_Release,
|
2005-01-26 22:07:05 +01:00
|
|
|
ClientIdentity_QueryMultipleInterfaces
|
2005-01-04 12:58:23 +01:00
|
|
|
};
|
|
|
|
|
2007-03-26 19:15:04 +02:00
|
|
|
/* FIXME: remove these */
|
|
|
|
static HRESULT WINAPI StdMarshalImpl_GetUnmarshalClass(LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, CLSID* pCid);
|
|
|
|
static HRESULT WINAPI StdMarshalImpl_GetMarshalSizeMax(LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext, void* pvDestContext, DWORD mshlflags, DWORD* pSize);
|
|
|
|
static HRESULT WINAPI StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv);
|
|
|
|
static HRESULT WINAPI StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm);
|
|
|
|
static HRESULT WINAPI StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved);
|
|
|
|
|
2005-08-27 11:25:16 +02:00
|
|
|
static HRESULT WINAPI Proxy_QueryInterface(IMarshal *iface, REFIID riid, void **ppvObject)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
|
|
|
|
return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Proxy_AddRef(IMarshal *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
|
|
|
|
return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Proxy_Release(IMarshal *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
|
|
|
|
return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Proxy_MarshalInterface(
|
|
|
|
LPMARSHAL iface, IStream *pStm, REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblMarshal, iface);
|
|
|
|
HRESULT hr;
|
|
|
|
struct ifproxy *ifproxy;
|
|
|
|
|
|
|
|
TRACE("(...,%s,...)\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
hr = proxy_manager_find_ifproxy(This, riid, &ifproxy);
|
2006-03-01 13:18:14 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2005-08-27 11:25:16 +02:00
|
|
|
{
|
2006-03-01 13:18:14 +01:00
|
|
|
STDOBJREF stdobjref = ifproxy->stdobjref;
|
2006-06-28 22:25:14 +02:00
|
|
|
|
2007-05-21 17:43:09 +02:00
|
|
|
stdobjref.cPublicRefs = 0;
|
|
|
|
|
|
|
|
if ((mshlflags != MSHLFLAGS_TABLEWEAK) &&
|
|
|
|
(mshlflags != MSHLFLAGS_TABLESTRONG))
|
2006-06-28 22:25:14 +02:00
|
|
|
{
|
2007-05-21 17:43:09 +02:00
|
|
|
ULONG cPublicRefs = ifproxy->refs;
|
|
|
|
ULONG cPublicRefsOld;
|
|
|
|
/* optimization - share out proxy's public references if possible
|
|
|
|
* instead of making new proxy do a roundtrip through the server */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ULONG cPublicRefsNew;
|
|
|
|
cPublicRefsOld = cPublicRefs;
|
|
|
|
stdobjref.cPublicRefs = cPublicRefs / 2;
|
|
|
|
cPublicRefsNew = cPublicRefs - stdobjref.cPublicRefs;
|
|
|
|
cPublicRefs = InterlockedCompareExchange(
|
|
|
|
(LONG *)&ifproxy->refs, cPublicRefsNew, cPublicRefsOld);
|
|
|
|
} while (cPublicRefs != cPublicRefsOld);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* normal and table-strong marshaling need at least one reference */
|
|
|
|
if (!stdobjref.cPublicRefs && (mshlflags != MSHLFLAGS_TABLEWEAK))
|
2006-06-28 22:25:14 +02:00
|
|
|
{
|
|
|
|
IRemUnknown *remunk;
|
|
|
|
hr = proxy_manager_get_remunknown(This, &remunk);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
HRESULT hrref = S_OK;
|
|
|
|
REMINTERFACEREF rif;
|
|
|
|
rif.ipid = ifproxy->stdobjref.ipid;
|
2007-05-21 17:43:09 +02:00
|
|
|
rif.cPublicRefs = (mshlflags == MSHLFLAGS_TABLESTRONG) ? 1 : NORMALEXTREFS;
|
2006-06-28 22:25:14 +02:00
|
|
|
rif.cPrivateRefs = 0;
|
|
|
|
hr = IRemUnknown_RemAddRef(remunk, 1, &rif, &hrref);
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_Release(remunk);
|
2006-06-28 22:25:14 +02:00
|
|
|
if (hr == S_OK && hrref == S_OK)
|
2007-05-21 17:43:09 +02:00
|
|
|
{
|
|
|
|
/* table-strong marshaling doesn't give the refs to the
|
|
|
|
* client that unmarshals the STDOBJREF */
|
|
|
|
if (mshlflags != MSHLFLAGS_TABLESTRONG)
|
|
|
|
stdobjref.cPublicRefs = rif.cPublicRefs;
|
|
|
|
}
|
2006-06-28 22:25:14 +02:00
|
|
|
else
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IRemUnknown_RemAddRef returned with 0x%08x, hrref = 0x%08x\n", hr, hrref);
|
2006-06-28 22:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-01 13:18:14 +01:00
|
|
|
|
2006-06-28 22:25:14 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2009-06-09 13:00:30 +02:00
|
|
|
TRACE("writing stdobjref: flags = %04x cPublicRefs = %d oxid = %s oid = %s ipid = %s\n",
|
2006-06-28 22:25:14 +02:00
|
|
|
stdobjref.flags, stdobjref.cPublicRefs,
|
|
|
|
wine_dbgstr_longlong(stdobjref.oxid),
|
|
|
|
wine_dbgstr_longlong(stdobjref.oid),
|
|
|
|
debugstr_guid(&stdobjref.ipid));
|
|
|
|
hr = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), NULL);
|
|
|
|
}
|
2005-08-27 11:25:16 +02:00
|
|
|
}
|
2006-03-01 13:18:14 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* we don't have the interface already unmarshaled so we have to
|
|
|
|
* request the object from the server */
|
|
|
|
IRemUnknown *remunk;
|
|
|
|
IPID *ipid;
|
|
|
|
REMQIRESULT *qiresults = NULL;
|
|
|
|
IID iid = *riid;
|
|
|
|
|
|
|
|
/* get the ipid of the first entry */
|
|
|
|
/* FIXME: should we implement ClientIdentity on the ifproxies instead
|
|
|
|
* of the proxy_manager so we use the correct ipid here? */
|
|
|
|
ipid = &LIST_ENTRY(list_head(&This->interfaces), struct ifproxy, entry)->stdobjref.ipid;
|
2005-08-27 11:25:16 +02:00
|
|
|
|
2006-03-01 13:18:14 +01:00
|
|
|
/* get IRemUnknown proxy so we can communicate with the remote object */
|
|
|
|
hr = proxy_manager_get_remunknown(This, &remunk);
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IRemUnknown_RemQueryInterface(remunk, ipid, NORMALEXTREFS,
|
|
|
|
1, &iid, &qiresults);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IStream_Write(pStm, &qiresults->std, sizeof(qiresults->std), NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
REMINTERFACEREF rif;
|
|
|
|
rif.ipid = qiresults->std.ipid;
|
|
|
|
rif.cPublicRefs = qiresults->std.cPublicRefs;
|
|
|
|
rif.cPrivateRefs = 0;
|
|
|
|
IRemUnknown_RemRelease(remunk, 1, &rif);
|
|
|
|
}
|
|
|
|
CoTaskMemFree(qiresults);
|
|
|
|
}
|
|
|
|
else
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IRemUnknown_RemQueryInterface failed with error 0x%08x\n", hr);
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_Release(remunk);
|
2006-03-01 13:18:14 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-27 11:25:16 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMarshalVtbl ProxyMarshal_Vtbl =
|
|
|
|
{
|
|
|
|
Proxy_QueryInterface,
|
|
|
|
Proxy_AddRef,
|
|
|
|
Proxy_Release,
|
|
|
|
StdMarshalImpl_GetUnmarshalClass,
|
|
|
|
StdMarshalImpl_GetMarshalSizeMax,
|
|
|
|
Proxy_MarshalInterface,
|
|
|
|
StdMarshalImpl_UnmarshalInterface,
|
|
|
|
StdMarshalImpl_ReleaseMarshalData,
|
|
|
|
StdMarshalImpl_DisconnectObject
|
|
|
|
};
|
|
|
|
|
2007-03-26 19:15:04 +02:00
|
|
|
static HRESULT WINAPI ProxyCliSec_QueryInterface(IClientSecurity *iface, REFIID riid, void **ppvObject)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
|
|
|
|
return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProxyCliSec_AddRef(IClientSecurity *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
|
|
|
|
return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProxyCliSec_Release(IClientSecurity *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(struct proxy_manager, lpVtblCliSec, iface);
|
|
|
|
return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyCliSec_QueryBlanket(IClientSecurity *iface,
|
|
|
|
IUnknown *pProxy,
|
|
|
|
DWORD *pAuthnSvc,
|
|
|
|
DWORD *pAuthzSvc,
|
2007-11-14 18:23:24 +01:00
|
|
|
OLECHAR **ppServerPrincName,
|
2007-03-26 19:15:04 +02:00
|
|
|
DWORD *pAuthnLevel,
|
|
|
|
DWORD *pImpLevel,
|
|
|
|
void **pAuthInfo,
|
|
|
|
DWORD *pCapabilities)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p, %p, %p, %p, %p, %p): stub\n", pProxy, pAuthnSvc,
|
2007-11-14 18:23:24 +01:00
|
|
|
pAuthzSvc, ppServerPrincName, pAuthnLevel, pImpLevel, pAuthInfo,
|
2007-03-26 19:15:04 +02:00
|
|
|
pCapabilities);
|
2007-11-14 18:23:24 +01:00
|
|
|
|
|
|
|
if (pAuthnSvc)
|
|
|
|
*pAuthnSvc = 0;
|
|
|
|
if (pAuthzSvc)
|
|
|
|
*pAuthzSvc = 0;
|
|
|
|
if (ppServerPrincName)
|
|
|
|
*ppServerPrincName = NULL;
|
|
|
|
if (pAuthnLevel)
|
|
|
|
*pAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
|
|
|
|
if (pImpLevel)
|
|
|
|
*pImpLevel = RPC_C_IMP_LEVEL_DEFAULT;
|
|
|
|
if (pAuthInfo)
|
|
|
|
*pAuthInfo = NULL;
|
|
|
|
if (pCapabilities)
|
|
|
|
*pCapabilities = EOAC_NONE;
|
|
|
|
|
2007-03-26 19:15:04 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyCliSec_SetBlanket(IClientSecurity *iface,
|
|
|
|
IUnknown *pProxy, DWORD AuthnSvc,
|
|
|
|
DWORD AuthzSvc,
|
|
|
|
OLECHAR *pServerPrincName,
|
|
|
|
DWORD AuthnLevel, DWORD ImpLevel,
|
|
|
|
void *pAuthInfo,
|
|
|
|
DWORD Capabilities)
|
|
|
|
{
|
2009-09-02 16:16:33 +02:00
|
|
|
FIXME("(%p, %d, %d, %s, %d, %d, %p, 0x%x): stub\n", pProxy, AuthnSvc, AuthzSvc,
|
2009-11-07 15:55:22 +01:00
|
|
|
pServerPrincName == COLE_DEFAULT_PRINCIPAL ? "<default principal>" : debugstr_w(pServerPrincName),
|
2009-09-02 16:16:33 +02:00
|
|
|
AuthnLevel, ImpLevel, pAuthInfo, Capabilities);
|
2007-03-26 19:15:04 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyCliSec_CopyProxy(IClientSecurity *iface,
|
|
|
|
IUnknown *pProxy, IUnknown **ppCopy)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", pProxy, ppCopy);
|
|
|
|
*ppCopy = NULL;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClientSecurityVtbl ProxyCliSec_Vtbl =
|
|
|
|
{
|
|
|
|
ProxyCliSec_QueryInterface,
|
|
|
|
ProxyCliSec_AddRef,
|
|
|
|
ProxyCliSec_Release,
|
|
|
|
ProxyCliSec_QueryBlanket,
|
|
|
|
ProxyCliSec_SetBlanket,
|
|
|
|
ProxyCliSec_CopyProxy
|
|
|
|
};
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
static HRESULT ifproxy_get_public_ref(struct ifproxy * This)
|
|
|
|
{
|
2005-01-26 22:07:05 +01:00
|
|
|
HRESULT hr = S_OK;
|
2005-03-17 11:26:20 +01:00
|
|
|
|
|
|
|
if (WAIT_OBJECT_0 != WaitForSingleObject(This->parent->remoting_mutex, INFINITE))
|
|
|
|
{
|
|
|
|
ERR("Wait failed for ifproxy %p\n", This);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2005-01-17 14:39:40 +01:00
|
|
|
if (This->refs == 0)
|
|
|
|
{
|
2005-01-26 22:07:05 +01:00
|
|
|
IRemUnknown *remunk = NULL;
|
2005-01-17 14:39:40 +01:00
|
|
|
|
|
|
|
TRACE("getting public ref for ifproxy %p\n", This);
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
hr = proxy_manager_get_remunknown(This->parent, &remunk);
|
|
|
|
if (hr == S_OK)
|
2005-01-17 14:39:40 +01:00
|
|
|
{
|
2006-01-11 12:09:17 +01:00
|
|
|
HRESULT hrref = S_OK;
|
2005-01-26 22:07:05 +01:00
|
|
|
REMINTERFACEREF rif;
|
2005-08-27 11:25:16 +02:00
|
|
|
rif.ipid = This->stdobjref.ipid;
|
2005-01-26 22:07:05 +01:00
|
|
|
rif.cPublicRefs = NORMALEXTREFS;
|
|
|
|
rif.cPrivateRefs = 0;
|
|
|
|
hr = IRemUnknown_RemAddRef(remunk, 1, &rif, &hrref);
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_Release(remunk);
|
2005-01-26 22:07:05 +01:00
|
|
|
if (hr == S_OK && hrref == S_OK)
|
2007-02-06 20:22:39 +01:00
|
|
|
InterlockedExchangeAdd((LONG *)&This->refs, NORMALEXTREFS);
|
2005-01-26 22:07:05 +01:00
|
|
|
else
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IRemUnknown_RemAddRef returned with 0x%08x, hrref = 0x%08x\n", hr, hrref);
|
2005-01-17 14:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
ReleaseMutex(This->parent->remoting_mutex);
|
2005-01-17 14:39:40 +01:00
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
return hr;
|
2004-08-02 20:28:29 +02:00
|
|
|
}
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
static HRESULT ifproxy_release_public_refs(struct ifproxy * This)
|
|
|
|
{
|
2005-01-26 21:42:30 +01:00
|
|
|
HRESULT hr = S_OK;
|
2007-02-06 20:22:39 +01:00
|
|
|
LONG public_refs;
|
2005-01-26 21:42:30 +01:00
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
if (WAIT_OBJECT_0 != WaitForSingleObject(This->parent->remoting_mutex, INFINITE))
|
|
|
|
{
|
|
|
|
ERR("Wait failed for ifproxy %p\n", This);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2007-02-06 20:22:39 +01:00
|
|
|
public_refs = This->refs;
|
|
|
|
if (public_refs > 0)
|
2005-01-17 14:39:40 +01:00
|
|
|
{
|
2005-01-26 21:42:30 +01:00
|
|
|
IRemUnknown *remunk = NULL;
|
|
|
|
|
2007-02-06 20:22:39 +01:00
|
|
|
TRACE("releasing %d refs\n", public_refs);
|
2005-01-26 21:42:30 +01:00
|
|
|
|
|
|
|
hr = proxy_manager_get_remunknown(This->parent, &remunk);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
REMINTERFACEREF rif;
|
2005-08-27 11:25:16 +02:00
|
|
|
rif.ipid = This->stdobjref.ipid;
|
2007-02-06 20:22:39 +01:00
|
|
|
rif.cPublicRefs = public_refs;
|
2005-01-26 21:42:30 +01:00
|
|
|
rif.cPrivateRefs = 0;
|
|
|
|
hr = IRemUnknown_RemRelease(remunk, 1, &rif);
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_Release(remunk);
|
2005-01-26 21:42:30 +01:00
|
|
|
if (hr == S_OK)
|
2007-02-06 20:22:39 +01:00
|
|
|
InterlockedExchangeAdd((LONG *)&This->refs, -public_refs);
|
2005-02-01 15:18:10 +01:00
|
|
|
else if (hr == RPC_E_DISCONNECTED)
|
|
|
|
WARN("couldn't release references because object was "
|
|
|
|
"disconnected: oxid = %s, oid = %s\n",
|
|
|
|
wine_dbgstr_longlong(This->parent->oxid),
|
|
|
|
wine_dbgstr_longlong(This->parent->oid));
|
2005-01-26 21:42:30 +01:00
|
|
|
else
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IRemUnknown_RemRelease failed with error 0x%08x\n", hr);
|
2005-01-26 21:42:30 +01:00
|
|
|
}
|
2005-01-17 14:39:40 +01:00
|
|
|
}
|
2005-03-17 11:26:20 +01:00
|
|
|
ReleaseMutex(This->parent->remoting_mutex);
|
2005-01-26 21:42:30 +01:00
|
|
|
|
|
|
|
return hr;
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-07 18:14:11 +01:00
|
|
|
/* should be called inside This->parent->cs critical section */
|
2005-01-04 12:58:23 +01:00
|
|
|
static void ifproxy_disconnect(struct ifproxy * This)
|
|
|
|
{
|
2005-01-26 21:42:30 +01:00
|
|
|
ifproxy_release_public_refs(This);
|
2005-01-27 11:39:44 +01:00
|
|
|
if (This->proxy) IRpcProxyBuffer_Disconnect(This->proxy);
|
2005-03-07 18:14:11 +01:00
|
|
|
|
|
|
|
IRpcChannelBuffer_Release(This->chan);
|
|
|
|
This->chan = NULL;
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
|
2005-03-07 18:14:11 +01:00
|
|
|
/* should be called in This->parent->cs critical section if it is an entry in parent's list */
|
2005-01-04 12:58:23 +01:00
|
|
|
static void ifproxy_destroy(struct ifproxy * This)
|
|
|
|
{
|
2005-01-19 18:00:20 +01:00
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
/* release public references to this object so that the stub can know
|
|
|
|
* when to destroy itself */
|
|
|
|
ifproxy_release_public_refs(This);
|
|
|
|
|
|
|
|
list_remove(&This->entry);
|
|
|
|
|
2005-03-07 18:14:11 +01:00
|
|
|
if (This->chan)
|
|
|
|
{
|
|
|
|
IRpcChannelBuffer_Release(This->chan);
|
|
|
|
This->chan = NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-22 23:17:13 +02:00
|
|
|
if (This->proxy) IRpcProxyBuffer_Release(This->proxy);
|
2005-01-19 18:00:20 +01:00
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2005-01-24 12:24:08 +01:00
|
|
|
static HRESULT proxy_manager_construct(
|
|
|
|
APARTMENT * apt, ULONG sorflags, OXID oxid, OID oid,
|
2007-03-26 19:23:16 +02:00
|
|
|
const OXID_INFO *oxid_info, struct proxy_manager ** proxy_manager)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
struct proxy_manager * This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
This->remoting_mutex = CreateMutexW(NULL, FALSE, NULL);
|
|
|
|
if (!This->remoting_mutex)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
2007-03-26 19:23:16 +02:00
|
|
|
if (oxid_info)
|
|
|
|
{
|
|
|
|
This->oxid_info.dwPid = oxid_info->dwPid;
|
|
|
|
This->oxid_info.dwTid = oxid_info->dwTid;
|
|
|
|
This->oxid_info.ipidRemUnknown = oxid_info->ipidRemUnknown;
|
|
|
|
This->oxid_info.dwAuthnHint = oxid_info->dwAuthnHint;
|
|
|
|
This->oxid_info.psa = NULL /* FIXME: copy from oxid_info */;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HRESULT hr = RPC_ResolveOxid(oxid, &This->oxid_info);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
CloseHandle(This->remoting_mutex);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
This->lpVtbl = &ClientIdentity_Vtbl;
|
2005-08-27 11:25:16 +02:00
|
|
|
This->lpVtblMarshal = &ProxyMarshal_Vtbl;
|
2007-03-26 19:15:04 +02:00
|
|
|
This->lpVtblCliSec = &ProxyCliSec_Vtbl;
|
2005-01-04 12:58:23 +01:00
|
|
|
|
|
|
|
list_init(&This->entry);
|
|
|
|
list_init(&This->interfaces);
|
|
|
|
|
|
|
|
InitializeCriticalSection(&This->cs);
|
2005-03-17 11:26:20 +01:00
|
|
|
DEBUG_SET_CRITSEC_NAME(&This->cs, "proxy_manager");
|
2005-01-04 12:58:23 +01:00
|
|
|
|
|
|
|
/* the apartment the object was unmarshaled into */
|
|
|
|
This->parent = apt;
|
|
|
|
|
|
|
|
/* the source apartment and id of the object */
|
|
|
|
This->oxid = oxid;
|
|
|
|
This->oid = oid;
|
|
|
|
|
2005-01-19 18:00:20 +01:00
|
|
|
This->refs = 1;
|
2005-01-04 12:58:23 +01:00
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
/* the DCOM draft specification states that the SORF_NOPING flag is
|
|
|
|
* proxy manager specific, not ifproxy specific, so this implies that we
|
2005-03-17 11:26:20 +01:00
|
|
|
* should store the STDOBJREF flags here in the proxy manager. */
|
2005-01-26 21:42:30 +01:00
|
|
|
This->sorflags = sorflags;
|
|
|
|
|
|
|
|
/* we create the IRemUnknown proxy on demand */
|
|
|
|
This->remunk = NULL;
|
|
|
|
|
2006-03-05 14:37:22 +01:00
|
|
|
/* initialise these values to the weakest values and they will be
|
|
|
|
* overwritten in proxy_manager_set_context */
|
|
|
|
This->dest_context = MSHCTX_INPROC;
|
|
|
|
This->dest_context_data = NULL;
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
EnterCriticalSection(&apt->cs);
|
2005-01-28 13:39:13 +01:00
|
|
|
/* FIXME: we are dependent on the ordering in here to make sure a proxy's
|
|
|
|
* IRemUnknown proxy doesn't get destroyed before the regual proxy does
|
|
|
|
* because we need the IRemUnknown proxy during the destruction of the
|
|
|
|
* regular proxy. Ideally, we should maintain a separate list for the
|
|
|
|
* IRemUnknown proxies that need late destruction */
|
|
|
|
list_add_tail(&apt->proxies, &This->entry);
|
2005-01-04 12:58:23 +01:00
|
|
|
LeaveCriticalSection(&apt->cs);
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
TRACE("%p created for OXID %s, OID %s\n", This,
|
|
|
|
wine_dbgstr_longlong(oxid), wine_dbgstr_longlong(oid));
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
*proxy_manager = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-05 14:37:22 +01:00
|
|
|
static inline void proxy_manager_set_context(struct proxy_manager *This, MSHCTX dest_context, void *dest_context_data)
|
|
|
|
{
|
|
|
|
MSHCTX old_dest_context = This->dest_context;
|
|
|
|
MSHCTX new_dest_context;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
new_dest_context = old_dest_context;
|
|
|
|
/* "stronger" values overwrite "weaker" values. stronger values are
|
|
|
|
* ones that disable more optimisations */
|
|
|
|
switch (old_dest_context)
|
|
|
|
{
|
|
|
|
case MSHCTX_INPROC:
|
|
|
|
new_dest_context = dest_context;
|
|
|
|
break;
|
|
|
|
case MSHCTX_CROSSCTX:
|
|
|
|
switch (dest_context)
|
|
|
|
{
|
|
|
|
case MSHCTX_INPROC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_dest_context = dest_context;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSHCTX_LOCAL:
|
|
|
|
switch (dest_context)
|
|
|
|
{
|
|
|
|
case MSHCTX_INPROC:
|
|
|
|
case MSHCTX_CROSSCTX:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_dest_context = dest_context;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSHCTX_NOSHAREDMEM:
|
|
|
|
switch (dest_context)
|
|
|
|
{
|
|
|
|
case MSHCTX_DIFFERENTMACHINE:
|
|
|
|
new_dest_context = dest_context;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_dest_context == new_dest_context) break;
|
|
|
|
|
|
|
|
old_dest_context = InterlockedCompareExchange((PLONG)&This->dest_context, new_dest_context, old_dest_context);
|
|
|
|
} while (new_dest_context != old_dest_context);
|
|
|
|
|
|
|
|
if (dest_context_data)
|
|
|
|
InterlockedExchangePointer(&This->dest_context_data, dest_context_data);
|
|
|
|
}
|
|
|
|
|
2005-01-26 22:07:05 +01:00
|
|
|
static HRESULT proxy_manager_query_local_interface(struct proxy_manager * This, REFIID riid, void ** ppv)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
struct ifproxy * ifproxy;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IMultiQI))
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppv = &This->lpVtbl;
|
2005-08-27 11:25:16 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
2005-01-26 22:07:05 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2005-08-27 11:25:16 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IMarshal))
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppv = &This->lpVtblMarshal;
|
2005-08-27 11:25:16 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (IsEqualIID(riid, &IID_IClientSecurity))
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppv = &This->lpVtblCliSec;
|
2007-03-26 19:15:04 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
|
|
|
return S_OK;
|
2005-08-27 11:25:16 +02:00
|
|
|
}
|
2005-01-26 22:07:05 +01:00
|
|
|
|
|
|
|
hr = proxy_manager_find_ifproxy(This, riid, &ifproxy);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
*ppv = ifproxy->iface;
|
|
|
|
IUnknown_AddRef((IUnknown *)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2005-01-24 12:24:08 +01:00
|
|
|
static HRESULT proxy_manager_create_ifproxy(
|
2005-08-27 11:25:16 +02:00
|
|
|
struct proxy_manager * This, const STDOBJREF *stdobjref, REFIID riid,
|
2005-03-07 18:14:11 +01:00
|
|
|
IRpcChannelBuffer * channel, struct ifproxy ** iif_out)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IPSFactoryBuffer * psfb;
|
|
|
|
struct ifproxy * ifproxy = HeapAlloc(GetProcessHeap(), 0, sizeof(*ifproxy));
|
|
|
|
if (!ifproxy) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
list_init(&ifproxy->entry);
|
|
|
|
|
2005-01-17 14:39:40 +01:00
|
|
|
ifproxy->parent = This;
|
2005-08-27 11:25:16 +02:00
|
|
|
ifproxy->stdobjref = *stdobjref;
|
2005-01-04 12:58:23 +01:00
|
|
|
ifproxy->iid = *riid;
|
2007-02-06 20:22:39 +01:00
|
|
|
ifproxy->refs = 0;
|
2005-01-04 12:58:23 +01:00
|
|
|
ifproxy->proxy = NULL;
|
|
|
|
|
2005-03-07 18:14:11 +01:00
|
|
|
assert(channel);
|
|
|
|
ifproxy->chan = channel; /* FIXME: we should take the binding strings and construct the channel in this function */
|
|
|
|
|
2005-01-27 11:39:44 +01:00
|
|
|
/* the IUnknown interface is special because it does not have a
|
2005-02-02 20:11:23 +01:00
|
|
|
* proxy associated with the ifproxy as we handle IUnknown ourselves */
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
ifproxy->iface = &This->lpVtbl;
|
2005-09-18 13:10:37 +02:00
|
|
|
IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
|
2005-01-27 11:39:44 +01:00
|
|
|
hr = S_OK;
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
2005-01-19 18:00:20 +01:00
|
|
|
else
|
2005-01-27 11:39:44 +01:00
|
|
|
{
|
|
|
|
hr = get_facbuf_for_iid(riid, &psfb);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
/* important note: the outer unknown is set to the proxy manager.
|
|
|
|
* This ensures the COM identity rules are not violated, by having a
|
|
|
|
* one-to-one mapping of objects on the proxy side to objects on the
|
|
|
|
* stub side, no matter which interface you view the object through */
|
|
|
|
hr = IPSFactoryBuffer_CreateProxy(psfb, (IUnknown *)&This->lpVtbl, riid,
|
|
|
|
&ifproxy->proxy, &ifproxy->iface);
|
|
|
|
IPSFactoryBuffer_Release(psfb);
|
|
|
|
if (hr != S_OK)
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Could not create proxy for interface %s, error 0x%08x\n",
|
2005-01-27 11:39:44 +01:00
|
|
|
debugstr_guid(riid), hr);
|
|
|
|
}
|
|
|
|
else
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Could not get IPSFactoryBuffer for interface %s, error 0x%08x\n",
|
2005-01-27 11:39:44 +01:00
|
|
|
debugstr_guid(riid), hr);
|
2005-01-04 12:58:23 +01:00
|
|
|
|
2005-01-27 11:39:44 +01:00
|
|
|
if (hr == S_OK)
|
2005-03-07 18:14:11 +01:00
|
|
|
hr = IRpcProxyBuffer_Connect(ifproxy->proxy, ifproxy->chan);
|
2005-01-27 11:39:44 +01:00
|
|
|
}
|
2005-01-04 12:58:23 +01:00
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
list_add_tail(&This->interfaces, &ifproxy->entry);
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
|
|
|
|
*iif_out = ifproxy;
|
2009-03-12 23:04:35 +01:00
|
|
|
TRACE("ifproxy %p created for IPID %s, interface %s with %u public refs\n",
|
2005-08-27 11:25:16 +02:00
|
|
|
ifproxy, debugstr_guid(&stdobjref->ipid), debugstr_guid(riid), stdobjref->cPublicRefs);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
else
|
2005-01-04 12:58:23 +01:00
|
|
|
ifproxy_destroy(ifproxy);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT proxy_manager_find_ifproxy(struct proxy_manager * This, REFIID riid, struct ifproxy ** ifproxy_found)
|
|
|
|
{
|
|
|
|
HRESULT hr = E_NOINTERFACE; /* assume not found */
|
|
|
|
struct list * cursor;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
LIST_FOR_EACH(cursor, &This->interfaces)
|
|
|
|
{
|
|
|
|
struct ifproxy * ifproxy = LIST_ENTRY(cursor, struct ifproxy, entry);
|
|
|
|
if (IsEqualIID(riid, &ifproxy->iid))
|
|
|
|
{
|
|
|
|
*ifproxy_found = ifproxy;
|
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void proxy_manager_disconnect(struct proxy_manager * This)
|
|
|
|
{
|
|
|
|
struct list * cursor;
|
|
|
|
|
2005-01-24 12:24:08 +01:00
|
|
|
TRACE("oxid = %s, oid = %s\n", wine_dbgstr_longlong(This->oxid),
|
|
|
|
wine_dbgstr_longlong(This->oid));
|
2005-01-14 18:20:13 +01:00
|
|
|
|
2005-09-18 13:10:37 +02:00
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
|
2005-06-05 21:19:24 +02:00
|
|
|
/* SORFP_NOLIFTIMEMGMT proxies (for IRemUnknown) shouldn't be
|
|
|
|
* disconnected - it won't do anything anyway, except cause
|
|
|
|
* problems for other objects that depend on this proxy always
|
|
|
|
* working */
|
2005-09-18 13:10:37 +02:00
|
|
|
if (!(This->sorflags & SORFP_NOLIFETIMEMGMT))
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
2005-09-18 13:10:37 +02:00
|
|
|
LIST_FOR_EACH(cursor, &This->interfaces)
|
|
|
|
{
|
|
|
|
struct ifproxy * ifproxy = LIST_ENTRY(cursor, struct ifproxy, entry);
|
|
|
|
ifproxy_disconnect(ifproxy);
|
|
|
|
}
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* apartment is being destroyed so don't keep a pointer around to it */
|
|
|
|
This->parent = NULL;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
}
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
static HRESULT proxy_manager_get_remunknown(struct proxy_manager * This, IRemUnknown **remunk)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2007-05-21 17:45:17 +02:00
|
|
|
struct apartment *apt;
|
|
|
|
BOOL called_in_original_apt;
|
2005-01-26 21:42:30 +01:00
|
|
|
|
|
|
|
/* we don't want to try and unmarshal or use IRemUnknown if we don't want
|
|
|
|
* lifetime management */
|
|
|
|
if (This->sorflags & SORFP_NOLIFETIMEMGMT)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2007-05-21 17:45:17 +02:00
|
|
|
apt = COM_CurrentApt();
|
|
|
|
if (!apt)
|
|
|
|
return CO_E_NOTINITIALIZED;
|
|
|
|
|
|
|
|
called_in_original_apt = This->parent && (This->parent->oxid == apt->oxid);
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
EnterCriticalSection(&This->cs);
|
2007-05-21 17:45:17 +02:00
|
|
|
/* only return the cached object if called from the original apartment.
|
|
|
|
* in future, we might want to make the IRemUnknown proxy callable from any
|
|
|
|
* apartment to avoid these checks */
|
|
|
|
if (This->remunk && called_in_original_apt)
|
2007-05-21 17:43:44 +02:00
|
|
|
{
|
2005-01-26 21:42:30 +01:00
|
|
|
/* already created - return existing object */
|
|
|
|
*remunk = This->remunk;
|
2007-05-21 17:43:44 +02:00
|
|
|
IRemUnknown_AddRef(*remunk);
|
|
|
|
}
|
2005-01-26 21:42:30 +01:00
|
|
|
else if (!This->parent)
|
|
|
|
/* disconnected - we can't create IRemUnknown */
|
|
|
|
hr = S_FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STDOBJREF stdobjref;
|
|
|
|
/* Don't want IRemUnknown lifetime management as this is IRemUnknown!
|
|
|
|
* We also don't care about whether or not the stub is still alive */
|
|
|
|
stdobjref.flags = SORFP_NOLIFETIMEMGMT | SORF_NOPING;
|
|
|
|
stdobjref.cPublicRefs = 1;
|
|
|
|
/* oxid of destination object */
|
|
|
|
stdobjref.oxid = This->oxid;
|
|
|
|
/* FIXME: what should be used for the oid? The DCOM draft doesn't say */
|
|
|
|
stdobjref.oid = (OID)-1;
|
2007-03-26 19:23:16 +02:00
|
|
|
stdobjref.ipid = This->oxid_info.ipidRemUnknown;
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
/* do the unmarshal */
|
2007-05-21 17:45:17 +02:00
|
|
|
hr = unmarshal_object(&stdobjref, COM_CurrentApt(), This->dest_context,
|
2006-03-05 14:37:22 +01:00
|
|
|
This->dest_context_data, &IID_IRemUnknown,
|
2007-05-21 17:43:44 +02:00
|
|
|
&This->oxid_info, (void**)remunk);
|
2007-05-21 17:45:17 +02:00
|
|
|
if (hr == S_OK && called_in_original_apt)
|
2007-05-21 17:43:44 +02:00
|
|
|
{
|
|
|
|
This->remunk = *remunk;
|
|
|
|
IRemUnknown_AddRef(This->remunk);
|
|
|
|
}
|
2005-01-26 21:42:30 +01:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("got IRemUnknown* pointer %p, hr = 0x%08x\n", *remunk, hr);
|
2005-01-26 21:42:30 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroys a proxy manager, freeing the memory it used.
|
|
|
|
* Note: this function should not be called from a list iteration in the
|
|
|
|
* apartment, due to the fact that it removes itself from the apartment and
|
|
|
|
* it could add a proxy to IRemUnknown into the apartment. */
|
2005-01-04 12:58:23 +01:00
|
|
|
static void proxy_manager_destroy(struct proxy_manager * This)
|
|
|
|
{
|
|
|
|
struct list * cursor;
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
TRACE("oxid = %s, oid = %s\n", wine_dbgstr_longlong(This->oxid),
|
|
|
|
wine_dbgstr_longlong(This->oid));
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
if (This->parent)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&This->parent->cs);
|
|
|
|
|
|
|
|
/* remove ourself from the list of proxy objects in the apartment */
|
|
|
|
LIST_FOR_EACH(cursor, &This->parent->proxies)
|
|
|
|
{
|
|
|
|
if (cursor == &This->entry)
|
|
|
|
{
|
|
|
|
list_remove(&This->entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->parent->cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy all of the interface proxies */
|
2005-01-19 18:00:20 +01:00
|
|
|
while ((cursor = list_head(&This->interfaces)))
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
struct ifproxy * ifproxy = LIST_ENTRY(cursor, struct ifproxy, entry);
|
|
|
|
ifproxy_destroy(ifproxy);
|
|
|
|
}
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
if (This->remunk) IRemUnknown_Release(This->remunk);
|
2007-03-26 19:23:16 +02:00
|
|
|
CoTaskMemFree(This->oxid_info.psa);
|
2005-01-04 21:33:02 +01:00
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
DEBUG_CLEAR_CRITSEC_NAME(&This->cs);
|
2005-01-04 12:58:23 +01:00
|
|
|
DeleteCriticalSection(&This->cs);
|
|
|
|
|
2005-03-17 11:26:20 +01:00
|
|
|
CloseHandle(This->remoting_mutex);
|
|
|
|
|
2005-01-04 12:58:23 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2005-01-19 18:00:20 +01:00
|
|
|
/* finds the proxy manager corresponding to a given OXID and OID that has
|
|
|
|
* been unmarshaled in the specified apartment. The caller must release the
|
|
|
|
* reference to the proxy_manager when the object is no longer used. */
|
2005-01-04 12:58:23 +01:00
|
|
|
static BOOL find_proxy_manager(APARTMENT * apt, OXID oxid, OID oid, struct proxy_manager ** proxy_found)
|
|
|
|
{
|
|
|
|
BOOL found = FALSE;
|
|
|
|
struct list * cursor;
|
|
|
|
|
|
|
|
EnterCriticalSection(&apt->cs);
|
|
|
|
LIST_FOR_EACH(cursor, &apt->proxies)
|
|
|
|
{
|
|
|
|
struct proxy_manager * proxy = LIST_ENTRY(cursor, struct proxy_manager, entry);
|
|
|
|
if ((oxid == proxy->oxid) && (oid == proxy->oid))
|
|
|
|
{
|
2007-11-22 20:08:23 +01:00
|
|
|
/* be careful of a race with ClientIdentity_Release, which would
|
|
|
|
* cause us to return a proxy which is in the process of being
|
|
|
|
* destroyed */
|
|
|
|
if (ClientIdentity_AddRef((IMultiQI *)&proxy->lpVtbl) != 0)
|
|
|
|
{
|
|
|
|
*proxy_found = proxy;
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-04 12:58:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&apt->cs);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2005-03-11 11:19:10 +01:00
|
|
|
HRESULT apartment_disconnectproxies(struct apartment *apt)
|
2005-01-04 12:58:23 +01:00
|
|
|
{
|
|
|
|
struct list * cursor;
|
|
|
|
|
|
|
|
LIST_FOR_EACH(cursor, &apt->proxies)
|
|
|
|
{
|
|
|
|
struct proxy_manager * proxy = LIST_ENTRY(cursor, struct proxy_manager, entry);
|
|
|
|
proxy_manager_disconnect(proxy);
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************** StdMarshal implementation ****************************/
|
2005-05-19 14:04:58 +02:00
|
|
|
typedef struct _StdMarshalImpl
|
|
|
|
{
|
|
|
|
const IMarshalVtbl *lpvtbl;
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2005-05-19 14:04:58 +02:00
|
|
|
|
|
|
|
IID iid;
|
|
|
|
DWORD dwDestContext;
|
|
|
|
LPVOID pvDestContext;
|
|
|
|
DWORD mshlflags;
|
2002-02-05 19:11:17 +01:00
|
|
|
} StdMarshalImpl;
|
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
static HRESULT WINAPI
|
|
|
|
StdMarshalImpl_QueryInterface(LPMARSHAL iface, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IMarshal, riid))
|
|
|
|
{
|
|
|
|
*ppv = iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("No interface for %s.\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static ULONG WINAPI
|
2005-05-19 14:04:58 +02:00
|
|
|
StdMarshalImpl_AddRef(LPMARSHAL iface)
|
|
|
|
{
|
|
|
|
StdMarshalImpl *This = (StdMarshalImpl *)iface;
|
|
|
|
return InterlockedIncrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static ULONG WINAPI
|
2005-05-19 14:04:58 +02:00
|
|
|
StdMarshalImpl_Release(LPMARSHAL iface)
|
|
|
|
{
|
|
|
|
StdMarshalImpl *This = (StdMarshalImpl *)iface;
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
if (!ref) HeapFree(GetProcessHeap(),0,This);
|
|
|
|
return ref;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2002-02-05 19:11:17 +01:00
|
|
|
StdMarshalImpl_GetUnmarshalClass(
|
2005-05-19 14:04:58 +02:00
|
|
|
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags, CLSID* pCid)
|
|
|
|
{
|
|
|
|
*pCid = CLSID_DfMarshal;
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2002-02-05 19:11:17 +01:00
|
|
|
StdMarshalImpl_GetMarshalSizeMax(
|
2005-05-19 14:04:58 +02:00
|
|
|
LPMARSHAL iface, REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags, DWORD* pSize)
|
2005-01-20 11:35:46 +01:00
|
|
|
{
|
|
|
|
*pSize = sizeof(STDOBJREF);
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2002-02-05 19:11:17 +01:00
|
|
|
StdMarshalImpl_MarshalInterface(
|
2005-05-19 14:04:58 +02:00
|
|
|
LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags)
|
|
|
|
{
|
|
|
|
STDOBJREF stdobjref;
|
|
|
|
ULONG res;
|
|
|
|
HRESULT hres;
|
|
|
|
APARTMENT *apt = COM_CurrentApt();
|
|
|
|
|
|
|
|
TRACE("(...,%s,...)\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (!apt)
|
|
|
|
{
|
|
|
|
ERR("Apartment not initialized\n");
|
|
|
|
return CO_E_NOTINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure this apartment can be reached from other threads / processes */
|
|
|
|
RPC_StartRemoting(apt);
|
|
|
|
|
2009-02-11 10:48:38 +01:00
|
|
|
hres = marshal_object(apt, &stdobjref, riid, pv, mshlflags);
|
2005-05-19 14:04:58 +02:00
|
|
|
if (hres)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to create ifstub, hres=0x%x\n", hres);
|
2005-05-19 14:04:58 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
hres = IStream_Write(pStm, &stdobjref, sizeof(stdobjref), &res);
|
|
|
|
if (hres) return hres;
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2005-01-24 12:24:08 +01:00
|
|
|
/* helper for StdMarshalImpl_UnmarshalInterface - does the unmarshaling with
|
|
|
|
* no questions asked about the rules surrounding same-apartment unmarshals
|
|
|
|
* and table marshaling */
|
2006-03-05 14:37:22 +01:00
|
|
|
static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
|
|
|
|
MSHCTX dest_context, void *dest_context_data,
|
2007-03-26 19:23:16 +02:00
|
|
|
REFIID riid, const OXID_INFO *oxid_info,
|
|
|
|
void **object)
|
2005-01-24 12:24:08 +01:00
|
|
|
{
|
|
|
|
struct proxy_manager *proxy_manager = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2005-01-26 21:42:30 +01:00
|
|
|
assert(apt);
|
|
|
|
|
2009-06-09 13:00:30 +02:00
|
|
|
TRACE("stdobjref: flags = %04x cPublicRefs = %d oxid = %s oid = %s ipid = %s\n",
|
2005-01-26 21:42:30 +01:00
|
|
|
stdobjref->flags, stdobjref->cPublicRefs,
|
|
|
|
wine_dbgstr_longlong(stdobjref->oxid),
|
|
|
|
wine_dbgstr_longlong(stdobjref->oid),
|
|
|
|
debugstr_guid(&stdobjref->ipid));
|
|
|
|
|
2006-10-15 17:05:01 +02:00
|
|
|
/* create a new proxy manager if one doesn't already exist for the
|
2005-01-24 12:24:08 +01:00
|
|
|
* object */
|
|
|
|
if (!find_proxy_manager(apt, stdobjref->oxid, stdobjref->oid, &proxy_manager))
|
|
|
|
{
|
2005-03-07 18:14:11 +01:00
|
|
|
hr = proxy_manager_construct(apt, stdobjref->flags,
|
2007-03-26 19:23:16 +02:00
|
|
|
stdobjref->oxid, stdobjref->oid, oxid_info,
|
2005-03-07 18:14:11 +01:00
|
|
|
&proxy_manager);
|
2005-01-24 12:24:08 +01:00
|
|
|
}
|
2005-02-08 13:55:26 +01:00
|
|
|
else
|
|
|
|
TRACE("proxy manager already created, using\n");
|
2005-01-24 12:24:08 +01:00
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2005-01-27 11:39:44 +01:00
|
|
|
struct ifproxy * ifproxy;
|
2006-03-05 14:37:22 +01:00
|
|
|
|
|
|
|
proxy_manager_set_context(proxy_manager, dest_context, dest_context_data);
|
|
|
|
|
2005-01-27 11:39:44 +01:00
|
|
|
hr = proxy_manager_find_ifproxy(proxy_manager, riid, &ifproxy);
|
|
|
|
if (hr == E_NOINTERFACE)
|
2005-03-07 18:14:11 +01:00
|
|
|
{
|
|
|
|
IRpcChannelBuffer *chanbuf;
|
2006-03-05 14:37:34 +01:00
|
|
|
hr = RPC_CreateClientChannel(&stdobjref->oxid, &stdobjref->ipid,
|
2007-03-27 19:15:41 +02:00
|
|
|
&proxy_manager->oxid_info,
|
2006-03-05 14:37:34 +01:00
|
|
|
proxy_manager->dest_context,
|
|
|
|
proxy_manager->dest_context_data,
|
|
|
|
&chanbuf);
|
2005-03-07 18:14:11 +01:00
|
|
|
if (hr == S_OK)
|
2005-08-27 11:25:16 +02:00
|
|
|
hr = proxy_manager_create_ifproxy(proxy_manager, stdobjref,
|
|
|
|
riid, chanbuf, &ifproxy);
|
2005-03-07 18:14:11 +01:00
|
|
|
}
|
2005-09-18 13:10:37 +02:00
|
|
|
else
|
|
|
|
IUnknown_AddRef((IUnknown *)ifproxy->iface);
|
2005-01-27 11:39:44 +01:00
|
|
|
|
2007-02-06 20:22:39 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
InterlockedExchangeAdd((LONG *)&ifproxy->refs, stdobjref->cPublicRefs);
|
|
|
|
/* get at least one external reference to the object to keep it alive */
|
|
|
|
hr = ifproxy_get_public_ref(ifproxy);
|
|
|
|
if (FAILED(hr))
|
|
|
|
ifproxy_destroy(ifproxy);
|
|
|
|
}
|
|
|
|
|
2005-01-27 11:39:44 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
*object = ifproxy->iface;
|
2005-01-24 12:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release our reference to the proxy manager - the client/apartment
|
|
|
|
* will hold on to the remaining reference for us */
|
2005-01-26 22:07:05 +01:00
|
|
|
if (proxy_manager) ClientIdentity_Release((IMultiQI*)&proxy_manager->lpVtbl);
|
2005-01-24 12:24:08 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2004-12-27 20:21:47 +01:00
|
|
|
StdMarshalImpl_UnmarshalInterface(LPMARSHAL iface, IStream *pStm, REFIID riid, void **ppv)
|
|
|
|
{
|
2006-03-05 14:37:22 +01:00
|
|
|
StdMarshalImpl *This = (StdMarshalImpl *)iface;
|
2007-03-26 19:23:16 +02:00
|
|
|
struct stub_manager *stubmgr = NULL;
|
2005-05-19 14:04:58 +02:00
|
|
|
STDOBJREF stdobjref;
|
|
|
|
ULONG res;
|
|
|
|
HRESULT hres;
|
|
|
|
APARTMENT *apt = COM_CurrentApt();
|
|
|
|
APARTMENT *stub_apt;
|
|
|
|
OXID oxid;
|
|
|
|
|
|
|
|
TRACE("(...,%s,....)\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
/* we need an apartment to unmarshal into */
|
|
|
|
if (!apt)
|
|
|
|
{
|
|
|
|
ERR("Apartment not initialized\n");
|
|
|
|
return CO_E_NOTINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read STDOBJREF from wire */
|
|
|
|
hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res);
|
2005-09-19 16:34:04 +02:00
|
|
|
if (hres) return STG_E_READFAULT;
|
2005-05-19 14:04:58 +02:00
|
|
|
|
|
|
|
hres = apartment_getoxid(apt, &oxid);
|
|
|
|
if (hres) return hres;
|
|
|
|
|
|
|
|
/* check if we're marshalling back to ourselves */
|
|
|
|
if ((oxid == stdobjref.oxid) && (stubmgr = get_stub_manager(apt, stdobjref.oid)))
|
|
|
|
{
|
|
|
|
TRACE("Unmarshalling object marshalled in same apartment for iid %s, "
|
|
|
|
"returning original object %p\n", debugstr_guid(riid), stubmgr->object);
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
hres = IUnknown_QueryInterface(stubmgr->object, riid, ppv);
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
/* unref the ifstub. FIXME: only do this on success? */
|
2005-09-02 13:18:45 +02:00
|
|
|
if (!stub_manager_is_table_marshaled(stubmgr, &stdobjref.ipid))
|
2008-04-28 20:42:51 +02:00
|
|
|
stub_manager_ext_release(stubmgr, stdobjref.cPublicRefs, stdobjref.flags & SORFP_TABLEWEAK, TRUE);
|
2005-05-19 14:04:58 +02:00
|
|
|
|
|
|
|
stub_manager_int_release(stubmgr);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notify stub manager about unmarshal if process-local object.
|
|
|
|
* note: if the oxid is not found then we and native will quite happily
|
|
|
|
* ignore table marshaling and normal marshaling rules regarding number of
|
|
|
|
* unmarshals, etc, but if you abuse these rules then your proxy could end
|
|
|
|
* up returning RPC_E_DISCONNECTED. */
|
|
|
|
if ((stub_apt = apartment_findfromoxid(stdobjref.oxid, TRUE)))
|
|
|
|
{
|
|
|
|
if ((stubmgr = get_stub_manager(stub_apt, stdobjref.oid)))
|
|
|
|
{
|
2005-09-02 13:18:45 +02:00
|
|
|
if (!stub_manager_notify_unmarshal(stubmgr, &stdobjref.ipid))
|
2005-05-19 14:04:58 +02:00
|
|
|
hres = CO_E_OBJNOTCONNECTED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Couldn't find object for OXID %s, OID %s, assuming disconnected\n",
|
|
|
|
wine_dbgstr_longlong(stdobjref.oxid),
|
|
|
|
wine_dbgstr_longlong(stdobjref.oid));
|
|
|
|
hres = CO_E_OBJNOTCONNECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("Treating unmarshal from OXID %s as inter-process\n",
|
2005-01-20 11:35:46 +01:00
|
|
|
wine_dbgstr_longlong(stdobjref.oxid));
|
2005-01-17 14:39:40 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
if (hres == S_OK)
|
2006-03-05 14:37:22 +01:00
|
|
|
hres = unmarshal_object(&stdobjref, apt, This->dwDestContext,
|
2007-03-26 19:23:16 +02:00
|
|
|
This->pvDestContext, riid,
|
|
|
|
stubmgr ? &stubmgr->oxid_info : NULL, ppv);
|
|
|
|
|
|
|
|
if (stubmgr) stub_manager_int_release(stubmgr);
|
|
|
|
if (stub_apt) apartment_release(stub_apt);
|
2005-01-20 11:35:46 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
if (hres) WARN("Failed with error 0x%08x\n", hres);
|
2005-05-19 14:04:58 +02:00
|
|
|
else TRACE("Successfully created proxy %p\n", *ppv);
|
2004-08-02 20:28:29 +02:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2005-05-19 14:04:58 +02:00
|
|
|
StdMarshalImpl_ReleaseMarshalData(LPMARSHAL iface, IStream *pStm)
|
|
|
|
{
|
2005-01-20 11:35:46 +01:00
|
|
|
STDOBJREF stdobjref;
|
2004-12-27 20:21:47 +01:00
|
|
|
ULONG res;
|
|
|
|
HRESULT hres;
|
|
|
|
struct stub_manager *stubmgr;
|
2005-01-14 17:48:34 +01:00
|
|
|
APARTMENT *apt;
|
2004-07-22 22:34:14 +02:00
|
|
|
|
2004-12-27 20:21:47 +01:00
|
|
|
TRACE("iface=%p, pStm=%p\n", iface, pStm);
|
|
|
|
|
2005-01-20 11:35:46 +01:00
|
|
|
hres = IStream_Read(pStm, &stdobjref, sizeof(stdobjref), &res);
|
2005-09-19 16:34:04 +02:00
|
|
|
if (hres) return STG_E_READFAULT;
|
2004-12-27 20:21:47 +01:00
|
|
|
|
2005-05-23 12:27:23 +02:00
|
|
|
TRACE("oxid = %s, oid = %s, ipid = %s\n",
|
|
|
|
wine_dbgstr_longlong(stdobjref.oxid),
|
|
|
|
wine_dbgstr_longlong(stdobjref.oid),
|
|
|
|
wine_dbgstr_guid(&stdobjref.ipid));
|
|
|
|
|
2005-03-11 11:19:10 +01:00
|
|
|
if (!(apt = apartment_findfromoxid(stdobjref.oxid, TRUE)))
|
2005-01-14 17:48:34 +01:00
|
|
|
{
|
2005-01-20 11:35:46 +01:00
|
|
|
WARN("Could not map OXID %s to apartment object\n",
|
|
|
|
wine_dbgstr_longlong(stdobjref.oxid));
|
2005-01-14 17:48:34 +01:00
|
|
|
return RPC_E_INVALID_OBJREF;
|
|
|
|
}
|
|
|
|
|
2005-01-20 11:35:46 +01:00
|
|
|
if (!(stubmgr = get_stub_manager(apt, stdobjref.oid)))
|
2004-12-27 20:21:47 +01:00
|
|
|
{
|
2005-09-20 13:36:40 +02:00
|
|
|
ERR("could not map object ID to stub manager, oxid=%s, oid=%s\n",
|
2005-01-20 11:35:46 +01:00
|
|
|
wine_dbgstr_longlong(stdobjref.oxid), wine_dbgstr_longlong(stdobjref.oid));
|
2004-12-27 20:21:47 +01:00
|
|
|
return RPC_E_INVALID_OBJREF;
|
|
|
|
}
|
2005-01-20 11:35:46 +01:00
|
|
|
|
2008-04-28 20:42:51 +02:00
|
|
|
stub_manager_release_marshal_data(stubmgr, stdobjref.cPublicRefs, &stdobjref.ipid, stdobjref.flags & SORFP_TABLEWEAK);
|
2005-01-11 11:45:34 +01:00
|
|
|
|
|
|
|
stub_manager_int_release(stubmgr);
|
2005-03-11 11:19:10 +01:00
|
|
|
apartment_release(apt);
|
2004-07-22 22:34:14 +02:00
|
|
|
|
2004-12-27 20:21:47 +01:00
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-08-02 20:47:31 +02:00
|
|
|
static HRESULT WINAPI
|
2005-05-19 14:04:58 +02:00
|
|
|
StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
FIXME("(), stub!\n");
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
static const IMarshalVtbl VT_StdMarshal =
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
StdMarshalImpl_QueryInterface,
|
|
|
|
StdMarshalImpl_AddRef,
|
|
|
|
StdMarshalImpl_Release,
|
|
|
|
StdMarshalImpl_GetUnmarshalClass,
|
|
|
|
StdMarshalImpl_GetMarshalSizeMax,
|
|
|
|
StdMarshalImpl_MarshalInterface,
|
|
|
|
StdMarshalImpl_UnmarshalInterface,
|
|
|
|
StdMarshalImpl_ReleaseMarshalData,
|
|
|
|
StdMarshalImpl_DisconnectObject
|
|
|
|
};
|
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
static HRESULT StdMarshalImpl_Construct(REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
StdMarshalImpl * pStdMarshal =
|
|
|
|
HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(StdMarshalImpl));
|
|
|
|
if (!pStdMarshal)
|
|
|
|
return E_OUTOFMEMORY;
|
2005-05-19 14:04:58 +02:00
|
|
|
pStdMarshal->lpvtbl = &VT_StdMarshal;
|
2004-12-14 16:14:40 +01:00
|
|
|
pStdMarshal->ref = 0;
|
|
|
|
return IMarshal_QueryInterface((IMarshal*)pStdMarshal, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoGetStandardMarshal [OLE32.@]
|
2002-02-05 19:11:17 +01:00
|
|
|
*
|
2004-12-14 16:31:05 +01:00
|
|
|
* Gets or creates a standard marshal object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* riid [I] Interface identifier of the pUnk object.
|
|
|
|
* pUnk [I] Optional. Object to get the marshal object for.
|
|
|
|
* dwDestContext [I] Destination. Used to enable or disable optimizations.
|
|
|
|
* pvDestContext [I] Reserved. Must be NULL.
|
|
|
|
* mshlflags [I] Flags affecting the marshaling process.
|
|
|
|
* ppMarshal [O] Address where marshal object will be stored.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* The function retrieves the IMarshal object associated with an object if
|
|
|
|
* that object is currently an active stub, otherwise a new marshal object is
|
|
|
|
* created.
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT WINAPI CoGetStandardMarshal(REFIID riid, IUnknown *pUnk,
|
|
|
|
DWORD dwDestContext, LPVOID pvDestContext,
|
|
|
|
DWORD mshlflags, LPMARSHAL *ppMarshal)
|
|
|
|
{
|
2005-05-19 14:04:58 +02:00
|
|
|
StdMarshalImpl *dm;
|
|
|
|
|
|
|
|
if (pUnk == NULL)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
FIXME("(%s,NULL,%x,%p,%x,%p), unimplemented yet.\n",
|
2005-05-19 14:04:58 +02:00
|
|
|
debugstr_guid(riid),dwDestContext,pvDestContext,mshlflags,ppMarshal);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%s,%p,%x,%p,%x,%p)\n",
|
2005-05-19 14:04:58 +02:00
|
|
|
debugstr_guid(riid),pUnk,dwDestContext,pvDestContext,mshlflags,ppMarshal);
|
|
|
|
*ppMarshal = HeapAlloc(GetProcessHeap(),0,sizeof(StdMarshalImpl));
|
|
|
|
dm = (StdMarshalImpl*) *ppMarshal;
|
|
|
|
if (!dm) return E_FAIL;
|
|
|
|
dm->lpvtbl = &VT_StdMarshal;
|
|
|
|
dm->ref = 1;
|
|
|
|
|
|
|
|
dm->iid = *riid;
|
|
|
|
dm->dwDestContext = dwDestContext;
|
|
|
|
dm->pvDestContext = pvDestContext;
|
|
|
|
dm->mshlflags = mshlflags;
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_marshaler [internal]
|
|
|
|
*
|
|
|
|
* Retrieves an IMarshal interface for an object.
|
|
|
|
*/
|
|
|
|
static HRESULT get_marshaler(REFIID riid, IUnknown *pUnk, DWORD dwDestContext,
|
|
|
|
void *pvDestContext, DWORD mshlFlags,
|
|
|
|
LPMARSHAL *pMarshal)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
if (!pUnk)
|
|
|
|
return E_POINTER;
|
|
|
|
hr = IUnknown_QueryInterface(pUnk, &IID_IMarshal, (LPVOID*)pMarshal);
|
|
|
|
if (hr)
|
|
|
|
hr = CoGetStandardMarshal(riid, pUnk, dwDestContext, pvDestContext,
|
|
|
|
mshlFlags, pMarshal);
|
|
|
|
return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_unmarshaler_from_stream [internal]
|
|
|
|
*
|
|
|
|
* Creates an IMarshal* object according to the data marshaled to the stream.
|
|
|
|
* The function leaves the stream pointer at the start of the data written
|
|
|
|
* to the stream by the IMarshal* object.
|
|
|
|
*/
|
2005-02-02 20:11:23 +01:00
|
|
|
static HRESULT get_unmarshaler_from_stream(IStream *stream, IMarshal **marshal, IID *iid)
|
2004-12-14 16:14:40 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG res;
|
|
|
|
OBJREF objref;
|
|
|
|
|
|
|
|
/* read common OBJREF header */
|
|
|
|
hr = IStream_Read(stream, &objref, FIELD_OFFSET(OBJREF, u_objref), &res);
|
|
|
|
if (hr || (res != FIELD_OFFSET(OBJREF, u_objref)))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to read common OBJREF header, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
return STG_E_READFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check on header */
|
|
|
|
if (objref.signature != OBJREF_SIGNATURE)
|
|
|
|
{
|
2009-03-12 23:04:35 +01:00
|
|
|
ERR("Bad OBJREF signature 0x%08x\n", objref.signature);
|
2004-12-14 16:14:40 +01:00
|
|
|
return RPC_E_INVALID_OBJREF;
|
|
|
|
}
|
|
|
|
|
2005-02-02 20:11:23 +01:00
|
|
|
if (iid) *iid = objref.iid;
|
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
/* FIXME: handler marshaling */
|
|
|
|
if (objref.flags & OBJREF_STANDARD)
|
|
|
|
{
|
|
|
|
TRACE("Using standard unmarshaling\n");
|
|
|
|
hr = StdMarshalImpl_Construct(&IID_IMarshal, (LPVOID*)marshal);
|
|
|
|
}
|
|
|
|
else if (objref.flags & OBJREF_CUSTOM)
|
|
|
|
{
|
2005-05-23 12:27:23 +02:00
|
|
|
ULONG custom_header_size = FIELD_OFFSET(OBJREF, u_objref.u_custom.pData) -
|
2004-12-14 16:14:40 +01:00
|
|
|
FIELD_OFFSET(OBJREF, u_objref.u_custom);
|
|
|
|
TRACE("Using custom unmarshaling\n");
|
|
|
|
/* read constant sized OR_CUSTOM data from stream */
|
|
|
|
hr = IStream_Read(stream, &objref.u_objref.u_custom,
|
|
|
|
custom_header_size, &res);
|
|
|
|
if (hr || (res != custom_header_size))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to read OR_CUSTOM header, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
return STG_E_READFAULT;
|
|
|
|
}
|
|
|
|
/* now create the marshaler specified in the stream */
|
|
|
|
hr = CoCreateInstance(&objref.u_objref.u_custom.clsid, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IMarshal,
|
|
|
|
(LPVOID*)marshal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 23:04:35 +01:00
|
|
|
FIXME("Invalid or unimplemented marshaling type specified: %x\n",
|
2004-12-14 16:14:40 +01:00
|
|
|
objref.flags);
|
|
|
|
return RPC_E_INVALID_OBJREF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr)
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to create marshal, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoGetMarshalSizeMax [OLE32.@]
|
2004-12-14 16:31:05 +01:00
|
|
|
*
|
|
|
|
* Gets the maximum amount of data that will be needed by a marshal.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pulSize [O] Address where maximum marshal size will be stored.
|
|
|
|
* riid [I] Identifier of the interface to marshal.
|
|
|
|
* pUnk [I] Pointer to the object to marshal.
|
|
|
|
* dwDestContext [I] Destination. Used to enable or disable optimizations.
|
|
|
|
* pvDestContext [I] Reserved. Must be NULL.
|
|
|
|
* mshlFlags [I] Flags that affect the marshaling. See CoMarshalInterface().
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* CoMarshalInterface().
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:14:40 +01:00
|
|
|
HRESULT WINAPI CoGetMarshalSizeMax(ULONG *pulSize, REFIID riid, IUnknown *pUnk,
|
|
|
|
DWORD dwDestContext, void *pvDestContext,
|
|
|
|
DWORD mshlFlags)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPMARSHAL pMarshal;
|
|
|
|
CLSID marshaler_clsid;
|
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
hr = get_marshaler(riid, pUnk, dwDestContext, pvDestContext, mshlFlags, &pMarshal);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IMarshal_GetUnmarshalClass(pMarshal, riid, pUnk, dwDestContext,
|
|
|
|
pvDestContext, mshlFlags, &marshaler_clsid);
|
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IMarshal::GetUnmarshalClass failed, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
IMarshal_Release(pMarshal);
|
|
|
|
return hr;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
hr = IMarshal_GetMarshalSizeMax(pMarshal, riid, pUnk, dwDestContext,
|
|
|
|
pvDestContext, mshlFlags, pulSize);
|
2006-05-08 13:42:36 +02:00
|
|
|
if (IsEqualCLSID(&marshaler_clsid, &CLSID_DfMarshal))
|
|
|
|
/* add on the size of the common header */
|
|
|
|
*pulSize += FIELD_OFFSET(OBJREF, u_objref);
|
|
|
|
else
|
|
|
|
/* custom marshaling: add on the size of the whole OBJREF structure
|
|
|
|
* like native does */
|
|
|
|
*pulSize += sizeof(OBJREF);
|
2004-12-14 16:14:40 +01:00
|
|
|
|
|
|
|
IMarshal_Release(pMarshal);
|
|
|
|
return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 13:18:45 +02:00
|
|
|
static void dump_MSHLFLAGS(MSHLFLAGS flags)
|
|
|
|
{
|
|
|
|
if (flags & MSHLFLAGS_TABLESTRONG)
|
|
|
|
TRACE(" MSHLFLAGS_TABLESTRONG");
|
|
|
|
if (flags & MSHLFLAGS_TABLEWEAK)
|
|
|
|
TRACE(" MSHLFLAGS_TABLEWEAK");
|
|
|
|
if (!(flags & (MSHLFLAGS_TABLESTRONG|MSHLFLAGS_TABLEWEAK)))
|
|
|
|
TRACE(" MSHLFLAGS_NORMAL");
|
|
|
|
if (flags & MSHLFLAGS_NOPING)
|
|
|
|
TRACE(" MSHLFLAGS_NOPING");
|
|
|
|
}
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoMarshalInterface [OLE32.@]
|
2004-12-14 16:31:05 +01:00
|
|
|
*
|
|
|
|
* Marshals an interface into a stream so that the object can then be
|
|
|
|
* unmarshaled from another COM apartment and used remotely.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pStream [I] Stream the object will be marshaled into.
|
|
|
|
* riid [I] Identifier of the interface to marshal.
|
|
|
|
* pUnk [I] Pointer to the object to marshal.
|
|
|
|
* dwDestContext [I] Destination. Used to enable or disable optimizations.
|
|
|
|
* pvDestContext [I] Reserved. Must be NULL.
|
|
|
|
* mshlFlags [I] Flags that affect the marshaling. See notes.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* The mshlFlags parameter can take one or more of the following flags:
|
|
|
|
*| MSHLFLAGS_NORMAL - Unmarshal once, releases stub on last proxy release.
|
|
|
|
*| MSHLFLAGS_TABLESTRONG - Unmarshal many, release when CoReleaseMarshalData() called.
|
|
|
|
*| MSHLFLAGS_TABLEWEAK - Unmarshal many, releases stub on last proxy release.
|
|
|
|
*| MSHLFLAGS_NOPING - No automatic garbage collection (and so reduces network traffic).
|
|
|
|
*
|
|
|
|
* If a marshaled object is not unmarshaled, then CoReleaseMarshalData() must
|
|
|
|
* be called in order to release the resources used in the marshaling.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* CoUnmarshalInterface(), CoReleaseMarshalData().
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:14:40 +01:00
|
|
|
HRESULT WINAPI CoMarshalInterface(IStream *pStream, REFIID riid, IUnknown *pUnk,
|
|
|
|
DWORD dwDestContext, void *pvDestContext,
|
|
|
|
DWORD mshlFlags)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
CLSID marshaler_clsid;
|
|
|
|
OBJREF objref;
|
|
|
|
LPMARSHAL pMarshal;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %s, %p, %x, %p,", pStream, debugstr_guid(riid), pUnk,
|
2005-09-02 13:18:45 +02:00
|
|
|
dwDestContext, pvDestContext);
|
|
|
|
dump_MSHLFLAGS(mshlFlags);
|
|
|
|
TRACE(")\n");
|
2004-12-14 16:14:40 +01:00
|
|
|
|
2007-01-09 18:16:19 +01:00
|
|
|
if (!pUnk || !pStream)
|
2004-12-14 16:14:40 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
objref.signature = OBJREF_SIGNATURE;
|
|
|
|
objref.iid = *riid;
|
|
|
|
|
|
|
|
/* get the marshaler for the specified interface */
|
2004-12-14 16:31:05 +01:00
|
|
|
hr = get_marshaler(riid, pUnk, dwDestContext, pvDestContext, mshlFlags, &pMarshal);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to get marshaller, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
hr = IMarshal_GetUnmarshalClass(pMarshal, riid, pUnk, dwDestContext,
|
|
|
|
pvDestContext, mshlFlags, &marshaler_clsid);
|
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IMarshal::GetUnmarshalClass failed, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-06-30 20:14:00 +02:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
/* FIXME: implement handler marshaling too */
|
|
|
|
if (IsEqualCLSID(&marshaler_clsid, &CLSID_DfMarshal))
|
|
|
|
{
|
|
|
|
TRACE("Using standard marshaling\n");
|
|
|
|
objref.flags = OBJREF_STANDARD;
|
2005-05-23 12:27:23 +02:00
|
|
|
|
|
|
|
/* write the common OBJREF header to the stream */
|
|
|
|
hr = IStream_Write(pStream, &objref, FIELD_OFFSET(OBJREF, u_objref), NULL);
|
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to write OBJREF header to stream, 0x%08x\n", hr);
|
2005-05-23 12:27:23 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-12-14 16:14:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Using custom marshaling\n");
|
|
|
|
objref.flags = OBJREF_CUSTOM;
|
2005-05-23 12:27:23 +02:00
|
|
|
objref.u_objref.u_custom.clsid = marshaler_clsid;
|
|
|
|
objref.u_objref.u_custom.cbExtension = 0;
|
|
|
|
objref.u_objref.u_custom.size = 0;
|
|
|
|
hr = IMarshal_GetMarshalSizeMax(pMarshal, riid, pUnk, dwDestContext,
|
|
|
|
pvDestContext, mshlFlags,
|
|
|
|
&objref.u_objref.u_custom.size);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to get max size of marshal data, error 0x%08x\n", hr);
|
2005-05-23 12:27:23 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
/* write constant sized common header and OR_CUSTOM data into stream */
|
|
|
|
hr = IStream_Write(pStream, &objref,
|
|
|
|
FIELD_OFFSET(OBJREF, u_objref.u_custom.pData), NULL);
|
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to write OR_CUSTOM header to stream with 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2004-07-23 21:10:13 +02:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
TRACE("Calling IMarshal::MarshalInterace\n");
|
|
|
|
/* call helper object to do the actual marshaling */
|
2005-05-23 12:27:23 +02:00
|
|
|
hr = IMarshal_MarshalInterface(pMarshal, pStream, riid, pUnk, dwDestContext,
|
2004-12-14 16:14:40 +01:00
|
|
|
pvDestContext, mshlFlags);
|
2004-07-23 21:10:13 +02:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Failed to marshal the interface %s, %x\n", debugstr_guid(riid), hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
IMarshal_Release(pMarshal);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("completed with hr 0x%08x\n", hr);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2002-02-05 19:11:17 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoUnmarshalInterface [OLE32.@]
|
2004-12-14 16:31:05 +01:00
|
|
|
*
|
|
|
|
* Unmarshals an object from a stream by creating a proxy to the remote
|
|
|
|
* object, if necessary.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
*
|
|
|
|
* pStream [I] Stream containing the marshaled object.
|
|
|
|
* riid [I] Interface identifier of the object to create a proxy to.
|
|
|
|
* ppv [O] Address where proxy will be stored.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT code.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* CoMarshalInterface().
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:14:40 +01:00
|
|
|
HRESULT WINAPI CoUnmarshalInterface(IStream *pStream, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2005-02-02 20:11:23 +01:00
|
|
|
HRESULT hr;
|
2004-12-14 16:14:40 +01:00
|
|
|
LPMARSHAL pMarshal;
|
2005-02-02 20:11:23 +01:00
|
|
|
IID iid;
|
|
|
|
IUnknown *object;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", pStream, debugstr_guid(riid), ppv);
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2007-01-09 18:17:24 +01:00
|
|
|
if (!pStream || !ppv)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-02-02 20:11:23 +01:00
|
|
|
hr = get_unmarshaler_from_stream(pStream, &pMarshal, &iid);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
/* call the helper object to do the actual unmarshaling */
|
2005-02-02 20:11:23 +01:00
|
|
|
hr = IMarshal_UnmarshalInterface(pMarshal, pStream, &iid, (LPVOID*)&object);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr)
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IMarshal::UnmarshalInterface failed, 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
|
2005-02-02 20:11:23 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2007-01-09 18:18:03 +01:00
|
|
|
/* IID_NULL means use the interface ID of the marshaled object */
|
|
|
|
if (!IsEqualIID(riid, &IID_NULL) && !IsEqualIID(riid, &iid))
|
2005-02-21 19:35:07 +01:00
|
|
|
{
|
|
|
|
TRACE("requested interface != marshalled interface, additional QI needed\n");
|
2007-01-09 18:18:03 +01:00
|
|
|
hr = IUnknown_QueryInterface(object, riid, ppv);
|
2005-02-21 19:35:07 +01:00
|
|
|
if (hr)
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("Couldn't query for interface %s, hr = 0x%08x\n",
|
2005-02-21 19:35:07 +01:00
|
|
|
debugstr_guid(riid), hr);
|
|
|
|
IUnknown_Release(object);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = object;
|
|
|
|
}
|
2005-02-02 20:11:23 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
IMarshal_Release(pMarshal);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("completed with hr 0x%x\n", hr);
|
2005-02-08 13:55:26 +01:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
return hr;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-05-02 06:20:37 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CoReleaseMarshalData [OLE32.@]
|
2004-12-14 16:31:05 +01:00
|
|
|
*
|
|
|
|
* Releases resources associated with an object that has been marshaled into
|
|
|
|
* a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
*
|
|
|
|
* pStream [I] The stream that the object has been marshaled into.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: HRESULT error code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* Call this function to release resources associated with a normal or
|
|
|
|
* table-weak marshal that will not be unmarshaled, and all table-strong
|
|
|
|
* marshals when they are no longer needed.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* CoMarshalInterface(), CoUnmarshalInterface().
|
2004-05-02 06:20:37 +02:00
|
|
|
*/
|
2004-12-14 16:14:40 +01:00
|
|
|
HRESULT WINAPI CoReleaseMarshalData(IStream *pStream)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPMARSHAL pMarshal;
|
2004-05-02 06:20:37 +02:00
|
|
|
|
2004-12-14 16:14:40 +01:00
|
|
|
TRACE("(%p)\n", pStream);
|
2004-05-02 06:20:37 +02:00
|
|
|
|
2005-02-02 20:11:23 +01:00
|
|
|
hr = get_unmarshaler_from_stream(pStream, &pMarshal, NULL);
|
2004-12-14 16:14:40 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
/* call the helper object to do the releasing of marshal data */
|
|
|
|
hr = IMarshal_ReleaseMarshalData(pMarshal, pStream);
|
|
|
|
if (hr)
|
2006-10-15 12:28:08 +02:00
|
|
|
ERR("IMarshal::ReleaseMarshalData failed with error 0x%08x\n", hr);
|
2004-12-14 16:14:40 +01:00
|
|
|
|
|
|
|
IMarshal_Release(pMarshal);
|
|
|
|
return hr;
|
2004-05-02 06:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 19:11:17 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoMarshalInterThreadInterfaceInStream [OLE32.@]
|
2002-02-05 19:11:17 +01:00
|
|
|
*
|
2004-05-29 02:22:55 +02:00
|
|
|
* Marshal an interface across threads in the same process.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* riid [I] Identifier of the interface to be marshalled.
|
|
|
|
* pUnk [I] Pointer to IUnknown-derived interface that will be marshalled.
|
2006-11-21 21:44:54 +01:00
|
|
|
* ppStm [O] Pointer to IStream object that is created and then used to store the marshalled interface.
|
2004-05-29 02:22:55 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: E_OUTOFMEMORY and other COM error codes
|
|
|
|
*
|
2004-12-14 16:31:05 +01:00
|
|
|
* SEE ALSO
|
2004-05-29 02:22:55 +02:00
|
|
|
* CoMarshalInterface(), CoUnmarshalInterface() and CoGetInterfaceAndReleaseStream()
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT WINAPI CoMarshalInterThreadInterfaceInStream(
|
|
|
|
REFIID riid, LPUNKNOWN pUnk, LPSTREAM * ppStm)
|
2004-05-29 02:22:55 +02:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER xpos;
|
|
|
|
LARGE_INTEGER seekto;
|
|
|
|
HRESULT hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-05-29 02:22:55 +02:00
|
|
|
TRACE("(%s, %p, %p)\n",debugstr_guid(riid), pUnk, ppStm);
|
|
|
|
|
2005-09-20 13:36:40 +02:00
|
|
|
hres = CreateStreamOnHGlobal(NULL, TRUE, ppStm);
|
2004-05-29 02:22:55 +02:00
|
|
|
if (FAILED(hres)) return hres;
|
|
|
|
hres = CoMarshalInterface(*ppStm, riid, pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
|
|
|
|
|
2005-09-20 13:36:40 +02:00
|
|
|
if (SUCCEEDED(hres))
|
|
|
|
{
|
|
|
|
memset(&seekto, 0, sizeof(seekto));
|
2007-01-09 18:15:59 +01:00
|
|
|
IStream_Seek(*ppStm, seekto, STREAM_SEEK_SET, &xpos);
|
2005-09-20 13:36:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IStream_Release(*ppStm);
|
|
|
|
*ppStm = NULL;
|
|
|
|
}
|
2004-05-29 02:22:55 +02:00
|
|
|
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* CoGetInterfaceAndReleaseStream [OLE32.@]
|
2004-05-29 02:22:55 +02:00
|
|
|
*
|
2006-11-21 21:44:54 +01:00
|
|
|
* Unmarshalls an interface from a stream and then releases the stream.
|
2004-05-29 02:22:55 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2006-11-21 21:44:54 +01:00
|
|
|
* pStm [I] Stream that contains the marshalled interface.
|
2004-05-29 02:22:55 +02:00
|
|
|
* riid [I] Interface identifier of the object to unmarshall.
|
|
|
|
* ppv [O] Address of pointer where the requested interface object will be stored.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: A COM error code
|
|
|
|
*
|
2004-12-14 16:31:05 +01:00
|
|
|
* SEE ALSO
|
2006-11-21 21:44:54 +01:00
|
|
|
* CoMarshalInterThreadInterfaceInStream() and CoUnmarshalInterface()
|
2002-02-05 19:11:17 +01:00
|
|
|
*/
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT WINAPI CoGetInterfaceAndReleaseStream(LPSTREAM pStm, REFIID riid,
|
|
|
|
LPVOID *ppv)
|
2004-05-29 02:22:55 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-05-29 02:22:55 +02:00
|
|
|
TRACE("(%p, %s, %p)\n", pStm, debugstr_guid(riid), ppv);
|
|
|
|
|
2006-11-21 21:40:37 +01:00
|
|
|
if(!pStm) return E_INVALIDARG;
|
2004-05-29 02:22:55 +02:00
|
|
|
hres = CoUnmarshalInterface(pStm, riid, ppv);
|
|
|
|
IStream_Release(pStm);
|
|
|
|
return hres;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
static HRESULT WINAPI StdMarshalCF_QueryInterface(LPCLASSFACTORY iface,
|
|
|
|
REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
*ppv = iface;
|
2004-12-14 16:31:05 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
static ULONG WINAPI StdMarshalCF_AddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
return 2; /* non-heap based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StdMarshalCF_Release(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
return 1; /* non-heap based object */
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMarshalCF_CreateInstance(LPCLASSFACTORY iface,
|
|
|
|
LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
2005-05-19 14:04:58 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IMarshal))
|
|
|
|
return StdMarshalImpl_Construct(riid, ppv);
|
2004-12-14 16:14:40 +01:00
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
FIXME("(%s), not supported.\n",debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
static HRESULT WINAPI StdMarshalCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
|
|
|
|
{
|
2002-02-05 19:11:17 +01:00
|
|
|
FIXME("(%d), stub!\n",fLock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-19 14:04:58 +02:00
|
|
|
static const IClassFactoryVtbl StdMarshalCFVtbl =
|
2004-12-14 16:31:05 +01:00
|
|
|
{
|
|
|
|
StdMarshalCF_QueryInterface,
|
|
|
|
StdMarshalCF_AddRef,
|
|
|
|
StdMarshalCF_Release,
|
|
|
|
StdMarshalCF_CreateInstance,
|
|
|
|
StdMarshalCF_LockServer
|
2002-02-05 19:11:17 +01:00
|
|
|
};
|
2005-05-19 14:04:58 +02:00
|
|
|
static const IClassFactoryVtbl *StdMarshalCF = &StdMarshalCFVtbl;
|
2002-02-05 19:11:17 +01:00
|
|
|
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv)
|
|
|
|
{
|
|
|
|
*ppv = &StdMarshalCF;
|
|
|
|
return S_OK;
|
2002-02-05 19:11:17 +01:00
|
|
|
}
|
2004-12-01 16:33:34 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CoMarshalHresult [OLE32.@]
|
|
|
|
*
|
|
|
|
* Marshals an HRESULT value into a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-12-20 20:27:06 +01:00
|
|
|
* pStm [I] Stream that hresult will be marshalled into.
|
|
|
|
* hresult [I] HRESULT to be marshalled.
|
2004-12-01 16:33:34 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: A COM error code
|
|
|
|
*
|
2004-12-14 16:31:05 +01:00
|
|
|
* SEE ALSO
|
2004-12-01 16:33:34 +01:00
|
|
|
* CoUnmarshalHresult().
|
|
|
|
*/
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT WINAPI CoMarshalHresult(LPSTREAM pStm, HRESULT hresult)
|
2004-12-01 16:33:34 +01:00
|
|
|
{
|
|
|
|
return IStream_Write(pStm, &hresult, sizeof(hresult), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CoUnmarshalHresult [OLE32.@]
|
|
|
|
*
|
|
|
|
* Unmarshals an HRESULT value from a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-12-20 20:27:06 +01:00
|
|
|
* pStm [I] Stream that hresult will be unmarshalled from.
|
|
|
|
* phresult [I] Pointer to HRESULT where the value will be unmarshalled to.
|
2004-12-01 16:33:34 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: A COM error code
|
|
|
|
*
|
2004-12-14 16:31:05 +01:00
|
|
|
* SEE ALSO
|
2004-12-01 16:33:34 +01:00
|
|
|
* CoMarshalHresult().
|
|
|
|
*/
|
2004-12-14 16:31:05 +01:00
|
|
|
HRESULT WINAPI CoUnmarshalHresult(LPSTREAM pStm, HRESULT * phresult)
|
2004-12-01 16:33:34 +01:00
|
|
|
{
|
|
|
|
return IStream_Read(pStm, phresult, sizeof(*phresult), NULL);
|
|
|
|
}
|