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.

172 lines
4.5 KiB

  1. // ODBCDataSourceAttribute.cpp: implementation of the CODBCDataSourceAttribute class.
  2. //
  3. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ODBCDataSourceAttribute.h"
  8. #include "ExtendString.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CODBCDataSourceAttribute::CODBCDataSourceAttribute(CRequestObject *pObj, IWbemServices *pNamespace,
  13. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  14. {
  15. }
  16. CODBCDataSourceAttribute::~CODBCDataSourceAttribute()
  17. {
  18. }
  19. HRESULT CODBCDataSourceAttribute::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 `DataSource_`, `Attribute` from ODBCSourceAttribute");
  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"ODBCSourceAttribute", 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_ODBCDataSourcespecification.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_ODBCSourceAttribute.Attribute=\"" );
  64. wcProp.Append ( 2, Buffer, L"\",DataSource=\"" );
  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. if(bDriver && bAttribute) bMatch = true;
  81. if((atAction != ACTIONTYPE_GET) || bMatch){
  82. hr = pHandler->Indicate(1, &m_pObj);
  83. }
  84. }
  85. }
  86. m_pObj->Release();
  87. m_pObj = NULL;
  88. g_fpMsiCloseHandle(hRecord);
  89. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  90. }
  91. }
  92. }
  93. catch(...)
  94. {
  95. if ( dynBuffer )
  96. {
  97. delete [] dynBuffer;
  98. dynBuffer = NULL;
  99. }
  100. if (hRecord)
  101. g_fpMsiCloseHandle(hRecord);
  102. if (hView)
  103. {
  104. g_fpMsiViewClose(hView);
  105. g_fpMsiCloseHandle(hView);
  106. }
  107. msidata.CloseDatabase ();
  108. if(m_pObj)
  109. {
  110. m_pObj->Release();
  111. m_pObj = NULL;
  112. }
  113. throw;
  114. }
  115. if (hRecord)
  116. g_fpMsiCloseHandle(hRecord);
  117. if (hView)
  118. {
  119. g_fpMsiViewClose(hView);
  120. g_fpMsiCloseHandle(hView);
  121. }
  122. msidata.CloseDatabase ();
  123. }
  124. if ( dynBuffer )
  125. {
  126. delete [] dynBuffer;
  127. dynBuffer = NULL;
  128. }
  129. return hr;
  130. }