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.

5227 lines
150 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: iuxml.cpp
  6. //
  7. // Description:
  8. //
  9. // Implementation for the CIUXml class
  10. //
  11. //=======================================================================
  12. #include "iuengine.h"
  13. #include "iuxml.h"
  14. #include <iucommon.h>
  15. #include <fileutil.h>
  16. #include <StringUtil.h>
  17. #include <shlwapi.h>
  18. #include <wininet.h>
  19. #include "schemakeys.h"
  20. #include "schemamisc.h"
  21. #include "v3applog.h"
  22. #define QuitIfNull(p) {if (NULL == p) {hr = E_INVALIDARG; LOG_ErrorMsg(hr); return hr;}}
  23. #define QuitIfFail(x) {hr = x; if (FAILED(hr)) goto CleanUp;}
  24. #define ReturnIfFail(x) {hr = x; if (FAILED(hr)) {LOG_ErrorMsg(hr); return hr;}}
  25. #define SkipIfFail(x) {hr = x; if (FAILED(hr)) {hr = S_FALSE; continue;}}
  26. const TCHAR IDENT_IUSCHEMA[] = _T("IUSchema");
  27. const TCHAR IDENT_IUSCHEMA_SYSTEMSPEC[] = _T("SystemSpecSchema");
  28. const TCHAR IDENT_IUSCHEMA_ITEMS[] = _T("ResultSchema");
  29. const WCHAR CORP_PLATFORM_DIR_NT4[] = L"x86WinNT4";
  30. const WCHAR CORP_PLATFORM_DIR_NT5[] = L"x86win2k";
  31. const WCHAR CORP_PLATFORM_DIR_W98[] = L"x86Win98";
  32. const WCHAR CORP_PLATFORM_DIR_W95[] = L"x86Win95";
  33. const WCHAR CORP_PLATFORM_DIR_WINME[] = L"x86WinME";
  34. const WCHAR CORP_PLATFORM_DIR_X86WHI[] = L"x86WinXP";
  35. const WCHAR CORP_PLATFROM_DIR_IA64WHI[] = L"ia64WinXP";
  36. // Initial length of the node array "m_ppNodeArray"
  37. const DWORD MAX_NODES = 16;
  38. // Initial length of the node array "m_ppNodeListArray"
  39. const DWORD MAX_NODELISTS = 16;
  40. // Bitmap of existence of all possible system info classes
  41. const DWORD COMPUTERSYSTEM = 0x00000001;
  42. const DWORD REGKEYS = 0x00000010;
  43. const DWORD PLATFORM = 0x00000100;
  44. const DWORD LOCALE = 0x00001000;
  45. const DWORD DEVICES = 0x00010000;
  46. // The following are constants used for V3 history migration:
  47. //
  48. // Log line types
  49. #define LOG_V2 "V2" // line format for items migrated from V2
  50. #define LOG_V3CAT "V3CAT" // V3 Beta format (version 1)
  51. #define LOG_V3_2 "V3_2" // V3 log line format (version 2)
  52. #define LOG_PSS "PSS" // Entry for PSS
  53. // LOG_V2 format
  54. // V2|DATE|TIME|LOGSTRING|
  55. //
  56. // LOG_V3CAT format
  57. // V3CAT|PUID|OPERATION|TITLE|VERSION|DATESTRING|TIMESTRING|RECTYPE|RESULT|ERRORCODE|ERRORSTRING|
  58. //
  59. // LOG_V3_2 format
  60. // V3_2|PUID|OPERATION|TITLE|VERSION|TIMESTAMP|RECTYPE|RESULT|ERRORCODE|ERRORSTRING|
  61. //
  62. // LOG_PSS format
  63. // PSS|PUID|OPERATION|TITLE|VERSION|TIMESTAMP|RECTYPE|RESULT|ERRORCODE|ERRORSTRING|
  64. //
  65. // operation type
  66. #define LOG_INSTALL "INSTALL"
  67. // result
  68. #define LOG_SUCCESS "SUCCESS"
  69. #define LOG_FAIL "FAIL"
  70. #define LOG_STARTED "STARTED" // started but reboot was required: exclusive items only
  71. const WCHAR C_V3_CLIENTINFO[] = L"WU_V3";
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CIUXml
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Constructor
  76. //
  77. /////////////////////////////////////////////////////////////////////////////
  78. CIUXml::CIUXml()
  79. : m_dwSizeNodeArray(MAX_NODES),
  80. m_dwSizeNodeListArray(MAX_NODELISTS),
  81. m_ppNodeArray(NULL),
  82. m_ppNodeListArray(NULL)
  83. {
  84. m_hHeap = GetProcessHeap();
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Destructor
  88. //
  89. /////////////////////////////////////////////////////////////////////////////
  90. CIUXml::~CIUXml()
  91. {
  92. DWORD dwIndex;
  93. if (NULL != m_ppNodeArray)
  94. {
  95. for (dwIndex = 0; dwIndex < m_dwSizeNodeArray; dwIndex++)
  96. {
  97. SafeReleaseNULL(m_ppNodeArray[dwIndex]);
  98. }
  99. HeapFree(m_hHeap, 0, m_ppNodeArray);
  100. m_ppNodeArray = NULL;
  101. }
  102. if (NULL != m_ppNodeListArray)
  103. {
  104. for (dwIndex = 0; dwIndex < m_dwSizeNodeListArray; dwIndex++)
  105. {
  106. SafeReleaseNULL(m_ppNodeListArray[dwIndex]);
  107. }
  108. HeapFree(m_hHeap, 0, m_ppNodeListArray);
  109. m_ppNodeListArray = NULL;
  110. }
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // SafeCloseHandleNode()
  114. //
  115. // User can explicitly can this function to release a node for reuse when
  116. // writing a xml doc.
  117. /////////////////////////////////////////////////////////////////////////////
  118. void CIUXml::SafeCloseHandleNode(HANDLE_NODE& hNode)
  119. {
  120. if (HANDLE_NODE_INVALID != hNode)
  121. {
  122. SafeReleaseNULL(m_ppNodeArray[hNode]);
  123. hNode = HANDLE_NODE_INVALID;
  124. }
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. // SafeFindCloseHandle()
  128. //
  129. // User can explicitly can this function to release a nodelist for reuse when
  130. // reading a xml doc.
  131. /////////////////////////////////////////////////////////////////////////////
  132. void CIUXml::SafeFindCloseHandle(HANDLE_NODELIST& hNodeList)
  133. {
  134. if (HANDLE_NODELIST_INVALID != hNodeList)
  135. {
  136. SafeReleaseNULL(m_ppNodeListArray[hNodeList]);
  137. hNodeList = HANDLE_NODELIST_INVALID;
  138. }
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // InitNodeArray()
  142. //
  143. // Allocate or re-allocate memory for the node array "m_ppNodeArray"
  144. /////////////////////////////////////////////////////////////////////////////
  145. HRESULT CIUXml::InitNodeArray(BOOL fRealloc /*= FALSE*/)
  146. {
  147. if (fRealloc) // re-allocation
  148. {
  149. IXMLDOMNode** ppNodeArrayTemp = (IXMLDOMNode**)HeapReAlloc(m_hHeap,
  150. HEAP_ZERO_MEMORY,
  151. m_ppNodeArray,
  152. m_dwSizeNodeArray * sizeof(IXMLDOMNode*));
  153. if (NULL == ppNodeArrayTemp)
  154. {
  155. return E_OUTOFMEMORY;
  156. }
  157. else
  158. {
  159. m_ppNodeArray = ppNodeArrayTemp;
  160. }
  161. }
  162. else // initial allocation
  163. {
  164. m_ppNodeArray = (IXMLDOMNode**)HeapAlloc(m_hHeap,
  165. HEAP_ZERO_MEMORY,
  166. m_dwSizeNodeArray * sizeof(IXMLDOMNode*));
  167. if (NULL == m_ppNodeArray)
  168. {
  169. return E_OUTOFMEMORY;
  170. }
  171. }
  172. return S_OK;
  173. }
  174. /////////////////////////////////////////////////////////////////////////////
  175. // InitNodeListArray()
  176. //
  177. // Allocate or re-allocate memory for the nodelist array "m_ppNodeListArray"
  178. /////////////////////////////////////////////////////////////////////////////
  179. HRESULT CIUXml::InitNodeListArray(BOOL fRealloc /*= FALSE*/)
  180. {
  181. if (fRealloc) // re-allocation
  182. {
  183. IXMLDOMNodeList** ppNodeListArrayTemp = (IXMLDOMNodeList**)HeapReAlloc(m_hHeap,
  184. HEAP_ZERO_MEMORY,
  185. m_ppNodeListArray,
  186. m_dwSizeNodeListArray * sizeof(IXMLDOMNodeList*));
  187. if (NULL == ppNodeListArrayTemp)
  188. {
  189. return E_OUTOFMEMORY;
  190. }
  191. else
  192. {
  193. m_ppNodeListArray = ppNodeListArrayTemp;
  194. }
  195. }
  196. else // initial allocation
  197. {
  198. m_ppNodeListArray = (IXMLDOMNodeList**)HeapAlloc(m_hHeap,
  199. HEAP_ZERO_MEMORY,
  200. m_dwSizeNodeListArray * sizeof(IXMLDOMNodeList*));
  201. if (NULL == m_ppNodeListArray)
  202. {
  203. return E_OUTOFMEMORY;
  204. }
  205. }
  206. return S_OK;
  207. }
  208. /////////////////////////////////////////////////////////////////////////////
  209. // GetNodeHandle()
  210. //
  211. // Look for the first un-used node from the "m_ppNodeArray" array,
  212. // including the memory allocation, if needed.
  213. /////////////////////////////////////////////////////////////////////////////
  214. HANDLE_NODE CIUXml::GetNodeHandle()
  215. {
  216. HRESULT hr;
  217. DWORD dwIndex;
  218. //
  219. // allocate memory for "m_ppNodeArray" array if this is the first time using it
  220. //
  221. if (NULL == m_ppNodeArray)
  222. {
  223. QuitIfFail(InitNodeArray());
  224. return 0; // return the first element of the array
  225. }
  226. //
  227. // find the next node to use, or, if any node was used but closed, reuse it
  228. //
  229. for (dwIndex = 0; dwIndex < m_dwSizeNodeArray; dwIndex++)
  230. {
  231. if (NULL == m_ppNodeArray[dwIndex])
  232. {
  233. return dwIndex;
  234. }
  235. }
  236. //
  237. // all pre-allocated nodes are used up, so re-allocate longer array
  238. //
  239. m_dwSizeNodeArray += m_dwSizeNodeArray; // double the size
  240. QuitIfFail(InitNodeArray(TRUE)); // re-allocation
  241. return dwIndex;
  242. CleanUp:
  243. return HANDLE_NODE_INVALID;
  244. }
  245. /////////////////////////////////////////////////////////////////////////////
  246. // GetNodeListHandle()
  247. //
  248. // Look for the first un-used nodelist from the "m_ppNodeListArray" array,
  249. // including the memory allocation, if needed.
  250. /////////////////////////////////////////////////////////////////////////////
  251. HANDLE_NODELIST CIUXml::GetNodeListHandle()
  252. {
  253. HRESULT hr;
  254. DWORD dwIndex;
  255. //
  256. // allocate memory for "m_ppNodeListArray" array if this is the first time using it
  257. //
  258. if (NULL == m_ppNodeListArray)
  259. {
  260. QuitIfFail(InitNodeListArray());
  261. return 0; // return the first element of the array
  262. }
  263. //
  264. // find the next nodelist to use, or, if any nodelist was used but closed, reuse it
  265. //
  266. for (dwIndex = 0; dwIndex < m_dwSizeNodeListArray; dwIndex++)
  267. {
  268. if (NULL == m_ppNodeListArray[dwIndex])
  269. {
  270. return dwIndex;
  271. }
  272. }
  273. //
  274. // all pre-allocated nodelists are used up, so re-allocate longer array
  275. //
  276. m_dwSizeNodeListArray += m_dwSizeNodeListArray; // double the size
  277. QuitIfFail(InitNodeListArray(TRUE)); // re-allocation
  278. return dwIndex;
  279. CleanUp:
  280. return HANDLE_NODELIST_INVALID;
  281. }
  282. /////////////////////////////////////////////////////////////////////////////
  283. // GetDOMNodebyHandle()
  284. //
  285. // Retrieve the xml node with the given index of m_ppNodeArray
  286. /////////////////////////////////////////////////////////////////////////////
  287. IXMLDOMNode* CIUXml::GetDOMNodebyHandle(HANDLE_NODE hNode)
  288. {
  289. if (NULL != m_ppNodeArray && HANDLE_NODE_INVALID != hNode)
  290. {
  291. return m_ppNodeArray[hNode];
  292. }
  293. return NULL;
  294. }
  295. /////////////////////////////////////////////////////////////////////////////
  296. // FindFirstDOMNode()
  297. //
  298. // Retrieve the first xml node with the given tag name under the given parent node
  299. /////////////////////////////////////////////////////////////////////////////
  300. HANDLE_NODELIST CIUXml::FindFirstDOMNode(IXMLDOMNode* pParentNode, BSTR bstrName, IXMLDOMNode** ppNode)
  301. {
  302. USES_IU_CONVERSION;
  303. HRESULT hr = S_OK;
  304. if (NULL == pParentNode)
  305. {
  306. hr = E_INVALIDARG;
  307. return HANDLE_NODELIST_INVALID;
  308. }
  309. DWORD dwIndex;
  310. dwIndex = GetNodeListHandle();
  311. if (HANDLE_NODELIST_INVALID != dwIndex)
  312. {
  313. LONG lLength;
  314. QuitIfFail(pParentNode->selectNodes(bstrName, &m_ppNodeListArray[dwIndex]));
  315. if (NULL == m_ppNodeListArray[dwIndex])
  316. {
  317. goto CleanUp;
  318. }
  319. QuitIfFail(m_ppNodeListArray[dwIndex]->get_length(&lLength));
  320. if (lLength <= 0)
  321. {
  322. goto CleanUp;
  323. }
  324. QuitIfFail(m_ppNodeListArray[dwIndex]->nextNode(ppNode));
  325. if (NULL == *ppNode)
  326. {
  327. goto CleanUp;
  328. }
  329. return dwIndex;
  330. }
  331. CleanUp:
  332. *ppNode = NULL;
  333. return HANDLE_NODELIST_INVALID;
  334. }
  335. /////////////////////////////////////////////////////////////////////////////
  336. // FindFirstDOMNode()
  337. //
  338. // Retrieve the handle of first xml node with the given tag name under the given parent node
  339. /////////////////////////////////////////////////////////////////////////////
  340. HANDLE_NODELIST CIUXml::FindFirstDOMNode(IXMLDOMNode* pParentNode, BSTR bstrName, HANDLE_NODE* phNode)
  341. {
  342. USES_IU_CONVERSION;
  343. HRESULT hr = S_OK;
  344. if (NULL == pParentNode)
  345. {
  346. hr = E_INVALIDARG;
  347. return HANDLE_NODELIST_INVALID;
  348. }
  349. DWORD dwIndex1, dwIndex2;
  350. dwIndex1 = GetNodeListHandle();
  351. if (HANDLE_NODELIST_INVALID != dwIndex1)
  352. {
  353. LONG lLength;
  354. QuitIfFail(pParentNode->selectNodes(bstrName, &m_ppNodeListArray[dwIndex1]));
  355. if (NULL == m_ppNodeListArray[dwIndex1])
  356. {
  357. goto CleanUp;
  358. }
  359. QuitIfFail(m_ppNodeListArray[dwIndex1]->get_length(&lLength));
  360. if (lLength <= 0)
  361. {
  362. goto CleanUp;
  363. }
  364. dwIndex2 = GetNodeHandle();
  365. if (HANDLE_NODE_INVALID != dwIndex2)
  366. {
  367. QuitIfFail(m_ppNodeListArray[dwIndex1]->nextNode(&m_ppNodeArray[dwIndex2]));
  368. if (NULL == m_ppNodeArray[dwIndex2])
  369. {
  370. goto CleanUp;
  371. }
  372. *phNode = dwIndex2;
  373. return dwIndex1;
  374. }
  375. }
  376. CleanUp:
  377. *phNode = HANDLE_NODE_INVALID;
  378. return HANDLE_NODELIST_INVALID;
  379. }
  380. /////////////////////////////////////////////////////////////////////////////
  381. // FindFirstDOMNode()
  382. //
  383. // Retrieve the first xml node with the given tag name in the given xml doc
  384. /////////////////////////////////////////////////////////////////////////////
  385. HANDLE_NODELIST CIUXml::FindFirstDOMNode(IXMLDOMDocument* pDoc, BSTR bstrName, IXMLDOMNode** ppNode)
  386. {
  387. USES_IU_CONVERSION;
  388. HRESULT hr = S_OK;
  389. if (NULL == pDoc)
  390. {
  391. hr = E_INVALIDARG;
  392. return HANDLE_NODELIST_INVALID;
  393. }
  394. DWORD dwIndex;
  395. IXMLDOMNode *pParentNode = NULL;
  396. dwIndex = GetNodeListHandle();
  397. if (HANDLE_NODELIST_INVALID != dwIndex)
  398. {
  399. LONG lLength;
  400. QuitIfFail(pDoc->QueryInterface(IID_IXMLDOMNode, (void**)&pParentNode));
  401. QuitIfFail(pParentNode->selectNodes(bstrName, &m_ppNodeListArray[dwIndex]));
  402. if (NULL == m_ppNodeListArray[dwIndex])
  403. {
  404. goto CleanUp;
  405. }
  406. QuitIfFail(m_ppNodeListArray[dwIndex]->get_length(&lLength));
  407. if (lLength <= 0)
  408. {
  409. goto CleanUp;
  410. }
  411. QuitIfFail(m_ppNodeListArray[dwIndex]->nextNode(ppNode));
  412. if (NULL == *ppNode)
  413. {
  414. goto CleanUp;
  415. }
  416. SafeReleaseNULL(pParentNode);
  417. return dwIndex;
  418. }
  419. CleanUp:
  420. *ppNode = NULL;
  421. SafeReleaseNULL(pParentNode);
  422. return HANDLE_NODELIST_INVALID;
  423. }
  424. /////////////////////////////////////////////////////////////////////////////
  425. // FindFirstDOMNode()
  426. //
  427. // Retrieve the handle of first xml node with the given tag name in the given xml doc
  428. /////////////////////////////////////////////////////////////////////////////
  429. HANDLE_NODELIST CIUXml::FindFirstDOMNode(IXMLDOMDocument* pDoc, BSTR bstrName, HANDLE_NODE* phNode)
  430. {
  431. USES_IU_CONVERSION;
  432. HRESULT hr = S_OK;
  433. if (NULL == pDoc)
  434. {
  435. hr = E_INVALIDARG;
  436. return HANDLE_NODELIST_INVALID;
  437. }
  438. DWORD dwIndex1, dwIndex2;
  439. IXMLDOMNode *pParentNode = NULL;
  440. dwIndex1 = GetNodeListHandle();
  441. if (HANDLE_NODELIST_INVALID != dwIndex1)
  442. {
  443. LONG lLength;
  444. QuitIfFail(pDoc->QueryInterface(IID_IXMLDOMNode, (void**)&pParentNode));
  445. QuitIfFail(pParentNode->selectNodes(bstrName, &m_ppNodeListArray[dwIndex1]));
  446. if (NULL == m_ppNodeListArray[dwIndex1])
  447. {
  448. goto CleanUp;
  449. }
  450. QuitIfFail(m_ppNodeListArray[dwIndex1]->get_length(&lLength));
  451. if (lLength <= 0)
  452. {
  453. goto CleanUp;
  454. }
  455. dwIndex2 = GetNodeHandle();
  456. if (HANDLE_NODE_INVALID != dwIndex2)
  457. {
  458. QuitIfFail(m_ppNodeListArray[dwIndex1]->nextNode(&m_ppNodeArray[dwIndex2]));
  459. if (NULL == m_ppNodeArray[dwIndex2])
  460. {
  461. goto CleanUp;
  462. }
  463. *phNode = dwIndex2;
  464. SafeReleaseNULL(pParentNode);
  465. return dwIndex1;
  466. }
  467. }
  468. CleanUp:
  469. *phNode = HANDLE_NODE_INVALID;
  470. SafeReleaseNULL(pParentNode);
  471. return HANDLE_NODELIST_INVALID;
  472. }
  473. /////////////////////////////////////////////////////////////////////////////
  474. // FindNextDOMNode()
  475. //
  476. // Retrieve the next xml node with the given tag name under the given parent node
  477. /////////////////////////////////////////////////////////////////////////////
  478. HRESULT CIUXml::FindNextDOMNode(HANDLE_NODELIST hNodeList, IXMLDOMNode** ppNode)
  479. {
  480. HRESULT hr = E_FAIL;
  481. if (HANDLE_NODELIST_INVALID != hNodeList)
  482. {
  483. hr = m_ppNodeListArray[hNodeList]->nextNode(ppNode);
  484. }
  485. if (FAILED(hr) || NULL == *ppNode)
  486. {
  487. *ppNode = NULL;
  488. return E_FAIL;
  489. }
  490. return hr;
  491. }
  492. /////////////////////////////////////////////////////////////////////////////
  493. // FindNextDOMNode()
  494. //
  495. // Retrieve the handle of next xml node with the given tag name under the given parent node
  496. /////////////////////////////////////////////////////////////////////////////
  497. HRESULT CIUXml::FindNextDOMNode(HANDLE_NODELIST hNodeList, HANDLE_NODE* phNode)
  498. {
  499. HRESULT hr = E_FAIL;
  500. DWORD dwIndex = HANDLE_NODE_INVALID;
  501. if (HANDLE_NODELIST_INVALID != hNodeList)
  502. {
  503. dwIndex = GetNodeHandle();
  504. if (HANDLE_NODE_INVALID != dwIndex)
  505. {
  506. hr = m_ppNodeListArray[hNodeList]->nextNode(&m_ppNodeArray[dwIndex]);
  507. }
  508. }
  509. if (FAILED(hr) || NULL == m_ppNodeArray[dwIndex])
  510. {
  511. *phNode = HANDLE_NODE_INVALID;
  512. return E_FAIL;
  513. }
  514. *phNode = dwIndex;
  515. return hr;
  516. }
  517. /////////////////////////////////////////////////////////////////////////////
  518. // CreateDOMNodeWithHandle()
  519. //
  520. // Create an xml node of the given type
  521. // Return: index of the node array "m_ppNodeArray"; or -1 if failure.
  522. /////////////////////////////////////////////////////////////////////////////
  523. HANDLE_NODE CIUXml::CreateDOMNodeWithHandle(IXMLDOMDocument* pDoc, SHORT nType, BSTR bstrName, BSTR bstrNamespaceURI /*= NULL*/)
  524. {
  525. USES_IU_CONVERSION;
  526. HRESULT hr = S_OK;
  527. if (NULL == pDoc)
  528. {
  529. hr = E_INVALIDARG;
  530. return HANDLE_NODE_INVALID;
  531. }
  532. DWORD dwIndex;
  533. VARIANT vType;
  534. VariantInit(&vType);
  535. vType.vt = VT_I2;
  536. vType.iVal = nType;
  537. dwIndex = GetNodeHandle();
  538. if (HANDLE_NODE_INVALID != dwIndex)
  539. {
  540. QuitIfFail(pDoc->createNode(vType, bstrName, bstrNamespaceURI, &m_ppNodeArray[dwIndex]));
  541. return dwIndex;
  542. }
  543. CleanUp:
  544. return HANDLE_NODE_INVALID;
  545. }
  546. /////////////////////////////////////////////////////////////////////////////
  547. // CXmlSystemSpec
  548. /////////////////////////////////////////////////////////////////////////////
  549. // Constructor
  550. //
  551. // Create IXMLDOMDocument* for SystemSpec
  552. /////////////////////////////////////////////////////////////////////////////
  553. CXmlSystemSpec::CXmlSystemSpec()
  554. : m_pDocSystemSpec(NULL),
  555. m_pNodeSystemInfo(NULL),
  556. m_pNodeComputerSystem(NULL),
  557. m_pNodeRegKeysSW(NULL),
  558. m_pNodePlatform(NULL),
  559. m_pNodeDevices(NULL)
  560. {
  561. LOG_Block("CXmlSystemSpec()");
  562. HRESULT hr = CoCreateInstance(CLSID_DOMDocument,
  563. NULL,
  564. CLSCTX_INPROC_SERVER,
  565. IID_IXMLDOMDocument,
  566. (void **) &m_pDocSystemSpec);
  567. if (FAILED(hr))
  568. {
  569. LOG_ErrorMsg(hr);
  570. }
  571. else
  572. {
  573. IXMLDOMNode* pNodeXML = NULL;
  574. BSTR bstrNameSpaceSchema = NULL;
  575. //
  576. // create the <?xml version="1.0"?> node
  577. //
  578. pNodeXML = CreateDOMNode(m_pDocSystemSpec, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  579. if (NULL == pNodeXML) goto CleanUp;
  580. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocSystemSpec, pNodeXML));
  581. //
  582. // process the iuident.txt to find the SystemSpec schema path
  583. //
  584. TCHAR szIUDir[MAX_PATH];
  585. TCHAR szIdentFile[MAX_PATH];
  586. LPTSTR pszSystemSpecSchema = NULL;
  587. LPTSTR pszNameSpaceSchema = NULL;
  588. pszSystemSpecSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  589. if (NULL == pszSystemSpecSchema)
  590. {
  591. LOG_ErrorMsg(E_OUTOFMEMORY);
  592. goto CleanUp;
  593. }
  594. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  595. if (NULL == pszNameSpaceSchema)
  596. {
  597. LOG_ErrorMsg(E_OUTOFMEMORY);
  598. goto CleanUp;
  599. }
  600. GetIndustryUpdateDirectory(szIUDir);
  601. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir,IDENTTXT);
  602. if (FAILED(hr))
  603. {
  604. LOG_ErrorMsg(hr);
  605. goto CleanUp;
  606. }
  607. if (GetPrivateProfileString(IDENT_IUSCHEMA,
  608. IDENT_IUSCHEMA_SYSTEMSPEC,
  609. _T(""),
  610. pszSystemSpecSchema,
  611. INTERNET_MAX_URL_LENGTH,
  612. szIdentFile) == INTERNET_MAX_URL_LENGTH - 1)
  613. {
  614. LOG_Error(_T("SystemSpec schema buffer overflow"));
  615. goto CleanUp;
  616. }
  617. if ('\0' == pszSystemSpecSchema[0])
  618. {
  619. // no SystemSpec schema path specified in iuident.txt
  620. LOG_Error(_T("No schema path specified in iuident.txt for SystemSpec"));
  621. goto CleanUp;
  622. }
  623. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  624. _T("x-schema:%s"), pszSystemSpecSchema);
  625. if (FAILED(hr))
  626. {
  627. LOG_ErrorMsg(hr);
  628. goto CleanUp;
  629. }
  630. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  631. //
  632. // create the <systemInfo> node with the path of the schema
  633. //
  634. m_pNodeSystemInfo = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_SYSTEMINFO, bstrNameSpaceSchema);
  635. SafeSysFreeString(bstrNameSpaceSchema);
  636. if (NULL == m_pNodeSystemInfo) goto CleanUp;
  637. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocSystemSpec, m_pNodeSystemInfo));
  638. CleanUp:
  639. SafeReleaseNULL(pNodeXML);
  640. SafeHeapFree(pszSystemSpecSchema);
  641. SafeHeapFree(pszNameSpaceSchema);
  642. }
  643. }
  644. /////////////////////////////////////////////////////////////////////////////
  645. // Destructor
  646. //
  647. // Release IXMLDOMDocument* for SystemSpec
  648. /////////////////////////////////////////////////////////////////////////////
  649. CXmlSystemSpec::~CXmlSystemSpec()
  650. {
  651. SafeReleaseNULL(m_pNodeDevices);
  652. SafeReleaseNULL(m_pNodePlatform);
  653. SafeReleaseNULL(m_pNodeRegKeysSW);
  654. SafeReleaseNULL(m_pNodeComputerSystem);
  655. SafeReleaseNULL(m_pNodeSystemInfo);
  656. SafeReleaseNULL(m_pDocSystemSpec);
  657. }
  658. /////////////////////////////////////////////////////////////////////////////
  659. // AddComputerSystem()
  660. /////////////////////////////////////////////////////////////////////////////
  661. HRESULT CXmlSystemSpec::AddComputerSystem(BSTR bstrManufacturer,
  662. BSTR bstrModel,
  663. BSTR bstrSupportSite /*= NULL*/,
  664. INT iAdmin /*= -1*/,
  665. INT iWUDisabled /*= -1*/,
  666. INT iAUEnabled /*= -1*/,
  667. BSTR bstrPID)
  668. {
  669. LOG_Block("AddComputerSystem()");
  670. HRESULT hr = E_FAIL;
  671. m_pNodeComputerSystem = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_COMPUTERSYSTEM);
  672. if (NULL == m_pNodeComputerSystem) return hr;
  673. //
  674. // Manufacturer and Model are now optional (RAID#337879 IU: can't get latest IU controls to work with IU site)
  675. //
  676. if (NULL != bstrManufacturer)
  677. {
  678. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_MANUFACTURER, bstrManufacturer));
  679. }
  680. if (NULL != bstrModel)
  681. {
  682. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_MODEL, bstrModel));
  683. }
  684. if (NULL != bstrSupportSite)
  685. {
  686. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_SUPPORTSITE, bstrSupportSite));
  687. }
  688. if (NULL != bstrPID)
  689. {
  690. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_PID, bstrPID));
  691. }
  692. if (-1 != iAdmin)
  693. {
  694. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_ADMINISTRATOR, iAdmin));
  695. }
  696. if (-1 != iWUDisabled)
  697. {
  698. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_WU_DISABLED, iWUDisabled));
  699. }
  700. if (-1 != iAUEnabled)
  701. {
  702. ReturnIfFail(SetAttribute(m_pNodeComputerSystem, KEY_AU_ENABLED, iAUEnabled));
  703. }
  704. ReturnIfFail(InsertNode(m_pNodeSystemInfo, m_pNodeComputerSystem));
  705. return hr;
  706. }
  707. /////////////////////////////////////////////////////////////////////////////
  708. // AddDriveSpace()
  709. /////////////////////////////////////////////////////////////////////////////
  710. HRESULT CXmlSystemSpec::AddDriveSpace(BSTR bstrDrive, INT iKBytes)
  711. {
  712. LOG_Block("AddDriveSpace()");
  713. HRESULT hr = E_FAIL;
  714. IXMLDOMNode* pNodeDriveSpace = NULL;
  715. pNodeDriveSpace = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_DRIVESPACE);
  716. if (NULL == pNodeDriveSpace) goto CleanUp;
  717. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDriveSpace, KEY_DRIVE, bstrDrive));
  718. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDriveSpace, KEY_KBYTES, iKBytes));
  719. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeComputerSystem, pNodeDriveSpace));
  720. CleanUp:
  721. SafeReleaseNULL(pNodeDriveSpace);
  722. return hr;
  723. }
  724. /////////////////////////////////////////////////////////////////////////////
  725. // AddReg()
  726. /////////////////////////////////////////////////////////////////////////////
  727. HRESULT CXmlSystemSpec::AddReg(BSTR bstrProvider)
  728. {
  729. LOG_Block("AddReg()");
  730. HRESULT hr = E_FAIL;
  731. IXMLDOMNode* pNodeRegKeys = NULL;
  732. IXMLDOMNode* pNodeRegKeysHKLM = NULL;
  733. IXMLDOMNode* pNodeRegValue = NULL;
  734. IXMLDOMNode* pNodeRegValueText = NULL;
  735. if (NULL == m_pNodeRegKeysSW)
  736. {
  737. //
  738. // create the <regKeys> node
  739. //
  740. pNodeRegKeys = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_REGKEYS);
  741. if (NULL == pNodeRegKeys) goto CleanUp;
  742. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeSystemInfo, pNodeRegKeys));
  743. //
  744. // create the <HKEY_LOCAL_MACHINE> node
  745. //
  746. pNodeRegKeysHKLM = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_REG_HKLM);
  747. if (NULL == pNodeRegKeysHKLM) goto CleanUp;
  748. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeRegKeys, pNodeRegKeysHKLM));
  749. //
  750. // create the <SOFTWARE> node
  751. //
  752. m_pNodeRegKeysSW = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_REG_SW);
  753. if (NULL == m_pNodeRegKeysSW) goto CleanUp;
  754. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeRegKeysHKLM, m_pNodeRegKeysSW));
  755. }
  756. //
  757. // add the <value> node
  758. //
  759. pNodeRegValue = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_VALUE);
  760. if (NULL == pNodeRegValue) goto CleanUp;
  761. pNodeRegValueText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  762. if (NULL == pNodeRegValueText) goto CleanUp;
  763. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeRegValueText, bstrProvider));
  764. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeRegValue, pNodeRegValueText));
  765. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeRegKeysSW, pNodeRegValue));
  766. CleanUp:
  767. if (FAILED(hr))
  768. SafeReleaseNULL(m_pNodeRegKeysSW);
  769. SafeReleaseNULL(pNodeRegKeys);
  770. SafeReleaseNULL(pNodeRegKeysHKLM);
  771. SafeReleaseNULL(pNodeRegValue);
  772. SafeReleaseNULL(pNodeRegValueText);
  773. return hr;
  774. }
  775. /////////////////////////////////////////////////////////////////////////////
  776. // AddPlatform()
  777. /////////////////////////////////////////////////////////////////////////////
  778. HRESULT CXmlSystemSpec::AddPlatform(BSTR bstrName)
  779. {
  780. LOG_Block("AddPlatform()");
  781. HRESULT hr = E_FAIL;
  782. m_pNodePlatform = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_PLATFORM);
  783. if (NULL == m_pNodePlatform) return hr;
  784. ReturnIfFail(SetAttribute(m_pNodePlatform, KEY_NAME, bstrName));
  785. ReturnIfFail(InsertNode(m_pNodeSystemInfo, m_pNodePlatform));
  786. return hr;
  787. }
  788. /////////////////////////////////////////////////////////////////////////////
  789. // AddProcessor()
  790. /////////////////////////////////////////////////////////////////////////////
  791. HRESULT CXmlSystemSpec::AddProcessor(BSTR bstrProcessor)
  792. {
  793. LOG_Block("AddProcessor()");
  794. HRESULT hr = E_FAIL;
  795. IXMLDOMNode* pNodeProcessor = NULL;
  796. IXMLDOMNode* pNodeProcessorText = NULL;
  797. pNodeProcessor = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_PROCESSORARCHITECTURE);
  798. if (NULL == pNodeProcessor) goto CleanUp;
  799. pNodeProcessorText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  800. if (NULL == pNodeProcessorText) goto CleanUp;
  801. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeProcessorText, bstrProcessor));
  802. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeProcessor, pNodeProcessorText));
  803. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodePlatform, pNodeProcessor));
  804. CleanUp:
  805. SafeReleaseNULL(pNodeProcessor);
  806. SafeReleaseNULL(pNodeProcessorText);
  807. return hr;
  808. }
  809. /////////////////////////////////////////////////////////////////////////////
  810. // AddVersion()
  811. /////////////////////////////////////////////////////////////////////////////
  812. HRESULT CXmlSystemSpec::AddVersion(INT iMajor /*= -1*/,
  813. INT iMinor /*= -1*/,
  814. INT iBuild /*= -1*/,
  815. INT iSPMajor /*= -1*/,
  816. INT iSPMinor /*= -1*/,
  817. BSTR bstrTimeStamp /*= NULL*/)
  818. {
  819. LOG_Block("AddVersion()");
  820. HRESULT hr = E_FAIL;
  821. IXMLDOMNode* pNodeVersion = NULL;
  822. //
  823. // create the <version> node
  824. //
  825. pNodeVersion = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_VERSION);
  826. if (NULL == pNodeVersion) goto CleanUp;
  827. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodePlatform, pNodeVersion));
  828. //
  829. // set the "major" attribute
  830. //
  831. if (-1 != iMajor)
  832. {
  833. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_MAJOR, iMajor));
  834. }
  835. //
  836. // set the "minor" attribute
  837. //
  838. if (-1 != iMinor)
  839. {
  840. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_MINOR, iMinor));
  841. }
  842. //
  843. // set the "build" attribute
  844. //
  845. if (-1 != iBuild)
  846. {
  847. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_BUILD, iBuild));
  848. }
  849. //
  850. // set the "servicePackMajor" attribute
  851. //
  852. if (-1 != iSPMajor)
  853. {
  854. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_SERVICEPACKMAJOR, iSPMajor));
  855. }
  856. //
  857. // set the "servicePackMinor" attribute
  858. //
  859. if (-1 != iSPMinor)
  860. {
  861. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_SERVICEPACKMINOR, iSPMinor));
  862. }
  863. //
  864. // set the "timestamp" attribute
  865. //
  866. if (NULL != bstrTimeStamp)
  867. {
  868. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeVersion, KEY_TIMESTAMP, bstrTimeStamp));
  869. }
  870. CleanUp:
  871. SafeReleaseNULL(pNodeVersion);
  872. return hr;
  873. }
  874. /////////////////////////////////////////////////////////////////////////////
  875. // AddSuite()
  876. /////////////////////////////////////////////////////////////////////////////
  877. HRESULT CXmlSystemSpec::AddSuite(BSTR bstrSuite)
  878. {
  879. LOG_Block("AddSuite()");
  880. HRESULT hr = E_FAIL;
  881. IXMLDOMNode* pNodeSuite = NULL;
  882. IXMLDOMNode* pNodeSuiteText = NULL;
  883. pNodeSuite = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_SUITE);
  884. if (NULL == pNodeSuite) goto CleanUp;
  885. pNodeSuiteText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  886. if (NULL == pNodeSuiteText) goto CleanUp;
  887. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeSuiteText, bstrSuite));
  888. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeSuite, pNodeSuiteText));
  889. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodePlatform, pNodeSuite));
  890. CleanUp:
  891. SafeReleaseNULL(pNodeSuite);
  892. SafeReleaseNULL(pNodeSuiteText);
  893. return hr;
  894. }
  895. /////////////////////////////////////////////////////////////////////////////
  896. // AddProductType()
  897. /////////////////////////////////////////////////////////////////////////////
  898. HRESULT CXmlSystemSpec::AddProductType(BSTR bstrProductType)
  899. {
  900. LOG_Block("AddProductType()");
  901. HRESULT hr = E_FAIL;
  902. IXMLDOMNode* pNodeProductType = NULL;
  903. IXMLDOMNode* pNodeProductTypeText = NULL;
  904. pNodeProductType = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_PRODUCTTYPE);
  905. if (NULL == pNodeProductType) goto CleanUp;
  906. pNodeProductTypeText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  907. if (NULL == pNodeProductTypeText) goto CleanUp;
  908. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeProductTypeText, bstrProductType));
  909. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeProductType, pNodeProductTypeText));
  910. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodePlatform, pNodeProductType));
  911. CleanUp:
  912. SafeReleaseNULL(pNodeProductType);
  913. SafeReleaseNULL(pNodeProductTypeText);
  914. return hr;
  915. }
  916. /////////////////////////////////////////////////////////////////////////////
  917. // AddLocale()
  918. //
  919. // We need to pass back a handle to differentiate different <locale> node
  920. /////////////////////////////////////////////////////////////////////////////
  921. HRESULT CXmlSystemSpec::AddLocale(BSTR bstrContext, HANDLE_NODE* phNodeLocale)
  922. {
  923. LOG_Block("AddLocale()");
  924. HRESULT hr = E_FAIL;
  925. *phNodeLocale = CreateDOMNodeWithHandle(m_pDocSystemSpec, NODE_ELEMENT, KEY_LOCALE);
  926. if (HANDLE_NODE_INVALID == *phNodeLocale) return hr;
  927. hr = SetAttribute(m_ppNodeArray[*phNodeLocale], KEY_CONTEXT, bstrContext);
  928. if (FAILED(hr))
  929. {
  930. SafeCloseHandleNode(*phNodeLocale);
  931. LOG_ErrorMsg(hr);
  932. return hr;
  933. }
  934. ReturnIfFail(InsertNode(m_pNodeSystemInfo, m_ppNodeArray[*phNodeLocale]));
  935. return hr;
  936. }
  937. /////////////////////////////////////////////////////////////////////////////
  938. // AddLanguage()
  939. /////////////////////////////////////////////////////////////////////////////
  940. HRESULT CXmlSystemSpec::AddLanguage(HANDLE_NODE hNodeLocale, BSTR bstrLocale)
  941. {
  942. LOG_Block("AddLanguage()");
  943. HRESULT hr = E_FAIL;
  944. IXMLDOMNode* pNodeLanguage = NULL;
  945. IXMLDOMNode* pNodeLanguageText = NULL;
  946. pNodeLanguage = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_LANGUAGE);
  947. if (NULL == pNodeLanguage) goto CleanUp;
  948. pNodeLanguageText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  949. if (NULL == pNodeLanguageText) goto CleanUp;
  950. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeLanguageText, bstrLocale));
  951. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeLanguage, pNodeLanguageText));
  952. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeLocale], pNodeLanguage));
  953. CleanUp:
  954. SafeReleaseNULL(pNodeLanguage);
  955. SafeReleaseNULL(pNodeLanguageText);
  956. return hr;
  957. }
  958. /////////////////////////////////////////////////////////////////////////////
  959. // AddDevice()
  960. //
  961. // We need to pass back a handle to differentiate different <device> node
  962. /////////////////////////////////////////////////////////////////////////////
  963. HRESULT CXmlSystemSpec::AddDevice(BSTR bstrDeviceInstance, /*= NULL - optional attribute*/
  964. INT iIsPrinter /*= -1*/,
  965. BSTR bstrProvider /*= NULL*/,
  966. BSTR bstrMfgName /*= NULL*/,
  967. BSTR bstrDriverName /*= NULL*/,
  968. HANDLE_NODE* phNodeDevice)
  969. {
  970. LOG_Block("AddDevice()");
  971. HRESULT hr = E_FAIL;
  972. IXMLDOMNode* pNodePrinterInfo = NULL;
  973. if (NULL == m_pNodeDevices)
  974. {
  975. //
  976. // create the <devices> node
  977. //
  978. m_pNodeDevices = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_DEVICES);
  979. if (NULL == m_pNodeDevices) goto CleanUp;
  980. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeSystemInfo, m_pNodeDevices));
  981. }
  982. //
  983. // add the <device> node
  984. //
  985. *phNodeDevice = CreateDOMNodeWithHandle(m_pDocSystemSpec, NODE_ELEMENT, KEY_DEVICE);
  986. if (HANDLE_NODE_INVALID == *phNodeDevice) goto CleanUp;
  987. if (NULL != bstrDeviceInstance && 0 < lstrlenW(bstrDeviceInstance))
  988. {
  989. //
  990. // set optional deviceInstance attribute of <device>
  991. //
  992. CleanUpIfFailedAndSetHrMsg(SetAttribute(m_ppNodeArray[*phNodeDevice], KEY_DEVICEINSTANCE, bstrDeviceInstance));
  993. }
  994. if (-1 != iIsPrinter)
  995. {
  996. //
  997. // set isPrinter attribute of <device>
  998. //
  999. CleanUpIfFailedAndSetHrMsg(SetAttribute(m_ppNodeArray[*phNodeDevice], KEY_ISPRINTER, iIsPrinter));
  1000. //
  1001. // Add a <printerInfo> node within <device>
  1002. //
  1003. pNodePrinterInfo = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, KEY_PRINTERINFO);
  1004. if (NULL != pNodePrinterInfo)
  1005. {
  1006. if (NULL != bstrProvider)
  1007. {
  1008. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodePrinterInfo, KEY_DRIVERPROVIDER, bstrProvider));
  1009. }
  1010. if (NULL != bstrMfgName)
  1011. {
  1012. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodePrinterInfo, KEY_MFGNAME, bstrMfgName));
  1013. }
  1014. if (NULL != bstrDriverName)
  1015. {
  1016. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodePrinterInfo, KEY_DRIVERNAME, bstrDriverName));
  1017. }
  1018. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeDevice], pNodePrinterInfo));
  1019. }
  1020. }
  1021. //
  1022. // insert to <devices>
  1023. //
  1024. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeDevices, m_ppNodeArray[*phNodeDevice]));
  1025. CleanUp:
  1026. SafeReleaseNULL(pNodePrinterInfo);
  1027. return hr;
  1028. }
  1029. /////////////////////////////////////////////////////////////////////////////
  1030. // AddHWID()
  1031. /////////////////////////////////////////////////////////////////////////////
  1032. HRESULT CXmlSystemSpec::AddHWID(HANDLE_NODE hNodeDevice,
  1033. BOOL fIsCompatible,
  1034. UINT iRank,
  1035. BSTR bstrHWID,
  1036. BSTR bstrDriverVer /*= NULL*/)
  1037. {
  1038. LOG_Block("AddHWID()");
  1039. HRESULT hr = E_FAIL;
  1040. IXMLDOMNode* pNodeHWID = NULL;
  1041. IXMLDOMNode* pNodeHWIDText = NULL;
  1042. BSTR bstrNameHWID = NULL;
  1043. if (fIsCompatible)
  1044. {
  1045. bstrNameHWID = SysAllocString(L"compid");
  1046. }
  1047. else
  1048. {
  1049. bstrNameHWID = SysAllocString(L"hwid");
  1050. }
  1051. pNodeHWID = CreateDOMNode(m_pDocSystemSpec, NODE_ELEMENT, bstrNameHWID);
  1052. if (NULL == pNodeHWID) goto CleanUp;
  1053. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeHWID, KEY_RANK, iRank));
  1054. if (NULL != bstrDriverVer)
  1055. {
  1056. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeHWID, KEY_DRIVERVER, bstrDriverVer));
  1057. }
  1058. pNodeHWIDText = CreateDOMNode(m_pDocSystemSpec, NODE_TEXT, NULL);
  1059. if (NULL == pNodeHWIDText) goto CleanUp;
  1060. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeHWIDText, bstrHWID));
  1061. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeHWID, pNodeHWIDText));
  1062. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeDevice], pNodeHWID));
  1063. CleanUp:
  1064. SafeReleaseNULL(pNodeHWID);
  1065. SafeReleaseNULL(pNodeHWIDText);
  1066. SysFreeString(bstrNameHWID);
  1067. return hr;
  1068. }
  1069. /////////////////////////////////////////////////////////////////////////////
  1070. // GetSystemSpecBSTR()
  1071. /////////////////////////////////////////////////////////////////////////////
  1072. HRESULT CXmlSystemSpec::GetSystemSpecBSTR(BSTR *pbstrXmlSystemSpec)
  1073. {
  1074. LOG_Block("GetSystemSpecBSTR()");
  1075. //
  1076. // convert XML DOC into BSTR
  1077. //
  1078. HRESULT hr = m_pDocSystemSpec->get_xml(pbstrXmlSystemSpec);
  1079. if (FAILED(hr))
  1080. {
  1081. LOG_ErrorMsg(hr);
  1082. }
  1083. return hr;
  1084. }
  1085. /////////////////////////////////////////////////////////////////////////////
  1086. // CXmlSystemClass
  1087. /////////////////////////////////////////////////////////////////////////////
  1088. // Constructor
  1089. //
  1090. // Create IXMLDOMDocument* for SystemInfoClasses
  1091. /////////////////////////////////////////////////////////////////////////////
  1092. CXmlSystemClass::CXmlSystemClass()
  1093. : m_pDocSystemClass(NULL)
  1094. {
  1095. }
  1096. /////////////////////////////////////////////////////////////////////////////
  1097. // Destructor
  1098. //
  1099. // Release IXMLDOMDocument* for SystemInfoClasses
  1100. /////////////////////////////////////////////////////////////////////////////
  1101. CXmlSystemClass::~CXmlSystemClass()
  1102. {
  1103. SafeReleaseNULL(m_pDocSystemClass);
  1104. }
  1105. /////////////////////////////////////////////////////////////////////////////
  1106. // LoadXMLDocument()
  1107. //
  1108. // Load an XML Document from string
  1109. /////////////////////////////////////////////////////////////////////////////
  1110. HRESULT CXmlSystemClass::LoadXMLDocument(BSTR bstrXml, BOOL fOfflineMode)
  1111. {
  1112. LOG_Block("LoadXMLDocument()");
  1113. SafeReleaseNULL(m_pDocSystemClass);
  1114. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocSystemClass, fOfflineMode);
  1115. if (FAILED(hr))
  1116. {
  1117. LOG_ErrorMsg(hr);
  1118. }
  1119. return hr;
  1120. }
  1121. /////////////////////////////////////////////////////////////////////////////
  1122. // GetClasses()
  1123. //
  1124. // Return the bitmap of existence of all possible system info classes
  1125. /////////////////////////////////////////////////////////////////////////////
  1126. DWORD CXmlSystemClass::GetClasses()
  1127. {
  1128. LOG_Block("GetClasses()");
  1129. DWORD dwResult = 0;
  1130. IXMLDOMNodeList* pNodeList = NULL;
  1131. BSTR bstrNameComputerSystem = SysAllocString(L"classes/computerSystem");
  1132. BSTR bstrNameRegKeys = SysAllocString(L"classes/regKeys");
  1133. BSTR bstrNamePlatform = SysAllocString(L"classes/platform");
  1134. BSTR bstrNameLocale = SysAllocString(L"classes/locale");
  1135. BSTR bstrNameDevices = SysAllocString(L"classes/devices");
  1136. pNodeList = FindDOMNodeList(m_pDocSystemClass, bstrNameComputerSystem);
  1137. if (NULL != pNodeList)
  1138. {
  1139. dwResult |= COMPUTERSYSTEM;
  1140. SafeReleaseNULL(pNodeList);
  1141. }
  1142. pNodeList = FindDOMNodeList(m_pDocSystemClass, bstrNameRegKeys);
  1143. if (NULL != pNodeList)
  1144. {
  1145. dwResult |= REGKEYS;
  1146. SafeReleaseNULL(pNodeList);
  1147. }
  1148. pNodeList = FindDOMNodeList(m_pDocSystemClass, bstrNamePlatform);
  1149. if (NULL != pNodeList)
  1150. {
  1151. dwResult |= PLATFORM;
  1152. SafeReleaseNULL(pNodeList);
  1153. }
  1154. pNodeList = FindDOMNodeList(m_pDocSystemClass, bstrNameLocale);
  1155. if (NULL != pNodeList)
  1156. {
  1157. dwResult |= LOCALE;
  1158. SafeReleaseNULL(pNodeList);
  1159. }
  1160. pNodeList = FindDOMNodeList(m_pDocSystemClass, bstrNameDevices);
  1161. if (NULL != pNodeList)
  1162. {
  1163. dwResult |= DEVICES;
  1164. SafeReleaseNULL(pNodeList);
  1165. }
  1166. SysFreeString(bstrNameComputerSystem);
  1167. SysFreeString(bstrNameRegKeys);
  1168. SysFreeString(bstrNamePlatform);
  1169. SysFreeString(bstrNameLocale);
  1170. SysFreeString(bstrNameDevices);
  1171. return dwResult;
  1172. }
  1173. /////////////////////////////////////////////////////////////////////////////
  1174. // CXmlCatalog
  1175. /////////////////////////////////////////////////////////////////////////////
  1176. // Constructor
  1177. //
  1178. // Create IXMLDOMDocument* for Catalog
  1179. /////////////////////////////////////////////////////////////////////////////
  1180. CXmlCatalog::CXmlCatalog()
  1181. : m_pDocCatalog(NULL)
  1182. {
  1183. }
  1184. /////////////////////////////////////////////////////////////////////////////
  1185. // Destructor
  1186. //
  1187. // Release IXMLDOMDocument* for Catalog
  1188. /////////////////////////////////////////////////////////////////////////////
  1189. CXmlCatalog::~CXmlCatalog()
  1190. {
  1191. SafeReleaseNULL(m_pDocCatalog);
  1192. }
  1193. /////////////////////////////////////////////////////////////////////////////
  1194. // LoadXMLDocument()
  1195. //
  1196. // Load an XML Document from string
  1197. /////////////////////////////////////////////////////////////////////////////
  1198. HRESULT CXmlCatalog::LoadXMLDocument(BSTR bstrXml, BOOL fOfflineMode)
  1199. {
  1200. LOG_Block("LoadXMLDocument()");
  1201. SafeReleaseNULL(m_pDocCatalog);
  1202. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocCatalog, fOfflineMode);
  1203. if (FAILED(hr))
  1204. {
  1205. LOG_ErrorMsg(hr);
  1206. }
  1207. return hr;
  1208. }
  1209. /////////////////////////////////////////////////////////////////////////////
  1210. // GetItemCount()
  1211. //
  1212. // Gets a Count of How Many Items are in this Catalog
  1213. /////////////////////////////////////////////////////////////////////////////
  1214. HRESULT CXmlCatalog::GetItemCount(LONG *plItemCount)
  1215. {
  1216. LOG_Block("GetItemCount()");
  1217. HRESULT hr = E_FAIL;
  1218. IXMLDOMNodeList *pItemList = NULL;
  1219. QuitIfNull(plItemCount);
  1220. QuitIfNull(m_pDocCatalog);
  1221. IXMLDOMNode *pParentNode = NULL;
  1222. CleanUpIfFailedAndSetHrMsg(m_pDocCatalog->QueryInterface(IID_IXMLDOMNode, (void**)&pParentNode));
  1223. CleanUpIfFailedAndSetHrMsg(pParentNode->selectNodes(KEY_ITEM_SEARCH, &pItemList));
  1224. if (NULL == pItemList) goto CleanUp;
  1225. CleanUpIfFailedAndSetHrMsg(pItemList->get_length(plItemCount));
  1226. CleanUp:
  1227. SafeReleaseNULL(pParentNode);
  1228. SafeReleaseNULL(pItemList);
  1229. return hr;
  1230. }
  1231. /////////////////////////////////////////////////////////////////////////////
  1232. // GetProviders()
  1233. //
  1234. // Find a list of <provider> node in catalog xml
  1235. /////////////////////////////////////////////////////////////////////////////
  1236. IXMLDOMNodeList* CXmlCatalog::GetProviders()
  1237. {
  1238. LOG_Block("GetProviders()");
  1239. IXMLDOMNodeList* pNodeList = NULL;
  1240. pNodeList = FindDOMNodeList(m_pDocCatalog, KEY_CATALOG_PROVIDER);
  1241. return pNodeList;
  1242. }
  1243. /////////////////////////////////////////////////////////////////////////////
  1244. // GetFirstProvider()
  1245. //
  1246. // Find the first provider in catalog xml doc
  1247. /////////////////////////////////////////////////////////////////////////////
  1248. HANDLE_NODELIST CXmlCatalog::GetFirstProvider(HANDLE_NODE* phNodeProvider)
  1249. {
  1250. LOG_Block("GetFirstProvider()");
  1251. HANDLE_NODELIST hNodeListProvider = FindFirstDOMNode(m_pDocCatalog, KEY_CATALOG_PROVIDER, phNodeProvider);
  1252. return hNodeListProvider;
  1253. }
  1254. /////////////////////////////////////////////////////////////////////////////
  1255. // GetNextProvider()
  1256. //
  1257. // Find the next provider in catalog xml doc
  1258. /////////////////////////////////////////////////////////////////////////////
  1259. HRESULT CXmlCatalog::GetNextProvider(HANDLE_NODELIST hNodeListProvider, HANDLE_NODE* phNodeProvider)
  1260. {
  1261. LOG_Block("GetNextProvider()");
  1262. return FindNextDOMNode(hNodeListProvider, phNodeProvider);
  1263. }
  1264. /////////////////////////////////////////////////////////////////////////////
  1265. // GetFirstItem()
  1266. //
  1267. // Find the first item in provider (parent) node
  1268. /////////////////////////////////////////////////////////////////////////////
  1269. HANDLE_NODELIST CXmlCatalog::GetFirstItem(HANDLE_NODE hNodeProvider, HANDLE_NODE* phNodeItem)
  1270. {
  1271. LOG_Block("GetFirstItem()");
  1272. HANDLE_NODELIST hNodeListItem = FindFirstDOMNode(m_ppNodeArray[hNodeProvider], KEY_ITEM, phNodeItem);
  1273. return hNodeListItem;
  1274. }
  1275. /////////////////////////////////////////////////////////////////////////////
  1276. // GetNextItem()
  1277. //
  1278. // Find the next item in provider (parent) node
  1279. /////////////////////////////////////////////////////////////////////////////
  1280. HRESULT CXmlCatalog::GetNextItem(HANDLE_NODELIST hNodeListItem, HANDLE_NODE* phNodeItem)
  1281. {
  1282. LOG_Block("GetNextItem()");
  1283. return FindNextDOMNode(hNodeListItem, phNodeItem);
  1284. }
  1285. /////////////////////////////////////////////////////////////////////////////
  1286. // GetFirstItemDependency()
  1287. //
  1288. // Find the first dependency item in Item Dependencies node
  1289. /////////////////////////////////////////////////////////////////////////////
  1290. HANDLE_NODELIST CXmlCatalog::GetFirstItemDependency(HANDLE_NODE hNodeItem, HANDLE_NODE* phNodeItem)
  1291. {
  1292. LOG_Block("GetFirstItemDependency");
  1293. HRESULT hr;
  1294. QuitIfNull(phNodeItem);
  1295. IXMLDOMNode* pNodeDependencies = NULL;
  1296. IXMLDOMNode* pNodeIdentity = NULL;
  1297. HANDLE_NODELIST hNodeListItem = HANDLE_NODELIST_INVALID;
  1298. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_DEPENDENCIES, &pNodeDependencies);
  1299. QuitIfFail(hr);
  1300. hNodeListItem = FindFirstDOMNode(pNodeDependencies, KEY_IDENTITY, &pNodeIdentity);
  1301. if (HANDLE_NODELIST_INVALID != hNodeListItem)
  1302. {
  1303. // We found at least one Identity in this Dependencies key, Try to find the matching
  1304. // Item in the Catalog and if found return as the phNodeItem
  1305. FindItemByIdentity(pNodeIdentity, phNodeItem);
  1306. }
  1307. CleanUp:
  1308. SafeReleaseNULL(pNodeIdentity);
  1309. SafeReleaseNULL(pNodeDependencies);
  1310. return hNodeListItem;
  1311. }
  1312. /////////////////////////////////////////////////////////////////////////////
  1313. // GetNextItemDependency()
  1314. //
  1315. // Find the next dependency item in the Item Dependencies node
  1316. /////////////////////////////////////////////////////////////////////////////
  1317. HRESULT CXmlCatalog::GetNextItemDependency(HANDLE_NODELIST hNodeListItem, HANDLE_NODE* phNodeItem)
  1318. {
  1319. LOG_Block("GetNextItemDependency");
  1320. HRESULT hr;
  1321. QuitIfNull(phNodeItem);
  1322. IXMLDOMNode* pNodeIdentity = NULL;
  1323. hr = FindNextDOMNode(hNodeListItem, &pNodeIdentity);
  1324. // This function is supposed to return S_FALSE when no more items are available
  1325. // but FindNextDOMNode returns E_FAIL when it can't find the next node. So we won't
  1326. // look at the return.
  1327. // CleanUpIfFailedAndMsg(hr);
  1328. if (NULL != pNodeIdentity)
  1329. {
  1330. // We found another Identity in this Dependencies Key
  1331. hr = FindItemByIdentity(pNodeIdentity, phNodeItem);
  1332. }
  1333. else
  1334. {
  1335. hr = S_FALSE; // indicate to caller there are no more identities.
  1336. }
  1337. SafeReleaseNULL(pNodeIdentity);
  1338. return hr;
  1339. }
  1340. /////////////////////////////////////////////////////////////////////////////
  1341. // CloseItemList()
  1342. //
  1343. // Release the item nodelist
  1344. /////////////////////////////////////////////////////////////////////////////
  1345. void CXmlCatalog::CloseItemList(HANDLE_NODELIST hNodeListItem)
  1346. {
  1347. SafeFindCloseHandle(hNodeListItem);
  1348. }
  1349. /////////////////////////////////////////////////////////////////////////////
  1350. // GetIdentity()
  1351. //
  1352. // Retrieve the unique name (identity) of the given provider or item
  1353. /////////////////////////////////////////////////////////////////////////////
  1354. //
  1355. // public version
  1356. //
  1357. HRESULT CXmlCatalog::GetIdentity(HANDLE_NODE hNode,
  1358. BSTR* pbstrName,
  1359. BSTR* pbstrPublisherName,
  1360. BSTR* pbstrGUID)
  1361. {
  1362. LOG_Block("GetIdentity()");
  1363. HRESULT hr = E_FAIL;
  1364. IXMLDOMNode* pNodeIdentity = NULL;
  1365. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNode], KEY_IDENTITY, &pNodeIdentity));
  1366. hr = Get3IdentiStrFromIdentNode(pNodeIdentity, pbstrName, pbstrPublisherName, pbstrGUID);
  1367. CleanUp:
  1368. SafeReleaseNULL(pNodeIdentity);
  1369. return hr;
  1370. }
  1371. /////////////////////////////////////////////////////////////////////////////
  1372. // GetIdentityStr()
  1373. //
  1374. // Retrieve the string that can be used to uniquely identify an object
  1375. // based on its <identity> node.
  1376. //
  1377. // This function defines the logic about what components can be used
  1378. // to define the uniqueness of an item based on the 3 parts of data from
  1379. // GetIdentity().
  1380. //
  1381. // The created string will be language neutral. That is, it can not
  1382. // ensure the uniqueness for two items having the same <identity> node
  1383. // except different only on <langauge> part inside <identity>
  1384. //
  1385. /////////////////////////////////////////////////////////////////////////////
  1386. HRESULT CXmlCatalog::GetIdentityStr(HANDLE_NODE hNode,
  1387. BSTR* pbstrUniqIdentifierString)
  1388. {
  1389. IXMLDOMNode* pIdentityNode = NULL;
  1390. HRESULT hr = E_INVALIDARG;
  1391. if (FindNode(m_ppNodeArray[hNode], KEY_IDENTITY, &pIdentityNode) && NULL != pIdentityNode)
  1392. {
  1393. hr = UtilGetUniqIdentityStr(pIdentityNode, pbstrUniqIdentifierString, 0x0);
  1394. SafeReleaseNULL(pIdentityNode);
  1395. }
  1396. return hr;
  1397. }
  1398. HRESULT CXmlCatalog::GetIdentityStrForPing(HANDLE_NODE hNode,
  1399. BSTR* pbstrUniqIdentifierString)
  1400. {
  1401. IXMLDOMNode* pIdentityNode = NULL;
  1402. HRESULT hr = E_INVALIDARG;
  1403. if (FindNode(m_ppNodeArray[hNode], KEY_IDENTITY, &pIdentityNode) && NULL != pIdentityNode)
  1404. {
  1405. //
  1406. // first, based on OP team's requirement, we try to look for <itemId> in the identity tag.
  1407. // if it's there, use use that. If not, we use the publisherName.itemname thing.
  1408. //
  1409. if (FAILED(hr = GetAttribute(pIdentityNode, KEY_ITEMID, pbstrUniqIdentifierString)) || NULL == *pbstrUniqIdentifierString)
  1410. {
  1411. // hr = UtilGetUniqIdentityStr(pIdentityNode, pbstrUniqIdentifierString, SKIP_SERVICEPACK_VER);
  1412. hr = E_INVALIDARG;
  1413. }
  1414. SafeReleaseNULL(pIdentityNode);
  1415. }
  1416. return hr;
  1417. }
  1418. /////////////////////////////////////////////////////////////////////////////
  1419. // GetBSTRItemForCallback()
  1420. //
  1421. // Create an item node as the passed-in node, have child nodes identity and
  1422. // platform (anything uniquely idenitify this item) then output this
  1423. // item node data as string, then delete the crated node
  1424. //
  1425. /////////////////////////////////////////////////////////////////////////////
  1426. HRESULT CXmlCatalog::GetBSTRItemForCallback(HANDLE_NODE hItem, BSTR* pbstrXmlItemForCallback)
  1427. {
  1428. HRESULT hr = E_INVALIDARG;
  1429. IXMLDOMNode* pNewItemNode = NULL;
  1430. IXMLDOMNode* pNewIdentityNode = NULL;
  1431. IXMLDOMNode* pNewPlatformNode = NULL;
  1432. IXMLDOMNode* pOldIdentityNode = NULL;
  1433. IXMLDOMNode* pOldPlatformNode = NULL;
  1434. IXMLDOMNode* p1 = NULL, *p2 = NULL;
  1435. LOG_Block("CXmlCatalog::GetBSTRItemForCallback()");
  1436. if (FAILED(hr = m_ppNodeArray[hItem]->cloneNode(VARIANT_FALSE, &pNewItemNode)) ||
  1437. FAILED(hr = FindSingleDOMNode(m_ppNodeArray[hItem], KEY_IDENTITY, &pOldIdentityNode)) ||
  1438. NULL == pOldIdentityNode ||
  1439. FAILED(hr = pOldIdentityNode->cloneNode(VARIANT_TRUE, &pNewIdentityNode)) ||
  1440. NULL == pNewIdentityNode ||
  1441. FAILED(hr = pNewItemNode->appendChild(pNewIdentityNode, &p1)) || NULL == p1)
  1442. {
  1443. if (S_FALSE == hr)
  1444. hr = E_INVALIDARG;
  1445. LOG_ErrorMsg(hr);
  1446. goto CleanUp;
  1447. }
  1448. //
  1449. // platform is optional
  1450. //
  1451. FindSingleDOMNode(m_ppNodeArray[hItem], KEY_PLATFORM, &pOldPlatformNode);
  1452. if (pOldPlatformNode)
  1453. {
  1454. if (FAILED(hr = pOldPlatformNode->cloneNode(VARIANT_TRUE, &pNewPlatformNode)) ||
  1455. NULL == pNewPlatformNode ||
  1456. FAILED(hr = pNewItemNode->appendChild(pNewPlatformNode, &p2)) || NULL == p2)
  1457. {
  1458. LOG_ErrorMsg(hr);
  1459. goto CleanUp;
  1460. }
  1461. }
  1462. pNewItemNode->get_xml(pbstrXmlItemForCallback);
  1463. CleanUp:
  1464. SafeReleaseNULL(pOldIdentityNode);
  1465. SafeReleaseNULL(pOldPlatformNode);
  1466. SafeReleaseNULL(pNewIdentityNode);
  1467. SafeReleaseNULL(pNewPlatformNode);
  1468. SafeReleaseNULL(p1);
  1469. SafeReleaseNULL(p2);
  1470. SafeReleaseNULL(pNewItemNode);
  1471. return hr;
  1472. }
  1473. /////////////////////////////////////////////////////////////////////////////
  1474. // IsPrinterDriver()
  1475. //
  1476. // Retrieves from the Catalog whether this Item is a Printer Driver
  1477. //
  1478. /////////////////////////////////////////////////////////////////////////////
  1479. BOOL CXmlCatalog::IsPrinterDriver(HANDLE_NODE hNode)
  1480. {
  1481. LOG_Block("IsPrinterDriver()");
  1482. BOOL fRet = FALSE;
  1483. HRESULT hr;
  1484. IXMLDOMNode* pNodeDetection = NULL;
  1485. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1486. IXMLDOMNode* pNodeDevice = NULL;
  1487. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1488. CleanUpIfFailedAndMsg(hr);
  1489. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1490. CleanUpIfFailedAndMsg(hr);
  1491. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1492. CleanUpIfFailedAndMsg(hr);
  1493. int intIsPrinter = 0;
  1494. GetAttribute(pNodeDevice, KEY_ISPRINTER, &intIsPrinter);
  1495. if (1 == intIsPrinter)
  1496. {
  1497. fRet = TRUE;
  1498. }
  1499. else
  1500. {
  1501. fRet = FALSE;
  1502. }
  1503. CleanUp:
  1504. SafeReleaseNULL(pNodeDevice);
  1505. SafeReleaseNULL(pNodeCompatibleHardware);
  1506. SafeReleaseNULL(pNodeDetection);
  1507. return fRet;
  1508. }
  1509. /////////////////////////////////////////////////////////////////////////////
  1510. // GetDriverInfo()
  1511. //
  1512. // Retrieves the Driver Information from the Catalog for this Item. Returns
  1513. // the Display Name and HWID for this driver - This is passed to the CDM
  1514. // installer
  1515. //
  1516. /////////////////////////////////////////////////////////////////////////////
  1517. HRESULT CXmlCatalog::GetDriverInfo(HANDLE_NODE hNode,
  1518. BSTR* pbstrHWID,
  1519. BSTR* pbstrDisplayName)
  1520. {
  1521. HRESULT hr;
  1522. LOG_Block("GetDriverInfo()");
  1523. QuitIfNull(pbstrHWID);
  1524. QuitIfNull(pbstrDisplayName);
  1525. *pbstrHWID = NULL;
  1526. *pbstrDisplayName = NULL;
  1527. IXMLDOMNode* pNodeDetection = NULL;
  1528. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1529. IXMLDOMNode* pNodeDevice = NULL;
  1530. IXMLDOMNode* pNodeHWID = NULL;
  1531. IXMLDOMNode* pNodeDescription = NULL;
  1532. IXMLDOMNode* pNodeDescriptionText = NULL;
  1533. IXMLDOMNode* pNodeTitle = NULL;
  1534. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1535. CleanUpIfFailedAndMsg(hr);
  1536. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1537. CleanUpIfFailedAndMsg(hr);
  1538. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1539. CleanUpIfFailedAndMsg(hr);
  1540. hr = FindSingleDOMNode(pNodeDevice, KEY_HWID, &pNodeHWID);
  1541. CleanUpIfFailedAndMsg(hr);
  1542. GetText(pNodeHWID, pbstrHWID);
  1543. hr = FindSingleDOMNode(pNodeDetection, KEY_DESCRIPTION, &pNodeDescription);
  1544. CleanUpIfFailedAndMsg(hr);
  1545. hr = FindSingleDOMNode(pNodeDescription, KEY_DESCRIPTIONTEXT, &pNodeDescriptionText);
  1546. CleanUpIfFailedAndMsg(hr);
  1547. hr = FindSingleDOMNode(pNodeDescriptionText, KEY_TITLE, &pNodeTitle);
  1548. CleanUpIfFailedAndMsg(hr);
  1549. GetText(pNodeTitle, pbstrDisplayName);
  1550. CleanUp:
  1551. if (FAILED(hr))
  1552. {
  1553. SafeSysFreeString(*pbstrHWID);
  1554. SafeSysFreeString(*pbstrDisplayName);
  1555. }
  1556. SafeReleaseNULL(pNodeTitle);
  1557. SafeReleaseNULL(pNodeDescriptionText);
  1558. SafeReleaseNULL(pNodeDescription);
  1559. SafeReleaseNULL(pNodeHWID);
  1560. SafeReleaseNULL(pNodeDevice);
  1561. SafeReleaseNULL(pNodeCompatibleHardware);
  1562. SafeReleaseNULL(pNodeDetection);
  1563. return hr;
  1564. }
  1565. /////////////////////////////////////////////////////////////////////////////
  1566. // GetPrinterDriverInfo()
  1567. //
  1568. // Retrieves the Printer Driver Information from the Catalog for this Item.
  1569. // Returns the DriverName and the Architecture - This is passed to the CDM
  1570. // installer
  1571. //
  1572. /////////////////////////////////////////////////////////////////////////////
  1573. HRESULT CXmlCatalog::GetPrinterDriverInfo(HANDLE_NODE hNode,
  1574. BSTR* pbstrDriverName,
  1575. BSTR* pbstrArchitecture)
  1576. {
  1577. HRESULT hr;
  1578. LOG_Block("GetPrinterDriverInfo()");
  1579. QuitIfNull(pbstrDriverName);
  1580. QuitIfNull(pbstrArchitecture);
  1581. IXMLDOMNode* pNodeDetection = NULL;
  1582. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1583. IXMLDOMNode* pNodeDevice = NULL;
  1584. IXMLDOMNode* pNodePrinterInfo = NULL;
  1585. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1586. CleanUpIfFailedAndMsg(hr);
  1587. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1588. CleanUpIfFailedAndMsg(hr);
  1589. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1590. CleanUpIfFailedAndMsg(hr);
  1591. hr = FindSingleDOMNode(pNodeDevice, KEY_PRINTERINFO, &pNodePrinterInfo);
  1592. CleanUpIfFailedAndMsg(hr);
  1593. GetAttribute(pNodePrinterInfo, KEY_DRIVERNAME, pbstrDriverName);
  1594. // NOTE: Currently the CatalogSchema site is not returning
  1595. // architecture for printers, and the schema doesn't require it
  1596. // CDM is using a default string for now based on compile architecture
  1597. // so we'll leave pbstrArchitecture NULL..
  1598. CleanUp:
  1599. SafeReleaseNULL(pNodePrinterInfo);
  1600. SafeReleaseNULL(pNodeDevice);
  1601. SafeReleaseNULL(pNodeCompatibleHardware);
  1602. SafeReleaseNULL(pNodeDetection);
  1603. return hr;
  1604. }
  1605. /////////////////////////////////////////////////////////////////////////////
  1606. // GetDriverInfoEx()
  1607. //
  1608. // Combines functionality of IsPrinterDriver, GetDriverInfo, and
  1609. // GetPrinterDriverInfo plus retreives MfgName and DriverProvider.
  1610. // Used by FindMatchingDriver()
  1611. //
  1612. // If SUCCEEDES pbstrHWID, pbstrDriverVer, and pbstrDisplayName
  1613. // are always returned.
  1614. // If SUCCEEDES && *pFIsPrinter == TRUE then pbstrDriverName,
  1615. // pbstrDriverProvider, and pbstrMfgName are returned.
  1616. //
  1617. // Currently pbstrArchitecture is never returned.
  1618. //
  1619. /////////////////////////////////////////////////////////////////////////////
  1620. HRESULT CXmlCatalog::GetDriverInfoEx( HANDLE_NODE hNode,
  1621. BOOL* pfIsPrinter,
  1622. BSTR* pbstrHWID,
  1623. BSTR* pbstrDriverVer,
  1624. BSTR* pbstrDisplayName,
  1625. BSTR* pbstrDriverName,
  1626. BSTR* pbstrDriverProvider,
  1627. BSTR* pbstrMfgName,
  1628. BSTR* pbstrArchitecture)
  1629. {
  1630. HRESULT hr;
  1631. LOG_Block("GetDriverInfoEx()");
  1632. QuitIfNull(pbstrHWID);
  1633. QuitIfNull(pbstrDriverVer);
  1634. QuitIfNull(pbstrDisplayName);
  1635. QuitIfNull(pbstrDriverName);
  1636. QuitIfNull(pbstrDriverProvider);
  1637. QuitIfNull(pbstrMfgName);
  1638. QuitIfNull(pbstrArchitecture);
  1639. *pbstrHWID = NULL;
  1640. *pbstrDriverVer = NULL;
  1641. *pbstrDisplayName = NULL;
  1642. *pbstrDriverName = NULL;
  1643. *pbstrDriverProvider = NULL;
  1644. *pbstrMfgName = NULL;
  1645. *pbstrArchitecture = NULL;
  1646. IXMLDOMNode* pNodeDetection = NULL;
  1647. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1648. IXMLDOMNode* pNodeDevice = NULL;
  1649. IXMLDOMNode* pNodeHWID = NULL;
  1650. IXMLDOMNode* pNodeDescription = NULL;
  1651. IXMLDOMNode* pNodeDescriptionText = NULL;
  1652. IXMLDOMNode* pNodeTitle = NULL;
  1653. IXMLDOMNode* pNodePrinterInfo = NULL;
  1654. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1655. CleanUpIfFailedAndMsg(hr);
  1656. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1657. CleanUpIfFailedAndMsg(hr);
  1658. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1659. CleanUpIfFailedAndMsg(hr);
  1660. //
  1661. // Is it a printer?
  1662. //
  1663. int intIsPrinter = 0;
  1664. GetAttribute(pNodeDevice, KEY_ISPRINTER, &intIsPrinter);
  1665. if (1 == intIsPrinter)
  1666. {
  1667. *pfIsPrinter = TRUE;
  1668. }
  1669. else
  1670. {
  1671. *pfIsPrinter = FALSE;
  1672. }
  1673. //
  1674. // HWID and Driver Description
  1675. //
  1676. hr = FindSingleDOMNode(pNodeDevice, KEY_HWID, &pNodeHWID);
  1677. CleanUpIfFailedAndMsg(hr);
  1678. hr = GetText(pNodeHWID, pbstrHWID);
  1679. CleanUpIfFailedAndMsg(hr);
  1680. hr = GetAttribute(pNodeHWID, KEY_DRIVERVER, pbstrDriverVer);
  1681. CleanUpIfFailedAndMsg(hr);
  1682. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DESCRIPTION, &pNodeDescription);
  1683. CleanUpIfFailedAndMsg(hr);
  1684. hr = FindSingleDOMNode(pNodeDescription, KEY_DESCRIPTIONTEXT, &pNodeDescriptionText);
  1685. CleanUpIfFailedAndMsg(hr);
  1686. hr = FindSingleDOMNode(pNodeDescriptionText, KEY_TITLE, &pNodeTitle);
  1687. CleanUpIfFailedAndMsg(hr);
  1688. hr = GetText(pNodeTitle, pbstrDisplayName);
  1689. CleanUpIfFailedAndMsg(hr);
  1690. if (*pfIsPrinter)
  1691. {
  1692. //
  1693. // Printer Attributes
  1694. //
  1695. hr = FindSingleDOMNode(pNodeDevice, KEY_PRINTERINFO, &pNodePrinterInfo);
  1696. CleanUpIfFailedAndMsg(hr);
  1697. hr = GetAttribute(pNodePrinterInfo, KEY_DRIVERNAME, pbstrDriverName);
  1698. CleanUpIfFailedAndMsg(hr);
  1699. hr = GetAttribute(pNodePrinterInfo, KEY_DRIVERPROVIDER, pbstrDriverProvider);
  1700. CleanUpIfFailedAndMsg(hr);
  1701. hr = GetAttribute(pNodePrinterInfo, KEY_MFGNAME, pbstrMfgName);
  1702. CleanUpIfFailedAndMsg(hr);
  1703. // NOTE: Currently the CatalogSchema site is not returning
  1704. // architecture for printers, and the schema doesn't require it
  1705. // CDM is using a default string for now based on compile architecture
  1706. // so we'll leave pbstrArchitecture NULL..
  1707. }
  1708. CleanUp:
  1709. if (FAILED(hr))
  1710. {
  1711. SafeSysFreeString(*pbstrHWID);
  1712. SafeSysFreeString(*pbstrDriverVer);
  1713. SafeSysFreeString(*pbstrDisplayName);
  1714. SafeSysFreeString(*pbstrDriverName);
  1715. SafeSysFreeString(*pbstrDriverProvider);
  1716. SafeSysFreeString(*pbstrMfgName);
  1717. SafeSysFreeString(*pbstrArchitecture);
  1718. }
  1719. SafeReleaseNULL(pNodeTitle);
  1720. SafeReleaseNULL(pNodeDescriptionText);
  1721. SafeReleaseNULL(pNodeDescription);
  1722. SafeReleaseNULL(pNodeHWID);
  1723. SafeReleaseNULL(pNodeDevice);
  1724. SafeReleaseNULL(pNodeCompatibleHardware);
  1725. SafeReleaseNULL(pNodeDetection);
  1726. SafeReleaseNULL(pNodePrinterInfo);
  1727. return hr;
  1728. }
  1729. /////////////////////////////////////////////////////////////////////////////
  1730. // GetItemPlatformStr()
  1731. //
  1732. // The input node pointer points to a node has <identity> as its child.
  1733. // This function will retrieve the <platform> node from <identity> and
  1734. // convert the data inside <platform> into a string that can be used to
  1735. // uniquely identify a platform.
  1736. //
  1737. /////////////////////////////////////////////////////////////////////////////
  1738. HRESULT CXmlCatalog::GetItemFirstPlatformStr(HANDLE_NODE hNodeItem,
  1739. BSTR* pbstrPlatform)
  1740. {
  1741. HRESULT hr;
  1742. IXMLDOMNode* pNodePlatform = NULL;
  1743. LOG_Block("GetItemFirstPlatformStr");
  1744. USES_IU_CONVERSION;
  1745. //
  1746. // get the first platform node from this item node
  1747. //
  1748. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatform);
  1749. CleanUpIfFailedAndMsg(hr);
  1750. //
  1751. // get platform data from this ndoe and convert it into string
  1752. //
  1753. hr = GetPlatformStrForPing(pNodePlatform, pbstrPlatform);
  1754. CleanUp:
  1755. SafeReleaseNULL(pNodePlatform);
  1756. //
  1757. // since platform is not a required element in <item>, so we should not
  1758. // return error if not found
  1759. //
  1760. if (HRESULT_FROM_WIN32(ERROR_NOT_FOUND) == hr)
  1761. {
  1762. *pbstrPlatform = NULL;
  1763. hr = S_FALSE;
  1764. }
  1765. return hr;
  1766. }
  1767. /////////////////////////////////////////////////////////////////////////////
  1768. // GetItemAllPlatformStr()
  1769. //
  1770. // The input node pointer points to an item node that has <platform> node(s).
  1771. // This function will retrieve every <platform> node from this item node and
  1772. // convert the data inside <platform> into a string that can be used to
  1773. // uniquely identify a platform.
  1774. //
  1775. /////////////////////////////////////////////////////////////////////////////
  1776. HRESULT CXmlCatalog::GetItemAllPlatformStr(HANDLE_NODE hNodeItem,
  1777. BSTR** ppbPlatforms, UINT* pnPlatformCount)
  1778. {
  1779. LOG_Block("GetItemAllPlatformStr");
  1780. HRESULT hr;
  1781. IXMLDOMNodeList* pPlatformList = NULL;
  1782. IXMLDOMElement* pElement = NULL;
  1783. IXMLDOMNode* pNodePlatform = NULL;
  1784. long lCount = 0;
  1785. int i;
  1786. BSTR* pbstrPlatformList = NULL;
  1787. //
  1788. // get list of platform nodes
  1789. //
  1790. hr = m_ppNodeArray[hNodeItem]->QueryInterface(IID_IXMLDOMElement, (void**)&pElement);
  1791. CleanUpIfFailedAndMsg(hr);
  1792. hr = pElement->getElementsByTagName(KEY_PLATFORM, &pPlatformList);
  1793. CleanUpIfFailedAndMsg(hr);
  1794. hr = pPlatformList->get_length(&lCount);
  1795. CleanUpIfFailedAndMsg(hr);
  1796. if (0 == lCount)
  1797. {
  1798. goto CleanUp;
  1799. }
  1800. pbstrPlatformList = (BSTR*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lCount * sizeof(BSTR*));
  1801. CleanUpFailedAllocSetHrMsg(pbstrPlatformList);
  1802. //
  1803. // loop through each suite, if any
  1804. //
  1805. pPlatformList->reset();
  1806. for (i = 0; i < lCount; i++)
  1807. {
  1808. hr = pPlatformList->get_item(i, &pNodePlatform);
  1809. CleanUpIfFailedAndMsg(hr);
  1810. if (pNodePlatform)
  1811. {
  1812. hr = pNodePlatform->get_text(&(pbstrPlatformList[i]));
  1813. CleanUpIfFailedAndMsg(hr);
  1814. pNodePlatform->Release();
  1815. pNodePlatform = NULL;
  1816. }
  1817. }
  1818. hr = S_OK;
  1819. CleanUp:
  1820. SafeReleaseNULL(pNodePlatform);
  1821. SafeReleaseNULL(pPlatformList);
  1822. SafeReleaseNULL(pElement);
  1823. if (SUCCEEDED(hr))
  1824. {
  1825. *pnPlatformCount = lCount;
  1826. *ppbPlatforms = pbstrPlatformList;
  1827. }
  1828. else
  1829. {
  1830. if (NULL != pbstrPlatformList)
  1831. {
  1832. *pnPlatformCount = 0;
  1833. //
  1834. // release all possibly allocated memory
  1835. //
  1836. for (i = 0; i < lCount; i++)
  1837. {
  1838. SafeSysFreeString(pbstrPlatformList[i]);
  1839. }
  1840. HeapFree(GetProcessHeap(), 0, pbstrPlatformList);
  1841. }
  1842. }
  1843. return hr;
  1844. }
  1845. /////////////////////////////////////////////////////////////////////////////
  1846. // GetItemPlatformStr()
  1847. //
  1848. // The input node pointer points to a node has <identity> as its child.
  1849. // This function will retrieve the <platform> node from <identity> and
  1850. // convert the data inside <platform> into a string that can be used to
  1851. // uniquely identify a platform.
  1852. //
  1853. /////////////////////////////////////////////////////////////////////////////
  1854. HRESULT CXmlCatalog::GetPlatformStr(IXMLDOMNode* pNodePlatform,
  1855. BSTR* pbstrPlatform)
  1856. {
  1857. return UtilGetPlatformStr(pNodePlatform, pbstrPlatform, 0x0);
  1858. }
  1859. HRESULT CXmlCatalog::GetPlatformStrForPing(IXMLDOMNode* pNodePlatform,
  1860. BSTR* pbstrPlatform)
  1861. {
  1862. return UtilGetPlatformStr(pNodePlatform, pbstrPlatform, SKIP_SUITES | SKIP_SERVICEPACK_VER);
  1863. }
  1864. /////////////////////////////////////////////////////////////////////////////
  1865. //
  1866. // get data from a version node and convert them into a string with
  1867. // format:
  1868. // VersionStr = <Version>[,<SvcPackVer>[,<timeStamp>]]
  1869. // <Version> = <Major>[.<Minor>[.<Build>]]
  1870. // <SvcPackVer> = <Major>[.<minor>]
  1871. //
  1872. // Assumption:
  1873. // pszVersion points to a buffer LARGE ENOUGH to store
  1874. // any legal version number.
  1875. //
  1876. /////////////////////////////////////////////////////////////////////////////
  1877. HRESULT CXmlCatalog::getVersionStr(IXMLDOMNode* pNodeVersion, LPTSTR pszVersion)
  1878. {
  1879. return UtilGetVersionStr(pNodeVersion, pszVersion, 0x0);
  1880. }
  1881. HRESULT CXmlCatalog::getVersionStrWithoutSvcPack(IXMLDOMNode* pNodeVersion, LPTSTR pszVersion)
  1882. {
  1883. return UtilGetVersionStr(pNodeVersion, pszVersion, SKIP_SERVICEPACK_VER);
  1884. }
  1885. /////////////////////////////////////////////////////////////////////////////
  1886. // GetItemFirstLanguageStr()
  1887. //
  1888. // The input node pointer points to a node has <identity> as its child.
  1889. // This function will retrieve the first <language> node from <identity>
  1890. // node
  1891. //
  1892. /////////////////////////////////////////////////////////////////////////////
  1893. HRESULT CXmlCatalog::GetItemFirstLanguageStr(HANDLE_NODE hNodeItem,
  1894. BSTR* pbstrLanguage)
  1895. {
  1896. LOG_Block("GetItemFirstLanguageStr");
  1897. IXMLDOMNode* pNodeIdentity = NULL;
  1898. IXMLDOMNode* pNodeLanguage = NULL;
  1899. HRESULT hr = m_ppNodeArray[hNodeItem]->selectSingleNode(KEY_IDENTITY, &pNodeIdentity);
  1900. CleanUpIfFailedAndMsg(hr);
  1901. if (pNodeIdentity)
  1902. {
  1903. if (HANDLE_NODELIST_INVALID == FindFirstDOMNode(pNodeIdentity, KEY_LANGUAGE, &pNodeLanguage))
  1904. {
  1905. hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  1906. goto CleanUp;
  1907. }
  1908. else
  1909. {
  1910. hr = pNodeLanguage->get_text(pbstrLanguage);
  1911. CleanUpIfFailedAndMsg(hr);
  1912. }
  1913. }
  1914. CleanUp:
  1915. SafeReleaseNULL(pNodeLanguage);
  1916. SafeReleaseNULL(pNodeIdentity);
  1917. //
  1918. // since language is not a required element in <identity>, so we should not
  1919. // return error if not found
  1920. //
  1921. if (HRESULT_FROM_WIN32(ERROR_NOT_FOUND) == hr)
  1922. {
  1923. *pbstrLanguage = NULL;
  1924. hr = S_FALSE;
  1925. }
  1926. return hr;
  1927. }
  1928. /////////////////////////////////////////////////////////////////////////////
  1929. // GetItemAllLanguageStr()
  1930. //
  1931. // The input node pointer points to a node has <identity> as its child.
  1932. // This function will retrieve every <language> node from <identity> node and
  1933. // convert the data into an BSTR array to return.
  1934. //
  1935. /////////////////////////////////////////////////////////////////////////////
  1936. HRESULT CXmlCatalog::GetItemAllLanguageStr(HANDLE_NODE hNodeItem,
  1937. BSTR** ppbstrLanguage, UINT* pnLangCount)
  1938. {
  1939. LOG_Block("GetItemAllLanguageStr");
  1940. HRESULT hr;
  1941. IXMLDOMNode* pNodeIdentity = NULL;
  1942. IXMLDOMNodeList* pLanguageList = NULL;
  1943. IXMLDOMElement* pElement = NULL;
  1944. IXMLDOMNode* pNodeLanguage = NULL;
  1945. long lCount = 0;
  1946. int i;
  1947. BSTR* pbstrLanguageList = NULL;
  1948. hr = m_ppNodeArray[hNodeItem]->selectSingleNode(KEY_IDENTITY, &pNodeIdentity);
  1949. CleanUpIfFailedAndMsg(hr);
  1950. //
  1951. // get list of nodes
  1952. //
  1953. hr = pNodeIdentity->QueryInterface(IID_IXMLDOMElement, (void**)&pElement);
  1954. CleanUpIfFailedAndMsg(hr);
  1955. hr = pElement->getElementsByTagName(KEY_LANGUAGE, &pLanguageList);
  1956. CleanUpIfFailedAndMsg(hr);
  1957. hr = pLanguageList->get_length(&lCount);
  1958. CleanUpIfFailedAndMsg(hr);
  1959. if (0 == lCount)
  1960. {
  1961. goto CleanUp;
  1962. }
  1963. pbstrLanguageList = (BSTR*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lCount * sizeof(BSTR*));
  1964. CleanUpFailedAllocSetHrMsg(pbstrLanguageList);
  1965. //
  1966. // loop through each suite, if any
  1967. //
  1968. pLanguageList->reset();
  1969. for (i = 0; i < lCount; i++)
  1970. {
  1971. hr = pLanguageList->get_item(i, &pNodeLanguage);
  1972. CleanUpIfFailedAndMsg(hr);
  1973. if (pNodeLanguage)
  1974. {
  1975. hr = pNodeLanguage->get_text(&(pbstrLanguageList[i]));
  1976. CleanUpIfFailedAndMsg(hr);
  1977. pNodeLanguage->Release();
  1978. pNodeLanguage = NULL;
  1979. }
  1980. }
  1981. hr = S_OK;
  1982. CleanUp:
  1983. SafeReleaseNULL(pNodeLanguage);
  1984. SafeReleaseNULL(pLanguageList);
  1985. SafeReleaseNULL(pElement);
  1986. SafeReleaseNULL(pNodeIdentity);
  1987. if (SUCCEEDED(hr))
  1988. {
  1989. *pnLangCount = lCount;
  1990. *ppbstrLanguage = pbstrLanguageList;
  1991. }
  1992. else
  1993. {
  1994. if (NULL != pbstrLanguageList)
  1995. {
  1996. *pnLangCount = 0;
  1997. //
  1998. // release all possibly allocated memory
  1999. //
  2000. for (i = 0; i < lCount; i++)
  2001. {
  2002. SafeSysFreeString(pbstrLanguageList[i]);
  2003. }
  2004. HeapFree(GetProcessHeap(), 0, pbstrLanguageList);
  2005. }
  2006. }
  2007. return hr;
  2008. }
  2009. /////////////////////////////////////////////////////////////////////////////
  2010. // GetItemFirstCodeBase()
  2011. //
  2012. // Find the first codebase (path) of the given item
  2013. /////////////////////////////////////////////////////////////////////////////
  2014. HANDLE_NODELIST CXmlCatalog::GetItemFirstCodeBase(HANDLE_NODE hNodeItem,
  2015. BSTR* pbstrCodeBase,
  2016. BSTR* pbstrName,
  2017. BSTR* pbstrCRC,
  2018. BOOL* pfPatchAvailable,
  2019. LONG* plSize)
  2020. {
  2021. LOG_Block("GetItemFirstCodeBase()");
  2022. HRESULT hr = E_FAIL;
  2023. QuitIfNull(pbstrCodeBase);
  2024. QuitIfNull(pbstrName);
  2025. QuitIfNull(pbstrCRC);
  2026. QuitIfNull(pfPatchAvailable);
  2027. QuitIfNull(plSize);
  2028. IXMLDOMNode* pNodeInstall = NULL;
  2029. IXMLDOMNode* pNodeCodeBaseSize = NULL;
  2030. HANDLE_NODE hNodeCodeBase = HANDLE_NODE_INVALID;
  2031. HANDLE_NODELIST hNodeListCodeBase = HANDLE_NODELIST_INVALID;
  2032. *pbstrCodeBase = NULL;
  2033. *pbstrName = NULL;
  2034. *pbstrCRC = NULL;
  2035. *pfPatchAvailable = FALSE;
  2036. *plSize = -1;
  2037. BSTR bstrSize = NULL;
  2038. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2039. hNodeListCodeBase = FindFirstDOMNode(pNodeInstall, KEY_CODEBASE, &hNodeCodeBase);
  2040. if (HANDLE_NODELIST_INVALID == hNodeListCodeBase) goto CleanUp;
  2041. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_HREF, pbstrCodeBase));
  2042. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_PATCHAVAILABLE, pfPatchAvailable));
  2043. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_CRC, pbstrCRC); // optional attribute, don't fail if its not there.
  2044. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_NAME, pbstrName);
  2045. FindSingleDOMNode(m_ppNodeArray[hNodeCodeBase], KEY_SIZE, &pNodeCodeBaseSize);
  2046. GetText(pNodeCodeBaseSize, &bstrSize);
  2047. if (NULL != bstrSize)
  2048. {
  2049. *plSize = MyBSTR2L(bstrSize);
  2050. SysFreeString(bstrSize);
  2051. }
  2052. CleanUp:
  2053. SafeReleaseNULL(pNodeInstall);
  2054. SafeReleaseNULL(pNodeCodeBaseSize);
  2055. if (FAILED(hr))
  2056. {
  2057. SafeSysFreeString(*pbstrCodeBase);
  2058. SafeSysFreeString(*pbstrName);
  2059. SafeSysFreeString(*pbstrCRC);
  2060. *pfPatchAvailable = FALSE;
  2061. *plSize = -1;
  2062. }
  2063. return hNodeListCodeBase;
  2064. }
  2065. /////////////////////////////////////////////////////////////////////////////
  2066. // GetItemNextCodeBase()
  2067. //
  2068. // Find the next codebase (path) of the given item
  2069. /////////////////////////////////////////////////////////////////////////////
  2070. HRESULT CXmlCatalog::GetItemNextCodeBase(HANDLE_NODELIST hNodeListCodeBase,
  2071. BSTR* pbstrCodeBase,
  2072. BSTR* pbstrName,
  2073. BSTR* pbstrCRC,
  2074. BOOL* pfPatchAvailable,
  2075. LONG* plSize)
  2076. {
  2077. LOG_Block("GetItemNextCodeBase()");
  2078. HRESULT hr = E_FAIL;
  2079. IXMLDOMNode* pNodeCodeBaseSize = NULL;
  2080. HANDLE_NODE hNodeCodeBase = HANDLE_NODE_INVALID;
  2081. if (NULL == pbstrCodeBase || NULL == pbstrName || NULL == pbstrCRC || NULL == pfPatchAvailable || NULL == plSize)
  2082. {
  2083. return E_INVALIDARG;
  2084. }
  2085. *pbstrCodeBase = NULL;
  2086. *pbstrName = NULL;
  2087. *pbstrCRC = NULL;
  2088. *pfPatchAvailable = FALSE;
  2089. *plSize = -1;
  2090. BSTR bstrSize = NULL;
  2091. if (SUCCEEDED(hr = FindNextDOMNode(hNodeListCodeBase, &hNodeCodeBase)))
  2092. {
  2093. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_HREF, pbstrCodeBase));
  2094. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_PATCHAVAILABLE, pfPatchAvailable));
  2095. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_NAME, pbstrName);
  2096. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_CRC, pbstrCRC);
  2097. FindSingleDOMNode(m_ppNodeArray[hNodeCodeBase], KEY_SIZE, &pNodeCodeBaseSize);
  2098. GetText(pNodeCodeBaseSize, &bstrSize);
  2099. if (NULL != bstrSize)
  2100. {
  2101. *plSize = MyBSTR2L(bstrSize);
  2102. }
  2103. }
  2104. CleanUp:
  2105. SafeReleaseNULL(pNodeCodeBaseSize);
  2106. SafeSysFreeString(bstrSize);
  2107. if (FAILED(hr))
  2108. {
  2109. SafeSysFreeString(*pbstrCodeBase);
  2110. SafeSysFreeString(*pbstrCRC);
  2111. SafeSysFreeString(*pbstrName);
  2112. *pfPatchAvailable = FALSE;
  2113. *plSize = -1;
  2114. }
  2115. return hr;
  2116. }
  2117. /////////////////////////////////////////////////////////////////////////////
  2118. // GetItemInstallInfo()
  2119. //
  2120. // Retrieve the installation information of the given item
  2121. /////////////////////////////////////////////////////////////////////////////
  2122. HRESULT CXmlCatalog::GetItemInstallInfo(HANDLE_NODE hNodeItem,
  2123. BSTR* pbstrInstallerType,
  2124. BOOL* pfExclusive,
  2125. BOOL* pfReboot,
  2126. LONG* plNumCommands)
  2127. {
  2128. LOG_Block("GetItemInstallInfo()");
  2129. HRESULT hr = E_FAIL;
  2130. QuitIfNull(pbstrInstallerType);
  2131. QuitIfNull(pfExclusive);
  2132. QuitIfNull(pfReboot);
  2133. QuitIfNull(plNumCommands);
  2134. *pbstrInstallerType = NULL;
  2135. *plNumCommands = 0; // may not be any, so initialize to 0
  2136. IXMLDOMNode* pNodeInstall = NULL;
  2137. IXMLDOMNodeList* pNodeListCommands = NULL;
  2138. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2139. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_INSTALLERTYPE, pbstrInstallerType));
  2140. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_EXCLUSIVE, pfExclusive));
  2141. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_NEEDSREBOOT, pfReboot));
  2142. pNodeListCommands = FindDOMNodeList(pNodeInstall, KEY_COMMAND);
  2143. if (NULL != pNodeListCommands)
  2144. {
  2145. CleanUpIfFailedAndSetHrMsg(pNodeListCommands->get_length(plNumCommands));
  2146. }
  2147. CleanUp:
  2148. if (FAILED(hr))
  2149. {
  2150. SafeSysFreeString(*pbstrInstallerType);
  2151. }
  2152. SafeReleaseNULL(pNodeInstall);
  2153. SafeReleaseNULL(pNodeListCommands);
  2154. return hr;
  2155. }
  2156. /////////////////////////////////////////////////////////////////////////////
  2157. // GetItemInstallCommand()
  2158. //
  2159. // Find the installation command and switches of the given item
  2160. /////////////////////////////////////////////////////////////////////////////
  2161. HRESULT CXmlCatalog::GetItemInstallCommand(HANDLE_NODE hNodeItem,
  2162. INT iOrder,
  2163. BSTR* pbstrCommandType,
  2164. BSTR* pbstrCommand,
  2165. BSTR* pbstrSwitches,
  2166. BSTR* pbstrInfSection)
  2167. {
  2168. LOG_Block("GetItemInstallCommand()");
  2169. USES_IU_CONVERSION;
  2170. HRESULT hr = E_FAIL;
  2171. QuitIfNull(pbstrCommandType);
  2172. QuitIfNull(pbstrCommand);
  2173. QuitIfNull(pbstrSwitches);
  2174. QuitIfNull(pbstrInfSection);
  2175. *pbstrCommandType = NULL;
  2176. *pbstrCommand = NULL;
  2177. *pbstrSwitches = NULL;
  2178. *pbstrInfSection = NULL;
  2179. IXMLDOMNode* pNodeInstall = NULL;
  2180. IXMLDOMNode* pNodeCommand = NULL;
  2181. IXMLDOMNode* pNodeSwitches = NULL;
  2182. BSTR bstrNameCommandTemp = SysAllocString(L"command[@order = ");
  2183. TCHAR szCommand[64];
  2184. hr = StringCchPrintfEx(szCommand, ARRAYSIZE(szCommand), NULL, NULL, MISTSAFE_STRING_FLAGS,
  2185. _T("%ls\"%d\"]"), bstrNameCommandTemp, iOrder);
  2186. CleanUpIfFailedAndSetHrMsg(hr);
  2187. BSTR bstrNameCommand = SysAllocString(T2OLE(szCommand));
  2188. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2189. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeInstall, bstrNameCommand, &pNodeCommand));
  2190. CleanUpIfFailedAndSetHrMsg(GetText(pNodeCommand, pbstrCommand));
  2191. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeCommand, KEY_COMMANDTYPE, pbstrCommandType));
  2192. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeCommand, KEY_INFINSTALL, pbstrInfSection));
  2193. if (SUCCEEDED(FindSingleDOMNode(pNodeCommand, KEY_SWITCHES, &pNodeSwitches)))
  2194. {
  2195. CleanUpIfFailedAndSetHrMsg(GetText(pNodeSwitches, pbstrSwitches));
  2196. }
  2197. CleanUp:
  2198. if (FAILED(hr))
  2199. {
  2200. SafeSysFreeString(*pbstrCommandType);
  2201. SafeSysFreeString(*pbstrCommand);
  2202. SafeSysFreeString(*pbstrSwitches);
  2203. SafeSysFreeString(*pbstrInfSection);
  2204. }
  2205. SafeReleaseNULL(pNodeInstall);
  2206. SafeReleaseNULL(pNodeCommand);
  2207. SafeReleaseNULL(pNodeSwitches);
  2208. SysFreeString(bstrNameCommand);
  2209. SysFreeString(bstrNameCommandTemp);
  2210. return hr;
  2211. }
  2212. /////////////////////////////////////////////////////////////////////////////
  2213. // CloseItem()
  2214. //
  2215. // Release the item node
  2216. /////////////////////////////////////////////////////////////////////////////
  2217. void CXmlCatalog::CloseItem(HANDLE_NODE hNodeItem)
  2218. {
  2219. SafeCloseHandleNode(hNodeItem);
  2220. }
  2221. /////////////////////////////////////////////////////////////////////////////
  2222. // GetTotalEstimatedSize()
  2223. //
  2224. // Get the Total Estimated Download Size of all Items based on Codebase Size
  2225. HRESULT CXmlCatalog::GetTotalEstimatedSize(LONG *plTotalSize)
  2226. {
  2227. LOG_Block("GetTotalEstimatedSize()");
  2228. HRESULT hr = E_FAIL;
  2229. BSTR bstrCodebaseSize = NULL;
  2230. IXMLDOMNodeList *pItemList = NULL;
  2231. IXMLDOMNodeList *pCodebaseList = NULL;
  2232. IXMLDOMNode *pNodeItem = NULL;
  2233. IXMLDOMNode *pNodeInstall = NULL;
  2234. IXMLDOMNode *pNodeCodebase = NULL;
  2235. IXMLDOMNode *pNodeSize = NULL;
  2236. LONG lItemCount = 0;
  2237. LONG lCodebaseCount = 0;
  2238. LONG lTotalSize = 0;
  2239. QuitIfNull(plTotalSize);
  2240. *plTotalSize = 0;
  2241. IXMLDOMNode *pParentNode = NULL;
  2242. CleanUpIfFailedAndSetHrMsg(m_pDocCatalog->QueryInterface(IID_IXMLDOMNode, (void**)&pParentNode));
  2243. CleanUpIfFailedAndSetHrMsg(pParentNode->selectNodes(KEY_ITEM_SEARCH, &pItemList));
  2244. if (NULL == pItemList) goto CleanUp;
  2245. CleanUpIfFailedAndSetHrMsg(pItemList->get_length(&lItemCount));
  2246. if (0 == lItemCount) goto CleanUp; // no items
  2247. // Loop through each Item
  2248. CleanUpIfFailedAndSetHrMsg(pItemList->nextNode(&pNodeItem));
  2249. while (NULL != pNodeItem)
  2250. {
  2251. // Get Installation Element
  2252. CleanUpIfFailedAndSetHrMsg(pNodeItem->selectSingleNode(KEY_INSTALLATION, &pNodeInstall));
  2253. if (NULL == pNodeInstall) goto CleanUp;
  2254. CleanUpIfFailedAndSetHrMsg(pNodeInstall->selectNodes(KEY_CODEBASE, &pCodebaseList));
  2255. if (NULL == pCodebaseList) goto CleanUp;
  2256. CleanUpIfFailedAndSetHrMsg(pCodebaseList->get_length(&lCodebaseCount));
  2257. if (0 == lCodebaseCount) goto CleanUp; // must be at least 1 cab
  2258. // Loop through each Codebase Getting the Size for Each one
  2259. CleanUpIfFailedAndSetHrMsg(pCodebaseList->nextNode(&pNodeCodebase));
  2260. while (NULL != pNodeCodebase)
  2261. {
  2262. // Get the Size Element
  2263. CleanUpIfFailedAndSetHrMsg(pNodeCodebase->selectSingleNode(KEY_SIZE, &pNodeSize));
  2264. if (NULL != pNodeSize)
  2265. {
  2266. pNodeSize->get_text(&bstrCodebaseSize);
  2267. if (NULL != bstrCodebaseSize)
  2268. {
  2269. // Add this Codebase's size to the total download size
  2270. lTotalSize += (DWORD) MyBSTR2L(bstrCodebaseSize);
  2271. SafeSysFreeString(bstrCodebaseSize);
  2272. }
  2273. }
  2274. SafeReleaseNULL(pNodeSize);
  2275. SafeReleaseNULL(pNodeCodebase);
  2276. CleanUpIfFailedAndSetHrMsg(pCodebaseList->nextNode(&pNodeCodebase));
  2277. }
  2278. SafeReleaseNULL(pCodebaseList);
  2279. SafeReleaseNULL(pNodeInstall);
  2280. SafeReleaseNULL(pNodeItem);
  2281. CleanUpIfFailedAndSetHrMsg(pItemList->nextNode(&pNodeItem)); // get the next Item Node
  2282. }
  2283. // Update the Total Size after completing.. if we fail anywhere through here
  2284. // we'll return 0.
  2285. *plTotalSize = lTotalSize;
  2286. CleanUp:
  2287. SafeReleaseNULL(pParentNode);
  2288. SafeReleaseNULL(pItemList);
  2289. SafeReleaseNULL(pCodebaseList);
  2290. SafeReleaseNULL(pNodeItem);
  2291. SafeReleaseNULL(pNodeInstall);
  2292. SafeReleaseNULL(pNodeCodebase);
  2293. SafeReleaseNULL(pNodeSize);
  2294. return hr;
  2295. }
  2296. /////////////////////////////////////////////////////////////////////////////
  2297. // FindItemByIdentity()
  2298. //
  2299. // Input:
  2300. // pNodeIdentity - a pointer to an Identity Node to match against an Items
  2301. // identity in the Catalog. We will search through each item
  2302. // till we find a match with the supplied identity
  2303. //
  2304. // Output:
  2305. // phNodeItem - Handle of the found Item
  2306. //
  2307. /////////////////////////////////////////////////////////////////////////////
  2308. HRESULT CXmlCatalog::FindItemByIdentity(IXMLDOMNode* pNodeIdentity, HANDLE_NODE* phNodeItem)
  2309. {
  2310. LOG_Block("FindItemByIdentity()");
  2311. HRESULT hr = E_FAIL;
  2312. IXMLDOMNode* pNodeIdentityDes = NULL;
  2313. *phNodeItem = HANDLE_NODE_INVALID;
  2314. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  2315. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  2316. hNodeList = FindFirstDOMNode(m_pDocCatalog, KEY_ITEM_SEARCH, &hNodeItem);
  2317. if (HANDLE_NODELIST_INVALID != hNodeList)
  2318. {
  2319. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2320. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentity))
  2321. {
  2322. *phNodeItem = hNodeItem;
  2323. goto CleanUp;
  2324. }
  2325. SafeReleaseNULL(pNodeIdentityDes);
  2326. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2327. while (SUCCEEDED(FindNextDOMNode(hNodeList, &hNodeItem)))
  2328. {
  2329. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2330. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentity))
  2331. {
  2332. *phNodeItem = hNodeItem;
  2333. goto CleanUp;
  2334. }
  2335. SafeReleaseNULL(pNodeIdentityDes);
  2336. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2337. }
  2338. }
  2339. CleanUp:
  2340. CloseItemList(hNodeList);
  2341. SafeReleaseNULL(pNodeIdentityDes);
  2342. if (HANDLE_NODE_INVALID == *phNodeItem)
  2343. {
  2344. LOG_Error(_T("Can't find the matching Item Node in Catalog"));
  2345. hr = E_FAIL;
  2346. }
  2347. return hr;
  2348. }
  2349. /*
  2350. /////////////////////////////////////////////////////////////////////////////
  2351. // IfSameIdentity()
  2352. //
  2353. // Return TRUE if the two <identity> nodes are identical. Return FALSE otherwise.
  2354. /////////////////////////////////////////////////////////////////////////////
  2355. BOOL CXmlCatalog::IfSameIdentity(IXMLDOMNode* pNodeIdentity1, IXMLDOMNode* pNodeIdentity2)
  2356. {
  2357. LOG_Block("IfSameIdentity()");
  2358. BOOL fResult = FALSE;
  2359. BSTR bstrNameGUID = SysAllocString(L"guid");
  2360. BSTR bstrNameIDName = SysAllocString(L"name");
  2361. BSTR bstrNameIDPublisherName = SysAllocString(L"publisherName");
  2362. BSTR bstrNameType = SysAllocString(L"type");
  2363. BSTR bstrNameVersion = SysAllocString(L"version");
  2364. BSTR bstrNameLanguage = SysAllocString(L"language");
  2365. //
  2366. // compare <guid> node
  2367. //
  2368. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameGUID))
  2369. {
  2370. goto CleanUp;
  2371. }
  2372. //
  2373. // compare <publisherName> node
  2374. //
  2375. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameIDPublisherName))
  2376. {
  2377. goto CleanUp;
  2378. }
  2379. //
  2380. // compare "name" attribute, this is a required attribute
  2381. //
  2382. if (!IfHasSameAttribute(pNodeIdentity1, pNodeIdentity2, bstrNameIDName, FALSE))
  2383. {
  2384. goto CleanUp;
  2385. }
  2386. //
  2387. // compare <type> node
  2388. //
  2389. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameType))
  2390. {
  2391. goto CleanUp;
  2392. }
  2393. //
  2394. // compare <version> node, which really means "file version" here
  2395. //
  2396. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameVersion))
  2397. {
  2398. goto CleanUp;
  2399. }
  2400. //
  2401. // compare <language> node
  2402. //
  2403. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameLanguage))
  2404. {
  2405. goto CleanUp;
  2406. }
  2407. fResult = TRUE;
  2408. CleanUp:
  2409. SysFreeString(bstrNameGUID);
  2410. SysFreeString(bstrNameIDName);
  2411. SysFreeString(bstrNameIDPublisherName);
  2412. SysFreeString(bstrNameType);
  2413. SysFreeString(bstrNameVersion);
  2414. SysFreeString(bstrNameLanguage);
  2415. if (!fResult)
  2416. {
  2417. LOG_XML(_T("Different <identity>\'s found."));
  2418. }
  2419. else
  2420. {
  2421. LOG_XML(_T("Same <identity>\'s found."));
  2422. }
  2423. return fResult;
  2424. }
  2425. */
  2426. /////////////////////////////////////////////////////////////////////////////
  2427. // GetItemLanguage()
  2428. //
  2429. // Get the Language Entity from the Item Identity
  2430. /////////////////////////////////////////////////////////////////////////////
  2431. HRESULT CXmlCatalog::GetItemLanguage(HANDLE_NODE hNodeItem, BSTR* pbstrLanguage)
  2432. {
  2433. HRESULT hr = S_OK;
  2434. if (HANDLE_NODE_INVALID == hNodeItem || NULL == pbstrLanguage)
  2435. {
  2436. return E_INVALIDARG;
  2437. }
  2438. IXMLDOMNode *pNodeIdentity = NULL;
  2439. IXMLDOMNode *pNodeLanguage = NULL;
  2440. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentity);
  2441. if (FAILED(hr))
  2442. goto CleanUp;
  2443. hr = FindSingleDOMNode(pNodeIdentity, KEY_LANGUAGE, &pNodeLanguage);
  2444. if (FAILED(hr))
  2445. goto CleanUp;
  2446. hr = GetText(pNodeLanguage, pbstrLanguage);
  2447. if (FAILED(hr))
  2448. goto CleanUp;
  2449. CleanUp:
  2450. SafeReleaseNULL(pNodeLanguage);
  2451. SafeReleaseNULL(pNodeIdentity);
  2452. return hr;
  2453. }
  2454. /////////////////////////////////////////////////////////////////////////////
  2455. // GetCorpItemPlatformStr()
  2456. //
  2457. // Get the Simplified Platform String for an Item (uses the first available platform element)
  2458. /////////////////////////////////////////////////////////////////////////////
  2459. HRESULT CXmlCatalog::GetCorpItemPlatformStr(HANDLE_NODE hNodeItem, BSTR* pbstrPlatformStr)
  2460. {
  2461. HRESULT hr = S_OK;
  2462. if (HANDLE_NODE_INVALID == hNodeItem || NULL == pbstrPlatformStr)
  2463. {
  2464. return E_INVALIDARG;
  2465. }
  2466. IXMLDOMNode *pNodePlatform = NULL;
  2467. IXMLDOMNode *pNodePlatformArchitecture = NULL;
  2468. IXMLDOMNode *pNodePlatformVersion = NULL;
  2469. BSTR bstrPlatformName = NULL;
  2470. BSTR bstrArchitecture = NULL;
  2471. int iMajor = 0;
  2472. int iMinor = 0;
  2473. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatform);
  2474. if (FAILED(hr))
  2475. goto CleanUp;
  2476. hr = GetAttribute(pNodePlatform, KEY_NAME, &bstrPlatformName);
  2477. if (FAILED(hr))
  2478. goto CleanUp;
  2479. hr = FindSingleDOMNode(pNodePlatform, KEY_PROCESSORARCHITECTURE, &pNodePlatformArchitecture);
  2480. if (FAILED(hr))
  2481. goto CleanUp;
  2482. hr = FindSingleDOMNode(pNodePlatform, KEY_VERSION, &pNodePlatformVersion);
  2483. if (FAILED(hr))
  2484. goto CleanUp;
  2485. if (NULL != bstrPlatformName && 0 != SysStringLen(bstrPlatformName))
  2486. {
  2487. if (CSTR_EQUAL == CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  2488. bstrPlatformName, -1, L"VER_PLATFORM_WIN32_NT", -1))
  2489. {
  2490. // this is an NT platform
  2491. hr = GetAttribute(pNodePlatformVersion, KEY_MAJOR, &iMajor);
  2492. if (FAILED(hr))
  2493. goto CleanUp;
  2494. if (4 == iMajor)
  2495. {
  2496. // WinNT4
  2497. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_NT4);
  2498. }
  2499. else // 5 == iMajor
  2500. {
  2501. hr = GetAttribute(pNodePlatformVersion, KEY_MINOR, &iMinor);
  2502. if (FAILED(hr))
  2503. goto CleanUp;
  2504. if (iMinor > 0)
  2505. {
  2506. hr = GetText(pNodePlatformArchitecture, &bstrArchitecture);
  2507. if (FAILED(hr))
  2508. goto CleanUp;
  2509. // whistler
  2510. if (CSTR_EQUAL == CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  2511. bstrArchitecture, -1, L"x86", -1))
  2512. {
  2513. // x86WinXP
  2514. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_X86WHI);
  2515. }
  2516. else
  2517. {
  2518. // ia64WinXP
  2519. *pbstrPlatformStr = SysAllocString(CORP_PLATFROM_DIR_IA64WHI);
  2520. }
  2521. }
  2522. else
  2523. {
  2524. // x86Win2k
  2525. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_NT5);
  2526. }
  2527. }
  2528. }
  2529. else // VER_PLATFORM_WIN32_WINDOWS
  2530. {
  2531. // this is a Win9x platform
  2532. hr = GetAttribute(pNodePlatformVersion, KEY_MINOR, &iMinor);
  2533. if (FAILED(hr))
  2534. goto CleanUp;
  2535. if (iMinor >= 90)
  2536. {
  2537. // x86WinME
  2538. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_WINME);
  2539. }
  2540. else if (iMinor > 0 && iMinor < 90)
  2541. {
  2542. // x86Win98
  2543. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_W98);
  2544. }
  2545. else
  2546. {
  2547. // x86Win95
  2548. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_W95);
  2549. }
  2550. }
  2551. }
  2552. CleanUp:
  2553. SysFreeString(bstrPlatformName);
  2554. SysFreeString(bstrArchitecture);
  2555. SafeReleaseNULL(pNodePlatformVersion);
  2556. SafeReleaseNULL(pNodePlatformArchitecture);
  2557. SafeReleaseNULL(pNodePlatform);
  2558. return hr;
  2559. }
  2560. /////////////////////////////////////////////////////////////////////////////
  2561. // CXmlItems
  2562. /////////////////////////////////////////////////////////////////////////////
  2563. // Constructor
  2564. //
  2565. // Create IXMLDOMDocument* for Items; this is for write only
  2566. /////////////////////////////////////////////////////////////////////////////
  2567. CXmlItems::CXmlItems()
  2568. : m_pDocItems(NULL),
  2569. m_pNodeItems(NULL)
  2570. {
  2571. LOG_Block("CXmlItems()");
  2572. Init();
  2573. }
  2574. /////////////////////////////////////////////////////////////////////////////
  2575. // Constructor
  2576. //
  2577. // Create IXMLDOMDocument* for Items; take TRUE for read, FALSE for write
  2578. /////////////////////////////////////////////////////////////////////////////
  2579. CXmlItems::CXmlItems(BOOL fRead)
  2580. : m_pDocItems(NULL),
  2581. m_pNodeItems(NULL)
  2582. {
  2583. LOG_Block("CXmlItems(BOOL fRead)");
  2584. //
  2585. // for writing Items only
  2586. //
  2587. if (!fRead)
  2588. {
  2589. Init();
  2590. }
  2591. }
  2592. /////////////////////////////////////////////////////////////////////////////
  2593. //
  2594. // Initialize XML DOC node pointers before writing
  2595. /////////////////////////////////////////////////////////////////////////////
  2596. void CXmlItems::Init()
  2597. {
  2598. LOG_Block("Init()");
  2599. HRESULT hr = CoCreateInstance(CLSID_DOMDocument,
  2600. NULL,
  2601. CLSCTX_INPROC_SERVER,
  2602. IID_IXMLDOMDocument,
  2603. (void **) &m_pDocItems);
  2604. if (FAILED(hr))
  2605. {
  2606. LOG_ErrorMsg(hr);
  2607. }
  2608. else
  2609. {
  2610. IXMLDOMNode* pNodeXML = NULL;
  2611. BSTR bstrNameSpaceSchema = NULL;
  2612. //
  2613. // create the <?xml version="1.0"?> node
  2614. //
  2615. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  2616. if (NULL == pNodeXML) goto CleanUp;
  2617. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  2618. //
  2619. // process the iuident.txt to find the Items schema path
  2620. //
  2621. TCHAR szIUDir[MAX_PATH];
  2622. TCHAR szIdentFile[MAX_PATH];
  2623. LPTSTR pszItemsSchema = NULL;
  2624. LPTSTR pszNameSpaceSchema = NULL;
  2625. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  2626. if (NULL == pszItemsSchema)
  2627. {
  2628. LOG_ErrorMsg(E_OUTOFMEMORY);
  2629. goto CleanUp;
  2630. }
  2631. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  2632. if (NULL == pszNameSpaceSchema)
  2633. {
  2634. LOG_ErrorMsg(E_OUTOFMEMORY);
  2635. goto CleanUp;
  2636. }
  2637. GetIndustryUpdateDirectory(szIUDir);
  2638. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  2639. if (FAILED(hr))
  2640. {
  2641. LOG_ErrorMsg(hr);
  2642. goto CleanUp;
  2643. }
  2644. GetPrivateProfileString(IDENT_IUSCHEMA,
  2645. IDENT_IUSCHEMA_ITEMS,
  2646. _T(""),
  2647. pszItemsSchema,
  2648. INTERNET_MAX_URL_LENGTH,
  2649. szIdentFile);
  2650. if ('\0' == pszItemsSchema[0])
  2651. {
  2652. // no Items schema path specified in iuident.txt
  2653. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  2654. goto CleanUp;
  2655. }
  2656. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  2657. _T("x-schema:%s"), pszItemsSchema);
  2658. if (FAILED(hr))
  2659. {
  2660. LOG_ErrorMsg(hr);
  2661. goto CleanUp;
  2662. }
  2663. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  2664. //
  2665. // create the <items> node with the path of the schema
  2666. //
  2667. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  2668. if (NULL == m_pNodeItems) goto CleanUp;
  2669. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  2670. CleanUp:
  2671. SafeReleaseNULL(pNodeXML);
  2672. SysFreeString(bstrNameSpaceSchema);
  2673. SafeHeapFree(pszItemsSchema);
  2674. SafeHeapFree(pszNameSpaceSchema);
  2675. }
  2676. }
  2677. /////////////////////////////////////////////////////////////////////////////
  2678. // Destructor
  2679. //
  2680. // Release IXMLDOMDocument* for Items
  2681. /////////////////////////////////////////////////////////////////////////////
  2682. CXmlItems::~CXmlItems()
  2683. {
  2684. SafeReleaseNULL(m_pNodeItems);
  2685. SafeReleaseNULL(m_pDocItems);
  2686. }
  2687. /////////////////////////////////////////////////////////////////////////////
  2688. // Clear()
  2689. //
  2690. // Reset IXMLDOMDocument* for Items
  2691. /////////////////////////////////////////////////////////////////////////////
  2692. void CXmlItems::Clear()
  2693. {
  2694. SafeReleaseNULL(m_pNodeItems);
  2695. SafeReleaseNULL(m_pDocItems);
  2696. }
  2697. /////////////////////////////////////////////////////////////////////////////
  2698. // LoadXMLDocument()
  2699. //
  2700. // Load an XML Document from string
  2701. /////////////////////////////////////////////////////////////////////////////
  2702. HRESULT CXmlItems::LoadXMLDocument(BSTR bstrXml)
  2703. {
  2704. LOG_Block("LoadXMLDocument()");
  2705. SafeReleaseNULL(m_pDocItems);
  2706. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocItems);
  2707. if (FAILED(hr))
  2708. {
  2709. LOG_ErrorMsg(hr);
  2710. }
  2711. return hr;
  2712. }
  2713. /////////////////////////////////////////////////////////////////////////////
  2714. // LoadXMLDocumentFile()
  2715. //
  2716. // Load an XML Document from the specified file
  2717. /////////////////////////////////////////////////////////////////////////////
  2718. HRESULT CXmlItems::LoadXMLDocumentFile(BSTR bstrFilePath)
  2719. {
  2720. LOG_Block("LoadXMLDocumentFile()");
  2721. SafeReleaseNULL(m_pDocItems);
  2722. HRESULT hr = LoadDocument(bstrFilePath, &m_pDocItems);
  2723. if (FAILED(hr))
  2724. {
  2725. LOG_ErrorMsg(hr);
  2726. }
  2727. return hr;
  2728. }
  2729. /////////////////////////////////////////////////////////////////////////////
  2730. // SaveXMLDocument()
  2731. //
  2732. // Save an XML Document to the specified location
  2733. /////////////////////////////////////////////////////////////////////////////
  2734. HRESULT CXmlItems::SaveXMLDocument(BSTR bstrFilePath)
  2735. {
  2736. LOG_Block("SaveXMLDocument()");
  2737. HRESULT hr = SaveDocument(m_pDocItems, bstrFilePath);
  2738. if (FAILED(hr))
  2739. {
  2740. LOG_ErrorMsg(hr);
  2741. }
  2742. return hr;
  2743. }
  2744. /////////////////////////////////////////////////////////////////////////////
  2745. // AddGlobalErrorCodeIfNoItems()
  2746. //
  2747. // Add the errorCode attribute for <items> if there's no <itemStatus> child node
  2748. /////////////////////////////////////////////////////////////////////////////
  2749. HANDLE_NODELIST CXmlItems::AddGlobalErrorCodeIfNoItems(DWORD dwErrorCode)
  2750. {
  2751. LOG_Block("AddGlobalErrorCodeIfNoItems()");
  2752. HRESULT hr = S_OK;
  2753. IXMLDOMNode* pNodeItem = NULL;
  2754. HANDLE_NODE hNodeItemStatus = HANDLE_NODE_INVALID;
  2755. FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, &hNodeItemStatus);
  2756. if (HANDLE_NODE_INVALID == hNodeItemStatus)
  2757. {
  2758. //
  2759. // set the "errorCode" attribute
  2760. //
  2761. FindFirstDOMNode(m_pDocItems, KEY_ITEMS, &pNodeItem);
  2762. if (NULL != pNodeItem)
  2763. {
  2764. hr = SetAttribute(pNodeItem, KEY_ERRORCODE, dwErrorCode);
  2765. }
  2766. }
  2767. SafeReleaseNULL(pNodeItem);
  2768. return hr;
  2769. }
  2770. /////////////////////////////////////////////////////////////////////////////
  2771. // GetFirstItem()
  2772. //
  2773. // Find the first item in Items xml doc
  2774. /////////////////////////////////////////////////////////////////////////////
  2775. HANDLE_NODELIST CXmlItems::GetFirstItem(HANDLE_NODE* phNodeItem)
  2776. {
  2777. LOG_Block("GetFirstItem()");
  2778. HANDLE_NODELIST hNodeListItem = FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, phNodeItem);
  2779. return hNodeListItem;
  2780. }
  2781. /////////////////////////////////////////////////////////////////////////////
  2782. // GetNextItem()
  2783. //
  2784. // Find the next item in Items xml doc
  2785. /////////////////////////////////////////////////////////////////////////////
  2786. HRESULT CXmlItems::GetNextItem(HANDLE_NODELIST hNodeListItem, HANDLE_NODE* phNodeItem)
  2787. {
  2788. LOG_Block("GetNextItem()");
  2789. return FindNextDOMNode(hNodeListItem, phNodeItem);
  2790. }
  2791. /////////////////////////////////////////////////////////////////////////////
  2792. // CloseItemList()
  2793. //
  2794. // Release the item nodelist
  2795. /////////////////////////////////////////////////////////////////////////////
  2796. void CXmlItems::CloseItemList(HANDLE_NODELIST hNodeListItem)
  2797. {
  2798. SafeFindCloseHandle(hNodeListItem);
  2799. }
  2800. /////////////////////////////////////////////////////////////////////////////
  2801. // GetItemDownloadPath()
  2802. //
  2803. // Retrieve the download path of the given item
  2804. /////////////////////////////////////////////////////////////////////////////
  2805. HRESULT CXmlItems::GetItemDownloadPath(HANDLE_NODE hNodeItem, BSTR* pbstrDownloadPath)
  2806. {
  2807. LOG_Block("GetItemDownloadPath()");
  2808. HRESULT hr = E_FAIL;
  2809. IXMLDOMNode* pNodeDownloadPath = NULL;
  2810. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_DOWNLOADPATH, &pNodeDownloadPath));
  2811. CleanUpIfFailedAndSetHrMsg(GetText(pNodeDownloadPath, pbstrDownloadPath));
  2812. CleanUp:
  2813. SafeReleaseNULL(pNodeDownloadPath);
  2814. return hr;
  2815. }
  2816. /////////////////////////////////////////////////////////////////////////////
  2817. // GetItemDownloadPath()
  2818. //
  2819. // Retrieve the download path of the given item in catalog
  2820. /////////////////////////////////////////////////////////////////////////////
  2821. HRESULT CXmlItems::GetItemDownloadPath(CXmlCatalog* pCatalog, HANDLE_NODE hNodeItem, BSTR* pbstrDownloadPath)
  2822. {
  2823. LOG_Block("GetItemDownloadPath() for an item in catalog");
  2824. HRESULT hr = E_FAIL;
  2825. IXMLDOMNode* pNodeItem = NULL;
  2826. IXMLDOMNode* pNodeDownloadPath = NULL;
  2827. HANDLE_NODE hNodeItemsItem = HANDLE_NODE_INVALID;
  2828. if (NULL != (pNodeItem = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  2829. {
  2830. hr = FindItem(pNodeItem, &hNodeItemsItem, TRUE);
  2831. }
  2832. else
  2833. {
  2834. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  2835. hr = E_FAIL;
  2836. goto CleanUp;
  2837. }
  2838. if (FAILED(hr) || HANDLE_NODE_INVALID == hNodeItemsItem)
  2839. {
  2840. LOG_Error(_T("Can't find item from Items xml"));
  2841. goto CleanUp;
  2842. }
  2843. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItemsItem], KEY_DOWNLOADPATH, &pNodeDownloadPath));
  2844. CleanUpIfFailedAndSetHrMsg(GetText(pNodeDownloadPath, pbstrDownloadPath));
  2845. CleanUp:
  2846. SafeReleaseNULL(pNodeDownloadPath);
  2847. return hr;
  2848. }
  2849. /////////////////////////////////////////////////////////////////////////////
  2850. // CloseItem()
  2851. //
  2852. // Release the item node
  2853. /////////////////////////////////////////////////////////////////////////////
  2854. void CXmlItems::CloseItem(HANDLE_NODE hNodeItem)
  2855. {
  2856. SafeCloseHandleNode(hNodeItem);
  2857. }
  2858. /////////////////////////////////////////////////////////////////////////////
  2859. // FindItem()
  2860. //
  2861. // Input:
  2862. // pNodeItem - the <itemStatus> node of the install items xml; we need
  2863. // to find the corresponding <itemStatus> node in the existing
  2864. // items xml with the identical <identity>, <platform> and
  2865. // <client> nodes.
  2866. // Output:
  2867. // phNodeItem - the handle we pass back to differentiate different
  2868. // <itemStatus> node in the existing items xml
  2869. /////////////////////////////////////////////////////////////////////////////
  2870. HRESULT CXmlItems::FindItem(IXMLDOMNode* pNodeItem, HANDLE_NODE* phNodeItem, BOOL fIdentityOnly /*= FALSE*/)
  2871. {
  2872. LOG_Block("FindItem()");
  2873. HRESULT hr1, hr2, hr = E_FAIL;
  2874. IXMLDOMNode* pNodeIdentitySrc = NULL;
  2875. IXMLDOMNode* pNodeIdentityDes = NULL;
  2876. IXMLDOMNode* pNodePlatformSrc = NULL;
  2877. IXMLDOMNode* pNodePlatformDes = NULL;
  2878. IXMLDOMNode* pNodeClientSrc = NULL;
  2879. IXMLDOMNode* pNodeClientDes = NULL;
  2880. *phNodeItem = HANDLE_NODE_INVALID;
  2881. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  2882. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  2883. hNodeList = FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, &hNodeItem);
  2884. if (HANDLE_NODELIST_INVALID != hNodeList)
  2885. {
  2886. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2887. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIdentitySrc));
  2888. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentitySrc))
  2889. {
  2890. if (fIdentityOnly)
  2891. {
  2892. //
  2893. // we now found the match
  2894. //
  2895. *phNodeItem = hNodeItem;
  2896. goto CleanUp;
  2897. }
  2898. else
  2899. {
  2900. hr1 = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatformDes);
  2901. hr2 = FindSingleDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatformSrc);
  2902. if ((FAILED(hr1) && FAILED(hr2)) ||
  2903. (SUCCEEDED(hr1) && SUCCEEDED(hr2) && AreNodesEqual(pNodePlatformDes, pNodePlatformSrc)))
  2904. {
  2905. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_CLIENT, &pNodeClientDes));
  2906. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClientSrc));
  2907. if (AreNodesEqual(pNodeClientDes, pNodeClientSrc))
  2908. {
  2909. //
  2910. // we now found the match
  2911. //
  2912. *phNodeItem = hNodeItem;
  2913. goto CleanUp;
  2914. }
  2915. }
  2916. }
  2917. }
  2918. SafeReleaseNULL(pNodeClientDes);
  2919. SafeReleaseNULL(pNodeClientSrc);
  2920. SafeReleaseNULL(pNodePlatformDes);
  2921. SafeReleaseNULL(pNodePlatformSrc);
  2922. SafeReleaseNULL(pNodeIdentityDes);
  2923. SafeReleaseNULL(pNodeIdentitySrc);
  2924. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2925. while (SUCCEEDED(FindNextDOMNode(hNodeList, &hNodeItem)))
  2926. {
  2927. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2928. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIdentitySrc));
  2929. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentitySrc))
  2930. {
  2931. if (fIdentityOnly)
  2932. {
  2933. //
  2934. // we now found the match
  2935. //
  2936. *phNodeItem = hNodeItem;
  2937. goto CleanUp;
  2938. }
  2939. else
  2940. {
  2941. hr1 = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatformDes);
  2942. hr2 = FindSingleDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatformSrc);
  2943. if ((FAILED(hr1) && FAILED(hr2)) ||
  2944. (SUCCEEDED(hr1) && SUCCEEDED(hr2) && AreNodesEqual(pNodePlatformDes, pNodePlatformSrc)))
  2945. {
  2946. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_CLIENT, &pNodeClientDes));
  2947. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClientSrc));
  2948. if (AreNodesEqual(pNodeClientDes, pNodeClientSrc))
  2949. {
  2950. //
  2951. // we now found the match
  2952. //
  2953. *phNodeItem = hNodeItem;
  2954. break;
  2955. }
  2956. }
  2957. }
  2958. }
  2959. SafeReleaseNULL(pNodeClientDes);
  2960. SafeReleaseNULL(pNodeClientSrc);
  2961. SafeReleaseNULL(pNodePlatformDes);
  2962. SafeReleaseNULL(pNodePlatformSrc);
  2963. SafeReleaseNULL(pNodeIdentityDes);
  2964. SafeReleaseNULL(pNodeIdentitySrc);
  2965. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2966. }
  2967. }
  2968. CleanUp:
  2969. CloseItemList(hNodeList);
  2970. SafeReleaseNULL(pNodeClientDes);
  2971. SafeReleaseNULL(pNodeClientSrc);
  2972. SafeReleaseNULL(pNodePlatformDes);
  2973. SafeReleaseNULL(pNodePlatformSrc);
  2974. SafeReleaseNULL(pNodeIdentityDes);
  2975. SafeReleaseNULL(pNodeIdentitySrc);
  2976. if (HANDLE_NODE_INVALID == *phNodeItem)
  2977. {
  2978. LOG_Error(_T("Can't find the identical item node in existing Items xml"));
  2979. hr = E_FAIL;
  2980. }
  2981. return hr;
  2982. }
  2983. /////////////////////////////////////////////////////////////////////////////
  2984. // FindItem()
  2985. //
  2986. // Input:
  2987. // pCatalog - the pointer to the CXmlCatalog object
  2988. // hNodeItem - the handle of the <item> node of the catalog xml; we need
  2989. // to find the corresponding <itemStatus> node in the existing
  2990. // items xml with the identical <identity>, <platform> and
  2991. // <client> nodes.
  2992. // Output:
  2993. // phNodeItem - the handle we pass back to differentiate different
  2994. // <itemStatus> node in items xml
  2995. /////////////////////////////////////////////////////////////////////////////
  2996. HRESULT CXmlItems::FindItem(CXmlCatalog* pCatalog,
  2997. HANDLE_NODE hNodeItem,
  2998. HANDLE_NODE* phNodeItem)
  2999. {
  3000. LOG_Block("FindItem() by handle");
  3001. IXMLDOMNode* pNode = NULL;
  3002. if (NULL != (pNode = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  3003. {
  3004. return FindItem(pNode, phNodeItem, TRUE);
  3005. }
  3006. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  3007. return E_FAIL;
  3008. }
  3009. /*
  3010. /////////////////////////////////////////////////////////////////////////////
  3011. // IfSameClientInfo()
  3012. //
  3013. // Return TRUE if the two <client> nodes are identical. Return FALSE otherwise.
  3014. /////////////////////////////////////////////////////////////////////////////
  3015. BOOL CXmlItems::IfSameClientInfo(IXMLDOMNode* pNodeClient1, IXMLDOMNode* pNodeClient2)
  3016. {
  3017. LOG_Block("IfSameClientInfo()");
  3018. BSTR bstrText1 = NULL, bstrText2 = NULL;
  3019. BOOL fResult = FALSE;
  3020. GetText(pNodeClient1, &bstrText1);
  3021. GetText(pNodeClient2, &bstrText2);
  3022. if (NULL != bstrText1 && NULL != bstrText2)
  3023. {
  3024. fResult = CompareBSTRsEqual(bstrText1, bstrText2);
  3025. }
  3026. SysFreeString(bstrText1);
  3027. SysFreeString(bstrText2);
  3028. if (!fResult)
  3029. {
  3030. LOG_XML(_T("Different <client>\'s found."));
  3031. }
  3032. else
  3033. {
  3034. LOG_XML(_T("Same <client>\'s found."));
  3035. }
  3036. return fResult;
  3037. }
  3038. /////////////////////////////////////////////////////////////////////////////
  3039. // IfSameIdentity()
  3040. //
  3041. // Return TRUE if the two <identity> nodes are identical. Return FALSE otherwise.
  3042. /////////////////////////////////////////////////////////////////////////////
  3043. BOOL CXmlItems::IfSameIdentity(IXMLDOMNode* pNodeIdentity1, IXMLDOMNode* pNodeIdentity2)
  3044. {
  3045. LOG_Block("IfSameIdentity()");
  3046. BOOL fResult = FALSE;
  3047. BSTR bstrNameGUID = SysAllocString(L"guid");
  3048. BSTR bstrNameIDName = SysAllocString(L"name");
  3049. BSTR bstrNameIDPublisherName = SysAllocString(L"publisherName");
  3050. BSTR bstrNameType = SysAllocString(L"type");
  3051. BSTR bstrNameVersion = SysAllocString(L"version");
  3052. BSTR bstrNameLanguage = SysAllocString(L"language");
  3053. //
  3054. // compare <guid> node
  3055. //
  3056. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameGUID))
  3057. {
  3058. goto CleanUp;
  3059. }
  3060. //
  3061. // compare <publisherName> node
  3062. //
  3063. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameIDPublisherName))
  3064. {
  3065. goto CleanUp;
  3066. }
  3067. //
  3068. // compare "name" attribute, this is a required attribute
  3069. //
  3070. if (!IfHasSameAttribute(pNodeIdentity1, pNodeIdentity2, bstrNameIDName, FALSE))
  3071. {
  3072. goto CleanUp;
  3073. }
  3074. //
  3075. // compare <type> node
  3076. //
  3077. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameType))
  3078. {
  3079. goto CleanUp;
  3080. }
  3081. //
  3082. // compare <version> node, which really means "file version" here
  3083. //
  3084. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameVersion))
  3085. {
  3086. goto CleanUp;
  3087. }
  3088. //
  3089. // compare <language> node
  3090. //
  3091. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameLanguage))
  3092. {
  3093. goto CleanUp;
  3094. }
  3095. fResult = TRUE;
  3096. CleanUp:
  3097. SysFreeString(bstrNameGUID);
  3098. SysFreeString(bstrNameIDName);
  3099. SysFreeString(bstrNameIDPublisherName);
  3100. SysFreeString(bstrNameType);
  3101. SysFreeString(bstrNameVersion);
  3102. SysFreeString(bstrNameLanguage);
  3103. if (!fResult)
  3104. {
  3105. LOG_XML(_T("Different <identity>\'s found."));
  3106. }
  3107. else
  3108. {
  3109. LOG_XML(_T("Same <identity>\'s found."));
  3110. }
  3111. return fResult;
  3112. }
  3113. /////////////////////////////////////////////////////////////////////////////
  3114. // IfSamePlatform()
  3115. //
  3116. // Return TRUE if the two <platform> nodes are identical. Return FALSE otherwise.
  3117. /////////////////////////////////////////////////////////////////////////////
  3118. BOOL CXmlItems::IfSamePlatform(IXMLDOMNode* pNodePlatform1, IXMLDOMNode* pNodePlatform2)
  3119. {
  3120. LOG_Block("IfSamePlatform()");
  3121. HRESULT hr1 = S_OK, hr2 = S_OK;
  3122. BSTR bstrPlatform1 = NULL, bstrPlatform2 = NULL;
  3123. BOOL fResult = FALSE;
  3124. hr1 = pNodePlatform1->get_xml(&bstrPlatform1);
  3125. hr2 = pNodePlatform2->get_xml(&bstrPlatform2);
  3126. if (FAILED(hr1) || FAILED(hr2) || !CompareBSTRsEqual(bstrPlatform1, bstrPlatform2))
  3127. goto CleanUp;
  3128. fResult = TRUE;
  3129. CleanUp:
  3130. SysFreeString(bstrPlatform1);
  3131. SysFreeString(bstrPlatform2);
  3132. return fResult;
  3133. }
  3134. */
  3135. /////////////////////////////////////////////////////////////////////////////
  3136. // MergeItemDownloaded()
  3137. //
  3138. // Insert items with download history into existing history (insert in front)
  3139. /////////////////////////////////////////////////////////////////////////////
  3140. HRESULT CXmlItems::MergeItemDownloaded(CXmlItems *pHistoryDownload)
  3141. {
  3142. LOG_Block("MergeItemDownloaded()");
  3143. HRESULT hr = S_OK;
  3144. IXMLDOMNode* pNodeItem = NULL;
  3145. IXMLDOMNode* pNodeItemNew = NULL;
  3146. IXMLDOMNode* pNodeItemRef = NULL;
  3147. IXMLDOMNode* pNodeXML = NULL;
  3148. BSTR bstrNameSpaceSchema = NULL;
  3149. LPTSTR pszItemsSchema = NULL;
  3150. LPTSTR pszNameSpaceSchema = NULL;
  3151. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  3152. HANDLE_NODELIST hNodeListItem = HANDLE_NODELIST_INVALID;
  3153. hNodeListItem = pHistoryDownload->GetFirstItem(&hNodeItem);
  3154. if (HANDLE_NODELIST_INVALID != hNodeListItem)
  3155. {
  3156. //
  3157. // if this is the first time writing history
  3158. // (e.g. the log file does not exist yet), do
  3159. // initialization for m_pDocItems here...
  3160. //
  3161. if (NULL == m_pDocItems)
  3162. {
  3163. hr = CoCreateInstance(CLSID_DOMDocument,
  3164. NULL,
  3165. CLSCTX_INPROC_SERVER,
  3166. IID_IXMLDOMDocument,
  3167. (void **) &m_pDocItems);
  3168. if (FAILED(hr))
  3169. {
  3170. LOG_ErrorMsg(hr);
  3171. }
  3172. else
  3173. {
  3174. //
  3175. // create the <?xml version="1.0"?> node
  3176. //
  3177. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3178. if (NULL == pNodeXML) goto CleanUp;
  3179. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3180. //
  3181. // process the iuident.txt to find the Items schema path
  3182. //
  3183. TCHAR szIUDir[MAX_PATH];
  3184. TCHAR szIdentFile[MAX_PATH];
  3185. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3186. if (NULL == pszItemsSchema)
  3187. {
  3188. hr = E_OUTOFMEMORY;
  3189. LOG_ErrorMsg(hr);
  3190. goto CleanUp;
  3191. }
  3192. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3193. if (NULL == pszNameSpaceSchema)
  3194. {
  3195. hr = E_OUTOFMEMORY;
  3196. LOG_ErrorMsg(hr);
  3197. goto CleanUp;
  3198. }
  3199. GetIndustryUpdateDirectory(szIUDir);
  3200. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  3201. if (FAILED(hr))
  3202. {
  3203. LOG_ErrorMsg(hr);
  3204. goto CleanUp;
  3205. }
  3206. GetPrivateProfileString(IDENT_IUSCHEMA,
  3207. IDENT_IUSCHEMA_ITEMS,
  3208. _T(""),
  3209. pszItemsSchema,
  3210. INTERNET_MAX_URL_LENGTH,
  3211. szIdentFile);
  3212. if ('\0' == pszItemsSchema[0])
  3213. {
  3214. // no Items schema path specified in iuident.txt
  3215. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  3216. goto CleanUp;
  3217. }
  3218. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  3219. _T("x-schema:%s"), pszItemsSchema);
  3220. if (FAILED(hr))
  3221. {
  3222. LOG_ErrorMsg(hr);
  3223. goto CleanUp;
  3224. }
  3225. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  3226. //
  3227. // create the <items> node with the path of the schema
  3228. //
  3229. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  3230. if (NULL == m_pNodeItems) goto CleanUp;
  3231. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  3232. }
  3233. }
  3234. else
  3235. {
  3236. SafeReleaseNULL(m_pNodeItems);
  3237. FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems);
  3238. }
  3239. if (NULL != m_pNodeItems)
  3240. {
  3241. if (NULL != (pNodeItem = pHistoryDownload->GetDOMNodebyHandle(hNodeItem)))
  3242. {
  3243. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3244. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3245. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3246. // SafeReleaseNULL(pNodeItem);
  3247. SafeReleaseNULL(pNodeItemNew);
  3248. SafeReleaseNULL(pNodeItemRef);
  3249. }
  3250. while (SUCCEEDED(pHistoryDownload->GetNextItem(hNodeListItem, &hNodeItem)))
  3251. {
  3252. if (NULL != (pNodeItem = pHistoryDownload->GetDOMNodebyHandle(hNodeItem)))
  3253. {
  3254. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3255. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3256. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3257. // SafeReleaseNULL(pNodeItem);
  3258. SafeReleaseNULL(pNodeItemNew);
  3259. SafeReleaseNULL(pNodeItemRef);
  3260. }
  3261. }
  3262. }
  3263. }
  3264. CleanUp:
  3265. pHistoryDownload->CloseItemList(hNodeListItem);
  3266. // SafeReleaseNULL(pNodeItem);
  3267. SafeReleaseNULL(pNodeItemNew);
  3268. SafeReleaseNULL(pNodeItemRef);
  3269. SafeReleaseNULL(pNodeXML);
  3270. SysFreeString(bstrNameSpaceSchema);
  3271. SafeHeapFree(pszItemsSchema);
  3272. SafeHeapFree(pszNameSpaceSchema);
  3273. return hr;
  3274. }
  3275. /////////////////////////////////////////////////////////////////////////////
  3276. // UpdateItemInstalled()
  3277. //
  3278. // Update items with installation history in existing history
  3279. /////////////////////////////////////////////////////////////////////////////
  3280. HRESULT CXmlItems::UpdateItemInstalled(CXmlItems *pHistoryInstall)
  3281. {
  3282. LOG_Block("UpdateItemInstalled()");
  3283. USES_IU_CONVERSION;
  3284. HRESULT hr = S_OK;
  3285. IXMLDOMNode* pNodeItem = NULL;
  3286. IXMLDOMNode* pNodeItemNew = NULL;
  3287. IXMLDOMNode* pNodeItemRef = NULL;
  3288. IXMLDOMNode* pNodeItemExist = NULL;
  3289. IXMLDOMNode* pNodeInstall = NULL;
  3290. IXMLDOMNode* pNodeInstallExist = NULL;
  3291. IXMLDOMNode* pNodeInstallNew = NULL;
  3292. IXMLDOMNode* pNodeInstallOut = NULL;
  3293. IXMLDOMNode* pNodeXML = NULL;
  3294. BSTR bstrInstallStatusExist = NULL;
  3295. BSTR bstrInstallStatusNew = NULL;
  3296. BSTR bstrTimeStamp = NULL;
  3297. BSTR bstrNameSpaceSchema = NULL;
  3298. LPTSTR pszItemsSchema = NULL;
  3299. LPTSTR pszNameSpaceSchema = NULL;
  3300. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  3301. HANDLE_NODE hNodeItemExist = HANDLE_NODE_INVALID;
  3302. HANDLE_NODELIST hNodeListItem = HANDLE_NODELIST_INVALID;
  3303. hNodeListItem = pHistoryInstall->GetFirstItem(&hNodeItem);
  3304. if (HANDLE_NODELIST_INVALID != hNodeListItem)
  3305. {
  3306. //
  3307. // if this is the first time writing history
  3308. // (e.g. the log file does not exist yet), do
  3309. // initialization for m_pDocItems here...
  3310. //
  3311. if (NULL == m_pDocItems)
  3312. {
  3313. hr = CoCreateInstance(CLSID_DOMDocument,
  3314. NULL,
  3315. CLSCTX_INPROC_SERVER,
  3316. IID_IXMLDOMDocument,
  3317. (void **) &m_pDocItems);
  3318. if (FAILED(hr))
  3319. {
  3320. LOG_ErrorMsg(hr);
  3321. }
  3322. else
  3323. {
  3324. //
  3325. // create the <?xml version="1.0"?> node
  3326. //
  3327. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3328. if (NULL == pNodeXML) goto CleanUp;
  3329. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3330. //
  3331. // process the iuident.txt to find the Items schema path
  3332. //
  3333. TCHAR szIUDir[MAX_PATH];
  3334. TCHAR szIdentFile[MAX_PATH];
  3335. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3336. if (NULL == pszItemsSchema)
  3337. {
  3338. hr = E_OUTOFMEMORY;
  3339. LOG_ErrorMsg(hr);
  3340. goto CleanUp;
  3341. }
  3342. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3343. if (NULL == pszNameSpaceSchema)
  3344. {
  3345. hr = E_OUTOFMEMORY;
  3346. LOG_ErrorMsg(hr);
  3347. goto CleanUp;
  3348. }
  3349. GetIndustryUpdateDirectory(szIUDir);
  3350. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  3351. if (FAILED(hr))
  3352. {
  3353. LOG_ErrorMsg(hr);
  3354. goto CleanUp;
  3355. }
  3356. GetPrivateProfileString(IDENT_IUSCHEMA,
  3357. IDENT_IUSCHEMA_ITEMS,
  3358. _T(""),
  3359. pszItemsSchema,
  3360. INTERNET_MAX_URL_LENGTH,
  3361. szIdentFile);
  3362. if ('\0' == pszItemsSchema[0])
  3363. {
  3364. // no Items schema path specified in iuident.txt
  3365. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  3366. goto CleanUp;
  3367. }
  3368. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  3369. _T("x-schema:%s"), pszItemsSchema);
  3370. if (FAILED(hr))
  3371. {
  3372. LOG_ErrorMsg(hr);
  3373. goto CleanUp;
  3374. }
  3375. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  3376. //
  3377. // create the <items> node with the path of the schema
  3378. //
  3379. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  3380. if (NULL == m_pNodeItems) goto CleanUp;
  3381. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  3382. }
  3383. }
  3384. else
  3385. {
  3386. SafeReleaseNULL(m_pNodeItems);
  3387. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems));
  3388. }
  3389. if (NULL != (pNodeItem = pHistoryInstall->GetDOMNodebyHandle(hNodeItem)))
  3390. {
  3391. if (SUCCEEDED(FindItem(pNodeItem, &hNodeItemExist)))
  3392. {
  3393. //
  3394. // successfully found the match
  3395. //
  3396. if (NULL != (pNodeItemExist = GetDOMNodebyHandle(hNodeItemExist)))
  3397. {
  3398. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_INSTALLSTATUS, &pNodeInstall));
  3399. FindSingleDOMNode(pNodeItemExist, KEY_INSTALLSTATUS, &pNodeInstallExist);
  3400. if (NULL != pNodeInstallExist)
  3401. {
  3402. //
  3403. // found the item already with installStatus; now find out if we want to update
  3404. // or append the installStatus
  3405. //
  3406. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstallExist, KEY_VALUE, &bstrInstallStatusExist));
  3407. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_VALUE, &bstrInstallStatusNew));
  3408. if (CSTR_EQUAL == WUCompareStringI(OLE2T(bstrInstallStatusExist), _T("IN_PROGRESS")) &&
  3409. CSTR_EQUAL != WUCompareStringI(OLE2T(bstrInstallStatusNew), _T("IN_PROGRESS")))
  3410. {
  3411. //
  3412. // this entry is an exclusive item with "IN_PROGRESS" installStatus and we found its
  3413. // updated installStatus, we need to update its installStatus
  3414. //
  3415. LOG_Out(_T("Update the exclusive item's installStatus"));
  3416. CleanUpIfFailedAndSetHrMsg(pNodeItemExist->removeChild(pNodeInstallExist, &pNodeInstallOut));
  3417. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3418. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3419. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3420. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3421. SafeSysFreeString(bstrTimeStamp);
  3422. }
  3423. else
  3424. {
  3425. //
  3426. // in this case we append a copy of this item with the new installStatus, since
  3427. // this comes from a separate install operation
  3428. //
  3429. LOG_Out(_T("This item was installed again, add an entry of this item into history \
  3430. for the new installation status only."));
  3431. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3432. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3433. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3434. }
  3435. SafeSysFreeString(bstrInstallStatusExist);
  3436. SafeSysFreeString(bstrInstallStatusNew);
  3437. }
  3438. else
  3439. {
  3440. //
  3441. // found the item without installStatus, update the entry with the installStatus
  3442. // and update the timeStamp with its installation timeStamp
  3443. //
  3444. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3445. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3446. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3447. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3448. SafeSysFreeString(bstrTimeStamp);
  3449. }
  3450. }
  3451. }
  3452. else
  3453. {
  3454. //
  3455. // no match found, this item was not downloaded through IU,
  3456. // append this item with the install status
  3457. //
  3458. LOG_Out(_T("Can't find the downloaded item in existing history. This item was not downloaded \
  3459. through IU. Add the item into history for installation status only."));
  3460. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3461. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3462. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3463. }
  3464. // SafeReleaseNULL(pNodeItem);
  3465. // SafeReleaseNULL(pNodeItemExist);
  3466. SafeReleaseNULL(pNodeItemNew);
  3467. SafeReleaseNULL(pNodeItemRef);
  3468. SafeReleaseNULL(pNodeInstall);
  3469. SafeReleaseNULL(pNodeInstallExist);
  3470. SafeReleaseNULL(pNodeInstallNew);
  3471. SafeReleaseNULL(pNodeInstallOut);
  3472. }
  3473. while (SUCCEEDED(pHistoryInstall->GetNextItem(hNodeListItem, &hNodeItem)))
  3474. {
  3475. if (NULL != (pNodeItem = pHistoryInstall->GetDOMNodebyHandle(hNodeItem)))
  3476. {
  3477. if (SUCCEEDED(FindItem(pNodeItem, &hNodeItemExist)))
  3478. {
  3479. //
  3480. // successfully found the match
  3481. //
  3482. if (NULL != (pNodeItemExist = GetDOMNodebyHandle(hNodeItemExist)))
  3483. {
  3484. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_INSTALLSTATUS, &pNodeInstall));
  3485. FindSingleDOMNode(pNodeItemExist, KEY_INSTALLSTATUS, &pNodeInstallExist);
  3486. if (NULL != pNodeInstallExist)
  3487. {
  3488. //
  3489. // found the item already with installStatus; now find out if we want to update
  3490. // or append the installStatus
  3491. //
  3492. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstallExist, KEY_VALUE, &bstrInstallStatusExist));
  3493. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_VALUE, &bstrInstallStatusNew));
  3494. if (CSTR_EQUAL == WUCompareStringI(OLE2T(bstrInstallStatusExist), _T("IN_PROGRESS")) &&
  3495. CSTR_EQUAL != WUCompareStringI(OLE2T(bstrInstallStatusNew), _T("IN_PROGRESS")))
  3496. {
  3497. //
  3498. // this entry is an exclusive item with "IN_PROGRESS" installStatus and we found its
  3499. // updated installStatus, we need to update its installStatus
  3500. //
  3501. LOG_Out(_T("Update the exclusive item's installStatus"));
  3502. CleanUpIfFailedAndSetHrMsg(pNodeItemExist->removeChild(pNodeInstallExist, &pNodeInstallOut));
  3503. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3504. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3505. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3506. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3507. SafeSysFreeString(bstrTimeStamp);
  3508. }
  3509. else
  3510. {
  3511. //
  3512. // in this case we append a copy of this item with the new installStatus, since
  3513. // this comes from a separate install operation
  3514. //
  3515. LOG_Out(_T("This item was installed again, add an entry of this item into history \
  3516. for the new installation status only."));
  3517. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3518. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3519. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3520. }
  3521. SafeSysFreeString(bstrInstallStatusExist);
  3522. SafeSysFreeString(bstrInstallStatusNew);
  3523. }
  3524. else
  3525. {
  3526. //
  3527. // found the item without installStatus, update the entry with the installStatus
  3528. // and update the timeStamp with its installation timeStamp
  3529. //
  3530. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3531. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3532. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3533. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3534. SafeSysFreeString(bstrTimeStamp);
  3535. }
  3536. }
  3537. }
  3538. else
  3539. {
  3540. //
  3541. // no match found, this item was not downloaded through IU,
  3542. // append this item with the install status
  3543. //
  3544. LOG_Out(_T("Can't find the downloaded item in existing history. This item was not downloaded \
  3545. through IU. Add the item into history for installation status only."));
  3546. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3547. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3548. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3549. }
  3550. // SafeReleaseNULL(pNodeItem);
  3551. // SafeReleaseNULL(pNodeItemExist);
  3552. SafeReleaseNULL(pNodeItemNew);
  3553. SafeReleaseNULL(pNodeItemRef);
  3554. SafeReleaseNULL(pNodeInstall);
  3555. SafeReleaseNULL(pNodeInstallExist);
  3556. SafeReleaseNULL(pNodeInstallNew);
  3557. SafeReleaseNULL(pNodeInstallOut);
  3558. }
  3559. }
  3560. }
  3561. CleanUp:
  3562. pHistoryInstall->CloseItemList(hNodeListItem);
  3563. // SafeReleaseNULL(pNodeItem);
  3564. // SafeReleaseNULL(pNodeItemExist);
  3565. SafeReleaseNULL(pNodeItemNew);
  3566. SafeReleaseNULL(pNodeItemRef);
  3567. SafeReleaseNULL(pNodeInstall);
  3568. SafeReleaseNULL(pNodeInstallExist);
  3569. SafeReleaseNULL(pNodeInstallNew);
  3570. SafeReleaseNULL(pNodeInstallOut);
  3571. SafeReleaseNULL(pNodeXML);
  3572. SysFreeString(bstrInstallStatusExist);
  3573. SysFreeString(bstrInstallStatusNew);
  3574. SysFreeString(bstrTimeStamp);
  3575. SysFreeString(bstrNameSpaceSchema);
  3576. SafeHeapFree(pszItemsSchema);
  3577. SafeHeapFree(pszNameSpaceSchema);
  3578. return hr;
  3579. }
  3580. /////////////////////////////////////////////////////////////////////////////
  3581. // UpdateItemInstallStatus()
  3582. //
  3583. // Update the install status of the given item
  3584. /////////////////////////////////////////////////////////////////////////////
  3585. HRESULT CXmlItems::UpdateItemInstallStatus(HANDLE_NODE hNodeItem,
  3586. BSTR bstrValue,
  3587. INT iNeedsReboot /*= -1*/,
  3588. DWORD dwErrorCode /*= 0*/)
  3589. {
  3590. LOG_Block("UpdateItemInstallStatus()");
  3591. HRESULT hr = E_FAIL;
  3592. IXMLDOMNode* pNodeInstallStatus = NULL;
  3593. //
  3594. // get the <installStatus> node
  3595. //
  3596. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLSTATUS, &pNodeInstallStatus));
  3597. //
  3598. // set the "value" attribute
  3599. //
  3600. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrValue));
  3601. //
  3602. // set the "needsReboot" attribute
  3603. //
  3604. if (-1 != iNeedsReboot)
  3605. {
  3606. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_NEEDSREBOOT, iNeedsReboot));
  3607. }
  3608. //
  3609. // set the "errorCode" attribute
  3610. //
  3611. if (0 != dwErrorCode)
  3612. {
  3613. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, dwErrorCode));
  3614. }
  3615. CleanUp:
  3616. SafeReleaseNULL(pNodeInstallStatus);
  3617. return hr;
  3618. }
  3619. /////////////////////////////////////////////////////////////////////////////
  3620. // AddItem()
  3621. //
  3622. // Input:
  3623. // pNodeItem - the <item> node of the catalog xml; we need to read
  3624. // <identity> node, <description> node and <platform> nodes
  3625. // from it and write to the items xml.
  3626. // Output:
  3627. // phNodeItem - the handle we pass back to differentiate different
  3628. // <itemStatus> node in items xml
  3629. /////////////////////////////////////////////////////////////////////////////
  3630. HRESULT CXmlItems::AddItem(IXMLDOMNode* pNodeItem, HANDLE_NODE* phNodeItem)
  3631. {
  3632. LOG_Block("AddItem()");
  3633. HRESULT hr = E_FAIL;
  3634. IXMLDOMNode* pNodeIndentity = NULL;
  3635. IXMLDOMNode* pNodeIndentityNew = NULL;
  3636. IXMLDOMNode* pNodeDescription = NULL;
  3637. IXMLDOMNode* pNodeDescriptionNew = NULL;
  3638. IXMLDOMNode* pNodePlatform = NULL;
  3639. IXMLDOMNode* pNodePlatformNew = NULL;
  3640. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  3641. *phNodeItem = CreateDOMNodeWithHandle(m_pDocItems, NODE_ELEMENT, KEY_ITEMSTATUS);
  3642. if (HANDLE_NODE_INVALID == *phNodeItem) goto CleanUp;
  3643. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, m_ppNodeArray[*phNodeItem]));
  3644. hNodeList = FindFirstDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIndentity);
  3645. if (HANDLE_NODELIST_INVALID != hNodeList)
  3646. {
  3647. SafeFindCloseHandle(hNodeList);
  3648. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeIndentity, m_pDocItems, &pNodeIndentityNew));
  3649. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodeIndentityNew));
  3650. }
  3651. hNodeList = FindFirstDOMNode(pNodeItem, KEY_DESCRIPTION, &pNodeDescription);
  3652. if (HANDLE_NODELIST_INVALID != hNodeList)
  3653. {
  3654. SafeFindCloseHandle(hNodeList);
  3655. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeDescription, m_pDocItems, &pNodeDescriptionNew));
  3656. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodeDescriptionNew));
  3657. }
  3658. hNodeList = FindFirstDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatform);
  3659. if (HANDLE_NODELIST_INVALID != hNodeList)
  3660. {
  3661. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodePlatform, m_pDocItems, &pNodePlatformNew));
  3662. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodePlatformNew));
  3663. SafeReleaseNULL(pNodePlatform);
  3664. SafeReleaseNULL(pNodePlatformNew);
  3665. while (SUCCEEDED(FindNextDOMNode(hNodeList, &pNodePlatform)))
  3666. {
  3667. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodePlatform, m_pDocItems, &pNodePlatformNew));
  3668. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodePlatformNew));
  3669. SafeReleaseNULL(pNodePlatform);
  3670. SafeReleaseNULL(pNodePlatformNew);
  3671. }
  3672. }
  3673. CleanUp:
  3674. if (HANDLE_NODELIST_INVALID != hNodeList)
  3675. {
  3676. SafeFindCloseHandle(hNodeList);
  3677. }
  3678. SafeReleaseNULL(pNodeIndentity);
  3679. SafeReleaseNULL(pNodeIndentityNew);
  3680. SafeReleaseNULL(pNodeDescription);
  3681. SafeReleaseNULL(pNodeDescriptionNew);
  3682. SafeReleaseNULL(pNodePlatform);
  3683. SafeReleaseNULL(pNodePlatformNew);
  3684. return hr;
  3685. }
  3686. /////////////////////////////////////////////////////////////////////////////
  3687. // AddItem()
  3688. //
  3689. // Input:
  3690. // pCatalog - the pointer to the CXmlCatalog object
  3691. // hNodeItem - the handle of the <item> node of the catalog xml; we need
  3692. // to read <identity> node, <description> node and <platform>
  3693. // nodes from it and write to the items xml.
  3694. // Output:
  3695. // phNodeItem - the handle we pass back to differentiate different
  3696. // <itemStatus> node in items xml
  3697. /////////////////////////////////////////////////////////////////////////////
  3698. HRESULT CXmlItems::AddItem(CXmlCatalog* pCatalog, HANDLE_NODE hNodeItem, HANDLE_NODE* phNodeItem)
  3699. {
  3700. LOG_Block("AddItem() by handle");
  3701. IXMLDOMNode* pNode = NULL;
  3702. if (NULL != (pNode = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  3703. {
  3704. return AddItem(pNode, phNodeItem);
  3705. }
  3706. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  3707. return E_FAIL;
  3708. }
  3709. /////////////////////////////////////////////////////////////////////////////
  3710. // AddTimeStamp()
  3711. /////////////////////////////////////////////////////////////////////////////
  3712. HRESULT CXmlItems::AddTimeStamp(HANDLE_NODE hNodeItem)
  3713. {
  3714. LOG_Block("AddTimeStamp()");
  3715. USES_IU_CONVERSION;
  3716. HRESULT hr = E_FAIL;
  3717. TCHAR szTimestamp[32];
  3718. SYSTEMTIME stTimestamp;
  3719. BSTR bstrTimeStamp = NULL;
  3720. GetLocalTime(&stTimestamp);
  3721. hr = StringCchPrintfEx(szTimestamp, ARRAYSIZE(szTimestamp), NULL, NULL, MISTSAFE_STRING_FLAGS,
  3722. _T("%4d-%02d-%02dT%02d:%02d:%02d"), // "ISO 8601" format for "datatime" datatype in xml
  3723. stTimestamp.wYear,
  3724. stTimestamp.wMonth,
  3725. stTimestamp.wDay,
  3726. stTimestamp.wHour,
  3727. stTimestamp.wMinute,
  3728. stTimestamp.wSecond);
  3729. CleanUpIfFailedAndSetHrMsg(hr);
  3730. bstrTimeStamp = SysAllocString(T2OLE(szTimestamp));
  3731. //
  3732. // set the "timestamp" attribute
  3733. //
  3734. CleanUpIfFailedAndSetHrMsg(SetAttribute(m_ppNodeArray[hNodeItem], KEY_TIMESTAMP, bstrTimeStamp));
  3735. CleanUp:
  3736. SysFreeString(bstrTimeStamp);
  3737. return hr;
  3738. }
  3739. /////////////////////////////////////////////////////////////////////////////
  3740. // AddDetectResult()
  3741. /////////////////////////////////////////////////////////////////////////////
  3742. HRESULT CXmlItems::AddDetectResult(HANDLE_NODE hNodeItem,
  3743. INT iInstalled /*= -1*/,
  3744. INT iUpToDate /*= -1*/,
  3745. INT iNewerVersion /*= -1*/,
  3746. INT iExcluded /*= -1*/,
  3747. INT iForce /*= -1*/,
  3748. INT iComputerSystem /* = -1 */)
  3749. {
  3750. LOG_Block("AddDetectResult()");
  3751. HRESULT hr = E_FAIL;
  3752. IXMLDOMNode* pNodeDetectResult = NULL;
  3753. //
  3754. // create the <detectResult> node
  3755. //
  3756. pNodeDetectResult = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DETECTRESULT);
  3757. if (NULL == pNodeDetectResult) goto CleanUp;
  3758. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDetectResult));
  3759. //
  3760. // set the "installed" attribute
  3761. //
  3762. if (-1 != iInstalled)
  3763. {
  3764. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_INSTALLED, iInstalled));
  3765. }
  3766. //
  3767. // set the "upToDate" attribute
  3768. //
  3769. if (-1 != iUpToDate)
  3770. {
  3771. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_UPTODATE, iUpToDate));
  3772. }
  3773. //
  3774. // set the "newerVersion" attribute
  3775. //
  3776. if (-1 != iNewerVersion)
  3777. {
  3778. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_NEWERVERSION, iNewerVersion));
  3779. }
  3780. //
  3781. // set the "excluded" attribute
  3782. //
  3783. if (-1 != iExcluded)
  3784. {
  3785. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_EXCLUDED, iExcluded));
  3786. }
  3787. //
  3788. // set the "force" attribute
  3789. //
  3790. if (-1 != iForce)
  3791. {
  3792. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_FORCE, iForce));
  3793. }
  3794. //
  3795. // set computerSystem attribute
  3796. //
  3797. if (-1 != iComputerSystem)
  3798. {
  3799. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_COMPUTERSYSTEM, iComputerSystem));
  3800. }
  3801. CleanUp:
  3802. SafeReleaseNULL(pNodeDetectResult);
  3803. return hr;
  3804. }
  3805. /////////////////////////////////////////////////////////////////////////////
  3806. // AddDownloadStatus()
  3807. /////////////////////////////////////////////////////////////////////////////
  3808. HRESULT CXmlItems::AddDownloadStatus(HANDLE_NODE hNodeItem, BSTR bstrValue, DWORD dwErrorCode /*= 0*/)
  3809. {
  3810. LOG_Block("AddDownloadStatus()");
  3811. HRESULT hr = E_FAIL;
  3812. IXMLDOMNode* pNodeDownloadStatus = NULL;
  3813. //
  3814. // create the <downloadStatus> node
  3815. //
  3816. pNodeDownloadStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DOWNLOADSTATUS);
  3817. if (NULL == pNodeDownloadStatus) goto CleanUp;
  3818. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDownloadStatus));
  3819. //
  3820. // set the "value" attribute
  3821. //
  3822. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDownloadStatus, KEY_VALUE, bstrValue));
  3823. //
  3824. // set the "errorCode" attribute
  3825. //
  3826. if (0 != dwErrorCode)
  3827. {
  3828. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDownloadStatus, KEY_ERRORCODE, dwErrorCode));
  3829. }
  3830. CleanUp:
  3831. SafeReleaseNULL(pNodeDownloadStatus);
  3832. return hr;
  3833. }
  3834. /////////////////////////////////////////////////////////////////////////////
  3835. // AddDownloadPath()
  3836. /////////////////////////////////////////////////////////////////////////////
  3837. HRESULT CXmlItems::AddDownloadPath(HANDLE_NODE hNodeItem, BSTR bstrDownloadPath)
  3838. {
  3839. LOG_Block("AddDownloadPath()");
  3840. HRESULT hr = E_FAIL;
  3841. IXMLDOMNode* pNodeDownloadPath = NULL;
  3842. IXMLDOMNode* pNodeDownloadPathText = NULL;
  3843. pNodeDownloadPath = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DOWNLOADPATH);
  3844. if (NULL == pNodeDownloadPath) goto CleanUp;
  3845. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDownloadPath));
  3846. pNodeDownloadPathText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  3847. if (NULL == pNodeDownloadPathText) goto CleanUp;
  3848. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeDownloadPathText, bstrDownloadPath));
  3849. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeDownloadPath, pNodeDownloadPathText));
  3850. CleanUp:
  3851. SafeReleaseNULL(pNodeDownloadPath);
  3852. SafeReleaseNULL(pNodeDownloadPathText);
  3853. return hr;
  3854. }
  3855. /////////////////////////////////////////////////////////////////////////////
  3856. // AddInstallStatus()
  3857. /////////////////////////////////////////////////////////////////////////////
  3858. HRESULT CXmlItems::AddInstallStatus(HANDLE_NODE hNodeItem,
  3859. BSTR bstrValue,
  3860. BOOL fNeedsReboot,
  3861. DWORD dwErrorCode /*= 0*/)
  3862. {
  3863. LOG_Block("AddInstallStatus()");
  3864. HRESULT hr = E_FAIL;
  3865. IXMLDOMNode* pNodeInstallStatus = NULL;
  3866. //
  3867. // create the <installStatus> node
  3868. //
  3869. pNodeInstallStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_INSTALLSTATUS);
  3870. if (NULL == pNodeInstallStatus) goto CleanUp;
  3871. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeInstallStatus));
  3872. //
  3873. // set the "value" attribute
  3874. //
  3875. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrValue));
  3876. //
  3877. // set the "needsReboot" attribute
  3878. //
  3879. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_NEEDSREBOOT, fNeedsReboot));
  3880. //
  3881. // set the "errorCode" attribute
  3882. //
  3883. if (0 != dwErrorCode)
  3884. {
  3885. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, dwErrorCode));
  3886. }
  3887. CleanUp:
  3888. SafeReleaseNULL(pNodeInstallStatus);
  3889. return hr;
  3890. }
  3891. /////////////////////////////////////////////////////////////////////////////
  3892. // AddClientInfo()
  3893. /////////////////////////////////////////////////////////////////////////////
  3894. HRESULT CXmlItems::AddClientInfo(HANDLE_NODE hNodeItem, BSTR bstrClient)
  3895. {
  3896. LOG_Block("AddClientInfo()");
  3897. HRESULT hr = E_FAIL;
  3898. IXMLDOMNode* pNodeClient = NULL;
  3899. IXMLDOMNode* pNodeClientText = NULL;
  3900. pNodeClient = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_CLIENT);
  3901. if (NULL == pNodeClient) goto CleanUp;
  3902. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeClient));
  3903. pNodeClientText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  3904. if (NULL == pNodeClientText) goto CleanUp;
  3905. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeClientText, bstrClient));
  3906. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeClient, pNodeClientText));
  3907. CleanUp:
  3908. SafeReleaseNULL(pNodeClient);
  3909. SafeReleaseNULL(pNodeClientText);
  3910. return hr;
  3911. }
  3912. /////////////////////////////////////////////////////////////////////////////
  3913. // MigrateV3History()
  3914. //
  3915. // Migrate V3 History: Consumer history only.
  3916. /////////////////////////////////////////////////////////////////////////////
  3917. HRESULT CXmlItems::MigrateV3History(LPCTSTR pszHistoryFilePath)
  3918. {
  3919. LOG_Block("MigrateV3History()");
  3920. HRESULT hr = S_OK;
  3921. IXMLDOMNode* pNodeXML = NULL;
  3922. IXMLDOMNode* pNodeItemStatus = NULL;
  3923. IXMLDOMNode* pNodeIdentity = NULL;
  3924. IXMLDOMNode* pNodeDescription = NULL;
  3925. IXMLDOMNode* pNodeDescriptionText = NULL;
  3926. IXMLDOMNode* pNodeTitle = NULL;
  3927. IXMLDOMNode* pNodeTitleText = NULL;
  3928. IXMLDOMNode* pNodeVersion = NULL;
  3929. IXMLDOMNode* pNodeVersionText = NULL;
  3930. IXMLDOMNode* pNodeInstallStatus = NULL;
  3931. IXMLDOMNode* pNodeClient = NULL;
  3932. IXMLDOMNode* pNodeClientText = NULL;
  3933. BSTR bstrNameSpaceSchema = NULL, bstrStatus = NULL, bstrString = NULL;
  3934. LPTSTR pszItemsSchema = NULL;
  3935. LPTSTR pszNameSpaceSchema = NULL;
  3936. CV3AppLog V3History(pszHistoryFilePath);
  3937. char szLineType[32];
  3938. char szTemp[32];
  3939. char szDate[32];
  3940. char szTime[32];
  3941. char szPUID[32]; // puid - migrate to <identity "name">
  3942. char szTitle[256]; // title - migrate to <description>-><descriptionText>-><title>
  3943. char szVersion[40]; // version - migrate to <identity>-><version>
  3944. char szTimeStamp[32]; // timestamp - migrate to <itemStatus "timestamp">
  3945. char szResult[16]; // result - migrate to <installStatus "value">
  3946. char szErrCode[16]; // errorcode - migrate to <installStatus "errorCode">
  3947. USES_IU_CONVERSION;
  3948. V3History.StartReading();
  3949. while (V3History.ReadLine())
  3950. {
  3951. SafeSysFreeString(bstrString);
  3952. // get line type (first field)
  3953. V3History.CopyNextField(szLineType, ARRAYSIZE(szLineType));
  3954. if ((_stricmp(szLineType, LOG_V3CAT) == 0) || (_stricmp(szLineType, LOG_V3_2) == 0))
  3955. {
  3956. // get "puid" field
  3957. V3History.CopyNextField(szPUID, ARRAYSIZE(szPUID));
  3958. // get "operation" field: installed/uninstalled
  3959. // we only migrate installed item
  3960. V3History.CopyNextField(szTemp, ARRAYSIZE(szTemp));
  3961. if (0 != _stricmp(szTemp, LOG_INSTALL))
  3962. continue;
  3963. //
  3964. // now we start to create <itemStatus> node for this item
  3965. //
  3966. if (NULL == m_pDocItems)
  3967. {
  3968. //
  3969. // we don't have IU history file yet
  3970. //
  3971. hr = CoCreateInstance(CLSID_DOMDocument,
  3972. NULL,
  3973. CLSCTX_INPROC_SERVER,
  3974. IID_IXMLDOMDocument,
  3975. (void **) &m_pDocItems);
  3976. if (FAILED(hr))
  3977. {
  3978. LOG_ErrorMsg(hr);
  3979. }
  3980. else
  3981. {
  3982. //
  3983. // create the <?xml version="1.0"?> node
  3984. //
  3985. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3986. if (NULL == pNodeXML) goto CleanUp;
  3987. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3988. //
  3989. // process the iuident.txt to find the Items schema path
  3990. //
  3991. TCHAR szIUDir[MAX_PATH];
  3992. TCHAR szIdentFile[MAX_PATH];
  3993. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3994. if (NULL == pszItemsSchema)
  3995. {
  3996. hr = E_OUTOFMEMORY;
  3997. LOG_ErrorMsg(hr);
  3998. goto CleanUp;
  3999. }
  4000. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  4001. if (NULL == pszNameSpaceSchema)
  4002. {
  4003. hr = E_OUTOFMEMORY;
  4004. LOG_ErrorMsg(hr);
  4005. goto CleanUp;
  4006. }
  4007. GetIndustryUpdateDirectory(szIUDir);
  4008. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  4009. if (FAILED(hr))
  4010. {
  4011. LOG_ErrorMsg(hr);
  4012. goto CleanUp;
  4013. }
  4014. GetPrivateProfileString(IDENT_IUSCHEMA,
  4015. IDENT_IUSCHEMA_ITEMS,
  4016. _T(""),
  4017. pszItemsSchema,
  4018. INTERNET_MAX_URL_LENGTH,
  4019. szIdentFile);
  4020. if ('\0' == pszItemsSchema[0])
  4021. {
  4022. // no Items schema path specified in iuident.txt
  4023. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  4024. goto CleanUp;
  4025. }
  4026. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  4027. _T("x-schema:%s"), pszItemsSchema);
  4028. if (FAILED(hr))
  4029. {
  4030. LOG_ErrorMsg(hr);
  4031. goto CleanUp;
  4032. }
  4033. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  4034. //
  4035. // create the <items> node with the path of the schema
  4036. //
  4037. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  4038. if (NULL == m_pNodeItems) goto CleanUp;
  4039. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  4040. }
  4041. }
  4042. else
  4043. {
  4044. SafeReleaseNULL(m_pNodeItems);
  4045. FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems);
  4046. }
  4047. // create <itemStatus> node
  4048. pNodeItemStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMSTATUS);
  4049. if (NULL == pNodeItemStatus) continue;
  4050. SkipIfFail(InsertNode(m_pNodeItems, pNodeItemStatus));
  4051. // create <client> node
  4052. pNodeClient = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_CLIENT);
  4053. if (NULL == pNodeClient) continue;
  4054. pNodeClientText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4055. if (NULL == pNodeClientText) continue;
  4056. BSTR bstrV3Client = SysAllocString(C_V3_CLIENTINFO);
  4057. SkipIfFail(SetValue(pNodeClientText, bstrV3Client));
  4058. SkipIfFail(InsertNode(pNodeClient, pNodeClientText));
  4059. SkipIfFail(InsertNode(pNodeItemStatus, pNodeClient));
  4060. SafeSysFreeString(bstrV3Client);
  4061. // create <identity> node
  4062. pNodeIdentity = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_IDENTITY);
  4063. if (NULL == pNodeIdentity) continue;
  4064. SkipIfFail(InsertNode(pNodeItemStatus, pNodeIdentity));
  4065. // set the "name" attribute for <identity>
  4066. bstrString = SysAllocString(A2OLE(szPUID));
  4067. SkipIfFail(SetAttribute(pNodeIdentity, KEY_NAME, bstrString));
  4068. // set the "itemID" attribute for <identity>
  4069. SkipIfFail(SetAttribute(pNodeIdentity, KEY_ITEMID, bstrString));
  4070. SafeSysFreeString(bstrString);
  4071. // get "title" field
  4072. V3History.CopyNextField(szTitle, ARRAYSIZE(szTitle));
  4073. // create <description> node
  4074. pNodeDescription = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DESCRIPTION);
  4075. if (NULL == pNodeDescription) continue;
  4076. SkipIfFail(SetAttribute(pNodeDescription, KEY_HIDDEN, 0));
  4077. SkipIfFail(InsertNode(pNodeItemStatus, pNodeDescription));
  4078. // create <descriptionText> node
  4079. pNodeDescriptionText = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DESCRIPTIONTEXT);
  4080. if (NULL == pNodeDescriptionText) continue;
  4081. SkipIfFail(InsertNode(pNodeDescription, pNodeDescriptionText));
  4082. // create <title> node
  4083. pNodeTitle = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_TITLE);
  4084. if (NULL == pNodeTitle) continue;
  4085. pNodeTitleText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4086. if (NULL == pNodeTitleText) continue;
  4087. bstrString = SysAllocString(A2OLE(szTitle));
  4088. SkipIfFail(SetValue(pNodeTitleText, bstrString));
  4089. SkipIfFail(InsertNode(pNodeTitle, pNodeTitleText));
  4090. SkipIfFail(InsertNode(pNodeDescriptionText, pNodeTitle));
  4091. SafeSysFreeString(bstrString);
  4092. // get "version" field
  4093. V3History.CopyNextField(szVersion, ARRAYSIZE(szVersion));
  4094. // create <version> node
  4095. pNodeVersion = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_VERSION);
  4096. if (NULL == pNodeVersion) continue;
  4097. pNodeVersionText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4098. if (NULL == pNodeVersionText) continue;
  4099. bstrString = SysAllocString(A2OLE(szVersion));
  4100. SkipIfFail(SetValue(pNodeVersionText, bstrString));
  4101. SkipIfFail(InsertNode(pNodeVersion, pNodeVersionText));
  4102. SkipIfFail(InsertNode(pNodeIdentity, pNodeVersion));
  4103. SafeSysFreeString(bstrString);
  4104. // get timestamp
  4105. if ((_stricmp(szLineType, LOG_V3_2) == 0))
  4106. {
  4107. // read the timestamp and convert to "ISO 8601" format for "datatime" datatype in xml:
  4108. // for example, 2001-05-01T18:30:00
  4109. // so we only need to replace the space with 'T'
  4110. // timestamp
  4111. V3History.CopyNextField(szTimeStamp, ARRAYSIZE(szTimeStamp));
  4112. char *p = strchr(szTimeStamp, ' ');
  4113. if (NULL != p) // if (NULL == p): there's no space then leave it as is to pass into SetAttribute
  4114. {
  4115. *p = 'T';
  4116. }
  4117. }
  4118. else
  4119. {
  4120. // V3 Beta had two fields for date and time, we need read both these fields:
  4121. // date
  4122. V3History.CopyNextField(szDate, ARRAYSIZE(szDate));
  4123. // time
  4124. V3History.CopyNextField(szTime, ARRAYSIZE(szTime));
  4125. hr = StringCchPrintfExA(szTimeStamp, ARRAYSIZE(szTimeStamp), NULL, NULL, MISTSAFE_STRING_FLAGS,
  4126. "%sT%s", szDate, szTime);
  4127. SkipIfFail(hr);
  4128. }
  4129. // set the "timestamp" attribute for <itemStatus>
  4130. bstrString = SysAllocString(A2OLE(szTimeStamp));
  4131. SkipIfFail(SetAttribute(pNodeItemStatus, KEY_TIMESTAMP, bstrString));
  4132. SafeSysFreeString(bstrString);
  4133. // skip the "record type" field
  4134. V3History.CopyNextField(szTemp, ARRAYSIZE(szTemp));
  4135. // get "result" field
  4136. V3History.CopyNextField(szResult, ARRAYSIZE(szResult));
  4137. // create <InstallStatus> node
  4138. pNodeInstallStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_INSTALLSTATUS);
  4139. if (NULL == pNodeInstallStatus) continue;
  4140. SkipIfFail(InsertNode(pNodeItemStatus, pNodeInstallStatus));
  4141. // set the "value" attribute for <installStatus>
  4142. if (_stricmp(szResult, LOG_SUCCESS) == 0)
  4143. {
  4144. bstrStatus = SysAllocString(L"COMPLETE");
  4145. }
  4146. else if (_stricmp(szTemp, LOG_STARTED) == 0)
  4147. {
  4148. bstrStatus = SysAllocString(L"IN_PROGRESS");
  4149. }
  4150. else
  4151. {
  4152. bstrStatus = SysAllocString(L"FAILED");
  4153. }
  4154. SkipIfFail(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrStatus));
  4155. if (_stricmp(szResult, LOG_SUCCESS) != 0)
  4156. {
  4157. // get "error code" field
  4158. V3History.CopyNextField(szErrCode, ARRAYSIZE(szErrCode));
  4159. // set the "errorCode" attribute for <installStatus>
  4160. SkipIfFail(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, atoh(szErrCode)));
  4161. }
  4162. }
  4163. }
  4164. V3History.StopReading();
  4165. CleanUp:
  4166. SafeReleaseNULL(pNodeXML);
  4167. SafeReleaseNULL(pNodeItemStatus);
  4168. SafeReleaseNULL(pNodeIdentity);
  4169. SafeReleaseNULL(pNodeDescriptionText);
  4170. SafeReleaseNULL(pNodeTitle);
  4171. SafeReleaseNULL(pNodeTitleText);
  4172. SafeReleaseNULL(pNodeVersion);
  4173. SafeReleaseNULL(pNodeVersionText);
  4174. SafeReleaseNULL(pNodeInstallStatus);
  4175. SafeReleaseNULL(pNodeClient);
  4176. SafeReleaseNULL(pNodeClientText);
  4177. SysFreeString(bstrString);
  4178. SysFreeString(bstrNameSpaceSchema);
  4179. SysFreeString(bstrStatus);
  4180. SafeHeapFree(pszItemsSchema);
  4181. SafeHeapFree(pszNameSpaceSchema);
  4182. return hr;
  4183. }
  4184. /////////////////////////////////////////////////////////////////////////////
  4185. // GetItemsBSTR()
  4186. /////////////////////////////////////////////////////////////////////////////
  4187. HRESULT CXmlItems::GetItemsBSTR(BSTR *pbstrXmlItems)
  4188. {
  4189. LOG_Block("GetItemsBSTR()");
  4190. if (NULL == m_pDocItems)
  4191. {
  4192. *pbstrXmlItems = NULL;
  4193. return S_OK;
  4194. }
  4195. //
  4196. // convert XML DOC into BSTR
  4197. //
  4198. HRESULT hr = m_pDocItems->get_xml(pbstrXmlItems);
  4199. if (FAILED(hr))
  4200. {
  4201. LOG_ErrorMsg(hr);
  4202. }
  4203. return hr;
  4204. }
  4205. /////////////////////////////////////////////////////////////////////////////
  4206. // GetFilteredHistoryBSTR()
  4207. /////////////////////////////////////////////////////////////////////////////
  4208. HRESULT CXmlItems::GetFilteredHistoryBSTR(BSTR bstrBeginDateTime,
  4209. BSTR bstrEndDateTime,
  4210. BSTR bstrClient,
  4211. BSTR *pbstrXmlHistory)
  4212. {
  4213. LOG_Block("GetFilteredHistoryBSTR()");
  4214. USES_IU_CONVERSION;
  4215. HRESULT hr = S_OK;
  4216. IXMLDOMNode* pNodeItems = NULL;
  4217. IXMLDOMNode* pNodeItem = NULL;
  4218. IXMLDOMNode* pNodeItemOut = NULL;
  4219. IXMLDOMNode* pNodeClient = NULL;
  4220. BSTR bstrTimeStamp = NULL;
  4221. BSTR bstrClientInfo = NULL;
  4222. BOOL fOutOfRange = FALSE;
  4223. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  4224. if (NULL == pbstrXmlHistory)
  4225. {
  4226. SetHrMsgAndGotoCleanUp(E_INVALIDARG);
  4227. }
  4228. if (NULL != m_pDocItems)
  4229. {
  4230. if (SUCCEEDED(FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &pNodeItems)))
  4231. {
  4232. hNodeList = FindFirstDOMNode(pNodeItems, KEY_ITEMSTATUS, &pNodeItem);
  4233. if (HANDLE_NODELIST_INVALID != hNodeList)
  4234. {
  4235. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  4236. if (NULL != bstrTimeStamp)
  4237. {
  4238. if ((NULL != bstrBeginDateTime) && (0 != SysStringLen(bstrBeginDateTime)) &&
  4239. (CompareBSTRs(bstrTimeStamp, bstrBeginDateTime) < 0))
  4240. {
  4241. //
  4242. // remove the item whose timestamp is out of range;
  4243. // set the flag to ignore the timestamp comparison for the rest of nodes
  4244. //
  4245. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4246. fOutOfRange = TRUE;
  4247. }
  4248. else if ((NULL != bstrEndDateTime) && (0 != SysStringLen(bstrEndDateTime)) &&
  4249. (CompareBSTRs(bstrTimeStamp, bstrEndDateTime) > 0))
  4250. {
  4251. //
  4252. // remove the item whose timestamp is out of range
  4253. //
  4254. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4255. }
  4256. else
  4257. {
  4258. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClient));
  4259. CleanUpIfFailedAndSetHrMsg(GetText(pNodeClient, &bstrClientInfo));
  4260. if ((NULL != bstrClient) && (0 != SysStringLen(bstrClient)) &&
  4261. (WUCompareStringI(OLE2T(bstrClientInfo), OLE2T(bstrClient)) != CSTR_EQUAL))
  4262. {
  4263. //
  4264. // remove the item whose clieninfo does not match what we need
  4265. //
  4266. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4267. }
  4268. }
  4269. }
  4270. SafeReleaseNULL(pNodeItem);
  4271. SafeReleaseNULL(pNodeItemOut);
  4272. SafeReleaseNULL(pNodeClient);
  4273. SafeSysFreeString(bstrTimeStamp);
  4274. SafeSysFreeString(bstrClientInfo);
  4275. while (SUCCEEDED(FindNextDOMNode(hNodeList, &pNodeItem)))
  4276. {
  4277. if (fOutOfRange)
  4278. {
  4279. //
  4280. // remove the item whose timestamp is out of range
  4281. //
  4282. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4283. }
  4284. else
  4285. {
  4286. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  4287. if (NULL != bstrTimeStamp)
  4288. {
  4289. if ((NULL != bstrBeginDateTime) && (0 != SysStringLen(bstrBeginDateTime)) &&
  4290. (CompareBSTRs(bstrTimeStamp, bstrBeginDateTime) < 0))
  4291. {
  4292. //
  4293. // remove the item whose timestamp is out of range;
  4294. // set the flag to ignore the timestamp comparison for the rest of nodes
  4295. //
  4296. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4297. fOutOfRange = TRUE;
  4298. }
  4299. else if ((NULL != bstrEndDateTime) && (0 != SysStringLen(bstrEndDateTime)) &&
  4300. (CompareBSTRs(bstrTimeStamp, bstrEndDateTime) > 0))
  4301. {
  4302. //
  4303. // remove the item whose timestamp is out of range
  4304. //
  4305. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4306. }
  4307. else
  4308. {
  4309. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClient));
  4310. CleanUpIfFailedAndSetHrMsg(GetText(pNodeClient, &bstrClientInfo));
  4311. if ((NULL != bstrClient) && (0 != SysStringLen(bstrClient)) &&
  4312. (WUCompareStringI(OLE2T(bstrClientInfo), OLE2T(bstrClient)) != CSTR_EQUAL))
  4313. {
  4314. //
  4315. // remove the item whose clieninfo does not match what we need
  4316. //
  4317. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4318. }
  4319. }
  4320. }
  4321. }
  4322. SafeReleaseNULL(pNodeItem);
  4323. SafeReleaseNULL(pNodeItemOut);
  4324. SafeReleaseNULL(pNodeClient);
  4325. SafeSysFreeString(bstrTimeStamp);
  4326. SafeSysFreeString(bstrClientInfo);
  4327. }
  4328. }
  4329. }
  4330. }
  4331. CleanUp:
  4332. CloseItemList(hNodeList);
  4333. SafeReleaseNULL(pNodeItems);
  4334. SafeReleaseNULL(pNodeItem);
  4335. SafeReleaseNULL(pNodeItemOut);
  4336. SafeReleaseNULL(pNodeClient);
  4337. SysFreeString(bstrTimeStamp);
  4338. SysFreeString(bstrClientInfo);
  4339. if (SUCCEEDED(hr))
  4340. {
  4341. hr = GetItemsBSTR(pbstrXmlHistory);
  4342. }
  4343. return hr;
  4344. }
  4345. /////////////////////////////////////////////////////////////////////////////
  4346. // CXmlClientInfo
  4347. CXmlClientInfo::CXmlClientInfo()
  4348. : m_pDocClientInfo(NULL)
  4349. {
  4350. }
  4351. CXmlClientInfo::~CXmlClientInfo()
  4352. {
  4353. SafeReleaseNULL(m_pDocClientInfo);
  4354. }
  4355. //
  4356. // load and parse and validate an XML document from string
  4357. //
  4358. HRESULT CXmlClientInfo::LoadXMLDocument(BSTR bstrXml, BOOL fOfflineMode)
  4359. {
  4360. LOG_Block("CXmlClientInfo::LoadXMLDocument()");
  4361. SafeReleaseNULL(m_pDocClientInfo);
  4362. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocClientInfo, fOfflineMode);
  4363. if (FAILED(hr))
  4364. {
  4365. LOG_ErrorMsg(hr);
  4366. }
  4367. return hr;
  4368. }
  4369. //
  4370. // retrieve client name attribute
  4371. //
  4372. HRESULT CXmlClientInfo::GetClientName(BSTR* pbstrClientName)
  4373. {
  4374. HRESULT hr= E_UNEXPECTED;
  4375. IXMLDOMElement* pElement = NULL;
  4376. BSTR bstrTagName = NULL;
  4377. VARIANT vAttr;
  4378. VariantInit(&vAttr);
  4379. LOG_Block("GetClientName()");
  4380. if (NULL == pbstrClientName)
  4381. {
  4382. return E_INVALIDARG;
  4383. }
  4384. if (NULL == m_pDocClientInfo)
  4385. {
  4386. return hr;
  4387. }
  4388. hr = m_pDocClientInfo->get_documentElement(&pElement);
  4389. CleanUpIfFailedAndMsg(hr);
  4390. if (NULL == pElement)
  4391. {
  4392. //
  4393. // no root element
  4394. //
  4395. hr = E_INVALIDARG; // clientInfo is bad! return this error back to caller
  4396. LOG_ErrorMsg(hr);
  4397. goto CleanUp;
  4398. }
  4399. hr = pElement->get_tagName(&bstrTagName);
  4400. CleanUpIfFailedAndMsg(hr);
  4401. if (!CompareBSTRsEqual(bstrTagName, KEY_CLIENTINFO))
  4402. {
  4403. //
  4404. // root is not clientInfo
  4405. //
  4406. hr = E_INVALIDARG;
  4407. LOG_ErrorMsg(hr);
  4408. goto CleanUp;
  4409. }
  4410. hr = pElement->getAttribute(KEY_CLIENTNAME, &vAttr);
  4411. CleanUpIfFailedAndMsg(hr);
  4412. if (VT_BSTR == vAttr.vt)
  4413. {
  4414. *pbstrClientName = SysAllocString(vAttr.bstrVal);
  4415. }
  4416. else
  4417. {
  4418. hr = E_FAIL;
  4419. CleanUpIfFailedAndMsg(hr);
  4420. }
  4421. CleanUp:
  4422. SafeReleaseNULL(pElement);
  4423. if (bstrTagName)
  4424. {
  4425. SysFreeString(bstrTagName);
  4426. bstrTagName = NULL;
  4427. }
  4428. VariantClear(&vAttr);
  4429. return hr;
  4430. }