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"
43 #include "wine/debug.h"
44 #include "wine/exception.h"
46 #include "rpc_server.h"
48 #include "rpc_message.h"
51 #define MAX_THREADS 128
53 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
55 typedef struct _RpcPacket
57 struct _RpcPacket
* next
;
58 struct _RpcConnection
* conn
;
63 typedef struct _RpcObjTypeMap
65 /* FIXME: a hash table would be better. */
66 struct _RpcObjTypeMap
*next
;
71 static RpcObjTypeMap
*RpcObjTypeMaps
;
73 static RpcServerProtseq
* protseqs
;
74 static RpcServerInterface
* ifs
;
76 static CRITICAL_SECTION server_cs
;
77 static CRITICAL_SECTION_DEBUG server_cs_debug
=
80 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
81 0, 0, { 0, (DWORD
)(__FILE__
": server_cs") }
83 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
85 static CRITICAL_SECTION listen_cs
;
86 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
89 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
90 0, 0, { 0, (DWORD
)(__FILE__
": listen_cs") }
92 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
94 /* whether the server is currently listening */
95 static BOOL std_listen
;
96 /* number of manual listeners (calls to RpcServerListen) */
97 static LONG manual_listen_count
;
98 /* total listeners including auto listeners */
99 static LONG listen_count
;
100 /* set on change of configuration (e.g. listening on new protseq) */
101 static HANDLE mgr_event
;
102 /* mutex for ensuring only one thread can change state at a time */
103 static HANDLE mgr_mutex
;
104 /* set when server thread has finished opening connections */
105 static HANDLE server_ready_event
;
107 static CRITICAL_SECTION spacket_cs
;
108 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
111 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
112 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
114 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
116 static RpcPacket
* spacket_head
;
117 static RpcPacket
* spacket_tail
;
118 static HANDLE server_sem
;
120 static DWORD worker_count
, worker_free
, worker_tls
;
122 static UUID uuid_nil
;
124 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
126 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
130 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
137 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
139 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
146 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
147 RPC_SYNTAX_IDENTIFIER
* if_id
,
150 UUID
* MgrType
= NULL
;
151 RpcServerInterface
* cif
= NULL
;
155 MgrType
= LookupObjType(object
);
156 EnterCriticalSection(&server_cs
);
159 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
160 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
164 LeaveCriticalSection(&server_cs
);
165 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
169 static void RPCRT4_push_packet(RpcPacket
* packet
)
172 EnterCriticalSection(&spacket_cs
);
174 spacket_tail
->next
= packet
;
175 spacket_tail
= packet
;
177 spacket_head
= packet
;
178 spacket_tail
= packet
;
180 LeaveCriticalSection(&spacket_cs
);
183 static RpcPacket
* RPCRT4_pop_packet(void)
186 EnterCriticalSection(&spacket_cs
);
187 packet
= spacket_head
;
189 spacket_head
= packet
->next
;
190 if (!spacket_head
) spacket_tail
= NULL
;
192 LeaveCriticalSection(&spacket_cs
);
193 if (packet
) packet
->next
= NULL
;
203 static WINE_EXCEPTION_FILTER(rpc_filter
)
207 state
= TlsGetValue(worker_tls
);
209 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
210 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
211 msg
->BufferLength
= sizeof(DWORD
);
213 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
214 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
215 TRACE("returning failure packet\n");
216 return EXCEPTION_EXECUTE_HANDLER
;
220 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
222 RpcServerInterface
* sif
;
223 RPC_DISPATCH_FUNCTION func
;
229 void *buf
= msg
->Buffer
;
235 TlsSetValue(worker_tls
, &state
);
238 switch (hdr
->common
.ptype
) {
240 TRACE("got bind packet\n");
242 /* FIXME: do more checks! */
243 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
244 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
245 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
248 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
251 TRACE("rejecting bind request on connection %p\n", conn
);
252 /* Report failure to client. */
253 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
254 RPC_VER_MAJOR
, RPC_VER_MINOR
);
256 TRACE("accepting bind request on connection %p\n", conn
);
259 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
263 RESULT_ACCEPT
, NO_REASON
,
264 &sif
->If
->TransferSyntax
);
266 /* save the interface for later use */
267 conn
->ActiveInterface
= hdr
->bind
.abstract
;
268 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
271 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
277 TRACE("got request packet\n");
279 /* fail if the connection isn't bound with an interface */
280 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
281 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
284 RPCRT4_Send(conn
, response
, NULL
, 0);
288 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
289 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
294 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
295 msg
->RpcInterfaceInformation
= sif
->If
;
296 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
297 msg
->ManagerEpv
= sif
->MgrEpv
;
298 if (object_uuid
!= NULL
) {
299 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
302 /* find dispatch function */
303 msg
->ProcNum
= hdr
->request
.opnum
;
304 if (sif
->Flags
& RPC_IF_OLE
) {
305 /* native ole32 always gives us a dispatch table with a single entry
306 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
307 func
= *sif
->If
->DispatchTable
->DispatchTable
;
309 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
310 ERR("invalid procnum\n");
313 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
316 /* put in the drep. FIXME: is this more universally applicable?
317 perhaps we should move this outward... */
318 msg
->DataRepresentation
=
319 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
320 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
326 } __EXCEPT(rpc_filter
) {
327 /* failure packet was created in rpc_filter */
333 /* send response packet */
336 msg
->RpcInterfaceInformation
= NULL
;
341 FIXME("unhandled packet type\n");
347 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
348 TRACE("freeing Buffer=%p\n", buf
);
349 HeapFree(GetProcessHeap(), 0, buf
);
350 RPCRT4_DestroyBinding(msg
->Handle
);
352 I_RpcFreeBuffer(msg
);
354 RPCRT4_FreeHeader(hdr
);
356 TlsSetValue(worker_tls
, NULL
);
360 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
366 /* idle timeout after 5s */
367 obj
= WaitForSingleObject(server_sem
, 5000);
368 if (obj
== WAIT_TIMEOUT
) {
369 /* if another idle thread exist, self-destruct */
370 if (worker_free
> 1) break;
373 pkt
= RPCRT4_pop_packet();
375 InterlockedDecrement(&worker_free
);
377 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
378 HeapFree(GetProcessHeap(), 0, pkt
);
379 /* try to grab another packet here without waiting
380 * on the semaphore, in case it hits max */
381 pkt
= RPCRT4_pop_packet();
383 /* decrement semaphore */
384 WaitForSingleObject(server_sem
, 0);
386 InterlockedIncrement(&worker_free
);
388 InterlockedDecrement(&worker_free
);
389 InterlockedDecrement(&worker_count
);
393 static void RPCRT4_create_worker_if_needed(void)
395 if (!worker_free
&& worker_count
< MAX_THREADS
) {
397 InterlockedIncrement(&worker_count
);
398 InterlockedIncrement(&worker_free
);
399 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
400 if (thread
) CloseHandle(thread
);
402 InterlockedDecrement(&worker_free
);
403 InterlockedDecrement(&worker_count
);
408 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
410 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
417 TRACE("(%p)\n", conn
);
420 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
422 /* create temporary binding for dispatch, it will be freed in
423 * RPCRT4_process_packet */
424 RPCRT4_MakeBinding(&pbind
, conn
);
425 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
427 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
428 if (status
!= RPC_S_OK
) {
429 WARN("receive failed with error %lx\n", status
);
434 RPCRT4_process_packet(conn
, hdr
, msg
);
436 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
440 RPCRT4_create_worker_if_needed();
441 RPCRT4_push_packet(packet
);
442 ReleaseSemaphore(server_sem
, 1, NULL
);
446 HeapFree(GetProcessHeap(), 0, msg
);
447 RPCRT4_DestroyConnection(conn
);
451 static void RPCRT4_new_client(RpcConnection
* conn
)
453 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
455 DWORD err
= GetLastError();
456 ERR("failed to create thread, error=%08lx\n", err
);
457 RPCRT4_DestroyConnection(conn
);
459 /* we could set conn->thread, but then we'd have to make the io_thread wait
460 * for that, otherwise the thread might finish, destroy the connection, and
461 * free the memory we'd write to before we did, causing crashes and stuff -
462 * so let's implement that later, when we really need conn->thread */
464 CloseHandle( thread
);
467 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
469 HANDLE m_event
= mgr_event
, b_handle
;
472 RpcServerProtseq
* cps
;
474 RpcConnection
* cconn
;
475 BOOL set_ready_event
= FALSE
;
477 TRACE("(the_arg == ^%p)\n", the_arg
);
480 EnterCriticalSection(&server_cs
);
481 /* open and count connections */
487 RPCRT4_OpenConnection(conn
);
488 if (conn
->ovl
[0].hEvent
) count
++;
493 /* make array of connections */
495 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
497 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
505 if (conn
->ovl
[0].hEvent
) objs
[count
++] = conn
->ovl
[0].hEvent
;
510 LeaveCriticalSection(&server_cs
);
514 /* signal to function that changed state that we are now sync'ed */
515 SetEvent(server_ready_event
);
516 set_ready_event
= FALSE
;
520 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
521 if (res
== WAIT_OBJECT_0
) {
524 SetEvent(server_ready_event
);
527 set_ready_event
= TRUE
;
529 else if (res
== WAIT_FAILED
) {
530 ERR("wait failed\n");
533 b_handle
= objs
[res
- WAIT_OBJECT_0
];
534 /* find which connection got a RPC */
535 EnterCriticalSection(&server_cs
);
541 if (conn
->ovl
[0].hEvent
== b_handle
) break;
548 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
549 LeaveCriticalSection(&server_cs
);
551 ERR("failed to locate connection for handle %p\n", b_handle
);
553 if (cconn
) RPCRT4_new_client(cconn
);
556 HeapFree(GetProcessHeap(), 0, objs
);
557 EnterCriticalSection(&server_cs
);
558 /* close connections */
563 RPCRT4_CloseConnection(conn
);
568 LeaveCriticalSection(&server_cs
);
572 /* tells the server thread that the state has changed and waits for it to
573 * make the changes */
574 static void RPCRT4_sync_with_server_thread(void)
576 /* make sure we are the only thread sync'ing the server state, otherwise
577 * there is a race with the server thread setting an older state and setting
578 * the server_ready_event when the new state hasn't yet been applied */
579 WaitForSingleObject(mgr_mutex
, INFINITE
);
582 /* wait for server thread to make the requested changes before returning */
583 WaitForSingleObject(server_ready_event
, INFINITE
);
585 ReleaseMutex(mgr_mutex
);
588 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
590 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
594 EnterCriticalSection(&listen_cs
);
595 if (auto_listen
|| (manual_listen_count
++ == 0))
598 if (++listen_count
== 1) {
599 HANDLE server_thread
;
600 /* first listener creates server thread */
601 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
602 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
603 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
604 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
605 if (!worker_tls
) worker_tls
= TlsAlloc();
607 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
608 CloseHandle(server_thread
);
611 LeaveCriticalSection(&listen_cs
);
616 static void RPCRT4_stop_listen(BOOL auto_listen
)
618 EnterCriticalSection(&listen_cs
);
619 if (auto_listen
|| (--manual_listen_count
== 0))
621 if (listen_count
!= 0 && --listen_count
== 0) {
623 LeaveCriticalSection(&listen_cs
);
624 RPCRT4_sync_with_server_thread();
627 assert(listen_count
>= 0);
629 LeaveCriticalSection(&listen_cs
);
632 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
634 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
636 EnterCriticalSection(&server_cs
);
639 LeaveCriticalSection(&server_cs
);
641 if (std_listen
) RPCRT4_sync_with_server_thread();
646 /***********************************************************************
647 * RpcServerInqBindings (RPCRT4.@)
649 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
653 RpcServerProtseq
* ps
;
657 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
659 ERR("(BindingVector == NULL!!?)\n");
661 EnterCriticalSection(&server_cs
);
662 /* count connections */
674 /* export bindings */
675 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
676 sizeof(RPC_BINDING_VECTOR
) +
677 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
678 (*BindingVector
)->Count
= count
;
684 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
693 *BindingVector
= NULL
;
694 status
= RPC_S_NO_BINDINGS
;
696 LeaveCriticalSection(&server_cs
);
700 /***********************************************************************
701 * RpcServerUseProtseqEpA (RPCRT4.@)
703 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
707 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
709 /* This should provide the default behaviour */
710 policy
.Length
= sizeof( policy
);
711 policy
.EndpointFlags
= 0;
714 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
717 /***********************************************************************
718 * RpcServerUseProtseqEpW (RPCRT4.@)
720 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
724 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
726 /* This should provide the default behaviour */
727 policy
.Length
= sizeof( policy
);
728 policy
.EndpointFlags
= 0;
731 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
734 /***********************************************************************
735 * RpcServerUseProtseqEpExA (RPCRT4.@)
737 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
738 PRPC_POLICY lpPolicy
)
740 RpcServerProtseq
* ps
;
742 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
743 debugstr_a( Endpoint
), SecurityDescriptor
,
744 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
746 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
747 ps
->MaxCalls
= MaxCalls
;
748 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
749 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
751 return RPCRT4_use_protseq(ps
);
754 /***********************************************************************
755 * RpcServerUseProtseqEpExW (RPCRT4.@)
757 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
758 PRPC_POLICY lpPolicy
)
760 RpcServerProtseq
* ps
;
762 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
763 debugstr_w( Endpoint
), SecurityDescriptor
,
764 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
766 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
767 ps
->MaxCalls
= MaxCalls
;
768 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
769 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
771 return RPCRT4_use_protseq(ps
);
774 /***********************************************************************
775 * RpcServerUseProtseqA (RPCRT4.@)
777 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
779 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
780 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
783 /***********************************************************************
784 * RpcServerUseProtseqW (RPCRT4.@)
786 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
788 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
789 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
792 /***********************************************************************
793 * RpcServerRegisterIf (RPCRT4.@)
795 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
797 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
798 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
801 /***********************************************************************
802 * RpcServerRegisterIfEx (RPCRT4.@)
804 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
805 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
807 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
808 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
811 /***********************************************************************
812 * RpcServerRegisterIf2 (RPCRT4.@)
814 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
815 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
817 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
818 RpcServerInterface
* sif
;
821 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
822 MaxRpcSize
, IfCallbackFn
);
823 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
824 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
825 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
826 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
827 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
828 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
829 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
830 if (If
->DispatchTable
) {
831 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
832 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
833 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
835 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
837 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
838 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
839 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
841 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
844 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
845 sif
->MgrEpv
= MgrEpv
;
847 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
848 sif
->MgrEpv
= If
->DefaultManagerEpv
;
851 sif
->MaxCalls
= MaxCalls
;
852 sif
->MaxRpcSize
= MaxRpcSize
;
853 sif
->IfCallbackFn
= IfCallbackFn
;
855 EnterCriticalSection(&server_cs
);
858 LeaveCriticalSection(&server_cs
);
860 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
861 RPCRT4_start_listen(TRUE
);
863 /* make sure server is actually listening on the interface before
865 RPCRT4_sync_with_server_thread();
871 /***********************************************************************
872 * RpcServerUnregisterIf (RPCRT4.@)
874 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
876 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
877 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
882 /***********************************************************************
883 * RpcServerUnregisterIfEx (RPCRT4.@)
885 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
887 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
888 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
893 /***********************************************************************
894 * RpcObjectSetType (RPCRT4.@)
897 * ObjUuid [I] "Object" UUID
898 * TypeUuid [I] "Type" UUID
901 * RPC_S_OK The call succeeded
902 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
903 * RPC_S_ALREADY_REGISTERED The provided object is already registered
905 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
906 * resets the mapping for the specified object UUID to nil (the default).
907 * The nil object is always associated with the nil type and cannot be
908 * reassigned. Servers can support multiple implementations on the same
909 * interface by registering different end-point vectors for the different
910 * types. There's no need to call this if a server only supports the nil
911 * type, as is typical.
913 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
915 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
918 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
919 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
920 /* nil uuid cannot be remapped */
921 return RPC_S_INVALID_OBJECT
;
924 /* find the mapping for this object if there is one ... */
926 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
930 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
931 /* ... and drop it from the list */
934 prev
->next
= map
->next
;
936 RpcObjTypeMaps
= map
->next
;
937 HeapFree(GetProcessHeap(), 0, map
);
940 /* ... , fail if we found it ... */
942 return RPC_S_ALREADY_REGISTERED
;
943 /* ... otherwise create a new one and add it in. */
944 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
945 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
946 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
949 prev
->next
= map
; /* prev is the last map in the linklist */
951 RpcObjTypeMaps
= map
;
957 /***********************************************************************
958 * RpcServerRegisterAuthInfoA (RPCRT4.@)
960 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
963 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
965 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
968 /***********************************************************************
969 * RpcServerRegisterAuthInfoW (RPCRT4.@)
971 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
974 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
976 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
979 /***********************************************************************
980 * RpcServerListen (RPCRT4.@)
982 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
986 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
989 return RPC_S_NO_PROTSEQS_REGISTERED
;
991 status
= RPCRT4_start_listen(FALSE
);
993 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
995 return RpcMgmtWaitServerListen();
998 /***********************************************************************
999 * RpcMgmtServerWaitListen (RPCRT4.@)
1001 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1005 EnterCriticalSection(&listen_cs
);
1008 LeaveCriticalSection(&listen_cs
);
1009 return RPC_S_NOT_LISTENING
;
1012 LeaveCriticalSection(&listen_cs
);
1014 RPCRT4_sync_with_server_thread();
1019 /***********************************************************************
1020 * RpcMgmtStopServerListening (RPCRT4.@)
1022 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1024 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1027 FIXME("client-side invocation not implemented.\n");
1028 return RPC_S_WRONG_KIND_OF_BINDING
;
1031 RPCRT4_stop_listen(FALSE
);
1036 /***********************************************************************
1037 * I_RpcServerStartListening (RPCRT4.@)
1039 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1041 FIXME( "(%p): stub\n", hWnd
);
1046 /***********************************************************************
1047 * I_RpcServerStopListening (RPCRT4.@)
1049 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1051 FIXME( "(): stub\n" );
1056 /***********************************************************************
1057 * I_RpcWindowProc (RPCRT4.@)
1059 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1061 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);