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 memset(pRpcMsg
, 0, sizeof(RPC_MESSAGE
));
59 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
60 pRpcMsg
->ProcNum
= ProcNum
;
61 pRpcMsg
->RpcInterfaceInformation
= pStubDescriptor
->RpcInterfaceInformation
;
62 pStubMsg
->RpcMsg
= pRpcMsg
;
63 pStubMsg
->IsClient
= 1;
64 pStubMsg
->ReuseBuffer
= 1;
65 pStubMsg
->pfnAllocate
= pStubDescriptor
->pfnAllocate
;
66 pStubMsg
->pfnFree
= pStubDescriptor
->pfnFree
;
67 pStubMsg
->StubDesc
= pStubDescriptor
;
68 if (This
) StdProxy_GetChannel(This
, &pStubMsg
->pRpcChannelBuffer
);
69 if (pStubMsg
->pRpcChannelBuffer
) {
70 hr
= IRpcChannelBuffer_GetDestCtx(pStubMsg
->pRpcChannelBuffer
,
71 &pStubMsg
->dwDestContext
,
72 &pStubMsg
->pvDestContext
);
74 TRACE("channel=%p\n", pStubMsg
->pRpcChannelBuffer
);
77 /***********************************************************************
78 * NdrProxyGetBuffer [RPCRT4.@]
80 void WINAPI
NdrProxyGetBuffer(void *This
,
81 PMIDL_STUB_MESSAGE pStubMsg
)
84 const IID
*riid
= NULL
;
86 TRACE("(%p,%p)\n", This
, pStubMsg
);
87 pStubMsg
->RpcMsg
->BufferLength
= pStubMsg
->BufferLength
;
88 pStubMsg
->dwStubPhase
= PROXY_GETBUFFER
;
89 hr
= StdProxy_GetIID(This
, &riid
);
90 hr
= IRpcChannelBuffer_GetBuffer(pStubMsg
->pRpcChannelBuffer
,
91 (RPCOLEMESSAGE
*)pStubMsg
->RpcMsg
,
93 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
94 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
95 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
96 pStubMsg
->dwStubPhase
= PROXY_MARSHAL
;
99 /***********************************************************************
100 * NdrProxySendReceive [RPCRT4.@]
102 void WINAPI
NdrProxySendReceive(void *This
,
103 PMIDL_STUB_MESSAGE pStubMsg
)
108 TRACE("(%p,%p)\n", This
, pStubMsg
);
109 pStubMsg
->dwStubPhase
= PROXY_SENDRECEIVE
;
110 hr
= IRpcChannelBuffer_SendReceive(pStubMsg
->pRpcChannelBuffer
,
111 (RPCOLEMESSAGE
*)pStubMsg
->RpcMsg
,
113 pStubMsg
->dwStubPhase
= PROXY_UNMARSHAL
;
114 pStubMsg
->BufferLength
= pStubMsg
->RpcMsg
->BufferLength
;
115 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
116 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
117 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
120 /***********************************************************************
121 * NdrProxyFreeBuffer [RPCRT4.@]
123 void WINAPI
NdrProxyFreeBuffer(void *This
,
124 PMIDL_STUB_MESSAGE pStubMsg
)
128 TRACE("(%p,%p)\n", This
, pStubMsg
);
129 hr
= IRpcChannelBuffer_FreeBuffer(pStubMsg
->pRpcChannelBuffer
,
130 (RPCOLEMESSAGE
*)pStubMsg
->RpcMsg
);
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 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
143 pStubMsg
->RpcMsg
= pRpcMsg
;
144 pStubMsg
->IsClient
= 0;
145 pStubMsg
->ReuseBuffer
= 1;
146 pStubMsg
->pfnAllocate
= pStubDescriptor
->pfnAllocate
;
147 pStubMsg
->pfnFree
= pStubDescriptor
->pfnFree
;
148 pStubMsg
->StubDesc
= pStubDescriptor
;
149 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
150 pStubMsg
->BufferLength
= pStubMsg
->RpcMsg
->BufferLength
;
151 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
152 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
153 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
156 /***********************************************************************
157 * NdrStubGetBuffer [RPCRT4.@]
159 void WINAPI
NdrStubGetBuffer(LPRPCSTUBBUFFER This
,
160 LPRPCCHANNELBUFFER pRpcChannelBuffer
,
161 PMIDL_STUB_MESSAGE pStubMsg
)
163 TRACE("(%p,%p)\n", This
, pStubMsg
);
164 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
165 pStubMsg
->RpcMsg
->BufferLength
= pStubMsg
->BufferLength
;
166 I_RpcGetBuffer(pStubMsg
->RpcMsg
); /* ? */
167 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
168 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
169 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
172 /************************************************************************
173 * NdrClientInitializeNew [RPCRT4.@]
175 void WINAPI
NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage
, PMIDL_STUB_MESSAGE pStubMsg
,
176 PMIDL_STUB_DESC pStubDesc
, unsigned int ProcNum
)
178 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
179 pRpcMessage
, pStubMsg
, pStubDesc
, ProcNum
);
181 assert( pRpcMessage
&& pStubMsg
&& pStubDesc
);
183 memset(pRpcMessage
, 0, sizeof(RPC_MESSAGE
));
184 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
186 pStubMsg
->ReuseBuffer
= TRUE
;
187 pStubMsg
->IsClient
= TRUE
;
188 pStubMsg
->StubDesc
= pStubDesc
;
189 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
190 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
191 pStubMsg
->RpcMsg
= pRpcMessage
;
193 pRpcMessage
->ProcNum
= ProcNum
;
194 pRpcMessage
->RpcInterfaceInformation
= pStubDesc
->RpcInterfaceInformation
;
197 /***********************************************************************
198 * NdrServerInitializeNew [RPCRT4.@]
200 unsigned char* WINAPI
NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg
, PMIDL_STUB_MESSAGE pStubMsg
,
201 PMIDL_STUB_DESC pStubDesc
)
203 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg
, pStubMsg
, pStubDesc
);
205 assert( pRpcMsg
&& pStubMsg
&& pStubDesc
);
207 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
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
= pRpcMsg
->Buffer
;
216 pStubMsg
->BufferLength
= pRpcMsg
->BufferLength
;
218 /* FIXME: determine the proper return value */
222 /***********************************************************************
223 * NdrGetBuffer [RPCRT4.@]
225 unsigned char *WINAPI
NdrGetBuffer(MIDL_STUB_MESSAGE
*stubmsg
, unsigned long buflen
, RPC_BINDING_HANDLE handle
)
227 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg
, buflen
, handle
);
229 assert( stubmsg
&& stubmsg
->RpcMsg
);
231 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
232 stubmsg
->RpcMsg
->Handle
= handle
;
234 stubmsg
->RpcMsg
->BufferLength
= buflen
;
235 if (I_RpcGetBuffer(stubmsg
->RpcMsg
) != S_OK
)
238 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
239 stubmsg
->BufferEnd
= stubmsg
->BufferStart
= 0;
240 return (stubmsg
->Buffer
= (unsigned char *)stubmsg
->RpcMsg
->Buffer
);
242 /***********************************************************************
243 * NdrFreeBuffer [RPCRT4.@]
245 void WINAPI
NdrFreeBuffer(MIDL_STUB_MESSAGE
*pStubMsg
)
247 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg
);
248 I_RpcFreeBuffer(pStubMsg
->RpcMsg
);
249 pStubMsg
->BufferLength
= 0;
250 pStubMsg
->Buffer
= (unsigned char *)(pStubMsg
->RpcMsg
->Buffer
= NULL
);
253 /************************************************************************
254 * NdrSendReceive [RPCRT4.@]
256 unsigned char *WINAPI
NdrSendReceive( MIDL_STUB_MESSAGE
*stubmsg
, unsigned char *buffer
)
258 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg
, buffer
);
260 /* FIXME: how to handle errors? (raise exception?) */
262 ERR("NULL stub message. No action taken.\n");
265 if (!stubmsg
->RpcMsg
) {
266 ERR("RPC Message not present in stub message. No action taken.\n");
269 if (stubmsg
->RpcMsg
->Buffer
!= buffer
) {
270 ERR("Ambiguous buffer doesn't match rpc message buffer. No action taken.\n");
274 /* not sure where MS does this; for now I'll stick it here */
275 stubmsg
->RpcMsg
->DataRepresentation
= NDR_LOCAL_DATA_REPRESENTATION
;
277 if (I_RpcSendReceive(stubmsg
->RpcMsg
) != RPC_S_OK
) {
278 WARN("I_RpcSendReceive did not return success.\n");
281 /* FIXME: is this the right return value? */