ReactOS 0.4.15-dev-6644-g539123c
nbnamecache.c File Reference
#include "netapi32.h"
Include dependency graph for nbnamecache.c:

Go to the source code of this file.

Classes

struct  _NBNameCacheNode
 
struct  NBNameCache
 

Typedefs

typedef struct _NBNameCacheNode NBNameCacheNode
 

Functions

static void NBNameCacheUnlinkNode (struct NBNameCache *cache, NBNameCacheNode **prev)
 
static NBNameCacheNode ** NBNameCacheWalk (struct NBNameCache *cache, const char name[NCBNAMSZ])
 
struct NBNameCacheNBNameCacheCreate (HANDLE heap, DWORD entryExpireTimeMS)
 
BOOL NBNameCacheAddEntry (struct NBNameCache *cache, NBNameCacheEntry *entry)
 
const NBNameCacheEntryNBNameCacheFindEntry (struct NBNameCache *cache, const UCHAR name[NCBNAMSZ])
 
void NBNameCacheDestroy (struct NBNameCache *cache)
 

Typedef Documentation

◆ NBNameCacheNode

Function Documentation

◆ NBNameCacheAddEntry()

BOOL NBNameCacheAddEntry ( struct NBNameCache cache,
NBNameCacheEntry entry 
)

Definition at line 111 of file nbnamecache.c.

112{
113 BOOL ret;
114
115 if (cache && entry)
116 {
118
120 node = NBNameCacheWalk(cache, (char*)entry->name);
121 if (node)
122 {
123 (*node)->expireTime = GetTickCount() +
124 cache->entryExpireTimeMS;
125 HeapFree(cache->heap, 0, (*node)->entry);
126 (*node)->entry = entry;
127 ret = TRUE;
128 }
129 else
130 {
131 NBNameCacheNode *newNode = HeapAlloc(cache->heap, 0, sizeof(NBNameCacheNode));
132 if (newNode)
133 {
134 newNode->expireTime = GetTickCount() +
135 cache->entryExpireTimeMS;
136 newNode->entry = entry;
137 newNode->next = cache->head;
138 cache->head = newNode;
139 ret = TRUE;
140 }
141 else
142 ret = FALSE;
143 }
145 }
146 else
147 ret = FALSE;
148 return ret;
149}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
unsigned int BOOL
Definition: ntddk_ex.h:94
uint32_t entry
Definition: isohybrid.c:63
static NBNameCacheNode ** NBNameCacheWalk(struct NBNameCache *cache, const char name[NCBNAMSZ])
Definition: nbnamecache.c:66
struct _NBNameCacheNode * next
Definition: nbnamecache.c:28
NBNameCacheEntry * entry
Definition: nbnamecache.c:27
Definition: cache.c:49
Definition: dlist.c:348
int ret
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by NetBTStoreCacheEntry().

◆ NBNameCacheCreate()

struct NBNameCache * NBNameCacheCreate ( HANDLE  heap,
DWORD  entryExpireTimeMS 
)

Definition at line 92 of file nbnamecache.c.

93{
94 struct NBNameCache *cache;
95
96
97 if (!heap)
99 cache = HeapAlloc(heap, 0, sizeof(struct NBNameCache));
100 if (cache)
101 {
102 cache->heap = heap;
104 cache->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": NBNameCache.cs");
105 cache->entryExpireTimeMS = entryExpireTimeMS;
106 cache->head = NULL;
107 }
108 return cache;
109}
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
static HANDLE heap
Definition: heap.c:65
DWORD entryExpireTimeMS
Definition: nbnamecache.c:35
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DWORD_PTR
Definition: treelist.c:76

Referenced by NetBTStoreCacheEntry().

◆ NBNameCacheDestroy()

void NBNameCacheDestroy ( struct NBNameCache cache)

Definition at line 176 of file nbnamecache.c.

177{
178 if (cache)
179 {
180 cache->cs.DebugInfo->Spare[0] = 0;
182 while (cache->head)
184 HeapFree(cache->heap, 0, cache);
185 }
186}
static void NBNameCacheUnlinkNode(struct NBNameCache *cache, NBNameCacheNode **prev)
Definition: nbnamecache.c:43
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by NetBTCleanup(), and NetBTCleanupAdapter().

◆ NBNameCacheFindEntry()

const NBNameCacheEntry * NBNameCacheFindEntry ( struct NBNameCache cache,
const UCHAR  name[NCBNAMSZ] 
)

Definition at line 151 of file nbnamecache.c.

153{
154 const NBNameCacheEntry *ret;
155 UCHAR printName[NCBNAMSZ];
156
157 memcpy(printName, name, NCBNAMSZ - 1);
158 printName[NCBNAMSZ - 1] = '\0';
159 if (cache)
160 {
162
164 node = NBNameCacheWalk(cache, (const char *)name);
165 if (node)
166 ret = (*node)->entry;
167 else
168 ret = NULL;
170 }
171 else
172 ret = NULL;
173 return ret;
174}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define NCBNAMSZ
Definition: nb30.h:7
Definition: name.c:39
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by NetBTInternalFindName().

◆ NBNameCacheUnlinkNode()

static void NBNameCacheUnlinkNode ( struct NBNameCache cache,
NBNameCacheNode **  prev 
)
static

Definition at line 43 of file nbnamecache.c.

45{
46 if (cache && prev && *prev)
47 {
48 NBNameCacheNode *next = (*prev)->next;
49
50 HeapFree(cache->heap, 0, (*prev)->entry);
51 HeapFree(cache->heap, 0, *prev);
52 *prev = next;
53 }
54}
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by NBNameCacheDestroy(), and NBNameCacheWalk().

◆ NBNameCacheWalk()

static NBNameCacheNode ** NBNameCacheWalk ( struct NBNameCache cache,
const char  name[NCBNAMSZ] 
)
static

Definition at line 66 of file nbnamecache.c.

68{
70
71 if (cache && cache->head)
72 {
74
75 ptr = &cache->head;
76 while (ptr && *ptr && (*ptr)->entry)
77 {
78 if (!memcmp((*ptr)->entry->name, name, NCBNAMSZ - 1))
79 ret = ptr;
80 else
81 {
82 if (GetTickCount() > (*ptr)->expireTime)
84 }
85 if (*ptr)
86 ptr = &(*ptr)->next;
87 }
88 }
89 return ret;
90}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static PVOID ptr
Definition: dispmode.c:27

Referenced by NBNameCacheAddEntry(), and NBNameCacheFindEntry().