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 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
198 TRACE("returning failure packet\n");
199 return EXCEPTION_EXECUTE_HANDLER
;
202 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, void* buf
)
206 RpcServerInterface
* sif
;
207 RPC_DISPATCH_FUNCTION func
;
212 TlsSetValue(worker_tls
, &state
);
213 memset(&msg
, 0, sizeof(msg
));
214 msg
.BufferLength
= hdr
->len
;
216 sif
= RPCRT4_find_interface(&hdr
->object
, &hdr
->if_id
);
218 TRACE("packet received for interface %s\n", debugstr_guid(&hdr
->if_id
));
219 msg
.RpcInterfaceInformation
= sif
->If
;
220 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
221 msg
.ManagerEpv
= sif
->MgrEpv
;
222 /* create temporary binding for dispatch */
223 RPCRT4_MakeBinding(&pbind
, conn
);
224 RPCRT4_SetBindingObject(pbind
, &hdr
->object
);
225 msg
.Handle
= (RPC_BINDING_HANDLE
)pbind
;
227 switch (hdr
->ptype
) {
229 /* find dispatch function */
230 msg
.ProcNum
= hdr
->opnum
;
231 if (sif
->Flags
& RPC_IF_OLE
) {
232 /* native ole32 always gives us a dispatch table with a single entry
233 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
234 func
= *sif
->If
->DispatchTable
->DispatchTable
;
236 if (msg
.ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
237 ERR("invalid procnum\n");
240 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
.ProcNum
];
243 /* put in the drep. FIXME: is this more universally applicable?
244 perhaps we should move this outward... */
245 msg
.DataRepresentation
=
246 MAKELONG( MAKEWORD(hdr
->drep
[0], hdr
->drep
[1]),
247 MAKEWORD(hdr
->drep
[2], 0));
251 if (func
) func(&msg
);
252 } __EXCEPT(rpc_filter
) {
253 /* failure packet was created in rpc_filter */
256 /* send response packet */
260 ERR("unknown packet type\n");
264 RPCRT4_DestroyBinding(pbind
);
266 msg
.RpcInterfaceInformation
= NULL
;
269 ERR("got RPC packet to unregistered interface %s\n", debugstr_guid(&hdr
->if_id
));
273 if (msg
.Buffer
== buf
) msg
.Buffer
= NULL
;
274 TRACE("freeing Buffer=%p\n", buf
);
275 HeapFree(GetProcessHeap(), 0, buf
);
276 I_RpcFreeBuffer(&msg
);
278 TlsSetValue(worker_tls
, NULL
);
281 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
287 /* idle timeout after 5s */
288 obj
= WaitForSingleObject(server_sem
, 5000);
289 if (obj
== WAIT_TIMEOUT
) {
290 /* if another idle thread exist, self-destruct */
291 if (worker_free
> 1) break;
294 pkt
= RPCRT4_pop_packet();
296 InterlockedDecrement(&worker_free
);
298 RPCRT4_process_packet(pkt
->conn
, &pkt
->hdr
, pkt
->buf
);
299 HeapFree(GetProcessHeap(), 0, pkt
);
300 /* try to grab another packet here without waiting
301 * on the semaphore, in case it hits max */
302 pkt
= RPCRT4_pop_packet();
304 /* decrement semaphore */
305 WaitForSingleObject(server_sem
, 0);
307 InterlockedIncrement(&worker_free
);
309 InterlockedDecrement(&worker_free
);
310 InterlockedDecrement(&worker_count
);
314 static void RPCRT4_create_worker_if_needed(void)
316 if (!worker_free
&& worker_count
< MAX_THREADS
) {
318 InterlockedIncrement(&worker_count
);
319 InterlockedIncrement(&worker_free
);
320 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
321 if (thread
) CloseHandle(thread
);
323 InterlockedDecrement(&worker_free
);
324 InterlockedDecrement(&worker_count
);
329 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
331 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
337 TRACE("(%p)\n", conn
);
340 /* read packet header */
341 #ifdef OVERLAPPED_WORKS
342 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, &conn
->ovl
)) {
343 DWORD err
= GetLastError();
344 if (err
!= ERROR_IO_PENDING
) {
345 TRACE("connection lost, error=%08lx\n", err
);
348 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
351 if (!ReadFile(conn
->conn
, &hdr
, sizeof(hdr
), &dwRead
, NULL
)) {
352 TRACE("connection lost, error=%08lx\n", GetLastError());
356 if (dwRead
!= sizeof(hdr
)) {
357 if (dwRead
) TRACE("protocol error: <hdrsz == %d, dwRead == %lu>\n", sizeof(hdr
), dwRead
);
361 /* read packet body */
362 buf
= HeapAlloc(GetProcessHeap(), 0, hdr
.len
);
363 TRACE("receiving payload=%d\n", hdr
.len
);
364 if (!hdr
.len
) dwRead
= 0; else
365 #ifdef OVERLAPPED_WORKS
366 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, &conn
->ovl
)) {
367 DWORD err
= GetLastError();
368 if (err
!= ERROR_IO_PENDING
) {
369 TRACE("connection lost, error=%08lx\n", err
);
372 if (!GetOverlappedResult(conn
->conn
, &conn
->ovl
, &dwRead
, TRUE
)) break;
375 if (!ReadFile(conn
->conn
, buf
, hdr
.len
, &dwRead
, NULL
)) {
376 TRACE("connection lost, error=%08lx\n", GetLastError());
380 if (dwRead
!= hdr
.len
) {
381 TRACE("protocol error: <bodylen == %d, dwRead == %lu>\n", hdr
.len
, dwRead
);
386 RPCRT4_process_packet(conn
, &hdr
, buf
);
388 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
392 RPCRT4_create_worker_if_needed();
393 RPCRT4_push_packet(packet
);
394 ReleaseSemaphore(server_sem
, 1, NULL
);
398 if (buf
) HeapFree(GetProcessHeap(), 0, buf
);
399 RPCRT4_DestroyConnection(conn
);
403 static void RPCRT4_new_client(RpcConnection
* conn
)
405 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
407 DWORD err
= GetLastError();
408 ERR("failed to create thread, error=%08lx\n", err
);
409 RPCRT4_DestroyConnection(conn
);
411 /* we could set conn->thread, but then we'd have to make the io_thread wait
412 * for that, otherwise the thread might finish, destroy the connection, and
413 * free the memory we'd write to before we did, causing crashes and stuff -
414 * so let's implement that later, when we really need conn->thread */
416 CloseHandle( thread
);
419 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
421 HANDLE m_event
= mgr_event
, b_handle
;
424 RpcServerProtseq
* cps
;
426 RpcConnection
* cconn
;
428 TRACE("(the_arg == ^%p)\n", the_arg
);
431 EnterCriticalSection(&server_cs
);
432 /* open and count connections */
438 RPCRT4_OpenConnection(conn
);
439 if (conn
->ovl
.hEvent
) count
++;
444 /* make array of connections */
446 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
448 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
456 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
461 LeaveCriticalSection(&server_cs
);
464 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
465 if (res
== WAIT_OBJECT_0
) {
467 if (!std_listen
) break;
469 else if (res
== WAIT_FAILED
) {
470 ERR("wait failed\n");
473 b_handle
= objs
[res
- WAIT_OBJECT_0
];
474 /* find which connection got a RPC */
475 EnterCriticalSection(&server_cs
);
481 if (conn
->ovl
.hEvent
== b_handle
) break;
488 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
489 LeaveCriticalSection(&server_cs
);
491 ERR("failed to locate connection for handle %p\n", b_handle
);
493 if (cconn
) RPCRT4_new_client(cconn
);
496 HeapFree(GetProcessHeap(), 0, objs
);
497 EnterCriticalSection(&server_cs
);
498 /* close connections */
503 RPCRT4_CloseConnection(conn
);
508 LeaveCriticalSection(&server_cs
);
512 static void RPCRT4_start_listen(void)
516 EnterCriticalSection(&listen_cs
);
517 if (! ++listen_count
) {
518 if (!mgr_event
) mgr_event
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
519 if (!server_sem
) server_sem
= CreateSemaphoreA(NULL
, 0, MAX_THREADS
, NULL
);
520 if (!worker_tls
) worker_tls
= TlsAlloc();
522 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
523 LeaveCriticalSection(&listen_cs
);
525 LeaveCriticalSection(&listen_cs
);
530 static void RPCRT4_stop_listen(void)
532 EnterCriticalSection(&listen_cs
);
533 if (listen_count
== -1)
534 LeaveCriticalSection(&listen_cs
);
535 else if (--listen_count
== -1) {
537 LeaveCriticalSection(&listen_cs
);
540 LeaveCriticalSection(&listen_cs
);
541 assert(listen_count
> -2);
544 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
546 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
548 EnterCriticalSection(&server_cs
);
551 LeaveCriticalSection(&server_cs
);
553 if (std_listen
) SetEvent(mgr_event
);
558 /***********************************************************************
559 * RpcServerInqBindings (RPCRT4.@)
561 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
565 RpcServerProtseq
* ps
;
569 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
571 ERR("(BindingVector == NULL!!?)\n");
573 EnterCriticalSection(&server_cs
);
574 /* count connections */
586 /* export bindings */
587 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
588 sizeof(RPC_BINDING_VECTOR
) +
589 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
590 (*BindingVector
)->Count
= count
;
596 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
605 *BindingVector
= NULL
;
606 status
= RPC_S_NO_BINDINGS
;
608 LeaveCriticalSection(&server_cs
);
612 /***********************************************************************
613 * RpcServerUseProtseqEpA (RPCRT4.@)
615 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
)
619 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
621 /* This should provide the default behaviour */
622 policy
.Length
= sizeof( policy
);
623 policy
.EndpointFlags
= 0;
626 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
629 /***********************************************************************
630 * RpcServerUseProtseqEpW (RPCRT4.@)
632 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
636 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
638 /* This should provide the default behaviour */
639 policy
.Length
= sizeof( policy
);
640 policy
.EndpointFlags
= 0;
643 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
646 /***********************************************************************
647 * RpcServerUseProtseqEpExA (RPCRT4.@)
649 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( LPSTR Protseq
, UINT MaxCalls
, LPSTR Endpoint
, LPVOID SecurityDescriptor
,
650 PRPC_POLICY lpPolicy
)
652 RpcServerProtseq
* ps
;
654 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
655 debugstr_a( Endpoint
), SecurityDescriptor
,
656 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
658 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
659 ps
->MaxCalls
= MaxCalls
;
660 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
661 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
663 return RPCRT4_use_protseq(ps
);
666 /***********************************************************************
667 * RpcServerUseProtseqEpExW (RPCRT4.@)
669 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
670 PRPC_POLICY lpPolicy
)
672 RpcServerProtseq
* ps
;
674 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
675 debugstr_w( Endpoint
), SecurityDescriptor
,
676 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
678 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
679 ps
->MaxCalls
= MaxCalls
;
680 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
681 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
683 return RPCRT4_use_protseq(ps
);
686 /***********************************************************************
687 * RpcServerUseProtseqA (RPCRT4.@)
689 RPC_STATUS WINAPI
RpcServerUseProtseqA(LPSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
691 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
692 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
695 /***********************************************************************
696 * RpcServerUseProtseqW (RPCRT4.@)
698 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
700 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
701 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
704 /***********************************************************************
705 * RpcServerRegisterIf (RPCRT4.@)
707 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
709 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
710 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
713 /***********************************************************************
714 * RpcServerRegisterIfEx (RPCRT4.@)
716 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
717 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
719 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
720 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
723 /***********************************************************************
724 * RpcServerRegisterIf2 (RPCRT4.@)
726 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
727 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
729 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
730 RpcServerInterface
* sif
;
733 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
734 MaxRpcSize
, IfCallbackFn
);
735 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
736 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
737 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
738 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
739 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
740 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
741 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
742 if (If
->DispatchTable
) {
743 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
744 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
745 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
747 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
749 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
750 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
751 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
752 TRACE(" flags: %08x\n", If
->Flags
);
754 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
757 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
758 sif
->MgrEpv
= MgrEpv
;
760 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
761 sif
->MgrEpv
= If
->DefaultManagerEpv
;
764 sif
->MaxCalls
= MaxCalls
;
765 sif
->MaxRpcSize
= MaxRpcSize
;
766 sif
->IfCallbackFn
= IfCallbackFn
;
768 EnterCriticalSection(&server_cs
);
771 LeaveCriticalSection(&server_cs
);
773 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
774 /* well, start listening, I think... */
775 RPCRT4_start_listen();
781 /***********************************************************************
782 * RpcServerUnregisterIf (RPCRT4.@)
784 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
786 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
787 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
792 /***********************************************************************
793 * RpcServerUnregisterIfEx (RPCRT4.@)
795 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
797 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
798 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
803 /***********************************************************************
804 * RpcObjectSetType (RPCRT4.@)
807 * ObjUuid [I] "Object" UUID
808 * TypeUuid [I] "Type" UUID
811 * RPC_S_OK The call succeeded
812 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
813 * RPC_S_ALREADY_REGISTERED The provided object is already registered
815 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
816 * resets the mapping for the specified object UUID to nil (the default).
817 * The nil object is always associated with the nil type and cannot be
818 * reassigned. Servers can support multiple implementations on the same
819 * interface by registering different end-point vectors for the different
820 * types. There's no need to call this if a server only supports the nil
821 * type, as is typical.
823 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
825 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
828 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
829 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
830 /* nil uuid cannot be remapped */
831 return RPC_S_INVALID_OBJECT
;
834 /* find the mapping for this object if there is one ... */
836 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
840 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
841 /* ... and drop it from the list */
844 prev
->next
= map
->next
;
846 RpcObjTypeMaps
= map
->next
;
847 HeapFree(GetProcessHeap(), 0, map
);
850 /* ... , fail if we found it ... */
852 return RPC_S_ALREADY_REGISTERED
;
853 /* ... otherwise create a new one and add it in. */
854 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
855 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
856 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
859 prev
->next
= map
; /* prev is the last map in the linklist */
861 RpcObjTypeMaps
= map
;
867 /***********************************************************************
868 * RpcServerRegisterAuthInfoA (RPCRT4.@)
870 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( LPSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
873 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
875 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
878 /***********************************************************************
879 * RpcServerRegisterAuthInfoW (RPCRT4.@)
881 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
884 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
886 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
889 /***********************************************************************
890 * RpcServerListen (RPCRT4.@)
892 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
894 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
897 return RPC_S_NO_PROTSEQS_REGISTERED
;
899 EnterCriticalSection(&listen_cs
);
902 LeaveCriticalSection(&listen_cs
);
903 return RPC_S_ALREADY_LISTENING
;
906 RPCRT4_start_listen();
908 LeaveCriticalSection(&listen_cs
);
910 if (DontWait
) return RPC_S_OK
;
912 return RpcMgmtWaitServerListen();
915 /***********************************************************************
916 * RpcMgmtServerWaitListen (RPCRT4.@)
918 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
920 RPC_STATUS rslt
= RPC_S_OK
;
924 EnterCriticalSection(&listen_cs
);
927 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
928 LeaveCriticalSection(&listen_cs
);
932 LeaveCriticalSection(&listen_cs
);
935 WaitForSingleObject(mgr_event
, INFINITE
);
937 Sleep(100); /* don't spin violently */
938 TRACE("spinning.\n");
945 /***********************************************************************
946 * RpcMgmtStopServerListening (RPCRT4.@)
948 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
950 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
953 FIXME("client-side invocation not implemented.\n");
954 return RPC_S_WRONG_KIND_OF_BINDING
;
958 EnterCriticalSection(&listen_cs
);
960 RPCRT4_stop_listen();
961 LeaveCriticalSection(&listen_cs
);
966 /***********************************************************************
967 * I_RpcServerStartListening (RPCRT4.@)
969 RPC_STATUS WINAPI
I_RpcServerStartListening( void* hWnd
)
971 FIXME( "(%p): stub\n", hWnd
);
976 /***********************************************************************
977 * I_RpcServerStopListening (RPCRT4.@)
979 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
981 FIXME( "(): stub\n" );
986 /***********************************************************************
987 * I_RpcWindowProc (RPCRT4.@)
989 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
991 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);