ndr_clientserver.c 6.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * MIDL proxy/stub stuff
 *
 * Copyright 2002 Ove Kven, 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24
 *
 * TODO:
 *  - figure out whether we *really* got this right
 *  - check for errors and throw exceptions
 */

25
#include <stdarg.h>
26 27
#include <stdio.h>
#include <string.h>
28
#include <assert.h>
29

30 31
#define COBJMACROS

32 33 34 35 36
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winreg.h"

37
#include "objbase.h"
38 39 40 41 42 43

#include "rpcproxy.h"

#include "wine/debug.h"

#include "ndr_misc.h"
44
#include "rpcndr.h"
45

46
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
47

48 49 50 51
/************************************************************************
 *             NdrClientInitializeNew [RPCRT4.@]
 */
void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, 
52
                                    PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
53
{
54 55 56
  TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
    pRpcMessage, pStubMsg, pStubDesc, ProcNum);

57 58
  assert( pRpcMessage && pStubMsg && pStubDesc );

59 60 61 62
  pRpcMessage->Handle = NULL;
  pRpcMessage->ProcNum = ProcNum;
  pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
  pRpcMessage->RpcFlags = 0;
63
  pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
64

65 66 67 68
  pStubMsg->RpcMsg = pRpcMessage;
  pStubMsg->BufferStart = NULL;
  pStubMsg->BufferEnd = NULL;
  pStubMsg->BufferLength = 0;
69
  pStubMsg->IsClient = TRUE;
70 71 72 73 74 75 76
  pStubMsg->ReuseBuffer = FALSE;
  pStubMsg->pAllocAllNodesContext = NULL;
  pStubMsg->pPointerQueueState = NULL;
  pStubMsg->IgnoreEmbeddedPointers = 0;
  pStubMsg->PointerBufferMark = NULL;
  pStubMsg->fBufferValid = 0;
  pStubMsg->uFlags = 0;
77 78
  pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  pStubMsg->pfnFree = pStubDesc->pfnFree;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  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;
  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;
100 101
}

102 103 104 105 106 107
/***********************************************************************
 *             NdrServerInitializeNew [RPCRT4.@]
 */
unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
                                              PMIDL_STUB_DESC pStubDesc )
{
108 109 110 111
  TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);

  assert( pRpcMsg && pStubMsg && pStubDesc );

112
  /* not everyone allocates stack space for w2kReserved */
113
  memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo));
114 115 116 117 118 119 120

  pStubMsg->ReuseBuffer = TRUE;
  pStubMsg->IsClient = FALSE;
  pStubMsg->StubDesc = pStubDesc;
  pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  pStubMsg->pfnFree = pStubDesc->pfnFree;
  pStubMsg->RpcMsg = pRpcMsg;
121
  pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
122
  pStubMsg->BufferLength = pRpcMsg->BufferLength;
123
  pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
124 125

  /* FIXME: determine the proper return value */
126 127 128
  return NULL;
}

129 130 131
/***********************************************************************
 *           NdrGetBuffer [RPCRT4.@]
 */
132
unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
133
{
134 135
  TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
  
136 137 138 139
  assert( stubmsg && stubmsg->RpcMsg );

  /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
  stubmsg->RpcMsg->Handle = handle;
140 141 142 143 144
  
  stubmsg->RpcMsg->BufferLength = buflen;
  if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
    return NULL;

145
  stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
146
  stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
147
  stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
148
  return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
149 150 151 152 153 154
}
/***********************************************************************
 *           NdrFreeBuffer [RPCRT4.@]
 */
void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
{
155 156 157
  TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
  I_RpcFreeBuffer(pStubMsg->RpcMsg);
  pStubMsg->BufferLength = 0;
158
  pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
159 160 161 162 163
}

/************************************************************************
 *           NdrSendReceive [RPCRT4.@]
 */
164
unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer  )
165
{
166 167
  RPC_STATUS status;

168 169 170 171 172 173 174 175 176 177 178
  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;
  }
179

180
  stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
181 182 183
  status = I_RpcSendReceive(stubmsg->RpcMsg);
  if (status != RPC_S_OK)
    RpcRaiseException(status);
184

185 186 187 188 189
  stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
  stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
  stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
  stubmsg->Buffer = stubmsg->BufferStart;

190
  /* FIXME: is this the right return value? */
191
  return NULL;
192
}
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

/************************************************************************
 *           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;
}