Author: tretiakov
Date: Thu Apr 20 19:45:01 2006
New Revision: 21672
URL:
http://svn.reactos.ru/svn/reactos?rev=21672&view=rev
Log:
Implement context handle support for servers: NdrServerContextMarshall,
NdrServerContextUnmarshall, NDRSContextMarshall, NDRSContextUnmarshall.
MSDN context handle examples now work in ros. Context rundown routines don't work
yet.
Modified:
trunk/reactos/dll/win32/rpcrt4/ndr_contexth.c
trunk/reactos/dll/win32/rpcrt4/ndr_contexth.h
trunk/reactos/dll/win32/rpcrt4/rpcrt4.spec
Modified: trunk/reactos/dll/win32/rpcrt4/ndr_contexth.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/dll/win32/rpcrt4/ndr_contex…
==============================================================================
--- trunk/reactos/dll/win32/rpcrt4/ndr_contexth.c (original)
+++ trunk/reactos/dll/win32/rpcrt4/ndr_contexth.c Thu Apr 20 19:45:01 2006
@@ -25,6 +25,110 @@
#include "rpc_binding.h"
#include "ndr_contexth.h"
+static SContextHandle *CtxList = NULL;
+
+static CRITICAL_SECTION CtxList_cs;
+static CRITICAL_SECTION_DEBUG CtxList_cs_debug =
+{
+ 0, 0, &CtxList_cs,
+ { &CtxList_cs_debug.ProcessLocksList, &CtxList_cs_debug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": CtxList_cs") }
+};
+static CRITICAL_SECTION CtxList_cs = { &CtxList_cs_debug, -1, 0, 0, 0, 0 };
+
+SContextHandle* RPCRT4_SrvAllocCtxHdl()
+{
+ SContextHandle *Hdl, *Tmp;
+
+ if((Hdl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+ sizeof(SContextHandle)))==NULL) return NULL;
+
+ EnterCriticalSection(&CtxList_cs);
+
+ if(!CtxList) CtxList = Hdl;
+ else
+ {
+ for(Tmp = CtxList; Tmp->Next; Tmp = Tmp->Next);
+ Tmp->Next = Hdl;
+ Hdl->Prev = Tmp;
+ }
+
+ LeaveCriticalSection(&CtxList_cs);
+
+ return Hdl;
+}
+
+void RPCRT4_SrvFreeCtxHdl(SContextHandle *Hdl)
+{
+ EnterCriticalSection(&CtxList_cs);
+
+ if(Hdl->Prev && Hdl->Next)
+ {
+ ((SContextHandle*)Hdl->Prev)->Next = Hdl->Next;
+ ((SContextHandle*)Hdl->Next)->Prev = Hdl->Prev;
+ }
+ else if(Hdl->Next)
+ {
+ ((SContextHandle*)Hdl->Next)->Prev = NULL;
+ CtxList = (SContextHandle*)Hdl->Next;
+ }
+ else if(Hdl->Prev)
+ ((SContextHandle*)Hdl->Prev)->Next = NULL;
+ else CtxList = NULL;
+
+ HeapFree(GetProcessHeap(), 0, Hdl);
+ LeaveCriticalSection(&CtxList_cs);
+}
+
+SContextHandle* RPCRT4_SrvFindCtxHdl(ContextHandleNdr *CtxNdr)
+{
+ SContextHandle *Hdl, *Ret=NULL;
+ RPC_STATUS status;
+ EnterCriticalSection(&CtxList_cs);
+
+ for(Hdl = CtxList; Hdl; Hdl = Hdl->Next)
+ if(UuidCompare(&Hdl->Ndr.uuid, &CtxNdr->uuid, &status)==0)
+ {
+ Ret = Hdl;
+ break;
+ }
+
+ LeaveCriticalSection(&CtxList_cs);
+ return Ret;
+}
+
+SContextHandle* RPCRT4_SrvUnmarshallCtxHdl(ContextHandleNdr *Ndr)
+{
+ SContextHandle *Hdl = NULL;
+ RPC_STATUS status;
+
+ if(!Ndr)
+ {
+ if((Hdl = RPCRT4_SrvAllocCtxHdl())==NULL)
+ RpcRaiseException(ERROR_OUTOFMEMORY);
+
+ UuidCreate(&Hdl->Ndr.uuid);
+ }
+ else if(!UuidIsNil(&Ndr->uuid, &status))
+ Hdl = RPCRT4_SrvFindCtxHdl(Ndr);
+
+ return Hdl;
+}
+
+void RPCRT4_SrvMarshallCtxHdl(SContextHandle *Hdl, ContextHandleNdr *Ndr)
+{
+ if(!Hdl->Value)
+ {
+ RPCRT4_SrvFreeCtxHdl(Hdl);
+ ZeroMemory(Ndr, sizeof(ContextHandleNdr));
+ }
+ else memcpy(Ndr, &Hdl->Ndr, sizeof(ContextHandleNdr));
+}
+
+void RPCRT4_DoContextRundownIfNeeded(RpcConnection *Conn)
+{
+
+}
/***********************************************************************
* NDRCContextBinding
@@ -103,11 +207,12 @@
NDR_CCONTEXT * pContextHandle,
RPC_BINDING_HANDLE BindHandle)
{
- if(!pContextHandle)
+
+ if(!pContextHandle || !BindHandle)
RpcRaiseException(ERROR_INVALID_HANDLE);
-
+
NDRCContextUnmarshall(pContextHandle,
- ((CContextHandle*)pContextHandle)->Binding,
+ (CContextHandle*)BindHandle,
pStubMsg->Buffer,
pStubMsg->RpcMsg->DataRepresentation);
@@ -165,39 +270,24 @@
}
/***********************************************************************
- * NDRSContextMarshall2
- */
-void WINAPI NDRSContextMarshall2(IN RPC_BINDING_HANDLE BindingHandle,
- IN NDR_SCONTEXT CContext,
- OUT void *pBuff,
- IN NDR_RUNDOWN userRunDownIn,
- IN void *CtxGuard,
- IN unsigned long Flags)
-{
- FIXME("stub\n");
-}
-
-/***********************************************************************
- * NDRSContextUnmarshall2
- */
-NDR_SCONTEXT WINAPI NDRSContextUnmarshall2(IN RPC_BINDING_HANDLE BindingHandle,
- IN void *pBuff,
- IN unsigned long DataRepresentation,
- IN void *CtxGuard,
- IN unsigned long Flags)
-{
- FIXME("stub\n");
- return NULL;
-}
-
-/***********************************************************************
* NdrServerContextMarshall
*/
void WINAPI NdrServerContextMarshall(PMIDL_STUB_MESSAGE pStubMsg,
NDR_SCONTEXT ContextHandle,
NDR_RUNDOWN RundownRoutine)
{
- FIXME("(%p, %p, %p): stub\n", pStubMsg, ContextHandle, RundownRoutine);
+ SContextHandle *Hdl;
+ RpcBinding *Binding;
+
+ if(!ContextHandle)
+ RpcRaiseException(ERROR_INVALID_HANDLE);
+
+ Hdl = (SContextHandle*)ContextHandle;
+ Binding = (RpcBinding*)pStubMsg->RpcMsg->Handle;
+ Hdl->Rundown = RundownRoutine;
+ Hdl->Conn = Binding->FromConn;
+ RPCRT4_SrvMarshallCtxHdl(Hdl, (ContextHandleNdr*)pStubMsg->Buffer);
+ pStubMsg->Buffer += sizeof(ContextHandleNdr);
}
/***********************************************************************
@@ -205,8 +295,10 @@
*/
NDR_SCONTEXT WINAPI NdrServerContextUnmarshall(PMIDL_STUB_MESSAGE pStubMsg)
{
- FIXME("(%p): stub\n", pStubMsg);
- return NULL;
+ SContextHandle *Hdl;
+
+ Hdl = RPCRT4_SrvUnmarshallCtxHdl((ContextHandleNdr*)pStubMsg->Buffer);
+ return (NDR_SCONTEXT)Hdl;
}
/***********************************************************************
@@ -237,7 +329,14 @@
OUT void *pBuff,
IN NDR_RUNDOWN userRunDownIn)
{
- FIXME("stub\n");
+ SContextHandle *Hdl;
+
+ if(!CContext)
+ RpcRaiseException(ERROR_INVALID_HANDLE);
+
+ Hdl = (SContextHandle*)CContext;
+ Hdl->Rundown = userRunDownIn;
+ RPCRT4_SrvMarshallCtxHdl(Hdl, (ContextHandleNdr*)pBuff);
}
/***********************************************************************
@@ -246,8 +345,7 @@
NDR_SCONTEXT WINAPI NDRSContextUnmarshall(IN void *pBuff,
IN unsigned long DataRepresentation)
{
- FIXME("stub\n");
- return NULL;
+ return (NDR_SCONTEXT) RPCRT4_SrvUnmarshallCtxHdl((ContextHandleNdr*)pBuff);
}
/***********************************************************************
Modified: trunk/reactos/dll/win32/rpcrt4/ndr_contexth.h
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/dll/win32/rpcrt4/ndr_contex…
==============================================================================
--- trunk/reactos/dll/win32/rpcrt4/ndr_contexth.h (original)
+++ trunk/reactos/dll/win32/rpcrt4/ndr_contexth.h Thu Apr 20 19:45:01 2006
@@ -36,4 +36,25 @@
ContextHandleNdr Ndr;
} CContextHandle;
+/*
+ Keep this structure compatible with public rpcndr.h
+ declaration, otherwise NDRSContextValue macro won't work.
+ typedef struct {
+ void *pad[2];
+ void *userContext;
+ } *NDR_SCONTEXT;
+*/
+
+typedef struct _SContextHandle
+{
+ PVOID Prev;
+ PVOID Next;
+ PVOID Value;
+ NDR_RUNDOWN Rundown;
+ RpcConnection *Conn;
+ ContextHandleNdr Ndr;
+} SContextHandle;
+
+void RPCRT4_DoContextRundownIfNeeded(RpcConnection *Conn);
+
#endif //__WINE_NDR_CONTEXTH_H
Modified: trunk/reactos/dll/win32/rpcrt4/rpcrt4.spec
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/dll/win32/rpcrt4/rpcrt4.spe…
==============================================================================
--- trunk/reactos/dll/win32/rpcrt4/rpcrt4.spec (original)
+++ trunk/reactos/dll/win32/rpcrt4/rpcrt4.spec Thu Apr 20 19:45:01 2006
@@ -140,10 +140,10 @@
@ stdcall NDRCContextBinding(ptr)
@ stdcall NDRCContextMarshall(ptr ptr)
@ stdcall NDRCContextUnmarshall(ptr ptr ptr long)
-@ stdcall NDRSContextMarshall2(ptr ptr ptr ptr ptr long)
+@ stub NDRSContextMarshall2
@ stdcall NDRSContextMarshall(ptr ptr ptr)
@ stdcall NDRSContextMarshallEx(ptr ptr ptr ptr)
-@ stdcall NDRSContextUnmarshall2(ptr ptr ptr ptr long)
+@ stub NDRSContextUnmarshall2
@ stdcall NDRSContextUnmarshall(ptr long)
@ stdcall NDRSContextUnmarshallEx(ptr ptr long)
@ stub NDRcopy