[DNSRSLVR][DNSAPI] Enable the DNS resolver cache
[reactos.git] / base / services / dnsrslvr / rpcserver.c
1 /*
2 * PROJECT: ReactOS DNS Resolver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/dnsrslvr/rpcserver.c
5 * PURPOSE: RPC server interface
6 * COPYRIGHT: Copyright 2016 Christoph von Wittich
7 */
8
9 #include "precomp.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 DWORD
15 WINAPI
16 RpcThreadRoutine(LPVOID lpParameter)
17 {
18 RPC_STATUS Status;
19
20 Status = RpcServerUseProtseqEpW(L"ncalrpc", 20, L"DNSResolver", NULL);
21 if (Status != RPC_S_OK)
22 {
23 DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
24 return 0;
25 }
26
27 Status = RpcServerRegisterIf(DnsResolver_v2_0_s_ifspec, NULL, NULL);
28 if (Status != RPC_S_OK)
29 {
30 DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
31 return 0;
32 }
33
34 Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0);
35 if (Status != RPC_S_OK)
36 {
37 DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
38 }
39
40 DPRINT("RpcServerListen finished\n");
41 return 0;
42 }
43
44 DWORD
45 R_ResolverFlushCache(
46 DNSRSLVR_HANDLE pwszServerName)
47 {
48 DPRINT("R_ResolverFlushCache()\n");
49
50 // FIXME Should store (and flush) entries by server handle
51 DnsIntCacheFlush();
52 return 0;
53 }
54
55 DWORD
56 R_ResolverQuery(
57 DNSRSLVR_HANDLE pszServerName,
58 LPCWSTR pszName,
59 WORD wType,
60 DWORD dwFlags,
61 DWORD *dwRecords,
62 DNS_RECORDW **ppResultRecords)
63 {
64 PDNS_RECORDW Record;
65 DNS_STATUS Status;
66
67 DPRINT("R_ResolverQuery(%S %S %x %lx %p %p)\n",
68 pszServerName, pszName, wType, dwFlags, dwRecords, ppResultRecords);
69
70 if (pszName == NULL || wType == 0 || ppResultRecords == NULL)
71 return ERROR_INVALID_PARAMETER;
72
73 if ((dwFlags & DNS_QUERY_WIRE_ONLY) != 0 && (dwFlags & DNS_QUERY_NO_WIRE_QUERY) != 0)
74 return ERROR_INVALID_PARAMETER;
75
76 if (DnsIntCacheGetEntryFromName(pszName, ppResultRecords))
77 {
78 DPRINT("DNS cache query successful!\n");
79 Status = ERROR_SUCCESS;
80 }
81 else
82 {
83 DPRINT("DNS query!\n");
84 Status = Query_Main(pszName,
85 wType,
86 dwFlags,
87 ppResultRecords);
88 if (Status == ERROR_SUCCESS)
89 {
90 DPRINT("DNS query successful!\n");
91 DnsIntCacheAddEntry(*ppResultRecords);
92 }
93 }
94
95 if (dwRecords)
96 {
97 *dwRecords = 0;
98
99 if (Status == ERROR_SUCCESS)
100 {
101 Record = *ppResultRecords;
102 while (Record)
103 {
104 DPRINT("Record: %S\n", Record->pName);
105 (*dwRecords)++;
106 Record = Record->pNext;
107 }
108 }
109 }
110
111 DPRINT("R_ResolverQuery result %ld %ld\n", Status, *dwRecords);
112
113 return Status;
114 }
115
116 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
117 {
118 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
119 }
120
121 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
122 {
123 HeapFree(GetProcessHeap(), 0, ptr);
124 }
125
126 void __RPC_USER WLANSVC_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)
127 {
128 }