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"
42 #include "wine/debug.h"
43 #include "wine/exception.h"
45 #include "rpc_server.h"
47 #include "rpc_message.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
52 typedef struct _RpcPacket
54 struct _RpcConnection* conn;
59 typedef struct _RpcObjTypeMap
61 /* FIXME: a hash table would be better. */
62 struct _RpcObjTypeMap *next;
67 static RpcObjTypeMap *RpcObjTypeMaps;
69 /* list of type RpcServerProtseq */
70 static struct list protseqs = LIST_INIT(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, { (DWORD_PTR)(__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, { (DWORD_PTR)(__FILE__ ": listen_cs") }
89 static CRITICAL_SECTION listen_cs = { &listen_cs_debug, -1, 0, 0, 0, 0 };
91 /* whether the server is currently listening */
92 static BOOL std_listen;
93 /* number of manual listeners (calls to RpcServerListen) */
94 static LONG manual_listen_count;
95 /* total listeners including auto listeners */
96 static LONG listen_count;
100 inline static RpcObjTypeMap *LookupObjTypeMap(UUID *ObjUuid)
102 RpcObjTypeMap *rslt = RpcObjTypeMaps;
106 if (! UuidCompare(ObjUuid, &rslt->Object, &dummy)) break;
113 inline static UUID *LookupObjType(UUID *ObjUuid)
115 RpcObjTypeMap *map = LookupObjTypeMap(ObjUuid);
122 static RpcServerInterface* RPCRT4_find_interface(UUID* object,
123 RPC_SYNTAX_IDENTIFIER* if_id,
126 UUID* MgrType = NULL;
127 RpcServerInterface* cif = NULL;
131 MgrType = LookupObjType(object);
132 EnterCriticalSection(&server_cs);
135 if (!memcmp(if_id, &cif->If->InterfaceId, sizeof(RPC_SYNTAX_IDENTIFIER)) &&
136 (check_object == FALSE || UuidEqual(MgrType, &cif->MgrTypeUuid, &status)) &&
140 LeaveCriticalSection(&server_cs);
141 TRACE("returning %p for %s\n", cif, debugstr_guid(object));
145 static WINE_EXCEPTION_FILTER(rpc_filter)
147 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
148 TRACE("returning failure packet\n");
149 /* catch every exception */
150 return EXCEPTION_EXECUTE_HANDLER;
153 static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr, RPC_MESSAGE* msg)
155 RpcServerInterface* sif;
156 RPC_DISPATCH_FUNCTION func;
159 void *buf = msg->Buffer;
162 switch (hdr->common.ptype) {
164 TRACE("got bind packet\n");
166 /* FIXME: do more checks! */
167 if (hdr->bind.max_tsize < RPC_MIN_PACKET_SIZE ||
168 !UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
169 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
172 sif = RPCRT4_find_interface(NULL, &hdr->bind.abstract, FALSE);
175 TRACE("rejecting bind request on connection %p\n", conn);
176 /* Report failure to client. */
177 response = RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION,
178 RPC_VER_MAJOR, RPC_VER_MINOR);
180 TRACE("accepting bind request on connection %p\n", conn);
183 response = RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION,
187 RESULT_ACCEPT, NO_REASON,
188 &sif->If->TransferSyntax);
190 /* save the interface for later use */
191 conn->ActiveInterface = hdr->bind.abstract;
192 conn->MaxTransmissionSize = hdr->bind.max_tsize;
195 status = RPCRT4_Send(conn, response, NULL, 0);
196 RPCRT4_FreeHeader(response);
197 if (status != RPC_S_OK)
203 TRACE("got request packet\n");
205 /* fail if the connection isn't bound with an interface */
206 if (UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
207 response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
210 RPCRT4_Send(conn, response, NULL, 0);
211 RPCRT4_FreeHeader(response);
215 if (hdr->common.flags & RPC_FLG_OBJECT_UUID) {
216 object_uuid = (UUID*)(&hdr->request + 1);
221 sif = RPCRT4_find_interface(object_uuid, &conn->ActiveInterface, TRUE);
222 msg->RpcInterfaceInformation = sif->If;
223 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
224 msg->ManagerEpv = sif->MgrEpv;
225 if (object_uuid != NULL) {
226 RPCRT4_SetBindingObject(msg->Handle, object_uuid);
229 /* find dispatch function */
230 msg->ProcNum = hdr->request.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->common.drep[0], hdr->common.drep[1]),
247 MAKEWORD(hdr->common.drep[2], hdr->common.drep[3]));
252 } __EXCEPT(rpc_filter) {
253 if (msg->Buffer != buf) I_RpcFreeBuffer(msg);
254 /* this will cause a failure packet to be sent in I_RpcSend */
255 msg->RpcFlags |= WINE_RPCFLAG_EXCEPTION;
256 msg->BufferLength = sizeof(DWORD);
258 *(DWORD*)msg->Buffer = GetExceptionCode();
261 /* send response packet */
264 msg->RpcInterfaceInformation = NULL;
269 FIXME("unhandled packet type\n");
275 if (msg->Buffer == buf) msg->Buffer = NULL;
276 TRACE("freeing Buffer=%p\n", buf);
277 HeapFree(GetProcessHeap(), 0, buf);
278 RPCRT4_DestroyBinding(msg->Handle);
280 I_RpcFreeBuffer(msg);
282 RPCRT4_FreeHeader(hdr);
283 HeapFree(GetProcessHeap(), 0, msg);
286 static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
288 RpcPacket *pkt = the_arg;
289 RPCRT4_process_packet(pkt->conn, pkt->hdr, pkt->msg);
290 HeapFree(GetProcessHeap(), 0, pkt);
294 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
296 RpcConnection* conn = (RpcConnection*)the_arg;
303 TRACE("(%p)\n", conn);
306 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_MESSAGE));
308 /* create temporary binding for dispatch, it will be freed in
309 * RPCRT4_process_packet */
310 RPCRT4_MakeBinding(&pbind, conn);
311 msg->Handle = (RPC_BINDING_HANDLE)pbind;
313 status = RPCRT4_Receive(conn, &hdr, msg);
314 if (status != RPC_S_OK) {
315 WARN("receive failed with error %lx\n", status);
316 HeapFree(GetProcessHeap(), 0, msg);
321 RPCRT4_process_packet(conn, hdr, msg);
323 packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
327 QueueUserWorkItem(RPCRT4_worker_thread, packet, WT_EXECUTEDEFAULT);
331 RPCRT4_DestroyConnection(conn);
335 void RPCRT4_new_client(RpcConnection* conn)
337 HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
339 DWORD err = GetLastError();
340 ERR("failed to create thread, error=%08x\n", err);
341 RPCRT4_DestroyConnection(conn);
343 /* we could set conn->thread, but then we'd have to make the io_thread wait
344 * for that, otherwise the thread might finish, destroy the connection, and
345 * free the memory we'd write to before we did, causing crashes and stuff -
346 * so let's implement that later, when we really need conn->thread */
348 CloseHandle( thread );
351 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
356 RpcServerProtseq* cps = the_arg;
358 BOOL set_ready_event = FALSE;
360 TRACE("(the_arg == ^%p)\n", the_arg);
363 objs = cps->ops->get_wait_array(cps, objs, &count);
367 /* signal to function that changed state that we are now sync'ed */
368 SetEvent(cps->server_ready_event);
369 set_ready_event = FALSE;
373 res = cps->ops->wait_for_new_connection(cps, count, objs);
380 SetEvent(cps->server_ready_event);
383 set_ready_event = TRUE;
386 cps->ops->free_wait_array(cps, objs);
387 EnterCriticalSection(&cps->cs);
388 /* close connections */
391 RPCRT4_CloseConnection(conn);
394 LeaveCriticalSection(&cps->cs);
398 /* tells the server thread that the state has changed and waits for it to
399 * make the changes */
400 static void RPCRT4_sync_with_server_thread(RpcServerProtseq *ps)
402 /* make sure we are the only thread sync'ing the server state, otherwise
403 * there is a race with the server thread setting an older state and setting
404 * the server_ready_event when the new state hasn't yet been applied */
405 WaitForSingleObject(ps->mgr_mutex, INFINITE);
407 ps->ops->signal_state_changed(ps);
409 /* wait for server thread to make the requested changes before returning */
410 WaitForSingleObject(ps->server_ready_event, INFINITE);
412 ReleaseMutex(ps->mgr_mutex);
415 static RPC_STATUS RPCRT4_start_listen_protseq(RpcServerProtseq *ps, BOOL auto_listen)
417 RPC_STATUS status = RPC_S_OK;
418 HANDLE server_thread;
420 EnterCriticalSection(&listen_cs);
421 if (ps->is_listening) goto done;
423 if (!ps->mgr_mutex) ps->mgr_mutex = CreateMutexW(NULL, FALSE, NULL);
424 if (!ps->server_ready_event) ps->server_ready_event = CreateEventW(NULL, FALSE, FALSE, NULL);
425 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, ps, 0, NULL);
428 status = RPC_S_OUT_OF_RESOURCES;
431 ps->is_listening = TRUE;
432 CloseHandle(server_thread);
435 LeaveCriticalSection(&listen_cs);
439 static RPC_STATUS RPCRT4_start_listen(BOOL auto_listen)
441 RPC_STATUS status = RPC_S_ALREADY_LISTENING;
442 RpcServerProtseq *cps;
446 EnterCriticalSection(&listen_cs);
447 if (auto_listen || (manual_listen_count++ == 0))
450 if (++listen_count == 1)
453 LeaveCriticalSection(&listen_cs);
457 EnterCriticalSection(&server_cs);
458 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
460 status = RPCRT4_start_listen_protseq(cps, TRUE);
461 if (status != RPC_S_OK)
464 /* make sure server is actually listening on the interface before
466 RPCRT4_sync_with_server_thread(cps);
468 LeaveCriticalSection(&server_cs);
474 static void RPCRT4_stop_listen(BOOL auto_listen)
476 EnterCriticalSection(&listen_cs);
477 if (auto_listen || (--manual_listen_count == 0))
479 if (listen_count != 0 && --listen_count == 0) {
480 RpcServerProtseq *cps;
483 LeaveCriticalSection(&listen_cs);
485 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
486 RPCRT4_sync_with_server_thread(cps);
490 assert(listen_count >= 0);
492 LeaveCriticalSection(&listen_cs);
495 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
499 status = ps->ops->open_endpoint(ps, ps->Endpoint);
500 if (status != RPC_S_OK)
503 EnterCriticalSection(&server_cs);
504 list_add_head(&protseqs, &ps->entry);
505 LeaveCriticalSection(&server_cs);
509 status = RPCRT4_start_listen_protseq(ps, FALSE);
510 if (status == RPC_S_OK)
511 RPCRT4_sync_with_server_thread(ps);
517 /***********************************************************************
518 * RpcServerInqBindings (RPCRT4.@)
520 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
524 RpcServerProtseq* ps;
528 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
530 ERR("(BindingVector == NULL!!?)\n");
532 EnterCriticalSection(&server_cs);
533 /* count connections */
535 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
536 EnterCriticalSection(&ps->cs);
542 LeaveCriticalSection(&ps->cs);
545 /* export bindings */
546 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
547 sizeof(RPC_BINDING_VECTOR) +
548 sizeof(RPC_BINDING_HANDLE)*(count-1));
549 (*BindingVector)->Count = count;
551 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
552 EnterCriticalSection(&ps->cs);
555 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
560 LeaveCriticalSection(&ps->cs);
564 *BindingVector = NULL;
565 status = RPC_S_NO_BINDINGS;
567 LeaveCriticalSection(&server_cs);
571 /***********************************************************************
572 * RpcServerUseProtseqEpA (RPCRT4.@)
574 RPC_STATUS WINAPI RpcServerUseProtseqEpA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor )
578 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
580 /* This should provide the default behaviour */
581 policy.Length = sizeof( policy );
582 policy.EndpointFlags = 0;
585 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
588 /***********************************************************************
589 * RpcServerUseProtseqEpW (RPCRT4.@)
591 RPC_STATUS WINAPI RpcServerUseProtseqEpW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor )
595 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
597 /* This should provide the default behaviour */
598 policy.Length = sizeof( policy );
599 policy.EndpointFlags = 0;
602 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
605 /***********************************************************************
606 * alloc_serverprotoseq (internal)
608 static RpcServerProtseq *alloc_serverprotoseq(UINT MaxCalls, char *Protseq, char *Endpoint)
610 RpcServerProtseq* ps;
611 const struct protseq_ops *ops = rpcrt4_get_protseq_ops(Protseq);
619 ps->MaxCalls = MaxCalls;
620 ps->Protseq = Protseq;
621 ps->Endpoint = Endpoint;
625 InitializeCriticalSection(&ps->cs);
626 ps->is_listening = FALSE;
627 ps->mgr_mutex = NULL;
628 ps->server_ready_event = NULL;
633 /***********************************************************************
634 * RpcServerUseProtseqEpExA (RPCRT4.@)
636 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor,
637 PRPC_POLICY lpPolicy )
639 char *szps = (char*)Protseq, *szep = (char*)Endpoint;
640 RpcServerProtseq* ps;
642 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps), MaxCalls,
643 debugstr_a(szep), SecurityDescriptor,
644 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
646 ps = alloc_serverprotoseq(MaxCalls, RPCRT4_strdupA(szps), RPCRT4_strdupA(szep));
648 return RPCRT4_use_protseq(ps);
651 /***********************************************************************
652 * RpcServerUseProtseqEpExW (RPCRT4.@)
654 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor,
655 PRPC_POLICY lpPolicy )
657 RpcServerProtseq* ps;
659 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
660 debugstr_w( Endpoint ), SecurityDescriptor,
661 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
663 ps = alloc_serverprotoseq(MaxCalls, RPCRT4_strdupWtoA(Protseq),
664 RPCRT4_strdupWtoA(Endpoint));
666 return RPCRT4_use_protseq(ps);
669 /***********************************************************************
670 * RpcServerUseProtseqA (RPCRT4.@)
672 RPC_STATUS WINAPI RpcServerUseProtseqA(RPC_CSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
674 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq), MaxCalls, SecurityDescriptor);
675 return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
678 /***********************************************************************
679 * RpcServerUseProtseqW (RPCRT4.@)
681 RPC_STATUS WINAPI RpcServerUseProtseqW(RPC_WSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
683 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
684 return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
687 /***********************************************************************
688 * RpcServerRegisterIf (RPCRT4.@)
690 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
692 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
693 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
696 /***********************************************************************
697 * RpcServerRegisterIfEx (RPCRT4.@)
699 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
700 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
702 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
703 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
706 /***********************************************************************
707 * RpcServerRegisterIf2 (RPCRT4.@)
709 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
710 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
712 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
713 RpcServerInterface* sif;
716 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
717 MaxRpcSize, IfCallbackFn);
718 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
719 If->InterfaceId.SyntaxVersion.MajorVersion,
720 If->InterfaceId.SyntaxVersion.MinorVersion);
721 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
722 If->TransferSyntax.SyntaxVersion.MajorVersion,
723 If->TransferSyntax.SyntaxVersion.MinorVersion);
724 TRACE(" dispatch table: %p\n", If->DispatchTable);
725 if (If->DispatchTable) {
726 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
727 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
728 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
730 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
732 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
733 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
734 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
736 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
739 memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
740 sif->MgrEpv = MgrEpv;
742 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
743 sif->MgrEpv = If->DefaultManagerEpv;
746 sif->MaxCalls = MaxCalls;
747 sif->MaxRpcSize = MaxRpcSize;
748 sif->IfCallbackFn = IfCallbackFn;
750 EnterCriticalSection(&server_cs);
753 LeaveCriticalSection(&server_cs);
755 if (sif->Flags & RPC_IF_AUTOLISTEN)
756 RPCRT4_start_listen(TRUE);
761 /***********************************************************************
762 * RpcServerUnregisterIf (RPCRT4.@)
764 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
766 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
767 IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
772 /***********************************************************************
773 * RpcServerUnregisterIfEx (RPCRT4.@)
775 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
777 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
778 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
783 /***********************************************************************
784 * RpcObjectSetType (RPCRT4.@)
787 * ObjUuid [I] "Object" UUID
788 * TypeUuid [I] "Type" UUID
791 * RPC_S_OK The call succeeded
792 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
793 * RPC_S_ALREADY_REGISTERED The provided object is already registered
795 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
796 * resets the mapping for the specified object UUID to nil (the default).
797 * The nil object is always associated with the nil type and cannot be
798 * reassigned. Servers can support multiple implementations on the same
799 * interface by registering different end-point vectors for the different
800 * types. There's no need to call this if a server only supports the nil
801 * type, as is typical.
803 RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
805 RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
808 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
809 if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
810 /* nil uuid cannot be remapped */
811 return RPC_S_INVALID_OBJECT;
814 /* find the mapping for this object if there is one ... */
816 if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
820 if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
821 /* ... and drop it from the list */
824 prev->next = map->next;
826 RpcObjTypeMaps = map->next;
827 HeapFree(GetProcessHeap(), 0, map);
830 /* ... , fail if we found it ... */
832 return RPC_S_ALREADY_REGISTERED;
833 /* ... otherwise create a new one and add it in. */
834 map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
835 memcpy(&map->Object, ObjUuid, sizeof(UUID));
836 memcpy(&map->Type, TypeUuid, sizeof(UUID));
839 prev->next = map; /* prev is the last map in the linklist */
841 RpcObjTypeMaps = map;
847 /***********************************************************************
848 * RpcServerRegisterAuthInfoA (RPCRT4.@)
850 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
853 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
855 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
858 /***********************************************************************
859 * RpcServerRegisterAuthInfoW (RPCRT4.@)
861 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
864 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
866 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
869 /***********************************************************************
870 * RpcServerListen (RPCRT4.@)
872 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
874 RPC_STATUS status = RPC_S_OK;
876 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
878 if (list_empty(&protseqs))
879 return RPC_S_NO_PROTSEQS_REGISTERED;
881 status = RPCRT4_start_listen(FALSE);
883 if (DontWait || (status != RPC_S_OK)) return status;
885 return RpcMgmtWaitServerListen();
888 /***********************************************************************
889 * RpcMgmtServerWaitListen (RPCRT4.@)
891 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
895 EnterCriticalSection(&listen_cs);
898 LeaveCriticalSection(&listen_cs);
899 return RPC_S_NOT_LISTENING;
902 LeaveCriticalSection(&listen_cs);
904 FIXME("not waiting for server calls to finish\n");
909 /***********************************************************************
910 * RpcMgmtStopServerListening (RPCRT4.@)
912 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
914 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
917 FIXME("client-side invocation not implemented.\n");
918 return RPC_S_WRONG_KIND_OF_BINDING;
921 RPCRT4_stop_listen(FALSE);
926 /***********************************************************************
927 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
929 RPC_STATUS WINAPI RpcMgmtEnableIdleCleanup(void)
935 /***********************************************************************
936 * I_RpcServerStartListening (RPCRT4.@)
938 RPC_STATUS WINAPI I_RpcServerStartListening( HWND hWnd )
940 FIXME( "(%p): stub\n", hWnd );
945 /***********************************************************************
946 * I_RpcServerStopListening (RPCRT4.@)
948 RPC_STATUS WINAPI I_RpcServerStopListening( void )
950 FIXME( "(): stub\n" );
955 /***********************************************************************
956 * I_RpcWindowProc (RPCRT4.@)
958 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
960 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd, Message, wParam, lParam );
965 /***********************************************************************
966 * RpcMgmtInqIfIds (RPCRT4.@)
968 RPC_STATUS WINAPI RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding, RPC_IF_ID_VECTOR **IfIdVector)
970 FIXME("(%p,%p): stub\n", Binding, IfIdVector);
971 return RPC_S_INVALID_BINDING;
974 /***********************************************************************
975 * RpcMgmtEpEltInqBegin (RPCRT4.@)
977 RPC_STATUS WINAPI RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding, unsigned long InquiryType,
978 RPC_IF_ID *IfId, unsigned long VersOption, UUID *ObjectUuid, RPC_EP_INQ_HANDLE* InquiryContext)
980 FIXME("(%p,%lu,%p,%lu,%p,%p): stub\n",
981 Binding, InquiryType, IfId, VersOption, ObjectUuid, InquiryContext);
982 return RPC_S_INVALID_BINDING;
985 /***********************************************************************
986 * RpcMgmtIsServerListening (RPCRT4.@)
988 RPC_STATUS WINAPI RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding)
990 FIXME("(%p): stub\n", Binding);
991 return RPC_S_INVALID_BINDING;
994 /***********************************************************************
995 * RpcMgmtSetServerStackSize (RPCRT4.@)
997 RPC_STATUS WINAPI RpcMgmtSetServerStackSize(unsigned long ThreadStackSize)
999 FIXME("(0x%lx): stub\n", ThreadStackSize);