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.

241 lines
6.1 KiB

  1. // SoftwareFeatureCondition.cpp: implementation of the CSoftwareFeatureCondition class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "SoftwareFeatureCondition.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CSoftwareFeatureCondition::CSoftwareFeatureCondition(CRequestObject *pObj, IWbemServices *pNamespace,
  12. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  13. {
  14. }
  15. CSoftwareFeatureCondition::~CSoftwareFeatureCondition()
  16. {
  17. }
  18. HRESULT CSoftwareFeatureCondition::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 wcBuf2[BUFF_SIZE];
  26. LPWSTR wcCondition = NULL;
  27. WCHAR wcQuery[BUFF_SIZE];
  28. WCHAR wcProductCode[39];
  29. WCHAR wcProp[BUFF_SIZE];
  30. DWORD dwBufSize;
  31. bool bMatch = false;
  32. UINT uiStatus;
  33. //These will change from class to class
  34. bool bFeature, bParent;
  35. // safe operation
  36. // lenght is smaller than BUFF_SIZE ( 512 )
  37. wcscpy(wcQuery, L"select distinct `Feature_`, `Level` from Condition");
  38. LPWSTR Buffer = NULL;
  39. LPWSTR dynBuffer = NULL;
  40. DWORD dwDynBuffer = 0L;
  41. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  42. {
  43. // safe operation:
  44. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  45. wcscpy(wcProductCode, m_pRequest->Package(i));
  46. //Open our database
  47. try
  48. {
  49. if ( GetView ( &hView, wcProductCode, wcQuery, L"Condition", TRUE, FALSE ) )
  50. {
  51. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  52. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  53. CheckMSI(uiStatus);
  54. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  55. //----------------------------------------------------
  56. dwBufSize = BUFF_SIZE;
  57. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  58. if ( ( wcCondition = new WCHAR [ dwBufSize + 1 ] ) != NULL )
  59. {
  60. wcscpy(wcCondition, Buffer);
  61. }
  62. else
  63. {
  64. throw CHeap_Exception (CHeap_Exception::E_ALLOCATION_ERROR);
  65. }
  66. if ( CreateSoftwareFeatureString ( Buffer, wcProductCode, wcProp, true ) )
  67. {
  68. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  69. {
  70. dynBuffer [ 0 ] = 0;
  71. }
  72. PutKeyProperty(m_pObj, pElement, wcProp, &bFeature, m_pRequest);
  73. dwBufSize = BUFF_SIZE;
  74. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf2, dwDynBuffer, dynBuffer, Buffer );
  75. if ( Buffer && Buffer [ 0 ] != 0 )
  76. {
  77. DWORD dwConstant = 0L;
  78. DWORD dwCondition = 0L;
  79. DWORD dwBuf = 0L;
  80. DWORD dwProductCode = 0L;
  81. dwCondition = wcslen ( wcCondition );
  82. dwBuf = dwBufSize;
  83. dwProductCode = wcslen ( wcProductCode );
  84. dwConstant = wcslen ( L"Win32_Condition.CheckID=\"" ) + wcslen ( L"\"" );
  85. if ( dwConstant + dwCondition + dwBuf + dwProductCode + 1 < BUFF_SIZE )
  86. {
  87. wcscpy(wcProp, L"Win32_Condition.CheckID=\"");
  88. wcscat(wcProp, wcCondition);
  89. wcscat(wcProp, Buffer);
  90. wcscat(wcProp, wcProductCode);
  91. wcscat(wcProp, L"\"");
  92. PutKeyProperty(m_pObj, pCheck, wcProp, &bParent, m_pRequest);
  93. }
  94. else
  95. {
  96. LPWSTR wsz = NULL;
  97. try
  98. {
  99. if ( ( wsz = new WCHAR [ dwConstant + dwCondition + dwBuf + dwProductCode + 1 ] ) != NULL )
  100. {
  101. wcscpy ( wsz, L"Win32_Condition.CheckID=\"" );
  102. wcscat ( wsz, wcCondition );
  103. wcscat ( wsz, Buffer
  104. );
  105. wcscat ( wsz, wcProductCode );
  106. wcscat ( wsz, L"\"" );
  107. PutKeyProperty ( m_pObj, pCheck, wsz, &bParent, m_pRequest );
  108. }
  109. else
  110. {
  111. throw CHeap_Exception(CHeap_Exception::E_ALLOCATION_ERROR);
  112. }
  113. }
  114. catch ( ... )
  115. {
  116. if ( wsz )
  117. {
  118. delete [] wsz;
  119. wsz = NULL;
  120. }
  121. throw;
  122. }
  123. if ( wsz )
  124. {
  125. delete [] wsz;
  126. wsz = NULL;
  127. }
  128. }
  129. //====================================================
  130. //----------------------------------------------------
  131. if(bFeature && bParent) bMatch = true;
  132. if((atAction != ACTIONTYPE_GET) || bMatch){
  133. hr = pHandler->Indicate(1, &m_pObj);
  134. }
  135. }
  136. }
  137. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  138. {
  139. dynBuffer [ 0 ] = 0;
  140. }
  141. m_pObj->Release();
  142. m_pObj = NULL;
  143. g_fpMsiCloseHandle(hRecord);
  144. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  145. if ( wcCondition )
  146. {
  147. delete [] wcCondition;
  148. wcCondition = NULL;
  149. }
  150. }
  151. }
  152. }
  153. catch(...)
  154. {
  155. if ( dynBuffer )
  156. {
  157. delete [] dynBuffer;
  158. dynBuffer = NULL;
  159. }
  160. if ( wcCondition )
  161. {
  162. delete [] wcCondition;
  163. wcCondition = NULL;
  164. }
  165. g_fpMsiCloseHandle(hRecord);
  166. g_fpMsiViewClose(hView);
  167. g_fpMsiCloseHandle(hView);
  168. msidata.CloseDatabase ();
  169. if(m_pObj)
  170. {
  171. m_pObj->Release();
  172. m_pObj = NULL;
  173. }
  174. throw;
  175. }
  176. g_fpMsiCloseHandle(hRecord);
  177. g_fpMsiViewClose(hView);
  178. g_fpMsiCloseHandle(hView);
  179. msidata.CloseDatabase ();
  180. }
  181. if ( dynBuffer )
  182. {
  183. delete [] dynBuffer;
  184. dynBuffer = NULL;
  185. }
  186. return hr;
  187. }