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.

238 lines
6.5 KiB

  1. // PublishComponent.cpp: implementation of the CPublishComponent class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "PublishComponent.h"
  8. #include "ExtendString.h"
  9. #include "ExtendQuery.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CPublishComponent::CPublishComponent(CRequestObject *pObj, IWbemServices *pNamespace,
  14. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  15. {
  16. }
  17. CPublishComponent::~CPublishComponent()
  18. {
  19. }
  20. HRESULT CPublishComponent::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 wcProp[39];
  29. DWORD dwBufSize;
  30. bool bMatch = false;
  31. UINT uiStatus;
  32. bool bGotID = false;
  33. WCHAR wcAction[BUFF_SIZE];
  34. WCHAR wcTestCode[39];
  35. //These will change from class to class
  36. bool bCheck;
  37. SetSinglePropertyPath(L"ActionID");
  38. //improve getobject performance by optimizing the query
  39. if(atAction != ACTIONTYPE_ENUM)
  40. {
  41. // we are doing GetObject so we need to be reinitialized
  42. hr = WBEM_E_NOT_FOUND;
  43. BSTR bstrCompare;
  44. int iPos = -1;
  45. bstrCompare = SysAllocString ( L"ActionID" );
  46. if ( bstrCompare )
  47. {
  48. if(FindIn(m_pRequest->m_Property, bstrCompare, &iPos))
  49. {
  50. if ( ::SysStringLen ( m_pRequest->m_Value[iPos] ) < BUFF_SIZE )
  51. {
  52. //Get the action we're looking for
  53. wcscpy(wcBuf, m_pRequest->m_Value[iPos]);
  54. // safe operation if wcslen ( wcBuf ) > 38
  55. if ( wcslen ( wcBuf ) > 38 )
  56. {
  57. wcscpy(wcTestCode, &(wcBuf[(wcslen(wcBuf) - 38)]));
  58. }
  59. else
  60. {
  61. // we are not good to go, they have sent us longer string
  62. SysFreeString ( bstrCompare );
  63. throw hr;
  64. }
  65. // safe because lenght has been tested already in condition
  66. GetFirstGUID(m_pRequest->m_Value[iPos], wcAction);
  67. bGotID = true;
  68. }
  69. else
  70. {
  71. // we are not good to go, they have sent us longer string
  72. SysFreeString ( bstrCompare );
  73. throw hr;
  74. }
  75. }
  76. SysFreeString ( bstrCompare );
  77. }
  78. else
  79. {
  80. throw CHeap_Exception(CHeap_Exception::E_ALLOCATION_ERROR);
  81. }
  82. }
  83. Query wcQuery;
  84. wcQuery.Append ( 1, L"select distinct `ComponentId`, `Component_`, `Qualifier`, `AppData` from PublishComponent" );
  85. //optimize for GetObject
  86. if ( bGotID )
  87. {
  88. wcQuery.Append ( 3, L" where `ComponentId`=\'", wcAction, L"\'" );
  89. }
  90. LPWSTR Buffer = NULL;
  91. LPWSTR dynBuffer = NULL;
  92. DWORD dwDynBuffer = 0L;
  93. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  94. {
  95. // safe operation:
  96. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  97. wcscpy(wcProductCode, m_pRequest->Package(i));
  98. if((atAction == ACTIONTYPE_ENUM) || (bGotID && (_wcsicmp(wcTestCode, wcProductCode) == 0))){
  99. //Open our database
  100. try
  101. {
  102. if ( GetView ( &hView, wcProductCode, wcQuery, L"PublishComponent", TRUE, FALSE ) )
  103. {
  104. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  105. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  106. CheckMSI(uiStatus);
  107. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  108. //----------------------------------------------------
  109. dwBufSize = 39;
  110. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 1, wcProp, &dwBufSize));
  111. PutProperty(m_pObj, pComponentID, wcProp);
  112. PutProperty(m_pObj, pName, wcProp);
  113. PutProperty(m_pObj, pCaption, wcProp);
  114. PutProperty(m_pObj, pDescription, wcProp);
  115. dwBufSize = BUFF_SIZE;
  116. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  117. if ( ValidateComponentName ( msidata.GetDatabase (), wcProductCode, Buffer ) )
  118. {
  119. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  120. {
  121. dynBuffer [ 0 ] = 0;
  122. }
  123. dwBufSize = BUFF_SIZE;
  124. GetBufferToPut ( hRecord, 3, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  125. PutProperty(m_pObj, pQual, Buffer);
  126. PutKeyProperty ( m_pObj, pActionID, wcProp, &bCheck, m_pRequest, 2, Buffer, wcProductCode );
  127. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  128. {
  129. dynBuffer [ 0 ] = 0;
  130. }
  131. //====================================================
  132. dwBufSize = BUFF_SIZE;
  133. PutPropertySpecial ( hRecord, 4, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, pAppData );
  134. //----------------------------------------------------
  135. if(bCheck) bMatch = true;
  136. if((atAction != ACTIONTYPE_GET) || bMatch){
  137. hr = pHandler->Indicate(1, &m_pObj);
  138. }
  139. }
  140. else
  141. {
  142. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  143. {
  144. dynBuffer [ 0 ] = 0;
  145. }
  146. }
  147. m_pObj->Release();
  148. m_pObj = NULL;
  149. g_fpMsiCloseHandle(hRecord);
  150. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  151. }
  152. }
  153. }
  154. catch(...)
  155. {
  156. if ( dynBuffer )
  157. {
  158. delete [] dynBuffer;
  159. dynBuffer = NULL;
  160. }
  161. g_fpMsiCloseHandle(hRecord);
  162. g_fpMsiViewClose(hView);
  163. g_fpMsiCloseHandle(hView);
  164. msidata.CloseDatabase ();
  165. if(m_pObj)
  166. {
  167. m_pObj->Release();
  168. m_pObj = NULL;
  169. }
  170. throw;
  171. }
  172. g_fpMsiCloseHandle(hRecord);
  173. g_fpMsiViewClose(hView);
  174. g_fpMsiCloseHandle(hView);
  175. msidata.CloseDatabase ();
  176. }
  177. }
  178. if ( dynBuffer )
  179. {
  180. delete [] dynBuffer;
  181. dynBuffer = NULL;
  182. }
  183. return hr;
  184. }