ReactOS 0.4.15-dev-7788-g1ad9096
ndr_clientserver.c
Go to the documentation of this file.
1/*
2 * MIDL proxy/stub stuff
3 *
4 * Copyright 2002 Ove Kåven, TransGaming Technologies
5 *
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.
10 *
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.
15 *
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
19 *
20 * TODO:
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
23 */
24
25#include <stdarg.h>
26
27#define COBJMACROS
28
29#include "windef.h"
30#include "winbase.h"
31#include "winerror.h"
32
33#include "objbase.h"
34
35#include "rpcproxy.h"
36
37#include "wine/debug.h"
38
39#include "ndr_misc.h"
40#include "rpcndr.h"
41
43
44/************************************************************************
45 * NdrClientInitializeNew [RPCRT4.@]
46 */
48 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
49{
50 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
51 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
52
53 pRpcMessage->Handle = NULL;
54 pRpcMessage->ProcNum = ProcNum | RPC_FLAGS_VALID_BIT;
55 pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
56 pRpcMessage->RpcFlags = 0;
57 pRpcMessage->ReservedForRuntime = NULL;
59
60 pStubMsg->RpcMsg = pRpcMessage;
61 pStubMsg->BufferStart = NULL;
62 pStubMsg->BufferEnd = NULL;
63 pStubMsg->BufferLength = 0;
64 pStubMsg->IsClient = TRUE;
65 pStubMsg->ReuseBuffer = FALSE;
66 pStubMsg->pAllocAllNodesContext = NULL;
67 pStubMsg->pPointerQueueState = NULL;
68 pStubMsg->IgnoreEmbeddedPointers = 0;
69 pStubMsg->PointerBufferMark = NULL;
70 pStubMsg->CorrDespIncrement = 0;
71 pStubMsg->uFlags = 0;
72 pStubMsg->UniquePtrCount = 0;
73 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
74 pStubMsg->pfnFree = pStubDesc->pfnFree;
75 pStubMsg->StackTop = NULL;
76 pStubMsg->StubDesc = pStubDesc;
77 pStubMsg->FullPtrRefId = 0;
78 pStubMsg->PointerLength = 0;
79 pStubMsg->fInDontFree = 0;
80 pStubMsg->fDontCallFreeInst = 0;
81 pStubMsg->fInOnlyParam = 0;
82 pStubMsg->fHasReturn = 0;
83 pStubMsg->fHasExtensions = 0;
84 pStubMsg->fHasNewCorrDesc = 0;
85 pStubMsg->fIsIn = 0;
86 pStubMsg->fIsOut = 0;
87 pStubMsg->fIsOicf = 0;
88 pStubMsg->fBufferValid = 0;
89 pStubMsg->fHasMemoryValidateCallback = 0;
90 pStubMsg->fInFree = 0;
91 pStubMsg->fNeedMCCP = 0;
92 pStubMsg->fUnused = 0;
93 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
94 pStubMsg->pvDestContext = NULL;
95 pStubMsg->pRpcChannelBuffer = NULL;
96 pStubMsg->pArrayInfo = NULL;
97 pStubMsg->dwStubPhase = 0;
98 /* FIXME: LowStackMark */
99 pStubMsg->pAsyncMsg = NULL;
100 pStubMsg->pCorrInfo = NULL;
101 pStubMsg->pCorrMemory = NULL;
102 pStubMsg->pMemoryList = NULL;
103}
104
105/***********************************************************************
106 * NdrServerInitializeNew [RPCRT4.@]
107 */
109 PMIDL_STUB_DESC pStubDesc )
110{
111 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
112
113 pStubMsg->RpcMsg = pRpcMsg;
114 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
115 pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
116 pStubMsg->BufferLength = pRpcMsg->BufferLength;
117 pStubMsg->IsClient = FALSE;
118 pStubMsg->ReuseBuffer = FALSE;
119 pStubMsg->pAllocAllNodesContext = NULL;
120 pStubMsg->pPointerQueueState = NULL;
121 pStubMsg->IgnoreEmbeddedPointers = 0;
122 pStubMsg->PointerBufferMark = NULL;
123 pStubMsg->CorrDespIncrement = 0;
124 pStubMsg->uFlags = 0;
125 pStubMsg->UniquePtrCount = 0;
126 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
127 pStubMsg->pfnFree = pStubDesc->pfnFree;
128 pStubMsg->StackTop = NULL;
129 pStubMsg->StubDesc = pStubDesc;
130 pStubMsg->FullPtrXlatTables = NULL;
131 pStubMsg->FullPtrRefId = 0;
132 pStubMsg->PointerLength = 0;
133 pStubMsg->fInDontFree = 0;
134 pStubMsg->fDontCallFreeInst = 0;
135 pStubMsg->fInOnlyParam = 0;
136 pStubMsg->fHasReturn = 0;
137 pStubMsg->fHasExtensions = 0;
138 pStubMsg->fHasNewCorrDesc = 0;
139 pStubMsg->fIsIn = 0;
140 pStubMsg->fIsOut = 0;
141 pStubMsg->fIsOicf = 0;
142 pStubMsg->fHasMemoryValidateCallback = 0;
143 pStubMsg->fInFree = 0;
144 pStubMsg->fNeedMCCP = 0;
145 pStubMsg->fUnused = 0;
146 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
147 pStubMsg->pvDestContext = NULL;
148 pStubMsg->pRpcChannelBuffer = NULL;
149 pStubMsg->pArrayInfo = NULL;
150 pStubMsg->dwStubPhase = 0;
151 /* FIXME: LowStackMark */
152 pStubMsg->pAsyncMsg = NULL;
153 pStubMsg->pCorrInfo = NULL;
154 pStubMsg->pCorrMemory = NULL;
155 pStubMsg->pMemoryList = NULL;
156
157 return NULL;
158}
159
160/***********************************************************************
161 * NdrGetBuffer [RPCRT4.@]
162 */
164{
166
167 TRACE("(stubmsg == ^%p, buflen == %u, handle == %p)\n", stubmsg, buflen, handle);
168
169 stubmsg->RpcMsg->Handle = handle;
170 stubmsg->RpcMsg->BufferLength = buflen;
171
172 status = I_RpcGetBuffer(stubmsg->RpcMsg);
173 if (status != RPC_S_OK)
175
176 stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
177 stubmsg->fBufferValid = TRUE;
178 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
179 return stubmsg->Buffer;
180}
181/***********************************************************************
182 * NdrFreeBuffer [RPCRT4.@]
183 */
185{
186 TRACE("(pStubMsg == ^%p)\n", pStubMsg);
187 if (pStubMsg->fBufferValid)
188 {
189 I_RpcFreeBuffer(pStubMsg->RpcMsg);
190 pStubMsg->fBufferValid = FALSE;
191 }
192}
193
194/************************************************************************
195 * NdrSendReceive [RPCRT4.@]
196 */
197unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer )
198{
200
201 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
202
203 /* FIXME: how to handle errors? (raise exception?) */
204 if (!stubmsg) {
205 ERR("NULL stub message. No action taken.\n");
206 return NULL;
207 }
208 if (!stubmsg->RpcMsg) {
209 ERR("RPC Message not present in stub message. No action taken.\n");
210 return NULL;
211 }
212
213 /* avoid sending uninitialised parts of the buffer on the wire */
214 stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
215 status = I_RpcSendReceive(stubmsg->RpcMsg);
216 if (status != RPC_S_OK)
218
219 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
220 stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
221 stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
222 stubmsg->Buffer = stubmsg->BufferStart;
223
224 /* FIXME: is this the right return value? */
225 return NULL;
226}
227
228/************************************************************************
229 * NdrMapCommAndFaultStatus [RPCRT4.@]
230 */
232 ULONG *pCommStatus,
233 ULONG *pFaultStatus,
235{
236 TRACE("(%p, %p, %p, %d)\n", pStubMsg, pCommStatus, pFaultStatus, Status);
237
238 switch (Status)
239 {
242 case RPC_S_UNKNOWN_IF:
252 *pCommStatus = Status;
253 *pFaultStatus = 0;
254 break;
255 default:
256 *pCommStatus = 0;
257 *pFaultStatus = Status;
258 }
259
260 return RPC_S_OK;
261}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
Status
Definition: gdiplustypes.h:25
GLuint buffer
Definition: glext.h:5915
void WINAPI NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum)
unsigned char *WINAPI NdrServerInitializeNew(PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDesc)
RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus(PMIDL_STUB_MESSAGE pStubMsg, ULONG *pCommStatus, ULONG *pFaultStatus, RPC_STATUS Status)
void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
unsigned char *WINAPI NdrSendReceive(PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer)
RPC_STATUS WINAPI I_RpcGetBuffer(PRPC_MESSAGE pMsg)
Definition: rpc_message.c:1638
RPC_STATUS WINAPI I_RpcSendReceive(PRPC_MESSAGE pMsg)
Definition: rpc_message.c:1918
RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg)
Definition: rpc_message.c:1696
#define RPC_FLAGS_VALID_BIT
Definition: rpcdcep.h:52
#define NDR_LOCAL_DATA_REPRESENTATION
Definition: rpcndr.h:107
#define RPC_S_OK
Definition: rpcnterr.h:22
void DECLSPEC_NORETURN WINAPI RpcRaiseException(RPC_STATUS exception)
Definition: rpcrt4_main.c:188
#define RPC_ENTRY
Definition: rpc.h:67
long RPC_STATUS
Definition: rpc.h:52
#define TRACE(s)
Definition: solgame.cpp:4
void * RpcInterfaceInformation
Definition: rpcndr.h:362
unsigned int fIsOicf
Definition: rpcndr.h:242
ULONG PointerLength
Definition: rpcndr.h:233
PNDR_CORRELATION_INFO pCorrInfo
Definition: rpcndr.h:262
unsigned char * StackTop
Definition: rpcndr.h:226
unsigned char CorrDespIncrement
Definition: rpcndr.h:218
unsigned int fIsIn
Definition: rpcndr.h:240
unsigned int fBufferValid
Definition: rpcndr.h:243
unsigned int fDontCallFreeInst
Definition: rpcndr.h:235
struct NDR_POINTER_QUEUE_STATE * pPointerQueueState
Definition: rpcndr.h:215
void * pvDestContext
Definition: rpcndr.h:250
DWORD dwStubPhase
Definition: rpcndr.h:259
unsigned int fNeedMCCP
Definition: rpcndr.h:246
ULONG FullPtrRefId
Definition: rpcndr.h:232
struct IRpcChannelBuffer * pRpcChannelBuffer
Definition: rpcndr.h:253
void * pMemoryList
Definition: rpcndr.h:264
PNDR_ASYNC_MESSAGE pAsyncMsg
Definition: rpcndr.h:261
unsigned int fHasReturn
Definition: rpcndr.h:237
unsigned char * Buffer
Definition: rpcndr.h:203
struct _FULL_PTR_XLAT_TABLES * FullPtrXlatTables
Definition: rpcndr.h:231
unsigned int fHasExtensions
Definition: rpcndr.h:238
unsigned int fInFree
Definition: rpcndr.h:245
PARRAY_INFO pArrayInfo
Definition: rpcndr.h:254
ULONG BufferLength
Definition: rpcndr.h:207
int IgnoreEmbeddedPointers
Definition: rpcndr.h:216
unsigned int fInOnlyParam
Definition: rpcndr.h:236
unsigned char * BufferEnd
Definition: rpcndr.h:205
DWORD dwDestContext
Definition: rpcndr.h:249
unsigned int fHasMemoryValidateCallback
Definition: rpcndr.h:244
unsigned char * pCorrMemory
Definition: rpcndr.h:263
unsigned char uFlags
Definition: rpcndr.h:219
PRPC_MESSAGE RpcMsg
Definition: rpcndr.h:202
const struct _MIDL_STUB_DESC * StubDesc
Definition: rpcndr.h:230
unsigned char IsClient
Definition: rpcndr.h:210
unsigned char * BufferStart
Definition: rpcndr.h:204
unsigned int fHasNewCorrDesc
Definition: rpcndr.h:239
struct NDR_ALLOC_ALL_NODES_CONTEXT * pAllocAllNodesContext
Definition: rpcndr.h:214
unsigned char * PointerBufferMark
Definition: rpcndr.h:217
unsigned short UniquePtrCount
Definition: rpcndr.h:220
unsigned int fIsOut
Definition: rpcndr.h:241
unsigned int fInDontFree
Definition: rpcndr.h:234
unsigned int BufferLength
Definition: rpcdcep.h:41
unsigned int ProcNum
Definition: rpcdcep.h:42
void * RpcInterfaceInformation
Definition: rpcdcep.h:44
void * Buffer
Definition: rpcdcep.h:40
ULONG DataRepresentation
Definition: rpcdcep.h:39
void * ReservedForRuntime
Definition: rpcdcep.h:45
RPC_BINDING_HANDLE Handle
Definition: rpcdcep.h:38
ULONG RpcFlags
Definition: rpcdcep.h:48
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
#define RPC_S_SERVER_TOO_BUSY
Definition: winerror.h:1034
#define RPC_S_CALL_FAILED_DNE
Definition: winerror.h:1038
#define EPT_S_NOT_REGISTERED
Definition: winerror.h:1061
#define RPC_S_UNSUPPORTED_TRANS_SYN
Definition: winerror.h:1040
#define RPC_S_UNSUPPORTED_TYPE
Definition: winerror.h:1041
#define RPC_S_UNKNOWN_IF
Definition: winerror.h:1028
#define RPC_S_PROTOCOL_ERROR
Definition: winerror.h:1039
#define RPC_S_SERVER_UNAVAILABLE
Definition: winerror.h:1033
#define RPC_S_INVALID_BINDING
Definition: winerror.h:1013
#define RPC_S_COMM_FAILURE
Definition: winerror.h:1127
#define RPC_S_PROCNUM_OUT_OF_RANGE
Definition: winerror.h:1053