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.

1017 lines
26 KiB

  1. #include "uddiservicesnode.h"
  2. #include "uddisitenode.h"
  3. #include "webservernode.h"
  4. #include <list>
  5. #include <algorithm>
  6. // {7334C141-C93C-4bb5-BB36-BDEE77BA2D87}
  7. const GUID CUDDIServicesNode::thisGuid = { 0x7334c141, 0xc93c, 0x4bb5, { 0xbb, 0x36, 0xbd, 0xee, 0x77, 0xba, 0x2d, 0x87 } };
  8. //==============================================================
  9. //
  10. // CUDDIServicesNode implementation
  11. //
  12. //
  13. CUDDIServicesNode::CUDDIServicesNode()
  14. : m_strRemoteComputerName( _T("") )
  15. {
  16. }
  17. void CUDDIServicesNode::SetRemoteComputerName( LPCTSTR szRemoteComputerName )
  18. {
  19. m_strRemoteComputerName = szRemoteComputerName;
  20. }
  21. LPCTSTR CUDDIServicesNode::GetRemoteComputerName()
  22. {
  23. return m_strRemoteComputerName.c_str();
  24. }
  25. CUDDIServicesNode::~CUDDIServicesNode()
  26. {
  27. if( !IsExtension() )
  28. {
  29. SaveUDDISites();
  30. }
  31. ClearChildMap();
  32. }
  33. BOOL CUDDIServicesNode::IsDirty()
  34. {
  35. return m_bIsDirty;
  36. }
  37. HRESULT CUDDIServicesNode::Load( IStream *pStm )
  38. {
  39. return S_OK;
  40. #if 0
  41. if( IsExtension() )
  42. return S_OK;
  43. ULONG ulSize = 0;
  44. ULONG ulRead = 0;
  45. HRESULT hr = pStm->Read( &ulSize, sizeof( ulSize ), &ulRead );
  46. if( FAILED(hr) )
  47. {
  48. return hr;
  49. }
  50. if( ulSize )
  51. {
  52. //
  53. // There are database servers saved in the file
  54. //
  55. //
  56. // Read the saved string into a buffer
  57. //
  58. PTCHAR szDatabaseNames = new TCHAR[ ulSize + 1 ];
  59. if( NULL == szDatabaseNames )
  60. {
  61. return E_OUTOFMEMORY;
  62. }
  63. hr =pStm->Read( szDatabaseNames, ulSize * sizeof( TCHAR ), &ulRead );
  64. if( FAILED(hr) )
  65. {
  66. delete [] szDatabaseNames;
  67. return hr;
  68. }
  69. //
  70. // Terminate the buffer
  71. //
  72. szDatabaseNames[ ulSize ] = NULL;
  73. //
  74. // Use begin and end to bracket each server name and
  75. // instance name. When a pair is found add the database instance
  76. // node to the collection of child nodes.
  77. // A % character is used as the delimiter.
  78. //
  79. PTCHAR begin = szDatabaseNames;
  80. PTCHAR end = szDatabaseNames;
  81. int n = 0;
  82. PTCHAR szTempServerName = NULL;
  83. BOOL bLookingForServerName = TRUE;
  84. while( *end )
  85. {
  86. if( _T('%') == *end )
  87. {
  88. //
  89. // Found either the database name or the instance name
  90. //
  91. *end = NULL;
  92. if( bLookingForServerName )
  93. {
  94. //
  95. // Found the server name, save it and keep
  96. // searching for the instance name
  97. // before we add a node.
  98. //
  99. szTempServerName = begin;
  100. bLookingForServerName = FALSE;
  101. }
  102. else
  103. {
  104. //
  105. // Found the instance name
  106. // Construct and add the node to the collection
  107. //
  108. m_mapChildren[ n ] = CUDDISiteNode::Create( szTempServerName, begin, n, this, FALSE );
  109. n++;
  110. bLookingForServerName = TRUE;
  111. }
  112. //
  113. // Update the pointers past the delimiter
  114. //
  115. end++;
  116. begin = end;
  117. }
  118. else
  119. {
  120. end++;
  121. }
  122. }
  123. }
  124. return S_OK;
  125. #endif
  126. }
  127. HRESULT CUDDIServicesNode::Save( IStream *pStm, BOOL fClearDirty )
  128. {
  129. return S_OK;
  130. #if 0
  131. if( IsExtension() )
  132. return S_OK;
  133. //
  134. // Create a string buffer of strings delimited by %
  135. //
  136. tstring str( _T("") );
  137. for( CChildMap::iterator iter = m_mapChildren.begin();
  138. iter != m_mapChildren.end(); iter++ )
  139. {
  140. CUDDISiteNode* pNode = (CUDDISiteNode*) iter->second;
  141. if( !pNode->IsDeleted() )
  142. {
  143. //
  144. // Server Name
  145. //
  146. str.append( pNode->GetName() );
  147. str.append( _T("%") );
  148. //
  149. // Database Instance Name
  150. //
  151. str.append( pNode->GetInstanceName() );
  152. str.append( _T("%") );
  153. }
  154. }
  155. //
  156. // Write out the size of the string into the stream
  157. //
  158. ULONG ulSize = (ULONG) str.length();
  159. ULONG ulWritten = 0;
  160. HRESULT hr = pStm->Write( &ulSize, sizeof( ulSize ), &ulWritten );
  161. _ASSERT( SUCCEEDED(hr) );
  162. //
  163. // Write the computer names out to the stream
  164. //
  165. hr = pStm->Write( str.c_str(), ulSize * sizeof( TCHAR ), &ulWritten );
  166. //
  167. // Clear the dirty flag if requested
  168. //
  169. if( fClearDirty )
  170. m_bIsDirty = FALSE;
  171. return hr;
  172. #endif
  173. }
  174. ULONG CUDDIServicesNode::GetSizeMax()
  175. {
  176. ULONG ulSize = 0;
  177. return (ULONG) ( m_mapChildren.size() * 512 );
  178. }
  179. HRESULT CUDDIServicesNode::OnAddMenuItems( IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed )
  180. {
  181. HRESULT hr = S_OK;
  182. if( !IsExtension() )
  183. {
  184. WCHAR szDatabaseServerMenuText[ MAX_PATH ];
  185. WCHAR szDatabaseServerMenuDescription[ MAX_PATH ];
  186. LoadStringW( g_hinst, IDS_DATABASE_SERVER_ADD, szDatabaseServerMenuText, ARRAYLEN( szDatabaseServerMenuText ) );
  187. LoadStringW( g_hinst, IDS_DATABASE_SERVER_DESCRIPTION, szDatabaseServerMenuDescription, ARRAYLEN( szDatabaseServerMenuDescription ) );
  188. CONTEXTMENUITEM menuItemsNew[] =
  189. {
  190. {
  191. szDatabaseServerMenuText, szDatabaseServerMenuDescription,
  192. IDM_NEW_DBSERVER, CCM_INSERTIONPOINTID_PRIMARY_TOP, 0, 0
  193. },
  194. { NULL, NULL, 0, 0, 0 }
  195. };
  196. //
  197. // Loop through and add each of the menu items, we
  198. // want to add to new menu, so see if it is allowed.
  199. //
  200. if( *pInsertionsAllowed & CCM_INSERTIONALLOWED_TOP )
  201. {
  202. for( LPCONTEXTMENUITEM m = menuItemsNew; m->strName; m++ )
  203. {
  204. hr = pContextMenuCallback->AddItem( m );
  205. if( FAILED(hr) )
  206. break;
  207. }
  208. }
  209. }
  210. return hr;
  211. }
  212. CDelegationBase *
  213. CUDDIServicesNode::FindChild( LPCTSTR szName )
  214. {
  215. for( CChildMap::iterator iter = m_mapChildren.begin();
  216. iter != m_mapChildren.end(); iter++ )
  217. {
  218. CUDDISiteNode* pNode = reinterpret_cast<CUDDISiteNode *>( iter->second );
  219. if( NULL == pNode )
  220. {
  221. continue;
  222. }
  223. if( !pNode->IsDeleted() && ( 0 == _tcsicmp( szName, pNode->GetName() ) ) )
  224. return iter->second;
  225. }
  226. return NULL;
  227. }
  228. HRESULT CUDDIServicesNode::OnMenuCommand( IConsole *pConsole, IConsoleNameSpace *pConsoleNameSpace, long lCommandID, IDataObject *pDataObject )
  229. {
  230. if( ( NULL == pConsole ) || ( NULL == pConsoleNameSpace ) || ( NULL == pDataObject ) )
  231. {
  232. return E_INVALIDARG;
  233. }
  234. if( IDM_NEW_DBSERVER != lCommandID )
  235. {
  236. return S_OK;
  237. }
  238. //
  239. // Add a new site to the console
  240. //
  241. HWND hwndConsole = NULL;
  242. HRESULT hr = pConsole->GetMainWindow( &hwndConsole );
  243. if( FAILED(hr) )
  244. {
  245. return hr;
  246. }
  247. DatabaseData data;
  248. data.pBase = this;
  249. INT_PTR nResult = DialogBoxParam( g_hinst, MAKEINTRESOURCE( IDD_SITE_CONNECT ), hwndConsole, CUDDISiteNode::NewDatabaseServerDialogProc, (LPARAM) &data );
  250. if( nResult )
  251. {
  252. try
  253. {
  254. //
  255. // Check to make sure this has the database component installed
  256. //
  257. if( !CUDDISiteNode::IsDatabaseServer( data.szServerName, data.szInstanceName ) )
  258. {
  259. _TCHAR szMessage[ 512 ];
  260. _TCHAR szTitle[ 128 ];
  261. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR, szMessage, ARRAYLEN( szMessage ) );
  262. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  263. MessageBox( hwndConsole,
  264. szMessage,
  265. szTitle,
  266. MB_OK );
  267. return S_OK;
  268. }
  269. if( FindChild( data.szServerName ) )
  270. {
  271. _TCHAR szMessage[ 512 ];
  272. _TCHAR szTitle[ 128 ];
  273. LoadString( g_hinst, IDS_DATABASE_SERVER_ALREADY_EXISTS, szMessage, ARRAYLEN( szMessage ) );
  274. LoadString( g_hinst, IDS_DATABASE_SERVER_SELECT_ERROR_TITLE, szTitle, ARRAYLEN( szTitle ) );
  275. MessageBox( hwndConsole,
  276. szMessage,
  277. szTitle,
  278. MB_OK );
  279. return S_OK;
  280. }
  281. //
  282. // Create new UDDI Site node. This call to Create will throw a CUDDIException
  283. // if it is unable to connect to the database on szServerName.
  284. //
  285. int n = (int) m_mapChildren.size();
  286. CUDDISiteNode *pSiteNode = CUDDISiteNode::Create( data.szServerName, data.szInstanceName, n, this, m_bIsExtension );
  287. m_mapChildren[ n ] = pSiteNode;
  288. SCOPEDATAITEM sdi;
  289. ZeroMemory( &sdi, sizeof(SCOPEDATAITEM) );
  290. sdi.mask = SDI_STR | // Displayname is valid
  291. SDI_PARAM | // lParam is valid
  292. SDI_IMAGE | // nImage is valid
  293. SDI_OPENIMAGE | // nOpenImage is valid
  294. SDI_PARENT |
  295. SDI_CHILDREN;
  296. sdi.relativeID = GetScopeItemValue();
  297. sdi.nImage = m_mapChildren[ n ]->GetBitmapIndex();
  298. sdi.nOpenImage = MMC_IMAGECALLBACK;
  299. sdi.displayname = MMC_CALLBACK;
  300. sdi.lParam = (LPARAM) m_mapChildren[ n ];
  301. sdi.cChildren = m_mapChildren[ n ]->HasChildren();
  302. hr = pConsoleNameSpace->InsertItem( &sdi );
  303. _ASSERT( SUCCEEDED(hr) );
  304. m_mapChildren[ n ]->SetScopeItemValue( sdi.ID );
  305. m_mapChildren[ n ]->SetParentScopeItem( sdi.relativeID );
  306. IConsoleNameSpace2 *pNS2 = NULL;
  307. hr = pConsoleNameSpace->QueryInterface( IID_IConsoleNameSpace2, reinterpret_cast<void **>( &pNS2 ) );
  308. if( FAILED(hr) )
  309. {
  310. return hr;
  311. }
  312. pNS2->Expand( sdi.ID );
  313. pNS2->Release();
  314. m_bIsDirty = TRUE;
  315. }
  316. catch( CUDDIException &e )
  317. {
  318. UDDIMsgBox( hwndConsole, (LPCTSTR) e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  319. return E_FAIL;
  320. }
  321. catch( ... )
  322. {
  323. UDDIMsgBox( hwndConsole, IDS_ERROR_ADDSVC, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  324. return E_UNEXPECTED;
  325. }
  326. }
  327. return S_OK;
  328. }
  329. const _TCHAR *CUDDIServicesNode::GetDisplayName( int nCol )
  330. {
  331. _TCHAR wszName[ 256 ];
  332. switch( nCol )
  333. {
  334. case 0:
  335. LoadString( g_hinst, IDS_UDDIMMC_SNAPINNAME, wszName, ARRAYLEN( wszName ) );
  336. break;
  337. case 1:
  338. LoadString( g_hinst, IDS_UDDIMMC_TYPE, wszName, ARRAYLEN( wszName ) );
  339. break;
  340. case 2:
  341. LoadString( g_hinst, IDS_UDDIMMC_DESCRIPTION, wszName, ARRAYLEN( wszName ) );
  342. break;
  343. default:
  344. _tcscpy( wszName, _T("") );
  345. break;
  346. }
  347. m_strDisplayName = wszName;
  348. return m_strDisplayName.c_str();
  349. }
  350. HRESULT CUDDIServicesNode::OnShow( IConsole *pConsole, BOOL bShow, HSCOPEITEM scopeitem )
  351. {
  352. HRESULT hr = S_OK;
  353. IHeaderCtrl *pHeaderCtrl = NULL;
  354. IResultData *pResultData = NULL;
  355. hr = pConsole->QueryInterface( IID_IHeaderCtrl, (void **)&pHeaderCtrl );
  356. if( FAILED(hr) )
  357. {
  358. return hr;
  359. }
  360. hr = pConsole->QueryInterface( IID_IResultData, (void **)&pResultData );
  361. if( FAILED(hr) )
  362. {
  363. pHeaderCtrl->Release();
  364. return hr;
  365. }
  366. if( bShow )
  367. {
  368. //
  369. // Set the column headers in the results pane
  370. //
  371. WCHAR szColumnName[ 256 ];
  372. ::LoadStringW( g_hinst, IDS_DATABASE_SERVER_COLUMN_NAME, szColumnName, ARRAYLEN( szColumnName ) );
  373. hr = pHeaderCtrl->InsertColumn( 0, szColumnName, 0, 150 );
  374. _ASSERT( S_OK == hr );
  375. ::LoadStringW( g_hinst, IDS_DATABASE_SERVER_COLUMN_COMPUTER, szColumnName, ARRAYLEN( szColumnName ) );
  376. hr = pHeaderCtrl->InsertColumn( 1, szColumnName, 0, 150 );
  377. _ASSERT( S_OK == hr );
  378. ::LoadStringW( g_hinst, IDS_DATABASE_SERVER_COLUMN_INSTANCE, szColumnName, ARRAYLEN( szColumnName ) );
  379. hr = pHeaderCtrl->InsertColumn( 2, szColumnName, 0, 150 );
  380. _ASSERT( S_OK == hr );
  381. ::LoadStringW( g_hinst, IDS_DATABASE_SERVER_COLUMN_DESCRIPTION, szColumnName, ARRAYLEN( szColumnName ) );
  382. hr = pHeaderCtrl->InsertColumn( 3, szColumnName, 0, 150 );
  383. _ASSERT( S_OK == hr );
  384. pHeaderCtrl->Release();
  385. pResultData->Release();
  386. }
  387. else
  388. {
  389. // pResultData->DeleteAllRsltItems();
  390. }
  391. return hr;
  392. }
  393. HRESULT
  394. CUDDIServicesNode::OnExpand( IConsoleNameSpace *pConsoleNameSpace,
  395. IConsole *pConsole,
  396. HSCOPEITEM parent )
  397. {
  398. if( ( NULL == pConsoleNameSpace ) || ( NULL == pConsole ) || ( NULL == parent ) )
  399. {
  400. return E_INVALIDARG;
  401. }
  402. HWND hwndConsole = NULL;
  403. HRESULT hr = pConsole->GetMainWindow( &hwndConsole );
  404. if( FAILED(hr) )
  405. {
  406. return hr;
  407. }
  408. //
  409. // Cache static node's HSCOPEITEM for future use
  410. //
  411. SetScopeItemValue( parent );
  412. wstring wszTargetComputerName;
  413. if( IsExtension() && m_strRemoteComputerName.length() > 0 )
  414. {
  415. //
  416. // The computer management console has been retargeted use the
  417. // computer name from the console.
  418. //
  419. wszTargetComputerName = m_strRemoteComputerName;
  420. }
  421. else
  422. {
  423. //
  424. // Use the local machine name
  425. //
  426. WCHAR wszLocalComputerName[ 256 ];
  427. DWORD dwSize = ARRAYLEN( wszLocalComputerName );
  428. wszLocalComputerName[ 0 ] = 0x00;
  429. ::GetComputerName( wszLocalComputerName, &dwSize );
  430. wszTargetComputerName = wszLocalComputerName;
  431. }
  432. LoadUDDISites( hwndConsole, wszTargetComputerName );
  433. //
  434. // Create the child nodes, then expand them
  435. //
  436. SCOPEDATAITEM sdi;
  437. for( CChildMap::iterator iter = m_mapChildren.begin();
  438. iter != m_mapChildren.end(); iter++ )
  439. {
  440. ZeroMemory( &sdi, sizeof(SCOPEDATAITEM) );
  441. sdi.mask = SDI_STR | // Displayname is valid
  442. SDI_PARAM | // lParam is valid
  443. SDI_IMAGE | // nImage is valid
  444. SDI_OPENIMAGE | // nOpenImage is valid
  445. SDI_PARENT |
  446. SDI_CHILDREN;
  447. sdi.relativeID = (HSCOPEITEM) parent;
  448. sdi.nImage = iter->second->GetBitmapIndex();
  449. sdi.nOpenImage = MMC_IMAGECALLBACK;
  450. sdi.displayname = MMC_CALLBACK;
  451. sdi.lParam = (LPARAM) iter->second;
  452. sdi.cChildren = iter->second->HasChildren();
  453. hr = pConsoleNameSpace->InsertItem( &sdi );
  454. _ASSERT( SUCCEEDED(hr) );
  455. iter->second->SetScopeItemValue( sdi.ID );
  456. iter->second->SetParentScopeItem( sdi.relativeID );
  457. IConsoleNameSpace2 *pNS2 = NULL;
  458. hr = pConsoleNameSpace->QueryInterface( IID_IConsoleNameSpace2, reinterpret_cast<void **>( &pNS2 ) );
  459. if( FAILED(hr) )
  460. {
  461. return hr;
  462. }
  463. pNS2->Expand( sdi.ID );
  464. pNS2->Release();
  465. }
  466. return hr;
  467. }
  468. HRESULT
  469. CUDDIServicesNode::OnShowContextHelp( IDisplayHelp *pDisplayHelp, LPOLESTR helpFile )
  470. {
  471. try
  472. {
  473. if( ( NULL == pDisplayHelp ) || ( NULL == helpFile ) )
  474. {
  475. return E_INVALIDARG;
  476. }
  477. wstring wstrTopicName = helpFile;
  478. wstrTopicName += g_wszUddiServicesNodeHelp;
  479. LPOLESTR pszTopic = static_cast<LPOLESTR>( CoTaskMemAlloc( ( wstrTopicName.length() + 1 ) * sizeof(WCHAR) ) );
  480. if( NULL == pszTopic )
  481. {
  482. return E_OUTOFMEMORY;
  483. }
  484. wcsncpy( pszTopic, wstrTopicName.c_str(), wstrTopicName.length() );
  485. pszTopic[ wstrTopicName.length() ] = NULL;
  486. return pDisplayHelp->ShowTopic( pszTopic );
  487. }
  488. catch( ... )
  489. {
  490. return E_OUTOFMEMORY;
  491. }
  492. }
  493. HRESULT
  494. CUDDIServicesNode::RemoveChildren( IConsoleNameSpace *pNS )
  495. {
  496. if( NULL == pNS )
  497. {
  498. return E_INVALIDARG;
  499. }
  500. for( CChildMap::iterator iter = m_mapChildren.begin();
  501. iter != m_mapChildren.end(); iter++ )
  502. {
  503. CDelegationBase *pBase = reinterpret_cast<CDelegationBase *>( iter->second );
  504. pBase->RemoveChildren( pNS );
  505. HSCOPEITEM hsi = pBase->GetScopeItemValue();
  506. pNS->DeleteItem( hsi, TRUE );
  507. }
  508. ClearChildMap();
  509. pNS->DeleteItem( GetScopeItemValue(), TRUE );
  510. return S_OK;
  511. }
  512. HRESULT
  513. CUDDIServicesNode::OnRefresh( IConsole *pConsole )
  514. {
  515. if( NULL == pConsole )
  516. {
  517. return S_FALSE;
  518. }
  519. CChildMap::iterator it = m_mapChildren.begin();
  520. while( it != m_mapChildren.end() )
  521. {
  522. it->second->OnRefresh( pConsole );
  523. it++;
  524. }
  525. return S_OK;
  526. }
  527. HRESULT CUDDIServicesNode::OnSelect( CComponent *pComponent, IConsole *pConsole, BOOL bScope, BOOL bSelect )
  528. {
  529. if( ( NULL == pComponent ) || ( NULL == pConsole ) )
  530. {
  531. return E_INVALIDARG;
  532. }
  533. HRESULT hr = E_FAIL;
  534. if( bSelect )
  535. {
  536. //
  537. // Enable refresh verb
  538. //
  539. IConsoleVerb *pConsoleVerb = NULL;
  540. hr = pConsole->QueryConsoleVerb( &pConsoleVerb );
  541. if( FAILED(hr) )
  542. {
  543. return hr;
  544. }
  545. hr = pConsoleVerb->SetVerbState( MMC_VERB_OPEN, ENABLED, TRUE );
  546. if( FAILED(hr) )
  547. {
  548. pConsoleVerb->Release();
  549. return hr;
  550. }
  551. hr = pConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  552. if( FAILED(hr) )
  553. {
  554. pConsoleVerb->Release();
  555. return hr;
  556. }
  557. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, HIDDEN, TRUE );
  558. pConsoleVerb->Release();
  559. }
  560. return hr;
  561. }
  562. //
  563. // The sole purpose of this function is to put the appropriate entries into
  564. // m_mapChildren. These entries are almost always CUDDISiteNode *'s, except
  565. // in 1 case when there can be exactly 1 CUDDIWebServerNode *.
  566. //
  567. // The entries in m_mapChildren are determined by 3 factors:
  568. //
  569. // 1. Wether we are running inside Computer Management as
  570. // an extension, or not.
  571. // 2. Wether the machine we are filling m_mapChildren for
  572. // hosts a UDDI Site, or not.
  573. // 3. Wether the machine we are filling m_mapChildren for
  574. // hosts a UDDI Web Server, or not.
  575. //
  576. // --------------------------------------------------------------------------
  577. // Is Extension - If we are running as an extension of Computer Management,
  578. // then we want to show only the UDDI bits that are located
  579. // on the computer, AND NOTHING ELSE.
  580. // --------------------------------------------------------------------------
  581. // TRUE : Do nothing.
  582. // --------------------------------------------------------------------------
  583. // FALSE : Create 1 entry in m_mapChildren for each persisted UDDI Site.
  584. // --------------------------------------------------------------------------
  585. //
  586. //
  587. // --------------------------------------------------------------------------
  588. // Host for UDDI Site - If szComputerName is host of a UDDI Site, then we
  589. // must ensure that that UDDI Site is present
  590. // in m_mapChildren.
  591. // --------------------------------------------------------------------------
  592. // TRUE : Attempt to add an entry to m_mapChildren which represents the
  593. // UDDI Site, if one does not already exist.
  594. // --------------------------------------------------------------------------
  595. // FALSE : Do nothing.
  596. // --------------------------------------------------------------------------
  597. //
  598. //
  599. // --------------------------------------------------------------------------
  600. // Host for UDDI Web Server - If we are running as an extension, we can only
  601. // show the UDDI bits on this particular computer.
  602. // So, show just the UDDI Web Server node. If not
  603. // running as an extension, add the UDDI Site that
  604. // the UDDI Web Server belongs to.
  605. // --------------------------------------------------------------------------
  606. // TRUE : If Extension, add an entry for that UDDI Web Server node to
  607. // m_mapChildren.
  608. // If not, determine the UDDI Site that the UDDI Web Server belongs
  609. // to, and add an entry for that UDDI Site.
  610. // --------------------------------------------------------------------------
  611. // FALSE : Do nothing.
  612. // --------------------------------------------------------------------------
  613. //
  614. BOOL
  615. CUDDIServicesNode::LoadUDDISites( HWND hwndConsole, const tstring& szComputerName )
  616. {
  617. try
  618. {
  619. BOOL fRet = TRUE;
  620. list< wstring > failedSiteRefs;
  621. failedSiteRefs.clear();
  622. ClearChildMap();
  623. //
  624. // ---- #1 ----
  625. //
  626. // If we are NOT running as an extension of Computer Management, then
  627. // load our list of persisted UDDI Sites.
  628. //
  629. if( FALSE == IsExtension() )
  630. {
  631. try
  632. {
  633. CUDDIRegistryKey sitesKey( HKEY_CURRENT_USER,
  634. g_szUDDIAdminSites,
  635. KEY_ALL_ACCESS,
  636. szComputerName.c_str() );
  637. HKEY hSitesKey = sitesKey.GetCurrentHandle();
  638. if( NULL == hSitesKey )
  639. {
  640. fRet = FALSE;
  641. }
  642. DWORD dwIndex = 0;
  643. int n = 0;
  644. WCHAR szComputer[ 128 ];
  645. WCHAR szInstance[ 128 ];
  646. DWORD dwNameSize;
  647. DWORD dwValueSize;
  648. DWORD dwType = REG_SZ;
  649. dwNameSize = 128;
  650. dwValueSize = 128 * sizeof( WCHAR );
  651. memset( szComputer, 0, 128 * sizeof( WCHAR ) );
  652. memset( szInstance, 0, 128 * sizeof( WCHAR ) );
  653. LONG lRet = RegEnumValue( hSitesKey,
  654. dwIndex,
  655. szComputer,
  656. &dwNameSize,
  657. NULL,
  658. &dwType,
  659. (LPBYTE)szInstance,
  660. &dwValueSize );
  661. while( ( ERROR_NO_MORE_ITEMS != lRet ) && ( ERROR_SUCCESS == lRet ) )
  662. {
  663. //
  664. // This call to Create will throw if it cannot connect to the
  665. // database on szComputer. However, this might be 1 of many
  666. // UDDI Sites we are trying to create a reference to! Instead
  667. // of exiting immediately here, just tell the user that there
  668. // was a problem, and continue on with the next Site in the list.
  669. //
  670. try
  671. {
  672. if( CUDDISiteNode::IsDatabaseServer( szComputer, szInstance ) )
  673. {
  674. ToUpper( szComputer );
  675. CUDDISiteNode *pSiteNode = CUDDISiteNode::Create( szComputer, szInstance, n, this, FALSE );
  676. m_mapChildren[ n ] = pSiteNode;
  677. n++;
  678. }
  679. dwIndex++;
  680. }
  681. catch( CUDDIException &e )
  682. {
  683. UDDIMsgBox( hwndConsole, e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  684. dwIndex++;
  685. failedSiteRefs.push_back( szComputer );
  686. }
  687. dwNameSize = 128;
  688. dwValueSize = 128 * sizeof( WCHAR );
  689. memset( szComputer, 0, 128 * sizeof( WCHAR ) );
  690. memset( szInstance, 0, 128 * sizeof( WCHAR ) );
  691. lRet = RegEnumValue( hSitesKey,
  692. dwIndex,
  693. szComputer,
  694. &dwNameSize,
  695. NULL,
  696. &dwType,
  697. (LPBYTE)szInstance,
  698. &dwValueSize );
  699. }
  700. }
  701. catch( ... )
  702. {
  703. //
  704. // If we are in here, it is most likely that the registry key containing
  705. // the names of the persisted UDDI Sites does not exist. If this is the
  706. // case, continue on silently and try to determine if the local machine
  707. // is host for a UDDI Site and/or a UDDI Web Server.
  708. //
  709. fRet = FALSE;
  710. }
  711. }
  712. //
  713. // ---- #2 ----
  714. //
  715. // If the machine that we are running on is host for a
  716. // UDDI Site, and that Site is currently not in our list
  717. // of Sites that are to be displayed, then add it.
  718. //
  719. if( CUDDISiteNode::IsDatabaseServer( (WCHAR *)szComputerName.c_str() ) &&
  720. ( NULL == FindChild( szComputerName.c_str() ) ) &&
  721. ( failedSiteRefs.end() == find( failedSiteRefs.begin(), failedSiteRefs.end(), szComputerName ) ) )
  722. {
  723. try
  724. {
  725. CUDDIRegistryKey key( _T( "SOFTWARE\\Microsoft\\UDDI\\Setup\\DBServer" ),
  726. KEY_READ,
  727. szComputerName );
  728. int iSize = m_mapChildren.size();
  729. tstring strInstance;
  730. strInstance = key.GetString( _T("InstanceNameOnly"), _T("----") );
  731. CUDDISiteNode* pNode = CUDDISiteNode::Create( (WCHAR *)szComputerName.c_str(),
  732. (WCHAR *)InstanceRealName( strInstance.c_str() ),
  733. iSize,
  734. this,
  735. m_bIsExtension );
  736. m_mapChildren[ iSize ] = pNode;
  737. }
  738. catch( CUDDIException &e )
  739. {
  740. UDDIMsgBox( hwndConsole, e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  741. fRet = FALSE;
  742. }
  743. catch( ... )
  744. {
  745. fRet = FALSE;
  746. }
  747. }
  748. //
  749. // ---- #3 ----
  750. //
  751. // Determine if the local machine hosts a UDDI Web Server. If it does,
  752. // determine which UDDI Site it is associated with, by examining the
  753. // connection string.
  754. //
  755. if( CUDDIWebServerNode::IsWebServer( szComputerName.c_str() ) )
  756. {
  757. wstring wszConnStrWriter;
  758. wstring wszDomain, wszServer, wszInstance;
  759. CUDDIWebServerNode::GetWriterConnectionString( szComputerName, wszConnStrWriter );
  760. CUDDIWebServerNode::CrackConnectionString( wszConnStrWriter,
  761. wszDomain,
  762. wszServer,
  763. wszInstance );
  764. if( NULL == FindChild( wszServer.c_str() ) )
  765. {
  766. //
  767. // If we are running as an extension of Computer Management, then
  768. // display JUST THE UDDI WEB SERVER.
  769. //
  770. // If we are running as the UDDI Admin Console, then add a UDDI
  771. // Site Node which represents the Site which the Web Server is
  772. // part of.
  773. //
  774. if( IsExtension() )
  775. {
  776. try
  777. {
  778. int iSize = m_mapChildren.size();
  779. CUDDIWebServerNode* pNode = new CUDDIWebServerNode( szComputerName.c_str(), iSize, 0, IsExtension() );
  780. m_mapChildren[ iSize ] = pNode;
  781. }
  782. catch( CUDDIException &e )
  783. {
  784. UDDIMsgBox( hwndConsole, e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  785. fRet = FALSE;
  786. }
  787. catch( ... )
  788. {
  789. fRet = FALSE;
  790. }
  791. }
  792. else if( failedSiteRefs.end() == find( failedSiteRefs.begin(), failedSiteRefs.end(), wszServer ) )
  793. {
  794. try
  795. {
  796. if( ( 0 != wszServer.length() ) && CUDDISiteNode::IsDatabaseServer( (TCHAR *)wszServer.c_str() ) )
  797. {
  798. int iSize = m_mapChildren.size();
  799. CUDDISiteNode* pNode = CUDDISiteNode::Create( (WCHAR *)wszServer.c_str(),
  800. (WCHAR *)InstanceRealName( wszInstance.c_str() ),
  801. iSize,
  802. this,
  803. m_bIsExtension );
  804. m_mapChildren[ iSize ] = pNode;
  805. }
  806. }
  807. catch( CUDDIException &e )
  808. {
  809. UDDIMsgBox( hwndConsole, e, IDS_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OK );
  810. fRet = FALSE;
  811. }
  812. catch( ... )
  813. {
  814. fRet = FALSE;
  815. }
  816. }
  817. }
  818. }
  819. return fRet;
  820. }
  821. catch( CUDDIException &e )
  822. {
  823. throw e;
  824. }
  825. catch(...)
  826. {
  827. return FALSE;
  828. }
  829. }
  830. BOOL
  831. CUDDIServicesNode::SaveUDDISites()
  832. {
  833. try
  834. {
  835. if( CUDDIRegistryKey::KeyExists( HKEY_CURRENT_USER, g_szUDDIAdminSites ) )
  836. {
  837. CUDDIRegistryKey::DeleteKey( HKEY_CURRENT_USER, g_szUDDIAdminSites );
  838. }
  839. CUDDIRegistryKey::Create( HKEY_CURRENT_USER, g_szUDDIAdminSites );
  840. CUDDIRegistryKey sitesKey( HKEY_CURRENT_USER, g_szUDDIAdminSites, KEY_ALL_ACCESS );
  841. for( CChildMap::iterator iter = m_mapChildren.begin(); iter != m_mapChildren.end(); iter++ )
  842. {
  843. CUDDISiteNode* pNode = reinterpret_cast<CUDDISiteNode *>( iter->second );
  844. if( ( NULL != pNode ) && ( !pNode->IsDeleted() ) )
  845. {
  846. sitesKey.SetValue( pNode->GetName(), pNode->GetInstanceName() );
  847. }
  848. }
  849. return TRUE;
  850. }
  851. catch(...)
  852. {
  853. return FALSE;
  854. }
  855. }
  856. void CUDDIServicesNode::ClearChildMap()
  857. {
  858. for( CChildMap::iterator iter = m_mapChildren.begin();
  859. iter != m_mapChildren.end(); iter++ )
  860. {
  861. delete iter->second;
  862. iter->second = NULL;
  863. }
  864. m_mapChildren.clear();
  865. }
  866. BOOL
  867. CUDDIServicesNode::ChildExists( const WCHAR *pwszName )
  868. {
  869. if( NULL == pwszName )
  870. {
  871. return FALSE;
  872. }
  873. return ( NULL == FindChild( pwszName ) ) ? FALSE : TRUE;
  874. }