Implemented localeconv() with libc function.
[wine.git] / dlls / rpcrt4 / ndr_midl.c
blob09b236f265c6e73ad8122642fda7bd8bec292263
1 /*
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
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
25 #include <stdio.h>
26 #include <string.h>
27 #include <assert.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winreg.h"
34 #include "objbase.h"
36 #include "rpcproxy.h"
38 #include "wine/debug.h"
40 #include "cpsf.h"
41 #include "ndr_misc.h"
42 #include "rpcndr.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
46 /***********************************************************************
47 * NdrProxyInitialize [RPCRT4.@]
49 void WINAPI NdrProxyInitialize(void *This,
50 PRPC_MESSAGE pRpcMsg,
51 PMIDL_STUB_MESSAGE pStubMsg,
52 PMIDL_STUB_DESC pStubDescriptor,
53 unsigned int ProcNum)
55 HRESULT hr;
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)
74 HRESULT hr;
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,
83 riid);
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)
96 ULONG Status = 0;
97 HRESULT hr;
99 TRACE("(%p,%p)\n", This, pStubMsg);
100 pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
101 hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
102 (RPCOLEMESSAGE*)pStubMsg->RpcMsg,
103 &Status);
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;
110 /* raise exception if call failed */
111 if (hr == RPC_S_CALL_FAILED) RpcRaiseException(*(DWORD*)pStubMsg->Buffer);
112 else if (FAILED(hr)) RpcRaiseException(hr);
115 /***********************************************************************
116 * NdrProxyFreeBuffer [RPCRT4.@]
118 void WINAPI NdrProxyFreeBuffer(void *This,
119 PMIDL_STUB_MESSAGE pStubMsg)
121 HRESULT hr;
123 TRACE("(%p,%p)\n", This, pStubMsg);
124 hr = IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
125 (RPCOLEMESSAGE*)pStubMsg->RpcMsg);
128 /***********************************************************************
129 * NdrProxyErrorHandler [RPCRT4.@]
131 HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
133 FIXME("(0x%08lx): semi-stub\n", dwExceptionCode);
134 return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_RPC, RPC_S_CALL_FAILED);
137 /***********************************************************************
138 * NdrStubInitialize [RPCRT4.@]
140 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
141 PMIDL_STUB_MESSAGE pStubMsg,
142 PMIDL_STUB_DESC pStubDescriptor,
143 LPRPCCHANNELBUFFER pRpcChannelBuffer)
145 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
146 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
147 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
150 /***********************************************************************
151 * NdrStubGetBuffer [RPCRT4.@]
153 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER This,
154 LPRPCCHANNELBUFFER pRpcChannelBuffer,
155 PMIDL_STUB_MESSAGE pStubMsg)
157 TRACE("(%p,%p)\n", This, pStubMsg);
158 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
159 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
160 I_RpcGetBuffer(pStubMsg->RpcMsg); /* ? */
161 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
162 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
163 pStubMsg->Buffer = pStubMsg->BufferStart;
166 /************************************************************************
167 * NdrClientInitializeNew [RPCRT4.@]
169 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
170 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
172 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
173 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
175 assert( pRpcMessage && pStubMsg && pStubDesc );
177 memset(pRpcMessage, 0, sizeof(RPC_MESSAGE));
179 /* not everyone allocates stack space for w2kReserved */
180 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
182 pStubMsg->ReuseBuffer = FALSE;
183 pStubMsg->IsClient = TRUE;
184 pStubMsg->StubDesc = pStubDesc;
185 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
186 pStubMsg->pfnFree = pStubDesc->pfnFree;
187 pStubMsg->RpcMsg = pRpcMessage;
189 pRpcMessage->ProcNum = ProcNum;
190 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
193 /***********************************************************************
194 * NdrServerInitializeNew [RPCRT4.@]
196 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
197 PMIDL_STUB_DESC pStubDesc )
199 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
201 assert( pRpcMsg && pStubMsg && pStubDesc );
203 /* not everyone allocates stack space for w2kReserved */
204 memset(pStubMsg, 0, sizeof(*pStubMsg) - sizeof(pStubMsg->w2kReserved));
206 pStubMsg->ReuseBuffer = TRUE;
207 pStubMsg->IsClient = FALSE;
208 pStubMsg->StubDesc = pStubDesc;
209 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
210 pStubMsg->pfnFree = pStubDesc->pfnFree;
211 pStubMsg->RpcMsg = pRpcMsg;
212 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
213 pStubMsg->BufferLength = pRpcMsg->BufferLength;
214 pStubMsg->BufferEnd = pStubMsg->Buffer + pStubMsg->BufferLength;
216 /* FIXME: determine the proper return value */
217 return NULL;
220 /***********************************************************************
221 * NdrGetBuffer [RPCRT4.@]
223 unsigned char *WINAPI NdrGetBuffer(MIDL_STUB_MESSAGE *stubmsg, unsigned long buflen, RPC_BINDING_HANDLE handle)
225 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg, buflen, handle);
227 assert( stubmsg && stubmsg->RpcMsg );
229 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
230 stubmsg->RpcMsg->Handle = handle;
232 stubmsg->RpcMsg->BufferLength = buflen;
233 if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
234 return NULL;
236 stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
237 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
238 stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
239 return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
241 /***********************************************************************
242 * NdrFreeBuffer [RPCRT4.@]
244 void WINAPI NdrFreeBuffer(MIDL_STUB_MESSAGE *pStubMsg)
246 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
247 I_RpcFreeBuffer(pStubMsg->RpcMsg);
248 pStubMsg->BufferLength = 0;
249 pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
252 /************************************************************************
253 * NdrSendReceive [RPCRT4.@]
255 unsigned char *WINAPI NdrSendReceive( MIDL_STUB_MESSAGE *stubmsg, unsigned char *buffer )
257 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
259 /* FIXME: how to handle errors? (raise exception?) */
260 if (!stubmsg) {
261 ERR("NULL stub message. No action taken.\n");
262 return NULL;
264 if (!stubmsg->RpcMsg) {
265 ERR("RPC Message not present in stub message. No action taken.\n");
266 return NULL;
268 if (stubmsg->RpcMsg->Buffer != buffer) {
269 ERR("Ambiguous buffer doesn't match rpc message buffer. No action taken.\n");
270 return NULL;
273 /* not sure where MS does this; for now I'll stick it here */
274 stubmsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
276 if (I_RpcSendReceive(stubmsg->RpcMsg) != RPC_S_OK) {
277 WARN("I_RpcSendReceive did not return success.\n");
280 /* FIXME: is this the right return value? */
281 return NULL;