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 #define MAX_THREADS 128
52 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
54 typedef struct _RpcPacket
56 struct _RpcPacket
* next
;
57 struct _RpcConnection
* conn
;
62 typedef struct _RpcObjTypeMap
64 /* FIXME: a hash table would be better. */
65 struct _RpcObjTypeMap
*next
;
70 static RpcObjTypeMap
*RpcObjTypeMaps
;
72 static RpcServerProtseq
* protseqs
;
73 static RpcServerInterface
* ifs
;
75 static CRITICAL_SECTION server_cs
;
76 static CRITICAL_SECTION_DEBUG server_cs_debug
=
79 { &server_cs_debug
.ProcessLocksList
, &server_cs_debug
.ProcessLocksList
},
80 0, 0, { (DWORD_PTR
)(__FILE__
": server_cs") }
82 static CRITICAL_SECTION server_cs
= { &server_cs_debug
, -1, 0, 0, 0, 0 };
84 static CRITICAL_SECTION listen_cs
;
85 static CRITICAL_SECTION_DEBUG listen_cs_debug
=
88 { &listen_cs_debug
.ProcessLocksList
, &listen_cs_debug
.ProcessLocksList
},
89 0, 0, { (DWORD_PTR
)(__FILE__
": listen_cs") }
91 static CRITICAL_SECTION listen_cs
= { &listen_cs_debug
, -1, 0, 0, 0, 0 };
93 /* whether the server is currently listening */
94 static BOOL std_listen
;
95 /* number of manual listeners (calls to RpcServerListen) */
96 static LONG manual_listen_count
;
97 /* total listeners including auto listeners */
98 static LONG listen_count
;
99 /* set on change of configuration (e.g. listening on new protseq) */
100 static HANDLE mgr_event
;
101 /* mutex for ensuring only one thread can change state at a time */
102 static HANDLE mgr_mutex
;
103 /* set when server thread has finished opening connections */
104 static HANDLE server_ready_event
;
106 static CRITICAL_SECTION spacket_cs
;
107 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
110 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
111 0, 0, { (DWORD_PTR
)(__FILE__
": spacket_cs") }
113 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
115 static RpcPacket
* spacket_head
;
116 static RpcPacket
* spacket_tail
;
117 static HANDLE server_sem
;
119 static LONG worker_count
, worker_free
, worker_tls
;
121 static UUID uuid_nil
;
123 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
125 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
129 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
136 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
138 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
145 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
146 RPC_SYNTAX_IDENTIFIER
* if_id
,
149 UUID
* MgrType
= NULL
;
150 RpcServerInterface
* cif
= NULL
;
154 MgrType
= LookupObjType(object
);
155 EnterCriticalSection(&server_cs
);
158 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
159 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
163 LeaveCriticalSection(&server_cs
);
164 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
168 static void RPCRT4_push_packet(RpcPacket
* packet
)
171 EnterCriticalSection(&spacket_cs
);
173 spacket_tail
->next
= packet
;
174 spacket_tail
= packet
;
176 spacket_head
= packet
;
177 spacket_tail
= packet
;
179 LeaveCriticalSection(&spacket_cs
);
182 static RpcPacket
* RPCRT4_pop_packet(void)
185 EnterCriticalSection(&spacket_cs
);
186 packet
= spacket_head
;
188 spacket_head
= packet
->next
;
189 if (!spacket_head
) spacket_tail
= NULL
;
191 LeaveCriticalSection(&spacket_cs
);
192 if (packet
) packet
->next
= NULL
;
201 static WINE_EXCEPTION_FILTER(rpc_filter
)
205 state
= TlsGetValue(worker_tls
);
207 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
208 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
209 msg
->BufferLength
= sizeof(DWORD
);
211 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
212 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
213 TRACE("returning failure packet\n");
214 return EXCEPTION_EXECUTE_HANDLER
;
217 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
219 RpcServerInterface
* sif
;
220 RPC_DISPATCH_FUNCTION func
;
224 void *buf
= msg
->Buffer
;
229 TlsSetValue(worker_tls
, &state
);
231 switch (hdr
->common
.ptype
) {
233 TRACE("got bind packet\n");
235 /* FIXME: do more checks! */
236 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
237 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
238 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
241 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
244 TRACE("rejecting bind request on connection %p\n", conn
);
245 /* Report failure to client. */
246 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
247 RPC_VER_MAJOR
, RPC_VER_MINOR
);
249 TRACE("accepting bind request on connection %p\n", conn
);
252 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
256 RESULT_ACCEPT
, NO_REASON
,
257 &sif
->If
->TransferSyntax
);
259 /* save the interface for later use */
260 conn
->ActiveInterface
= hdr
->bind
.abstract
;
261 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
264 status
= RPCRT4_Send(conn
, response
, NULL
, 0);
265 RPCRT4_FreeHeader(response
);
266 if (status
!= RPC_S_OK
)
272 TRACE("got request packet\n");
274 /* fail if the connection isn't bound with an interface */
275 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
276 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
279 RPCRT4_Send(conn
, response
, NULL
, 0);
280 RPCRT4_FreeHeader(response
);
284 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
285 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
290 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
291 msg
->RpcInterfaceInformation
= sif
->If
;
292 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
293 msg
->ManagerEpv
= sif
->MgrEpv
;
294 if (object_uuid
!= NULL
) {
295 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
298 /* find dispatch function */
299 msg
->ProcNum
= hdr
->request
.opnum
;
300 if (sif
->Flags
& RPC_IF_OLE
) {
301 /* native ole32 always gives us a dispatch table with a single entry
302 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
303 func
= *sif
->If
->DispatchTable
->DispatchTable
;
305 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
306 ERR("invalid procnum\n");
309 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
312 /* put in the drep. FIXME: is this more universally applicable?
313 perhaps we should move this outward... */
314 msg
->DataRepresentation
=
315 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
316 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
321 } __EXCEPT(rpc_filter
) {
322 /* failure packet was created in rpc_filter */
325 /* send response packet */
328 msg
->RpcInterfaceInformation
= NULL
;
333 FIXME("unhandled packet type\n");
339 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
340 TRACE("freeing Buffer=%p\n", buf
);
341 HeapFree(GetProcessHeap(), 0, buf
);
342 RPCRT4_DestroyBinding(msg
->Handle
);
344 I_RpcFreeBuffer(msg
);
346 RPCRT4_FreeHeader(hdr
);
347 TlsSetValue(worker_tls
, NULL
);
348 HeapFree(GetProcessHeap(), 0, msg
);
351 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
357 /* idle timeout after 5s */
358 obj
= WaitForSingleObject(server_sem
, 5000);
359 if (obj
== WAIT_TIMEOUT
) {
360 /* if another idle thread exist, self-destruct */
361 if (worker_free
> 1) break;
364 pkt
= RPCRT4_pop_packet();
366 InterlockedDecrement(&worker_free
);
368 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
369 HeapFree(GetProcessHeap(), 0, pkt
);
370 /* try to grab another packet here without waiting
371 * on the semaphore, in case it hits max */
372 pkt
= RPCRT4_pop_packet();
374 /* decrement semaphore */
375 WaitForSingleObject(server_sem
, 0);
377 InterlockedIncrement(&worker_free
);
379 InterlockedDecrement(&worker_free
);
380 InterlockedDecrement(&worker_count
);
384 static void RPCRT4_create_worker_if_needed(void)
386 if (!worker_free
&& worker_count
< MAX_THREADS
) {
388 InterlockedIncrement(&worker_count
);
389 InterlockedIncrement(&worker_free
);
390 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
391 if (thread
) CloseHandle(thread
);
393 InterlockedDecrement(&worker_free
);
394 InterlockedDecrement(&worker_count
);
399 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
401 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
408 TRACE("(%p)\n", conn
);
411 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
413 /* create temporary binding for dispatch, it will be freed in
414 * RPCRT4_process_packet */
415 RPCRT4_MakeBinding(&pbind
, conn
);
416 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
418 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
419 if (status
!= RPC_S_OK
) {
420 WARN("receive failed with error %lx\n", status
);
421 HeapFree(GetProcessHeap(), 0, msg
);
426 RPCRT4_process_packet(conn
, hdr
, msg
);
428 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
432 RPCRT4_create_worker_if_needed();
433 RPCRT4_push_packet(packet
);
434 ReleaseSemaphore(server_sem
, 1, NULL
);
438 RPCRT4_DestroyConnection(conn
);
442 static void RPCRT4_new_client(RpcConnection
* conn
)
444 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
446 DWORD err
= GetLastError();
447 ERR("failed to create thread, error=%08lx\n", err
);
448 RPCRT4_DestroyConnection(conn
);
450 /* we could set conn->thread, but then we'd have to make the io_thread wait
451 * for that, otherwise the thread might finish, destroy the connection, and
452 * free the memory we'd write to before we did, causing crashes and stuff -
453 * so let's implement that later, when we really need conn->thread */
455 CloseHandle( thread
);
458 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
460 HANDLE m_event
= mgr_event
, b_handle
;
463 RpcServerProtseq
* cps
;
465 RpcConnection
* cconn
;
466 BOOL set_ready_event
= FALSE
;
468 TRACE("(the_arg == ^%p)\n", the_arg
);
471 EnterCriticalSection(&server_cs
);
472 /* open and count connections */
478 RPCRT4_OpenConnection(conn
);
479 if (rpcrt4_conn_get_wait_object(conn
))
485 /* make array of connections */
487 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
489 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
497 if ((objs
[count
] = rpcrt4_conn_get_wait_object(conn
)))
503 LeaveCriticalSection(&server_cs
);
507 /* signal to function that changed state that we are now sync'ed */
508 SetEvent(server_ready_event
);
509 set_ready_event
= FALSE
;
513 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
514 if (res
== WAIT_OBJECT_0
) {
517 SetEvent(server_ready_event
);
520 set_ready_event
= TRUE
;
522 else if (res
== WAIT_FAILED
) {
523 ERR("wait failed\n");
526 b_handle
= objs
[res
- WAIT_OBJECT_0
];
527 /* find which connection got a RPC */
528 EnterCriticalSection(&server_cs
);
534 if (b_handle
== rpcrt4_conn_get_wait_object(conn
)) break;
542 RPCRT4_SpawnConnection(&cconn
, conn
);
544 ERR("failed to locate connection for handle %p\n", b_handle
);
545 LeaveCriticalSection(&server_cs
);
546 if (cconn
) RPCRT4_new_client(cconn
);
549 HeapFree(GetProcessHeap(), 0, objs
);
550 EnterCriticalSection(&server_cs
);
551 /* close connections */
556 RPCRT4_CloseConnection(conn
);
561 LeaveCriticalSection(&server_cs
);
565 /* tells the server thread that the state has changed and waits for it to
566 * make the changes */
567 static void RPCRT4_sync_with_server_thread(void)
569 /* make sure we are the only thread sync'ing the server state, otherwise
570 * there is a race with the server thread setting an older state and setting
571 * the server_ready_event when the new state hasn't yet been applied */
572 WaitForSingleObject(mgr_mutex
, INFINITE
);
575 /* wait for server thread to make the requested changes before returning */
576 WaitForSingleObject(server_ready_event
, INFINITE
);
578 ReleaseMutex(mgr_mutex
);
581 static RPC_STATUS
RPCRT4_start_listen(BOOL auto_listen
)
583 RPC_STATUS status
= RPC_S_ALREADY_LISTENING
;
587 EnterCriticalSection(&listen_cs
);
588 if (auto_listen
|| (manual_listen_count
++ == 0))
591 if (++listen_count
== 1) {
592 HANDLE server_thread
;
593 /* first listener creates server thread */
594 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
595 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
596 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
597 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
598 if (!worker_tls
) worker_tls
= TlsAlloc();
600 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
601 CloseHandle(server_thread
);
604 LeaveCriticalSection(&listen_cs
);
609 static void RPCRT4_stop_listen(BOOL auto_listen
)
611 EnterCriticalSection(&listen_cs
);
612 if (auto_listen
|| (--manual_listen_count
== 0))
614 if (listen_count
!= 0 && --listen_count
== 0) {
616 LeaveCriticalSection(&listen_cs
);
617 RPCRT4_sync_with_server_thread();
620 assert(listen_count
>= 0);
622 LeaveCriticalSection(&listen_cs
);
625 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
627 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
,
630 EnterCriticalSection(&server_cs
);
633 LeaveCriticalSection(&server_cs
);
635 if (std_listen
) RPCRT4_sync_with_server_thread();
640 /***********************************************************************
641 * RpcServerInqBindings (RPCRT4.@)
643 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
647 RpcServerProtseq
* ps
;
651 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
653 ERR("(BindingVector == NULL!!?)\n");
655 EnterCriticalSection(&server_cs
);
656 /* count connections */
668 /* export bindings */
669 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
670 sizeof(RPC_BINDING_VECTOR
) +
671 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
672 (*BindingVector
)->Count
= count
;
678 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
687 *BindingVector
= NULL
;
688 status
= RPC_S_NO_BINDINGS
;
690 LeaveCriticalSection(&server_cs
);
694 /***********************************************************************
695 * RpcServerUseProtseqEpA (RPCRT4.@)
697 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
701 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
703 /* This should provide the default behaviour */
704 policy
.Length
= sizeof( policy
);
705 policy
.EndpointFlags
= 0;
708 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
711 /***********************************************************************
712 * RpcServerUseProtseqEpW (RPCRT4.@)
714 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
718 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
720 /* This should provide the default behaviour */
721 policy
.Length
= sizeof( policy
);
722 policy
.EndpointFlags
= 0;
725 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
728 /***********************************************************************
729 * alloc_serverprotoseq (internal)
731 static RpcServerProtseq
*alloc_serverprotoseq(UINT MaxCalls
, char *Protseq
, char *Endpoint
)
733 RpcServerProtseq
* ps
;
735 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
736 ps
->MaxCalls
= MaxCalls
;
737 ps
->Protseq
= Protseq
;
738 ps
->Endpoint
= Endpoint
;
743 /***********************************************************************
744 * RpcServerUseProtseqEpExA (RPCRT4.@)
746 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
747 PRPC_POLICY lpPolicy
)
749 char *szps
= (char*)Protseq
, *szep
= (char*)Endpoint
;
750 RpcServerProtseq
* ps
;
752 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a(szps
), MaxCalls
,
753 debugstr_a(szep
), SecurityDescriptor
,
754 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
756 ps
= alloc_serverprotoseq(MaxCalls
, RPCRT4_strdupA(szps
), RPCRT4_strdupA(szep
));
758 return RPCRT4_use_protseq(ps
);
761 /***********************************************************************
762 * RpcServerUseProtseqEpExW (RPCRT4.@)
764 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
765 PRPC_POLICY lpPolicy
)
767 RpcServerProtseq
* ps
;
769 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
770 debugstr_w( Endpoint
), SecurityDescriptor
,
771 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
773 ps
= alloc_serverprotoseq(MaxCalls
, RPCRT4_strdupWtoA(Protseq
),
774 RPCRT4_strdupWtoA(Endpoint
));
776 return RPCRT4_use_protseq(ps
);
779 /***********************************************************************
780 * RpcServerUseProtseqA (RPCRT4.@)
782 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
784 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a((char*)Protseq
), MaxCalls
, SecurityDescriptor
);
785 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
788 /***********************************************************************
789 * RpcServerUseProtseqW (RPCRT4.@)
791 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
793 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
794 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
797 /***********************************************************************
798 * RpcServerRegisterIf (RPCRT4.@)
800 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
802 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
803 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
806 /***********************************************************************
807 * RpcServerRegisterIfEx (RPCRT4.@)
809 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
810 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
812 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
813 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
816 /***********************************************************************
817 * RpcServerRegisterIf2 (RPCRT4.@)
819 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
820 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
822 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
823 RpcServerInterface
* sif
;
826 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
827 MaxRpcSize
, IfCallbackFn
);
828 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
829 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
830 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
831 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
832 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
833 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
834 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
835 if (If
->DispatchTable
) {
836 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
837 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
838 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
840 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
842 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
843 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
844 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
846 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
849 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
850 sif
->MgrEpv
= MgrEpv
;
852 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
853 sif
->MgrEpv
= If
->DefaultManagerEpv
;
856 sif
->MaxCalls
= MaxCalls
;
857 sif
->MaxRpcSize
= MaxRpcSize
;
858 sif
->IfCallbackFn
= IfCallbackFn
;
860 EnterCriticalSection(&server_cs
);
863 LeaveCriticalSection(&server_cs
);
865 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
866 RPCRT4_start_listen(TRUE
);
868 /* make sure server is actually listening on the interface before
870 RPCRT4_sync_with_server_thread();
876 /***********************************************************************
877 * RpcServerUnregisterIf (RPCRT4.@)
879 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
881 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
882 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
887 /***********************************************************************
888 * RpcServerUnregisterIfEx (RPCRT4.@)
890 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
892 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
893 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
898 /***********************************************************************
899 * RpcObjectSetType (RPCRT4.@)
902 * ObjUuid [I] "Object" UUID
903 * TypeUuid [I] "Type" UUID
906 * RPC_S_OK The call succeeded
907 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
908 * RPC_S_ALREADY_REGISTERED The provided object is already registered
910 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
911 * resets the mapping for the specified object UUID to nil (the default).
912 * The nil object is always associated with the nil type and cannot be
913 * reassigned. Servers can support multiple implementations on the same
914 * interface by registering different end-point vectors for the different
915 * types. There's no need to call this if a server only supports the nil
916 * type, as is typical.
918 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
920 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
923 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
924 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
925 /* nil uuid cannot be remapped */
926 return RPC_S_INVALID_OBJECT
;
929 /* find the mapping for this object if there is one ... */
931 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
935 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
936 /* ... and drop it from the list */
939 prev
->next
= map
->next
;
941 RpcObjTypeMaps
= map
->next
;
942 HeapFree(GetProcessHeap(), 0, map
);
945 /* ... , fail if we found it ... */
947 return RPC_S_ALREADY_REGISTERED
;
948 /* ... otherwise create a new one and add it in. */
949 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
950 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
951 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
954 prev
->next
= map
; /* prev is the last map in the linklist */
956 RpcObjTypeMaps
= map
;
962 /***********************************************************************
963 * RpcServerRegisterAuthInfoA (RPCRT4.@)
965 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
968 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
970 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
973 /***********************************************************************
974 * RpcServerRegisterAuthInfoW (RPCRT4.@)
976 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
979 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
981 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
984 /***********************************************************************
985 * RpcServerListen (RPCRT4.@)
987 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
991 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
994 return RPC_S_NO_PROTSEQS_REGISTERED
;
996 status
= RPCRT4_start_listen(FALSE
);
998 if (status
== RPC_S_OK
)
999 RPCRT4_sync_with_server_thread();
1001 if (DontWait
|| (status
!= RPC_S_OK
)) return status
;
1003 return RpcMgmtWaitServerListen();
1006 /***********************************************************************
1007 * RpcMgmtServerWaitListen (RPCRT4.@)
1009 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
1013 EnterCriticalSection(&listen_cs
);
1016 LeaveCriticalSection(&listen_cs
);
1017 return RPC_S_NOT_LISTENING
;
1020 LeaveCriticalSection(&listen_cs
);
1022 FIXME("not waiting for server calls to finish\n");
1027 /***********************************************************************
1028 * RpcMgmtStopServerListening (RPCRT4.@)
1030 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1032 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1035 FIXME("client-side invocation not implemented.\n");
1036 return RPC_S_WRONG_KIND_OF_BINDING
;
1039 RPCRT4_stop_listen(FALSE
);
1044 /***********************************************************************
1045 * I_RpcServerStartListening (RPCRT4.@)
1047 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1049 FIXME( "(%p): stub\n", hWnd
);
1054 /***********************************************************************
1055 * I_RpcServerStopListening (RPCRT4.@)
1057 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1059 FIXME( "(): stub\n" );
1064 /***********************************************************************
1065 * I_RpcWindowProc (RPCRT4.@)
1067 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1069 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);
1074 /***********************************************************************
1075 * RpcMgmtInqIfIds (RPCRT4.@)
1077 RPC_STATUS WINAPI
RpcMgmtInqIfIds(RPC_BINDING_HANDLE Binding
, RPC_IF_ID_VECTOR
**IfIdVector
)
1079 FIXME("(%p,%p): stub\n", Binding
, IfIdVector
);
1080 return RPC_S_INVALID_BINDING
;
1083 /***********************************************************************
1084 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1086 RPC_STATUS WINAPI
RpcMgmtEpEltInqBegin(RPC_BINDING_HANDLE Binding
, unsigned long InquiryType
,
1087 RPC_IF_ID
*IfId
, unsigned long VersOption
, UUID
*ObjectUuid
, RPC_EP_INQ_HANDLE
* InquiryContext
)
1089 FIXME("(%p,%lu,%p,%lu,%p,%p): stub\n",
1090 Binding
, InquiryType
, IfId
, VersOption
, ObjectUuid
, InquiryContext
);
1091 return RPC_S_INVALID_BINDING
;
1094 /***********************************************************************
1095 * RpcMgmtEpEltInqBegin (RPCRT4.@)
1097 RPC_STATUS WINAPI
RpcMgmtIsServerListening(RPC_BINDING_HANDLE Binding
)
1099 FIXME("(%p): stub\n", Binding
);
1100 return RPC_S_INVALID_BINDING
;