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
;
202 static WINE_EXCEPTION_FILTER(rpc_filter
)
206 state
= TlsGetValue(worker_tls
);
208 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
209 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
210 msg
->BufferLength
= sizeof(DWORD
);
212 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
213 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
214 TRACE("returning failure packet\n");
215 return EXCEPTION_EXECUTE_HANDLER
;
219 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
221 RpcServerInterface
* sif
;
222 RPC_DISPATCH_FUNCTION func
;
228 void *buf
= msg
->Buffer
;
234 TlsSetValue(worker_tls
, &state
);
237 switch (hdr
->common
.ptype
) {
239 TRACE("got bind packet\n");
241 /* FIXME: do more checks! */
242 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
243 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
244 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
247 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
250 TRACE("rejecting bind request on connection %p\n", conn
);
251 /* Report failure to client. */
252 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
253 RPC_VER_MAJOR
, RPC_VER_MINOR
);
255 TRACE("accepting bind request on connection %p\n", conn
);
258 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
262 RESULT_ACCEPT
, NO_REASON
,
263 &sif
->If
->TransferSyntax
);
265 /* save the interface for later use */
266 conn
->ActiveInterface
= hdr
->bind
.abstract
;
267 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
270 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
276 TRACE("got request packet\n");
278 /* fail if the connection isn't bound with an interface */
279 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
280 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
283 RPCRT4_Send(conn
, response
, NULL
, 0);
287 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
288 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
293 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
294 msg
->RpcInterfaceInformation
= sif
->If
;
295 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
296 msg
->ManagerEpv
= sif
->MgrEpv
;
297 if (object_uuid
!= NULL
) {
298 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
301 /* find dispatch function */
302 msg
->ProcNum
= hdr
->request
.opnum
;
303 if (sif
->Flags
& RPC_IF_OLE
) {
304 /* native ole32 always gives us a dispatch table with a single entry
305 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
306 func
= *sif
->If
->DispatchTable
->DispatchTable
;
308 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
309 ERR("invalid procnum\n");
312 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
315 /* put in the drep. FIXME: is this more universally applicable?
316 perhaps we should move this outward... */
317 msg
->DataRepresentation
=
318 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
319 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
325 } __EXCEPT(rpc_filter
) {
326 /* failure packet was created in rpc_filter */
332 /* send response packet */
335 msg
->RpcInterfaceInformation
= NULL
;
340 FIXME("unhandled packet type\n");
346 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
347 TRACE("freeing Buffer=%p\n", buf
);
348 HeapFree(GetProcessHeap(), 0, buf
);
349 RPCRT4_DestroyBinding(msg
->Handle
);
351 I_RpcFreeBuffer(msg
);
353 RPCRT4_FreeHeader(hdr
);
355 TlsSetValue(worker_tls
, NULL
);
359 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
365 /* idle timeout after 5s */
366 obj
= WaitForSingleObject(server_sem
, 5000);
367 if (obj
== WAIT_TIMEOUT
) {
368 /* if another idle thread exist, self-destruct */
369 if (worker_free
> 1) break;
372 pkt
= RPCRT4_pop_packet();
374 InterlockedDecrement(&worker_free
);
376 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
377 HeapFree(GetProcessHeap(), 0, pkt
);
378 /* try to grab another packet here without waiting
379 * on the semaphore, in case it hits max */
380 pkt
= RPCRT4_pop_packet();
382 /* decrement semaphore */
383 WaitForSingleObject(server_sem
, 0);
385 InterlockedIncrement(&worker_free
);
387 InterlockedDecrement(&worker_free
);
388 InterlockedDecrement(&worker_count
);
392 static void RPCRT4_create_worker_if_needed(void)
394 if (!worker_free
&& worker_count
< MAX_THREADS
) {
396 InterlockedIncrement(&worker_count
);
397 InterlockedIncrement(&worker_free
);
398 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
399 if (thread
) CloseHandle(thread
);
401 InterlockedDecrement(&worker_free
);
402 InterlockedDecrement(&worker_count
);
407 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
409 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
416 TRACE("(%p)\n", conn
);
419 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
421 /* create temporary binding for dispatch, it will be freed in
422 * RPCRT4_process_packet */
423 RPCRT4_MakeBinding(&pbind
, conn
);
424 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
426 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
427 if (status
!= RPC_S_OK
) {
428 WARN("receive failed with error %lx\n", status
);
433 RPCRT4_process_packet(conn
, hdr
, msg
);
435 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
439 RPCRT4_create_worker_if_needed();
440 RPCRT4_push_packet(packet
);
441 ReleaseSemaphore(server_sem
, 1, NULL
);
445 HeapFree(GetProcessHeap(), 0, msg
);
446 RPCRT4_DestroyConnection(conn
);
450 static void RPCRT4_new_client(RpcConnection
* conn
)
452 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
454 DWORD err
= GetLastError();
455 ERR("failed to create thread, error=%08lx\n", err
);
456 RPCRT4_DestroyConnection(conn
);
458 /* we could set conn->thread, but then we'd have to make the io_thread wait
459 * for that, otherwise the thread might finish, destroy the connection, and
460 * free the memory we'd write to before we did, causing crashes and stuff -
461 * so let's implement that later, when we really need conn->thread */
463 CloseHandle( thread
);
466 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
468 HANDLE m_event
= mgr_event
, b_handle
;
471 RpcServerProtseq
* cps
;
473 RpcConnection
* cconn
;
474 BOOL set_ready_event
= FALSE
;
476 TRACE("(the_arg == ^%p)\n", the_arg
);
479 EnterCriticalSection(&server_cs
);
480 /* open and count connections */
486 RPCRT4_OpenConnection(conn
);
487 if (conn
->ovl
[0].hEvent
) count
++;
492 /* make array of connections */
494 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
496 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
504 if (conn
->ovl
[0].hEvent
) objs
[count
++] = conn
->ovl
[0].hEvent
;
509 LeaveCriticalSection(&server_cs
);
513 /* signal to function that changed state that we are now sync'ed */
514 SetEvent(server_ready_event
);
515 set_ready_event
= FALSE
;
519 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
520 if (res
== WAIT_OBJECT_0
) {
523 SetEvent(server_ready_event
);
526 set_ready_event
= TRUE
;
528 else if (res
== WAIT_FAILED
) {
529 ERR("wait failed\n");
532 b_handle
= objs
[res
- WAIT_OBJECT_0
];
533 /* find which connection got a RPC */
534 EnterCriticalSection(&server_cs
);
540 if (conn
->ovl
[0].hEvent
== b_handle
) break;
547 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
548 LeaveCriticalSection(&server_cs
);
550 ERR("failed to locate connection for handle %p\n", b_handle
);
552 if (cconn
) RPCRT4_new_client(cconn
);
555 HeapFree(GetProcessHeap(), 0, objs
);
556 EnterCriticalSection(&server_cs
);
557 /* close connections */
562 RPCRT4_CloseConnection(conn
);
567 LeaveCriticalSection(&server_cs
);
571 /* tells the server thread that the state has changed and waits for it to
572 * make the changes */
573 static void RPCRT4_sync_with_server_thread(void)
575 /* make sure we are the only thread sync'ing the server state, otherwise
576 * there is a race with the server thread setting an older state and setting
577 * the server_ready_event when the new state hasn't yet been applied */
578 WaitForSingleObject(mgr_mutex
, INFINITE
);
581 /* wait for server thread to make the requested changes before returning */
582 WaitForSingleObject(server_ready_event
, INFINITE
);
584 ReleaseMutex(mgr_mutex
);
587 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
589 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
593 EnterCriticalSection(&listen_cs
);
594 if (auto_listen
|| (manual_listen_count
++ == 0))
597 if (++listen_count
== 1) {
598 HANDLE server_thread
;
599 /* first listener creates server thread */
600 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
601 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
602 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
603 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
604 if (!worker_tls
) worker_tls
= TlsAlloc();
606 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
607 CloseHandle(server_thread
);
610 LeaveCriticalSection(&listen_cs
);
615 static void RPCRT4_stop_listen(BOOL auto_listen
)
617 EnterCriticalSection(&listen_cs
);
618 if (auto_listen
|| (--manual_listen_count
== 0))
620 if (listen_count
!= 0 && --listen_count
== 0) {
622 LeaveCriticalSection(&listen_cs
);
623 RPCRT4_sync_with_server_thread();
626 assert(listen_count
>= 0);
628 LeaveCriticalSection(&listen_cs
);
631 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
633 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
635 EnterCriticalSection(&server_cs
);
638 LeaveCriticalSection(&server_cs
);
640 if (std_listen
) RPCRT4_sync_with_server_thread();
645 /***********************************************************************
646 * RpcServerInqBindings (RPCRT4.@)
648 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
652 RpcServerProtseq
* ps
;
656 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
658 ERR("(BindingVector == NULL!!?)\n");
660 EnterCriticalSection(&server_cs
);
661 /* count connections */
673 /* export bindings */
674 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
675 sizeof(RPC_BINDING_VECTOR
) +
676 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
677 (*BindingVector
)->Count
= count
;
683 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
692 *BindingVector
= NULL
;
693 status
= RPC_S_NO_BINDINGS
;
695 LeaveCriticalSection(&server_cs
);
699 /***********************************************************************
700 * RpcServerUseProtseqEpA (RPCRT4.@)
702 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
706 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
708 /* This should provide the default behaviour */
709 policy
.Length
= sizeof( policy
);
710 policy
.EndpointFlags
= 0;
713 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
716 /***********************************************************************
717 * RpcServerUseProtseqEpW (RPCRT4.@)
719 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
723 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
725 /* This should provide the default behaviour */
726 policy
.Length
= sizeof( policy
);
727 policy
.EndpointFlags
= 0;
730 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
733 /***********************************************************************
734 * RpcServerUseProtseqEpExA (RPCRT4.@)
736 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
737 PRPC_POLICY lpPolicy
)
739 RpcServerProtseq
* ps
;
741 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( (char*)Protseq
), MaxCalls
,
742 debugstr_a( (char*)Endpoint
), SecurityDescriptor
,
743 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
745 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
746 ps
->MaxCalls
= MaxCalls
;
747 ps
->Protseq
= RPCRT4_strdupA((char*)Protseq
);
748 ps
->Endpoint
= RPCRT4_strdupA((char*)Endpoint
);
750 return RPCRT4_use_protseq(ps
);
753 /***********************************************************************
754 * RpcServerUseProtseqEpExW (RPCRT4.@)
756 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
757 PRPC_POLICY lpPolicy
)
759 RpcServerProtseq
* ps
;
761 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
762 debugstr_w( Endpoint
), SecurityDescriptor
,
763 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
765 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
766 ps
->MaxCalls
= MaxCalls
;
767 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
768 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
770 return RPCRT4_use_protseq(ps
);
773 /***********************************************************************
774 * RpcServerUseProtseqA (RPCRT4.@)
776 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
778 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
779 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
782 /***********************************************************************
783 * RpcServerUseProtseqW (RPCRT4.@)
785 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
787 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
788 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
791 /***********************************************************************
792 * RpcServerRegisterIf (RPCRT4.@)
794 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
796 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
797 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
800 /***********************************************************************
801 * RpcServerRegisterIfEx (RPCRT4.@)
803 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
804 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
806 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
807 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
810 /***********************************************************************
811 * RpcServerRegisterIf2 (RPCRT4.@)
813 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
814 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
816 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
817 RpcServerInterface
* sif
;
820 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
821 MaxRpcSize
, IfCallbackFn
);
822 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
823 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
824 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
825 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
826 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
827 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
828 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
829 if (If
->DispatchTable
) {
830 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
831 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
832 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
834 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
836 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
837 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
838 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
840 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
843 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
844 sif
->MgrEpv
= MgrEpv
;
846 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
847 sif
->MgrEpv
= If
->DefaultManagerEpv
;
850 sif
->MaxCalls
= MaxCalls
;
851 sif
->MaxRpcSize
= MaxRpcSize
;
852 sif
->IfCallbackFn
= IfCallbackFn
;
854 EnterCriticalSection(&server_cs
);
857 LeaveCriticalSection(&server_cs
);
859 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
860 RPCRT4_start_listen(TRUE
);
862 /* make sure server is actually listening on the interface before
864 RPCRT4_sync_with_server_thread();
870 /***********************************************************************
871 * RpcServerUnregisterIf (RPCRT4.@)
873 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
875 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
876 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
881 /***********************************************************************
882 * RpcServerUnregisterIfEx (RPCRT4.@)
884 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
886 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
887 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
892 /***********************************************************************
893 * RpcObjectSetType (RPCRT4.@)
896 * ObjUuid [I] "Object" UUID
897 * TypeUuid [I] "Type" UUID
900 * RPC_S_OK The call succeeded
901 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
902 * RPC_S_ALREADY_REGISTERED The provided object is already registered
904 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
905 * resets the mapping for the specified object UUID to nil (the default).
906 * The nil object is always associated with the nil type and cannot be
907 * reassigned. Servers can support multiple implementations on the same
908 * interface by registering different end-point vectors for the different
909 * types. There's no need to call this if a server only supports the nil
910 * type, as is typical.
912 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
914 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
917 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
918 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
919 /* nil uuid cannot be remapped */
920 return RPC_S_INVALID_OBJECT
;
923 /* find the mapping for this object if there is one ... */
925 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
929 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
930 /* ... and drop it from the list */
933 prev
->next
= map
->next
;
935 RpcObjTypeMaps
= map
->next
;
936 HeapFree(GetProcessHeap(), 0, map
);
939 /* ... , fail if we found it ... */
941 return RPC_S_ALREADY_REGISTERED
;
942 /* ... otherwise create a new one and add it in. */
943 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
944 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
945 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
948 prev
->next
= map
; /* prev is the last map in the linklist */
950 RpcObjTypeMaps
= map
;
956 /***********************************************************************
957 * RpcServerRegisterAuthInfoA (RPCRT4.@)
959 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
962 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
964 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
967 /***********************************************************************
968 * RpcServerRegisterAuthInfoW (RPCRT4.@)
970 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
973 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
975 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
978 /***********************************************************************
979 * RpcServerListen (RPCRT4.@)
981 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
985 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
988 return RPC_S_NO_PROTSEQS_REGISTERED
;
990 status
= RPCRT4_start_listen(FALSE
);
992 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
994 return RpcMgmtWaitServerListen();
997 /***********************************************************************
998 * RpcMgmtServerWaitListen (RPCRT4.@)
1000 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1004 EnterCriticalSection(&listen_cs
);
1007 LeaveCriticalSection(&listen_cs
);
1008 return RPC_S_NOT_LISTENING
;
1011 LeaveCriticalSection(&listen_cs
);
1013 RPCRT4_sync_with_server_thread();
1018 /***********************************************************************
1019 * RpcMgmtStopServerListening (RPCRT4.@)
1021 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1023 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1026 FIXME("client-side invocation not implemented.\n");
1027 return RPC_S_WRONG_KIND_OF_BINDING
;
1030 RPCRT4_stop_listen(FALSE
);
1035 /***********************************************************************
1036 * I_RpcServerStartListening (RPCRT4.@)
1038 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1040 FIXME( "(%p): stub\n", hWnd
);
1045 /***********************************************************************
1046 * I_RpcServerStopListening (RPCRT4.@)
1048 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1050 FIXME( "(): stub\n" );
1055 /***********************************************************************
1056 * I_RpcWindowProc (RPCRT4.@)
1058 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1060 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);