kernel32: Add GetCPInfo test.
[wine] / dlls / rpcrt4 / ndr_clientserver.c
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 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
29
30 #define COBJMACROS
31
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "winreg.h"
36
37 #include "objbase.h"
38
39 #include "rpcproxy.h"
40
41 #include "wine/debug.h"
42
43 #include "ndr_misc.h"
44 #include "rpcndr.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
47
48 /************************************************************************
49  *             NdrClientInitializeNew [RPCRT4.@]
50  */
51 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, 
52                                     PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
53 {
54   TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
55     pRpcMessage, pStubMsg, pStubDesc, ProcNum);
56
57   assert( pRpcMessage && pStubMsg && pStubDesc );
58
59   pRpcMessage->Handle = NULL;
60   pRpcMessage->ProcNum = ProcNum;
61   pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
62   pRpcMessage->RpcFlags = 0;
63   pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
64
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;
76   pStubMsg->uFlags = 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;
100 }
101
102 /***********************************************************************
103  *             NdrServerInitializeNew [RPCRT4.@]
104  */
105 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
106                                               PMIDL_STUB_DESC pStubDesc )
107 {
108   TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
109
110   assert( pRpcMsg && pStubMsg && pStubDesc );
111
112   /* not everyone allocates stack space for w2kReserved */
113   memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo));
114
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;
124
125   /* FIXME: determine the proper return value */
126   return NULL;
127 }
128
129 /***********************************************************************
130  *           NdrGetBuffer [RPCRT4.@]
131  */
132 unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
133 {
134   TRACE("(stubmsg == ^%p, buflen == %u, handle == %p): wild guess.\n", stubmsg, buflen, handle);
135   
136   assert( stubmsg && stubmsg->RpcMsg );
137
138   /* I guess this is our chance to put the binding handle into the RPC_MESSAGE */
139   stubmsg->RpcMsg->Handle = handle;
140   
141   stubmsg->RpcMsg->BufferLength = buflen;
142   if (I_RpcGetBuffer(stubmsg->RpcMsg) != S_OK)
143     return NULL;
144
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);
149 }
150 /***********************************************************************
151  *           NdrFreeBuffer [RPCRT4.@]
152  */
153 void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
154 {
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);
159 }
160
161 /************************************************************************
162  *           NdrSendReceive [RPCRT4.@]
163  */
164 unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer  )
165 {
166   RPC_STATUS status;
167
168   TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
169
170   /* FIXME: how to handle errors? (raise exception?) */
171   if (!stubmsg) {
172     ERR("NULL stub message.  No action taken.\n");
173     return NULL;
174   }
175   if (!stubmsg->RpcMsg) {
176     ERR("RPC Message not present in stub message.  No action taken.\n");
177     return NULL;
178   }
179
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);
184
185   stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
186   stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
187   stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
188   stubmsg->Buffer = stubmsg->BufferStart;
189
190   /* FIXME: is this the right return value? */
191   return NULL;
192 }
193
194 /************************************************************************
195  *           NdrMapCommAndFaultStatus [RPCRT4.@]
196  */
197 RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
198                                                ULONG *pCommStatus,
199                                                ULONG *pFaultStatus,
200                                                RPC_STATUS Status )
201 {
202     FIXME("(%p, %p, %p, %ld): stub\n", pStubMsg, pCommStatus, pFaultStatus, Status);
203
204     *pCommStatus = 0;
205     *pFaultStatus = 0;
206
207     return RPC_S_OK;
208 }