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.

1620 lines
41 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. CThemeContextActivator themeActivator;
  629. pNode->GetParent(&spServerNode);
  630. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  631. if (IDYES != AfxMessageBox(IDS_REP_START_CONFIRM, MB_YESNO))
  632. return hrOK;
  633. int nItems = (int)m_RepPartnersArray.GetSize();
  634. DWORD err;
  635. for (int n = 0; n < nItems; n++)
  636. {
  637. CWinsServerObj ws;
  638. ws = m_RepPartnersArray.GetAt(n);
  639. BEGIN_WAIT_CURSOR
  640. if (ws.IsPull())
  641. {
  642. if ((err = ::SendTrigger(pServer->GetBinding(), (LONG) ws.GetIpAddress(), FALSE, FALSE)) != ERROR_SUCCESS)
  643. {
  644. ::WinsMessageBox(WIN32_FROM_HRESULT(err));
  645. continue;
  646. }
  647. }
  648. if (ws.IsPush())
  649. {
  650. if ((err = ::SendTrigger(pServer->GetBinding(), (LONG) ws.GetIpAddress(), TRUE, TRUE)) != ERROR_SUCCESS)
  651. {
  652. ::WinsMessageBox(WIN32_FROM_HRESULT(err));
  653. continue;
  654. }
  655. }
  656. END_WAIT_CURSOR
  657. }
  658. if (err == ERROR_SUCCESS)
  659. {
  660. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  661. }
  662. return HRESULT_FROM_WIN32(err);
  663. }
  664. /*---------------------------------------------------------------------------
  665. CReplicationPartnersHandler::OnCreateRepPartner
  666. Invokes new replication partner Wizard
  667. Author: v-shubk
  668. ---------------------------------------------------------------------------*/
  669. HRESULT
  670. CReplicationPartnersHandler::OnCreateRepPartner
  671. (
  672. ITFSNode * pNode
  673. )
  674. {
  675. HRESULT hr = hrOK;
  676. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  677. // check to see if the user has access
  678. SPITFSNode spServerNode;
  679. pNode->GetParent(&spServerNode);
  680. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  681. if (!pServer->GetConfig().IsAdmin())
  682. {
  683. // access denied
  684. WinsMessageBox(ERROR_ACCESS_DENIED);
  685. return hr;
  686. }
  687. // the user has access. ask for the partner info
  688. CNewReplicationPartner dlg;
  689. CThemeContextActivator themeActivator;
  690. dlg.m_spRepPartNode.Set(pNode);
  691. dlg.m_pRepPartHandler = this;
  692. if (dlg.DoModal() == IDOK)
  693. {
  694. // create the new replication partner
  695. CWinsServerObj ws;
  696. // grab the name and ip from the dlg
  697. ws.SetstrIPAddress(dlg.m_strServerIp);
  698. ws.SetIpAddress(dlg.m_strServerIp);
  699. ws.SetNetBIOSName(dlg.m_strServerName);
  700. // default is push/pull partner
  701. ws.SetPush(TRUE, TRUE);
  702. ws.SetPull(TRUE, TRUE);
  703. ws.SetPullClean(TRUE);
  704. ws.SetPushClean(TRUE);
  705. DWORD dwErr = AddRegEntry(pNode, ws);
  706. if (dwErr != ERROR_SUCCESS)
  707. {
  708. WinsMessageBox(dwErr);
  709. }
  710. else
  711. {
  712. HandleResultMessage(pNode);
  713. }
  714. }
  715. return hrOK;
  716. }
  717. /*---------------------------------------------------------------------------
  718. CReplicationPartnersHandler::Store(ITFSNode *pNode)
  719. Adds the new replication partner info to the registry
  720. Author: v-shubk
  721. ---------------------------------------------------------------------------*/
  722. HRESULT
  723. CReplicationPartnersHandler::Store
  724. (
  725. ITFSNode * pNode
  726. )
  727. {
  728. DWORD err = ERROR_SUCCESS;
  729. CString strServerName;
  730. GetServerName(pNode, strServerName);
  731. CString strTemp =_T("\\\\");
  732. strServerName = strTemp + strServerName;
  733. RegKey rkPull;
  734. err = rkPull.Create(HKEY_LOCAL_MACHINE,
  735. (LPCTSTR)lpstrPullRoot,
  736. REG_OPTION_NON_VOLATILE,
  737. KEY_ALL_ACCESS,
  738. NULL,
  739. strServerName);
  740. RegKey rkPush;
  741. err = rkPush.Create(HKEY_LOCAL_MACHINE,
  742. (LPCTSTR)lpstrPushRoot,
  743. REG_OPTION_NON_VOLATILE,
  744. KEY_ALL_ACCESS,
  745. NULL,
  746. strServerName);
  747. if (err)
  748. return HRESULT_FROM_WIN32(err);
  749. RegKeyIterator iterPushkey;
  750. RegKeyIterator iterPullkey;
  751. err = iterPushkey.Init(&rkPush);
  752. err = iterPullkey.Init(&rkPull);
  753. if (err)
  754. return HRESULT_FROM_WIN32(err);
  755. CWinsServerObj ws;
  756. CString strName;
  757. // Read in push partners
  758. while ((err = iterPushkey.Next(&strName, NULL)) == ERROR_SUCCESS )
  759. {
  760. // Key name is the IP address.
  761. ws.SetIpAddress(strName);
  762. ws.SetstrIPAddress(strName);
  763. CString strKey = (CString)lpstrPushRoot + _T("\\") + strName;
  764. RegKey rk;
  765. err = rk.Create(HKEY_LOCAL_MACHINE,
  766. strKey,
  767. 0,
  768. KEY_ALL_ACCESS,
  769. NULL,
  770. strServerName);
  771. if (err)
  772. {
  773. return HRESULT_FROM_WIN32(err);
  774. }
  775. if (err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName()))
  776. {
  777. // This replication partner is does not have a netbios
  778. // name listed with it. This is not a major problem,
  779. // as the name is for display purposes only.
  780. CString strTemp;
  781. strTemp.LoadString(IDS_NAME_UNKNOWN);
  782. ws.GetNetBIOSName() = strTemp;
  783. }
  784. DWORD dwTest;
  785. if (rk.QueryValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&) dwTest) != ERROR_SUCCESS)
  786. {
  787. ws.GetPushUpdateCount() = 0;
  788. }
  789. ws.SetPush(TRUE, TRUE);
  790. // Make sure the Pull intervals are reset.
  791. ws.SetPull(FALSE, TRUE);
  792. ws.GetPullReplicationInterval() = 0;
  793. ws.GetPullStartTime() = (time_t)0;
  794. m_RepPartnersArray.Add(ws);
  795. }
  796. // Read in pull partners
  797. while ((err = iterPullkey.Next(&strName, NULL)) == ERROR_SUCCESS)
  798. {
  799. // Key name is the IP address.
  800. ws.SetIpAddress(strName);
  801. ws.SetstrIPAddress(strName);
  802. CString strKey = (CString)lpstrPullRoot + _T("\\") + strName;
  803. RegKey rk;
  804. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  805. if (err)
  806. {
  807. return HRESULT_FROM_WIN32(err);
  808. }
  809. if (err = rk.QueryValue(lpstrNetBIOSName, ws.GetNetBIOSName()))
  810. {
  811. // No netbios name given.
  812. CString strTemp;
  813. strTemp.LoadString(IDS_NAME_UNKNOWN);
  814. ws.GetNetBIOSName() = strTemp;
  815. }
  816. DWORD dwPullInt;
  817. if (rk.QueryValue(WINSCNF_RPL_INTERVAL_NM, (DWORD &)dwPullInt) != ERROR_SUCCESS)
  818. {
  819. ws.GetPullReplicationInterval() = 0;
  820. }
  821. else
  822. {
  823. ws.GetPullReplicationInterval() = dwPullInt;
  824. }
  825. if (rk.QueryValue(WINSCNF_SP_TIME_NM, (DWORD &)dwPullInt) != ERROR_SUCCESS)
  826. {
  827. ws.GetPullStartTime() = (time_t)0;
  828. }
  829. else
  830. {
  831. ws.GetPullStartTime() = (time_t)dwPullInt;
  832. }
  833. int pos;
  834. CWinsServerObj wsTarget;
  835. // If it's already in the list as a push partner,
  836. // then simply set the push flag, as this replication
  837. // partner is both a push and a pull partner.
  838. if ((pos = IsInList(ws))!= -1)
  839. {
  840. wsTarget = (CWinsServerObj)m_RepPartnersArray.GetAt(pos);
  841. ASSERT(wsTarget != NULL);
  842. wsTarget.SetPull(TRUE, TRUE);
  843. wsTarget.GetPullReplicationInterval() = ws.GetPullReplicationInterval();
  844. wsTarget.GetPullStartTime() = ws.GetPullStartTime();
  845. m_RepPartnersArray.SetAt(pos, wsTarget);
  846. }
  847. else
  848. {
  849. ws.SetPull(TRUE, TRUE);
  850. // Reset push flags
  851. ws.SetPush(FALSE, TRUE);
  852. ws.GetPushUpdateCount() = 0;
  853. m_RepPartnersArray.Add(ws);
  854. }
  855. }
  856. return hrOK;
  857. }
  858. /*---------------------------------------------------------------------------
  859. CReplicationPartnersHandler::OnResultDelete
  860. Deletes replication partner
  861. Author: v-shubk
  862. ---------------------------------------------------------------------------*/
  863. HRESULT
  864. CReplicationPartnersHandler::OnResultDelete
  865. (
  866. ITFSComponent * pComponent,
  867. LPDATAOBJECT pDataObject,
  868. MMC_COOKIE cookie,
  869. LPARAM arg,
  870. LPARAM param
  871. )
  872. {
  873. HRESULT hr = hrOK;
  874. DWORD err = ERROR_SUCCESS;
  875. CThemeContextActivator themeActivator;
  876. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  877. // translate the cookie into a node pointer
  878. SPITFSNode spReplicationPartnersHandler, spSelectedNode;
  879. m_spNodeMgr->FindNode(cookie, &spReplicationPartnersHandler);
  880. pComponent->GetSelectedNode(&spSelectedNode);
  881. Assert(spSelectedNode == spReplicationPartnersHandler);
  882. if (spSelectedNode != spReplicationPartnersHandler)
  883. return hr;
  884. SPITFSNode spServerNode ;
  885. spReplicationPartnersHandler->GetParent(&spServerNode);
  886. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  887. // build the list of selected nodes
  888. CTFSNodeList listNodesToDelete;
  889. hr = BuildSelectedItemList(pComponent, &listNodesToDelete);
  890. // Confirm with the user
  891. CString strMessage, strTemp;
  892. int nNodes = (int)listNodesToDelete.GetCount();
  893. if (nNodes > 1)
  894. {
  895. strTemp.Format(_T("%d"), nNodes);
  896. AfxFormatString1(strMessage, IDS_DELETE_ITEMS, (LPCTSTR) strTemp);
  897. }
  898. else
  899. {
  900. strMessage.LoadString(IDS_DELETE_ITEM);
  901. }
  902. if (AfxMessageBox(strMessage, MB_YESNO) == IDNO)
  903. {
  904. return NOERROR;
  905. }
  906. BOOL fAskedPurge = FALSE;
  907. BOOL fPurge = FALSE;
  908. while (listNodesToDelete.GetCount() > 0)
  909. {
  910. SPITFSNode spRepNode;
  911. spRepNode = listNodesToDelete.RemoveHead();
  912. CReplicationPartner * pItem = GETHANDLER(CReplicationPartner , spRepNode);
  913. CString str = pItem->GetServerName();
  914. // Do we also need to remove all references to this
  915. // WINS server from the database?
  916. if (!fAskedPurge)
  917. {
  918. int nReturn = AfxMessageBox(IDS_MSG_PURGE_WINS, MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_ICONQUESTION);
  919. fAskedPurge = TRUE;
  920. if (nReturn == IDYES)
  921. {
  922. fPurge = TRUE;
  923. }
  924. else if (nReturn == IDCANCEL)
  925. {
  926. //
  927. // Forget the whole thing
  928. //
  929. return NOERROR;
  930. }
  931. }
  932. CWinsServerObj pws = pItem->m_Server;
  933. if (pws.IsPush() || pws.IsPull())
  934. {
  935. pws.SetPush(FALSE);
  936. pws.SetPushClean(FALSE);
  937. pws.SetPull(FALSE);
  938. pws.SetPullClean(FALSE);
  939. err = UpdateReg(spReplicationPartnersHandler, &pws);
  940. }
  941. if (err == ERROR_SUCCESS && fPurge)
  942. {
  943. BEGIN_WAIT_CURSOR
  944. err = pServer->DeleteWinsServer((LONG) pws.GetIpAddress());
  945. END_WAIT_CURSOR
  946. }
  947. if (err == ERROR_SUCCESS)
  948. {
  949. int pos = IsInList(pws);
  950. m_RepPartnersArray.RemoveAt(pos,pws);
  951. //
  952. // Remove from UI now
  953. //
  954. spReplicationPartnersHandler->RemoveChild(spRepNode);
  955. spRepNode.Release();
  956. }
  957. if (err != ERROR_SUCCESS)
  958. {
  959. if (::WinsMessageBox(err, MB_OKCANCEL) == IDCANCEL)
  960. break;
  961. }
  962. }
  963. HandleResultMessage(spReplicationPartnersHandler);
  964. return hr;
  965. }
  966. /*---------------------------------------------------------------------------
  967. CReplicationPartnersHandler::OnResultRefresh
  968. Base handler override
  969. Author: v-shubk
  970. ---------------------------------------------------------------------------*/
  971. HRESULT
  972. CReplicationPartnersHandler::OnResultRefresh
  973. (
  974. ITFSComponent * pComponent,
  975. LPDATAOBJECT pDataObject,
  976. MMC_COOKIE cookie,
  977. LPARAM arg,
  978. LPARAM lParam
  979. )
  980. {
  981. HRESULT hr = hrOK;
  982. SPITFSNode spNode;
  983. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  984. BEGIN_WAIT_CURSOR
  985. OnRefreshNode(spNode, pDataObject);
  986. END_WAIT_CURSOR
  987. Error:
  988. return hr;
  989. }
  990. /*!--------------------------------------------------------------------------
  991. CReplicationPartnersHandler::OnResultSelect
  992. Handles the MMCN_SELECT notifcation
  993. Author: EricDav
  994. ---------------------------------------------------------------------------*/
  995. HRESULT
  996. CReplicationPartnersHandler::OnResultSelect
  997. (
  998. ITFSComponent * pComponent,
  999. LPDATAOBJECT pDataObject,
  1000. MMC_COOKIE cookie,
  1001. LPARAM arg,
  1002. LPARAM lParam
  1003. )
  1004. {
  1005. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1006. HRESULT hr = hrOK;
  1007. SPITFSNode spNode;
  1008. CORg(CWinsHandler::OnResultSelect(pComponent, pDataObject, cookie, arg, lParam));
  1009. m_spResultNodeMgr->FindNode(cookie, &spNode);
  1010. HandleResultMessage(spNode);
  1011. Error:
  1012. return hr;
  1013. }
  1014. /*!--------------------------------------------------------------------------
  1015. CReplicationPartnersHandler::HandleResultMessage
  1016. Displays the message in the result pane
  1017. Author: EricDav
  1018. ---------------------------------------------------------------------------*/
  1019. HRESULT
  1020. CReplicationPartnersHandler::HandleResultMessage(ITFSNode * pNode)
  1021. {
  1022. HRESULT hr = hrOK;
  1023. if (m_RepPartnersArray.GetSize() == 0)
  1024. {
  1025. CString strTitle, strBody, strTemp;
  1026. int i;
  1027. strTitle.LoadString(IDS_REPLICATION_PARTNERS_MESSAGE_TITLE);
  1028. for (i = 0; ; i++)
  1029. {
  1030. if (guReplicationPartnersMessageStrings[i] == -1)
  1031. break;
  1032. strTemp.LoadString(guReplicationPartnersMessageStrings[i]);
  1033. strBody += strTemp;
  1034. }
  1035. ShowMessage(pNode, strTitle, strBody, Icon_Information);
  1036. }
  1037. else
  1038. {
  1039. ClearMessage(pNode);
  1040. }
  1041. return hr;
  1042. }
  1043. /*---------------------------------------------------------------------------
  1044. CReplicationPartnersHandler::OnRefreshNode
  1045. refreshes the list of replication partners
  1046. Author: v-shubk
  1047. ---------------------------------------------------------------------------*/
  1048. HRESULT
  1049. CReplicationPartnersHandler::OnRefreshNode
  1050. (
  1051. ITFSNode * pNode,
  1052. LPDATAOBJECT pDataObject
  1053. )
  1054. {
  1055. HRESULT hr = hrOK;
  1056. // remove the nodes first
  1057. hr = RemoveChildren(pNode);
  1058. hr = Load(pNode);
  1059. if (SUCCEEDED(hr))
  1060. {
  1061. DWORD err = CreateNodes(pNode);
  1062. HandleResultMessage(pNode);
  1063. }
  1064. return hr;
  1065. }
  1066. /*---------------------------------------------------------------------------
  1067. CReplicationPartnersHandler:: RemoveChildren
  1068. Deletes the child nodes
  1069. Author: v-shubk
  1070. ---------------------------------------------------------------------------*/
  1071. HRESULT
  1072. CReplicationPartnersHandler:: RemoveChildren
  1073. (
  1074. ITFSNode* pNode
  1075. )
  1076. {
  1077. // enumerate thro' all the nodes
  1078. HRESULT hr = hrOK;
  1079. SPITFSNodeEnum spNodeEnum;
  1080. SPITFSNode spCurrentNode;
  1081. ULONG nNumReturned = 0;
  1082. // get the enumerator for this node
  1083. pNode->GetEnum(&spNodeEnum);
  1084. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1085. while (nNumReturned)
  1086. {
  1087. // walk the list of replication servers
  1088. pNode->RemoveChild(spCurrentNode);
  1089. spCurrentNode.Release();
  1090. // get the next Server in the list
  1091. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1092. }
  1093. return hr;
  1094. }
  1095. /*---------------------------------------------------------------------------
  1096. CReplicationPartnersHandler::OnGetResultViewType
  1097. Overridden for multiple selection
  1098. Author: v-shubk
  1099. ---------------------------------------------------------------------------*/
  1100. HRESULT
  1101. CReplicationPartnersHandler::OnGetResultViewType
  1102. (
  1103. ITFSComponent * pComponent,
  1104. MMC_COOKIE cookie,
  1105. LPOLESTR * ppViewType,
  1106. long * pViewOptions
  1107. )
  1108. {
  1109. HRESULT hr = hrOK;
  1110. // call the base class to see if it is handling this
  1111. if (CWinsHandler::OnGetResultViewType(pComponent, cookie, ppViewType, pViewOptions) != S_OK)
  1112. {
  1113. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  1114. hr = S_FALSE;
  1115. }
  1116. return hr;
  1117. }
  1118. /*---------------------------------------------------------------------------
  1119. CReplicationPartnersHandler::UpdateReg()
  1120. Updates the regisrty, called from OnApply()
  1121. ---------------------------------------------------------------------------*/
  1122. DWORD
  1123. CReplicationPartnersHandler::UpdateReg(ITFSNode *pNode, CWinsServerObj* pws)
  1124. {
  1125. DWORD err = ERROR_SUCCESS;
  1126. HRESULT hr = hrOK;
  1127. CString strServerName;
  1128. GetServerName(pNode, strServerName);
  1129. const DWORD dwZero = 0;
  1130. CString strTemp =_T("\\\\");
  1131. strServerName = strTemp + strServerName;
  1132. RegKey rkPush;
  1133. RegKey rkPull;
  1134. CString strKey = lpstrPushRoot + _T("\\") + (CString)pws->GetstrIPAddress();
  1135. err = rkPush.Create(HKEY_LOCAL_MACHINE,
  1136. (CString)lpstrPushRoot,
  1137. 0,
  1138. KEY_ALL_ACCESS,
  1139. NULL,
  1140. strServerName);
  1141. if (err)
  1142. return err;
  1143. strKey = lpstrPullRoot + _T("\\") + (CString)pws->GetstrIPAddress();
  1144. err = rkPull.Create(HKEY_LOCAL_MACHINE,
  1145. (CString)lpstrPullRoot,
  1146. 0,
  1147. KEY_ALL_ACCESS,
  1148. NULL,
  1149. strServerName);
  1150. if (err)
  1151. return err;
  1152. RegKeyIterator iterPushkey;
  1153. RegKeyIterator iterPullkey;
  1154. hr = iterPushkey.Init(&rkPush);
  1155. if (FAILED(hr))
  1156. return WIN32_FROM_HRESULT(hr);
  1157. hr = iterPullkey.Init(&rkPull);
  1158. if (FAILED(hr))
  1159. return WIN32_FROM_HRESULT(hr);
  1160. DWORD errDel;
  1161. CString csKeyName;
  1162. // if none, delete the key from registry
  1163. if (!pws->IsPush() && !pws->IsPull())
  1164. {
  1165. // cleanup push partners list
  1166. hr = iterPushkey.Next (&csKeyName, NULL);
  1167. while (hr != S_FALSE && SUCCEEDED(hr))
  1168. {
  1169. if (csKeyName == pws->GetstrIPAddress())
  1170. {
  1171. errDel = RegDeleteKey (HKEY(rkPush), csKeyName);
  1172. iterPushkey.Reset();
  1173. }
  1174. hr = iterPushkey.Next (&csKeyName, NULL);
  1175. }
  1176. if (FAILED(hr))
  1177. err = WIN32_FROM_HRESULT(hr);
  1178. hr = iterPullkey.Next (&csKeyName, NULL);
  1179. while (hr != S_FALSE && SUCCEEDED(hr))
  1180. {
  1181. if (csKeyName == pws->GetstrIPAddress())
  1182. {
  1183. errDel = RegDeleteKey (HKEY(rkPull), csKeyName);
  1184. iterPullkey.Reset();
  1185. }
  1186. hr = iterPullkey.Next (&csKeyName, NULL);
  1187. }
  1188. if (FAILED(hr))
  1189. err = WIN32_FROM_HRESULT(hr);
  1190. }
  1191. return err;
  1192. }
  1193. /*---------------------------------------------------------------------------
  1194. CReplicationPartnersHandler::UpdateReg(ITFSNode *pNode,
  1195. CWinsServerObj* pws)
  1196. Creates a new replication partner entry
  1197. ---------------------------------------------------------------------------*/
  1198. DWORD
  1199. CReplicationPartnersHandler::AddRegEntry(ITFSNode * pNode, CWinsServerObj & ws)
  1200. {
  1201. // get the server handler for default values
  1202. SPITFSNode spServerNode;
  1203. pNode->GetParent(&spServerNode);
  1204. CWinsServerHandler * pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  1205. // Set the defaults
  1206. ws.SetPushUpdateCount(pServer->GetConfig().m_dwPushUpdateCount);
  1207. ws.SetPullReplicationInterval(pServer->GetConfig().m_dwPullTimeInterval);
  1208. ws.SetPullStartTime(pServer->GetConfig().m_dwPullSpTime);
  1209. ws.SetPullPersistence(pServer->GetConfig().m_dwPullPersistence);
  1210. ws.SetPushPersistence(pServer->GetConfig().m_dwPushPersistence);
  1211. // write the information to the registry
  1212. CString strTemp =_T("\\\\");
  1213. CString strServerName;
  1214. GetServerName(pNode, strServerName);
  1215. strServerName = strTemp + strServerName;
  1216. DWORD err;
  1217. DWORD dwZero = 0;
  1218. RegKey rk;
  1219. if (ws.IsPush())
  1220. {
  1221. CString strKey = lpstrPushRoot + _T("\\") + (CString)ws.GetstrIPAddress();
  1222. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  1223. DWORD dwResult;
  1224. if (!err)
  1225. {
  1226. err = rk.SetValue(lpstrNetBIOSName, ws.GetNetBIOSName());
  1227. if (!err)
  1228. err = rk.QueryValue(WINSCNF_SELF_FND_NM, (DWORD&)dwResult);
  1229. if (err)
  1230. err = rk.SetValue(WINSCNF_SELF_FND_NM,(DWORD&) dwZero);
  1231. DWORD dwPushUpdateCount = (LONG) ws.GetPushUpdateCount();
  1232. if (dwPushUpdateCount > 0)
  1233. err = rk.SetValue(WINSCNF_UPDATE_COUNT_NM, (DWORD&)dwPushUpdateCount);
  1234. DWORD dwPersistence = ws.GetPushPersistence();
  1235. err = rk.SetValue(lpstrPersistence, dwPersistence);
  1236. }
  1237. }
  1238. if (ws.IsPull())
  1239. {
  1240. CString strKey = lpstrPullRoot + _T("\\") + (CString)ws.GetstrIPAddress();
  1241. err = rk.Create(HKEY_LOCAL_MACHINE, strKey, 0, KEY_ALL_ACCESS, NULL, strServerName);
  1242. DWORD dwResult;
  1243. if (!err)
  1244. {
  1245. err = rk.SetValue(lpstrNetBIOSName, ws.GetNetBIOSName());
  1246. if (!err)
  1247. err = rk.QueryValue(WINSCNF_SELF_FND_NM, dwResult);
  1248. if (err)
  1249. err = rk.SetValue(WINSCNF_SELF_FND_NM, (DWORD) dwZero);
  1250. DWORD dwPullTimeInterval = (LONG) ws.GetPullReplicationInterval();
  1251. if (dwPullTimeInterval > 0)
  1252. {
  1253. err = rk.SetValue(WINSCNF_RPL_INTERVAL_NM, dwPullTimeInterval);
  1254. }
  1255. DWORD dwSpTime = (DWORD) ws.GetPullStartTime();
  1256. if (!err)
  1257. {
  1258. if (dwSpTime > (time_t)0)
  1259. err = rk.SetValue(WINSCNF_SP_TIME_NM, ws.GetPullStartTime().IntlFormat(CIntlTime::TFRQ_MILITARY_TIME));
  1260. }
  1261. DWORD dwPersistence = ws.GetPullPersistence();
  1262. err = rk.SetValue(lpstrPersistence, dwPersistence);
  1263. }
  1264. }
  1265. if (err == ERROR_SUCCESS)
  1266. {
  1267. // add to the list of replication partners
  1268. m_RepPartnersArray.Add(ws);
  1269. SPITFSNode spNode;
  1270. SPITFSNodeMgr spNodeMgr;
  1271. pNode->GetNodeMgr(&spNodeMgr);
  1272. // Create a new node for this partner
  1273. CReplicationPartner *pRepNew = new CReplicationPartner(m_spTFSCompData, &ws);
  1274. CreateLeafTFSNode(&spNode,
  1275. &GUID_WinsReplicationPartnerLeafNodeType,
  1276. pRepNew,
  1277. pRepNew,
  1278. spNodeMgr);
  1279. // Tell the handler to initialize any specific data
  1280. pRepNew->InitializeNode((ITFSNode *) spNode);
  1281. pNode->AddChild(spNode);
  1282. pRepNew->Release();
  1283. }
  1284. return err;
  1285. }