ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ndr_clientserver.c
Go to the documentation of this file.
00001 /*
00002  * MIDL proxy/stub stuff
00003  *
00004  * Copyright 2002 Ove Kåven, TransGaming Technologies
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  *
00020  * TODO:
00021  *  - figure out whether we *really* got this right
00022  *  - check for errors and throw exceptions
00023  */
00024 
00025 #include <stdarg.h>
00026 
00027 #define COBJMACROS
00028 
00029 #include "windef.h"
00030 #include "winbase.h"
00031 #include "winerror.h"
00032 
00033 #include "objbase.h"
00034 
00035 #include "rpcproxy.h"
00036 
00037 #include "wine/debug.h"
00038 
00039 #include "ndr_misc.h"
00040 #include "rpcndr.h"
00041 
00042 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
00043 
00044 /************************************************************************
00045  *             NdrClientInitializeNew [RPCRT4.@]
00046  */
00047 void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, 
00048                                     PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum )
00049 {
00050   TRACE("(pRpcMessage == ^%p, pStubMsg == ^%p, pStubDesc == ^%p, ProcNum == %d)\n",
00051     pRpcMessage, pStubMsg, pStubDesc, ProcNum);
00052 
00053   pRpcMessage->Handle = NULL;
00054   pRpcMessage->ProcNum = ProcNum | RPC_FLAGS_VALID_BIT;
00055   pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
00056   pRpcMessage->RpcFlags = 0;
00057   pRpcMessage->ReservedForRuntime = NULL;
00058   pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
00059 
00060   pStubMsg->RpcMsg = pRpcMessage;
00061   pStubMsg->BufferStart = NULL;
00062   pStubMsg->BufferEnd = NULL;
00063   pStubMsg->BufferLength = 0;
00064   pStubMsg->IsClient = TRUE;
00065   pStubMsg->ReuseBuffer = FALSE;
00066   pStubMsg->pAllocAllNodesContext = NULL;
00067   pStubMsg->pPointerQueueState = NULL;
00068   pStubMsg->IgnoreEmbeddedPointers = 0;
00069   pStubMsg->PointerBufferMark = NULL;
00070   pStubMsg->CorrDespIncrement = 0;
00071   pStubMsg->uFlags = 0;
00072   pStubMsg->UniquePtrCount = 0;
00073   pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
00074   pStubMsg->pfnFree = pStubDesc->pfnFree;
00075   pStubMsg->StackTop = NULL;
00076   pStubMsg->StubDesc = pStubDesc;
00077   pStubMsg->FullPtrRefId = 0;
00078   pStubMsg->PointerLength = 0;
00079   pStubMsg->fInDontFree = 0;
00080   pStubMsg->fDontCallFreeInst = 0;
00081   pStubMsg->fInOnlyParam = 0;
00082   pStubMsg->fHasReturn = 0;
00083   pStubMsg->fHasExtensions = 0;
00084   pStubMsg->fHasNewCorrDesc = 0;
00085   pStubMsg->fIsIn = 0;
00086   pStubMsg->fIsOut = 0;
00087   pStubMsg->fIsOicf = 0;
00088   pStubMsg->fBufferValid = 0;
00089   pStubMsg->fHasMemoryValidateCallback = 0;
00090   pStubMsg->fInFree = 0;
00091   pStubMsg->fNeedMCCP = 0;
00092   pStubMsg->fUnused = 0;
00093   pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
00094   pStubMsg->pvDestContext = NULL;
00095   pStubMsg->pRpcChannelBuffer = NULL;
00096   pStubMsg->pArrayInfo = NULL;
00097   pStubMsg->dwStubPhase = 0;
00098   /* FIXME: LowStackMark */
00099   pStubMsg->pAsyncMsg = NULL;
00100   pStubMsg->pCorrInfo = NULL;
00101   pStubMsg->pCorrMemory = NULL;
00102   pStubMsg->pMemoryList = NULL;
00103 }
00104 
00105 /***********************************************************************
00106  *             NdrServerInitializeNew [RPCRT4.@]
00107  */
00108 unsigned char* WINAPI NdrServerInitializeNew( PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg,
00109                                               PMIDL_STUB_DESC pStubDesc )
00110 {
00111   TRACE("(pRpcMsg == ^%p, pStubMsg == ^%p, pStubDesc == ^%p)\n", pRpcMsg, pStubMsg, pStubDesc);
00112 
00113   pStubMsg->RpcMsg = pRpcMsg;
00114   pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
00115   pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
00116   pStubMsg->BufferLength = pRpcMsg->BufferLength;
00117   pStubMsg->IsClient = FALSE;
00118   pStubMsg->ReuseBuffer = FALSE;
00119   pStubMsg->pAllocAllNodesContext = NULL;
00120   pStubMsg->pPointerQueueState = NULL;
00121   pStubMsg->IgnoreEmbeddedPointers = 0;
00122   pStubMsg->PointerBufferMark = NULL;
00123   pStubMsg->uFlags = 0;
00124   pStubMsg->UniquePtrCount = 0;
00125   pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
00126   pStubMsg->pfnFree = pStubDesc->pfnFree;
00127   pStubMsg->StackTop = NULL;
00128   pStubMsg->StubDesc = pStubDesc;
00129   pStubMsg->FullPtrXlatTables = NULL;
00130   pStubMsg->FullPtrRefId = 0;
00131   pStubMsg->PointerLength = 0;
00132   pStubMsg->fInDontFree = 0;
00133   pStubMsg->fDontCallFreeInst = 0;
00134   pStubMsg->fInOnlyParam = 0;
00135   pStubMsg->fHasReturn = 0;
00136   pStubMsg->fHasExtensions = 0;
00137   pStubMsg->fHasNewCorrDesc = 0;
00138   pStubMsg->fIsIn = 0;
00139   pStubMsg->fIsOut = 0;
00140   pStubMsg->fIsOicf = 0;
00141   pStubMsg->fHasMemoryValidateCallback = 0;
00142   pStubMsg->fInFree = 0;
00143   pStubMsg->fNeedMCCP = 0;
00144   pStubMsg->fUnused = 0;
00145   pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
00146   pStubMsg->pvDestContext = NULL;
00147   pStubMsg->pRpcChannelBuffer = NULL;
00148   pStubMsg->pArrayInfo = NULL;
00149   pStubMsg->dwStubPhase = 0;
00150   /* FIXME: LowStackMark */
00151   pStubMsg->pAsyncMsg = NULL;
00152   pStubMsg->pCorrInfo = NULL;
00153   pStubMsg->pCorrMemory = NULL;
00154   pStubMsg->pMemoryList = NULL;
00155 
00156   return NULL;
00157 }
00158 
00159 /***********************************************************************
00160  *           NdrGetBuffer [RPCRT4.@]
00161  */
00162 unsigned char *WINAPI NdrGetBuffer(PMIDL_STUB_MESSAGE stubmsg, ULONG buflen, RPC_BINDING_HANDLE handle)
00163 {
00164   RPC_STATUS status;
00165 
00166   TRACE("(stubmsg == ^%p, buflen == %u, handle == %p)\n", stubmsg, buflen, handle);
00167   
00168   stubmsg->RpcMsg->Handle = handle;
00169   stubmsg->RpcMsg->BufferLength = buflen;
00170 
00171   status = I_RpcGetBuffer(stubmsg->RpcMsg);
00172   if (status != RPC_S_OK)
00173     RpcRaiseException(status);
00174 
00175   stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
00176   stubmsg->fBufferValid = TRUE;
00177   stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
00178   return stubmsg->Buffer;
00179 }
00180 /***********************************************************************
00181  *           NdrFreeBuffer [RPCRT4.@]
00182  */
00183 void WINAPI NdrFreeBuffer(PMIDL_STUB_MESSAGE pStubMsg)
00184 {
00185   TRACE("(pStubMsg == ^%p)\n", pStubMsg);
00186   if (pStubMsg->fBufferValid)
00187   {
00188     I_RpcFreeBuffer(pStubMsg->RpcMsg);
00189     pStubMsg->fBufferValid = FALSE;
00190   }
00191 }
00192 
00193 /************************************************************************
00194  *           NdrSendReceive [RPCRT4.@]
00195  */
00196 unsigned char *WINAPI NdrSendReceive( PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer  )
00197 {
00198   RPC_STATUS status;
00199 
00200   TRACE("(stubmsg == ^%p, buffer == ^%p)\n", stubmsg, buffer);
00201 
00202   /* FIXME: how to handle errors? (raise exception?) */
00203   if (!stubmsg) {
00204     ERR("NULL stub message.  No action taken.\n");
00205     return NULL;
00206   }
00207   if (!stubmsg->RpcMsg) {
00208     ERR("RPC Message not present in stub message.  No action taken.\n");
00209     return NULL;
00210   }
00211 
00212   /* avoid sending uninitialised parts of the buffer on the wire */
00213   stubmsg->RpcMsg->BufferLength = buffer - (unsigned char *)stubmsg->RpcMsg->Buffer;
00214   status = I_RpcSendReceive(stubmsg->RpcMsg);
00215   if (status != RPC_S_OK)
00216     RpcRaiseException(status);
00217 
00218   stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
00219   stubmsg->BufferStart = stubmsg->RpcMsg->Buffer;
00220   stubmsg->BufferEnd = stubmsg->BufferStart + stubmsg->BufferLength;
00221   stubmsg->Buffer = stubmsg->BufferStart;
00222 
00223   /* FIXME: is this the right return value? */
00224   return NULL;
00225 }
00226 
00227 /************************************************************************
00228  *           NdrMapCommAndFaultStatus [RPCRT4.@]
00229  */
00230 RPC_STATUS RPC_ENTRY NdrMapCommAndFaultStatus( PMIDL_STUB_MESSAGE pStubMsg,
00231                                                ULONG *pCommStatus,
00232                                                ULONG *pFaultStatus,
00233                                                RPC_STATUS Status )
00234 {
00235     TRACE("(%p, %p, %p, %d)\n", pStubMsg, pCommStatus, pFaultStatus, Status);
00236 
00237     switch (Status)
00238     {
00239     case ERROR_INVALID_HANDLE:
00240     case RPC_S_INVALID_BINDING:
00241     case RPC_S_UNKNOWN_IF:
00242     case RPC_S_SERVER_UNAVAILABLE:
00243     case RPC_S_SERVER_TOO_BUSY:
00244     case RPC_S_CALL_FAILED_DNE:
00245     case RPC_S_PROTOCOL_ERROR:
00246     case RPC_S_UNSUPPORTED_TRANS_SYN:
00247     case RPC_S_UNSUPPORTED_TYPE:
00248     case RPC_S_PROCNUM_OUT_OF_RANGE:
00249     case EPT_S_NOT_REGISTERED:
00250     case RPC_S_COMM_FAILURE:
00251         *pCommStatus = Status;
00252         *pFaultStatus = 0;
00253         break;
00254     default:
00255         *pCommStatus = 0;
00256         *pFaultStatus = Status;
00257     }
00258 
00259     return RPC_S_OK;
00260 }

Generated on Mon May 28 2012 04:25:39 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.