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.

1961 lines
53 KiB

  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include "webservernode.h"
  4. #include "comp.h"
  5. #include "compdata.h"
  6. #include "dataobj.h"
  7. #include "globals.h"
  8. #include "resource.h"
  9. #include "uddi.h"
  10. #include "uddisitenode.h"
  11. #include "objectpicker.h"
  12. #include <htmlhelp.h>
  13. #include <windowsx.h>
  14. #include <commctrl.h>
  15. // {8ACBC688-ADDB-4298-9475-76AC4BF01FB1}
  16. const GUID CUDDIWebServerNode::thisGuid = { 0x8acbc688, 0xaddb, 0x4298, { 0x94, 0x75, 0x76, 0xac, 0x4b, 0xf0, 0x1f, 0xb1 } };
  17. //==============================================================
  18. //
  19. // CUDDIWebServerNode implementation
  20. //
  21. //
  22. CUDDIWebServerNode::CUDDIWebServerNode( const _TCHAR *szName, int id, CUDDISiteNode* parent, BOOL bExtension )
  23. : m_szName(NULL)
  24. , m_nId( id )
  25. , m_ppHandle( 0 )
  26. , m_isDeleted( FALSE )
  27. , m_pParent( parent )
  28. , m_pToolbar( NULL )
  29. , m_isScopeItem( TRUE )
  30. , m_bStdSvr( TRUE )
  31. , m_fDeleteFromScopePane( FALSE )
  32. , m_hwndPropSheet( NULL )
  33. {
  34. int iLen = _tcslen( szName ) + 1;
  35. m_szName = new _TCHAR[ iLen ];
  36. memset( m_szName, 0, iLen * sizeof( _TCHAR ) );
  37. _tcsncpy( m_szName, szName, iLen - 1 );
  38. m_bIsExtension = bExtension;
  39. GetData();
  40. BOOL bW3SvcRunning = IsW3SvcRunning();
  41. if( ( FALSE == bW3SvcRunning ) && IsRunning() )
  42. {
  43. Stop();
  44. m_mapProperties[ UDDI_RUN ] = _T("0");
  45. }
  46. }
  47. CUDDIWebServerNode::~CUDDIWebServerNode()
  48. {
  49. if( m_szName )
  50. {
  51. delete [] m_szName;
  52. }
  53. if( NULL != m_ppHandle )
  54. {
  55. MMCFreeNotifyHandle( m_ppHandle );
  56. }
  57. if( NULL != m_hwndPropSheet )
  58. {
  59. SendMessage( m_hwndPropSheet, WM_CLOSE, 0, 0 );
  60. }
  61. }
  62. HRESULT CUDDIWebServerNode::GetData()
  63. {
  64. try
  65. {
  66. //
  67. // Determine if the OS that this web server is running on is Windows Server 2003 Standard or not.
  68. //
  69. HRESULT hr = E_FAIL;
  70. hr = IsStandardServer( m_szName, &m_bStdSvr );
  71. if( FAILED(hr) )
  72. {
  73. THROW_UDDIEXCEPTION_ST( hr, IDS_DOT_NET_SERVER, g_hinst );
  74. }
  75. m_mapProperties.clear();
  76. CUDDIRegistryKey rootkey( _T( "SOFTWARE\\Microsoft\\UDDI"), KEY_READ, m_szName );
  77. _TCHAR szRun[ 35 ];
  78. m_mapProperties[ UDDI_RUN ] = _itot( rootkey.GetDWORD( _T("Run"), 1 ), szRun, 10 );
  79. m_mapProperties[ UDDI_SETUP_LOCATION ] = rootkey.GetString( _T("InstallRoot"), _T("") );
  80. rootkey.Close();
  81. CUDDIRegistryKey databasekey( _T( "SOFTWARE\\Microsoft\\UDDI\\Database"), KEY_READ, m_szName );
  82. m_mapProperties[ UDDI_READER_CXN ] = databasekey.GetString( _T("ReaderConnectionString"), _T("") );
  83. m_mapProperties[ UDDI_WRITER_CXN ] = databasekey.GetString( _T("WriterConnectionString"), _T("") );
  84. databasekey.Close();
  85. //
  86. // Ensure that the UDDI Site that this web server thinks it communicates
  87. // with is still installed.
  88. //
  89. tstring strDomain, strServer, strInstance;
  90. CrackConnectionString( m_mapProperties[ UDDI_WRITER_CXN ], strDomain, strServer, strInstance );
  91. if( !CUDDISiteNode::IsDatabaseServer( (PTCHAR)strServer.c_str() ) )
  92. {
  93. m_mapProperties[ UDDI_READER_CXN ] = _T( "" );
  94. m_mapProperties[ UDDI_WRITER_CXN ] = _T( "" );
  95. }
  96. _TCHAR szValue[ 100 ];
  97. _TCHAR szDefaultLogFile[ _MAX_PATH + 1 ];
  98. memset( szDefaultLogFile, 0, ( _MAX_PATH + 1 ) * sizeof( _TCHAR ) );
  99. GetSystemDirectory( szDefaultLogFile, _MAX_PATH );
  100. tstring strDefaultLogFile( szDefaultLogFile );
  101. strDefaultLogFile += _T( "\\LogFiles\\UDDI\\uddi.log" );
  102. try
  103. {
  104. CUDDIRegistryKey debugkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Debug"), KEY_READ, m_szName );
  105. m_mapProperties[ UDDI_EVENTLOG_LEVEL ] = _itot( debugkey.GetDWORD( _T("EventLogLevel"), 2 ), szValue, 10 );
  106. m_mapProperties[ UDDI_FILELOG_LEVEL ] = _itot( debugkey.GetDWORD( _T("FileLogLevel"), 0 ), szValue, 10 );
  107. m_mapProperties[ UDDI_LOG_FILENAME ] = debugkey.GetString( _T("LogFilename"), strDefaultLogFile.c_str() );
  108. debugkey.Close();
  109. }
  110. catch( ... )
  111. {
  112. m_mapProperties[ UDDI_EVENTLOG_LEVEL ] = _itot( 2, szValue, 10 );
  113. m_mapProperties[ UDDI_FILELOG_LEVEL ] = _itot( 0, szValue, 10 );
  114. m_mapProperties[ UDDI_LOG_FILENAME ] = strDefaultLogFile;
  115. }
  116. //
  117. // Get the setup information
  118. //
  119. CUDDIRegistryKey setupkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup"), KEY_READ, m_szName );
  120. m_mapProperties[ UDDI_SETUP_DB ] = _itot( setupkey.GetDWORD( _T("DBServer"), 0 ), szValue, 10 );
  121. m_mapProperties[ UDDI_SETUP_WEB ] = _itot( setupkey.GetDWORD( _T("WebServer"), 0 ), szValue, 10 );
  122. m_mapProperties[ UDDI_SETUP_ADMIN ] = _itot( setupkey.GetDWORD( _T("Admin"), 0 ), szValue, 10 );
  123. setupkey.Close();
  124. CUDDIRegistryKey webkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\WebServer"), KEY_READ, m_szName );
  125. m_mapProperties[ UDDI_SETUP_DATE ] = webkey.GetString( _T("InstallDate"), _T("") );
  126. m_mapProperties[ UDDI_SETUP_LANGUAGE ] = webkey.GetString( _T("ProductLanguage"), _T("") );
  127. m_mapProperties[ UDDI_SETUP_NAME ] = webkey.GetString( _T("ProductName"), _T("") );
  128. m_mapProperties[ UDDI_SETUP_FRAMEWORK_VERSION ] = webkey.GetString( _T("FrameworkVersion"), _T("") );
  129. m_mapProperties[ UDDI_SETUP_MANUFACTURER ] = webkey.GetString( _T("Manufacturer"), _T("") );
  130. m_mapProperties[ UDDI_SETUP_VERSION ] = webkey.GetString( _T("ProductVersion"), _T("") );
  131. webkey.Close();
  132. }
  133. catch(...)
  134. {
  135. return E_FAIL;
  136. }
  137. return S_OK;
  138. }
  139. const LPCTSTR CUDDIWebServerNode::GetName()
  140. {
  141. return m_szName;
  142. }
  143. BOOL
  144. CUDDIWebServerNode::ChildExists( const WCHAR *pwszName )
  145. {
  146. if( NULL == pwszName )
  147. {
  148. return FALSE;
  149. }
  150. wstring strWriterConn;
  151. GetWriterConnectionString( m_szName, strWriterConn );
  152. wstring strDomain, strServer, strInstance;
  153. CrackConnectionString( strWriterConn, strDomain, strServer, strInstance );
  154. return ( 0 == _wcsicmp( pwszName, strServer.c_str() ) ) ? TRUE : FALSE;
  155. }
  156. HRESULT CUDDIWebServerNode::SaveData()
  157. {
  158. try
  159. {
  160. //
  161. // Save the changed values
  162. //
  163. for( CPropertyMap::iterator iter = m_mapChanges.begin();
  164. iter != m_mapChanges.end(); iter++ )
  165. {
  166. if( _T("Database.ReaderConnectionString") == (*iter).first )
  167. {
  168. CUDDIRegistryKey databasekey( _T( "SOFTWARE\\Microsoft\\UDDI\\Database"), KEY_ALL_ACCESS, m_szName );
  169. databasekey.SetValue( _T( "ReaderConnectionString" ), m_mapChanges[ _T( "Database.ReaderConnectionString" ) ].c_str() );
  170. databasekey.Close();
  171. }
  172. else if( UDDI_WRITER_CXN == (*iter).first )
  173. {
  174. CUDDIRegistryKey databasekey( _T( "SOFTWARE\\Microsoft\\UDDI\\Database"), KEY_ALL_ACCESS, m_szName );
  175. databasekey.SetValue( _T( "WriterConnectionString" ), m_mapChanges[ _T( "Database.WriterConnectionString" ) ].c_str() );
  176. databasekey.Close();
  177. }
  178. else if(UDDI_EVENTLOG_LEVEL == (*iter).first )
  179. {
  180. DWORD dwValue = _ttoi( m_mapChanges[ UDDI_EVENTLOG_LEVEL ].c_str() );
  181. UDDIASSERT( dwValue < 7 );
  182. CUDDIRegistryKey debugkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Debug"), KEY_ALL_ACCESS, m_szName );
  183. debugkey.SetValue( _T("EventLogLevel"), dwValue );
  184. debugkey.Close();
  185. }
  186. else if( (*iter).first == UDDI_FILELOG_LEVEL )
  187. {
  188. DWORD dwValue = _ttoi( m_mapChanges[ UDDI_FILELOG_LEVEL ].c_str() );
  189. UDDIASSERT( dwValue < 7 );
  190. CUDDIRegistryKey debugkey( _T( "SOFTWARE\\Microsoft\\UDDI\\Debug"), KEY_ALL_ACCESS, m_szName );
  191. debugkey.SetValue( _T("FileLogLevel"), dwValue );
  192. debugkey.Close();
  193. }
  194. }
  195. //
  196. // Clear the changes collection
  197. //
  198. m_mapChanges.clear();
  199. }
  200. catch(...)
  201. {
  202. return E_FAIL;
  203. }
  204. return S_OK;
  205. }
  206. BOOL CUDDIWebServerNode::IsWebServer( const WCHAR *pwszName )
  207. {
  208. if( ( NULL == pwszName ) || ( 0 == _tcslen( pwszName ) ) )
  209. {
  210. return FALSE;
  211. }
  212. try
  213. {
  214. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup" ), KEY_READ, pwszName );
  215. DWORD dwDB = key.GetDWORD( _T( "WebServer" ) );
  216. return TRUE;
  217. }
  218. catch(...)
  219. {
  220. return FALSE;
  221. }
  222. }
  223. BOOL CUDDIWebServerNode::Start()
  224. {
  225. return SetRunState( TRUE );
  226. }
  227. BOOL CUDDIWebServerNode::SetRunState( BOOL bStart )
  228. {
  229. try
  230. {
  231. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI" ), KEY_ALL_ACCESS, m_szName );
  232. key.SetValue( _T("Run"), bStart ? 1UL : 0UL );
  233. }
  234. catch(...)
  235. {
  236. return FALSE;
  237. }
  238. return TRUE;
  239. }
  240. BOOL CUDDIWebServerNode::Stop()
  241. {
  242. return SetRunState( FALSE );
  243. }
  244. const BOOL CUDDIWebServerNode::IsRunning()
  245. {
  246. CPropertyMap::const_iterator it = m_mapProperties.find( UDDI_RUN );
  247. if( m_mapProperties.end() == it )
  248. {
  249. return FALSE;
  250. }
  251. else
  252. {
  253. return ( _T("0") == it->second ) ? FALSE : TRUE;
  254. }
  255. }
  256. const _TCHAR *CUDDIWebServerNode::GetDisplayName( int nCol )
  257. {
  258. _TCHAR szRunning[ 256 ];
  259. memset( szRunning, 0, 256 * sizeof( _TCHAR ) );
  260. ::LoadString( g_hinst, IDS_WEBSERVER_RUNNING, szRunning, ARRAYLEN(szRunning) );
  261. _TCHAR szStopped[ 256 ];
  262. memset( szStopped, 0, 256 * sizeof( _TCHAR ) );
  263. ::LoadString( g_hinst, IDS_WEBSERVER_STOPPED, szStopped, ARRAYLEN(szStopped) );
  264. BOOL bIsRunning = IsRunning();
  265. switch( nCol )
  266. {
  267. case 0:
  268. {
  269. m_strDisplayName = m_szName;
  270. if( !bIsRunning )
  271. {
  272. m_strDisplayName += _T(" (");
  273. m_strDisplayName += szStopped;
  274. m_strDisplayName += _T(")");
  275. }
  276. break;
  277. }
  278. case 1:
  279. {
  280. m_strDisplayName = bIsRunning ? szRunning : szStopped;
  281. break;
  282. }
  283. default:
  284. m_strDisplayName = _T("");
  285. }
  286. return m_strDisplayName.c_str();
  287. }
  288. //
  289. // Handle anything special when the user clicks Apply or Ok
  290. // on the property sheet. This sample directly accesses the
  291. // operated-on object, so there's nothing special to do...
  292. // ...except to update all views
  293. //
  294. HRESULT CUDDIWebServerNode::OnPropertyChange( IConsole *pConsole, CComponent *pComponent )
  295. {
  296. HRESULT hr = S_FALSE;
  297. CPropertyMap::iterator it = m_mapChanges.find( UDDI_WRITER_CXN );
  298. BOOL fWriterChanged = ( m_mapChanges.end() == it ) ? FALSE : TRUE;
  299. if( TRUE == fWriterChanged )
  300. {
  301. wstring strDomain, strServer, strInstance;
  302. CUDDIWebServerNode::CrackConnectionString( m_mapChanges[ UDDI_WRITER_CXN ], strDomain, strServer, strInstance );
  303. HWND hwndConsole = NULL;
  304. pConsole->GetMainWindow( &hwndConsole );
  305. BOOL fSuccess = CUDDISiteNode::AddWebServerToSite( strServer,
  306. m_szName,
  307. ( NULL == m_hwndPropSheet ) ? hwndConsole : m_hwndPropSheet );
  308. if( fSuccess )
  309. {
  310. m_fDeleteFromScopePane = TRUE;
  311. //
  312. // If our parent pointer is not NULL, then this web server node is the child of
  313. // a UDDI Site node.
  314. //
  315. // If our parent pointer is NULL, then this web server node is a child of the
  316. // UDDI Services node.
  317. //
  318. if( NULL != m_pParent )
  319. {
  320. CUDDIServicesNode *pStaticNode = m_pParent->GetStaticNode();
  321. if( NULL != pStaticNode )
  322. {
  323. CUDDISiteNode *pSiteNode = reinterpret_cast<CUDDISiteNode *>( pStaticNode->FindChild( strServer.c_str() ) );
  324. if( NULL != pSiteNode )
  325. {
  326. pSiteNode->AddChild( m_szName, pConsole );
  327. }
  328. }
  329. }
  330. else
  331. {
  332. HSCOPEITEM hsiParent = GetParentScopeItem();
  333. IConsoleNameSpace *pNS = NULL;
  334. hr = pConsole->QueryInterface( IID_IConsoleNameSpace, reinterpret_cast<void **>( &pNS ) );
  335. if( FAILED(hr) )
  336. {
  337. return hr;
  338. }
  339. SCOPEDATAITEM sdi;
  340. memset( &sdi, 0, sizeof( SCOPEDATAITEM ) );
  341. sdi.ID = hsiParent;
  342. sdi.mask = SDI_PARAM;
  343. hr = pNS->GetItem( &sdi );
  344. if( FAILED(hr) )
  345. {
  346. pNS->Release();
  347. return hr;
  348. }
  349. pNS->Release();
  350. CUDDIServicesNode *pStaticNode = (CUDDIServicesNode *)sdi.lParam;
  351. CUDDISiteNode *pSiteNode = reinterpret_cast<CUDDISiteNode *>( pStaticNode->FindChild( strServer.c_str() ) );
  352. if( NULL != pSiteNode )
  353. {
  354. pSiteNode->AddChild( m_szName, pConsole );
  355. }
  356. DeleteFromScopePane( pNS );
  357. }
  358. }
  359. }
  360. //
  361. // The SaveData() method communicates any issues.
  362. //
  363. hr = SaveData();
  364. hr = pConsole->UpdateAllViews( NULL, GetScopeItemValue(), 0 );
  365. _ASSERT( S_OK == hr);
  366. return hr;
  367. }
  368. HRESULT
  369. CUDDIWebServerNode::OnSelect( CComponent *pComponent, IConsole *pConsole, BOOL bScope, BOOL bSelect )
  370. {
  371. if( ( NULL == pComponent ) || ( NULL == pConsole ) )
  372. {
  373. return E_INVALIDARG;
  374. }
  375. HRESULT hr = E_FAIL;
  376. if( bSelect )
  377. {
  378. //
  379. // Enable refresh, and delete verbs
  380. //
  381. IConsoleVerb *pConsoleVerb = NULL;
  382. hr = pConsole->QueryConsoleVerb( &pConsoleVerb );
  383. if( FAILED(hr) )
  384. {
  385. return hr;
  386. }
  387. hr = pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  388. if( !IsExtension() && !m_bStdSvr )
  389. {
  390. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  391. _ASSERT( S_OK == hr );
  392. }
  393. //
  394. // Can't get to properties (via the standard methods) unless
  395. // we tell MMC to display the Properties menu item and
  396. // toolbar button, this will give the user a visual cue that
  397. // there's "something" to do
  398. //
  399. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  400. //
  401. // Also set MMC_VERB_PROPERTIES as the default verb
  402. //
  403. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  404. pConsoleVerb->Release();
  405. }
  406. return S_FALSE;
  407. }
  408. BOOL CALLBACK CUDDIWebServerNode::GeneralDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  409. {
  410. switch( uMsg )
  411. {
  412. case WM_INITDIALOG:
  413. {
  414. CUDDIWebServerNode *pWebServer = NULL;
  415. pWebServer = reinterpret_cast<CUDDIWebServerNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  416. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR)pWebServer );
  417. CPropertyMap& m_mapProperties = pWebServer->m_mapProperties;
  418. _TCHAR szComponentName[ 256 ];
  419. HWND hwndParent = GetParent( hwndDlg );
  420. pWebServer->m_hwndPropSheet = hwndParent;
  421. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_INSTALL_DATE, LocalizedDate( m_mapProperties[ UDDI_SETUP_DATE ] ).c_str() );
  422. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_UDDI_LANGUAGE, m_mapProperties[ UDDI_SETUP_LANGUAGE ].c_str() );
  423. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_FRAMEWORK_VERSION, m_mapProperties[ UDDI_SETUP_FRAMEWORK_VERSION ].c_str() );
  424. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_UDDI_VERSION, m_mapProperties[ UDDI_SETUP_VERSION ].c_str() );
  425. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_INSTALL_LOCATION, m_mapProperties[ UDDI_SETUP_LOCATION ].c_str() );
  426. //
  427. // Build up "Web Server Component on <computername>" string for heading
  428. //
  429. LoadString( g_hinst, IDS_WEBSERVER_DISPLAYNAME_TEMPLATE, szComponentName, ARRAYLEN( szComponentName ) - 1 );
  430. WCHAR wszBuf[ 512 ];
  431. memset( wszBuf, 0, 512 * sizeof( WCHAR ) );
  432. _sntprintf( wszBuf, 512, szComponentName, pWebServer->m_szName );
  433. wszBuf[ 511 ] = 0x00;
  434. tstring strDisplayName ( wszBuf );
  435. SetDlgItemText( hwndDlg, IDC_GENERAL_SITE_TXT_DISPLAYNAME, strDisplayName.c_str() );
  436. if( _T("1") == m_mapProperties[ UDDI_SETUP_WEB ] )
  437. {
  438. LoadString( g_hinst, IDS_WEBSERVER_COMPONENT_DESCRIPTION, szComponentName, ARRAYLEN( szComponentName ) - 1 );
  439. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szComponentName );
  440. }
  441. if( _T("1") == m_mapProperties[ UDDI_SETUP_DB ] )
  442. {
  443. LoadString( g_hinst, IDS_DATABASE_SERVER_COMPONENT_DESCRIPTION, szComponentName, ARRAYLEN( szComponentName ) - 1 );
  444. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szComponentName );
  445. }
  446. if( _T("1") == m_mapProperties[ UDDI_SETUP_ADMIN ] )
  447. {
  448. LoadString( g_hinst, IDS_UDDIMMC_COMPONENT_DESCRIPTION, szComponentName, ARRAYLEN( szComponentName ) - 1 );
  449. ListBox_AddString( GetDlgItem( hwndDlg, IDC_GENERAL_SITE_LIST_SERVICES ), szComponentName );
  450. }
  451. }
  452. break;
  453. case WM_NOTIFY:
  454. {
  455. if( PSN_HELP == ((NMHDR *) lParam)->code )
  456. {
  457. CUDDIWebServerNode *pWebServer = (CUDDIWebServerNode *)GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  458. if( NULL != pWebServer )
  459. {
  460. wstring strHelp( pWebServer->GetHelpFile() );
  461. strHelp += g_wszUddiWebGeneralPageHelp;
  462. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  463. }
  464. }
  465. break;
  466. }
  467. case WM_CLOSE:
  468. {
  469. CUDDIWebServerNode *pWebServer = (CUDDIWebServerNode *)GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  470. if( NULL != pWebServer )
  471. {
  472. pWebServer->m_hwndPropSheet = NULL;
  473. }
  474. break;
  475. }
  476. case WM_HELP:
  477. {
  478. CUDDIWebServerNode *pWebServer = (CUDDIWebServerNode *)GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  479. if( NULL != pWebServer )
  480. {
  481. wstring strHelp( pWebServer->GetHelpFile() );
  482. strHelp += g_wszUddiWebGeneralPageHelp;
  483. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  484. }
  485. }
  486. break;
  487. }
  488. return FALSE;
  489. }
  490. int split( const TCHAR * pszConnection, TCHAR *pszA, TCHAR *pszB, TCHAR *pszC )
  491. {
  492. //
  493. // Example: Data Source=localhost;Initial Catalog=uddi;Integrated Security=SSPI
  494. //
  495. TCHAR strConnection[ 512 ];
  496. strConnection[ 0 ] = 0x00;
  497. _tcsncpy( strConnection, pszConnection, 512 );
  498. strConnection[ 511 ] = 0x00;
  499. _tcslwr( strConnection );
  500. //
  501. // Get Data Source value
  502. //
  503. PTCHAR begin = _tcsstr( strConnection, _T("data source=") );
  504. _ASSERT( begin );
  505. begin += 12;
  506. PTCHAR end = begin;
  507. int n = 0;
  508. BOOL bDone = FALSE;
  509. while( !bDone )
  510. {
  511. if( _T('\\') == *end )
  512. {
  513. if( 0 == n )
  514. {
  515. _tcsncpy( pszA, begin, end - begin );
  516. pszA[ end - begin ] = NULL;
  517. }
  518. else if( 1 == n )
  519. {
  520. _tcsncpy( pszB, begin, end - begin );
  521. pszB[ end - begin ] = NULL;
  522. }
  523. else
  524. {
  525. _tcsncpy( pszC, begin, end - begin );
  526. pszC[ end - begin ] = NULL;
  527. }
  528. begin = end + 1;
  529. end++;
  530. n++;
  531. }
  532. else if( NULL == *end || _T(';') == *end )
  533. {
  534. if( 0 == n )
  535. {
  536. _tcsncpy( pszA, begin, end - begin );
  537. pszA[ end - begin ] = NULL;
  538. }
  539. else if( 1 == n )
  540. {
  541. _tcsncpy( pszB, begin, end - begin );
  542. pszB[ end - begin ] = NULL;
  543. }
  544. else
  545. {
  546. _tcsncpy( pszC, begin, end - begin );
  547. pszC[ end - begin ] = NULL;
  548. }
  549. bDone = TRUE;
  550. n++;
  551. }
  552. else
  553. {
  554. end++;
  555. }
  556. }
  557. return n;
  558. }
  559. //
  560. // Cases:
  561. // 1. <domain>\<machine>\<instance>
  562. //
  563. // 2. <domain>\<machine>
  564. //
  565. // 3. <machine>\<instance>
  566. //
  567. // 4. <machine>
  568. //
  569. void
  570. CUDDIWebServerNode::CrackConnectionString( const tstring& strConnection, tstring& strDomain, tstring& strServer, tstring& strInstance )
  571. {
  572. if( 0 == strConnection.length() )
  573. {
  574. strDomain = _T( "" );
  575. strServer = _T( "" );
  576. strInstance = _T( "" );
  577. return;
  578. }
  579. // TCHAR *pstrs[3] = { new TCHAR[ 256 ], new TCHAR[ 256 ], new TCHAR[ 256 ] };
  580. TCHAR *pszA, *pszB, *pszC;
  581. pszA = new TCHAR[ 256 ];
  582. pszB = new TCHAR[ 256 ];
  583. pszC = new TCHAR[ 256 ];
  584. if( ( NULL == pszA ) || ( NULL == pszB ) || ( NULL == pszC ) )
  585. {
  586. strDomain = _T( "" );
  587. strServer = _T( "" );
  588. strInstance = _T( "" );
  589. return;
  590. }
  591. memset( pszA, 0, 256 * sizeof( TCHAR ) );
  592. memset( pszB, 0, 256 * sizeof( TCHAR ) );
  593. memset( pszC, 0, 256 * sizeof( TCHAR ) );
  594. _TCHAR szConnection[ 512 ];
  595. memset( szConnection, 0, 512 * sizeof( TCHAR ) );
  596. _tcscpy( szConnection, strConnection.c_str() );
  597. int n = split( szConnection, pszA, pszB, pszC );
  598. if( 1 == n )
  599. {
  600. //
  601. // Case 4: <machine>
  602. //
  603. strDomain = _T("");
  604. strServer = pszA;
  605. strInstance = _T("");
  606. }
  607. else if( 3 == n )
  608. {
  609. //
  610. // Case 1 <domain>\<machine>\<instancename>
  611. //
  612. strDomain = pszA;
  613. strServer = pszB;
  614. strInstance = pszC;
  615. }
  616. else
  617. {
  618. //
  619. // TODO: Write code to determine between case 2 and case 3
  620. //
  621. // Assume case 3: <machine>\<instancename>
  622. //
  623. strDomain = _T("");
  624. strServer = pszA;
  625. strInstance = pszB;
  626. }
  627. delete [] pszA;
  628. delete [] pszB;
  629. delete [] pszC;
  630. return;
  631. }
  632. struct DatabaseConnectionData
  633. {
  634. DatabaseConnectionData( CUDDIWebServerNode *pWeb )
  635. : pWebServer( pWeb )
  636. , bReadChanged( false )
  637. , bWriteChanged( false ){}
  638. bool bReadChanged;
  639. bool bWriteChanged;
  640. CUDDIWebServerNode *pWebServer;
  641. };
  642. tstring
  643. CUDDIWebServerNode::BuildConnectionString( const wstring& strComputer )
  644. {
  645. try
  646. {
  647. tstring strInstanceName;
  648. BOOL fSuccess = CUDDISiteNode::GetFullyQualifiedInstanceName( strComputer.c_str(), strInstanceName );
  649. if( !fSuccess )
  650. {
  651. return _T( "" );
  652. }
  653. tstring strConnection( _T("Data Source=") );
  654. strConnection += strInstanceName;
  655. strConnection += _T(";Initial Catalog=uddi;Integrated Security=SSPI");
  656. return strConnection;
  657. }
  658. catch( ... )
  659. {
  660. return _T( "" );
  661. }
  662. }
  663. BOOL CALLBACK CUDDIWebServerNode::DatabaseConnectionDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  664. {
  665. switch( uMsg )
  666. {
  667. case WM_INITDIALOG:
  668. {
  669. //
  670. // Load up the "not found" strings in case of a future failure
  671. //
  672. TCHAR szNoServer[ 256 ],
  673. szNoInstance[ 256 ];
  674. ZeroMemory( szNoServer, sizeof szNoServer );
  675. ZeroMemory( szNoInstance, sizeof szNoInstance );
  676. LoadString( g_hinst, IDS_UDDIMMC_NODBSERVER, szNoServer, ARRAYLEN( szNoServer ) - 1 );
  677. LoadString( g_hinst, IDS_UDDIMMC_NOINSTANCE, szNoInstance, ARRAYLEN( szNoInstance ) - 1 );
  678. //
  679. // Catch the "this" pointer so we can actually operate on the object
  680. //
  681. CUDDIWebServerNode *pWebServer = reinterpret_cast<CUDDIWebServerNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  682. DatabaseConnectionData* pdata = new DatabaseConnectionData( pWebServer );
  683. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR) pdata );
  684. //
  685. // User can select a new database to read from/write to ONLY if the machine the web server
  686. // is running on is NOT Windows Server 2003 Standard Server.
  687. //
  688. // EnableWindow( GetDlgItem( hwndDlg, IDC_DB_CONNECTION_BTN_READER_SELECT ), pWebServer->m_bStdSvr ? FALSE : TRUE );
  689. EnableWindow( GetDlgItem( hwndDlg, IDC_DB_CONNECTION_BTN_WRITER_SELECT ), pWebServer->m_bStdSvr ? FALSE : TRUE );
  690. //
  691. // For Heartland RC2, we are removing the distinction between reader &
  692. // writer connection strings. There can be only 1 connection string,
  693. // so we will use just the writer.
  694. //
  695. EnableWindow( GetDlgItem( hwndDlg, IDC_DB_CONNECTION_BTN_READER_SELECT ), FALSE );
  696. //
  697. // Example: Data Source=localhost;Initial Catalog=uddi;Integrated Security=SSPI
  698. //
  699. tstring strDomain, strMachine, strInstance;
  700. tstring strReaderConn = pWebServer->m_mapProperties[ UDDI_READER_CXN ];
  701. tstring strWriterConn = pWebServer->m_mapProperties[ UDDI_WRITER_CXN ];
  702. if( strReaderConn.empty() )
  703. {
  704. strMachine = szNoServer;
  705. strInstance = szNoInstance;
  706. }
  707. else
  708. {
  709. CrackConnectionString( strReaderConn, strDomain, strMachine, strInstance );
  710. }
  711. tstring strServer( _T("") );
  712. if( !strDomain.empty() )
  713. {
  714. strServer = strDomain;
  715. strServer += _T("\\");
  716. strServer += strMachine;
  717. }
  718. else
  719. {
  720. strServer = strMachine;
  721. }
  722. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_SERVER, strServer.c_str() );
  723. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_INSTANCE, strInstance.empty() ? DefaultInstanceDisplayName() : strInstance.c_str() );
  724. if( strWriterConn.empty() )
  725. {
  726. strMachine = szNoServer;
  727. strInstance = szNoInstance;
  728. }
  729. else
  730. {
  731. CrackConnectionString( strWriterConn, strDomain, strMachine, strInstance );
  732. }
  733. if( !strDomain.empty() )
  734. {
  735. strServer = strDomain;
  736. strServer += _T("\\");
  737. strServer += strMachine;
  738. }
  739. else
  740. {
  741. strServer = strMachine;
  742. }
  743. CUDDISiteNode::GetFullyQualifiedInstanceName( strServer.c_str(), strInstance );
  744. WCHAR wszServer[ 128 ];
  745. WCHAR wszInstance[ 256 ];
  746. memset( wszServer, 0, 128 * sizeof( WCHAR ) );
  747. memset( wszInstance, 0, 256 * sizeof( WCHAR ) );
  748. wcsncpy( wszServer, strServer.c_str(), strServer.length() );
  749. wcsncpy( wszInstance, strInstance.c_str(), strInstance.length() );
  750. ToUpper( wszServer );
  751. ToUpper( wszInstance );
  752. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_SERVER, wszServer );
  753. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_INSTANCE, wszInstance );
  754. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_SERVER, wszServer );
  755. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_INSTANCE, wszInstance );
  756. }
  757. break;
  758. case WM_COMMAND:
  759. {
  760. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  761. switch( LOWORD(wParam) )
  762. {
  763. case IDC_DB_CONNECTION_BTN_READER_SELECT:
  764. {
  765. DatabaseData data;
  766. data.pBase = pdata->pWebServer;
  767. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_SITE_CONNECT ), hwndDlg, CUDDISiteNode::NewDatabaseServerDialogProc, (LPARAM) &data );
  768. if( nResult )
  769. {
  770. //
  771. // The user is not allowed to point the connection strings to a database
  772. // instance running on a Windows Server 2003 Standard machine. So, tell them so.
  773. //
  774. BOOL bIsStandard = TRUE;
  775. HRESULT hr = ::IsStandardServer( data.szServerName, &bIsStandard );
  776. if( FAILED(hr) )
  777. {
  778. UDDIMsgBox( hwndDlg,
  779. IDS_DOT_NET_SERVER,
  780. IDS_ERROR_TITLE,
  781. MB_ICONEXCLAMATION | MB_OK );
  782. break;
  783. }
  784. if( TRUE == bIsStandard )
  785. {
  786. UDDIMsgBox( hwndDlg,
  787. IDS_DATABASE_STANDARD_SERVER_DETAIL,
  788. IDS_DATABASE_STANDARD_SERVER,
  789. MB_ICONEXCLAMATION | MB_OK );
  790. }
  791. else
  792. {
  793. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_SERVER, data.szServerName );
  794. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_INSTANCE, InstanceDisplayName(data.szInstanceName) );
  795. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  796. pdata->bReadChanged = true;
  797. }
  798. }
  799. break;
  800. }
  801. case IDC_DB_CONNECTION_BTN_WRITER_SELECT:
  802. {
  803. DatabaseData data;
  804. data.pBase = pdata->pWebServer;
  805. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_SITE_CONNECT ), hwndDlg, CUDDISiteNode::NewDatabaseServerDialogProc, (LPARAM) &data );
  806. if( nResult )
  807. {
  808. //
  809. // The user is not allowed to point the connection strings to a database
  810. // instance running on a Windows Server 2003 Standard machine. So, tell them so.
  811. //
  812. BOOL bIsStandard = TRUE;
  813. HRESULT hr = ::IsStandardServer( data.szServerName, &bIsStandard );
  814. if( FAILED(hr) )
  815. {
  816. UDDIMsgBox( hwndDlg,
  817. IDS_DOT_NET_SERVER,
  818. IDS_ERROR_TITLE,
  819. MB_ICONEXCLAMATION | MB_OK );
  820. break;
  821. }
  822. if( TRUE == bIsStandard )
  823. {
  824. UDDIMsgBox( hwndDlg,
  825. IDS_DATABASE_STANDARD_SERVER_DETAIL,
  826. IDS_DATABASE_STANDARD_SERVER,
  827. MB_ICONEXCLAMATION | MB_OK );
  828. }
  829. else
  830. {
  831. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_SERVER, data.szServerName );
  832. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_INSTANCE, InstanceDisplayName(data.szInstanceName) );
  833. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_SERVER, data.szServerName );
  834. SetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_INSTANCE, InstanceDisplayName(data.szInstanceName) );
  835. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM) hwndDlg, 0 );
  836. pdata->bWriteChanged = true;
  837. }
  838. }
  839. break;
  840. }
  841. }
  842. }
  843. break;
  844. case WM_HELP:
  845. {
  846. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  847. wstring strHelp( pdata->pWebServer->GetHelpFile() );
  848. strHelp += g_wszUddiDatabaseConnectionPageHelp;
  849. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  850. break;
  851. }
  852. case WM_DESTROY:
  853. {
  854. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  855. //
  856. // Tell MMC that we're done with the property sheet (we got this
  857. // handle in CreatePropertyPages
  858. //
  859. MMCFreeNotifyHandle( pdata->pWebServer->m_ppHandle );
  860. pdata->pWebServer->m_ppHandle = NULL;
  861. delete pdata;
  862. break;
  863. }
  864. case WM_NOTIFY:
  865. if( PSN_APPLY == ((NMHDR *) lParam)->code )
  866. {
  867. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  868. if( pdata->bReadChanged )
  869. {
  870. _TCHAR szComputer[ 256 ];
  871. _TCHAR szInstance[ 256 ];
  872. GetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_SERVER, szComputer, ARRAYLEN( szComputer ) );
  873. GetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_READER_INSTANCE, szInstance, ARRAYLEN( szInstance ) );
  874. pdata->pWebServer->m_mapChanges[ UDDI_READER_CXN ] = BuildConnectionString( szComputer );
  875. }
  876. if( pdata->bWriteChanged )
  877. {
  878. _TCHAR szComputer[ 256 ];
  879. _TCHAR szInstance[ 256 ];
  880. GetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_SERVER, szComputer, ARRAYLEN( szComputer ) );
  881. GetDlgItemText( hwndDlg, IDC_DB_CONNECTION_TXT_WRITER_INSTANCE, szInstance, ARRAYLEN( szInstance ) );
  882. pdata->pWebServer->m_mapChanges[ UDDI_WRITER_CXN ] = BuildConnectionString( szComputer );
  883. }
  884. //
  885. // Ask MMC to send us a message (on the main thread) so
  886. // we know the Apply button was clicked.
  887. //
  888. HRESULT hr = MMCPropertyChangeNotify( pdata->pWebServer->m_ppHandle, reinterpret_cast<LONG_PTR>(pdata->pWebServer) );
  889. _ASSERT( SUCCEEDED(hr) );
  890. //
  891. // Reset the window data after migration to the change collection
  892. //
  893. pdata->bReadChanged = false;
  894. pdata->bWriteChanged = false;
  895. return PSNRET_NOERROR;
  896. }
  897. else if( PSN_HELP == ((NMHDR *) lParam)->code )
  898. {
  899. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  900. wstring strHelp( pdata->pWebServer->GetHelpFile() );
  901. strHelp += g_wszUddiDatabaseConnectionPageHelp;
  902. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  903. }
  904. break;
  905. }
  906. return FALSE;
  907. }
  908. HRESULT CUDDIWebServerNode::HasPropertySheets()
  909. {
  910. //
  911. // Say "yes" when MMC asks if we have pages
  912. //
  913. return S_OK;
  914. }
  915. HRESULT CUDDIWebServerNode::CreatePropertyPages( IPropertySheetCallback *lpProvider, LONG_PTR handle )
  916. {
  917. if( ( NULL == lpProvider ) || ( 0 == handle ) )
  918. {
  919. return E_INVALIDARG;
  920. }
  921. //
  922. // Reinitialize the data before we display the property pages
  923. //
  924. HRESULT hr = GetData();
  925. _ASSERT( SUCCEEDED( hr ) );
  926. PropertyPages pps[] = {
  927. { IDD_GENERAL_WEB_PROPPAGE, GeneralDialogProc },
  928. { IDD_LOGGING_PROPPAGE, LoggingDialogProc },
  929. { IDD_DB_CONNECTION_PROPPAGE, DatabaseConnectionDialogProc } };
  930. PROPSHEETPAGE psp;
  931. HPROPSHEETPAGE hPage = NULL;
  932. //
  933. // Cache this handle so we can call MMCPropertyChangeNotify
  934. //
  935. m_ppHandle = handle;
  936. //
  937. // Create the property page for this node.
  938. // NOTE: if your node has multiple pages, put the following
  939. // in a loop and create multiple pages calling
  940. // lpProvider->AddPage() for each page.
  941. //
  942. psp.dwSize = sizeof(PROPSHEETPAGE);
  943. psp.dwFlags = PSP_DEFAULT | PSP_HASHELP;
  944. psp.hInstance = g_hinst;
  945. psp.lParam = reinterpret_cast<LPARAM>(this);
  946. for( int i = 0; i < ARRAYLEN( pps ); i++ )
  947. {
  948. psp.pszTemplate = MAKEINTRESOURCE( pps[ i ].id );
  949. psp.pfnDlgProc = pps[ i ].dlgproc;
  950. hPage = CreatePropertySheetPage( &psp );
  951. _ASSERT( hPage );
  952. hr = lpProvider->AddPage( hPage );
  953. if( FAILED(hr) )
  954. {
  955. break;
  956. }
  957. }
  958. return hr;
  959. }
  960. HRESULT
  961. CUDDIWebServerNode::GetWatermarks(HBITMAP *lphWatermark,
  962. HBITMAP *lphHeader,
  963. HPALETTE *lphPalette,
  964. BOOL *bStretch)
  965. {
  966. return S_FALSE;
  967. }
  968. HRESULT
  969. CUDDIWebServerNode::OnUpdateItem( IConsole *pConsole, long item, ITEM_TYPE itemtype )
  970. {
  971. if( NULL == pConsole )
  972. {
  973. return E_INVALIDARG;
  974. }
  975. HRESULT hr = S_OK;
  976. hr = UpdateScopePaneItem( pConsole, GetScopeItemValue() );
  977. _ASSERT( S_OK == hr );
  978. return hr;
  979. }
  980. HRESULT
  981. CUDDIWebServerNode::OnRefresh( IConsole *pConsole )
  982. {
  983. if( TRUE == m_fDeleteFromScopePane )
  984. {
  985. IConsoleNameSpace *pNS = NULL;
  986. HRESULT hr = pConsole->QueryInterface( IID_IConsoleNameSpace, reinterpret_cast<void **>( &pNS ) );
  987. if( FAILED(hr) )
  988. {
  989. return hr;
  990. }
  991. DeleteFromScopePane( pNS );
  992. pNS->Release();
  993. return S_OK;
  994. }
  995. //
  996. // The web server that this node represents might very well live on
  997. // some other machine. The state of that web server might have changed
  998. // since the last time we queried it... ie, m_mapProperties might be
  999. // out of sync with the true state of the web server. So, re-get the
  1000. // web server's info.
  1001. //
  1002. GetData();
  1003. BOOL bW3SvcRunning = IsW3SvcRunning();
  1004. if( ( FALSE == bW3SvcRunning ) && IsRunning() )
  1005. {
  1006. Stop();
  1007. m_mapProperties[ UDDI_RUN ] = _T("0");
  1008. }
  1009. //
  1010. // Call IConsole::UpdateAllViews to redraw all views
  1011. // owned by the parent scope item
  1012. //
  1013. LPDATAOBJECT lpDataObj = new CDataObject( (MMC_COOKIE)this, CCT_SCOPE );
  1014. HRESULT hr;
  1015. UPDATE_VIEWS_HINT hint = ( TRUE == m_isScopeItem ) ? UPDATE_SCOPEITEM : UPDATE_RESULTITEM;
  1016. hr = pConsole->UpdateAllViews( lpDataObj, GetScopeItemValue(), hint );
  1017. _ASSERT( S_OK == hr);
  1018. return hr;
  1019. }
  1020. HRESULT
  1021. CUDDIWebServerNode::OnDelete( IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsoleComp )
  1022. {
  1023. DeleteFromScopePane( pConsoleNameSpace );
  1024. m_mapChanges[ UDDI_WRITER_CXN ] = _T("");
  1025. m_mapChanges[ UDDI_READER_CXN ] = _T("");
  1026. SaveData();
  1027. GetData();
  1028. //
  1029. // Now set isDeleted member so that the parent doesn't try to
  1030. // to insert it again in CUDDIServicesNode::OnShow. Admittedly, a hack...
  1031. //
  1032. m_isDeleted = TRUE;
  1033. m_pParent->OnDeleteChild( m_szName );
  1034. return S_OK;
  1035. }
  1036. HRESULT
  1037. CUDDIWebServerNode::OnSetToolbar( IControlbar *pControlbar, IToolbar *pToolbar, BOOL bScope, BOOL bSelect )
  1038. {
  1039. HRESULT hr = S_OK;
  1040. if( bSelect )
  1041. {
  1042. pToolbar->SetButtonState( ID_BUTTONSTOP, BUTTONPRESSED, !IsRunning() );
  1043. pToolbar->SetButtonState( ID_BUTTONSTART, BUTTONPRESSED, IsRunning() );
  1044. pToolbar->SetButtonState( ID_BUTTONSTART, ENABLED, !IsRunning() && IsW3SvcRunning() );
  1045. pToolbar->SetButtonState( ID_BUTTONSTOP, ENABLED, IsRunning() || !IsW3SvcRunning() );
  1046. //
  1047. // Always make sure the menuButton is attached
  1048. //
  1049. hr = pControlbar->Attach( TOOLBAR, pToolbar );
  1050. m_isScopeItem = bScope;
  1051. } else
  1052. {
  1053. //
  1054. // Always make sure the toolbar is detached
  1055. //
  1056. hr = pControlbar->Detach( pToolbar );
  1057. m_pToolbar = NULL;
  1058. }
  1059. return hr;
  1060. }
  1061. HRESULT
  1062. CUDDIWebServerNode::OnToolbarCommand( IConsole *pConsole, MMC_CONSOLE_VERB verb, IDataObject *pDataObject )
  1063. {
  1064. CDataObject *pDO = GetOurDataObject( pDataObject );
  1065. if( NULL == pDO )
  1066. {
  1067. return S_OK;
  1068. }
  1069. CDelegationBase *pBase = pDO->GetBaseNodeObject();
  1070. if( NULL == pBase )
  1071. {
  1072. return S_OK;
  1073. }
  1074. CUDDIWebServerNode *pWSNode = static_cast<CUDDIWebServerNode *>( pBase );
  1075. UPDATE_VIEWS_HINT hint = ( TRUE == pWSNode->m_isScopeItem ) ? UPDATE_SCOPEITEM : UPDATE_RESULTITEM;
  1076. switch( verb )
  1077. {
  1078. case ID_BUTTONSTART:
  1079. Start();
  1080. break;
  1081. case ID_BUTTONSTOP:
  1082. Stop();
  1083. break;
  1084. }
  1085. HRESULT hr = GetData();
  1086. if( FAILED( hr ) )
  1087. return hr;
  1088. hr = pConsole->UpdateAllViews( pDataObject, GetScopeItemValue(), hint );
  1089. _ASSERT( S_OK == hr);
  1090. return S_OK;
  1091. }
  1092. HRESULT CUDDIWebServerNode::OnShowContextHelp( IDisplayHelp *pDisplayHelp, LPOLESTR helpFile )
  1093. {
  1094. if( ( NULL == pDisplayHelp ) || ( NULL == helpFile ) )
  1095. {
  1096. return E_INVALIDARG;
  1097. }
  1098. wstring wstrHelpInfo = helpFile;
  1099. wstrHelpInfo += g_wszUddiWebServerNodeHelp;
  1100. LPOLESTR pszTopic = static_cast<LPOLESTR>(CoTaskMemAlloc((wstrHelpInfo.length() + 1) * sizeof(WCHAR)));
  1101. if( NULL == pszTopic )
  1102. {
  1103. return E_OUTOFMEMORY;
  1104. }
  1105. wcsncpy( pszTopic, wstrHelpInfo.c_str(), wstrHelpInfo.length() );
  1106. pszTopic[ wstrHelpInfo.length() ] = NULL;
  1107. return pDisplayHelp->ShowTopic( pszTopic );
  1108. }
  1109. HRESULT CUDDIWebServerNode::OnAddMenuItems( IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed )
  1110. {
  1111. WCHAR szStartMenuText[ MAX_PATH ];
  1112. WCHAR szStartMenuDescription[ MAX_PATH ];
  1113. WCHAR szStopMenuText[ MAX_PATH ];
  1114. WCHAR szStopMenuDescription[ MAX_PATH ];
  1115. LoadStringW( g_hinst, IDS_WEBSERVER_START, szStartMenuText, ARRAYLEN( szStartMenuText ) );
  1116. LoadStringW( g_hinst, IDS_WEBSERVER_START_DESCRIPTION, szStartMenuDescription, ARRAYLEN( szStartMenuDescription ) );
  1117. LoadStringW( g_hinst, IDS_WEBSERVER_STOP, szStopMenuText, ARRAYLEN( szStopMenuText ) );
  1118. LoadStringW( g_hinst, IDS_WEBSERVER_STOP_DESCRIPTION, szStopMenuDescription, ARRAYLEN( szStopMenuDescription ) );
  1119. HRESULT hr = S_OK;
  1120. CONTEXTMENUITEM menuItemsNew[] =
  1121. {
  1122. {
  1123. szStartMenuText, szStartMenuDescription,
  1124. IDM_WEBSERVER_START, CCM_INSERTIONPOINTID_PRIMARY_TOP, 0, 0
  1125. },
  1126. {
  1127. szStopMenuText, szStopMenuDescription,
  1128. IDM_WEBSERVER_STOP, CCM_INSERTIONPOINTID_PRIMARY_TOP, 0, 0
  1129. },
  1130. { NULL, NULL, 0, 0, 0 }
  1131. };
  1132. menuItemsNew[ IsRunning() ? 0 : 1 ].fFlags = MF_GRAYED;
  1133. if( !IsW3SvcRunning() )
  1134. {
  1135. menuItemsNew[ 0 ].fFlags = MF_GRAYED;
  1136. }
  1137. //
  1138. // Loop through and add each of the menu items, we
  1139. // want to add to new menu, so see if it is allowed.
  1140. //
  1141. if( *pInsertionsAllowed & CCM_INSERTIONALLOWED_TOP )
  1142. {
  1143. for( LPCONTEXTMENUITEM m = menuItemsNew; m->strName; m++ )
  1144. {
  1145. hr = pContextMenuCallback->AddItem( m );
  1146. _ASSERT( SUCCEEDED(hr) );
  1147. }
  1148. }
  1149. return hr;
  1150. }
  1151. HRESULT CUDDIWebServerNode::OnMenuCommand( IConsole *pConsole, IConsoleNameSpace *pConsoleNameSpace, long lCommandID, IDataObject *pDataObject )
  1152. {
  1153. switch( lCommandID )
  1154. {
  1155. case IDM_WEBSERVER_START:
  1156. OnToolbarCommand( pConsole, (MMC_CONSOLE_VERB) ID_BUTTONSTART, pDataObject );
  1157. break;
  1158. case IDM_WEBSERVER_STOP:
  1159. OnToolbarCommand( pConsole, (MMC_CONSOLE_VERB) ID_BUTTONSTOP, pDataObject );
  1160. break;
  1161. }
  1162. return S_OK;
  1163. }
  1164. struct LoggingData
  1165. {
  1166. LoggingData()
  1167. : bEventLogChanged( false )
  1168. , bFileLogChanged( false )
  1169. , pWebServer( NULL ){}
  1170. bool bEventLogChanged;
  1171. bool bFileLogChanged;
  1172. CUDDIWebServerNode *pWebServer;
  1173. };
  1174. BOOL CALLBACK CUDDIWebServerNode::LoggingDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1175. {
  1176. switch( uMsg )
  1177. {
  1178. case WM_INITDIALOG:
  1179. {
  1180. //
  1181. // Setup the window data
  1182. //
  1183. CUDDIWebServerNode *pWebServer = reinterpret_cast<CUDDIWebServerNode *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  1184. LoggingData *pdata = new LoggingData();
  1185. if( NULL == pdata )
  1186. {
  1187. return FALSE;
  1188. }
  1189. pdata->pWebServer = pWebServer;
  1190. SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR) pdata );
  1191. CPropertyMap& m_mapProperties = pWebServer->m_mapProperties;
  1192. int nEventLogLevel = _tstoi( m_mapProperties[ UDDI_EVENTLOG_LEVEL ].c_str() );
  1193. int nFileLogLevel = _tstoi( m_mapProperties[ UDDI_FILELOG_LEVEL ].c_str() );
  1194. SetDlgItemText( hwndDlg, IDC_LOGGING_TXT_LOGFILE_LOCATION, m_mapProperties[ UDDI_LOG_FILENAME ].c_str() );
  1195. SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_FILELOG, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 6 ) );
  1196. SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_EVENTLOG, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 6 ) );
  1197. SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_EVENTLOG, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) nEventLogLevel );
  1198. SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_FILELOG, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) nFileLogLevel );
  1199. break;
  1200. }
  1201. case WM_DESTROY:
  1202. {
  1203. //
  1204. // Release the window data
  1205. //
  1206. LoggingData* pData = (LoggingData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  1207. delete pData;
  1208. }
  1209. break;
  1210. case WM_HELP:
  1211. {
  1212. LoggingData* pData = (LoggingData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  1213. wstring strHelp( pData->pWebServer->GetHelpFile() );
  1214. strHelp += g_wszUddiLoggingPageHelp;
  1215. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1216. }
  1217. break;
  1218. case WM_HSCROLL:
  1219. {
  1220. //
  1221. // This message indicates that a slider has changed position
  1222. //
  1223. LoggingData* pData = (LoggingData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  1224. //
  1225. // The handle of slider is in the LPARAM
  1226. //
  1227. if( IDC_LOGGING_SLIDER_EVENTLOG == GetDlgCtrlID( (HWND) lParam ) )
  1228. {
  1229. pData->bEventLogChanged = true;
  1230. SendMessage( GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0 );
  1231. }
  1232. else if( IDC_LOGGING_SLIDER_FILELOG == GetDlgCtrlID( (HWND) lParam ) )
  1233. {
  1234. pData->bFileLogChanged = true;
  1235. SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
  1236. }
  1237. break;
  1238. }
  1239. case WM_NOTIFY:
  1240. if( PSN_APPLY == ( (NMHDR *) lParam )->code )
  1241. {
  1242. //
  1243. // The Apply button or the OK Button was clicked
  1244. //
  1245. LoggingData* pdata = (LoggingData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  1246. if( pdata->bEventLogChanged )
  1247. {
  1248. _TCHAR szPos[ 34 ];
  1249. int nPos = (int) SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_EVENTLOG, TBM_GETPOS, 0, 0 );
  1250. pdata->pWebServer->m_mapChanges[ UDDI_EVENTLOG_LEVEL ] = _itot( nPos, szPos, 10 );
  1251. }
  1252. if( pdata->bFileLogChanged )
  1253. {
  1254. _TCHAR szPos[ 34 ];
  1255. int nPos = (int) SendDlgItemMessage( hwndDlg, IDC_LOGGING_SLIDER_FILELOG, TBM_GETPOS, 0, 0 );
  1256. pdata->pWebServer->m_mapChanges[ UDDI_FILELOG_LEVEL ] = _itot( nPos, szPos, 10 );
  1257. }
  1258. //
  1259. // Reset the change indicators so we don't update twice
  1260. //
  1261. pdata->bEventLogChanged = false;
  1262. pdata->bFileLogChanged = false;
  1263. //
  1264. // Ask MMC to send us a message (on the main thread) so
  1265. // we know the Apply button was clicked.
  1266. //
  1267. HRESULT hr = MMCPropertyChangeNotify( pdata->pWebServer->m_ppHandle, (LPARAM) pdata->pWebServer );
  1268. _ASSERT(SUCCEEDED(hr));
  1269. return PSNRET_NOERROR;
  1270. }
  1271. else if( PSN_HELP == ((NMHDR *) lParam)->code )
  1272. {
  1273. DatabaseConnectionData* pdata = (DatabaseConnectionData*) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
  1274. tstring strHelp( pdata->pWebServer->GetHelpFile() );
  1275. strHelp += g_wszUddiLoggingPageHelp;
  1276. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1277. }
  1278. break;
  1279. }
  1280. return FALSE;
  1281. }
  1282. BOOL CALLBACK CUDDIWebServerNode::NewWebServerDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  1283. {
  1284. static WebServerData* pWSData = NULL;
  1285. switch( uMsg )
  1286. {
  1287. case WM_INITDIALOG:
  1288. {
  1289. pWSData = reinterpret_cast<WebServerData *>(lParam);
  1290. if( NULL == pWSData || NULL == pWSData->pBase )
  1291. {
  1292. return FALSE;
  1293. }
  1294. WCHAR wszBuf[ MAX_PATH ];
  1295. DWORD dwBufSize = MAX_PATH;
  1296. wszBuf[ 0 ] = 0x00;
  1297. if( !GetComputerName( wszBuf, &dwBufSize ) )
  1298. {
  1299. return FALSE;
  1300. }
  1301. BOOL fChildExists = pWSData->pBase->ChildExists( wszBuf );
  1302. if( IsWebServer( wszBuf ) && !fChildExists )
  1303. {
  1304. // Defaults for the groups of radio buttons are: add this computer,
  1305. // and add it as both a reader + writer.
  1306. //
  1307. SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER, BM_SETCHECK, TRUE, NULL );
  1308. SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_BOTH, BM_SETCHECK, TRUE, NULL );
  1309. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  1310. pWSData->connectMode = CM_Both;
  1311. }
  1312. else
  1313. {
  1314. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER ), FALSE );
  1315. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), TRUE );
  1316. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), TRUE );
  1317. EnableWindow( GetDlgItem( hwndDlg, IDOK ), FALSE );
  1318. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_TXT_DATABASE_INSTANCE, _T("") );
  1319. SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_ANOTHERCOMPUTER, BM_SETCHECK, TRUE, NULL );
  1320. SetFocus( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ) );
  1321. }
  1322. break;
  1323. }
  1324. case WM_HELP:
  1325. {
  1326. tstring strHelp( pWSData->pBase->GetHelpFile() );
  1327. strHelp += g_wszUddiAddWebServerHelp;
  1328. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1329. break;
  1330. }
  1331. case WM_COMMAND:
  1332. switch( LOWORD(wParam) )
  1333. {
  1334. case IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER:
  1335. {
  1336. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), FALSE );
  1337. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), FALSE );
  1338. EnableWindow( GetDlgItem( hwndDlg, IDOK ), TRUE );
  1339. break;
  1340. }
  1341. case IDC_SITE_CONNECT_RADIO_ANOTHERCOMPUTER:
  1342. {
  1343. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_BTN_BROWSE ), TRUE );
  1344. EnableWindow( GetDlgItem( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER ), TRUE );
  1345. WCHAR wszComputerName[ 256 ];
  1346. wszComputerName[ 0 ] = 0x00;
  1347. GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, wszComputerName, ARRAYLEN( wszComputerName ) );
  1348. //
  1349. // Enable the OK button only if there is some sort of text
  1350. // in the edit control where the computer name is supposed
  1351. // to be typed in.
  1352. //
  1353. EnableWindow( GetDlgItem( hwndDlg, IDOK ), 0 == wcslen( wszComputerName ) ? FALSE : TRUE );
  1354. break;
  1355. }
  1356. case IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER:
  1357. {
  1358. if( EN_CHANGE == HIWORD(wParam) )
  1359. {
  1360. WCHAR wszComputerName[ 256 ];
  1361. wszComputerName[ 0 ] = 0x00;
  1362. GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, wszComputerName, ARRAYLEN( wszComputerName ) );
  1363. //
  1364. // Enable the OK button only if there is some sort of text
  1365. // in the edit control where the computer name is supposed
  1366. // to be typed in.
  1367. //
  1368. EnableWindow( GetDlgItem( hwndDlg, IDOK ), 0 == wcslen( wszComputerName ) ? FALSE : TRUE );
  1369. }
  1370. break;
  1371. }
  1372. case IDC_SITE_CONNECT_BTN_BROWSE:
  1373. {
  1374. _TCHAR szComputerName[ 256 ];
  1375. if( ObjectPicker( hwndDlg, OT_Computer, szComputerName, ARRAYLEN( szComputerName ) ) )
  1376. {
  1377. SetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, szComputerName );
  1378. }
  1379. break;
  1380. }
  1381. case IDHELP:
  1382. {
  1383. wstring strHelp( pWSData->pBase->GetHelpFile() );
  1384. strHelp += g_wszUddiAddWebServerHelp;
  1385. ::HtmlHelp( hwndDlg, strHelp.c_str(), HH_DISPLAY_TOPIC, NULL );
  1386. break;
  1387. }
  1388. case IDOK:
  1389. {
  1390. _TCHAR szBuf[ MAX_PATH + 1 ];
  1391. DWORD dwSize = MAX_PATH + 1;
  1392. memset( szBuf, 0, dwSize * sizeof( _TCHAR ) );
  1393. if( SendDlgItemMessage( hwndDlg, IDC_SITE_CONNECT_RADIO_LOCALCOMPUTER, BM_GETCHECK, NULL, NULL ) )
  1394. {
  1395. szBuf[ 0 ] = 0;
  1396. ::GetComputerName( szBuf, &dwSize );
  1397. ToUpper( szBuf );
  1398. pWSData->szName = szBuf;
  1399. }
  1400. else
  1401. {
  1402. ::GetDlgItemText( hwndDlg, IDC_SITE_CONNECT_EDIT_ANOTHERCOMPUTER, szBuf, dwSize );
  1403. ToUpper( szBuf );
  1404. pWSData->szName = szBuf;
  1405. }
  1406. if( !CUDDIWebServerNode::IsWebServer( pWSData->szName.c_str() ) )
  1407. {
  1408. _TCHAR szTitle[ 256 ];
  1409. _TCHAR szMessage[ 1024 ];
  1410. LoadString( g_hinst, IDS_WEBSERVER_SELECT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  1411. LoadString( g_hinst, IDS_WEBSERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  1412. MessageBox( hwndDlg, szMessage, szTitle, MB_ICONERROR );
  1413. return FALSE;
  1414. }
  1415. EndDialog( hwndDlg, TRUE );
  1416. return TRUE;
  1417. }
  1418. case IDCANCEL:
  1419. {
  1420. EndDialog( hwndDlg, FALSE );
  1421. }
  1422. }
  1423. case WM_DESTROY:
  1424. break;
  1425. }
  1426. return FALSE;
  1427. }
  1428. HRESULT
  1429. CUDDIWebServerNode::UpdateResultPaneItem(IConsole *pConsole, HRESULTITEM item)
  1430. {
  1431. HRESULT hr = E_INVALIDARG;
  1432. if( NULL == pConsole )
  1433. {
  1434. return E_INVALIDARG;
  1435. }
  1436. IResultData *pResultData = NULL;
  1437. hr = pConsole->QueryInterface( IID_IResultData, (void **)&pResultData );
  1438. if( S_OK != hr )
  1439. {
  1440. return hr;
  1441. }
  1442. RESULTDATAITEM rditem;
  1443. ZeroMemory( &rditem, sizeof( RESULTDATAITEM ) );
  1444. rditem.itemID = item;
  1445. hr = pResultData->GetItem( &rditem );
  1446. _ASSERT( S_OK == hr );
  1447. rditem.mask &= RDI_STR;
  1448. rditem.str = MMC_CALLBACK;
  1449. hr = pResultData->SetItem( &rditem );
  1450. _ASSERT( S_OK == hr );
  1451. //
  1452. // Update the "Status" column. Because we are updating the text, we
  1453. // don't change the mask in rditem.
  1454. //
  1455. rditem.nCol = 1;
  1456. hr = pResultData->SetItem( &rditem );
  1457. _ASSERT( S_OK == hr );
  1458. pResultData->Release();
  1459. return hr;
  1460. }
  1461. HRESULT
  1462. CUDDIWebServerNode::UpdateScopePaneItem( IConsole *pConsole, HSCOPEITEM item )
  1463. {
  1464. HRESULT hr = E_INVALIDARG;
  1465. if( NULL == pConsole )
  1466. {
  1467. return E_INVALIDARG;
  1468. }
  1469. IConsoleNameSpace *pNameSpace = NULL;
  1470. hr = pConsole->QueryInterface( IID_IConsoleNameSpace, (void **)&pNameSpace );
  1471. if( S_OK != hr )
  1472. {
  1473. return hr;
  1474. }
  1475. SCOPEDATAITEM sditem;
  1476. ZeroMemory( &sditem, sizeof( SCOPEDATAITEM ) );
  1477. sditem.ID = item;
  1478. hr = pNameSpace->GetItem( &sditem );
  1479. _ASSERT( S_OK == hr );
  1480. sditem.mask &= SDI_STR;
  1481. sditem.displayname = MMC_CALLBACK;
  1482. hr = pNameSpace->SetItem( &sditem );
  1483. _ASSERT( S_OK == hr );
  1484. pNameSpace->Release();
  1485. return hr;
  1486. }
  1487. BOOL
  1488. CUDDIWebServerNode::IsW3SvcRunning()
  1489. {
  1490. BOOL bRet = FALSE;
  1491. // 1. Open the Service Control Manager on the machine which the
  1492. // Web Server is currently running on.
  1493. //
  1494. SC_HANDLE hSCManager = OpenSCManager( m_szName, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT );
  1495. if( NULL == hSCManager )
  1496. {
  1497. return bRet;
  1498. }
  1499. // 2. Get a handle to the WWW Service on said machine. Note the
  1500. // access permissions that we are using.
  1501. //
  1502. SC_HANDLE hW3Svc = OpenService( hSCManager, _T("w3svc"), SERVICE_QUERY_STATUS );
  1503. if( NULL == hW3Svc )
  1504. {
  1505. CloseServiceHandle( hSCManager );
  1506. return bRet;
  1507. }
  1508. // 3. Query the status of the WWW Service.
  1509. //
  1510. SERVICE_STATUS stW3Svc;
  1511. ZeroMemory( &stW3Svc, sizeof( SERVICE_STATUS ) );
  1512. if( QueryServiceStatus( hW3Svc, &stW3Svc ) )
  1513. {
  1514. bRet = ( SERVICE_RUNNING == stW3Svc.dwCurrentState ) ? TRUE : FALSE;
  1515. }
  1516. CloseServiceHandle( hSCManager );
  1517. CloseServiceHandle( hW3Svc );
  1518. return bRet;
  1519. }
  1520. BOOL
  1521. CUDDIWebServerNode::GetReaderConnectionString( const tstring& szName, tstring &szReader )
  1522. {
  1523. try
  1524. {
  1525. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Database" ), KEY_READ, szName.c_str() );
  1526. szReader = key.GetString( _T("ReaderConnectionString"), _T("") );
  1527. return TRUE;
  1528. }
  1529. catch( ... )
  1530. {
  1531. return FALSE;
  1532. }
  1533. }
  1534. BOOL
  1535. CUDDIWebServerNode::GetWriterConnectionString( const tstring& szName, tstring &szWriter )
  1536. {
  1537. try
  1538. {
  1539. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Database" ), KEY_READ, szName.c_str() );
  1540. szWriter = key.GetString( _T("WriterConnectionString"), _T("") );
  1541. return TRUE;
  1542. }
  1543. catch( ... )
  1544. {
  1545. return FALSE;
  1546. }
  1547. }
  1548. BOOL
  1549. CUDDIWebServerNode::SetReaderConnectionString( const tstring& szName, const tstring& szReader )
  1550. {
  1551. try
  1552. {
  1553. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Database" ), KEY_ALL_ACCESS, szName.c_str() );
  1554. key.SetValue( _T("ReaderConnectionString"), szReader.c_str() );
  1555. return TRUE;
  1556. }
  1557. catch( ... )
  1558. {
  1559. return FALSE;
  1560. }
  1561. }
  1562. BOOL
  1563. CUDDIWebServerNode::SetWriterConnectionString( const tstring& szName, const tstring& szWriter )
  1564. {
  1565. try
  1566. {
  1567. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Database" ), KEY_ALL_ACCESS, szName.c_str() );
  1568. key.SetValue( _T("WriterConnectionString"), szWriter.c_str() );
  1569. return TRUE;
  1570. }
  1571. catch( ... )
  1572. {
  1573. return FALSE;
  1574. }
  1575. }
  1576. BOOL
  1577. CUDDIWebServerNode::IsAssignedToSite( const tstring& szWebServer, const ConnectMode& cm, tstring& szSite )
  1578. {
  1579. try
  1580. {
  1581. tstring szConnStr = _T( "" );
  1582. tstring szDomain = _T( "" );
  1583. tstring szInstance = _T( "" );
  1584. szSite = _T( "" );
  1585. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Database" ), KEY_READ, szWebServer.c_str() );
  1586. tstring szName = ( CM_Reader == cm ) ? _T("ReaderConnectionString") : _T("WriterConnectionString");
  1587. szConnStr = key.GetString( szName.c_str() );
  1588. if( 0 < szConnStr.length() )
  1589. {
  1590. CrackConnectionString( szConnStr, szDomain, szSite, szInstance );
  1591. }
  1592. return ( 0 == szSite.length() ) ? FALSE : TRUE;
  1593. }
  1594. catch( ... )
  1595. {
  1596. return FALSE;
  1597. }
  1598. }
  1599. BOOL
  1600. CUDDIWebServerNode::GetDBSchemaVersion( tstring& szVersion )
  1601. {
  1602. try
  1603. {
  1604. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\WebServer" ), KEY_READ, m_szName );
  1605. szVersion = key.GetString( _T( "DBSchemaVersion" ) );
  1606. return ( 0 == szVersion.length() ) ? FALSE : TRUE;
  1607. }
  1608. catch( ... )
  1609. {
  1610. return FALSE;
  1611. }
  1612. }
  1613. BOOL
  1614. CUDDIWebServerNode::GetDBSchemaVersion( const wstring& strComputer, wstring& strVersion )
  1615. {
  1616. try
  1617. {
  1618. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\WebServer" ), KEY_READ, strComputer );
  1619. strVersion = key.GetString( _T( "DBSchemaVersion" ) );
  1620. return ( 0 == strVersion.length() ) ? FALSE : TRUE;
  1621. }
  1622. catch( ... )
  1623. {
  1624. return FALSE;
  1625. }
  1626. }
  1627. void
  1628. CUDDIWebServerNode::DeleteFromScopePane( IConsoleNameSpace *pConsoleNameSpace )
  1629. {
  1630. if( NULL != pConsoleNameSpace )
  1631. {
  1632. pConsoleNameSpace->DeleteItem( GetScopeItemValue(), TRUE );
  1633. m_isDeleted = TRUE;
  1634. }
  1635. }