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(ole
);
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 static BOOL std_listen
;
95 static LONG listen_count
= -1;
96 static HANDLE mgr_event
, server_thread
;
98 static CRITICAL_SECTION spacket_cs
;
99 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
102 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
103 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
105 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
107 static RpcPacket
* spacket_head
;
108 static RpcPacket
* spacket_tail
;
109 static HANDLE server_sem
;
111 static DWORD worker_count
, worker_free
, worker_tls
;
113 static UUID uuid_nil
;
115 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
117 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
121 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
128 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
130 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
137 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
138 RPC_SYNTAX_IDENTIFIER
* if_id
,
141 UUID
* MgrType
= NULL
;
142 RpcServerInterface
* cif
= NULL
;
146 MgrType
= LookupObjType(object
);
147 EnterCriticalSection(&server_cs
);
150 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
151 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
152 (std_listen
|| (cif
->Flags
& RPC_IF_AUTOLISTEN
))) break;
155 LeaveCriticalSection(&server_cs
);
156 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
160 static void RPCRT4_push_packet(RpcPacket
* packet
)
163 EnterCriticalSection(&spacket_cs
);
165 spacket_tail
->next
= packet
;
166 spacket_tail
= packet
;
168 spacket_head
= packet
;
169 spacket_tail
= packet
;
171 LeaveCriticalSection(&spacket_cs
);
174 static RpcPacket
* RPCRT4_pop_packet(void)
177 EnterCriticalSection(&spacket_cs
);
178 packet
= spacket_head
;
180 spacket_head
= packet
->next
;
181 if (!spacket_head
) spacket_tail
= NULL
;
183 LeaveCriticalSection(&spacket_cs
);
184 if (packet
) packet
->next
= NULL
;
193 static WINE_EXCEPTION_FILTER(rpc_filter
)
197 state
= TlsGetValue(worker_tls
);
199 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
200 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
201 msg
->BufferLength
= sizeof(DWORD
);
203 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
204 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
205 TRACE("returning failure packet\n");
206 return EXCEPTION_EXECUTE_HANDLER
;
209 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
211 RpcServerInterface
* sif
;
212 RPC_DISPATCH_FUNCTION func
;
216 void *buf
= msg
->Buffer
;
221 TlsSetValue(worker_tls
, &state
);
223 switch (hdr
->common
.ptype
) {
225 TRACE("got bind packet\n");
227 /* FIXME: do more checks! */
228 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
229 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
230 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
233 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
236 TRACE("rejecting bind request on connection %p\n", conn
);
237 /* Report failure to client. */
238 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
239 RPC_VER_MAJOR
, RPC_VER_MINOR
);
241 TRACE("accepting bind request on connection %p\n", conn
);
244 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
248 RESULT_ACCEPT
, NO_REASON
,
249 &sif
->If
->TransferSyntax
);
251 /* save the interface for later use */
252 conn
->ActiveInterface
= hdr
->bind
.abstract
;
253 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
256 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
262 TRACE("got request packet\n");
264 /* fail if the connection isn't bound with an interface */
265 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
266 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
269 RPCRT4_Send(conn
, response
, NULL
, 0);
273 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
274 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
279 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
280 msg
->RpcInterfaceInformation
= sif
->If
;
281 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
282 msg
->ManagerEpv
= sif
->MgrEpv
;
283 if (object_uuid
!= NULL
) {
284 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
287 /* find dispatch function */
288 msg
->ProcNum
= hdr
->request
.opnum
;
289 if (sif
->Flags
& RPC_IF_OLE
) {
290 /* native ole32 always gives us a dispatch table with a single entry
291 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
292 func
= *sif
->If
->DispatchTable
->DispatchTable
;
294 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
295 ERR("invalid procnum\n");
298 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
301 /* put in the drep. FIXME: is this more universally applicable?
302 perhaps we should move this outward... */
303 msg
->DataRepresentation
=
304 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
305 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
310 } __EXCEPT(rpc_filter
) {
311 /* failure packet was created in rpc_filter */
314 /* send response packet */
317 msg
->RpcInterfaceInformation
= NULL
;
322 FIXME("unhandled packet type\n");
328 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
329 TRACE("freeing Buffer=%p\n", buf
);
330 HeapFree(GetProcessHeap(), 0, buf
);
331 RPCRT4_DestroyBinding(msg
->Handle
);
333 I_RpcFreeBuffer(msg
);
335 RPCRT4_FreeHeader(hdr
);
336 TlsSetValue(worker_tls
, NULL
);
339 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
345 /* idle timeout after 5s */
346 obj
= WaitForSingleObject(server_sem
, 5000);
347 if (obj
== WAIT_TIMEOUT
) {
348 /* if another idle thread exist, self-destruct */
349 if (worker_free
> 1) break;
352 pkt
= RPCRT4_pop_packet();
354 InterlockedDecrement(&worker_free
);
356 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
357 HeapFree(GetProcessHeap(), 0, pkt
);
358 /* try to grab another packet here without waiting
359 * on the semaphore, in case it hits max */
360 pkt
= RPCRT4_pop_packet();
362 /* decrement semaphore */
363 WaitForSingleObject(server_sem
, 0);
365 InterlockedIncrement(&worker_free
);
367 InterlockedDecrement(&worker_free
);
368 InterlockedDecrement(&worker_count
);
372 static void RPCRT4_create_worker_if_needed(void)
374 if (!worker_free
&& worker_count
< MAX_THREADS
) {
376 InterlockedIncrement(&worker_count
);
377 InterlockedIncrement(&worker_free
);
378 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
379 if (thread
) CloseHandle(thread
);
381 InterlockedDecrement(&worker_free
);
382 InterlockedDecrement(&worker_count
);
387 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
389 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
396 TRACE("(%p)\n", conn
);
399 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
401 /* create temporary binding for dispatch, it will be freed in
402 * RPCRT4_process_packet */
403 RPCRT4_MakeBinding(&pbind
, conn
);
404 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
406 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
407 if (status
!= RPC_S_OK
) {
408 WARN("receive failed with error %lx\n", status
);
413 RPCRT4_process_packet(conn
, hdr
, msg
);
415 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
419 RPCRT4_create_worker_if_needed();
420 RPCRT4_push_packet(packet
);
421 ReleaseSemaphore(server_sem
, 1, NULL
);
425 if (msg
) HeapFree(GetProcessHeap(), 0, msg
);
426 RPCRT4_DestroyConnection(conn
);
430 static void RPCRT4_new_client(RpcConnection
* conn
)
432 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
434 DWORD err
= GetLastError();
435 ERR("failed to create thread, error=%08lx\n", err
);
436 RPCRT4_DestroyConnection(conn
);
438 /* we could set conn->thread, but then we'd have to make the io_thread wait
439 * for that, otherwise the thread might finish, destroy the connection, and
440 * free the memory we'd write to before we did, causing crashes and stuff -
441 * so let's implement that later, when we really need conn->thread */
443 CloseHandle( thread
);
446 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
448 HANDLE m_event
= mgr_event
, b_handle
;
451 RpcServerProtseq
* cps
;
453 RpcConnection
* cconn
;
455 TRACE("(the_arg == ^%p)\n", the_arg
);
458 EnterCriticalSection(&server_cs
);
459 /* open and count connections */
465 RPCRT4_OpenConnection(conn
);
466 if (conn
->ovl
.hEvent
) count
++;
471 /* make array of connections */
473 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
475 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
483 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
488 LeaveCriticalSection(&server_cs
);
491 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
492 if (res
== WAIT_OBJECT_0
) {
494 if (!std_listen
) break;
496 else if (res
== WAIT_FAILED
) {
497 ERR("wait failed\n");
500 b_handle
= objs
[res
- WAIT_OBJECT_0
];
501 /* find which connection got a RPC */
502 EnterCriticalSection(&server_cs
);
508 if (conn
->ovl
.hEvent
== b_handle
) break;
515 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
516 LeaveCriticalSection(&server_cs
);
518 ERR("failed to locate connection for handle %p\n", b_handle
);
520 if (cconn
) RPCRT4_new_client(cconn
);
523 HeapFree(GetProcessHeap(), 0, objs
);
524 EnterCriticalSection(&server_cs
);
525 /* close connections */
530 RPCRT4_CloseConnection(conn
);
535 LeaveCriticalSection(&server_cs
);
539 static void RPCRT4_start_listen(void)
543 EnterCriticalSection(&listen_cs
);
544 if (! ++listen_count
) {
545 if (!mgr_event
) mgr_event
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
546 if (!server_sem
) server_sem
= CreateSemaphoreA(NULL
, 0, MAX_THREADS
, NULL
);
547 if (!worker_tls
) worker_tls
= TlsAlloc();
549 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
550 LeaveCriticalSection(&listen_cs
);
552 LeaveCriticalSection(&listen_cs
);
557 static void RPCRT4_stop_listen(void)
559 EnterCriticalSection(&listen_cs
);
560 if (listen_count
== -1)
561 LeaveCriticalSection(&listen_cs
);
562 else if (--listen_count
== -1) {
564 LeaveCriticalSection(&listen_cs
);
567 LeaveCriticalSection(&listen_cs
);
568 assert(listen_count
> -2);
571 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
573 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
575 EnterCriticalSection(&server_cs
);
578 LeaveCriticalSection(&server_cs
);
580 if (std_listen
) SetEvent(mgr_event
);
585 /***********************************************************************
586 * RpcServerInqBindings (RPCRT4.@)
588 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
592 RpcServerProtseq
* ps
;
596 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
598 ERR("(BindingVector == NULL!!?)\n");
600 EnterCriticalSection(&server_cs
);
601 /* count connections */
613 /* export bindings */
614 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
615 sizeof(RPC_BINDING_VECTOR
) +
616 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
617 (*BindingVector
)->Count
= count
;
623 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
632 *BindingVector
= NULL
;
633 status
= RPC_S_NO_BINDINGS
;
635 LeaveCriticalSection(&server_cs
);
639 /***********************************************************************
640 * RpcServerUseProtseqEpA (RPCRT4.@)
642 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
646 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
648 /* This should provide the default behaviour */
649 policy
.Length
= sizeof( policy
);
650 policy
.EndpointFlags
= 0;
653 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
656 /***********************************************************************
657 * RpcServerUseProtseqEpW (RPCRT4.@)
659 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
663 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
665 /* This should provide the default behaviour */
666 policy
.Length
= sizeof( policy
);
667 policy
.EndpointFlags
= 0;
670 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
673 /***********************************************************************
674 * RpcServerUseProtseqEpExA (RPCRT4.@)
676 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
677 PRPC_POLICY lpPolicy
)
679 RpcServerProtseq
* ps
;
681 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
682 debugstr_a( Endpoint
), SecurityDescriptor
,
683 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
685 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
686 ps
->MaxCalls
= MaxCalls
;
687 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
688 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
690 return RPCRT4_use_protseq(ps
);
693 /***********************************************************************
694 * RpcServerUseProtseqEpExW (RPCRT4.@)
696 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
697 PRPC_POLICY lpPolicy
)
699 RpcServerProtseq
* ps
;
701 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
702 debugstr_w( Endpoint
), SecurityDescriptor
,
703 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
705 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
706 ps
->MaxCalls
= MaxCalls
;
707 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
708 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
710 return RPCRT4_use_protseq(ps
);
713 /***********************************************************************
714 * RpcServerUseProtseqA (RPCRT4.@)
716 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
718 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
719 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
722 /***********************************************************************
723 * RpcServerUseProtseqW (RPCRT4.@)
725 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
727 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
728 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
731 /***********************************************************************
732 * RpcServerRegisterIf (RPCRT4.@)
734 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
736 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
737 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
740 /***********************************************************************
741 * RpcServerRegisterIfEx (RPCRT4.@)
743 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
744 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
746 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
747 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
750 /***********************************************************************
751 * RpcServerRegisterIf2 (RPCRT4.@)
753 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
754 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
756 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
757 RpcServerInterface
* sif
;
760 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
761 MaxRpcSize
, IfCallbackFn
);
762 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
763 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
764 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
765 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
766 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
767 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
768 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
769 if (If
->DispatchTable
) {
770 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
771 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
772 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
774 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
776 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
777 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
778 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
780 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
783 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
784 sif
->MgrEpv
= MgrEpv
;
786 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
787 sif
->MgrEpv
= If
->DefaultManagerEpv
;
790 sif
->MaxCalls
= MaxCalls
;
791 sif
->MaxRpcSize
= MaxRpcSize
;
792 sif
->IfCallbackFn
= IfCallbackFn
;
794 EnterCriticalSection(&server_cs
);
797 LeaveCriticalSection(&server_cs
);
799 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
800 /* well, start listening, I think... */
801 RPCRT4_start_listen();
807 /***********************************************************************
808 * RpcServerUnregisterIf (RPCRT4.@)
810 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
812 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
813 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
818 /***********************************************************************
819 * RpcServerUnregisterIfEx (RPCRT4.@)
821 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
823 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
824 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
829 /***********************************************************************
830 * RpcObjectSetType (RPCRT4.@)
833 * ObjUuid [I] "Object" UUID
834 * TypeUuid [I] "Type" UUID
837 * RPC_S_OK The call succeeded
838 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
839 * RPC_S_ALREADY_REGISTERED The provided object is already registered
841 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
842 * resets the mapping for the specified object UUID to nil (the default).
843 * The nil object is always associated with the nil type and cannot be
844 * reassigned. Servers can support multiple implementations on the same
845 * interface by registering different end-point vectors for the different
846 * types. There's no need to call this if a server only supports the nil
847 * type, as is typical.
849 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
851 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
854 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
855 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
856 /* nil uuid cannot be remapped */
857 return RPC_S_INVALID_OBJECT
;
860 /* find the mapping for this object if there is one ... */
862 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
866 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
867 /* ... and drop it from the list */
870 prev
->next
= map
->next
;
872 RpcObjTypeMaps
= map
->next
;
873 HeapFree(GetProcessHeap(), 0, map
);
876 /* ... , fail if we found it ... */
878 return RPC_S_ALREADY_REGISTERED
;
879 /* ... otherwise create a new one and add it in. */
880 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
881 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
882 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
885 prev
->next
= map
; /* prev is the last map in the linklist */
887 RpcObjTypeMaps
= map
;
893 /***********************************************************************
894 * RpcServerRegisterAuthInfoA (RPCRT4.@)
896 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
899 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
901 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
904 /***********************************************************************
905 * RpcServerRegisterAuthInfoW (RPCRT4.@)
907 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, ULONG AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
910 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
912 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
915 /***********************************************************************
916 * RpcServerListen (RPCRT4.@)
918 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
920 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
923 return RPC_S_NO_PROTSEQS_REGISTERED
;
925 EnterCriticalSection(&listen_cs
);
928 LeaveCriticalSection(&listen_cs
);
929 return RPC_S_ALREADY_LISTENING
;
932 RPCRT4_start_listen();
934 LeaveCriticalSection(&listen_cs
);
936 if (DontWait
) return RPC_S_OK
;
938 return RpcMgmtWaitServerListen();
941 /***********************************************************************
942 * RpcMgmtServerWaitListen (RPCRT4.@)
944 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
946 RPC_STATUS rslt
= RPC_S_OK
;
950 EnterCriticalSection(&listen_cs
);
953 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
954 LeaveCriticalSection(&listen_cs
);
958 LeaveCriticalSection(&listen_cs
);
961 WaitForSingleObject(mgr_event
, INFINITE
);
963 Sleep(100); /* don't spin violently */
964 TRACE("spinning.\n");
971 /***********************************************************************
972 * RpcMgmtStopServerListening (RPCRT4.@)
974 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
976 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
979 FIXME("client-side invocation not implemented.\n");
980 return RPC_S_WRONG_KIND_OF_BINDING
;
984 EnterCriticalSection(&listen_cs
);
986 RPCRT4_stop_listen();
987 LeaveCriticalSection(&listen_cs
);
992 /***********************************************************************
993 * I_RpcServerStartListening (RPCRT4.@)
995 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
997 FIXME( "(%p): stub\n", hWnd
);
1002 /***********************************************************************
1003 * I_RpcServerStopListening (RPCRT4.@)
1005 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1007 FIXME( "(): stub\n" );
1012 /***********************************************************************
1013 * I_RpcWindowProc (RPCRT4.@)
1015 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1017 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);