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
41 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
48 /************************************************************************
49 * NdrClientInitializeNew [RPCRT4.@]
51 void WINAPI
NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage
, PMIDL_STUB_MESSAGE pStubMsg
,
52 PMIDL_STUB_DESC pStubDesc
, unsigned int ProcNum
)
54 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
55 pRpcMessage
, pStubMsg
, pStubDesc
, ProcNum
);
57 assert( pRpcMessage
&& pStubMsg
&& pStubDesc
);
59 pRpcMessage
->Handle
= NULL
;
60 pRpcMessage
->ProcNum
= ProcNum
;
61 pRpcMessage
->RpcInterfaceInformation
= pStubDesc
->RpcInterfaceInformation
;
62 pRpcMessage
->RpcFlags
= 0;
63 pRpcMessage
->DataRepresentation
= NDR_LOCAL_DATA_REPRESENTATION
;
65 pStubMsg
->RpcMsg
= pRpcMessage
;
66 pStubMsg
->BufferStart
= NULL
;
67 pStubMsg
->BufferEnd
= NULL
;
68 pStubMsg
->BufferLength
= 0;
69 pStubMsg
->IsClient
= TRUE
;
70 pStubMsg
->ReuseBuffer
= FALSE
;
71 pStubMsg
->pAllocAllNodesContext
= NULL
;
72 pStubMsg
->pPointerQueueState
= NULL
;
73 pStubMsg
->IgnoreEmbeddedPointers
= 0;
74 pStubMsg
->PointerBufferMark
= NULL
;
75 pStubMsg
->fBufferValid
= 0;
77 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
78 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
79 pStubMsg
->StackTop
= NULL
;
80 pStubMsg
->StubDesc
= pStubDesc
;
81 pStubMsg
->FullPtrRefId
= 0;
82 pStubMsg
->PointerLength
= 0;
83 pStubMsg
->fInDontFree
= 0;
84 pStubMsg
->fDontCallFreeInst
= 0;
85 pStubMsg
->fInOnlyParam
= 0;
86 pStubMsg
->fHasReturn
= 0;
87 pStubMsg
->fHasExtensions
= 0;
88 pStubMsg
->fHasNewCorrDesc
= 0;
89 pStubMsg
->fUnused
= 0;
90 pStubMsg
->dwDestContext
= MSHCTX_DIFFERENTMACHINE
;
91 pStubMsg
->pvDestContext
= NULL
;
92 pStubMsg
->pRpcChannelBuffer
= NULL
;
93 pStubMsg
->pArrayInfo
= NULL
;
94 pStubMsg
->dwStubPhase
= 0;
95 /* FIXME: LowStackMark */
96 pStubMsg
->pAsyncMsg
= NULL
;
97 pStubMsg
->pCorrInfo
= NULL
;
98 pStubMsg
->pCorrMemory
= NULL
;
99 pStubMsg
->pMemoryList
= NULL
;
102 /***********************************************************************
103 * NdrServerInitializeNew [RPCRT4.@]
105 unsigned char* WINAPI
NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg
, PMIDL_STUB_MESSAGE pStubMsg
,
106 PMIDL_STUB_DESC pStubDesc
)
108 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg
, pStubMsg
, pStubDesc
);
110 assert( pRpcMsg
&& pStubMsg
&& pStubDesc
);
112 /* not everyone allocates stack space for w2kReserved */
113 memset(pStubMsg
, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE
,pCSInfo
));
115 pStubMsg
->ReuseBuffer
= TRUE
;
116 pStubMsg
->IsClient
= FALSE
;
117 pStubMsg
->StubDesc
= pStubDesc
;
118 pStubMsg
->pfnAllocate
= pStubDesc
->pfnAllocate
;
119 pStubMsg
->pfnFree
= pStubDesc
->pfnFree
;
120 pStubMsg
->RpcMsg
= pRpcMsg
;
121 pStubMsg
->Buffer
= pStubMsg
->BufferStart
= pRpcMsg
->Buffer
;
122 pStubMsg
->BufferLength
= pRpcMsg
->BufferLength
;
123 pStubMsg
->BufferEnd
= pStubMsg
->Buffer
+ pStubMsg
->BufferLength
;
125 /* FIXME: determine the proper return value */
129 /***********************************************************************
130 * NdrGetBuffer [RPCRT4.@]
132 unsigned char *WINAPI
NdrGetBuffer(MIDL_STUB_MESSAGE
*stubmsg
, unsigned long buflen
, RPC_BINDING_HANDLE handle
)
134 TRACE("(stubmsg == ^%p, buflen == %lu, handle == %p): wild guess.\n", stubmsg
, buflen
, handle
);
136 assert( stubmsg
&& stubmsg
->RpcMsg
);
138 /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
139 stubmsg
->RpcMsg
->Handle
= handle
;
141 stubmsg
->RpcMsg
->BufferLength
= buflen
;
142 if (I_RpcGetBuffer(stubmsg
->RpcMsg
) != S_OK
)
145 stubmsg
->Buffer
= stubmsg
->BufferStart
= stubmsg
->RpcMsg
->Buffer
;
146 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
147 stubmsg
->BufferEnd
= stubmsg
->Buffer
+ stubmsg
->BufferLength
;
148 return (stubmsg
->Buffer
= (unsigned char *)stubmsg
->RpcMsg
->Buffer
);
150 /***********************************************************************
151 * NdrFreeBuffer [RPCRT4.@]
153 void WINAPI
NdrFreeBuffer(MIDL_STUB_MESSAGE
*pStubMsg
)
155 TRACE("(pStubMsg == ^%p): wild guess.\n", pStubMsg
);
156 I_RpcFreeBuffer(pStubMsg
->RpcMsg
);
157 pStubMsg
->BufferLength
= 0;
158 pStubMsg
->Buffer
= pStubMsg
->BufferEnd
= (unsigned char *)(pStubMsg
->RpcMsg
->Buffer
= NULL
);
161 /************************************************************************
162 * NdrSendReceive [RPCRT4.@]
164 unsigned char *WINAPI
NdrSendReceive( MIDL_STUB_MESSAGE
*stubmsg
, unsigned char *buffer
)
168 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg
, buffer
);
170 /* FIXME: how to handle errors? (raise exception?) */
172 ERR("NULL stub message. No action taken.\n");
175 if (!stubmsg
->RpcMsg
) {
176 ERR("RPC Message not present in stub message. No action taken.\n");
180 stubmsg
->RpcMsg
->BufferLength
= buffer
- (unsigned char *)stubmsg
->RpcMsg
->Buffer
;
181 status
= I_RpcSendReceive(stubmsg
->RpcMsg
);
182 if (status
!= RPC_S_OK
)
183 RpcRaiseException(status
);
185 stubmsg
->BufferLength
= stubmsg
->RpcMsg
->BufferLength
;
186 stubmsg
->BufferStart
= stubmsg
->RpcMsg
->Buffer
;
187 stubmsg
->BufferEnd
= stubmsg
->BufferStart
+ stubmsg
->BufferLength
;
188 stubmsg
->Buffer
= stubmsg
->BufferStart
;
190 /* FIXME: is this the right return value? */
194 /************************************************************************
195 * NdrMapCommAndFaultStatus [RPCRT4.@]
197 RPC_STATUS RPC_ENTRY
NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg
,
198 unsigned long *pCommStatus
,
199 unsigned long *pFaultStatus
,
202 FIXME("(%p, %p, %p, %ld): stub\n", pStubMsg
, pCommStatus
, pFaultStatus
, Status
);