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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
38 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
46 /***********************************************************************
47 * NdrProxyInitialize [RPCRT4.@]
49 void WINAPI NdrProxyInitialize(void *This,
51 PMIDL_STUB_MESSAGE pStubMsg,
52 PMIDL_STUB_DESC pStubDescriptor,
57 TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
58 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
59 if (This) StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer);
60 if (pStubMsg->pRpcChannelBuffer) {
61 hr = IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
62 &pStubMsg->dwDestContext,
63 &pStubMsg->pvDestContext);
65 TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer);
68 /***********************************************************************
69 * NdrProxyGetBuffer [RPCRT4.@]
71 void WINAPI NdrProxyGetBuffer(void *This,
72 PMIDL_STUB_MESSAGE pStubMsg)
75 const IID *riid = NULL;
77 TRACE("(%p,%p)\n", This, pStubMsg);
78 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
79 pStubMsg->dwStubPhase = PROXY_GETBUFFER;
80 hr = StdProxy_GetIID(This, &riid);
81 hr = IRpcChannelBuffer_GetBuffer(pStubMsg->pRpcChannelBuffer,
82 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
84 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
85 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
86 pStubMsg->Buffer = pStubMsg->BufferStart;
87 pStubMsg->dwStubPhase = PROXY_MARSHAL;
90 /***********************************************************************
91 * NdrProxySendReceive [RPCRT4.@]
93 void WINAPI NdrProxySendReceive(void *This,
94 PMIDL_STUB_MESSAGE pStubMsg)
99 TRACE("(%p,%p)\n", This, pStubMsg);
100 pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
101 hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
102 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
104 pStubMsg->dwStubPhase = PROXY_UNMARSHAL;
105 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
106 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
107 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
108 pStubMsg->Buffer = pStubMsg->BufferStart;
111 /***********************************************************************
112 * NdrProxyFreeBuffer [RPCRT4.@]
114 void WINAPI NdrProxyFreeBuffer(void *This,
115 PMIDL_STUB_MESSAGE pStubMsg)
119 TRACE("(%p,%p)\n", This, pStubMsg);
120 hr = IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
121 (RPCOLEMESSAGE*)pStubMsg->RpcMsg);
124 /***********************************************************************
125 * NdrProxyErrorHandler [RPCRT4.@]
127 HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
129 FIXME("(0x%08lx): semi-stub\n", dwExceptionCode);
130 return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_RPC, RPC_S_CALL_FAILED);
133 /***********************************************************************
134 * NdrStubInitialize [RPCRT4.@]
136 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
137 PMIDL_STUB_MESSAGE pStubMsg,
138 PMIDL_STUB_DESC pStubDescriptor,
139 LPRPCCHANNELBUFFER pRpcChannelBuffer)
141 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
142 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
143 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
146 /***********************************************************************
147 * NdrStubGetBuffer [RPCRT4.@]
149 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER This,
150 LPRPCCHANNELBUFFER pRpcChannelBuffer,
151 PMIDL_STUB_MESSAGE pStubMsg)
153 TRACE("(%p,%p)\n", This, pStubMsg);
154 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
155 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
156 I_RpcGetBuffer(pStubMsg->RpcMsg); /* ? */
157 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
158 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
159 pStubMsg->Buffer = pStubMsg->BufferStart;
162 /************************************************************************
163 * NdrClientInitializeNew [RPCRT4.@]
165 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
166 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
168 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
169 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
171 assert( pRpcMessage && pStubMsg && pStubDesc );
173 memset(pRpcMessage, 0, sizeof(RPC_MESSAGE));
175 /* not everyone allocates stack space for w2kReserved */
176 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
178 pStubMsg->ReuseBuffer = FALSE;
179 pStubMsg->IsClient = TRUE;
180 pStubMsg->StubDesc = pStubDesc;
181 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
182 pStubMsg->pfnFree = pStubDesc->pfnFree;
183 pStubMsg->RpcMsg = pRpcMessage;
185 pRpcMessage->ProcNum = ProcNum;
186 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
189 /***********************************************************************
190 * NdrServerInitializeNew [RPCRT4.@]
192 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
193 PMIDL_STUB_DESC pStubDesc )
195 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
197 assert( pRpcMsg && pStubMsg && pStubDesc );
199 /* not everyone allocates stack space for w2kReserved */
200 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
202 pStubMsg->ReuseBuffer = TRUE;
203 pStubMsg->IsClient = FALSE;
204 pStubMsg->StubDesc = pStubDesc;
205 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
206 pStubMsg->pfnFree = pStubDesc->pfnFree;
207 pStubMsg->RpcMsg = pRpcMsg;
208 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
209 pStubMsg->BufferLength = pRpcMsg->BufferLength;
210 pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
212 /* FIXME: determine the proper return value */
216 /***********************************************************************
217 * NdrGetBuffer [RPCRT4.@]
219 unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
221 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
223 assert( stubmsg && stubmsg->RpcMsg );
225 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
226 stubmsg->RpcMsg->Handle = handle;
228 stubmsg->RpcMsg->BufferLength = buflen;
229 if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
232 stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
233 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
234 stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
235 return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
237 /***********************************************************************
238 * NdrFreeBuffer [RPCRT4.@]
240 void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
242 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
243 I_RpcFreeBuffer(pStubMsg->RpcMsg);
244 pStubMsg->BufferLength = 0;
245 pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
248 /************************************************************************
249 * NdrSendReceive [RPCRT4.@]
251 unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer )
253 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
255 /* FIXME: how to handle errors? (raise exception?) */
257 ERR("NULL stub message. No action taken.\n");
260 if (!stubmsg->RpcMsg) {
261 ERR("RPC Message not present in stub message. No action taken.\n");
264 if (stubmsg->RpcMsg->Buffer != buffer) {
265 ERR("Ambiguous buffer doesn't match rpc message buffer. No action taken.\n");
269 /* not sure where MS does this; for now I'll stick it here */
270 stubmsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
272 if (I_RpcSendReceive(stubmsg->RpcMsg) != RPC_S_OK) {
273 WARN("I_RpcSendReceive did not return success.\n");
276 /* FIXME: is this the right return value? */