rpcrt4: Fix the MIDL_STUB_MESSAGE fields set by NdrServerInitializeNew.
[wine/wine64.git] / dlls / rpcrt4 / ndr_clientserver.c
bloba43b92058a689d37009ead2596cd346116bbe035
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
30 #define COBJMACROS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
36 #include "objbase.h"
38 #include "rpcproxy.h"
40 #include "wine/debug.h"
42 #include "ndr_misc.h"
43 #include "rpcndr.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
47 /************************************************************************
48 * NdrClientInitializeNew [RPCRT4.@]
50 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
51 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
53 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
54 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
56 assert( pRpcMessage && pStubMsg && pStubDesc );
58 pRpcMessage->Handle = NULL;
59 pRpcMessage->ProcNum = ProcNum;
60 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
61 pRpcMessage->RpcFlags = 0;
62 pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
64 pStubMsg->RpcMsg = pRpcMessage;
65 pStubMsg->BufferStart = NULL;
66 pStubMsg->BufferEnd = NULL;
67 pStubMsg->BufferLength = 0;
68 pStubMsg->IsClient = TRUE;
69 pStubMsg->ReuseBuffer = FALSE;
70 pStubMsg->pAllocAllNodesContext = NULL;
71 pStubMsg->pPointerQueueState = NULL;
72 pStubMsg->IgnoreEmbeddedPointers = 0;
73 pStubMsg->PointerBufferMark = NULL;
74 pStubMsg->fBufferValid = 0;
75 pStubMsg->uFlags = 0;
76 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
77 pStubMsg->pfnFree = pStubDesc->pfnFree;
78 pStubMsg->StackTop = NULL;
79 pStubMsg->StubDesc = pStubDesc;
80 pStubMsg->FullPtrRefId = 0;
81 pStubMsg->PointerLength = 0;
82 pStubMsg->fInDontFree = 0;
83 pStubMsg->fDontCallFreeInst = 0;
84 pStubMsg->fInOnlyParam = 0;
85 pStubMsg->fHasReturn = 0;
86 pStubMsg->fHasExtensions = 0;
87 pStubMsg->fHasNewCorrDesc = 0;
88 pStubMsg->fUnused = 0;
89 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
90 pStubMsg->pvDestContext = NULL;
91 pStubMsg->pRpcChannelBuffer = NULL;
92 pStubMsg->pArrayInfo = NULL;
93 pStubMsg->dwStubPhase = 0;
94 /* FIXME: LowStackMark */
95 pStubMsg->pAsyncMsg = NULL;
96 pStubMsg->pCorrInfo = NULL;
97 pStubMsg->pCorrMemory = NULL;
98 pStubMsg->pMemoryList = NULL;
101 /***********************************************************************
102 * NdrServerInitializeNew [RPCRT4.@]
104 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
105 PMIDL_STUB_DESC pStubDesc )
107 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
109 pStubMsg->RpcMsg = pRpcMsg;
110 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
111 pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
112 pStubMsg->BufferLength = pRpcMsg->BufferLength;
113 pStubMsg->IsClient = FALSE;
114 pStubMsg->ReuseBuffer = FALSE;
115 pStubMsg->pAllocAllNodesContext = NULL;
116 pStubMsg->pPointerQueueState = NULL;
117 pStubMsg->IgnoreEmbeddedPointers = 0;
118 pStubMsg->PointerBufferMark = NULL;
119 pStubMsg->uFlags = 0;
120 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
121 pStubMsg->pfnFree = pStubDesc->pfnFree;
122 pStubMsg->StackTop = NULL;
123 pStubMsg->StubDesc = pStubDesc;
124 pStubMsg->FullPtrXlatTables = NULL;
125 pStubMsg->FullPtrRefId = 0;
126 pStubMsg->PointerLength = 0;
127 pStubMsg->fInDontFree = 0;
128 pStubMsg->fDontCallFreeInst = 0;
129 pStubMsg->fInOnlyParam = 0;
130 pStubMsg->fHasReturn = 0;
131 pStubMsg->fHasExtensions = 0;
132 pStubMsg->fHasNewCorrDesc = 0;
133 pStubMsg->fUnused = 0;
134 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
135 pStubMsg->pvDestContext = NULL;
136 pStubMsg->pRpcChannelBuffer = NULL;
137 pStubMsg->pArrayInfo = NULL;
138 pStubMsg->dwStubPhase = 0;
139 /* FIXME: LowStackMark */
140 pStubMsg->pAsyncMsg = NULL;
141 pStubMsg->pCorrInfo = NULL;
142 pStubMsg->pCorrMemory = NULL;
143 pStubMsg->pMemoryList = NULL;
145 return NULL;
148 /***********************************************************************
149 * NdrGetBuffer [RPCRT4.@]
151 unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
153 TRACE("(stubmsg == ^%p, buflen == %u, handle == %p): wild guess.\n", stubmsg, buflen, handle);
155 assert( stubmsg && stubmsg->RpcMsg );
157 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
158 stubmsg->RpcMsg->Handle = handle;
160 stubmsg->RpcMsg->BufferLength = buflen;
161 if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
162 return NULL;
164 stubmsg->Buffer = stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
165 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
166 stubmsg->BufferEnd = stubmsg->Buffer + stubmsg->BufferLength;
167 return (stubmsg->Buffer = (unsigned char *)stubmsg->RpcMsg->Buffer);
169 /***********************************************************************
170 * NdrFreeBuffer [RPCRT4.@]
172 void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
174 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg);
175 I_RpcFreeBuffer(pStubMsg->RpcMsg);
176 pStubMsg->BufferLength = 0;
177 pStubMsg->Buffer = pStubMsg->BufferEnd = (unsigned char *)(pStubMsg->RpcMsg->Buffer = NULL);
180 /************************************************************************
181 * NdrSendReceive [RPCRT4.@]
183 unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer )
185 RPC_STATUS status;
187 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
189 /* FIXME: how to handle errors? (raise exception?) */
190 if (!stubmsg) {
191 ERR("NULL stub message. No action taken.\n");
192 return NULL;
194 if (!stubmsg->RpcMsg) {
195 ERR("RPC Message not present in stub message. No action taken.\n");
196 return NULL;
199 stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
200 status = I_RpcSendReceive(stubmsg->RpcMsg);
201 if (status != RPC_S_OK)
202 RpcRaiseException(status);
204 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
205 stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
206 stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
207 stubmsg->Buffer = stubmsg->BufferStart;
209 /* FIXME: is this the right return value? */
210 return NULL;
213 /************************************************************************
214 * NdrMapCommAndFaultStatus [RPCRT4.@]
216 RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
217 ULONG *pCommStatus,
218 ULONG *pFaultStatus,
219 RPC_STATUS Status )
221 FIXME("(%p, %p, %p, %ld): stub\n", pStubMsg, pCommStatus, pFaultStatus, Status);
223 *pCommStatus = 0;
224 *pFaultStatus = 0;
226 return RPC_S_OK;