4 * Copyright 2001 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
41 #include "wine/debug.h"
42 #include "wine/exception.h"
44 #include "rpc_server.h"
48 #define MAX_THREADS 128
50 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
52 typedef struct _RpcPacket
54 struct _RpcPacket
* next
;
55 struct _RpcConnection
* conn
;
60 typedef struct _RpcObjTypeMap
62 /* FIXME: a hash table would be better. */
63 struct _RpcObjTypeMap
*next
;
68 static RpcObjTypeMap
*RpcObjTypeMaps
;
70 static RpcServerProtseq
* protseqs
;
71 static RpcServerInterface
* ifs
;
73 static CRITICAL_SECTION server_cs
;
74 static CRITICAL_SECTION_DEBUG server_cs_debug
=
77 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
78 0, 0, { 0, (DWORD
)(__FILE__
": server_cs") }
80 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
82 static CRITICAL_SECTION listen_cs
;
83 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
86 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
87 0, 0, { 0, (DWORD
)(__FILE__
": listen_cs") }
89 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
91 static BOOL std_listen
;
92 static LONG listen_count
= -1;
93 static HANDLE mgr_event
, server_thread
;
95 static CRITICAL_SECTION spacket_cs
;
96 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
99 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
100 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
102 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
104 static RpcPacket
* spacket_head
;
105 static RpcPacket
* spacket_tail
;
106 static HANDLE server_sem
;
108 static DWORD worker_count
, worker_free
, worker_tls
;
110 static UUID uuid_nil
;
112 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
114 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
118 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
125 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
127 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
134 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
, UUID
* if_id
)
136 UUID
* MgrType
= NULL
;
137 RpcServerInterface
* cif
= NULL
;
140 MgrType
= LookupObjType(object
);
141 EnterCriticalSection(&server_cs
);
144 if (UuidEqual(if_id
, &cif
->If
->InterfaceId
.SyntaxGUID
, &status
) &&
145 UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
) &&
146 (std_listen
|| (cif
->Flags
& RPC_IF_AUTOLISTEN
))) break;
149 LeaveCriticalSection(&server_cs
);
153 static void RPCRT4_push_packet(RpcPacket
* packet
)
156 EnterCriticalSection(&spacket_cs
);
158 spacket_tail
->next
= packet
;
159 spacket_tail
= packet
;
161 spacket_head
= packet
;
162 spacket_tail
= packet
;
164 LeaveCriticalSection(&spacket_cs
);
167 static RpcPacket
* RPCRT4_pop_packet(void)
170 EnterCriticalSection(&spacket_cs
);
171 packet
= spacket_head
;
173 spacket_head
= packet
->next
;
174 if (!spacket_head
) spacket_tail
= NULL
;
176 LeaveCriticalSection(&spacket_cs
);
177 if (packet
) packet
->next
= NULL
;
186 static WINE_EXCEPTION_FILTER(rpc_filter
)
190 state
= TlsGetValue(worker_tls
);
192 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
193 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
194 msg
->BufferLength
= sizeof(DWORD
);
196 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
197 return EXCEPTION_EXECUTE_HANDLER
;
200 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, void* buf
)
204 RpcServerInterface
* sif
;
205 RPC_DISPATCH_FUNCTION func
;
210 TlsSetValue(worker_tls
, &state
);
211 memset(&msg
, 0, sizeof(msg
));
212 msg
.BufferLength
= hdr
->len
;
214 sif
= RPCRT4_find_interface(&hdr
->object
, &hdr
->if_id
);
216 TRACE("packet received for interface %s\n", debugstr_guid(&hdr
->if_id
));
217 msg
.RpcInterfaceInformation
= sif
->If
;
218 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
219 msg
.ManagerEpv
= sif
->MgrEpv
;
220 /* create temporary binding for dispatch */
221 RPCRT4_MakeBinding(&pbind
, conn
);
222 RPCRT4_SetBindingObject(pbind
, &hdr
->object
);
223 msg
.Handle
= (RPC_BINDING_HANDLE
)pbind
;
225 switch (hdr
->ptype
) {
227 /* find dispatch function */
228 msg
.ProcNum
= hdr
->opnum
;
229 if (sif
->Flags
& RPC_IF_OLE
) {
230 /* native ole32 always gives us a dispatch table with a single entry
231 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
232 func
= *sif
->If
->DispatchTable
->DispatchTable
;
234 if (msg
.ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
235 ERR("invalid procnum\n");
238 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
.ProcNum
];
241 /* put in the drep. FIXME: is this more universally applicable?
242 perhaps we should move this outward... */
243 msg
.DataRepresentation
=
244 MAKELONG( MAKEWORD(hdr
->drep
[0], hdr
->drep
[1]),
245 MAKEWORD(hdr
->drep
[2], 0));
249 if (func
) func(&msg
);
250 } __EXCEPT(rpc_filter
) {
251 /* failure packet was created in rpc_filter */
252 TRACE("exception caught, returning failure packet\n");
255 /* send response packet */
259 ERR("unknown packet type\n");
263 RPCRT4_DestroyBinding(pbind
);
265 msg
.RpcInterfaceInformation
= NULL
;
268 ERR("got RPC packet to unregistered interface %s\n", debugstr_guid(&hdr
->if_id
));
272 if (msg
.Buffer
== buf
) msg
.Buffer
= NULL
;
273 TRACE("freeing Buffer=%p\n", buf
);
274 HeapFree(GetProcessHeap(), 0, buf
);
275 I_RpcFreeBuffer(&msg
);
277 TlsSetValue(worker_tls
, NULL
);
280 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
286 /* idle timeout after 5s */
287 obj
= WaitForSingleObject(server_sem
, 5000);
288 if (obj
== WAIT_TIMEOUT
) {
289 /* if another idle thread exist, self-destruct */
290 if (worker_free
> 1) break;
293 pkt
= RPCRT4_pop_packet();
295 InterlockedDecrement(&worker_free
);
297 RPCRT4_process_packet(pkt
->conn
, &pkt
->hdr
, pkt
->buf
);
298 HeapFree(GetProcessHeap(), 0, pkt
);
299 /* try to grab another packet here without waiting
300 * on the semaphore, in case it hits max */
301 pkt
= RPCRT4_pop_packet();
303 /* decrement semaphore */
304 WaitForSingleObject(server_sem
, 0);
306 InterlockedIncrement(&worker_free
);
308 InterlockedDecrement(&worker_free
);
309 InterlockedDecrement(&worker_count
);
313 static void RPCRT4_create_worker_if_needed(void)
315 if (!worker_free
&& worker_count
< MAX_THREADS
) {
317 InterlockedIncrement(&worker_count
);
318 InterlockedIncrement(&worker_free
);
319 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
320 if (thread
) CloseHandle(thread
);
322 InterlockedDecrement(&worker_free
);
323 InterlockedDecrement(&worker_count
);
328 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
330 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
336 TRACE("(%p)\n", conn
);
339 /* read packet header */
340 #ifdef OVERLAPPED_WORKS
341 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, &conn
->ovl
)) {
342 DWORD err
= GetLastError();
343 if (err
!= ERROR_IO_PENDING
) {
344 TRACE("connection lost, error=%08lx\n", err
);
347 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
350 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, NULL
)) {
351 TRACE("connection lost, error=%08lx\n", GetLastError());
355 if (dwRead
!= sizeof(hdr
)) {
356 if (dwRead
) TRACE("protocol error: <hdrsz == %d, dwRead == %lu>\n", sizeof(hdr
), dwRead
);
360 /* read packet body */
361 buf
= HeapAlloc(GetProcessHeap(), 0, hdr
.len
);
362 TRACE("receiving payload=%d\n", hdr
.len
);
363 if (!hdr
.len
) dwRead
= 0; else
364 #ifdef OVERLAPPED_WORKS
365 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, &conn
->ovl
)) {
366 DWORD err
= GetLastError();
367 if (err
!= ERROR_IO_PENDING
) {
368 TRACE("connection lost, error=%08lx\n", err
);
371 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
374 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, NULL
)) {
375 TRACE("connection lost, error=%08lx\n", GetLastError());
379 if (dwRead
!= hdr
.len
) {
380 TRACE("protocol error: <bodylen == %d, dwRead == %lu>\n", hdr
.len
, dwRead
);
385 RPCRT4_process_packet(conn
, &hdr
, buf
);
387 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
391 RPCRT4_create_worker_if_needed();
392 RPCRT4_push_packet(packet
);
393 ReleaseSemaphore(server_sem
, 1, NULL
);
397 if (buf
) HeapFree(GetProcessHeap(), 0, buf
);
398 RPCRT4_DestroyConnection(conn
);
402 static void RPCRT4_new_client(RpcConnection
* conn
)
404 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
406 DWORD err
= GetLastError();
407 ERR("failed to create thread, error=%08lx\n", err
);
408 RPCRT4_DestroyConnection(conn
);
410 /* we could set conn->thread, but then we'd have to make the io_thread wait
411 * for that, otherwise the thread might finish, destroy the connection, and
412 * free the memory we'd write to before we did, causing crashes and stuff -
413 * so let's implement that later, when we really need conn->thread */
415 CloseHandle( thread
);
418 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
420 HANDLE m_event
= mgr_event
, b_handle
;
423 RpcServerProtseq
* cps
;
425 RpcConnection
* cconn
;
427 TRACE("(the_arg == ^%p)\n", the_arg
);
430 EnterCriticalSection(&server_cs
);
431 /* open and count connections */
437 RPCRT4_OpenConnection(conn
);
438 if (conn
->ovl
.hEvent
) count
++;
443 /* make array of connections */
445 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
447 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
455 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
460 LeaveCriticalSection(&server_cs
);
463 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
464 if (res
== WAIT_OBJECT_0
) {
466 if (!std_listen
) break;
468 else if (res
== WAIT_FAILED
) {
469 ERR("wait failed\n");
472 b_handle
= objs
[res
- WAIT_OBJECT_0
];
473 /* find which connection got a RPC */
474 EnterCriticalSection(&server_cs
);
480 if (conn
->ovl
.hEvent
== b_handle
) break;
487 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
488 LeaveCriticalSection(&server_cs
);
490 ERR("failed to locate connection for handle %p\n", b_handle
);
492 if (cconn
) RPCRT4_new_client(cconn
);
495 HeapFree(GetProcessHeap(), 0, objs
);
496 EnterCriticalSection(&server_cs
);
497 /* close connections */
502 RPCRT4_CloseConnection(conn
);
507 LeaveCriticalSection(&server_cs
);
511 static void RPCRT4_start_listen(void)
515 EnterCriticalSection(&listen_cs
);
516 if (! ++listen_count
) {
517 if (!mgr_event
) mgr_event
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
518 if (!server_sem
) server_sem
= CreateSemaphoreA(NULL
, 0, MAX_THREADS
, NULL
);
519 if (!worker_tls
) worker_tls
= TlsAlloc();
521 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
522 LeaveCriticalSection(&listen_cs
);
524 LeaveCriticalSection(&listen_cs
);
529 static void RPCRT4_stop_listen(void)
531 EnterCriticalSection(&listen_cs
);
532 if (listen_count
== -1)
533 LeaveCriticalSection(&listen_cs
);
534 else if (--listen_count
== -1) {
536 LeaveCriticalSection(&listen_cs
);
539 LeaveCriticalSection(&listen_cs
);
540 assert(listen_count
> -2);
543 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
545 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
547 EnterCriticalSection(&server_cs
);
550 LeaveCriticalSection(&server_cs
);
552 if (std_listen
) SetEvent(mgr_event
);
557 /***********************************************************************
558 * RpcServerInqBindings (RPCRT4.@)
560 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
564 RpcServerProtseq
* ps
;
568 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
570 ERR("(BindingVector == NULL!!?)\n");
572 EnterCriticalSection(&server_cs
);
573 /* count connections */
585 /* export bindings */
586 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
587 sizeof(RPC_BINDING_VECTOR
) +
588 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
589 (*BindingVector
)->Count
= count
;
595 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
604 *BindingVector
= NULL
;
605 status
= RPC_S_NO_BINDINGS
;
607 LeaveCriticalSection(&server_cs
);
611 /***********************************************************************
612 * RpcServerUseProtseqEpA (RPCRT4.@)
614 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
)
618 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
620 /* This should provide the default behaviour */
621 policy
.Length
= sizeof( policy
);
622 policy
.EndpointFlags
= 0;
625 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
628 /***********************************************************************
629 * RpcServerUseProtseqEpW (RPCRT4.@)
631 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
635 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
637 /* This should provide the default behaviour */
638 policy
.Length
= sizeof( policy
);
639 policy
.EndpointFlags
= 0;
642 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
645 /***********************************************************************
646 * RpcServerUseProtseqEpExA (RPCRT4.@)
648 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
,
649 PRPC_POLICY lpPolicy
)
651 RpcServerProtseq
* ps
;
653 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
654 debugstr_a( Endpoint
), SecurityDescriptor
,
655 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
657 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
658 ps
->MaxCalls
= MaxCalls
;
659 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
660 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
662 return RPCRT4_use_protseq(ps
);
665 /***********************************************************************
666 * RpcServerUseProtseqEpExW (RPCRT4.@)
668 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
669 PRPC_POLICY lpPolicy
)
671 RpcServerProtseq
* ps
;
673 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
674 debugstr_w( Endpoint
), SecurityDescriptor
,
675 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
677 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
678 ps
->MaxCalls
= MaxCalls
;
679 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
680 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
682 return RPCRT4_use_protseq(ps
);
685 /***********************************************************************
686 * RpcServerUseProtseqA (RPCRT4.@)
688 RPC_STATUS WINAPI
RpcServerUseProtseqA(LPSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
690 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
691 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
694 /***********************************************************************
695 * RpcServerUseProtseqW (RPCRT4.@)
697 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
699 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
700 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
703 /***********************************************************************
704 * RpcServerRegisterIf (RPCRT4.@)
706 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
708 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
709 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
712 /***********************************************************************
713 * RpcServerRegisterIfEx (RPCRT4.@)
715 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
716 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
718 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
719 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
722 /***********************************************************************
723 * RpcServerRegisterIf2 (RPCRT4.@)
725 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
726 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
728 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
729 RpcServerInterface
* sif
;
732 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
733 MaxRpcSize
, IfCallbackFn
);
734 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
735 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
736 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
737 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
738 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
739 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
740 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
741 if (If
->DispatchTable
) {
742 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
743 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
744 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
746 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
748 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
749 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
750 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
751 TRACE(" flags: %08x\n", If
->Flags
);
753 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
756 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
757 sif
->MgrEpv
= MgrEpv
;
759 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
760 sif
->MgrEpv
= If
->DefaultManagerEpv
;
763 sif
->MaxCalls
= MaxCalls
;
764 sif
->MaxRpcSize
= MaxRpcSize
;
765 sif
->IfCallbackFn
= IfCallbackFn
;
767 EnterCriticalSection(&server_cs
);
770 LeaveCriticalSection(&server_cs
);
772 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
773 /* well, start listening, I think... */
774 RPCRT4_start_listen();
780 /***********************************************************************
781 * RpcServerUnregisterIf (RPCRT4.@)
783 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
785 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
786 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
791 /***********************************************************************
792 * RpcServerUnregisterIfEx (RPCRT4.@)
794 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
796 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
797 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
802 /***********************************************************************
803 * RpcObjectSetType (RPCRT4.@)
806 * ObjUuid [I] "Object" UUID
807 * TypeUuid [I] "Type" UUID
810 * RPC_S_OK The call succeeded
811 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
812 * RPC_S_ALREADY_REGISTERED The provided object is already registered
814 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
815 * resets the mapping for the specified object UUID to nil (the default).
816 * The nil object is always associated with the nil type and cannot be
817 * reassigned. Servers can support multiple implementations on the same
818 * interface by registering different end-point vectors for the different
819 * types. There's no need to call this if a server only supports the nil
820 * type, as is typical.
822 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
824 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
827 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
828 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
829 /* nil uuid cannot be remapped */
830 return RPC_S_INVALID_OBJECT
;
833 /* find the mapping for this object if there is one ... */
835 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
839 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
840 /* ... and drop it from the list */
843 prev
->next
= map
->next
;
845 RpcObjTypeMaps
= map
->next
;
846 HeapFree(GetProcessHeap(), 0, map
);
849 /* ... , fail if we found it ... */
851 return RPC_S_ALREADY_REGISTERED
;
852 /* ... otherwise create a new one and add it in. */
853 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
854 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
855 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
858 prev
->next
= map
; /* prev is the last map in the linklist */
860 RpcObjTypeMaps
= map
;
866 /***********************************************************************
867 * RpcServerRegisterAuthInfoA (RPCRT4.@)
869 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( LPSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
872 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
874 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
877 /***********************************************************************
878 * RpcServerRegisterAuthInfoW (RPCRT4.@)
880 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
883 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
885 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
888 /***********************************************************************
889 * RpcServerListen (RPCRT4.@)
891 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
893 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
896 return RPC_S_NO_PROTSEQS_REGISTERED
;
898 EnterCriticalSection(&listen_cs
);
901 LeaveCriticalSection(&listen_cs
);
902 return RPC_S_ALREADY_LISTENING
;
905 RPCRT4_start_listen();
907 LeaveCriticalSection(&listen_cs
);
909 if (DontWait
) return RPC_S_OK
;
911 return RpcMgmtWaitServerListen();
914 /***********************************************************************
915 * RpcMgmtServerWaitListen (RPCRT4.@)
917 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
919 RPC_STATUS rslt
= RPC_S_OK
;
923 EnterCriticalSection(&listen_cs
);
926 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
927 LeaveCriticalSection(&listen_cs
);
931 LeaveCriticalSection(&listen_cs
);
934 WaitForSingleObject(mgr_event
, INFINITE
);
936 Sleep(100); /* don't spin violently */
937 TRACE("spinning.\n");
944 /***********************************************************************
945 * RpcMgmtStopServerListening (RPCRT4.@)
947 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
949 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
952 FIXME("client-side invocation not implemented.\n");
953 return RPC_S_WRONG_KIND_OF_BINDING
;
957 EnterCriticalSection(&listen_cs
);
959 RPCRT4_stop_listen();
960 LeaveCriticalSection(&listen_cs
);
965 /***********************************************************************
966 * I_RpcServerStartListening (RPCRT4.@)
968 RPC_STATUS WINAPI
I_RpcServerStartListening( void* hWnd
)
970 FIXME( "(%p): stub\n", hWnd
);
975 /***********************************************************************
976 * I_RpcServerStopListening (RPCRT4.@)
978 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
980 FIXME( "(): stub\n" );
985 /***********************************************************************
986 * I_RpcWindowProc (RPCRT4.@)
988 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
990 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);