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
;
181 static WINE_EXCEPTION_FILTER(rpc_filter
)
184 msg
= TlsGetValue(worker_tls
);
185 I_RpcFreeBuffer(msg
);
186 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
187 msg
->BufferLength
= sizeof(DWORD
);
189 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
190 return EXCEPTION_EXECUTE_HANDLER
;
193 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, void* buf
)
197 RpcServerInterface
* sif
;
198 RPC_DISPATCH_FUNCTION func
;
200 TlsSetValue(worker_tls
, &msg
);
201 memset(&msg
, 0, sizeof(msg
));
202 msg
.BufferLength
= hdr
->len
;
204 sif
= RPCRT4_find_interface(&hdr
->object
, &hdr
->if_id
);
206 TRACE("packet received for interface %s\n", debugstr_guid(&hdr
->if_id
));
207 msg
.RpcInterfaceInformation
= sif
->If
;
208 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
209 msg
.ManagerEpv
= sif
->MgrEpv
;
210 /* create temporary binding for dispatch */
211 RPCRT4_MakeBinding(&pbind
, conn
);
212 RPCRT4_SetBindingObject(pbind
, &hdr
->object
);
213 msg
.Handle
= (RPC_BINDING_HANDLE
)pbind
;
215 switch (hdr
->ptype
) {
217 /* find dispatch function */
218 msg
.ProcNum
= hdr
->opnum
;
219 if (sif
->Flags
& RPC_IF_OLE
) {
220 /* native ole32 always gives us a dispatch table with a single entry
221 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
222 func
= *sif
->If
->DispatchTable
->DispatchTable
;
224 if (msg
.ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
225 ERR("invalid procnum\n");
228 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
.ProcNum
];
231 /* put in the drep. FIXME: is this more universally applicable?
232 perhaps we should move this outward... */
233 msg
.DataRepresentation
=
234 MAKELONG( MAKEWORD(hdr
->drep
[0], hdr
->drep
[1]),
235 MAKEWORD(hdr
->drep
[2], 0));
239 if (func
) func(&msg
);
240 } __EXCEPT(rpc_filter
) {
241 /* failure packet was created in rpc_filter */
242 TRACE("exception caught, returning failure packet\n");
245 /* send response packet */
249 ERR("unknown packet type\n");
253 RPCRT4_DestroyBinding(pbind
);
255 msg
.RpcInterfaceInformation
= NULL
;
258 ERR("got RPC packet to unregistered interface %s\n", debugstr_guid(&hdr
->if_id
));
262 if (msg
.Buffer
== buf
) msg
.Buffer
= NULL
;
263 TRACE("freeing Buffer=%p\n", buf
);
264 HeapFree(GetProcessHeap(), 0, buf
);
265 I_RpcFreeBuffer(&msg
);
267 TlsSetValue(worker_tls
, NULL
);
270 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
276 /* idle timeout after 5s */
277 obj
= WaitForSingleObject(server_sem
, 5000);
278 if (obj
== WAIT_TIMEOUT
) {
279 /* if another idle thread exist, self-destruct */
280 if (worker_free
> 1) break;
283 pkt
= RPCRT4_pop_packet();
285 InterlockedDecrement(&worker_free
);
287 RPCRT4_process_packet(pkt
->conn
, &pkt
->hdr
, pkt
->buf
);
288 HeapFree(GetProcessHeap(), 0, pkt
);
289 /* try to grab another packet here without waiting
290 * on the semaphore, in case it hits max */
291 pkt
= RPCRT4_pop_packet();
293 /* decrement semaphore */
294 WaitForSingleObject(server_sem
, 0);
296 InterlockedIncrement(&worker_free
);
298 InterlockedDecrement(&worker_free
);
299 InterlockedDecrement(&worker_count
);
303 static void RPCRT4_create_worker_if_needed(void)
305 if (!worker_free
&& worker_count
< MAX_THREADS
) {
307 InterlockedIncrement(&worker_count
);
308 InterlockedIncrement(&worker_free
);
309 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
310 if (thread
) CloseHandle(thread
);
312 InterlockedDecrement(&worker_free
);
313 InterlockedDecrement(&worker_count
);
318 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
320 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
326 TRACE("(%p)\n", conn
);
329 /* read packet header */
330 #ifdef OVERLAPPED_WORKS
331 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, &conn
->ovl
)) {
332 DWORD err
= GetLastError();
333 if (err
!= ERROR_IO_PENDING
) {
334 TRACE("connection lost, error=%08lx\n", err
);
337 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
340 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, NULL
)) {
341 TRACE("connection lost, error=%08lx\n", GetLastError());
345 if (dwRead
!= sizeof(hdr
)) {
346 if (dwRead
) TRACE("protocol error: <hdrsz == %d, dwRead == %lu>\n", sizeof(hdr
), dwRead
);
350 /* read packet body */
351 buf
= HeapAlloc(GetProcessHeap(), 0, hdr
.len
);
352 TRACE("receiving payload=%d\n", hdr
.len
);
353 if (!hdr
.len
) dwRead
= 0; else
354 #ifdef OVERLAPPED_WORKS
355 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, &conn
->ovl
)) {
356 DWORD err
= GetLastError();
357 if (err
!= ERROR_IO_PENDING
) {
358 TRACE("connection lost, error=%08lx\n", err
);
361 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
364 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, NULL
)) {
365 TRACE("connection lost, error=%08lx\n", GetLastError());
369 if (dwRead
!= hdr
.len
) {
370 TRACE("protocol error: <bodylen == %d, dwRead == %lu>\n", hdr
.len
, dwRead
);
375 RPCRT4_process_packet(conn
, &hdr
, buf
);
377 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
381 RPCRT4_create_worker_if_needed();
382 RPCRT4_push_packet(packet
);
383 ReleaseSemaphore(server_sem
, 1, NULL
);
387 if (buf
) HeapFree(GetProcessHeap(), 0, buf
);
388 RPCRT4_DestroyConnection(conn
);
392 static void RPCRT4_new_client(RpcConnection
* conn
)
394 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
396 DWORD err
= GetLastError();
397 ERR("failed to create thread, error=%08lx\n", err
);
398 RPCRT4_DestroyConnection(conn
);
400 /* we could set conn->thread, but then we'd have to make the io_thread wait
401 * for that, otherwise the thread might finish, destroy the connection, and
402 * free the memory we'd write to before we did, causing crashes and stuff -
403 * so let's implement that later, when we really need conn->thread */
405 CloseHandle( thread
);
408 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
410 HANDLE m_event
= mgr_event
, b_handle
;
413 RpcServerProtseq
* cps
;
415 RpcConnection
* cconn
;
417 TRACE("(the_arg == ^%p)\n", the_arg
);
420 EnterCriticalSection(&server_cs
);
421 /* open and count connections */
427 RPCRT4_OpenConnection(conn
);
428 if (conn
->ovl
.hEvent
) count
++;
433 /* make array of connections */
435 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
437 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
445 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
450 LeaveCriticalSection(&server_cs
);
453 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
454 if (res
== WAIT_OBJECT_0
) {
456 if (!std_listen
) break;
458 else if (res
== WAIT_FAILED
) {
459 ERR("wait failed\n");
462 b_handle
= objs
[res
- WAIT_OBJECT_0
];
463 /* find which connection got a RPC */
464 EnterCriticalSection(&server_cs
);
470 if (conn
->ovl
.hEvent
== b_handle
) break;
477 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
478 LeaveCriticalSection(&server_cs
);
480 ERR("failed to locate connection for handle %p\n", b_handle
);
482 if (cconn
) RPCRT4_new_client(cconn
);
485 HeapFree(GetProcessHeap(), 0, objs
);
486 EnterCriticalSection(&server_cs
);
487 /* close connections */
492 RPCRT4_CloseConnection(conn
);
497 LeaveCriticalSection(&server_cs
);
501 static void RPCRT4_start_listen(void)
505 EnterCriticalSection(&listen_cs
);
506 if (! ++listen_count
) {
507 if (!mgr_event
) mgr_event
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
508 if (!server_sem
) server_sem
= CreateSemaphoreA(NULL
, 0, MAX_THREADS
, NULL
);
509 if (!worker_tls
) worker_tls
= TlsAlloc();
511 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
512 LeaveCriticalSection(&listen_cs
);
514 LeaveCriticalSection(&listen_cs
);
519 static void RPCRT4_stop_listen(void)
521 EnterCriticalSection(&listen_cs
);
522 if (listen_count
== -1)
523 LeaveCriticalSection(&listen_cs
);
524 else if (--listen_count
== -1) {
526 LeaveCriticalSection(&listen_cs
);
529 LeaveCriticalSection(&listen_cs
);
530 assert(listen_count
> -2);
533 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
535 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
537 EnterCriticalSection(&server_cs
);
540 LeaveCriticalSection(&server_cs
);
542 if (std_listen
) SetEvent(mgr_event
);
547 /***********************************************************************
548 * RpcServerInqBindings (RPCRT4.@)
550 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
554 RpcServerProtseq
* ps
;
558 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
560 ERR("(BindingVector == NULL!!?)\n");
562 EnterCriticalSection(&server_cs
);
563 /* count connections */
575 /* export bindings */
576 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
577 sizeof(RPC_BINDING_VECTOR
) +
578 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
579 (*BindingVector
)->Count
= count
;
585 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
594 *BindingVector
= NULL
;
595 status
= RPC_S_NO_BINDINGS
;
597 LeaveCriticalSection(&server_cs
);
601 /***********************************************************************
602 * RpcServerUseProtseqEpA (RPCRT4.@)
604 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
)
608 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
610 /* This should provide the default behaviour */
611 policy
.Length
= sizeof( policy
);
612 policy
.EndpointFlags
= 0;
615 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
618 /***********************************************************************
619 * RpcServerUseProtseqEpW (RPCRT4.@)
621 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
625 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
627 /* This should provide the default behaviour */
628 policy
.Length
= sizeof( policy
);
629 policy
.EndpointFlags
= 0;
632 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
635 /***********************************************************************
636 * RpcServerUseProtseqEpExA (RPCRT4.@)
638 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
,
639 PRPC_POLICY lpPolicy
)
641 RpcServerProtseq
* ps
;
643 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
644 debugstr_a( Endpoint
), SecurityDescriptor
,
645 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
647 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
648 ps
->MaxCalls
= MaxCalls
;
649 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
650 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
652 return RPCRT4_use_protseq(ps
);
655 /***********************************************************************
656 * RpcServerUseProtseqEpExW (RPCRT4.@)
658 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
659 PRPC_POLICY lpPolicy
)
661 RpcServerProtseq
* ps
;
663 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
664 debugstr_w( Endpoint
), SecurityDescriptor
,
665 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
667 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
668 ps
->MaxCalls
= MaxCalls
;
669 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
670 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
672 return RPCRT4_use_protseq(ps
);
675 /***********************************************************************
676 * RpcServerUseProtseqA (RPCRT4.@)
678 RPC_STATUS WINAPI
RpcServerUseProtseqA(LPSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
680 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
681 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
684 /***********************************************************************
685 * RpcServerUseProtseqW (RPCRT4.@)
687 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
689 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
690 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
693 /***********************************************************************
694 * RpcServerRegisterIf (RPCRT4.@)
696 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
698 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
699 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
702 /***********************************************************************
703 * RpcServerRegisterIfEx (RPCRT4.@)
705 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
706 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
708 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
709 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
712 /***********************************************************************
713 * RpcServerRegisterIf2 (RPCRT4.@)
715 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
716 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
718 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
719 RpcServerInterface
* sif
;
722 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
723 MaxRpcSize
, IfCallbackFn
);
724 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
725 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
726 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
727 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
728 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
729 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
730 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
731 if (If
->DispatchTable
) {
732 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
733 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
734 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
736 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
738 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
739 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
740 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
741 TRACE(" flags: %08x\n", If
->Flags
);
743 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
746 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
747 sif
->MgrEpv
= MgrEpv
;
749 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
750 sif
->MgrEpv
= If
->DefaultManagerEpv
;
753 sif
->MaxCalls
= MaxCalls
;
754 sif
->MaxRpcSize
= MaxRpcSize
;
755 sif
->IfCallbackFn
= IfCallbackFn
;
757 EnterCriticalSection(&server_cs
);
760 LeaveCriticalSection(&server_cs
);
762 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
763 /* well, start listening, I think... */
764 RPCRT4_start_listen();
770 /***********************************************************************
771 * RpcServerUnregisterIf (RPCRT4.@)
773 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
775 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
776 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
781 /***********************************************************************
782 * RpcServerUnregisterIfEx (RPCRT4.@)
784 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
786 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
787 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
792 /***********************************************************************
793 * RpcObjectSetType (RPCRT4.@)
796 * ObjUuid [I] "Object" UUID
797 * TypeUuid [I] "Type" UUID
800 * RPC_S_OK The call succeeded
801 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
802 * RPC_S_ALREADY_REGISTERED The provided object is already registered
804 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
805 * resets the mapping for the specified object UUID to nil (the default).
806 * The nil object is always associated with the nil type and cannot be
807 * reassigned. Servers can support multiple implementations on the same
808 * interface by registering different end-point vectors for the different
809 * types. There's no need to call this if a server only supports the nil
810 * type, as is typical.
812 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
814 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
817 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
818 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
819 /* nil uuid cannot be remapped */
820 return RPC_S_INVALID_OBJECT
;
823 /* find the mapping for this object if there is one ... */
825 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
829 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
830 /* ... and drop it from the list */
833 prev
->next
= map
->next
;
835 RpcObjTypeMaps
= map
->next
;
836 HeapFree(GetProcessHeap(), 0, map
);
839 /* ... , fail if we found it ... */
841 return RPC_S_ALREADY_REGISTERED
;
842 /* ... otherwise create a new one and add it in. */
843 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
844 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
845 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
848 prev
->next
= map
; /* prev is the last map in the linklist */
850 RpcObjTypeMaps
= map
;
856 /***********************************************************************
857 * RpcServerRegisterAuthInfoA (RPCRT4.@)
859 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( LPSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
862 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
864 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
867 /***********************************************************************
868 * RpcServerRegisterAuthInfoW (RPCRT4.@)
870 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
873 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
875 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
878 /***********************************************************************
879 * RpcServerListen (RPCRT4.@)
881 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
883 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
886 return RPC_S_NO_PROTSEQS_REGISTERED
;
888 EnterCriticalSection(&listen_cs
);
891 LeaveCriticalSection(&listen_cs
);
892 return RPC_S_ALREADY_LISTENING
;
895 RPCRT4_start_listen();
897 LeaveCriticalSection(&listen_cs
);
899 if (DontWait
) return RPC_S_OK
;
901 return RpcMgmtWaitServerListen();
904 /***********************************************************************
905 * RpcMgmtServerWaitListen (RPCRT4.@)
907 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
909 RPC_STATUS rslt
= RPC_S_OK
;
913 EnterCriticalSection(&listen_cs
);
916 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
917 LeaveCriticalSection(&listen_cs
);
921 LeaveCriticalSection(&listen_cs
);
924 WaitForSingleObject(mgr_event
, INFINITE
);
926 Sleep(100); /* don't spin violently */
927 TRACE("spinning.\n");
934 /***********************************************************************
935 * RpcMgmtStopServerListening (RPCRT4.@)
937 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
939 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
942 FIXME("client-side invocation not implemented.\n");
943 return RPC_S_WRONG_KIND_OF_BINDING
;
947 EnterCriticalSection(&listen_cs
);
949 RPCRT4_stop_listen();
950 LeaveCriticalSection(&listen_cs
);
955 /***********************************************************************
956 * I_RpcServerStartListening (RPCRT4.@)
958 RPC_STATUS WINAPI
I_RpcServerStartListening( void* hWnd
)
960 FIXME( "(%p): stub\n", hWnd
);
965 /***********************************************************************
966 * I_RpcServerStopListening (RPCRT4.@)
968 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
970 FIXME( "(): stub\n" );
975 /***********************************************************************
976 * I_RpcWindowProc (RPCRT4.@)
978 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
980 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);