ReactOS 0.4.16-dev-1946-g52006dd
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->fHasReturn = 0;
82 pStubMsg->fHasExtensions = 0;
83 pStubMsg->fHasNewCorrDesc = 0;
84 pStubMsg->fIsIn = 0;
85 pStubMsg->fIsOut = 0;
86 pStubMsg->fIsOicf = 0;
87 pStubMsg->fBufferValid = 0;
88 pStubMsg->fHasMemoryValidateCallback = 0;
89 pStubMsg->fInFree = 0;
90 pStubMsg->fNeedMCCP = 0;
91 pStubMsg->fUnused2 = 0;
92 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
93 pStubMsg->pvDestContext = NULL;
94 pStubMsg->pRpcChannelBuffer = NULL;
95 pStubMsg->pArrayInfo = NULL;
96 pStubMsg->dwStubPhase = 0;
97 /* FIXME: LowStackMark */
98 pStubMsg->pAsyncMsg = NULL;
99 pStubMsg->pCorrInfo = NULL;
100 pStubMsg->pCorrMemory = NULL;
101 pStubMsg->pMemoryList = NULL;
102}
103
104/***********************************************************************
105 * NdrServerInitializeNew [RPCRT4.@]
106 */
108 PMIDL_STUB_DESC pStubDesc )
109{
110 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
111
112 pStubMsg->RpcMsg = pRpcMsg;
113 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
114 pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
115 pStubMsg->BufferLength = pRpcMsg->BufferLength;
116 pStubMsg->IsClient = FALSE;
117 pStubMsg->ReuseBuffer = FALSE;
118 pStubMsg->pAllocAllNodesContext = NULL;
119 pStubMsg->pPointerQueueState = NULL;
120 pStubMsg->IgnoreEmbeddedPointers = 0;
121 pStubMsg->PointerBufferMark = NULL;
122 pStubMsg->CorrDespIncrement = 0;
123 pStubMsg->uFlags = 0;
124 pStubMsg->UniquePtrCount = 0;
125 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
126 pStubMsg->pfnFree = pStubDesc->pfnFree;
127 pStubMsg->StackTop = NULL;
128 pStubMsg->StubDesc = pStubDesc;
129 pStubMsg->FullPtrXlatTables = NULL;
130 pStubMsg->FullPtrRefId = 0;
131 pStubMsg->PointerLength = 0;
132 pStubMsg->fInDontFree = 0;
133 pStubMsg->fDontCallFreeInst = 0;
134 pStubMsg->fHasReturn = 0;
135 pStubMsg->fHasExtensions = 0;
136 pStubMsg->fHasNewCorrDesc = 0;
137 pStubMsg->fIsIn = 0;
138 pStubMsg->fIsOut = 0;
139 pStubMsg->fIsOicf = 0;
140 pStubMsg->fHasMemoryValidateCallback = 0;
141 pStubMsg->fInFree = 0;
142 pStubMsg->fNeedMCCP = 0;
143 pStubMsg->fUnused2 = 0;
144 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
145 pStubMsg->pvDestContext = NULL;
146 pStubMsg->pRpcChannelBuffer = NULL;
147 pStubMsg->pArrayInfo = NULL;
148 pStubMsg->dwStubPhase = 0;
149 /* FIXME: LowStackMark */
150 pStubMsg->pAsyncMsg = NULL;
151 pStubMsg->pCorrInfo = NULL;
152 pStubMsg->pCorrMemory = NULL;
153 pStubMsg->pMemoryList = NULL;
154
155 return NULL;
156}
157
158/***********************************************************************
159 * NdrGetBuffer [RPCRT4.@]
160 */
162{
164
165 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p)\n", stubmsg, buflen, handle);
166
167 stubmsg->RpcMsg->Handle = handle;
168 stubmsg->RpcMsg->BufferLength = buflen;
169
170 status = I_RpcGetBuffer(stubmsg->RpcMsg);
171 if (status != RPC_S_OK)
173
174 stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
175 stubmsg->fBufferValid = TRUE;
176 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
177 return stubmsg->Buffer;
178}
179/***********************************************************************
180 * NdrFreeBuffer [RPCRT4.@]
181 */
183{
184 TRACE("(pStubMsg == ^%p)\n", pStubMsg);
185 if (pStubMsg->fBufferValid)
186 {
187 I_RpcFreeBuffer(pStubMsg->RpcMsg);
188 pStubMsg->fBufferValid = FALSE;
189 }
190}
191
192/************************************************************************
193 * NdrSendReceive [RPCRT4.@]
194 */
195unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer )
196{
198
199 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
200
201 /* FIXME: how to handle errors? (raise exception?) */
202 if (!stubmsg) {
203 ERR("NULL stub message. No action taken.\n");
204 return NULL;
205 }
206 if (!stubmsg->RpcMsg) {
207 ERR("RPC Message not present in stub message. No action taken.\n");
208 return NULL;
209 }
210
211 /* avoid sending uninitialised parts of the buffer on the wire */
212 stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
213 status = I_RpcSendReceive(stubmsg->RpcMsg);
214 if (status != RPC_S_OK)
216
217 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
218 stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
219 stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
220 stubmsg->Buffer = stubmsg->BufferStart;
221
222 /* FIXME: is this the right return value? */
223 return NULL;
224}
225
226/************************************************************************
227 * NdrMapCommAndFaultStatus [RPCRT4.@]
228 */
230 ULONG *pCommStatus,
231 ULONG *pFaultStatus,
233{
234 TRACE("(%p, %p, %p, %ld)\n", pStubMsg, pCommStatus, pFaultStatus, Status);
235
236 switch (Status)
237 {
240 case RPC_S_UNKNOWN_IF:
250 *pCommStatus = Status;
251 *pFaultStatus = 0;
252 break;
253 default:
254 *pCommStatus = 0;
255 *pFaultStatus = Status;
256 }
257
258 return RPC_S_OK;
259}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ERR(fmt,...)
Definition: precomp.h:57
#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:1634
RPC_STATUS WINAPI I_RpcSendReceive(PRPC_MESSAGE pMsg)
Definition: rpc_message.c:1914
RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg)
Definition: rpc_message.c:1692
#define RPC_FLAGS_VALID_BIT
Definition: rpcdcep.h:52
#define NDR_LOCAL_DATA_REPRESENTATION
Definition: rpcndr.h:68
#define RPC_S_OK
Definition: rpcnterr.h:22
void DECLSPEC_NORETURN WINAPI RpcRaiseException(RPC_STATUS exception)
Definition: rpcrt4_main.c:213
#define RPC_ENTRY
Definition: rpc.h:63
long RPC_STATUS
Definition: rpc.h:48
#define TRACE(s)
Definition: solgame.cpp:4
void * RpcInterfaceInformation
Definition: rpcndr.h:378
unsigned int fIsOicf
Definition: rpcndr.h:225
ULONG PointerLength
Definition: rpcndr.h:216
PNDR_CORRELATION_INFO pCorrInfo
Definition: rpcndr.h:245
unsigned char * StackTop
Definition: rpcndr.h:209
unsigned char CorrDespIncrement
Definition: rpcndr.h:201
unsigned int fIsIn
Definition: rpcndr.h:223
unsigned int fBufferValid
Definition: rpcndr.h:226
unsigned int fDontCallFreeInst
Definition: rpcndr.h:218
struct NDR_POINTER_QUEUE_STATE * pPointerQueueState
Definition: rpcndr.h:198
void * pvDestContext
Definition: rpcndr.h:233
DWORD dwStubPhase
Definition: rpcndr.h:242
unsigned int fNeedMCCP
Definition: rpcndr.h:229
ULONG FullPtrRefId
Definition: rpcndr.h:215
struct IRpcChannelBuffer * pRpcChannelBuffer
Definition: rpcndr.h:236
void * pMemoryList
Definition: rpcndr.h:247
PNDR_ASYNC_MESSAGE pAsyncMsg
Definition: rpcndr.h:244
unsigned int fHasReturn
Definition: rpcndr.h:220
unsigned char * Buffer
Definition: rpcndr.h:186
struct _FULL_PTR_XLAT_TABLES * FullPtrXlatTables
Definition: rpcndr.h:214
unsigned int fHasExtensions
Definition: rpcndr.h:221
unsigned int fInFree
Definition: rpcndr.h:228
PARRAY_INFO pArrayInfo
Definition: rpcndr.h:237
ULONG BufferLength
Definition: rpcndr.h:190
int IgnoreEmbeddedPointers
Definition: rpcndr.h:199
unsigned char * BufferEnd
Definition: rpcndr.h:188
DWORD dwDestContext
Definition: rpcndr.h:232
unsigned int fHasMemoryValidateCallback
Definition: rpcndr.h:227
unsigned char * pCorrMemory
Definition: rpcndr.h:246
unsigned char uFlags
Definition: rpcndr.h:202
PRPC_MESSAGE RpcMsg
Definition: rpcndr.h:185
const struct _MIDL_STUB_DESC * StubDesc
Definition: rpcndr.h:213
unsigned char IsClient
Definition: rpcndr.h:193
unsigned char * BufferStart
Definition: rpcndr.h:187
unsigned int fHasNewCorrDesc
Definition: rpcndr.h:222
struct NDR_ALLOC_ALL_NODES_CONTEXT * pAllocAllNodesContext
Definition: rpcndr.h:197
unsigned char * PointerBufferMark
Definition: rpcndr.h:200
unsigned short UniquePtrCount
Definition: rpcndr.h:203
unsigned int fIsOut
Definition: rpcndr.h:224
unsigned int fInDontFree
Definition: rpcndr.h:217
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:1390
#define RPC_S_CALL_FAILED_DNE
Definition: winerror.h:1394
#define EPT_S_NOT_REGISTERED
Definition: winerror.h:1418
#define RPC_S_UNSUPPORTED_TRANS_SYN
Definition: winerror.h:1397
#define RPC_S_UNSUPPORTED_TYPE
Definition: winerror.h:1398
#define RPC_S_UNKNOWN_IF
Definition: winerror.h:1384
#define RPC_S_PROTOCOL_ERROR
Definition: winerror.h:1395
#define RPC_S_SERVER_UNAVAILABLE
Definition: winerror.h:1389
#define RPC_S_INVALID_BINDING
Definition: winerror.h:1369
#define RPC_S_COMM_FAILURE
Definition: winerror.h:1484
#define RPC_S_PROCNUM_OUT_OF_RANGE
Definition: winerror.h:1410