ReactOS  0.4.15-dev-492-ga1108f6
cache.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for cache.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DnsCacheLock()   do { EnterCriticalSection(&DnsCache.Lock); } while (0)
 
#define DnsCacheUnlock()   do { LeaveCriticalSection(&DnsCache.Lock); } while (0)
 

Functions

VOID DnsIntCacheInitialize (VOID)
 
VOID DnsIntCacheFree (VOID)
 
VOID DnsIntCacheRemoveEntryItem (PRESOLVER_CACHE_ENTRY CacheEntry)
 
DNS_STATUS DnsIntCacheFlush (_In_ ULONG ulFlags)
 
DNS_STATUS DnsIntCacheGetEntryByName (LPCWSTR Name, WORD wType, DWORD dwFlags, PDNS_RECORDW *Record)
 
BOOL DnsIntCacheRemoveEntryByName (LPCWSTR Name)
 
VOID DnsIntCacheAddEntry (_In_ PDNS_RECORDW Record, _In_ BOOL bHostsFileEntry)
 
DNS_STATUS DnsIntCacheGetEntries (_Out_ DNS_CACHE_ENTRY **ppCacheEntries)
 

Variables

static RESOLVER_CACHE DnsCache
 
static BOOL DnsCacheInitialized = FALSE
 

Macro Definition Documentation

◆ DnsCacheLock

#define DnsCacheLock ( )    do { EnterCriticalSection(&DnsCache.Lock); } while (0)

Definition at line 17 of file cache.c.

◆ DnsCacheUnlock

#define DnsCacheUnlock ( )    do { LeaveCriticalSection(&DnsCache.Lock); } while (0)

Definition at line 18 of file cache.c.

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file cache.c.

Function Documentation

◆ DnsIntCacheAddEntry()

VOID DnsIntCacheAddEntry ( _In_ PDNS_RECORDW  Record,
_In_ BOOL  bHostsFileEntry 
)

Definition at line 188 of file cache.c.

191 {
193 
194  DPRINT("DnsIntCacheAddEntry(%p %u)\n",
195  Record, bHostsFileEntry);
196 
197  DPRINT("Name: %S\n", Record->pName);
198  DPRINT("TTL: %lu\n", Record->dwTtl);
199 
200  /* Lock the cache */
201  DnsCacheLock();
202 
203  /* Match the Id with all the entries in the List */
204  Entry = (PRESOLVER_CACHE_ENTRY)HeapAlloc(GetProcessHeap(), 0, sizeof(*Entry));
205  if (!Entry)
206  return;
207 
208  Entry->bHostsFileEntry = bHostsFileEntry;
210 
211  /* Insert it to our List */
212  InsertTailList(&DnsCache.RecordList, &Entry->CacheLink);
213 
214  /* Release the cache */
215  DnsCacheUnlock();
216 }
Definition: precomp.h:27
struct _Entry Entry
Definition: kefuncs.h:627
#define InsertTailList(ListHead, Entry)
struct _RESOLVER_CACHE_ENTRY * PRESOLVER_CACHE_ENTRY
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:256
void DPRINT(...)
Definition: polytest.cpp:61
#define DnsCacheUnlock()
Definition: cache.c:18
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LIST_ENTRY RecordList
Definition: precomp.h:36
#define DnsCacheLock()
Definition: cache.c:17
PDNS_RECORD WINAPI DnsRecordSetCopyEx(PDNS_RECORD src_set, DNS_CHARSET in, DNS_CHARSET out)
Definition: record.c:712
base of all file and directory entries
Definition: entries.h:82

Referenced by AddIpv4HostEntries(), AddIpv6HostEntries(), and R_ResolverQuery().

◆ DnsIntCacheFlush()

DNS_STATUS DnsIntCacheFlush ( _In_ ULONG  ulFlags)

Definition at line 69 of file cache.c.

71 {
72  PLIST_ENTRY Entry, NextEntry;
73  PRESOLVER_CACHE_ENTRY CacheEntry;
74 
75  DPRINT("DnsIntCacheFlush(%lu)\n", ulFlags);
76 
77  /* Lock the cache */
78  DnsCacheLock();
79 
80  /* Loop every entry */
82  while (Entry != &DnsCache.RecordList)
83  {
84  NextEntry = Entry->Flink;
85 
86  /* Get this entry */
87  CacheEntry = CONTAINING_RECORD(Entry, RESOLVER_CACHE_ENTRY, CacheLink);
88 
89  /* Remove it from list */
90  if (((ulFlags & CACHE_FLUSH_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry != FALSE)) ||
91  ((ulFlags & CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry == FALSE)))
92  DnsIntCacheRemoveEntryItem(CacheEntry);
93 
94  /* Move to the next entry */
95  Entry = NextEntry;
96  }
97 
98  /* Unlock the cache */
100 
101  return ERROR_SUCCESS;
102 }
Definition: precomp.h:27
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _Entry Entry
Definition: kefuncs.h:627
VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry)
Definition: cache.c:54
void DPRINT(...)
Definition: polytest.cpp:61
#define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES
Definition: precomp.h:48
#define DnsCacheUnlock()
Definition: cache.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
LIST_ENTRY RecordList
Definition: precomp.h:36
#define DnsCacheLock()
Definition: cache.c:17
BOOL bHostsFileEntry
Definition: precomp.h:30
Definition: typedefs.h:118
#define CACHE_FLUSH_HOSTS_FILE_ENTRIES
Definition: precomp.h:47
base of all file and directory entries
Definition: entries.h:82

Referenced by DnsIntCacheFree(), and R_ResolverFlushCache().

◆ DnsIntCacheFree()

VOID DnsIntCacheFree ( VOID  )

Definition at line 36 of file cache.c.

37 {
38  DPRINT("DnsIntCacheFree()\n");
39 
40  /* Check if we're initialized */
42  return;
43 
45  return;
46 
48 
51 }
static BOOL DnsCacheInitialized
Definition: cache.c:15
DNS_STATUS DnsIntCacheFlush(_In_ ULONG ulFlags)
Definition: cache.c:69
CRITICAL_SECTION Lock
Definition: precomp.h:37
#define CACHE_FLUSH_ALL
Definition: precomp.h:49
void DPRINT(...)
Definition: polytest.cpp:61
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
LIST_ENTRY RecordList
Definition: precomp.h:36
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by ServiceControlHandler(), and ServiceMain().

◆ DnsIntCacheGetEntries()

DNS_STATUS DnsIntCacheGetEntries ( _Out_ DNS_CACHE_ENTRY **  ppCacheEntries)

Definition at line 219 of file cache.c.

221 {
222  PRESOLVER_CACHE_ENTRY CacheEntry;
223  PLIST_ENTRY NextEntry;
224  PDNS_CACHE_ENTRY pLastEntry = NULL, pNewEntry;
225 
226  /* Lock the cache */
227  DnsCacheLock();
228 
229  *ppCacheEntries = NULL;
230 
231  NextEntry = DnsCache.RecordList.Flink;
232  while (NextEntry != &DnsCache.RecordList)
233  {
234  /* Get the Current Entry */
235  CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
236 
237  DPRINT("1 %S %lu\n", CacheEntry->Record->pName, CacheEntry->Record->wType);
238  if (CacheEntry->Record->pNext)
239  {
240  DPRINT("2 %S %lu\n", CacheEntry->Record->pNext->pName, CacheEntry->Record->pNext->wType);
241  }
242 
243  pNewEntry = midl_user_allocate(sizeof(DNS_CACHE_ENTRY));
244  if (pNewEntry == NULL)
245  {
246  return ERROR_OUTOFMEMORY;
247  }
248 
249  pNewEntry->pszName = midl_user_allocate((wcslen(CacheEntry->Record->pName) + 1) * sizeof(WCHAR));
250  if (pNewEntry->pszName == NULL)
251  {
252  return ERROR_OUTOFMEMORY;
253  }
254 
255  wcscpy(pNewEntry->pszName, CacheEntry->Record->pName);
256  pNewEntry->wType1 = CacheEntry->Record->wType;
257  pNewEntry->wType2 = 0;
258  pNewEntry->wFlags = 0;
259 
260  if (pLastEntry == NULL)
261  *ppCacheEntries = pNewEntry;
262  else
263  pLastEntry->pNext = pNewEntry;
264  pLastEntry = pNewEntry;
265 
266  NextEntry = NextEntry->Flink;
267  }
268 
269  /* Release the cache */
270  DnsCacheUnlock();
271 
272  return ERROR_SUCCESS;
273 }
Definition: precomp.h:27
#define ERROR_SUCCESS
Definition: deptool.c:10
#define midl_user_allocate
Definition: rpc.h:44
struct _DNS_CACHE_ENTRY * pNext
Definition: windns_undoc.h:10
Definition: windns_undoc.h:8
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define DnsCacheUnlock()
Definition: cache.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_ENTRY RecordList
Definition: precomp.h:36
#define DnsCacheLock()
Definition: cache.c:17
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
Definition: typedefs.h:118
WORD wType
Definition: windns.h:600
PDNS_RECORDW Record
Definition: precomp.h:31
struct _DnsRecordW * pNext
Definition: windns.h:598
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
LPWSTR pName
Definition: windns.h:599

Referenced by CRrReadCache().

◆ DnsIntCacheGetEntryByName()

DNS_STATUS DnsIntCacheGetEntryByName ( LPCWSTR  Name,
WORD  wType,
DWORD  dwFlags,
PDNS_RECORDW Record 
)

Definition at line 105 of file cache.c.

110 {
111  DNS_STATUS Status = DNS_INFO_NO_RECORDS;
112  PRESOLVER_CACHE_ENTRY CacheEntry;
113  PLIST_ENTRY NextEntry;
114 
115  DPRINT("DnsIntCacheGetEntryByName(%S %hu 0x%lx %p)\n",
116  Name, wType, dwFlags, Record);
117 
118  /* Assume failure */
119  *Record = NULL;
120 
121  /* Lock the cache */
122  DnsCacheLock();
123 
124  /* Match the Id with all the entries in the List */
125  NextEntry = DnsCache.RecordList.Flink;
126  while (NextEntry != &DnsCache.RecordList)
127  {
128  /* Get the Current Entry */
129  CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
130 
131  /* Check if this is the Catalog Entry ID we want */
132  if (_wcsicmp(CacheEntry->Record->pName, Name) == 0)
133  {
134  /* Copy the entry and return it */
137  break;
138  }
139 
140  NextEntry = NextEntry->Flink;
141  }
142 
143  /* Release the cache */
144  DnsCacheUnlock();
145 
146  return Status;
147 }
Definition: precomp.h:27
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DNS_INFO_NO_RECORDS
Definition: winerror.h:1861
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:256
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define DnsCacheUnlock()
Definition: cache.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
LIST_ENTRY RecordList
Definition: precomp.h:36
#define DnsCacheLock()
Definition: cache.c:17
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
PDNS_RECORDW Record
Definition: precomp.h:31
PDNS_RECORD WINAPI DnsRecordSetCopyEx(PDNS_RECORD src_set, DNS_CHARSET in, DNS_CHARSET out)
Definition: record.c:712
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPWSTR pName
Definition: windns.h:599

Referenced by R_ResolverQuery().

◆ DnsIntCacheInitialize()

VOID DnsIntCacheInitialize ( VOID  )

Definition at line 21 of file cache.c.

22 {
23  DPRINT("DnsIntCacheInitialize()\n");
24 
25  /* Check if we're initialized */
27  return;
28 
29  /* Initialize the cache lock and namespace list */
33 }
#define TRUE
Definition: types.h:120
static BOOL DnsCacheInitialized
Definition: cache.c:15
CRITICAL_SECTION Lock
Definition: precomp.h:37
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
void DPRINT(...)
Definition: polytest.cpp:61
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
LIST_ENTRY RecordList
Definition: precomp.h:36
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by ServiceMain().

◆ DnsIntCacheRemoveEntryByName()

BOOL DnsIntCacheRemoveEntryByName ( LPCWSTR  Name)

Definition at line 150 of file cache.c.

151 {
152  BOOL Ret = FALSE;
153  PRESOLVER_CACHE_ENTRY CacheEntry;
154  PLIST_ENTRY NextEntry;
155 
156  DPRINT("DnsIntCacheRemoveEntryByName(%S)\n", Name);
157 
158  /* Lock the cache */
159  DnsCacheLock();
160 
161  /* Match the Id with all the entries in the List */
162  NextEntry = DnsCache.RecordList.Flink;
163  while (NextEntry != &DnsCache.RecordList)
164  {
165  /* Get the Current Entry */
166  CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
167 
168  /* Check if this is the Catalog Entry ID we want */
169  if (_wcsicmp(CacheEntry->Record->pName, Name) == 0)
170  {
171  /* Remove the entry */
172  DnsIntCacheRemoveEntryItem(CacheEntry);
173  Ret = TRUE;
174  break;
175  }
176 
177  NextEntry = NextEntry->Flink;
178  }
179 
180  /* Release the cache */
181  DnsCacheUnlock();
182 
183  /* Return */
184  return Ret;
185 }
Definition: precomp.h:27
#define TRUE
Definition: types.h:120
VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry)
Definition: cache.c:54
unsigned int BOOL
Definition: ntddk_ex.h:94
void DPRINT(...)
Definition: polytest.cpp:61
#define DnsCacheUnlock()
Definition: cache.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
LIST_ENTRY RecordList
Definition: precomp.h:36
#define DnsCacheLock()
Definition: cache.c:17
Definition: typedefs.h:118
PDNS_RECORDW Record
Definition: precomp.h:31
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPWSTR pName
Definition: windns.h:599

◆ DnsIntCacheRemoveEntryItem()

VOID DnsIntCacheRemoveEntryItem ( PRESOLVER_CACHE_ENTRY  CacheEntry)

Definition at line 54 of file cache.c.

55 {
56  DPRINT("DnsIntCacheRemoveEntryItem(%p)\n", CacheEntry);
57 
58  /* Remove the entry from the list */
59  RemoveEntryList(&CacheEntry->CacheLink);
60 
61  /* Free record */
63 
64  /* Delete us */
65  HeapFree(GetProcessHeap(), 0, CacheEntry);
66 }
LIST_ENTRY CacheLink
Definition: precomp.h:29
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
void DPRINT(...)
Definition: polytest.cpp:61
#define GetProcessHeap()
Definition: compat.h:404
PDNS_RECORDW Record
Definition: precomp.h:31
#define HeapFree(x, y, z)
Definition: compat.h:403

Referenced by DnsIntCacheFlush(), and DnsIntCacheRemoveEntryByName().

Variable Documentation

◆ DnsCache

◆ DnsCacheInitialized

BOOL DnsCacheInitialized = FALSE
static

Definition at line 15 of file cache.c.

Referenced by DnsIntCacheFree(), and DnsIntCacheInitialize().