Source code of Windows XP (NT5)
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.

2723 lines
75 KiB

  1. //
  2. // Copyright (c) 1996 Microsoft Corporation
  3. //
  4. // Module Name: Url History Interfaces
  5. //
  6. // Author:
  7. // Zeke Lucas (zekel) 10-April-96
  8. //
  9. // !!! Take NOTE: CUrlHistory *MUST* be thread safe! DANGER, WILL ROBINSON, DANGER!
  10. #include "priv.h"
  11. #include "sccls.h"
  12. #include "ishcut.h"
  13. #include <inetreg.h>
  14. #include <varutil.h>
  15. #include "iface.h"
  16. #include "util.h"
  17. #define DM_UHRETRIEVE 0
  18. #define DM_URLCLEANUP 0
  19. #define DM_HISTGENERATE 0
  20. #define DM_HISTPROP 0
  21. #define DM_HISTEXTRA 0
  22. #define DM_HISTCOMMIT 0
  23. #define DM_HISTSPLAT 0
  24. #define DM_HISTMISS 0
  25. #define DM_HISTNLS 0
  26. #define DW_FOREVERLOW (0xFFFFFFFF)
  27. #define DW_FOREVERHIGH (0x7FFFFFFF)
  28. #ifdef UNICODE
  29. #define VT_LPTSTR VT_LPWSTR
  30. #else
  31. #define VT_LPTSTR VT_LPSTR
  32. #endif
  33. inline UINT DW_ALIGNED(UINT i) {
  34. return ((i+3) & 0xfffffffc);
  35. }
  36. inline BOOL IS_DW_ALIGNED(UINT i) {
  37. return ((i & 3)==0);
  38. }
  39. // Old one (beta-2)
  40. typedef struct _HISTDATAOLD
  41. {
  42. WORD cbSize;
  43. DWORD dwFlags;
  44. WORD wTitleOffset;
  45. WORD aFragsOffset;
  46. WORD cFrags; //right now the top five bits are used for Prop_MshtmlMCS
  47. WORD wPropNameOffset;
  48. WORD wMCSIndex;
  49. } HISTDATAOLD, *LPHISTDATAOLD;
  50. // Forward reference
  51. typedef struct HISTEXTRA* LPHISTEXTRA;
  52. // Version 0.01
  53. //
  54. // PID_INTSITE_WHATSNEW stored as a HISTEXTRA
  55. // PID_INTSITE_AUTHOR stored as a HISTEXTRA
  56. // PID_INTSITE_LASTVISIT from lpCEI->LastAccessTime
  57. // PID_INTSITE_LASTMOD from lpCEI->LastModifiedTime
  58. // PID_INTSITE_VISITCOUNT dwVisits
  59. // PID_INTSITE_DESCRIPTION stored as a HISTEXTRA
  60. // PID_INTSITE_COMMENT stored as a HISTEXTRA
  61. // PID_INTSITE_FLAGS dwFlags
  62. // PID_INTSITE_CONTENTLEN (never used)
  63. // PID_INTSITE_CONTENTCODE (never used)
  64. // PID_INTSITE_RECURSE (never used)
  65. // PID_INTSITE_WATCH dwWatch
  66. // PID_INTSITE_SUBSCRIPTION stored as a HISTEXTRA
  67. // PID_INTSITE_URL URL itself
  68. // PID_INTSITE_TITLE Title
  69. // PID_INTSITE_FRAGMENT Visited Fragment (private)
  70. //
  71. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  72. // HACKHACK: If you change this data structure, you must talk
  73. // to Adrian Canter (adrianc) -- we put a copy of it
  74. // in wininet\urlcache\401imprt.cxx to make importing
  75. // from old-style cache happen quick n' dirty
  76. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  77. struct _HISTDATA_V001
  78. {
  79. UINT cbSize : 16; // size of this header
  80. UINT cbVer : 16; // version
  81. DWORD dwFlags; // PID_INTSITE_FLAGS (PIDISF_ flags)
  82. DWORD dwWatch; // PID_INTSITE_WATCH (PIDISM_ flags)
  83. DWORD dwVisits; // PID_INTSITE_VISITCOUNT
  84. };
  85. #define HISTDATA_VER 2
  86. class CHistoryData : public _HISTDATA_V001
  87. {
  88. public:
  89. LPHISTEXTRA _GetExtra(void) const {
  90. ASSERT( this->cbSize == sizeof(_HISTDATA_V001) );
  91. ASSERT( this->cbVer == HISTDATA_VER );
  92. return (LPHISTEXTRA)(((BYTE*)this) + this->cbSize);
  93. }
  94. const HISTEXTRA * _FindExtra(UINT idExtra) const;
  95. HISTEXTRA * _FindExtraForSave(UINT idExtra) {
  96. return (HISTEXTRA*)_FindExtra(idExtra);
  97. }
  98. void _GetTitle(LPTSTR szTitle, UINT cchMax) const;
  99. BOOL _HasFragment(LPCTSTR pszFragment) const;
  100. BOOL _IsOldHistory(void) const {
  101. return (cbSize==SIZEOF(HISTDATAOLD) && cbVer==0);
  102. };
  103. static CHistoryData* s_GetHistoryData(LPINTERNET_CACHE_ENTRY_INFO lpCEI);
  104. static CHistoryData* s_AllocateHeaderInfo(UINT cbExtra, const CHistoryData* phdPrev, ULONG* pcbTotal);
  105. HISTEXTRA* CopyExtra(HISTEXTRA* phextCur) const;
  106. UINT GetTotalExtraSize() const;
  107. };
  108. //
  109. // Right after HISTDATA (always at cbSize), we have optional (typically
  110. // variable length) data which has following data structure. It may have
  111. // more than one but always has a null-terimiator (cbExtra == 0).
  112. //
  113. struct HISTEXTRA
  114. {
  115. UINT cbExtra : 16;
  116. UINT idExtra : 8; // PID_INTSITE_*
  117. UINT vtExtra : 8; // VT_*
  118. BYTE abExtra[1]; // abExtra[cbExtra-4];
  119. BOOL IsTerminator(void) const {
  120. return (this->cbExtra==0);
  121. }
  122. const HISTEXTRA* GetNextFast(void) const {
  123. ASSERT( ! IsTerminator() );
  124. return (LPHISTEXTRA)(((BYTE*)this) + this->cbExtra);
  125. }
  126. HISTEXTRA* GetNextFastForSave(void) const {
  127. ASSERT( ! IsTerminator() );
  128. return (LPHISTEXTRA)(((BYTE*)this) + this->cbExtra);
  129. }
  130. const HISTEXTRA* GetNext(void) const {
  131. if (this->cbExtra) {
  132. return (LPHISTEXTRA)(((BYTE*)this) + this->cbExtra);
  133. }
  134. return NULL;
  135. }
  136. };
  137. // We want to make sure that our history binary data is valid so
  138. // we don't crash or something
  139. BOOL ValidateHistoryData(LPINTERNET_CACHE_ENTRY_INFOA pcei)
  140. {
  141. DWORD cb = 0;
  142. if (!pcei->lpHeaderInfo)
  143. {
  144. ASSERT(pcei->dwHeaderInfoSize==0);
  145. pcei->dwHeaderInfoSize = 0;
  146. return TRUE;
  147. }
  148. // First, let's check HISTDATA
  149. CHistoryData* phd = (CHistoryData*)pcei->lpHeaderInfo;
  150. if ((phd->cbSize!=sizeof(_HISTDATA_V001))
  151. ||
  152. (phd->cbSize > pcei->dwHeaderInfoSize))
  153. {
  154. pcei->dwHeaderInfoSize = 0;
  155. pcei->lpHeaderInfo = NULL;
  156. return FALSE;
  157. }
  158. cb += phd->cbSize;
  159. // Now, let's check HISTEXTRA
  160. LPHISTEXTRA phe = phd->_GetExtra();
  161. while (phe && !phe->IsTerminator())
  162. {
  163. cb += phe->cbExtra;
  164. if (cb >= pcei->dwHeaderInfoSize)
  165. {
  166. // Hmm. We're expecting more data than we got. Not good. Prune the rest off.
  167. // We're adding 1 for the terminator
  168. pcei->dwHeaderInfoSize = cb - phe->cbExtra + 4;
  169. phe->cbExtra = 0;
  170. return FALSE;
  171. }
  172. phe = phe->GetNextFastForSave();
  173. }
  174. // Add a DWORD for the terminator
  175. cb += sizeof(DWORD);
  176. // ASSERT(pcei->dwHeaderInfoSize==cb);
  177. return TRUE;
  178. }
  179. //
  180. // Typically, we need 200-300 bytes to retrieve a cached entry in this
  181. // history database. To avoid allocating memory in 99% of cases, we
  182. // allocate 500 bytes in the stack and call LocalAlloc only if we need
  183. // more than that.
  184. //
  185. #define DEFAULT_CEI_BUFFER_SIZE (500 * sizeof(WCHAR))
  186. const TCHAR c_szHistoryPrefix[] = TEXT("Visited: ");
  187. struct CEI_PREALLOC {
  188. LPINTERNET_CACHE_ENTRY_INFO pcei;
  189. LPCTSTR pszFragment;
  190. TCHAR szPrefixedUrl[MAX_URL_STRING + ARRAYSIZE(c_szHistoryPrefix)];
  191. union {
  192. #ifdef UNIX
  193. double alignOn8ByteBoundary;
  194. #endif /* UNIX */
  195. INTERNET_CACHE_ENTRY_INFO cei;
  196. BYTE ab[DEFAULT_CEI_BUFFER_SIZE];
  197. };
  198. CEI_PREALLOC() : pcei(NULL), pszFragment(NULL) {}
  199. ~CEI_PREALLOC() {
  200. if (pcei && pcei != &cei) {
  201. TraceMsg(DM_TRACE, "CEI_PREALLOC::dtr freeing pcei");
  202. LocalFree(pcei);
  203. pcei = NULL;
  204. }
  205. }
  206. };
  207. #define VER_HISTDATA 1
  208. typedef CHistoryData HISTDATA;
  209. typedef HISTDATA* LPHISTDATA;
  210. // CUrlHistory manages the other interfaces and handles alot of the basic functions
  211. class CUrlHistory : public IUrlHistoryPriv
  212. {
  213. public:
  214. CUrlHistory (void);
  215. ~CUrlHistory(void);
  216. // IUnknown methods
  217. virtual STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppvObj);
  218. virtual STDMETHODIMP_(ULONG) AddRef(void);
  219. virtual STDMETHODIMP_(ULONG) Release(void);
  220. // IUrlHistoryStg methods
  221. STDMETHODIMP AddUrl(LPCWSTR pwszUrl, LPCWSTR pwszTitle, DWORD dwFlags);
  222. STDMETHODIMP DeleteUrl(LPCWSTR pwszUrl, DWORD dwFlags);
  223. STDMETHODIMP QueryUrl(LPCWSTR pwszUrl, DWORD dwFlags, LPSTATURL lpSTATURL);
  224. STDMETHODIMP BindToObject(LPCWSTR pwszUrl, REFIID riid, void **ppvOut);
  225. STDMETHODIMP EnumUrls(IEnumSTATURL **ppEnum);
  226. // IUrlHistoryStg2 methods
  227. STDMETHODIMP AddUrlAndNotify(LPCWSTR pwszUrl, LPCWSTR pwszTitle, DWORD dwFlags, BOOL fWriteHistory, IOleCommandTarget *poctNotify, IUnknown *punkSFHistory);
  228. STDMETHODIMP ClearHistory();
  229. // IUrlHistoryPriv methods
  230. STDMETHOD(QueryUrlA)(LPCSTR pszUrl, DWORD dwFlags, LPSTATURL lpSTATURL);
  231. STDMETHOD(CleanupHistory)(void);
  232. STDMETHOD_(DWORD,GetDaysToKeep)(void) { return s_GetDaysToKeep(); }
  233. STDMETHOD(GetProperty)(LPCTSTR pszUrl, PROPID pid, PROPVARIANT* pvarOut);
  234. STDMETHOD(GetUserName)(LPTSTR pszUserName, DWORD cchUserName);
  235. STDMETHOD(AddUrlAndNotifyCP)(LPCWSTR pwszUrl, LPCWSTR pwszTitle, DWORD dwFlags, BOOL fWriteHistory, IOleCommandTarget *poctNotify, IUnknown *punkSFHistory, UINT* pcodepage);
  236. static void s_Init();
  237. static DWORD s_GetDaysToKeep(void);
  238. #if defined(ux10) && defined(UNIX)
  239. static void s_SetDaysToKeep(DWORD dwDays);
  240. #endif
  241. protected:
  242. void _WriteToHistory(LPCTSTR pszPrefixedurl,
  243. FILETIME& ftExpires,
  244. IOleCommandTarget *poctNotify,
  245. IUnknown *punkSFHistory);
  246. friend class CEnumSTATURL;
  247. // friend class CUrlHObj;
  248. friend class IntsiteProp;
  249. static HRESULT s_CleanupHistory(void);
  250. static HRESULT s_EnumUrls(IEnumSTATURL **ppEnum);
  251. static HRESULT s_DeleteUrl(LPCWSTR pwszUrl, DWORD dwFlags);
  252. static void s_ConvertToPrefixedUrlW(
  253. IN LPCWSTR pwszUrl,
  254. OUT LPTSTR pszPrefixedUrl,
  255. IN DWORD cchPrefixedUrl,
  256. OUT LPCTSTR *ppszFragment
  257. );
  258. static HRESULT s_QueryUrlCommon(
  259. LPCTSTR lpszPrefixedUrl,
  260. LPCTSTR lpszFragment,
  261. DWORD dwFlags,
  262. LPSTATURL lpSTATURL
  263. );
  264. static void s_RetrievePrefixedUrlInfo(
  265. LPCTSTR lpszUrl, CEI_PREALLOC* pbuf);
  266. static BOOL s_CommitUrlCacheEntry(LPCTSTR pszPrefixedUrl,
  267. LPINTERNET_CACHE_ENTRY_INFO pcei);
  268. static BOOL s_IsCached(IN LPCTSTR pszUrl)
  269. { return ::GetUrlCacheEntryInfoEx(pszUrl, NULL, NULL, NULL, NULL, NULL, INTERNET_CACHE_FLAG_ALLOW_COLLISIONS); }
  270. static HISTDATA* s_GenerateHeaderInfo(
  271. IN LPCTSTR pszTitle,
  272. IN HISTDATA* phdPrev,
  273. IN LPCTSTR pszFragment,
  274. OUT LPDWORD pcbHeader
  275. );
  276. static HRESULT s_GenerateSTATURL(IN PCTSTR pszUrl, IN LPINTERNET_CACHE_ENTRY_INFO lpCEI, IN DWORD dwFlags, OUT LPSTATURL lpsu);
  277. static void s_UpdateIcon(Intshcut* pintshcut, DWORD dwFlags);
  278. DWORD _cRef;
  279. static TCHAR s_szUserPrefix[INTERNET_MAX_USER_NAME_LENGTH + 1];
  280. static DWORD s_cchUserPrefix ;
  281. static DWORD s_dwDaysToKeep;
  282. };
  283. class CEnumSTATURL : public IEnumSTATURL
  284. {
  285. public:
  286. CEnumSTATURL() : _cRef(1) {}
  287. ~CEnumSTATURL();
  288. // IUnknown methods
  289. STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppvObj);
  290. STDMETHODIMP_(ULONG) AddRef(void);
  291. STDMETHODIMP_(ULONG) Release(void);
  292. // IEnumXXXX methods
  293. STDMETHODIMP Next (ULONG celt, LPSTATURL rgelt, ULONG * pceltFetched) ;
  294. STDMETHODIMP Skip(ULONG celt) ;
  295. STDMETHODIMP Reset(void) ;
  296. STDMETHODIMP Clone(IEnumSTATURL ** ppenum) ;
  297. // IEnumSTATURL methods
  298. STDMETHODIMP SetFilter(LPCWSTR poszFilter, DWORD dwFlags) ;
  299. private:
  300. HRESULT RetrieveFirstUrlInfo(void);
  301. HRESULT RetrieveNextUrlInfo(void);
  302. DWORD _cRef;
  303. // search object parameters
  304. LPWSTR m_poszFilter;
  305. DWORD m_dwFilter;
  306. HANDLE m_hEnum;
  307. TCHAR _szPrefixedUrl[MAX_URL_STRING];
  308. DWORD m_cchPrefixedUrl;
  309. LPCTSTR m_lpszFragment;
  310. LPINTERNET_CACHE_ENTRY_INFO m_lpCEI;
  311. DWORD m_cbCEI;
  312. };
  313. #if defined(ux10) && defined(UNIX)
  314. //Work around for mmap limitation in hp-ux10. Change the corresponding
  315. //value even in inetcpl/general.cpp
  316. #define MAX_HISTORY_DAYS 30
  317. #endif
  318. #define FILETIME_SEC 10000000
  319. #define SECS_PER_DAY (60 * 60 * 24)
  320. #define CCHHISTORYPREFIX (ARRAYSIZE(c_szHistoryPrefix) - 1)
  321. #define CLEANUP_HISTORY_INTERVAL (24 * 60 * 60 * 1000) // One day, in milliseconds
  322. DWORD g_tCleanupHistory = 0;
  323. #define OFFSET_TO_LPTSTR(p, o) ( (LPTSTR) ( (LPBYTE) (p) + (o) ) )
  324. #define OFFSET_TO_LPBYTE(p, o) ( (LPBYTE) ( (LPBYTE) (p) + (o) ) )
  325. #define OFFSET_TO_LPWORD(p, o) ( (LPWORD) ( (LPBYTE) (p) + (o) ) )
  326. #define LPTSTR_TO_OFFSET(p, s) ( (WORD) ( (LPTSTR) (s) - (LPTSTR) (p) ) )
  327. #define LPBYTE_TO_OFFSET(p, b) ( (WORD) ( (LPBYTE) (b) - (LPBYTE) (p) ) )
  328. // NOTE: REARCHITECT chrisfra 3/26/97 , ext\cachevu\priv.h has a duplicate copy of this
  329. // structure and uses it to access cache. this needs to be covered by procedural or
  330. // object interface and moved to a common location.
  331. // This structure uses the flags bits as follows: if HFL_VERSIONED is true, then
  332. // the rest of the flags word is the version.
  333. #define HFL_VERSIONED (0x80000000)
  334. //
  335. // We store binary data in the lpHeaderInfo field. CommitUrlCacheEntryW tries
  336. // to convert this data to ansi and messes it up. To get around this we thunk
  337. // through to the A version CommitUrlCacheEntry.
  338. //
  339. BOOL
  340. CommitUrlCacheEntryBinary(
  341. IN LPCWSTR lpszUrlName,
  342. IN FILETIME ExpireTime,
  343. IN FILETIME LastModifiedTime,
  344. IN DWORD CacheEntryType,
  345. IN LPBYTE lpHeaderInfo,
  346. IN DWORD dwHeaderSize
  347. )
  348. {
  349. ASSERT(lpszUrlName);
  350. CHAR szUrl[MAX_URL_STRING + ARRAYSIZE(c_szHistoryPrefix)];
  351. SHUnicodeToAnsi(lpszUrlName, szUrl, ARRAYSIZE(szUrl));
  352. INTERNET_CACHE_ENTRY_INFOA cei;
  353. cei.lpHeaderInfo = (LPSTR)lpHeaderInfo;
  354. cei.dwHeaderInfoSize = dwHeaderSize;
  355. ValidateHistoryData(&cei);
  356. return CommitUrlCacheEntryA(szUrl, NULL, ExpireTime, LastModifiedTime,
  357. CacheEntryType, lpHeaderInfo, dwHeaderSize,
  358. NULL, NULL);
  359. }
  360. GetUrlCacheEntryInfoBinary(
  361. IN LPCWSTR lpszUrlName,
  362. OUT LPINTERNET_CACHE_ENTRY_INFOW lpCacheEntryInfo,
  363. IN OUT LPDWORD lpdwCacheEntryInfoBufferSize
  364. )
  365. {
  366. ASSERT(lpszUrlName);
  367. BOOL fRet;
  368. CHAR szUrl[MAX_URL_STRING + ARRAYSIZE(c_szHistoryPrefix)];
  369. SHUnicodeToAnsi(lpszUrlName, szUrl, ARRAYSIZE(szUrl));
  370. //
  371. // Warning! This doesn't convert any of thge string parameters in
  372. // lpCacheEntryInfo back to unicode. History only uses
  373. // lpCacheEntryInfo->lpHeaderInfo so this isn't a problem.
  374. //
  375. fRet = GetUrlCacheEntryInfoA(szUrl,
  376. (LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo,
  377. lpdwCacheEntryInfoBufferSize);
  378. //
  379. // Set unused out paramters to NULL incase someone tries to use them
  380. //
  381. lpCacheEntryInfo->lpszSourceUrlName = NULL;
  382. lpCacheEntryInfo->lpszLocalFileName = NULL;
  383. lpCacheEntryInfo->lpszFileExtension = NULL;
  384. if (fRet)
  385. {
  386. ValidateHistoryData((LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo);
  387. }
  388. return fRet;
  389. }
  390. //
  391. // Warning! This function converts cei structures for use by history. It is
  392. // not a generic conversion. It converts the minimum data required by history.
  393. //
  394. int
  395. CacheEntryInfoAToCacheEntryInfoW(
  396. LPINTERNET_CACHE_ENTRY_INFOA pceiA,
  397. LPINTERNET_CACHE_ENTRY_INFOW pceiW,
  398. int cbceiW
  399. )
  400. {
  401. int nRet;
  402. ASSERT(pceiA->lpszSourceUrlName);
  403. int cchSourceUrlName = lstrlenA(pceiA->lpszSourceUrlName) + 1;
  404. int cbRequired = sizeof(INTERNET_CACHE_ENTRY_INFOA) +
  405. pceiA->dwHeaderInfoSize +
  406. cchSourceUrlName * sizeof(WCHAR);
  407. if (cbRequired <= cbceiW)
  408. {
  409. ASSERT(sizeof(*pceiA) == sizeof(*pceiW));
  410. // Copy the structure.
  411. *pceiW = *(INTERNET_CACHE_ENTRY_INFOW*)pceiA;
  412. // Append the binary data. Note dwHeaderInfoSize is already copied.
  413. pceiW->lpHeaderInfo = (LPWSTR)(pceiW + 1);
  414. memcpy(pceiW->lpHeaderInfo, pceiA->lpHeaderInfo, pceiA->dwHeaderInfoSize);
  415. // Append the source url name.
  416. pceiW->lpszSourceUrlName = (LPWSTR)((BYTE*)(pceiW + 1) + pceiW->dwHeaderInfoSize);
  417. SHAnsiToUnicode(pceiA->lpszSourceUrlName, pceiW->lpszSourceUrlName,
  418. cchSourceUrlName);
  419. // Null out bogus pointers so we'll fault if someone deref's them
  420. pceiW->lpszLocalFileName = NULL;
  421. pceiW->lpszFileExtension = NULL;
  422. nRet = 0;
  423. }
  424. else
  425. {
  426. nRet = cbRequired;
  427. }
  428. return nRet;
  429. }
  430. HANDLE
  431. FindFirstUrlCacheEntryBinary(
  432. IN LPCWSTR lpszUrlSearchPattern,
  433. OUT LPINTERNET_CACHE_ENTRY_INFOW lpFirstCacheEntryInfo,
  434. IN OUT LPDWORD lpdwFirstCacheEntryInfoBufferSize
  435. )
  436. {
  437. ASSERT(NULL != lpszUrlSearchPattern);
  438. ASSERT(NULL != lpFirstCacheEntryInfo);
  439. ASSERT(NULL != lpdwFirstCacheEntryInfoBufferSize);
  440. HANDLE hRet;
  441. CHAR szPattern[MAX_PATH];
  442. ASSERT(lstrlenW(lpszUrlSearchPattern) < ARRAYSIZE(szPattern));
  443. SHUnicodeToAnsi(lpszUrlSearchPattern, szPattern, ARRAYSIZE(szPattern));
  444. BYTE ab[MAX_CACHE_ENTRY_INFO_SIZE];
  445. INTERNET_CACHE_ENTRY_INFOA* pceiA = (INTERNET_CACHE_ENTRY_INFOA*)ab;
  446. DWORD dwSize;
  447. BOOL fAllocated = FALSE;
  448. pceiA->dwStructSize = dwSize = sizeof(ab);
  449. hRet = FindFirstUrlCacheEntryA(szPattern, pceiA, &dwSize);
  450. if (NULL == hRet && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
  451. {
  452. pceiA = (INTERNET_CACHE_ENTRY_INFOA*)LocalAlloc(LPTR, dwSize);
  453. if (pceiA)
  454. {
  455. fAllocated = TRUE;
  456. pceiA->dwStructSize = dwSize;
  457. hRet = FindFirstUrlCacheEntryA(szPattern, pceiA, &dwSize);
  458. ASSERT(hRet || GetLastError() != ERROR_INSUFFICIENT_BUFFER);
  459. }
  460. else
  461. {
  462. SetLastError(ERROR_OUTOFMEMORY);
  463. }
  464. }
  465. if (hRet)
  466. {
  467. int nRet;
  468. ValidateHistoryData(pceiA);
  469. nRet = CacheEntryInfoAToCacheEntryInfoW(pceiA, lpFirstCacheEntryInfo,
  470. *lpdwFirstCacheEntryInfoBufferSize);
  471. if (nRet)
  472. {
  473. FindCloseUrlCache(hRet);
  474. hRet = NULL;
  475. *lpdwFirstCacheEntryInfoBufferSize = nRet;
  476. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  477. }
  478. }
  479. if (fAllocated)
  480. {
  481. LocalFree(pceiA);
  482. pceiA = NULL;
  483. }
  484. return hRet;
  485. }
  486. BOOL
  487. FindNextUrlCacheEntryBinary(
  488. IN HANDLE hEnumHandle,
  489. OUT LPINTERNET_CACHE_ENTRY_INFOW lpNextCacheEntryInfo,
  490. IN OUT LPDWORD lpdwNextCacheEntryInfoBufferSize
  491. )
  492. {
  493. ASSERT(NULL != hEnumHandle);
  494. ASSERT(NULL != lpNextCacheEntryInfo);
  495. ASSERT(NULL != lpdwNextCacheEntryInfoBufferSize);
  496. BOOL fRet;
  497. BYTE ab[MAX_CACHE_ENTRY_INFO_SIZE];
  498. INTERNET_CACHE_ENTRY_INFOA* pceiA = (INTERNET_CACHE_ENTRY_INFOA*)ab;
  499. DWORD dwSize;
  500. BOOL fAllocated = FALSE;
  501. pceiA->dwStructSize = dwSize = sizeof(ab);
  502. fRet = FindNextUrlCacheEntryA(hEnumHandle, pceiA, &dwSize);
  503. if (!fRet && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
  504. {
  505. pceiA = (INTERNET_CACHE_ENTRY_INFOA*)LocalAlloc(LPTR, dwSize);
  506. if (pceiA)
  507. {
  508. fAllocated = TRUE;
  509. pceiA->dwStructSize = dwSize;
  510. fRet = FindNextUrlCacheEntryA(hEnumHandle, pceiA, &dwSize);
  511. ASSERT(fRet || GetLastError() != ERROR_INSUFFICIENT_BUFFER);
  512. }
  513. else
  514. {
  515. SetLastError(ERROR_OUTOFMEMORY);
  516. }
  517. }
  518. if (fRet)
  519. {
  520. int nRet;
  521. ValidateHistoryData(pceiA);
  522. nRet = CacheEntryInfoAToCacheEntryInfoW(pceiA, lpNextCacheEntryInfo,
  523. *lpdwNextCacheEntryInfoBufferSize);
  524. if (nRet)
  525. {
  526. fRet = FALSE;
  527. *lpdwNextCacheEntryInfoBufferSize = nRet;
  528. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  529. }
  530. }
  531. if (fAllocated)
  532. {
  533. LocalFree(pceiA);
  534. pceiA = NULL;
  535. }
  536. return fRet;
  537. }
  538. #define DEFAULT_DAYS_TO_KEEP 21
  539. static const TCHAR c_szRegValDaysToKeep[] = TEXT("DaysToKeep");
  540. static const TCHAR c_szRegValDirectory[] = TEXT("Directory");
  541. #ifdef UNIX
  542. #define DIR_SEPARATOR_CHAR TEXT('/')
  543. #else
  544. #define DIR_SEPARATOR_CHAR TEXT('\\')
  545. #endif
  546. // ** this has been moved to util.cpp 07.28.2000 **
  547. // thunk to shell32.SHGetFolderPath() so this code works downlevel
  548. // HRESULT SHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
  549. // ** this has been moved to util.cpp 07.28.2000 **
  550. HRESULT SHGetHistoryPIDL(LPITEMIDLIST *ppidlHistory)
  551. {
  552. *ppidlHistory = NULL;
  553. TCHAR szHistory[MAX_PATH];
  554. szHistory[0] = 0;
  555. HRESULT hres = SHGetFolderPathD(NULL, CSIDL_HISTORY | CSIDL_FLAG_CREATE, NULL, 0, szHistory);
  556. if (hres != S_OK)
  557. {
  558. GetHistoryFolderPath(szHistory, ARRAYSIZE(szHistory));
  559. PathRemoveFileSpec(szHistory); // get the trailing slash
  560. PathRemoveFileSpec(szHistory); // trim the "content.ie5" junk
  561. }
  562. if (szHistory[0])
  563. {
  564. TCHAR szIniFile[MAX_PATH];
  565. PathCombine(szIniFile, szHistory, TEXT("desktop.ini"));
  566. if (GetFileAttributes(szIniFile) == -1)
  567. {
  568. DWORD dwAttrib = GetFileAttributes(szHistory);
  569. dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
  570. dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
  571. // make sure system, but not hidden
  572. SetFileAttributes(szHistory, dwAttrib);
  573. WritePrivateProfileString(TEXT(".ShellClassInfo"), TEXT("ConfirmFileOp"), TEXT("0"), szIniFile);
  574. WritePrivateProfileString(TEXT(".ShellClassInfo"), TEXT("CLSID"), TEXT("{FF393560-C2A7-11CF-BFF4-444553540000}"), szIniFile);
  575. }
  576. IShellFolder *psfDesktop;
  577. hres = SHGetDesktopFolder(&psfDesktop);
  578. if (SUCCEEDED(hres))
  579. {
  580. hres = psfDesktop->ParseDisplayName(NULL, NULL,
  581. szHistory, NULL, ppidlHistory, NULL);
  582. psfDesktop->Release();
  583. }
  584. }
  585. else
  586. hres = E_FAIL;
  587. return hres;
  588. }
  589. //
  590. // This function is called from hist/hsfolder.cpp
  591. //
  592. HRESULT CUrlHistory::GetUserName(LPTSTR pszUserName, DWORD cchUserName)
  593. {
  594. s_Init();
  595. if (cchUserName < s_cchUserPrefix)
  596. {
  597. return E_FAIL;
  598. }
  599. CopyMemory(pszUserName, s_szUserPrefix, (s_cchUserPrefix-1) * sizeof(TCHAR));
  600. pszUserName[s_cchUserPrefix-1] = 0;
  601. return S_OK;
  602. }
  603. #if defined (ux10) && defined(UNIX)
  604. void CUrlHistory::s_SetDaysToKeep(DWORD dwDays)
  605. {
  606. HKEY hk;
  607. DWORD dwDisp;
  608. DWORD Error = RegCreateKeyEx(
  609. HKEY_CURRENT_USER,
  610. REGSTR_PATH_URLHISTORY,
  611. 0, NULL, 0,
  612. KEY_WRITE,
  613. NULL,
  614. &hk,
  615. &dwDisp);
  616. if(ERROR_SUCCESS != Error)
  617. {
  618. ASSERT(FALSE);
  619. return;
  620. }
  621. Error = RegSetValueEx(
  622. hk,
  623. c_szRegValDaysToKeep,
  624. 0,
  625. REG_DWORD,
  626. (LPBYTE) &dwDays,
  627. sizeof(dwDays));
  628. ASSERT(ERROR_SUCCESS == Error);
  629. RegCloseKey(hk);
  630. return;
  631. }
  632. #endif
  633. //
  634. // This function is called from hist/hsfolder.cpp
  635. //
  636. DWORD CUrlHistory::s_GetDaysToKeep(void)
  637. {
  638. HKEY hk;
  639. DWORD cbDays = SIZEOF(DWORD);
  640. DWORD dwDays = DEFAULT_DAYS_TO_KEEP;
  641. DWORD dwType;
  642. DWORD Error = RegOpenKeyEx(
  643. HKEY_CURRENT_USER,
  644. REGSTR_PATH_URLHISTORY,
  645. 0,
  646. KEY_READ,
  647. &hk);
  648. if(Error)
  649. {
  650. Error = RegOpenKeyEx(
  651. HKEY_LOCAL_MACHINE,
  652. REGSTR_PATH_URLHISTORY,
  653. 0,
  654. KEY_READ,
  655. &hk);
  656. }
  657. if(!Error)
  658. {
  659. Error = RegQueryValueEx(
  660. hk,
  661. c_szRegValDaysToKeep,
  662. 0,
  663. &dwType,
  664. (LPBYTE) &dwDays,
  665. &cbDays);
  666. RegCloseKey(hk);
  667. }
  668. return dwDays;
  669. }
  670. IUrlHistoryPriv* g_puhUrlHistory = NULL;
  671. void CUrlHistory_CleanUp()
  672. {
  673. // Release will clean up the global
  674. ENTERCRITICAL;
  675. if (g_puhUrlHistory)
  676. g_puhUrlHistory->Release();
  677. LEAVECRITICAL;
  678. }
  679. STDAPI CUrlHistory_CreateInstance(IUnknown* pUnkOuter, IUnknown **ppunk, LPCOBJECTINFO poi)
  680. {
  681. HRESULT hr = E_OUTOFMEMORY;
  682. *ppunk = NULL;
  683. // !!! Take NOTE: CUrlHistory *MUST* be thread safe!
  684. // aggregation checking is handled in class factory
  685. ENTERCRITICAL;
  686. if (!g_puhUrlHistory)
  687. {
  688. CUrlHistory *pcuh = new CUrlHistory;
  689. if (pcuh)
  690. {
  691. g_puhUrlHistory = SAFECAST(pcuh, IUrlHistoryPriv *);
  692. // The memory tracking code thinks this is a leak
  693. }
  694. }
  695. if (g_puhUrlHistory)
  696. {
  697. *ppunk = SAFECAST(g_puhUrlHistory, IUnknown*);
  698. g_puhUrlHistory->AddRef();
  699. hr = S_OK;
  700. }
  701. LEAVECRITICAL;
  702. return hr;
  703. }
  704. //
  705. // Public members of CUrlHistory
  706. //
  707. CUrlHistory::CUrlHistory(void) : _cRef(1)
  708. {
  709. //
  710. // Update s_dwDaysToKeep for each call
  711. //
  712. s_dwDaysToKeep = s_GetDaysToKeep();
  713. #if defined(ux10) && defined(UNIX)
  714. //Work around for mmap limitation in hp-ux10
  715. if (s_dwDaysToKeep > MAX_HISTORY_DAYS)
  716. {
  717. s_dwDaysToKeep = MAX_HISTORY_DAYS;
  718. s_SetDaysToKeep(s_dwDaysToKeep);
  719. }
  720. #endif
  721. #ifdef DEBUG
  722. if (g_dwPrototype & 0x00000020) {
  723. s_CleanupHistory();
  724. }
  725. #endif
  726. DllAddRef();
  727. }
  728. CUrlHistory::~CUrlHistory(void)
  729. {
  730. DllRelease();
  731. }
  732. HRESULT LoadHistoryShellFolder(IUnknown *punk, IHistSFPrivate **ppsfpHistory)
  733. {
  734. HRESULT hr;
  735. *ppsfpHistory = NULL;
  736. if (punk)
  737. {
  738. hr = punk->QueryInterface(IID_IHistSFPrivate, (void **)ppsfpHistory);
  739. }
  740. else
  741. {
  742. LPITEMIDLIST pidlHistory;
  743. hr = SHGetHistoryPIDL(&pidlHistory);
  744. if (SUCCEEDED(hr))
  745. {
  746. hr = SHBindToObject(NULL, IID_IHistSFPrivate, pidlHistory, (void **)ppsfpHistory);
  747. ILFree(pidlHistory);
  748. }
  749. }
  750. return hr;
  751. }
  752. // ClearHistory on a per user basis. moved from inetcpl to facilitate changes in
  753. // implementation.
  754. HRESULT CUrlHistory::ClearHistory()
  755. {
  756. HRESULT hr;
  757. IEnumSTATURL *penum;
  758. IHistSFPrivate *psfpHistory = NULL;
  759. hr = THR(EnumUrls(&penum));
  760. if (SUCCEEDED(hr))
  761. {
  762. penum->SetFilter(NULL, STATURL_QUERYFLAG_NOTITLE);
  763. ULONG cFetched;
  764. STATURL rsu[1] = {{sizeof(STATURL), NULL, NULL}};
  765. while (SUCCEEDED(penum->Next(1, rsu, &cFetched)) && cFetched)
  766. {
  767. ASSERT(rsu[0].pwcsUrl);
  768. hr = THR(DeleteUrl(rsu[0].pwcsUrl, URLFLAG_DONT_DELETE_SUBSCRIBED));
  769. OleFree(rsu[0].pwcsUrl);
  770. rsu[0].pwcsUrl = NULL;
  771. ASSERT(!rsu[0].pwcsTitle);
  772. }
  773. penum->Release();
  774. }
  775. hr = LoadHistoryShellFolder(NULL, &psfpHistory);
  776. if (SUCCEEDED(hr))
  777. {
  778. hr = psfpHistory->ClearHistory();
  779. psfpHistory->Release();
  780. }
  781. return hr;
  782. }
  783. extern void _FileTimeDeltaDays(FILETIME *pftBase, FILETIME *pftNew, int Days);
  784. HRESULT CUrlHistory::s_CleanupHistory(void)
  785. {
  786. TraceMsg(DM_URLCLEANUP, "CUH::s_CleanupHistory called");
  787. HRESULT hr;
  788. DWORD tCurrent = GetTickCount();
  789. if (!g_tCleanupHistory || (tCurrent > g_tCleanupHistory + CLEANUP_HISTORY_INTERVAL)) {
  790. g_tCleanupHistory = tCurrent;
  791. } else {
  792. #ifdef DEBUG
  793. if (!(g_dwPrototype & 0x00000020))
  794. #endif
  795. return S_OK;
  796. }
  797. SYSTEMTIME st;
  798. FILETIME ftNow;
  799. FILETIME ftOldest;
  800. GetSystemTime(&st);
  801. SystemTimeToFileTime(&st, &ftNow);
  802. _FileTimeDeltaDays(&ftNow, &ftOldest, -((int)s_GetDaysToKeep()));
  803. IEnumSTATURL * penum = NULL;
  804. if (SUCCEEDED(s_EnumUrls(&penum)))
  805. {
  806. STATURL rsu[1] = {{sizeof(STATURL), NULL, NULL}};
  807. ULONG cFetched = 0;
  808. penum->SetFilter(NULL, STATURL_QUERYFLAG_NOTITLE);
  809. while (S_OK == penum->Next(1, rsu, &cFetched))
  810. {
  811. ASSERT(cFetched);
  812. ASSERT(rsu[0].pwcsUrl);
  813. ASSERT(rsu[0].pwcsTitle==NULL);
  814. #ifdef DEBUG
  815. TCHAR szUrl[MAX_URL_STRING];
  816. SHUnicodeToTChar(rsu[0].pwcsUrl, szUrl, ARRAYSIZE(szUrl));
  817. #endif
  818. // check to see if expires is not special && ftLastUpdated is earlier
  819. // than we need
  820. if (CompareFileTime(&(rsu[0].ftLastUpdated), &ftOldest) < 0 &&
  821. (rsu[0].ftExpires.dwLowDateTime != DW_FOREVERLOW ||
  822. rsu[0].ftExpires.dwHighDateTime != DW_FOREVERHIGH))
  823. {
  824. hr = THR(s_DeleteUrl(rsu[0].pwcsUrl, 0));
  825. #ifdef DEBUG
  826. TraceMsg(DM_URLCLEANUP, "CUH::s_Cleanup deleting %s", szUrl);
  827. #endif
  828. } else {
  829. #ifdef DEBUG
  830. TraceMsg(DM_URLCLEANUP, "CUH::s_Cleanup keeping %s", szUrl);
  831. #endif
  832. }
  833. CoTaskMemFree(rsu[0].pwcsUrl);
  834. rsu[0].pwcsUrl = NULL;
  835. cFetched = 0;
  836. ASSERT(!rsu[0].pwcsTitle);
  837. }
  838. penum->Release();
  839. }
  840. else
  841. ASSERT(FALSE);
  842. TraceMsg(DM_URLCLEANUP, "CUH::s_CleanupHistory (expensive!) just called");
  843. return S_OK;
  844. }
  845. HRESULT CUrlHistory::CleanupHistory()
  846. {
  847. return CUrlHistory::s_CleanupHistory();
  848. }
  849. TCHAR CUrlHistory::s_szUserPrefix[INTERNET_MAX_USER_NAME_LENGTH + 1] = TEXT("");
  850. DWORD CUrlHistory::s_cchUserPrefix = 0;
  851. DWORD CUrlHistory::s_dwDaysToKeep = 0;
  852. void CUrlHistory::s_Init(void)
  853. {
  854. // Cache the user name only once per process
  855. if (!s_cchUserPrefix)
  856. {
  857. ENTERCRITICAL;
  858. // Maybe it changed since entering the crit sec.
  859. // This really happened to me (BryanSt)
  860. // We do it twice for perf reasons.
  861. if (!s_cchUserPrefix)
  862. {
  863. ASSERT(s_szUserPrefix[0] == '\0');
  864. s_cchUserPrefix = ARRAYSIZE(s_szUserPrefix);
  865. // Get the current user or set to default
  866. ::GetUserName(s_szUserPrefix, &s_cchUserPrefix);
  867. StrCatBuff(s_szUserPrefix, TEXT("@"), ARRAYSIZE(s_szUserPrefix));
  868. s_cchUserPrefix = lstrlen(s_szUserPrefix);
  869. }
  870. LEAVECRITICAL;
  871. }
  872. }
  873. HRESULT CUrlHistory::QueryInterface(REFIID riid, PVOID *ppvObj)
  874. {
  875. HRESULT hr = E_NOINTERFACE;
  876. *ppvObj = NULL;
  877. if (IsEqualIID(riid, IID_IUnknown) ||
  878. IsEqualIID(riid, IID_IUrlHistoryStg2) ||
  879. IsEqualIID(riid, IID_IUrlHistoryPriv) ||
  880. IsEqualIID(riid, IID_IUrlHistoryStg))
  881. {
  882. AddRef();
  883. *ppvObj = (LPVOID) SAFECAST(this, IUrlHistoryPriv *);
  884. hr = S_OK;
  885. }
  886. else if (IsEqualIID(riid, CLSID_CUrlHistory))
  887. {
  888. AddRef();
  889. *ppvObj = (LPVOID) this;
  890. hr = S_OK;
  891. }
  892. return hr;
  893. }
  894. ULONG CUrlHistory::AddRef(void)
  895. {
  896. _cRef++;
  897. return _cRef;
  898. }
  899. ULONG CUrlHistory::Release(void)
  900. {
  901. ASSERT(_cRef > 0);
  902. _cRef--;
  903. if (!_cRef)
  904. {
  905. //time to go bye bye
  906. ENTERCRITICAL;
  907. g_puhUrlHistory = NULL;
  908. LEAVECRITICAL;
  909. delete this;
  910. return 0;
  911. }
  912. return _cRef;
  913. }
  914. //
  915. // Converts a normal URL to a URL with the correct cache prefix.
  916. // it also finds a fragment (local Anchor) if it exists in the URL.
  917. //
  918. // if the URL is invalid, then the returned lplpszPrefixedUrl is just
  919. // the prefix. this is used primarily for doing enumeration.
  920. //
  921. void CUrlHistory::s_ConvertToPrefixedUrlW(
  922. IN LPCWSTR pszUrl,
  923. OUT LPTSTR pszPrefixedUrl,
  924. IN DWORD cchPrefixedUrl,
  925. OUT LPCTSTR *ppszFragment
  926. )
  927. {
  928. //
  929. // Make it sure that s_cchUserPrefix is initialized.
  930. //
  931. s_Init();
  932. // Prefix + UserPrefix + '@'
  933. ASSERT(pszPrefixedUrl && ppszFragment);
  934. // clear the out params
  935. pszPrefixedUrl[0] = L'\0';
  936. *ppszFragment = NULL;
  937. // if there is no URL, send back a default case
  938. // this is just for EnumObjects
  939. if (!pszUrl || !*pszUrl)
  940. {
  941. wnsprintf(pszPrefixedUrl, cchPrefixedUrl, L"%s%s", c_szHistoryPrefix, s_szUserPrefix);
  942. }
  943. else
  944. {
  945. int slen;
  946. int nScheme;
  947. LPWSTR pszFragment;
  948. wnsprintf(pszPrefixedUrl, cchPrefixedUrl, L"%s%s", c_szHistoryPrefix, s_szUserPrefix);
  949. slen = lstrlen(pszPrefixedUrl);
  950. StrCpyN(pszPrefixedUrl + slen, pszUrl, MAX_URL_STRING-slen);
  951. // Only strip the anchor fragment if it's not JAVASCRIPT: or VBSCRIPT:, because a # could not an
  952. // anchor but a string to be evaluated by a script engine like #00ff00 for an RGB color.
  953. nScheme = GetUrlSchemeW(pszPrefixedUrl);
  954. if (nScheme == URL_SCHEME_JAVASCRIPT || nScheme == URL_SCHEME_VBSCRIPT)
  955. {
  956. pszFragment = NULL;
  957. }
  958. else
  959. {
  960. // locate local anchor fragment if possible
  961. pszFragment = StrChr(pszPrefixedUrl + slen, L'#'); // a-naghej Added " + slen" to fix WinSe bug# 13822 & 13926
  962. }
  963. if(pszFragment)
  964. {
  965. // kill the '#' so that lpszPrefixedUrl is isolated
  966. *pszFragment = L'\0';
  967. *ppszFragment = pszFragment+1;
  968. }
  969. // check for trailing slash and eliminate
  970. LPWSTR pszT = CharPrev(pszPrefixedUrl, pszPrefixedUrl + lstrlen(pszPrefixedUrl));
  971. if (pszT[0] == L'/') {
  972. TraceMsg(DM_HISTNLS, "CUH::s_Convert removing the trailing slash of %s", pszPrefixedUrl);
  973. ASSERT(lstrlen(pszT)==1);
  974. pszT[0] = L'\0';
  975. }
  976. }
  977. }
  978. //
  979. // Basically a wrapper function for RetreiveUrlCacheEntryInfo
  980. // meant to be called with the prefixed Url.
  981. // it handles allocating the buffer and reallocating if necessary.
  982. //
  983. void CUrlHistory::s_RetrievePrefixedUrlInfo(
  984. LPCTSTR pszUrl, CEI_PREALLOC* pbuf)
  985. {
  986. TraceMsg(DM_UHRETRIEVE, "CURLHistory::s_RetrievePrefixUrlInfo called (%s)", pszUrl);
  987. s_Init();
  988. DWORD cbCEI = SIZEOF(pbuf->ab);
  989. pbuf->pcei = &pbuf->cei;
  990. BOOL fSuccess = GetUrlCacheEntryInfoBinary(pszUrl, pbuf->pcei, &cbCEI);
  991. if (!fSuccess) {
  992. pbuf->pcei = NULL;
  993. if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
  994. TraceMsg(DM_TRACE, "CUH::s_RetrievePUI not enough buffer. Allocate! (%d)", cbCEI);
  995. pbuf->pcei = (LPINTERNET_CACHE_ENTRY_INFO)LocalAlloc(LPTR, cbCEI);
  996. if (pbuf->pcei) {
  997. fSuccess = GetUrlCacheEntryInfoBinary(pszUrl, pbuf->pcei, &cbCEI);
  998. if (!fSuccess) {
  999. TraceMsg(DM_HISTMISS, "CUH::s_Retrieve (%s) failed %x (on second attempt)",
  1000. pszUrl, GetLastError());
  1001. LocalFree(pbuf->pcei);
  1002. pbuf->pcei = NULL;
  1003. SetLastError(ERROR_FILE_NOT_FOUND);
  1004. }
  1005. }
  1006. } else {
  1007. TraceMsg(DM_HISTMISS, "CUH::s_Retrieve (%s) failed %x (on first attempt)",
  1008. pszUrl, GetLastError());
  1009. SetLastError(ERROR_FILE_NOT_FOUND);
  1010. }
  1011. }
  1012. }
  1013. //
  1014. // Return the total of a double-null terminated string (including the
  1015. // terminating null).
  1016. //
  1017. UINT lstrzlen(LPCTSTR pszz)
  1018. {
  1019. for (LPCTSTR psz=pszz; *psz; psz += lstrlen(psz) + 1) ;
  1020. return (unsigned int)(psz+1-pszz);
  1021. }
  1022. /*++
  1023. Routine Description:
  1024. this creates a buffer that holds a HISTDATA, and everything the HISTDATAs offsets
  1025. point to. it only sets those offsets that are passed in.
  1026. Arguments:
  1027. lpszTitle Title to place in the buffer
  1028. lpBase this is the base of the offsets in aFrags
  1029. aFrags an array of offsets to the fragments to place in the buffer
  1030. cFrags number of fragments in aFrags
  1031. lpszNewFrag this is an additional fragment to add in the new buffer
  1032. pcbHeader this is a pointer to the final size of the buffer returned
  1033. NOTE: any of the arguments except pcbHeader may be NULL.
  1034. if lpBase is NULL, then aFrags must also be NULL. this is CALLERs responsibility!
  1035. if a parameter is NULL, then it just isnt added to the buffer.
  1036. Return Value:
  1037. POINTER
  1038. Success - a valid pointer to a buffer that must be freed.
  1039. Failure - NULL. this only fails with ERROR_NOT_ENOUGH_MEMORY
  1040. NOTE: Caller must free the returned pointer. *pcbHeader only set upon successful return.
  1041. --*/
  1042. HISTDATA* CUrlHistory::s_GenerateHeaderInfo(
  1043. IN LPCTSTR pszTitle,
  1044. IN HISTDATA* phdPrev,
  1045. IN LPCTSTR pszFragment,
  1046. OUT LPDWORD pcbHeader
  1047. )
  1048. {
  1049. DWORD cbHeader = 0;
  1050. UINT cbHistExtra = 0;
  1051. HISTEXTRA* phextPrev;
  1052. // Get the size for title
  1053. UINT cchTitle = 0;
  1054. if (pszTitle[0]) {
  1055. cchTitle = lstrlen(pszTitle) + 1;
  1056. cbHistExtra += DW_ALIGNED(SIZEOF(HISTEXTRA) + (cchTitle * sizeof(TCHAR)));
  1057. if (phdPrev && (phextPrev = phdPrev->_FindExtraForSave(PID_INTSITE_TITLE))!=NULL) {
  1058. phextPrev->vtExtra = VT_EMPTY;
  1059. }
  1060. }
  1061. // Get the size of fragments
  1062. UINT cchFragsPrev = 0;
  1063. UINT cchFragment = 0;
  1064. if (pszFragment) {
  1065. cchFragment = lstrlen(pszFragment) + 2; // Double NULL terminated
  1066. if (phdPrev && (phextPrev=phdPrev->_FindExtraForSave(PID_INTSITE_FRAGMENT))!=NULL) {
  1067. cchFragsPrev = lstrzlen((LPCTSTR)phextPrev->abExtra) - 1; // lstrzlen includes both terminating nulls
  1068. // -1 since cchFragment already accounts
  1069. // for double terminating NULLs.
  1070. ASSERT(cchFragsPrev != (UINT)-1);
  1071. phextPrev->vtExtra = VT_EMPTY;
  1072. }
  1073. cbHistExtra += DW_ALIGNED(SIZEOF(HISTEXTRA) + (cchFragsPrev + cchFragment) * sizeof(TCHAR));
  1074. }
  1075. // Get the size of other extra
  1076. if (phdPrev) {
  1077. cbHistExtra += phdPrev->GetTotalExtraSize();
  1078. }
  1079. // Allocate it
  1080. CHistoryData* phdNew = CHistoryData::s_AllocateHeaderInfo(
  1081. cbHistExtra, phdPrev,
  1082. &cbHeader);
  1083. if (phdNew) {
  1084. HISTEXTRA* phext = phdNew->_GetExtra();
  1085. ASSERT( phext );
  1086. // Append title
  1087. if (pszTitle[0]) {
  1088. phext->cbExtra = DW_ALIGNED((cchTitle * sizeof(TCHAR)) + SIZEOF(HISTEXTRA));
  1089. phext->idExtra = PID_INTSITE_TITLE;
  1090. phext->vtExtra = VT_LPTSTR;
  1091. StrCpyN((LPTSTR)phext->abExtra, pszTitle, cchTitle);
  1092. phext = phext->GetNextFastForSave();
  1093. }
  1094. // Append fragment
  1095. if (pszFragment) {
  1096. // Copy pszFragment to the top.
  1097. StrCpyN((LPTSTR)phext->abExtra, pszFragment, cchFragment);
  1098. // Double NULL terminate. Note cchFragment = strlen + 2
  1099. *(((LPTSTR)phext->abExtra) + cchFragment - 1) = TEXT('\0');
  1100. // Copy existing fragments if any
  1101. if (cchFragsPrev) {
  1102. ASSERT(phdPrev);
  1103. phextPrev = phdPrev->_FindExtraForSave(PID_INTSITE_FRAGMENT);
  1104. ASSERT(phextPrev);
  1105. if (phextPrev) {
  1106. ASSERT(IS_DW_ALIGNED(phextPrev->cbExtra));
  1107. memcpy(phext->abExtra + ((cchFragment - 1) * sizeof(TCHAR)), phextPrev->abExtra,
  1108. (cchFragsPrev + 1) * sizeof(TCHAR));
  1109. }
  1110. }
  1111. ASSERT(lstrzlen((LPCTSTR)phext->abExtra) == cchFragsPrev + cchFragment);
  1112. phext->cbExtra += DW_ALIGNED(SIZEOF(HISTEXTRA) + (cchFragsPrev + cchFragment) * sizeof(TCHAR));
  1113. phext->idExtra = PID_INTSITE_FRAGMENT;
  1114. phext->vtExtra = VT_NULL; // HACK (means internal)
  1115. phext = phext->GetNextFastForSave();
  1116. }
  1117. // Migrate extra data from previous one
  1118. if (phdPrev) {
  1119. phext = phdPrev->CopyExtra(phext);
  1120. }
  1121. ASSERT( phext->cbExtra == 0); // terminator
  1122. ASSERT( (LPBYTE)phdNew+cbHeader == (LPBYTE)phext+SIZEOF(DWORD) );
  1123. ASSERT( cbHistExtra == phdNew->GetTotalExtraSize() );
  1124. }
  1125. *pcbHeader = cbHeader;
  1126. TraceMsg(DM_HISTGENERATE, "CUH::s_GenerateHeader allocated %d bytes (%d extra)",
  1127. cbHeader, cbHistExtra);
  1128. return phdNew;
  1129. }
  1130. // FEATURE: Move this to UTIL.CPP
  1131. LPWSTR AllocOleStrFromTChar(LPCTSTR psz)
  1132. {
  1133. DWORD cch = lstrlen(psz) + 1;
  1134. LPWSTR pwsz = (LPWSTR)CoTaskMemAlloc(cch * SIZEOF(WCHAR));
  1135. if (pwsz) {
  1136. SHTCharToUnicode(psz, pwsz, cch);
  1137. }
  1138. return pwsz;
  1139. }
  1140. HRESULT CUrlHistory::s_GenerateSTATURL(
  1141. IN PCTSTR pszPrefixedURL,
  1142. IN LPINTERNET_CACHE_ENTRY_INFO lpCEI,
  1143. IN DWORD dwFlags,
  1144. OUT LPSTATURL lpSTATURL)
  1145. {
  1146. ASSERT(lpCEI);
  1147. ASSERT(lpSTATURL);
  1148. if (!lpCEI || !lpSTATURL)
  1149. return E_INVALIDARG;
  1150. HRESULT hr = S_OK;
  1151. LPHISTDATA phd = CHistoryData::s_GetHistoryData(lpCEI);
  1152. // I've seen lpCEI->lpszSourceUrlName be NULL with help "ms-its:" URLs.
  1153. LPCTSTR pszUrl = lpCEI->lpszSourceUrlName ? lpCEI->lpszSourceUrlName : pszPrefixedURL;
  1154. if (pszUrl && *pszUrl)
  1155. {
  1156. pszUrl += s_cchUserPrefix + CCHHISTORYPREFIX;
  1157. }
  1158. ZeroMemory(lpSTATURL, SIZEOF(STATURL));
  1159. lpSTATURL->ftLastUpdated = lpCEI->LastModifiedTime;
  1160. lpSTATURL->ftExpires = lpCEI->ExpireTime;
  1161. lpSTATURL->ftLastVisited = lpCEI->LastSyncTime;
  1162. if(dwFlags & STATURL_QUERYFLAG_ISCACHED)
  1163. {
  1164. if (pszUrl)
  1165. {
  1166. if (s_IsCached(pszUrl))
  1167. lpSTATURL->dwFlags |= STATURLFLAG_ISCACHED;
  1168. }
  1169. else
  1170. {
  1171. hr = E_UNEXPECTED;
  1172. }
  1173. }
  1174. if (dwFlags & STATURL_QUERYFLAG_TOPLEVEL)
  1175. {
  1176. if (phd) {
  1177. if (phd->dwFlags & PIDISF_HISTORY)
  1178. {
  1179. lpSTATURL->dwFlags |= STATURLFLAG_ISTOPLEVEL;
  1180. }
  1181. }
  1182. }
  1183. if (!(dwFlags & STATFLAG_NONAME))
  1184. {
  1185. if (!(dwFlags & STATURL_QUERYFLAG_NOURL))
  1186. {
  1187. if (pszUrl)
  1188. {
  1189. // set the Url
  1190. lpSTATURL->pwcsUrl = AllocOleStrFromTChar(pszUrl); // This will RIP if NULL is passed.
  1191. if (lpSTATURL->pwcsUrl == NULL)
  1192. {
  1193. hr = E_OUTOFMEMORY;
  1194. }
  1195. }
  1196. else
  1197. {
  1198. hr = E_UNEXPECTED;
  1199. }
  1200. }
  1201. if (!(dwFlags & STATURL_QUERYFLAG_NOTITLE))
  1202. {
  1203. // is there a title to set?
  1204. if (phd)
  1205. {
  1206. const HISTEXTRA* phextTitle = phd->_FindExtra(PID_INTSITE_TITLE);
  1207. if (phextTitle && phextTitle->vtExtra == VT_LPTSTR) {
  1208. lpSTATURL->pwcsTitle = AllocOleStrFromTChar((LPCTSTR)phextTitle->abExtra);
  1209. if (lpSTATURL->pwcsTitle == NULL) {
  1210. if (lpSTATURL->pwcsUrl)
  1211. CoTaskMemFree(lpSTATURL->pwcsUrl);
  1212. lpSTATURL->pwcsUrl = NULL;
  1213. hr = E_OUTOFMEMORY;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }
  1219. ASSERT(SUCCEEDED(hr) || (lpSTATURL->pwcsUrl==NULL && lpSTATURL->pwcsTitle==NULL));
  1220. return hr;
  1221. }
  1222. /*++
  1223. Routine Description:
  1224. Places the specified URL into the history.
  1225. If it does not exist, then it is created. If it does exist it is overwritten.
  1226. Arguments:
  1227. pwszUrl - The URL in question.
  1228. pwszTitle - pointer to the friendly title that should be associated
  1229. with this URL. If NULL, no title will be added.
  1230. dwFlags - Sets options for storage type and durability
  1231. Not implemented yet
  1232. Return Value:
  1233. HRESULT
  1234. Success - S_OK
  1235. Failure - E_ hresult
  1236. --*/
  1237. HRESULT CUrlHistory::AddUrl(
  1238. IN LPCWSTR pwszUrl, // Full URL to be added
  1239. IN LPCWSTR pwszTitle,
  1240. IN DWORD dwFlags // Storage options
  1241. )
  1242. {
  1243. BOOL fWriteHistory = TRUE;
  1244. if (ADDURL_ADDTOCACHE == dwFlags)
  1245. {
  1246. fWriteHistory = FALSE;
  1247. }
  1248. return AddUrlAndNotify(pwszUrl, pwszTitle, dwFlags, fWriteHistory, NULL, NULL);
  1249. }
  1250. BOOL CUrlHistory::s_CommitUrlCacheEntry(LPCTSTR pszPrefixedUrl,
  1251. LPINTERNET_CACHE_ENTRY_INFO pcei)
  1252. {
  1253. if (s_dwDaysToKeep==0) {
  1254. s_dwDaysToKeep = s_GetDaysToKeep();
  1255. }
  1256. //
  1257. // prepare the expire time
  1258. //
  1259. SYSTEMTIME st;
  1260. GetSystemTime(&st);
  1261. SystemTimeToFileTime(&st, &pcei->LastModifiedTime);
  1262. //
  1263. // Assume the normal expiration date ... we add 6 days to expiration date
  1264. // to make sure when we show the oldest week, we'll still have data for days
  1265. // that are past the s_dwDaysToKeep
  1266. //
  1267. LONGLONG llExpireHorizon = SECS_PER_DAY * (s_dwDaysToKeep + 6);
  1268. llExpireHorizon *= FILETIME_SEC;
  1269. pcei->ExpireTime.dwLowDateTime = pcei->LastModifiedTime.dwLowDateTime + (DWORD) (llExpireHorizon % 0xFFFFFFFF);
  1270. pcei->ExpireTime.dwHighDateTime = pcei->LastModifiedTime.dwHighDateTime + (DWORD) (llExpireHorizon / 0xFFFFFFFF);
  1271. //
  1272. // Check if it's subscribed
  1273. //
  1274. CHistoryData* phd = CHistoryData::s_GetHistoryData(pcei);
  1275. if (phd && phd->_FindExtra(PID_INTSITE_SUBSCRIPTION)) {
  1276. //
  1277. // It's subscribed. Keep it forever (until unsubscribed).
  1278. //
  1279. TraceMsg(DM_URLCLEANUP, "CUH::s_CommitUrlCacheEntry found subscription key %s", pszPrefixedUrl);
  1280. pcei->ExpireTime.dwLowDateTime = DW_FOREVERLOW;
  1281. pcei->ExpireTime.dwHighDateTime = DW_FOREVERHIGH;
  1282. }
  1283. #ifdef DEBUG
  1284. LPCTSTR pszTitle = TEXT("(no extra data)");
  1285. if (phd) {
  1286. const HISTEXTRA* phext = phd->_FindExtra(PID_INTSITE_TITLE);
  1287. if (phext && phext->vtExtra==VT_LPTSTR) {
  1288. pszTitle = (LPCTSTR)phext->abExtra;
  1289. } else {
  1290. pszTitle = TEXT("(no title property)");
  1291. }
  1292. TraceMsg(DM_HISTCOMMIT, "CURL::s_C calling Commit for %s with %s",
  1293. pszPrefixedUrl, pszTitle);
  1294. }
  1295. #endif
  1296. return CommitUrlCacheEntryBinary(pszPrefixedUrl,
  1297. pcei->ExpireTime,
  1298. pcei->LastModifiedTime,
  1299. pcei->CacheEntryType | URLHISTORY_CACHE_ENTRY,
  1300. (LPBYTE)pcei->lpHeaderInfo,
  1301. pcei->dwHeaderInfoSize);
  1302. }
  1303. void CUrlHistory::_WriteToHistory(LPCTSTR pszPrefixedUrl, FILETIME& ftExpires, IOleCommandTarget *poctNotify, IUnknown *punkSFHistory)
  1304. {
  1305. IHistSFPrivate *psfpHistory;
  1306. HRESULT hr = LoadHistoryShellFolder(punkSFHistory, &psfpHistory);
  1307. if (SUCCEEDED(hr))
  1308. {
  1309. LPITEMIDLIST pidlNotify = NULL;
  1310. //
  1311. // prepare the local mod time
  1312. //
  1313. SYSTEMTIME st;
  1314. GetLocalTime (&st);
  1315. FILETIME ftLocModified; // new history written in "User Perceived Time"
  1316. SystemTimeToFileTime(&st, &ftLocModified);
  1317. hr = psfpHistory->WriteHistory(pszPrefixedUrl,
  1318. ftExpires,
  1319. ftLocModified,
  1320. poctNotify ? &pidlNotify : NULL);
  1321. if (pidlNotify)
  1322. {
  1323. VARIANTARG var;
  1324. InitVariantFromIDList(&var, pidlNotify);
  1325. poctNotify->Exec(&CGID_Explorer, SBCMDID_SELECTHISTPIDL, OLECMDEXECOPT_PROMPTUSER, &var, NULL);
  1326. ILFree(pidlNotify);
  1327. VariantClear(&var);
  1328. }
  1329. psfpHistory->Release();
  1330. }
  1331. // if we made it to here, we win!
  1332. }
  1333. void CUrlHistory::s_UpdateIcon(Intshcut* pintshcut, DWORD dwFlags)
  1334. {
  1335. TCHAR szPath[MAX_PATH];
  1336. int niIcon = 0;
  1337. UINT uFlags;
  1338. // mask off the other stuff so we get consistent results.
  1339. dwFlags &= PIDISF_RECENTLYCHANGED;
  1340. // Get the old icon location
  1341. pintshcut->GetIconLocationFromFlags(0, szPath, SIZECHARS(szPath),
  1342. &niIcon, &uFlags, dwFlags);
  1343. // property.
  1344. // int icachedImage = SHLookupIconIndex(PathFindFileName(szPath), niIcon, uFlags);
  1345. int icachedImage = Shell_GetCachedImageIndex(szPath, niIcon, uFlags);
  1346. TraceMsg(DM_HISTSPLAT, "CUH::s_UpdateIcon splat flag is changed for %s (%d)",
  1347. szPath, icachedImage);
  1348. SHUpdateImage(szPath, niIcon, uFlags, icachedImage );
  1349. }
  1350. HRESULT CUrlHistory::AddUrlAndNotify(
  1351. IN LPCWSTR pwszUrl, // Full URL to be added
  1352. IN LPCWSTR pwszTitle,
  1353. IN DWORD dwFlags, // Storage options
  1354. IN BOOL fWriteHistory, // Write History ShellFolder
  1355. IN IOleCommandTarget *poctNotify,
  1356. IN IUnknown *punkSFHistory)
  1357. {
  1358. return AddUrlAndNotifyCP(pwszUrl, pwszTitle, dwFlags, fWriteHistory,
  1359. poctNotify, punkSFHistory, NULL);
  1360. }
  1361. HRESULT CUrlHistory::AddUrlAndNotifyCP(
  1362. IN LPCWSTR pwszUrl, // Full URL to be added
  1363. IN LPCWSTR pwszTitle,
  1364. IN DWORD dwFlags, // Storage options
  1365. IN BOOL fWriteHistory, // Write History ShellFolder
  1366. IN IOleCommandTarget *poctNotify,
  1367. IN IUnknown *punkSFHistory,
  1368. UINT* pcodepage)
  1369. {
  1370. if (pcodepage) {
  1371. *pcodepage = CP_ACP; // this is default.
  1372. }
  1373. HRESULT hr = S_OK;
  1374. LPCWSTR pwszTitleToStore = pwszTitle;
  1375. // check to make sure we got an URL
  1376. if (!pwszUrl || !pwszUrl[0])
  1377. {
  1378. TraceMsg( TF_WARNING, "CUrlHistory::AddUrlAndNotifyCP() - pwszUrl is NULL or Empty!" );
  1379. return E_INVALIDARG;
  1380. }
  1381. if (pwszTitleToStore && 0 == StrCmpIW(pwszTitleToStore, pwszUrl))
  1382. {
  1383. // Suppress redundant title data
  1384. pwszTitleToStore = NULL;
  1385. }
  1386. CEI_PREALLOC buf;
  1387. INTERNET_CACHE_ENTRY_INFO cei = { 0 };
  1388. // Wininet URL cache only supports 8-bit ANSI, so we need to encode any characters
  1389. // which can't be converted by the system code page, in order to allow Unicode
  1390. // filenames in History. The URLs will remain in the encoded form through most of
  1391. // the History code paths, with only the display and navigation code needing to be
  1392. // aware of the UTF8
  1393. LPCTSTR pszUrlSource = pwszUrl; // points to the URL that we decide to use
  1394. TCHAR szEncodedUrl[MAX_URL_STRING];
  1395. BOOL bUsedDefaultChar;
  1396. // Find out if any of the chars will get scrambled. We can use our szEncodedUrl
  1397. // buffer to store he multibyte result because we don't actually want it
  1398. WideCharToMultiByte(CP_ACP, 0, pwszUrl, -1,
  1399. (LPSTR) szEncodedUrl, sizeof(szEncodedUrl), NULL, &bUsedDefaultChar);
  1400. StrCpyN(szEncodedUrl, pwszUrl, ARRAYSIZE(szEncodedUrl));
  1401. SHCleanupUrlForDisplay(szEncodedUrl);
  1402. pszUrlSource = szEncodedUrl;
  1403. if (bUsedDefaultChar)
  1404. {
  1405. // one or more chars couldn't be converted, so we store the UTF8 escaped string
  1406. ConvertToUtf8Escaped(szEncodedUrl, ARRAYSIZE(szEncodedUrl));
  1407. }
  1408. s_ConvertToPrefixedUrlW(pszUrlSource, buf.szPrefixedUrl, ARRAYSIZE(buf.szPrefixedUrl), &buf.pszFragment);
  1409. s_RetrievePrefixedUrlInfo(buf.szPrefixedUrl, &buf);
  1410. LPHISTDATA phdPrev = NULL;
  1411. TCHAR szTitle[MAX_PATH];
  1412. szTitle[0] = '\0';
  1413. LPINTERNET_CACHE_ENTRY_INFO pceiUrl = NULL;
  1414. //
  1415. // if there is already an entry for this Url, then we will reuse some of the
  1416. // settings. retrieve the relevant info if possible.
  1417. //
  1418. if (buf.pcei)
  1419. {
  1420. // The existing one cannot be copied since the size may vary.
  1421. // That is, the s_RetrievePrefixedUrlInfo above may allocate a larger buffer than expected.
  1422. pceiUrl = buf.pcei;
  1423. phdPrev = CHistoryData::s_GetHistoryData( pceiUrl );
  1424. if (pwszTitle==NULL && phdPrev) {
  1425. phdPrev->_GetTitle(szTitle, ARRAYSIZE(szTitle));
  1426. }
  1427. if (pcodepage && phdPrev) {
  1428. //
  1429. // NOTES: This is the best place get the codepage stored
  1430. // in this URL history.
  1431. //
  1432. const HISTEXTRA* phextCP =phdPrev->_FindExtra(PID_INTSITE_CODEPAGE);
  1433. if (phextCP && phextCP->vtExtra == VT_UI4) {
  1434. *pcodepage = *(DWORD*)phextCP->abExtra;
  1435. TraceMsg(DM_TRACE, "CUH::AddAndNotify this URL has CP=%d",
  1436. *pcodepage);
  1437. }
  1438. }
  1439. }
  1440. else
  1441. {
  1442. pceiUrl = &cei;
  1443. cei.CacheEntryType = NORMAL_CACHE_ENTRY;
  1444. ASSERT(cei.dwHeaderInfoSize == 0);
  1445. }
  1446. ASSERT( pceiUrl );
  1447. if ( ! pceiUrl )
  1448. {
  1449. TraceMsg( TF_ERROR, "CUrlHistory::AddUrlAndNotifyCP() - pceiUrl is NULL!" );
  1450. return E_FAIL;
  1451. }
  1452. //
  1453. // search for a fragment if necessary
  1454. //
  1455. if (buf.pszFragment && phdPrev)
  1456. {
  1457. if (phdPrev->_HasFragment(buf.pszFragment)) {
  1458. buf.pszFragment = NULL;
  1459. }
  1460. }
  1461. // Override the title if specified.
  1462. if (pwszTitleToStore) {
  1463. // GetDisplayableTitle puts szTitle[0] = '\0' if it's
  1464. // not displayable with shell codepage
  1465. StrCpyN(szTitle, pwszTitleToStore, ARRAYSIZE(szTitle));
  1466. }
  1467. CHistoryData* phdNew = s_GenerateHeaderInfo(
  1468. szTitle, phdPrev, buf.pszFragment, &pceiUrl->dwHeaderInfoSize);
  1469. if (phdNew)
  1470. {
  1471. pceiUrl->lpHeaderInfo = (LPTSTR)phdNew;
  1472. //
  1473. // [alanau] Background: See IE5 Bug #110378 and related.
  1474. //
  1475. // For secure URLs (https:) that respond with a cache control header (pragma: no-cache or
  1476. // cache-control: no-cache or no-store), we presume that these can contain sensitive data that
  1477. // the site did not want retained on the client machine. Therefore, we do not write a history entry
  1478. // for such sites.
  1479. //
  1480. // Previously, a check was made in CDocObjectHost::CDOHBindStatusCallback::OnObjectAvailable(), where
  1481. // the binding was queried for INTERNET_REQFLAG_CACHE_WRITE_DISABLED. This flag would be set not only
  1482. // for https: URLs but for http: URLs that contained cache-control: no-store. With Native Frames, however,
  1483. // OnObjectAvailable() is no longer called (as Trident performs the bind), so SHDOCVW doesn't have access
  1484. // to the PIB any longer. However, all we are really interested in is whether or not the URL is in cache,
  1485. // and we have a straightforward way to check that.
  1486. //
  1487. // Note that IE 5.5 has a deliberate change of behavior to write http: (non-secure) URLs that
  1488. // contain cache-control: no-store to history.
  1489. // If caller specified to write history, and the scheme is a history-enabled scheme,
  1490. //
  1491. if (fWriteHistory && !UrlIsNoHistoryW(pwszUrl))
  1492. {
  1493. // If it's https://, we have more work to do.
  1494. //
  1495. if (URL_SCHEME_HTTPS == GetUrlScheme(pwszUrl))
  1496. {
  1497. // Check the cache. If https: and in cache, add to history.
  1498. //
  1499. if (UrlIsInCache(pwszUrl))
  1500. {
  1501. phdNew->dwFlags |= PIDISF_HISTORY;
  1502. }
  1503. }
  1504. else
  1505. {
  1506. // Not https:, so turn on history flag.
  1507. //
  1508. phdNew->dwFlags |= PIDISF_HISTORY;
  1509. }
  1510. }
  1511. else
  1512. {
  1513. phdNew->dwFlags &= ~PIDISF_HISTORY; // clear the flag
  1514. }
  1515. BOOL fUpdateIcon = FALSE;
  1516. if (phdNew->dwFlags & PIDISF_RECENTLYCHANGED) {
  1517. fUpdateIcon = TRUE;
  1518. phdNew->dwFlags &= ~PIDISF_RECENTLYCHANGED;
  1519. }
  1520. if ( s_CommitUrlCacheEntry( buf.szPrefixedUrl, pceiUrl ) )
  1521. {
  1522. if (fUpdateIcon) {
  1523. TraceMsg(DM_HISTSPLAT, "CUH::AddAndNotify remove splat!");
  1524. // APPCOMPAT: This is a temporary hack to make splat update
  1525. // work as bad as previously.
  1526. Intshcut* pintshcut = new Intshcut();
  1527. if (pintshcut) {
  1528. pintshcut->SetURL(pwszUrl ,0);
  1529. s_UpdateIcon(pintshcut, PIDISF_RECENTLYCHANGED);
  1530. pintshcut->Release();
  1531. }
  1532. }
  1533. //
  1534. // When we have successfully updated the global history and
  1535. // we have updated something in the HISTDATA, update the
  1536. // date-based history as well.
  1537. //
  1538. //
  1539. // Cache IShellFolder for the history folder if we don't have
  1540. // it yet.
  1541. //
  1542. // Use the previously set PIDISF_HISTORY flag to decide whether or not to write history here too.
  1543. if (phdNew->dwFlags & PIDISF_HISTORY)
  1544. {
  1545. _WriteToHistory( buf.szPrefixedUrl, pceiUrl->ExpireTime, poctNotify, punkSFHistory );
  1546. }
  1547. }
  1548. else
  1549. {
  1550. hr = HRESULT_FROM_WIN32(GetLastError ());
  1551. }
  1552. LocalFree(phdNew);
  1553. phdNew = NULL;
  1554. }
  1555. #ifdef DEBUG
  1556. if (g_dwPrototype & 0x00000020) {
  1557. TCHAR szUrl[MAX_URL_STRING];
  1558. SHUnicodeToTChar(pwszUrl, szUrl, ARRAYSIZE(szUrl));
  1559. PROPVARIANT var = { 0 };
  1560. HRESULT hrT = GetProperty(szUrl, PID_INTSITE_SUBSCRIPTION, &var);
  1561. if (SUCCEEDED(hrT)) {
  1562. TraceMsg(DM_TRACE, "CUH::AddAndNotify got property vt=%d lVal=%x",
  1563. var.vt, var.lVal);
  1564. PropVariantClear(&var);
  1565. } else {
  1566. TraceMsg(DM_TRACE, "CUH::AddAndNotify failed to get property (%x)", hrT);
  1567. }
  1568. }
  1569. #endif
  1570. return hr;
  1571. }
  1572. HRESULT CUrlHistory::QueryUrl(
  1573. IN LPCWSTR pwszUrl,
  1574. IN DWORD dwFlags,
  1575. OUT LPSTATURL lpSTATURL
  1576. )
  1577. {
  1578. if (!pwszUrl || !pwszUrl[0])
  1579. {
  1580. return E_INVALIDARG;
  1581. }
  1582. if (lpSTATURL)
  1583. {
  1584. lpSTATURL->pwcsUrl = NULL;
  1585. lpSTATURL->pwcsTitle = NULL;
  1586. }
  1587. LPCTSTR pszFragment;
  1588. TCHAR szPrefixedUrl[MAX_URL_STRING];
  1589. s_ConvertToPrefixedUrlW(pwszUrl, szPrefixedUrl, ARRAYSIZE(szPrefixedUrl), &pszFragment);
  1590. return s_QueryUrlCommon(szPrefixedUrl, pszFragment, dwFlags, lpSTATURL);
  1591. }
  1592. HRESULT CUrlHistory::s_QueryUrlCommon(
  1593. IN LPCTSTR lpszPrefixedUrl,
  1594. LPCTSTR lpszFragment,
  1595. IN DWORD dwFlags,
  1596. OUT LPSTATURL lpSTATURL
  1597. )
  1598. /*++
  1599. Routine Description:
  1600. Checks to see if Url is a valid History item
  1601. Arguments:
  1602. pwszUrl - The URL in question.
  1603. dwFlags - Flags on the query
  1604. lpSTATURL - points to a STATURL storage structure
  1605. If this is NULL, then a S_OK means the URL was found.
  1606. Return Value:
  1607. HRESULT
  1608. Success - S_OK, Item found and STATURL filled
  1609. Failure - valid E_ code
  1610. HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) indicates the URL is not available
  1611. --*/
  1612. {
  1613. HRESULT hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  1614. LPHISTDATA phd = NULL;
  1615. CEI_PREALLOC buf;
  1616. //
  1617. // if there is no data required, and there are no fragments
  1618. // we dont need to get a copy of the CEI
  1619. //
  1620. if(!lpSTATURL && !lpszFragment)
  1621. {
  1622. if(s_IsCached(lpszPrefixedUrl))
  1623. hr = S_OK;
  1624. else
  1625. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  1626. goto quit;
  1627. }
  1628. s_RetrievePrefixedUrlInfo(lpszPrefixedUrl, &buf);
  1629. if (buf.pcei)
  1630. {
  1631. DEBUG_CODE(DWORD cbNHI = buf.pcei->dwHeaderInfoSize;)
  1632. phd = CHistoryData::s_GetHistoryData(buf.pcei);
  1633. hr = S_OK;
  1634. }
  1635. else
  1636. {
  1637. hr = HRESULT_FROM_WIN32(GetLastError ());
  1638. goto quit;
  1639. }
  1640. //
  1641. // Need to check for local anchor fragments
  1642. //
  1643. if (lpszFragment)
  1644. {
  1645. if (phd && phd->_HasFragment(lpszFragment))
  1646. {
  1647. hr = S_OK;
  1648. }
  1649. } else {
  1650. hr = S_OK;
  1651. }
  1652. // check to see if we should fill the STATURL
  1653. if (S_OK == hr && lpSTATURL) {
  1654. hr = s_GenerateSTATURL(lpszPrefixedUrl, buf.pcei, dwFlags, lpSTATURL);
  1655. }
  1656. quit:
  1657. if (S_OK != hr && lpSTATURL)
  1658. {
  1659. if (lpSTATURL->pwcsUrl)
  1660. {
  1661. LocalFree(lpSTATURL->pwcsUrl);
  1662. lpSTATURL->pwcsUrl = NULL;
  1663. }
  1664. if (lpSTATURL->pwcsTitle)
  1665. {
  1666. LocalFree(lpSTATURL->pwcsTitle);
  1667. lpSTATURL->pwcsTitle = NULL;
  1668. }
  1669. }
  1670. return hr;
  1671. }
  1672. HRESULT CUrlHistory::QueryUrlA(LPCSTR pszUrl, DWORD dwFlags, LPSTATURL lpSTATURL)
  1673. {
  1674. TCHAR szPrefixedUrl[MAX_URL_STRING];
  1675. LPCTSTR lpszFragment = NULL;
  1676. HRESULT hr = S_OK;
  1677. if (!pszUrl || !pszUrl[0]) {
  1678. return E_INVALIDARG;
  1679. }
  1680. if (lpSTATURL)
  1681. {
  1682. lpSTATURL->pwcsUrl = NULL;
  1683. lpSTATURL->pwcsTitle = NULL;
  1684. }
  1685. TCHAR szUrl[MAX_URL_STRING];
  1686. SHAnsiToUnicode(pszUrl, szUrl, ARRAYSIZE(szUrl));
  1687. CUrlHistory::s_ConvertToPrefixedUrlW(szUrl, szPrefixedUrl, ARRAYSIZE(szPrefixedUrl), &lpszFragment);
  1688. return CUrlHistory::s_QueryUrlCommon(szPrefixedUrl, lpszFragment, dwFlags, lpSTATURL);
  1689. }
  1690. HRESULT CUrlHistory::s_DeleteUrl(LPCWSTR pwszUrl, DWORD dwFlags)
  1691. {
  1692. DWORD Error = ERROR_SUCCESS;
  1693. TCHAR szPrefixedUrl[MAX_URL_STRING];
  1694. LPCTSTR lpszFragment;
  1695. BOOL fDoDelete = TRUE;
  1696. if (!pwszUrl || !pwszUrl[0]) {
  1697. return E_INVALIDARG;
  1698. }
  1699. s_ConvertToPrefixedUrlW(pwszUrl, szPrefixedUrl, ARRAYSIZE(szPrefixedUrl), &lpszFragment);
  1700. // don't delete it if its not a subscription
  1701. if (dwFlags & URLFLAG_DONT_DELETE_SUBSCRIBED) {
  1702. CEI_PREALLOC buf;
  1703. // query to find out if its a subscription
  1704. s_RetrievePrefixedUrlInfo(szPrefixedUrl, &buf);
  1705. if (buf.pcei &&
  1706. // Hack alert (chrisfra) avoid deleting subscriptions, etc!
  1707. ((buf.pcei)->ExpireTime.dwLowDateTime == DW_FOREVERLOW) &&
  1708. ((buf.pcei)->ExpireTime.dwHighDateTime == DW_FOREVERHIGH))
  1709. {
  1710. fDoDelete = FALSE;
  1711. // re-write it as a non-history item and just a subscription
  1712. CHistoryData *phdPrev = CHistoryData::s_GetHistoryData(buf.pcei);
  1713. if (phdPrev) // offset into pcei structure
  1714. {
  1715. phdPrev->dwFlags &= ~PIDISF_HISTORY;
  1716. s_CommitUrlCacheEntry(szPrefixedUrl, buf.pcei);
  1717. }
  1718. else {
  1719. // I'd rather return ERROR_OUT_OF_PAPER...
  1720. Error = ERROR_FILE_NOT_FOUND;
  1721. }
  1722. }
  1723. }
  1724. if (fDoDelete) {
  1725. if(!::DeleteUrlCacheEntry(szPrefixedUrl))
  1726. Error = GetLastError();
  1727. }
  1728. return HRESULT_FROM_WIN32(Error);
  1729. }
  1730. HRESULT CUrlHistory::DeleteUrl(LPCWSTR pwszUrl, DWORD dwFlags)
  1731. {
  1732. return s_DeleteUrl(pwszUrl, dwFlags);
  1733. }
  1734. HRESULT CUrlHistory::BindToObject (LPCWSTR pwszUrl, REFIID riid, void **ppvOut)
  1735. {
  1736. *ppvOut = NULL;
  1737. return E_NOTIMPL;
  1738. #if 0
  1739. HRESULT hr;
  1740. if(!ppvOut || !pwszUrl || !*pwszUrl)
  1741. return E_INVALIDARG;
  1742. *ppvOut = NULL;
  1743. CUrlHObj *pcuho = new CUrlHObj (this);
  1744. if (!pcuho)
  1745. return E_OUTOFMEMORY;
  1746. hr = pcuho->QueryInterface(riid, ppvOut);
  1747. pcuho->Release();
  1748. if (SUCCEEDED(hr))
  1749. {
  1750. hr = pcuho->Init(pwszUrl);
  1751. if (FAILED(hr))
  1752. {
  1753. pcuho->Release();
  1754. *ppvOut = NULL;
  1755. }
  1756. }
  1757. return hr;
  1758. #endif
  1759. }
  1760. HRESULT CUrlHistory::s_EnumUrls(IEnumSTATURL **ppEnum)
  1761. {
  1762. HRESULT hres = E_OUTOFMEMORY;
  1763. *ppEnum = NULL;
  1764. CEnumSTATURL *penum = new CEnumSTATURL();
  1765. if (penum)
  1766. {
  1767. *ppEnum = (IEnumSTATURL *)penum;
  1768. hres = S_OK;
  1769. }
  1770. return hres;
  1771. }
  1772. HRESULT CUrlHistory::EnumUrls(IEnumSTATURL **ppEnum)
  1773. {
  1774. return s_EnumUrls(ppEnum);
  1775. }
  1776. HRESULT CUrlHistory::GetProperty(LPCTSTR pszURL, PROPID pid, PROPVARIANT* pvarOut)
  1777. {
  1778. HRESULT hres = E_FAIL; // assume error
  1779. PropVariantInit(pvarOut);
  1780. CEI_PREALLOC buf;
  1781. CUrlHistory::s_ConvertToPrefixedUrlW(pszURL, buf.szPrefixedUrl, ARRAYSIZE(buf.szPrefixedUrl), &buf.pszFragment);
  1782. CUrlHistory::s_RetrievePrefixedUrlInfo(buf.szPrefixedUrl, &buf);
  1783. if (buf.pcei) {
  1784. CHistoryData* phdPrev = CHistoryData::s_GetHistoryData(buf.pcei);
  1785. if (phdPrev) {
  1786. const HISTEXTRA* phextPrev;
  1787. switch(pid) {
  1788. case PID_INTSITE_FLAGS:
  1789. pvarOut->vt = VT_UI4;
  1790. pvarOut->lVal = phdPrev->dwFlags;
  1791. hres = S_OK;
  1792. break;
  1793. case PID_INTSITE_LASTVISIT:
  1794. pvarOut->vt = VT_FILETIME;
  1795. pvarOut->filetime = buf.pcei->LastAccessTime;
  1796. hres = S_OK;
  1797. break;
  1798. case PID_INTSITE_LASTMOD:
  1799. pvarOut->vt = VT_FILETIME;
  1800. pvarOut->filetime = buf.pcei->LastModifiedTime;
  1801. hres = S_OK;
  1802. break;
  1803. case PID_INTSITE_WATCH:
  1804. pvarOut->vt = VT_UI4;
  1805. pvarOut->lVal = phdPrev->dwWatch;
  1806. hres = S_OK;
  1807. break;
  1808. case PID_INTSITE_VISITCOUNT:
  1809. pvarOut->vt = VT_UI4;
  1810. pvarOut->lVal = buf.pcei->dwHitRate;
  1811. hres = S_OK;
  1812. break;
  1813. default:
  1814. phextPrev = phdPrev->_FindExtra(pid);
  1815. LPCWSTR pwsz;
  1816. if (phextPrev) {
  1817. WCHAR wszBuf[MAX_URL_STRING];
  1818. switch(phextPrev->vtExtra) {
  1819. case VT_UI4:
  1820. case VT_I4:
  1821. pvarOut->vt = phextPrev->vtExtra;
  1822. pvarOut->lVal = *(DWORD*)phextPrev->abExtra;
  1823. hres = S_OK;
  1824. break;
  1825. case VT_LPSTR:
  1826. AnsiToUnicode((LPCSTR)phextPrev->abExtra, wszBuf, ARRAYSIZE(wszBuf));
  1827. pwsz = wszBuf;
  1828. goto Return_LPWSTR;
  1829. case VT_LPWSTR:
  1830. pwsz = (LPWSTR)phextPrev->abExtra;
  1831. Return_LPWSTR:
  1832. int cch = lstrlenW(pwsz)+1;
  1833. pvarOut->pwszVal = (LPWSTR)CoTaskMemAlloc(cch * SIZEOF(WCHAR));
  1834. if (pvarOut->pwszVal) {
  1835. StrCpyNW(pvarOut->pwszVal, pwsz, cch);
  1836. pvarOut->vt = VT_LPWSTR;
  1837. hres = S_OK;
  1838. } else {
  1839. hres = E_OUTOFMEMORY;
  1840. }
  1841. break;
  1842. }
  1843. }
  1844. break;
  1845. }
  1846. }
  1847. }
  1848. return hres;
  1849. }
  1850. //
  1851. // IEnumSTATURL methods
  1852. //
  1853. CEnumSTATURL::~CEnumSTATURL()
  1854. {
  1855. if(m_lpCEI)
  1856. {
  1857. LocalFree(m_lpCEI);
  1858. m_lpCEI = NULL;
  1859. }
  1860. if(m_hEnum)
  1861. FindCloseUrlCache(m_hEnum);
  1862. return;
  1863. }
  1864. HRESULT CEnumSTATURL::QueryInterface(REFIID riid, PVOID *ppvObj)
  1865. {
  1866. if (!ppvObj)
  1867. return E_INVALIDARG;
  1868. *ppvObj = NULL;
  1869. if (IsEqualIID(IID_IUnknown, riid))
  1870. {
  1871. *ppvObj = (IUnknown *) this;
  1872. AddRef();
  1873. return S_OK;
  1874. }
  1875. else if (IsEqualIID(IID_IEnumSTATURL, riid))
  1876. {
  1877. *ppvObj = (IEnumSTATURL *) this;
  1878. AddRef();
  1879. return S_OK;
  1880. }
  1881. return E_NOINTERFACE;
  1882. }
  1883. ULONG CEnumSTATURL::AddRef(void)
  1884. {
  1885. _cRef++;
  1886. return _cRef;
  1887. }
  1888. ULONG CEnumSTATURL::Release(void)
  1889. {
  1890. _cRef--;
  1891. if (!_cRef)
  1892. {
  1893. delete this;
  1894. return 0;
  1895. }
  1896. return _cRef;
  1897. }
  1898. HRESULT CEnumSTATURL::RetrieveFirstUrlInfo()
  1899. {
  1900. HRESULT hr = S_OK;
  1901. ASSERT(!m_lpCEI);
  1902. m_cbCEI = DEFAULT_CEI_BUFFER_SIZE;
  1903. m_lpCEI = (LPINTERNET_CACHE_ENTRY_INFO) LocalAlloc(LPTR, DEFAULT_CEI_BUFFER_SIZE);
  1904. if (!m_lpCEI)
  1905. {
  1906. hr = E_OUTOFMEMORY;
  1907. goto quit;
  1908. }
  1909. while (TRUE)
  1910. {
  1911. m_hEnum = FindFirstUrlCacheEntryBinary(_szPrefixedUrl,
  1912. m_lpCEI,
  1913. &m_cbCEI);
  1914. if (!m_hEnum)
  1915. {
  1916. DWORD Error = GetLastError ();
  1917. LocalFree(m_lpCEI);
  1918. m_lpCEI = NULL;
  1919. if (Error == ERROR_INSUFFICIENT_BUFFER)
  1920. {
  1921. m_lpCEI = (LPINTERNET_CACHE_ENTRY_INFO) LocalAlloc(LPTR, m_cbCEI);
  1922. if (!m_lpCEI)
  1923. {
  1924. hr = E_OUTOFMEMORY;
  1925. break;
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if (ERROR_NO_MORE_ITEMS == Error)
  1931. hr = S_FALSE;
  1932. else
  1933. hr = HRESULT_FROM_WIN32(Error);
  1934. break;
  1935. }
  1936. }
  1937. else break;
  1938. }
  1939. quit:
  1940. m_cbCEI = (DWORD)max(m_cbCEI, DEFAULT_CEI_BUFFER_SIZE);
  1941. return hr;
  1942. }
  1943. // This function should not becaused if the previous call failed
  1944. // and ::Reset() was never called.
  1945. HRESULT CEnumSTATURL::RetrieveNextUrlInfo()
  1946. {
  1947. HRESULT hr = S_OK;
  1948. BOOL ok;
  1949. ASSERT(m_hEnum);
  1950. while (TRUE)
  1951. {
  1952. ok = FindNextUrlCacheEntryBinary(m_hEnum,
  1953. m_lpCEI,
  1954. &m_cbCEI);
  1955. if (!ok)
  1956. {
  1957. DWORD Error = GetLastError ();
  1958. if (m_lpCEI)
  1959. {
  1960. LocalFree(m_lpCEI);
  1961. m_lpCEI = NULL;
  1962. }
  1963. if (Error == ERROR_INSUFFICIENT_BUFFER)
  1964. {
  1965. m_lpCEI = (LPINTERNET_CACHE_ENTRY_INFO) LocalAlloc(LPTR, m_cbCEI);
  1966. if (!m_lpCEI)
  1967. {
  1968. hr = E_OUTOFMEMORY;
  1969. break;
  1970. }
  1971. }
  1972. else
  1973. {
  1974. if (ERROR_NO_MORE_ITEMS == Error)
  1975. hr = S_FALSE;
  1976. else
  1977. hr = HRESULT_FROM_WIN32(Error);
  1978. break;
  1979. }
  1980. }
  1981. else break;
  1982. }
  1983. m_cbCEI = (DWORD)max(m_cbCEI, DEFAULT_CEI_BUFFER_SIZE);
  1984. return hr;
  1985. }
  1986. HRESULT CEnumSTATURL::Next(ULONG celt, LPSTATURL rgelt, ULONG * pceltFetched)
  1987. /*++
  1988. Routine Description:
  1989. Searches through the History looking for URLs that match the search pattern,
  1990. and copies the STATURL into the buffer.
  1991. Arguments:
  1992. Return Value:
  1993. --*/
  1994. {
  1995. HRESULT hr = S_OK;
  1996. BOOL found = FALSE;
  1997. LPHISTDATA phd = NULL;
  1998. if(pceltFetched)
  1999. *pceltFetched = 0;
  2000. if(!celt)
  2001. goto quit;
  2002. if (!m_hEnum)
  2003. {
  2004. //must handle new enumerator
  2005. CUrlHistory::s_ConvertToPrefixedUrlW(m_poszFilter, _szPrefixedUrl, ARRAYSIZE(_szPrefixedUrl), &m_lpszFragment);
  2006. //loop until we get our first handle or bag out
  2007. hr = RetrieveFirstUrlInfo();
  2008. if (S_OK != hr || !m_lpCEI)
  2009. goto quit;
  2010. m_cchPrefixedUrl = lstrlen(_szPrefixedUrl);
  2011. while(StrCmpN(_szPrefixedUrl, m_lpCEI->lpszSourceUrlName, m_cchPrefixedUrl))
  2012. {
  2013. hr = RetrieveNextUrlInfo();
  2014. if(S_OK != hr || !m_lpCEI)
  2015. goto quit;
  2016. }
  2017. }
  2018. else
  2019. {
  2020. do
  2021. {
  2022. hr = RetrieveNextUrlInfo();
  2023. if (S_OK != hr || !m_lpCEI)
  2024. goto quit;
  2025. } while(StrCmpN(_szPrefixedUrl, m_lpCEI->lpszSourceUrlName, m_cchPrefixedUrl));
  2026. }
  2027. hr = CUrlHistory::s_GenerateSTATURL(NULL, m_lpCEI, m_dwFilter, rgelt);
  2028. if(SUCCEEDED(hr) && pceltFetched)
  2029. (*pceltFetched)++;
  2030. quit:
  2031. if (pceltFetched) {
  2032. ASSERT((0 == *pceltFetched && (S_FALSE == hr || FAILED(hr))) ||
  2033. (*pceltFetched && S_OK == hr));
  2034. }
  2035. return hr;
  2036. }
  2037. HISTEXTRA* CHistoryData::CopyExtra(HISTEXTRA* phextCur) const
  2038. {
  2039. const HISTEXTRA* phext;
  2040. for (phext = _GetExtra();
  2041. phext && !phext->IsTerminator();
  2042. phext = phext->GetNextFast())
  2043. {
  2044. if (phext->vtExtra != VT_EMPTY) {
  2045. TraceMsg(DM_HISTEXTRA, "CHD::CopyExtra copying vt=%d id=%d %d bytes",
  2046. phext->vtExtra, phext->idExtra, phext->cbExtra);
  2047. memcpy(phextCur, phext, phext->cbExtra);
  2048. phextCur = phextCur->GetNextFastForSave();
  2049. } else {
  2050. TraceMsg(DM_HISTEXTRA, "CHD::CopyExtra skipping vt=%d id=%d %d bytes",
  2051. phext->vtExtra, phext->idExtra, phext->cbExtra);
  2052. }
  2053. }
  2054. return phextCur;
  2055. }
  2056. CHistoryData* CHistoryData::s_AllocateHeaderInfo(UINT cbExtra, const HISTDATA* phdPrev, ULONG* pcbTotal)
  2057. {
  2058. DWORD cbTotal = SIZEOF(HISTDATA) + SIZEOF(DWORD) + cbExtra;
  2059. LPHISTDATA phdNew = (LPHISTDATA)LocalAlloc(LPTR, cbTotal);
  2060. if (phdNew) {
  2061. if (phdPrev) {
  2062. *phdNew = *phdPrev; // Copy all the field
  2063. }
  2064. phdNew->cbSize = SIZEOF(HISTDATA);
  2065. phdNew->cbVer = HISTDATA_VER;
  2066. *pcbTotal = cbTotal;
  2067. }
  2068. return phdNew;
  2069. }
  2070. //
  2071. // Returns the total size of extra data (exclude VT_EMPTY)
  2072. //
  2073. UINT CHistoryData::GetTotalExtraSize() const
  2074. {
  2075. const HISTEXTRA* phext;
  2076. UINT cbTotal = 0;
  2077. for (phext = _GetExtra();
  2078. phext && !phext->IsTerminator();
  2079. phext = phext->GetNextFast())
  2080. {
  2081. if (phext->vtExtra != VT_EMPTY) {
  2082. cbTotal += phext->cbExtra;
  2083. }
  2084. }
  2085. return cbTotal;
  2086. }
  2087. HRESULT CEnumSTATURL::Skip(ULONG celt)
  2088. {
  2089. return E_NOTIMPL;
  2090. }
  2091. HRESULT CEnumSTATURL::Reset(void)
  2092. {
  2093. if(m_hEnum)
  2094. {
  2095. FindCloseUrlCache(m_hEnum);
  2096. m_hEnum = NULL;
  2097. }
  2098. if(m_poszFilter)
  2099. {
  2100. LocalFree(m_poszFilter);
  2101. m_poszFilter = NULL;
  2102. }
  2103. if(m_lpCEI)
  2104. {
  2105. LocalFree(m_lpCEI);
  2106. m_lpCEI = NULL;
  2107. }
  2108. m_dwFilter = 0;
  2109. return S_OK;
  2110. }
  2111. HRESULT CEnumSTATURL::Clone(IEnumSTATURL ** ppenum)
  2112. {
  2113. return E_NOTIMPL;
  2114. }
  2115. // IEnumSTATURL methods
  2116. HRESULT CEnumSTATURL::SetFilter(LPCWSTR poszFilter, DWORD dwFlags)
  2117. {
  2118. HRESULT hr = S_OK;
  2119. if(poszFilter)
  2120. {
  2121. m_poszFilter = StrDupW(poszFilter);
  2122. if (!m_poszFilter)
  2123. {
  2124. hr = E_OUTOFMEMORY;
  2125. goto quit;
  2126. }
  2127. }
  2128. m_dwFilter = dwFlags;
  2129. quit:
  2130. return hr;
  2131. }
  2132. const HISTEXTRA * CHistoryData::_FindExtra(UINT idExtra) const
  2133. {
  2134. for (const HISTEXTRA* phext = _GetExtra();
  2135. phext && !phext->IsTerminator();
  2136. phext = phext->GetNextFastForSave())
  2137. {
  2138. if (phext->idExtra == idExtra) {
  2139. return phext;
  2140. }
  2141. }
  2142. return NULL;
  2143. }
  2144. CHistoryData* CHistoryData::s_GetHistoryData(LPINTERNET_CACHE_ENTRY_INFO lpCEI)
  2145. {
  2146. CHistoryData* phd = (CHistoryData*)lpCEI->lpHeaderInfo;
  2147. if (phd && phd->_IsOldHistory()) {
  2148. TraceMsg(DM_TRACE, "CHistoryData::GetHistoryData found old header. Ignore");
  2149. phd = NULL;
  2150. }
  2151. if (phd && phd->cbVer != HISTDATA_VER) {
  2152. TraceMsg(DM_TRACE, "CHistoryData::GetHistoryData found old header (%d). Ignore",
  2153. phd->cbVer);
  2154. phd = NULL;
  2155. }
  2156. return phd;
  2157. }
  2158. BOOL CHistoryData::_HasFragment(LPCTSTR pszFragment) const
  2159. {
  2160. BOOL fHas = FALSE;
  2161. const HISTEXTRA* phext = _FindExtra(PID_INTSITE_FRAGMENT);
  2162. if (phext) {
  2163. for (LPCTSTR psz=(LPCTSTR)(phext->abExtra); *psz ; psz += lstrlen(psz)+1) {
  2164. if (StrCmp(psz, pszFragment)==0) {
  2165. fHas = TRUE;
  2166. break;
  2167. }
  2168. }
  2169. }
  2170. return fHas;
  2171. }
  2172. void CHistoryData::_GetTitle(LPTSTR szTitle, UINT cchMax) const
  2173. {
  2174. szTitle[0] = '\0';
  2175. const HISTEXTRA* phext = _FindExtra(PID_INTSITE_TITLE);
  2176. if (phext && phext->vtExtra == VT_LPSTR) {
  2177. StrCpyN(szTitle, (LPCTSTR)phext->abExtra, cchMax);
  2178. }
  2179. }
  2180. #ifdef USE_NEW_HISTORYDATA
  2181. #include "urlprop2.cpp"
  2182. #endif // USE_NEW_HISTORYDATA