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.

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