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.

170 lines
4.4 KiB

  1. // Condition.cpp: implementation of the CCondition class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "Condition.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CCondition::CCondition(CRequestObject *pObj, IWbemServices *pNamespace,
  12. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  13. {
  14. }
  15. CCondition::~CCondition()
  16. {
  17. }
  18. HRESULT CCondition::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  19. {
  20. HRESULT hr = WBEM_S_NO_ERROR;
  21. MSIHANDLE hView = NULL;
  22. MSIHANDLE hRecord = NULL;
  23. int i = -1;
  24. WCHAR wcBuf[BUFF_SIZE];
  25. WCHAR wcQuery[BUFF_SIZE];
  26. WCHAR wcProductCode[39];
  27. WCHAR wcProp[BUFF_SIZE];
  28. DWORD dwBufSize;
  29. bool bMatch = false;
  30. UINT uiStatus;
  31. //These will change from class to class
  32. bool bCheck;
  33. if ( atAction != ACTIONTYPE_ENUM )
  34. {
  35. // we are doing GetObject so we need to be reinitialized
  36. hr = WBEM_E_NOT_FOUND;
  37. }
  38. // safe operation
  39. // lenght is smaller than BUFF_SIZE ( 512 )
  40. wcscpy(wcQuery, L"select distinct `Feature_`, `Level`, `Condition` from Condition");
  41. SetSinglePropertyPath(L"CheckID");
  42. LPWSTR Buffer = NULL;
  43. LPWSTR dynBuffer = NULL;
  44. DWORD dwDynBuffer = 0L;
  45. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  46. {
  47. // safe operation:
  48. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  49. wcscpy(wcProductCode, m_pRequest->Package(i));
  50. //Open our database
  51. try
  52. {
  53. if ( GetView ( &hView, wcProductCode, wcQuery, L"Condition", TRUE, FALSE ) )
  54. {
  55. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  56. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  57. CheckMSI(uiStatus);
  58. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  59. //----------------------------------------------------
  60. dwBufSize = BUFF_SIZE;
  61. GetBufferToPut ( hRecord, 1, dwBufSize, wcProp, dwDynBuffer, dynBuffer, Buffer );
  62. PutProperty(m_pObj, pName, Buffer);
  63. PutProperty(m_pObj, pFeature, Buffer);
  64. PutProperty(m_pObj, pCaption, Buffer);
  65. PutProperty(m_pObj, pDescription, Buffer);
  66. if ( ValidateFeatureName ( Buffer, wcProductCode ) )
  67. {
  68. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 2, wcBuf, &dwBufSize));
  69. PutKeyProperty ( m_pObj, pCheckID, Buffer, &bCheck, m_pRequest, 2, wcBuf, wcProductCode);
  70. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  71. {
  72. dynBuffer [ 0 ] = 0;
  73. }
  74. //====================================================
  75. PutProperty(m_pObj, pLevel, g_fpMsiRecordGetInteger(hRecord, 2));
  76. dwBufSize = BUFF_SIZE;
  77. PutPropertySpecial ( hRecord, 3, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, pCondition, FALSE );
  78. //----------------------------------------------------
  79. if(bCheck) bMatch = true;
  80. if((atAction != ACTIONTYPE_GET) || bMatch){
  81. hr = pHandler->Indicate(1, &m_pObj);
  82. }
  83. }
  84. else
  85. {
  86. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  87. {
  88. dynBuffer [ 0 ] = 0;
  89. }
  90. }
  91. m_pObj->Release();
  92. m_pObj = NULL;
  93. g_fpMsiCloseHandle(hRecord);
  94. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  95. }
  96. }
  97. }
  98. catch(...)
  99. {
  100. if ( dynBuffer )
  101. {
  102. delete [] dynBuffer;
  103. dynBuffer = NULL;
  104. }
  105. g_fpMsiCloseHandle(hRecord);
  106. g_fpMsiViewClose(hView);
  107. g_fpMsiCloseHandle(hView);
  108. msidata.CloseDatabase ();
  109. if(m_pObj)
  110. {
  111. m_pObj->Release();
  112. m_pObj = NULL;
  113. }
  114. throw;
  115. }
  116. g_fpMsiCloseHandle(hRecord);
  117. g_fpMsiViewClose(hView);
  118. g_fpMsiCloseHandle(hView);
  119. msidata.CloseDatabase ();
  120. }
  121. if ( dynBuffer )
  122. {
  123. delete [] dynBuffer;
  124. dynBuffer = NULL;
  125. }
  126. return hr;
  127. }