2002-10-11 01:26:53 +02:00
|
|
|
/*
|
|
|
|
* MIDL proxy/stub stuff
|
|
|
|
*
|
2008-10-18 19:20:44 +02:00
|
|
|
* Copyright 2002 Ove Kåven, TransGaming Technologies
|
2002-10-11 01:26:53 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-11 01:26:53 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
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"
|
|
|
|
|
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 "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
|
|
|
|
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);
|
|
|
|
|
2006-06-01 21:24:34 +02:00
|
|
|
pRpcMessage->Handle = NULL;
|
2008-01-07 16:19:57 +01:00
|
|
|
pRpcMessage->ProcNum = ProcNum | RPC_FLAGS_VALID_BIT;
|
2006-06-01 21:24:34 +02:00
|
|
|
pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
|
|
|
|
pRpcMessage->RpcFlags = 0;
|
2008-01-07 16:21:27 +01:00
|
|
|
pRpcMessage->ReservedForRuntime = NULL;
|
2005-06-05 21:19:50 +02:00
|
|
|
pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
|
2003-05-21 20:22:49 +02:00
|
|
|
|
2006-06-01 21:24:34 +02:00
|
|
|
pStubMsg->RpcMsg = pRpcMessage;
|
|
|
|
pStubMsg->BufferStart = NULL;
|
|
|
|
pStubMsg->BufferEnd = NULL;
|
|
|
|
pStubMsg->BufferLength = 0;
|
2002-10-24 01:36:53 +02:00
|
|
|
pStubMsg->IsClient = TRUE;
|
2006-06-01 21:24:34 +02:00
|
|
|
pStubMsg->ReuseBuffer = FALSE;
|
|
|
|
pStubMsg->pAllocAllNodesContext = NULL;
|
|
|
|
pStubMsg->pPointerQueueState = NULL;
|
|
|
|
pStubMsg->IgnoreEmbeddedPointers = 0;
|
|
|
|
pStubMsg->PointerBufferMark = NULL;
|
2008-06-22 17:17:32 +02:00
|
|
|
pStubMsg->CorrDespIncrement = 0;
|
2006-06-01 21:24:34 +02:00
|
|
|
pStubMsg->uFlags = 0;
|
2008-06-20 11:15:03 +02:00
|
|
|
pStubMsg->UniquePtrCount = 0;
|
2002-10-24 01:36:53 +02:00
|
|
|
pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
|
|
|
|
pStubMsg->pfnFree = pStubDesc->pfnFree;
|
2006-06-01 21:24:34 +02:00
|
|
|
pStubMsg->StackTop = NULL;
|
|
|
|
pStubMsg->StubDesc = pStubDesc;
|
|
|
|
pStubMsg->FullPtrRefId = 0;
|
|
|
|
pStubMsg->PointerLength = 0;
|
|
|
|
pStubMsg->fInDontFree = 0;
|
|
|
|
pStubMsg->fDontCallFreeInst = 0;
|
|
|
|
pStubMsg->fInOnlyParam = 0;
|
|
|
|
pStubMsg->fHasReturn = 0;
|
|
|
|
pStubMsg->fHasExtensions = 0;
|
|
|
|
pStubMsg->fHasNewCorrDesc = 0;
|
2008-06-22 17:17:32 +02:00
|
|
|
pStubMsg->fIsIn = 0;
|
|
|
|
pStubMsg->fIsOut = 0;
|
|
|
|
pStubMsg->fIsOicf = 0;
|
|
|
|
pStubMsg->fBufferValid = 0;
|
|
|
|
pStubMsg->fHasMemoryValidateCallback = 0;
|
|
|
|
pStubMsg->fInFree = 0;
|
|
|
|
pStubMsg->fNeedMCCP = 0;
|
2006-06-01 21:24:34 +02:00
|
|
|
pStubMsg->fUnused = 0;
|
|
|
|
pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
|
|
|
|
pStubMsg->pvDestContext = NULL;
|
|
|
|
pStubMsg->pRpcChannelBuffer = NULL;
|
|
|
|
pStubMsg->pArrayInfo = NULL;
|
|
|
|
pStubMsg->dwStubPhase = 0;
|
|
|
|
/* FIXME: LowStackMark */
|
|
|
|
pStubMsg->pAsyncMsg = NULL;
|
|
|
|
pStubMsg->pCorrInfo = NULL;
|
|
|
|
pStubMsg->pCorrMemory = NULL;
|
|
|
|
pStubMsg->pMemoryList = NULL;
|
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);
|
|
|
|
|
|
|
|
pStubMsg->RpcMsg = pRpcMsg;
|
2003-01-31 04:22:53 +01:00
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
|
2007-12-30 17:46:05 +01:00
|
|
|
pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
|
2002-10-29 00:53:23 +01:00
|
|
|
pStubMsg->BufferLength = pRpcMsg->BufferLength;
|
2007-12-30 17:46:05 +01:00
|
|
|
pStubMsg->IsClient = FALSE;
|
|
|
|
pStubMsg->ReuseBuffer = FALSE;
|
|
|
|
pStubMsg->pAllocAllNodesContext = NULL;
|
|
|
|
pStubMsg->pPointerQueueState = NULL;
|
|
|
|
pStubMsg->IgnoreEmbeddedPointers = 0;
|
|
|
|
pStubMsg->PointerBufferMark = NULL;
|
|
|
|
pStubMsg->uFlags = 0;
|
2008-06-22 10:42:08 +02:00
|
|
|
pStubMsg->UniquePtrCount = 0;
|
2007-12-30 17:46:05 +01:00
|
|
|
pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
|
|
|
|
pStubMsg->pfnFree = pStubDesc->pfnFree;
|
|
|
|
pStubMsg->StackTop = NULL;
|
|
|
|
pStubMsg->StubDesc = pStubDesc;
|
|
|
|
pStubMsg->FullPtrXlatTables = NULL;
|
|
|
|
pStubMsg->FullPtrRefId = 0;
|
|
|
|
pStubMsg->PointerLength = 0;
|
|
|
|
pStubMsg->fInDontFree = 0;
|
|
|
|
pStubMsg->fDontCallFreeInst = 0;
|
|
|
|
pStubMsg->fInOnlyParam = 0;
|
|
|
|
pStubMsg->fHasReturn = 0;
|
|
|
|
pStubMsg->fHasExtensions = 0;
|
|
|
|
pStubMsg->fHasNewCorrDesc = 0;
|
2008-06-22 17:17:32 +02:00
|
|
|
pStubMsg->fIsIn = 0;
|
|
|
|
pStubMsg->fIsOut = 0;
|
|
|
|
pStubMsg->fIsOicf = 0;
|
|
|
|
pStubMsg->fHasMemoryValidateCallback = 0;
|
|
|
|
pStubMsg->fInFree = 0;
|
|
|
|
pStubMsg->fNeedMCCP = 0;
|
2007-12-30 17:46:05 +01:00
|
|
|
pStubMsg->fUnused = 0;
|
|
|
|
pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
|
|
|
|
pStubMsg->pvDestContext = NULL;
|
|
|
|
pStubMsg->pRpcChannelBuffer = NULL;
|
|
|
|
pStubMsg->pArrayInfo = NULL;
|
|
|
|
pStubMsg->dwStubPhase = 0;
|
|
|
|
/* FIXME: LowStackMark */
|
|
|
|
pStubMsg->pAsyncMsg = NULL;
|
|
|
|
pStubMsg->pCorrInfo = NULL;
|
|
|
|
pStubMsg->pCorrMemory = NULL;
|
|
|
|
pStubMsg->pMemoryList = NULL;
|
2002-10-28 22:14:16 +01:00
|
|
|
|
2002-10-28 21:07:01 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-19 21:14:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NdrGetBuffer [RPCRT4.@]
|
|
|
|
*/
|
2007-02-07 16:20:45 +01:00
|
|
|
unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
|
2002-10-19 21:14:25 +02:00
|
|
|
{
|
2007-12-30 17:46:45 +01:00
|
|
|
RPC_STATUS status;
|
2002-10-25 23:02:02 +02:00
|
|
|
|
2007-12-30 17:46:45 +01:00
|
|
|
TRACE("(stubmsg == ^%p, buflen == %u, handle == %p)\n", stubmsg, buflen, handle);
|
2002-10-25 21:03:43 +02:00
|
|
|
|
2007-12-30 17:46:45 +01:00
|
|
|
stubmsg->RpcMsg->Handle = handle;
|
2002-10-25 21:03:43 +02:00
|
|
|
stubmsg->RpcMsg->BufferLength = buflen;
|
|
|
|
|
2007-12-30 17:46:45 +01:00
|
|
|
status = I_RpcGetBuffer(stubmsg->RpcMsg);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
RpcRaiseException(status);
|
|
|
|
|
|
|
|
stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
|
|
|
|
stubmsg->fBufferValid = TRUE;
|
2002-10-25 21:03:43 +02:00
|
|
|
stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
|
2007-12-30 17:46:45 +01:00
|
|
|
return stubmsg->Buffer;
|
2002-10-19 21:14:25 +02:00
|
|
|
}
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrFreeBuffer [RPCRT4.@]
|
|
|
|
*/
|
2007-02-07 16:20:45 +01:00
|
|
|
void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
|
2002-10-19 21:14:25 +02:00
|
|
|
{
|
2007-12-30 17:46:45 +01:00
|
|
|
TRACE("(pStubMsg == ^%p)\n", pStubMsg);
|
|
|
|
if (pStubMsg->fBufferValid)
|
|
|
|
{
|
|
|
|
I_RpcFreeBuffer(pStubMsg->RpcMsg);
|
|
|
|
pStubMsg->fBufferValid = FALSE;
|
|
|
|
}
|
2002-10-19 21:14:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* NdrSendReceive [RPCRT4.@]
|
|
|
|
*/
|
2007-02-07 16:20:45 +01:00
|
|
|
unsigned char *WINAPI NdrSendReceive( PMIDL_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
|
|
|
|
2008-07-01 09:08:55 +02:00
|
|
|
/* avoid sending uninitialised parts of the buffer on the wire */
|
2006-06-01 21:24:42 +02:00
|
|
|
stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
|
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,
|
2006-11-09 23:02:09 +01:00
|
|
|
ULONG *pCommStatus,
|
|
|
|
ULONG *pFaultStatus,
|
2005-08-03 16:55:57 +02:00
|
|
|
RPC_STATUS Status )
|
|
|
|
{
|
2008-01-08 19:14:20 +01:00
|
|
|
TRACE("(%p, %p, %p, %ld)\n", pStubMsg, pCommStatus, pFaultStatus, Status);
|
|
|
|
|
|
|
|
switch (Status)
|
|
|
|
{
|
|
|
|
case ERROR_INVALID_HANDLE:
|
|
|
|
case RPC_S_INVALID_BINDING:
|
|
|
|
case RPC_S_UNKNOWN_IF:
|
|
|
|
case RPC_S_SERVER_UNAVAILABLE:
|
|
|
|
case RPC_S_SERVER_TOO_BUSY:
|
|
|
|
case RPC_S_CALL_FAILED_DNE:
|
|
|
|
case RPC_S_PROTOCOL_ERROR:
|
|
|
|
case RPC_S_UNSUPPORTED_TRANS_SYN:
|
|
|
|
case RPC_S_UNSUPPORTED_TYPE:
|
|
|
|
case RPC_S_PROCNUM_OUT_OF_RANGE:
|
|
|
|
case EPT_S_NOT_REGISTERED:
|
|
|
|
case RPC_S_COMM_FAILURE:
|
|
|
|
*pCommStatus = Status;
|
|
|
|
*pFaultStatus = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*pCommStatus = 0;
|
|
|
|
*pFaultStatus = Status;
|
|
|
|
}
|
2005-08-03 16:55:57 +02:00
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|