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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
41 #include "wine/debug.h"
42 #include "wine/exception.h"
44 #include "rpc_server.h"
46 #include "rpc_message.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
51 typedef struct _RpcPacket
53 struct _RpcConnection
* conn
;
58 typedef struct _RpcObjTypeMap
60 /* FIXME: a hash table would be better. */
61 struct _RpcObjTypeMap
*next
;
66 static RpcObjTypeMap
*RpcObjTypeMaps
;
68 /* list of type RpcServerProtseq */
69 static struct list protseqs
= LIST_INIT(protseqs
);
70 static struct list server_interfaces
= LIST_INIT(server_interfaces
);
72 static CRITICAL_SECTION server_cs
;
73 static CRITICAL_SECTION_DEBUG server_cs_debug
=
76 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
77 0, 0, { (DWORD_PTR
)(__FILE__
": server_cs") }
79 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
81 static CRITICAL_SECTION listen_cs
;
82 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
85 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
86 0, 0, { (DWORD_PTR
)(__FILE__
": listen_cs") }
88 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
90 /* whether the server is currently listening */
91 static BOOL std_listen
;
92 /* number of manual listeners (calls to RpcServerListen) */
93 static LONG manual_listen_count
;
94 /* total listeners including auto listeners */
95 static LONG listen_count
;
99 static inline RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
101 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
105 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
112 static inline UUID
*LookupObjType(UUID
*ObjUuid
)
114 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
121 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
122 RPC_SYNTAX_IDENTIFIER
* if_id
,
125 UUID
* MgrType
= NULL
;
126 RpcServerInterface
* cif
;
130 MgrType
= LookupObjType(object
);
131 EnterCriticalSection(&server_cs
);
132 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
133 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
134 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
136 InterlockedIncrement(&cif
->CurrentCalls
);
140 LeaveCriticalSection(&server_cs
);
141 if (&cif
->entry
== &server_interfaces
) cif
= NULL
;
142 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
146 static void RPCRT4_release_server_interface(RpcServerInterface
*sif
)
148 if (!InterlockedDecrement(&sif
->CurrentCalls
) &&
149 sif
->CallsCompletedEvent
) {
150 /* sif must have been removed from server_interfaces before
151 * CallsCompletedEvent is set */
152 SetEvent(sif
->CallsCompletedEvent
);
153 HeapFree(GetProcessHeap(), 0, sif
);
157 static WINE_EXCEPTION_FILTER(rpc_filter
)
159 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
160 TRACE("returning failure packet\n");
161 /* catch every exception */
162 return EXCEPTION_EXECUTE_HANDLER
;
165 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
167 RpcServerInterface
* sif
;
168 RPC_DISPATCH_FUNCTION func
;
171 void *buf
= msg
->Buffer
;
174 switch (hdr
->common
.ptype
) {
176 TRACE("got bind packet\n");
178 /* FIXME: do more checks! */
179 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
180 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
181 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
184 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
187 TRACE("rejecting bind request on connection %p\n", conn
);
188 /* Report failure to client. */
189 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
190 RPC_VER_MAJOR
, RPC_VER_MINOR
);
192 TRACE("accepting bind request on connection %p for %s\n", conn
,
193 debugstr_guid(&hdr
->bind
.abstract
.SyntaxGUID
));
196 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
200 RESULT_ACCEPT
, NO_REASON
,
201 &sif
->If
->TransferSyntax
);
203 /* save the interface for later use */
204 conn
->ActiveInterface
= hdr
->bind
.abstract
;
205 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
207 RPCRT4_release_server_interface(sif
);
210 status
= RPCRT4_Send(conn
, response
, NULL
, 0);
211 RPCRT4_FreeHeader(response
);
212 if (status
!= RPC_S_OK
)
218 TRACE("got request packet\n");
220 /* fail if the connection isn't bound with an interface */
221 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
222 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
225 RPCRT4_Send(conn
, response
, NULL
, 0);
226 RPCRT4_FreeHeader(response
);
230 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
231 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
236 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
238 WARN("interface %s no longer registered, returning fault packet\n", debugstr_guid(&conn
->ActiveInterface
.SyntaxGUID
));
239 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
242 RPCRT4_Send(conn
, response
, NULL
, 0);
243 RPCRT4_FreeHeader(response
);
246 msg
->RpcInterfaceInformation
= sif
->If
;
247 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
248 msg
->ManagerEpv
= sif
->MgrEpv
;
249 if (object_uuid
!= NULL
) {
250 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
253 /* find dispatch function */
254 msg
->ProcNum
= hdr
->request
.opnum
;
255 if (sif
->Flags
& RPC_IF_OLE
) {
256 /* native ole32 always gives us a dispatch table with a single entry
257 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
258 func
= *sif
->If
->DispatchTable
->DispatchTable
;
260 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
261 ERR("invalid procnum\n");
264 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
267 /* put in the drep. FIXME: is this more universally applicable?
268 perhaps we should move this outward... */
269 msg
->DataRepresentation
=
270 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
271 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
276 } __EXCEPT(rpc_filter
) {
277 if (msg
->Buffer
!= buf
) I_RpcFreeBuffer(msg
);
278 /* this will cause a failure packet to be sent in I_RpcSend */
279 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
280 msg
->BufferLength
= sizeof(DWORD
);
282 if (GetExceptionCode() == STATUS_ACCESS_VIOLATION
)
283 *(DWORD
*)msg
->Buffer
= ERROR_NOACCESS
;
285 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
288 /* send response packet */
291 msg
->RpcInterfaceInformation
= NULL
;
292 RPCRT4_release_server_interface(sif
);
297 FIXME("unhandled packet type %u\n", hdr
->common
.ptype
);
303 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
304 TRACE("freeing Buffer=%p\n", buf
);
305 HeapFree(GetProcessHeap(), 0, buf
);
306 RPCRT4_DestroyBinding(msg
->Handle
);
308 I_RpcFreeBuffer(msg
);
310 RPCRT4_FreeHeader(hdr
);
311 HeapFree(GetProcessHeap(), 0, msg
);
314 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
316 RpcPacket
*pkt
= the_arg
;
317 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
318 HeapFree(GetProcessHeap(), 0, pkt
);
322 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
324 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
331 TRACE("(%p)\n", conn
);
334 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
336 /* create temporary binding for dispatch, it will be freed in
337 * RPCRT4_process_packet */
338 RPCRT4_MakeBinding(&pbind
, conn
);
339 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
341 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
342 if (status
!= RPC_S_OK
) {
343 WARN("receive failed with error %lx\n", status
);
344 HeapFree(GetProcessHeap(), 0, msg
);
349 RPCRT4_process_packet(conn
, hdr
, msg
);
351 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
355 QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTELONGFUNCTION
);
359 RPCRT4_DestroyConnection(conn
);
363 void RPCRT4_new_client(RpcConnection
* conn
)
365 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
367 DWORD err
= GetLastError();
368 ERR("failed to create thread, error=%08x\n", err
);
369 RPCRT4_DestroyConnection(conn
);
371 /* we could set conn->thread, but then we'd have to make the io_thread wait
372 * for that, otherwise the thread might finish, destroy the connection, and
373 * free the memory we'd write to before we did, causing crashes and stuff -
374 * so let's implement that later, when we really need conn->thread */
376 CloseHandle( thread
);
379 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
384 RpcServerProtseq
* cps
= the_arg
;
386 BOOL set_ready_event
= FALSE
;
388 TRACE("(the_arg == ^%p)\n", the_arg
);
391 objs
= cps
->ops
->get_wait_array(cps
, objs
, &count
);
395 /* signal to function that changed state that we are now sync'ed */
396 SetEvent(cps
->server_ready_event
);
397 set_ready_event
= FALSE
;
401 res
= cps
->ops
->wait_for_new_connection(cps
, count
, objs
);
408 SetEvent(cps
->server_ready_event
);
411 set_ready_event
= TRUE
;
414 cps
->ops
->free_wait_array(cps
, objs
);
415 EnterCriticalSection(&cps
->cs
);
416 /* close connections */
419 RPCRT4_CloseConnection(conn
);
422 LeaveCriticalSection(&cps
->cs
);
426 /* tells the server thread that the state has changed and waits for it to
427 * make the changes */
428 static void RPCRT4_sync_with_server_thread(RpcServerProtseq
*ps
)
430 /* make sure we are the only thread sync'ing the server state, otherwise
431 * there is a race with the server thread setting an older state and setting
432 * the server_ready_event when the new state hasn't yet been applied */
433 WaitForSingleObject(ps
->mgr_mutex
, INFINITE
);
435 ps
->ops
->signal_state_changed(ps
);
437 /* wait for server thread to make the requested changes before returning */
438 WaitForSingleObject(ps
->server_ready_event
, INFINITE
);
440 ReleaseMutex(ps
->mgr_mutex
);
443 static RPC_STATUS
RPCRT4_start_listen_protseq(RpcServerProtseq
*ps
, BOOL auto_listen
)
445 RPC_STATUS status
= RPC_S_OK
;
446 HANDLE server_thread
;
448 EnterCriticalSection(&listen_cs
);
449 if (ps
->is_listening
) goto done
;
451 if (!ps
->mgr_mutex
) ps
->mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
452 if (!ps
->server_ready_event
) ps
->server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
453 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, ps
, 0, NULL
);
456 status
= RPC_S_OUT_OF_RESOURCES
;
459 ps
->is_listening
= TRUE
;
460 CloseHandle(server_thread
);
463 LeaveCriticalSection(&listen_cs
);
467 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
469 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
470 RpcServerProtseq
*cps
;
474 EnterCriticalSection(&listen_cs
);
475 if (auto_listen
|| (manual_listen_count
++ == 0))
478 if (++listen_count
== 1)
481 LeaveCriticalSection(&listen_cs
);
485 EnterCriticalSection(&server_cs
);
486 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
488 status
= RPCRT4_start_listen_protseq(cps
, TRUE
);
489 if (status
!= RPC_S_OK
)
492 /* make sure server is actually listening on the interface before
494 RPCRT4_sync_with_server_thread(cps
);
496 LeaveCriticalSection(&server_cs
);
502 static void RPCRT4_stop_listen(BOOL auto_listen
)
504 EnterCriticalSection(&listen_cs
);
505 if (auto_listen
|| (--manual_listen_count
== 0))
507 if (listen_count
!= 0 && --listen_count
== 0) {
508 RpcServerProtseq
*cps
;
511 LeaveCriticalSection(&listen_cs
);
513 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
514 RPCRT4_sync_with_server_thread(cps
);
518 assert(listen_count
>= 0);
520 LeaveCriticalSection(&listen_cs
);
523 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
, LPSTR endpoint
)
527 status
= ps
->ops
->open_endpoint(ps
, endpoint
);
528 if (status
!= RPC_S_OK
)
533 status
= RPCRT4_start_listen_protseq(ps
, FALSE
);
534 if (status
== RPC_S_OK
)
535 RPCRT4_sync_with_server_thread(ps
);
541 /***********************************************************************
542 * RpcServerInqBindings (RPCRT4.@)
544 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
548 RpcServerProtseq
* ps
;
552 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
554 ERR("(BindingVector == NULL!!?)\n");
556 EnterCriticalSection(&server_cs
);
557 /* count connections */
559 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
560 EnterCriticalSection(&ps
->cs
);
566 LeaveCriticalSection(&ps
->cs
);
569 /* export bindings */
570 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
571 sizeof(RPC_BINDING_VECTOR
) +
572 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
573 (*BindingVector
)->Count
= count
;
575 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
576 EnterCriticalSection(&ps
->cs
);
579 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
584 LeaveCriticalSection(&ps
->cs
);
588 *BindingVector
= NULL
;
589 status
= RPC_S_NO_BINDINGS
;
591 LeaveCriticalSection(&server_cs
);
595 /***********************************************************************
596 * RpcServerUseProtseqEpA (RPCRT4.@)
598 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
)
602 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
604 /* This should provide the default behaviour */
605 policy
.Length
= sizeof( policy
);
606 policy
.EndpointFlags
= 0;
609 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
612 /***********************************************************************
613 * RpcServerUseProtseqEpW (RPCRT4.@)
615 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
)
619 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
621 /* This should provide the default behaviour */
622 policy
.Length
= sizeof( policy
);
623 policy
.EndpointFlags
= 0;
626 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
629 /***********************************************************************
630 * alloc_serverprotoseq (internal)
632 * Must be called with server_cs held.
634 static RPC_STATUS
alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
636 const struct protseq_ops
*ops
= rpcrt4_get_protseq_ops(Protseq
);
640 FIXME("protseq %s not supported\n", debugstr_a(Protseq
));
641 return RPC_S_PROTSEQ_NOT_SUPPORTED
;
646 return RPC_S_OUT_OF_RESOURCES
;
647 (*ps
)->MaxCalls
= MaxCalls
;
648 (*ps
)->Protseq
= Protseq
;
652 InitializeCriticalSection(&(*ps
)->cs
);
653 (*ps
)->is_listening
= FALSE
;
654 (*ps
)->mgr_mutex
= NULL
;
655 (*ps
)->server_ready_event
= NULL
;
657 list_add_head(&protseqs
, &(*ps
)->entry
);
659 TRACE("new protseq %p created for %s\n", *ps
, Protseq
);
664 /* Finds a given protseq or creates a new one if one doesn't already exist */
665 static RPC_STATUS
RPCRT4_get_or_create_serverprotseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
668 RpcServerProtseq
*cps
;
670 EnterCriticalSection(&server_cs
);
672 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
673 if (!strcmp(cps
->Protseq
, Protseq
))
675 TRACE("found existing protseq object for %s\n", Protseq
);
677 LeaveCriticalSection(&server_cs
);
681 status
= alloc_serverprotoseq(MaxCalls
, Protseq
, ps
);
683 LeaveCriticalSection(&server_cs
);
688 /***********************************************************************
689 * RpcServerUseProtseqEpExA (RPCRT4.@)
691 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
,
692 PRPC_POLICY lpPolicy
)
694 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
695 RpcServerProtseq
* ps
;
698 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
699 debugstr_a(szep
), SecurityDescriptor
,
700 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
702 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupA(szps
), &ps
);
703 if (status
!= RPC_S_OK
)
706 return RPCRT4_use_protseq(ps
, szep
);
709 /***********************************************************************
710 * RpcServerUseProtseqEpExW (RPCRT4.@)
712 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
,
713 PRPC_POLICY lpPolicy
)
715 RpcServerProtseq
* ps
;
719 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
720 debugstr_w( Endpoint
), SecurityDescriptor
,
721 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
723 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
), &ps
);
724 if (status
!= RPC_S_OK
)
727 EndpointA
= RPCRT4_strdupWtoA(Endpoint
);
728 status
= RPCRT4_use_protseq(ps
, EndpointA
);
729 RPCRT4_strfree(EndpointA
);
733 /***********************************************************************
734 * RpcServerUseProtseqA (RPCRT4.@)
736 RPC_STATUS WINAPI
RpcServerUseProtseqA(RPC_CSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
738 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
739 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
742 /***********************************************************************
743 * RpcServerUseProtseqW (RPCRT4.@)
745 RPC_STATUS WINAPI
RpcServerUseProtseqW(RPC_WSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
747 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
748 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
751 /***********************************************************************
752 * RpcServerRegisterIf (RPCRT4.@)
754 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
756 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
757 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
760 /***********************************************************************
761 * RpcServerRegisterIfEx (RPCRT4.@)
763 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
764 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
766 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
767 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
770 /***********************************************************************
771 * RpcServerRegisterIf2 (RPCRT4.@)
773 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
774 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
776 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
777 RpcServerInterface
* sif
;
780 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
781 MaxRpcSize
, IfCallbackFn
);
782 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
783 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
784 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
785 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
786 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
787 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
788 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
789 if (If
->DispatchTable
) {
790 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
791 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
792 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
794 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
796 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
797 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
798 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
800 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
803 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
804 sif
->MgrEpv
= MgrEpv
;
806 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
807 sif
->MgrEpv
= If
->DefaultManagerEpv
;
810 sif
->MaxCalls
= MaxCalls
;
811 sif
->MaxRpcSize
= MaxRpcSize
;
812 sif
->IfCallbackFn
= IfCallbackFn
;
814 EnterCriticalSection(&server_cs
);
815 list_add_head(&server_interfaces
, &sif
->entry
);
816 LeaveCriticalSection(&server_cs
);
818 if (sif
->Flags
& RPC_IF_AUTOLISTEN
)
819 RPCRT4_start_listen(TRUE
);
824 /***********************************************************************
825 * RpcServerUnregisterIf (RPCRT4.@)
827 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
829 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
832 BOOL completed
= TRUE
;
833 RpcServerInterface
*cif
;
836 TRACE("(IfSpec == (RPC_IF_HANDLE)^%p (%s), MgrTypeUuid == %s, WaitForCallsToComplete == %u)\n",
837 IfSpec
, debugstr_guid(&If
->InterfaceId
.SyntaxGUID
), debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
839 EnterCriticalSection(&server_cs
);
840 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
841 if ((!IfSpec
|| !memcmp(&If
->InterfaceId
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
))) &&
842 UuidEqual(MgrTypeUuid
, &cif
->MgrTypeUuid
, &status
)) {
843 list_remove(&cif
->entry
);
844 if (cif
->CurrentCalls
) {
846 if (WaitForCallsToComplete
)
847 cif
->CallsCompletedEvent
= event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
853 LeaveCriticalSection(&server_cs
);
856 ERR("not found for object %s\n", debugstr_guid(MgrTypeUuid
));
857 return RPC_S_UNKNOWN_IF
;
861 HeapFree(GetProcessHeap(), 0, cif
);
863 /* sif will be freed when the last call is completed, so be careful not to
864 * touch that memory here as that could happen before we get here */
865 WaitForSingleObject(event
, INFINITE
);
872 /***********************************************************************
873 * RpcServerUnregisterIfEx (RPCRT4.@)
875 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
877 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
878 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
883 /***********************************************************************
884 * RpcObjectSetType (RPCRT4.@)
887 * ObjUuid [I] "Object" UUID
888 * TypeUuid [I] "Type" UUID
891 * RPC_S_OK The call succeeded
892 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
893 * RPC_S_ALREADY_REGISTERED The provided object is already registered
895 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
896 * resets the mapping for the specified object UUID to nil (the default).
897 * The nil object is always associated with the nil type and cannot be
898 * reassigned. Servers can support multiple implementations on the same
899 * interface by registering different end-point vectors for the different
900 * types. There's no need to call this if a server only supports the nil
901 * type, as is typical.
903 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
905 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
908 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
909 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
910 /* nil uuid cannot be remapped */
911 return RPC_S_INVALID_OBJECT
;
914 /* find the mapping for this object if there is one ... */
916 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
920 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
921 /* ... and drop it from the list */
924 prev
->next
= map
->next
;
926 RpcObjTypeMaps
= map
->next
;
927 HeapFree(GetProcessHeap(), 0, map
);
930 /* ... , fail if we found it ... */
932 return RPC_S_ALREADY_REGISTERED
;
933 /* ... otherwise create a new one and add it in. */
934 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
935 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
936 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
939 prev
->next
= map
; /* prev is the last map in the linklist */
941 RpcObjTypeMaps
= map
;
947 /***********************************************************************
948 * RpcServerRegisterAuthInfoA (RPCRT4.@)
950 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
953 FIXME( "(%s,%u,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
955 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
958 /***********************************************************************
959 * RpcServerRegisterAuthInfoW (RPCRT4.@)
961 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
964 FIXME( "(%s,%u,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
966 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
969 /***********************************************************************
970 * RpcServerListen (RPCRT4.@)
972 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
974 RPC_STATUS status
= RPC_S_OK
;
976 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
978 if (list_empty(&protseqs
))
979 return RPC_S_NO_PROTSEQS_REGISTERED
;
981 status
= RPCRT4_start_listen(FALSE
);
983 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
985 return RpcMgmtWaitServerListen();
988 /***********************************************************************
989 * RpcMgmtServerWaitListen (RPCRT4.@)
991 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
995 EnterCriticalSection(&listen_cs
);
998 LeaveCriticalSection(&listen_cs
);
999 return RPC_S_NOT_LISTENING
;
1002 LeaveCriticalSection(&listen_cs
);
1004 FIXME("not waiting for server calls to finish\n");
1009 /***********************************************************************
1010 * RpcMgmtStopServerListening (RPCRT4.@)
1012 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1014 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1017 FIXME("client-side invocation not implemented.\n");
1018 return RPC_S_WRONG_KIND_OF_BINDING
;
1021 RPCRT4_stop_listen(FALSE
);
1026 /***********************************************************************
1027 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1029 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
1031 FIXME("(): stub\n");
1035 /***********************************************************************
1036 * I_RpcServerStartListening (RPCRT4.@)
1038 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1040 FIXME( "(%p): stub\n", hWnd
);
1045 /***********************************************************************
1046 * I_RpcServerStopListening (RPCRT4.@)
1048 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1050 FIXME( "(): stub\n" );
1055 /***********************************************************************
1056 * I_RpcWindowProc (RPCRT4.@)
1058 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1060 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd
, Message
, wParam
, lParam
);
1065 /***********************************************************************
1066 * RpcMgmtInqIfIds (RPCRT4.@)
1068 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1070 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1071 return RPC_S_INVALID_BINDING
;
1074 /***********************************************************************
1075 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1077 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, ULONG InquiryType
,
1078 RPC_IF_ID
*IfId
, ULONG VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1080 FIXME("(%p,%u,%p,%u,%p,%p): stub\n",
1081 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1082 return RPC_S_INVALID_BINDING
;
1085 /***********************************************************************
1086 * RpcMgmtIsServerListening (RPCRT4.@)
1088 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1090 FIXME("(%p): stub\n", Binding
);
1091 return RPC_S_INVALID_BINDING
;
1094 /***********************************************************************
1095 * RpcMgmtSetServerStackSize (RPCRT4.@)
1097 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(ULONG ThreadStackSize
)
1099 FIXME("(0x%x): stub\n", ThreadStackSize
);