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.

1617 lines
39 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. reppart.cpp
  7. WINS replication partners node information.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "reppart.h"
  12. #include "server.h"
  13. #include "nodes.h"
  14. #include "repnodpp.h"
  15. #include "ipadddlg.h"
  16. UINT guReplicationPartnersMessageStrings[] =
  17. {
  18. IDS_REPLICATION_PARTNERS_MESSAGE_BODY1,
  19. IDS_REPLICATION_PARTNERS_MESSAGE_BODY2,
  20. IDS_REPLICATION_PARTNERS_MESSAGE_BODY3,
  21. IDS_REPLICATION_PARTNERS_MESSAGE_BODY4,
  22. -1
  23. };
  24. // various registry keys
  25. const CReplicationPartnersHandler::REGKEYNAME CReplicationPartnersHandler::lpstrPullRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Partners\\Pull");
  26. const CReplicationPartnersHandler::REGKEYNAME CReplicationPartnersHandler::lpstrPushRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Partners\\Push");
  27. const CReplicationPartnersHandler::REGKEYNAME CReplicationPartnersHandler::lpstrNetBIOSName = _T("NetBIOSName");
  28. const CReplicationPartnersHandler::REGKEYNAME CReplicationPartnersHandler::lpstrPersistence = _T("PersistentRplOn");
  29. /*---------------------------------------------------------------------------
  30. CReplicationPartnersHandler::CReplicationPartnersHandler
  31. Description
  32. Author: EricDav
  33. ---------------------------------------------------------------------------*/
  34. CReplicationPartnersHandler::CReplicationPartnersHandler(
  35. ITFSComponentData *pCompData)
  36. : CWinsHandler(pCompData)
  37. {
  38. m_bExpanded = FALSE;
  39. //m_verbDefault = MMC_VERB_PROPERTIES;
  40. m_nState = loaded;
  41. }
  42. /*---------------------------------------------------------------------------
  43. CReplicationPartnersHandler::InitializeNode
  44. Initializes node specific data
  45. Author: EricDav
  46. ---------------------------------------------------------------------------*/
  47. HRESULT
  48. CReplicationPartnersHandler::InitializeNode
  49. (
  50. ITFSNode * pNode
  51. )
  52. {
  53. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  54. CString strTemp;
  55. strTemp.LoadString(IDS_REPLICATION);
  56. SetDisplayName(strTemp);
  57. m_strDescription.LoadString(IDS_REPLICATION_DISC);
  58. // Make the node immediately visible
  59. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  60. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_REP_PARTNERS_FOLDER_CLOSED);
  61. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_REP_PARTNERS_FOLDER_OPEN);
  62. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  63. pNode->SetData(TFS_DATA_TYPE, WINSSNAP_REPLICATION_PARTNERS);
  64. pNode->SetData(TFS_DATA_SCOPE_LEAF_NODE, TRUE);
  65. SetColumnStringIDs(&aColumns[WINSSNAP_REPLICATION_PARTNERS][0]);
  66. SetColumnWidths(&aColumnWidths[WINSSNAP_REPLICATION_PARTNERS][0]);
  67. return hrOK;
  68. }
  69. /*---------------------------------------------------------------------------
  70. CReplicationPartnersHandler::OnCreateNodeId2
  71. Returns a unique string for this node
  72. Author: EricDav
  73. ---------------------------------------------------------------------------*/
  74. HRESULT CReplicationPartnersHandler::OnCreateNodeId2(ITFSNode * pNode, CString & strId, DWORD * dwFlags)
  75. {
  76. const GUID * pGuid = pNode->GetNodeType();
  77. CString strGuid;
  78. StringFromGUID2(*pGuid, strGuid.GetBuffer(256), 256);
  79. strGuid.ReleaseBuffer();
  80. SPITFSNode spServerNode;
  81. pNode->GetParent(&spServerNode);
  82. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  83. strId = pServer->m_strServerAddress + strGuid;
  84. return hrOK;
  85. }
  86. /*---------------------------------------------------------------------------
  87. Overridden base handler functions
  88. ---------------------------------------------------------------------------*/
  89. /*---------------------------------------------------------------------------
  90. CReplicationPartnersHandler::GetString
  91. Implementation of ITFSNodeHandler::GetString
  92. Author: KennT
  93. ---------------------------------------------------------------------------*/
  94. STDMETHODIMP_(LPCTSTR)
  95. CReplicationPartnersHandler::GetString
  96. (
  97. ITFSNode * pNode,
  98. int nCol
  99. )
  100. {
  101. if (nCol == 0 || nCol == -1)
  102. return GetDisplayName();
  103. else if(nCol == 1)
  104. return m_strDescription;
  105. else
  106. return NULL;
  107. }
  108. /*---------------------------------------------------------------------------
  109. CReplicationPartnersHandler::OnAddMenuItems
  110. Description
  111. Author: EricDav
  112. ---------------------------------------------------------------------------*/
  113. STDMETHODIMP
  114. CReplicationPartnersHandler::OnAddMenuItems
  115. (
  116. ITFSNode * pNode,
  117. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  118. LPDATAOBJECT lpDataObject,
  119. DATA_OBJECT_TYPES type,
  120. DWORD dwType,
  121. long * pInsertionAllowed
  122. )
  123. {
  124. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  125. HRESULT hr = S_OK;
  126. CString strMenuItem;
  127. if (type == CCT_SCOPE)
  128. {
  129. // these menu items go in the new menu,
  130. // only visible from scope pane
  131. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  132. {
  133. strMenuItem.LoadString(IDS_REP_NEW_REPLICATION_PARTNER);
  134. hr = LoadAndAddMenuItem( pContextMenuCallback,
  135. strMenuItem,
  136. IDS_REP_NEW_REPLICATION_PARTNER,
  137. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  138. 0 );
  139. ASSERT( SUCCEEDED(hr) );
  140. strMenuItem.LoadString(IDS_REP_REPLICATE_NOW);
  141. hr = LoadAndAddMenuItem( pContextMenuCallback,
  142. strMenuItem,
  143. IDS_REP_REPLICATE_NOW,
  144. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  145. 0 );
  146. ASSERT( SUCCEEDED(hr) );
  147. }
  148. }
  149. return hr;
  150. }
  151. /*---------------------------------------------------------------------------
  152. CReplicationPartnersHandler::OnCommand
  153. Description
  154. Author: EricDav
  155. ---------------------------------------------------------------------------*/
  156. STDMETHODIMP
  157. CReplicationPartnersHandler::OnCommand
  158. (
  159. ITFSNode * pNode,
  160. long nCommandId,
  161. DATA_OBJECT_TYPES type,
  162. LPDATAOBJECT pDataObject,
  163. DWORD dwType
  164. )
  165. {
  166. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  167. HRESULT hr = S_OK;
  168. switch(nCommandId)
  169. {
  170. case IDS_REP_REPLICATE_NOW:
  171. hr = OnReplicateNow(pNode);
  172. break;
  173. case IDS_REP_NEW_REPLICATION_PARTNER:
  174. hr = OnCreateRepPartner(pNode);
  175. break;
  176. default:
  177. break;
  178. }
  179. return hr;
  180. }
  181. /*!--------------------------------------------------------------------------
  182. CReplicationPartnersHandler::HasPropertyPages
  183. Implementation of ITFSNodeHandler::HasPropertyPages
  184. NOTE: the root node handler has to over-ride this function to
  185. handle the snapin manager property page (wizard) case!!!
  186. Author: KennT
  187. ---------------------------------------------------------------------------*/
  188. STDMETHODIMP
  189. CReplicationPartnersHandler::HasPropertyPages
  190. (
  191. ITFSNode * pNode,
  192. LPDATAOBJECT pDataObject,
  193. DATA_OBJECT_TYPES type,
  194. DWORD dwType
  195. )
  196. {
  197. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  198. HRESULT hr = hrOK;
  199. if (dwType & TFS_COMPDATA_CREATE)
  200. {
  201. // This is the case where we are asked to bring up property
  202. // pages when the user is adding a new snapin. These calls
  203. // are forwarded to the root node to handle.
  204. hr = hrOK;
  205. }
  206. else
  207. {
  208. // we have property pages in the normal case
  209. hr = hrOK;
  210. }
  211. return hr;
  212. }
  213. /*---------------------------------------------------------------------------
  214. CReplicationPartnersHandler::CreatePropertyPages
  215. Description
  216. Author: EricDav
  217. ---------------------------------------------------------------------------*/
  218. STDMETHODIMP
  219. CReplicationPartnersHandler::CreatePropertyPages
  220. (
  221. ITFSNode * pNode,
  222. LPPROPERTYSHEETCALLBACK lpProvider,
  223. LPDATAOBJECT pDataObject,
  224. LONG_PTR handle,
  225. DWORD dwType
  226. )
  227. {
  228. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  229. HRESULT hr = hrOK;
  230. Assert(pNode->GetData(TFS_DATA_COOKIE) != 0);
  231. // get the server info
  232. SPITFSNode spServerNode;
  233. pNode->GetParent(&spServerNode);
  234. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  235. // Object gets deleted when the page is destroyed
  236. SPIComponentData spComponentData;
  237. m_spNodeMgr->GetComponentData(&spComponentData);
  238. CRepNodeProperties * pRepProp =
  239. new CRepNodeProperties( pNode,
  240. spComponentData,
  241. m_spTFSCompData,
  242. NULL);
  243. pRepProp->m_pageGeneral.m_uImage = (UINT) pNode->GetData(TFS_DATA_IMAGEINDEX);
  244. pRepProp->SetConfig(&pServer->GetConfig());
  245. Assert(lpProvider != NULL);
  246. return pRepProp->CreateModelessSheet(lpProvider, handle);
  247. }
  248. /*---------------------------------------------------------------------------
  249. CReplicationPartnersHandler::OnPropertyChange
  250. Description
  251. Author: EricDav
  252. ---------------------------------------------------------------------------*/
  253. HRESULT
  254. CReplicationPartnersHandler::OnPropertyChange
  255. (
  256. ITFSNode * pNode,
  257. LPDATAOBJECT pDataobject,
  258. DWORD dwType,
  259. LPARAM arg,
  260. LPARAM lParam
  261. )
  262. {
  263. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  264. CRepNodeProperties * pProp
  265. = reinterpret_cast<CRepNodeProperties *>(lParam);
  266. LONG_PTR changeMask = 0;
  267. // tell the property page to do whatever now that we are back on the
  268. // main thread
  269. pProp->OnPropertyChange(TRUE, &changeMask);
  270. pProp->AcknowledgeNotify();
  271. if (changeMask)
  272. pNode->ChangeNode(changeMask);
  273. return hrOK;
  274. }
  275. /*---------------------------------------------------------------------------
  276. CReplicationPartnersHandler::CompareItems
  277. Description
  278. Author: EricDav
  279. ---------------------------------------------------------------------------*/
  280. STDMETHODIMP_(int)
  281. CReplicationPartnersHandler::CompareItems
  282. (
  283. ITFSComponent * pComponent,
  284. MMC_COOKIE cookieA,
  285. MMC_COOKIE cookieB,
  286. int nCol
  287. )
  288. {
  289. SPITFSNode spNode1, spNode2;
  290. m_spNodeMgr->FindNode(cookieA, &spNode1);
  291. m_spNodeMgr->FindNode(cookieB, &spNode2);
  292. int nCompare = 0;
  293. CReplicationPartner *pRepPart1 = GETHANDLER(CReplicationPartner, spNode1);
  294. CReplicationPartner *pRepPart2 = GETHANDLER(CReplicationPartner, spNode2);
  295. switch (nCol)
  296. {
  297. case 0:
  298. {
  299. //
  300. // Name compare
  301. //
  302. CString strName1 = pRepPart1->GetServerName();
  303. nCompare = strName1.CompareNoCase(pRepPart2->GetServerName());
  304. }
  305. break;
  306. case 1:
  307. {
  308. // compare the IP Addresses
  309. CString strIp1, strIp2;
  310. strIp1 = pRepPart1->GetIPAddress();
  311. strIp2 = pRepPart2->GetIPAddress();
  312. CIpAddress ipa1(strIp1);
  313. CIpAddress ipa2(strIp2);
  314. if ((LONG) ipa1 < (LONG) ipa2)
  315. nCompare = -1;
  316. else
  317. if ((LONG) ipa1 > (LONG) ipa2)
  318. nCompare = 1;
  319. // default is equal
  320. }
  321. break;
  322. case 2:
  323. {
  324. // compare the types
  325. CString str1;
  326. str1 = pRepPart1->GetType();
  327. nCompare = str1.CompareNoCase(pRepPart2->GetType());
  328. }
  329. break;
  330. }
  331. return nCompare;
  332. }
  333. /*---------------------------------------------------------------------------
  334. Command handlers
  335. ---------------------------------------------------------------------------*/
  336. HRESULT
  337. CReplicationPartnersHandler::OnExpand
  338. (
  339. ITFSNode * pNode,
  340. LPDATAOBJECT pDataObject,
  341. DWORD dwType,
  342. LPARAM arg,
  343. LPARAM param
  344. )
  345. {
  346. HRESULT hr = hrOK;
  347. if (m_bExpanded)
  348. return hr;
  349. BEGIN_WAIT_CURSOR
  350. // read the values from the registry
  351. hr = Load(pNode);
  352. if (SUCCEEDED(hr))
  353. {
  354. // remove any nodes that may have been created before we were expanded.
  355. pNode->DeleteAllChildren(FALSE);
  356. hr = CreateNodes(pNode);
  357. }
  358. else
  359. {
  360. WinsMessageBox(WIN32_FROM_HRESULT(hr));
  361. }
  362. END_WAIT_CURSOR
  363. return hr;
  364. }
  365. /*---------------------------------------------------------------------------
  366. CReplicationPartnersHandler::CreateNodes(ITFSNode *pNode)
  367. Adds the replication partnes to the result pane
  368. Author: v-shubk
  369. ---------------------------------------------------------------------------*/
  370. HRESULT
  371. CReplicationPartnersHandler::CreateNodes
  372. (
  373. ITFSNode * pNode
  374. )
  375. {
  376. HRESULT hr = hrOK;
  377. for (int i = 0; i < m_RepPartnersArray.GetSize(); i++)
  378. {
  379. SPITFSNode spRepNode;
  380. CReplicationPartner * pRep =
  381. new CReplicationPartner(m_spTFSCompData,
  382. &m_RepPartnersArray.GetAt(i) );
  383. CreateLeafTFSNode(&spRepNode,
  384. &GUID_WinsReplicationPartnerLeafNodeType,
  385. pRep,
  386. pRep,
  387. m_spNodeMgr);
  388. // Tell the handler to initialize any specific data
  389. pRep->InitializeNode((ITFSNode *) spRepNode);
  390. // Add the node as a child to the Active Leases container
  391. pNode->AddChild(spRepNode);
  392. pRep->Release();
  393. }
  394. return hr;
  395. }
  396. /*---------------------------------------------------------------------------
  397. CReplicationPartnersHandler::Load(ITFSNode *pNode)
  398. Loads the rpelication partners by reading from the registry
  399. Author: v-shubk
  400. ---------------------------------------------------------------------------*/
  401. HRESULT
  402. CReplicationPartnersHandler::Load
  403. (
  404. ITFSNode *pNode
  405. )
  406. {
  407. DWORD err = ERROR_SUCCESS;
  408. HRESULT hr = hrOK;
  409. CString strServerName;
  410. GetServerName(pNode, strServerName);
  411. CString strTemp =_T("\\\\");
  412. strServerName = strTemp + strServerName;
  413. RegKey rkPull;
  414. err = rkPull.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPullRoot, KEY_READ, strServerName);
  415. if (err)
  416. {
  417. // might not be there, try to create
  418. err = rkPull.Create(HKEY_LOCAL_MACHINE,
  419. (LPCTSTR)lpstrPullRoot,
  420. REG_OPTION_NON_VOLATILE,
  421. KEY_ALL_ACCESS,
  422. NULL,
  423. strServerName);
  424. }
  425. RegKey rkPush;
  426. err = rkPush.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPushRoot, KEY_READ, strServerName);
  427. if (err)
  428. {
  429. err = rkPush.Create(HKEY_LOCAL_MACHINE,
  430. (LPCTSTR)lpstrPushRoot,
  431. REG_OPTION_NON_VOLATILE,
  432. KEY_ALL_ACCESS,
  433. NULL,
  434. strServerName);
  435. }
  436. if (err)
  437. return HRESULT_FROM_WIN32(err);
  438. RegKeyIterator iterPushkey;
  439. RegKeyIterator iterPullkey;
  440. hr = iterPushkey.Init(&rkPush);
  441. if (FAILED(hr))
  442. return hr;
  443. hr = iterPullkey.Init(&rkPull);
  444. if (FAILED(hr))
  445. return hr;
  446. m_RepPartnersArray.RemoveAll();
  447. CWinsServerObj ws;
  448. CString strName;
  449. // Read in push partners
  450. hr = iterPushkey.Next(&strName, NULL);
  451. while (hr != S_FALSE && SUCCEEDED(hr))
  452. {
  453. // Key name is the IP address.
  454. ws.SetIpAddress(strName);
  455. ws.SetstrIPAddress(strName);
  456. CString strKey = (CString)lpstrPushRoot + _T("\\") + strName;
  457. RegKey rk;
  458. err = rk.Open(HKEY_LOCAL_MACHINE, strKey, KEY_READ, strServerName);
  459. if (err)
  460. {
  461. hr = HRESULT_FROM_WIN32(err);
  462. break;
  463. }
  464. if (err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName()))
  465. {
  466. // This replication partner is does not have a netbios
  467. // name listed with it. This is not a major problem,
  468. // as the name is for display purposes only.
  469. CString strTemp;
  470. strTemp.LoadString(IDS_NAME_UNKNOWN);
  471. ws.GetNetBIOSName() = strTemp;
  472. }
  473. DWORD dwTest;
  474. if (rk.QueryValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&) dwTest)
  475. != ERROR_SUCCESS)
  476. {
  477. ws.GetPushUpdateCount() = 0;
  478. }
  479. else
  480. {
  481. ws.GetPushUpdateCount() = dwTest;
  482. }
  483. ws.SetPush(TRUE, TRUE);
  484. // check for the persistence stuff
  485. dwTest = (rk.QueryValue(lpstrPersistence, dwTest) == ERROR_SUCCESS) ? dwTest : 0;
  486. ws.SetPushPersistence(dwTest);
  487. // Make sure the Pull intervals are reset.
  488. ws.SetPull(FALSE, TRUE);
  489. ws.GetPullReplicationInterval() = 0;
  490. ws.GetPullStartTime() = (time_t)0;
  491. m_RepPartnersArray.Add(ws);
  492. hr = iterPushkey.Next(&strName, NULL);
  493. }
  494. if (FAILED(hr))
  495. return hr;
  496. // Read in pull partners
  497. hr = iterPullkey.Next(&strName, NULL);
  498. while (hr != S_FALSE && SUCCEEDED(hr))
  499. {
  500. // Key name is the IP address.
  501. ws.SetIpAddress(strName);
  502. ws.SetstrIPAddress(strName);
  503. CString strKey = (CString)lpstrPullRoot + _T("\\") + strName;
  504. RegKey rk;
  505. err = rk.Open(HKEY_LOCAL_MACHINE, strKey, KEY_READ, strServerName);
  506. if (err)
  507. {
  508. hr = HRESULT_FROM_WIN32(err);
  509. break;
  510. }
  511. err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName());
  512. if (err)
  513. {
  514. // No netbios name given.
  515. CString strTemp;
  516. strTemp.LoadString(IDS_NAME_UNKNOWN);
  517. ws.GetNetBIOSName() = strTemp;
  518. }
  519. DWORD dwPullInt;
  520. err = rk.QueryValue(WINSCNF_RPL_INTERVAL_NM, (DWORD &)dwPullInt);
  521. if (err != ERROR_SUCCESS)
  522. {
  523. ws.GetPullReplicationInterval() = 0;
  524. }
  525. else
  526. {
  527. ws.GetPullReplicationInterval() = dwPullInt;
  528. }
  529. CString strSpTime;
  530. err = rk.QueryValue(WINSCNF_SP_TIME_NM, strSpTime);
  531. if (err != ERROR_SUCCESS)
  532. {
  533. ws.GetPullStartTime() = (time_t)0;
  534. }
  535. else
  536. {
  537. CIntlTime spTime(strSpTime);
  538. ws.GetPullStartTime() = spTime;
  539. }
  540. DWORD dwTest = 0;
  541. // check for the persistence stuff
  542. dwTest = (rk.QueryValue(lpstrPersistence, dwTest) == ERROR_SUCCESS) ? dwTest : 0;
  543. ws.SetPullPersistence(dwTest);
  544. int pos;
  545. CWinsServerObj wsTarget;
  546. // If it's already in the list as a push partner,
  547. // then simply set the push flag, as this replication
  548. // partner is both a push and a pull partner.
  549. if ((pos = IsInList(ws))!= -1)
  550. {
  551. wsTarget = (CWinsServerObj)m_RepPartnersArray.GetAt(pos);
  552. ASSERT(wsTarget != NULL);
  553. wsTarget.SetPull(TRUE, TRUE);
  554. wsTarget.GetPullReplicationInterval() = ws.GetPullReplicationInterval();
  555. wsTarget.GetPullStartTime() = ws.GetPullStartTime();
  556. wsTarget.SetPullPersistence(ws.GetPullPersistence());
  557. m_RepPartnersArray.SetAt(pos, wsTarget);
  558. }
  559. else
  560. {
  561. ws.SetPull(TRUE, TRUE);
  562. ws.SetPullPersistence(dwTest);
  563. // Reset push flags
  564. ws.SetPush(FALSE, TRUE);
  565. ws.GetPushUpdateCount() = 0;
  566. m_RepPartnersArray.Add(ws);
  567. }
  568. hr = iterPullkey.Next(&strName, NULL);
  569. }
  570. return hr;
  571. }
  572. /*---------------------------------------------------------------------------
  573. CReplicationPartnersHandler::IsInList
  574. Checks if the given server is present in the list of
  575. replication partners, returns a valid value if found
  576. else returns -1
  577. Author: v-shubk
  578. ---------------------------------------------------------------------------*/
  579. int
  580. CReplicationPartnersHandler::IsInList
  581. (
  582. const CIpNamePair& inpTarget,
  583. BOOL bBoth
  584. ) const
  585. {
  586. CIpNamePair Current;
  587. int pos1;
  588. for (pos1 = 0;pos1 <m_RepPartnersArray.GetSize(); pos1++)
  589. {
  590. Current = (CIpNamePair)m_RepPartnersArray.GetAt(pos1);
  591. if (Current.Compare(inpTarget, bBoth) == 0)
  592. {
  593. return pos1;
  594. }
  595. }
  596. return -1;
  597. }
  598. /*---------------------------------------------------------------------------
  599. CReplicationPartnersHandler::GetServerName
  600. Gets the server name from the server node
  601. Suthor:v-shubk
  602. ---------------------------------------------------------------------------*/
  603. void
  604. CReplicationPartnersHandler::GetServerName
  605. (
  606. ITFSNode * pNode,
  607. CString & strName
  608. )
  609. {
  610. SPITFSNode spServerNode;
  611. pNode->GetParent(&spServerNode);
  612. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  613. strName = pServer->GetServerAddress();
  614. }
  615. /*---------------------------------------------------------------------------
  616. CReplicationPartnersHandler::OnReplicateNow(ITFSNode* pNode)
  617. Send the replication triger to all it's partners
  618. Author: v-shubk
  619. ---------------------------------------------------------------------------*/
  620. HRESULT
  621. CReplicationPartnersHandler::OnReplicateNow
  622. (
  623. ITFSNode * pNode
  624. )
  625. {
  626. HRESULT hr = hrOK;
  627. SPITFSNode spServerNode;
  628. pNode->GetParent(&spServerNode);
  629. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  630. if (IDYES != AfxMessageBox(IDS_REP_START_CONFIRM, MB_YESNO))
  631. return hrOK;
  632. int nItems = (int)m_RepPartnersArray.GetSize();
  633. DWORD err;
  634. for (int n = 0; n < nItems; n++)
  635. {
  636. CWinsServerObj ws;
  637. ws = m_RepPartnersArray.GetAt(n);
  638. BEGIN_WAIT_CURSOR
  639. if (ws.IsPull())
  640. {
  641. if ((err = ::SendTrigger(pServer->GetBinding(), (LONG) ws.GetIpAddress(), FALSE, FALSE)) != ERROR_SUCCESS)
  642. {
  643. ::WinsMessageBox(WIN32_FROM_HRESULT(err));
  644. continue;
  645. }
  646. }
  647. if (ws.IsPush())
  648. {
  649. if ((err = ::SendTrigger(pServer->GetBinding(), (LONG) ws.GetIpAddress(), TRUE, TRUE)) != ERROR_SUCCESS)
  650. {
  651. ::WinsMessageBox(WIN32_FROM_HRESULT(err));
  652. continue;
  653. }
  654. }
  655. END_WAIT_CURSOR
  656. }
  657. if (err == ERROR_SUCCESS)
  658. {
  659. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  660. }
  661. return HRESULT_FROM_WIN32(err);
  662. }
  663. /*---------------------------------------------------------------------------
  664. CReplicationPartnersHandler::OnCreateRepPartner
  665. Invokes new replication partner Wizard
  666. Author: v-shubk
  667. ---------------------------------------------------------------------------*/
  668. HRESULT
  669. CReplicationPartnersHandler::OnCreateRepPartner
  670. (
  671. ITFSNode * pNode
  672. )
  673. {
  674. HRESULT hr = hrOK;
  675. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  676. // check to see if the user has access
  677. SPITFSNode spServerNode;
  678. pNode->GetParent(&spServerNode);
  679. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  680. if (!pServer->GetConfig().IsAdmin())
  681. {
  682. // access denied
  683. WinsMessageBox(ERROR_ACCESS_DENIED);
  684. return hr;
  685. }
  686. // the user has access. ask for the partner info
  687. CNewReplicationPartner dlg;
  688. dlg.m_spRepPartNode.Set(pNode);
  689. dlg.m_pRepPartHandler = this;
  690. if (dlg.DoModal() == IDOK)
  691. {
  692. // create the new replication partner
  693. CWinsServerObj ws;
  694. // grab the name and ip from the dlg
  695. ws.SetstrIPAddress(dlg.m_strServerIp);
  696. ws.SetIpAddress(dlg.m_strServerIp);
  697. ws.SetNetBIOSName(dlg.m_strServerName);
  698. // default is push/pull partner
  699. ws.SetPush(TRUE, TRUE);
  700. ws.SetPull(TRUE, TRUE);
  701. ws.SetPullClean(TRUE);
  702. ws.SetPushClean(TRUE);
  703. DWORD dwErr = AddRegEntry(pNode, ws);
  704. if (dwErr != ERROR_SUCCESS)
  705. {
  706. WinsMessageBox(dwErr);
  707. }
  708. else
  709. {
  710. HandleResultMessage(pNode);
  711. }
  712. }
  713. return hrOK;
  714. }
  715. /*---------------------------------------------------------------------------
  716. CReplicationPartnersHandler::Store(ITFSNode *pNode)
  717. Adds the new replication partner info to the registry
  718. Author: v-shubk
  719. ---------------------------------------------------------------------------*/
  720. HRESULT
  721. CReplicationPartnersHandler::Store
  722. (
  723. ITFSNode * pNode
  724. )
  725. {
  726. DWORD err = ERROR_SUCCESS;
  727. CString strServerName;
  728. GetServerName(pNode, strServerName);
  729. CString strTemp =_T("\\\\");
  730. strServerName = strTemp + strServerName;
  731. RegKey rkPull;
  732. err = rkPull.Create(HKEY_LOCAL_MACHINE,
  733. (LPCTSTR)lpstrPullRoot,
  734. REG_OPTION_NON_VOLATILE,
  735. KEY_ALL_ACCESS,
  736. NULL,
  737. strServerName);
  738. RegKey rkPush;
  739. err = rkPush.Create(HKEY_LOCAL_MACHINE,
  740. (LPCTSTR)lpstrPushRoot,
  741. REG_OPTION_NON_VOLATILE,
  742. KEY_ALL_ACCESS,
  743. NULL,
  744. strServerName);
  745. if (err)
  746. return HRESULT_FROM_WIN32(err);
  747. RegKeyIterator iterPushkey;
  748. RegKeyIterator iterPullkey;
  749. err = iterPushkey.Init(&rkPush);
  750. err = iterPullkey.Init(&rkPull);
  751. if (err)
  752. return HRESULT_FROM_WIN32(err);
  753. CWinsServerObj ws;
  754. CString strName;
  755. // Read in push partners
  756. while ((err = iterPushkey.Next(&strName, NULL)) == ERROR_SUCCESS )
  757. {
  758. // Key name is the IP address.
  759. ws.SetIpAddress(strName);
  760. ws.SetstrIPAddress(strName);
  761. CString strKey = (CString)lpstrPushRoot + _T("\\") + strName;
  762. RegKey rk;
  763. err = rk.Create(HKEY_LOCAL_MACHINE,
  764. strKey,
  765. 0,
  766. KEY_ALL_ACCESS,
  767. NULL,
  768. strServerName);
  769. if (err)
  770. {
  771. return HRESULT_FROM_WIN32(err);
  772. }
  773. if (err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName()))
  774. {
  775. // This replication partner is does not have a netbios
  776. // name listed with it. This is not a major problem,
  777. // as the name is for display purposes only.
  778. CString strTemp;
  779. strTemp.LoadString(IDS_NAME_UNKNOWN);
  780. ws.GetNetBIOSName() = strTemp;
  781. }
  782. DWORD dwTest;
  783. if (rk.QueryValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&) dwTest) != ERROR_SUCCESS)
  784. {
  785. ws.GetPushUpdateCount() = 0;
  786. }
  787. ws.SetPush(TRUE, TRUE);
  788. // Make sure the Pull intervals are reset.
  789. ws.SetPull(FALSE, TRUE);
  790. ws.GetPullReplicationInterval() = 0;
  791. ws.GetPullStartTime() = (time_t)0;
  792. m_RepPartnersArray.Add(ws);
  793. }
  794. // Read in pull partners
  795. while ((err = iterPullkey.Next(&strName, NULL)) == ERROR_SUCCESS)
  796. {
  797. // Key name is the IP address.
  798. ws.SetIpAddress(strName);
  799. ws.SetstrIPAddress(strName);
  800. CString strKey = (CString)lpstrPullRoot + _T("\\") + strName;
  801. RegKey rk;
  802. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  803. if (err)
  804. {
  805. return HRESULT_FROM_WIN32(err);
  806. }
  807. if (err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName()))
  808. {
  809. // No netbios name given.
  810. CString strTemp;
  811. strTemp.LoadString(IDS_NAME_UNKNOWN);
  812. ws.GetNetBIOSName() = strTemp;
  813. }
  814. DWORD dwPullInt;
  815. if (rk.QueryValue(WINSCNF_RPL_INTERVAL_NM, (DWORD &)dwPullInt) != ERROR_SUCCESS)
  816. {
  817. ws.GetPullReplicationInterval() = 0;
  818. }
  819. else
  820. {
  821. ws.GetPullReplicationInterval() = dwPullInt;
  822. }
  823. if (rk.QueryValue(WINSCNF_SP_TIME_NM, (DWORD &)dwPullInt) != ERROR_SUCCESS)
  824. {
  825. ws.GetPullStartTime() = (time_t)0;
  826. }
  827. else
  828. {
  829. ws.GetPullStartTime() = (time_t)dwPullInt;
  830. }
  831. int pos;
  832. CWinsServerObj wsTarget;
  833. // If it's already in the list as a push partner,
  834. // then simply set the push flag, as this replication
  835. // partner is both a push and a pull partner.
  836. if ((pos = IsInList(ws))!= -1)
  837. {
  838. wsTarget = (CWinsServerObj)m_RepPartnersArray.GetAt(pos);
  839. ASSERT(wsTarget != NULL);
  840. wsTarget.SetPull(TRUE, TRUE);
  841. wsTarget.GetPullReplicationInterval() = ws.GetPullReplicationInterval();
  842. wsTarget.GetPullStartTime() = ws.GetPullStartTime();
  843. m_RepPartnersArray.SetAt(pos, wsTarget);
  844. }
  845. else
  846. {
  847. ws.SetPull(TRUE, TRUE);
  848. // Reset push flags
  849. ws.SetPush(FALSE, TRUE);
  850. ws.GetPushUpdateCount() = 0;
  851. m_RepPartnersArray.Add(ws);
  852. }
  853. }
  854. return hrOK;
  855. }
  856. /*---------------------------------------------------------------------------
  857. CReplicationPartnersHandler::OnResultDelete
  858. Deletes replication partner
  859. Author: v-shubk
  860. ---------------------------------------------------------------------------*/
  861. HRESULT
  862. CReplicationPartnersHandler::OnResultDelete
  863. (
  864. ITFSComponent * pComponent,
  865. LPDATAOBJECT pDataObject,
  866. MMC_COOKIE cookie,
  867. LPARAM arg,
  868. LPARAM param
  869. )
  870. {
  871. HRESULT hr = hrOK;
  872. DWORD err = ERROR_SUCCESS;
  873. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  874. // translate the cookie into a node pointer
  875. SPITFSNode spReplicationPartnersHandler, spSelectedNode;
  876. m_spNodeMgr->FindNode(cookie, &spReplicationPartnersHandler);
  877. pComponent->GetSelectedNode(&spSelectedNode);
  878. Assert(spSelectedNode == spReplicationPartnersHandler);
  879. if (spSelectedNode != spReplicationPartnersHandler)
  880. return hr;
  881. SPITFSNode spServerNode ;
  882. spReplicationPartnersHandler->GetParent(&spServerNode);
  883. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  884. // build the list of selected nodes
  885. CTFSNodeList listNodesToDelete;
  886. hr = BuildSelectedItemList(pComponent, &listNodesToDelete);
  887. // Confirm with the user
  888. CString strMessage, strTemp;
  889. int nNodes = (int)listNodesToDelete.GetCount();
  890. if (nNodes > 1)
  891. {
  892. strTemp.Format(_T("%d"), nNodes);
  893. AfxFormatString1(strMessage, IDS_DELETE_ITEMS, (LPCTSTR) strTemp);
  894. }
  895. else
  896. {
  897. strMessage.LoadString(IDS_DELETE_ITEM);
  898. }
  899. if (AfxMessageBox(strMessage, MB_YESNO) == IDNO)
  900. {
  901. return NOERROR;
  902. }
  903. BOOL fAskedPurge = FALSE;
  904. BOOL fPurge = FALSE;
  905. while (listNodesToDelete.GetCount() > 0)
  906. {
  907. SPITFSNode spRepNode;
  908. spRepNode = listNodesToDelete.RemoveHead();
  909. CReplicationPartner * pItem = GETHANDLER(CReplicationPartner , spRepNode);
  910. CString str = pItem->GetServerName();
  911. // Do we also need to remove all references to this
  912. // WINS server from the database?
  913. if (!fAskedPurge)
  914. {
  915. int nReturn = AfxMessageBox(IDS_MSG_PURGE_WINS, MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_ICONQUESTION);
  916. fAskedPurge = TRUE;
  917. if (nReturn == IDYES)
  918. {
  919. fPurge = TRUE;
  920. }
  921. else if (nReturn == IDCANCEL)
  922. {
  923. //
  924. // Forget the whole thing
  925. //
  926. return NOERROR;
  927. }
  928. }
  929. CWinsServerObj pws = pItem->m_Server;
  930. if (pws.IsPush() || pws.IsPull())
  931. {
  932. pws.SetPush(FALSE);
  933. pws.SetPushClean(FALSE);
  934. pws.SetPull(FALSE);
  935. pws.SetPullClean(FALSE);
  936. err = UpdateReg(spReplicationPartnersHandler, &pws);
  937. }
  938. if (err == ERROR_SUCCESS && fPurge)
  939. {
  940. BEGIN_WAIT_CURSOR
  941. err = pServer->DeleteWinsServer((LONG) pws.GetIpAddress());
  942. END_WAIT_CURSOR
  943. }
  944. if (err == ERROR_SUCCESS)
  945. {
  946. int pos = IsInList(pws);
  947. m_RepPartnersArray.RemoveAt(pos,pws);
  948. //
  949. // Remove from UI now
  950. //
  951. spReplicationPartnersHandler->RemoveChild(spRepNode);
  952. spRepNode.Release();
  953. }
  954. if (err != ERROR_SUCCESS)
  955. {
  956. if (::WinsMessageBox(err, MB_OKCANCEL) == IDCANCEL)
  957. break;
  958. }
  959. }
  960. HandleResultMessage(spReplicationPartnersHandler);
  961. return hr;
  962. }
  963. /*---------------------------------------------------------------------------
  964. CReplicationPartnersHandler::OnResultRefresh
  965. Base handler override
  966. Author: v-shubk
  967. ---------------------------------------------------------------------------*/
  968. HRESULT
  969. CReplicationPartnersHandler::OnResultRefresh
  970. (
  971. ITFSComponent * pComponent,
  972. LPDATAOBJECT pDataObject,
  973. MMC_COOKIE cookie,
  974. LPARAM arg,
  975. LPARAM lParam
  976. )
  977. {
  978. HRESULT hr = hrOK;
  979. SPITFSNode spNode;
  980. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  981. BEGIN_WAIT_CURSOR
  982. OnRefreshNode(spNode, pDataObject);
  983. END_WAIT_CURSOR
  984. Error:
  985. return hr;
  986. }
  987. /*!--------------------------------------------------------------------------
  988. CReplicationPartnersHandler::OnResultSelect
  989. Handles the MMCN_SELECT notifcation
  990. Author: EricDav
  991. ---------------------------------------------------------------------------*/
  992. HRESULT
  993. CReplicationPartnersHandler::OnResultSelect
  994. (
  995. ITFSComponent * pComponent,
  996. LPDATAOBJECT pDataObject,
  997. MMC_COOKIE cookie,
  998. LPARAM arg,
  999. LPARAM lParam
  1000. )
  1001. {
  1002. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1003. HRESULT hr = hrOK;
  1004. SPITFSNode spNode;
  1005. CORg(CWinsHandler::OnResultSelect(pComponent, pDataObject, cookie, arg, lParam));
  1006. m_spResultNodeMgr->FindNode(cookie, &spNode);
  1007. HandleResultMessage(spNode);
  1008. Error:
  1009. return hr;
  1010. }
  1011. /*!--------------------------------------------------------------------------
  1012. CReplicationPartnersHandler::HandleResultMessage
  1013. Displays the message in the result pane
  1014. Author: EricDav
  1015. ---------------------------------------------------------------------------*/
  1016. HRESULT
  1017. CReplicationPartnersHandler::HandleResultMessage(ITFSNode * pNode)
  1018. {
  1019. HRESULT hr = hrOK;
  1020. if (m_RepPartnersArray.GetSize() == 0)
  1021. {
  1022. CString strTitle, strBody, strTemp;
  1023. int i;
  1024. strTitle.LoadString(IDS_REPLICATION_PARTNERS_MESSAGE_TITLE);
  1025. for (i = 0; ; i++)
  1026. {
  1027. if (guReplicationPartnersMessageStrings[i] == -1)
  1028. break;
  1029. strTemp.LoadString(guReplicationPartnersMessageStrings[i]);
  1030. strBody += strTemp;
  1031. }
  1032. ShowMessage(pNode, strTitle, strBody, Icon_Information);
  1033. }
  1034. else
  1035. {
  1036. ClearMessage(pNode);
  1037. }
  1038. return hr;
  1039. }
  1040. /*---------------------------------------------------------------------------
  1041. CReplicationPartnersHandler::OnRefreshNode
  1042. refreshes the list of replication partners
  1043. Author: v-shubk
  1044. ---------------------------------------------------------------------------*/
  1045. HRESULT
  1046. CReplicationPartnersHandler::OnRefreshNode
  1047. (
  1048. ITFSNode * pNode,
  1049. LPDATAOBJECT pDataObject
  1050. )
  1051. {
  1052. HRESULT hr = hrOK;
  1053. // remove the nodes first
  1054. hr = RemoveChildren(pNode);
  1055. hr = Load(pNode);
  1056. if (SUCCEEDED(hr))
  1057. {
  1058. DWORD err = CreateNodes(pNode);
  1059. HandleResultMessage(pNode);
  1060. }
  1061. return hr;
  1062. }
  1063. /*---------------------------------------------------------------------------
  1064. CReplicationPartnersHandler:: RemoveChildren
  1065. Deletes the child nodes
  1066. Author: v-shubk
  1067. ---------------------------------------------------------------------------*/
  1068. HRESULT
  1069. CReplicationPartnersHandler:: RemoveChildren
  1070. (
  1071. ITFSNode* pNode
  1072. )
  1073. {
  1074. // enumerate thro' all the nodes
  1075. HRESULT hr = hrOK;
  1076. SPITFSNodeEnum spNodeEnum;
  1077. SPITFSNode spCurrentNode;
  1078. ULONG nNumReturned = 0;
  1079. // get the enumerator for this node
  1080. pNode->GetEnum(&spNodeEnum);
  1081. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1082. while (nNumReturned)
  1083. {
  1084. // walk the list of replication servers
  1085. pNode->RemoveChild(spCurrentNode);
  1086. spCurrentNode.Release();
  1087. // get the next Server in the list
  1088. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1089. }
  1090. return hr;
  1091. }
  1092. /*---------------------------------------------------------------------------
  1093. CReplicationPartnersHandler::OnGetResultViewType
  1094. Overridden for multiple selection
  1095. Author: v-shubk
  1096. ---------------------------------------------------------------------------*/
  1097. HRESULT
  1098. CReplicationPartnersHandler::OnGetResultViewType
  1099. (
  1100. ITFSComponent * pComponent,
  1101. MMC_COOKIE cookie,
  1102. LPOLESTR * ppViewType,
  1103. long * pViewOptions
  1104. )
  1105. {
  1106. HRESULT hr = hrOK;
  1107. // call the base class to see if it is handling this
  1108. if (CWinsHandler::OnGetResultViewType(pComponent, cookie, ppViewType, pViewOptions) != S_OK)
  1109. {
  1110. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  1111. hr = S_FALSE;
  1112. }
  1113. return hr;
  1114. }
  1115. /*---------------------------------------------------------------------------
  1116. CReplicationPartnersHandler::UpdateReg()
  1117. Updates the regisrty, called from OnApply()
  1118. ---------------------------------------------------------------------------*/
  1119. DWORD
  1120. CReplicationPartnersHandler::UpdateReg(ITFSNode *pNode, CWinsServerObj* pws)
  1121. {
  1122. DWORD err = ERROR_SUCCESS;
  1123. HRESULT hr = hrOK;
  1124. CString strServerName;
  1125. GetServerName(pNode, strServerName);
  1126. const DWORD dwZero = 0;
  1127. CString strTemp =_T("\\\\");
  1128. strServerName = strTemp + strServerName;
  1129. RegKey rkPush;
  1130. RegKey rkPull;
  1131. CString strKey = lpstrPushRoot + _T("\\") + (CString)pws->GetstrIPAddress();
  1132. err = rkPush.Create(HKEY_LOCAL_MACHINE,
  1133. (CString)lpstrPushRoot,
  1134. 0,
  1135. KEY_ALL_ACCESS,
  1136. NULL,
  1137. strServerName);
  1138. if (err)
  1139. return err;
  1140. strKey = lpstrPullRoot + _T("\\") + (CString)pws->GetstrIPAddress();
  1141. err = rkPull.Create(HKEY_LOCAL_MACHINE,
  1142. (CString)lpstrPullRoot,
  1143. 0,
  1144. KEY_ALL_ACCESS,
  1145. NULL,
  1146. strServerName);
  1147. if (err)
  1148. return err;
  1149. RegKeyIterator iterPushkey;
  1150. RegKeyIterator iterPullkey;
  1151. hr = iterPushkey.Init(&rkPush);
  1152. if (FAILED(hr))
  1153. return WIN32_FROM_HRESULT(hr);
  1154. hr = iterPullkey.Init(&rkPull);
  1155. if (FAILED(hr))
  1156. return WIN32_FROM_HRESULT(hr);
  1157. DWORD errDel;
  1158. CString csKeyName;
  1159. // if none, delete the key from registry
  1160. if (!pws->IsPush() && !pws->IsPull())
  1161. {
  1162. // cleanup push partners list
  1163. hr = iterPushkey.Next (&csKeyName, NULL);
  1164. while (hr != S_FALSE && SUCCEEDED(hr))
  1165. {
  1166. if (csKeyName == pws->GetstrIPAddress())
  1167. {
  1168. errDel = RegDeleteKey (HKEY(rkPush), csKeyName);
  1169. iterPushkey.Reset();
  1170. }
  1171. hr = iterPushkey.Next (&csKeyName, NULL);
  1172. }
  1173. if (FAILED(hr))
  1174. err = WIN32_FROM_HRESULT(hr);
  1175. hr = iterPullkey.Next (&csKeyName, NULL);
  1176. while (hr != S_FALSE && SUCCEEDED(hr))
  1177. {
  1178. if (csKeyName == pws->GetstrIPAddress())
  1179. {
  1180. errDel = RegDeleteKey (HKEY(rkPull), csKeyName);
  1181. iterPullkey.Reset();
  1182. }
  1183. hr = iterPullkey.Next (&csKeyName, NULL);
  1184. }
  1185. if (FAILED(hr))
  1186. err = WIN32_FROM_HRESULT(hr);
  1187. }
  1188. return err;
  1189. }
  1190. /*---------------------------------------------------------------------------
  1191. CReplicationPartnersHandler::UpdateReg(ITFSNode *pNode,
  1192. CWinsServerObj* pws)
  1193. Creates a new replication partner entry
  1194. ---------------------------------------------------------------------------*/
  1195. DWORD
  1196. CReplicationPartnersHandler::AddRegEntry(ITFSNode * pNode, CWinsServerObj & ws)
  1197. {
  1198. // get the server handler for default values
  1199. SPITFSNode spServerNode;
  1200. pNode->GetParent(&spServerNode);
  1201. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  1202. // Set the defaults
  1203. ws.SetPushUpdateCount(pServer->GetConfig().m_dwPushUpdateCount);
  1204. ws.SetPullReplicationInterval(pServer->GetConfig().m_dwPullTimeInterval);
  1205. ws.SetPullStartTime(pServer->GetConfig().m_dwPullSpTime);
  1206. ws.SetPullPersistence(pServer->GetConfig().m_dwPullPersistence);
  1207. ws.SetPushPersistence(pServer->GetConfig().m_dwPushPersistence);
  1208. // write the information to the registry
  1209. CString strTemp =_T("\\\\");
  1210. CString strServerName;
  1211. GetServerName(pNode, strServerName);
  1212. strServerName = strTemp + strServerName;
  1213. DWORD err;
  1214. DWORD dwZero = 0;
  1215. RegKey rk;
  1216. if (ws.IsPush())
  1217. {
  1218. CString strKey = lpstrPushRoot + _T("\\") + (CString)ws.GetstrIPAddress();
  1219. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  1220. DWORD dwResult;
  1221. if (!err)
  1222. {
  1223. err = rk.SetValue(lpstrNetBIOSName, ws.GetNetBIOSName());
  1224. if (!err)
  1225. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&)dwResult);
  1226. if (err)
  1227. err = rk.SetValue(WINSCNF_SELF_FND_NM,(DWORD&) dwZero);
  1228. DWORD dwPushUpdateCount = (LONG) ws.GetPushUpdateCount();
  1229. if (dwPushUpdateCount > 0)
  1230. err = rk.SetValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&)dwPushUpdateCount);
  1231. DWORD dwPersistence = ws.GetPushPersistence();
  1232. err = rk.SetValue(lpstrPersistence, dwPersistence);
  1233. }
  1234. }
  1235. if (ws.IsPull())
  1236. {
  1237. CString strKey = lpstrPullRoot + _T("\\") + (CString)ws.GetstrIPAddress();
  1238. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  1239. DWORD dwResult;
  1240. if (!err)
  1241. {
  1242. err = rk.SetValue(lpstrNetBIOSName, ws.GetNetBIOSName());
  1243. if (!err)
  1244. err = rk.QueryValue(WINSCNF_SELF_FND_NM, dwResult);
  1245. if (err)
  1246. err = rk.SetValue(WINSCNF_SELF_FND_NM, (DWORD) dwZero);
  1247. DWORD dwPullTimeInterval = (LONG) ws.GetPullReplicationInterval();
  1248. if (dwPullTimeInterval > 0)
  1249. {
  1250. err = rk.SetValue(WINSCNF_RPL_INTERVAL_NM, dwPullTimeInterval);
  1251. }
  1252. DWORD dwSpTime = (DWORD) ws.GetPullStartTime();
  1253. if (!err)
  1254. {
  1255. if (dwSpTime > (time_t)0)
  1256. err = rk.SetValue(WINSCNF_SP_TIME_NM, ws.GetPullStartTime().IntlFormat(CIntlTime::TFRQ_MILITARY_TIME));
  1257. }
  1258. DWORD dwPersistence = ws.GetPullPersistence();
  1259. err = rk.SetValue(lpstrPersistence, dwPersistence);
  1260. }
  1261. }
  1262. if (err == ERROR_SUCCESS)
  1263. {
  1264. // add to the list of replication partners
  1265. m_RepPartnersArray.Add(ws);
  1266. SPITFSNode spNode;
  1267. SPITFSNodeMgr spNodeMgr;
  1268. pNode->GetNodeMgr(&spNodeMgr);
  1269. // Create a new node for this partner
  1270. CReplicationPartner *pRepNew = new CReplicationPartner(m_spTFSCompData, &ws);
  1271. CreateLeafTFSNode(&spNode,
  1272. &GUID_WinsReplicationPartnerLeafNodeType,
  1273. pRepNew,
  1274. pRepNew,
  1275. spNodeMgr);
  1276. // Tell the handler to initialize any specific data
  1277. pRepNew->InitializeNode((ITFSNode *) spNode);
  1278. pNode->AddChild(spNode);
  1279. pRepNew->Release();
  1280. }
  1281. return err;
  1282. }