4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2004 Filip Navara
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
43 #include "wine/debug.h"
44 #include "wine/exception.h"
46 #include "rpc_server.h"
48 #include "rpc_message.h"
51 #define MAX_THREADS 128
53 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
55 typedef struct _RpcPacket
57 struct _RpcPacket
* next
;
58 struct _RpcConnection
* conn
;
63 typedef struct _RpcObjTypeMap
65 /* FIXME: a hash table would be better. */
66 struct _RpcObjTypeMap
*next
;
71 static RpcObjTypeMap
*RpcObjTypeMaps
;
73 static RpcServerProtseq
* protseqs
;
74 static RpcServerInterface
* ifs
;
76 static CRITICAL_SECTION server_cs
;
77 static CRITICAL_SECTION_DEBUG server_cs_debug
=
80 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
81 0, 0, { 0, (DWORD
)(__FILE__
": server_cs") }
83 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
85 static CRITICAL_SECTION listen_cs
;
86 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
89 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
90 0, 0, { 0, (DWORD
)(__FILE__
": listen_cs") }
92 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
94 static BOOL std_listen
;
95 static LONG listen_count
= -1;
96 static HANDLE mgr_event
, server_thread
;
98 static CRITICAL_SECTION spacket_cs
;
99 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
102 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
103 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
105 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
107 static RpcPacket
* spacket_head
;
108 static RpcPacket
* spacket_tail
;
109 static HANDLE server_sem
;
111 static DWORD worker_count
, worker_free
, worker_tls
;
113 static UUID uuid_nil
;
115 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
117 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
121 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
128 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
130 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
137 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
138 RPC_SYNTAX_IDENTIFIER
* if_id
,
141 UUID
* MgrType
= NULL
;
142 RpcServerInterface
* cif
= NULL
;
146 MgrType
= LookupObjType(object
);
147 EnterCriticalSection(&server_cs
);
150 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
151 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
152 (std_listen
|| (cif
->Flags
& RPC_IF_AUTOLISTEN
))) break;
155 LeaveCriticalSection(&server_cs
);
156 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
160 static void RPCRT4_push_packet(RpcPacket
* packet
)
163 EnterCriticalSection(&spacket_cs
);
165 spacket_tail
->next
= packet
;
166 spacket_tail
= packet
;
168 spacket_head
= packet
;
169 spacket_tail
= packet
;
171 LeaveCriticalSection(&spacket_cs
);
174 static RpcPacket
* RPCRT4_pop_packet(void)
177 EnterCriticalSection(&spacket_cs
);
178 packet
= spacket_head
;
180 spacket_head
= packet
->next
;
181 if (!spacket_head
) spacket_tail
= NULL
;
183 LeaveCriticalSection(&spacket_cs
);
184 if (packet
) packet
->next
= NULL
;
194 static WINE_EXCEPTION_FILTER(rpc_filter
)
198 state
= TlsGetValue(worker_tls
);
200 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
201 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
202 msg
->BufferLength
= sizeof(DWORD
);
204 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
205 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
206 TRACE("returning failure packet\n");
207 return EXCEPTION_EXECUTE_HANDLER
;
211 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
213 RpcServerInterface
* sif
;
214 RPC_DISPATCH_FUNCTION func
;
220 void *buf
= msg
->Buffer
;
226 TlsSetValue(worker_tls
, &state
);
229 switch (hdr
->common
.ptype
) {
231 TRACE("got bind packet\n");
233 /* FIXME: do more checks! */
234 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
235 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
236 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
239 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
242 TRACE("rejecting bind request on connection %p\n", conn
);
243 /* Report failure to client. */
244 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
245 RPC_VER_MAJOR
, RPC_VER_MINOR
);
247 TRACE("accepting bind request on connection %p\n", conn
);
250 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
254 RESULT_ACCEPT
, NO_REASON
,
255 &sif
->If
->TransferSyntax
);
257 /* save the interface for later use */
258 conn
->ActiveInterface
= hdr
->bind
.abstract
;
259 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
262 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
268 TRACE("got request packet\n");
270 /* fail if the connection isn't bound with an interface */
271 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
272 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
275 RPCRT4_Send(conn
, response
, NULL
, 0);
279 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
280 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
285 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
286 msg
->RpcInterfaceInformation
= sif
->If
;
287 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
288 msg
->ManagerEpv
= sif
->MgrEpv
;
289 if (object_uuid
!= NULL
) {
290 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
293 /* find dispatch function */
294 msg
->ProcNum
= hdr
->request
.opnum
;
295 if (sif
->Flags
& RPC_IF_OLE
) {
296 /* native ole32 always gives us a dispatch table with a single entry
297 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
298 func
= *sif
->If
->DispatchTable
->DispatchTable
;
300 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
301 ERR("invalid procnum\n");
304 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
307 /* put in the drep. FIXME: is this more universally applicable?
308 perhaps we should move this outward... */
309 msg
->DataRepresentation
=
310 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
311 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
317 } __EXCEPT(rpc_filter
) {
318 /* failure packet was created in rpc_filter */
324 /* send response packet */
327 msg
->RpcInterfaceInformation
= NULL
;
332 FIXME("unhandled packet type\n");
338 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
339 TRACE("freeing Buffer=%p\n", buf
);
340 HeapFree(GetProcessHeap(), 0, buf
);
341 RPCRT4_DestroyBinding(msg
->Handle
);
343 I_RpcFreeBuffer(msg
);
345 RPCRT4_FreeHeader(hdr
);
347 TlsSetValue(worker_tls
, NULL
);
351 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
357 /* idle timeout after 5s */
358 obj
= WaitForSingleObject(server_sem
, 5000);
359 if (obj
== WAIT_TIMEOUT
) {
360 /* if another idle thread exist, self-destruct */
361 if (worker_free
> 1) break;
364 pkt
= RPCRT4_pop_packet();
366 InterlockedDecrement(&worker_free
);
368 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
369 HeapFree(GetProcessHeap(), 0, pkt
);
370 /* try to grab another packet here without waiting
371 * on the semaphore, in case it hits max */
372 pkt
= RPCRT4_pop_packet();
374 /* decrement semaphore */
375 WaitForSingleObject(server_sem
, 0);
377 InterlockedIncrement(&worker_free
);
379 InterlockedDecrement(&worker_free
);
380 InterlockedDecrement(&worker_count
);
384 static void RPCRT4_create_worker_if_needed(void)
386 if (!worker_free
&& worker_count
< MAX_THREADS
) {
388 InterlockedIncrement(&worker_count
);
389 InterlockedIncrement(&worker_free
);
390 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
391 if (thread
) CloseHandle(thread
);
393 InterlockedDecrement(&worker_free
);
394 InterlockedDecrement(&worker_count
);
399 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
401 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
408 TRACE("(%p)\n", conn
);
411 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
413 /* create temporary binding for dispatch, it will be freed in
414 * RPCRT4_process_packet */
415 RPCRT4_MakeBinding(&pbind
, conn
);
416 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
418 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
419 if (status
!= RPC_S_OK
) {
420 WARN("receive failed with error %lx\n", status
);
425 RPCRT4_process_packet(conn
, hdr
, msg
);
427 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
431 RPCRT4_create_worker_if_needed();
432 RPCRT4_push_packet(packet
);
433 ReleaseSemaphore(server_sem
, 1, NULL
);
437 HeapFree(GetProcessHeap(), 0, msg
);
438 RPCRT4_DestroyConnection(conn
);
442 static void RPCRT4_new_client(RpcConnection
* conn
)
444 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
446 DWORD err
= GetLastError();
447 ERR("failed to create thread, error=%08lx\n", err
);
448 RPCRT4_DestroyConnection(conn
);
450 /* we could set conn->thread, but then we'd have to make the io_thread wait
451 * for that, otherwise the thread might finish, destroy the connection, and
452 * free the memory we'd write to before we did, causing crashes and stuff -
453 * so let's implement that later, when we really need conn->thread */
455 CloseHandle( thread
);
458 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
460 HANDLE m_event
= mgr_event
, b_handle
;
463 RpcServerProtseq
* cps
;
465 RpcConnection
* cconn
;
467 TRACE("(the_arg == ^%p)\n", the_arg
);
470 EnterCriticalSection(&server_cs
);
471 /* open and count connections */
477 RPCRT4_OpenConnection(conn
);
478 if (conn
->ovl
.hEvent
) count
++;
483 /* make array of connections */
485 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
487 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
495 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
500 LeaveCriticalSection(&server_cs
);
503 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
504 if (res
== WAIT_OBJECT_0
) {
506 if (!std_listen
) break;
508 else if (res
== WAIT_FAILED
) {
509 ERR("wait failed\n");
512 b_handle
= objs
[res
- WAIT_OBJECT_0
];
513 /* find which connection got a RPC */
514 EnterCriticalSection(&server_cs
);
520 if (conn
->ovl
.hEvent
== b_handle
) break;
527 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
528 LeaveCriticalSection(&server_cs
);
530 ERR("failed to locate connection for handle %p\n", b_handle
);
532 if (cconn
) RPCRT4_new_client(cconn
);
535 HeapFree(GetProcessHeap(), 0, objs
);
536 EnterCriticalSection(&server_cs
);
537 /* close connections */
542 RPCRT4_CloseConnection(conn
);
547 LeaveCriticalSection(&server_cs
);
551 static void RPCRT4_start_listen(void)
555 EnterCriticalSection(&listen_cs
);
556 if (! ++listen_count
) {
557 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
558 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
559 if (!worker_tls
) worker_tls
= TlsAlloc();
561 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
562 LeaveCriticalSection(&listen_cs
);
564 LeaveCriticalSection(&listen_cs
);
569 static void RPCRT4_stop_listen(void)
571 EnterCriticalSection(&listen_cs
);
572 if (listen_count
== -1)
573 LeaveCriticalSection(&listen_cs
);
574 else if (--listen_count
== -1) {
576 LeaveCriticalSection(&listen_cs
);
579 LeaveCriticalSection(&listen_cs
);
580 assert(listen_count
> -2);
583 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
585 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
587 EnterCriticalSection(&server_cs
);
590 LeaveCriticalSection(&server_cs
);
592 if (std_listen
) SetEvent(mgr_event
);
597 /***********************************************************************
598 * RpcServerInqBindings (RPCRT4.@)
600 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
604 RpcServerProtseq
* ps
;
608 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
610 ERR("(BindingVector == NULL!!?)\n");
612 EnterCriticalSection(&server_cs
);
613 /* count connections */
625 /* export bindings */
626 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
627 sizeof(RPC_BINDING_VECTOR
) +
628 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
629 (*BindingVector
)->Count
= count
;
635 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
644 *BindingVector
= NULL
;
645 status
= RPC_S_NO_BINDINGS
;
647 LeaveCriticalSection(&server_cs
);
651 /***********************************************************************
652 * RpcServerUseProtseqEpA (RPCRT4.@)
654 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
658 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
660 /* This should provide the default behaviour */
661 policy
.Length
= sizeof( policy
);
662 policy
.EndpointFlags
= 0;
665 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
668 /***********************************************************************
669 * RpcServerUseProtseqEpW (RPCRT4.@)
671 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
675 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
677 /* This should provide the default behaviour */
678 policy
.Length
= sizeof( policy
);
679 policy
.EndpointFlags
= 0;
682 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
685 /***********************************************************************
686 * RpcServerUseProtseqEpExA (RPCRT4.@)
688 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
689 PRPC_POLICY lpPolicy
)
691 RpcServerProtseq
* ps
;
693 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
694 debugstr_a( Endpoint
), SecurityDescriptor
,
695 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
697 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
698 ps
->MaxCalls
= MaxCalls
;
699 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
700 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
702 return RPCRT4_use_protseq(ps
);
705 /***********************************************************************
706 * RpcServerUseProtseqEpExW (RPCRT4.@)
708 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
709 PRPC_POLICY lpPolicy
)
711 RpcServerProtseq
* ps
;
713 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
714 debugstr_w( Endpoint
), SecurityDescriptor
,
715 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
717 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
718 ps
->MaxCalls
= MaxCalls
;
719 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
720 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
722 return RPCRT4_use_protseq(ps
);
725 /***********************************************************************
726 * RpcServerUseProtseqA (RPCRT4.@)
728 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
730 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
731 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
734 /***********************************************************************
735 * RpcServerUseProtseqW (RPCRT4.@)
737 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
739 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
740 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
743 /***********************************************************************
744 * RpcServerRegisterIf (RPCRT4.@)
746 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
748 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
749 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
752 /***********************************************************************
753 * RpcServerRegisterIfEx (RPCRT4.@)
755 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
756 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
758 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
759 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
762 /***********************************************************************
763 * RpcServerRegisterIf2 (RPCRT4.@)
765 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
766 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
768 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
769 RpcServerInterface
* sif
;
772 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
773 MaxRpcSize
, IfCallbackFn
);
774 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
775 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
776 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
777 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
778 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
779 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
780 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
781 if (If
->DispatchTable
) {
782 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
783 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
784 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
786 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
788 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
789 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
790 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
792 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
795 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
796 sif
->MgrEpv
= MgrEpv
;
798 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
799 sif
->MgrEpv
= If
->DefaultManagerEpv
;
802 sif
->MaxCalls
= MaxCalls
;
803 sif
->MaxRpcSize
= MaxRpcSize
;
804 sif
->IfCallbackFn
= IfCallbackFn
;
806 EnterCriticalSection(&server_cs
);
809 LeaveCriticalSection(&server_cs
);
811 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
812 /* well, start listening, I think... */
813 RPCRT4_start_listen();
819 /***********************************************************************
820 * RpcServerUnregisterIf (RPCRT4.@)
822 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
824 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
825 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
830 /***********************************************************************
831 * RpcServerUnregisterIfEx (RPCRT4.@)
833 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
835 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
836 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
841 /***********************************************************************
842 * RpcObjectSetType (RPCRT4.@)
845 * ObjUuid [I] "Object" UUID
846 * TypeUuid [I] "Type" UUID
849 * RPC_S_OK The call succeeded
850 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
851 * RPC_S_ALREADY_REGISTERED The provided object is already registered
853 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
854 * resets the mapping for the specified object UUID to nil (the default).
855 * The nil object is always associated with the nil type and cannot be
856 * reassigned. Servers can support multiple implementations on the same
857 * interface by registering different end-point vectors for the different
858 * types. There's no need to call this if a server only supports the nil
859 * type, as is typical.
861 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
863 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
866 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
867 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
868 /* nil uuid cannot be remapped */
869 return RPC_S_INVALID_OBJECT
;
872 /* find the mapping for this object if there is one ... */
874 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
878 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
879 /* ... and drop it from the list */
882 prev
->next
= map
->next
;
884 RpcObjTypeMaps
= map
->next
;
885 HeapFree(GetProcessHeap(), 0, map
);
888 /* ... , fail if we found it ... */
890 return RPC_S_ALREADY_REGISTERED
;
891 /* ... otherwise create a new one and add it in. */
892 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
893 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
894 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
897 prev
->next
= map
; /* prev is the last map in the linklist */
899 RpcObjTypeMaps
= map
;
905 /***********************************************************************
906 * RpcServerRegisterAuthInfoA (RPCRT4.@)
908 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
911 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
913 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
916 /***********************************************************************
917 * RpcServerRegisterAuthInfoW (RPCRT4.@)
919 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
922 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
924 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
927 /***********************************************************************
928 * RpcServerListen (RPCRT4.@)
930 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
932 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
935 return RPC_S_NO_PROTSEQS_REGISTERED
;
937 EnterCriticalSection(&listen_cs
);
940 LeaveCriticalSection(&listen_cs
);
941 return RPC_S_ALREADY_LISTENING
;
944 RPCRT4_start_listen();
946 LeaveCriticalSection(&listen_cs
);
948 if (DontWait
) return RPC_S_OK
;
950 return RpcMgmtWaitServerListen();
953 /***********************************************************************
954 * RpcMgmtServerWaitListen (RPCRT4.@)
956 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
958 RPC_STATUS rslt
= RPC_S_OK
;
962 EnterCriticalSection(&listen_cs
);
965 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
966 LeaveCriticalSection(&listen_cs
);
970 LeaveCriticalSection(&listen_cs
);
973 WaitForSingleObject(mgr_event
, INFINITE
);
975 Sleep(100); /* don't spin violently */
976 TRACE("spinning.\n");
983 /***********************************************************************
984 * RpcMgmtStopServerListening (RPCRT4.@)
986 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
988 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
991 FIXME("client-side invocation not implemented.\n");
992 return RPC_S_WRONG_KIND_OF_BINDING
;
996 EnterCriticalSection(&listen_cs
);
998 RPCRT4_stop_listen();
999 LeaveCriticalSection(&listen_cs
);
1004 /***********************************************************************
1005 * I_RpcServerStartListening (RPCRT4.@)
1007 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1009 FIXME( "(%p): stub\n", hWnd
);
1014 /***********************************************************************
1015 * I_RpcServerStopListening (RPCRT4.@)
1017 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1019 FIXME( "(): stub\n" );
1024 /***********************************************************************
1025 * I_RpcWindowProc (RPCRT4.@)
1027 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1029 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);