7 internal static class _WinInetCache
10 internal enum EntryType
23 internal enum Entry_FC
39 InsufficientBuffer = 122,
43 SharingViolation = 0x20,
44 InvalidParameter = 87,
46 FatalErrors = 16781312,
47 CorruptedHeaders = 16781313,
48 InternalError = 16781314
75 High = (uint)(time >> 32);
80 return (
long)(((ulong)High << 32) | Low);
85 internal struct EntryBuffer
91 public int ExemptDelta;
97 public static int MarshalSize =
Marshal.
SizeOf(typeof(EntryBuffer));
99 public int StructSize;
101 public IntPtr _OffsetSourceUrlName;
103 public IntPtr _OffsetFileName;
105 public EntryType EntryType;
123 public IntPtr _OffsetHeaderInfo;
125 public int HeaderInfoChars;
127 public IntPtr _OffsetExtension;
134 public const int DefaultBufferSize = 2048;
140 public string Filename;
142 public string FileExt;
144 public int OptionalLength;
146 public string OriginalUrl;
148 public string MetaInfo;
150 public int MaxBufferBytes;
152 public EntryBuffer Info;
154 public Entry(
string key,
int maxHeadersSize)
157 MaxBufferBytes = maxHeadersSize;
158 if (maxHeadersSize !=
int.MaxValue &&
int.MaxValue - (key.Length + EntryBuffer.MarshalSize + 1024) * 2 > maxHeadersSize)
160 MaxBufferBytes += (key.Length + EntryBuffer.MarshalSize + 1024) * 2;
162 Info.EntryType = EntryType.NormalEntry;
166 private const int c_CharSz = 2;
168 internal unsafe
static Status LookupInfo(Entry entry)
170 byte[] array =
new byte[2048];
171 int bufferSz = array.Length;
172 byte[] array2 = array;
173 for (
int i = 0; i < 64; i++)
177 byte[] array3 = array2;
178 fixed (
byte* ptr = array3)
180 if (UnsafeNclNativeMethods.UnsafeWinInetCache.GetUrlCacheEntryInfoW(entry.Key, ptr, ref bufferSz))
183 entry.MaxBufferBytes = bufferSz;
184 EntryFixup(entry, (EntryBuffer*)ptr, array2);
185 entry.Error = Status.Success;
189 if (entry.Error == Status.InsufficientBuffer && array2 == array && bufferSz <= entry.MaxBufferBytes)
191 array2 =
new byte[bufferSz];
204 internal unsafe
static SafeUnlockUrlCacheEntryFile LookupFile(Entry entry)
206 byte[] array =
new byte[2048];
207 int entryBufSize = array.Length;
208 SafeUnlockUrlCacheEntryFile handle =
null;
215 byte[] array2 = array;
216 fixed (
byte* ptr = array2)
218 entry.Error = SafeUnlockUrlCacheEntryFile.GetAndLockFile(entry.Key, ptr, ref entryBufSize, out handle);
219 if (entry.Error == Status.Success)
221 entry.MaxBufferBytes = entryBufSize;
222 EntryFixup(entry, (EntryBuffer*)ptr, array);
225 if (entry.Error == Status.InsufficientBuffer && entryBufSize <= entry.MaxBufferBytes)
227 array =
new byte[entryBufSize];
245 if (entry.Error == Status.Success)
247 entry.Error = Status.InternalError;
253 private unsafe
static Status EntryFixup(Entry entry, EntryBuffer* bufferPtr,
byte[] buffer)
255 bufferPtr->_OffsetExtension = ((bufferPtr->_OffsetExtension ==
IntPtr.
Zero) ?
IntPtr.
Zero : ((
IntPtr)((
byte*)(
void*)bufferPtr->_OffsetExtension - (
byte*)bufferPtr)));
256 bufferPtr->_OffsetFileName = ((bufferPtr->_OffsetFileName ==
IntPtr.
Zero) ?
IntPtr.
Zero : ((
IntPtr)((
byte*)(
void*)bufferPtr->_OffsetFileName - (
byte*)bufferPtr)));
257 bufferPtr->_OffsetHeaderInfo = ((bufferPtr->_OffsetHeaderInfo ==
IntPtr.
Zero) ?
IntPtr.
Zero : ((
IntPtr)((
byte*)(
void*)bufferPtr->_OffsetHeaderInfo - (
byte*)bufferPtr)));
258 bufferPtr->_OffsetSourceUrlName = ((bufferPtr->_OffsetSourceUrlName ==
IntPtr.
Zero) ?
IntPtr.
Zero : ((
IntPtr)((
byte*)(
void*)bufferPtr->_OffsetSourceUrlName - (
byte*)bufferPtr)));
259 entry.Info = *bufferPtr;
260 entry.OriginalUrl = GetEntryBufferString(bufferPtr, (
int)bufferPtr->_OffsetSourceUrlName);
261 entry.Filename = GetEntryBufferString(bufferPtr, (
int)bufferPtr->_OffsetFileName);
262 entry.FileExt = GetEntryBufferString(bufferPtr, (
int)bufferPtr->_OffsetExtension);
263 return GetEntryHeaders(entry, bufferPtr, buffer);
266 internal static Status CreateFileName(Entry entry)
268 entry.Error = Status.Success;
270 if (UnsafeNclNativeMethods.UnsafeWinInetCache.CreateUrlCacheEntryW(entry.Key, entry.OptionalLength, entry.FileExt, stringBuilder, 0))
272 entry.Filename = stringBuilder.
ToString();
273 return Status.Success;
279 internal unsafe
static Status Commit(Entry entry)
281 string text = entry.MetaInfo;
286 if (text.Length + entry.Key.Length + entry.Filename.Length + ((entry.OriginalUrl !=
null) ? entry.OriginalUrl.Length : 0) > entry.MaxBufferBytes / 2)
288 entry.Error = Status.InsufficientBuffer;
291 entry.Error = Status.Success;
292 fixed (
char* ptr = text)
294 byte* headerInfo = (
byte*)(
long)((text.Length == 0) ? ((
IntPtr)(
void*)
null) : ((
IntPtr)ptr));
295 if (!UnsafeNclNativeMethods.UnsafeWinInetCache.CommitUrlCacheEntryW(entry.Key, entry.Filename, entry.Info.ExpireTime, entry.Info.LastModifiedTime, entry.Info.EntryType, headerInfo, text.Length,
null, entry.OriginalUrl))
303 internal unsafe
static Status Update(Entry newEntry, Entry_FC attributes)
305 byte[] array =
new byte[EntryBuffer.MarshalSize];
306 newEntry.Error = Status.Success;
307 byte[] array2 = array;
308 fixed (
byte* ptr = array2)
310 EntryBuffer* ptr2 = (EntryBuffer*)ptr;
311 *ptr2 = newEntry.Info;
312 ptr2->StructSize = EntryBuffer.MarshalSize;
313 if ((attributes & Entry_FC.Headerinfo) == Entry_FC.None)
315 if (!UnsafeNclNativeMethods.UnsafeWinInetCache.SetUrlCacheEntryInfoW(newEntry.Key, ptr, attributes))
322 Entry entry =
new Entry(newEntry.Key, newEntry.MaxBufferBytes);
323 SafeUnlockUrlCacheEntryFile safeUnlockUrlCacheEntryFile =
null;
327 safeUnlockUrlCacheEntryFile = LookupFile(entry);
328 if (safeUnlockUrlCacheEntryFile ==
null)
330 newEntry.Error = entry.Error;
331 return newEntry.Error;
333 newEntry.Filename = entry.Filename;
334 newEntry.OriginalUrl = entry.OriginalUrl;
335 newEntry.FileExt = entry.FileExt;
336 attributes &= ~Entry_FC.Headerinfo;
337 if ((attributes & Entry_FC.Exptime) == Entry_FC.None)
339 newEntry.Info.ExpireTime = entry.Info.ExpireTime;
341 if ((attributes & Entry_FC.Modtime) == Entry_FC.None)
343 newEntry.Info.LastModifiedTime = entry.Info.LastModifiedTime;
345 if ((attributes & Entry_FC.Attribute) == Entry_FC.None)
347 newEntry.Info.EntryType = entry.Info.EntryType;
348 newEntry.Info.U.ExemptDelta = entry.Info.U.ExemptDelta;
349 if ((entry.Info.EntryType & EntryType.StickyEntry) == EntryType.StickyEntry)
351 attributes |= (Entry_FC.Attribute | Entry_FC.ExemptDelta);
354 attributes &= ~(Entry_FC.Modtime | Entry_FC.Exptime);
355 flag = ((entry.Info.EntryType & EntryType.Edited) != (EntryType)0);
358 entry.Info.EntryType |= EntryType.Edited;
359 if (Update(entry, Entry_FC.Attribute) != 0)
361 newEntry.Error = entry.Error;
362 return newEntry.Error;
368 safeUnlockUrlCacheEntryFile?.Close();
371 if (Commit(newEntry) != 0)
375 entry.Info.EntryType &= ~EntryType.Edited;
376 Update(entry, Entry_FC.Attribute);
378 return newEntry.Error;
382 Update(newEntry, attributes);
386 return newEntry.Error;
389 internal static Status Remove(Entry entry)
391 entry.Error = Status.Success;
392 if (!UnsafeNclNativeMethods.UnsafeWinInetCache.DeleteUrlCacheEntryW(entry.Key))
399 private unsafe
static string GetEntryBufferString(
void* bufferPtr,
int offset)
409 private unsafe
static Status GetEntryHeaders(Entry entry, EntryBuffer* bufferPtr,
byte[] buffer)
411 entry.Error = Status.Success;
412 entry.MetaInfo =
null;
413 if (bufferPtr->_OffsetHeaderInfo ==
IntPtr.
Zero || bufferPtr->HeaderInfoChars == 0 || (bufferPtr->EntryType & EntryType.UrlHistory) != 0)
415 return Status.Success;
417 int num = bufferPtr->HeaderInfoChars + (int)bufferPtr->_OffsetHeaderInfo / 2;
418 if (num * 2 > entry.MaxBufferBytes)
420 num = entry.MaxBufferBytes / 2;
422 while (*(ushort*)((
byte*)bufferPtr + (
long)(num - 1) * 2
L) == 0)
426 entry.MetaInfo =
Encoding.
Unicode.
GetString(buffer, (
int)bufferPtr->_OffsetHeaderInfo, (num - (
int)bufferPtr->_OffsetHeaderInfo / 2) * 2);
Represents a character encoding.To browse the .NET Framework source code for this type,...
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
The exception that is thrown when the execution stack overflows because it contains too many nested m...
static Encoding Unicode
Gets an encoding for the UTF-16 format using the little endian byte order.
Represents the base class for custom attributes.
LayoutKind
Controls the layout of an object when exported to unmanaged code.
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
For internal use only. The Framework will throw an T:System.ArgumentException if you try to use this ...
A platform-specific type that is used to represent a pointer or a handle.
The exception that is thrown when there is not enough memory to continue the execution of a program.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
CharSet
Dictates which character set marshaled strings should use.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static unsafe string PtrToStringUni(IntPtr ptr, int len)
Allocates a managed T:System.String and copies a specified number of characters from an unmanaged Uni...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Provides a set of properties and methods that are used to manage cookies. This class cannot be inheri...
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
The exception that is thrown when a call is made to the M:System.Threading.Thread....
Use T:System.Runtime.InteropServices.ComTypes.FILETIME instead.