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.

174 lines
4.5 KiB

  1. // ODBCDriverAttribute.cpp: implementation of the CODBCDriverAttribute class.
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ODBCDriverAttribute.h"
  8. #include "ExtendString.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CODBCDriverAttribute::CODBCDriverAttribute(CRequestObject *pObj, IWbemServices *pNamespace,
  13. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  14. {
  15. }
  16. CODBCDriverAttribute::~CODBCDriverAttribute()
  17. {
  18. }
  19. HRESULT CODBCDriverAttribute::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  20. {
  21. HRESULT hr = WBEM_S_NO_ERROR;
  22. MSIHANDLE hView = NULL, hRecord = NULL;
  23. int i = -1;
  24. WCHAR wcBuf[BUFF_SIZE];
  25. WCHAR wcQuery[BUFF_SIZE];
  26. WCHAR wcProductCode[39];
  27. DWORD dwBufSize;
  28. bool bMatch = false;
  29. UINT uiStatus;
  30. CStringExt wcProp;
  31. //These will change from class to class
  32. bool bDriver, bAttribute;
  33. // safe operation
  34. // lenght is smaller than BUFF_SIZE ( 512 )
  35. wcscpy(wcQuery, L"select distinct `Driver_`, `Attribute` from ODBCAttribute");
  36. LPWSTR Buffer = NULL;
  37. LPWSTR dynBuffer = NULL;
  38. DWORD dwDynBuffer = 0L;
  39. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  40. {
  41. // safe operation:
  42. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  43. wcscpy(wcProductCode, m_pRequest->Package(i));
  44. //Open our database
  45. try
  46. {
  47. if ( GetView ( &hView, wcProductCode, wcQuery, L"ODBCAttribute", TRUE, FALSE ) )
  48. {
  49. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  50. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  51. CheckMSI(uiStatus);
  52. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  53. //----------------------------------------------------
  54. dwBufSize = BUFF_SIZE;
  55. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  56. if ( Buffer && Buffer [ 0 ] != 0 )
  57. {
  58. // safe operation
  59. wcProp.Copy ( L"Win32_ODBCDriverSpecification.CheckID=\"" );
  60. wcProp.Append ( 3, Buffer, wcProductCode, L"\"");
  61. PutKeyProperty(m_pObj, pCheck, wcProp, &bDriver, m_pRequest);
  62. // safe operation
  63. wcProp.Copy ( L"Win32_ODBCAttribute.Attribute=\"" );
  64. wcProp.Append ( 2, Buffer, L"\",Driver=\"" );
  65. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  66. {
  67. dynBuffer [ 0 ] = 0;
  68. }
  69. dwBufSize = BUFF_SIZE;
  70. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  71. if ( Buffer && Buffer [ 0 ] != 0 )
  72. {
  73. wcProp.Append ( 2, Buffer, L"\"" );
  74. PutKeyProperty(m_pObj, pSetting, wcProp, &bAttribute, m_pRequest);
  75. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  76. {
  77. dynBuffer [ 0 ] = 0;
  78. }
  79. //=====================================================
  80. //----------------------------------------------------
  81. if(bDriver && bAttribute) bMatch = true;
  82. if((atAction != ACTIONTYPE_GET) || bMatch){
  83. hr = pHandler->Indicate(1, &m_pObj);
  84. }
  85. }
  86. }
  87. m_pObj->Release();
  88. m_pObj = NULL;
  89. g_fpMsiCloseHandle(hRecord);
  90. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  91. }
  92. }
  93. }
  94. catch(...)
  95. {
  96. if ( dynBuffer )
  97. {
  98. delete [] dynBuffer;
  99. dynBuffer = NULL;
  100. }
  101. if (hRecord)
  102. g_fpMsiCloseHandle(hRecord);
  103. if (hView)
  104. {
  105. g_fpMsiViewClose(hView);
  106. g_fpMsiCloseHandle(hView);
  107. }
  108. msidata.CloseDatabase ();
  109. if(m_pObj)
  110. {
  111. m_pObj->Release();
  112. m_pObj = NULL;
  113. }
  114. throw;
  115. }
  116. if (hRecord)
  117. g_fpMsiCloseHandle(hRecord);
  118. if (hView)
  119. {
  120. g_fpMsiViewClose(hView);
  121. g_fpMsiCloseHandle(hView);
  122. }
  123. msidata.CloseDatabase ();
  124. }
  125. if ( dynBuffer )
  126. {
  127. delete [] dynBuffer;
  128. dynBuffer = NULL;
  129. }
  130. return hr;
  131. }