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.

206 lines
5.3 KiB

  1. // PatchPackAge.cpp: implementation of the CPatchPackAge class.
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "PatchPackAge.h"
  8. #include "ExtendString.h"
  9. #include "ExtendQuery.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CPatchPackAge::CPatchPackAge(CRequestObject *pObj, IWbemServices *pNamespace,
  14. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  15. {
  16. }
  17. CPatchPackAge::~CPatchPackAge()
  18. {
  19. }
  20. HRESULT CPatchPackAge::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  21. {
  22. HRESULT hr = WBEM_S_NO_ERROR;
  23. MSIHANDLE hView = NULL, hRecord = NULL;
  24. int i = -1;
  25. WCHAR wcBuf[39];
  26. WCHAR wcProductCode[39];
  27. DWORD dwBufSize;
  28. bool bMatch = false;
  29. UINT uiStatus;
  30. bool bGotID = false;
  31. WCHAR wcTestCode[39];
  32. bool bGotName = false;
  33. WCHAR wcName[BUFF_SIZE];
  34. //These will change from class to class
  35. bool bPatchID, bProductCode;
  36. //improve getobject performance by optimizing the query
  37. if(atAction != ACTIONTYPE_ENUM)
  38. {
  39. // we are doing GetObject so we need to be reinitialized
  40. hr = WBEM_E_NOT_FOUND;
  41. BSTR bstrCompare;
  42. int iPos = -1;
  43. bstrCompare = SysAllocString ( L"ProductCode" );
  44. if ( bstrCompare )
  45. {
  46. if(FindIn(m_pRequest->m_Property, bstrCompare, &iPos))
  47. {
  48. if ( ::SysStringLen ( m_pRequest->m_Value[iPos] ) == 38 )
  49. {
  50. //Get the product code we're looking for
  51. wcscpy(wcTestCode, m_pRequest->m_Value[iPos]);
  52. bGotID = true;
  53. }
  54. else
  55. {
  56. // we are not good to go, they have sent us longer string
  57. SysFreeString ( bstrCompare );
  58. throw hr;
  59. }
  60. }
  61. SysFreeString ( bstrCompare );
  62. }
  63. else
  64. {
  65. throw CHeap_Exception(CHeap_Exception::E_ALLOCATION_ERROR);
  66. }
  67. iPos = -1;
  68. bstrCompare = SysAllocString ( L"PatchID" );
  69. if ( bstrCompare )
  70. {
  71. if(FindIn(m_pRequest->m_Property, bstrCompare, &iPos))
  72. {
  73. if ( ::SysStringLen ( m_pRequest->m_Value[iPos] ) < BUFF_SIZE )
  74. {
  75. //Get the name we're looking for
  76. wcscpy(wcName, m_pRequest->m_Value[iPos]);
  77. bGotName = true;
  78. }
  79. else
  80. {
  81. // we are not good to go, they have sent us longer string
  82. SysFreeString ( bstrCompare );
  83. throw hr;
  84. }
  85. }
  86. SysFreeString ( bstrCompare );
  87. }
  88. else
  89. {
  90. throw CHeap_Exception(CHeap_Exception::E_ALLOCATION_ERROR);
  91. }
  92. }
  93. Query wcQuery;
  94. wcQuery.Append ( 1, L"select distinct `PatchId` from PatchPackage" );
  95. //optimize for GetObject
  96. if ( bGotName )
  97. {
  98. wcQuery.Append ( 3, L" where `PatchId`=\'", wcName, L"\'" );
  99. }
  100. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  101. {
  102. // safe operation:
  103. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  104. wcscpy(wcProductCode, m_pRequest->Package(i));
  105. if((atAction == ACTIONTYPE_ENUM) || (bGotID && (_wcsicmp(wcTestCode, wcProductCode) == 0))){
  106. //Open our database
  107. try
  108. {
  109. if ( GetView ( &hView, wcProductCode, wcQuery, L"PatchPackage", TRUE, FALSE ) )
  110. {
  111. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  112. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  113. CheckMSI(uiStatus);
  114. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  115. //----------------------------------------------------
  116. dwBufSize = 39;
  117. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 1, wcBuf, &dwBufSize));
  118. PutKeyProperty(m_pObj, pPatchID, wcBuf, &bPatchID, m_pRequest);
  119. PutProperty(m_pObj, pCaption, wcBuf);
  120. PutProperty(m_pObj, pDescription, wcBuf);
  121. PutKeyProperty(m_pObj, pProductCode, wcProductCode, &bProductCode, m_pRequest);
  122. //----------------------------------------------------
  123. if(bPatchID && bProductCode) bMatch = true;
  124. if((atAction != ACTIONTYPE_GET) || bMatch){
  125. hr = pHandler->Indicate(1, &m_pObj);
  126. }
  127. m_pObj->Release();
  128. m_pObj = NULL;
  129. g_fpMsiCloseHandle(hRecord);
  130. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  131. }
  132. }
  133. }
  134. catch(...)
  135. {
  136. if (hRecord)
  137. g_fpMsiCloseHandle(hRecord);
  138. if (hView)
  139. {
  140. g_fpMsiViewClose(hView);
  141. g_fpMsiCloseHandle(hView);
  142. }
  143. msidata.CloseDatabase ();
  144. if(m_pObj)
  145. {
  146. m_pObj->Release();
  147. m_pObj = NULL;
  148. }
  149. throw;
  150. }
  151. if (hRecord)
  152. g_fpMsiCloseHandle(hRecord);
  153. if (hView)
  154. {
  155. g_fpMsiViewClose(hView);
  156. g_fpMsiCloseHandle(hView);
  157. }
  158. msidata.CloseDatabase ();
  159. }
  160. }
  161. return hr;
  162. }