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.

199 lines
6.5 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. RemoteConfig.h
  5. Abstract:
  6. Implements the class CRemoteConfig that contains methods for retrieving the updated
  7. config file (parameter list file).
  8. Revision History:
  9. a-prakac created 10/24/2000
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. #include <SvcUtils.h>
  13. /************
  14. Method - CRemoteConfig::RetrieveList(CComBSTR bstrQuery, CComBSTR bstrFilePath)
  15. Description - This method retrieves the latest copy of the product list from a webservice.
  16. It also checks to see if an update is required in the first place. The old product list is
  17. replaced back in case of errors.
  18. ************/
  19. HRESULT CRemoteConfig::RetrieveList( /*[in]*/ BSTR bstrQuery ,
  20. /*[in]*/ BSTR bstrLCID ,
  21. /*[in]*/ BSTR bstrSKU ,
  22. /*[in]*/ BSTR bstrFilePath ,
  23. /*[in]*/ long lFrequency )
  24. {
  25. __HCP_FUNC_ENTRY( "CRemoteConfig::RetrieveList" );
  26. HRESULT hr;
  27. CComPtr<IXMLDOMNode> ptrDOMNode;
  28. CComBSTR bstrTemp;
  29. MPC::wstring strQuery;
  30. bool fLoaded;
  31. bool fFound;
  32. SANITIZEWSTR(bstrQuery);
  33. SANITIZEWSTR(bstrLCID);
  34. SANITIZEWSTR(bstrSKU);
  35. SANITIZEWSTR(bstrFilePath);
  36. //
  37. // Check if an update is required and if so, call the webservice
  38. //
  39. {
  40. bool fUpdateRequired;
  41. long lUpdateFrequency;
  42. //
  43. // If a valid Update Frequency (non negative) has been passed in then use it - else use the default update frequency (7)
  44. //
  45. lUpdateFrequency = (lFrequency > 0) ? lFrequency : UPDATE_FREQUENCY;
  46. __MPC_EXIT_IF_METHOD_FAILS(hr, CheckIfUpdateReqd( bstrFilePath, lUpdateFrequency, fUpdateRequired ) );
  47. if(!fUpdateRequired)
  48. {
  49. __MPC_SET_ERROR_AND_EXIT( hr, S_OK );
  50. }
  51. }
  52. //
  53. // Add the 'hardcoded' parameters before calling the URL
  54. //
  55. {
  56. MPC::URL urlQuery;
  57. __MPC_EXIT_IF_METHOD_FAILS(hr, urlQuery.put_URL ( bstrQuery ));
  58. __MPC_EXIT_IF_METHOD_FAILS(hr, urlQuery.AppendQueryParameter( NSW_PARAM_LCID, bstrLCID ));
  59. __MPC_EXIT_IF_METHOD_FAILS(hr, urlQuery.AppendQueryParameter( NSW_PARAM_SKU , bstrSKU ));
  60. __MPC_EXIT_IF_METHOD_FAILS(hr, urlQuery.get_URL ( strQuery ));
  61. }
  62. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.SetTimeout( NSW_TIMEOUT_REMOTECONFIG ));
  63. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.Load( strQuery.c_str(), NULL, fLoaded, &fFound ));
  64. // Check if the file was loaded
  65. if(fLoaded)
  66. {
  67. // Check to see if the root node is "CONFIG_DATA" or "string"
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.GetRoot( &ptrDOMNode ) );
  69. __MPC_EXIT_IF_METHOD_FAILS(hr, ptrDOMNode->get_nodeName( &bstrTemp ) );
  70. ptrDOMNode = NULL;
  71. // If it is a webservice, then the root node returned is "string". In this case, get the value of
  72. // this node
  73. if(MPC::StrCmp( bstrTemp, NSW_TAG_STRING) == 0)
  74. {
  75. CComVariant vVar;
  76. __MPC_EXIT_IF_METHOD_FAILS( hr, m_xmlUpdatedList.GetValue ( NULL, vVar , fFound ));
  77. __MPC_EXIT_IF_METHOD_FAILS( hr, m_xmlUpdatedList.LoadAsString( vVar.bstrVal, NSW_TAG_CONFIGDATA, fLoaded, &fFound ));
  78. if(!fLoaded)
  79. {
  80. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  81. }
  82. }
  83. // If a successful download occured then stamp the file with the current time value and save
  84. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.PutAttribute( NULL, NSW_TAG_LASTUPDATED, MPC::GetSystemTime(), fFound ));
  85. {
  86. MPC::wstring strFile( bstrFilePath );
  87. CComPtr<MPC::FileStream> streamDst;
  88. CComPtr<IStream> streamSrc;
  89. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::SafeSave_Init( strFile, streamDst ));
  90. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.SaveAsStream( (IUnknown**)&streamSrc ));
  91. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::BaseStream::TransferData( streamSrc, streamDst ));
  92. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::SafeSave_Finalize( strFile, streamDst ));
  93. }
  94. }
  95. hr = S_OK;
  96. __HCP_FUNC_CLEANUP;
  97. __HCP_FUNC_EXIT(hr);
  98. }
  99. HRESULT CRemoteConfig::Abort()
  100. {
  101. return m_xmlUpdatedList.Abort();
  102. }
  103. /************
  104. Method - CRemoteConfig::CheckIfUpdateReqd(MPC::wstring wszFilePath, long lUpdateFrequency)
  105. Description - This method is called by RetrieveList to see if an update is really required. This method
  106. returns E_FAIL if an update is not required otherwise it returns S_OK. It checks to see if the
  107. UPDATE_FREQEUNCY amount of time has elapsed since the last time the file was updated.
  108. ************/
  109. HRESULT CRemoteConfig::CheckIfUpdateReqd( /*[in]*/ const MPC::wstring& strFilePath, /*[in]*/ long lUpdateFrequency, /*[out]*/ bool& fUpdateRequired )
  110. {
  111. __HCP_FUNC_ENTRY( "CRemoteConfig::CheckIfUpdateReqd" );
  112. HRESULT hr;
  113. //Default behaviour is update required
  114. fUpdateRequired = true;
  115. if(MPC::FileSystemObject::IsFile( strFilePath.c_str() ))
  116. {
  117. bool fLoaded;
  118. bool fFound;
  119. //
  120. // Get the attribute LASTUPDATED from the product list file - if not found then exit and download the config file again
  121. //
  122. __MPC_EXIT_IF_METHOD_FAILS(hr, m_xmlUpdatedList.Load( strFilePath.c_str(), NSW_TAG_CONFIGDATA, fLoaded, &fFound ));
  123. if(fLoaded)
  124. {
  125. long lLastUpdateTime;
  126. __MPC_EXIT_IF_METHOD_FAILS( hr, m_xmlUpdatedList.GetAttribute( NULL, NSW_TAG_LASTUPDATED, lLastUpdateTime, fFound ));
  127. if(fFound)
  128. {
  129. long lCurrentTime = MPC::GetSystemTime();
  130. //
  131. // If current time - last updated time is less than the update frequency then return E_FAIL - no update takes place in this case
  132. //
  133. if((lCurrentTime - lLastUpdateTime) < lUpdateFrequency)
  134. {
  135. fUpdateRequired = false;
  136. }
  137. }
  138. }
  139. }
  140. hr = S_OK;
  141. __HCP_FUNC_CLEANUP;
  142. __HCP_FUNC_EXIT(hr);
  143. }