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 /* 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
;
102 /* thread that waits for connections */
103 static HANDLE server_thread
;
105 static CRITICAL_SECTION spacket_cs
;
106 static CRITICAL_SECTION_DEBUG spacket_cs_debug
=
109 { &spacket_cs_debug
.ProcessLocksList
, &spacket_cs_debug
.ProcessLocksList
},
110 0, 0, { 0, (DWORD
)(__FILE__
": spacket_cs") }
112 static CRITICAL_SECTION spacket_cs
= { &spacket_cs_debug
, -1, 0, 0, 0, 0 };
114 static RpcPacket
* spacket_head
;
115 static RpcPacket
* spacket_tail
;
116 static HANDLE server_sem
;
118 static DWORD worker_count
, worker_free
, worker_tls
;
120 static UUID uuid_nil
;
122 inline static RpcObjTypeMap
*LookupObjTypeMap(UUID
*ObjUuid
)
124 RpcObjTypeMap
*rslt
= RpcObjTypeMaps
;
128 if (! UuidCompare(ObjUuid
, &rslt
->Object
, &dummy
)) break;
135 inline static UUID
*LookupObjType(UUID
*ObjUuid
)
137 RpcObjTypeMap
*map
= LookupObjTypeMap(ObjUuid
);
144 static RpcServerInterface
* RPCRT4_find_interface(UUID
* object
,
145 RPC_SYNTAX_IDENTIFIER
* if_id
,
148 UUID
* MgrType
= NULL
;
149 RpcServerInterface
* cif
= NULL
;
153 MgrType
= LookupObjType(object
);
154 EnterCriticalSection(&server_cs
);
157 if (!memcmp(if_id
, &cif
->If
->InterfaceId
, sizeof(RPC_SYNTAX_IDENTIFIER
)) &&
158 (check_object
== FALSE
|| UuidEqual(MgrType
, &cif
->MgrTypeUuid
, &status
)) &&
159 (std_listen
|| (cif
->Flags
& RPC_IF_AUTOLISTEN
))) break;
162 LeaveCriticalSection(&server_cs
);
163 TRACE("returning %p for %s\n", cif
, debugstr_guid(object
));
167 static void RPCRT4_push_packet(RpcPacket
* packet
)
170 EnterCriticalSection(&spacket_cs
);
172 spacket_tail
->next
= packet
;
173 spacket_tail
= packet
;
175 spacket_head
= packet
;
176 spacket_tail
= packet
;
178 LeaveCriticalSection(&spacket_cs
);
181 static RpcPacket
* RPCRT4_pop_packet(void)
184 EnterCriticalSection(&spacket_cs
);
185 packet
= spacket_head
;
187 spacket_head
= packet
->next
;
188 if (!spacket_head
) spacket_tail
= NULL
;
190 LeaveCriticalSection(&spacket_cs
);
191 if (packet
) packet
->next
= NULL
;
200 static WINE_EXCEPTION_FILTER(rpc_filter
)
204 state
= TlsGetValue(worker_tls
);
206 if (msg
->Buffer
!= state
->buf
) I_RpcFreeBuffer(msg
);
207 msg
->RpcFlags
|= WINE_RPCFLAG_EXCEPTION
;
208 msg
->BufferLength
= sizeof(DWORD
);
210 *(DWORD
*)msg
->Buffer
= GetExceptionCode();
211 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD
*)msg
->Buffer
, *(DWORD
*)msg
->Buffer
);
212 TRACE("returning failure packet\n");
213 return EXCEPTION_EXECUTE_HANDLER
;
216 static void RPCRT4_process_packet(RpcConnection
* conn
, RpcPktHdr
* hdr
, RPC_MESSAGE
* msg
)
218 RpcServerInterface
* sif
;
219 RPC_DISPATCH_FUNCTION func
;
223 void *buf
= msg
->Buffer
;
228 TlsSetValue(worker_tls
, &state
);
230 switch (hdr
->common
.ptype
) {
232 TRACE("got bind packet\n");
234 /* FIXME: do more checks! */
235 if (hdr
->bind
.max_tsize
< RPC_MIN_PACKET_SIZE
||
236 !UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
237 TRACE("packet size less than min size, or active interface syntax guid non-null\n");
240 sif
= RPCRT4_find_interface(NULL
, &hdr
->bind
.abstract
, FALSE
);
243 TRACE("rejecting bind request on connection %p\n", conn
);
244 /* Report failure to client. */
245 response
= RPCRT4_BuildBindNackHeader(NDR_LOCAL_DATA_REPRESENTATION
,
246 RPC_VER_MAJOR
, RPC_VER_MINOR
);
248 TRACE("accepting bind request on connection %p\n", conn
);
251 response
= RPCRT4_BuildBindAckHeader(NDR_LOCAL_DATA_REPRESENTATION
,
255 RESULT_ACCEPT
, NO_REASON
,
256 &sif
->If
->TransferSyntax
);
258 /* save the interface for later use */
259 conn
->ActiveInterface
= hdr
->bind
.abstract
;
260 conn
->MaxTransmissionSize
= hdr
->bind
.max_tsize
;
263 if (RPCRT4_Send(conn
, response
, NULL
, 0) != RPC_S_OK
)
269 TRACE("got request packet\n");
271 /* fail if the connection isn't bound with an interface */
272 if (UuidIsNil(&conn
->ActiveInterface
.SyntaxGUID
, &status
)) {
273 response
= RPCRT4_BuildFaultHeader(NDR_LOCAL_DATA_REPRESENTATION
,
276 RPCRT4_Send(conn
, response
, NULL
, 0);
280 if (hdr
->common
.flags
& RPC_FLG_OBJECT_UUID
) {
281 object_uuid
= (UUID
*)(&hdr
->request
+ 1);
286 sif
= RPCRT4_find_interface(object_uuid
, &conn
->ActiveInterface
, TRUE
);
287 msg
->RpcInterfaceInformation
= sif
->If
;
288 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
289 msg
->ManagerEpv
= sif
->MgrEpv
;
290 if (object_uuid
!= NULL
) {
291 RPCRT4_SetBindingObject(msg
->Handle
, object_uuid
);
294 /* find dispatch function */
295 msg
->ProcNum
= hdr
->request
.opnum
;
296 if (sif
->Flags
& RPC_IF_OLE
) {
297 /* native ole32 always gives us a dispatch table with a single entry
298 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
299 func
= *sif
->If
->DispatchTable
->DispatchTable
;
301 if (msg
->ProcNum
>= sif
->If
->DispatchTable
->DispatchTableCount
) {
302 ERR("invalid procnum\n");
305 func
= sif
->If
->DispatchTable
->DispatchTable
[msg
->ProcNum
];
308 /* put in the drep. FIXME: is this more universally applicable?
309 perhaps we should move this outward... */
310 msg
->DataRepresentation
=
311 MAKELONG( MAKEWORD(hdr
->common
.drep
[0], hdr
->common
.drep
[1]),
312 MAKEWORD(hdr
->common
.drep
[2], hdr
->common
.drep
[3]));
317 } __EXCEPT(rpc_filter
) {
318 /* failure packet was created in rpc_filter */
321 /* send response packet */
324 msg
->RpcInterfaceInformation
= NULL
;
329 FIXME("unhandled packet type\n");
335 if (msg
->Buffer
== buf
) msg
->Buffer
= NULL
;
336 TRACE("freeing Buffer=%p\n", buf
);
337 HeapFree(GetProcessHeap(), 0, buf
);
338 RPCRT4_DestroyBinding(msg
->Handle
);
340 I_RpcFreeBuffer(msg
);
342 RPCRT4_FreeHeader(hdr
);
343 TlsSetValue(worker_tls
, NULL
);
346 static DWORD CALLBACK
RPCRT4_worker_thread(LPVOID the_arg
)
352 /* idle timeout after 5s */
353 obj
= WaitForSingleObject(server_sem
, 5000);
354 if (obj
== WAIT_TIMEOUT
) {
355 /* if another idle thread exist, self-destruct */
356 if (worker_free
> 1) break;
359 pkt
= RPCRT4_pop_packet();
361 InterlockedDecrement(&worker_free
);
363 RPCRT4_process_packet(pkt
->conn
, pkt
->hdr
, pkt
->msg
);
364 HeapFree(GetProcessHeap(), 0, pkt
);
365 /* try to grab another packet here without waiting
366 * on the semaphore, in case it hits max */
367 pkt
= RPCRT4_pop_packet();
369 /* decrement semaphore */
370 WaitForSingleObject(server_sem
, 0);
372 InterlockedIncrement(&worker_free
);
374 InterlockedDecrement(&worker_free
);
375 InterlockedDecrement(&worker_count
);
379 static void RPCRT4_create_worker_if_needed(void)
381 if (!worker_free
&& worker_count
< MAX_THREADS
) {
383 InterlockedIncrement(&worker_count
);
384 InterlockedIncrement(&worker_free
);
385 thread
= CreateThread(NULL
, 0, RPCRT4_worker_thread
, NULL
, 0, NULL
);
386 if (thread
) CloseHandle(thread
);
388 InterlockedDecrement(&worker_free
);
389 InterlockedDecrement(&worker_count
);
394 static DWORD CALLBACK
RPCRT4_io_thread(LPVOID the_arg
)
396 RpcConnection
* conn
= (RpcConnection
*)the_arg
;
403 TRACE("(%p)\n", conn
);
406 msg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RPC_MESSAGE
));
408 /* create temporary binding for dispatch, it will be freed in
409 * RPCRT4_process_packet */
410 RPCRT4_MakeBinding(&pbind
, conn
);
411 msg
->Handle
= (RPC_BINDING_HANDLE
)pbind
;
413 status
= RPCRT4_Receive(conn
, &hdr
, msg
);
414 if (status
!= RPC_S_OK
) {
415 WARN("receive failed with error %lx\n", status
);
420 RPCRT4_process_packet(conn
, hdr
, msg
);
422 packet
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket
));
426 RPCRT4_create_worker_if_needed();
427 RPCRT4_push_packet(packet
);
428 ReleaseSemaphore(server_sem
, 1, NULL
);
432 HeapFree(GetProcessHeap(), 0, msg
);
433 RPCRT4_DestroyConnection(conn
);
437 static void RPCRT4_new_client(RpcConnection
* conn
)
439 HANDLE thread
= CreateThread(NULL
, 0, RPCRT4_io_thread
, conn
, 0, NULL
);
441 DWORD err
= GetLastError();
442 ERR("failed to create thread, error=%08lx\n", err
);
443 RPCRT4_DestroyConnection(conn
);
445 /* we could set conn->thread, but then we'd have to make the io_thread wait
446 * for that, otherwise the thread might finish, destroy the connection, and
447 * free the memory we'd write to before we did, causing crashes and stuff -
448 * so let's implement that later, when we really need conn->thread */
450 CloseHandle( thread
);
453 static DWORD CALLBACK
RPCRT4_server_thread(LPVOID the_arg
)
455 HANDLE m_event
= mgr_event
, b_handle
;
458 RpcServerProtseq
* cps
;
460 RpcConnection
* cconn
;
461 BOOL set_ready_event
= FALSE
;
463 TRACE("(the_arg == ^%p)\n", the_arg
);
466 EnterCriticalSection(&server_cs
);
467 /* open and count connections */
473 RPCRT4_OpenConnection(conn
);
474 if (conn
->ovl
.hEvent
) count
++;
479 /* make array of connections */
481 objs
= HeapReAlloc(GetProcessHeap(), 0, objs
, count
*sizeof(HANDLE
));
483 objs
= HeapAlloc(GetProcessHeap(), 0, count
*sizeof(HANDLE
));
491 if (conn
->ovl
.hEvent
) objs
[count
++] = conn
->ovl
.hEvent
;
496 LeaveCriticalSection(&server_cs
);
500 /* signal to function that changed state that we are now sync'ed */
501 SetEvent(server_ready_event
);
502 set_ready_event
= FALSE
;
506 res
= WaitForMultipleObjects(count
, objs
, FALSE
, INFINITE
);
507 if (res
== WAIT_OBJECT_0
) {
510 SetEvent(server_ready_event
);
513 set_ready_event
= TRUE
;
515 else if (res
== WAIT_FAILED
) {
516 ERR("wait failed\n");
519 b_handle
= objs
[res
- WAIT_OBJECT_0
];
520 /* find which connection got a RPC */
521 EnterCriticalSection(&server_cs
);
527 if (conn
->ovl
.hEvent
== b_handle
) break;
534 if (conn
) RPCRT4_SpawnConnection(&cconn
, conn
);
535 LeaveCriticalSection(&server_cs
);
537 ERR("failed to locate connection for handle %p\n", b_handle
);
539 if (cconn
) RPCRT4_new_client(cconn
);
542 HeapFree(GetProcessHeap(), 0, objs
);
543 EnterCriticalSection(&server_cs
);
544 /* close connections */
549 RPCRT4_CloseConnection(conn
);
554 LeaveCriticalSection(&server_cs
);
558 /* tells the server thread that the state has changed and waits for it to
559 * make the changes */
560 static void RPCRT4_sync_with_server_thread(void)
562 /* make sure we are the only thread sync'ing the server state, otherwise
563 * there is a race with the server thread setting an older state and setting
564 * the server_ready_event when the new state hasn't yet been applied */
565 WaitForSingleObject(mgr_mutex
, INFINITE
);
568 /* wait for server thread to make the requested changes before returning */
569 WaitForSingleObject(server_ready_event
, INFINITE
);
571 ReleaseMutex(mgr_mutex
);
574 static void RPCRT4_start_listen(void)
578 EnterCriticalSection(&listen_cs
);
579 if (! ++listen_count
) {
580 if (!mgr_mutex
) mgr_mutex
= CreateMutexW(NULL
, FALSE
, NULL
);
581 if (!mgr_event
) mgr_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
582 if (!server_ready_event
) server_ready_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
583 if (!server_sem
) server_sem
= CreateSemaphoreW(NULL
, 0, MAX_THREADS
, NULL
);
584 if (!worker_tls
) worker_tls
= TlsAlloc();
586 server_thread
= CreateThread(NULL
, 0, RPCRT4_server_thread
, NULL
, 0, NULL
);
587 LeaveCriticalSection(&listen_cs
);
589 LeaveCriticalSection(&listen_cs
);
590 RPCRT4_sync_with_server_thread();
594 static void RPCRT4_stop_listen(void)
596 EnterCriticalSection(&listen_cs
);
597 if (listen_count
== -1)
598 LeaveCriticalSection(&listen_cs
);
599 else if (--listen_count
== -1) {
601 LeaveCriticalSection(&listen_cs
);
602 RPCRT4_sync_with_server_thread();
604 LeaveCriticalSection(&listen_cs
);
605 assert(listen_count
> -2);
608 static RPC_STATUS
RPCRT4_use_protseq(RpcServerProtseq
* ps
)
610 RPCRT4_CreateConnection(&ps
->conn
, TRUE
, ps
->Protseq
, NULL
, ps
->Endpoint
, NULL
, NULL
);
612 EnterCriticalSection(&server_cs
);
615 LeaveCriticalSection(&server_cs
);
617 if (std_listen
) RPCRT4_sync_with_server_thread();
622 /***********************************************************************
623 * RpcServerInqBindings (RPCRT4.@)
625 RPC_STATUS WINAPI
RpcServerInqBindings( RPC_BINDING_VECTOR
** BindingVector
)
629 RpcServerProtseq
* ps
;
633 TRACE("(*BindingVector == ^%p)\n", *BindingVector
);
635 ERR("(BindingVector == NULL!!?)\n");
637 EnterCriticalSection(&server_cs
);
638 /* count connections */
650 /* export bindings */
651 *BindingVector
= HeapAlloc(GetProcessHeap(), 0,
652 sizeof(RPC_BINDING_VECTOR
) +
653 sizeof(RPC_BINDING_HANDLE
)*(count
-1));
654 (*BindingVector
)->Count
= count
;
660 RPCRT4_MakeBinding((RpcBinding
**)&(*BindingVector
)->BindingH
[count
],
669 *BindingVector
= NULL
;
670 status
= RPC_S_NO_BINDINGS
;
672 LeaveCriticalSection(&server_cs
);
676 /***********************************************************************
677 * RpcServerUseProtseqEpA (RPCRT4.@)
679 RPC_STATUS WINAPI
RpcServerUseProtseqEpA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
)
683 TRACE( "(%s,%u,%s,%p)\n", Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
);
685 /* This should provide the default behaviour */
686 policy
.Length
= sizeof( policy
);
687 policy
.EndpointFlags
= 0;
690 return RpcServerUseProtseqEpExA( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
693 /***********************************************************************
694 * RpcServerUseProtseqEpW (RPCRT4.@)
696 RPC_STATUS WINAPI
RpcServerUseProtseqEpW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
)
700 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq
), MaxCalls
, debugstr_w( Endpoint
), SecurityDescriptor
);
702 /* This should provide the default behaviour */
703 policy
.Length
= sizeof( policy
);
704 policy
.EndpointFlags
= 0;
707 return RpcServerUseProtseqEpExW( Protseq
, MaxCalls
, Endpoint
, SecurityDescriptor
, &policy
);
710 /***********************************************************************
711 * RpcServerUseProtseqEpExA (RPCRT4.@)
713 RPC_STATUS WINAPI
RpcServerUseProtseqEpExA( unsigned char *Protseq
, UINT MaxCalls
, unsigned char *Endpoint
, LPVOID SecurityDescriptor
,
714 PRPC_POLICY lpPolicy
)
716 RpcServerProtseq
* ps
;
718 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq
), MaxCalls
,
719 debugstr_a( Endpoint
), SecurityDescriptor
,
720 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
722 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
723 ps
->MaxCalls
= MaxCalls
;
724 ps
->Protseq
= RPCRT4_strdupA(Protseq
);
725 ps
->Endpoint
= RPCRT4_strdupA(Endpoint
);
727 return RPCRT4_use_protseq(ps
);
730 /***********************************************************************
731 * RpcServerUseProtseqEpExW (RPCRT4.@)
733 RPC_STATUS WINAPI
RpcServerUseProtseqEpExW( LPWSTR Protseq
, UINT MaxCalls
, LPWSTR Endpoint
, LPVOID SecurityDescriptor
,
734 PRPC_POLICY lpPolicy
)
736 RpcServerProtseq
* ps
;
738 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq
), MaxCalls
,
739 debugstr_w( Endpoint
), SecurityDescriptor
,
740 lpPolicy
->Length
, lpPolicy
->EndpointFlags
, lpPolicy
->NICFlags
);
742 ps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerProtseq
));
743 ps
->MaxCalls
= MaxCalls
;
744 ps
->Protseq
= RPCRT4_strdupWtoA(Protseq
);
745 ps
->Endpoint
= RPCRT4_strdupWtoA(Endpoint
);
747 return RPCRT4_use_protseq(ps
);
750 /***********************************************************************
751 * RpcServerUseProtseqA (RPCRT4.@)
753 RPC_STATUS WINAPI
RpcServerUseProtseqA(unsigned char *Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
755 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq
), MaxCalls
, SecurityDescriptor
);
756 return RpcServerUseProtseqEpA(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
759 /***********************************************************************
760 * RpcServerUseProtseqW (RPCRT4.@)
762 RPC_STATUS WINAPI
RpcServerUseProtseqW(LPWSTR Protseq
, unsigned int MaxCalls
, void *SecurityDescriptor
)
764 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq
), MaxCalls
, SecurityDescriptor
);
765 return RpcServerUseProtseqEpW(Protseq
, MaxCalls
, NULL
, SecurityDescriptor
);
768 /***********************************************************************
769 * RpcServerRegisterIf (RPCRT4.@)
771 RPC_STATUS WINAPI
RpcServerRegisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
)
773 TRACE("(%p,%s,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
);
774 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, (UINT
)-1, NULL
);
777 /***********************************************************************
778 * RpcServerRegisterIfEx (RPCRT4.@)
780 RPC_STATUS WINAPI
RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
781 UINT Flags
, UINT MaxCalls
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
783 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
, IfCallbackFn
);
784 return RpcServerRegisterIf2( IfSpec
, MgrTypeUuid
, MgrEpv
, Flags
, MaxCalls
, (UINT
)-1, IfCallbackFn
);
787 /***********************************************************************
788 * RpcServerRegisterIf2 (RPCRT4.@)
790 RPC_STATUS WINAPI
RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, RPC_MGR_EPV
* MgrEpv
,
791 UINT Flags
, UINT MaxCalls
, UINT MaxRpcSize
, RPC_IF_CALLBACK_FN
* IfCallbackFn
)
793 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
794 RpcServerInterface
* sif
;
797 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec
, debugstr_guid(MgrTypeUuid
), MgrEpv
, Flags
, MaxCalls
,
798 MaxRpcSize
, IfCallbackFn
);
799 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
),
800 If
->InterfaceId
.SyntaxVersion
.MajorVersion
,
801 If
->InterfaceId
.SyntaxVersion
.MinorVersion
);
802 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If
->TransferSyntax
.SyntaxGUID
),
803 If
->TransferSyntax
.SyntaxVersion
.MajorVersion
,
804 If
->TransferSyntax
.SyntaxVersion
.MinorVersion
);
805 TRACE(" dispatch table: %p\n", If
->DispatchTable
);
806 if (If
->DispatchTable
) {
807 TRACE(" dispatch table count: %d\n", If
->DispatchTable
->DispatchTableCount
);
808 for (i
=0; i
<If
->DispatchTable
->DispatchTableCount
; i
++) {
809 TRACE(" entry %d: %p\n", i
, If
->DispatchTable
->DispatchTable
[i
]);
811 TRACE(" reserved: %ld\n", If
->DispatchTable
->Reserved
);
813 TRACE(" protseq endpoint count: %d\n", If
->RpcProtseqEndpointCount
);
814 TRACE(" default manager epv: %p\n", If
->DefaultManagerEpv
);
815 TRACE(" interpreter info: %p\n", If
->InterpreterInfo
);
817 sif
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(RpcServerInterface
));
820 memcpy(&sif
->MgrTypeUuid
, MgrTypeUuid
, sizeof(UUID
));
821 sif
->MgrEpv
= MgrEpv
;
823 memset(&sif
->MgrTypeUuid
, 0, sizeof(UUID
));
824 sif
->MgrEpv
= If
->DefaultManagerEpv
;
827 sif
->MaxCalls
= MaxCalls
;
828 sif
->MaxRpcSize
= MaxRpcSize
;
829 sif
->IfCallbackFn
= IfCallbackFn
;
831 EnterCriticalSection(&server_cs
);
834 LeaveCriticalSection(&server_cs
);
836 if (sif
->Flags
& RPC_IF_AUTOLISTEN
) {
837 /* well, start listening, I think... */
838 RPCRT4_start_listen();
844 /***********************************************************************
845 * RpcServerUnregisterIf (RPCRT4.@)
847 RPC_STATUS WINAPI
RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, UINT WaitForCallsToComplete
)
849 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
850 IfSpec
, debugstr_guid(MgrTypeUuid
), WaitForCallsToComplete
);
855 /***********************************************************************
856 * RpcServerUnregisterIfEx (RPCRT4.@)
858 RPC_STATUS WINAPI
RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec
, UUID
* MgrTypeUuid
, int RundownContextHandles
)
860 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
861 IfSpec
, debugstr_guid(MgrTypeUuid
), RundownContextHandles
);
866 /***********************************************************************
867 * RpcObjectSetType (RPCRT4.@)
870 * ObjUuid [I] "Object" UUID
871 * TypeUuid [I] "Type" UUID
874 * RPC_S_OK The call succeeded
875 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
876 * RPC_S_ALREADY_REGISTERED The provided object is already registered
878 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
879 * resets the mapping for the specified object UUID to nil (the default).
880 * The nil object is always associated with the nil type and cannot be
881 * reassigned. Servers can support multiple implementations on the same
882 * interface by registering different end-point vectors for the different
883 * types. There's no need to call this if a server only supports the nil
884 * type, as is typical.
886 RPC_STATUS WINAPI
RpcObjectSetType( UUID
* ObjUuid
, UUID
* TypeUuid
)
888 RpcObjTypeMap
*map
= RpcObjTypeMaps
, *prev
= NULL
;
891 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid
), debugstr_guid(TypeUuid
));
892 if ((! ObjUuid
) || UuidIsNil(ObjUuid
, &dummy
)) {
893 /* nil uuid cannot be remapped */
894 return RPC_S_INVALID_OBJECT
;
897 /* find the mapping for this object if there is one ... */
899 if (! UuidCompare(ObjUuid
, &map
->Object
, &dummy
)) break;
903 if ((! TypeUuid
) || UuidIsNil(TypeUuid
, &dummy
)) {
904 /* ... and drop it from the list */
907 prev
->next
= map
->next
;
909 RpcObjTypeMaps
= map
->next
;
910 HeapFree(GetProcessHeap(), 0, map
);
913 /* ... , fail if we found it ... */
915 return RPC_S_ALREADY_REGISTERED
;
916 /* ... otherwise create a new one and add it in. */
917 map
= HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap
));
918 memcpy(&map
->Object
, ObjUuid
, sizeof(UUID
));
919 memcpy(&map
->Type
, TypeUuid
, sizeof(UUID
));
922 prev
->next
= map
; /* prev is the last map in the linklist */
924 RpcObjTypeMaps
= map
;
930 /***********************************************************************
931 * RpcServerRegisterAuthInfoA (RPCRT4.@)
933 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoA( unsigned char *ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
936 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName
, AuthnSvc
, GetKeyFn
, Arg
);
938 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
941 /***********************************************************************
942 * RpcServerRegisterAuthInfoW (RPCRT4.@)
944 RPC_STATUS WINAPI
RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName
, unsigned long AuthnSvc
, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn
,
947 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName
), AuthnSvc
, GetKeyFn
, Arg
);
949 return RPC_S_UNKNOWN_AUTHN_SERVICE
; /* We don't know any authentication services */
952 /***********************************************************************
953 * RpcServerListen (RPCRT4.@)
955 RPC_STATUS WINAPI
RpcServerListen( UINT MinimumCallThreads
, UINT MaxCalls
, UINT DontWait
)
957 TRACE("(%u,%u,%u)\n", MinimumCallThreads
, MaxCalls
, DontWait
);
960 return RPC_S_NO_PROTSEQS_REGISTERED
;
962 EnterCriticalSection(&listen_cs
);
965 LeaveCriticalSection(&listen_cs
);
966 return RPC_S_ALREADY_LISTENING
;
969 RPCRT4_start_listen();
971 LeaveCriticalSection(&listen_cs
);
973 if (DontWait
) return RPC_S_OK
;
975 return RpcMgmtWaitServerListen();
978 /***********************************************************************
979 * RpcMgmtServerWaitListen (RPCRT4.@)
981 RPC_STATUS WINAPI
RpcMgmtWaitServerListen( void )
983 RPC_STATUS rslt
= RPC_S_OK
;
987 EnterCriticalSection(&listen_cs
);
990 if ( (rslt
= RpcServerListen(1, 0, TRUE
)) != RPC_S_OK
) {
991 LeaveCriticalSection(&listen_cs
);
995 LeaveCriticalSection(&listen_cs
);
998 WaitForSingleObject(mgr_event
, INFINITE
);
1000 Sleep(100); /* don't spin violently */
1001 TRACE("spinning.\n");
1008 /***********************************************************************
1009 * RpcMgmtStopServerListening (RPCRT4.@)
1011 RPC_STATUS WINAPI
RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding
)
1013 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding
);
1016 FIXME("client-side invocation not implemented.\n");
1017 return RPC_S_WRONG_KIND_OF_BINDING
;
1021 EnterCriticalSection(&listen_cs
);
1023 RPCRT4_stop_listen();
1024 LeaveCriticalSection(&listen_cs
);
1029 /***********************************************************************
1030 * I_RpcServerStartListening (RPCRT4.@)
1032 RPC_STATUS WINAPI
I_RpcServerStartListening( HWND hWnd
)
1034 FIXME( "(%p): stub\n", hWnd
);
1039 /***********************************************************************
1040 * I_RpcServerStopListening (RPCRT4.@)
1042 RPC_STATUS WINAPI
I_RpcServerStopListening( void )
1044 FIXME( "(): stub\n" );
1049 /***********************************************************************
1050 * I_RpcWindowProc (RPCRT4.@)
1052 UINT WINAPI
I_RpcWindowProc( void *hWnd
, UINT Message
, UINT wParam
, ULONG lParam
)
1054 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd
, Message
, wParam
, lParam
);