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 /* FIXME: send fault packet? */
241 msg
->RpcInterfaceInformation
= sif
->If
;
242 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
243 msg
->ManagerEpv
= sif
->MgrEpv
;
244 if (object_uuid
!= NULL
) {
245 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
248 /* find dispatch function */
249 msg
->ProcNum
= hdr
->request
.opnum
;
250 if (sif
->Flags
& RPC_IF_OLE
) {
251 /* native ole32 always gives us a dispatch table with a single entry
252 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
253 func
= *sif
->If
->DispatchTable
->DispatchTable
;
255 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
256 ERR("invalid procnum\n");
259 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
262 /* put in the drep. FIXME: is this more universally applicable?
263 perhaps we should move this outward... */
264 msg
->DataRepresentation
=
265 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
266 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
271 } __EXCEPT(rpc_filter
) {
272 if (msg
->Buffer
!= buf
) I_RpcFreeBuffer(msg
);
273 /* this will cause a failure packet to be sent in I_RpcSend */
274 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
275 msg
->BufferLength
= sizeof(DWORD
);
277 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
280 /* send response packet */
283 msg
->RpcInterfaceInformation
= NULL
;
284 RPCRT4_release_server_interface(sif
);
289 FIXME("unhandled packet type %u\n", hdr
->common
.ptype
);
295 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
296 TRACE("freeing Buffer=%p\n", buf
);
297 HeapFree(GetProcessHeap(), 0, buf
);
298 RPCRT4_DestroyBinding(msg
->Handle
);
300 I_RpcFreeBuffer(msg
);
302 RPCRT4_FreeHeader(hdr
);
303 HeapFree(GetProcessHeap(), 0, msg
);
306 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
308 RpcPacket
*pkt
= the_arg
;
309 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
310 HeapFree(GetProcessHeap(), 0, pkt
);
314 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
316 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
323 TRACE("(%p)\n", conn
);
326 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
328 /* create temporary binding for dispatch, it will be freed in
329 * RPCRT4_process_packet */
330 RPCRT4_MakeBinding(&pbind
, conn
);
331 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
333 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
334 if (status
!= RPC_S_OK
) {
335 WARN("receive failed with error %lx\n", status
);
336 HeapFree(GetProcessHeap(), 0, msg
);
341 RPCRT4_process_packet(conn
, hdr
, msg
);
343 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
347 QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTELONGFUNCTION
);
351 RPCRT4_DestroyConnection(conn
);
355 void RPCRT4_new_client(RpcConnection
* conn
)
357 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
359 DWORD err
= GetLastError();
360 ERR("failed to create thread, error=%08x\n", err
);
361 RPCRT4_DestroyConnection(conn
);
363 /* we could set conn->thread, but then we'd have to make the io_thread wait
364 * for that, otherwise the thread might finish, destroy the connection, and
365 * free the memory we'd write to before we did, causing crashes and stuff -
366 * so let's implement that later, when we really need conn->thread */
368 CloseHandle( thread
);
371 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
376 RpcServerProtseq
* cps
= the_arg
;
378 BOOL set_ready_event
= FALSE
;
380 TRACE("(the_arg == ^%p)\n", the_arg
);
383 objs
= cps
->ops
->get_wait_array(cps
, objs
, &count
);
387 /* signal to function that changed state that we are now sync'ed */
388 SetEvent(cps
->server_ready_event
);
389 set_ready_event
= FALSE
;
393 res
= cps
->ops
->wait_for_new_connection(cps
, count
, objs
);
400 SetEvent(cps
->server_ready_event
);
403 set_ready_event
= TRUE
;
406 cps
->ops
->free_wait_array(cps
, objs
);
407 EnterCriticalSection(&cps
->cs
);
408 /* close connections */
411 RPCRT4_CloseConnection(conn
);
414 LeaveCriticalSection(&cps
->cs
);
418 /* tells the server thread that the state has changed and waits for it to
419 * make the changes */
420 static void RPCRT4_sync_with_server_thread(RpcServerProtseq
*ps
)
422 /* make sure we are the only thread sync'ing the server state, otherwise
423 * there is a race with the server thread setting an older state and setting
424 * the server_ready_event when the new state hasn't yet been applied */
425 WaitForSingleObject(ps
->mgr_mutex
, INFINITE
);
427 ps
->ops
->signal_state_changed(ps
);
429 /* wait for server thread to make the requested changes before returning */
430 WaitForSingleObject(ps
->server_ready_event
, INFINITE
);
432 ReleaseMutex(ps
->mgr_mutex
);
435 static RPC_STATUS
RPCRT4_start_listen_protseq(RpcServerProtseq
*ps
, BOOL auto_listen
)
437 RPC_STATUS status
= RPC_S_OK
;
438 HANDLE server_thread
;
440 EnterCriticalSection(&listen_cs
);
441 if (ps
->is_listening
) goto done
;
443 if (!ps
->mgr_mutex
) ps
->mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
444 if (!ps
->server_ready_event
) ps
->server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
445 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, ps
, 0, NULL
);
448 status
= RPC_S_OUT_OF_RESOURCES
;
451 ps
->is_listening
= TRUE
;
452 CloseHandle(server_thread
);
455 LeaveCriticalSection(&listen_cs
);
459 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
461 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
462 RpcServerProtseq
*cps
;
466 EnterCriticalSection(&listen_cs
);
467 if (auto_listen
|| (manual_listen_count
++ == 0))
470 if (++listen_count
== 1)
473 LeaveCriticalSection(&listen_cs
);
477 EnterCriticalSection(&server_cs
);
478 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
480 status
= RPCRT4_start_listen_protseq(cps
, TRUE
);
481 if (status
!= RPC_S_OK
)
484 /* make sure server is actually listening on the interface before
486 RPCRT4_sync_with_server_thread(cps
);
488 LeaveCriticalSection(&server_cs
);
494 static void RPCRT4_stop_listen(BOOL auto_listen
)
496 EnterCriticalSection(&listen_cs
);
497 if (auto_listen
|| (--manual_listen_count
== 0))
499 if (listen_count
!= 0 && --listen_count
== 0) {
500 RpcServerProtseq
*cps
;
503 LeaveCriticalSection(&listen_cs
);
505 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
506 RPCRT4_sync_with_server_thread(cps
);
510 assert(listen_count
>= 0);
512 LeaveCriticalSection(&listen_cs
);
515 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
, LPSTR endpoint
)
519 status
= ps
->ops
->open_endpoint(ps
, endpoint
);
520 if (status
!= RPC_S_OK
)
525 status
= RPCRT4_start_listen_protseq(ps
, FALSE
);
526 if (status
== RPC_S_OK
)
527 RPCRT4_sync_with_server_thread(ps
);
533 /***********************************************************************
534 * RpcServerInqBindings (RPCRT4.@)
536 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
540 RpcServerProtseq
* ps
;
544 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
546 ERR("(BindingVector == NULL!!?)\n");
548 EnterCriticalSection(&server_cs
);
549 /* count connections */
551 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
552 EnterCriticalSection(&ps
->cs
);
558 LeaveCriticalSection(&ps
->cs
);
561 /* export bindings */
562 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
563 sizeof(RPC_BINDING_VECTOR
) +
564 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
565 (*BindingVector
)->Count
= count
;
567 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
568 EnterCriticalSection(&ps
->cs
);
571 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
576 LeaveCriticalSection(&ps
->cs
);
580 *BindingVector
= NULL
;
581 status
= RPC_S_NO_BINDINGS
;
583 LeaveCriticalSection(&server_cs
);
587 /***********************************************************************
588 * RpcServerUseProtseqEpA (RPCRT4.@)
590 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
)
594 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
596 /* This should provide the default behaviour */
597 policy
.Length
= sizeof( policy
);
598 policy
.EndpointFlags
= 0;
601 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
604 /***********************************************************************
605 * RpcServerUseProtseqEpW (RPCRT4.@)
607 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
)
611 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
613 /* This should provide the default behaviour */
614 policy
.Length
= sizeof( policy
);
615 policy
.EndpointFlags
= 0;
618 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
621 /***********************************************************************
622 * alloc_serverprotoseq (internal)
624 * Must be called with server_cs held.
626 static RPC_STATUS
alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
628 const struct protseq_ops
*ops
= rpcrt4_get_protseq_ops(Protseq
);
632 FIXME("protseq %s not supported\n", debugstr_a(Protseq
));
633 return RPC_S_PROTSEQ_NOT_SUPPORTED
;
638 return RPC_S_OUT_OF_RESOURCES
;
639 (*ps
)->MaxCalls
= MaxCalls
;
640 (*ps
)->Protseq
= Protseq
;
644 InitializeCriticalSection(&(*ps
)->cs
);
645 (*ps
)->is_listening
= FALSE
;
646 (*ps
)->mgr_mutex
= NULL
;
647 (*ps
)->server_ready_event
= NULL
;
649 list_add_head(&protseqs
, &(*ps
)->entry
);
651 TRACE("new protseq %p created for %s\n", *ps
, Protseq
);
656 /* Finds a given protseq or creates a new one if one doesn't already exist */
657 static RPC_STATUS
RPCRT4_get_or_create_serverprotseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
660 RpcServerProtseq
*cps
;
662 EnterCriticalSection(&server_cs
);
664 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
665 if (!strcmp(cps
->Protseq
, Protseq
))
667 TRACE("found existing protseq object for %s\n", Protseq
);
669 LeaveCriticalSection(&server_cs
);
673 status
= alloc_serverprotoseq(MaxCalls
, Protseq
, ps
);
675 LeaveCriticalSection(&server_cs
);
680 /***********************************************************************
681 * RpcServerUseProtseqEpExA (RPCRT4.@)
683 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
,
684 PRPC_POLICY lpPolicy
)
686 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
687 RpcServerProtseq
* ps
;
690 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
691 debugstr_a(szep
), SecurityDescriptor
,
692 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
694 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupA(szps
), &ps
);
695 if (status
!= RPC_S_OK
)
698 return RPCRT4_use_protseq(ps
, szep
);
701 /***********************************************************************
702 * RpcServerUseProtseqEpExW (RPCRT4.@)
704 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
,
705 PRPC_POLICY lpPolicy
)
707 RpcServerProtseq
* ps
;
711 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
712 debugstr_w( Endpoint
), SecurityDescriptor
,
713 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
715 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
), &ps
);
716 if (status
!= RPC_S_OK
)
719 EndpointA
= RPCRT4_strdupWtoA(Endpoint
);
720 status
= RPCRT4_use_protseq(ps
, EndpointA
);
721 RPCRT4_strfree(EndpointA
);
725 /***********************************************************************
726 * RpcServerUseProtseqA (RPCRT4.@)
728 RPC_STATUS WINAPI
RpcServerUseProtseqA(RPC_CSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
730 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
731 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
734 /***********************************************************************
735 * RpcServerUseProtseqW (RPCRT4.@)
737 RPC_STATUS WINAPI
RpcServerUseProtseqW(RPC_WSTR 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
);
807 list_add_head(&server_interfaces
, &sif
->entry
);
808 LeaveCriticalSection(&server_cs
);
810 if (sif
->Flags
& RPC_IF_AUTOLISTEN
)
811 RPCRT4_start_listen(TRUE
);
816 /***********************************************************************
817 * RpcServerUnregisterIf (RPCRT4.@)
819 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
821 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
824 BOOL completed
= TRUE
;
825 RpcServerInterface
*cif
;
828 TRACE("(IfSpec == (RPC_IF_HANDLE)^%p (%s), MgrTypeUuid == %s, WaitForCallsToComplete == %u)\n",
829 IfSpec
, debugstr_guid(&If
->InterfaceId
.SyntaxGUID
), debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
831 EnterCriticalSection(&server_cs
);
832 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
833 if ((!IfSpec
|| !memcmp(&If
->InterfaceId
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
))) &&
834 UuidEqual(MgrTypeUuid
, &cif
->MgrTypeUuid
, &status
)) {
835 list_remove(&cif
->entry
);
836 if (cif
->CurrentCalls
) {
838 if (WaitForCallsToComplete
)
839 cif
->CallsCompletedEvent
= event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
845 LeaveCriticalSection(&server_cs
);
848 ERR("not found for object %s\n", debugstr_guid(MgrTypeUuid
));
849 return RPC_S_UNKNOWN_IF
;
853 HeapFree(GetProcessHeap(), 0, cif
);
855 /* sif will be freed when the last call is completed, so be careful not to
856 * touch that memory here as that could happen before we get here */
857 WaitForSingleObject(event
, INFINITE
);
864 /***********************************************************************
865 * RpcServerUnregisterIfEx (RPCRT4.@)
867 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
869 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
870 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
875 /***********************************************************************
876 * RpcObjectSetType (RPCRT4.@)
879 * ObjUuid [I] "Object" UUID
880 * TypeUuid [I] "Type" UUID
883 * RPC_S_OK The call succeeded
884 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
885 * RPC_S_ALREADY_REGISTERED The provided object is already registered
887 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
888 * resets the mapping for the specified object UUID to nil (the default).
889 * The nil object is always associated with the nil type and cannot be
890 * reassigned. Servers can support multiple implementations on the same
891 * interface by registering different end-point vectors for the different
892 * types. There's no need to call this if a server only supports the nil
893 * type, as is typical.
895 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
897 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
900 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
901 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
902 /* nil uuid cannot be remapped */
903 return RPC_S_INVALID_OBJECT
;
906 /* find the mapping for this object if there is one ... */
908 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
912 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
913 /* ... and drop it from the list */
916 prev
->next
= map
->next
;
918 RpcObjTypeMaps
= map
->next
;
919 HeapFree(GetProcessHeap(), 0, map
);
922 /* ... , fail if we found it ... */
924 return RPC_S_ALREADY_REGISTERED
;
925 /* ... otherwise create a new one and add it in. */
926 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
927 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
928 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
931 prev
->next
= map
; /* prev is the last map in the linklist */
933 RpcObjTypeMaps
= map
;
939 /***********************************************************************
940 * RpcServerRegisterAuthInfoA (RPCRT4.@)
942 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
945 FIXME( "(%s,%u,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
947 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
950 /***********************************************************************
951 * RpcServerRegisterAuthInfoW (RPCRT4.@)
953 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
956 FIXME( "(%s,%u,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
958 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
961 /***********************************************************************
962 * RpcServerListen (RPCRT4.@)
964 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
966 RPC_STATUS status
= RPC_S_OK
;
968 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
970 if (list_empty(&protseqs
))
971 return RPC_S_NO_PROTSEQS_REGISTERED
;
973 status
= RPCRT4_start_listen(FALSE
);
975 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
977 return RpcMgmtWaitServerListen();
980 /***********************************************************************
981 * RpcMgmtServerWaitListen (RPCRT4.@)
983 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
987 EnterCriticalSection(&listen_cs
);
990 LeaveCriticalSection(&listen_cs
);
991 return RPC_S_NOT_LISTENING
;
994 LeaveCriticalSection(&listen_cs
);
996 FIXME("not waiting for server calls to finish\n");
1001 /***********************************************************************
1002 * RpcMgmtStopServerListening (RPCRT4.@)
1004 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1006 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1009 FIXME("client-side invocation not implemented.\n");
1010 return RPC_S_WRONG_KIND_OF_BINDING
;
1013 RPCRT4_stop_listen(FALSE
);
1018 /***********************************************************************
1019 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1021 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
1023 FIXME("(): stub\n");
1027 /***********************************************************************
1028 * I_RpcServerStartListening (RPCRT4.@)
1030 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1032 FIXME( "(%p): stub\n", hWnd
);
1037 /***********************************************************************
1038 * I_RpcServerStopListening (RPCRT4.@)
1040 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1042 FIXME( "(): stub\n" );
1047 /***********************************************************************
1048 * I_RpcWindowProc (RPCRT4.@)
1050 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1052 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd
, Message
, wParam
, lParam
);
1057 /***********************************************************************
1058 * RpcMgmtInqIfIds (RPCRT4.@)
1060 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1062 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1063 return RPC_S_INVALID_BINDING
;
1066 /***********************************************************************
1067 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1069 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, ULONG InquiryType
,
1070 RPC_IF_ID
*IfId
, ULONG VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1072 FIXME("(%p,%u,%p,%u,%p,%p): stub\n",
1073 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1074 return RPC_S_INVALID_BINDING
;
1077 /***********************************************************************
1078 * RpcMgmtIsServerListening (RPCRT4.@)
1080 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1082 FIXME("(%p): stub\n", Binding
);
1083 return RPC_S_INVALID_BINDING
;
1086 /***********************************************************************
1087 * RpcMgmtSetServerStackSize (RPCRT4.@)
1089 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(ULONG ThreadStackSize
)
1091 FIXME("(0x%x): stub\n", ThreadStackSize
);