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
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
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
|
|
|
|
|
2005-03-14 11:11:04 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
|
2002-10-11 01:26:53 +02:00
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* 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);
|
2004-12-14 12:44:11 +01:00
|
|
|
|
|
|
|
|
|
if (!pStubMsg->pRpcChannelBuffer)
|
|
|
|
|
{
|
|
|
|
|
WARN("Trying to use disconnected proxy %p\n", This);
|
|
|
|
|
RpcRaiseException(RPC_E_DISCONNECTED);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-11 01:26:53 +02:00
|
|
|
|
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)
|
|
|
|
|
{
|
2005-11-29 10:41:45 +01:00
|
|
|
|
WARN("(0x%08lx): a proxy call failed\n", dwExceptionCode);
|
|
|
|
|
|
|
|
|
|
if (FAILED(dwExceptionCode))
|
|
|
|
|
return dwExceptionCode;
|
|
|
|
|
else
|
|
|
|
|
return HRESULT_FROM_WIN32(dwExceptionCode);
|
2003-05-21 20:22:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
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));
|
2005-06-05 21:19:50 +02:00
|
|
|
|
pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
|
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
|
|
|
|
{
|
2006-02-03 18:46:32 +01:00
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
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
|
|
|
|
|
2006-02-03 18:46:32 +01:00
|
|
|
|
status = I_RpcSendReceive(stubmsg->RpcMsg);
|
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
|
RpcRaiseException(status);
|
2002-10-25 23:02:02 +02:00
|
|
|
|
|
2005-11-28 11:31:04 +01:00
|
|
|
|
stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
|
|
|
|
|
stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
|
|
|
|
|
stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
|
|
|
|
|
stubmsg->Buffer = stubmsg->BufferStart;
|
|
|
|
|
|
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
|
|
|
|
}
|
2005-08-03 16:55:57 +02:00
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
* NdrMapCommAndFaultStatus [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
|
unsigned long *pCommStatus,
|
|
|
|
|
unsigned long *pFaultStatus,
|
|
|
|
|
RPC_STATUS Status )
|
|
|
|
|
{
|
|
|
|
|
FIXME("(%p, %p, %p, %ld): stub\n", pStubMsg, pCommStatus, pFaultStatus, Status);
|
|
|
|
|
|
|
|
|
|
*pCommStatus = 0;
|
|
|
|
|
*pFaultStatus = 0;
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
2005-10-26 15:56:00 +02:00
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
* NdrStubForwardingFunction [RPCRT4.@]
|
|
|
|
|
*/
|
|
|
|
|
void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *This, IRpcChannelBuffer *pChannel,
|
|
|
|
|
PRPC_MESSAGE pMsg, DWORD *pdwStubPhase )
|
|
|
|
|
{
|
|
|
|
|
FIXME("Not implemented\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|