2 * MIDL proxy/stub stuff
4 * Copyright 2002 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * 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
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
41 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
49 /***********************************************************************
50 * NdrProxyInitialize [RPCRT4.@]
52 void WINAPI NdrProxyInitialize(void *This,
54 PMIDL_STUB_MESSAGE pStubMsg,
55 PMIDL_STUB_DESC pStubDescriptor,
60 TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
61 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
62 if (This) StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer);
63 if (pStubMsg->pRpcChannelBuffer) {
64 hr = IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
65 &pStubMsg->dwDestContext,
66 &pStubMsg->pvDestContext);
68 TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer);
71 /***********************************************************************
72 * NdrProxyGetBuffer [RPCRT4.@]
74 void WINAPI NdrProxyGetBuffer(void *This,
75 PMIDL_STUB_MESSAGE pStubMsg)
78 const IID *riid = NULL;
80 TRACE("(%p,%p)\n", This, pStubMsg);
81 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
82 pStubMsg->dwStubPhase = PROXY_GETBUFFER;
83 hr = StdProxy_GetIID(This, &riid);
84 hr = IRpcChannelBuffer_GetBuffer(pStubMsg->pRpcChannelBuffer,
85 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
87 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
88 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
89 pStubMsg->Buffer = pStubMsg->BufferStart;
90 pStubMsg->dwStubPhase = PROXY_MARSHAL;
93 /***********************************************************************
94 * NdrProxySendReceive [RPCRT4.@]
96 void WINAPI NdrProxySendReceive(void *This,
97 PMIDL_STUB_MESSAGE pStubMsg)
102 TRACE("(%p,%p)\n", This, pStubMsg);
104 if (!pStubMsg->pRpcChannelBuffer)
106 WARN("Trying to use disconnected proxy %p\n", This);
107 RpcRaiseException(RPC_E_DISCONNECTED);
110 pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
111 hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
112 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
114 pStubMsg->dwStubPhase = PROXY_UNMARSHAL;
115 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
116 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
117 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
118 pStubMsg->Buffer = pStubMsg->BufferStart;
120 /* raise exception if call failed */
121 if (hr == RPC_S_CALL_FAILED) RpcRaiseException(*(DWORD*)pStubMsg->Buffer);
122 else if (FAILED(hr)) RpcRaiseException(hr);
125 /***********************************************************************
126 * NdrProxyFreeBuffer [RPCRT4.@]
128 void WINAPI NdrProxyFreeBuffer(void *This,
129 PMIDL_STUB_MESSAGE pStubMsg)
133 TRACE("(%p,%p)\n", This, pStubMsg);
134 hr = IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
135 (RPCOLEMESSAGE*)pStubMsg->RpcMsg);
138 /***********************************************************************
139 * NdrProxyErrorHandler [RPCRT4.@]
141 HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
143 WARN("(0x%08lx): a proxy call failed\n", dwExceptionCode);
145 if (FAILED(dwExceptionCode))
146 return dwExceptionCode;
148 return HRESULT_FROM_WIN32(dwExceptionCode);
151 /***********************************************************************
152 * NdrStubInitialize [RPCRT4.@]
154 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
155 PMIDL_STUB_MESSAGE pStubMsg,
156 PMIDL_STUB_DESC pStubDescriptor,
157 LPRPCCHANNELBUFFER pRpcChannelBuffer)
159 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
160 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
161 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
164 /***********************************************************************
165 * NdrStubGetBuffer [RPCRT4.@]
167 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER This,
168 LPRPCCHANNELBUFFER pRpcChannelBuffer,
169 PMIDL_STUB_MESSAGE pStubMsg)
171 TRACE("(%p,%p)\n", This, pStubMsg);
172 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
173 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
174 I_RpcGetBuffer(pStubMsg->RpcMsg); /* ? */
175 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
176 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
177 pStubMsg->Buffer = pStubMsg->BufferStart;
180 /************************************************************************
181 * NdrClientInitializeNew [RPCRT4.@]
183 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
184 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
186 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
187 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
189 assert( pRpcMessage && pStubMsg && pStubDesc );
191 pRpcMessage->Handle = NULL;
192 pRpcMessage->ProcNum = ProcNum;
193 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
194 pRpcMessage->RpcFlags = 0;
195 pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
197 pStubMsg->RpcMsg = pRpcMessage;
198 pStubMsg->BufferStart = NULL;
199 pStubMsg->BufferEnd = NULL;
200 pStubMsg->BufferLength = 0;
201 pStubMsg->IsClient = TRUE;
202 pStubMsg->ReuseBuffer = FALSE;
203 pStubMsg->pAllocAllNodesContext = NULL;
204 pStubMsg->pPointerQueueState = NULL;
205 pStubMsg->IgnoreEmbeddedPointers = 0;
206 pStubMsg->PointerBufferMark = NULL;
207 pStubMsg->fBufferValid = 0;
208 pStubMsg->uFlags = 0;
209 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
210 pStubMsg->pfnFree = pStubDesc->pfnFree;
211 pStubMsg->StackTop = NULL;
212 pStubMsg->StubDesc = pStubDesc;
213 pStubMsg->FullPtrRefId = 0;
214 pStubMsg->PointerLength = 0;
215 pStubMsg->fInDontFree = 0;
216 pStubMsg->fDontCallFreeInst = 0;
217 pStubMsg->fInOnlyParam = 0;
218 pStubMsg->fHasReturn = 0;
219 pStubMsg->fHasExtensions = 0;
220 pStubMsg->fHasNewCorrDesc = 0;
221 pStubMsg->fUnused = 0;
222 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
223 pStubMsg->pvDestContext = NULL;
224 pStubMsg->pRpcChannelBuffer = NULL;
225 pStubMsg->pArrayInfo = NULL;
226 pStubMsg->dwStubPhase = 0;
227 /* FIXME: LowStackMark */
228 pStubMsg->pAsyncMsg = NULL;
229 pStubMsg->pCorrInfo = NULL;
230 pStubMsg->pCorrMemory = NULL;
231 pStubMsg->pMemoryList = NULL;
234 /***********************************************************************
235 * NdrServerInitializeNew [RPCRT4.@]
237 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
238 PMIDL_STUB_DESC pStubDesc )
240 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
242 assert( pRpcMsg && pStubMsg && pStubDesc );
244 /* not everyone allocates stack space for w2kReserved */
245 memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo));
247 pStubMsg->ReuseBuffer = TRUE;
248 pStubMsg->IsClient = FALSE;
249 pStubMsg->StubDesc = pStubDesc;
250 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
251 pStubMsg->pfnFree = pStubDesc->pfnFree;
252 pStubMsg->RpcMsg = pRpcMsg;
253 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
254 pStubMsg->BufferLength = pRpcMsg->BufferLength;
255 pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
257 /* FIXME: determine the proper return value */
261 /***********************************************************************
262 * NdrGetBuffer [RPCRT4.@]
264 unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
266 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
268 assert( stubmsg && stubmsg->RpcMsg );
270 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
271 stubmsg->RpcMsg->Handle = handle;
273 stubmsg->RpcMsg->BufferLength = buflen;
274 if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
277 stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
278 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
279 stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
280 return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
282 /***********************************************************************
283 * NdrFreeBuffer [RPCRT4.@]
285 void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
287 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
288 I_RpcFreeBuffer(pStubMsg->RpcMsg);
289 pStubMsg->BufferLength = 0;
290 pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
293 /************************************************************************
294 * NdrSendReceive [RPCRT4.@]
296 unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer )
300 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
302 /* FIXME: how to handle errors? (raise exception?) */
304 ERR("NULL stub message. No action taken.\n");
307 if (!stubmsg->RpcMsg) {
308 ERR("RPC Message not present in stub message. No action taken.\n");
312 stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
313 status = I_RpcSendReceive(stubmsg->RpcMsg);
314 if (status != RPC_S_OK)
315 RpcRaiseException(status);
317 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
318 stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
319 stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
320 stubmsg->Buffer = stubmsg->BufferStart;
322 /* FIXME: is this the right return value? */
326 /************************************************************************
327 * NdrMapCommAndFaultStatus [RPCRT4.@]
329 RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
330 unsigned long *pCommStatus,
331 unsigned long *pFaultStatus,
334 FIXME("(%p, %p, %p, %ld): stub\n", pStubMsg, pCommStatus, pFaultStatus, Status);
342 /************************************************************************
343 * NdrStubForwardingFunction [RPCRT4.@]
345 void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *This, IRpcChannelBuffer *pChannel,
346 PRPC_MESSAGE pMsg, DWORD *pdwStubPhase )
348 FIXME("Not implemented\n");