Stub implementations for LresultFromObject and
[wine.git] / dlls / rpcrt4 / rpc_server.c
blob5a9bfa1d61407439eb9930ee1b2d118ba813897c
1 /*
2 * RPC server API
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * TODO:
21 * - a whole lot
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <assert.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "winreg.h"
36 #include "ntstatus.h"
38 #include "rpc.h"
39 #include "excpt.h"
41 #include "wine/debug.h"
42 #include "wine/exception.h"
44 #include "rpc_server.h"
45 #include "rpc_misc.h"
46 #include "rpc_defs.h"
48 #define MAX_THREADS 128
50 WINE_DEFAULT_DEBUG_CHANNEL(ole);
52 typedef struct _RpcPacket
54 struct _RpcPacket* next;
55 struct _RpcConnection* conn;
56 RpcPktHdr hdr;
57 void* buf;
58 } RpcPacket;
60 typedef struct _RpcObjTypeMap
62 /* FIXME: a hash table would be better. */
63 struct _RpcObjTypeMap *next;
64 UUID Object;
65 UUID Type;
66 } RpcObjTypeMap;
68 static RpcObjTypeMap *RpcObjTypeMaps;
70 static RpcServerProtseq* protseqs;
71 static RpcServerInterface* ifs;
73 static CRITICAL_SECTION server_cs;
74 static CRITICAL_SECTION_DEBUG server_cs_debug =
76 0, 0, &server_cs,
77 { &server_cs_debug.ProcessLocksList, &server_cs_debug.ProcessLocksList },
78 0, 0, { 0, (DWORD)(__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 =
85 0, 0, &listen_cs,
86 { &listen_cs_debug.ProcessLocksList, &listen_cs_debug.ProcessLocksList },
87 0, 0, { 0, (DWORD)(__FILE__ ": listen_cs") }
89 static CRITICAL_SECTION listen_cs = { &listen_cs_debug, -1, 0, 0, 0, 0 };
91 static BOOL std_listen;
92 static LONG listen_count = -1;
93 static HANDLE mgr_event, server_thread;
95 static CRITICAL_SECTION spacket_cs;
96 static CRITICAL_SECTION_DEBUG spacket_cs_debug =
98 0, 0, &spacket_cs,
99 { &spacket_cs_debug.ProcessLocksList, &spacket_cs_debug.ProcessLocksList },
100 0, 0, { 0, (DWORD)(__FILE__ ": spacket_cs") }
102 static CRITICAL_SECTION spacket_cs = { &spacket_cs_debug, -1, 0, 0, 0, 0 };
104 static RpcPacket* spacket_head;
105 static RpcPacket* spacket_tail;
106 static HANDLE server_sem;
108 static DWORD worker_count, worker_free, worker_tls;
110 static UUID uuid_nil;
112 inline static RpcObjTypeMap *LookupObjTypeMap(UUID *ObjUuid)
114 RpcObjTypeMap *rslt = RpcObjTypeMaps;
115 RPC_STATUS dummy;
117 while (rslt) {
118 if (! UuidCompare(ObjUuid, &rslt->Object, &dummy)) break;
119 rslt = rslt->next;
122 return rslt;
125 inline static UUID *LookupObjType(UUID *ObjUuid)
127 RpcObjTypeMap *map = LookupObjTypeMap(ObjUuid);
128 if (map)
129 return &map->Type;
130 else
131 return &uuid_nil;
134 static RpcServerInterface* RPCRT4_find_interface(UUID* object, UUID* if_id)
136 UUID* MgrType = NULL;
137 RpcServerInterface* cif = NULL;
138 RPC_STATUS status;
140 MgrType = LookupObjType(object);
141 EnterCriticalSection(&server_cs);
142 cif = ifs;
143 while (cif) {
144 if (UuidEqual(if_id, &cif->If->InterfaceId.SyntaxGUID, &status) &&
145 UuidEqual(MgrType, &cif->MgrTypeUuid, &status) &&
146 (std_listen || (cif->Flags & RPC_IF_AUTOLISTEN))) break;
147 cif = cif->Next;
149 LeaveCriticalSection(&server_cs);
150 return cif;
153 static void RPCRT4_push_packet(RpcPacket* packet)
155 packet->next = NULL;
156 EnterCriticalSection(&spacket_cs);
157 if (spacket_tail) {
158 spacket_tail->next = packet;
159 spacket_tail = packet;
160 } else {
161 spacket_head = packet;
162 spacket_tail = packet;
164 LeaveCriticalSection(&spacket_cs);
167 static RpcPacket* RPCRT4_pop_packet(void)
169 RpcPacket* packet;
170 EnterCriticalSection(&spacket_cs);
171 packet = spacket_head;
172 if (packet) {
173 spacket_head = packet->next;
174 if (!spacket_head) spacket_tail = NULL;
176 LeaveCriticalSection(&spacket_cs);
177 if (packet) packet->next = NULL;
178 return packet;
181 typedef struct {
182 PRPC_MESSAGE msg;
183 void* buf;
184 } packet_state;
186 static WINE_EXCEPTION_FILTER(rpc_filter)
188 packet_state* state;
189 PRPC_MESSAGE msg;
190 state = TlsGetValue(worker_tls);
191 msg = state->msg;
192 if (msg->Buffer != state->buf) I_RpcFreeBuffer(msg);
193 msg->RpcFlags |= WINE_RPCFLAG_EXCEPTION;
194 msg->BufferLength = sizeof(DWORD);
195 I_RpcGetBuffer(msg);
196 *(DWORD*)msg->Buffer = GetExceptionCode();
197 WARN("exception caught with code 0x%08lx = %ld\n", *(DWORD*)msg->Buffer, *(DWORD*)msg->Buffer);
198 TRACE("returning failure packet\n");
199 return EXCEPTION_EXECUTE_HANDLER;
202 static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr, void* buf)
204 RpcBinding* pbind;
205 RPC_MESSAGE msg;
206 RpcServerInterface* sif;
207 RPC_DISPATCH_FUNCTION func;
208 packet_state state;
210 state.msg = &msg;
211 state.buf = buf;
212 TlsSetValue(worker_tls, &state);
213 memset(&msg, 0, sizeof(msg));
214 msg.BufferLength = hdr->len;
215 msg.Buffer = buf;
216 sif = RPCRT4_find_interface(&hdr->object, &hdr->if_id);
217 if (sif) {
218 TRACE("packet received for interface %s\n", debugstr_guid(&hdr->if_id));
219 msg.RpcInterfaceInformation = sif->If;
220 /* copy the endpoint vector from sif to msg so that midl-generated code will use it */
221 msg.ManagerEpv = sif->MgrEpv;
222 /* create temporary binding for dispatch */
223 RPCRT4_MakeBinding(&pbind, conn);
224 RPCRT4_SetBindingObject(pbind, &hdr->object);
225 msg.Handle = (RPC_BINDING_HANDLE)pbind;
226 /* process packet */
227 switch (hdr->ptype) {
228 case PKT_REQUEST:
229 /* find dispatch function */
230 msg.ProcNum = hdr->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;
235 } else {
236 if (msg.ProcNum >= sif->If->DispatchTable->DispatchTableCount) {
237 ERR("invalid procnum\n");
238 func = NULL;
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->drep[0], hdr->drep[1]),
247 MAKEWORD(hdr->drep[2], 0));
249 /* dispatch */
250 __TRY {
251 if (func) func(&msg);
252 } __EXCEPT(rpc_filter) {
253 /* failure packet was created in rpc_filter */
254 } __ENDTRY
256 /* send response packet */
257 I_RpcSend(&msg);
258 break;
259 default:
260 ERR("unknown packet type\n");
261 break;
264 RPCRT4_DestroyBinding(pbind);
265 msg.Handle = 0;
266 msg.RpcInterfaceInformation = NULL;
268 else {
269 ERR("got RPC packet to unregistered interface %s\n", debugstr_guid(&hdr->if_id));
272 /* clean up */
273 if (msg.Buffer == buf) msg.Buffer = NULL;
274 TRACE("freeing Buffer=%p\n", buf);
275 HeapFree(GetProcessHeap(), 0, buf);
276 I_RpcFreeBuffer(&msg);
277 msg.Buffer = NULL;
278 TlsSetValue(worker_tls, NULL);
281 static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
283 DWORD obj;
284 RpcPacket* pkt;
286 for (;;) {
287 /* idle timeout after 5s */
288 obj = WaitForSingleObject(server_sem, 5000);
289 if (obj == WAIT_TIMEOUT) {
290 /* if another idle thread exist, self-destruct */
291 if (worker_free > 1) break;
292 continue;
294 pkt = RPCRT4_pop_packet();
295 if (!pkt) continue;
296 InterlockedDecrement(&worker_free);
297 for (;;) {
298 RPCRT4_process_packet(pkt->conn, &pkt->hdr, pkt->buf);
299 HeapFree(GetProcessHeap(), 0, pkt);
300 /* try to grab another packet here without waiting
301 * on the semaphore, in case it hits max */
302 pkt = RPCRT4_pop_packet();
303 if (!pkt) break;
304 /* decrement semaphore */
305 WaitForSingleObject(server_sem, 0);
307 InterlockedIncrement(&worker_free);
309 InterlockedDecrement(&worker_free);
310 InterlockedDecrement(&worker_count);
311 return 0;
314 static void RPCRT4_create_worker_if_needed(void)
316 if (!worker_free && worker_count < MAX_THREADS) {
317 HANDLE thread;
318 InterlockedIncrement(&worker_count);
319 InterlockedIncrement(&worker_free);
320 thread = CreateThread(NULL, 0, RPCRT4_worker_thread, NULL, 0, NULL);
321 if (thread) CloseHandle(thread);
322 else {
323 InterlockedDecrement(&worker_free);
324 InterlockedDecrement(&worker_count);
329 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
331 RpcConnection* conn = (RpcConnection*)the_arg;
332 RpcPktHdr hdr;
333 DWORD dwRead;
334 void* buf = NULL;
335 RpcPacket* packet;
337 TRACE("(%p)\n", conn);
339 for (;;) {
340 /* read packet header */
341 #ifdef OVERLAPPED_WORKS
342 if (!ReadFile(conn->conn, &hdr, sizeof(hdr), &dwRead, &conn->ovl)) {
343 DWORD err = GetLastError();
344 if (err != ERROR_IO_PENDING) {
345 TRACE("connection lost, error=%08lx\n", err);
346 break;
348 if (!GetOverlappedResult(conn->conn, &conn->ovl, &dwRead, TRUE)) break;
350 #else
351 if (!ReadFile(conn->conn, &hdr, sizeof(hdr), &dwRead, NULL)) {
352 TRACE("connection lost, error=%08lx\n", GetLastError());
353 break;
355 #endif
356 if (dwRead != sizeof(hdr)) {
357 if (dwRead) TRACE("protocol error: <hdrsz == %d, dwRead == %lu>\n", sizeof(hdr), dwRead);
358 break;
361 /* read packet body */
362 buf = HeapAlloc(GetProcessHeap(), 0, hdr.len);
363 TRACE("receiving payload=%d\n", hdr.len);
364 if (!hdr.len) dwRead = 0; else
365 #ifdef OVERLAPPED_WORKS
366 if (!ReadFile(conn->conn, buf, hdr.len, &dwRead, &conn->ovl)) {
367 DWORD err = GetLastError();
368 if (err != ERROR_IO_PENDING) {
369 TRACE("connection lost, error=%08lx\n", err);
370 break;
372 if (!GetOverlappedResult(conn->conn, &conn->ovl, &dwRead, TRUE)) break;
374 #else
375 if (!ReadFile(conn->conn, buf, hdr.len, &dwRead, NULL)) {
376 TRACE("connection lost, error=%08lx\n", GetLastError());
377 break;
379 #endif
380 if (dwRead != hdr.len) {
381 TRACE("protocol error: <bodylen == %d, dwRead == %lu>\n", hdr.len, dwRead);
382 break;
385 #if 0
386 RPCRT4_process_packet(conn, &hdr, buf);
387 #else
388 packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
389 packet->conn = conn;
390 packet->hdr = hdr;
391 packet->buf = buf;
392 RPCRT4_create_worker_if_needed();
393 RPCRT4_push_packet(packet);
394 ReleaseSemaphore(server_sem, 1, NULL);
395 #endif
396 buf = NULL;
398 if (buf) HeapFree(GetProcessHeap(), 0, buf);
399 RPCRT4_DestroyConnection(conn);
400 return 0;
403 static void RPCRT4_new_client(RpcConnection* conn)
405 HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
406 if (!thread) {
407 DWORD err = GetLastError();
408 ERR("failed to create thread, error=%08lx\n", err);
409 RPCRT4_DestroyConnection(conn);
411 /* we could set conn->thread, but then we'd have to make the io_thread wait
412 * for that, otherwise the thread might finish, destroy the connection, and
413 * free the memory we'd write to before we did, causing crashes and stuff -
414 * so let's implement that later, when we really need conn->thread */
416 CloseHandle( thread );
419 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
421 HANDLE m_event = mgr_event, b_handle;
422 HANDLE *objs = NULL;
423 DWORD count, res;
424 RpcServerProtseq* cps;
425 RpcConnection* conn;
426 RpcConnection* cconn;
428 TRACE("(the_arg == ^%p)\n", the_arg);
430 for (;;) {
431 EnterCriticalSection(&server_cs);
432 /* open and count connections */
433 count = 1;
434 cps = protseqs;
435 while (cps) {
436 conn = cps->conn;
437 while (conn) {
438 RPCRT4_OpenConnection(conn);
439 if (conn->ovl.hEvent) count++;
440 conn = conn->Next;
442 cps = cps->Next;
444 /* make array of connections */
445 if (objs)
446 objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
447 else
448 objs = HeapAlloc(GetProcessHeap(), 0, count*sizeof(HANDLE));
450 objs[0] = m_event;
451 count = 1;
452 cps = protseqs;
453 while (cps) {
454 conn = cps->conn;
455 while (conn) {
456 if (conn->ovl.hEvent) objs[count++] = conn->ovl.hEvent;
457 conn = conn->Next;
459 cps = cps->Next;
461 LeaveCriticalSection(&server_cs);
463 /* start waiting */
464 res = WaitForMultipleObjects(count, objs, FALSE, INFINITE);
465 if (res == WAIT_OBJECT_0) {
466 ResetEvent(m_event);
467 if (!std_listen) break;
469 else if (res == WAIT_FAILED) {
470 ERR("wait failed\n");
472 else {
473 b_handle = objs[res - WAIT_OBJECT_0];
474 /* find which connection got a RPC */
475 EnterCriticalSection(&server_cs);
476 conn = NULL;
477 cps = protseqs;
478 while (cps) {
479 conn = cps->conn;
480 while (conn) {
481 if (conn->ovl.hEvent == b_handle) break;
482 conn = conn->Next;
484 if (conn) break;
485 cps = cps->Next;
487 cconn = NULL;
488 if (conn) RPCRT4_SpawnConnection(&cconn, conn);
489 LeaveCriticalSection(&server_cs);
490 if (!conn) {
491 ERR("failed to locate connection for handle %p\n", b_handle);
493 if (cconn) RPCRT4_new_client(cconn);
496 HeapFree(GetProcessHeap(), 0, objs);
497 EnterCriticalSection(&server_cs);
498 /* close connections */
499 cps = protseqs;
500 while (cps) {
501 conn = cps->conn;
502 while (conn) {
503 RPCRT4_CloseConnection(conn);
504 conn = conn->Next;
506 cps = cps->Next;
508 LeaveCriticalSection(&server_cs);
509 return 0;
512 static void RPCRT4_start_listen(void)
514 TRACE("\n");
516 EnterCriticalSection(&listen_cs);
517 if (! ++listen_count) {
518 if (!mgr_event) mgr_event = CreateEventA(NULL, TRUE, FALSE, NULL);
519 if (!server_sem) server_sem = CreateSemaphoreA(NULL, 0, MAX_THREADS, NULL);
520 if (!worker_tls) worker_tls = TlsAlloc();
521 std_listen = TRUE;
522 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);
523 LeaveCriticalSection(&listen_cs);
524 } else {
525 LeaveCriticalSection(&listen_cs);
526 SetEvent(mgr_event);
530 static void RPCRT4_stop_listen(void)
532 EnterCriticalSection(&listen_cs);
533 if (listen_count == -1)
534 LeaveCriticalSection(&listen_cs);
535 else if (--listen_count == -1) {
536 std_listen = FALSE;
537 LeaveCriticalSection(&listen_cs);
538 SetEvent(mgr_event);
539 } else
540 LeaveCriticalSection(&listen_cs);
541 assert(listen_count > -2);
544 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
546 RPCRT4_CreateConnection(&ps->conn, TRUE, ps->Protseq, NULL, ps->Endpoint, NULL, NULL);
548 EnterCriticalSection(&server_cs);
549 ps->Next = protseqs;
550 protseqs = ps;
551 LeaveCriticalSection(&server_cs);
553 if (std_listen) SetEvent(mgr_event);
555 return RPC_S_OK;
558 /***********************************************************************
559 * RpcServerInqBindings (RPCRT4.@)
561 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
563 RPC_STATUS status;
564 DWORD count;
565 RpcServerProtseq* ps;
566 RpcConnection* conn;
568 if (BindingVector)
569 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
570 else
571 ERR("(BindingVector == NULL!!?)\n");
573 EnterCriticalSection(&server_cs);
574 /* count connections */
575 count = 0;
576 ps = protseqs;
577 while (ps) {
578 conn = ps->conn;
579 while (conn) {
580 count++;
581 conn = conn->Next;
583 ps = ps->Next;
585 if (count) {
586 /* export bindings */
587 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
588 sizeof(RPC_BINDING_VECTOR) +
589 sizeof(RPC_BINDING_HANDLE)*(count-1));
590 (*BindingVector)->Count = count;
591 count = 0;
592 ps = protseqs;
593 while (ps) {
594 conn = ps->conn;
595 while (conn) {
596 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
597 conn);
598 count++;
599 conn = conn->Next;
601 ps = ps->Next;
603 status = RPC_S_OK;
604 } else {
605 *BindingVector = NULL;
606 status = RPC_S_NO_BINDINGS;
608 LeaveCriticalSection(&server_cs);
609 return status;
612 /***********************************************************************
613 * RpcServerUseProtseqEpA (RPCRT4.@)
615 RPC_STATUS WINAPI RpcServerUseProtseqEpA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor )
617 RPC_POLICY policy;
619 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
621 /* This should provide the default behaviour */
622 policy.Length = sizeof( policy );
623 policy.EndpointFlags = 0;
624 policy.NICFlags = 0;
626 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
629 /***********************************************************************
630 * RpcServerUseProtseqEpW (RPCRT4.@)
632 RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
634 RPC_POLICY policy;
636 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
638 /* This should provide the default behaviour */
639 policy.Length = sizeof( policy );
640 policy.EndpointFlags = 0;
641 policy.NICFlags = 0;
643 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
646 /***********************************************************************
647 * RpcServerUseProtseqEpExA (RPCRT4.@)
649 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor,
650 PRPC_POLICY lpPolicy )
652 RpcServerProtseq* ps;
654 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq ), MaxCalls,
655 debugstr_a( Endpoint ), SecurityDescriptor,
656 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
658 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
659 ps->MaxCalls = MaxCalls;
660 ps->Protseq = RPCRT4_strdupA(Protseq);
661 ps->Endpoint = RPCRT4_strdupA(Endpoint);
663 return RPCRT4_use_protseq(ps);
666 /***********************************************************************
667 * RpcServerUseProtseqEpExW (RPCRT4.@)
669 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
670 PRPC_POLICY lpPolicy )
672 RpcServerProtseq* ps;
674 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
675 debugstr_w( Endpoint ), SecurityDescriptor,
676 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
678 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
679 ps->MaxCalls = MaxCalls;
680 ps->Protseq = RPCRT4_strdupWtoA(Protseq);
681 ps->Endpoint = RPCRT4_strdupWtoA(Endpoint);
683 return RPCRT4_use_protseq(ps);
686 /***********************************************************************
687 * RpcServerUseProtseqA (RPCRT4.@)
689 RPC_STATUS WINAPI RpcServerUseProtseqA(LPSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
691 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_a(Protseq), MaxCalls, SecurityDescriptor);
692 return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
695 /***********************************************************************
696 * RpcServerUseProtseqW (RPCRT4.@)
698 RPC_STATUS WINAPI RpcServerUseProtseqW(LPWSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
700 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)\n", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
701 return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
704 /***********************************************************************
705 * RpcServerRegisterIf (RPCRT4.@)
707 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
709 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
710 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
713 /***********************************************************************
714 * RpcServerRegisterIfEx (RPCRT4.@)
716 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
717 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
719 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
720 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
723 /***********************************************************************
724 * RpcServerRegisterIf2 (RPCRT4.@)
726 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
727 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
729 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
730 RpcServerInterface* sif;
731 int i;
733 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
734 MaxRpcSize, IfCallbackFn);
735 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
736 If->InterfaceId.SyntaxVersion.MajorVersion,
737 If->InterfaceId.SyntaxVersion.MinorVersion);
738 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
739 If->TransferSyntax.SyntaxVersion.MajorVersion,
740 If->TransferSyntax.SyntaxVersion.MinorVersion);
741 TRACE(" dispatch table: %p\n", If->DispatchTable);
742 if (If->DispatchTable) {
743 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
744 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
745 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
747 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
749 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
750 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
751 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
752 TRACE(" flags: %08x\n", If->Flags);
754 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
755 sif->If = If;
756 if (MgrTypeUuid) {
757 memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
758 sif->MgrEpv = MgrEpv;
759 } else {
760 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
761 sif->MgrEpv = If->DefaultManagerEpv;
763 sif->Flags = Flags;
764 sif->MaxCalls = MaxCalls;
765 sif->MaxRpcSize = MaxRpcSize;
766 sif->IfCallbackFn = IfCallbackFn;
768 EnterCriticalSection(&server_cs);
769 sif->Next = ifs;
770 ifs = sif;
771 LeaveCriticalSection(&server_cs);
773 if (sif->Flags & RPC_IF_AUTOLISTEN) {
774 /* well, start listening, I think... */
775 RPCRT4_start_listen();
778 return RPC_S_OK;
781 /***********************************************************************
782 * RpcServerUnregisterIf (RPCRT4.@)
784 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
786 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
787 IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
789 return RPC_S_OK;
792 /***********************************************************************
793 * RpcServerUnregisterIfEx (RPCRT4.@)
795 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
797 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
798 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
800 return RPC_S_OK;
803 /***********************************************************************
804 * RpcObjectSetType (RPCRT4.@)
806 * PARAMS
807 * ObjUuid [I] "Object" UUID
808 * TypeUuid [I] "Type" UUID
810 * RETURNS
811 * RPC_S_OK The call succeeded
812 * RPC_S_INVALID_OBJECT The provided object (nil) is not valid
813 * RPC_S_ALREADY_REGISTERED The provided object is already registered
815 * Maps "Object" UUIDs to "Type" UUID's. Passing the nil UUID as the type
816 * resets the mapping for the specified object UUID to nil (the default).
817 * The nil object is always associated with the nil type and cannot be
818 * reassigned. Servers can support multiple implementations on the same
819 * interface by registering different end-point vectors for the different
820 * types. There's no need to call this if a server only supports the nil
821 * type, as is typical.
823 RPC_STATUS WINAPI RpcObjectSetType( UUID* ObjUuid, UUID* TypeUuid )
825 RpcObjTypeMap *map = RpcObjTypeMaps, *prev = NULL;
826 RPC_STATUS dummy;
828 TRACE("(ObjUUID == %s, TypeUuid == %s).\n", debugstr_guid(ObjUuid), debugstr_guid(TypeUuid));
829 if ((! ObjUuid) || UuidIsNil(ObjUuid, &dummy)) {
830 /* nil uuid cannot be remapped */
831 return RPC_S_INVALID_OBJECT;
834 /* find the mapping for this object if there is one ... */
835 while (map) {
836 if (! UuidCompare(ObjUuid, &map->Object, &dummy)) break;
837 prev = map;
838 map = map->next;
840 if ((! TypeUuid) || UuidIsNil(TypeUuid, &dummy)) {
841 /* ... and drop it from the list */
842 if (map) {
843 if (prev)
844 prev->next = map->next;
845 else
846 RpcObjTypeMaps = map->next;
847 HeapFree(GetProcessHeap(), 0, map);
849 } else {
850 /* ... , fail if we found it ... */
851 if (map)
852 return RPC_S_ALREADY_REGISTERED;
853 /* ... otherwise create a new one and add it in. */
854 map = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcObjTypeMap));
855 memcpy(&map->Object, ObjUuid, sizeof(UUID));
856 memcpy(&map->Type, TypeUuid, sizeof(UUID));
857 map->next = NULL;
858 if (prev)
859 prev->next = map; /* prev is the last map in the linklist */
860 else
861 RpcObjTypeMaps = map;
864 return RPC_S_OK;
867 /***********************************************************************
868 * RpcServerRegisterAuthInfoA (RPCRT4.@)
870 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( LPSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
871 LPVOID Arg )
873 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
875 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
878 /***********************************************************************
879 * RpcServerRegisterAuthInfoW (RPCRT4.@)
881 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
882 LPVOID Arg )
884 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
886 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
889 /***********************************************************************
890 * RpcServerListen (RPCRT4.@)
892 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
894 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
896 if (!protseqs)
897 return RPC_S_NO_PROTSEQS_REGISTERED;
899 EnterCriticalSection(&listen_cs);
901 if (std_listen) {
902 LeaveCriticalSection(&listen_cs);
903 return RPC_S_ALREADY_LISTENING;
906 RPCRT4_start_listen();
908 LeaveCriticalSection(&listen_cs);
910 if (DontWait) return RPC_S_OK;
912 return RpcMgmtWaitServerListen();
915 /***********************************************************************
916 * RpcMgmtServerWaitListen (RPCRT4.@)
918 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
920 RPC_STATUS rslt = RPC_S_OK;
922 TRACE("\n");
924 EnterCriticalSection(&listen_cs);
926 if (!std_listen)
927 if ( (rslt = RpcServerListen(1, 0, TRUE)) != RPC_S_OK ) {
928 LeaveCriticalSection(&listen_cs);
929 return rslt;
932 LeaveCriticalSection(&listen_cs);
934 while (std_listen) {
935 WaitForSingleObject(mgr_event, INFINITE);
936 if (!std_listen) {
937 Sleep(100); /* don't spin violently */
938 TRACE("spinning.\n");
942 return rslt;
945 /***********************************************************************
946 * RpcMgmtStopServerListening (RPCRT4.@)
948 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
950 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
952 if (Binding) {
953 FIXME("client-side invocation not implemented.\n");
954 return RPC_S_WRONG_KIND_OF_BINDING;
957 /* hmm... */
958 EnterCriticalSection(&listen_cs);
959 while (std_listen)
960 RPCRT4_stop_listen();
961 LeaveCriticalSection(&listen_cs);
963 return RPC_S_OK;
966 /***********************************************************************
967 * I_RpcServerStartListening (RPCRT4.@)
969 RPC_STATUS WINAPI I_RpcServerStartListening( void* hWnd )
971 FIXME( "(%p): stub\n", hWnd );
973 return RPC_S_OK;
976 /***********************************************************************
977 * I_RpcServerStopListening (RPCRT4.@)
979 RPC_STATUS WINAPI I_RpcServerStopListening( void )
981 FIXME( "(): stub\n" );
983 return RPC_S_OK;
986 /***********************************************************************
987 * I_RpcWindowProc (RPCRT4.@)
989 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
991 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd, Message, wParam, lParam );
993 return 0;