Source code of Windows XP (NT5)
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.

245 lines
6.7 KiB

  1. // LogODBC.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "logui.h"
  6. #include "LogODBC.h"
  7. #include "CnfrmPsD.h"
  8. #include "wrapmb.h"
  9. #include "metatool.h"
  10. #include <iiscnfg.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CLogODBC property page
  18. IMPLEMENT_DYNCREATE(CLogODBC, CPropertyPage)
  19. //--------------------------------------------------------------------------
  20. CLogODBC::CLogODBC() : CPropertyPage(CLogODBC::IDD),
  21. m_fInitialized( FALSE )
  22. {
  23. //{{AFX_DATA_INIT(CLogODBC)
  24. m_sz_datasource = _T("");
  25. m_sz_password = _T("");
  26. m_sz_table = _T("");
  27. m_sz_username = _T("");
  28. //}}AFX_DATA_INIT
  29. m_szOrigPass.Empty();
  30. m_bPassTyped = FALSE;
  31. }
  32. //--------------------------------------------------------------------------
  33. CLogODBC::~CLogODBC()
  34. {
  35. }
  36. //--------------------------------------------------------------------------
  37. void CLogODBC::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CPropertyPage::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CLogODBC)
  41. DDX_Control(pDX, IDC_ODBC_PASSWORD, m_cedit_password);
  42. DDX_Text(pDX, IDC_ODBC_DATASOURCE, m_sz_datasource);
  43. DDX_Text(pDX, IDC_ODBC_PASSWORD, m_sz_password);
  44. DDX_Text(pDX, IDC_ODBC_TABLE, m_sz_table);
  45. DDX_Text(pDX, IDC_ODBC_USERNAME, m_sz_username);
  46. //}}AFX_DATA_MAP
  47. }
  48. //--------------------------------------------------------------------------
  49. BEGIN_MESSAGE_MAP(CLogODBC, CPropertyPage)
  50. //{{AFX_MSG_MAP(CLogODBC)
  51. ON_EN_CHANGE(IDC_ODBC_DATASOURCE, OnChangeOdbcDatasource)
  52. ON_EN_CHANGE(IDC_ODBC_PASSWORD, OnChangeOdbcPassword)
  53. ON_EN_CHANGE(IDC_ODBC_TABLE, OnChangeOdbcTable)
  54. ON_EN_CHANGE(IDC_ODBC_USERNAME, OnChangeOdbcUsername)
  55. //}}AFX_MSG_MAP
  56. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  57. ON_COMMAND(ID_HELP, DoHelp)
  58. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  59. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  60. END_MESSAGE_MAP()
  61. //---------------------------------------------------------------------------
  62. void CLogODBC::DoHelp()
  63. {
  64. WinHelp( HIDD_LOGUI_ODBC );
  65. }
  66. //--------------------------------------------------------------------------
  67. void CLogODBC::Init()
  68. {
  69. UpdateData( TRUE );
  70. DWORD dw;
  71. LPCTSTR pstr;
  72. // we will just be pulling stuff out of the metabase here
  73. // prepare the metabase wrapper
  74. CWrapMetaBase mbWrap;
  75. if ( !mbWrap.FInit(m_pMB) ) return;
  76. // open the target
  77. if ( mbWrap.Open( m_szMeta, METADATA_PERMISSION_READ ) )
  78. {
  79. // datasources
  80. pstr = (LPCTSTR)mbWrap.GetData( _T(""), MD_LOGSQL_DATA_SOURCES, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  81. if ( pstr )
  82. {
  83. m_sz_datasource = pstr;
  84. // free it
  85. mbWrap.FreeWrapData( (PVOID)pstr );
  86. }
  87. // password
  88. pstr = (LPCTSTR)mbWrap.GetData( _T(""), MD_LOGSQL_PASSWORD, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  89. if ( pstr )
  90. {
  91. m_sz_password = pstr;
  92. // free it
  93. mbWrap.FreeWrapData( (PVOID)pstr );
  94. m_szOrigPass = m_sz_password;
  95. if ( !m_sz_password.IsEmpty() )
  96. m_sz_password.LoadString( IDS_SHOWN_PASSWORD );
  97. }
  98. // table name
  99. pstr = (LPCTSTR)mbWrap.GetData( _T(""), MD_LOGSQL_TABLE_NAME, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  100. if ( pstr )
  101. {
  102. m_sz_table = pstr;
  103. // free it
  104. mbWrap.FreeWrapData( (PVOID)pstr );
  105. }
  106. // user name
  107. pstr = (LPCTSTR)mbWrap.GetData( _T(""), MD_LOGSQL_USER_NAME, IIS_MD_UT_SERVER, STRING_METADATA, &dw, METADATA_INHERIT );
  108. if ( pstr )
  109. {
  110. m_sz_username = pstr;
  111. // free it
  112. mbWrap.FreeWrapData( (PVOID)pstr );
  113. }
  114. // close the metabase
  115. mbWrap.Close();
  116. }
  117. // put the data into place
  118. UpdateData( FALSE );
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CLogODBC message handlers
  122. //--------------------------------------------------------------------------
  123. BOOL CLogODBC::OnApply()
  124. {
  125. BOOL f;
  126. UpdateData( TRUE );
  127. // confirm the password
  128. if ( m_bPassTyped )
  129. {
  130. CConfirmPassDlg dlgPass;
  131. dlgPass.m_szOrigPass = m_sz_password;
  132. if ( dlgPass.DoModal() != IDOK )
  133. {
  134. m_cedit_password.SetFocus();
  135. m_cedit_password.SetSel(0, -1);
  136. return FALSE;
  137. }
  138. }
  139. // prepare and open the metabase object
  140. CWrapMetaBase mb;
  141. if ( !mb.FInit(m_pMB) ) return FALSE;
  142. // open the target
  143. if ( OpenAndCreate( &mb, m_szMeta,
  144. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ, TRUE ) )
  145. {
  146. // prepare for the inheritence checks
  147. CCheckInheritList listInherit;
  148. f = SetMBString(&mb, &listInherit, _T(""), MD_LOGSQL_DATA_SOURCES,
  149. IIS_MD_UT_SERVER, m_sz_datasource, FALSE);
  150. if ( m_bPassTyped )
  151. {
  152. f = SetMBString(&mb, &listInherit, _T(""), MD_LOGSQL_PASSWORD,
  153. IIS_MD_UT_SERVER, m_sz_password, TRUE);
  154. }
  155. f = SetMBString(&mb, &listInherit, _T(""), MD_LOGSQL_TABLE_NAME,
  156. IIS_MD_UT_SERVER, m_sz_table, FALSE);
  157. f = SetMBString(&mb, &listInherit, _T(""), MD_LOGSQL_USER_NAME,
  158. IIS_MD_UT_SERVER, m_sz_username, FALSE);
  159. // close the metabase
  160. mb.Close();
  161. // do all the inheritence checks
  162. listInherit.CheckInheritence( m_szServer, m_szMeta );
  163. }
  164. // clear the modified flag
  165. SetModified( FALSE );
  166. // reset the internal password-typed flag
  167. m_szOrigPass = m_sz_password;
  168. m_bPassTyped = FALSE;
  169. return CPropertyPage::OnApply();
  170. }
  171. //--------------------------------------------------------------------------
  172. BOOL CLogODBC::OnSetActive()
  173. {
  174. if ( !m_fInitialized )
  175. {
  176. Init();
  177. m_fInitialized = TRUE;
  178. }
  179. return CPropertyPage::OnSetActive();
  180. }
  181. //--------------------------------------------------------------------------
  182. void CLogODBC::OnChangeOdbcDatasource()
  183. {
  184. SetModified();
  185. }
  186. //--------------------------------------------------------------------------
  187. void CLogODBC::OnChangeOdbcPassword()
  188. {
  189. m_bPassTyped = TRUE;
  190. SetModified();
  191. }
  192. //--------------------------------------------------------------------------
  193. void CLogODBC::OnChangeOdbcTable()
  194. {
  195. SetModified();
  196. }
  197. //--------------------------------------------------------------------------
  198. void CLogODBC::OnChangeOdbcUsername()
  199. {
  200. SetModified();
  201. }