2002-10-11 01:26:53 +02:00
|
|
|
|
/*
|
|
|
|
|
* MIDL proxy/stub stuff
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2002 Ove K<EFBFBD>ven, TransGaming Technologies
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* TODO:
|
|
|
|
|
* - figure out whether we *really* got this right
|
|
|
|
|
* - check for errors and throw exceptions
|
|
|
|
|
*/
|
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
2002-10-11 01:26:53 +02:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2002-10-25 23:02:02 +02:00
|
|
|
|
#include <assert.h>
|
2002-10-11 01:26:53 +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:26:53 +02:00
|
|
|
|
|
|
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
|
|
#include "cpsf.h"
|
|
|
|
|
#include "ndr_misc.h"
|
2002-10-28 22:14:16 +01:00
|
|
|
|
#include "rpcndr.h"
|
2002-10-11 01:26:53 +02:00
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrProxyInitialize [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrProxyInitialize(void *This,
|
|
|
|
|
PRPC_MESSAGE pRpcMsg,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
|
PMIDL_STUB_DESC pStubDescriptor,
|
|
|
|
|
unsigned int ProcNum)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
|
2003-01-31 04:22:53 +01:00
|
|
|
|
NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
|
2002-10-11 01:26:53 +02:00
|
|
|
|
if (This) StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer);
|
|
|
|
|
if (pStubMsg->pRpcChannelBuffer) {
|
|
|
|
|
hr = IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
|
|
|
|
|
&pStubMsg->dwDestContext,
|
|
|
|
|
&pStubMsg->pvDestContext);
|
|
|
|
|
}
|
|
|
|
|
TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrProxyGetBuffer [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrProxyGetBuffer(void *This,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
const IID *riid = NULL;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
|
pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
|
|
|
|
|
pStubMsg->dwStubPhase = PROXY_GETBUFFER;
|
|
|
|
|
hr = StdProxy_GetIID(This, &riid);
|
|
|
|
|
hr = IRpcChannelBuffer_GetBuffer(pStubMsg->pRpcChannelBuffer,
|
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg,
|
|
|
|
|
riid);
|
|
|
|
|
pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
|
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
|
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart;
|
|
|
|
|
pStubMsg->dwStubPhase = PROXY_MARSHAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrProxySendReceive [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrProxySendReceive(void *This,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
|
{
|
|
|
|
|
ULONG Status = 0;
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
|
pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
|
|
|
|
|
hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
|
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg,
|
|
|
|
|
&Status);
|
|
|
|
|
pStubMsg->dwStubPhase = PROXY_UNMARSHAL;
|
|
|
|
|
pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
|
|
|
|
|
pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
|
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
|
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart;
|
2003-05-22 05:36:00 +02:00
|
|
|
|
|
|
|
|
|
/* raise exception if call failed */
|
|
|
|
|
if (hr == RPC_S_CALL_FAILED) RpcRaiseException(*(DWORD*)pStubMsg->Buffer);
|
|
|
|
|
else if (FAILED(hr)) RpcRaiseException(hr);
|
2002-10-11 01:26:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrProxyFreeBuffer [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrProxyFreeBuffer(void *This,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
|
{
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
|
hr = IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
|
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-21 20:22:49 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrProxyErrorHandler [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
|
|
|
|
|
{
|
|
|
|
|
FIXME("(0x%08lx): semi-stub\n", dwExceptionCode);
|
|
|
|
|
return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_RPC, RPC_S_CALL_FAILED);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 01:26:53 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrStubInitialize [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
|
PMIDL_STUB_DESC pStubDescriptor,
|
|
|
|
|
LPRPCCHANNELBUFFER pRpcChannelBuffer)
|
|
|
|
|
{
|
|
|
|
|
TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
|
2003-01-31 04:22:53 +01:00
|
|
|
|
NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
|
2002-10-11 01:26:53 +02:00
|
|
|
|
pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrStubGetBuffer [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER This,
|
|
|
|
|
LPRPCCHANNELBUFFER pRpcChannelBuffer,
|
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
|
{
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
|
pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
|
|
|
|
|
pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
|
|
|
|
|
I_RpcGetBuffer(pStubMsg->RpcMsg); /* ? */
|
|
|
|
|
pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
|
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
|
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart;
|
|
|
|
|
}
|
2002-10-19 21:14:25 +02:00
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
* NdrClientInitializeNew [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
|
2002-10-24 01:36:53 +02:00
|
|
|
|
PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
|
2002-10-19 21:14:25 +02:00
|
|
|
|
{
|
2002-10-24 01:36:53 +02:00
|
|
|
|
TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
|
|
|
|
|
pRpcMessage, pStubMsg, pStubDesc, ProcNum);
|
|
|
|
|
|
2002-10-28 22:14:16 +01:00
|
|
|
|
assert( pRpcMessage && pStubMsg && pStubDesc );
|
|
|
|
|
|
2002-10-24 01:36:53 +02:00
|
|
|
|
memset(pRpcMessage, 0, sizeof(RPC_MESSAGE));
|
2003-05-21 20:22:49 +02:00
|
|
|
|
|
|
|
|
|
/* not everyone allocates stack space for w2kReserved */
|
2004-09-08 03:27:24 +02:00
|
|
|
|
memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo));
|
2002-10-24 01:36:53 +02:00
|
|
|
|
|
2003-01-31 04:22:53 +01:00
|
|
|
|
pStubMsg->ReuseBuffer = FALSE;
|
2002-10-24 01:36:53 +02:00
|
|
|
|
pStubMsg->IsClient = TRUE;
|
|
|
|
|
pStubMsg->StubDesc = pStubDesc;
|
|
|
|
|
pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
|
|
|
|
|
pStubMsg->pfnFree = pStubDesc->pfnFree;
|
|
|
|
|
pStubMsg->RpcMsg = pRpcMessage;
|
|
|
|
|
|
|
|
|
|
pRpcMessage->ProcNum = ProcNum;
|
|
|
|
|
pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
|
2002-10-19 21:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-28 21:07:01 +01:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrServerInitializeNew [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
|
PMIDL_STUB_DESC pStubDesc )
|
|
|
|
|
{
|
2002-10-28 22:14:16 +01:00
|
|
|
|
TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
|
|
|
|
|
|
|
|
|
|
assert( pRpcMsg && pStubMsg && pStubDesc );
|
|
|
|
|
|
2003-05-21 20:22:49 +02:00
|
|
|
|
/* not everyone allocates stack space for w2kReserved */
|
2004-09-08 03:27:24 +02:00
|
|
|
|
memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo));
|
2002-10-28 22:14:16 +01:00
|
|
|
|
|
|
|
|
|
pStubMsg->ReuseBuffer = TRUE;
|
|
|
|
|
pStubMsg->IsClient = FALSE;
|
|
|
|
|
pStubMsg->StubDesc = pStubDesc;
|
|
|
|
|
pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
|
|
|
|
|
pStubMsg->pfnFree = pStubDesc->pfnFree;
|
|
|
|
|
pStubMsg->RpcMsg = pRpcMsg;
|
2003-01-31 04:22:53 +01:00
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
|
2002-10-29 00:53:23 +01:00
|
|
|
|
pStubMsg->BufferLength = pRpcMsg->BufferLength;
|
2003-01-31 04:22:53 +01:00
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
|
2002-10-28 22:14:16 +01:00
|
|
|
|
|
|
|
|
|
/* FIXME: determine the proper return value */
|
2002-10-28 21:07:01 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-19 21:14:25 +02:00
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrGetBuffer [RPCRT4.@]
|
|
|
|
|
*/
|
2002-10-22 01:42:01 +02:00
|
|
|
|
unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
|
2002-10-19 21:14:25 +02:00
|
|
|
|
{
|
2002-10-25 21:03:43 +02:00
|
|
|
|
TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
|
|
|
|
|
|
2002-10-25 23:02:02 +02:00
|
|
|
|
assert( stubmsg && stubmsg->RpcMsg );
|
|
|
|
|
|
|
|
|
|
/* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
|
|
|
|
|
stubmsg->RpcMsg->Handle = handle;
|
2002-10-25 21:03:43 +02:00
|
|
|
|
|
|
|
|
|
stubmsg->RpcMsg->BufferLength = buflen;
|
|
|
|
|
if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2003-01-31 04:22:53 +01:00
|
|
|
|
stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
|
2002-10-25 21:03:43 +02:00
|
|
|
|
stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
|
2003-01-31 04:22:53 +01:00
|
|
|
|
stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
|
2002-10-25 21:03:43 +02:00
|
|
|
|
return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
|
2002-10-19 21:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* NdrFreeBuffer [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
|
|
|
|
|
{
|
2002-10-25 21:03:43 +02:00
|
|
|
|
TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
|
|
|
|
|
I_RpcFreeBuffer(pStubMsg->RpcMsg);
|
|
|
|
|
pStubMsg->BufferLength = 0;
|
2003-01-31 04:22:53 +01:00
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
|
2002-10-19 21:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
* NdrSendReceive [RPCRT4.@]
|
|
|
|
|
*/
|
2002-10-22 01:42:01 +02:00
|
|
|
|
unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer )
|
2002-10-19 21:14:25 +02:00
|
|
|
|
{
|
2002-10-25 23:02:02 +02:00
|
|
|
|
TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
|
|
|
|
|
|
|
|
|
|
/* FIXME: how to handle errors? (raise exception?) */
|
|
|
|
|
if (!stubmsg) {
|
|
|
|
|
ERR("NULL stub message. No action taken.\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (!stubmsg->RpcMsg) {
|
|
|
|
|
ERR("RPC Message not present in stub message. No action taken.\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2003-01-31 04:22:53 +01:00
|
|
|
|
|
2003-10-22 01:49:57 +02:00
|
|
|
|
/* FIXME: Seems wrong. Where should this really come from, and when? */
|
2002-10-28 22:14:16 +01:00
|
|
|
|
stubmsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
|
2002-10-25 23:02:02 +02:00
|
|
|
|
|
|
|
|
|
if (I_RpcSendReceive(stubmsg->RpcMsg) != RPC_S_OK) {
|
|
|
|
|
WARN("I_RpcSendReceive did not return success.\n");
|
2003-10-22 01:49:57 +02:00
|
|
|
|
/* FIXME: raise exception? */
|
2002-10-25 23:02:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* FIXME: is this the right return value? */
|
2002-10-22 01:42:01 +02:00
|
|
|
|
return NULL;
|
2002-10-19 21:14:25 +02:00
|
|
|
|
}
|