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.

144 lines
3.9 KiB

  1. // PatchPackageSource.cpp: implementation of the CPatchPackageSource class.
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "PatchPackageSource.h"
  8. #include "ExtendString.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CPatchPackageSource::CPatchPackageSource(CRequestObject *pObj, IWbemServices *pNamespace,
  13. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  14. {
  15. }
  16. CPatchPackageSource::~CPatchPackageSource()
  17. {
  18. }
  19. HRESULT CPatchPackageSource::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  20. {
  21. HRESULT hr = WBEM_S_NO_ERROR;
  22. MSIHANDLE hView = NULL, hRecord = NULL;
  23. int i = -1;
  24. WCHAR wcBuf[39];
  25. WCHAR wcQuery[BUFF_SIZE];
  26. WCHAR wcProductCode[39];
  27. DWORD dwBufSize;
  28. bool bMatch = false;
  29. UINT uiStatus;
  30. CStringExt wcPatch;
  31. CStringExt wcMedia;
  32. //These will change from class to class
  33. bool bPatch, bMedia;
  34. // safe operation
  35. // lenght is smaller than BUFF_SIZE ( 512 )
  36. wcscpy(wcQuery, L"select distinct `PatchId`, `Media_` from PatchPackage");
  37. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  38. {
  39. // safe operation:
  40. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  41. wcscpy(wcProductCode, m_pRequest->Package(i));
  42. //Open our database
  43. try
  44. {
  45. if ( GetView ( &hView, wcProductCode, wcQuery, L"PatchPackage", TRUE, FALSE ) )
  46. {
  47. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  48. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  49. CheckMSI(uiStatus);
  50. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  51. //----------------------------------------------------
  52. dwBufSize = 39;
  53. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 1, wcBuf, &dwBufSize));
  54. if(wcscmp(wcBuf, L"") != 0)
  55. {
  56. // safe operation
  57. wcPatch.Copy ( L"Win32_PatchPackage.PatchID=\"" );
  58. wcPatch.Append ( 4, wcBuf, L"\",ProductCode=\"", wcProductCode, L"\"" );
  59. PutKeyProperty(m_pObj, pPatch, wcPatch, &bPatch, m_pRequest);
  60. dwBufSize = 39;
  61. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 2, wcBuf, &dwBufSize));
  62. if(wcscmp(wcBuf, L"") != 0)
  63. {
  64. // safe operation
  65. wcMedia.Copy ( L"Win32_MSILogicalDisk.DiskID=\"" );
  66. wcMedia.Append ( 2, wcBuf, L"\"" );
  67. PutKeyProperty(m_pObj, pSource, wcMedia, &bMedia, m_pRequest);
  68. //----------------------------------------------------
  69. if(bPatch && bMedia) bMatch = true;
  70. if((atAction != ACTIONTYPE_GET) || bMatch){
  71. hr = pHandler->Indicate(1, &m_pObj);
  72. }
  73. }
  74. }
  75. m_pObj->Release();
  76. m_pObj = NULL;
  77. g_fpMsiCloseHandle(hRecord);
  78. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  79. }
  80. }
  81. }
  82. catch(...)
  83. {
  84. if (hRecord)
  85. g_fpMsiCloseHandle(hRecord);
  86. if (hView)
  87. {
  88. g_fpMsiViewClose(hView);
  89. g_fpMsiCloseHandle(hView);
  90. }
  91. msidata.CloseDatabase ();
  92. if(m_pObj)
  93. {
  94. m_pObj->Release();
  95. m_pObj = NULL;
  96. }
  97. throw;
  98. }
  99. if (hRecord)
  100. g_fpMsiCloseHandle(hRecord);
  101. if (hView)
  102. {
  103. g_fpMsiViewClose(hView);
  104. g_fpMsiCloseHandle(hView);
  105. }
  106. msidata.CloseDatabase ();
  107. }
  108. return hr;
  109. }