-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCacheEntry.cpp
186 lines (165 loc) · 4.32 KB
/
CacheEntry.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//////////////////////////////////////////////////////////////////////
// Classe : CacheEntry
// Resume : Enumerate Cache Entry
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CacheEntry.h"
#define CACHE_BUFSIZE 4096
//////////////////////////////////////////////////////////////////////
// Methode : CCacheEntry
// Resume : Constructeur
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
CCacheEntry::CCacheEntry()
{
m_CacheHandle = NULL;
}
//////////////////////////////////////////////////////////////////////
// Methode : ~CCacheEntry
// Resume : Destructor
// In : None
// Out : None
//////////////////////////////////////////////////////////////////////
CCacheEntry::~CCacheEntry()
{
}
//////////////////////////////////////////////////////////////////////
// Methode : First
// Resume : Return the first cache Entry
// In : LPCTSTR lpszSearchPattern
// Out : LPINTERNET_CACHE_ENTRY_INFO
// 120713 Adding error checking
//////////////////////////////////////////////////////////////////////
LPINTERNET_CACHE_ENTRY_INFO CCacheEntry::First(LPCTSTR lpszSearchPattern)
{
//Close previous handle
if(m_CacheHandle != NULL)
{
BOOL bReturn=FALSE;
bReturn=::FindCloseUrlCache(m_CacheHandle);
if (bReturn != TRUE)
{
printf("Error calling FindCloseUrlCache: %x\r\n", GetLastError());
}
}
LPINTERNET_CACHE_ENTRY_INFO pInfoReturn = NULL;
DWORD dwSize = CACHE_BUFSIZE;
bool bContinue = true;
//Contiue the make the first find until done with a large enough cache size
do
{
if(m_CacheInfo.GetSize() < dwSize)
{
m_CacheInfo.Allocate(dwSize);
}
else
{
m_CacheInfo.InitMemory();
}
m_CacheHandle = ::FindFirstUrlCacheEntryEx(lpszSearchPattern, 0, 0xFFFFFFFF, 0, m_CacheInfo.GetInfo(), &dwSize,0,0,0);
if(m_CacheHandle)
{
//Return info
pInfoReturn = m_CacheInfo.GetInfo();
//Stop the loop
bContinue = false;
}
else
{
if(ERROR_INSUFFICIENT_BUFFER == ::GetLastError())
{
//dwSize should now be set to the size needed
bContinue = true;
}
else
{
//Some other error
bContinue = false;
}
}
}while(bContinue);
return pInfoReturn;
}
//////////////////////////////////////////////////////////////////////
// Methode : Next
// Resume : Find next Url Cache Entry
// In : None
// Out : LPINTERNET_CACHE_ENTRY_INFO
//////////////////////////////////////////////////////////////////////
LPINTERNET_CACHE_ENTRY_INFO CCacheEntry::Next()
{
if(m_CacheHandle == NULL)
{
return NULL;
}
LPINTERNET_CACHE_ENTRY_INFO pInfoReturn = NULL;
DWORD dwSize = m_CacheInfo.GetSize();
bool bContinue = true;
//find First find Next until cache size
do
{
if(m_CacheInfo.GetSize() < dwSize)
{
m_CacheInfo.Allocate(dwSize);
}
else
{
m_CacheInfo.InitMemory();
}
BOOL bFindNext = ::FindNextUrlCacheEntry(m_CacheHandle, m_CacheInfo.GetInfo(), &dwSize);
if(bFindNext)
{
//Return info
pInfoReturn = m_CacheInfo.GetInfo();
bContinue = false;
}
else
{
DWORD dwError = ::GetLastError();
switch(dwError)
{
case ERROR_INSUFFICIENT_BUFFER:
bContinue = true;
break;
case ERROR_NO_MORE_ITEMS:
bContinue = false;
break;
default:
bContinue = false;
break;
}
}
}while(bContinue);
return pInfoReturn;
}
//////////////////////////////////////////////////////////////////////
// Methode : IsCookie
// Resume : Test if Cache entry is a Cookies
// In : None
// Out : bool
//////////////////////////////////////////////////////////////////////
bool CCacheEntry::IsCookie(DWORD dwType)
{
return ((dwType & COOKIE_CACHE_ENTRY) == COOKIE_CACHE_ENTRY);
}
//////////////////////////////////////////////////////////////////////
// Methode : IsHistory
// Resume : Test if Cache entry is a History
// In : None
// Out : bool
//////////////////////////////////////////////////////////////////////
bool CCacheEntry::IsHistory(DWORD dwType)
{
return ((dwType & URLHISTORY_CACHE_ENTRY) == URLHISTORY_CACHE_ENTRY);
}
//////////////////////////////////////////////////////////////////////
// Methode : IsTemporary
// Resume : Test if Cache entry is a Temporary Internet File
// In : None
// Out : bool
//////////////////////////////////////////////////////////////////////
bool CCacheEntry::IsTemporary(DWORD dwType)
{
return (dwType == NORMAL_CACHE_ENTRY ? TRUE:FALSE);
}