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.

295 lines
7.6 KiB

  1. /** Copyright (c) 2000 Microsoft Corporation
  2. ******************************************************************************
  3. ** Module Name:
  4. **
  5. ** Newsver.cpp
  6. **
  7. ** Abstract:
  8. **
  9. ** Implementation of Newsver class
  10. **
  11. ** Author:
  12. **
  13. ** Martha Arellano (t-alopez) 03-Oct-2000
  14. **
  15. **
  16. ** Revision History:
  17. **
  18. ** Martha Arellano (t-alopez) 05-Oct-2000 Changed Newsver.xml format
  19. **
  20. ** 11-Oct-2000 Added URL and get_URL property
  21. **
  22. ** 12-Oct-2000 Added Download method
  23. **
  24. **
  25. ******************************************************************************
  26. **/
  27. #include "stdafx.h"
  28. //////////////////////////////////////////////////////////////////////
  29. // CONFIG MAP
  30. //////////////////////////////////////////////////////////////////////
  31. /*<?xml version="1.0" ?>
  32. <NEWSVER URL="www" FREQUENCY="20">
  33. <LANGUAGE LCID="1033">
  34. <SKU VERSION="Personal">
  35. <NEWSBLOCK URL="http://windows.microsoft.com" />
  36. </SKU>
  37. </LANGUAGE>
  38. </NEWSVER>
  39. */
  40. CFG_BEGIN_FIELDS_MAP(News::Newsver::Newsblock)
  41. CFG_ATTRIBUTE( L"URL", wstring, m_strURL ),
  42. CFG_ATTRIBUTE( L"OEM", bool, m_fNewsblockHasHeadlines ),
  43. CFG_END_FIELDS_MAP()
  44. CFG_BEGIN_CHILD_MAP(News::Newsver::Newsblock)
  45. CFG_END_CHILD_MAP()
  46. DEFINE_CFG_OBJECT(News::Newsver::Newsblock, L"NEWSBLOCK")
  47. DEFINE_CONFIG_METHODS__NOCHILD(News::Newsver::Newsblock)
  48. ////////////////////
  49. CFG_BEGIN_FIELDS_MAP(News::Newsver::SKU)
  50. CFG_ATTRIBUTE( L"VERSION", wstring, m_strSKU),
  51. CFG_END_FIELDS_MAP()
  52. CFG_BEGIN_CHILD_MAP(News::Newsver::SKU)
  53. CFG_CHILD(News::Newsver::Newsblock)
  54. CFG_END_CHILD_MAP()
  55. DEFINE_CFG_OBJECT(News::Newsver::SKU, L"SKU")
  56. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(News::Newsver::SKU,tag,defSubType)
  57. if(tag == _cfg_table_tags[0])
  58. {
  59. defSubType = &(*(m_vecNewsblocks.insert( m_vecNewsblocks.end() )));
  60. return S_OK;
  61. }
  62. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(News::Newsver::SKU,xdn)
  63. hr = MPC::Config::SaveList( m_vecNewsblocks, xdn );
  64. DEFINE_CONFIG_METHODS_END(News::Newsver::SKU)
  65. ////////////////////
  66. CFG_BEGIN_FIELDS_MAP(News::Newsver::Language)
  67. CFG_ATTRIBUTE( L"LCID", long, m_lLCID ),
  68. CFG_END_FIELDS_MAP()
  69. CFG_BEGIN_CHILD_MAP(News::Newsver::Language)
  70. CFG_CHILD(News::Newsver::SKU)
  71. CFG_END_CHILD_MAP()
  72. DEFINE_CFG_OBJECT(News::Newsver::Language,L"LANGUAGE")
  73. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(News::Newsver::Language,tag,defSubType)
  74. if(tag == _cfg_table_tags[0])
  75. {
  76. defSubType = &(*(m_lstSKUs.insert( m_lstSKUs.end() )));
  77. return S_OK;
  78. }
  79. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(News::Newsver::Language,xdn)
  80. hr = MPC::Config::SaveList( m_lstSKUs, xdn );
  81. DEFINE_CONFIG_METHODS_END(News::Newsver::Language)
  82. ////////////////////
  83. CFG_BEGIN_FIELDS_MAP(News::Newsver)
  84. CFG_ATTRIBUTE( L"URL", wstring, m_strURL ),
  85. CFG_ATTRIBUTE( L"FREQUENCY", int , m_nFrequency ),
  86. CFG_END_FIELDS_MAP()
  87. CFG_BEGIN_CHILD_MAP(News::Newsver)
  88. CFG_CHILD(News::Newsver::Language)
  89. CFG_END_CHILD_MAP()
  90. DEFINE_CFG_OBJECT(News::Newsver,L"NEWSVER")
  91. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(News::Newsver,tag,defSubType)
  92. if(tag == _cfg_table_tags[0])
  93. {
  94. defSubType = &(*(m_lstLanguages.insert( m_lstLanguages.end() )));
  95. return S_OK;
  96. }
  97. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(News::Newsver,xdn)
  98. hr = MPC::Config::SaveList( m_lstLanguages, xdn );
  99. DEFINE_CONFIG_METHODS_END(News::Newsver)
  100. /////////////////////////////////////////////////////////////////////////////
  101. /////////////////////////////////////////////////////////////////////////////
  102. /////////////////////////////////////////////////////////////////////////////
  103. News::Newsver::Newsblock::Newsblock()
  104. {
  105. // MPC::wstring m_strURL;
  106. }
  107. News::Newsver::SKU::SKU()
  108. {
  109. // MPC::wstring m_strSKU;
  110. // NewsblockVector m_vecNewsblocks;
  111. }
  112. News::Newsver::Language::Language()
  113. {
  114. m_lLCID = 0; // long m_lLCID;
  115. // SKUList m_lstSKUs;
  116. }
  117. News::Newsver::Newsver()
  118. {
  119. // MPC::wstring m_strURL;
  120. m_nFrequency = 0; // int m_nFrequency;
  121. m_fLoaded = false; // bool m_fLoaded;
  122. m_fDirty = false; // bool m_fDirty;
  123. //
  124. // LanguageList m_lstLanguages;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. //
  128. // Routine Description:
  129. //
  130. // Downloads the newsver.xml file and saves it in HC_HCUPDATE_NEWSVER
  131. //
  132. // Arguments:
  133. //
  134. // strNewsverURL the URL for newsver.xml
  135. //
  136. HRESULT News::Newsver::Download( /*[in]*/ const MPC::wstring& strNewsverURL )
  137. {
  138. __HCP_FUNC_ENTRY( "News::Newsver::Download" );
  139. HRESULT hr;
  140. CComPtr<IStream> stream;
  141. MPC::wstring strPath;
  142. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SubstituteEnvVariables( strPath = HC_HCUPDATE_NEWSVER ));
  143. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::MakeDir ( strPath ));
  144. __MPC_EXIT_IF_METHOD_FAILS(hr, News::LoadXMLFile( strNewsverURL.c_str(), stream ));
  145. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadStream( this, stream ));
  146. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::SaveFile( this, strPath.c_str() ));
  147. hr = S_OK;
  148. __HCP_FUNC_CLEANUP;
  149. __HCP_FUNC_EXIT(hr);
  150. }
  151. //
  152. // Routine Description:
  153. //
  154. // Loads the cached newsver.xml file and looks for the newsblocks for the specified LCID and SKUVersion
  155. //
  156. // if the newsblocks are found, m_fReady is TRUE
  157. //
  158. // Arguments:
  159. //
  160. // lLCID the Language to look for
  161. //
  162. // strSKU the SKU to look for
  163. //
  164. //
  165. HRESULT News::Newsver::Load( /*[in]*/ long lLCID, /*[in]*/ const MPC::wstring& strSKU )
  166. {
  167. __HCP_FUNC_ENTRY( "News::Newsver::Load" );
  168. HRESULT hr;
  169. MPC::wstring strPath = HC_HCUPDATE_NEWSVER; MPC::SubstituteEnvVariables( strPath );
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadFile( this, strPath.c_str() ));
  171. /////////////// looks for LCID and SKU
  172. m_data = NULL;
  173. for(LanguageIter it = m_lstLanguages.begin(); it != m_lstLanguages.end(); it++)
  174. {
  175. if(it->m_lLCID == lLCID)
  176. {
  177. for(SKUIter it2 = it->m_lstSKUs.begin(); it2 != it->m_lstSKUs.end(); it2++)
  178. {
  179. if(!MPC::StrICmp( it2->m_strSKU, strSKU ))
  180. {
  181. m_data = &(*it2);
  182. break;
  183. }
  184. }
  185. break;
  186. }
  187. }
  188. if(m_data == NULL)
  189. {
  190. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_INVALID_DATA);
  191. }
  192. hr = S_OK;
  193. __HCP_FUNC_CLEANUP;
  194. __HCP_FUNC_EXIT(hr);
  195. }
  196. //
  197. // Routine Description:
  198. //
  199. // Returns true if the newsblock has the HEADLINES attribute set to true else returns false
  200. //
  201. bool News::Newsver::OEMNewsblock( /*[in]*/ size_t nIndex )
  202. {
  203. if(m_data == NULL || nIndex >= m_data->m_vecNewsblocks.size() )
  204. {
  205. return false;
  206. }
  207. return (m_data->m_vecNewsblocks[nIndex].m_fNewsblockHasHeadlines);
  208. }
  209. ////////////////////////////////////////////////////////////////////////////////
  210. size_t News::Newsver::get_NumberOfNewsblocks()
  211. {
  212. return m_data ? m_data->m_vecNewsblocks.size() : 0;
  213. }
  214. const MPC::wstring* News::Newsver::get_NewsblockURL( /*[in]*/ size_t nIndex )
  215. {
  216. if(m_data == NULL || nIndex >= m_data->m_vecNewsblocks.size() )
  217. {
  218. return NULL;
  219. }
  220. return &(m_data->m_vecNewsblocks[nIndex].m_strURL);
  221. }
  222. const MPC::wstring* News::Newsver::get_URL()
  223. {
  224. return m_strURL.size() ? &m_strURL : NULL;
  225. }
  226. int News::Newsver::get_Frequency()
  227. {
  228. return m_nFrequency;
  229. }