ReactOS  0.4.14-dev-41-g31d7680
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 }
Definition: cache.c:46
#define TRUE
Definition: types.h:120
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct node node
unsigned int BOOL
Definition: ntddk_ex.h:94
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int ret
uint32_t entry
Definition: isohybrid.c:63
NBNameCacheEntry * entry
Definition: nbnamecache.c:27
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static NBNameCacheNode ** NBNameCacheWalk(struct NBNameCache *cache, const char name[NCBNAMSZ])
Definition: nbnamecache.c:66
#define HeapFree(x, y, z)
Definition: compat.h:394
struct _NBNameCacheNode * next
Definition: nbnamecache.c:28
Definition: dlist.c:348

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)
98  heap = GetProcessHeap();
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 }
Definition: cache.c:46
#define DWORD_PTR
Definition: treelist.c:76
HANDLE heap
Definition: nbnamecache.c:33
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static IOleCache * cache
Definition: ole2.c:75
DWORD entryExpireTimeMS
Definition: nbnamecache.c:35

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 }
Definition: cache.c:46
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static void NBNameCacheUnlinkNode(struct NBNameCache *cache, NBNameCacheNode **prev)
Definition: nbnamecache.c:43
#define HeapFree(x, y, z)
Definition: compat.h:394

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 }
Definition: cache.c:46
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct node node
smooth NULL
Definition: ftsmooth.c:416
#define NCBNAMSZ
Definition: nb30.h:7
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: name.c:36
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static NBNameCacheNode ** NBNameCacheWalk(struct NBNameCache *cache, const char name[NCBNAMSZ])
Definition: nbnamecache.c:66
Definition: dlist.c:348

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 }
Definition: cache.c:46
static unsigned __int64 next
Definition: rand_nt.c:6
#define HeapFree(x, y, z)
Definition: compat.h:394

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 }
Definition: cache.c:46
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define NCBNAMSZ
Definition: nb30.h:7
static void NBNameCacheUnlinkNode(struct NBNameCache *cache, NBNameCacheNode **prev)
Definition: nbnamecache.c:43
int ret
Definition: name.c:36

Referenced by NBNameCacheAddEntry(), and NBNameCacheFindEntry().