4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2004 Filip Navara
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
42 #include "wine/debug.h"
43 #include "wine/exception.h"
45 #include "rpc_server.h"
47 #include "rpc_message.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
52 typedef struct _RpcPacket
54 struct _RpcConnection
* conn
;
59 typedef struct _RpcObjTypeMap
61 /* FIXME: a hash table would be better. */
62 struct _RpcObjTypeMap
*next
;
67 static RpcObjTypeMap
*RpcObjTypeMaps
;
69 static RpcServerProtseq
* protseqs
;
70 static RpcServerInterface
* ifs
;
72 static CRITICAL_SECTION server_cs
;
73 static CRITICAL_SECTION_DEBUG server_cs_debug
=
76 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
77 0, 0, { (DWORD_PTR
)(__FILE__
": server_cs") }
79 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
81 static CRITICAL_SECTION listen_cs
;
82 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
85 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
86 0, 0, { (DWORD_PTR
)(__FILE__
": listen_cs") }
88 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
90 /* whether the server is currently listening */
91 static BOOL std_listen
;
92 /* number of manual listeners (calls to RpcServerListen) */
93 static LONG manual_listen_count
;
94 /* total listeners including auto listeners */
95 static LONG listen_count
;
96 /* set on change of configuration (e.g. listening on new protseq) */
97 static HANDLE mgr_event
;
98 /* mutex for ensuring only one thread can change state at a time */
99 static HANDLE mgr_mutex
;
100 /* set when server thread has finished opening connections */
101 static HANDLE server_ready_event
;
103 static UUID uuid_nil
;
105 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
107 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
111 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
118 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
120 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
127 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
128 RPC_SYNTAX_IDENTIFIER
* if_id
,
131 UUID
* MgrType
= NULL
;
132 RpcServerInterface
* cif
= NULL
;
136 MgrType
= LookupObjType(object
);
137 EnterCriticalSection(&server_cs
);
140 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
141 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
145 LeaveCriticalSection(&server_cs
);
146 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
150 static WINE_EXCEPTION_FILTER(rpc_filter
)
152 WARN("exception caught with code 0x%08lx = %ld\n", GetExceptionCode(), GetExceptionCode());
153 TRACE("returning failure packet\n");
154 /* catch every exception */
155 return EXCEPTION_EXECUTE_HANDLER
;
158 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
160 RpcServerInterface
* sif
;
161 RPC_DISPATCH_FUNCTION func
;
164 void *buf
= msg
->Buffer
;
167 switch (hdr
->common
.ptype
) {
169 TRACE("got bind packet\n");
171 /* FIXME: do more checks! */
172 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
173 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
174 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
177 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
180 TRACE("rejecting bind request on connection %p\n", conn
);
181 /* Report failure to client. */
182 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
183 RPC_VER_MAJOR
, RPC_VER_MINOR
);
185 TRACE("accepting bind request on connection %p\n", conn
);
188 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
192 RESULT_ACCEPT
, NO_REASON
,
193 &sif
->If
->TransferSyntax
);
195 /* save the interface for later use */
196 conn
->ActiveInterface
= hdr
->bind
.abstract
;
197 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
200 status
= RPCRT4_Send(conn
, response
, NULL
, 0);
201 RPCRT4_FreeHeader(response
);
202 if (status
!= RPC_S_OK
)
208 TRACE("got request packet\n");
210 /* fail if the connection isn't bound with an interface */
211 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
212 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
215 RPCRT4_Send(conn
, response
, NULL
, 0);
216 RPCRT4_FreeHeader(response
);
220 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
221 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
226 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
227 msg
->RpcInterfaceInformation
= sif
->If
;
228 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
229 msg
->ManagerEpv
= sif
->MgrEpv
;
230 if (object_uuid
!= NULL
) {
231 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
234 /* find dispatch function */
235 msg
->ProcNum
= hdr
->request
.opnum
;
236 if (sif
->Flags
& RPC_IF_OLE
) {
237 /* native ole32 always gives us a dispatch table with a single entry
238 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
239 func
= *sif
->If
->DispatchTable
->DispatchTable
;
241 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
242 ERR("invalid procnum\n");
245 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
248 /* put in the drep. FIXME: is this more universally applicable?
249 perhaps we should move this outward... */
250 msg
->DataRepresentation
=
251 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
252 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
257 } __EXCEPT(rpc_filter
) {
258 if (msg
->Buffer
!= buf
) I_RpcFreeBuffer(msg
);
259 /* this will cause a failure packet to be sent in I_RpcSend */
260 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
261 msg
->BufferLength
= sizeof(DWORD
);
263 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
266 /* send response packet */
269 msg
->RpcInterfaceInformation
= NULL
;
274 FIXME("unhandled packet type\n");
280 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
281 TRACE("freeing Buffer=%p\n", buf
);
282 HeapFree(GetProcessHeap(), 0, buf
);
283 RPCRT4_DestroyBinding(msg
->Handle
);
285 I_RpcFreeBuffer(msg
);
287 RPCRT4_FreeHeader(hdr
);
288 HeapFree(GetProcessHeap(), 0, msg
);
291 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
293 RpcPacket
*pkt
= the_arg
;
294 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
295 HeapFree(GetProcessHeap(), 0, pkt
);
299 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
301 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
308 TRACE("(%p)\n", conn
);
311 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
313 /* create temporary binding for dispatch, it will be freed in
314 * RPCRT4_process_packet */
315 RPCRT4_MakeBinding(&pbind
, conn
);
316 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
318 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
319 if (status
!= RPC_S_OK
) {
320 WARN("receive failed with error %lx\n", status
);
321 HeapFree(GetProcessHeap(), 0, msg
);
326 RPCRT4_process_packet(conn
, hdr
, msg
);
328 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
332 QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTEDEFAULT
);
336 RPCRT4_DestroyConnection(conn
);
340 static void RPCRT4_new_client(RpcConnection
* conn
)
342 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
344 DWORD err
= GetLastError();
345 ERR("failed to create thread, error=%08lx\n", err
);
346 RPCRT4_DestroyConnection(conn
);
348 /* we could set conn->thread, but then we'd have to make the io_thread wait
349 * for that, otherwise the thread might finish, destroy the connection, and
350 * free the memory we'd write to before we did, causing crashes and stuff -
351 * so let's implement that later, when we really need conn->thread */
353 CloseHandle( thread
);
356 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
358 HANDLE m_event
= mgr_event
, b_handle
;
361 RpcServerProtseq
* cps
;
363 RpcConnection
* cconn
;
364 BOOL set_ready_event
= FALSE
;
366 TRACE("(the_arg == ^%p)\n", the_arg
);
369 EnterCriticalSection(&server_cs
);
370 /* open and count connections */
376 RPCRT4_OpenConnection(conn
);
377 if (rpcrt4_conn_get_wait_object(conn
))
383 /* make array of connections */
385 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
387 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
395 if ((objs
[count
] = rpcrt4_conn_get_wait_object(conn
)))
401 LeaveCriticalSection(&server_cs
);
405 /* signal to function that changed state that we are now sync'ed */
406 SetEvent(server_ready_event
);
407 set_ready_event
= FALSE
;
411 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
412 if (res
== WAIT_OBJECT_0
) {
415 SetEvent(server_ready_event
);
418 set_ready_event
= TRUE
;
420 else if (res
== WAIT_FAILED
) {
421 ERR("wait failed\n");
424 b_handle
= objs
[res
- WAIT_OBJECT_0
];
425 /* find which connection got a RPC */
426 EnterCriticalSection(&server_cs
);
432 if (b_handle
== rpcrt4_conn_get_wait_object(conn
)) break;
440 RPCRT4_SpawnConnection(&cconn
, conn
);
442 ERR("failed to locate connection for handle %p\n", b_handle
);
443 LeaveCriticalSection(&server_cs
);
444 if (cconn
) RPCRT4_new_client(cconn
);
447 HeapFree(GetProcessHeap(), 0, objs
);
448 EnterCriticalSection(&server_cs
);
449 /* close connections */
454 RPCRT4_CloseConnection(conn
);
459 LeaveCriticalSection(&server_cs
);
463 /* tells the server thread that the state has changed and waits for it to
464 * make the changes */
465 static void RPCRT4_sync_with_server_thread(void)
467 /* make sure we are the only thread sync'ing the server state, otherwise
468 * there is a race with the server thread setting an older state and setting
469 * the server_ready_event when the new state hasn't yet been applied */
470 WaitForSingleObject(mgr_mutex
, INFINITE
);
473 /* wait for server thread to make the requested changes before returning */
474 WaitForSingleObject(server_ready_event
, INFINITE
);
476 ReleaseMutex(mgr_mutex
);
479 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
481 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
485 EnterCriticalSection(&listen_cs
);
486 if (auto_listen
|| (manual_listen_count
++ == 0))
489 if (++listen_count
== 1) {
490 HANDLE server_thread
;
491 /* first listener creates server thread */
492 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
493 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
494 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
496 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
497 CloseHandle(server_thread
);
500 LeaveCriticalSection(&listen_cs
);
505 static void RPCRT4_stop_listen(BOOL auto_listen
)
507 EnterCriticalSection(&listen_cs
);
508 if (auto_listen
|| (--manual_listen_count
== 0))
510 if (listen_count
!= 0 && --listen_count
== 0) {
512 LeaveCriticalSection(&listen_cs
);
513 RPCRT4_sync_with_server_thread();
516 assert(listen_count
>= 0);
518 LeaveCriticalSection(&listen_cs
);
521 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
523 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
,
526 EnterCriticalSection(&server_cs
);
529 LeaveCriticalSection(&server_cs
);
531 if (std_listen
) RPCRT4_sync_with_server_thread();
536 /***********************************************************************
537 * RpcServerInqBindings (RPCRT4.@)
539 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
543 RpcServerProtseq
* ps
;
547 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
549 ERR("(BindingVector == NULL!!?)\n");
551 EnterCriticalSection(&server_cs
);
552 /* count connections */
564 /* export bindings */
565 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
566 sizeof(RPC_BINDING_VECTOR
) +
567 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
568 (*BindingVector
)->Count
= count
;
574 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
583 *BindingVector
= NULL
;
584 status
= RPC_S_NO_BINDINGS
;
586 LeaveCriticalSection(&server_cs
);
590 /***********************************************************************
591 * RpcServerUseProtseqEpA (RPCRT4.@)
593 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
597 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
599 /* This should provide the default behaviour */
600 policy
.Length
= sizeof( policy
);
601 policy
.EndpointFlags
= 0;
604 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
607 /***********************************************************************
608 * RpcServerUseProtseqEpW (RPCRT4.@)
610 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
614 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
616 /* This should provide the default behaviour */
617 policy
.Length
= sizeof( policy
);
618 policy
.EndpointFlags
= 0;
621 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
624 /***********************************************************************
625 * alloc_serverprotoseq (internal)
627 static RpcServerProtseq
*alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, char *Endpoint
)
629 RpcServerProtseq
* ps
;
631 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
632 ps
->MaxCalls
= MaxCalls
;
633 ps
->Protseq
= Protseq
;
634 ps
->Endpoint
= Endpoint
;
639 /***********************************************************************
640 * RpcServerUseProtseqEpExA (RPCRT4.@)
642 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
643 PRPC_POLICY lpPolicy
)
645 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
646 RpcServerProtseq
* ps
;
648 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
649 debugstr_a(szep
), SecurityDescriptor
,
650 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
652 ps
= alloc_serverprotoseq(MaxCalls
, RPCRT4_strdupA(szps
), RPCRT4_strdupA(szep
));
654 return RPCRT4_use_protseq(ps
);
657 /***********************************************************************
658 * RpcServerUseProtseqEpExW (RPCRT4.@)
660 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
661 PRPC_POLICY lpPolicy
)
663 RpcServerProtseq
* ps
;
665 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
666 debugstr_w( Endpoint
), SecurityDescriptor
,
667 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
669 ps
= alloc_serverprotoseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
),
670 RPCRT4_strdupWtoA(Endpoint
));
672 return RPCRT4_use_protseq(ps
);
675 /***********************************************************************
676 * RpcServerUseProtseqA (RPCRT4.@)
678 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
680 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
681 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
684 /***********************************************************************
685 * RpcServerUseProtseqW (RPCRT4.@)
687 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
689 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
690 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
693 /***********************************************************************
694 * RpcServerRegisterIf (RPCRT4.@)
696 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
698 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
699 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
702 /***********************************************************************
703 * RpcServerRegisterIfEx (RPCRT4.@)
705 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
706 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
708 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
709 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
712 /***********************************************************************
713 * RpcServerRegisterIf2 (RPCRT4.@)
715 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
716 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
718 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
719 RpcServerInterface
* sif
;
722 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
723 MaxRpcSize
, IfCallbackFn
);
724 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
725 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
726 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
727 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
728 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
729 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
730 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
731 if (If
->DispatchTable
) {
732 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
733 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
734 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
736 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
738 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
739 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
740 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
742 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
745 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
746 sif
->MgrEpv
= MgrEpv
;
748 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
749 sif
->MgrEpv
= If
->DefaultManagerEpv
;
752 sif
->MaxCalls
= MaxCalls
;
753 sif
->MaxRpcSize
= MaxRpcSize
;
754 sif
->IfCallbackFn
= IfCallbackFn
;
756 EnterCriticalSection(&server_cs
);
759 LeaveCriticalSection(&server_cs
);
761 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
762 RPCRT4_start_listen(TRUE
);
764 /* make sure server is actually listening on the interface before
766 RPCRT4_sync_with_server_thread();
772 /***********************************************************************
773 * RpcServerUnregisterIf (RPCRT4.@)
775 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
777 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
778 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
783 /***********************************************************************
784 * RpcServerUnregisterIfEx (RPCRT4.@)
786 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
788 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
789 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
794 /***********************************************************************
795 * RpcObjectSetType (RPCRT4.@)
798 * ObjUuid [I] "Object" UUID
799 * TypeUuid [I] "Type" UUID
802 * RPC_S_OK The call succeeded
803 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
804 * RPC_S_ALREADY_REGISTERED The provided object is already registered
806 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
807 * resets the mapping for the specified object UUID to nil (the default).
808 * The nil object is always associated with the nil type and cannot be
809 * reassigned. Servers can support multiple implementations on the same
810 * interface by registering different end-point vectors for the different
811 * types. There's no need to call this if a server only supports the nil
812 * type, as is typical.
814 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
816 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
819 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
820 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
821 /* nil uuid cannot be remapped */
822 return RPC_S_INVALID_OBJECT
;
825 /* find the mapping for this object if there is one ... */
827 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
831 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
832 /* ... and drop it from the list */
835 prev
->next
= map
->next
;
837 RpcObjTypeMaps
= map
->next
;
838 HeapFree(GetProcessHeap(), 0, map
);
841 /* ... , fail if we found it ... */
843 return RPC_S_ALREADY_REGISTERED
;
844 /* ... otherwise create a new one and add it in. */
845 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
846 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
847 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
850 prev
->next
= map
; /* prev is the last map in the linklist */
852 RpcObjTypeMaps
= map
;
858 /***********************************************************************
859 * RpcServerRegisterAuthInfoA (RPCRT4.@)
861 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
864 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
866 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
869 /***********************************************************************
870 * RpcServerRegisterAuthInfoW (RPCRT4.@)
872 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
875 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
877 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
880 /***********************************************************************
881 * RpcServerListen (RPCRT4.@)
883 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
887 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
890 return RPC_S_NO_PROTSEQS_REGISTERED
;
892 status
= RPCRT4_start_listen(FALSE
);
894 if (status
== RPC_S_OK
)
895 RPCRT4_sync_with_server_thread();
897 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
899 return RpcMgmtWaitServerListen();
902 /***********************************************************************
903 * RpcMgmtServerWaitListen (RPCRT4.@)
905 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
909 EnterCriticalSection(&listen_cs
);
912 LeaveCriticalSection(&listen_cs
);
913 return RPC_S_NOT_LISTENING
;
916 LeaveCriticalSection(&listen_cs
);
918 FIXME("not waiting for server calls to finish\n");
923 /***********************************************************************
924 * RpcMgmtStopServerListening (RPCRT4.@)
926 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
928 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
931 FIXME("client-side invocation not implemented.\n");
932 return RPC_S_WRONG_KIND_OF_BINDING
;
935 RPCRT4_stop_listen(FALSE
);
940 /***********************************************************************
941 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
943 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
949 /***********************************************************************
950 * I_RpcServerStartListening (RPCRT4.@)
952 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
954 FIXME( "(%p): stub\n", hWnd
);
959 /***********************************************************************
960 * I_RpcServerStopListening (RPCRT4.@)
962 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
964 FIXME( "(): stub\n" );
969 /***********************************************************************
970 * I_RpcWindowProc (RPCRT4.@)
972 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
974 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);
979 /***********************************************************************
980 * RpcMgmtInqIfIds (RPCRT4.@)
982 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
984 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
985 return RPC_S_INVALID_BINDING
;
988 /***********************************************************************
989 * RpcMgmtEpEltInqBegin (RPCRT4.@)
991 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, unsigned long InquiryType
,
992 RPC_IF_ID
*IfId
, unsigned long VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
994 FIXME("(%p,%lu,%p,%lu,%p,%p): stub\n",
995 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
996 return RPC_S_INVALID_BINDING
;
999 /***********************************************************************
1000 * RpcMgmtIsServerListening (RPCRT4.@)
1002 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1004 FIXME("(%p): stub\n", Binding
);
1005 return RPC_S_INVALID_BINDING
;
1008 /***********************************************************************
1009 * RpcMgmtSetServerStackSize (RPCRT4.@)
1011 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(unsigned int ThreadStackSize
)
1013 FIXME("(0x%x): stub\n", ThreadStackSize
);