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 /* list of type RpcServerProtseq */
70 static struct list protseqs
= LIST_INIT(protseqs
);
71 static struct list server_interfaces
= LIST_INIT(server_interfaces
);
73 static CRITICAL_SECTION server_cs
;
74 static CRITICAL_SECTION_DEBUG server_cs_debug
=
77 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
78 0, 0, { (DWORD_PTR
)(__FILE__
": server_cs") }
80 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
82 static CRITICAL_SECTION listen_cs
;
83 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
86 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
87 0, 0, { (DWORD_PTR
)(__FILE__
": listen_cs") }
89 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
91 /* whether the server is currently listening */
92 static BOOL std_listen
;
93 /* number of manual listeners (calls to RpcServerListen) */
94 static LONG manual_listen_count
;
95 /* total listeners including auto listeners */
96 static LONG listen_count
;
100 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
102 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
106 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
113 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
115 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
122 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
123 RPC_SYNTAX_IDENTIFIER
* if_id
,
126 UUID
* MgrType
= NULL
;
127 RpcServerInterface
* cif
;
131 MgrType
= LookupObjType(object
);
132 EnterCriticalSection(&server_cs
);
133 LIST_FOR_EACH_ENTRY(cif
, &server_interfaces
, RpcServerInterface
, entry
) {
134 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
135 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
138 LeaveCriticalSection(&server_cs
);
139 if (&cif
->entry
== &server_interfaces
) cif
= NULL
;
140 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
144 static WINE_EXCEPTION_FILTER(rpc_filter
)
146 WARN("exception caught with code 0x%08x = %d\n", GetExceptionCode(), GetExceptionCode());
147 TRACE("returning failure packet\n");
148 /* catch every exception */
149 return EXCEPTION_EXECUTE_HANDLER
;
152 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
154 RpcServerInterface
* sif
;
155 RPC_DISPATCH_FUNCTION func
;
158 void *buf
= msg
->Buffer
;
161 switch (hdr
->common
.ptype
) {
163 TRACE("got bind packet\n");
165 /* FIXME: do more checks! */
166 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
167 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
168 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
171 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
174 TRACE("rejecting bind request on connection %p\n", conn
);
175 /* Report failure to client. */
176 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
177 RPC_VER_MAJOR
, RPC_VER_MINOR
);
179 TRACE("accepting bind request on connection %p for %s\n", conn
,
180 debugstr_guid(&hdr
->bind
.abstract
.SyntaxGUID
));
183 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
187 RESULT_ACCEPT
, NO_REASON
,
188 &sif
->If
->TransferSyntax
);
190 /* save the interface for later use */
191 conn
->ActiveInterface
= hdr
->bind
.abstract
;
192 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
195 status
= RPCRT4_Send(conn
, response
, NULL
, 0);
196 RPCRT4_FreeHeader(response
);
197 if (status
!= RPC_S_OK
)
203 TRACE("got request packet\n");
205 /* fail if the connection isn't bound with an interface */
206 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
207 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
210 RPCRT4_Send(conn
, response
, NULL
, 0);
211 RPCRT4_FreeHeader(response
);
215 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
216 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
221 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
222 msg
->RpcInterfaceInformation
= sif
->If
;
223 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
224 msg
->ManagerEpv
= sif
->MgrEpv
;
225 if (object_uuid
!= NULL
) {
226 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
229 /* find dispatch function */
230 msg
->ProcNum
= hdr
->request
.opnum
;
231 if (sif
->Flags
& RPC_IF_OLE
) {
232 /* native ole32 always gives us a dispatch table with a single entry
233 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
234 func
= *sif
->If
->DispatchTable
->DispatchTable
;
236 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
237 ERR("invalid procnum\n");
240 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
243 /* put in the drep. FIXME: is this more universally applicable?
244 perhaps we should move this outward... */
245 msg
->DataRepresentation
=
246 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
247 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
252 } __EXCEPT(rpc_filter
) {
253 if (msg
->Buffer
!= buf
) I_RpcFreeBuffer(msg
);
254 /* this will cause a failure packet to be sent in I_RpcSend */
255 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
256 msg
->BufferLength
= sizeof(DWORD
);
258 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
261 /* send response packet */
264 msg
->RpcInterfaceInformation
= NULL
;
269 FIXME("unhandled packet type\n");
275 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
276 TRACE("freeing Buffer=%p\n", buf
);
277 HeapFree(GetProcessHeap(), 0, buf
);
278 RPCRT4_DestroyBinding(msg
->Handle
);
280 I_RpcFreeBuffer(msg
);
282 RPCRT4_FreeHeader(hdr
);
283 HeapFree(GetProcessHeap(), 0, msg
);
286 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
288 RpcPacket
*pkt
= the_arg
;
289 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
290 HeapFree(GetProcessHeap(), 0, pkt
);
294 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
296 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
303 TRACE("(%p)\n", conn
);
306 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
308 /* create temporary binding for dispatch, it will be freed in
309 * RPCRT4_process_packet */
310 RPCRT4_MakeBinding(&pbind
, conn
);
311 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
313 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
314 if (status
!= RPC_S_OK
) {
315 WARN("receive failed with error %lx\n", status
);
316 HeapFree(GetProcessHeap(), 0, msg
);
321 RPCRT4_process_packet(conn
, hdr
, msg
);
323 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
327 QueueUserWorkItem(RPCRT4_worker_thread
, packet
, WT_EXECUTEDEFAULT
);
331 RPCRT4_DestroyConnection(conn
);
335 void RPCRT4_new_client(RpcConnection
* conn
)
337 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
339 DWORD err
= GetLastError();
340 ERR("failed to create thread, error=%08x\n", err
);
341 RPCRT4_DestroyConnection(conn
);
343 /* we could set conn->thread, but then we'd have to make the io_thread wait
344 * for that, otherwise the thread might finish, destroy the connection, and
345 * free the memory we'd write to before we did, causing crashes and stuff -
346 * so let's implement that later, when we really need conn->thread */
348 CloseHandle( thread
);
351 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
356 RpcServerProtseq
* cps
= the_arg
;
358 BOOL set_ready_event
= FALSE
;
360 TRACE("(the_arg == ^%p)\n", the_arg
);
363 objs
= cps
->ops
->get_wait_array(cps
, objs
, &count
);
367 /* signal to function that changed state that we are now sync'ed */
368 SetEvent(cps
->server_ready_event
);
369 set_ready_event
= FALSE
;
373 res
= cps
->ops
->wait_for_new_connection(cps
, count
, objs
);
380 SetEvent(cps
->server_ready_event
);
383 set_ready_event
= TRUE
;
386 cps
->ops
->free_wait_array(cps
, objs
);
387 EnterCriticalSection(&cps
->cs
);
388 /* close connections */
391 RPCRT4_CloseConnection(conn
);
394 LeaveCriticalSection(&cps
->cs
);
398 /* tells the server thread that the state has changed and waits for it to
399 * make the changes */
400 static void RPCRT4_sync_with_server_thread(RpcServerProtseq
*ps
)
402 /* make sure we are the only thread sync'ing the server state, otherwise
403 * there is a race with the server thread setting an older state and setting
404 * the server_ready_event when the new state hasn't yet been applied */
405 WaitForSingleObject(ps
->mgr_mutex
, INFINITE
);
407 ps
->ops
->signal_state_changed(ps
);
409 /* wait for server thread to make the requested changes before returning */
410 WaitForSingleObject(ps
->server_ready_event
, INFINITE
);
412 ReleaseMutex(ps
->mgr_mutex
);
415 static RPC_STATUS
RPCRT4_start_listen_protseq(RpcServerProtseq
*ps
, BOOL auto_listen
)
417 RPC_STATUS status
= RPC_S_OK
;
418 HANDLE server_thread
;
420 EnterCriticalSection(&listen_cs
);
421 if (ps
->is_listening
) goto done
;
423 if (!ps
->mgr_mutex
) ps
->mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
424 if (!ps
->server_ready_event
) ps
->server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
425 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, ps
, 0, NULL
);
428 status
= RPC_S_OUT_OF_RESOURCES
;
431 ps
->is_listening
= TRUE
;
432 CloseHandle(server_thread
);
435 LeaveCriticalSection(&listen_cs
);
439 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
441 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
442 RpcServerProtseq
*cps
;
446 EnterCriticalSection(&listen_cs
);
447 if (auto_listen
|| (manual_listen_count
++ == 0))
450 if (++listen_count
== 1)
453 LeaveCriticalSection(&listen_cs
);
457 EnterCriticalSection(&server_cs
);
458 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
460 status
= RPCRT4_start_listen_protseq(cps
, TRUE
);
461 if (status
!= RPC_S_OK
)
464 /* make sure server is actually listening on the interface before
466 RPCRT4_sync_with_server_thread(cps
);
468 LeaveCriticalSection(&server_cs
);
474 static void RPCRT4_stop_listen(BOOL auto_listen
)
476 EnterCriticalSection(&listen_cs
);
477 if (auto_listen
|| (--manual_listen_count
== 0))
479 if (listen_count
!= 0 && --listen_count
== 0) {
480 RpcServerProtseq
*cps
;
483 LeaveCriticalSection(&listen_cs
);
485 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
486 RPCRT4_sync_with_server_thread(cps
);
490 assert(listen_count
>= 0);
492 LeaveCriticalSection(&listen_cs
);
495 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
, LPSTR endpoint
)
499 status
= ps
->ops
->open_endpoint(ps
, endpoint
);
500 if (status
!= RPC_S_OK
)
505 status
= RPCRT4_start_listen_protseq(ps
, FALSE
);
506 if (status
== RPC_S_OK
)
507 RPCRT4_sync_with_server_thread(ps
);
513 /***********************************************************************
514 * RpcServerInqBindings (RPCRT4.@)
516 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
520 RpcServerProtseq
* ps
;
524 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
526 ERR("(BindingVector == NULL!!?)\n");
528 EnterCriticalSection(&server_cs
);
529 /* count connections */
531 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
532 EnterCriticalSection(&ps
->cs
);
538 LeaveCriticalSection(&ps
->cs
);
541 /* export bindings */
542 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
543 sizeof(RPC_BINDING_VECTOR
) +
544 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
545 (*BindingVector
)->Count
= count
;
547 LIST_FOR_EACH_ENTRY(ps
, &protseqs
, RpcServerProtseq
, entry
) {
548 EnterCriticalSection(&ps
->cs
);
551 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
556 LeaveCriticalSection(&ps
->cs
);
560 *BindingVector
= NULL
;
561 status
= RPC_S_NO_BINDINGS
;
563 LeaveCriticalSection(&server_cs
);
567 /***********************************************************************
568 * RpcServerUseProtseqEpA (RPCRT4.@)
570 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
)
574 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
576 /* This should provide the default behaviour */
577 policy
.Length
= sizeof( policy
);
578 policy
.EndpointFlags
= 0;
581 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
584 /***********************************************************************
585 * RpcServerUseProtseqEpW (RPCRT4.@)
587 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
)
591 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
593 /* This should provide the default behaviour */
594 policy
.Length
= sizeof( policy
);
595 policy
.EndpointFlags
= 0;
598 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
601 /***********************************************************************
602 * alloc_serverprotoseq (internal)
604 * Must be called with server_cs held.
606 static RPC_STATUS
alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
608 const struct protseq_ops
*ops
= rpcrt4_get_protseq_ops(Protseq
);
612 FIXME("protseq %s not supported\n", debugstr_a(Protseq
));
613 return RPC_S_PROTSEQ_NOT_SUPPORTED
;
618 return RPC_S_OUT_OF_RESOURCES
;
619 (*ps
)->MaxCalls
= MaxCalls
;
620 (*ps
)->Protseq
= Protseq
;
624 InitializeCriticalSection(&(*ps
)->cs
);
625 (*ps
)->is_listening
= FALSE
;
626 (*ps
)->mgr_mutex
= NULL
;
627 (*ps
)->server_ready_event
= NULL
;
629 list_add_head(&protseqs
, &(*ps
)->entry
);
631 TRACE("new protseq %p created for %s\n", *ps
, Protseq
);
636 /* Finds a given protseq or creates a new one if one doesn't already exist */
637 static RPC_STATUS
RPCRT4_get_or_create_serverprotseq(UINT MaxCalls
, char *Protseq
, RpcServerProtseq
**ps
)
640 RpcServerProtseq
*cps
;
642 EnterCriticalSection(&server_cs
);
644 LIST_FOR_EACH_ENTRY(cps
, &protseqs
, RpcServerProtseq
, entry
)
645 if (!strcmp(cps
->Protseq
, Protseq
))
647 TRACE("found existing protseq object for %s\n", Protseq
);
649 LeaveCriticalSection(&server_cs
);
653 status
= alloc_serverprotoseq(MaxCalls
, Protseq
, ps
);
655 LeaveCriticalSection(&server_cs
);
660 /***********************************************************************
661 * RpcServerUseProtseqEpExA (RPCRT4.@)
663 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( RPC_CSTR Protseq
, UINT MaxCalls
, RPC_CSTR Endpoint
, LPVOID SecurityDescriptor
,
664 PRPC_POLICY lpPolicy
)
666 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
667 RpcServerProtseq
* ps
;
670 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
671 debugstr_a(szep
), SecurityDescriptor
,
672 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
674 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupA(szps
), &ps
);
675 if (status
!= RPC_S_OK
)
678 return RPCRT4_use_protseq(ps
, szep
);
681 /***********************************************************************
682 * RpcServerUseProtseqEpExW (RPCRT4.@)
684 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( RPC_WSTR Protseq
, UINT MaxCalls
, RPC_WSTR Endpoint
, LPVOID SecurityDescriptor
,
685 PRPC_POLICY lpPolicy
)
687 RpcServerProtseq
* ps
;
691 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
692 debugstr_w( Endpoint
), SecurityDescriptor
,
693 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
695 status
= RPCRT4_get_or_create_serverprotseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
), &ps
);
696 if (status
!= RPC_S_OK
)
699 EndpointA
= RPCRT4_strdupWtoA(Endpoint
);
700 status
= RPCRT4_use_protseq(ps
, EndpointA
);
701 RPCRT4_strfree(EndpointA
);
705 /***********************************************************************
706 * RpcServerUseProtseqA (RPCRT4.@)
708 RPC_STATUS WINAPI
RpcServerUseProtseqA(RPC_CSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
710 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
711 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
714 /***********************************************************************
715 * RpcServerUseProtseqW (RPCRT4.@)
717 RPC_STATUS WINAPI
RpcServerUseProtseqW(RPC_WSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
719 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
720 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
723 /***********************************************************************
724 * RpcServerRegisterIf (RPCRT4.@)
726 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
728 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
729 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
732 /***********************************************************************
733 * RpcServerRegisterIfEx (RPCRT4.@)
735 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
736 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
738 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
739 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
742 /***********************************************************************
743 * RpcServerRegisterIf2 (RPCRT4.@)
745 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
746 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
748 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
749 RpcServerInterface
* sif
;
752 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
753 MaxRpcSize
, IfCallbackFn
);
754 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
755 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
756 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
757 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
758 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
759 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
760 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
761 if (If
->DispatchTable
) {
762 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
763 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
764 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
766 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
768 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
769 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
770 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
772 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
775 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
776 sif
->MgrEpv
= MgrEpv
;
778 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
779 sif
->MgrEpv
= If
->DefaultManagerEpv
;
782 sif
->MaxCalls
= MaxCalls
;
783 sif
->MaxRpcSize
= MaxRpcSize
;
784 sif
->IfCallbackFn
= IfCallbackFn
;
786 EnterCriticalSection(&server_cs
);
787 list_add_head(&server_interfaces
, &sif
->entry
);
788 LeaveCriticalSection(&server_cs
);
790 if (sif
->Flags
& RPC_IF_AUTOLISTEN
)
791 RPCRT4_start_listen(TRUE
);
796 /***********************************************************************
797 * RpcServerUnregisterIf (RPCRT4.@)
799 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
801 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
802 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
807 /***********************************************************************
808 * RpcServerUnregisterIfEx (RPCRT4.@)
810 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
812 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
813 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
818 /***********************************************************************
819 * RpcObjectSetType (RPCRT4.@)
822 * ObjUuid [I] "Object" UUID
823 * TypeUuid [I] "Type" UUID
826 * RPC_S_OK The call succeeded
827 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
828 * RPC_S_ALREADY_REGISTERED The provided object is already registered
830 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
831 * resets the mapping for the specified object UUID to nil (the default).
832 * The nil object is always associated with the nil type and cannot be
833 * reassigned. Servers can support multiple implementations on the same
834 * interface by registering different end-point vectors for the different
835 * types. There's no need to call this if a server only supports the nil
836 * type, as is typical.
838 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
840 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
843 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
844 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
845 /* nil uuid cannot be remapped */
846 return RPC_S_INVALID_OBJECT
;
849 /* find the mapping for this object if there is one ... */
851 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
855 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
856 /* ... and drop it from the list */
859 prev
->next
= map
->next
;
861 RpcObjTypeMaps
= map
->next
;
862 HeapFree(GetProcessHeap(), 0, map
);
865 /* ... , fail if we found it ... */
867 return RPC_S_ALREADY_REGISTERED
;
868 /* ... otherwise create a new one and add it in. */
869 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
870 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
871 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
874 prev
->next
= map
; /* prev is the last map in the linklist */
876 RpcObjTypeMaps
= map
;
882 /***********************************************************************
883 * RpcServerRegisterAuthInfoA (RPCRT4.@)
885 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
888 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
890 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
893 /***********************************************************************
894 * RpcServerRegisterAuthInfoW (RPCRT4.@)
896 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
899 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
901 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
904 /***********************************************************************
905 * RpcServerListen (RPCRT4.@)
907 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
909 RPC_STATUS status
= RPC_S_OK
;
911 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
913 if (list_empty(&protseqs
))
914 return RPC_S_NO_PROTSEQS_REGISTERED
;
916 status
= RPCRT4_start_listen(FALSE
);
918 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
920 return RpcMgmtWaitServerListen();
923 /***********************************************************************
924 * RpcMgmtServerWaitListen (RPCRT4.@)
926 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
930 EnterCriticalSection(&listen_cs
);
933 LeaveCriticalSection(&listen_cs
);
934 return RPC_S_NOT_LISTENING
;
937 LeaveCriticalSection(&listen_cs
);
939 FIXME("not waiting for server calls to finish\n");
944 /***********************************************************************
945 * RpcMgmtStopServerListening (RPCRT4.@)
947 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
949 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
952 FIXME("client-side invocation not implemented.\n");
953 return RPC_S_WRONG_KIND_OF_BINDING
;
956 RPCRT4_stop_listen(FALSE
);
961 /***********************************************************************
962 * RpcMgmtEnableIdleCleanup (RPCRT4.@)
964 RPC_STATUS WINAPI
RpcMgmtEnableIdleCleanup(void)
970 /***********************************************************************
971 * I_RpcServerStartListening (RPCRT4.@)
973 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
975 FIXME( "(%p): stub\n", hWnd
);
980 /***********************************************************************
981 * I_RpcServerStopListening (RPCRT4.@)
983 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
985 FIXME( "(): stub\n" );
990 /***********************************************************************
991 * I_RpcWindowProc (RPCRT4.@)
993 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
995 FIXME( "(%p,%08x,%08x,%08x): stub\n", hWnd
, Message
, wParam
, lParam
);
1000 /***********************************************************************
1001 * RpcMgmtInqIfIds (RPCRT4.@)
1003 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1005 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1006 return RPC_S_INVALID_BINDING
;
1009 /***********************************************************************
1010 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1012 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, unsigned long InquiryType
,
1013 RPC_IF_ID
*IfId
, unsigned long VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1015 FIXME("(%p,%lu,%p,%lu,%p,%p): stub\n",
1016 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1017 return RPC_S_INVALID_BINDING
;
1020 /***********************************************************************
1021 * RpcMgmtIsServerListening (RPCRT4.@)
1023 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1025 FIXME("(%p): stub\n", Binding
);
1026 return RPC_S_INVALID_BINDING
;
1029 /***********************************************************************
1030 * RpcMgmtSetServerStackSize (RPCRT4.@)
1032 RPC_STATUS WINAPI
RpcMgmtSetServerStackSize(unsigned long ThreadStackSize
)
1034 FIXME("(0x%lx): stub\n", ThreadStackSize
);