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%08lx = %ld\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 static 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=%08lx\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 typedef struct _RpcServerProtseq_np
353 RpcServerProtseq common;
355 } RpcServerProtseq_np;
357 static RpcServerProtseq *rpcrt4_protseq_np_alloc(void)
359 RpcServerProtseq_np *ps = HeapAlloc(GetProcessHeap(), 0, sizeof(*ps));
361 ps->mgr_event = CreateEventW(NULL, FALSE, FALSE, NULL);
365 static void rpcrt4_protseq_np_signal_state_changed(RpcServerProtseq *protseq)
367 RpcServerProtseq_np *npps = CONTAINING_RECORD(protseq, RpcServerProtseq_np, common);
368 SetEvent(npps->mgr_event);
371 static void *rpcrt4_protseq_np_get_wait_array(RpcServerProtseq *protseq, void *prev_array, unsigned int *count)
373 HANDLE *objs = prev_array;
375 RpcServerProtseq_np *npps = CONTAINING_RECORD(protseq, RpcServerProtseq_np, common);
377 EnterCriticalSection(&protseq->cs);
379 /* open and count connections */
381 conn = protseq->conn;
383 RPCRT4_OpenConnection(conn);
384 if (rpcrt4_conn_get_wait_object(conn))
389 /* make array of connections */
391 objs = HeapReAlloc(GetProcessHeap(), 0, objs, *count*sizeof(HANDLE));
393 objs = HeapAlloc(GetProcessHeap(), 0, *count*sizeof(HANDLE));
396 ERR("couldn't allocate objs\n");
397 LeaveCriticalSection(&protseq->cs);
401 objs[0] = npps->mgr_event;
403 conn = protseq->conn;
405 if ((objs[*count] = rpcrt4_conn_get_wait_object(conn)))
409 LeaveCriticalSection(&protseq->cs);
413 static void rpcrt4_protseq_np_free_wait_array(RpcServerProtseq *protseq, void *array)
415 HeapFree(GetProcessHeap(), 0, array);
418 static int rpcrt4_protseq_np_wait_for_new_connection(RpcServerProtseq *protseq, unsigned int count, void *wait_array)
421 HANDLE *objs = wait_array;
423 RpcConnection* cconn;
429 res = WaitForMultipleObjects(count, objs, FALSE, INFINITE);
430 if (res == WAIT_OBJECT_0)
432 else if (res == WAIT_FAILED)
434 ERR("wait failed with error %ld\n", GetLastError());
439 b_handle = objs[res - WAIT_OBJECT_0];
440 /* find which connection got a RPC */
441 EnterCriticalSection(&protseq->cs);
442 conn = protseq->conn;
444 if (b_handle == rpcrt4_conn_get_wait_object(conn)) break;
449 RPCRT4_SpawnConnection(&cconn, conn);
451 ERR("failed to locate connection for handle %p\n", b_handle);
452 LeaveCriticalSection(&protseq->cs);
455 RPCRT4_new_client(cconn);
462 static const struct protseq_ops protseq_list[] =
466 rpcrt4_protseq_np_alloc,
467 rpcrt4_protseq_np_signal_state_changed,
468 rpcrt4_protseq_np_get_wait_array,
469 rpcrt4_protseq_np_free_wait_array,
470 rpcrt4_protseq_np_wait_for_new_connection,
474 rpcrt4_protseq_np_alloc,
475 rpcrt4_protseq_np_signal_state_changed,
476 rpcrt4_protseq_np_get_wait_array,
477 rpcrt4_protseq_np_free_wait_array,
478 rpcrt4_protseq_np_wait_for_new_connection,
482 rpcrt4_protseq_np_alloc,
483 rpcrt4_protseq_np_signal_state_changed,
484 rpcrt4_protseq_np_get_wait_array,
485 rpcrt4_protseq_np_free_wait_array,
486 rpcrt4_protseq_np_wait_for_new_connection,
490 static const struct protseq_ops *rpcrt4_get_protseq_ops(const char *protseq)
493 for(i=0; i < sizeof(protseq_list)/sizeof(protseq_list[0]); i++)
494 if (!strcmp(protseq_list[i].name, protseq))
495 return &protseq_list[i];
499 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
504 RpcServerProtseq* cps = the_arg;
506 BOOL set_ready_event = FALSE;
508 TRACE("(the_arg == ^%p)\n", the_arg);
511 objs = cps->ops->get_wait_array(cps, objs, &count);
515 /* signal to function that changed state that we are now sync'ed */
516 SetEvent(cps->server_ready_event);
517 set_ready_event = FALSE;
521 res = cps->ops->wait_for_new_connection(cps, count, objs);
528 SetEvent(cps->server_ready_event);
531 set_ready_event = TRUE;
534 cps->ops->free_wait_array(cps, objs);
535 EnterCriticalSection(&cps->cs);
536 /* close connections */
539 RPCRT4_CloseConnection(conn);
542 LeaveCriticalSection(&cps->cs);
546 /* tells the server thread that the state has changed and waits for it to
547 * make the changes */
548 static void RPCRT4_sync_with_server_thread(RpcServerProtseq *ps)
550 /* make sure we are the only thread sync'ing the server state, otherwise
551 * there is a race with the server thread setting an older state and setting
552 * the server_ready_event when the new state hasn't yet been applied */
553 WaitForSingleObject(ps->mgr_mutex, INFINITE);
555 ps->ops->signal_state_changed(ps);
557 /* wait for server thread to make the requested changes before returning */
558 WaitForSingleObject(ps->server_ready_event, INFINITE);
560 ReleaseMutex(ps->mgr_mutex);
563 static RPC_STATUS RPCRT4_start_listen_protseq(RpcServerProtseq *ps, BOOL auto_listen)
565 RPC_STATUS status = RPC_S_OK;
566 HANDLE server_thread;
568 EnterCriticalSection(&listen_cs);
569 if (ps->is_listening) goto done;
571 if (!ps->mgr_mutex) ps->mgr_mutex = CreateMutexW(NULL, FALSE, NULL);
572 if (!ps->server_ready_event) ps->server_ready_event = CreateEventW(NULL, FALSE, FALSE, NULL);
573 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, ps, 0, NULL);
576 status = RPC_S_OUT_OF_RESOURCES;
579 ps->is_listening = TRUE;
580 CloseHandle(server_thread);
583 LeaveCriticalSection(&listen_cs);
587 static RPC_STATUS RPCRT4_start_listen(BOOL auto_listen)
589 RPC_STATUS status = RPC_S_ALREADY_LISTENING;
590 RpcServerProtseq *cps;
594 EnterCriticalSection(&listen_cs);
595 if (auto_listen || (manual_listen_count++ == 0))
598 if (++listen_count == 1)
601 LeaveCriticalSection(&listen_cs);
605 EnterCriticalSection(&server_cs);
606 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
608 status = RPCRT4_start_listen_protseq(cps, TRUE);
609 if (status != RPC_S_OK)
612 /* make sure server is actually listening on the interface before
614 RPCRT4_sync_with_server_thread(cps);
616 LeaveCriticalSection(&server_cs);
622 static void RPCRT4_stop_listen(BOOL auto_listen)
624 EnterCriticalSection(&listen_cs);
625 if (auto_listen || (--manual_listen_count == 0))
627 if (listen_count != 0 && --listen_count == 0) {
628 RpcServerProtseq *cps;
631 LeaveCriticalSection(&listen_cs);
633 LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
634 RPCRT4_sync_with_server_thread(cps);
638 assert(listen_count >= 0);
640 LeaveCriticalSection(&listen_cs);
643 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
647 status = RPCRT4_CreateConnection(&ps->conn, TRUE, ps->Protseq, NULL,
648 ps->Endpoint, NULL, NULL, NULL);
649 if (status != RPC_S_OK)
652 EnterCriticalSection(&server_cs);
653 list_add_head(&protseqs, &ps->entry);
654 LeaveCriticalSection(&server_cs);
658 status = RPCRT4_start_listen_protseq(ps, FALSE);
659 if (status == RPC_S_OK)
660 RPCRT4_sync_with_server_thread(ps);
666 /***********************************************************************
667 * RpcServerInqBindings (RPCRT4.@)
669 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
673 RpcServerProtseq* ps;
677 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
679 ERR("(BindingVector == NULL!!?)\n");
681 EnterCriticalSection(&server_cs);
682 /* count connections */
684 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
685 EnterCriticalSection(&ps->cs);
691 LeaveCriticalSection(&ps->cs);
694 /* export bindings */
695 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
696 sizeof(RPC_BINDING_VECTOR) +
697 sizeof(RPC_BINDING_HANDLE)*(count-1));
698 (*BindingVector)->Count = count;
700 LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
701 EnterCriticalSection(&ps->cs);
704 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
709 LeaveCriticalSection(&ps->cs);
713 *BindingVector = NULL;
714 status = RPC_S_NO_BINDINGS;
716 LeaveCriticalSection(&server_cs);
720 /***********************************************************************
721 * RpcServerUseProtseqEpA (RPCRT4.@)
723 RPC_STATUS WINAPI RpcServerUseProtseqEpA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor )
727 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
729 /* This should provide the default behaviour */
730 policy.Length = sizeof( policy );
731 policy.EndpointFlags = 0;
734 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
737 /***********************************************************************
738 * RpcServerUseProtseqEpW (RPCRT4.@)
740 RPC_STATUS WINAPI RpcServerUseProtseqEpW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor )
744 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
746 /* This should provide the default behaviour */
747 policy.Length = sizeof( policy );
748 policy.EndpointFlags = 0;
751 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
754 /***********************************************************************
755 * alloc_serverprotoseq (internal)
757 static RpcServerProtseq *alloc_serverprotoseq(UINT MaxCalls, char *Protseq, char *Endpoint)
759 RpcServerProtseq* ps;
760 const struct protseq_ops *ops = rpcrt4_get_protseq_ops(Protseq);
768 ps->MaxCalls = MaxCalls;
769 ps->Protseq = Protseq;
770 ps->Endpoint = Endpoint;
774 InitializeCriticalSection(&ps->cs);
775 ps->is_listening = FALSE;
776 ps->mgr_mutex = NULL;
777 ps->server_ready_event = NULL;
782 /***********************************************************************
783 * RpcServerUseProtseqEpExA (RPCRT4.@)
785 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( RPC_CSTR Protseq, UINT MaxCalls, RPC_CSTR Endpoint, LPVOID SecurityDescriptor,
786 PRPC_POLICY lpPolicy )
788 char *szps = (char*)Protseq, *szep = (char*)Endpoint;
789 RpcServerProtseq* ps;
791 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps), MaxCalls,
792 debugstr_a(szep), SecurityDescriptor,
793 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
795 ps = alloc_serverprotoseq(MaxCalls, RPCRT4_strdupA(szps), RPCRT4_strdupA(szep));
797 return RPCRT4_use_protseq(ps);
800 /***********************************************************************
801 * RpcServerUseProtseqEpExW (RPCRT4.@)
803 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor,
804 PRPC_POLICY lpPolicy )
806 RpcServerProtseq* ps;
808 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
809 debugstr_w( Endpoint ), SecurityDescriptor,
810 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
812 ps = alloc_serverprotoseq(MaxCalls, RPCRT4_strdupWtoA(Protseq),
813 RPCRT4_strdupWtoA(Endpoint));
815 return RPCRT4_use_protseq(ps);
818 /***********************************************************************
819 * RpcServerUseProtseqA (RPCRT4.@)
821 RPC_STATUS WINAPI RpcServerUseProtseqA(RPC_CSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
823 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq), MaxCalls, SecurityDescriptor);
824 return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
827 /***********************************************************************
828 * RpcServerUseProtseqW (RPCRT4.@)
830 RPC_STATUS WINAPI RpcServerUseProtseqW(RPC_WSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
832 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
833 return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
836 /***********************************************************************
837 * RpcServerRegisterIf (RPCRT4.@)
839 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
841 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
842 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
845 /***********************************************************************
846 * RpcServerRegisterIfEx (RPCRT4.@)
848 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
849 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
851 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
852 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
855 /***********************************************************************
856 * RpcServerRegisterIf2 (RPCRT4.@)
858 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
859 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
861 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
862 RpcServerInterface* sif;
865 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
866 MaxRpcSize, IfCallbackFn);
867 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
868 If->InterfaceId.SyntaxVersion.MajorVersion,
869 If->InterfaceId.SyntaxVersion.MinorVersion);
870 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
871 If->TransferSyntax.SyntaxVersion.MajorVersion,
872 If->TransferSyntax.SyntaxVersion.MinorVersion);
873 TRACE(" dispatch table: %p\n", If->DispatchTable);
874 if (If->DispatchTable) {
875 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
876 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
877 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
879 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
881 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
882 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
883 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
885 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
888 memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
889 sif->MgrEpv = MgrEpv;
891 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
892 sif->MgrEpv = If->DefaultManagerEpv;
895 sif->MaxCalls = MaxCalls;
896 sif->MaxRpcSize = MaxRpcSize;
897 sif->IfCallbackFn = IfCallbackFn;
899 EnterCriticalSection(&server_cs);
902 LeaveCriticalSection(&server_cs);
904 if (sif->Flags & RPC_IF_AUTOLISTEN)
905 RPCRT4_start_listen(TRUE);
910 /***********************************************************************
911 * RpcServerUnregisterIf (RPCRT4.@)
913 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
915 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
916 IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
921 /***********************************************************************
922 * RpcServerUnregisterIfEx (RPCRT4.@)
924 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
926 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
927 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
932 /***********************************************************************
933 * RpcObjectSetType (RPCRT4.@)
936 * ObjUuid [I] "Object" UUID
937 * TypeUuid [I] "Type" UUID
940 * RPC_S_OK The call succeeded
941 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
942 * RPC_S_ALREADY_REGISTERED The provided object is already registered
944 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
945 * resets the mapping for the specified object UUID to nil (the default).
946 * The nil object is always associated with the nil type and cannot be
947 * reassigned. Servers can support multiple implementations on the same
948 * interface by registering different end-point vectors for the different
949 * types. There's no need to call this if a server only supports the nil
950 * type, as is typical.
952 RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
954 RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
957 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
958 if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
959 /* nil uuid cannot be remapped */
960 return RPC_S_INVALID_OBJECT;
963 /* find the mapping for this object if there is one ... */
965 if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
969 if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
970 /* ... and drop it from the list */
973 prev->next = map->next;
975 RpcObjTypeMaps = map->next;
976 HeapFree(GetProcessHeap(), 0, map);
979 /* ... , fail if we found it ... */
981 return RPC_S_ALREADY_REGISTERED;
982 /* ... otherwise create a new one and add it in. */
983 map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
984 memcpy(&map->Object, ObjUuid, sizeof(UUID));
985 memcpy(&map->Type, TypeUuid, sizeof(UUID));
988 prev->next = map; /* prev is the last map in the linklist */
990 RpcObjTypeMaps = map;
996 /***********************************************************************
997 * RpcServerRegisterAuthInfoA (RPCRT4.@)
999 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
1002 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
1004 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
1007 /***********************************************************************
1008 * RpcServerRegisterAuthInfoW (RPCRT4.@)
1010 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName, unsigned long AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
1013 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
1015 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
1018 /***********************************************************************
1019 * RpcServerListen (RPCRT4.@)
1021 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
1023 RPC_STATUS status = RPC_S_OK;
1025 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
1027 if (list_empty(&protseqs))
1028 return RPC_S_NO_PROTSEQS_REGISTERED;
1030 status = RPCRT4_start_listen(FALSE);
1032 if (DontWait || (status != RPC_S_OK)) return status;
1034 return RpcMgmtWaitServerListen();
1037 /***********************************************************************
1038 * RpcMgmtServerWaitListen (RPCRT4.@)
1040 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
1044 EnterCriticalSection(&listen_cs);
1047 LeaveCriticalSection(&listen_cs);
1048 return RPC_S_NOT_LISTENING;
1051 LeaveCriticalSection(&listen_cs);
1053 FIXME("not waiting for server calls to finish\n");
1058 /***********************************************************************
1059 * RpcMgmtStopServerListening (RPCRT4.@)
1061 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
1063 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
1066 FIXME("client-side invocation not implemented.\n");
1067 return RPC_S_WRONG_KIND_OF_BINDING;
1070 RPCRT4_stop_listen(FALSE);
1075 /***********************************************************************
1076 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
1078 RPC_STATUS WINAPI RpcMgmtEnableIdleCleanup(void)
1080 FIXME("(): stub\n");
1084 /***********************************************************************
1085 * I_RpcServerStartListening (RPCRT4.@)
1087 RPC_STATUS WINAPI I_RpcServerStartListening( HWND hWnd )
1089 FIXME( "(%p): stub\n", hWnd );
1094 /***********************************************************************
1095 * I_RpcServerStopListening (RPCRT4.@)
1097 RPC_STATUS WINAPI I_RpcServerStopListening( void )
1099 FIXME( "(): stub\n" );
1104 /***********************************************************************
1105 * I_RpcWindowProc (RPCRT4.@)
1107 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
1109 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd, Message, wParam, lParam );
1114 /***********************************************************************
1115 * RpcMgmtInqIfIds (RPCRT4.@)
1117 RPC_STATUS WINAPI RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding, RPC_IF_ID_VECTOR **IfIdVector)
1119 FIXME("(%p,%p): stub\n", Binding, IfIdVector);
1120 return RPC_S_INVALID_BINDING;
1123 /***********************************************************************
1124 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1126 RPC_STATUS WINAPI RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding, unsigned long InquiryType,
1127 RPC_IF_ID *IfId, unsigned long VersOption, UUID *ObjectUuid, RPC_EP_INQ_HANDLE* InquiryContext)
1129 FIXME("(%p,%lu,%p,%lu,%p,%p): stub\n",
1130 Binding, InquiryType, IfId, VersOption, ObjectUuid, InquiryContext);
1131 return RPC_S_INVALID_BINDING;
1134 /***********************************************************************
1135 * RpcMgmtIsServerListening (RPCRT4.@)
1137 RPC_STATUS WINAPI RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding)
1139 FIXME("(%p): stub\n", Binding);
1140 return RPC_S_INVALID_BINDING;
1143 /***********************************************************************
1144 * RpcMgmtSetServerStackSize (RPCRT4.@)
1146 RPC_STATUS WINAPI RpcMgmtSetServerStackSize(unsigned long ThreadStackSize)
1148 FIXME("(0x%lx): stub\n", ThreadStackSize);