Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5234 lines
155 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* pbstrHWID,
  1576. BSTR* pbstrManufacturer,
  1577. BSTR* pbstrProvider)
  1578. {
  1579. HRESULT hr = S_OK;
  1580. LOG_Block("GetPrinterDriverInfo()");
  1581. QuitIfNull(pbstrDriverName);
  1582. QuitIfNull(pbstrHWID);
  1583. QuitIfNull(pbstrManufacturer);
  1584. QuitIfNull(pbstrProvider);
  1585. IXMLDOMNode* pNodeDetection = NULL;
  1586. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1587. IXMLDOMNode* pNodeDevice = NULL;
  1588. IXMLDOMNode* pNodePrinterInfo = NULL;
  1589. IXMLDOMNode* pNodeHWID = NULL;
  1590. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1591. CleanUpIfFailedAndMsg(hr);
  1592. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1593. CleanUpIfFailedAndMsg(hr);
  1594. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1595. CleanUpIfFailedAndMsg(hr);
  1596. hr = FindSingleDOMNode(pNodeDevice, KEY_HWID, &pNodeHWID);
  1597. CleanUpIfFailedAndMsg(hr);
  1598. hr = FindSingleDOMNode(pNodeDevice, KEY_PRINTERINFO, &pNodePrinterInfo);
  1599. CleanUpIfFailedAndMsg(hr);
  1600. GetText(pNodeHWID, pbstrHWID);
  1601. GetAttribute(pNodePrinterInfo, KEY_DRIVERNAME, pbstrDriverName);
  1602. GetAttribute(pNodePrinterInfo, KEY_DRIVERPROVIDER, pbstrProvider);
  1603. GetAttribute(pNodePrinterInfo, KEY_MFGNAME, pbstrManufacturer);
  1604. CleanUp:
  1605. SafeReleaseNULL(pNodePrinterInfo);
  1606. SafeReleaseNULL(pNodeHWID);
  1607. SafeReleaseNULL(pNodeDevice);
  1608. SafeReleaseNULL(pNodeCompatibleHardware);
  1609. SafeReleaseNULL(pNodeDetection);
  1610. return hr;
  1611. }
  1612. /////////////////////////////////////////////////////////////////////////////
  1613. // GetDriverInfoEx()
  1614. //
  1615. // Combines functionality of IsPrinterDriver, GetDriverInfo, and
  1616. // GetPrinterDriverInfo plus retreives MfgName and DriverProvider.
  1617. // Used by FindMatchingDriver()
  1618. //
  1619. // If SUCCEEDES pbstrHWID, pbstrDriverVer, and pbstrDisplayName
  1620. // are always returned.
  1621. // If SUCCEEDES && *pFIsPrinter == TRUE then pbstrDriverName,
  1622. // pbstrDriverProvider, and pbstrMfgName are returned.
  1623. //
  1624. // Currently pbstrArchitecture is never returned.
  1625. //
  1626. /////////////////////////////////////////////////////////////////////////////
  1627. HRESULT CXmlCatalog::GetDriverInfoEx( HANDLE_NODE hNode,
  1628. BOOL* pfIsPrinter,
  1629. BSTR* pbstrHWID,
  1630. BSTR* pbstrDriverVer,
  1631. BSTR* pbstrDisplayName,
  1632. BSTR* pbstrDriverName,
  1633. BSTR* pbstrDriverProvider,
  1634. BSTR* pbstrMfgName,
  1635. BSTR* pbstrArchitecture)
  1636. {
  1637. HRESULT hr;
  1638. LOG_Block("GetDriverInfoEx()");
  1639. QuitIfNull(pbstrHWID);
  1640. QuitIfNull(pbstrDriverVer);
  1641. QuitIfNull(pbstrDisplayName);
  1642. QuitIfNull(pbstrDriverName);
  1643. QuitIfNull(pbstrDriverProvider);
  1644. QuitIfNull(pbstrMfgName);
  1645. QuitIfNull(pbstrArchitecture);
  1646. *pbstrHWID = NULL;
  1647. *pbstrDriverVer = NULL;
  1648. *pbstrDisplayName = NULL;
  1649. *pbstrDriverName = NULL;
  1650. *pbstrDriverProvider = NULL;
  1651. *pbstrMfgName = NULL;
  1652. *pbstrArchitecture = NULL;
  1653. IXMLDOMNode* pNodeDetection = NULL;
  1654. IXMLDOMNode* pNodeCompatibleHardware = NULL;
  1655. IXMLDOMNode* pNodeDevice = NULL;
  1656. IXMLDOMNode* pNodeHWID = NULL;
  1657. IXMLDOMNode* pNodeDescription = NULL;
  1658. IXMLDOMNode* pNodeDescriptionText = NULL;
  1659. IXMLDOMNode* pNodeTitle = NULL;
  1660. IXMLDOMNode* pNodePrinterInfo = NULL;
  1661. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DETECTION, &pNodeDetection);
  1662. CleanUpIfFailedAndMsg(hr);
  1663. hr = FindSingleDOMNode(pNodeDetection, KEY_COMPATIBLEHARDWARE, &pNodeCompatibleHardware);
  1664. CleanUpIfFailedAndMsg(hr);
  1665. hr = FindSingleDOMNode(pNodeCompatibleHardware, KEY_DEVICE, &pNodeDevice);
  1666. CleanUpIfFailedAndMsg(hr);
  1667. //
  1668. // Is it a printer?
  1669. //
  1670. int intIsPrinter = 0;
  1671. GetAttribute(pNodeDevice, KEY_ISPRINTER, &intIsPrinter);
  1672. if (1 == intIsPrinter)
  1673. {
  1674. *pfIsPrinter = TRUE;
  1675. }
  1676. else
  1677. {
  1678. *pfIsPrinter = FALSE;
  1679. }
  1680. //
  1681. // HWID and Driver Description
  1682. //
  1683. hr = FindSingleDOMNode(pNodeDevice, KEY_HWID, &pNodeHWID);
  1684. CleanUpIfFailedAndMsg(hr);
  1685. hr = GetText(pNodeHWID, pbstrHWID);
  1686. CleanUpIfFailedAndMsg(hr);
  1687. hr = GetAttribute(pNodeHWID, KEY_DRIVERVER, pbstrDriverVer);
  1688. CleanUpIfFailedAndMsg(hr);
  1689. hr = FindSingleDOMNode(m_ppNodeArray[hNode], KEY_DESCRIPTION, &pNodeDescription);
  1690. CleanUpIfFailedAndMsg(hr);
  1691. hr = FindSingleDOMNode(pNodeDescription, KEY_DESCRIPTIONTEXT, &pNodeDescriptionText);
  1692. CleanUpIfFailedAndMsg(hr);
  1693. hr = FindSingleDOMNode(pNodeDescriptionText, KEY_TITLE, &pNodeTitle);
  1694. CleanUpIfFailedAndMsg(hr);
  1695. hr = GetText(pNodeTitle, pbstrDisplayName);
  1696. CleanUpIfFailedAndMsg(hr);
  1697. if (*pfIsPrinter)
  1698. {
  1699. //
  1700. // Printer Attributes
  1701. //
  1702. hr = FindSingleDOMNode(pNodeDevice, KEY_PRINTERINFO, &pNodePrinterInfo);
  1703. CleanUpIfFailedAndMsg(hr);
  1704. hr = GetAttribute(pNodePrinterInfo, KEY_DRIVERNAME, pbstrDriverName);
  1705. CleanUpIfFailedAndMsg(hr);
  1706. hr = GetAttribute(pNodePrinterInfo, KEY_DRIVERPROVIDER, pbstrDriverProvider);
  1707. CleanUpIfFailedAndMsg(hr);
  1708. hr = GetAttribute(pNodePrinterInfo, KEY_MFGNAME, pbstrMfgName);
  1709. CleanUpIfFailedAndMsg(hr);
  1710. // NOTE: Currently the CatalogSchema site is not returning
  1711. // architecture for printers, and the schema doesn't require it
  1712. // CDM is using a default string for now based on compile architecture
  1713. // so we'll leave pbstrArchitecture NULL..
  1714. }
  1715. CleanUp:
  1716. if (FAILED(hr))
  1717. {
  1718. SafeSysFreeString(*pbstrHWID);
  1719. SafeSysFreeString(*pbstrDriverVer);
  1720. SafeSysFreeString(*pbstrDisplayName);
  1721. SafeSysFreeString(*pbstrDriverName);
  1722. SafeSysFreeString(*pbstrDriverProvider);
  1723. SafeSysFreeString(*pbstrMfgName);
  1724. SafeSysFreeString(*pbstrArchitecture);
  1725. }
  1726. SafeReleaseNULL(pNodeTitle);
  1727. SafeReleaseNULL(pNodeDescriptionText);
  1728. SafeReleaseNULL(pNodeDescription);
  1729. SafeReleaseNULL(pNodeHWID);
  1730. SafeReleaseNULL(pNodeDevice);
  1731. SafeReleaseNULL(pNodeCompatibleHardware);
  1732. SafeReleaseNULL(pNodeDetection);
  1733. SafeReleaseNULL(pNodePrinterInfo);
  1734. return hr;
  1735. }
  1736. /////////////////////////////////////////////////////////////////////////////
  1737. // GetItemPlatformStr()
  1738. //
  1739. // The input node pointer points to a node has <identity> as its child.
  1740. // This function will retrieve the <platform> node from <identity> and
  1741. // convert the data inside <platform> into a string that can be used to
  1742. // uniquely identify a platform.
  1743. //
  1744. /////////////////////////////////////////////////////////////////////////////
  1745. HRESULT CXmlCatalog::GetItemFirstPlatformStr(HANDLE_NODE hNodeItem,
  1746. BSTR* pbstrPlatform)
  1747. {
  1748. HRESULT hr;
  1749. IXMLDOMNode* pNodePlatform = NULL;
  1750. LOG_Block("GetItemFirstPlatformStr");
  1751. USES_IU_CONVERSION;
  1752. //
  1753. // get the first platform node from this item node
  1754. //
  1755. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatform);
  1756. CleanUpIfFailedAndMsg(hr);
  1757. //
  1758. // get platform data from this ndoe and convert it into string
  1759. //
  1760. hr = GetPlatformStrForPing(pNodePlatform, pbstrPlatform);
  1761. CleanUp:
  1762. SafeReleaseNULL(pNodePlatform);
  1763. //
  1764. // since platform is not a required element in <item>, so we should not
  1765. // return error if not found
  1766. //
  1767. if (HRESULT_FROM_WIN32(ERROR_NOT_FOUND) == hr)
  1768. {
  1769. *pbstrPlatform = NULL;
  1770. hr = S_FALSE;
  1771. }
  1772. return hr;
  1773. }
  1774. /////////////////////////////////////////////////////////////////////////////
  1775. // GetItemAllPlatformStr()
  1776. //
  1777. // The input node pointer points to an item node that has <platform> node(s).
  1778. // This function will retrieve every <platform> node from this item node and
  1779. // convert the data inside <platform> into a string that can be used to
  1780. // uniquely identify a platform.
  1781. //
  1782. /////////////////////////////////////////////////////////////////////////////
  1783. HRESULT CXmlCatalog::GetItemAllPlatformStr(HANDLE_NODE hNodeItem,
  1784. BSTR** ppbPlatforms, UINT* pnPlatformCount)
  1785. {
  1786. LOG_Block("GetItemAllPlatformStr");
  1787. HRESULT hr;
  1788. IXMLDOMNodeList* pPlatformList = NULL;
  1789. IXMLDOMElement* pElement = NULL;
  1790. IXMLDOMNode* pNodePlatform = NULL;
  1791. long lCount = 0;
  1792. int i;
  1793. BSTR* pbstrPlatformList = NULL;
  1794. //
  1795. // get list of platform nodes
  1796. //
  1797. hr = m_ppNodeArray[hNodeItem]->QueryInterface(IID_IXMLDOMElement, (void**)&pElement);
  1798. CleanUpIfFailedAndMsg(hr);
  1799. hr = pElement->getElementsByTagName(KEY_PLATFORM, &pPlatformList);
  1800. CleanUpIfFailedAndMsg(hr);
  1801. hr = pPlatformList->get_length(&lCount);
  1802. CleanUpIfFailedAndMsg(hr);
  1803. if (0 == lCount)
  1804. {
  1805. goto CleanUp;
  1806. }
  1807. pbstrPlatformList = (BSTR*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lCount * sizeof(BSTR*));
  1808. CleanUpFailedAllocSetHrMsg(pbstrPlatformList);
  1809. //
  1810. // loop through each suite, if any
  1811. //
  1812. pPlatformList->reset();
  1813. for (i = 0; i < lCount; i++)
  1814. {
  1815. hr = pPlatformList->get_item(i, &pNodePlatform);
  1816. CleanUpIfFailedAndMsg(hr);
  1817. if (pNodePlatform)
  1818. {
  1819. hr = pNodePlatform->get_text(&(pbstrPlatformList[i]));
  1820. CleanUpIfFailedAndMsg(hr);
  1821. pNodePlatform->Release();
  1822. pNodePlatform = NULL;
  1823. }
  1824. }
  1825. hr = S_OK;
  1826. CleanUp:
  1827. SafeReleaseNULL(pNodePlatform);
  1828. SafeReleaseNULL(pPlatformList);
  1829. SafeReleaseNULL(pElement);
  1830. if (SUCCEEDED(hr))
  1831. {
  1832. *pnPlatformCount = lCount;
  1833. *ppbPlatforms = pbstrPlatformList;
  1834. }
  1835. else
  1836. {
  1837. if (NULL != pbstrPlatformList)
  1838. {
  1839. *pnPlatformCount = 0;
  1840. //
  1841. // release all possibly allocated memory
  1842. //
  1843. for (i = 0; i < lCount; i++)
  1844. {
  1845. SafeSysFreeString(pbstrPlatformList[i]);
  1846. }
  1847. HeapFree(GetProcessHeap(), 0, pbstrPlatformList);
  1848. }
  1849. }
  1850. return hr;
  1851. }
  1852. /////////////////////////////////////////////////////////////////////////////
  1853. // GetItemPlatformStr()
  1854. //
  1855. // The input node pointer points to a node has <identity> as its child.
  1856. // This function will retrieve the <platform> node from <identity> and
  1857. // convert the data inside <platform> into a string that can be used to
  1858. // uniquely identify a platform.
  1859. //
  1860. /////////////////////////////////////////////////////////////////////////////
  1861. HRESULT CXmlCatalog::GetPlatformStr(IXMLDOMNode* pNodePlatform,
  1862. BSTR* pbstrPlatform)
  1863. {
  1864. return UtilGetPlatformStr(pNodePlatform, pbstrPlatform, 0x0);
  1865. }
  1866. HRESULT CXmlCatalog::GetPlatformStrForPing(IXMLDOMNode* pNodePlatform,
  1867. BSTR* pbstrPlatform)
  1868. {
  1869. return UtilGetPlatformStr(pNodePlatform, pbstrPlatform, SKIP_SUITES | SKIP_SERVICEPACK_VER);
  1870. }
  1871. /////////////////////////////////////////////////////////////////////////////
  1872. //
  1873. // get data from a version node and convert them into a string with
  1874. // format:
  1875. // VersionStr = <Version>[,<SvcPackVer>[,<timeStamp>]]
  1876. // <Version> = <Major>[.<Minor>[.<Build>]]
  1877. // <SvcPackVer> = <Major>[.<minor>]
  1878. //
  1879. // Assumption:
  1880. // pszVersion points to a buffer LARGE ENOUGH to store
  1881. // any legal version number.
  1882. //
  1883. /////////////////////////////////////////////////////////////////////////////
  1884. HRESULT CXmlCatalog::getVersionStr(IXMLDOMNode* pNodeVersion, LPTSTR pszVersion)
  1885. {
  1886. return UtilGetVersionStr(pNodeVersion, pszVersion, 0x0);
  1887. }
  1888. HRESULT CXmlCatalog::getVersionStrWithoutSvcPack(IXMLDOMNode* pNodeVersion, LPTSTR pszVersion)
  1889. {
  1890. return UtilGetVersionStr(pNodeVersion, pszVersion, SKIP_SERVICEPACK_VER);
  1891. }
  1892. /////////////////////////////////////////////////////////////////////////////
  1893. // GetItemFirstLanguageStr()
  1894. //
  1895. // The input node pointer points to a node has <identity> as its child.
  1896. // This function will retrieve the first <language> node from <identity>
  1897. // node
  1898. //
  1899. /////////////////////////////////////////////////////////////////////////////
  1900. HRESULT CXmlCatalog::GetItemFirstLanguageStr(HANDLE_NODE hNodeItem,
  1901. BSTR* pbstrLanguage)
  1902. {
  1903. LOG_Block("GetItemFirstLanguageStr");
  1904. IXMLDOMNode* pNodeIdentity = NULL;
  1905. IXMLDOMNode* pNodeLanguage = NULL;
  1906. HRESULT hr = m_ppNodeArray[hNodeItem]->selectSingleNode(KEY_IDENTITY, &pNodeIdentity);
  1907. CleanUpIfFailedAndMsg(hr);
  1908. if (pNodeIdentity)
  1909. {
  1910. if (HANDLE_NODELIST_INVALID == FindFirstDOMNode(pNodeIdentity, KEY_LANGUAGE, &pNodeLanguage))
  1911. {
  1912. hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  1913. goto CleanUp;
  1914. }
  1915. else
  1916. {
  1917. hr = pNodeLanguage->get_text(pbstrLanguage);
  1918. CleanUpIfFailedAndMsg(hr);
  1919. }
  1920. }
  1921. CleanUp:
  1922. SafeReleaseNULL(pNodeLanguage);
  1923. SafeReleaseNULL(pNodeIdentity);
  1924. //
  1925. // since language is not a required element in <identity>, so we should not
  1926. // return error if not found
  1927. //
  1928. if (HRESULT_FROM_WIN32(ERROR_NOT_FOUND) == hr)
  1929. {
  1930. *pbstrLanguage = NULL;
  1931. hr = S_FALSE;
  1932. }
  1933. return hr;
  1934. }
  1935. /////////////////////////////////////////////////////////////////////////////
  1936. // GetItemAllLanguageStr()
  1937. //
  1938. // The input node pointer points to a node has <identity> as its child.
  1939. // This function will retrieve every <language> node from <identity> node and
  1940. // convert the data into an BSTR array to return.
  1941. //
  1942. /////////////////////////////////////////////////////////////////////////////
  1943. HRESULT CXmlCatalog::GetItemAllLanguageStr(HANDLE_NODE hNodeItem,
  1944. BSTR** ppbstrLanguage, UINT* pnLangCount)
  1945. {
  1946. LOG_Block("GetItemAllLanguageStr");
  1947. HRESULT hr;
  1948. IXMLDOMNode* pNodeIdentity = NULL;
  1949. IXMLDOMNodeList* pLanguageList = NULL;
  1950. IXMLDOMElement* pElement = NULL;
  1951. IXMLDOMNode* pNodeLanguage = NULL;
  1952. long lCount = 0;
  1953. int i;
  1954. BSTR* pbstrLanguageList = NULL;
  1955. hr = m_ppNodeArray[hNodeItem]->selectSingleNode(KEY_IDENTITY, &pNodeIdentity);
  1956. CleanUpIfFailedAndMsg(hr);
  1957. //
  1958. // get list of nodes
  1959. //
  1960. hr = pNodeIdentity->QueryInterface(IID_IXMLDOMElement, (void**)&pElement);
  1961. CleanUpIfFailedAndMsg(hr);
  1962. hr = pElement->getElementsByTagName(KEY_LANGUAGE, &pLanguageList);
  1963. CleanUpIfFailedAndMsg(hr);
  1964. hr = pLanguageList->get_length(&lCount);
  1965. CleanUpIfFailedAndMsg(hr);
  1966. if (0 == lCount)
  1967. {
  1968. goto CleanUp;
  1969. }
  1970. pbstrLanguageList = (BSTR*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lCount * sizeof(BSTR*));
  1971. CleanUpFailedAllocSetHrMsg(pbstrLanguageList);
  1972. //
  1973. // loop through each suite, if any
  1974. //
  1975. pLanguageList->reset();
  1976. for (i = 0; i < lCount; i++)
  1977. {
  1978. hr = pLanguageList->get_item(i, &pNodeLanguage);
  1979. CleanUpIfFailedAndMsg(hr);
  1980. if (pNodeLanguage)
  1981. {
  1982. hr = pNodeLanguage->get_text(&(pbstrLanguageList[i]));
  1983. CleanUpIfFailedAndMsg(hr);
  1984. pNodeLanguage->Release();
  1985. pNodeLanguage = NULL;
  1986. }
  1987. }
  1988. hr = S_OK;
  1989. CleanUp:
  1990. SafeReleaseNULL(pNodeLanguage);
  1991. SafeReleaseNULL(pLanguageList);
  1992. SafeReleaseNULL(pElement);
  1993. SafeReleaseNULL(pNodeIdentity);
  1994. if (SUCCEEDED(hr))
  1995. {
  1996. *pnLangCount = lCount;
  1997. *ppbstrLanguage = pbstrLanguageList;
  1998. }
  1999. else
  2000. {
  2001. if (NULL != pbstrLanguageList)
  2002. {
  2003. *pnLangCount = 0;
  2004. //
  2005. // release all possibly allocated memory
  2006. //
  2007. for (i = 0; i < lCount; i++)
  2008. {
  2009. SafeSysFreeString(pbstrLanguageList[i]);
  2010. }
  2011. HeapFree(GetProcessHeap(), 0, pbstrLanguageList);
  2012. }
  2013. }
  2014. return hr;
  2015. }
  2016. /////////////////////////////////////////////////////////////////////////////
  2017. // GetItemFirstCodeBase()
  2018. //
  2019. // Find the first codebase (path) of the given item
  2020. /////////////////////////////////////////////////////////////////////////////
  2021. HANDLE_NODELIST CXmlCatalog::GetItemFirstCodeBase(HANDLE_NODE hNodeItem,
  2022. BSTR* pbstrCodeBase,
  2023. BSTR* pbstrName,
  2024. BSTR* pbstrCRC,
  2025. BOOL* pfPatchAvailable,
  2026. LONG* plSize)
  2027. {
  2028. LOG_Block("GetItemFirstCodeBase()");
  2029. HRESULT hr = E_FAIL;
  2030. QuitIfNull(pbstrCodeBase);
  2031. QuitIfNull(pbstrName);
  2032. QuitIfNull(pbstrCRC);
  2033. QuitIfNull(pfPatchAvailable);
  2034. QuitIfNull(plSize);
  2035. IXMLDOMNode* pNodeInstall = NULL;
  2036. IXMLDOMNode* pNodeCodeBaseSize = NULL;
  2037. HANDLE_NODE hNodeCodeBase = HANDLE_NODE_INVALID;
  2038. HANDLE_NODELIST hNodeListCodeBase = HANDLE_NODELIST_INVALID;
  2039. *pbstrCodeBase = NULL;
  2040. *pbstrName = NULL;
  2041. *pbstrCRC = NULL;
  2042. *pfPatchAvailable = FALSE;
  2043. *plSize = -1;
  2044. BSTR bstrSize = NULL;
  2045. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2046. hNodeListCodeBase = FindFirstDOMNode(pNodeInstall, KEY_CODEBASE, &hNodeCodeBase);
  2047. if (HANDLE_NODELIST_INVALID == hNodeListCodeBase) goto CleanUp;
  2048. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_HREF, pbstrCodeBase));
  2049. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_PATCHAVAILABLE, pfPatchAvailable));
  2050. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_CRC, pbstrCRC); // optional attribute, don't fail if its not there.
  2051. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_NAME, pbstrName);
  2052. FindSingleDOMNode(m_ppNodeArray[hNodeCodeBase], KEY_SIZE, &pNodeCodeBaseSize);
  2053. GetText(pNodeCodeBaseSize, &bstrSize);
  2054. if (NULL != bstrSize)
  2055. {
  2056. *plSize = MyBSTR2L(bstrSize);
  2057. SysFreeString(bstrSize);
  2058. }
  2059. CleanUp:
  2060. SafeReleaseNULL(pNodeInstall);
  2061. SafeReleaseNULL(pNodeCodeBaseSize);
  2062. if (FAILED(hr))
  2063. {
  2064. SafeSysFreeString(*pbstrCodeBase);
  2065. SafeSysFreeString(*pbstrName);
  2066. SafeSysFreeString(*pbstrCRC);
  2067. *pfPatchAvailable = FALSE;
  2068. *plSize = -1;
  2069. }
  2070. return hNodeListCodeBase;
  2071. }
  2072. /////////////////////////////////////////////////////////////////////////////
  2073. // GetItemNextCodeBase()
  2074. //
  2075. // Find the next codebase (path) of the given item
  2076. /////////////////////////////////////////////////////////////////////////////
  2077. HRESULT CXmlCatalog::GetItemNextCodeBase(HANDLE_NODELIST hNodeListCodeBase,
  2078. BSTR* pbstrCodeBase,
  2079. BSTR* pbstrName,
  2080. BSTR* pbstrCRC,
  2081. BOOL* pfPatchAvailable,
  2082. LONG* plSize)
  2083. {
  2084. LOG_Block("GetItemNextCodeBase()");
  2085. HRESULT hr = E_FAIL;
  2086. IXMLDOMNode* pNodeCodeBaseSize = NULL;
  2087. HANDLE_NODE hNodeCodeBase = HANDLE_NODE_INVALID;
  2088. if (NULL == pbstrCodeBase || NULL == pbstrName || NULL == pbstrCRC || NULL == pfPatchAvailable || NULL == plSize)
  2089. {
  2090. return E_INVALIDARG;
  2091. }
  2092. *pbstrCodeBase = NULL;
  2093. *pbstrName = NULL;
  2094. *pbstrCRC = NULL;
  2095. *pfPatchAvailable = FALSE;
  2096. *plSize = -1;
  2097. BSTR bstrSize = NULL;
  2098. if (SUCCEEDED(hr = FindNextDOMNode(hNodeListCodeBase, &hNodeCodeBase)))
  2099. {
  2100. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_HREF, pbstrCodeBase));
  2101. CleanUpIfFailedAndSetHrMsg(GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_PATCHAVAILABLE, pfPatchAvailable));
  2102. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_NAME, pbstrName);
  2103. GetAttribute(m_ppNodeArray[hNodeCodeBase], KEY_CRC, pbstrCRC);
  2104. FindSingleDOMNode(m_ppNodeArray[hNodeCodeBase], KEY_SIZE, &pNodeCodeBaseSize);
  2105. GetText(pNodeCodeBaseSize, &bstrSize);
  2106. if (NULL != bstrSize)
  2107. {
  2108. *plSize = MyBSTR2L(bstrSize);
  2109. }
  2110. }
  2111. CleanUp:
  2112. SafeReleaseNULL(pNodeCodeBaseSize);
  2113. SafeSysFreeString(bstrSize);
  2114. if (FAILED(hr))
  2115. {
  2116. SafeSysFreeString(*pbstrCodeBase);
  2117. SafeSysFreeString(*pbstrCRC);
  2118. SafeSysFreeString(*pbstrName);
  2119. *pfPatchAvailable = FALSE;
  2120. *plSize = -1;
  2121. }
  2122. return hr;
  2123. }
  2124. /////////////////////////////////////////////////////////////////////////////
  2125. // GetItemInstallInfo()
  2126. //
  2127. // Retrieve the installation information of the given item
  2128. /////////////////////////////////////////////////////////////////////////////
  2129. HRESULT CXmlCatalog::GetItemInstallInfo(HANDLE_NODE hNodeItem,
  2130. BSTR* pbstrInstallerType,
  2131. BOOL* pfExclusive,
  2132. BOOL* pfReboot,
  2133. LONG* plNumCommands)
  2134. {
  2135. LOG_Block("GetItemInstallInfo()");
  2136. HRESULT hr = E_FAIL;
  2137. QuitIfNull(pbstrInstallerType);
  2138. QuitIfNull(pfExclusive);
  2139. QuitIfNull(pfReboot);
  2140. QuitIfNull(plNumCommands);
  2141. *pbstrInstallerType = NULL;
  2142. *plNumCommands = 0; // may not be any, so initialize to 0
  2143. IXMLDOMNode* pNodeInstall = NULL;
  2144. IXMLDOMNodeList* pNodeListCommands = NULL;
  2145. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2146. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_INSTALLERTYPE, pbstrInstallerType));
  2147. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_EXCLUSIVE, pfExclusive));
  2148. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_NEEDSREBOOT, pfReboot));
  2149. pNodeListCommands = FindDOMNodeList(pNodeInstall, KEY_COMMAND);
  2150. if (NULL != pNodeListCommands)
  2151. {
  2152. CleanUpIfFailedAndSetHrMsg(pNodeListCommands->get_length(plNumCommands));
  2153. }
  2154. CleanUp:
  2155. if (FAILED(hr))
  2156. {
  2157. SafeSysFreeString(*pbstrInstallerType);
  2158. }
  2159. SafeReleaseNULL(pNodeInstall);
  2160. SafeReleaseNULL(pNodeListCommands);
  2161. return hr;
  2162. }
  2163. /////////////////////////////////////////////////////////////////////////////
  2164. // GetItemInstallCommand()
  2165. //
  2166. // Find the installation command and switches of the given item
  2167. /////////////////////////////////////////////////////////////////////////////
  2168. HRESULT CXmlCatalog::GetItemInstallCommand(HANDLE_NODE hNodeItem,
  2169. INT iOrder,
  2170. BSTR* pbstrCommandType,
  2171. BSTR* pbstrCommand,
  2172. BSTR* pbstrSwitches,
  2173. BSTR* pbstrInfSection)
  2174. {
  2175. LOG_Block("GetItemInstallCommand()");
  2176. USES_IU_CONVERSION;
  2177. HRESULT hr = E_FAIL;
  2178. QuitIfNull(pbstrCommandType);
  2179. QuitIfNull(pbstrCommand);
  2180. QuitIfNull(pbstrSwitches);
  2181. QuitIfNull(pbstrInfSection);
  2182. *pbstrCommandType = NULL;
  2183. *pbstrCommand = NULL;
  2184. *pbstrSwitches = NULL;
  2185. *pbstrInfSection = NULL;
  2186. IXMLDOMNode* pNodeInstall = NULL;
  2187. IXMLDOMNode* pNodeCommand = NULL;
  2188. IXMLDOMNode* pNodeSwitches = NULL;
  2189. BSTR bstrNameCommand = NULL;
  2190. BSTR bstrNameCommandTemp = SysAllocString(L"command[@order = ");
  2191. TCHAR szCommand[64];
  2192. hr = StringCchPrintfEx(szCommand, ARRAYSIZE(szCommand), NULL, NULL, MISTSAFE_STRING_FLAGS,
  2193. _T("%ls\"%d\"]"), bstrNameCommandTemp, iOrder);
  2194. CleanUpIfFailedAndSetHrMsg(hr);
  2195. bstrNameCommand = SysAllocString(T2OLE(szCommand));
  2196. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLATION, &pNodeInstall));
  2197. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeInstall, bstrNameCommand, &pNodeCommand));
  2198. CleanUpIfFailedAndSetHrMsg(GetText(pNodeCommand, pbstrCommand));
  2199. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeCommand, KEY_COMMANDTYPE, pbstrCommandType));
  2200. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeCommand, KEY_INFINSTALL, pbstrInfSection));
  2201. if (SUCCEEDED(FindSingleDOMNode(pNodeCommand, KEY_SWITCHES, &pNodeSwitches)))
  2202. {
  2203. CleanUpIfFailedAndSetHrMsg(GetText(pNodeSwitches, pbstrSwitches));
  2204. }
  2205. CleanUp:
  2206. if (FAILED(hr))
  2207. {
  2208. SafeSysFreeString(*pbstrCommandType);
  2209. SafeSysFreeString(*pbstrCommand);
  2210. SafeSysFreeString(*pbstrSwitches);
  2211. SafeSysFreeString(*pbstrInfSection);
  2212. }
  2213. SafeReleaseNULL(pNodeInstall);
  2214. SafeReleaseNULL(pNodeCommand);
  2215. SafeReleaseNULL(pNodeSwitches);
  2216. SysFreeString(bstrNameCommand);
  2217. SysFreeString(bstrNameCommandTemp);
  2218. return hr;
  2219. }
  2220. /////////////////////////////////////////////////////////////////////////////
  2221. // CloseItem()
  2222. //
  2223. // Release the item node
  2224. /////////////////////////////////////////////////////////////////////////////
  2225. void CXmlCatalog::CloseItem(HANDLE_NODE hNodeItem)
  2226. {
  2227. SafeCloseHandleNode(hNodeItem);
  2228. }
  2229. /////////////////////////////////////////////////////////////////////////////
  2230. // GetTotalEstimatedSize()
  2231. //
  2232. // Get the Total Estimated Download Size of all Items based on Codebase Size
  2233. HRESULT CXmlCatalog::GetTotalEstimatedSize(LONG *plTotalSize)
  2234. {
  2235. LOG_Block("GetTotalEstimatedSize()");
  2236. HRESULT hr = E_FAIL;
  2237. BSTR bstrCodebaseSize = NULL;
  2238. IXMLDOMNodeList *pItemList = NULL;
  2239. IXMLDOMNodeList *pCodebaseList = NULL;
  2240. IXMLDOMNode *pNodeItem = NULL;
  2241. IXMLDOMNode *pNodeInstall = NULL;
  2242. IXMLDOMNode *pNodeCodebase = NULL;
  2243. IXMLDOMNode *pNodeSize = NULL;
  2244. LONG lItemCount = 0;
  2245. LONG lCodebaseCount = 0;
  2246. LONG lTotalSize = 0;
  2247. QuitIfNull(plTotalSize);
  2248. *plTotalSize = 0;
  2249. IXMLDOMNode *pParentNode = NULL;
  2250. CleanUpIfFailedAndSetHrMsg(m_pDocCatalog->QueryInterface(IID_IXMLDOMNode, (void**)&pParentNode));
  2251. CleanUpIfFailedAndSetHrMsg(pParentNode->selectNodes(KEY_ITEM_SEARCH, &pItemList));
  2252. if (NULL == pItemList) goto CleanUp;
  2253. CleanUpIfFailedAndSetHrMsg(pItemList->get_length(&lItemCount));
  2254. if (0 == lItemCount) goto CleanUp; // no items
  2255. // Loop through each Item
  2256. CleanUpIfFailedAndSetHrMsg(pItemList->nextNode(&pNodeItem));
  2257. while (NULL != pNodeItem)
  2258. {
  2259. // Get Installation Element
  2260. CleanUpIfFailedAndSetHrMsg(pNodeItem->selectSingleNode(KEY_INSTALLATION, &pNodeInstall));
  2261. if (NULL == pNodeInstall) goto CleanUp;
  2262. CleanUpIfFailedAndSetHrMsg(pNodeInstall->selectNodes(KEY_CODEBASE, &pCodebaseList));
  2263. if (NULL == pCodebaseList) goto CleanUp;
  2264. CleanUpIfFailedAndSetHrMsg(pCodebaseList->get_length(&lCodebaseCount));
  2265. if (0 == lCodebaseCount) goto CleanUp; // must be at least 1 cab
  2266. // Loop through each Codebase Getting the Size for Each one
  2267. CleanUpIfFailedAndSetHrMsg(pCodebaseList->nextNode(&pNodeCodebase));
  2268. while (NULL != pNodeCodebase)
  2269. {
  2270. // Get the Size Element
  2271. CleanUpIfFailedAndSetHrMsg(pNodeCodebase->selectSingleNode(KEY_SIZE, &pNodeSize));
  2272. if (NULL != pNodeSize)
  2273. {
  2274. pNodeSize->get_text(&bstrCodebaseSize);
  2275. if (NULL != bstrCodebaseSize)
  2276. {
  2277. // Add this Codebase's size to the total download size
  2278. lTotalSize += (DWORD) MyBSTR2L(bstrCodebaseSize);
  2279. SafeSysFreeString(bstrCodebaseSize);
  2280. }
  2281. }
  2282. SafeReleaseNULL(pNodeSize);
  2283. SafeReleaseNULL(pNodeCodebase);
  2284. CleanUpIfFailedAndSetHrMsg(pCodebaseList->nextNode(&pNodeCodebase));
  2285. }
  2286. SafeReleaseNULL(pCodebaseList);
  2287. SafeReleaseNULL(pNodeInstall);
  2288. SafeReleaseNULL(pNodeItem);
  2289. CleanUpIfFailedAndSetHrMsg(pItemList->nextNode(&pNodeItem)); // get the next Item Node
  2290. }
  2291. // Update the Total Size after completing.. if we fail anywhere through here
  2292. // we'll return 0.
  2293. *plTotalSize = lTotalSize;
  2294. CleanUp:
  2295. SafeReleaseNULL(pParentNode);
  2296. SafeReleaseNULL(pItemList);
  2297. SafeReleaseNULL(pCodebaseList);
  2298. SafeReleaseNULL(pNodeItem);
  2299. SafeReleaseNULL(pNodeInstall);
  2300. SafeReleaseNULL(pNodeCodebase);
  2301. SafeReleaseNULL(pNodeSize);
  2302. return hr;
  2303. }
  2304. /////////////////////////////////////////////////////////////////////////////
  2305. // FindItemByIdentity()
  2306. //
  2307. // Input:
  2308. // pNodeIdentity - a pointer to an Identity Node to match against an Items
  2309. // identity in the Catalog. We will search through each item
  2310. // till we find a match with the supplied identity
  2311. //
  2312. // Output:
  2313. // phNodeItem - Handle of the found Item
  2314. //
  2315. /////////////////////////////////////////////////////////////////////////////
  2316. HRESULT CXmlCatalog::FindItemByIdentity(IXMLDOMNode* pNodeIdentity, HANDLE_NODE* phNodeItem)
  2317. {
  2318. LOG_Block("FindItemByIdentity()");
  2319. HRESULT hr = E_FAIL;
  2320. IXMLDOMNode* pNodeIdentityDes = NULL;
  2321. *phNodeItem = HANDLE_NODE_INVALID;
  2322. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  2323. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  2324. hNodeList = FindFirstDOMNode(m_pDocCatalog, KEY_ITEM_SEARCH, &hNodeItem);
  2325. if (HANDLE_NODELIST_INVALID != hNodeList)
  2326. {
  2327. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2328. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentity))
  2329. {
  2330. *phNodeItem = hNodeItem;
  2331. goto CleanUp;
  2332. }
  2333. SafeReleaseNULL(pNodeIdentityDes);
  2334. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2335. while (SUCCEEDED(FindNextDOMNode(hNodeList, &hNodeItem)))
  2336. {
  2337. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2338. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentity))
  2339. {
  2340. *phNodeItem = hNodeItem;
  2341. goto CleanUp;
  2342. }
  2343. SafeReleaseNULL(pNodeIdentityDes);
  2344. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2345. }
  2346. }
  2347. CleanUp:
  2348. CloseItemList(hNodeList);
  2349. SafeReleaseNULL(pNodeIdentityDes);
  2350. if (HANDLE_NODE_INVALID == *phNodeItem)
  2351. {
  2352. LOG_Error(_T("Can't find the matching Item Node in Catalog"));
  2353. hr = E_FAIL;
  2354. }
  2355. return hr;
  2356. }
  2357. /*
  2358. /////////////////////////////////////////////////////////////////////////////
  2359. // IfSameIdentity()
  2360. //
  2361. // Return TRUE if the two <identity> nodes are identical. Return FALSE otherwise.
  2362. /////////////////////////////////////////////////////////////////////////////
  2363. BOOL CXmlCatalog::IfSameIdentity(IXMLDOMNode* pNodeIdentity1, IXMLDOMNode* pNodeIdentity2)
  2364. {
  2365. LOG_Block("IfSameIdentity()");
  2366. BOOL fResult = FALSE;
  2367. BSTR bstrNameGUID = SysAllocString(L"guid");
  2368. BSTR bstrNameIDName = SysAllocString(L"name");
  2369. BSTR bstrNameIDPublisherName = SysAllocString(L"publisherName");
  2370. BSTR bstrNameType = SysAllocString(L"type");
  2371. BSTR bstrNameVersion = SysAllocString(L"version");
  2372. BSTR bstrNameLanguage = SysAllocString(L"language");
  2373. //
  2374. // compare <guid> node
  2375. //
  2376. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameGUID))
  2377. {
  2378. goto CleanUp;
  2379. }
  2380. //
  2381. // compare <publisherName> node
  2382. //
  2383. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameIDPublisherName))
  2384. {
  2385. goto CleanUp;
  2386. }
  2387. //
  2388. // compare "name" attribute, this is a required attribute
  2389. //
  2390. if (!IfHasSameAttribute(pNodeIdentity1, pNodeIdentity2, bstrNameIDName, FALSE))
  2391. {
  2392. goto CleanUp;
  2393. }
  2394. //
  2395. // compare <type> node
  2396. //
  2397. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameType))
  2398. {
  2399. goto CleanUp;
  2400. }
  2401. //
  2402. // compare <version> node, which really means "file version" here
  2403. //
  2404. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameVersion))
  2405. {
  2406. goto CleanUp;
  2407. }
  2408. //
  2409. // compare <language> node
  2410. //
  2411. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameLanguage))
  2412. {
  2413. goto CleanUp;
  2414. }
  2415. fResult = TRUE;
  2416. CleanUp:
  2417. SysFreeString(bstrNameGUID);
  2418. SysFreeString(bstrNameIDName);
  2419. SysFreeString(bstrNameIDPublisherName);
  2420. SysFreeString(bstrNameType);
  2421. SysFreeString(bstrNameVersion);
  2422. SysFreeString(bstrNameLanguage);
  2423. if (!fResult)
  2424. {
  2425. LOG_XML(_T("Different <identity>\'s found."));
  2426. }
  2427. else
  2428. {
  2429. LOG_XML(_T("Same <identity>\'s found."));
  2430. }
  2431. return fResult;
  2432. }
  2433. */
  2434. /////////////////////////////////////////////////////////////////////////////
  2435. // GetItemLanguage()
  2436. //
  2437. // Get the Language Entity from the Item Identity
  2438. /////////////////////////////////////////////////////////////////////////////
  2439. HRESULT CXmlCatalog::GetItemLanguage(HANDLE_NODE hNodeItem, BSTR* pbstrLanguage)
  2440. {
  2441. HRESULT hr = S_OK;
  2442. if (HANDLE_NODE_INVALID == hNodeItem || NULL == pbstrLanguage)
  2443. {
  2444. return E_INVALIDARG;
  2445. }
  2446. IXMLDOMNode *pNodeIdentity = NULL;
  2447. IXMLDOMNode *pNodeLanguage = NULL;
  2448. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentity);
  2449. if (FAILED(hr))
  2450. goto CleanUp;
  2451. hr = FindSingleDOMNode(pNodeIdentity, KEY_LANGUAGE, &pNodeLanguage);
  2452. if (FAILED(hr))
  2453. goto CleanUp;
  2454. hr = GetText(pNodeLanguage, pbstrLanguage);
  2455. if (FAILED(hr))
  2456. goto CleanUp;
  2457. CleanUp:
  2458. SafeReleaseNULL(pNodeLanguage);
  2459. SafeReleaseNULL(pNodeIdentity);
  2460. return hr;
  2461. }
  2462. /////////////////////////////////////////////////////////////////////////////
  2463. // GetCorpItemPlatformStr()
  2464. //
  2465. // Get the Simplified Platform String for an Item (uses the first available platform element)
  2466. /////////////////////////////////////////////////////////////////////////////
  2467. HRESULT CXmlCatalog::GetCorpItemPlatformStr(HANDLE_NODE hNodeItem, BSTR* pbstrPlatformStr)
  2468. {
  2469. HRESULT hr = S_OK;
  2470. if (HANDLE_NODE_INVALID == hNodeItem || NULL == pbstrPlatformStr)
  2471. {
  2472. return E_INVALIDARG;
  2473. }
  2474. IXMLDOMNode *pNodePlatform = NULL;
  2475. IXMLDOMNode *pNodePlatformArchitecture = NULL;
  2476. IXMLDOMNode *pNodePlatformVersion = NULL;
  2477. BSTR bstrPlatformName = NULL;
  2478. BSTR bstrArchitecture = NULL;
  2479. int iMajor = 0;
  2480. int iMinor = 0;
  2481. hr = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatform);
  2482. if (FAILED(hr))
  2483. goto CleanUp;
  2484. hr = GetAttribute(pNodePlatform, KEY_NAME, &bstrPlatformName);
  2485. if (FAILED(hr))
  2486. goto CleanUp;
  2487. hr = FindSingleDOMNode(pNodePlatform, KEY_PROCESSORARCHITECTURE, &pNodePlatformArchitecture);
  2488. if (FAILED(hr))
  2489. goto CleanUp;
  2490. hr = FindSingleDOMNode(pNodePlatform, KEY_VERSION, &pNodePlatformVersion);
  2491. if (FAILED(hr))
  2492. goto CleanUp;
  2493. if (NULL != bstrPlatformName && 0 != SysStringLen(bstrPlatformName))
  2494. {
  2495. if (CSTR_EQUAL == CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  2496. bstrPlatformName, -1, L"VER_PLATFORM_WIN32_NT", -1))
  2497. {
  2498. // this is an NT platform
  2499. hr = GetAttribute(pNodePlatformVersion, KEY_MAJOR, &iMajor);
  2500. if (FAILED(hr))
  2501. goto CleanUp;
  2502. if (4 == iMajor)
  2503. {
  2504. // WinNT4
  2505. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_NT4);
  2506. }
  2507. else // 5 == iMajor
  2508. {
  2509. hr = GetAttribute(pNodePlatformVersion, KEY_MINOR, &iMinor);
  2510. if (FAILED(hr))
  2511. goto CleanUp;
  2512. if (iMinor > 0)
  2513. {
  2514. hr = GetText(pNodePlatformArchitecture, &bstrArchitecture);
  2515. if (FAILED(hr))
  2516. goto CleanUp;
  2517. // whistler
  2518. if (CSTR_EQUAL == CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE,
  2519. bstrArchitecture, -1, L"x86", -1))
  2520. {
  2521. // x86WinXP
  2522. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_X86WHI);
  2523. }
  2524. else
  2525. {
  2526. // ia64WinXP
  2527. *pbstrPlatformStr = SysAllocString(CORP_PLATFROM_DIR_IA64WHI);
  2528. }
  2529. }
  2530. else
  2531. {
  2532. // x86Win2k
  2533. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_NT5);
  2534. }
  2535. }
  2536. }
  2537. else // VER_PLATFORM_WIN32_WINDOWS
  2538. {
  2539. // this is a Win9x platform
  2540. hr = GetAttribute(pNodePlatformVersion, KEY_MINOR, &iMinor);
  2541. if (FAILED(hr))
  2542. goto CleanUp;
  2543. if (iMinor >= 90)
  2544. {
  2545. // x86WinME
  2546. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_WINME);
  2547. }
  2548. else if (iMinor > 0 && iMinor < 90)
  2549. {
  2550. // x86Win98
  2551. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_W98);
  2552. }
  2553. else
  2554. {
  2555. // x86Win95
  2556. *pbstrPlatformStr = SysAllocString(CORP_PLATFORM_DIR_W95);
  2557. }
  2558. }
  2559. }
  2560. CleanUp:
  2561. SysFreeString(bstrPlatformName);
  2562. SysFreeString(bstrArchitecture);
  2563. SafeReleaseNULL(pNodePlatformVersion);
  2564. SafeReleaseNULL(pNodePlatformArchitecture);
  2565. SafeReleaseNULL(pNodePlatform);
  2566. return hr;
  2567. }
  2568. /////////////////////////////////////////////////////////////////////////////
  2569. // CXmlItems
  2570. /////////////////////////////////////////////////////////////////////////////
  2571. // Constructor
  2572. //
  2573. // Create IXMLDOMDocument* for Items; this is for write only
  2574. /////////////////////////////////////////////////////////////////////////////
  2575. CXmlItems::CXmlItems()
  2576. : m_pDocItems(NULL),
  2577. m_pNodeItems(NULL)
  2578. {
  2579. LOG_Block("CXmlItems()");
  2580. Init();
  2581. }
  2582. /////////////////////////////////////////////////////////////////////////////
  2583. // Constructor
  2584. //
  2585. // Create IXMLDOMDocument* for Items; take TRUE for read, FALSE for write
  2586. /////////////////////////////////////////////////////////////////////////////
  2587. CXmlItems::CXmlItems(BOOL fRead)
  2588. : m_pDocItems(NULL),
  2589. m_pNodeItems(NULL)
  2590. {
  2591. LOG_Block("CXmlItems(BOOL fRead)");
  2592. //
  2593. // for writing Items only
  2594. //
  2595. if (!fRead)
  2596. {
  2597. Init();
  2598. }
  2599. }
  2600. /////////////////////////////////////////////////////////////////////////////
  2601. //
  2602. // Initialize XML DOC node pointers before writing
  2603. /////////////////////////////////////////////////////////////////////////////
  2604. void CXmlItems::Init()
  2605. {
  2606. LOG_Block("Init()");
  2607. HRESULT hr = CoCreateInstance(CLSID_DOMDocument,
  2608. NULL,
  2609. CLSCTX_INPROC_SERVER,
  2610. IID_IXMLDOMDocument,
  2611. (void **) &m_pDocItems);
  2612. if (FAILED(hr))
  2613. {
  2614. LOG_ErrorMsg(hr);
  2615. }
  2616. else
  2617. {
  2618. IXMLDOMNode* pNodeXML = NULL;
  2619. BSTR bstrNameSpaceSchema = NULL;
  2620. //
  2621. // create the <?xml version="1.0"?> node
  2622. //
  2623. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  2624. if (NULL == pNodeXML) goto CleanUp;
  2625. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  2626. //
  2627. // process the iuident.txt to find the Items schema path
  2628. //
  2629. TCHAR szIUDir[MAX_PATH];
  2630. TCHAR szIdentFile[MAX_PATH];
  2631. LPTSTR pszItemsSchema = NULL;
  2632. LPTSTR pszNameSpaceSchema = NULL;
  2633. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  2634. if (NULL == pszItemsSchema)
  2635. {
  2636. LOG_ErrorMsg(E_OUTOFMEMORY);
  2637. goto CleanUp;
  2638. }
  2639. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  2640. if (NULL == pszNameSpaceSchema)
  2641. {
  2642. LOG_ErrorMsg(E_OUTOFMEMORY);
  2643. goto CleanUp;
  2644. }
  2645. GetIndustryUpdateDirectory(szIUDir);
  2646. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  2647. if (FAILED(hr))
  2648. {
  2649. LOG_ErrorMsg(hr);
  2650. goto CleanUp;
  2651. }
  2652. GetPrivateProfileString(IDENT_IUSCHEMA,
  2653. IDENT_IUSCHEMA_ITEMS,
  2654. _T(""),
  2655. pszItemsSchema,
  2656. INTERNET_MAX_URL_LENGTH,
  2657. szIdentFile);
  2658. if ('\0' == pszItemsSchema[0])
  2659. {
  2660. // no Items schema path specified in iuident.txt
  2661. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  2662. goto CleanUp;
  2663. }
  2664. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  2665. _T("x-schema:%s"), pszItemsSchema);
  2666. if (FAILED(hr))
  2667. {
  2668. LOG_ErrorMsg(hr);
  2669. goto CleanUp;
  2670. }
  2671. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  2672. //
  2673. // create the <items> node with the path of the schema
  2674. //
  2675. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  2676. if (NULL == m_pNodeItems) goto CleanUp;
  2677. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  2678. CleanUp:
  2679. SafeReleaseNULL(pNodeXML);
  2680. SysFreeString(bstrNameSpaceSchema);
  2681. SafeHeapFree(pszItemsSchema);
  2682. SafeHeapFree(pszNameSpaceSchema);
  2683. }
  2684. }
  2685. /////////////////////////////////////////////////////////////////////////////
  2686. // Destructor
  2687. //
  2688. // Release IXMLDOMDocument* for Items
  2689. /////////////////////////////////////////////////////////////////////////////
  2690. CXmlItems::~CXmlItems()
  2691. {
  2692. SafeReleaseNULL(m_pNodeItems);
  2693. SafeReleaseNULL(m_pDocItems);
  2694. }
  2695. /////////////////////////////////////////////////////////////////////////////
  2696. // Clear()
  2697. //
  2698. // Reset IXMLDOMDocument* for Items
  2699. /////////////////////////////////////////////////////////////////////////////
  2700. void CXmlItems::Clear()
  2701. {
  2702. SafeReleaseNULL(m_pNodeItems);
  2703. SafeReleaseNULL(m_pDocItems);
  2704. }
  2705. /////////////////////////////////////////////////////////////////////////////
  2706. // LoadXMLDocument()
  2707. //
  2708. // Load an XML Document from string
  2709. /////////////////////////////////////////////////////////////////////////////
  2710. HRESULT CXmlItems::LoadXMLDocument(BSTR bstrXml)
  2711. {
  2712. LOG_Block("LoadXMLDocument()");
  2713. SafeReleaseNULL(m_pDocItems);
  2714. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocItems);
  2715. if (FAILED(hr))
  2716. {
  2717. LOG_ErrorMsg(hr);
  2718. }
  2719. return hr;
  2720. }
  2721. /////////////////////////////////////////////////////////////////////////////
  2722. // LoadXMLDocumentFile()
  2723. //
  2724. // Load an XML Document from the specified file
  2725. /////////////////////////////////////////////////////////////////////////////
  2726. HRESULT CXmlItems::LoadXMLDocumentFile(BSTR bstrFilePath)
  2727. {
  2728. LOG_Block("LoadXMLDocumentFile()");
  2729. SafeReleaseNULL(m_pDocItems);
  2730. HRESULT hr = LoadDocument(bstrFilePath, &m_pDocItems);
  2731. if (FAILED(hr))
  2732. {
  2733. LOG_ErrorMsg(hr);
  2734. }
  2735. return hr;
  2736. }
  2737. /////////////////////////////////////////////////////////////////////////////
  2738. // SaveXMLDocument()
  2739. //
  2740. // Save an XML Document to the specified location
  2741. /////////////////////////////////////////////////////////////////////////////
  2742. HRESULT CXmlItems::SaveXMLDocument(BSTR bstrFilePath)
  2743. {
  2744. LOG_Block("SaveXMLDocument()");
  2745. HRESULT hr = SaveDocument(m_pDocItems, bstrFilePath);
  2746. if (FAILED(hr))
  2747. {
  2748. LOG_ErrorMsg(hr);
  2749. }
  2750. return hr;
  2751. }
  2752. /////////////////////////////////////////////////////////////////////////////
  2753. // AddGlobalErrorCodeIfNoItems()
  2754. //
  2755. // Add the errorCode attribute for <items> if there's no <itemStatus> child node
  2756. /////////////////////////////////////////////////////////////////////////////
  2757. HANDLE_NODELIST CXmlItems::AddGlobalErrorCodeIfNoItems(DWORD dwErrorCode)
  2758. {
  2759. LOG_Block("AddGlobalErrorCodeIfNoItems()");
  2760. HRESULT hr = S_OK;
  2761. IXMLDOMNode* pNodeItem = NULL;
  2762. HANDLE_NODE hNodeItemStatus = HANDLE_NODE_INVALID;
  2763. FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, &hNodeItemStatus);
  2764. if (HANDLE_NODE_INVALID == hNodeItemStatus)
  2765. {
  2766. //
  2767. // set the "errorCode" attribute
  2768. //
  2769. FindFirstDOMNode(m_pDocItems, KEY_ITEMS, &pNodeItem);
  2770. if (NULL != pNodeItem)
  2771. {
  2772. hr = SetAttribute(pNodeItem, KEY_ERRORCODE, dwErrorCode);
  2773. }
  2774. }
  2775. SafeReleaseNULL(pNodeItem);
  2776. return hr;
  2777. }
  2778. /////////////////////////////////////////////////////////////////////////////
  2779. // GetFirstItem()
  2780. //
  2781. // Find the first item in Items xml doc
  2782. /////////////////////////////////////////////////////////////////////////////
  2783. HANDLE_NODELIST CXmlItems::GetFirstItem(HANDLE_NODE* phNodeItem)
  2784. {
  2785. LOG_Block("GetFirstItem()");
  2786. HANDLE_NODELIST hNodeListItem = FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, phNodeItem);
  2787. return hNodeListItem;
  2788. }
  2789. /////////////////////////////////////////////////////////////////////////////
  2790. // GetNextItem()
  2791. //
  2792. // Find the next item in Items xml doc
  2793. /////////////////////////////////////////////////////////////////////////////
  2794. HRESULT CXmlItems::GetNextItem(HANDLE_NODELIST hNodeListItem, HANDLE_NODE* phNodeItem)
  2795. {
  2796. LOG_Block("GetNextItem()");
  2797. return FindNextDOMNode(hNodeListItem, phNodeItem);
  2798. }
  2799. /////////////////////////////////////////////////////////////////////////////
  2800. // CloseItemList()
  2801. //
  2802. // Release the item nodelist
  2803. /////////////////////////////////////////////////////////////////////////////
  2804. void CXmlItems::CloseItemList(HANDLE_NODELIST hNodeListItem)
  2805. {
  2806. SafeFindCloseHandle(hNodeListItem);
  2807. }
  2808. /////////////////////////////////////////////////////////////////////////////
  2809. // GetItemDownloadPath()
  2810. //
  2811. // Retrieve the download path of the given item
  2812. /////////////////////////////////////////////////////////////////////////////
  2813. HRESULT CXmlItems::GetItemDownloadPath(HANDLE_NODE hNodeItem, BSTR* pbstrDownloadPath)
  2814. {
  2815. LOG_Block("GetItemDownloadPath()");
  2816. HRESULT hr = E_FAIL;
  2817. IXMLDOMNode* pNodeDownloadPath = NULL;
  2818. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_DOWNLOADPATH, &pNodeDownloadPath));
  2819. CleanUpIfFailedAndSetHrMsg(GetText(pNodeDownloadPath, pbstrDownloadPath));
  2820. CleanUp:
  2821. SafeReleaseNULL(pNodeDownloadPath);
  2822. return hr;
  2823. }
  2824. /////////////////////////////////////////////////////////////////////////////
  2825. // GetItemDownloadPath()
  2826. //
  2827. // Retrieve the download path of the given item in catalog
  2828. /////////////////////////////////////////////////////////////////////////////
  2829. HRESULT CXmlItems::GetItemDownloadPath(CXmlCatalog* pCatalog, HANDLE_NODE hNodeItem, BSTR* pbstrDownloadPath)
  2830. {
  2831. LOG_Block("GetItemDownloadPath() for an item in catalog");
  2832. HRESULT hr = E_FAIL;
  2833. IXMLDOMNode* pNodeItem = NULL;
  2834. IXMLDOMNode* pNodeDownloadPath = NULL;
  2835. HANDLE_NODE hNodeItemsItem = HANDLE_NODE_INVALID;
  2836. if (NULL != (pNodeItem = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  2837. {
  2838. hr = FindItem(pNodeItem, &hNodeItemsItem, TRUE);
  2839. }
  2840. else
  2841. {
  2842. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  2843. hr = E_FAIL;
  2844. goto CleanUp;
  2845. }
  2846. if (FAILED(hr) || HANDLE_NODE_INVALID == hNodeItemsItem)
  2847. {
  2848. LOG_Error(_T("Can't find item from Items xml"));
  2849. goto CleanUp;
  2850. }
  2851. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItemsItem], KEY_DOWNLOADPATH, &pNodeDownloadPath));
  2852. CleanUpIfFailedAndSetHrMsg(GetText(pNodeDownloadPath, pbstrDownloadPath));
  2853. CleanUp:
  2854. SafeReleaseNULL(pNodeDownloadPath);
  2855. return hr;
  2856. }
  2857. /////////////////////////////////////////////////////////////////////////////
  2858. // CloseItem()
  2859. //
  2860. // Release the item node
  2861. /////////////////////////////////////////////////////////////////////////////
  2862. void CXmlItems::CloseItem(HANDLE_NODE hNodeItem)
  2863. {
  2864. SafeCloseHandleNode(hNodeItem);
  2865. }
  2866. /////////////////////////////////////////////////////////////////////////////
  2867. // FindItem()
  2868. //
  2869. // Input:
  2870. // pNodeItem - the <itemStatus> node of the install items xml; we need
  2871. // to find the corresponding <itemStatus> node in the existing
  2872. // items xml with the identical <identity>, <platform> and
  2873. // <client> nodes.
  2874. // Output:
  2875. // phNodeItem - the handle we pass back to differentiate different
  2876. // <itemStatus> node in the existing items xml
  2877. /////////////////////////////////////////////////////////////////////////////
  2878. HRESULT CXmlItems::FindItem(IXMLDOMNode* pNodeItem, HANDLE_NODE* phNodeItem, BOOL fIdentityOnly /*= FALSE*/)
  2879. {
  2880. LOG_Block("FindItem()");
  2881. HRESULT hr1, hr2, hr = E_FAIL;
  2882. IXMLDOMNode* pNodeIdentitySrc = NULL;
  2883. IXMLDOMNode* pNodeIdentityDes = NULL;
  2884. IXMLDOMNode* pNodePlatformSrc = NULL;
  2885. IXMLDOMNode* pNodePlatformDes = NULL;
  2886. IXMLDOMNode* pNodeClientSrc = NULL;
  2887. IXMLDOMNode* pNodeClientDes = NULL;
  2888. *phNodeItem = HANDLE_NODE_INVALID;
  2889. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  2890. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  2891. hNodeList = FindFirstDOMNode(m_pDocItems, KEY_ITEM_ITEMSTATUS, &hNodeItem);
  2892. if (HANDLE_NODELIST_INVALID != hNodeList)
  2893. {
  2894. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2895. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIdentitySrc));
  2896. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentitySrc))
  2897. {
  2898. if (fIdentityOnly)
  2899. {
  2900. //
  2901. // we now found the match
  2902. //
  2903. *phNodeItem = hNodeItem;
  2904. goto CleanUp;
  2905. }
  2906. else
  2907. {
  2908. hr1 = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatformDes);
  2909. hr2 = FindSingleDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatformSrc);
  2910. if ((FAILED(hr1) && FAILED(hr2)) ||
  2911. (SUCCEEDED(hr1) && SUCCEEDED(hr2) && AreNodesEqual(pNodePlatformDes, pNodePlatformSrc)))
  2912. {
  2913. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_CLIENT, &pNodeClientDes));
  2914. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClientSrc));
  2915. if (AreNodesEqual(pNodeClientDes, pNodeClientSrc))
  2916. {
  2917. //
  2918. // we now found the match
  2919. //
  2920. *phNodeItem = hNodeItem;
  2921. goto CleanUp;
  2922. }
  2923. }
  2924. }
  2925. }
  2926. SafeReleaseNULL(pNodeClientDes);
  2927. SafeReleaseNULL(pNodeClientSrc);
  2928. SafeReleaseNULL(pNodePlatformDes);
  2929. SafeReleaseNULL(pNodePlatformSrc);
  2930. SafeReleaseNULL(pNodeIdentityDes);
  2931. SafeReleaseNULL(pNodeIdentitySrc);
  2932. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2933. while (SUCCEEDED(FindNextDOMNode(hNodeList, &hNodeItem)))
  2934. {
  2935. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_IDENTITY, &pNodeIdentityDes));
  2936. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIdentitySrc));
  2937. if (AreNodesEqual(pNodeIdentityDes, pNodeIdentitySrc))
  2938. {
  2939. if (fIdentityOnly)
  2940. {
  2941. //
  2942. // we now found the match
  2943. //
  2944. *phNodeItem = hNodeItem;
  2945. goto CleanUp;
  2946. }
  2947. else
  2948. {
  2949. hr1 = FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_PLATFORM, &pNodePlatformDes);
  2950. hr2 = FindSingleDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatformSrc);
  2951. if ((FAILED(hr1) && FAILED(hr2)) ||
  2952. (SUCCEEDED(hr1) && SUCCEEDED(hr2) && AreNodesEqual(pNodePlatformDes, pNodePlatformSrc)))
  2953. {
  2954. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_CLIENT, &pNodeClientDes));
  2955. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClientSrc));
  2956. if (AreNodesEqual(pNodeClientDes, pNodeClientSrc))
  2957. {
  2958. //
  2959. // we now found the match
  2960. //
  2961. *phNodeItem = hNodeItem;
  2962. break;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. SafeReleaseNULL(pNodeClientDes);
  2968. SafeReleaseNULL(pNodeClientSrc);
  2969. SafeReleaseNULL(pNodePlatformDes);
  2970. SafeReleaseNULL(pNodePlatformSrc);
  2971. SafeReleaseNULL(pNodeIdentityDes);
  2972. SafeReleaseNULL(pNodeIdentitySrc);
  2973. SafeReleaseNULL(m_ppNodeArray[hNodeItem]);
  2974. }
  2975. }
  2976. CleanUp:
  2977. CloseItemList(hNodeList);
  2978. SafeReleaseNULL(pNodeClientDes);
  2979. SafeReleaseNULL(pNodeClientSrc);
  2980. SafeReleaseNULL(pNodePlatformDes);
  2981. SafeReleaseNULL(pNodePlatformSrc);
  2982. SafeReleaseNULL(pNodeIdentityDes);
  2983. SafeReleaseNULL(pNodeIdentitySrc);
  2984. if (HANDLE_NODE_INVALID == *phNodeItem)
  2985. {
  2986. LOG_Error(_T("Can't find the identical item node in existing Items xml"));
  2987. hr = E_FAIL;
  2988. }
  2989. return hr;
  2990. }
  2991. /////////////////////////////////////////////////////////////////////////////
  2992. // FindItem()
  2993. //
  2994. // Input:
  2995. // pCatalog - the pointer to the CXmlCatalog object
  2996. // hNodeItem - the handle of the <item> node of the catalog xml; we need
  2997. // to find the corresponding <itemStatus> node in the existing
  2998. // items xml with the identical <identity>, <platform> and
  2999. // <client> nodes.
  3000. // Output:
  3001. // phNodeItem - the handle we pass back to differentiate different
  3002. // <itemStatus> node in items xml
  3003. /////////////////////////////////////////////////////////////////////////////
  3004. HRESULT CXmlItems::FindItem(CXmlCatalog* pCatalog,
  3005. HANDLE_NODE hNodeItem,
  3006. HANDLE_NODE* phNodeItem)
  3007. {
  3008. LOG_Block("FindItem() by handle");
  3009. IXMLDOMNode* pNode = NULL;
  3010. if (NULL != (pNode = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  3011. {
  3012. return FindItem(pNode, phNodeItem, TRUE);
  3013. }
  3014. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  3015. return E_FAIL;
  3016. }
  3017. /*
  3018. /////////////////////////////////////////////////////////////////////////////
  3019. // IfSameClientInfo()
  3020. //
  3021. // Return TRUE if the two <client> nodes are identical. Return FALSE otherwise.
  3022. /////////////////////////////////////////////////////////////////////////////
  3023. BOOL CXmlItems::IfSameClientInfo(IXMLDOMNode* pNodeClient1, IXMLDOMNode* pNodeClient2)
  3024. {
  3025. LOG_Block("IfSameClientInfo()");
  3026. BSTR bstrText1 = NULL, bstrText2 = NULL;
  3027. BOOL fResult = FALSE;
  3028. GetText(pNodeClient1, &bstrText1);
  3029. GetText(pNodeClient2, &bstrText2);
  3030. if (NULL != bstrText1 && NULL != bstrText2)
  3031. {
  3032. fResult = CompareBSTRsEqual(bstrText1, bstrText2);
  3033. }
  3034. SysFreeString(bstrText1);
  3035. SysFreeString(bstrText2);
  3036. if (!fResult)
  3037. {
  3038. LOG_XML(_T("Different <client>\'s found."));
  3039. }
  3040. else
  3041. {
  3042. LOG_XML(_T("Same <client>\'s found."));
  3043. }
  3044. return fResult;
  3045. }
  3046. /////////////////////////////////////////////////////////////////////////////
  3047. // IfSameIdentity()
  3048. //
  3049. // Return TRUE if the two <identity> nodes are identical. Return FALSE otherwise.
  3050. /////////////////////////////////////////////////////////////////////////////
  3051. BOOL CXmlItems::IfSameIdentity(IXMLDOMNode* pNodeIdentity1, IXMLDOMNode* pNodeIdentity2)
  3052. {
  3053. LOG_Block("IfSameIdentity()");
  3054. BOOL fResult = FALSE;
  3055. BSTR bstrNameGUID = SysAllocString(L"guid");
  3056. BSTR bstrNameIDName = SysAllocString(L"name");
  3057. BSTR bstrNameIDPublisherName = SysAllocString(L"publisherName");
  3058. BSTR bstrNameType = SysAllocString(L"type");
  3059. BSTR bstrNameVersion = SysAllocString(L"version");
  3060. BSTR bstrNameLanguage = SysAllocString(L"language");
  3061. //
  3062. // compare <guid> node
  3063. //
  3064. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameGUID))
  3065. {
  3066. goto CleanUp;
  3067. }
  3068. //
  3069. // compare <publisherName> node
  3070. //
  3071. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameIDPublisherName))
  3072. {
  3073. goto CleanUp;
  3074. }
  3075. //
  3076. // compare "name" attribute, this is a required attribute
  3077. //
  3078. if (!IfHasSameAttribute(pNodeIdentity1, pNodeIdentity2, bstrNameIDName, FALSE))
  3079. {
  3080. goto CleanUp;
  3081. }
  3082. //
  3083. // compare <type> node
  3084. //
  3085. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameType))
  3086. {
  3087. goto CleanUp;
  3088. }
  3089. //
  3090. // compare <version> node, which really means "file version" here
  3091. //
  3092. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameVersion))
  3093. {
  3094. goto CleanUp;
  3095. }
  3096. //
  3097. // compare <language> node
  3098. //
  3099. if (!IfHasSameElement(pNodeIdentity1, pNodeIdentity2, bstrNameLanguage))
  3100. {
  3101. goto CleanUp;
  3102. }
  3103. fResult = TRUE;
  3104. CleanUp:
  3105. SysFreeString(bstrNameGUID);
  3106. SysFreeString(bstrNameIDName);
  3107. SysFreeString(bstrNameIDPublisherName);
  3108. SysFreeString(bstrNameType);
  3109. SysFreeString(bstrNameVersion);
  3110. SysFreeString(bstrNameLanguage);
  3111. if (!fResult)
  3112. {
  3113. LOG_XML(_T("Different <identity>\'s found."));
  3114. }
  3115. else
  3116. {
  3117. LOG_XML(_T("Same <identity>\'s found."));
  3118. }
  3119. return fResult;
  3120. }
  3121. /////////////////////////////////////////////////////////////////////////////
  3122. // IfSamePlatform()
  3123. //
  3124. // Return TRUE if the two <platform> nodes are identical. Return FALSE otherwise.
  3125. /////////////////////////////////////////////////////////////////////////////
  3126. BOOL CXmlItems::IfSamePlatform(IXMLDOMNode* pNodePlatform1, IXMLDOMNode* pNodePlatform2)
  3127. {
  3128. LOG_Block("IfSamePlatform()");
  3129. HRESULT hr1 = S_OK, hr2 = S_OK;
  3130. BSTR bstrPlatform1 = NULL, bstrPlatform2 = NULL;
  3131. BOOL fResult = FALSE;
  3132. hr1 = pNodePlatform1->get_xml(&bstrPlatform1);
  3133. hr2 = pNodePlatform2->get_xml(&bstrPlatform2);
  3134. if (FAILED(hr1) || FAILED(hr2) || !CompareBSTRsEqual(bstrPlatform1, bstrPlatform2))
  3135. goto CleanUp;
  3136. fResult = TRUE;
  3137. CleanUp:
  3138. SysFreeString(bstrPlatform1);
  3139. SysFreeString(bstrPlatform2);
  3140. return fResult;
  3141. }
  3142. */
  3143. /////////////////////////////////////////////////////////////////////////////
  3144. // MergeItemDownloaded()
  3145. //
  3146. // Insert items with download history into existing history (insert in front)
  3147. /////////////////////////////////////////////////////////////////////////////
  3148. HRESULT CXmlItems::MergeItemDownloaded(CXmlItems *pHistoryDownload)
  3149. {
  3150. LOG_Block("MergeItemDownloaded()");
  3151. HRESULT hr = S_OK;
  3152. IXMLDOMNode* pNodeItem = NULL;
  3153. IXMLDOMNode* pNodeItemNew = NULL;
  3154. IXMLDOMNode* pNodeItemRef = NULL;
  3155. IXMLDOMNode* pNodeXML = NULL;
  3156. BSTR bstrNameSpaceSchema = NULL;
  3157. LPTSTR pszItemsSchema = NULL;
  3158. LPTSTR pszNameSpaceSchema = NULL;
  3159. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  3160. HANDLE_NODELIST hNodeListItem = HANDLE_NODELIST_INVALID;
  3161. hNodeListItem = pHistoryDownload->GetFirstItem(&hNodeItem);
  3162. if (HANDLE_NODELIST_INVALID != hNodeListItem)
  3163. {
  3164. //
  3165. // if this is the first time writing history
  3166. // (e.g. the log file does not exist yet), do
  3167. // initialization for m_pDocItems here...
  3168. //
  3169. if (NULL == m_pDocItems)
  3170. {
  3171. hr = CoCreateInstance(CLSID_DOMDocument,
  3172. NULL,
  3173. CLSCTX_INPROC_SERVER,
  3174. IID_IXMLDOMDocument,
  3175. (void **) &m_pDocItems);
  3176. if (FAILED(hr))
  3177. {
  3178. LOG_ErrorMsg(hr);
  3179. }
  3180. else
  3181. {
  3182. //
  3183. // create the <?xml version="1.0"?> node
  3184. //
  3185. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3186. if (NULL == pNodeXML) goto CleanUp;
  3187. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3188. //
  3189. // process the iuident.txt to find the Items schema path
  3190. //
  3191. TCHAR szIUDir[MAX_PATH];
  3192. TCHAR szIdentFile[MAX_PATH];
  3193. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3194. if (NULL == pszItemsSchema)
  3195. {
  3196. hr = E_OUTOFMEMORY;
  3197. LOG_ErrorMsg(hr);
  3198. goto CleanUp;
  3199. }
  3200. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3201. if (NULL == pszNameSpaceSchema)
  3202. {
  3203. hr = E_OUTOFMEMORY;
  3204. LOG_ErrorMsg(hr);
  3205. goto CleanUp;
  3206. }
  3207. GetIndustryUpdateDirectory(szIUDir);
  3208. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  3209. if (FAILED(hr))
  3210. {
  3211. LOG_ErrorMsg(hr);
  3212. goto CleanUp;
  3213. }
  3214. GetPrivateProfileString(IDENT_IUSCHEMA,
  3215. IDENT_IUSCHEMA_ITEMS,
  3216. _T(""),
  3217. pszItemsSchema,
  3218. INTERNET_MAX_URL_LENGTH,
  3219. szIdentFile);
  3220. if ('\0' == pszItemsSchema[0])
  3221. {
  3222. // no Items schema path specified in iuident.txt
  3223. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  3224. goto CleanUp;
  3225. }
  3226. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  3227. _T("x-schema:%s"), pszItemsSchema);
  3228. if (FAILED(hr))
  3229. {
  3230. LOG_ErrorMsg(hr);
  3231. goto CleanUp;
  3232. }
  3233. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  3234. //
  3235. // create the <items> node with the path of the schema
  3236. //
  3237. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  3238. if (NULL == m_pNodeItems) goto CleanUp;
  3239. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  3240. }
  3241. }
  3242. else
  3243. {
  3244. SafeReleaseNULL(m_pNodeItems);
  3245. FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems);
  3246. }
  3247. if (NULL != m_pNodeItems)
  3248. {
  3249. if (NULL != (pNodeItem = pHistoryDownload->GetDOMNodebyHandle(hNodeItem)))
  3250. {
  3251. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3252. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3253. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3254. // SafeReleaseNULL(pNodeItem);
  3255. SafeReleaseNULL(pNodeItemNew);
  3256. SafeReleaseNULL(pNodeItemRef);
  3257. }
  3258. while (SUCCEEDED(pHistoryDownload->GetNextItem(hNodeListItem, &hNodeItem)))
  3259. {
  3260. if (NULL != (pNodeItem = pHistoryDownload->GetDOMNodebyHandle(hNodeItem)))
  3261. {
  3262. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3263. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3264. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3265. // SafeReleaseNULL(pNodeItem);
  3266. SafeReleaseNULL(pNodeItemNew);
  3267. SafeReleaseNULL(pNodeItemRef);
  3268. }
  3269. }
  3270. }
  3271. }
  3272. CleanUp:
  3273. pHistoryDownload->CloseItemList(hNodeListItem);
  3274. // SafeReleaseNULL(pNodeItem);
  3275. SafeReleaseNULL(pNodeItemNew);
  3276. SafeReleaseNULL(pNodeItemRef);
  3277. SafeReleaseNULL(pNodeXML);
  3278. SysFreeString(bstrNameSpaceSchema);
  3279. SafeHeapFree(pszItemsSchema);
  3280. SafeHeapFree(pszNameSpaceSchema);
  3281. return hr;
  3282. }
  3283. /////////////////////////////////////////////////////////////////////////////
  3284. // UpdateItemInstalled()
  3285. //
  3286. // Update items with installation history in existing history
  3287. /////////////////////////////////////////////////////////////////////////////
  3288. HRESULT CXmlItems::UpdateItemInstalled(CXmlItems *pHistoryInstall)
  3289. {
  3290. LOG_Block("UpdateItemInstalled()");
  3291. USES_IU_CONVERSION;
  3292. HRESULT hr = S_OK;
  3293. IXMLDOMNode* pNodeItem = NULL;
  3294. IXMLDOMNode* pNodeItemNew = NULL;
  3295. IXMLDOMNode* pNodeItemRef = NULL;
  3296. IXMLDOMNode* pNodeItemExist = NULL;
  3297. IXMLDOMNode* pNodeInstall = NULL;
  3298. IXMLDOMNode* pNodeInstallExist = NULL;
  3299. IXMLDOMNode* pNodeInstallNew = NULL;
  3300. IXMLDOMNode* pNodeInstallOut = NULL;
  3301. IXMLDOMNode* pNodeXML = NULL;
  3302. BSTR bstrInstallStatusExist = NULL;
  3303. BSTR bstrInstallStatusNew = NULL;
  3304. BSTR bstrTimeStamp = NULL;
  3305. BSTR bstrNameSpaceSchema = NULL;
  3306. LPTSTR pszItemsSchema = NULL;
  3307. LPTSTR pszNameSpaceSchema = NULL;
  3308. HANDLE_NODE hNodeItem = HANDLE_NODE_INVALID;
  3309. HANDLE_NODE hNodeItemExist = HANDLE_NODE_INVALID;
  3310. HANDLE_NODELIST hNodeListItem = HANDLE_NODELIST_INVALID;
  3311. hNodeListItem = pHistoryInstall->GetFirstItem(&hNodeItem);
  3312. if (HANDLE_NODELIST_INVALID != hNodeListItem)
  3313. {
  3314. //
  3315. // if this is the first time writing history
  3316. // (e.g. the log file does not exist yet), do
  3317. // initialization for m_pDocItems here...
  3318. //
  3319. if (NULL == m_pDocItems)
  3320. {
  3321. hr = CoCreateInstance(CLSID_DOMDocument,
  3322. NULL,
  3323. CLSCTX_INPROC_SERVER,
  3324. IID_IXMLDOMDocument,
  3325. (void **) &m_pDocItems);
  3326. if (FAILED(hr))
  3327. {
  3328. LOG_ErrorMsg(hr);
  3329. }
  3330. else
  3331. {
  3332. //
  3333. // create the <?xml version="1.0"?> node
  3334. //
  3335. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3336. if (NULL == pNodeXML) goto CleanUp;
  3337. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3338. //
  3339. // process the iuident.txt to find the Items schema path
  3340. //
  3341. TCHAR szIUDir[MAX_PATH];
  3342. TCHAR szIdentFile[MAX_PATH];
  3343. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3344. if (NULL == pszItemsSchema)
  3345. {
  3346. hr = E_OUTOFMEMORY;
  3347. LOG_ErrorMsg(hr);
  3348. goto CleanUp;
  3349. }
  3350. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  3351. if (NULL == pszNameSpaceSchema)
  3352. {
  3353. hr = E_OUTOFMEMORY;
  3354. LOG_ErrorMsg(hr);
  3355. goto CleanUp;
  3356. }
  3357. GetIndustryUpdateDirectory(szIUDir);
  3358. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  3359. if (FAILED(hr))
  3360. {
  3361. LOG_ErrorMsg(hr);
  3362. goto CleanUp;
  3363. }
  3364. GetPrivateProfileString(IDENT_IUSCHEMA,
  3365. IDENT_IUSCHEMA_ITEMS,
  3366. _T(""),
  3367. pszItemsSchema,
  3368. INTERNET_MAX_URL_LENGTH,
  3369. szIdentFile);
  3370. if ('\0' == pszItemsSchema[0])
  3371. {
  3372. // no Items schema path specified in iuident.txt
  3373. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  3374. goto CleanUp;
  3375. }
  3376. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  3377. _T("x-schema:%s"), pszItemsSchema);
  3378. if (FAILED(hr))
  3379. {
  3380. LOG_ErrorMsg(hr);
  3381. goto CleanUp;
  3382. }
  3383. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  3384. //
  3385. // create the <items> node with the path of the schema
  3386. //
  3387. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  3388. if (NULL == m_pNodeItems) goto CleanUp;
  3389. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  3390. }
  3391. }
  3392. else
  3393. {
  3394. SafeReleaseNULL(m_pNodeItems);
  3395. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems));
  3396. }
  3397. if (NULL != (pNodeItem = pHistoryInstall->GetDOMNodebyHandle(hNodeItem)))
  3398. {
  3399. if (SUCCEEDED(FindItem(pNodeItem, &hNodeItemExist)))
  3400. {
  3401. //
  3402. // successfully found the match
  3403. //
  3404. if (NULL != (pNodeItemExist = GetDOMNodebyHandle(hNodeItemExist)))
  3405. {
  3406. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_INSTALLSTATUS, &pNodeInstall));
  3407. FindSingleDOMNode(pNodeItemExist, KEY_INSTALLSTATUS, &pNodeInstallExist);
  3408. if (NULL != pNodeInstallExist)
  3409. {
  3410. //
  3411. // found the item already with installStatus; now find out if we want to update
  3412. // or append the installStatus
  3413. //
  3414. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstallExist, KEY_VALUE, &bstrInstallStatusExist));
  3415. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_VALUE, &bstrInstallStatusNew));
  3416. if (CSTR_EQUAL == WUCompareStringI(OLE2T(bstrInstallStatusExist), _T("IN_PROGRESS")) &&
  3417. CSTR_EQUAL != WUCompareStringI(OLE2T(bstrInstallStatusNew), _T("IN_PROGRESS")))
  3418. {
  3419. //
  3420. // this entry is an exclusive item with "IN_PROGRESS" installStatus and we found its
  3421. // updated installStatus, we need to update its installStatus
  3422. //
  3423. LOG_Out(_T("Update the exclusive item's installStatus"));
  3424. CleanUpIfFailedAndSetHrMsg(pNodeItemExist->removeChild(pNodeInstallExist, &pNodeInstallOut));
  3425. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3426. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3427. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3428. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3429. SafeSysFreeString(bstrTimeStamp);
  3430. }
  3431. else
  3432. {
  3433. //
  3434. // in this case we append a copy of this item with the new installStatus, since
  3435. // this comes from a separate install operation
  3436. //
  3437. LOG_Out(_T("This item was installed again, add an entry of this item into history \
  3438. for the new installation status only."));
  3439. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3440. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3441. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3442. }
  3443. SafeSysFreeString(bstrInstallStatusExist);
  3444. SafeSysFreeString(bstrInstallStatusNew);
  3445. }
  3446. else
  3447. {
  3448. //
  3449. // found the item without installStatus, update the entry with the installStatus
  3450. // and update the timeStamp with its installation timeStamp
  3451. //
  3452. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3453. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3454. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3455. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3456. SafeSysFreeString(bstrTimeStamp);
  3457. }
  3458. }
  3459. }
  3460. else
  3461. {
  3462. //
  3463. // no match found, this item was not downloaded through IU,
  3464. // append this item with the install status
  3465. //
  3466. LOG_Out(_T("Can't find the downloaded item in existing history. This item was not downloaded \
  3467. through IU. Add the item into history for installation status only."));
  3468. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3469. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3470. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3471. }
  3472. // SafeReleaseNULL(pNodeItem);
  3473. // SafeReleaseNULL(pNodeItemExist);
  3474. SafeReleaseNULL(pNodeItemNew);
  3475. SafeReleaseNULL(pNodeItemRef);
  3476. SafeReleaseNULL(pNodeInstall);
  3477. SafeReleaseNULL(pNodeInstallExist);
  3478. SafeReleaseNULL(pNodeInstallNew);
  3479. SafeReleaseNULL(pNodeInstallOut);
  3480. }
  3481. while (SUCCEEDED(pHistoryInstall->GetNextItem(hNodeListItem, &hNodeItem)))
  3482. {
  3483. if (NULL != (pNodeItem = pHistoryInstall->GetDOMNodebyHandle(hNodeItem)))
  3484. {
  3485. if (SUCCEEDED(FindItem(pNodeItem, &hNodeItemExist)))
  3486. {
  3487. //
  3488. // successfully found the match
  3489. //
  3490. if (NULL != (pNodeItemExist = GetDOMNodebyHandle(hNodeItemExist)))
  3491. {
  3492. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_INSTALLSTATUS, &pNodeInstall));
  3493. FindSingleDOMNode(pNodeItemExist, KEY_INSTALLSTATUS, &pNodeInstallExist);
  3494. if (NULL != pNodeInstallExist)
  3495. {
  3496. //
  3497. // found the item already with installStatus; now find out if we want to update
  3498. // or append the installStatus
  3499. //
  3500. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstallExist, KEY_VALUE, &bstrInstallStatusExist));
  3501. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeInstall, KEY_VALUE, &bstrInstallStatusNew));
  3502. if (CSTR_EQUAL == WUCompareStringI(OLE2T(bstrInstallStatusExist), _T("IN_PROGRESS")) &&
  3503. CSTR_EQUAL != WUCompareStringI(OLE2T(bstrInstallStatusNew), _T("IN_PROGRESS")))
  3504. {
  3505. //
  3506. // this entry is an exclusive item with "IN_PROGRESS" installStatus and we found its
  3507. // updated installStatus, we need to update its installStatus
  3508. //
  3509. LOG_Out(_T("Update the exclusive item's installStatus"));
  3510. CleanUpIfFailedAndSetHrMsg(pNodeItemExist->removeChild(pNodeInstallExist, &pNodeInstallOut));
  3511. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3512. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3513. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3514. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3515. SafeSysFreeString(bstrTimeStamp);
  3516. }
  3517. else
  3518. {
  3519. //
  3520. // in this case we append a copy of this item with the new installStatus, since
  3521. // this comes from a separate install operation
  3522. //
  3523. LOG_Out(_T("This item was installed again, add an entry of this item into history \
  3524. for the new installation status only."));
  3525. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3526. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3527. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3528. }
  3529. SafeSysFreeString(bstrInstallStatusExist);
  3530. SafeSysFreeString(bstrInstallStatusNew);
  3531. }
  3532. else
  3533. {
  3534. //
  3535. // found the item without installStatus, update the entry with the installStatus
  3536. // and update the timeStamp with its installation timeStamp
  3537. //
  3538. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeInstall, m_pDocItems, &pNodeInstallNew));
  3539. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeItemExist, pNodeInstallNew));
  3540. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  3541. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeItemExist, KEY_TIMESTAMP, bstrTimeStamp));
  3542. SafeSysFreeString(bstrTimeStamp);
  3543. }
  3544. }
  3545. }
  3546. else
  3547. {
  3548. //
  3549. // no match found, this item was not downloaded through IU,
  3550. // append this item with the install status
  3551. //
  3552. LOG_Out(_T("Can't find the downloaded item in existing history. This item was not downloaded \
  3553. through IU. Add the item into history for installation status only."));
  3554. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeItem, m_pDocItems, &pNodeItemNew));
  3555. CleanUpIfFailedAndSetHrMsg(m_pNodeItems->get_firstChild(&pNodeItemRef));
  3556. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, pNodeItemNew, pNodeItemRef));
  3557. }
  3558. // SafeReleaseNULL(pNodeItem);
  3559. // SafeReleaseNULL(pNodeItemExist);
  3560. SafeReleaseNULL(pNodeItemNew);
  3561. SafeReleaseNULL(pNodeItemRef);
  3562. SafeReleaseNULL(pNodeInstall);
  3563. SafeReleaseNULL(pNodeInstallExist);
  3564. SafeReleaseNULL(pNodeInstallNew);
  3565. SafeReleaseNULL(pNodeInstallOut);
  3566. }
  3567. }
  3568. }
  3569. CleanUp:
  3570. pHistoryInstall->CloseItemList(hNodeListItem);
  3571. // SafeReleaseNULL(pNodeItem);
  3572. // SafeReleaseNULL(pNodeItemExist);
  3573. SafeReleaseNULL(pNodeItemNew);
  3574. SafeReleaseNULL(pNodeItemRef);
  3575. SafeReleaseNULL(pNodeInstall);
  3576. SafeReleaseNULL(pNodeInstallExist);
  3577. SafeReleaseNULL(pNodeInstallNew);
  3578. SafeReleaseNULL(pNodeInstallOut);
  3579. SafeReleaseNULL(pNodeXML);
  3580. SysFreeString(bstrInstallStatusExist);
  3581. SysFreeString(bstrInstallStatusNew);
  3582. SysFreeString(bstrTimeStamp);
  3583. SysFreeString(bstrNameSpaceSchema);
  3584. SafeHeapFree(pszItemsSchema);
  3585. SafeHeapFree(pszNameSpaceSchema);
  3586. return hr;
  3587. }
  3588. /////////////////////////////////////////////////////////////////////////////
  3589. // UpdateItemInstallStatus()
  3590. //
  3591. // Update the install status of the given item
  3592. /////////////////////////////////////////////////////////////////////////////
  3593. HRESULT CXmlItems::UpdateItemInstallStatus(HANDLE_NODE hNodeItem,
  3594. BSTR bstrValue,
  3595. INT iNeedsReboot /*= -1*/,
  3596. DWORD dwErrorCode /*= 0*/)
  3597. {
  3598. LOG_Block("UpdateItemInstallStatus()");
  3599. HRESULT hr = E_FAIL;
  3600. IXMLDOMNode* pNodeInstallStatus = NULL;
  3601. //
  3602. // get the <installStatus> node
  3603. //
  3604. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(m_ppNodeArray[hNodeItem], KEY_INSTALLSTATUS, &pNodeInstallStatus));
  3605. //
  3606. // set the "value" attribute
  3607. //
  3608. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrValue));
  3609. //
  3610. // set the "needsReboot" attribute
  3611. //
  3612. if (-1 != iNeedsReboot)
  3613. {
  3614. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_NEEDSREBOOT, iNeedsReboot));
  3615. }
  3616. //
  3617. // set the "errorCode" attribute
  3618. //
  3619. if (0 != dwErrorCode)
  3620. {
  3621. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, dwErrorCode));
  3622. }
  3623. CleanUp:
  3624. SafeReleaseNULL(pNodeInstallStatus);
  3625. return hr;
  3626. }
  3627. /////////////////////////////////////////////////////////////////////////////
  3628. // AddItem()
  3629. //
  3630. // Input:
  3631. // pNodeItem - the <item> node of the catalog xml; we need to read
  3632. // <identity> node, <description> node and <platform> nodes
  3633. // from it and write to the items xml.
  3634. // Output:
  3635. // phNodeItem - the handle we pass back to differentiate different
  3636. // <itemStatus> node in items xml
  3637. /////////////////////////////////////////////////////////////////////////////
  3638. HRESULT CXmlItems::AddItem(IXMLDOMNode* pNodeItem, HANDLE_NODE* phNodeItem)
  3639. {
  3640. LOG_Block("AddItem()");
  3641. HRESULT hr = E_FAIL;
  3642. IXMLDOMNode* pNodeIndentity = NULL;
  3643. IXMLDOMNode* pNodeIndentityNew = NULL;
  3644. IXMLDOMNode* pNodeDescription = NULL;
  3645. IXMLDOMNode* pNodeDescriptionNew = NULL;
  3646. IXMLDOMNode* pNodePlatform = NULL;
  3647. IXMLDOMNode* pNodePlatformNew = NULL;
  3648. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  3649. *phNodeItem = CreateDOMNodeWithHandle(m_pDocItems, NODE_ELEMENT, KEY_ITEMSTATUS);
  3650. if (HANDLE_NODE_INVALID == *phNodeItem) goto CleanUp;
  3651. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pNodeItems, m_ppNodeArray[*phNodeItem]));
  3652. hNodeList = FindFirstDOMNode(pNodeItem, KEY_IDENTITY, &pNodeIndentity);
  3653. if (HANDLE_NODELIST_INVALID != hNodeList)
  3654. {
  3655. SafeFindCloseHandle(hNodeList);
  3656. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeIndentity, m_pDocItems, &pNodeIndentityNew));
  3657. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodeIndentityNew));
  3658. }
  3659. hNodeList = FindFirstDOMNode(pNodeItem, KEY_DESCRIPTION, &pNodeDescription);
  3660. if (HANDLE_NODELIST_INVALID != hNodeList)
  3661. {
  3662. SafeFindCloseHandle(hNodeList);
  3663. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodeDescription, m_pDocItems, &pNodeDescriptionNew));
  3664. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodeDescriptionNew));
  3665. }
  3666. hNodeList = FindFirstDOMNode(pNodeItem, KEY_PLATFORM, &pNodePlatform);
  3667. if (HANDLE_NODELIST_INVALID != hNodeList)
  3668. {
  3669. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodePlatform, m_pDocItems, &pNodePlatformNew));
  3670. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodePlatformNew));
  3671. SafeReleaseNULL(pNodePlatform);
  3672. SafeReleaseNULL(pNodePlatformNew);
  3673. while (SUCCEEDED(FindNextDOMNode(hNodeList, &pNodePlatform)))
  3674. {
  3675. CleanUpIfFailedAndSetHrMsg(CopyNode(pNodePlatform, m_pDocItems, &pNodePlatformNew));
  3676. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[*phNodeItem], pNodePlatformNew));
  3677. SafeReleaseNULL(pNodePlatform);
  3678. SafeReleaseNULL(pNodePlatformNew);
  3679. }
  3680. }
  3681. CleanUp:
  3682. if (HANDLE_NODELIST_INVALID != hNodeList)
  3683. {
  3684. SafeFindCloseHandle(hNodeList);
  3685. }
  3686. SafeReleaseNULL(pNodeIndentity);
  3687. SafeReleaseNULL(pNodeIndentityNew);
  3688. SafeReleaseNULL(pNodeDescription);
  3689. SafeReleaseNULL(pNodeDescriptionNew);
  3690. SafeReleaseNULL(pNodePlatform);
  3691. SafeReleaseNULL(pNodePlatformNew);
  3692. return hr;
  3693. }
  3694. /////////////////////////////////////////////////////////////////////////////
  3695. // AddItem()
  3696. //
  3697. // Input:
  3698. // pCatalog - the pointer to the CXmlCatalog object
  3699. // hNodeItem - the handle of the <item> node of the catalog xml; we need
  3700. // to read <identity> node, <description> node and <platform>
  3701. // nodes from it and write to the items xml.
  3702. // Output:
  3703. // phNodeItem - the handle we pass back to differentiate different
  3704. // <itemStatus> node in items xml
  3705. /////////////////////////////////////////////////////////////////////////////
  3706. HRESULT CXmlItems::AddItem(CXmlCatalog* pCatalog, HANDLE_NODE hNodeItem, HANDLE_NODE* phNodeItem)
  3707. {
  3708. LOG_Block("AddItem() by handle");
  3709. IXMLDOMNode* pNode = NULL;
  3710. if (NULL != (pNode = pCatalog->GetDOMNodebyHandle(hNodeItem)))
  3711. {
  3712. return AddItem(pNode, phNodeItem);
  3713. }
  3714. LOG_Error(_T("Can't retrieve valid item node from catalog xml"));
  3715. return E_FAIL;
  3716. }
  3717. /////////////////////////////////////////////////////////////////////////////
  3718. // AddTimeStamp()
  3719. /////////////////////////////////////////////////////////////////////////////
  3720. HRESULT CXmlItems::AddTimeStamp(HANDLE_NODE hNodeItem)
  3721. {
  3722. LOG_Block("AddTimeStamp()");
  3723. USES_IU_CONVERSION;
  3724. HRESULT hr = E_FAIL;
  3725. TCHAR szTimestamp[32];
  3726. SYSTEMTIME stTimestamp;
  3727. BSTR bstrTimeStamp = NULL;
  3728. GetLocalTime(&stTimestamp);
  3729. hr = StringCchPrintfEx(szTimestamp, ARRAYSIZE(szTimestamp), NULL, NULL, MISTSAFE_STRING_FLAGS,
  3730. _T("%4d-%02d-%02dT%02d:%02d:%02d"), // "ISO 8601" format for "datatime" datatype in xml
  3731. stTimestamp.wYear,
  3732. stTimestamp.wMonth,
  3733. stTimestamp.wDay,
  3734. stTimestamp.wHour,
  3735. stTimestamp.wMinute,
  3736. stTimestamp.wSecond);
  3737. CleanUpIfFailedAndSetHrMsg(hr);
  3738. bstrTimeStamp = SysAllocString(T2OLE(szTimestamp));
  3739. //
  3740. // set the "timestamp" attribute
  3741. //
  3742. CleanUpIfFailedAndSetHrMsg(SetAttribute(m_ppNodeArray[hNodeItem], KEY_TIMESTAMP, bstrTimeStamp));
  3743. CleanUp:
  3744. SysFreeString(bstrTimeStamp);
  3745. return hr;
  3746. }
  3747. /////////////////////////////////////////////////////////////////////////////
  3748. // AddDetectResult()
  3749. /////////////////////////////////////////////////////////////////////////////
  3750. HRESULT CXmlItems::AddDetectResult(HANDLE_NODE hNodeItem,
  3751. INT iInstalled /*= -1*/,
  3752. INT iUpToDate /*= -1*/,
  3753. INT iNewerVersion /*= -1*/,
  3754. INT iExcluded /*= -1*/,
  3755. INT iForce /*= -1*/,
  3756. INT iComputerSystem /* = -1 */)
  3757. {
  3758. LOG_Block("AddDetectResult()");
  3759. HRESULT hr = E_FAIL;
  3760. IXMLDOMNode* pNodeDetectResult = NULL;
  3761. //
  3762. // create the <detectResult> node
  3763. //
  3764. pNodeDetectResult = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DETECTRESULT);
  3765. if (NULL == pNodeDetectResult) goto CleanUp;
  3766. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDetectResult));
  3767. //
  3768. // set the "installed" attribute
  3769. //
  3770. if (-1 != iInstalled)
  3771. {
  3772. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_INSTALLED, iInstalled));
  3773. }
  3774. //
  3775. // set the "upToDate" attribute
  3776. //
  3777. if (-1 != iUpToDate)
  3778. {
  3779. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_UPTODATE, iUpToDate));
  3780. }
  3781. //
  3782. // set the "newerVersion" attribute
  3783. //
  3784. if (-1 != iNewerVersion)
  3785. {
  3786. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_NEWERVERSION, iNewerVersion));
  3787. }
  3788. //
  3789. // set the "excluded" attribute
  3790. //
  3791. if (-1 != iExcluded)
  3792. {
  3793. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_EXCLUDED, iExcluded));
  3794. }
  3795. //
  3796. // set the "force" attribute
  3797. //
  3798. if (-1 != iForce)
  3799. {
  3800. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_FORCE, iForce));
  3801. }
  3802. //
  3803. // set computerSystem attribute
  3804. //
  3805. if (-1 != iComputerSystem)
  3806. {
  3807. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDetectResult, KEY_COMPUTERSYSTEM, iComputerSystem));
  3808. }
  3809. CleanUp:
  3810. SafeReleaseNULL(pNodeDetectResult);
  3811. return hr;
  3812. }
  3813. /////////////////////////////////////////////////////////////////////////////
  3814. // AddDownloadStatus()
  3815. /////////////////////////////////////////////////////////////////////////////
  3816. HRESULT CXmlItems::AddDownloadStatus(HANDLE_NODE hNodeItem, BSTR bstrValue, DWORD dwErrorCode /*= 0*/)
  3817. {
  3818. LOG_Block("AddDownloadStatus()");
  3819. HRESULT hr = E_FAIL;
  3820. IXMLDOMNode* pNodeDownloadStatus = NULL;
  3821. //
  3822. // create the <downloadStatus> node
  3823. //
  3824. pNodeDownloadStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DOWNLOADSTATUS);
  3825. if (NULL == pNodeDownloadStatus) goto CleanUp;
  3826. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDownloadStatus));
  3827. //
  3828. // set the "value" attribute
  3829. //
  3830. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDownloadStatus, KEY_VALUE, bstrValue));
  3831. //
  3832. // set the "errorCode" attribute
  3833. //
  3834. if (0 != dwErrorCode)
  3835. {
  3836. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeDownloadStatus, KEY_ERRORCODE, dwErrorCode));
  3837. }
  3838. CleanUp:
  3839. SafeReleaseNULL(pNodeDownloadStatus);
  3840. return hr;
  3841. }
  3842. /////////////////////////////////////////////////////////////////////////////
  3843. // AddDownloadPath()
  3844. /////////////////////////////////////////////////////////////////////////////
  3845. HRESULT CXmlItems::AddDownloadPath(HANDLE_NODE hNodeItem, BSTR bstrDownloadPath)
  3846. {
  3847. LOG_Block("AddDownloadPath()");
  3848. HRESULT hr = E_FAIL;
  3849. IXMLDOMNode* pNodeDownloadPath = NULL;
  3850. IXMLDOMNode* pNodeDownloadPathText = NULL;
  3851. pNodeDownloadPath = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DOWNLOADPATH);
  3852. if (NULL == pNodeDownloadPath) goto CleanUp;
  3853. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeDownloadPath));
  3854. pNodeDownloadPathText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  3855. if (NULL == pNodeDownloadPathText) goto CleanUp;
  3856. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeDownloadPathText, bstrDownloadPath));
  3857. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeDownloadPath, pNodeDownloadPathText));
  3858. CleanUp:
  3859. SafeReleaseNULL(pNodeDownloadPath);
  3860. SafeReleaseNULL(pNodeDownloadPathText);
  3861. return hr;
  3862. }
  3863. /////////////////////////////////////////////////////////////////////////////
  3864. // AddInstallStatus()
  3865. /////////////////////////////////////////////////////////////////////////////
  3866. HRESULT CXmlItems::AddInstallStatus(HANDLE_NODE hNodeItem,
  3867. BSTR bstrValue,
  3868. BOOL fNeedsReboot,
  3869. DWORD dwErrorCode /*= 0*/)
  3870. {
  3871. LOG_Block("AddInstallStatus()");
  3872. HRESULT hr = E_FAIL;
  3873. IXMLDOMNode* pNodeInstallStatus = NULL;
  3874. //
  3875. // create the <installStatus> node
  3876. //
  3877. pNodeInstallStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_INSTALLSTATUS);
  3878. if (NULL == pNodeInstallStatus) goto CleanUp;
  3879. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeInstallStatus));
  3880. //
  3881. // set the "value" attribute
  3882. //
  3883. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrValue));
  3884. //
  3885. // set the "needsReboot" attribute
  3886. //
  3887. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_NEEDSREBOOT, fNeedsReboot));
  3888. //
  3889. // set the "errorCode" attribute
  3890. //
  3891. if (0 != dwErrorCode)
  3892. {
  3893. CleanUpIfFailedAndSetHrMsg(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, dwErrorCode));
  3894. }
  3895. CleanUp:
  3896. SafeReleaseNULL(pNodeInstallStatus);
  3897. return hr;
  3898. }
  3899. /////////////////////////////////////////////////////////////////////////////
  3900. // AddClientInfo()
  3901. /////////////////////////////////////////////////////////////////////////////
  3902. HRESULT CXmlItems::AddClientInfo(HANDLE_NODE hNodeItem, BSTR bstrClient)
  3903. {
  3904. LOG_Block("AddClientInfo()");
  3905. HRESULT hr = E_FAIL;
  3906. IXMLDOMNode* pNodeClient = NULL;
  3907. IXMLDOMNode* pNodeClientText = NULL;
  3908. pNodeClient = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_CLIENT);
  3909. if (NULL == pNodeClient) goto CleanUp;
  3910. CleanUpIfFailedAndSetHrMsg(InsertNode(m_ppNodeArray[hNodeItem], pNodeClient));
  3911. pNodeClientText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  3912. if (NULL == pNodeClientText) goto CleanUp;
  3913. CleanUpIfFailedAndSetHrMsg(SetValue(pNodeClientText, bstrClient));
  3914. CleanUpIfFailedAndSetHrMsg(InsertNode(pNodeClient, pNodeClientText));
  3915. CleanUp:
  3916. SafeReleaseNULL(pNodeClient);
  3917. SafeReleaseNULL(pNodeClientText);
  3918. return hr;
  3919. }
  3920. /////////////////////////////////////////////////////////////////////////////
  3921. // MigrateV3History()
  3922. //
  3923. // Migrate V3 History: Consumer history only.
  3924. /////////////////////////////////////////////////////////////////////////////
  3925. HRESULT CXmlItems::MigrateV3History(LPCTSTR pszHistoryFilePath)
  3926. {
  3927. LOG_Block("MigrateV3History()");
  3928. HRESULT hr = S_OK;
  3929. IXMLDOMNode* pNodeXML = NULL;
  3930. IXMLDOMNode* pNodeItemStatus = NULL;
  3931. IXMLDOMNode* pNodeIdentity = NULL;
  3932. IXMLDOMNode* pNodeDescription = NULL;
  3933. IXMLDOMNode* pNodeDescriptionText = NULL;
  3934. IXMLDOMNode* pNodeTitle = NULL;
  3935. IXMLDOMNode* pNodeTitleText = NULL;
  3936. IXMLDOMNode* pNodeVersion = NULL;
  3937. IXMLDOMNode* pNodeVersionText = NULL;
  3938. IXMLDOMNode* pNodeInstallStatus = NULL;
  3939. IXMLDOMNode* pNodeClient = NULL;
  3940. IXMLDOMNode* pNodeClientText = NULL;
  3941. BSTR bstrNameSpaceSchema = NULL, bstrStatus = NULL, bstrString = NULL;
  3942. LPTSTR pszItemsSchema = NULL;
  3943. LPTSTR pszNameSpaceSchema = NULL;
  3944. CV3AppLog V3History(pszHistoryFilePath);
  3945. char szLineType[32];
  3946. char szTemp[32];
  3947. char szDate[32];
  3948. char szTime[32];
  3949. char szPUID[32]; // puid - migrate to <identity "name">
  3950. char szTitle[256]; // title - migrate to <description>-><descriptionText>-><title>
  3951. char szVersion[40]; // version - migrate to <identity>-><version>
  3952. char szTimeStamp[32]; // timestamp - migrate to <itemStatus "timestamp">
  3953. char szResult[16]; // result - migrate to <installStatus "value">
  3954. char szErrCode[16]; // errorcode - migrate to <installStatus "errorCode">
  3955. USES_IU_CONVERSION;
  3956. V3History.StartReading();
  3957. while (V3History.ReadLine())
  3958. {
  3959. SafeSysFreeString(bstrString);
  3960. // get line type (first field)
  3961. V3History.CopyNextField(szLineType, ARRAYSIZE(szLineType));
  3962. if ((_stricmp(szLineType, LOG_V3CAT) == 0) || (_stricmp(szLineType, LOG_V3_2) == 0))
  3963. {
  3964. // get "puid" field
  3965. V3History.CopyNextField(szPUID, ARRAYSIZE(szPUID));
  3966. // get "operation" field: installed/uninstalled
  3967. // we only migrate installed item
  3968. V3History.CopyNextField(szTemp, ARRAYSIZE(szTemp));
  3969. if (0 != _stricmp(szTemp, LOG_INSTALL))
  3970. continue;
  3971. //
  3972. // now we start to create <itemStatus> node for this item
  3973. //
  3974. if (NULL == m_pDocItems)
  3975. {
  3976. //
  3977. // we don't have IU history file yet
  3978. //
  3979. hr = CoCreateInstance(CLSID_DOMDocument,
  3980. NULL,
  3981. CLSCTX_INPROC_SERVER,
  3982. IID_IXMLDOMDocument,
  3983. (void **) &m_pDocItems);
  3984. if (FAILED(hr))
  3985. {
  3986. LOG_ErrorMsg(hr);
  3987. }
  3988. else
  3989. {
  3990. //
  3991. // create the <?xml version="1.0"?> node
  3992. //
  3993. pNodeXML = CreateDOMNode(m_pDocItems, NODE_PROCESSING_INSTRUCTION, KEY_XML);
  3994. if (NULL == pNodeXML) goto CleanUp;
  3995. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, pNodeXML));
  3996. //
  3997. // process the iuident.txt to find the Items schema path
  3998. //
  3999. TCHAR szIUDir[MAX_PATH];
  4000. TCHAR szIdentFile[MAX_PATH];
  4001. pszItemsSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  4002. if (NULL == pszItemsSchema)
  4003. {
  4004. hr = E_OUTOFMEMORY;
  4005. LOG_ErrorMsg(hr);
  4006. goto CleanUp;
  4007. }
  4008. pszNameSpaceSchema = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, INTERNET_MAX_URL_LENGTH * sizeof(TCHAR));
  4009. if (NULL == pszNameSpaceSchema)
  4010. {
  4011. hr = E_OUTOFMEMORY;
  4012. LOG_ErrorMsg(hr);
  4013. goto CleanUp;
  4014. }
  4015. GetIndustryUpdateDirectory(szIUDir);
  4016. hr = PathCchCombine(szIdentFile, ARRAYSIZE(szIdentFile), szIUDir, IDENTTXT);
  4017. if (FAILED(hr))
  4018. {
  4019. LOG_ErrorMsg(hr);
  4020. goto CleanUp;
  4021. }
  4022. GetPrivateProfileString(IDENT_IUSCHEMA,
  4023. IDENT_IUSCHEMA_ITEMS,
  4024. _T(""),
  4025. pszItemsSchema,
  4026. INTERNET_MAX_URL_LENGTH,
  4027. szIdentFile);
  4028. if ('\0' == pszItemsSchema[0])
  4029. {
  4030. // no Items schema path specified in iuident.txt
  4031. LOG_Error(_T("No schema path specified in iuident.txt for Items"));
  4032. goto CleanUp;
  4033. }
  4034. hr = StringCchPrintfEx(pszNameSpaceSchema, INTERNET_MAX_URL_LENGTH, NULL, NULL, MISTSAFE_STRING_FLAGS,
  4035. _T("x-schema:%s"), pszItemsSchema);
  4036. if (FAILED(hr))
  4037. {
  4038. LOG_ErrorMsg(hr);
  4039. goto CleanUp;
  4040. }
  4041. bstrNameSpaceSchema = T2BSTR(pszNameSpaceSchema);
  4042. //
  4043. // create the <items> node with the path of the schema
  4044. //
  4045. m_pNodeItems = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMS, bstrNameSpaceSchema);
  4046. if (NULL == m_pNodeItems) goto CleanUp;
  4047. CleanUpIfFailedAndSetHrMsg(InsertNode(m_pDocItems, m_pNodeItems));
  4048. }
  4049. }
  4050. else
  4051. {
  4052. SafeReleaseNULL(m_pNodeItems);
  4053. FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &m_pNodeItems);
  4054. }
  4055. // create <itemStatus> node
  4056. pNodeItemStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_ITEMSTATUS);
  4057. if (NULL == pNodeItemStatus) continue;
  4058. SkipIfFail(InsertNode(m_pNodeItems, pNodeItemStatus));
  4059. // create <client> node
  4060. pNodeClient = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_CLIENT);
  4061. if (NULL == pNodeClient) continue;
  4062. pNodeClientText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4063. if (NULL == pNodeClientText) continue;
  4064. BSTR bstrV3Client = SysAllocString(C_V3_CLIENTINFO);
  4065. SkipIfFail(SetValue(pNodeClientText, bstrV3Client));
  4066. SkipIfFail(InsertNode(pNodeClient, pNodeClientText));
  4067. SkipIfFail(InsertNode(pNodeItemStatus, pNodeClient));
  4068. SafeSysFreeString(bstrV3Client);
  4069. // create <identity> node
  4070. pNodeIdentity = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_IDENTITY);
  4071. if (NULL == pNodeIdentity) continue;
  4072. SkipIfFail(InsertNode(pNodeItemStatus, pNodeIdentity));
  4073. // set the "name" attribute for <identity>
  4074. bstrString = SysAllocString(A2OLE(szPUID));
  4075. SkipIfFail(SetAttribute(pNodeIdentity, KEY_NAME, bstrString));
  4076. // set the "itemID" attribute for <identity>
  4077. SkipIfFail(SetAttribute(pNodeIdentity, KEY_ITEMID, bstrString));
  4078. SafeSysFreeString(bstrString);
  4079. // get "title" field
  4080. V3History.CopyNextField(szTitle, ARRAYSIZE(szTitle));
  4081. // create <description> node
  4082. pNodeDescription = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DESCRIPTION);
  4083. if (NULL == pNodeDescription) continue;
  4084. SkipIfFail(SetAttribute(pNodeDescription, KEY_HIDDEN, 0));
  4085. SkipIfFail(InsertNode(pNodeItemStatus, pNodeDescription));
  4086. // create <descriptionText> node
  4087. pNodeDescriptionText = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_DESCRIPTIONTEXT);
  4088. if (NULL == pNodeDescriptionText) continue;
  4089. SkipIfFail(InsertNode(pNodeDescription, pNodeDescriptionText));
  4090. // create <title> node
  4091. pNodeTitle = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_TITLE);
  4092. if (NULL == pNodeTitle) continue;
  4093. pNodeTitleText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4094. if (NULL == pNodeTitleText) continue;
  4095. bstrString = SysAllocString(A2OLE(szTitle));
  4096. SkipIfFail(SetValue(pNodeTitleText, bstrString));
  4097. SkipIfFail(InsertNode(pNodeTitle, pNodeTitleText));
  4098. SkipIfFail(InsertNode(pNodeDescriptionText, pNodeTitle));
  4099. SafeSysFreeString(bstrString);
  4100. // get "version" field
  4101. V3History.CopyNextField(szVersion, ARRAYSIZE(szVersion));
  4102. // create <version> node
  4103. pNodeVersion = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_VERSION);
  4104. if (NULL == pNodeVersion) continue;
  4105. pNodeVersionText = CreateDOMNode(m_pDocItems, NODE_TEXT, NULL);
  4106. if (NULL == pNodeVersionText) continue;
  4107. bstrString = SysAllocString(A2OLE(szVersion));
  4108. SkipIfFail(SetValue(pNodeVersionText, bstrString));
  4109. SkipIfFail(InsertNode(pNodeVersion, pNodeVersionText));
  4110. SkipIfFail(InsertNode(pNodeIdentity, pNodeVersion));
  4111. SafeSysFreeString(bstrString);
  4112. // get timestamp
  4113. if ((_stricmp(szLineType, LOG_V3_2) == 0))
  4114. {
  4115. // read the timestamp and convert to "ISO 8601" format for "datatime" datatype in xml:
  4116. // for example, 2001-05-01T18:30:00
  4117. // so we only need to replace the space with 'T'
  4118. // timestamp
  4119. V3History.CopyNextField(szTimeStamp, ARRAYSIZE(szTimeStamp));
  4120. char *p = strchr(szTimeStamp, ' ');
  4121. if (NULL != p) // if (NULL == p): there's no space then leave it as is to pass into SetAttribute
  4122. {
  4123. *p = 'T';
  4124. }
  4125. }
  4126. else
  4127. {
  4128. // V3 Beta had two fields for date and time, we need read both these fields:
  4129. // date
  4130. V3History.CopyNextField(szDate, ARRAYSIZE(szDate));
  4131. // time
  4132. V3History.CopyNextField(szTime, ARRAYSIZE(szTime));
  4133. hr = StringCchPrintfExA(szTimeStamp, ARRAYSIZE(szTimeStamp), NULL, NULL, MISTSAFE_STRING_FLAGS,
  4134. "%sT%s", szDate, szTime);
  4135. SkipIfFail(hr);
  4136. }
  4137. // set the "timestamp" attribute for <itemStatus>
  4138. bstrString = SysAllocString(A2OLE(szTimeStamp));
  4139. SkipIfFail(SetAttribute(pNodeItemStatus, KEY_TIMESTAMP, bstrString));
  4140. SafeSysFreeString(bstrString);
  4141. // skip the "record type" field
  4142. V3History.CopyNextField(szTemp, ARRAYSIZE(szTemp));
  4143. // get "result" field
  4144. V3History.CopyNextField(szResult, ARRAYSIZE(szResult));
  4145. // create <InstallStatus> node
  4146. pNodeInstallStatus = CreateDOMNode(m_pDocItems, NODE_ELEMENT, KEY_INSTALLSTATUS);
  4147. if (NULL == pNodeInstallStatus) continue;
  4148. SkipIfFail(InsertNode(pNodeItemStatus, pNodeInstallStatus));
  4149. // set the "value" attribute for <installStatus>
  4150. if (_stricmp(szResult, LOG_SUCCESS) == 0)
  4151. {
  4152. bstrStatus = SysAllocString(L"COMPLETE");
  4153. }
  4154. else if (_stricmp(szTemp, LOG_STARTED) == 0)
  4155. {
  4156. bstrStatus = SysAllocString(L"IN_PROGRESS");
  4157. }
  4158. else
  4159. {
  4160. bstrStatus = SysAllocString(L"FAILED");
  4161. }
  4162. SkipIfFail(SetAttribute(pNodeInstallStatus, KEY_VALUE, bstrStatus));
  4163. if (_stricmp(szResult, LOG_SUCCESS) != 0)
  4164. {
  4165. // get "error code" field
  4166. V3History.CopyNextField(szErrCode, ARRAYSIZE(szErrCode));
  4167. // set the "errorCode" attribute for <installStatus>
  4168. SkipIfFail(SetAttribute(pNodeInstallStatus, KEY_ERRORCODE, atoh(szErrCode)));
  4169. }
  4170. }
  4171. }
  4172. V3History.StopReading();
  4173. CleanUp:
  4174. SafeReleaseNULL(pNodeXML);
  4175. SafeReleaseNULL(pNodeItemStatus);
  4176. SafeReleaseNULL(pNodeIdentity);
  4177. SafeReleaseNULL(pNodeDescriptionText);
  4178. SafeReleaseNULL(pNodeTitle);
  4179. SafeReleaseNULL(pNodeTitleText);
  4180. SafeReleaseNULL(pNodeVersion);
  4181. SafeReleaseNULL(pNodeVersionText);
  4182. SafeReleaseNULL(pNodeInstallStatus);
  4183. SafeReleaseNULL(pNodeClient);
  4184. SafeReleaseNULL(pNodeClientText);
  4185. SysFreeString(bstrString);
  4186. SysFreeString(bstrNameSpaceSchema);
  4187. SysFreeString(bstrStatus);
  4188. SafeHeapFree(pszItemsSchema);
  4189. SafeHeapFree(pszNameSpaceSchema);
  4190. return hr;
  4191. }
  4192. /////////////////////////////////////////////////////////////////////////////
  4193. // GetItemsBSTR()
  4194. /////////////////////////////////////////////////////////////////////////////
  4195. HRESULT CXmlItems::GetItemsBSTR(BSTR *pbstrXmlItems)
  4196. {
  4197. LOG_Block("GetItemsBSTR()");
  4198. if (NULL == m_pDocItems)
  4199. {
  4200. *pbstrXmlItems = NULL;
  4201. return S_OK;
  4202. }
  4203. //
  4204. // convert XML DOC into BSTR
  4205. //
  4206. HRESULT hr = m_pDocItems->get_xml(pbstrXmlItems);
  4207. if (FAILED(hr))
  4208. {
  4209. LOG_ErrorMsg(hr);
  4210. }
  4211. return hr;
  4212. }
  4213. /////////////////////////////////////////////////////////////////////////////
  4214. // GetFilteredHistoryBSTR()
  4215. /////////////////////////////////////////////////////////////////////////////
  4216. HRESULT CXmlItems::GetFilteredHistoryBSTR(BSTR bstrBeginDateTime,
  4217. BSTR bstrEndDateTime,
  4218. BSTR bstrClient,
  4219. BSTR *pbstrXmlHistory)
  4220. {
  4221. LOG_Block("GetFilteredHistoryBSTR()");
  4222. USES_IU_CONVERSION;
  4223. HRESULT hr = S_OK;
  4224. IXMLDOMNode* pNodeItems = NULL;
  4225. IXMLDOMNode* pNodeItem = NULL;
  4226. IXMLDOMNode* pNodeItemOut = NULL;
  4227. IXMLDOMNode* pNodeClient = NULL;
  4228. BSTR bstrTimeStamp = NULL;
  4229. BSTR bstrClientInfo = NULL;
  4230. BOOL fOutOfRange = FALSE;
  4231. HANDLE_NODELIST hNodeList = HANDLE_NODELIST_INVALID;
  4232. if (NULL == pbstrXmlHistory)
  4233. {
  4234. SetHrMsgAndGotoCleanUp(E_INVALIDARG);
  4235. }
  4236. if (NULL != m_pDocItems)
  4237. {
  4238. if (SUCCEEDED(FindSingleDOMNode(m_pDocItems, KEY_ITEMS, &pNodeItems)))
  4239. {
  4240. hNodeList = FindFirstDOMNode(pNodeItems, KEY_ITEMSTATUS, &pNodeItem);
  4241. if (HANDLE_NODELIST_INVALID != hNodeList)
  4242. {
  4243. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  4244. if (NULL != bstrTimeStamp)
  4245. {
  4246. if ((NULL != bstrBeginDateTime) && (0 != SysStringLen(bstrBeginDateTime)) &&
  4247. (CompareBSTRs(bstrTimeStamp, bstrBeginDateTime) < 0))
  4248. {
  4249. //
  4250. // remove the item whose timestamp is out of range;
  4251. // set the flag to ignore the timestamp comparison for the rest of nodes
  4252. //
  4253. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4254. fOutOfRange = TRUE;
  4255. }
  4256. else if ((NULL != bstrEndDateTime) && (0 != SysStringLen(bstrEndDateTime)) &&
  4257. (CompareBSTRs(bstrTimeStamp, bstrEndDateTime) > 0))
  4258. {
  4259. //
  4260. // remove the item whose timestamp is out of range
  4261. //
  4262. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4263. }
  4264. else
  4265. {
  4266. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClient));
  4267. CleanUpIfFailedAndSetHrMsg(GetText(pNodeClient, &bstrClientInfo));
  4268. if ((NULL != bstrClient) && (0 != SysStringLen(bstrClient)) &&
  4269. (WUCompareStringI(OLE2T(bstrClientInfo), OLE2T(bstrClient)) != CSTR_EQUAL))
  4270. {
  4271. //
  4272. // remove the item whose clieninfo does not match what we need
  4273. //
  4274. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4275. }
  4276. }
  4277. }
  4278. SafeReleaseNULL(pNodeItem);
  4279. SafeReleaseNULL(pNodeItemOut);
  4280. SafeReleaseNULL(pNodeClient);
  4281. SafeSysFreeString(bstrTimeStamp);
  4282. SafeSysFreeString(bstrClientInfo);
  4283. while (SUCCEEDED(FindNextDOMNode(hNodeList, &pNodeItem)))
  4284. {
  4285. if (fOutOfRange)
  4286. {
  4287. //
  4288. // remove the item whose timestamp is out of range
  4289. //
  4290. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4291. }
  4292. else
  4293. {
  4294. CleanUpIfFailedAndSetHrMsg(GetAttribute(pNodeItem, KEY_TIMESTAMP, &bstrTimeStamp));
  4295. if (NULL != bstrTimeStamp)
  4296. {
  4297. if ((NULL != bstrBeginDateTime) && (0 != SysStringLen(bstrBeginDateTime)) &&
  4298. (CompareBSTRs(bstrTimeStamp, bstrBeginDateTime) < 0))
  4299. {
  4300. //
  4301. // remove the item whose timestamp is out of range;
  4302. // set the flag to ignore the timestamp comparison for the rest of nodes
  4303. //
  4304. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4305. fOutOfRange = TRUE;
  4306. }
  4307. else if ((NULL != bstrEndDateTime) && (0 != SysStringLen(bstrEndDateTime)) &&
  4308. (CompareBSTRs(bstrTimeStamp, bstrEndDateTime) > 0))
  4309. {
  4310. //
  4311. // remove the item whose timestamp is out of range
  4312. //
  4313. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4314. }
  4315. else
  4316. {
  4317. CleanUpIfFailedAndSetHrMsg(FindSingleDOMNode(pNodeItem, KEY_CLIENT, &pNodeClient));
  4318. CleanUpIfFailedAndSetHrMsg(GetText(pNodeClient, &bstrClientInfo));
  4319. if ((NULL != bstrClient) && (0 != SysStringLen(bstrClient)) &&
  4320. (WUCompareStringI(OLE2T(bstrClientInfo), OLE2T(bstrClient)) != CSTR_EQUAL))
  4321. {
  4322. //
  4323. // remove the item whose clieninfo does not match what we need
  4324. //
  4325. CleanUpIfFailedAndSetHrMsg(pNodeItems->removeChild(pNodeItem, &pNodeItemOut));
  4326. }
  4327. }
  4328. }
  4329. }
  4330. SafeReleaseNULL(pNodeItem);
  4331. SafeReleaseNULL(pNodeItemOut);
  4332. SafeReleaseNULL(pNodeClient);
  4333. SafeSysFreeString(bstrTimeStamp);
  4334. SafeSysFreeString(bstrClientInfo);
  4335. }
  4336. }
  4337. }
  4338. }
  4339. CleanUp:
  4340. CloseItemList(hNodeList);
  4341. SafeReleaseNULL(pNodeItems);
  4342. SafeReleaseNULL(pNodeItem);
  4343. SafeReleaseNULL(pNodeItemOut);
  4344. SafeReleaseNULL(pNodeClient);
  4345. SysFreeString(bstrTimeStamp);
  4346. SysFreeString(bstrClientInfo);
  4347. if (SUCCEEDED(hr))
  4348. {
  4349. hr = GetItemsBSTR(pbstrXmlHistory);
  4350. }
  4351. return hr;
  4352. }
  4353. /////////////////////////////////////////////////////////////////////////////
  4354. // CXmlClientInfo
  4355. CXmlClientInfo::CXmlClientInfo()
  4356. : m_pDocClientInfo(NULL)
  4357. {
  4358. }
  4359. CXmlClientInfo::~CXmlClientInfo()
  4360. {
  4361. SafeReleaseNULL(m_pDocClientInfo);
  4362. }
  4363. //
  4364. // load and parse and validate an XML document from string
  4365. //
  4366. HRESULT CXmlClientInfo::LoadXMLDocument(BSTR bstrXml, BOOL fOfflineMode)
  4367. {
  4368. LOG_Block("CXmlClientInfo::LoadXMLDocument()");
  4369. SafeReleaseNULL(m_pDocClientInfo);
  4370. HRESULT hr = LoadXMLDoc(bstrXml, &m_pDocClientInfo, fOfflineMode);
  4371. if (FAILED(hr))
  4372. {
  4373. LOG_ErrorMsg(hr);
  4374. }
  4375. return hr;
  4376. }
  4377. //
  4378. // retrieve client name attribute
  4379. //
  4380. HRESULT CXmlClientInfo::GetClientName(BSTR* pbstrClientName)
  4381. {
  4382. HRESULT hr= E_UNEXPECTED;
  4383. IXMLDOMElement* pElement = NULL;
  4384. BSTR bstrTagName = NULL;
  4385. VARIANT vAttr;
  4386. VariantInit(&vAttr);
  4387. LOG_Block("GetClientName()");
  4388. if (NULL == pbstrClientName)
  4389. {
  4390. return E_INVALIDARG;
  4391. }
  4392. if (NULL == m_pDocClientInfo)
  4393. {
  4394. return hr;
  4395. }
  4396. hr = m_pDocClientInfo->get_documentElement(&pElement);
  4397. CleanUpIfFailedAndMsg(hr);
  4398. if (NULL == pElement)
  4399. {
  4400. //
  4401. // no root element
  4402. //
  4403. hr = E_INVALIDARG; // clientInfo is bad! return this error back to caller
  4404. LOG_ErrorMsg(hr);
  4405. goto CleanUp;
  4406. }
  4407. hr = pElement->get_tagName(&bstrTagName);
  4408. CleanUpIfFailedAndMsg(hr);
  4409. if (!CompareBSTRsEqual(bstrTagName, KEY_CLIENTINFO))
  4410. {
  4411. //
  4412. // root is not clientInfo
  4413. //
  4414. hr = E_INVALIDARG;
  4415. LOG_ErrorMsg(hr);
  4416. goto CleanUp;
  4417. }
  4418. hr = pElement->getAttribute(KEY_CLIENTNAME, &vAttr);
  4419. CleanUpIfFailedAndMsg(hr);
  4420. if (VT_BSTR == vAttr.vt)
  4421. {
  4422. *pbstrClientName = SysAllocString(vAttr.bstrVal);
  4423. }
  4424. else
  4425. {
  4426. hr = E_FAIL;
  4427. CleanUpIfFailedAndMsg(hr);
  4428. }
  4429. CleanUp:
  4430. SafeReleaseNULL(pElement);
  4431. if (bstrTagName)
  4432. {
  4433. SysFreeString(bstrTagName);
  4434. bstrTagName = NULL;
  4435. }
  4436. VariantClear(&vAttr);
  4437. return hr;
  4438. }