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.

1392 lines
34 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. cachapia.cxx
  5. Abstract:
  6. contains the ANSI version of cache mangemant APIs.
  7. Author:
  8. Madan Appiah (madana) 12-Dec-1994
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include <wininetp.h>
  14. #include <cache.hxx>
  15. /*-----------------------------------------------------------------------------
  16. CreateContainer
  17. ----------------------------------------------------------------------------*/
  18. URLCACHEAPI
  19. BOOL
  20. WINAPI
  21. CreateUrlCacheContainerA(
  22. IN LPCSTR Name,
  23. IN LPCSTR CachePrefix,
  24. IN LPCSTR CachePath,
  25. IN DWORD KBCacheLimit,
  26. IN DWORD dwContainerType,
  27. IN DWORD dwOptions,
  28. IN OUT LPVOID pvBuffer,
  29. IN OUT LPDWORD cbBuffer
  30. )
  31. {
  32. ENTER_CACHE_API ((DBG_API, Bool, "CreateUrlCacheContainerA", "%q, %q, %q, %d, %d, %d, %#x, %#x",
  33. Name, CachePrefix, CachePath, KBCacheLimit, dwContainerType, dwOptions, pvBuffer, cbBuffer));
  34. DWORD Error;
  35. // Initialize globals
  36. if (!InitGlobals())
  37. {
  38. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  39. goto Cleanup;
  40. }
  41. Error = GlobalUrlContainers->CreateContainer(
  42. Name,
  43. CachePrefix,
  44. CachePath,
  45. KBCacheLimit,
  46. dwOptions);
  47. LEAVE_CACHE_API();
  48. }
  49. URLCACHEAPI
  50. BOOL
  51. WINAPI
  52. DeleteUrlCacheContainerA(
  53. IN LPCSTR Name,
  54. IN DWORD dwOptions)
  55. {
  56. ENTER_CACHE_API ((DBG_API, Bool, "DeleteContainerA", "%q, %d", Name, dwOptions));
  57. DWORD Error;
  58. // Initialize globals
  59. if (!InitGlobals())
  60. {
  61. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  62. goto Cleanup;
  63. }
  64. Error = GlobalUrlContainers->DeleteContainer(
  65. Name,
  66. 0
  67. );
  68. LEAVE_CACHE_API();
  69. }
  70. URLCACHEAPI
  71. HANDLE
  72. WINAPI
  73. FindFirstUrlCacheContainerA(
  74. IN OUT LPDWORD pdwModified,
  75. OUT LPINTERNET_CACHE_CONTAINER_INFOA lpContainerInfo,
  76. IN OUT LPDWORD lpdwContainerInfoBufferSize,
  77. IN DWORD dwOptions
  78. )
  79. {
  80. ENTER_CACHE_API ((DBG_API, Bool, "FindFirstContainerA",
  81. "%#x, %#x, %#x, %#x",
  82. pdwModified,
  83. lpContainerInfo,
  84. lpdwContainerInfoBufferSize,
  85. dwOptions
  86. ));
  87. DWORD Error;
  88. HANDLE hFind = NULL;
  89. // Initialize globals.
  90. if (!InitGlobals())
  91. {
  92. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  93. goto Cleanup;
  94. }
  95. hFind = GlobalUrlContainers->FindFirstContainer(pdwModified,
  96. lpContainerInfo, lpdwContainerInfoBufferSize, dwOptions);
  97. if (hFind)
  98. Error = ERROR_SUCCESS;
  99. else
  100. {
  101. Error = GetLastError();
  102. // BUGBUG: Free hFind?
  103. // does the free take NULL?
  104. }
  105. Cleanup:
  106. if( Error != ERROR_SUCCESS )
  107. {
  108. SetLastError( Error );
  109. DEBUG_ERROR(API, Error);
  110. }
  111. DEBUG_LEAVE_API (hFind);
  112. return hFind;
  113. }
  114. URLCACHEAPI
  115. BOOL
  116. WINAPI
  117. FindNextUrlCacheContainerA(
  118. IN HANDLE hFind,
  119. OUT LPINTERNET_CACHE_CONTAINER_INFOA lpContainerInfo,
  120. IN OUT LPDWORD lpdwContainerInfoBufferSize
  121. )
  122. {
  123. ENTER_CACHE_API ((DBG_API, Bool, "FindNextContainerA",
  124. "%#x, %#x, %#x",
  125. hFind,
  126. lpContainerInfo,
  127. lpdwContainerInfoBufferSize
  128. ));
  129. DWORD Error;
  130. DWORD i;
  131. // Initialize globals.
  132. if (!InitGlobals())
  133. {
  134. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  135. goto Cleanup;
  136. }
  137. if (GlobalUrlContainers->FindNextContainer(hFind,
  138. lpContainerInfo, lpdwContainerInfoBufferSize))
  139. Error = ERROR_SUCCESS;
  140. else
  141. Error = GetLastError();
  142. LEAVE_CACHE_API();
  143. }
  144. URLCACHEAPI
  145. BOOL
  146. WINAPI
  147. CreateUrlCacheEntryA(
  148. IN LPCSTR lpszUrlName,
  149. IN DWORD dwExpectedFileSize,
  150. IN LPCSTR lpszFileExtension,
  151. OUT LPSTR lpszFileName,
  152. IN DWORD dwReserved
  153. )
  154. /*++
  155. Routine Description:
  156. This function creates a temperary file in the cache storage. This call
  157. is called by the application when it receives a url file from a
  158. server. When the receive is completed it caches this file to url cache
  159. management, which will move the file to permanent cache file. The idea
  160. is the cache file is written only once directly into the cache store.
  161. Arguments:
  162. lpszUrlName : name of the url file (unused now).
  163. lpszFileExtension: File extension for the saved data file
  164. dwExpectedFileSize : expected size of the incoming file. If it is unknown
  165. this value is set to null.
  166. lpszFileName : pointer to a buffer that receives the full path name of
  167. the the temp file.
  168. dwReserved : reserved for future use.
  169. Return Value:
  170. Windows Error Code.
  171. --*/
  172. {
  173. ENTER_CACHE_API ((DBG_API, Bool, "CreateUrlCacheEntryA", "%q, %q, %d, %q, %#x",
  174. lpszUrlName, lpszFileExtension, dwExpectedFileSize, lpszFileName, dwReserved));
  175. DWORD Error;
  176. //
  177. // validate parameters.
  178. //
  179. if( IsBadUrl( lpszUrlName ) || IsBadWriteFileName( lpszFileName ) ) {
  180. Error = ERROR_INVALID_PARAMETER;
  181. goto Cleanup;
  182. }
  183. // Initialize globals
  184. if (!InitGlobals())
  185. {
  186. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  187. goto Cleanup;
  188. }
  189. // Null first char in lpszFileName cues CreateUniqueFile
  190. // to generate a file name from scratch. Otherwise,
  191. // an attempt will be made to generate the filename
  192. // using the contents of the buffer.
  193. *lpszFileName = '\0';
  194. Error = GlobalUrlContainers->CreateUniqueFile(
  195. lpszUrlName,
  196. dwExpectedFileSize,
  197. lpszFileExtension,
  198. lpszFileName,
  199. NULL
  200. );
  201. LEAVE_CACHE_API();
  202. }
  203. URLCACHEAPI
  204. BOOL
  205. WINAPI
  206. CommitUrlCacheEntryA(
  207. IN LPCSTR lpszUrlName,
  208. IN LPCSTR lpszLocalFileName,
  209. IN FILETIME ExpireTime,
  210. IN FILETIME LastModifiedTime,
  211. IN DWORD CacheEntryType,
  212. IN LPBYTE lpHeaderInfo,
  213. IN DWORD dwHeaderSize,
  214. IN LPCSTR lpszFileExtension,
  215. IN LPCSTR lpszOriginalUrl
  216. )
  217. /*++
  218. Routine Description:
  219. This API caches a specified URL in the internet service cache
  220. storage. It creates a database entry of the URL info and moves the
  221. URL file to cache storage.
  222. Arguments:
  223. lpszUrlName : name of the URL that is cached.
  224. lpszLocalFileName : name of the local file where the URL data is
  225. stored. This file will be moved to an another file in cache storage, so
  226. this name is invalid after this api successfully returns. The
  227. name should include full path.
  228. ExpireTime : Expire time (GMT) of the file being cached. If it is
  229. unknown set it to zero.
  230. LastModifiedTime : Last modified time of this file. if this value is
  231. zero, current time is set as the last modified time.
  232. CacheEntryType : type of this new entry.
  233. lpHeaderInfo : if this pointer is non-NULL, it stores the HeaderInfo
  234. data as part of the URL entry in the memory mapped file, otherwise
  235. the app may store it else where. The size of the header info is
  236. specified by the HeaderSize parameter.
  237. dwHeaderSize : size of the header info associated with this URL, this
  238. can be non-zero even if the HeaderInfo specified above is NULL.
  239. lpszFileExtension : file extension used to create this file.
  240. dwReserved : reserved for future use.
  241. Return Value:
  242. Windows Error code.
  243. --*/
  244. {
  245. ENTER_CACHE_API ((DBG_API, Bool, "CommitUrlCacheEntryA",
  246. "%q, %q, <expires>, <last-mod>, %d, %#x, %d, %q, %q",
  247. lpszUrlName,
  248. lpszLocalFileName,
  249. CacheEntryType,
  250. lpHeaderInfo,
  251. dwHeaderSize,
  252. lpszFileExtension,
  253. lpszOriginalUrl
  254. ));
  255. DWORD Error;
  256. // validate parameters.
  257. if( IsBadUrl( lpszUrlName ) ||
  258. ( lpszLocalFileName ? IsBadReadFileName( lpszLocalFileName ) : FALSE ) )
  259. {
  260. Error = ERROR_INVALID_PARAMETER;
  261. goto Cleanup;
  262. }
  263. if( lpHeaderInfo != NULL )
  264. {
  265. if( IsBadReadPtr(lpHeaderInfo, dwHeaderSize) )
  266. {
  267. Error = ERROR_INVALID_PARAMETER;
  268. goto Cleanup;
  269. }
  270. }
  271. if( lpszFileExtension != NULL )
  272. {
  273. if( IsBadReadPtr(lpszFileExtension, 3) )
  274. {
  275. Error = ERROR_INVALID_PARAMETER;
  276. goto Cleanup;
  277. }
  278. }
  279. FILETIME ftPostCheck;
  280. ftPostCheck.dwLowDateTime = 0;
  281. ftPostCheck.dwHighDateTime = 0;
  282. // Record args in structure.
  283. AddUrlArg Args;
  284. memset(&Args, 0, sizeof(Args));
  285. Args.pszUrl = lpszUrlName;
  286. Args.pszFilePath = lpszLocalFileName;
  287. Args.dwFileSize = 0;
  288. Args.qwExpires = FT2LL(ExpireTime);
  289. Args.qwLastMod = FT2LL(LastModifiedTime);
  290. Args.qwPostCheck = FT2LL(ftPostCheck);
  291. Args.ftCreate = LastModifiedTime;
  292. Args.dwEntryType = CacheEntryType;
  293. Args.pbHeaders = (LPSTR)lpHeaderInfo;
  294. Args.cbHeaders = dwHeaderSize;
  295. Args.pszFileExt = lpszFileExtension;
  296. Args.pszRedirect = lpszOriginalUrl ? (LPSTR) lpszOriginalUrl : NULL;
  297. Args.fImage = FALSE;
  298. Error = UrlCacheCommitFile(&Args);
  299. LEAVE_CACHE_API();
  300. }
  301. URLCACHEAPI
  302. BOOL
  303. WINAPI
  304. RetrieveUrlCacheEntryFileA(
  305. IN LPCSTR lpszUrlName,
  306. OUT LPCACHE_ENTRY_INFOA lpCacheEntryInfo,
  307. IN OUT LPDWORD lpdwCacheEntryInfoBufferSize,
  308. IN DWORD dwReserved
  309. )
  310. /*++
  311. Routine Description:
  312. This API retrieves the specified URL file. When the file is retrieved
  313. it also checked out to the user to use. The user has to call
  314. UnlockUrlFile when he/she finished using it.
  315. Arguments:
  316. lpszUrlName : name of the URL that is being retrieved.
  317. lpCacheEntryInfo : pointer to the url info structure that receives the url
  318. info.
  319. lpdwCacheEntryInfoBufferSize : pointer to a location where length of
  320. the above buffer is passed in. On return, this contains the length
  321. of the above buffer that is fulled in.
  322. dwReserved : reserved for future use.
  323. Return Value:
  324. Windows Error code.
  325. --*/
  326. {
  327. ENTER_CACHE_API ((DBG_API, Bool, "RetrieveUrlCacheEntryFileA","%q, %#x, %#x, %#x",
  328. lpszUrlName, lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize, dwReserved));
  329. DWORD Error;
  330. // validate parameters.
  331. if( IsBadUrl( lpszUrlName ) ||
  332. IsBadWriteUrlInfo(
  333. lpCacheEntryInfo,
  334. *lpdwCacheEntryInfoBufferSize) ) {
  335. Error = ERROR_INVALID_PARAMETER;
  336. goto Cleanup;
  337. }
  338. if (!InitGlobals())
  339. {
  340. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  341. goto Cleanup;
  342. }
  343. Error = GlobalUrlContainers->RetrieveUrl(
  344. lpszUrlName,
  345. (lpCacheEntryInfo ? &lpCacheEntryInfo : NULL),
  346. lpdwCacheEntryInfoBufferSize,
  347. LOOKUP_URL_CREATE,
  348. RETRIEVE_WITH_CHECKS);
  349. LEAVE_CACHE_API();
  350. }
  351. URLCACHEAPI
  352. HANDLE
  353. WINAPI
  354. RetrieveUrlCacheEntryStreamA(
  355. IN LPCSTR lpszUrlName,
  356. OUT LPCACHE_ENTRY_INFOA lpCacheEntryInfo,
  357. IN OUT LPDWORD lpdwCacheEntryInfoBufferSize,
  358. IN BOOL fRandomRead,
  359. IN DWORD dwReserved
  360. )
  361. /*++
  362. Routine Description:
  363. This API retrieves the specified URL file. When the file is retrieved
  364. it also checked out to the user to use. The user has to call
  365. UnlockUrlFile when he/she finished using it.
  366. Arguments:
  367. lpszUrlName : name of the URL that is being retrieved.
  368. lpCacheEntryInfo : pointer to the url info structure that receives the url
  369. info.
  370. lpdwCacheEntryInfoBufferSize : pointer to a location where length of
  371. the above buffer is passed in. On return, this contains the length
  372. of the above buffer that is fulled in.
  373. fRandomRead : if this flag is set to TRUE, then stream is open for
  374. random access.
  375. dwReserved: must pass 0
  376. Return Value:
  377. Windows Error code.
  378. --*/
  379. {
  380. ENTER_CACHE_API ((DBG_API, Handle, "RetrieveUrlCacheEntryStreamA",
  381. "%q, %#x, %#x, %d, %#x",
  382. lpszUrlName,
  383. lpCacheEntryInfo,
  384. lpdwCacheEntryInfoBufferSize,
  385. fRandomRead,
  386. dwReserved
  387. ));
  388. BOOL fLocked = FALSE;
  389. HANDLE hStream = NULL;
  390. HANDLE hFile = INVALID_HANDLE_VALUE;
  391. DWORD Error, dwFileSize;
  392. // Validate parameters.
  393. if( IsBadUrl( lpszUrlName )
  394. || IsBadWriteUrlInfo(lpCacheEntryInfo, *lpdwCacheEntryInfoBufferSize))
  395. {
  396. Error = ERROR_INVALID_PARAMETER;
  397. goto Cleanup;
  398. }
  399. // Initialize globals.
  400. if (!InitGlobals())
  401. {
  402. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  403. goto Cleanup;
  404. }
  405. Error = GlobalUrlContainers->RetrieveUrl
  406. (lpszUrlName, &lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize,
  407. LOOKUP_URL_NOCREATE, RETRIEVE_WITHOUT_CHECKS);
  408. if( Error != ERROR_SUCCESS )
  409. goto Cleanup;
  410. fLocked = TRUE;
  411. // Allocate a stream handle.
  412. CACHE_STREAM_CONTEXT_HANDLE* pStream;
  413. LOCK_CACHE();
  414. hStream = HandleMgr.Alloc (sizeof(CACHE_STREAM_CONTEXT_HANDLE));
  415. if (hStream)
  416. {
  417. pStream = (CACHE_STREAM_CONTEXT_HANDLE*) HandleMgr.Map (hStream);
  418. INET_ASSERT (pStream);
  419. }
  420. UNLOCK_CACHE();
  421. if (!hStream)
  422. {
  423. Error = ERROR_NOT_ENOUGH_MEMORY;
  424. goto Cleanup;
  425. }
  426. // Open the file.
  427. hFile = CreateFile
  428. (
  429. lpCacheEntryInfo->lpszLocalFileName,
  430. GENERIC_READ,
  431. FILE_SHARE_READ,
  432. NULL,
  433. OPEN_EXISTING,
  434. FILE_ATTRIBUTE_NORMAL |
  435. (fRandomRead ? FILE_FLAG_RANDOM_ACCESS : FILE_FLAG_SEQUENTIAL_SCAN),
  436. // improves file read (cache) performance?
  437. NULL
  438. );
  439. if( hFile == INVALID_HANDLE_VALUE )
  440. {
  441. Error = GetLastError();
  442. goto Cleanup;
  443. }
  444. dwFileSize = GetFileSize(hFile, NULL);
  445. if (dwFileSize != lpCacheEntryInfo->dwSizeLow)
  446. {
  447. Error = (dwFileSize==0xFFFFFFFF) ? GetLastError() : ERROR_INVALID_DATA;
  448. goto Cleanup;
  449. }
  450. pStream->FileHandle = hFile;
  451. // Copy URL name storage.
  452. pStream->SourceUrlName = NewString(lpszUrlName);
  453. if( !pStream->SourceUrlName)
  454. {
  455. Error = ERROR_NOT_ENOUGH_MEMORY;
  456. goto Cleanup;
  457. }
  458. Error = ERROR_SUCCESS;
  459. Cleanup:
  460. if( Error != ERROR_SUCCESS )
  461. {
  462. if (hStream)
  463. {
  464. HandleMgr.Free (hStream);
  465. hStream = NULL;
  466. }
  467. if (hFile)
  468. CloseHandle (hFile);
  469. if (fLocked)
  470. GlobalUrlContainers->UnlockUrl(lpszUrlName);
  471. SetLastError (Error);
  472. DEBUG_ERROR(API, Error);
  473. }
  474. DEBUG_LEAVE_API (hStream);
  475. return hStream;
  476. }
  477. URLCACHEAPI
  478. BOOL
  479. WINAPI
  480. GetUrlCacheEntryInfoA(
  481. IN LPCSTR lpszUrlName,
  482. OUT LPCACHE_ENTRY_INFOA lpCacheEntryInfo,
  483. IN OUT LPDWORD lpdwCacheEntryInfoBufferSize
  484. )
  485. /*++
  486. Routine Description:
  487. This function retrieves the specified cache entry info.
  488. Arguments:
  489. lpszUrlName : name of the url file (unused now).
  490. lpCacheEntryInfo : pointer to the url info structure that receives the url
  491. info.
  492. lpdwCacheEntryInfoBufferSize : pointer to a location where length of
  493. the above buffer is passed in. On return, this contains the length
  494. of the above buffer that is fulled in.
  495. Return Value:
  496. Windows Error Code.
  497. --*/
  498. {
  499. ENTER_CACHE_API ((DBG_API, Bool, "GetUrlCacheEntryInfoA", "%q, %#x, %#x",
  500. lpszUrlName, lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize));
  501. DWORD Error;
  502. // Validate parameters.
  503. if( IsBadUrl( lpszUrlName ) ||
  504. (lpCacheEntryInfo && !lpdwCacheEntryInfoBufferSize) ||
  505. (lpCacheEntryInfo && lpdwCacheEntryInfoBufferSize && IsBadWriteUrlInfo(
  506. lpCacheEntryInfo,
  507. *lpdwCacheEntryInfoBufferSize) ) )
  508. {
  509. Error = ERROR_INVALID_PARAMETER;
  510. goto Cleanup;
  511. }
  512. // Initialize globals.
  513. if (!InitGlobals())
  514. {
  515. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  516. goto Cleanup;
  517. }
  518. Error = GlobalUrlContainers->GetUrlInfo(
  519. lpszUrlName,
  520. lpCacheEntryInfo,
  521. lpdwCacheEntryInfoBufferSize,
  522. LOOKUP_URL_NOCREATE,
  523. 0);
  524. LEAVE_CACHE_API();
  525. }
  526. BOOLAPI
  527. GetUrlCacheEntryInfoExA(
  528. IN LPCSTR lpszUrl,
  529. OUT LPINTERNET_CACHE_ENTRY_INFOA lpCEI,
  530. IN OUT LPDWORD lpcbCEI,
  531. OUT LPSTR lpszOut,
  532. IN OUT LPDWORD lpcbOut,
  533. LPVOID lpReserved,
  534. DWORD dwFlags
  535. )
  536. {
  537. ENTER_CACHE_API ((DBG_API, Bool, "GetUrlCacheEntryInfoExA",
  538. "%q, %#x, %#x, %#x, %#x, %#x, %#x", lpszUrl, lpCEI, lpcbCEI, lpszOut, lpcbOut, lpReserved, dwFlags));
  539. DWORD Error;
  540. // Validate parameters
  541. // NOTE: once the following params change, edit GetUrlCacheEntryInfoExW accordingly.
  542. if ( IsBadUrl(lpszUrl)
  543. || lpszOut
  544. || lpcbOut
  545. || lpReserved
  546. )
  547. {
  548. INET_ASSERT (FALSE);
  549. Error = ERROR_INVALID_PARAMETER;
  550. goto Cleanup;
  551. }
  552. // Initialize globals.
  553. if (!InitGlobals())
  554. {
  555. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  556. goto Cleanup;
  557. }
  558. // We allow mixing of INTERNET_CACHE_FLAG_ALLOW_COLLISIONS with lookup flags
  559. Error = GlobalUrlContainers->GetUrlInfo
  560. (lpszUrl, lpCEI, lpcbCEI, LOOKUP_URL_TRANSLATE | (dwFlags & INTERNET_CACHE_FLAG_ALLOW_COLLISIONS), dwFlags);
  561. LEAVE_CACHE_API();
  562. }
  563. URLCACHEAPI
  564. BOOL
  565. WINAPI
  566. SetUrlCacheEntryInfoA(
  567. IN LPCSTR lpszUrlName,
  568. IN LPCACHE_ENTRY_INFOA lpCacheEntryInfo,
  569. IN DWORD dwFieldControl
  570. )
  571. /*++
  572. Routine Description:
  573. This function sets the specified fields of the cache entry info.
  574. Arguments:
  575. lpszUrlName : name of the url file (unused now).
  576. lpCacheEntryInfo : pointer to the url info structure that has the url info to
  577. be set.
  578. dwFieldControl : Bitmask that specifies the fields to be set.
  579. Return Value:
  580. Windows Error Code.
  581. --*/
  582. {
  583. ENTER_CACHE_API ((DBG_API, Bool, "SetUrlCacheEntryInfoA", "%q, %#x, %d",
  584. lpszUrlName, lpCacheEntryInfo, dwFieldControl));
  585. DWORD Error;
  586. //
  587. // validate parameters.
  588. //
  589. if( IsBadUrl( lpszUrlName ) ||
  590. IsBadReadUrlInfo( lpCacheEntryInfo )) {
  591. Error = ERROR_INVALID_PARAMETER;
  592. goto Cleanup;
  593. }
  594. // Initialize globals.
  595. if (!InitGlobals())
  596. {
  597. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  598. goto Cleanup;
  599. }
  600. Error = GlobalUrlContainers->SetUrlInfo(
  601. lpszUrlName,
  602. lpCacheEntryInfo,
  603. dwFieldControl );
  604. LEAVE_CACHE_API();
  605. }
  606. URLCACHEAPI
  607. HANDLE
  608. WINAPI
  609. FindFirstUrlCacheEntryA(
  610. IN LPCSTR lpszUrlSearchPattern,
  611. OUT LPCACHE_ENTRY_INFOA lpFirstCacheEntryInfo,
  612. IN OUT LPDWORD lpdwFirstCacheEntryInfoBufferSize
  613. )
  614. /*++
  615. Routine Description:
  616. This member function starts the cache entries enumeration and returns
  617. the first entry in the cache.
  618. Arguments:
  619. lpszUrlSearchPattern : pointer to a search pattern string. Currently
  620. it is not implemented.
  621. lpFirstCacheEntryInfo : pointer to a cache entry info structure.
  622. Return Value:
  623. Returns the find first handle. If the returned handle is NULL,
  624. GetLastError() returns the extended error code.
  625. --*/
  626. {
  627. ENTER_CACHE_API ((DBG_API, Bool, "FindFirstUrlCacheEntryA",
  628. "%q, %#x, %#x",
  629. lpszUrlSearchPattern,
  630. lpFirstCacheEntryInfo,
  631. lpdwFirstCacheEntryInfoBufferSize
  632. ));
  633. DWORD Error;
  634. HANDLE hFind = 0;
  635. // Validate parameters.
  636. if (IsBadWriteUrlInfo(lpFirstCacheEntryInfo,
  637. *lpdwFirstCacheEntryInfoBufferSize))
  638. {
  639. Error = ERROR_INVALID_PARAMETER;
  640. goto Cleanup;
  641. }
  642. // Initialize globals.
  643. if (!InitGlobals())
  644. {
  645. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  646. goto Cleanup;
  647. }
  648. // Get the first entry.
  649. Error = GlobalUrlContainers->FindNextEntry(&hFind,
  650. lpszUrlSearchPattern,
  651. lpFirstCacheEntryInfo,
  652. lpdwFirstCacheEntryInfoBufferSize,
  653. URLCACHE_FIND_DEFAULT_FILTER,
  654. NULL,
  655. FIND_FLAGS_OLD_SEMANTICS);
  656. Cleanup:
  657. if( Error != ERROR_SUCCESS )
  658. {
  659. GlobalUrlContainers->FreeFindHandle(hFind);
  660. hFind = NULL;
  661. SetLastError(Error);
  662. DEBUG_ERROR(API, Error);
  663. }
  664. DEBUG_LEAVE_API (hFind);
  665. return hFind;
  666. }
  667. URLCACHEAPI
  668. BOOL
  669. WINAPI
  670. FindNextUrlCacheEntryA(
  671. IN HANDLE hFind,
  672. OUT LPCACHE_ENTRY_INFOA lpNextCacheEntryInfo,
  673. IN OUT LPDWORD lpdwNextCacheEntryInfoBufferSize
  674. )
  675. /*++
  676. Routine Description:
  677. This member function returns the next entry in the cache.
  678. Arguments:
  679. hEnumHandle : Find First handle.
  680. lpFirstCacheEntryInfo : pointer to a cache entry info structure.
  681. Return Value:
  682. Returns the find first handle. If the returned handle is NULL,
  683. GetLastError() returns the extended error code. It returns
  684. ERROR_NO_MORE_ITEMS after it returns the last entry in the cache.
  685. --*/
  686. {
  687. ENTER_CACHE_API ((DBG_API, Bool, "FindNextUrlCacheEntryA",
  688. "%#x, %#x, %#x",
  689. hFind,
  690. lpNextCacheEntryInfo,
  691. lpdwNextCacheEntryInfoBufferSize
  692. ));
  693. DWORD Error = ERROR_SUCCESS;
  694. CACHE_FIND_FIRST_HANDLE* pFind;
  695. // Validate parameters.
  696. if (!hFind || IsBadWriteUrlInfo(lpNextCacheEntryInfo,
  697. *lpdwNextCacheEntryInfoBufferSize))
  698. {
  699. Error = ERROR_INVALID_PARAMETER;
  700. goto Cleanup;
  701. }
  702. // Initialize globals.
  703. if (!InitGlobals())
  704. {
  705. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  706. goto Cleanup;
  707. }
  708. // Get the next entry.
  709. Error = GlobalUrlContainers->FindNextEntry(&hFind,
  710. NULL,
  711. lpNextCacheEntryInfo,
  712. lpdwNextCacheEntryInfoBufferSize,
  713. URLCACHE_FIND_DEFAULT_FILTER,
  714. NULL,
  715. FIND_FLAGS_OLD_SEMANTICS);
  716. Cleanup:
  717. if (Error!=ERROR_SUCCESS)
  718. {
  719. SetLastError(Error);
  720. DEBUG_ERROR(INET, Error);
  721. }
  722. DEBUG_LEAVE_API(Error==ERROR_SUCCESS);
  723. return (Error == ERROR_SUCCESS );
  724. }
  725. INTERNETAPI
  726. HANDLE
  727. WINAPI
  728. FindFirstUrlCacheEntryExA(
  729. IN LPCSTR lpszUrlSearchPattern,
  730. IN DWORD dwFlags,
  731. IN DWORD dwFilter,
  732. IN GROUPID GroupId,
  733. OUT LPINTERNET_CACHE_ENTRY_INFOA pEntryInfo,
  734. IN OUT LPDWORD pcbEntryInfo,
  735. OUT LPVOID lpGroupAttributes, // must pass NULL
  736. IN OUT LPDWORD pcbGroupAttributes, // must pass NULL
  737. IN LPVOID lpReserved // must pass NULL
  738. )
  739. {
  740. ENTER_CACHE_API ((DBG_API, Bool, "FindFirstUrlCacheEntryExA",
  741. "%q, %#x, %#x, %#x, %#x, %#x, %#x, %#x, %#x",
  742. lpszUrlSearchPattern,
  743. dwFlags,
  744. dwFilter,
  745. GroupId,
  746. pEntryInfo,
  747. pcbEntryInfo,
  748. lpGroupAttributes,
  749. pcbGroupAttributes,
  750. lpReserved
  751. ));
  752. DWORD Error;
  753. HANDLE hFind = NULL;
  754. // Validate parameters.
  755. if (IsBadWritePtr (pcbEntryInfo, sizeof(DWORD)))
  756. {
  757. Error = ERROR_INVALID_PARAMETER;
  758. goto Cleanup;
  759. }
  760. // Initialize globals.
  761. if (!InitGlobals())
  762. {
  763. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  764. goto Cleanup;
  765. }
  766. // Get the first entry.
  767. Error = GlobalUrlContainers->FindNextEntry(&hFind,
  768. lpszUrlSearchPattern,
  769. pEntryInfo,
  770. pcbEntryInfo,
  771. dwFilter,
  772. GroupId,
  773. dwFlags);
  774. Cleanup:
  775. if( Error != ERROR_SUCCESS )
  776. {
  777. if (hFind)
  778. {
  779. GlobalUrlContainers->FreeFindHandle(hFind);
  780. hFind = NULL;
  781. }
  782. SetLastError(Error);
  783. DEBUG_ERROR(API, Error);
  784. }
  785. DEBUG_LEAVE_API (hFind);
  786. return hFind;
  787. }
  788. BOOLAPI
  789. FindNextUrlCacheEntryExA(
  790. IN HANDLE hFind,
  791. OUT LPINTERNET_CACHE_ENTRY_INFOA pEntryInfo,
  792. IN OUT LPDWORD pcbEntryInfo,
  793. OUT LPVOID lpGroupAttributes, // must pass NULL
  794. IN OUT LPDWORD pcbGroupAttributes, // must pass NULL
  795. IN LPVOID lpReserved // must pass NULL
  796. )
  797. {
  798. ENTER_CACHE_API ((DBG_API, Bool, "FindNextUrlCacheEntryExA",
  799. "%#x, %#x, %#x, %#x, %#x, %#x",
  800. hFind,
  801. pEntryInfo,
  802. pcbEntryInfo,
  803. lpGroupAttributes,
  804. pcbGroupAttributes,
  805. lpReserved
  806. ));
  807. DWORD Error;
  808. // Validate parameters.
  809. if (!hFind || IsBadWritePtr (pcbEntryInfo, sizeof(DWORD)))
  810. {
  811. Error = ERROR_INVALID_PARAMETER;
  812. goto Cleanup;
  813. }
  814. // Initialize globals.
  815. if (!InitGlobals())
  816. {
  817. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  818. goto Cleanup;
  819. }
  820. // Get the next entry.
  821. Error = GlobalUrlContainers->FindNextEntry(&hFind,
  822. NULL,
  823. pEntryInfo,
  824. pcbEntryInfo,
  825. NULL,
  826. NULL,
  827. NULL);
  828. LEAVE_CACHE_API();
  829. }
  830. URLCACHEAPI
  831. BOOL
  832. WINAPI
  833. FreeUrlCacheSpaceA(
  834. IN LPCSTR lpszCachePath,
  835. IN DWORD dwFactor,
  836. IN DWORD dwFilter
  837. )
  838. /*++
  839. Routine Description:
  840. This function cleans up the cache entries in the specified ccahe
  841. path to make space for future cache entries.
  842. Arguments:
  843. dwFactor: % of free space
  844. Return Value:
  845. TRUE if the cleanup is successful. Otherwise FALSE, GetLastError()
  846. returns the extended error.
  847. --*/
  848. {
  849. DWORD Error;
  850. ENTER_CACHE_API ((DBG_API, Bool, "FreeUrlCacheSpace",
  851. "<path>,%d, %#x", dwFactor, dwFilter));
  852. // Initialize globals.
  853. if (!InitGlobals())
  854. {
  855. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  856. goto Cleanup;
  857. }
  858. Error = GlobalUrlContainers->CleanupUrls(lpszCachePath, dwFactor, dwFilter);
  859. LEAVE_CACHE_API();
  860. }
  861. URLCACHEAPI
  862. BOOL
  863. WINAPI
  864. UnlockUrlCacheEntryFileA(
  865. LPCSTR lpszUrlName,
  866. IN DWORD dwReserved
  867. )
  868. /*++
  869. Routine Description:
  870. This API checks in the file that was check out as part of
  871. RetrieveUrlFile API.
  872. Arguments:
  873. lpszUrlName : name of the URL that is being retrieved.
  874. dwReserved : reserved for future use.
  875. Return Value:
  876. Windows Error code.
  877. --*/
  878. {
  879. DWORD Error;
  880. DWORD i;
  881. ENTER_CACHE_API ((DBG_API, Bool, "UnlockUrlCacheEntryFile",
  882. "%q, %#x", lpszUrlName, dwReserved));
  883. // validate parameters.
  884. if( IsBadUrl( lpszUrlName ) ) {
  885. Error = ERROR_INVALID_PARAMETER;
  886. goto Cleanup;
  887. }
  888. // Initialize globals
  889. if (!InitGlobals())
  890. {
  891. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  892. goto Cleanup;
  893. }
  894. Error = GlobalUrlContainers->UnlockUrl(lpszUrlName);
  895. LEAVE_CACHE_API();
  896. }
  897. URLCACHEAPI
  898. BOOL
  899. WINAPI
  900. DeleteUrlCacheEntryA(
  901. IN LPCSTR lpszUrlName
  902. )
  903. {
  904. ENTER_CACHE_API ((DBG_API, Bool, "DeleteUrlCacheEntry",
  905. "%q", lpszUrlName));
  906. DWORD Error;
  907. // Validate parameters.
  908. if( IsBadUrl( lpszUrlName ) ) {
  909. Error = ERROR_INVALID_PARAMETER;
  910. goto Cleanup;
  911. }
  912. // Initialize globals
  913. if (!InitGlobals())
  914. {
  915. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  916. goto Cleanup;
  917. }
  918. Error = GlobalUrlContainers->DeleteUrl(lpszUrlName);
  919. LEAVE_CACHE_API();
  920. }
  921. #ifdef __URLCACHE_JUNK__
  922. BOOLAPI
  923. SetUrlCacheEntryGroupA(
  924. IN LPCSTR lpszUrlName,
  925. IN DWORD dwFlags,
  926. IN GROUPID GroupId,
  927. IN LPBYTE pbGroupAttributes, // must pass NULL
  928. IN DWORD cbGroupAttributes, // must pass 0
  929. IN LPVOID lpReserved // must pass NULL
  930. )
  931. {
  932. ENTER_CACHE_API ((DBG_API, Bool, "SetUrlCacheEntryGroupA",
  933. "%q, %#x, %#x, %#x, %#x, %#x", lpszUrlName, dwFlags, GroupId, pbGroupAttributes, cbGroupAttributes, lpReserved));
  934. DWORD Error;
  935. // Validate parameters.
  936. if (IsBadUrl(lpszUrlName)
  937. || !GroupId
  938. || pbGroupAttributes
  939. || cbGroupAttributes
  940. || lpReserved
  941. )
  942. {
  943. Error = ERROR_INVALID_PARAMETER;
  944. goto Cleanup;
  945. }
  946. // Initialize globals
  947. if (!InitGlobals())
  948. {
  949. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  950. goto Cleanup;
  951. }
  952. Error = GlobalUrlContainers->SetUrlGroup (lpszUrlName, dwFlags, GroupId);
  953. LEAVE_CACHE_API();
  954. }
  955. URLCACHEAPI
  956. BOOL
  957. WINAPI
  958. GetUrlCacheGroupAttributeA(
  959. IN GROUPID gid,
  960. IN DWORD dwFlags,
  961. IN DWORD dwAttributes,
  962. OUT LPINTERNET_CACHE_GROUP_INFOA lpGroupInfo,
  963. IN OUT LPDWORD lpdwGroupInfo,
  964. IN OUT LPVOID lpReserved
  965. )
  966. {
  967. ENTER_CACHE_API ((DBG_API, Bool, "GetUrlCacheGroupAttributeA",
  968. "%#x, %d, %d, %#x, %#x, %#x",
  969. gid, dwFlags, dwAttributes, lpGroupInfo, lpdwGroupInfo, lpReserved ));
  970. DWORD Error;
  971. // Validate parameters.
  972. if( !lpGroupInfo ||
  973. !lpdwGroupInfo ||
  974. IsBadWriteUrlInfo(lpGroupInfo, *lpdwGroupInfo) )
  975. {
  976. Error = ERROR_INVALID_PARAMETER;
  977. goto Cleanup;
  978. }
  979. if( *lpdwGroupInfo < sizeof(INTERNET_CACHE_GROUP_INFOA) )
  980. {
  981. Error = ERROR_INSUFFICIENT_BUFFER;
  982. goto Cleanup;
  983. }
  984. // Initialize globals.
  985. if (!InitGlobals())
  986. {
  987. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  988. goto Cleanup;
  989. }
  990. Error = GlobalUrlContainers->GetGroupAttributes(
  991. gid,
  992. dwAttributes,
  993. lpGroupInfo,
  994. lpdwGroupInfo );
  995. LEAVE_CACHE_API();
  996. }
  997. URLCACHEAPI
  998. BOOL
  999. WINAPI
  1000. SetUrlCacheGroupAttributeA(
  1001. IN GROUPID gid,
  1002. IN DWORD dwFlags,
  1003. IN DWORD dwAttributes,
  1004. IN LPINTERNET_CACHE_GROUP_INFOA lpGroupInfo,
  1005. IN OUT LPVOID lpReserved
  1006. )
  1007. {
  1008. ENTER_CACHE_API ((DBG_API, Bool, "SetUrlCacheGroupAttributeA",
  1009. "%#x, %d, %d, %#x, %#x",
  1010. gid, dwFlags, dwAttributes, lpGroupInfo, lpReserved));
  1011. DWORD Error;
  1012. // validate parameters.
  1013. if( IsBadReadPtr(lpGroupInfo, sizeof(INTERNET_CACHE_GROUP_INFOA) ) )
  1014. {
  1015. Error = ERROR_INVALID_PARAMETER;
  1016. goto Cleanup;
  1017. }
  1018. // Initialize globals.
  1019. if (!InitGlobals())
  1020. {
  1021. Error = ERROR_WINHTTP_INTERNAL_ERROR;
  1022. goto Cleanup;
  1023. }
  1024. Error = GlobalUrlContainers->SetGroupAttributes(
  1025. gid, dwAttributes, lpGroupInfo);
  1026. LEAVE_CACHE_API();
  1027. }
  1028. #endif // __URLCACHE_JUNK__
  1029. // This function will be removed from the export table
  1030. BOOLAPI
  1031. IsUrlCacheEntryExpiredA(
  1032. IN LPCSTR lpszUrlName,
  1033. IN DWORD dwFlags,
  1034. IN OUT FILETIME* pftLastModifiedTime
  1035. )
  1036. {
  1037. return FALSE;
  1038. }
  1039. /*
  1040. BOOL bRet = TRUE;
  1041. CACHE_ENTRY_INFOEX* pCEI = NULL;
  1042. DWORD cbCEI;
  1043. DWORD dwError;
  1044. BOOL bLazy = FALSE;
  1045. BOOL fLocked = FALSE;
  1046. // Validate parameters.
  1047. if( IsBadUrl( lpszUrlName ) || !pftLastModifiedTime ) {
  1048. INET_ASSERT(FALSE);
  1049. return ERROR_INVALID_PARAMETER;
  1050. }
  1051. // set out LastModTime to 0
  1052. pftLastModifiedTime->dwLowDateTime = 0 ;
  1053. pftLastModifiedTime->dwHighDateTime = 0 ;
  1054. if (!InitGlobals())
  1055. {
  1056. INET_ASSERT(FALSE);
  1057. return ERROR_WINHTTP_INTERNAL_ERROR;
  1058. }
  1059. //
  1060. // BUGBUG
  1061. // ideally, we should use GlobalUrlContainers->GetUrlInfo()
  1062. // with NO_ALLOCATION and HEADONLY flag for perf.
  1063. // however, there is a flag (lookup flag v.s entry flag) collision
  1064. // in that code path which prevents this working
  1065. // so we use this anti-perf RetrieveUrl for now until that one
  1066. // gets fixed
  1067. // --DanpoZ, 98.09.09
  1068. // Find the container and search the index.
  1069. dwError = GlobalUrlContainers->RetrieveUrl(
  1070. lpszUrlName,
  1071. (CACHE_ENTRY_INFO**) &pCEI,
  1072. &cbCEI,
  1073. (dwFlags & INTERNET_FLAG_FWD_BACK)?
  1074. LOOKUP_URL_TRANSLATE : LOOKUP_URL_NOCREATE,
  1075. RETRIEVE_WITHOUT_CHECKS | RETRIEVE_WITH_ALLOCATION);
  1076. // not found in cache
  1077. if( dwError != ERROR_SUCCESS )
  1078. goto Cleanup;
  1079. fLocked = TRUE;
  1080. // found in cache, get the last modified time
  1081. *pftLastModifiedTime = pCEI->LastModifiedTime;
  1082. bRet = IsExpired(pCEI, dwFlags, &bLazy);
  1083. if( bRet && bLazy )
  1084. {
  1085. //
  1086. // the entry is not expired, however, we need to post-fetch
  1087. // so we have to return EXPIRED back to trident to force them
  1088. // issue a binding, on the new binding, urlmon-wininet returns
  1089. // the cache content and queue a background update
  1090. // (an alternative would be to ask trident to catch this case
  1091. // and call background update themself)
  1092. //
  1093. bRet = FALSE;
  1094. }
  1095. Cleanup:
  1096. if( pCEI )
  1097. FREE_MEMORY(pCEI);
  1098. if (fLocked)
  1099. GlobalUrlContainers->UnlockUrl(lpszUrlName);
  1100. return bRet;
  1101. }
  1102. */