Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corp.
  3. Module Name: urlcache.cxx
  4. Abstract:
  5. Urlcache API enhanced and optimized for internal use by wininet.
  6. Author:
  7. Rajeev Dujari (rajeevd) 10-Apr-97
  8. --*/
  9. #include <cache.hxx>
  10. DWORD
  11. UrlCacheRetrieve
  12. (
  13. IN LPSTR pszUrl,
  14. IN BOOL fOffline,
  15. OUT HANDLE* phStream,
  16. OUT CACHE_ENTRY_INFOEX** ppCEI
  17. )
  18. {
  19. BOOL fLocked = FALSE;
  20. HANDLE hStream = NULL;
  21. HANDLE hFile = INVALID_HANDLE_VALUE;
  22. DWORD dwErr;
  23. if (!InitGlobals())
  24. {
  25. INET_ASSERT(FALSE);
  26. return ERROR_INTERNET_INTERNAL_ERROR;
  27. }
  28. DWORD dwLookupFlags = fOffline? LOOKUP_URL_TRANSLATE
  29. : (LOOKUP_BIT_SPARSE | LOOKUP_URL_NOCREATE);
  30. DWORD cbCEI;
  31. // Find the container and search the index.
  32. dwErr = GlobalUrlContainers->RetrieveUrl(
  33. pszUrl,
  34. (CACHE_ENTRY_INFO **) ppCEI,
  35. &cbCEI,
  36. dwLookupFlags,
  37. RETRIEVE_WITHOUT_CHECKS | RETRIEVE_WITH_ALLOCATION);
  38. if (dwErr != ERROR_SUCCESS)
  39. goto Cleanup;
  40. fLocked = TRUE;
  41. if ((*ppCEI)->CacheEntryType & SPARSE_CACHE_ENTRY)
  42. {
  43. *phStream = NULL;
  44. }
  45. else
  46. {
  47. // Allocate a stream handle.
  48. CACHE_STREAM_CONTEXT_HANDLE* pStream;
  49. LOCK_CACHE();
  50. hStream = HandleMgr.Alloc (sizeof(CACHE_STREAM_CONTEXT_HANDLE));
  51. if (hStream)
  52. {
  53. pStream = (CACHE_STREAM_CONTEXT_HANDLE*) HandleMgr.Map (hStream);
  54. INET_ASSERT (pStream);
  55. }
  56. UNLOCK_CACHE();
  57. if (!hStream)
  58. {
  59. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  60. goto Cleanup;
  61. }
  62. // Open the file.
  63. hFile = CreateFile
  64. (
  65. (*ppCEI)->lpszLocalFileName,
  66. GENERIC_READ,
  67. FILE_SHARE_READ,
  68. NULL,
  69. OPEN_EXISTING,
  70. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  71. NULL
  72. );
  73. if( hFile == INVALID_HANDLE_VALUE )
  74. {
  75. dwErr = GetLastError();
  76. goto Cleanup;
  77. }
  78. DWORD dwFileSize = GetFileSize(hFile, NULL);
  79. if (dwFileSize != (*ppCEI)->dwSizeLow)
  80. {
  81. dwErr = (dwFileSize==0xFFFFFFFF) ? GetLastError() : ERROR_INVALID_DATA;
  82. goto Cleanup;
  83. }
  84. pStream->FileHandle = hFile;
  85. // Copy URL name storage.
  86. pStream->SourceUrlName = NewString(pszUrl);
  87. if( !pStream->SourceUrlName)
  88. {
  89. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  90. goto Cleanup;
  91. }
  92. *phStream = hStream;
  93. }
  94. dwErr = ERROR_SUCCESS;
  95. Cleanup:
  96. if( dwErr != ERROR_SUCCESS )
  97. {
  98. if (*ppCEI)
  99. {
  100. FREE_MEMORY (*ppCEI);
  101. *ppCEI = NULL;
  102. }
  103. if (hStream)
  104. HandleMgr.Free (hStream);
  105. if (hFile)
  106. CloseHandle (hFile);
  107. if (fLocked)
  108. GlobalUrlContainers->UnlockUrl(pszUrl);
  109. }
  110. return dwErr;
  111. }
  112. void UrlCacheFlush (void)
  113. {
  114. DWORD fPersist;
  115. REGISTRY_OBJ regCache (HKEY_CURRENT_USER, OLD_CACHE_KEY);
  116. if ( ERROR_SUCCESS == regCache.GetStatus()
  117. && ERROR_SUCCESS == regCache.GetValue (CACHE_PERSISTENT, &fPersist)
  118. && !fPersist
  119. )
  120. {
  121. FreeUrlCacheSpace (NULL, 100, STICKY_CACHE_ENTRY);
  122. }
  123. }
  124. DWORD UrlCacheCreateFile(LPCSTR szUrl, LPTSTR szExt, LPTSTR szFile, HANDLE *phfHandle, BOOL fCreatePerUser)
  125. {
  126. if (!InitGlobals())
  127. return ERROR_INTERNET_INTERNAL_ERROR;
  128. else
  129. return GlobalUrlContainers->CreateUniqueFile(szUrl, 0, szExt, szFile, phfHandle, fCreatePerUser);
  130. }
  131. DWORD UrlCacheCommitFile(AddUrlArg* pArgs)
  132. {
  133. if (!InitGlobals())
  134. return ERROR_INTERNET_INTERNAL_ERROR;
  135. else
  136. return GlobalUrlContainers->AddUrl(pArgs);
  137. }
  138. DWORD UrlCacheSendNotification(DWORD dwOp)
  139. {
  140. DWORD Error;
  141. // Initialize globals.
  142. if (!InitGlobals())
  143. {
  144. Error = ERROR_INTERNET_INTERNAL_ERROR;
  145. goto Cleanup;
  146. }
  147. Error = GlobalUrlContainers->SendCacheNotification(dwOp);
  148. Cleanup:
  149. return Error;
  150. }
  151. DWORD UrlCacheAddLeakFile (IN LPCSTR pszFile)
  152. {
  153. if (!InitGlobals())
  154. return ERROR_INTERNET_INTERNAL_ERROR;
  155. else
  156. return GlobalUrlContainers->AddLeakFile (pszFile);
  157. }