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
;
106 /* thread that waits for connections */
107 static HANDLE server_thread
;
109 static CRITICAL_SECTION spacket_cs
;
110 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
113 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
114 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
116 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
118 static RpcPacket
* spacket_head
;
119 static RpcPacket
* spacket_tail
;
120 static HANDLE server_sem
;
122 static DWORD worker_count
, worker_free
, worker_tls
;
124 static UUID uuid_nil
;
126 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
128 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
132 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
139 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
141 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
148 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
149 RPC_SYNTAX_IDENTIFIER
* if_id
,
152 UUID
* MgrType
= NULL
;
153 RpcServerInterface
* cif
= NULL
;
157 MgrType
= LookupObjType(object
);
158 EnterCriticalSection(&server_cs
);
161 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
162 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
166 LeaveCriticalSection(&server_cs
);
167 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
171 static void RPCRT4_push_packet(RpcPacket
* packet
)
174 EnterCriticalSection(&spacket_cs
);
176 spacket_tail
->next
= packet
;
177 spacket_tail
= packet
;
179 spacket_head
= packet
;
180 spacket_tail
= packet
;
182 LeaveCriticalSection(&spacket_cs
);
185 static RpcPacket
* RPCRT4_pop_packet(void)
188 EnterCriticalSection(&spacket_cs
);
189 packet
= spacket_head
;
191 spacket_head
= packet
->next
;
192 if (!spacket_head
) spacket_tail
= NULL
;
194 LeaveCriticalSection(&spacket_cs
);
195 if (packet
) packet
->next
= NULL
;
205 static WINE_EXCEPTION_FILTER(rpc_filter
)
209 state
= TlsGetValue(worker_tls
);
211 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
212 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
213 msg
->BufferLength
= sizeof(DWORD
);
215 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
216 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
217 TRACE("returning failure packet\n");
218 return EXCEPTION_EXECUTE_HANDLER
;
222 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
224 RpcServerInterface
* sif
;
225 RPC_DISPATCH_FUNCTION func
;
231 void *buf
= msg
->Buffer
;
237 TlsSetValue(worker_tls
, &state
);
240 switch (hdr
->common
.ptype
) {
242 TRACE("got bind packet\n");
244 /* FIXME: do more checks! */
245 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
246 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
247 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
250 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
253 TRACE("rejecting bind request on connection %p\n", conn
);
254 /* Report failure to client. */
255 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
256 RPC_VER_MAJOR
, RPC_VER_MINOR
);
258 TRACE("accepting bind request on connection %p\n", conn
);
261 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
265 RESULT_ACCEPT
, NO_REASON
,
266 &sif
->If
->TransferSyntax
);
268 /* save the interface for later use */
269 conn
->ActiveInterface
= hdr
->bind
.abstract
;
270 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
273 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
279 TRACE("got request packet\n");
281 /* fail if the connection isn't bound with an interface */
282 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
283 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
286 RPCRT4_Send(conn
, response
, NULL
, 0);
290 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
291 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
296 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
297 msg
->RpcInterfaceInformation
= sif
->If
;
298 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
299 msg
->ManagerEpv
= sif
->MgrEpv
;
300 if (object_uuid
!= NULL
) {
301 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
304 /* find dispatch function */
305 msg
->ProcNum
= hdr
->request
.opnum
;
306 if (sif
->Flags
& RPC_IF_OLE
) {
307 /* native ole32 always gives us a dispatch table with a single entry
308 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
309 func
= *sif
->If
->DispatchTable
->DispatchTable
;
311 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
312 ERR("invalid procnum\n");
315 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
318 /* put in the drep. FIXME: is this more universally applicable?
319 perhaps we should move this outward... */
320 msg
->DataRepresentation
=
321 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
322 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
328 } __EXCEPT(rpc_filter
) {
329 /* failure packet was created in rpc_filter */
335 /* send response packet */
338 msg
->RpcInterfaceInformation
= NULL
;
343 FIXME("unhandled packet type\n");
349 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
350 TRACE("freeing Buffer=%p\n", buf
);
351 HeapFree(GetProcessHeap(), 0, buf
);
352 RPCRT4_DestroyBinding(msg
->Handle
);
354 I_RpcFreeBuffer(msg
);
356 RPCRT4_FreeHeader(hdr
);
358 TlsSetValue(worker_tls
, NULL
);
362 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
368 /* idle timeout after 5s */
369 obj
= WaitForSingleObject(server_sem
, 5000);
370 if (obj
== WAIT_TIMEOUT
) {
371 /* if another idle thread exist, self-destruct */
372 if (worker_free
> 1) break;
375 pkt
= RPCRT4_pop_packet();
377 InterlockedDecrement(&worker_free
);
379 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
380 HeapFree(GetProcessHeap(), 0, pkt
);
381 /* try to grab another packet here without waiting
382 * on the semaphore, in case it hits max */
383 pkt
= RPCRT4_pop_packet();
385 /* decrement semaphore */
386 WaitForSingleObject(server_sem
, 0);
388 InterlockedIncrement(&worker_free
);
390 InterlockedDecrement(&worker_free
);
391 InterlockedDecrement(&worker_count
);
395 static void RPCRT4_create_worker_if_needed(void)
397 if (!worker_free
&& worker_count
< MAX_THREADS
) {
399 InterlockedIncrement(&worker_count
);
400 InterlockedIncrement(&worker_free
);
401 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
402 if (thread
) CloseHandle(thread
);
404 InterlockedDecrement(&worker_free
);
405 InterlockedDecrement(&worker_count
);
410 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
412 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
419 TRACE("(%p)\n", conn
);
422 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
424 /* create temporary binding for dispatch, it will be freed in
425 * RPCRT4_process_packet */
426 RPCRT4_MakeBinding(&pbind
, conn
);
427 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
429 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
430 if (status
!= RPC_S_OK
) {
431 WARN("receive failed with error %lx\n", status
);
436 RPCRT4_process_packet(conn
, hdr
, msg
);
438 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
442 RPCRT4_create_worker_if_needed();
443 RPCRT4_push_packet(packet
);
444 ReleaseSemaphore(server_sem
, 1, NULL
);
448 HeapFree(GetProcessHeap(), 0, msg
);
449 RPCRT4_DestroyConnection(conn
);
453 static void RPCRT4_new_client(RpcConnection
* conn
)
455 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
457 DWORD err
= GetLastError();
458 ERR("failed to create thread, error=%08lx\n", err
);
459 RPCRT4_DestroyConnection(conn
);
461 /* we could set conn->thread, but then we'd have to make the io_thread wait
462 * for that, otherwise the thread might finish, destroy the connection, and
463 * free the memory we'd write to before we did, causing crashes and stuff -
464 * so let's implement that later, when we really need conn->thread */
466 CloseHandle( thread
);
469 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
471 HANDLE m_event
= mgr_event
, b_handle
;
474 RpcServerProtseq
* cps
;
476 RpcConnection
* cconn
;
477 BOOL set_ready_event
= FALSE
;
479 TRACE("(the_arg == ^%p)\n", the_arg
);
482 EnterCriticalSection(&server_cs
);
483 /* open and count connections */
489 RPCRT4_OpenConnection(conn
);
490 if (conn
->ovl
[0].hEvent
) count
++;
495 /* make array of connections */
497 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
499 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
507 if (conn
->ovl
[0].hEvent
) objs
[count
++] = conn
->ovl
[0].hEvent
;
512 LeaveCriticalSection(&server_cs
);
516 /* signal to function that changed state that we are now sync'ed */
517 SetEvent(server_ready_event
);
518 set_ready_event
= FALSE
;
522 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
523 if (res
== WAIT_OBJECT_0
) {
526 SetEvent(server_ready_event
);
529 set_ready_event
= TRUE
;
531 else if (res
== WAIT_FAILED
) {
532 ERR("wait failed\n");
535 b_handle
= objs
[res
- WAIT_OBJECT_0
];
536 /* find which connection got a RPC */
537 EnterCriticalSection(&server_cs
);
543 if (conn
->ovl
[0].hEvent
== b_handle
) break;
550 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
551 LeaveCriticalSection(&server_cs
);
553 ERR("failed to locate connection for handle %p\n", b_handle
);
555 if (cconn
) RPCRT4_new_client(cconn
);
558 HeapFree(GetProcessHeap(), 0, objs
);
559 EnterCriticalSection(&server_cs
);
560 /* close connections */
565 RPCRT4_CloseConnection(conn
);
570 LeaveCriticalSection(&server_cs
);
574 /* tells the server thread that the state has changed and waits for it to
575 * make the changes */
576 static void RPCRT4_sync_with_server_thread(void)
578 /* make sure we are the only thread sync'ing the server state, otherwise
579 * there is a race with the server thread setting an older state and setting
580 * the server_ready_event when the new state hasn't yet been applied */
581 WaitForSingleObject(mgr_mutex
, INFINITE
);
584 /* wait for server thread to make the requested changes before returning */
585 WaitForSingleObject(server_ready_event
, INFINITE
);
587 ReleaseMutex(mgr_mutex
);
590 static void RPCRT4_start_listen(BOOL auto_listen
)
594 EnterCriticalSection(&listen_cs
);
595 if (auto_listen
|| (manual_listen_count
++ == 0))
597 if (++listen_count
== 1) {
598 /* first listener creates server thread */
599 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
600 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
601 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
602 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
603 if (!worker_tls
) worker_tls
= TlsAlloc();
605 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
607 LeaveCriticalSection(&listen_cs
);
608 RPCRT4_sync_with_server_thread();
612 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( Protseq
), MaxCalls
,
742 debugstr_a( 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(Protseq
);
748 ps
->Endpoint
= RPCRT4_strdupA(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(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 /* well, start listening, I think... */
861 RPCRT4_start_listen(TRUE
);
867 /***********************************************************************
868 * RpcServerUnregisterIf (RPCRT4.@)
870 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
872 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
873 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
878 /***********************************************************************
879 * RpcServerUnregisterIfEx (RPCRT4.@)
881 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
883 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
884 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
889 /***********************************************************************
890 * RpcObjectSetType (RPCRT4.@)
893 * ObjUuid [I] "Object" UUID
894 * TypeUuid [I] "Type" UUID
897 * RPC_S_OK The call succeeded
898 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
899 * RPC_S_ALREADY_REGISTERED The provided object is already registered
901 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
902 * resets the mapping for the specified object UUID to nil (the default).
903 * The nil object is always associated with the nil type and cannot be
904 * reassigned. Servers can support multiple implementations on the same
905 * interface by registering different end-point vectors for the different
906 * types. There's no need to call this if a server only supports the nil
907 * type, as is typical.
909 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
911 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
914 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
915 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
916 /* nil uuid cannot be remapped */
917 return RPC_S_INVALID_OBJECT
;
920 /* find the mapping for this object if there is one ... */
922 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
926 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
927 /* ... and drop it from the list */
930 prev
->next
= map
->next
;
932 RpcObjTypeMaps
= map
->next
;
933 HeapFree(GetProcessHeap(), 0, map
);
936 /* ... , fail if we found it ... */
938 return RPC_S_ALREADY_REGISTERED
;
939 /* ... otherwise create a new one and add it in. */
940 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
941 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
942 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
945 prev
->next
= map
; /* prev is the last map in the linklist */
947 RpcObjTypeMaps
= map
;
953 /***********************************************************************
954 * RpcServerRegisterAuthInfoA (RPCRT4.@)
956 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
959 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
961 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
964 /***********************************************************************
965 * RpcServerRegisterAuthInfoW (RPCRT4.@)
967 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
970 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
972 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
975 /***********************************************************************
976 * RpcServerListen (RPCRT4.@)
978 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
980 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
983 return RPC_S_NO_PROTSEQS_REGISTERED
;
985 EnterCriticalSection(&listen_cs
);
988 LeaveCriticalSection(&listen_cs
);
989 return RPC_S_ALREADY_LISTENING
;
992 RPCRT4_start_listen(FALSE
);
994 LeaveCriticalSection(&listen_cs
);
996 if (DontWait
) return RPC_S_OK
;
998 return RpcMgmtWaitServerListen();
1001 /***********************************************************************
1002 * RpcMgmtServerWaitListen (RPCRT4.@)
1004 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1006 RPC_STATUS rslt
= RPC_S_OK
;
1010 EnterCriticalSection(&listen_cs
);
1013 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
1014 LeaveCriticalSection(&listen_cs
);
1018 LeaveCriticalSection(&listen_cs
);
1020 while (std_listen
) {
1021 WaitForSingleObject(mgr_event
, INFINITE
);
1023 Sleep(100); /* don't spin violently */
1024 TRACE("spinning.\n");
1031 /***********************************************************************
1032 * RpcMgmtStopServerListening (RPCRT4.@)
1034 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1036 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1039 FIXME("client-side invocation not implemented.\n");
1040 return RPC_S_WRONG_KIND_OF_BINDING
;
1043 RPCRT4_stop_listen(FALSE
);
1048 /***********************************************************************
1049 * I_RpcServerStartListening (RPCRT4.@)
1051 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1053 FIXME( "(%p): stub\n", hWnd
);
1058 /***********************************************************************
1059 * I_RpcServerStopListening (RPCRT4.@)
1061 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1063 FIXME( "(): stub\n" );
1068 /***********************************************************************
1069 * I_RpcWindowProc (RPCRT4.@)
1071 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1073 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);