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.

168 lines
4.4 KiB

  1. // ODBCDriverSoftwareElement.cpp: implementation of the CODBCDriverSoftwareElement class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ODBCDriverSoftwareElement.h"
  8. #include "ExtendString.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CODBCDriverSoftwareElement::CODBCDriverSoftwareElement(CRequestObject *pObj, IWbemServices *pNamespace,
  13. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  14. {
  15. }
  16. CODBCDriverSoftwareElement::~CODBCDriverSoftwareElement()
  17. {
  18. }
  19. HRESULT CODBCDriverSoftwareElement::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  20. {
  21. HRESULT hr = WBEM_S_NO_ERROR;
  22. MSIHANDLE hView = NULL;
  23. MSIHANDLE hRecord = NULL;
  24. int i = -1;
  25. WCHAR wcBuf[BUFF_SIZE];
  26. WCHAR wcQuery[BUFF_SIZE];
  27. WCHAR wcProductCode[39];
  28. WCHAR wcProp[BUFF_SIZE];
  29. DWORD dwBufSize;
  30. bool bMatch = false;
  31. UINT uiStatus;
  32. CStringExt str;
  33. //These will change from class to class
  34. bool bFeature, bElement;
  35. // safe operation
  36. // lenght is smaller than BUFF_SIZE ( 512 )
  37. wcscpy(wcQuery, L"select distinct `Component_`, `Driver` from ODBCDriver");
  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"ODBCDriver", 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. dwBufSize = BUFF_SIZE;
  59. uiStatus = CreateSoftwareElementString ( msidata.GetDatabase(),
  60. Buffer,
  61. wcProductCode,
  62. wcProp,
  63. &dwBufSize
  64. );
  65. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  66. {
  67. dynBuffer [ 0 ] = 0;
  68. }
  69. if ( uiStatus == ERROR_SUCCESS )
  70. {
  71. PutKeyProperty(m_pObj, pElement, wcProp, &bElement, m_pRequest);
  72. dwBufSize = BUFF_SIZE;
  73. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  74. if ( Buffer && Buffer [ 0 ] != 0 )
  75. {
  76. // safe operation
  77. str.Copy ( L"Win32_ODBCDriverSpecification.CheckID=\"" );
  78. str.Append ( 3, Buffer, wcProductCode, L"\"" );
  79. PutKeyProperty(m_pObj, pCheck, str, &bFeature, m_pRequest);
  80. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  81. {
  82. dynBuffer [ 0 ] = 0;
  83. }
  84. if(bFeature && bElement) bMatch = true;
  85. if((atAction != ACTIONTYPE_GET) || bMatch){
  86. hr = pHandler->Indicate(1, &m_pObj);
  87. }
  88. }
  89. }
  90. m_pObj->Release();
  91. m_pObj = NULL;
  92. g_fpMsiCloseHandle(hRecord);
  93. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  94. }
  95. }
  96. }
  97. catch(...)
  98. {
  99. if ( dynBuffer )
  100. {
  101. delete [] dynBuffer;
  102. dynBuffer = NULL;
  103. }
  104. g_fpMsiCloseHandle(hRecord);
  105. g_fpMsiViewClose(hView);
  106. g_fpMsiCloseHandle(hView);
  107. msidata.CloseDatabase ();
  108. if(m_pObj)
  109. {
  110. m_pObj->Release();
  111. m_pObj = NULL;
  112. }
  113. throw;
  114. }
  115. g_fpMsiCloseHandle(hRecord);
  116. g_fpMsiViewClose(hView);
  117. g_fpMsiCloseHandle(hView);
  118. msidata.CloseDatabase ();
  119. }
  120. if ( dynBuffer )
  121. {
  122. delete [] dynBuffer;
  123. dynBuffer = NULL;
  124. }
  125. return hr;
  126. }