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"
42 #include "wine/debug.h"
43 #include "wine/exception.h"
45 #include "rpc_server.h"
47 #include "rpc_message.h"
50 #define MAX_THREADS 128
52 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
54 typedef struct _RpcPacket
56 struct _RpcPacket* next;
57 struct _RpcConnection* conn;
62 typedef struct _RpcObjTypeMap
64 /* FIXME: a hash table would be better. */
65 struct _RpcObjTypeMap *next;
70 static RpcObjTypeMap *RpcObjTypeMaps;
72 static RpcServerProtseq* protseqs;
73 static RpcServerInterface* ifs;
75 static CRITICAL_SECTION server_cs;
76 static CRITICAL_SECTION_DEBUG server_cs_debug =
79 { &server_cs_debug.ProcessLocksList, &server_cs_debug.ProcessLocksList },
80 0, 0, { (DWORD_PTR)(__FILE__ ": server_cs") }
82 static CRITICAL_SECTION server_cs = { &server_cs_debug, -1, 0, 0, 0, 0 };
84 static CRITICAL_SECTION listen_cs;
85 static CRITICAL_SECTION_DEBUG listen_cs_debug =
88 { &listen_cs_debug.ProcessLocksList, &listen_cs_debug.ProcessLocksList },
89 0, 0, { (DWORD_PTR)(__FILE__ ": listen_cs") }
91 static CRITICAL_SECTION listen_cs = { &listen_cs_debug, -1, 0, 0, 0, 0 };
93 /* whether the server is currently listening */
94 static BOOL std_listen;
95 /* number of manual listeners (calls to RpcServerListen) */
96 static LONG manual_listen_count;
97 /* total listeners including auto listeners */
98 static LONG listen_count;
99 /* set on change of configuration (e.g. listening on new protseq) */
100 static HANDLE mgr_event;
101 /* mutex for ensuring only one thread can change state at a time */
102 static HANDLE mgr_mutex;
103 /* set when server thread has finished opening connections */
104 static HANDLE server_ready_event;
106 static CRITICAL_SECTION spacket_cs;
107 static CRITICAL_SECTION_DEBUG spacket_cs_debug =
110 { &spacket_cs_debug.ProcessLocksList, &spacket_cs_debug.ProcessLocksList },
111 0, 0, { (DWORD_PTR)(__FILE__ ": spacket_cs") }
113 static CRITICAL_SECTION spacket_cs = { &spacket_cs_debug, -1, 0, 0, 0, 0 };
115 static RpcPacket* spacket_head;
116 static RpcPacket* spacket_tail;
117 static HANDLE server_sem;
119 static LONG worker_count, worker_free, worker_tls;
121 static UUID uuid_nil;
123 inline static RpcObjTypeMap *LookupObjTypeMap(UUID *ObjUuid)
125 RpcObjTypeMap *rslt = RpcObjTypeMaps;
129 if (! UuidCompare(ObjUuid, &rslt->Object, &dummy)) break;
136 inline static UUID *LookupObjType(UUID *ObjUuid)
138 RpcObjTypeMap *map = LookupObjTypeMap(ObjUuid);
145 static RpcServerInterface* RPCRT4_find_interface(UUID* object,
146 RPC_SYNTAX_IDENTIFIER* if_id,
149 UUID* MgrType = NULL;
150 RpcServerInterface* cif = NULL;
154 MgrType = LookupObjType(object);
155 EnterCriticalSection(&server_cs);
158 if (!memcmp(if_id, &cif->If->InterfaceId, sizeof(RPC_SYNTAX_IDENTIFIER)) &&
159 (check_object == FALSE || UuidEqual(MgrType, &cif->MgrTypeUuid, &status)) &&
163 LeaveCriticalSection(&server_cs);
164 TRACE("returning %p for %s\n", cif, debugstr_guid(object));
168 static void RPCRT4_push_packet(RpcPacket* packet)
171 EnterCriticalSection(&spacket_cs);
173 spacket_tail->next = packet;
174 spacket_tail = packet;
176 spacket_head = packet;
177 spacket_tail = packet;
179 LeaveCriticalSection(&spacket_cs);
182 static RpcPacket* RPCRT4_pop_packet(void)
185 EnterCriticalSection(&spacket_cs);
186 packet = spacket_head;
188 spacket_head = packet->next;
189 if (!spacket_head) spacket_tail = NULL;
191 LeaveCriticalSection(&spacket_cs);
192 if (packet) packet->next = NULL;
201 static WINE_EXCEPTION_FILTER(rpc_filter)
205 state = TlsGetValue(worker_tls);
207 if (msg->Buffer != state->buf) I_RpcFreeBuffer(msg);
208 msg->RpcFlags |= WINE_RPCFLAG_EXCEPTION;
209 msg->BufferLength = sizeof(DWORD);
211 *(DWORD*)msg->Buffer = GetExceptionCode();
212 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD*)msg->Buffer, *(DWORD*)msg->Buffer);
213 TRACE("returning failure packet\n");
214 return EXCEPTION_EXECUTE_HANDLER;
217 static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr, RPC_MESSAGE* msg)
219 RpcServerInterface* sif;
220 RPC_DISPATCH_FUNCTION func;
224 void *buf = msg->Buffer;
229 TlsSetValue(worker_tls, &state);
231 switch (hdr->common.ptype) {
233 TRACE("got bind packet\n");
235 /* FIXME: do more checks! */
236 if (hdr->bind.max_tsize < RPC_MIN_PACKET_SIZE ||
237 !UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
238 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
241 sif = RPCRT4_find_interface(NULL, &hdr->bind.abstract, FALSE);
244 TRACE("rejecting bind request on connection %p\n", conn);
245 /* Report failure to client. */
246 response = RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION,
247 RPC_VER_MAJOR, RPC_VER_MINOR);
249 TRACE("accepting bind request on connection %p\n", conn);
252 response = RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION,
256 RESULT_ACCEPT, NO_REASON,
257 &sif->If->TransferSyntax);
259 /* save the interface for later use */
260 conn->ActiveInterface = hdr->bind.abstract;
261 conn->MaxTransmissionSize = hdr->bind.max_tsize;
264 if (RPCRT4_Send(conn, response, NULL, 0) != RPC_S_OK)
270 TRACE("got request packet\n");
272 /* fail if the connection isn't bound with an interface */
273 if (UuidIsNil(&conn->ActiveInterface.SyntaxGUID, &status)) {
274 response = RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION,
277 RPCRT4_Send(conn, response, NULL, 0);
281 if (hdr->common.flags & RPC_FLG_OBJECT_UUID) {
282 object_uuid = (UUID*)(&hdr->request + 1);
287 sif = RPCRT4_find_interface(object_uuid, &conn->ActiveInterface, TRUE);
288 msg->RpcInterfaceInformation = sif->If;
289 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
290 msg->ManagerEpv = sif->MgrEpv;
291 if (object_uuid != NULL) {
292 RPCRT4_SetBindingObject(msg->Handle, object_uuid);
295 /* find dispatch function */
296 msg->ProcNum = hdr->request.opnum;
297 if (sif->Flags & RPC_IF_OLE) {
298 /* native ole32 always gives us a dispatch table with a single entry
299 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
300 func = *sif->If->DispatchTable->DispatchTable;
302 if (msg->ProcNum >= sif->If->DispatchTable->DispatchTableCount) {
303 ERR("invalid procnum\n");
306 func = sif->If->DispatchTable->DispatchTable[msg->ProcNum];
309 /* put in the drep. FIXME: is this more universally applicable?
310 perhaps we should move this outward... */
311 msg->DataRepresentation =
312 MAKELONG( MAKEWORD(hdr->common.drep[0], hdr->common.drep[1]),
313 MAKEWORD(hdr->common.drep[2], hdr->common.drep[3]));
318 } __EXCEPT(rpc_filter) {
319 /* failure packet was created in rpc_filter */
322 /* send response packet */
325 msg->RpcInterfaceInformation = NULL;
330 FIXME("unhandled packet type\n");
336 if (msg->Buffer == buf) msg->Buffer = NULL;
337 TRACE("freeing Buffer=%p\n", buf);
338 HeapFree(GetProcessHeap(), 0, buf);
339 RPCRT4_DestroyBinding(msg->Handle);
341 I_RpcFreeBuffer(msg);
343 RPCRT4_FreeHeader(hdr);
344 TlsSetValue(worker_tls, NULL);
347 static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
353 /* idle timeout after 5s */
354 obj = WaitForSingleObject(server_sem, 5000);
355 if (obj == WAIT_TIMEOUT) {
356 /* if another idle thread exist, self-destruct */
357 if (worker_free > 1) break;
360 pkt = RPCRT4_pop_packet();
362 InterlockedDecrement(&worker_free);
364 RPCRT4_process_packet(pkt->conn, pkt->hdr, pkt->msg);
365 HeapFree(GetProcessHeap(), 0, pkt);
366 /* try to grab another packet here without waiting
367 * on the semaphore, in case it hits max */
368 pkt = RPCRT4_pop_packet();
370 /* decrement semaphore */
371 WaitForSingleObject(server_sem, 0);
373 InterlockedIncrement(&worker_free);
375 InterlockedDecrement(&worker_free);
376 InterlockedDecrement(&worker_count);
380 static void RPCRT4_create_worker_if_needed(void)
382 if (!worker_free && worker_count < MAX_THREADS) {
384 InterlockedIncrement(&worker_count);
385 InterlockedIncrement(&worker_free);
386 thread = CreateThread(NULL, 0, RPCRT4_worker_thread, NULL, 0, NULL);
387 if (thread) CloseHandle(thread);
389 InterlockedDecrement(&worker_free);
390 InterlockedDecrement(&worker_count);
395 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
397 RpcConnection* conn = (RpcConnection*)the_arg;
404 TRACE("(%p)\n", conn);
407 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RPC_MESSAGE));
409 /* create temporary binding for dispatch, it will be freed in
410 * RPCRT4_process_packet */
411 RPCRT4_MakeBinding(&pbind, conn);
412 msg->Handle = (RPC_BINDING_HANDLE)pbind;
414 status = RPCRT4_Receive(conn, &hdr, msg);
415 if (status != RPC_S_OK) {
416 WARN("receive failed with error %lx\n", status);
421 RPCRT4_process_packet(conn, hdr, msg);
423 packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
427 RPCRT4_create_worker_if_needed();
428 RPCRT4_push_packet(packet);
429 ReleaseSemaphore(server_sem, 1, NULL);
433 HeapFree(GetProcessHeap(), 0, msg);
434 RPCRT4_DestroyConnection(conn);
438 static void RPCRT4_new_client(RpcConnection* conn)
440 HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
442 DWORD err = GetLastError();
443 ERR("failed to create thread, error=%08lx\n", err);
444 RPCRT4_DestroyConnection(conn);
446 /* we could set conn->thread, but then we'd have to make the io_thread wait
447 * for that, otherwise the thread might finish, destroy the connection, and
448 * free the memory we'd write to before we did, causing crashes and stuff -
449 * so let's implement that later, when we really need conn->thread */
451 CloseHandle( thread );
454 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
456 HANDLE m_event = mgr_event, b_handle;
459 RpcServerProtseq* cps;
461 RpcConnection* cconn;
462 BOOL set_ready_event = FALSE;
464 TRACE("(the_arg == ^%p)\n", the_arg);
467 EnterCriticalSection(&server_cs);
468 /* open and count connections */
474 RPCRT4_OpenConnection(conn);
475 if (conn->ovl.hEvent) count++;
480 /* make array of connections */
482 objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
484 objs = HeapAlloc(GetProcessHeap(), 0, count*sizeof(HANDLE));
492 if (conn->ovl.hEvent) objs[count++] = conn->ovl.hEvent;
497 LeaveCriticalSection(&server_cs);
501 /* signal to function that changed state that we are now sync'ed */
502 SetEvent(server_ready_event);
503 set_ready_event = FALSE;
507 res = WaitForMultipleObjects(count, objs, FALSE, INFINITE);
508 if (res == WAIT_OBJECT_0) {
511 SetEvent(server_ready_event);
514 set_ready_event = TRUE;
516 else if (res == WAIT_FAILED) {
517 ERR("wait failed\n");
520 b_handle = objs[res - WAIT_OBJECT_0];
521 /* find which connection got a RPC */
522 EnterCriticalSection(&server_cs);
528 if (conn->ovl.hEvent == b_handle) break;
535 if (conn) RPCRT4_SpawnConnection(&cconn, conn);
536 LeaveCriticalSection(&server_cs);
538 ERR("failed to locate connection for handle %p\n", b_handle);
540 if (cconn) RPCRT4_new_client(cconn);
543 HeapFree(GetProcessHeap(), 0, objs);
544 EnterCriticalSection(&server_cs);
545 /* close connections */
550 RPCRT4_CloseConnection(conn);
555 LeaveCriticalSection(&server_cs);
559 /* tells the server thread that the state has changed and waits for it to
560 * make the changes */
561 static void RPCRT4_sync_with_server_thread(void)
563 /* make sure we are the only thread sync'ing the server state, otherwise
564 * there is a race with the server thread setting an older state and setting
565 * the server_ready_event when the new state hasn't yet been applied */
566 WaitForSingleObject(mgr_mutex, INFINITE);
569 /* wait for server thread to make the requested changes before returning */
570 WaitForSingleObject(server_ready_event, INFINITE);
572 ReleaseMutex(mgr_mutex);
575 static RPC_STATUS RPCRT4_start_listen(BOOL auto_listen)
577 RPC_STATUS status = RPC_S_ALREADY_LISTENING;
581 EnterCriticalSection(&listen_cs);
582 if (auto_listen || (manual_listen_count++ == 0))
585 if (++listen_count == 1) {
586 HANDLE server_thread;
587 /* first listener creates server thread */
588 if (!mgr_mutex) mgr_mutex = CreateMutexW(NULL, FALSE, NULL);
589 if (!mgr_event) mgr_event = CreateEventW(NULL, FALSE, FALSE, NULL);
590 if (!server_ready_event) server_ready_event = CreateEventW(NULL, FALSE, FALSE, NULL);
591 if (!server_sem) server_sem = CreateSemaphoreW(NULL, 0, MAX_THREADS, NULL);
592 if (!worker_tls) worker_tls = TlsAlloc();
594 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);
595 CloseHandle(server_thread);
598 LeaveCriticalSection(&listen_cs);
603 static void RPCRT4_stop_listen(BOOL auto_listen)
605 EnterCriticalSection(&listen_cs);
606 if (auto_listen || (--manual_listen_count == 0))
608 if (listen_count != 0 && --listen_count == 0) {
610 LeaveCriticalSection(&listen_cs);
611 RPCRT4_sync_with_server_thread();
614 assert(listen_count >= 0);
616 LeaveCriticalSection(&listen_cs);
619 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
621 RPCRT4_CreateConnection(&ps->conn, TRUE, ps->Protseq, NULL, ps->Endpoint, NULL, NULL);
623 EnterCriticalSection(&server_cs);
626 LeaveCriticalSection(&server_cs);
628 if (std_listen) RPCRT4_sync_with_server_thread();
633 /***********************************************************************
634 * RpcServerInqBindings (RPCRT4.@)
636 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
640 RpcServerProtseq* ps;
644 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
646 ERR("(BindingVector == NULL!!?)\n");
648 EnterCriticalSection(&server_cs);
649 /* count connections */
661 /* export bindings */
662 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
663 sizeof(RPC_BINDING_VECTOR) +
664 sizeof(RPC_BINDING_HANDLE)*(count-1));
665 (*BindingVector)->Count = count;
671 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
680 *BindingVector = NULL;
681 status = RPC_S_NO_BINDINGS;
683 LeaveCriticalSection(&server_cs);
687 /***********************************************************************
688 * RpcServerUseProtseqEpA (RPCRT4.@)
690 RPC_STATUS WINAPI RpcServerUseProtseqEpA( unsigned char *Protseq, UINT MaxCalls, unsigned char *Endpoint, LPVOID SecurityDescriptor )
694 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
696 /* This should provide the default behaviour */
697 policy.Length = sizeof( policy );
698 policy.EndpointFlags = 0;
701 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
704 /***********************************************************************
705 * RpcServerUseProtseqEpW (RPCRT4.@)
707 RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
711 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
713 /* This should provide the default behaviour */
714 policy.Length = sizeof( policy );
715 policy.EndpointFlags = 0;
718 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
721 /***********************************************************************
722 * RpcServerUseProtseqEpExA (RPCRT4.@)
724 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( unsigned char *Protseq, UINT MaxCalls, unsigned char *Endpoint, LPVOID SecurityDescriptor,
725 PRPC_POLICY lpPolicy )
727 RpcServerProtseq* ps;
729 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( (char*)Protseq ), MaxCalls,
730 debugstr_a( (char*)Endpoint ), SecurityDescriptor,
731 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
733 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
734 ps->MaxCalls = MaxCalls;
735 ps->Protseq = RPCRT4_strdupA((char*)Protseq);
736 ps->Endpoint = RPCRT4_strdupA((char*)Endpoint);
738 return RPCRT4_use_protseq(ps);
741 /***********************************************************************
742 * RpcServerUseProtseqEpExW (RPCRT4.@)
744 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
745 PRPC_POLICY lpPolicy )
747 RpcServerProtseq* ps;
749 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
750 debugstr_w( Endpoint ), SecurityDescriptor,
751 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
753 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
754 ps->MaxCalls = MaxCalls;
755 ps->Protseq = RPCRT4_strdupWtoA(Protseq);
756 ps->Endpoint = RPCRT4_strdupWtoA(Endpoint);
758 return RPCRT4_use_protseq(ps);
761 /***********************************************************************
762 * RpcServerUseProtseqA (RPCRT4.@)
764 RPC_STATUS WINAPI RpcServerUseProtseqA(unsigned char *Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
766 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq), MaxCalls, SecurityDescriptor);
767 return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
770 /***********************************************************************
771 * RpcServerUseProtseqW (RPCRT4.@)
773 RPC_STATUS WINAPI RpcServerUseProtseqW(LPWSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
775 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
776 return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
779 /***********************************************************************
780 * RpcServerRegisterIf (RPCRT4.@)
782 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
784 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
785 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
788 /***********************************************************************
789 * RpcServerRegisterIfEx (RPCRT4.@)
791 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
792 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
794 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
795 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
798 /***********************************************************************
799 * RpcServerRegisterIf2 (RPCRT4.@)
801 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
802 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
804 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
805 RpcServerInterface* sif;
808 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
809 MaxRpcSize, IfCallbackFn);
810 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
811 If->InterfaceId.SyntaxVersion.MajorVersion,
812 If->InterfaceId.SyntaxVersion.MinorVersion);
813 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
814 If->TransferSyntax.SyntaxVersion.MajorVersion,
815 If->TransferSyntax.SyntaxVersion.MinorVersion);
816 TRACE(" dispatch table: %p\n", If->DispatchTable);
817 if (If->DispatchTable) {
818 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
819 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
820 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
822 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
824 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
825 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
826 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
828 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
831 memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
832 sif->MgrEpv = MgrEpv;
834 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
835 sif->MgrEpv = If->DefaultManagerEpv;
838 sif->MaxCalls = MaxCalls;
839 sif->MaxRpcSize = MaxRpcSize;
840 sif->IfCallbackFn = IfCallbackFn;
842 EnterCriticalSection(&server_cs);
845 LeaveCriticalSection(&server_cs);
847 if (sif->Flags & RPC_IF_AUTOLISTEN) {
848 RPCRT4_start_listen(TRUE);
850 /* make sure server is actually listening on the interface before
852 RPCRT4_sync_with_server_thread();
858 /***********************************************************************
859 * RpcServerUnregisterIf (RPCRT4.@)
861 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
863 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
864 IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
869 /***********************************************************************
870 * RpcServerUnregisterIfEx (RPCRT4.@)
872 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
874 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
875 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
880 /***********************************************************************
881 * RpcObjectSetType (RPCRT4.@)
884 * ObjUuid [I] "Object" UUID
885 * TypeUuid [I] "Type" UUID
888 * RPC_S_OK The call succeeded
889 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
890 * RPC_S_ALREADY_REGISTERED The provided object is already registered
892 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
893 * resets the mapping for the specified object UUID to nil (the default).
894 * The nil object is always associated with the nil type and cannot be
895 * reassigned. Servers can support multiple implementations on the same
896 * interface by registering different end-point vectors for the different
897 * types. There's no need to call this if a server only supports the nil
898 * type, as is typical.
900 RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
902 RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
905 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
906 if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
907 /* nil uuid cannot be remapped */
908 return RPC_S_INVALID_OBJECT;
911 /* find the mapping for this object if there is one ... */
913 if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
917 if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
918 /* ... and drop it from the list */
921 prev->next = map->next;
923 RpcObjTypeMaps = map->next;
924 HeapFree(GetProcessHeap(), 0, map);
927 /* ... , fail if we found it ... */
929 return RPC_S_ALREADY_REGISTERED;
930 /* ... otherwise create a new one and add it in. */
931 map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
932 memcpy(&map->Object, ObjUuid, sizeof(UUID));
933 memcpy(&map->Type, TypeUuid, sizeof(UUID));
936 prev->next = map; /* prev is the last map in the linklist */
938 RpcObjTypeMaps = map;
944 /***********************************************************************
945 * RpcServerRegisterAuthInfoA (RPCRT4.@)
947 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
950 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
952 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
955 /***********************************************************************
956 * RpcServerRegisterAuthInfoW (RPCRT4.@)
958 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
961 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
963 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
966 /***********************************************************************
967 * RpcServerListen (RPCRT4.@)
969 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
973 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
976 return RPC_S_NO_PROTSEQS_REGISTERED;
978 status = RPCRT4_start_listen(FALSE);
980 if (status == RPC_S_OK)
981 RPCRT4_sync_with_server_thread();
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);
1007 /***********************************************************************
1008 * RpcMgmtStopServerListening (RPCRT4.@)
1010 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
1012 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
1015 FIXME("client-side invocation not implemented.\n");
1016 return RPC_S_WRONG_KIND_OF_BINDING;
1019 RPCRT4_stop_listen(FALSE);
1024 /***********************************************************************
1025 * I_RpcServerStartListening (RPCRT4.@)
1027 RPC_STATUS WINAPI I_RpcServerStartListening( HWND hWnd )
1029 FIXME( "(%p): stub\n", hWnd );
1034 /***********************************************************************
1035 * I_RpcServerStopListening (RPCRT4.@)
1037 RPC_STATUS WINAPI I_RpcServerStopListening( void )
1039 FIXME( "(): stub\n" );
1044 /***********************************************************************
1045 * I_RpcWindowProc (RPCRT4.@)
1047 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
1049 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd, Message, wParam, lParam );