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.

1436 lines
42 KiB

  1. // PrivacyImport.cpp - handles parsing and import of privacy preferences
  2. #include "priv.h"
  3. #include "resource.h"
  4. #include <mluisupp.h>
  5. #include "SmallUtil.hpp"
  6. #include "PrivacyImport.hpp"
  7. #define MAX_TOKEN_SIZE 64
  8. #define NUM_OF_ZONES (1 + IDS_PRIVACYXML6_COOKIEZONE_LAST - IDS_PRIVACYXML6_COOKIEZONE_FIRST)
  9. #define NUM_OF_ACTIONS (1 + IDS_PRIVACYXML6_ACTION_LAST - IDS_PRIVACYXML6_ACTION_FIRST)
  10. //
  11. // DeleteCacheCookies was copy'n'pasted from Cachecpl.cpp
  12. //
  13. // Any changes to either version should probably be transfered to both.
  14. //
  15. BOOL DeleteCacheCookies()
  16. {
  17. BOOL bRetval = TRUE;
  18. DWORD dwEntrySize, dwLastEntrySize;
  19. LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntry;
  20. HANDLE hCacheDir = NULL;
  21. dwEntrySize = dwLastEntrySize = MAX_CACHE_ENTRY_INFO_SIZE;
  22. lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFOA) new BYTE[dwEntrySize];
  23. if( lpCacheEntry == NULL)
  24. {
  25. bRetval = FALSE;
  26. goto Exit;
  27. }
  28. lpCacheEntry->dwStructSize = dwEntrySize;
  29. Again:
  30. if (!(hCacheDir = FindFirstUrlCacheEntryA("cookie:",lpCacheEntry,&dwEntrySize)))
  31. {
  32. delete [] lpCacheEntry;
  33. switch(GetLastError())
  34. {
  35. case ERROR_NO_MORE_ITEMS:
  36. goto Exit;
  37. case ERROR_INSUFFICIENT_BUFFER:
  38. lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFOA)
  39. new BYTE[dwEntrySize];
  40. if( lpCacheEntry == NULL)
  41. {
  42. bRetval = FALSE;
  43. goto Exit;
  44. }
  45. lpCacheEntry->dwStructSize = dwLastEntrySize = dwEntrySize;
  46. goto Again;
  47. default:
  48. bRetval = FALSE;
  49. goto Exit;
  50. }
  51. }
  52. do
  53. {
  54. if (lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY)
  55. DeleteUrlCacheEntryA(lpCacheEntry->lpszSourceUrlName);
  56. dwEntrySize = dwLastEntrySize;
  57. Retry:
  58. if (!FindNextUrlCacheEntryA(hCacheDir,lpCacheEntry, &dwEntrySize))
  59. {
  60. delete [] lpCacheEntry;
  61. switch(GetLastError())
  62. {
  63. case ERROR_NO_MORE_ITEMS:
  64. goto Exit;
  65. case ERROR_INSUFFICIENT_BUFFER:
  66. lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFOA)
  67. new BYTE[dwEntrySize];
  68. if( lpCacheEntry == NULL)
  69. {
  70. bRetval = FALSE;
  71. goto Exit;
  72. }
  73. lpCacheEntry->dwStructSize = dwLastEntrySize = dwEntrySize;
  74. goto Retry;
  75. default:
  76. bRetval = FALSE;
  77. goto Exit;
  78. }
  79. }
  80. }
  81. while (TRUE);
  82. Exit:
  83. if (hCacheDir)
  84. FindCloseUrlCache(hCacheDir);
  85. return bRetval;
  86. }
  87. //*****************************************************************************************
  88. //*****************************************************************************************
  89. //
  90. // CPrivacyXMLResourceStrings
  91. //
  92. // just stores the Privacy format XML strings..
  93. class CPrivacyXMLResourceStrings
  94. {
  95. WCHAR m_szResourceString[IDS_PRIVACYXML6_LASTPRIVACYXML6
  96. -IDS_PRIVACYXML6 + 1] [MAX_TOKEN_SIZE];
  97. public:
  98. LPCWSTR GetResourceString( int iIndex) { return m_szResourceString[ iIndex - IDS_PRIVACYXML6];};
  99. BOOL Initialize()
  100. {
  101. for( int i = 0;
  102. i < ARRAYSIZE(m_szResourceString);
  103. i++)
  104. {
  105. if( 0 == MLLoadStringW( IDS_PRIVACYXML6 + i,
  106. m_szResourceString[i], MAX_TOKEN_SIZE))
  107. return FALSE;
  108. }
  109. return TRUE;
  110. }
  111. };
  112. //*****************************************************************************************
  113. //*****************************************************************************************
  114. //
  115. // CParseAccumulation is a class that stores the results of parsing an XML privacy
  116. //preference file. These results can then be sent to the system after parsing
  117. //successfully completes.
  118. //
  119. class CParseAccumulation : public CPrivacyXMLResourceStrings
  120. {
  121. public:
  122. bool m_fFlushCookies;
  123. bool m_fFlushSiteList;
  124. bool m_fLeashCookies;
  125. struct SPerZonePartyPreferences
  126. {
  127. UINT m_uiNoPolicyDefault;
  128. UINT m_uiNoRuleDefault;
  129. bool m_fAlwaysAllowSession;
  130. CGrowingString m_cZonePreference;
  131. };
  132. struct SPerZonePreferences
  133. {
  134. UINT m_uiZoneID;
  135. bool m_fSetZone;
  136. SPerZonePartyPreferences m_party[2]; // first party = 0, third party = 1
  137. };
  138. SPerZonePreferences m_zonePref[NUM_OF_ZONES];
  139. CQueueSortOf m_queueSitesToAccept;
  140. CQueueSortOf m_queueSitesToReject;
  141. ~CParseAccumulation()
  142. {
  143. void* iterator;
  144. iterator = NULL;
  145. // free up the names sites to be accepted
  146. while( NULL != (iterator = m_queueSitesToAccept.StepEnumerate( iterator)))
  147. {
  148. SysFreeString( (BSTR)m_queueSitesToAccept.Get( iterator));
  149. }
  150. iterator = NULL;
  151. // free up the names of sites to be rejected
  152. while( NULL != (iterator = m_queueSitesToReject.StepEnumerate( iterator)))
  153. {
  154. SysFreeString( (BSTR)m_queueSitesToReject.Get( iterator));
  155. }
  156. }
  157. BOOL Initialize()
  158. {
  159. m_fFlushCookies = false;
  160. m_fFlushSiteList = false;
  161. m_fLeashCookies = true;
  162. for( int i = 0; i < ARRAYSIZE( m_zonePref); i++)
  163. {
  164. m_zonePref[i].m_uiZoneID = 0;
  165. m_zonePref[i].m_fSetZone = false;
  166. m_zonePref[i].m_party[0].m_uiNoPolicyDefault = 0;
  167. m_zonePref[i].m_party[0].m_uiNoRuleDefault = 0;
  168. m_zonePref[i].m_party[0].m_fAlwaysAllowSession = false;
  169. m_zonePref[i].m_party[1].m_uiNoPolicyDefault = 0;
  170. m_zonePref[i].m_party[1].m_uiNoRuleDefault = 0;
  171. m_zonePref[i].m_party[1].m_fAlwaysAllowSession = false;
  172. }
  173. return CPrivacyXMLResourceStrings::Initialize();
  174. }
  175. BOOL AddSiteRule( BSTR bstrDomain, DWORD uiAction)
  176. {
  177. if( uiAction == IDS_PRIVACYXML6_ACTION_ACCEPT)
  178. return m_queueSitesToAccept.InsertAtEnd( (void*)bstrDomain) ? TRUE : FALSE;
  179. else if( uiAction == IDS_PRIVACYXML6_ACTION_REJECT)
  180. return m_queueSitesToReject.InsertAtEnd( (void*)bstrDomain) ? TRUE : FALSE;
  181. else
  182. return FALSE;
  183. }
  184. long GetZoneFromResource( UINT uiZoneResource)
  185. {
  186. switch(uiZoneResource)
  187. {
  188. case IDS_PRIVACYXML6_COOKIEZONE_INTERNET:
  189. return URLZONE_INTERNET;
  190. case IDS_PRIVACYXML6_COOKIEZONE_INTRANET:
  191. return URLZONE_INTRANET;
  192. case IDS_PRIVACYXML6_COOKIEZONE_TRUSTED:
  193. return URLZONE_TRUSTED;
  194. default:
  195. return -1;
  196. }
  197. }
  198. BOOL DoAccumulation()
  199. {
  200. BOOL returnValue = FALSE;
  201. long i;
  202. void* iterator;
  203. if( m_fFlushSiteList)
  204. InternetClearAllPerSiteCookieDecisions();
  205. DWORD dwSetValue = m_fLeashCookies ? TRUE : FALSE;
  206. SHSetValue(HKEY_CURRENT_USER, REGSTR_PATH_INTERNET_SETTINGS, REGSTR_VAL_PRIVLEASHLEGACY,
  207. REG_DWORD, &dwSetValue, sizeof(DWORD));
  208. if( m_fFlushCookies)
  209. DeleteCacheCookies();
  210. // Set compact policy response rules for each zone
  211. for( i = 0; i < ARRAYSIZE(m_zonePref); i++)
  212. {
  213. if( !m_zonePref[i].m_fSetZone)
  214. continue;
  215. if( ERROR_SUCCESS !=
  216. PrivacySetZonePreferenceW(
  217. GetZoneFromResource(m_zonePref[i].m_uiZoneID),
  218. PRIVACY_TYPE_FIRST_PARTY, PRIVACY_TEMPLATE_CUSTOM,
  219. m_zonePref[i].m_party[0].m_cZonePreference.m_szString))
  220. {
  221. goto doneDoAccumulation;
  222. }
  223. if( ERROR_SUCCESS !=
  224. PrivacySetZonePreferenceW(
  225. GetZoneFromResource(m_zonePref[i].m_uiZoneID),
  226. PRIVACY_TYPE_THIRD_PARTY, PRIVACY_TEMPLATE_CUSTOM,
  227. m_zonePref[i].m_party[1].m_cZonePreference.m_szString))
  228. {
  229. goto doneDoAccumulation;
  230. }
  231. }
  232. // If any per-site rules were specified, we modify the persite list..
  233. if( NULL != m_queueSitesToAccept.StepEnumerate(NULL)
  234. || NULL != m_queueSitesToReject.StepEnumerate(NULL))
  235. {
  236. // First we clear all existing per site rules..
  237. InternetClearAllPerSiteCookieDecisions();
  238. // Then we add the Accept per-site exceptions
  239. iterator = NULL;
  240. while( NULL != (iterator = m_queueSitesToAccept.StepEnumerate( iterator)))
  241. {
  242. InternetSetPerSiteCookieDecision( (LPCWSTR)m_queueSitesToAccept.Get( iterator), COOKIE_STATE_ACCEPT);
  243. }
  244. // and then the Reject per-site exceptions
  245. iterator = NULL;
  246. while( NULL != (iterator = m_queueSitesToReject.StepEnumerate( iterator)))
  247. {
  248. InternetSetPerSiteCookieDecision( (LPCWSTR)m_queueSitesToReject.Get( iterator), COOKIE_STATE_REJECT);
  249. }
  250. }
  251. returnValue = TRUE;
  252. doneDoAccumulation:
  253. return returnValue;
  254. }
  255. };
  256. int FindP3PPolicySymbolWrap( LPCWSTR szSymbol)
  257. {
  258. char szSymBuffer[MAX_PATH];
  259. int length = lstrlen( szSymbol);
  260. if( length + 1 > ARRAYSIZE( szSymBuffer))
  261. return -1;
  262. szSymBuffer[0] = '\0';
  263. SHTCharToAnsi( szSymbol, szSymBuffer, ARRAYSIZE( szSymBuffer));
  264. return FindP3PPolicySymbol( szSymBuffer);
  265. }
  266. //*****************************************************************************
  267. //*****************************************************************************
  268. //
  269. // XML Parsing functions
  270. //
  271. // These functions help parsing XML.
  272. //
  273. // GetNextToken looks at the node you are at (*ppCurrentNode) and tests
  274. //if it has a particular tag value. If it does, *ppOutToken is set to
  275. //be a pointer to the node, *ppCurrentNode is advanced to the next node,
  276. //and *pfFoundToken is set to TRUE. If the *ppCurrentNode doesn't have
  277. //the target tag, the *pfFoundToken is FALSE, *ppCurrentNode is unchanged,
  278. //and *ppOutToken is NULL.
  279. // If *ppCurrentNode is the last node, *ppCurrentNode would be advanced
  280. //to NULL when finding the target token.
  281. BOOL GetNextToken( IN OUT IXMLDOMNode ** ppCurrentNode, IN LPCWSTR szTargetToken,
  282. OUT BOOL * pfFoundToken, OUT IXMLDOMNode ** ppOutTokenNode)
  283. {
  284. BOOL returnValue = FALSE;
  285. HRESULT hr;
  286. BSTR bstrNodeName = NULL;
  287. VARIANT var;
  288. VariantInit( &var);
  289. if( *ppCurrentNode == NULL)
  290. {
  291. *pfFoundToken = FALSE;
  292. *ppOutTokenNode = NULL;
  293. returnValue = TRUE;
  294. goto doneGetNextToken;
  295. }
  296. hr = (*ppCurrentNode)->get_nodeName( &bstrNodeName);
  297. if( FAILED(hr))
  298. goto doneGetNextToken;
  299. if( 0 != StrCmpW( szTargetToken, bstrNodeName))
  300. {
  301. *pfFoundToken = FALSE;
  302. *ppOutTokenNode = NULL;
  303. returnValue = TRUE;
  304. }
  305. else
  306. {
  307. IXMLDOMNode * pNode = NULL;
  308. hr = (*ppCurrentNode)->get_nextSibling( &pNode);
  309. if( FAILED(hr))
  310. goto doneGetNextToken;
  311. *ppOutTokenNode = *ppCurrentNode;
  312. if( hr == S_OK)
  313. *ppCurrentNode = pNode;
  314. else
  315. *ppCurrentNode = NULL;
  316. *pfFoundToken = TRUE;
  317. returnValue = TRUE;
  318. }
  319. doneGetNextToken:
  320. if( bstrNodeName != NULL)
  321. SysFreeString( bstrNodeName);
  322. return returnValue;
  323. }
  324. // GeAttributes retrieves the XML attributes for a node. The attributes to
  325. //be fetched are passed in in array aszName, of length iStringCount. The results
  326. //are returned as VT_BSTRs on success of VT_EMPTY on failure. The total number
  327. //of attributes for the node is also returned (*plAllAttributesCount).
  328. BOOL GetAttributes(
  329. IN IXMLDOMNode * pNode, IN LPCWSTR * aszName, IN long iStringCount,
  330. OUT VARIANT * aAttributeVariants, OUT long * plAllAttributesCount)
  331. {
  332. BOOL returnValue = FALSE;
  333. HRESULT hr;
  334. BSTR bstrAttributeName = NULL;
  335. IXMLDOMNamedNodeMap * pAttributes = NULL;
  336. IXMLDOMNode * pTempNode = NULL;
  337. hr = pNode->get_attributes( &pAttributes);
  338. if( FAILED(hr))
  339. goto doneGetAttributes;
  340. if( plAllAttributesCount != NULL)
  341. {
  342. hr = pAttributes->get_length( plAllAttributesCount);
  343. if( FAILED(hr))
  344. goto doneGetAttributes;
  345. }
  346. for( int i = 0; i < iStringCount; i++)
  347. {
  348. if( pTempNode != NULL)
  349. pTempNode->Release();
  350. pTempNode = NULL;
  351. if( bstrAttributeName != NULL)
  352. SysFreeString( bstrAttributeName);
  353. bstrAttributeName = NULL;
  354. aAttributeVariants[i].vt = VT_EMPTY;
  355. aAttributeVariants[i].bstrVal = NULL;
  356. bstrAttributeName = SysAllocString( aszName[i]);
  357. if( bstrAttributeName == NULL)
  358. continue;
  359. // test if the ith attribute was set
  360. hr = pAttributes->getNamedItem( bstrAttributeName, &pTempNode);
  361. if( FAILED(hr) || pTempNode == NULL)
  362. continue;
  363. // get the value
  364. hr = pTempNode->get_nodeTypedValue( &aAttributeVariants[i]);
  365. // convert the value to a BSTR.
  366. hr = VariantChangeType( &aAttributeVariants[i], &aAttributeVariants[i], NULL, VT_BSTR);
  367. if( FAILED(hr) || aAttributeVariants[i].bstrVal == NULL)
  368. {
  369. VariantClear( &aAttributeVariants[i]);
  370. aAttributeVariants[i].vt = VT_EMPTY;
  371. aAttributeVariants[i].bstrVal = NULL;
  372. }
  373. }
  374. returnValue = TRUE;
  375. doneGetAttributes:
  376. if( bstrAttributeName != NULL)
  377. SysFreeString( bstrAttributeName);
  378. if( pAttributes != NULL)
  379. pAttributes->Release();
  380. if( pTempNode != NULL)
  381. pTempNode->Release();
  382. return returnValue;
  383. }
  384. // The actions by GetActionByResource are formatted for
  385. //PrivacySetZonePreference, like /token=n/ where n is the action.
  386. LPCWSTR GetActionByResource( UINT uiActionResource)
  387. {
  388. switch( uiActionResource)
  389. {
  390. case IDS_PRIVACYXML6_ACTION_ACCEPT:
  391. return L"=a/";
  392. case IDS_PRIVACYXML6_ACTION_PROMPT:
  393. return L"=p/";
  394. case IDS_PRIVACYXML6_ACTION_FIRSTPARTY:
  395. return L"=l/";
  396. case IDS_PRIVACYXML6_ACTION_SESSION:
  397. return L"=d/";
  398. case IDS_PRIVACYXML6_ACTION_REJECT:
  399. return L"=r/";
  400. default:
  401. ASSERT(0);
  402. return L"r/";
  403. }
  404. }
  405. LPCWSTR GetShortActionByResource( UINT uiActionResource)
  406. {
  407. switch( uiActionResource)
  408. {
  409. case IDS_PRIVACYXML6_ACTION_ACCEPT:
  410. return L"=a";
  411. case IDS_PRIVACYXML6_ACTION_PROMPT:
  412. return L"=p";
  413. case IDS_PRIVACYXML6_ACTION_FIRSTPARTY:
  414. return L"=l";
  415. case IDS_PRIVACYXML6_ACTION_SESSION:
  416. return L"=d";
  417. case IDS_PRIVACYXML6_ACTION_REJECT:
  418. return L"=r";
  419. default:
  420. ASSERT(0);
  421. return L"r";
  422. }
  423. }
  424. // GetChildrenByName takes an XML node and returns all the subnodes
  425. //with a particular name.
  426. BOOL GetChildrenByName( IN IXMLDOMNode * pNode, IN LPCWSTR szName,
  427. OUT IXMLDOMNodeList ** ppOutNodeList, OUT long * plCount)
  428. {
  429. BOOL returnValue = FALSE;
  430. HRESULT hr;
  431. BSTR bstr = NULL;
  432. IXMLDOMNodeList * pSelectedNodes;
  433. if( NULL == (bstr = SysAllocString( szName)))
  434. goto doneGetChildrenByName;
  435. hr = pNode->selectNodes( bstr, &pSelectedNodes);
  436. if( FAILED(hr))
  437. goto doneGetChildrenByName;
  438. if( plCount != NULL)
  439. {
  440. hr = pSelectedNodes->get_length( plCount);
  441. if( FAILED(hr))
  442. goto doneGetChildrenByName;
  443. }
  444. returnValue = TRUE;
  445. *ppOutNodeList = pSelectedNodes;
  446. pSelectedNodes = NULL;
  447. doneGetChildrenByName:
  448. if( bstr != NULL)
  449. SysFreeString( bstr);
  450. if( pSelectedNodes != NULL)
  451. pSelectedNodes->Release();
  452. return returnValue;
  453. }
  454. //*****************************************************************************
  455. //*****************************************************************************
  456. //
  457. // XML preference parsing functions
  458. //
  459. // These functions are specific to the v6 XML format of privacy preferences
  460. //
  461. // To make sense of these functions, their easiest to look at looking at
  462. //the bottom function first, then moving up to the next function.
  463. // parses <if expr="rule" action="act">
  464. // where rule is like " token & ! token" and act is like "accept"
  465. BOOL ParseIfRule( IN IXMLDOMNode* pIfNode,
  466. CParseAccumulation::SPerZonePartyPreferences* pAccumParty,
  467. CParseAccumulation& thisAccum)
  468. {
  469. BOOL returnValue = FALSE;
  470. LONG lTemp;
  471. UINT uiTemp;
  472. VARIANT avarRule[2];
  473. for( lTemp = 0; lTemp < ARRAYSIZE( avarRule); lTemp++)
  474. VariantInit( &avarRule[lTemp]);
  475. LPCWSTR aszRuleAttributes[2] =
  476. { thisAccum.GetResourceString(IDS_PRIVACYXML6_EXPR),
  477. thisAccum.GetResourceString(IDS_PRIVACYXML6_ACTION)};
  478. if( TRUE != GetAttributes(
  479. pIfNode, aszRuleAttributes, ARRAYSIZE(aszRuleAttributes),
  480. avarRule, &lTemp)
  481. || lTemp != 2
  482. || avarRule[0].vt == VT_EMPTY
  483. || avarRule[1].vt == VT_EMPTY)
  484. {
  485. goto doneParseIfRule;
  486. }
  487. // determine the action
  488. UINT uiActionResource;
  489. uiActionResource = 0;
  490. for( uiTemp = IDS_PRIVACYXML6_ACTION_FIRST;
  491. uiTemp <= IDS_PRIVACYXML6_ACTION_LAST;
  492. uiTemp++)
  493. {
  494. if( 0 == StrCmp( avarRule[1].bstrVal, thisAccum.GetResourceString(uiTemp)))
  495. uiActionResource = uiTemp;
  496. }
  497. if( uiActionResource == 0)
  498. goto doneParseIfRule;
  499. // Write the beginning of the next rule " /"
  500. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L" /"))
  501. goto doneParseIfRule;
  502. // Write the rule expression formatted for GetZoneFromResource
  503. LPWSTR pCursor, pEndCursor;
  504. pCursor = avarRule[0].bstrVal;
  505. bool fContinue, fNegated;
  506. fContinue = true;
  507. while( fContinue)
  508. {
  509. while( *pCursor == L' ')
  510. pCursor++;
  511. fNegated = false;
  512. while( *pCursor == L'!')
  513. {
  514. fNegated = !fNegated;
  515. pCursor++;
  516. while( *pCursor == L' ')
  517. pCursor++;
  518. }
  519. if( fNegated)
  520. {
  521. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L"!"))
  522. goto doneParseIfRule;
  523. }
  524. while( *pCursor == L' ')
  525. pCursor++;
  526. pEndCursor = pCursor;
  527. while( *pEndCursor != L'\0' && *pEndCursor != L',' && *pEndCursor != L' ')
  528. {
  529. pEndCursor++;
  530. }
  531. WCHAR szToken[10];
  532. if( pEndCursor == pCursor
  533. || pEndCursor - pCursor > ARRAYSIZE(szToken)-1)
  534. {
  535. goto doneParseIfRule;
  536. }
  537. StrCpyNW( szToken, pCursor, (int)(pEndCursor-pCursor+1));
  538. szToken[ pEndCursor-pCursor] = L'\0';
  539. if( -1 == FindP3PPolicySymbolWrap( szToken))
  540. goto doneParseIfRule;
  541. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(szToken))
  542. goto doneParseIfRule;
  543. pCursor = pEndCursor;
  544. while( *pCursor == L' ')
  545. pCursor++;
  546. fContinue = false;
  547. if( *pCursor == L',')
  548. {
  549. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L"&"))
  550. goto doneParseIfRule;
  551. fContinue = true;
  552. pCursor++;
  553. }
  554. }
  555. while( *pCursor == L' ')
  556. pCursor++;
  557. if( *pCursor != L'\0')
  558. goto doneParseIfRule;
  559. // Write the ending of the next rule "=action/"
  560. if( TRUE != pAccumParty->m_cZonePreference.AppendToString( GetActionByResource(
  561. uiActionResource)))
  562. {
  563. goto doneParseIfRule;
  564. }
  565. returnValue = TRUE;
  566. doneParseIfRule:
  567. for( lTemp = 0; lTemp < ARRAYSIZE( avarRule); lTemp++)
  568. VariantClear( &avarRule[lTemp]);
  569. return returnValue;
  570. }
  571. // parses <firstParty ...> or <thirdParty ...> elements
  572. BOOL ParsePartyBlock( IN IXMLDOMNode* pPartyNode,
  573. CParseAccumulation::SPerZonePartyPreferences* pAccumParty,
  574. CParseAccumulation& thisAccum)
  575. {
  576. BOOL returnValue = FALSE;
  577. long lTemp;
  578. UINT uiTemp;
  579. HRESULT hr;
  580. IXMLDOMNode * pCurrentNode = NULL;
  581. IXMLDOMNode * pRuleNode = NULL;
  582. VARIANT avarAttributes[3];
  583. for( lTemp = 0; lTemp < ARRAYSIZE( avarAttributes); lTemp++)
  584. VariantInit( &avarAttributes[lTemp]);
  585. LPCWSTR aszAttributes[3] =
  586. { thisAccum.GetResourceString(IDS_PRIVACYXML6_NOPOLICYDEFAULT),
  587. thisAccum.GetResourceString(IDS_PRIVACYXML6_NORULESDEFAULT),
  588. thisAccum.GetResourceString(IDS_PRIVACYXML6_ALWAYSALLOWSESSION)};
  589. if( TRUE != GetAttributes( pPartyNode, aszAttributes, ARRAYSIZE(aszAttributes),
  590. avarAttributes, &lTemp)
  591. || lTemp != 3
  592. || avarAttributes[0].vt == VT_EMPTY
  593. || avarAttributes[1].vt == VT_EMPTY
  594. || avarAttributes[2].vt == VT_EMPTY)
  595. {
  596. goto doneParsePartyBlock;
  597. }
  598. hr = pPartyNode->get_firstChild( &pCurrentNode);
  599. if( FAILED(hr))
  600. goto doneParsePartyBlock;
  601. // Determine No Policy and No Rule Matched defaults
  602. pAccumParty->m_uiNoPolicyDefault = 0;
  603. pAccumParty->m_uiNoRuleDefault = 0;
  604. for( uiTemp = IDS_PRIVACYXML6_ACTION_FIRST;
  605. uiTemp <= IDS_PRIVACYXML6_ACTION_LAST;
  606. uiTemp++)
  607. {
  608. if( 0 == StrCmp( avarAttributes[0].bstrVal, thisAccum.GetResourceString(uiTemp)))
  609. pAccumParty->m_uiNoPolicyDefault = uiTemp;
  610. if( 0 == StrCmp( avarAttributes[1].bstrVal, thisAccum.GetResourceString(uiTemp)))
  611. pAccumParty->m_uiNoRuleDefault = uiTemp;
  612. }
  613. if( pAccumParty->m_uiNoPolicyDefault == 0 || pAccumParty->m_uiNoRuleDefault == 0)
  614. goto doneParsePartyBlock;
  615. // Determine if we should always allow session cookies.
  616. if( 0 == StrCmp( avarAttributes[2].bstrVal,
  617. thisAccum.GetResourceString(IDS_PRIVACYXML6_YES)))
  618. {
  619. pAccumParty->m_fAlwaysAllowSession = true;
  620. }
  621. else if( 0 == StrCmp( avarAttributes[2].bstrVal,
  622. thisAccum.GetResourceString(IDS_PRIVACYXML6_NO)))
  623. {
  624. pAccumParty->m_fAlwaysAllowSession = false;
  625. }
  626. else
  627. {
  628. goto doneParsePartyBlock;
  629. }
  630. // Write the response if there is no policy
  631. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L"IE6-P3PV1/settings: nopolicy"))
  632. goto doneParsePartyBlock;
  633. if( TRUE != pAccumParty->m_cZonePreference.AppendToString( GetShortActionByResource(
  634. pAccumParty->m_uiNoPolicyDefault)))
  635. {
  636. goto doneParsePartyBlock;
  637. }
  638. // If we allow all session cookies, write that rule.
  639. if( pAccumParty->m_fAlwaysAllowSession)
  640. {
  641. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L" session=a"))
  642. goto doneParsePartyBlock;
  643. }
  644. // Write each of the rules in IF blocks
  645. while( pCurrentNode != NULL)
  646. {
  647. if( pRuleNode != NULL)
  648. pRuleNode->Release();
  649. pRuleNode = NULL;
  650. BOOL fFoundIfRule;
  651. if( TRUE != GetNextToken(
  652. &pCurrentNode, thisAccum.GetResourceString( IDS_PRIVACYXML6_IF),
  653. &fFoundIfRule, &pRuleNode)
  654. || fFoundIfRule != TRUE)
  655. {
  656. goto doneParsePartyBlock;
  657. }
  658. if( TRUE != ParseIfRule( pRuleNode, pAccumParty, thisAccum))
  659. goto doneParsePartyBlock;
  660. }
  661. // Write the command for the No Rule Matched rule..
  662. if( TRUE != pAccumParty->m_cZonePreference.AppendToString(L" /"))
  663. goto doneParsePartyBlock;
  664. if( TRUE != pAccumParty->m_cZonePreference.AppendToString( GetActionByResource(
  665. pAccumParty->m_uiNoRuleDefault)))
  666. {
  667. goto doneParsePartyBlock;
  668. }
  669. returnValue = TRUE;
  670. doneParsePartyBlock:
  671. if( pCurrentNode != NULL)
  672. pCurrentNode->Release();
  673. if( pRuleNode != NULL)
  674. pRuleNode->Release();
  675. for( lTemp = 0; lTemp < ARRAYSIZE( avarAttributes); lTemp++)
  676. VariantClear( &avarAttributes[lTemp]);
  677. return returnValue;
  678. }
  679. BOOL ParseP3pCookiePolicyBlock( IN IXMLDOMNode* pP3pPolicyNode, CParseAccumulation& thisAccum)
  680. {
  681. BOOL returnValue = FALSE;
  682. HRESULT hr;
  683. BOOL bl;
  684. long iTemp;
  685. VARIANT varZoneAttribute;
  686. VariantInit( &varZoneAttribute);
  687. IXMLDOMNode * pCurrentNode = NULL;
  688. IXMLDOMNode * pFirstPartyNode = NULL;
  689. IXMLDOMNode * pThirdPartyNode = NULL;
  690. LPCWSTR aszAttributes[1] = { thisAccum.GetResourceString(IDS_PRIVACYXML6_COOKIEZONE_ZONE)};
  691. if( TRUE != GetAttributes( pP3pPolicyNode,
  692. aszAttributes, ARRAYSIZE( aszAttributes),
  693. &varZoneAttribute, &iTemp)
  694. || iTemp != 1
  695. || varZoneAttribute.vt == VT_EMPTY)
  696. {
  697. goto doneParseP3pCookiePolicyBlock;
  698. }
  699. hr = pP3pPolicyNode->get_firstChild( &pCurrentNode);
  700. if( FAILED( hr))
  701. goto doneParseP3pCookiePolicyBlock;
  702. if( TRUE != GetNextToken( &pCurrentNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_FIRSTPARTY),
  703. &bl, &pFirstPartyNode)
  704. || bl != TRUE)
  705. {
  706. goto doneParseP3pCookiePolicyBlock;
  707. }
  708. if( TRUE != GetNextToken( &pCurrentNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_THIRDPARTY),
  709. &bl, &pThirdPartyNode)
  710. || bl != TRUE)
  711. {
  712. goto doneParseP3pCookiePolicyBlock;
  713. }
  714. if( pCurrentNode != NULL) // to many elements ...
  715. goto doneParseP3pCookiePolicyBlock;
  716. long iCurrentZone;
  717. iCurrentZone = -1;
  718. for( iTemp = 0; iTemp < NUM_OF_ZONES; iTemp++)
  719. {
  720. if( 0 == StrCmp(varZoneAttribute.bstrVal,
  721. thisAccum.GetResourceString( iTemp + IDS_PRIVACYXML6_COOKIEZONE_FIRST)))
  722. {
  723. iCurrentZone = iTemp;
  724. }
  725. }
  726. if( iCurrentZone == -1)
  727. goto doneParseP3pCookiePolicyBlock;
  728. thisAccum.m_zonePref[iCurrentZone].m_uiZoneID = iCurrentZone + IDS_PRIVACYXML6_COOKIEZONE_FIRST;
  729. thisAccum.m_zonePref[iCurrentZone].m_fSetZone = true;
  730. if( TRUE != ParsePartyBlock( pFirstPartyNode, &(thisAccum.m_zonePref[iCurrentZone].m_party[0]),
  731. thisAccum))
  732. {
  733. goto doneParseP3pCookiePolicyBlock;
  734. }
  735. if( TRUE != ParsePartyBlock( pThirdPartyNode, &(thisAccum.m_zonePref[iCurrentZone].m_party[1]),
  736. thisAccum))
  737. {
  738. goto doneParseP3pCookiePolicyBlock;
  739. }
  740. returnValue = TRUE;
  741. doneParseP3pCookiePolicyBlock:
  742. VariantClear( &varZoneAttribute);
  743. if( pCurrentNode != NULL)
  744. pCurrentNode->Release();
  745. if( pFirstPartyNode != NULL)
  746. pFirstPartyNode->Release();
  747. if( pThirdPartyNode != NULL)
  748. pThirdPartyNode->Release();
  749. return returnValue;
  750. }
  751. BOOL ParseMSIEPrivacyBlock( IXMLDOMNode* pMSIEPrivacyNode, CParseAccumulation& thisAccum)
  752. {
  753. bool returnValue = NULL;
  754. HRESULT hr;
  755. BOOL bl;
  756. long iZoneIndex;
  757. IXMLDOMNode * pCurrentNode = NULL;
  758. IXMLDOMNode * pAlwaysReplayLegacyNode = NULL;
  759. IXMLDOMNode * pFlushCookiesNode = NULL;
  760. IXMLDOMNode * pFlushSiteListNode = NULL;
  761. IXMLDOMNode * apZoneNode[NUM_OF_ZONES];
  762. for( iZoneIndex = 0; iZoneIndex < ARRAYSIZE(apZoneNode); iZoneIndex++)
  763. apZoneNode[iZoneIndex] = NULL;
  764. // The correctness of attributes for this node was verified in
  765. //LoadPrivacySettings().. (formatVersion="6.0")
  766. hr = pMSIEPrivacyNode->get_firstChild( &pCurrentNode);
  767. if( FAILED( hr))
  768. goto doneParseMSIEPrivacyBlock;
  769. for( iZoneIndex = 0; iZoneIndex < ARRAYSIZE( apZoneNode); iZoneIndex++)
  770. {
  771. if( TRUE != GetNextToken( &pCurrentNode,
  772. thisAccum.GetResourceString(IDS_PRIVACYXML6_COOKIEZONE),
  773. &bl, &apZoneNode[iZoneIndex]))
  774. {
  775. goto doneParseMSIEPrivacyBlock;
  776. }
  777. }
  778. if( TRUE != GetNextToken( &pCurrentNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_ALWAYSREPLAYLEGACY),
  779. &bl, &pAlwaysReplayLegacyNode))
  780. {
  781. goto doneParseMSIEPrivacyBlock;
  782. }
  783. thisAccum.m_fLeashCookies = pAlwaysReplayLegacyNode == NULL;
  784. if( TRUE != GetNextToken( &pCurrentNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_FLUSHCOOKIES),
  785. &bl, &pFlushCookiesNode))
  786. {
  787. goto doneParseMSIEPrivacyBlock;
  788. }
  789. thisAccum.m_fFlushCookies = pFlushCookiesNode != NULL;
  790. if( TRUE != GetNextToken( &pCurrentNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_FLUSHSITELIST),
  791. &bl, &pFlushSiteListNode))
  792. {
  793. goto doneParseMSIEPrivacyBlock;
  794. }
  795. thisAccum.m_fFlushSiteList = pFlushSiteListNode != NULL;
  796. if( pCurrentNode != NULL)
  797. goto doneParseMSIEPrivacyBlock;
  798. for( iZoneIndex = 0; iZoneIndex < ARRAYSIZE( apZoneNode); iZoneIndex++)
  799. {
  800. if( apZoneNode[iZoneIndex] != NULL)
  801. {
  802. if( TRUE != ParseP3pCookiePolicyBlock( apZoneNode[iZoneIndex], thisAccum))
  803. goto doneParseMSIEPrivacyBlock;
  804. }
  805. }
  806. returnValue = TRUE;
  807. doneParseMSIEPrivacyBlock:
  808. if( pCurrentNode != NULL)
  809. pCurrentNode->Release();
  810. if( pAlwaysReplayLegacyNode != NULL)
  811. pAlwaysReplayLegacyNode->Release();
  812. if( pFlushCookiesNode != NULL)
  813. pFlushCookiesNode->Release();
  814. if( pFlushSiteListNode != NULL)
  815. pFlushSiteListNode->Release();
  816. for( iZoneIndex = 0; iZoneIndex < ARRAYSIZE(apZoneNode); iZoneIndex++)
  817. {
  818. if( apZoneNode[iZoneIndex] != NULL)
  819. apZoneNode[iZoneIndex]->Release();
  820. }
  821. return returnValue;
  822. }
  823. BOOL ParsePerSiteRule( IXMLDOMNode* pPerSiteRule, CParseAccumulation& thisAccum)
  824. {
  825. BOOL returnValue = FALSE;
  826. LONG lTemp;
  827. VARIANT avarRule[2];
  828. for( lTemp = 0; lTemp < ARRAYSIZE( avarRule); lTemp++)
  829. VariantInit( &avarRule[lTemp]);
  830. VARIANT varDomain;
  831. VariantInit( &varDomain);
  832. LPCWSTR aszRuleAttributes[2] =
  833. { thisAccum.GetResourceString(IDS_PRIVACYXML6_DOMAIN),
  834. thisAccum.GetResourceString(IDS_PRIVACYXML6_ACTION)};
  835. if( TRUE != GetAttributes(
  836. pPerSiteRule, aszRuleAttributes, ARRAYSIZE(aszRuleAttributes),
  837. avarRule, &lTemp)
  838. || lTemp != 2
  839. || avarRule[0].vt == VT_EMPTY
  840. || avarRule[1].vt == VT_EMPTY)
  841. {
  842. goto doneParsePerSiteRule;
  843. }
  844. // get the domain and make sure its legit
  845. varDomain.vt = avarRule[0].vt;
  846. varDomain.bstrVal = avarRule[0].bstrVal;
  847. avarRule[0].vt = VT_EMPTY;
  848. avarRule[0].bstrVal = NULL;
  849. if( TRUE != IsDomainLegalCookieDomain( varDomain.bstrVal, varDomain.bstrVal))
  850. goto doneParsePerSiteRule;
  851. // get the action, ensuring its also legit
  852. UINT uiActionResource;
  853. if( 0 == StrCmp( avarRule[1].bstrVal, thisAccum.GetResourceString(IDS_PRIVACYXML6_ACTION_ACCEPT)))
  854. uiActionResource = IDS_PRIVACYXML6_ACTION_ACCEPT;
  855. else if( 0 == StrCmp( avarRule[1].bstrVal, thisAccum.GetResourceString(IDS_PRIVACYXML6_ACTION_REJECT)))
  856. uiActionResource = IDS_PRIVACYXML6_ACTION_REJECT;
  857. else
  858. goto doneParsePerSiteRule;
  859. // store the rule in the accumulated result
  860. if( TRUE != thisAccum.AddSiteRule( varDomain.bstrVal, uiActionResource))
  861. goto doneParsePerSiteRule;
  862. varDomain.vt = VT_EMPTY;
  863. varDomain.bstrVal = NULL;
  864. returnValue = TRUE;
  865. doneParsePerSiteRule:
  866. for( lTemp = 0; lTemp < ARRAYSIZE( avarRule); lTemp++)
  867. VariantClear( &avarRule[lTemp]);
  868. VariantClear( &varDomain);
  869. return returnValue;
  870. }
  871. BOOL ParseMSIEPerSiteBlock( IXMLDOMNode* pPerSiteRule, CParseAccumulation& thisAccum)
  872. {
  873. BOOL returnValue = FALSE;
  874. HRESULT hr;
  875. IXMLDOMNode * pCurrentNode = NULL;
  876. IXMLDOMNode * pRuleNode = NULL;
  877. hr = pPerSiteRule->get_firstChild( &pCurrentNode);
  878. if( FAILED(hr))
  879. goto doneParsePerSiteBlock;
  880. while( pCurrentNode != NULL)
  881. {
  882. if( pRuleNode != NULL)
  883. pRuleNode->Release();
  884. pRuleNode = NULL;
  885. BOOL fFoundPerSiteRule;
  886. if( TRUE != GetNextToken(
  887. &pCurrentNode, thisAccum.GetResourceString( IDS_PRIVACYXML6_SITE),
  888. &fFoundPerSiteRule, &pRuleNode)
  889. || fFoundPerSiteRule != TRUE)
  890. {
  891. goto doneParsePerSiteBlock;
  892. }
  893. if( TRUE != ParsePerSiteRule( pRuleNode, thisAccum))
  894. goto doneParsePerSiteBlock;
  895. }
  896. returnValue = TRUE;
  897. doneParsePerSiteBlock:
  898. if( pCurrentNode != NULL)
  899. pCurrentNode->Release();
  900. if( pRuleNode != NULL)
  901. pRuleNode->Release();
  902. return returnValue;
  903. }
  904. BOOL OpenXMLFile( LPCWSTR szFilename, IXMLDOMNode ** ppOutputNode)
  905. {
  906. BOOL returnValue = FALSE;
  907. HRESULT hr;
  908. VARIANT varFilename;
  909. VariantInit( &varFilename);
  910. IXMLDOMDocument * pXMLDoc = NULL;
  911. IXMLDOMElement * pXMLRoot = NULL;
  912. IXMLDOMNode * pRootNode = NULL;
  913. hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
  914. IID_IXMLDOMDocument, (void**)&pXMLDoc);
  915. if( FAILED(hr))
  916. goto doneOpenXMLFile;
  917. hr = pXMLDoc->put_async( VARIANT_FALSE);
  918. if( FAILED(hr))
  919. goto doneOpenXMLFile;
  920. varFilename.vt = VT_BSTR;
  921. varFilename.bstrVal = SysAllocString( szFilename);
  922. if( varFilename.bstrVal == NULL)
  923. goto doneOpenXMLFile;
  924. VARIANT_BOOL varbool;
  925. hr = pXMLDoc->load( varFilename, &varbool);
  926. if( FAILED(hr) || varbool != VARIANT_TRUE)
  927. goto doneOpenXMLFile;
  928. hr = pXMLDoc->get_documentElement( &pXMLRoot);
  929. if( FAILED(hr))
  930. goto doneOpenXMLFile;
  931. hr = pXMLRoot->QueryInterface( IID_IXMLDOMNode, (void **)&pRootNode);
  932. if( FAILED(hr))
  933. goto doneOpenXMLFile;
  934. returnValue = TRUE;
  935. *ppOutputNode = pRootNode;
  936. pRootNode = NULL;
  937. doneOpenXMLFile:
  938. if( pXMLDoc != NULL)
  939. pXMLDoc->Release();
  940. if( pXMLRoot != NULL)
  941. pXMLRoot->Release();
  942. if( pRootNode != NULL)
  943. pRootNode->Release();
  944. VariantClear( &varFilename);
  945. return returnValue;
  946. }
  947. //
  948. // GetVersionedTag
  949. //
  950. // Looks at all tags in pSource with the tag szTargetTag. Returns
  951. //the member with version fVersion. Fails if zero or >1 such
  952. //tags are found.
  953. //
  954. BOOL GetVersionedTag( IXMLDOMNode* pSource, LPCWSTR szTargetTag, LPCWSTR szVersionAttribute, float fVersion,
  955. IXMLDOMNode** ppOutputNode)
  956. {
  957. BOOL returnValue = FALSE;
  958. HRESULT hr;
  959. IXMLDOMNode * pNode = NULL;
  960. IXMLDOMNode * pResult = NULL;
  961. IXMLDOMNodeList * pRootNodeList = NULL;
  962. IXMLDOMNode * pVersionAttribute = NULL;
  963. VARIANT varVersion;
  964. VariantInit( &varVersion);
  965. // Get the elements in pSource with tag szTargetTag
  966. long iListSize;
  967. if( TRUE != GetChildrenByName( pSource, szTargetTag,
  968. &pRootNodeList, &iListSize))
  969. {
  970. goto doneGetVersionedTag;
  971. }
  972. long iListIndex;
  973. for( iListIndex = 0; iListIndex < iListSize; iListIndex++)
  974. {
  975. if( pNode != NULL)
  976. pNode->Release();
  977. pNode = NULL;
  978. if( pVersionAttribute != NULL)
  979. pVersionAttribute->Release();
  980. pVersionAttribute = NULL;
  981. VariantClear( &varVersion);
  982. hr = pRootNodeList->get_item( iListIndex, &pNode);
  983. if( FAILED(hr))
  984. goto doneGetVersionedTag;
  985. long iTotalAttributeCount;
  986. LPCWSTR aszAttributes[1] = { szVersionAttribute};
  987. if( TRUE != GetAttributes( pNode, aszAttributes, ARRAYSIZE(aszAttributes),
  988. &varVersion, &iTotalAttributeCount)
  989. || varVersion.vt == VT_EMPTY)
  990. {
  991. continue;
  992. }
  993. hr = VariantChangeType( &varVersion, &varVersion, NULL, VT_R4);
  994. if( FAILED(hr))
  995. goto doneGetVersionedTag;
  996. if( varVersion.fltVal != fVersion)
  997. continue;
  998. if( pResult == NULL)
  999. {
  1000. pResult = pNode;
  1001. pNode = NULL;
  1002. }
  1003. else
  1004. { // found multiple of right version.. syntax problem.
  1005. goto doneGetVersionedTag;
  1006. }
  1007. }
  1008. *ppOutputNode = pResult;
  1009. pResult = NULL;
  1010. returnValue = TRUE;
  1011. doneGetVersionedTag:
  1012. if( pNode != NULL)
  1013. pNode->Release();
  1014. if( pResult != NULL)
  1015. pResult->Release();
  1016. if( pRootNodeList != NULL)
  1017. pRootNodeList->Release();
  1018. if( pVersionAttribute != NULL)
  1019. pVersionAttribute->Release();
  1020. VariantClear( &varVersion);
  1021. return returnValue;
  1022. }
  1023. BOOL LoadPrivacySettings(LPCWSTR szFilename, CParseAccumulation& thisAccum,
  1024. IN OUT BOOL* pfParsePrivacyPreferences, IN OUT BOOL* pfParsePerSiteRules)
  1025. {
  1026. BOOL returnValue = FALSE;
  1027. IXMLDOMNode * pRootNode = NULL;
  1028. IXMLDOMNode * pPrivacyPreferencesNode = NULL;
  1029. IXMLDOMNode * pPerSiteSettingsNode = NULL;
  1030. // Load the XML file
  1031. if( TRUE != OpenXMLFile( szFilename, &pRootNode))
  1032. goto doneLoadPrivacySettings;
  1033. // Get the node containing privacy settings
  1034. if( TRUE != GetVersionedTag( pRootNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_ROOTPRIVACY),
  1035. thisAccum.GetResourceString(IDS_PRIVACYXML6_VERSION), 6.0, &pPrivacyPreferencesNode))
  1036. {
  1037. goto doneLoadPrivacySettings;
  1038. }
  1039. // Get the node containing per-site settings
  1040. if( TRUE != GetVersionedTag( pRootNode, thisAccum.GetResourceString(IDS_PRIVACYXML6_ROOTPERSITE),
  1041. thisAccum.GetResourceString(IDS_PRIVACYXML6_VERSION), 6.0, &pPerSiteSettingsNode))
  1042. {
  1043. goto doneLoadPrivacySettings;
  1044. }
  1045. // If we're supposed to import privacy preferences and we found some, parse privacy preferences.
  1046. if( *pfParsePrivacyPreferences == TRUE && pPrivacyPreferencesNode != NULL)
  1047. {
  1048. if( TRUE != ParseMSIEPrivacyBlock( pPrivacyPreferencesNode, thisAccum))
  1049. {
  1050. goto doneLoadPrivacySettings;
  1051. }
  1052. }
  1053. // If we're supposed to import per-site rules and we found some, parse per-site rules.
  1054. if( *pfParsePerSiteRules == TRUE && pPerSiteSettingsNode != NULL)
  1055. {
  1056. if( TRUE != ParseMSIEPerSiteBlock( pPerSiteSettingsNode, thisAccum))
  1057. {
  1058. goto doneLoadPrivacySettings;
  1059. }
  1060. }
  1061. // Indicate whether privacy preferences or per-site rules were parsed..
  1062. *pfParsePrivacyPreferences = (*pfParsePrivacyPreferences == TRUE) && (pPrivacyPreferencesNode != NULL);
  1063. *pfParsePerSiteRules = (*pfParsePerSiteRules == TRUE) && (pPerSiteSettingsNode != NULL);
  1064. returnValue = TRUE;
  1065. doneLoadPrivacySettings:
  1066. if( pRootNode != NULL)
  1067. pRootNode->Release();
  1068. if( pPrivacyPreferencesNode != NULL)
  1069. pPrivacyPreferencesNode->Release();
  1070. if( pPerSiteSettingsNode != NULL)
  1071. pPerSiteSettingsNode->Release();
  1072. return returnValue;
  1073. }
  1074. // Top-level import function.. optionally imports privacy settings and per-site rules.
  1075. //The flag in tells if those items should be parsed, the flag out indicates if they were found.
  1076. //
  1077. // Returns TRUE to indicate the import was successful, no syntax problems in the import
  1078. //file and the output flags are set.
  1079. //
  1080. // Returns FALSE if there were any problems loading the file or writing the imported settings.
  1081. SHDOCAPI_(BOOL) ImportPrivacySettings( IN LPCWSTR szFilename,
  1082. IN OUT BOOL* pfParsePrivacyPreferences,
  1083. IN OUT BOOL* pfParsePerSiteRules)
  1084. {
  1085. BOOL returnValue = FALSE;
  1086. CParseAccumulation thisAccum;
  1087. if( TRUE != thisAccum.Initialize())
  1088. goto doneImportPrivacySettings;
  1089. if( TRUE != LoadPrivacySettings( szFilename, thisAccum,
  1090. pfParsePrivacyPreferences, pfParsePerSiteRules))
  1091. goto doneImportPrivacySettings;
  1092. returnValue = thisAccum.DoAccumulation();
  1093. doneImportPrivacySettings:
  1094. return returnValue;
  1095. }
  1096. //*****************************************************************************************
  1097. //*****************************************************************************************
  1098. //
  1099. //*****************************************************************************************
  1100. //*****************************************************************************************
  1101. //
  1102. // Privacy Export
  1103. //
  1104. // This code exists to export the per-site list only.
  1105. //
  1106. CHAR g_szPerSiteFileBegin[] =
  1107. "\
  1108. <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n\
  1109. <MSIEPrivacy>\r\n\
  1110. <MSIESiteRules formatVersion=\"6.0\">\r\n\
  1111. ";
  1112. CHAR g_szPerSiteRule[] = "<site domain=\"%s\" \taction=\"%s\"></site>\r\n";
  1113. CHAR g_szAccept[] = "accept";
  1114. CHAR g_szReject[] = "reject";
  1115. CHAR g_szPerSiteFileEnd[] =
  1116. "\
  1117. </MSIESiteRules>\r\n\
  1118. </MSIEPrivacy>\r\n\
  1119. ";
  1120. SHDOCAPI_(BOOL) ExportPerSiteListW( IN LPCWSTR szFilename)
  1121. {
  1122. BOOL retVal = FALSE;
  1123. CFileOutputStream OutputStream;
  1124. PCHAR pszRuleBuffer = NULL;
  1125. int iRuleIndex = 0;
  1126. // Allocate a temporary buffer to write the rules to
  1127. long cRuleBufferSize = MAX_URL_STRING + ARRAYSIZE( g_szPerSiteRule) + MAX_PATH;
  1128. pszRuleBuffer = new CHAR[ cRuleBufferSize];
  1129. if( pszRuleBuffer == NULL)
  1130. goto doneExportCookieFileW;
  1131. // Load the output file
  1132. if( !OutputStream.Load( szFilename, FALSE))
  1133. goto doneExportCookieFileW;
  1134. // Write the begining of the file.
  1135. if( !OutputStream.DumpStr( g_szPerSiteFileBegin, ARRAYSIZE( g_szPerSiteFileBegin) - 1))
  1136. goto doneExportCookieFileW;
  1137. // Enumerate the per-site rules and export the accept/reject rules
  1138. CHAR szSiteName[ MAX_URL_STRING];
  1139. DWORD cSiteNameSize;
  1140. DWORD dwDecision;
  1141. while( (cSiteNameSize = ARRAYSIZE( szSiteName)) // initialize in-out param
  1142. && InternetEnumPerSiteCookieDecisionA( szSiteName, &cSiteNameSize, &dwDecision, iRuleIndex++))
  1143. {
  1144. if( dwDecision == COOKIE_STATE_ACCEPT
  1145. || dwDecision == COOKIE_STATE_REJECT)
  1146. {
  1147. int iRuleLength =
  1148. wnsprintfA(pszRuleBuffer, cRuleBufferSize, g_szPerSiteRule,
  1149. szSiteName,
  1150. (dwDecision == COOKIE_STATE_ACCEPT) ? g_szAccept : g_szReject);
  1151. OutputStream.DumpStr( pszRuleBuffer, iRuleLength);
  1152. }
  1153. }
  1154. // Write the ending of the file.
  1155. if( !OutputStream.DumpStr( g_szPerSiteFileEnd, ARRAYSIZE( g_szPerSiteFileEnd) - 1))
  1156. goto doneExportCookieFileW;
  1157. retVal = TRUE;
  1158. doneExportCookieFileW:
  1159. if( pszRuleBuffer != NULL)
  1160. delete [] pszRuleBuffer;
  1161. return retVal;
  1162. }