Implemented localeconv() with libc function.
[wine.git] / dlls / rpcrt4 / rpc_server.c
blob95955a03a07805479ae82352a6dd89ab07b313e2
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 <stdio.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "winreg.h"
33 #include "rpc.h"
34 #include "excpt.h"
36 #include "wine/debug.h"
37 #include "wine/exception.h"
39 #include "rpc_server.h"
40 #include "rpc_misc.h"
41 #include "rpc_defs.h"
43 #define MAX_THREADS 128
45 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 typedef struct _RpcPacket
49 struct _RpcPacket* next;
50 struct _RpcConnection* conn;
51 RpcPktHdr hdr;
52 void* buf;
53 } RpcPacket;
55 static RpcServerProtseq* protseqs;
56 static RpcServerInterface* ifs;
58 static CRITICAL_SECTION server_cs = CRITICAL_SECTION_INIT("RpcServer");
59 static CRITICAL_SECTION listen_cs = CRITICAL_SECTION_INIT("RpcListen");
60 static BOOL std_listen;
61 static LONG listen_count = -1;
62 static HANDLE mgr_event, server_thread;
64 static CRITICAL_SECTION spacket_cs = CRITICAL_SECTION_INIT("RpcServerPacket");
65 static RpcPacket* spacket_head;
66 static RpcPacket* spacket_tail;
67 static HANDLE server_sem;
69 static DWORD worker_count, worker_free, worker_tls;
71 static RpcServerInterface* RPCRT4_find_interface(UUID* object, UUID* if_id)
73 UUID* MgrType = NULL;
74 RpcServerInterface* cif = NULL;
75 RPC_STATUS status;
77 /* FIXME: object -> MgrType */
78 EnterCriticalSection(&server_cs);
79 cif = ifs;
80 while (cif) {
81 if (UuidEqual(if_id, &cif->If->InterfaceId.SyntaxGUID, &status) &&
82 UuidEqual(MgrType, &cif->MgrTypeUuid, &status) &&
83 (std_listen || (cif->Flags & RPC_IF_AUTOLISTEN))) break;
84 cif = cif->Next;
86 LeaveCriticalSection(&server_cs);
87 return cif;
90 static void RPCRT4_push_packet(RpcPacket* packet)
92 packet->next = NULL;
93 EnterCriticalSection(&spacket_cs);
94 if (spacket_tail) spacket_tail->next = packet;
95 else {
96 spacket_head = packet;
97 spacket_tail = packet;
99 LeaveCriticalSection(&spacket_cs);
102 static RpcPacket* RPCRT4_pop_packet(void)
104 RpcPacket* packet;
105 EnterCriticalSection(&spacket_cs);
106 packet = spacket_head;
107 if (packet) {
108 spacket_head = packet->next;
109 if (!spacket_head) spacket_tail = NULL;
111 LeaveCriticalSection(&spacket_cs);
112 if (packet) packet->next = NULL;
113 return packet;
116 static WINE_EXCEPTION_FILTER(rpc_filter)
118 PRPC_MESSAGE msg;
119 msg = TlsGetValue(worker_tls);
120 I_RpcFreeBuffer(msg);
121 msg->RpcFlags |= WINE_RPCFLAG_EXCEPTION;
122 msg->BufferLength = sizeof(DWORD);
123 I_RpcGetBuffer(msg);
124 *(DWORD*)msg->Buffer = GetExceptionCode();
125 return EXCEPTION_EXECUTE_HANDLER;
128 static void RPCRT4_process_packet(RpcConnection* conn, RpcPktHdr* hdr, void* buf)
130 RpcBinding* pbind;
131 RPC_MESSAGE msg;
132 RpcServerInterface* sif;
133 RPC_DISPATCH_FUNCTION func;
135 TlsSetValue(worker_tls, &msg);
136 memset(&msg, 0, sizeof(msg));
137 msg.BufferLength = hdr->len;
138 msg.Buffer = buf;
139 sif = RPCRT4_find_interface(&hdr->object, &hdr->if_id);
140 if (sif) {
141 TRACE("packet received for interface %s\n", debugstr_guid(&hdr->if_id));
142 msg.RpcInterfaceInformation = sif->If;
143 /* create temporary binding for dispatch */
144 RPCRT4_MakeBinding(&pbind, conn);
145 RPCRT4_SetBindingObject(pbind, &hdr->object);
146 msg.Handle = (RPC_BINDING_HANDLE)pbind;
147 /* process packet */
148 switch (hdr->ptype) {
149 case PKT_REQUEST:
150 /* find dispatch function */
151 msg.ProcNum = hdr->opnum;
152 if (sif->Flags & RPC_IF_OLE) {
153 /* native ole32 always gives us a dispatch table with a single entry
154 * (I assume that's a wrapper for IRpcStubBuffer::Invoke) */
155 func = *sif->If->DispatchTable->DispatchTable;
156 } else {
157 if (msg.ProcNum >= sif->If->DispatchTable->DispatchTableCount) {
158 ERR("invalid procnum\n");
159 func = NULL;
161 func = sif->If->DispatchTable->DispatchTable[msg.ProcNum];
164 /* put in the drep. FIXME: is this more universally applicable?
165 perhaps we should move this outward... */
166 msg.DataRepresentation =
167 MAKELONG( MAKEWORD(hdr->drep[0], hdr->drep[1]),
168 MAKEWORD(hdr->drep[2], 0));
170 /* dispatch */
171 __TRY {
172 if (func) func(&msg);
173 } __EXCEPT(rpc_filter) {
174 /* failure packet was created in rpc_filter */
175 TRACE("exception caught, returning failure packet\n");
176 } __ENDTRY
178 /* send response packet */
179 I_RpcSend(&msg);
180 break;
181 default:
182 ERR("unknown packet type\n");
183 break;
186 RPCRT4_DestroyBinding(pbind);
187 msg.Handle = 0;
188 msg.RpcInterfaceInformation = NULL;
190 else {
191 ERR("got RPC packet to unregistered interface %s\n", debugstr_guid(&hdr->if_id));
194 /* clean up */
195 if (msg.Buffer == buf) msg.Buffer = NULL;
196 TRACE("freeing Buffer=%p\n", buf);
197 HeapFree(GetProcessHeap(), 0, buf);
198 I_RpcFreeBuffer(&msg);
199 msg.Buffer = NULL;
200 TlsSetValue(worker_tls, NULL);
203 static DWORD CALLBACK RPCRT4_worker_thread(LPVOID the_arg)
205 DWORD obj;
206 RpcPacket* pkt;
208 for (;;) {
209 /* idle timeout after 5s */
210 obj = WaitForSingleObject(server_sem, 5000);
211 if (obj == WAIT_TIMEOUT) {
212 /* if another idle thread exist, self-destruct */
213 if (worker_free > 1) break;
214 continue;
216 pkt = RPCRT4_pop_packet();
217 if (!pkt) continue;
218 InterlockedDecrement(&worker_free);
219 for (;;) {
220 RPCRT4_process_packet(pkt->conn, &pkt->hdr, pkt->buf);
221 HeapFree(GetProcessHeap(), 0, pkt);
222 /* try to grab another packet here without waiting
223 * on the semaphore, in case it hits max */
224 pkt = RPCRT4_pop_packet();
225 if (!pkt) break;
226 /* decrement semaphore */
227 WaitForSingleObject(server_sem, 0);
229 InterlockedIncrement(&worker_free);
231 InterlockedDecrement(&worker_free);
232 InterlockedDecrement(&worker_count);
233 return 0;
236 static void RPCRT4_create_worker_if_needed(void)
238 if (!worker_free && worker_count < MAX_THREADS) {
239 HANDLE thread;
240 InterlockedIncrement(&worker_count);
241 InterlockedIncrement(&worker_free);
242 thread = CreateThread(NULL, 0, RPCRT4_worker_thread, NULL, 0, NULL);
243 if (thread) CloseHandle(thread);
244 else {
245 InterlockedDecrement(&worker_free);
246 InterlockedDecrement(&worker_count);
251 static DWORD CALLBACK RPCRT4_io_thread(LPVOID the_arg)
253 RpcConnection* conn = (RpcConnection*)the_arg;
254 RpcPktHdr hdr;
255 DWORD dwRead;
256 void* buf = NULL;
257 RpcPacket* packet;
259 TRACE("(%p)\n", conn);
261 for (;;) {
262 /* read packet header */
263 #ifdef OVERLAPPED_WORKS
264 if (!ReadFile(conn->conn, &hdr, sizeof(hdr), &dwRead, &conn->ovl)) {
265 DWORD err = GetLastError();
266 if (err != ERROR_IO_PENDING) {
267 TRACE("connection lost, error=%08lx\n", err);
268 break;
270 if (!GetOverlappedResult(conn->conn, &conn->ovl, &dwRead, TRUE)) break;
272 #else
273 if (!ReadFile(conn->conn, &hdr, sizeof(hdr), &dwRead, NULL)) {
274 TRACE("connection lost, error=%08lx\n", GetLastError());
275 break;
277 #endif
278 if (dwRead != sizeof(hdr)) {
279 if (dwRead) TRACE("protocol error: <hdrsz == %d, dwRead == %lu>\n", sizeof(hdr), dwRead);
280 break;
283 /* read packet body */
284 buf = HeapAlloc(GetProcessHeap(), 0, hdr.len);
285 TRACE("receiving payload=%d\n", hdr.len);
286 if (!hdr.len) dwRead = 0; else
287 #ifdef OVERLAPPED_WORKS
288 if (!ReadFile(conn->conn, buf, hdr.len, &dwRead, &conn->ovl)) {
289 DWORD err = GetLastError();
290 if (err != ERROR_IO_PENDING) {
291 TRACE("connection lost, error=%08lx\n", err);
292 break;
294 if (!GetOverlappedResult(conn->conn, &conn->ovl, &dwRead, TRUE)) break;
296 #else
297 if (!ReadFile(conn->conn, buf, hdr.len, &dwRead, NULL)) {
298 TRACE("connection lost, error=%08lx\n", GetLastError());
299 break;
301 #endif
302 if (dwRead != hdr.len) {
303 TRACE("protocol error: <bodylen == %d, dwRead == %lu>\n", hdr.len, dwRead);
304 break;
307 #if 0
308 RPCRT4_process_packet(conn, &hdr, buf);
309 #else
310 packet = HeapAlloc(GetProcessHeap(), 0, sizeof(RpcPacket));
311 packet->conn = conn;
312 packet->hdr = hdr;
313 packet->buf = buf;
314 RPCRT4_create_worker_if_needed();
315 RPCRT4_push_packet(packet);
316 ReleaseSemaphore(server_sem, 1, NULL);
317 #endif
318 buf = NULL;
320 if (buf) HeapFree(GetProcessHeap(), 0, buf);
321 RPCRT4_DestroyConnection(conn);
322 return 0;
325 static void RPCRT4_new_client(RpcConnection* conn)
327 HANDLE thread = CreateThread(NULL, 0, RPCRT4_io_thread, conn, 0, NULL);
328 if (!thread) {
329 DWORD err = GetLastError();
330 ERR("failed to create thread, error=%08lx\n", err);
331 RPCRT4_DestroyConnection(conn);
333 /* we could set conn->thread, but then we'd have to make the io_thread wait
334 * for that, otherwise the thread might finish, destroy the connection, and
335 * free the memory we'd write to before we did, causing crashes and stuff -
336 * so let's implement that later, when we really need conn->thread */
338 CloseHandle( thread );
341 static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
343 HANDLE m_event = mgr_event, b_handle;
344 HANDLE *objs = NULL;
345 DWORD count, res;
346 RpcServerProtseq* cps;
347 RpcConnection* conn;
348 RpcConnection* cconn;
350 for (;;) {
351 EnterCriticalSection(&server_cs);
352 /* open and count connections */
353 count = 1;
354 cps = protseqs;
355 while (cps) {
356 conn = cps->conn;
357 while (conn) {
358 RPCRT4_OpenConnection(conn);
359 if (conn->ovl.hEvent) count++;
360 conn = conn->Next;
362 cps = cps->Next;
364 /* make array of connections */
365 objs = HeapReAlloc(GetProcessHeap(), 0, objs, count*sizeof(HANDLE));
366 objs[0] = m_event;
367 count = 1;
368 cps = protseqs;
369 while (cps) {
370 conn = cps->conn;
371 while (conn) {
372 if (conn->ovl.hEvent) objs[count++] = conn->ovl.hEvent;
373 conn = conn->Next;
375 cps = cps->Next;
377 LeaveCriticalSection(&server_cs);
379 /* start waiting */
380 res = WaitForMultipleObjects(count, objs, FALSE, INFINITE);
381 if (res == WAIT_OBJECT_0) {
382 ResetEvent(m_event);
383 if (!std_listen) break;
385 else if (res == WAIT_FAILED) {
386 ERR("wait failed\n");
388 else {
389 b_handle = objs[res - WAIT_OBJECT_0];
390 /* find which connection got a RPC */
391 EnterCriticalSection(&server_cs);
392 conn = NULL;
393 cps = protseqs;
394 while (cps) {
395 conn = cps->conn;
396 while (conn) {
397 if (conn->ovl.hEvent == b_handle) break;
398 conn = conn->Next;
400 if (conn) break;
401 cps = cps->Next;
403 cconn = NULL;
404 if (conn) RPCRT4_SpawnConnection(&cconn, conn);
405 LeaveCriticalSection(&server_cs);
406 if (!conn) {
407 ERR("failed to locate connection for handle %p\n", b_handle);
409 if (cconn) RPCRT4_new_client(cconn);
412 HeapFree(GetProcessHeap(), 0, objs);
413 EnterCriticalSection(&server_cs);
414 /* close connections */
415 cps = protseqs;
416 while (cps) {
417 conn = cps->conn;
418 while (conn) {
419 RPCRT4_CloseConnection(conn);
420 conn = conn->Next;
422 cps = cps->Next;
424 LeaveCriticalSection(&server_cs);
425 return 0;
428 static void RPCRT4_start_listen(void)
430 TRACE("\n");
432 EnterCriticalSection(&listen_cs);
433 if (! ++listen_count) {
434 if (!mgr_event) mgr_event = CreateEventA(NULL, TRUE, FALSE, NULL);
435 if (!server_sem) server_sem = CreateSemaphoreA(NULL, 0, MAX_THREADS, NULL);
436 if (!worker_tls) worker_tls = TlsAlloc();
437 std_listen = TRUE;
438 server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);
439 LeaveCriticalSection(&listen_cs);
440 } else {
441 LeaveCriticalSection(&listen_cs);
442 SetEvent(mgr_event);
446 static void RPCRT4_stop_listen(void)
448 EnterCriticalSection(&listen_cs);
449 if (listen_count == -1)
450 LeaveCriticalSection(&listen_cs);
451 else if (--listen_count == -1) {
452 std_listen = FALSE;
453 LeaveCriticalSection(&listen_cs);
454 SetEvent(mgr_event);
455 } else
456 LeaveCriticalSection(&listen_cs);
457 assert(listen_count > -2);
460 static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps)
462 RPCRT4_CreateConnection(&ps->conn, TRUE, ps->Protseq, NULL, ps->Endpoint, NULL, NULL);
464 EnterCriticalSection(&server_cs);
465 ps->Next = protseqs;
466 protseqs = ps;
467 LeaveCriticalSection(&server_cs);
469 if (std_listen) SetEvent(mgr_event);
471 return RPC_S_OK;
474 /***********************************************************************
475 * RpcServerInqBindings (RPCRT4.@)
477 RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
479 RPC_STATUS status;
480 DWORD count;
481 RpcServerProtseq* ps;
482 RpcConnection* conn;
484 if (BindingVector)
485 TRACE("(*BindingVector == ^%p)\n", *BindingVector);
486 else
487 ERR("(BindingVector == ^null!!?)\n");
489 EnterCriticalSection(&server_cs);
490 /* count connections */
491 count = 0;
492 ps = protseqs;
493 while (ps) {
494 conn = ps->conn;
495 while (conn) {
496 count++;
497 conn = conn->Next;
499 ps = ps->Next;
501 if (count) {
502 /* export bindings */
503 *BindingVector = HeapAlloc(GetProcessHeap(), 0,
504 sizeof(RPC_BINDING_VECTOR) +
505 sizeof(RPC_BINDING_HANDLE)*(count-1));
506 (*BindingVector)->Count = count;
507 count = 0;
508 ps = protseqs;
509 while (ps) {
510 conn = ps->conn;
511 while (conn) {
512 RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
513 conn);
514 count++;
515 conn = conn->Next;
517 ps = ps->Next;
519 status = RPC_S_OK;
520 } else {
521 *BindingVector = NULL;
522 status = RPC_S_NO_BINDINGS;
524 LeaveCriticalSection(&server_cs);
525 return status;
528 /***********************************************************************
529 * RpcServerUseProtseqEpA (RPCRT4.@)
531 RPC_STATUS WINAPI RpcServerUseProtseqEpA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor )
533 RPC_POLICY policy;
535 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
537 /* This should provide the default behaviour */
538 policy.Length = sizeof( policy );
539 policy.EndpointFlags = 0;
540 policy.NICFlags = 0;
542 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
545 /***********************************************************************
546 * RpcServerUseProtseqEpW (RPCRT4.@)
548 RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
550 RPC_POLICY policy;
552 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
554 /* This should provide the default behaviour */
555 policy.Length = sizeof( policy );
556 policy.EndpointFlags = 0;
557 policy.NICFlags = 0;
559 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
562 /***********************************************************************
563 * RpcServerUseProtseqEpExA (RPCRT4.@)
565 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor,
566 PRPC_POLICY lpPolicy )
568 RpcServerProtseq* ps;
570 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_a( Protseq ), MaxCalls,
571 debugstr_a( Endpoint ), SecurityDescriptor,
572 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
574 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
575 ps->MaxCalls = MaxCalls;
576 ps->Protseq = RPCRT4_strdupA(Protseq);
577 ps->Endpoint = RPCRT4_strdupA(Endpoint);
579 return RPCRT4_use_protseq(ps);
582 /***********************************************************************
583 * RpcServerUseProtseqEpExW (RPCRT4.@)
585 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
586 PRPC_POLICY lpPolicy )
588 RpcServerProtseq* ps;
590 TRACE("(%s,%u,%s,%p,{%u,%lu,%lu})\n", debugstr_w( Protseq ), MaxCalls,
591 debugstr_w( Endpoint ), SecurityDescriptor,
592 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
594 ps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerProtseq));
595 ps->MaxCalls = MaxCalls;
596 /* FIXME: Did Ove have these next two as RPCRT4_strdupW for a reason? */
597 ps->Protseq = RPCRT4_strdupWtoA(Protseq);
598 ps->Endpoint = RPCRT4_strdupWtoA(Endpoint);
600 return RPCRT4_use_protseq(ps);
603 /***********************************************************************
604 * RpcServerUseProtseqA (RPCRT4.@)
606 RPC_STATUS WINAPI RpcServerUseProtseqA(LPSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
608 TRACE("(Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_a(Protseq), MaxCalls, SecurityDescriptor);
609 return RpcServerUseProtseqEpA(Protseq, MaxCalls, NULL, SecurityDescriptor);
612 /***********************************************************************
613 * RpcServerUseProtseqW (RPCRT4.@)
615 RPC_STATUS WINAPI RpcServerUseProtseqW(LPWSTR Protseq, unsigned int MaxCalls, void *SecurityDescriptor)
617 TRACE("Protseq == %s, MaxCalls == %d, SecurityDescriptor == ^%p)", debugstr_w(Protseq), MaxCalls, SecurityDescriptor);
618 return RpcServerUseProtseqEpW(Protseq, MaxCalls, NULL, SecurityDescriptor);
621 /***********************************************************************
622 * RpcServerRegisterIf (RPCRT4.@)
624 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
626 TRACE("(%p,%s,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv);
627 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
630 /***********************************************************************
631 * RpcServerRegisterIfEx (RPCRT4.@)
633 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
634 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
636 TRACE("(%p,%s,%p,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls, IfCallbackFn);
637 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
640 /***********************************************************************
641 * RpcServerRegisterIf2 (RPCRT4.@)
643 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
644 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
646 PRPC_SERVER_INTERFACE If = (PRPC_SERVER_INTERFACE)IfSpec;
647 RpcServerInterface* sif;
648 int i;
650 TRACE("(%p,%s,%p,%u,%u,%u,%p)\n", IfSpec, debugstr_guid(MgrTypeUuid), MgrEpv, Flags, MaxCalls,
651 MaxRpcSize, IfCallbackFn);
652 TRACE(" interface id: %s %d.%d\n", debugstr_guid(&If->InterfaceId.SyntaxGUID),
653 If->InterfaceId.SyntaxVersion.MajorVersion,
654 If->InterfaceId.SyntaxVersion.MinorVersion);
655 TRACE(" transfer syntax: %s %d.%d\n", debugstr_guid(&If->TransferSyntax.SyntaxGUID),
656 If->TransferSyntax.SyntaxVersion.MajorVersion,
657 If->TransferSyntax.SyntaxVersion.MinorVersion);
658 TRACE(" dispatch table: %p\n", If->DispatchTable);
659 if (If->DispatchTable) {
660 TRACE(" dispatch table count: %d\n", If->DispatchTable->DispatchTableCount);
661 for (i=0; i<If->DispatchTable->DispatchTableCount; i++) {
662 TRACE(" entry %d: %p\n", i, If->DispatchTable->DispatchTable[i]);
664 TRACE(" reserved: %ld\n", If->DispatchTable->Reserved);
666 TRACE(" protseq endpoint count: %d\n", If->RpcProtseqEndpointCount);
667 TRACE(" default manager epv: %p\n", If->DefaultManagerEpv);
668 TRACE(" interpreter info: %p\n", If->InterpreterInfo);
669 TRACE(" flags: %08x\n", If->Flags);
671 sif = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcServerInterface));
672 sif->If = If;
673 if (MgrTypeUuid)
674 memcpy(&sif->MgrTypeUuid, MgrTypeUuid, sizeof(UUID));
675 else
676 memset(&sif->MgrTypeUuid, 0, sizeof(UUID));
677 sif->MgrEpv = MgrEpv;
678 sif->Flags = Flags;
679 sif->MaxCalls = MaxCalls;
680 sif->MaxRpcSize = MaxRpcSize;
681 sif->IfCallbackFn = IfCallbackFn;
683 EnterCriticalSection(&server_cs);
684 sif->Next = ifs;
685 ifs = sif;
686 LeaveCriticalSection(&server_cs);
688 if (sif->Flags & RPC_IF_AUTOLISTEN) {
689 /* well, start listening, I think... */
690 RPCRT4_start_listen();
693 return RPC_S_OK;
696 /***********************************************************************
697 * RpcServerUnregisterIf (RPCRT4.@)
699 RPC_STATUS WINAPI RpcServerUnregisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, UINT WaitForCallsToComplete )
701 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, WaitForCallsToComplete == %u): stub\n",
702 IfSpec, debugstr_guid(MgrTypeUuid), WaitForCallsToComplete);
704 return RPC_S_OK;
707 /***********************************************************************
708 * RpcServerUnregisterIfEx (RPCRT4.@)
710 RPC_STATUS WINAPI RpcServerUnregisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, int RundownContextHandles )
712 FIXME("(IfSpec == (RPC_IF_HANDLE)^%p, MgrTypeUuid == %s, RundownContextHandles == %d): stub\n",
713 IfSpec, debugstr_guid(MgrTypeUuid), RundownContextHandles);
715 return RPC_S_OK;
718 /***********************************************************************
719 * RpcServerRegisterAuthInfoA (RPCRT4.@)
721 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( LPSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
722 LPVOID Arg )
724 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
726 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
729 /***********************************************************************
730 * RpcServerRegisterAuthInfoW (RPCRT4.@)
732 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
733 LPVOID Arg )
735 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
737 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
740 /***********************************************************************
741 * RpcServerListen (RPCRT4.@)
743 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
745 TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
747 if (!protseqs)
748 return RPC_S_NO_PROTSEQS_REGISTERED;
750 EnterCriticalSection(&listen_cs);
752 if (std_listen) {
753 LeaveCriticalSection(&listen_cs);
754 return RPC_S_ALREADY_LISTENING;
757 RPCRT4_start_listen();
759 LeaveCriticalSection(&listen_cs);
761 if (DontWait) return RPC_S_OK;
763 return RpcMgmtWaitServerListen();
766 /***********************************************************************
767 * RpcMgmtServerWaitListen (RPCRT4.@)
769 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
771 RPC_STATUS rslt = RPC_S_OK;
773 TRACE("\n");
775 EnterCriticalSection(&listen_cs);
777 if (!std_listen)
778 if ( (rslt = RpcServerListen(1, 0, TRUE)) != RPC_S_OK ) {
779 LeaveCriticalSection(&listen_cs);
780 return rslt;
783 LeaveCriticalSection(&listen_cs);
785 while (std_listen) {
786 WaitForSingleObject(mgr_event, INFINITE);
787 if (!std_listen) {
788 Sleep(100); /* don't spin violently */
789 TRACE("spinning.\n");
793 return rslt;
796 /***********************************************************************
797 * RpcMgmtStopServerListening (RPCRT4.@)
799 RPC_STATUS WINAPI RpcMgmtStopServerListening ( RPC_BINDING_HANDLE Binding )
801 TRACE("(Binding == (RPC_BINDING_HANDLE)^%p)\n", Binding);
803 if (Binding) {
804 FIXME("client-side invocation not implemented.\n");
805 return RPC_S_WRONG_KIND_OF_BINDING;
808 /* hmm... */
809 EnterCriticalSection(&listen_cs);
810 while (std_listen)
811 RPCRT4_stop_listen();
812 LeaveCriticalSection(&listen_cs);
814 return RPC_S_OK;
817 /***********************************************************************
818 * I_RpcServerStartListening (RPCRT4.@)
820 RPC_STATUS WINAPI I_RpcServerStartListening( void* hWnd )
822 FIXME( "(%p): stub\n", hWnd );
824 return RPC_S_OK;
827 /***********************************************************************
828 * I_RpcServerStopListening (RPCRT4.@)
830 RPC_STATUS WINAPI I_RpcServerStopListening( void )
832 FIXME( "(): stub\n" );
834 return RPC_S_OK;
837 /***********************************************************************
838 * I_RpcWindowProc (RPCRT4.@)
840 UINT WINAPI I_RpcWindowProc( void *hWnd, UINT Message, UINT wParam, ULONG lParam )
842 FIXME( "(%p,%08x,%08x,%08lx): stub\n", hWnd, Message, wParam, lParam );
844 return 0;