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.

320 lines
8.6 KiB

  1. // SoftwareFeatureParent.cpp: implementation of the CSoftwareFeatureParent class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "SoftwareFeatureParent.h"
  8. #include "ExtendString.h"
  9. #include "ExtendQuery.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CSoftwareFeatureParent::CSoftwareFeatureParent(CRequestObject *pObj, IWbemServices *pNamespace,
  14. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  15. {
  16. }
  17. CSoftwareFeatureParent::~CSoftwareFeatureParent()
  18. {
  19. }
  20. HRESULT CSoftwareFeatureParent::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  21. {
  22. HRESULT hr = WBEM_S_NO_ERROR;
  23. MSIHANDLE hView = NULL;
  24. MSIHANDLE hRecord = NULL;
  25. int i = -1;
  26. WCHAR wcBuf[BUFF_SIZE];
  27. WCHAR wcProductCode[39];
  28. WCHAR wcTestCode[39];
  29. WCHAR wcProp[BUFF_SIZE];
  30. WCHAR wcAntFeature[BUFF_SIZE];
  31. WCHAR wcDepFeature[BUFF_SIZE];
  32. DWORD dwBufSize;
  33. bool bMatch = false;;
  34. bool bAnt = false;
  35. bool bDep = false;
  36. bool bTestCode = false;
  37. UINT uiStatus;
  38. CRequestObject *pDepRObj = NULL;
  39. CRequestObject *pAntRObj = NULL;
  40. try{
  41. if(atAction != ACTIONTYPE_ENUM)
  42. {
  43. // we are doing GetObject so we need to be reinitialized
  44. hr = WBEM_E_NOT_FOUND;
  45. int j;
  46. //GetObject optimizations
  47. CHeap_Exception he(CHeap_Exception::E_ALLOCATION_ERROR);
  48. for(j = 0; j < m_pRequest->m_iPropCount; j++){
  49. if(_wcsicmp(m_pRequest->m_Property[j], L"Dependent") == 0){
  50. pDepRObj = new CRequestObject();
  51. if(!pDepRObj) throw he;
  52. pDepRObj->Initialize(m_pNamespace);
  53. pDepRObj->ParsePath(m_pRequest->m_Value[j]);
  54. break;
  55. }
  56. }
  57. if(pDepRObj){
  58. for(j = 0; j < pDepRObj->m_iPropCount; j++){
  59. if(_wcsicmp(pDepRObj->m_Property[j], L"IdentifyingNumber") == 0){
  60. //Get the product code we're looking for
  61. if ( ::SysStringLen ( pDepRObj->m_Value[j] ) < BUFF_SIZE )
  62. {
  63. wcscpy(wcTestCode, pDepRObj->m_Value[j]);
  64. bTestCode = true;
  65. }
  66. }
  67. if(_wcsicmp(pDepRObj->m_Property[j], L"Name") == 0){
  68. //Get the product code we're looking for
  69. if ( ::SysStringLen ( pDepRObj->m_Value[j] ) < BUFF_SIZE )
  70. {
  71. wcscpy(wcDepFeature, pDepRObj->m_Value[j]);
  72. bDep = true;
  73. }
  74. }
  75. }
  76. pDepRObj->Cleanup();
  77. delete pDepRObj;
  78. pDepRObj = NULL;
  79. }
  80. for(j = 0; j < m_pRequest->m_iPropCount; j++){
  81. if(_wcsicmp(m_pRequest->m_Property[j], L"Antecedent") == 0){
  82. pAntRObj = new CRequestObject();
  83. if(!pAntRObj) throw he;
  84. pAntRObj->Initialize(m_pNamespace);
  85. pAntRObj->ParsePath(m_pRequest->m_Value[j]);
  86. break;
  87. }
  88. }
  89. if(pAntRObj){
  90. for(j = 0; j < pAntRObj->m_iPropCount; j++){
  91. if(_wcsicmp(pAntRObj->m_Property[j], L"IdentifyingNumber") == 0){
  92. //Get the product code we're looking for
  93. if ( ::SysStringLen ( pAntRObj->m_Value[j] ) < BUFF_SIZE )
  94. {
  95. wcscpy(wcTestCode, pAntRObj->m_Value[j]);
  96. }
  97. }
  98. if(_wcsicmp(pAntRObj->m_Property[j], L"Name") == 0){
  99. //Get the product code we're looking for
  100. if ( ::SysStringLen ( pAntRObj->m_Value[j] ) < BUFF_SIZE )
  101. {
  102. wcscpy(wcAntFeature, pAntRObj->m_Value[j]);
  103. bAnt = true;
  104. }
  105. }
  106. }
  107. pAntRObj->Cleanup();
  108. delete pAntRObj;
  109. pAntRObj = NULL;
  110. }
  111. }
  112. //These will change from class to class
  113. bool bFeature, bParent;
  114. Query wcQuery;
  115. wcQuery.Append ( 1, L"select distinct `Feature_Parent`, `Feature` from Feature" );
  116. //optimize for GetObject
  117. if ( bAnt || bDep )
  118. {
  119. if ( bDep )
  120. {
  121. wcQuery.Append ( 3, L" where `Feature`=\'", wcDepFeature, L"\'" );
  122. }
  123. if ( bAnt )
  124. {
  125. if ( bDep )
  126. {
  127. wcQuery.Append ( 3, L" or `Feature_Parent`=\'", wcAntFeature, L"\'" );
  128. }
  129. else
  130. {
  131. wcQuery.Append ( 3, L" where `Feature_Parent`=\'", wcAntFeature, L"\'" );
  132. }
  133. }
  134. }
  135. LPWSTR Buffer = NULL;
  136. LPWSTR dynBuffer = NULL;
  137. DWORD dwDynBuffer = 0L;
  138. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  139. {
  140. // safe operation:
  141. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  142. wcscpy(wcProductCode, m_pRequest->Package(i));
  143. if((atAction == ACTIONTYPE_ENUM) ||
  144. (bTestCode && (_wcsicmp(wcTestCode, wcProductCode) == 0))){
  145. //Open our database
  146. try
  147. {
  148. if ( GetView ( &hView, wcProductCode, wcQuery, L"Feature", TRUE, FALSE ) )
  149. {
  150. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  151. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  152. CheckMSI(uiStatus);
  153. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  154. //----------------------------------------------------
  155. dwBufSize = BUFF_SIZE;
  156. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  157. if ( CreateSoftwareFeatureString ( Buffer, wcProductCode, wcProp, true ) )
  158. {
  159. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  160. {
  161. dynBuffer [ 0 ] = 0;
  162. }
  163. PutKeyProperty(m_pObj, pAntecedent, wcProp, &bParent, m_pRequest);
  164. dwBufSize = BUFF_SIZE;
  165. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  166. if ( CreateSoftwareFeatureString ( Buffer, wcProductCode, wcProp, true ) )
  167. {
  168. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  169. {
  170. dynBuffer [ 0 ] = 0;
  171. }
  172. PutKeyProperty(m_pObj, pDependent, wcProp, &bFeature, m_pRequest);
  173. if(bFeature && bParent) bMatch = true;
  174. if((atAction != ACTIONTYPE_GET) || bMatch){
  175. hr = pHandler->Indicate(1, &m_pObj);
  176. }
  177. }
  178. else
  179. {
  180. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  181. {
  182. dynBuffer [ 0 ] = 0;
  183. }
  184. }
  185. }
  186. else
  187. {
  188. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  189. {
  190. dynBuffer [ 0 ] = 0;
  191. }
  192. }
  193. m_pObj->Release();
  194. m_pObj = NULL;
  195. g_fpMsiCloseHandle(hRecord);
  196. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  197. }
  198. }
  199. }
  200. catch(...)
  201. {
  202. if ( dynBuffer )
  203. {
  204. delete [] dynBuffer;
  205. dynBuffer = NULL;
  206. }
  207. g_fpMsiCloseHandle(hRecord);
  208. g_fpMsiViewClose(hView);
  209. g_fpMsiCloseHandle(hView);
  210. msidata.CloseDatabase ();
  211. if(m_pObj)
  212. {
  213. m_pObj->Release();
  214. m_pObj = NULL;
  215. }
  216. throw;
  217. }
  218. g_fpMsiCloseHandle(hRecord);
  219. g_fpMsiViewClose(hView);
  220. g_fpMsiCloseHandle(hView);
  221. msidata.CloseDatabase ();
  222. }
  223. }
  224. if ( dynBuffer )
  225. {
  226. delete [] dynBuffer;
  227. dynBuffer = NULL;
  228. }
  229. }
  230. catch(...)
  231. {
  232. if(pDepRObj){
  233. pDepRObj->Cleanup();
  234. delete pDepRObj;
  235. pDepRObj = NULL;
  236. }
  237. if(pAntRObj){
  238. pAntRObj->Cleanup();
  239. delete pAntRObj;
  240. pAntRObj = NULL;
  241. }
  242. throw;
  243. }
  244. return hr;
  245. }