winspool: Export ConvertAnsiDevModeToUnicodeDevMode and ConvertUnicodeDevModeToAnsiDe...
[wine/hacks.git] / dlls / rpcrt4 / ndr_clientserver.c
blob1afab2a62184e64cb55e4b2e419312e676fed95b
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>
27 #define COBJMACROS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
33 #include "objbase.h"
35 #include "rpcproxy.h"
37 #include "wine/debug.h"
39 #include "ndr_misc.h"
40 #include "rpcndr.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
44 /************************************************************************
45 * NdrClientInitializeNew [RPCRT4.@]
47 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
48 PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
50 TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
51 pRpcMessage, pStubMsg, pStubDesc, ProcNum);
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;
58 pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
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->fBufferValid = 0;
71 pStubMsg->uFlags = 0;
72 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
73 pStubMsg->pfnFree = pStubDesc->pfnFree;
74 pStubMsg->StackTop = NULL;
75 pStubMsg->StubDesc = pStubDesc;
76 pStubMsg->FullPtrRefId = 0;
77 pStubMsg->PointerLength = 0;
78 pStubMsg->fInDontFree = 0;
79 pStubMsg->fDontCallFreeInst = 0;
80 pStubMsg->fInOnlyParam = 0;
81 pStubMsg->fHasReturn = 0;
82 pStubMsg->fHasExtensions = 0;
83 pStubMsg->fHasNewCorrDesc = 0;
84 pStubMsg->fUnused = 0;
85 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
86 pStubMsg->pvDestContext = NULL;
87 pStubMsg->pRpcChannelBuffer = NULL;
88 pStubMsg->pArrayInfo = NULL;
89 pStubMsg->dwStubPhase = 0;
90 /* FIXME: LowStackMark */
91 pStubMsg->pAsyncMsg = NULL;
92 pStubMsg->pCorrInfo = NULL;
93 pStubMsg->pCorrMemory = NULL;
94 pStubMsg->pMemoryList = NULL;
97 /***********************************************************************
98 * NdrServerInitializeNew [RPCRT4.@]
100 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
101 PMIDL_STUB_DESC pStubDesc )
103 TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
105 pStubMsg->RpcMsg = pRpcMsg;
106 pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
107 pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
108 pStubMsg->BufferLength = pRpcMsg->BufferLength;
109 pStubMsg->IsClient = FALSE;
110 pStubMsg->ReuseBuffer = FALSE;
111 pStubMsg->pAllocAllNodesContext = NULL;
112 pStubMsg->pPointerQueueState = NULL;
113 pStubMsg->IgnoreEmbeddedPointers = 0;
114 pStubMsg->PointerBufferMark = NULL;
115 pStubMsg->uFlags = 0;
116 pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
117 pStubMsg->pfnFree = pStubDesc->pfnFree;
118 pStubMsg->StackTop = NULL;
119 pStubMsg->StubDesc = pStubDesc;
120 pStubMsg->FullPtrXlatTables = NULL;
121 pStubMsg->FullPtrRefId = 0;
122 pStubMsg->PointerLength = 0;
123 pStubMsg->fInDontFree = 0;
124 pStubMsg->fDontCallFreeInst = 0;
125 pStubMsg->fInOnlyParam = 0;
126 pStubMsg->fHasReturn = 0;
127 pStubMsg->fHasExtensions = 0;
128 pStubMsg->fHasNewCorrDesc = 0;
129 pStubMsg->fUnused = 0;
130 pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
131 pStubMsg->pvDestContext = NULL;
132 pStubMsg->pRpcChannelBuffer = NULL;
133 pStubMsg->pArrayInfo = NULL;
134 pStubMsg->dwStubPhase = 0;
135 /* FIXME: LowStackMark */
136 pStubMsg->pAsyncMsg = NULL;
137 pStubMsg->pCorrInfo = NULL;
138 pStubMsg->pCorrMemory = NULL;
139 pStubMsg->pMemoryList = NULL;
141 return NULL;
144 /***********************************************************************
145 * NdrGetBuffer [RPCRT4.@]
147 unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
149 RPC_STATUS status;
151 TRACE("(stubmsg == ^%p, buflen == %u, handle == %p)\n", stubmsg, buflen, handle);
153 stubmsg->RpcMsg->Handle = handle;
154 stubmsg->RpcMsg->BufferLength = buflen;
156 status = I_RpcGetBuffer(stubmsg->RpcMsg);
157 if (status != RPC_S_OK)
158 RpcRaiseException(status);
160 stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
161 stubmsg->fBufferValid = TRUE;
162 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
163 return stubmsg->Buffer;
165 /***********************************************************************
166 * NdrFreeBuffer [RPCRT4.@]
168 void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
170 TRACE("(pStubMsg == ^%p)\n", pStubMsg);
171 if (pStubMsg->fBufferValid)
173 I_RpcFreeBuffer(pStubMsg->RpcMsg);
174 pStubMsg->fBufferValid = FALSE;
178 /************************************************************************
179 * NdrSendReceive [RPCRT4.@]
181 unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer )
183 RPC_STATUS status;
185 TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
187 /* FIXME: how to handle errors? (raise exception?) */
188 if (!stubmsg) {
189 ERR("NULL stub message. No action taken.\n");
190 return NULL;
192 if (!stubmsg->RpcMsg) {
193 ERR("RPC Message not present in stub message. No action taken.\n");
194 return NULL;
197 stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
198 status = I_RpcSendReceive(stubmsg->RpcMsg);
199 if (status != RPC_S_OK)
200 RpcRaiseException(status);
202 stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
203 stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
204 stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
205 stubmsg->Buffer = stubmsg->BufferStart;
207 /* FIXME: is this the right return value? */
208 return NULL;
211 /************************************************************************
212 * NdrMapCommAndFaultStatus [RPCRT4.@]
214 RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
215 ULONG *pCommStatus,
216 ULONG *pFaultStatus,
217 RPC_STATUS Status )
219 TRACE("(%p, %p, %p, %ld)\n", pStubMsg, pCommStatus, pFaultStatus, Status);
221 switch (Status)
223 case ERROR_INVALID_HANDLE:
224 case RPC_S_INVALID_BINDING:
225 case RPC_S_UNKNOWN_IF:
226 case RPC_S_SERVER_UNAVAILABLE:
227 case RPC_S_SERVER_TOO_BUSY:
228 case RPC_S_CALL_FAILED_DNE:
229 case RPC_S_PROTOCOL_ERROR:
230 case RPC_S_UNSUPPORTED_TRANS_SYN:
231 case RPC_S_UNSUPPORTED_TYPE:
232 case RPC_S_PROCNUM_OUT_OF_RANGE:
233 case EPT_S_NOT_REGISTERED:
234 case RPC_S_COMM_FAILURE:
235 *pCommStatus = Status;
236 *pFaultStatus = 0;
237 break;
238 default:
239 *pCommStatus = 0;
240 *pFaultStatus = Status;
243 return RPC_S_OK;