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 * NdrStubInitialize [RPCRT4.@]
127 void WINAPI
NdrStubInitialize(PRPC_MESSAGE pRpcMsg
,
128 PMIDL_STUB_MESSAGE pStubMsg
,
129 PMIDL_STUB_DESC pStubDescriptor
,
130 LPRPCCHANNELBUFFER pRpcChannelBuffer
)
132 TRACE("(%p,%p,%p,%p)\n", pRpcMsg
, pStubMsg
, pStubDescriptor
, pRpcChannelBuffer
);
133 NdrServerInitializeNew(pRpcMsg
, pStubMsg
, pStubDescriptor
);
134 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
137 /***********************************************************************
138 * NdrStubGetBuffer [RPCRT4.@]
140 void WINAPI
NdrStubGetBuffer(LPRPCSTUBBUFFER This
,
141 LPRPCCHANNELBUFFER pRpcChannelBuffer
,
142 PMIDL_STUB_MESSAGE pStubMsg
)
144 TRACE("(%p,%p)\n", This
, pStubMsg
);
145 pStubMsg
->pRpcChannelBuffer
= pRpcChannelBuffer
;
146 pStubMsg
->RpcMsg
->BufferLength
= pStubMsg
->BufferLength
;
147 I_RpcGetBuffer(pStubMsg
->RpcMsg
); /* ? */
148 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
149 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
150 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
153 /************************************************************************
154 * NdrClientInitializeNew [RPCRT4.@]
156 void WINAPI
NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage
, PMIDL_STUB_MESSAGE pStubMsg
,
157 PMIDL_STUB_DESC pStubDesc
, unsigned int ProcNum
)
159 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
160 pRpcMessage
, pStubMsg
, pStubDesc
, ProcNum
);
162 assert( pRpcMessage
&& pStubMsg
&& pStubDesc
);
164 memset(pRpcMessage
, 0, sizeof(RPC_MESSAGE
));
165 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
167 pStubMsg
->ReuseBuffer
= FALSE
;
168 pStubMsg
->IsClient
= TRUE
;
169 pStubMsg
->StubDesc
= pStubDesc
;
170 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
171 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
172 pStubMsg
->RpcMsg
= pRpcMessage
;
174 pRpcMessage
->ProcNum
= ProcNum
;
175 pRpcMessage
->RpcInterfaceInformation
= pStubDesc
->RpcInterfaceInformation
;
178 /***********************************************************************
179 * NdrServerInitializeNew [RPCRT4.@]
181 unsigned char* WINAPI
NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg
, PMIDL_STUB_MESSAGE pStubMsg
,
182 PMIDL_STUB_DESC pStubDesc
)
184 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg
, pStubMsg
, pStubDesc
);
186 assert( pRpcMsg
&& pStubMsg
&& pStubDesc
);
188 memset(pStubMsg
, 0, sizeof(MIDL_STUB_MESSAGE
));
190 pStubMsg
->ReuseBuffer
= TRUE
;
191 pStubMsg
->IsClient
= FALSE
;
192 pStubMsg
->StubDesc
= pStubDesc
;
193 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
194 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
195 pStubMsg
->RpcMsg
= pRpcMsg
;
196 pStubMsg
->Buffer
= pStubMsg
->BufferStart
= pRpcMsg
->Buffer
;
197 pStubMsg
->BufferLength
= pRpcMsg
->BufferLength
;
198 pStubMsg
->BufferEnd
= pStubMsg
->Buffer
+ pStubMsg
->BufferLength
;
200 /* FIXME: determine the proper return value */
204 /***********************************************************************
205 * NdrGetBuffer [RPCRT4.@]
207 unsigned char *WINAPI
NdrGetBuffer(MIDL_STUB_MESSAGE
*stubmsg
, unsigned long buflen
, RPC_BINDING_HANDLE handle
)
209 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg
, buflen
, handle
);
211 assert( stubmsg
&& stubmsg
->RpcMsg
);
213 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
214 stubmsg
->RpcMsg
->Handle
= handle
;
216 stubmsg
->RpcMsg
->BufferLength
= buflen
;
217 if (I_RpcGetBuffer(stubmsg
->RpcMsg
) != S_OK
)
220 stubmsg
->Buffer
= stubmsg
->BufferStart
= stubmsg
->RpcMsg
->Buffer
;
221 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
222 stubmsg
->BufferEnd
= stubmsg
->Buffer
+ stubmsg
->BufferLength
;
223 return (stubmsg
->Buffer
= (unsigned char *)stubmsg
->RpcMsg
->Buffer
);
225 /***********************************************************************
226 * NdrFreeBuffer [RPCRT4.@]
228 void WINAPI
NdrFreeBuffer(MIDL_STUB_MESSAGE
*pStubMsg
)
230 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg
);
231 I_RpcFreeBuffer(pStubMsg
->RpcMsg
);
232 pStubMsg
->BufferLength
= 0;
233 pStubMsg
->Buffer
= pStubMsg
->BufferEnd
= (unsigned char *)(pStubMsg
->RpcMsg
->Buffer
= NULL
);
236 /************************************************************************
237 * NdrSendReceive [RPCRT4.@]
239 unsigned char *WINAPI
NdrSendReceive( MIDL_STUB_MESSAGE
*stubmsg
, unsigned char *buffer
)
241 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg
, buffer
);
243 /* FIXME: how to handle errors? (raise exception?) */
245 ERR("NULL stub message. No action taken.\n");
248 if (!stubmsg
->RpcMsg
) {
249 ERR("RPC Message not present in stub message. No action taken.\n");
252 if (stubmsg
->RpcMsg
->Buffer
!= buffer
) {
253 ERR("Ambiguous buffer doesn't match rpc message buffer. No action taken.\n");
257 /* not sure where MS does this; for now I'll stick it here */
258 stubmsg
->RpcMsg
->DataRepresentation
= NDR_LOCAL_DATA_REPRESENTATION
;
260 if (I_RpcSendReceive(stubmsg
->RpcMsg
) != RPC_S_OK
) {
261 WARN("I_RpcSendReceive did not return success.\n");
264 /* FIXME: is this the right return value? */