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
21 * - figure out whether we *really* got this right
22 * - check for errors and throw exceptions
25 #define WIN32_NO_STATUS
34 //#include "winerror.h"
38 //#include "rpcproxy.h"
40 #include <wine/debug.h>
42 //#include "ndr_misc.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 pRpcMessage
->Handle
= NULL
;
57 pRpcMessage
->ProcNum
= ProcNum
| RPC_FLAGS_VALID_BIT
;
58 pRpcMessage
->RpcInterfaceInformation
= pStubDesc
->RpcInterfaceInformation
;
59 pRpcMessage
->RpcFlags
= 0;
60 pRpcMessage
->ReservedForRuntime
= NULL
;
61 pRpcMessage
->DataRepresentation
= NDR_LOCAL_DATA_REPRESENTATION
;
63 pStubMsg
->RpcMsg
= pRpcMessage
;
64 pStubMsg
->BufferStart
= NULL
;
65 pStubMsg
->BufferEnd
= NULL
;
66 pStubMsg
->BufferLength
= 0;
67 pStubMsg
->IsClient
= TRUE
;
68 pStubMsg
->ReuseBuffer
= FALSE
;
69 pStubMsg
->pAllocAllNodesContext
= NULL
;
70 pStubMsg
->pPointerQueueState
= NULL
;
71 pStubMsg
->IgnoreEmbeddedPointers
= 0;
72 pStubMsg
->PointerBufferMark
= NULL
;
73 pStubMsg
->CorrDespIncrement
= 0;
75 pStubMsg
->UniquePtrCount
= 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;
90 pStubMsg
->fIsOicf
= 0;
91 pStubMsg
->fBufferValid
= 0;
92 pStubMsg
->fHasMemoryValidateCallback
= 0;
93 pStubMsg
->fInFree
= 0;
94 pStubMsg
->fNeedMCCP
= 0;
95 pStubMsg
->fUnused
= 0;
96 pStubMsg
->dwDestContext
= MSHCTX_DIFFERENTMACHINE
;
97 pStubMsg
->pvDestContext
= NULL
;
98 pStubMsg
->pRpcChannelBuffer
= NULL
;
99 pStubMsg
->pArrayInfo
= NULL
;
100 pStubMsg
->dwStubPhase
= 0;
101 /* FIXME: LowStackMark */
102 pStubMsg
->pAsyncMsg
= NULL
;
103 pStubMsg
->pCorrInfo
= NULL
;
104 pStubMsg
->pCorrMemory
= NULL
;
105 pStubMsg
->pMemoryList
= NULL
;
108 /***********************************************************************
109 * NdrServerInitializeNew [RPCRT4.@]
111 unsigned char* WINAPI
NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg
, PMIDL_STUB_MESSAGE pStubMsg
,
112 PMIDL_STUB_DESC pStubDesc
)
114 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg
, pStubMsg
, pStubDesc
);
116 pStubMsg
->RpcMsg
= pRpcMsg
;
117 pStubMsg
->Buffer
= pStubMsg
->BufferStart
= pRpcMsg
->Buffer
;
118 pStubMsg
->BufferEnd
= pStubMsg
->Buffer
+ pRpcMsg
->BufferLength
;
119 pStubMsg
->BufferLength
= pRpcMsg
->BufferLength
;
120 pStubMsg
->IsClient
= FALSE
;
121 pStubMsg
->ReuseBuffer
= FALSE
;
122 pStubMsg
->pAllocAllNodesContext
= NULL
;
123 pStubMsg
->pPointerQueueState
= NULL
;
124 pStubMsg
->IgnoreEmbeddedPointers
= 0;
125 pStubMsg
->PointerBufferMark
= NULL
;
126 pStubMsg
->uFlags
= 0;
127 pStubMsg
->UniquePtrCount
= 0;
128 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
129 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
130 pStubMsg
->StackTop
= NULL
;
131 pStubMsg
->StubDesc
= pStubDesc
;
132 pStubMsg
->FullPtrXlatTables
= NULL
;
133 pStubMsg
->FullPtrRefId
= 0;
134 pStubMsg
->PointerLength
= 0;
135 pStubMsg
->fInDontFree
= 0;
136 pStubMsg
->fDontCallFreeInst
= 0;
137 pStubMsg
->fInOnlyParam
= 0;
138 pStubMsg
->fHasReturn
= 0;
139 pStubMsg
->fHasExtensions
= 0;
140 pStubMsg
->fHasNewCorrDesc
= 0;
142 pStubMsg
->fIsOut
= 0;
143 pStubMsg
->fIsOicf
= 0;
144 pStubMsg
->fHasMemoryValidateCallback
= 0;
145 pStubMsg
->fInFree
= 0;
146 pStubMsg
->fNeedMCCP
= 0;
147 pStubMsg
->fUnused
= 0;
148 pStubMsg
->dwDestContext
= MSHCTX_DIFFERENTMACHINE
;
149 pStubMsg
->pvDestContext
= NULL
;
150 pStubMsg
->pRpcChannelBuffer
= NULL
;
151 pStubMsg
->pArrayInfo
= NULL
;
152 pStubMsg
->dwStubPhase
= 0;
153 /* FIXME: LowStackMark */
154 pStubMsg
->pAsyncMsg
= NULL
;
155 pStubMsg
->pCorrInfo
= NULL
;
156 pStubMsg
->pCorrMemory
= NULL
;
157 pStubMsg
->pMemoryList
= NULL
;
162 /***********************************************************************
163 * NdrGetBuffer [RPCRT4.@]
165 unsigned char *WINAPI
NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg
, ULONG buflen
, RPC_BINDING_HANDLE handle
)
169 TRACE("(stubmsg == ^%p, buflen == %u, handle == %p)\n", stubmsg
, buflen
, handle
);
171 stubmsg
->RpcMsg
->Handle
= handle
;
172 stubmsg
->RpcMsg
->BufferLength
= buflen
;
174 status
= I_RpcGetBuffer(stubmsg
->RpcMsg
);
175 if (status
!= RPC_S_OK
)
176 RpcRaiseException(status
);
178 stubmsg
->Buffer
= stubmsg
->RpcMsg
->Buffer
;
179 stubmsg
->fBufferValid
= TRUE
;
180 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
181 return stubmsg
->Buffer
;
183 /***********************************************************************
184 * NdrFreeBuffer [RPCRT4.@]
186 void WINAPI
NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg
)
188 TRACE("(pStubMsg == ^%p)\n", pStubMsg
);
189 if (pStubMsg
->fBufferValid
)
191 I_RpcFreeBuffer(pStubMsg
->RpcMsg
);
192 pStubMsg
->fBufferValid
= FALSE
;
196 /************************************************************************
197 * NdrSendReceive [RPCRT4.@]
199 unsigned char *WINAPI
NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg
, unsigned char *buffer
)
203 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg
, buffer
);
205 /* FIXME: how to handle errors? (raise exception?) */
207 ERR("NULL stub message. No action taken.\n");
210 if (!stubmsg
->RpcMsg
) {
211 ERR("RPC Message not present in stub message. No action taken.\n");
215 /* avoid sending uninitialised parts of the buffer on the wire */
216 stubmsg
->RpcMsg
->BufferLength
= buffer
- (unsigned char *)stubmsg
->RpcMsg
->Buffer
;
217 status
= I_RpcSendReceive(stubmsg
->RpcMsg
);
218 if (status
!= RPC_S_OK
)
219 RpcRaiseException(status
);
221 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
222 stubmsg
->BufferStart
= stubmsg
->RpcMsg
->Buffer
;
223 stubmsg
->BufferEnd
= stubmsg
->BufferStart
+ stubmsg
->BufferLength
;
224 stubmsg
->Buffer
= stubmsg
->BufferStart
;
226 /* FIXME: is this the right return value? */
230 /************************************************************************
231 * NdrMapCommAndFaultStatus [RPCRT4.@]
233 RPC_STATUS RPC_ENTRY
NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg
,
238 TRACE("(%p, %p, %p, %d)\n", pStubMsg
, pCommStatus
, pFaultStatus
, Status
);
242 case ERROR_INVALID_HANDLE
:
243 case RPC_S_INVALID_BINDING
:
244 case RPC_S_UNKNOWN_IF
:
245 case RPC_S_SERVER_UNAVAILABLE
:
246 case RPC_S_SERVER_TOO_BUSY
:
247 case RPC_S_CALL_FAILED_DNE
:
248 case RPC_S_PROTOCOL_ERROR
:
249 case RPC_S_UNSUPPORTED_TRANS_SYN
:
250 case RPC_S_UNSUPPORTED_TYPE
:
251 case RPC_S_PROCNUM_OUT_OF_RANGE
:
252 case EPT_S_NOT_REGISTERED
:
253 case RPC_S_COMM_FAILURE
:
254 *pCommStatus
= Status
;
259 *pFaultStatus
= Status
;