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
41 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
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
);
103 pStubMsg
->dwStubPhase
= PROXY_SENDRECEIVE
;
104 hr
= IRpcChannelBuffer_SendReceive(pStubMsg
->pRpcChannelBuffer
,
105 (RPCOLEMESSAGE
*)pStubMsg
->RpcMsg
,
107 pStubMsg
->dwStubPhase
= PROXY_UNMARSHAL
;
108 pStubMsg
->BufferLength
= pStubMsg
->RpcMsg
->BufferLength
;
109 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
110 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
111 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
113 /* raise exception if call failed */
114 if (hr
== RPC_S_CALL_FAILED
) RpcRaiseException(*(DWORD
*)pStubMsg
->Buffer
);
115 else if (FAILED(hr
)) RpcRaiseException(hr
);
118 /***********************************************************************
119 * NdrProxyFreeBuffer [RPCRT4.@]
121 void WINAPI
NdrProxyFreeBuffer(void *This
,
122 PMIDL_STUB_MESSAGE pStubMsg
)
126 TRACE("(%p,%p)\n", This
, pStubMsg
);
127 hr
= IRpcChannelBuffer_FreeBuffer(pStubMsg
->pRpcChannelBuffer
,
128 (RPCOLEMESSAGE
*)pStubMsg
->RpcMsg
);
131 /***********************************************************************
132 * NdrProxyErrorHandler [RPCRT4.@]
134 HRESULT WINAPI
NdrProxyErrorHandler(DWORD dwExceptionCode
)
136 FIXME("(0x%08lx): semi-stub\n", dwExceptionCode
);
137 return MAKE_HRESULT(SEVERITY_ERROR
, FACILITY_RPC
, RPC_S_CALL_FAILED
);
140 /***********************************************************************
141 * NdrStubInitialize [RPCRT4.@]
143 void WINAPI
NdrStubInitialize(PRPC_MESSAGE pRpcMsg
,
144 PMIDL_STUB_MESSAGE pStubMsg
,
145 PMIDL_STUB_DESC pStubDescriptor
,
146 LPRPCCHANNELBUFFER pRpcChannelBuffer
)
148 TRACE("(%p,%p,%p,%p)\n", pRpcMsg
, pStubMsg
, pStubDescriptor
, pRpcChannelBuffer
);
149 NdrServerInitializeNew(pRpcMsg
, pStubMsg
, pStubDescriptor
);
150 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
153 /***********************************************************************
154 * NdrStubGetBuffer [RPCRT4.@]
156 void WINAPI
NdrStubGetBuffer(LPRPCSTUBBUFFER This
,
157 LPRPCCHANNELBUFFER pRpcChannelBuffer
,
158 PMIDL_STUB_MESSAGE pStubMsg
)
160 TRACE("(%p,%p)\n", This
, pStubMsg
);
161 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
162 pStubMsg
->RpcMsg
->BufferLength
= pStubMsg
->BufferLength
;
163 I_RpcGetBuffer(pStubMsg
->RpcMsg
); /* ? */
164 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
165 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
166 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
169 /************************************************************************
170 * NdrClientInitializeNew [RPCRT4.@]
172 void WINAPI
NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage
, PMIDL_STUB_MESSAGE pStubMsg
,
173 PMIDL_STUB_DESC pStubDesc
, unsigned int ProcNum
)
175 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
176 pRpcMessage
, pStubMsg
, pStubDesc
, ProcNum
);
178 assert( pRpcMessage
&& pStubMsg
&& pStubDesc
);
180 memset(pRpcMessage
, 0, sizeof(RPC_MESSAGE
));
182 /* not everyone allocates stack space for w2kReserved */
183 memset(pStubMsg
, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE
,pCSInfo
));
185 pStubMsg
->ReuseBuffer
= FALSE
;
186 pStubMsg
->IsClient
= TRUE
;
187 pStubMsg
->StubDesc
= pStubDesc
;
188 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
189 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
190 pStubMsg
->RpcMsg
= pRpcMessage
;
192 pRpcMessage
->ProcNum
= ProcNum
;
193 pRpcMessage
->RpcInterfaceInformation
= pStubDesc
->RpcInterfaceInformation
;
196 /***********************************************************************
197 * NdrServerInitializeNew [RPCRT4.@]
199 unsigned char* WINAPI
NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg
, PMIDL_STUB_MESSAGE pStubMsg
,
200 PMIDL_STUB_DESC pStubDesc
)
202 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg
, pStubMsg
, pStubDesc
);
204 assert( pRpcMsg
&& pStubMsg
&& pStubDesc
);
206 /* not everyone allocates stack space for w2kReserved */
207 memset(pStubMsg
, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE
,pCSInfo
));
209 pStubMsg
->ReuseBuffer
= TRUE
;
210 pStubMsg
->IsClient
= FALSE
;
211 pStubMsg
->StubDesc
= pStubDesc
;
212 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
213 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
214 pStubMsg
->RpcMsg
= pRpcMsg
;
215 pStubMsg
->Buffer
= pStubMsg
->BufferStart
= pRpcMsg
->Buffer
;
216 pStubMsg
->BufferLength
= pRpcMsg
->BufferLength
;
217 pStubMsg
->BufferEnd
= pStubMsg
->Buffer
+ pStubMsg
->BufferLength
;
219 /* FIXME: determine the proper return value */
223 /***********************************************************************
224 * NdrGetBuffer [RPCRT4.@]
226 unsigned char *WINAPI
NdrGetBuffer(MIDL_STUB_MESSAGE
*stubmsg
, unsigned long buflen
, RPC_BINDING_HANDLE handle
)
228 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg
, buflen
, handle
);
230 assert( stubmsg
&& stubmsg
->RpcMsg
);
232 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
233 stubmsg
->RpcMsg
->Handle
= handle
;
235 stubmsg
->RpcMsg
->BufferLength
= buflen
;
236 if (I_RpcGetBuffer(stubmsg
->RpcMsg
) != S_OK
)
239 stubmsg
->Buffer
= stubmsg
->BufferStart
= stubmsg
->RpcMsg
->Buffer
;
240 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
241 stubmsg
->BufferEnd
= stubmsg
->Buffer
+ stubmsg
->BufferLength
;
242 return (stubmsg
->Buffer
= (unsigned char *)stubmsg
->RpcMsg
->Buffer
);
244 /***********************************************************************
245 * NdrFreeBuffer [RPCRT4.@]
247 void WINAPI
NdrFreeBuffer(MIDL_STUB_MESSAGE
*pStubMsg
)
249 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg
);
250 I_RpcFreeBuffer(pStubMsg
->RpcMsg
);
251 pStubMsg
->BufferLength
= 0;
252 pStubMsg
->Buffer
= pStubMsg
->BufferEnd
= (unsigned char *)(pStubMsg
->RpcMsg
->Buffer
= NULL
);
255 /************************************************************************
256 * NdrSendReceive [RPCRT4.@]
258 unsigned char *WINAPI
NdrSendReceive( MIDL_STUB_MESSAGE
*stubmsg
, unsigned char *buffer
)
260 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg
, buffer
);
262 /* FIXME: how to handle errors? (raise exception?) */
264 ERR("NULL stub message. No action taken.\n");
267 if (!stubmsg
->RpcMsg
) {
268 ERR("RPC Message not present in stub message. No action taken.\n");
272 /* FIXME: Seems wrong. Where should this really come from, and when? */
273 stubmsg
->RpcMsg
->DataRepresentation
= NDR_LOCAL_DATA_REPRESENTATION
;
275 if (I_RpcSendReceive(stubmsg
->RpcMsg
) != RPC_S_OK
) {
276 WARN("I_RpcSendReceive did not return success.\n");
277 /* FIXME: raise exception? */
280 /* FIXME: is this the right return value? */