-
Notifications
You must be signed in to change notification settings - Fork 29
/
Util_Db.cpp
120 lines (99 loc) · 2.09 KB
/
Util_Db.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <Windows.h>
#include "ORADAD.h"
extern HANDLE g_hHeap;
extern HANDLE g_hLogFile;
extern BOOL g_bSupportsAnsi;
//
// Public functions
//
BOOL
DbAddKey (
_Inout_ PDB_ENTRY *pBase,
_In_opt_z_ LPWSTR szKeyName,
_In_ DWORD dwKeyValue,
_In_ DbCompareMode CompareMode
)
{
PDB_ENTRY pCurrent;
if (szKeyName == NULL)
return NULL;
pCurrent = DbLookupKey(*pBase, szKeyName);
if (pCurrent == NULL)
{
pCurrent = (PDB_ENTRY)_HeapAlloc(sizeof(DB_ENTRY));
if (pCurrent == NULL)
return FALSE;
DuplicateString(szKeyName, &pCurrent->szKeyName);
pCurrent->dwKeyValue = dwKeyValue;
if (*pBase == NULL)
{
*pBase = pCurrent;
}
else
{
PDB_ENTRY pLast = *pBase;
while (pLast->pNext != NULL)
pLast = (PDB_ENTRY)pLast->pNext;
pLast->pNext = pCurrent;
}
}
else
{
BOOL bUpdateValue = FALSE;
if (CompareMode == DbCompareMode::Max)
{
if (dwKeyValue > pCurrent->dwKeyValue)
{
bUpdateValue = TRUE;
}
}
else if (CompareMode == DbCompareMode::Last)
{
bUpdateValue = TRUE;
}
if (bUpdateValue == TRUE)
{
pCurrent->dwKeyValue = dwKeyValue;
}
}
return TRUE;
}
PDB_ENTRY
DbLookupKey (
_Inout_ PDB_ENTRY pBase,
_In_opt_z_ LPWSTR szKeyName
)
{
PDB_ENTRY pCurrent;
if ((pBase == NULL) || (szKeyName==NULL))
return NULL;
pCurrent = pBase;
while (pCurrent != NULL)
{
if (_wcsicmp(pCurrent->szKeyName, szKeyName) == 0)
return pCurrent;
pCurrent = (PDB_ENTRY)((PDB_ENTRY)pCurrent)->pNext;
}
// pCurrent should be null here
return pCurrent;
}
BOOL
DbFree (
_Inout_ PDB_ENTRY *pBase
)
{
PDB_ENTRY pCurrent;
if (*pBase == NULL)
return TRUE;
pCurrent = *pBase;
while (pCurrent != NULL)
{
PDB_ENTRY pBackup;
_SafeHeapRelease(pCurrent->szKeyName);
pBackup = (PDB_ENTRY)pCurrent->pNext;
_SafeHeapRelease(pCurrent);
pCurrent = pBackup;
}
*pBase = NULL;
return TRUE;
}