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.

1478 lines
50 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. pkgdesc.cpp
  5. Abstract:
  6. Functions related to package description file processing
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 07/07/99
  9. - created
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. HRESULT HCUpdate::Engine::GetNodeDepth( /*[in]*/ LPCWSTR szCategory, /*[out]*/ int& iDepth )
  14. {
  15. __HCP_FUNC_ENTRY( "HCUpdate::Engine::GetNodeDepth" );
  16. HRESULT hr;
  17. MPC::WStringVector vec;
  18. iDepth = 0;
  19. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::Settings::SplitNodePath( szCategory, vec ));
  20. iDepth = vec.size();
  21. hr = S_OK;
  22. __HCP_FUNC_CLEANUP;
  23. __HCP_FUNC_EXIT(hr);
  24. }
  25. HRESULT HCUpdate::Engine::CheckNode( /*[in] */ LPCWSTR szCategory ,
  26. /*[out]*/ bool& fExist ,
  27. /*[out]*/ bool& fCanCreate )
  28. {
  29. __HCP_FUNC_ENTRY( "HCUpdate::Engine::CheckNode" );
  30. const HRESULT hrDenied = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);
  31. HRESULT hr;
  32. Taxonomy::RS_Taxonomy* rs;
  33. fExist = false;
  34. fCanCreate = false;
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.GetTaxonomy( &rs ));
  36. //
  37. // Check if node already exists.
  38. //
  39. {
  40. long ID_node;
  41. if(SUCCEEDED(m_updater.LocateTaxonomyNode( ID_node, szCategory, false )))
  42. {
  43. //
  44. // Make sure it's owned by the same entity. Microsoft can however grab a node from an OEM.
  45. //
  46. if(IsMicrosoft() == false)
  47. {
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_Node( ID_node ));
  49. if(rs->m_ID_owner != m_updater.GetOwner())
  50. {
  51. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hrDenied, L"ERROR: node already exists" ));
  52. }
  53. }
  54. fCanCreate = true;
  55. fExist = true;
  56. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  57. }
  58. }
  59. //
  60. // Check if it is Microsoft.
  61. //
  62. if(IsMicrosoft())
  63. {
  64. fCanCreate = true;
  65. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  66. }
  67. //
  68. // Check number of nodes created already (only during normal package update).
  69. //
  70. if(m_sku)
  71. {
  72. bool fFound;
  73. bool fOwnerOfParent = false;
  74. int iCount = 0;
  75. int iLimit;
  76. int iDepth;
  77. int iMinLevel;
  78. long ID_parent;
  79. __MPC_EXIT_IF_METHOD_FAILS(hr, GetNodeDepth( szCategory, iDepth ));
  80. //
  81. // Get the parent node
  82. //
  83. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.LocateTaxonomyNode( ID_parent, szCategory, true ));
  84. //
  85. // Check if node is to be created as a child of a node of the same owner.
  86. //
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_Node( ID_parent ));
  88. if(rs->m_ID_owner == m_updater.GetOwner())
  89. {
  90. fOwnerOfParent = true;
  91. }
  92. ////////////////////
  93. if(m_sku->m_inst.m_fServer)
  94. {
  95. //
  96. // Mininum level of insertion: 3 (2 for OEM)
  97. //
  98. // Top-level nodes: only one per OEM, nothing for NTCC.
  99. // Other nodes : any number for OEM and NTCC owning the parent, 1 otherwise.
  100. //
  101. iMinLevel = m_updater.IsOEM() ? 2 : 3;
  102. switch(iDepth)
  103. {
  104. case 0:
  105. case 1:
  106. iLimit = 0;
  107. break;
  108. case 2:
  109. if(m_updater.IsOEM())
  110. {
  111. iLimit = 1;
  112. }
  113. else
  114. {
  115. iLimit = 0;
  116. }
  117. break;
  118. default:
  119. if(m_updater.IsOEM() || fOwnerOfParent)
  120. {
  121. iLimit = -1;
  122. }
  123. else
  124. {
  125. iLimit = 1;
  126. }
  127. break;
  128. }
  129. }
  130. if(m_sku->m_inst.m_fDesktop)
  131. {
  132. //
  133. // Mininum level of insertion: 4 (2 for OEM)
  134. //
  135. // Top-level nodes : only one per OEM, nothing for NTCC.
  136. // Second-level nodes: 3 nodes per OEM, nothing for NTCC.
  137. // Other nodes : any number for OEM and NTCC owning the parent, 1 otherwise.
  138. //
  139. iMinLevel = m_updater.IsOEM() ? 2 : 4;
  140. switch(iDepth)
  141. {
  142. case 0:
  143. case 1:
  144. iLimit = 0;
  145. break;
  146. case 2:
  147. if(m_updater.IsOEM())
  148. {
  149. iLimit = 1;
  150. }
  151. else
  152. {
  153. iLimit = 0;
  154. }
  155. break;
  156. case 3:
  157. if(m_updater.IsOEM())
  158. {
  159. iLimit = 3;
  160. }
  161. else
  162. {
  163. iLimit = 0;
  164. }
  165. break;
  166. default:
  167. if(m_updater.IsOEM() || fOwnerOfParent)
  168. {
  169. iLimit = -1;
  170. }
  171. else
  172. {
  173. iLimit = 1;
  174. }
  175. break;
  176. }
  177. }
  178. if(iDepth < iMinLevel)
  179. {
  180. LPCWSTR szSuffix;
  181. switch(iMinLevel)
  182. {
  183. case 1 : szSuffix = L"st"; break;
  184. case 2 : szSuffix = L"nd"; break;
  185. case 3 : szSuffix = L"rd"; break;
  186. default: szSuffix = L"th"; break;
  187. }
  188. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hrDenied,
  189. L"ERROR: Nodes can only be created starting from the %d%s level down for %s SKUs",
  190. iMinLevel, szSuffix, m_sku->m_inst.m_fServer ? L"SERVER" : L"DESKTOP" ));
  191. }
  192. if(iLimit > 0)
  193. {
  194. //
  195. // Count number of nodes at the same level.
  196. //
  197. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_Children( ID_parent, &fFound ));
  198. while(fFound)
  199. {
  200. if(rs->m_ID_owner == m_updater.GetOwner())
  201. {
  202. iCount++;
  203. }
  204. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Move( 0, JET_MoveNext, &fFound ));
  205. }
  206. if(iCount >= iLimit)
  207. {
  208. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hrDenied, L"ERROR: allowed number of nodes (%d) to be created exceeded", iLimit ));
  209. }
  210. }
  211. if(iLimit == 0)
  212. {
  213. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hrDenied, L"ERROR: the current Vendor privileges don't allow the creation of such a node" ));
  214. }
  215. fCanCreate = true;
  216. }
  217. hr = S_OK;
  218. __HCP_FUNC_CLEANUP;
  219. __HCP_FUNC_EXIT(hr);
  220. }
  221. HRESULT HCUpdate::Engine::CheckTopic( /*[in]*/ long ID_node ,
  222. /*[in]*/ LPCWSTR szURI ,
  223. /*[in]*/ LPCWSTR szCategory )
  224. {
  225. __HCP_FUNC_ENTRY( "HCUpdate::Engine::CheckTopic" );
  226. HRESULT hr;
  227. Taxonomy::RS_Taxonomy* rsTaxonomy;
  228. Taxonomy::RS_Topics* rsTopics;
  229. //
  230. // Check if URI is empty
  231. //
  232. if(!STRINGISPRESENT(szURI))
  233. {
  234. //
  235. // BUGBUG: Production tool doesn't check for this and the currently checked-in HHTs break...
  236. //
  237. if(m_fCreationMode == false)
  238. {
  239. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"ERROR: URI cannot be empty" ));
  240. }
  241. }
  242. //
  243. // Check if it is Microsoft or OEM
  244. //
  245. if(IsMicrosoft() || m_updater.IsOEM())
  246. {
  247. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  248. }
  249. if(m_sku)
  250. {
  251. //
  252. // Check if parent node owner is same
  253. //
  254. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.GetTaxonomy( &rsTaxonomy ));
  255. __MPC_EXIT_IF_METHOD_FAILS(hr, rsTaxonomy->Seek_Node( ID_node ));
  256. if(rsTaxonomy->m_ID_owner != m_updater.GetOwner())
  257. {
  258. bool fFound;
  259. int iDepth;
  260. int iCount = 0;
  261. //
  262. // If not the same owner, then we have to check if another topic exists with the same owner
  263. //
  264. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.GetTopics( &rsTopics ));
  265. __MPC_EXIT_IF_METHOD_FAILS(hr, rsTopics->Seek_TopicsUnderNode( ID_node, &fFound ));
  266. while(fFound && rsTopics->m_ID_node == ID_node)
  267. {
  268. //
  269. // If the topic owner is the same, see if it is an update
  270. // If it is not, then we cannot add anymore since each CC can only have one topic in each node
  271. //
  272. if(rsTopics->m_ID_owner == m_updater.GetOwner())
  273. {
  274. //
  275. // Count if it is not an update
  276. //
  277. if(MPC::StrICmp( rsTopics->m_strURI, szURI ) != 0)
  278. {
  279. iCount++;
  280. }
  281. }
  282. __MPC_EXIT_IF_METHOD_FAILS(hr, rsTopics->Move( 0, JET_MoveNext, &fFound ));
  283. }
  284. if(iCount > 0)
  285. {
  286. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"ERROR: allowed number of topics to be created exceeded" ));
  287. }
  288. //
  289. // Check the depth/level of the node being inserted
  290. //
  291. __MPC_EXIT_IF_METHOD_FAILS(hr, GetNodeDepth( szCategory, iDepth ));
  292. if(m_sku->m_inst.m_fServer && iDepth <= 2)
  293. {
  294. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"ERROR: Topics can only be added starting from the 2nd level down for SERVER SKUs" ));
  295. }
  296. if(m_sku->m_inst.m_fDesktop && iDepth <= 3)
  297. {
  298. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"ERROR: Topics can only be added starting from the 3nd level down for DESKTOP SKUs" ));
  299. }
  300. }
  301. }
  302. hr = S_OK;
  303. __HCP_FUNC_CLEANUP;
  304. __HCP_FUNC_EXIT(hr);
  305. }
  306. ////////////////////////////////////////////////////////////////////////////////
  307. HRESULT HCUpdate::Engine::InsertNode( /*[in]*/ Action idAction ,
  308. /*[in]*/ LPCWSTR szCategory ,
  309. /*[in]*/ LPCWSTR szEntry ,
  310. /*[in]*/ LPCWSTR szTitle ,
  311. /*[in]*/ LPCWSTR szDescription ,
  312. /*[in]*/ LPCWSTR szURI ,
  313. /*[in]*/ LPCWSTR szIconURI ,
  314. /*[in]*/ bool fVisible ,
  315. /*[in]*/ bool fSubsite ,
  316. /*[in]*/ long lNavModel ,
  317. /*[in]*/ long lPos )
  318. {
  319. __HCP_FUNC_ENTRY( "HCUpdate::Engine::InsertNode" );
  320. HRESULT hr;
  321. MPC::wstring strFullNode;
  322. bool fExists;
  323. bool fCanCreate;
  324. WriteLog( S_OK, L"Inserting Node '%s' into Category '%s'", szEntry, szCategory );
  325. //
  326. // Create full path for the new node.
  327. //
  328. if(szCategory && szCategory[0])
  329. {
  330. strFullNode = szCategory;
  331. strFullNode += L"/";
  332. }
  333. strFullNode += szEntry;
  334. //
  335. // Check if can insert node
  336. //
  337. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckNode( strFullNode.c_str(), fExists, fCanCreate ));
  338. if(fCanCreate)
  339. {
  340. long ID_node;
  341. //
  342. // Get the parent node.
  343. //
  344. if(FAILED(hr = m_updater.LocateTaxonomyNode( ID_node, strFullNode.c_str(), true )))
  345. {
  346. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error cannot obtain parent title to insert node: %s", strFullNode.c_str() ));
  347. }
  348. //
  349. // Create node.
  350. //
  351. if(FAILED(hr = m_updater.CreateTaxonomyNode( ID_node, strFullNode.c_str(), szTitle, szDescription, szURI, szIconURI, fVisible, fSubsite, lNavModel, lPos )))
  352. {
  353. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error inserting Node: %s", strFullNode.c_str() ));
  354. }
  355. }
  356. hr = S_OK;
  357. __HCP_FUNC_CLEANUP;
  358. __HCP_FUNC_EXIT(hr);
  359. }
  360. HRESULT HCUpdate::Engine::InsertTaxonomy( /*[in]*/ MPC::XmlUtil& oXMLUtil ,
  361. /*[in]*/ IXMLDOMNode* poNode )
  362. {
  363. __HCP_FUNC_ENTRY( "HCUpdate::Engine::InsertTaxonomy" );
  364. HRESULT hr;
  365. bool fFound;
  366. WCHAR rgURI [MAX_PATH];
  367. WCHAR rgIconURI[MAX_PATH];
  368. Action idAction;
  369. MPC::wstring strAction;
  370. MPC::wstring strCategory;
  371. MPC::wstring strEntry;
  372. MPC::wstring strURI;
  373. MPC::wstring strIconURI;
  374. MPC::wstring strTitle;
  375. MPC::wstring strDescription;
  376. MPC::wstring strVisible;
  377. MPC::wstring strSubsite;
  378. MPC::wstring strNavModel;
  379. MPC::wstring strInsertMode;
  380. MPC::wstring strInsertLocation;
  381. long lType = 1;
  382. long lPos = -1;
  383. bool fVisible = true;
  384. bool fSubsite = false;
  385. long lNavModel = QR_DEFAULT;
  386. long ID_node = -1;
  387. long ID_topic = -1;
  388. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode);
  389. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_TAXONOMY_CATEGORY , strCategory , fFound, poNode);
  390. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_ENTRY , strEntry , fFound, poNode);
  391. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_URI , strURI , fFound, poNode);
  392. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_ICONURI , strIconURI , fFound, poNode);
  393. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_TAXONOMY_TITLE , strTitle , fFound, poNode);
  394. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_DESCRIPTION , strDescription , fFound, poNode);
  395. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_TYPE , lType , fFound, poNode);
  396. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_VISIBLE , strVisible , fFound, poNode);
  397. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_SUBSITE , strSubsite , fFound, poNode);
  398. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_NAVMODEL , strNavModel , fFound, poNode);
  399. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_INSERTMODE , strInsertMode , fFound, poNode);
  400. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_TAXONOMY_INSERTLOCATION, strInsertLocation, fFound, poNode);
  401. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction ( strAction .c_str(), idAction ));
  402. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupBoolean ( strVisible .c_str(), fVisible , true ));
  403. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupBoolean ( strSubsite .c_str(), fSubsite , false ));
  404. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupNavModel( strNavModel.c_str(), lNavModel, QR_DEFAULT ));
  405. {
  406. int pos;
  407. //
  408. // Remove trailing slashes.
  409. //
  410. pos = strCategory.size() - 1;
  411. while(pos >= 0 && strCategory[pos] == '/')
  412. {
  413. strCategory.erase( pos--, 1 );
  414. }
  415. //
  416. // Remove double slashes.
  417. //
  418. pos = strCategory.size() - 1;
  419. while(pos > 0)
  420. {
  421. if(strCategory[pos] == '/' && strCategory[pos-1] == '/')
  422. {
  423. strCategory.erase( pos, 1 );
  424. }
  425. pos--;
  426. }
  427. }
  428. // <NODE NodeType="Group" Key="1" Title="Help &amp; Information:"/>
  429. // <NODE NodeType="Group" Key="2" Title="Common Questions:"/>
  430. // <NODE NodeType="Group" Key="3" Title="Troubleshooting:"/>
  431. // <NODE NodeType="Group" Key="4" Title="Technical Resources:"/>
  432. // <NODE NodeType="Group" Key="5" Title="Tours &amp; Tutorials:"/>
  433. // <NODE NodeType="Group" Key="6" Title="Help Files:"/>
  434. // <NODE NodeType="Group" Key="7" Title="Fix a problem:"/>
  435. // <NODE NodeType="Group" Key="8" Title="Pick a task:"/>
  436. // <NODE NodeType="Group" Key="9" Title="Overviews, Articles, and Tutorials:"/>
  437. // <NODE NodeType="Group" Key="10" Title="References:"/>
  438. if(lType < 1 || lType > 10)
  439. {
  440. lType = 1;
  441. }
  442. //
  443. // Get the complete URLs for the link.
  444. //
  445. if(strURI.size())
  446. {
  447. AppendVendorDir( strURI.c_str(), m_pkg->m_strVendorID.c_str(), NULL, rgURI, MAXSTRLEN(rgURI) );
  448. }
  449. else
  450. {
  451. rgURI[0] = 0;
  452. }
  453. if(strIconURI.size())
  454. {
  455. AppendVendorDir( strIconURI.c_str(), m_pkg->m_strVendorID.c_str(), NULL, rgIconURI, MAXSTRLEN(rgIconURI) );
  456. }
  457. else
  458. {
  459. rgIconURI[0] = 0;
  460. }
  461. if(FAILED(m_updater.LocateTaxonomyNode( ID_node, strCategory.c_str(), /*fLookForFather*/false )))
  462. {
  463. if(idAction == ACTION_ADD)
  464. {
  465. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"Error category '%s' does not exist", strCategory.c_str() ));
  466. }
  467. else
  468. {
  469. WriteLog( S_OK, L"Category not found. Skipping deletion..." );
  470. }
  471. }
  472. if(idAction == ACTION_ADD)
  473. {
  474. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.MakeRoomForInsert( strCategory.c_str(), strInsertMode.c_str(), strInsertLocation.c_str(), lPos ));
  475. }
  476. //
  477. // Check if inserting nodes
  478. //
  479. if(strEntry.empty() == false)
  480. {
  481. if(idAction == ACTION_ADD)
  482. {
  483. __MPC_EXIT_IF_METHOD_FAILS(hr, InsertNode( idAction ,
  484. strCategory .c_str() ,
  485. strEntry .c_str() ,
  486. strTitle .c_str() ,
  487. strDescription.c_str() ,
  488. rgURI ,
  489. rgIconURI ,
  490. fVisible ,
  491. fSubsite ,
  492. lNavModel ,
  493. lPos ));
  494. }
  495. else if(idAction == ACTION_DELETE)
  496. {
  497. MPC::wstring strFull( strCategory );
  498. if(strFull.size())
  499. {
  500. if(strEntry.size())
  501. {
  502. strFull += L"/";
  503. strFull += strEntry;
  504. }
  505. }
  506. else
  507. {
  508. strFull = strEntry;
  509. }
  510. WriteLog( S_OK, L"Deleting Node '%s' from Category '%s'", strEntry.c_str(), strCategory.c_str() );
  511. if(SUCCEEDED(m_updater.LocateTaxonomyNode( ID_node, strFull.c_str(), /*fLookForFather*/false )))
  512. {
  513. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.DeleteTaxonomyNode( ID_node ));
  514. }
  515. }
  516. }
  517. else
  518. {
  519. WriteLog( S_OK, L"Processing Taxonomy entry : Category : %s, URI : %s, Title : %s, Desc : %s", strCategory.c_str(), rgURI, strTitle.c_str(), strDescription.c_str() );
  520. if(idAction == ACTION_ADD)
  521. {
  522. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckTopic(ID_node, rgURI, strCategory.c_str()));
  523. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.CreateTopicEntry( ID_topic ,
  524. ID_node ,
  525. strTitle .c_str() ,
  526. rgURI ,
  527. strDescription.c_str() ,
  528. rgIconURI ,
  529. lType ,
  530. fVisible ,
  531. lPos ));
  532. //
  533. // Retrieve all the keywords and insert them into table
  534. //
  535. {
  536. CComPtr<IXMLDOMNodeList> poKeywordNodeList;
  537. //
  538. // Get all the keyword tags
  539. //
  540. if(FAILED(hr = poNode->selectNodes( CComBSTR(PCH_XQL_TOPIC_KEYWORDS), &poKeywordNodeList)))
  541. {
  542. PCH_MACRO_DEBUG( L"Error querying taxonomy nodes in HHT file" );
  543. }
  544. else if(poKeywordNodeList)
  545. {
  546. CComPtr<IXMLDOMNode> poKeywordNode;
  547. //
  548. // Process all the nodes.
  549. //
  550. for(;SUCCEEDED(hr = poKeywordNodeList->nextNode( &poKeywordNode )) && poKeywordNode != NULL; poKeywordNode.Release())
  551. {
  552. MPC::wstring strKeyword;
  553. PCH_MACRO_CHECK_ABORT(hr);
  554. //
  555. // Get the value from the XML keyword tag.
  556. //
  557. if(FAILED(hr = oXMLUtil.GetValue( NULL, strKeyword, fFound, poKeywordNode )) || fFound == false)
  558. {
  559. PCH_MACRO_DEBUG( L"Error getting keyword value" );
  560. }
  561. else
  562. {
  563. MPC::WStringList lst;
  564. MPC::WStringIter it;
  565. MPC::wstring strHHK;
  566. bool fHHK;
  567. long lPriority;
  568. //
  569. // Get the optional attribute.
  570. //
  571. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_KEYWORD_HHK, strHHK, fFound, poKeywordNode);
  572. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupBoolean( strHHK.c_str(), fHHK, true ));
  573. //
  574. // Non-trusted certificates aren't allowed to set the priority of a match.
  575. //
  576. if(IsMicrosoft() == false && m_updater.IsOEM() == false) lPriority = 0;
  577. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_KEYWORD_PRIORITY, lPriority, fFound, poKeywordNode);
  578. //
  579. // Look up for synonyms (Microsoft updates only use Microsoft synsets).
  580. //
  581. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.LocateSynonyms( strKeyword.c_str(), lst, /*fMatchOwner*/IsMicrosoft() ));
  582. if(lst.size() == 0 || lPriority != 0)
  583. {
  584. if(FAILED(hr = m_updater.CreateMatch( strKeyword.c_str(), ID_topic, lPriority, fHHK )))
  585. {
  586. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error updating keyword in database: %s", strKeyword.c_str() ));
  587. }
  588. }
  589. for(it=lst.begin(); it!=lst.end(); it++)
  590. {
  591. if(FAILED(hr = m_updater.CreateMatch( it->c_str(), ID_topic, 0, fHHK )))
  592. {
  593. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error updating keyword in database: %s", strKeyword.c_str() ));
  594. }
  595. }
  596. }
  597. }
  598. }
  599. }
  600. }
  601. else if(idAction == ACTION_DELETE)
  602. {
  603. if(ID_node != -1 && SUCCEEDED(m_updater.LocateTopicEntry( ID_topic, ID_node, rgURI, /*fCheckOwner*/true )))
  604. {
  605. if(FAILED(hr = m_updater.DeleteTopicEntry( ID_topic )))
  606. {
  607. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error attempting to remove node: %s", rgURI ));
  608. }
  609. }
  610. else
  611. {
  612. WriteLog( S_OK, L"Topic not found. Nothing to delete..." );
  613. }
  614. }
  615. }
  616. hr = S_OK;
  617. __HCP_FUNC_CLEANUP;
  618. __HCP_FUNC_EXIT(hr);
  619. }
  620. ////////////////////////////////////////////////////////////////////////////////
  621. HRESULT HCUpdate::Engine::UpdateStopSign( /*[in]*/ Action idAction, /*[in]*/ const MPC::wstring& strContext, /*[in]*/ const MPC::wstring& strStopSign )
  622. {
  623. __HCP_FUNC_ENTRY( "HCUpdate::Engine::UpdateStopSign" );
  624. HRESULT hr;
  625. Taxonomy::Updater_Set id;
  626. //
  627. // Check if stop sign is only a single character
  628. //
  629. if(strStopSign.size () != 1 ||
  630. strContext .empty() )
  631. {
  632. __MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
  633. }
  634. id = (MPC::StrICmp( strContext, L"ENDOFWORD" ) == 0) ? Taxonomy::UPDATER_SET_STOPSIGNS_ATENDOFWORD : Taxonomy::UPDATER_SET_STOPSIGNS;
  635. switch(idAction)
  636. {
  637. case ACTION_ADD : __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddWordToSet ( id, strStopSign.c_str() )); break;
  638. case ACTION_DELETE: __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveWordFromSet( id, strStopSign.c_str() )); break;
  639. }
  640. hr = S_OK;
  641. __HCP_FUNC_CLEANUP;
  642. __HCP_FUNC_EXIT(hr);
  643. }
  644. HRESULT HCUpdate::Engine::UpdateStopWord( /*[in]*/ Action idAction, /*[in]*/ const MPC::wstring& strStopWord )
  645. {
  646. __HCP_FUNC_ENTRY( "HCUpdate::Engine::UpdateStopWord" );
  647. HRESULT hr;
  648. //
  649. // Check parameters
  650. //
  651. if(strStopWord.empty())
  652. {
  653. __MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
  654. }
  655. switch(idAction)
  656. {
  657. case ACTION_ADD : __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddWordToSet ( Taxonomy::UPDATER_SET_STOPWORDS, strStopWord.c_str() )); break;
  658. case ACTION_DELETE: __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveWordFromSet( Taxonomy::UPDATER_SET_STOPWORDS, strStopWord.c_str() )); break;
  659. }
  660. hr = S_OK;
  661. __HCP_FUNC_CLEANUP;
  662. __HCP_FUNC_EXIT(hr);
  663. }
  664. HRESULT HCUpdate::Engine::UpdateOperator( /*[in]*/ Action idAction, /*[in]*/ const MPC::wstring& strOperator, /*[in]*/ const MPC::wstring& strOperation )
  665. {
  666. __HCP_FUNC_ENTRY( "HCUpdate::Engine::UpdateOperator" );
  667. HRESULT hr;
  668. Taxonomy::Updater_Set id;
  669. //
  670. // Check parameters
  671. //
  672. if(strOperator .empty() ||
  673. strOperation.empty() )
  674. {
  675. __MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
  676. }
  677. {
  678. LPCWSTR szOperation = strOperation.c_str();
  679. if(_wcsicmp( szOperation, L"AND" ) == 0)
  680. {
  681. id = Taxonomy::UPDATER_SET_OPERATOR_AND;
  682. }
  683. else if(_wcsicmp( szOperation, L"OR" ) == 0)
  684. {
  685. id = Taxonomy::UPDATER_SET_OPERATOR_OR;
  686. }
  687. else if(_wcsicmp( szOperation, L"NOT" ) == 0)
  688. {
  689. id = Taxonomy::UPDATER_SET_OPERATOR_NOT;
  690. }
  691. else
  692. {
  693. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  694. }
  695. }
  696. switch(idAction)
  697. {
  698. case ACTION_ADD : __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddWordToSet ( id, strOperator.c_str() )); break;
  699. case ACTION_DELETE: __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveWordFromSet( id, strOperator.c_str() )); break;
  700. }
  701. hr = S_OK;
  702. __HCP_FUNC_CLEANUP;
  703. __HCP_FUNC_EXIT(hr);
  704. }
  705. ////////////////////////////////////////////////////////////////////////////////
  706. ////////////////////////////////////////////////////////////////////////////////
  707. ////////////////////////////////////////////////////////////////////////////////
  708. /*****************************************************************************
  709. *
  710. * FUNCTION : ProcessHHTFile
  711. *
  712. * DESCRIPTION : Processes the HHT file in the following manner :
  713. * 1. Extract the HHT information from XML data blob
  714. * 2. Check to see what action to take
  715. * 3. If adding a HHT entry :
  716. * a. Check to see if TopicURL is a URI
  717. * b. If URL, insert as is
  718. * c. if not URI append vendor's dir as prefix
  719. * d. Insert HHT entry into Topic table
  720. * e. Get the OID and insert all keywords into keyword table
  721. * 4. If deleting a HHT entry :
  722. * a. Check if entry exists by getting OID
  723. * b. If exists, delete HHT entry using OID
  724. * c. Delete all corresponding keywords using OID
  725. *
  726. * INPUTS :
  727. *
  728. * RETURNS :
  729. *
  730. * COMMENTS :
  731. *
  732. *****************************************************************************/
  733. HRESULT HCUpdate::Engine::ProcessHHTFile( /*[in]*/ LPCWSTR szHHTName ,
  734. /*[in]*/ MPC::XmlUtil& oXMLUtil )
  735. {
  736. __HCP_FUNC_ENTRY( "HCUpdate::Engine::ProcessHHTFile" );
  737. HRESULT hr;
  738. bool fFound;
  739. WriteLog( S_OK, L"Processing HHT file: %s", szHHTName );
  740. ////////////////////////////////////////////////////////////////////////////////
  741. //
  742. // Update SCOPE sections
  743. //
  744. {
  745. CComPtr<IXMLDOMNodeList> poNodeList;
  746. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_SCOPES, &poNodeList )))
  747. {
  748. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  749. }
  750. else if(CountNodes(poNodeList) > 0)
  751. {
  752. JetBlue::TransactionHandle transaction;
  753. CComPtr<IXMLDOMNode> poNode;
  754. Action idAction;
  755. MPC::wstring strAction;
  756. MPC::wstring strID;
  757. MPC::wstring strName;
  758. MPC::wstring strCategory;
  759. long ID_scope;
  760. long ID_owner;
  761. //
  762. // Process all the nodes.
  763. //
  764. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  765. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  766. {
  767. PCH_MACRO_CHECK_ABORT(hr);
  768. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  769. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_SCOPE_ID , strID , fFound, poNode );
  770. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_SCOPE_NAME , strName , fFound, poNode );
  771. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_SCOPE_CATEGORY, strCategory, fFound, poNode );
  772. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  773. WriteLog( S_OK, L"Processing Scope : %s : ID : %s, Category : %s", s_ActionText[idAction], strID.c_str(), strCategory.c_str() );
  774. //
  775. // Check if it is adding helpfiles
  776. //
  777. if(idAction == ACTION_ADD)
  778. {
  779. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.CreateScope( ID_scope, strID.c_str(), strName.c_str(), strCategory.c_str() ));
  780. }
  781. else if(idAction == ACTION_DELETE)
  782. {
  783. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.LocateScope( ID_scope, ID_owner, strID.c_str() ));
  784. if(ID_scope != -1)
  785. {
  786. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveScope( ID_scope ));
  787. }
  788. }
  789. m_fRecreateIndex = true;
  790. }
  791. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  792. }
  793. }
  794. ////////////////////////////////////////////////////////////////////////////////
  795. //
  796. // Update FTS files
  797. //
  798. {
  799. CComPtr<IXMLDOMNodeList> poNodeList;
  800. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_FTS, &poNodeList )))
  801. {
  802. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  803. }
  804. else if(CountNodes(poNodeList) > 0)
  805. {
  806. JetBlue::TransactionHandle transaction;
  807. CComPtr<IXMLDOMNode> poNode;
  808. Action idAction;
  809. MPC::wstring strAction;
  810. MPC::wstring strCHMname;
  811. MPC::wstring strCHQname;
  812. MPC::wstring strScope;
  813. long ID_scope;
  814. long ID_owner;
  815. //
  816. // Process all the nodes.
  817. //
  818. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  819. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  820. {
  821. PCH_MACRO_CHECK_ABORT(hr);
  822. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  823. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_HELPFILE_CHM , strCHMname, fFound, poNode );
  824. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_CHQ , strCHQname, fFound, poNode );
  825. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_SCOPE, strScope , fFound, poNode ); if(!fFound) strScope = PCH_STR_SCOPE_DEFAULT;
  826. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  827. WriteLog( S_OK, L"Processing Full Text Search : %s : CHM : %s, CHQ : %s", s_ActionText[idAction], strCHMname.c_str(), strCHQname.c_str() );
  828. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.LocateScope( ID_scope, ID_owner, strScope.c_str() ));
  829. //
  830. // Check if it is adding helpfiles
  831. //
  832. if(idAction == ACTION_ADD)
  833. {
  834. if(ID_scope == -1)
  835. {
  836. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"Error scope '%s' does not exist", strScope.c_str() ));
  837. }
  838. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddFullTextSearchQuery( ID_scope, strCHMname.c_str(), strCHQname.c_str() ));
  839. }
  840. else if(idAction == ACTION_DELETE)
  841. {
  842. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveFullTextSearchQuery( ID_scope, strCHMname.c_str() ));
  843. }
  844. m_fRecreateIndex = true;
  845. }
  846. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  847. }
  848. }
  849. ////////////////////////////////////////////////////////////////////////////////
  850. //
  851. // Update HHK files
  852. //
  853. {
  854. CComPtr<IXMLDOMNodeList> poNodeList;
  855. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_INDEX, &poNodeList )))
  856. {
  857. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  858. }
  859. else if(CountNodes(poNodeList) > 0)
  860. {
  861. JetBlue::TransactionHandle transaction;
  862. CComPtr<IXMLDOMNode> poNode;
  863. Action idAction;
  864. MPC::wstring strAction;
  865. MPC::wstring strCHMname;
  866. MPC::wstring strHHKname;
  867. MPC::wstring strScope;
  868. long ID_scope;
  869. long ID_owner;
  870. //
  871. // Process all the nodes.
  872. //
  873. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  874. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  875. {
  876. PCH_MACRO_CHECK_ABORT(hr);
  877. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  878. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_HELPFILE_CHM , strCHMname, fFound, poNode );
  879. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_HELPFILE_HHK , strHHKname, fFound, poNode );
  880. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_SCOPE, strScope , fFound, poNode ); if(!fFound) strScope = PCH_STR_SCOPE_DEFAULT;
  881. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  882. WriteLog( S_OK, L"Processing Index : %s : CHM : %s, HHK : %s", s_ActionText[idAction], strCHMname.c_str(), strHHKname.c_str() );
  883. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.LocateScope( ID_scope, ID_owner, strScope.c_str() ));
  884. //
  885. // Check if it is adding helpfiles
  886. //
  887. if(idAction == ACTION_ADD)
  888. {
  889. if(ID_scope == -1)
  890. {
  891. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), L"Error scope '%s' does not exist", strScope.c_str() ));
  892. }
  893. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddIndexFile( ID_scope, strCHMname.c_str(), strHHKname.c_str() ));
  894. }
  895. else if(idAction == ACTION_DELETE)
  896. {
  897. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveIndexFile( ID_scope, strCHMname.c_str(), strHHKname.c_str() ));
  898. }
  899. m_fRecreateIndex = true;
  900. }
  901. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  902. }
  903. }
  904. ////////////////////////////////////////////////////////////////////////////////
  905. //
  906. // Update files for the Help Image.
  907. //
  908. {
  909. CComPtr<IXMLDOMNodeList> poNodeList;
  910. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_HELPIMAGE, &poNodeList )))
  911. {
  912. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  913. }
  914. else if(CountNodes(poNodeList) > 0)
  915. {
  916. JetBlue::TransactionHandle transaction;
  917. CComPtr<IXMLDOMNode> poNode;
  918. Action idAction;
  919. MPC::wstring strAction;
  920. MPC::wstring strCHMname;
  921. MPC::wstring strCHQname;
  922. MPC::wstring strOTHname;
  923. //
  924. // Process all the nodes.
  925. //
  926. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  927. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  928. {
  929. PCH_MACRO_CHECK_ABORT(hr);
  930. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  931. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_CHM , strCHMname, fFound, poNode );
  932. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_CHQ , strCHQname, fFound, poNode );
  933. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_HELPFILE_OTHER, strOTHname, fFound, poNode );
  934. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  935. WriteLog( S_OK, L"Processing HelpImage : %s : CHM : %s, CHQ : %s, OTHER : %s", s_ActionText[idAction], strCHMname.c_str(), strCHQname.c_str(), strOTHname.c_str() );
  936. //
  937. // Check if it is adding helpfiles
  938. //
  939. if(idAction == ACTION_ADD)
  940. {
  941. if(strCHMname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddFile( strCHMname.c_str() )); }
  942. if(strCHQname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddFile( strCHQname.c_str() )); }
  943. if(strOTHname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.AddFile( strOTHname.c_str() )); }
  944. }
  945. else if(idAction == ACTION_DELETE)
  946. {
  947. if(strCHMname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveFile( strCHMname.c_str() )); }
  948. if(strCHQname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveFile( strCHQname.c_str() )); }
  949. if(strOTHname.size()) { __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.RemoveFile( strOTHname.c_str() )); }
  950. }
  951. }
  952. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  953. }
  954. }
  955. ////////////////////////////////////////////////////////////////////////////////
  956. //
  957. // Update StopSigns
  958. //
  959. if(IsMicrosoft())
  960. {
  961. CComPtr<IXMLDOMNodeList> poNodeList;
  962. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_STOPSIGN, &poNodeList )))
  963. {
  964. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  965. }
  966. else if(CountNodes(poNodeList) > 0)
  967. {
  968. JetBlue::TransactionHandle transaction;
  969. CComPtr<IXMLDOMNode> poNode;
  970. Action idAction;
  971. MPC::wstring strAction;
  972. MPC::wstring strContext;
  973. MPC::wstring strStopSign;
  974. //
  975. // Process all the nodes.
  976. //
  977. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  978. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  979. {
  980. PCH_MACRO_CHECK_ABORT(hr);
  981. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  982. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_STOPSIGN_CONTEXT , strContext , fFound, poNode );
  983. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_STOPSIGN_STOPSIGN, strStopSign, fFound, poNode );
  984. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  985. WriteLog( S_OK, L"Processing StopSign : %s : StopSign : %s, Context : %s", s_ActionText[idAction], strStopSign.c_str(), strContext.c_str() );
  986. __MPC_EXIT_IF_METHOD_FAILS(hr, UpdateStopSign( idAction, strContext, strStopSign ));
  987. }
  988. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  989. }
  990. }
  991. ////////////////////////////////////////////////////////////////////////////////
  992. //
  993. // Update StopWords
  994. //
  995. if(IsMicrosoft())
  996. {
  997. CComPtr<IXMLDOMNodeList> poNodeList;
  998. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_STOPWORD, &poNodeList )))
  999. {
  1000. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  1001. }
  1002. else if(CountNodes(poNodeList) > 0)
  1003. {
  1004. JetBlue::TransactionHandle transaction;
  1005. CComPtr<IXMLDOMNode> poNode;
  1006. Action idAction;
  1007. MPC::wstring strAction;
  1008. MPC::wstring strStopSign;
  1009. //
  1010. // Process all the nodes.
  1011. //
  1012. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  1013. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  1014. {
  1015. PCH_MACRO_CHECK_ABORT(hr);
  1016. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  1017. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_STOPWORD_STOPWORD, strStopSign, fFound, poNode );
  1018. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  1019. WriteLog( S_OK, L"Processing StopWord : %s : StopWord : %s", s_ActionText[idAction], strStopSign.c_str() );
  1020. __MPC_EXIT_IF_METHOD_FAILS(hr, UpdateStopWord( idAction, strStopSign ));
  1021. }
  1022. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  1023. }
  1024. }
  1025. ////////////////////////////////////////////////////////////////////////////////
  1026. //
  1027. // Update Operator
  1028. //
  1029. if(IsMicrosoft())
  1030. {
  1031. CComPtr<IXMLDOMNodeList> poNodeList;
  1032. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_OPERATOR, &poNodeList )))
  1033. {
  1034. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  1035. }
  1036. else if(CountNodes(poNodeList) > 0)
  1037. {
  1038. JetBlue::TransactionHandle transaction;
  1039. CComPtr<IXMLDOMNode> poNode;
  1040. Action idAction;
  1041. MPC::wstring strAction;
  1042. MPC::wstring strOperator;
  1043. MPC::wstring strOperation;
  1044. //
  1045. // Process all the nodes.
  1046. //
  1047. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  1048. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  1049. {
  1050. PCH_MACRO_CHECK_ABORT(hr);
  1051. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode);
  1052. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_OPERATOR_OPERATION, strOperation, fFound, poNode);
  1053. HCUPDATE_GETATTRIBUTE(hr, oXMLUtil, PCH_TAG_OPERATOR_OPERATOR , strOperator , fFound, poNode);
  1054. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  1055. WriteLog( S_OK, L"Processing Operator : %s : Operator : %s, Operation : %s", s_ActionText[idAction], strOperator.c_str(), strOperation.c_str() );
  1056. __MPC_EXIT_IF_METHOD_FAILS(hr, UpdateOperator( idAction, strOperator, strOperation ));
  1057. }
  1058. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  1059. }
  1060. }
  1061. ////////////////////////////////////////////////////////////////////////////////
  1062. //
  1063. // Update SYNTABLE sections
  1064. //
  1065. {
  1066. CComPtr<IXMLDOMNodeList> poNodeList;
  1067. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_SYNSET, &poNodeList )))
  1068. {
  1069. PCH_MACRO_DEBUG( L"Error processing package_description xml" );
  1070. }
  1071. else if(CountNodes(poNodeList) > 0)
  1072. {
  1073. JetBlue::TransactionHandle transaction;
  1074. CComPtr<IXMLDOMNode> poNode;
  1075. Action idAction;
  1076. MPC::wstring strAction;
  1077. MPC::wstring strID;
  1078. long ID_synset;
  1079. //
  1080. // Process all the nodes.
  1081. //
  1082. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  1083. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  1084. {
  1085. PCH_MACRO_CHECK_ABORT(hr);
  1086. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_ACTION , strAction , fFound, poNode );
  1087. HCUPDATE_GETATTRIBUTE (hr, oXMLUtil, PCH_TAG_SYNSET_ID, strID , fFound, poNode );
  1088. if(strAction.size())
  1089. {
  1090. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction.c_str(), idAction ));
  1091. }
  1092. else
  1093. {
  1094. idAction = ACTION_ADD;
  1095. }
  1096. WriteLog( S_OK, L"Processing SynSet : %s : ID : %s", s_ActionText[idAction], strID.c_str() );
  1097. //
  1098. // Check if it is adding helpfiles
  1099. //
  1100. if(idAction == ACTION_ADD)
  1101. {
  1102. if(FAILED(hr = m_updater.CreateSynSet( ID_synset, strID.c_str() )))
  1103. {
  1104. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error updating synset in database: %s", strID.c_str() ));
  1105. }
  1106. {
  1107. CComPtr<IXMLDOMNodeList> poSynonymNodeList;
  1108. //
  1109. // Get all the synonym tags
  1110. //
  1111. if(FAILED(hr = poNode->selectNodes( CComBSTR(PCH_XQL_SYNONYM), &poSynonymNodeList)))
  1112. {
  1113. PCH_MACRO_DEBUG( L"Error querying synset synonyms in HHT file" );
  1114. }
  1115. else if(poSynonymNodeList)
  1116. {
  1117. CComPtr<IXMLDOMNode> poSynonymNode;
  1118. //
  1119. // Process all the nodes.
  1120. //
  1121. for(;SUCCEEDED(hr = poSynonymNodeList->nextNode( &poSynonymNode )) && poSynonymNode != NULL; poSynonymNode.Release())
  1122. {
  1123. MPC::wstring strSynonym;
  1124. PCH_MACRO_CHECK_ABORT(hr);
  1125. //
  1126. // Get the value from the XML synonym tag.
  1127. //
  1128. if(FAILED(hr = oXMLUtil.GetValue( NULL, strSynonym, fFound, poSynonymNode )) || fFound == false)
  1129. {
  1130. PCH_MACRO_DEBUG( L"Error getting synonym value" );
  1131. }
  1132. else
  1133. {
  1134. Action idAction2;
  1135. MPC::wstring strAction2;
  1136. HCUPDATE_GETATTRIBUTE_OPT(hr, oXMLUtil, PCH_TAG_ACTION, strAction2, fFound, poNode );
  1137. if(fFound)
  1138. {
  1139. __MPC_EXIT_IF_METHOD_FAILS(hr, LookupAction( strAction2.c_str(), idAction2 ));
  1140. }
  1141. else
  1142. {
  1143. idAction2 = ACTION_ADD;
  1144. }
  1145. if(idAction2 == ACTION_ADD)
  1146. {
  1147. hr = m_updater.CreateSynonym( ID_synset, strSynonym.c_str() );
  1148. }
  1149. else if(idAction == ACTION_DELETE)
  1150. {
  1151. hr = m_updater.DeleteSynonym( ID_synset, strSynonym.c_str() );
  1152. }
  1153. else
  1154. {
  1155. hr = S_OK;
  1156. }
  1157. if(FAILED(hr))
  1158. {
  1159. __MPC_SET_ERROR_AND_EXIT(hr, WriteLog( hr, L"Error updating synonym in database: %s", strSynonym.c_str() ));
  1160. }
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. else if(idAction == ACTION_DELETE)
  1167. {
  1168. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.DeleteSynSet( strID.c_str() ));
  1169. }
  1170. }
  1171. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  1172. }
  1173. }
  1174. ////////////////////////////////////////////////////////////////////////////////
  1175. //
  1176. // Insert Taxonomy entries.
  1177. //
  1178. {
  1179. CComPtr<IXMLDOMNodeList> poNodeList;
  1180. if(FAILED(hr = oXMLUtil.GetNodes( PCH_XQL_TAXONOMY, &poNodeList )))
  1181. {
  1182. PCH_MACRO_DEBUG( L"Error querying taxonomy nodes in HHT file" );
  1183. }
  1184. else if(CountNodes(poNodeList) > 0)
  1185. {
  1186. CComPtr<IXMLDOMNode> poNode;
  1187. //
  1188. // Process all the nodes.
  1189. //
  1190. for(;SUCCEEDED(hr = poNodeList->nextNode( &poNode )) && poNode != NULL; poNode.Release())
  1191. {
  1192. JetBlue::TransactionHandle transaction;
  1193. PCH_MACRO_CHECK_ABORT(hr);
  1194. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  1195. {
  1196. __MPC_EXIT_IF_METHOD_FAILS(hr, InsertTaxonomy( oXMLUtil, poNode ));
  1197. }
  1198. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  1199. m_fTaxonomyModified = true;
  1200. }
  1201. }
  1202. }
  1203. {
  1204. JetBlue::TransactionHandle transaction;
  1205. HCUPDATE_BEGIN_TRANSACTION(hr,transaction);
  1206. {
  1207. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater.FlushWordSets());
  1208. }
  1209. HCUPDATE_COMMIT_TRANSACTION(hr,transaction);
  1210. }
  1211. ////////////////////////////////////////////////////////////////////////////////
  1212. WriteLog( S_OK, L"Processed HHT file: %s", szHHTName );
  1213. ////////////////////////////////////////////////////////////////////////////////
  1214. hr = S_OK;
  1215. __HCP_FUNC_CLEANUP;
  1216. if(FAILED(hr))
  1217. {
  1218. WriteLog( hr, L"Error processing HHT file: %s", szHHTName );
  1219. }
  1220. __HCP_FUNC_EXIT(hr);
  1221. }