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.

218 lines
5.5 KiB

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