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.

565 lines
15 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. //
  6. // nbprop.cpp
  7. // IPX summary node property sheet and property pages
  8. //
  9. // FILE HISTORY:
  10. #include "stdafx.h"
  11. #include "rtrutil.h" // smart MPR handle pointers
  12. #include "format.h" // FormatNumber function
  13. #include "IpxStaticNBName.h"
  14. #include "summary.h"
  15. #include "ipxrtdef.h"
  16. #include "filter.h"
  17. #include "ipxutil.h"
  18. extern "C"
  19. {
  20. #include "routprot.h"
  21. };
  22. // ---------------------------------------------------------------------------
  23. // IpxStaticNBNamePropertySheet::IpxStaticNBNamePropertySheet
  24. // Initialize the RtrPropertySheet and only Property Page.
  25. // Author: Deonb
  26. // ---------------------------------------------------------------------------
  27. IpxStaticNBNamePropertySheet::IpxStaticNBNamePropertySheet(ITFSNode *pNode,
  28. IComponentData *pComponentData,
  29. ITFSComponentData *pTFSCompData,
  30. LPCTSTR pszSheetName,
  31. CWnd *pParent,
  32. UINT iPage,
  33. BOOL fScopePane)
  34. : RtrPropertySheet(pNode, pComponentData, pTFSCompData,
  35. pszSheetName, pParent, iPage, fScopePane),
  36. m_pageGeneral(IDD_STATIC_NETBIOS_NAME_PROPERTYPAGE)
  37. {
  38. m_spNode = pNode;
  39. }
  40. // ---------------------------------------------------------------------------
  41. // IpxStaticNBNamePropertySheet::Init
  42. // Initialize the property sheets. The general action here will be
  43. // to initialize/add the various pages.
  44. // Author: Deonb
  45. // ---------------------------------------------------------------------------
  46. HRESULT IpxStaticNBNamePropertySheet::Init(
  47. BaseIPXResultNodeData *pNodeData,
  48. IInterfaceInfo * spInterfaceInfo)
  49. {
  50. HRESULT hr = hrOK;
  51. BaseIPXResultNodeData * pData;
  52. m_pNodeData = pNodeData;
  53. m_spInterfaceInfo = spInterfaceInfo;
  54. pData = GET_BASEIPXRESULT_NODEDATA(m_spNode);
  55. ASSERT_BASEIPXRESULT_NODEDATA(pData);
  56. // The pages are embedded members of the class
  57. // do not delete them.
  58. m_bAutoDeletePages = FALSE;
  59. m_pageGeneral.Init(pNodeData, this);
  60. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  61. return S_OK;
  62. }
  63. // ---------------------------------------------------------------------------
  64. // IpxStaticNBNamePropertySheet::SaveSheetData
  65. // Not sure what this does - this is never called. Kenn had this so I'll just
  66. // copy this too.
  67. // Author: Deonb
  68. // ---------------------------------------------------------------------------
  69. BOOL IpxStaticNBNamePropertySheet::SaveSheetData()
  70. {
  71. SPITFSNodeHandler spHandler;
  72. SPITFSNode spParent;
  73. // By this time each page should have written its information out
  74. // to the infobase
  75. // Force the node to do a resync
  76. m_spNode->GetParent(&spParent);
  77. spParent->GetHandler(&spHandler);
  78. spHandler->OnCommand(spParent, IDS_MENU_SYNC, CCT_RESULT,
  79. NULL, 0);
  80. return TRUE;
  81. }
  82. // --------------------------------------------------------------------------
  83. // IpxStaticNBNamePropertySheet::CancelSheetData
  84. // -
  85. // Author: Deonb
  86. // ---------------------------------------------------------------------------
  87. void IpxStaticNBNamePropertySheet::CancelSheetData()
  88. {
  89. }
  90. // ***************************************************************************
  91. // ---------------------------------------------------------------------------
  92. // IpxStaticNBNamePropertyPage
  93. // ---------------------------------------------------------------------------
  94. IpxStaticNBNamePropertyPage::~IpxStaticNBNamePropertyPage()
  95. {
  96. }
  97. BEGIN_MESSAGE_MAP(IpxStaticNBNamePropertyPage, RtrPropertyPage)
  98. //{{AFX_MSG_MAP(IpxStaticNBNamePropertyPage)
  99. //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101. void IpxStaticNBNamePropertyPage::OnChangeButton()
  102. {
  103. SetDirty(TRUE);
  104. SetModified();
  105. }
  106. //--------------------------------------------------------------------------
  107. // IpxStaticNBNamePropertyPage::Init
  108. // -
  109. // Author: Deonb
  110. //---------------------------------------------------------------------------
  111. HRESULT IpxStaticNBNamePropertyPage::Init(BaseIPXResultNodeData *pNodeData,
  112. IpxStaticNBNamePropertySheet * pIPXPropSheet)
  113. {
  114. ATLASSERT(pSREntry);
  115. ATLASSERT(pIPXPropSheet);
  116. m_pIPXPropSheet = pIPXPropSheet;
  117. m_SNEntry.LoadFrom(pNodeData);
  118. m_InitSNEntry = m_SNEntry;
  119. return hrOK;
  120. }
  121. // --------------------------------------------------------------------------
  122. // IpxStaticNBNamePropertyPage::OnInitDialog
  123. // -
  124. // Author: Deonb
  125. // ---------------------------------------------------------------------------
  126. BOOL IpxStaticNBNamePropertyPage::OnInitDialog()
  127. {
  128. HRESULT hr = hrOK;
  129. PBYTE pData;
  130. DWORD dwIfType;
  131. UINT iButton;
  132. TCHAR szName[32];
  133. TCHAR szType[32];
  134. CString st;
  135. USHORT uType;
  136. RtrPropertyPage::OnInitDialog();
  137. ((CEdit *) GetDlgItem(IDC_SND_EDIT_NAME))->LimitText(15);
  138. ((CEdit *) GetDlgItem(IDC_SND_EDIT_TYPE))->LimitText(2);
  139. FormatNetBIOSName(szName, &uType, (LPCSTR) m_SNEntry.m_name.Name);
  140. st = szName;
  141. st.TrimRight();
  142. st.TrimLeft();
  143. SetDlgItemText(IDC_SND_EDIT_NAME, st);
  144. wsprintf(szType, _T("%.2x"), uType);
  145. SetDlgItemText(IDC_SND_EDIT_TYPE, szType);
  146. return TRUE;
  147. }
  148. // --------------------------------------------------------------------------
  149. // IpxStaticNBNamePropertyPage::DoDataExchange
  150. // -
  151. // Author: Deonb
  152. // ---------------------------------------------------------------------------
  153. void IpxStaticNBNamePropertyPage::DoDataExchange(CDataExchange *pDX)
  154. {
  155. RtrPropertyPage::DoDataExchange(pDX);
  156. //{{AFX_DATA_MAP(IpxStaticNBNamePropertyPage)
  157. //}}AFX_DATA_MAP
  158. }
  159. // --------------------------------------------------------------------------
  160. // IpxStaticNBNamePropertyPage::OnApply
  161. // -
  162. // Author: Deonb
  163. // ---------------------------------------------------------------------------
  164. BOOL IpxStaticNBNamePropertyPage::OnApply()
  165. {
  166. CString st;
  167. BOOL fReturn;
  168. HRESULT hr = hrOK;
  169. USHORT uType;
  170. if ( m_pIPXPropSheet->IsCancel() )
  171. {
  172. CancelApply();
  173. return TRUE;
  174. }
  175. // Get the rest of the data
  176. GetDlgItemText(IDC_SND_EDIT_TYPE, st);
  177. uType = (USHORT) _tcstoul(st, NULL, 16);
  178. GetDlgItemText(IDC_SND_EDIT_NAME, st);
  179. st.TrimLeft();
  180. st.TrimRight();
  181. if (st.IsEmpty())
  182. {
  183. GetDlgItem(IDC_SND_EDIT_NAME)->SetFocus();
  184. AfxMessageBox(IDS_ERR_INVALID_NETBIOS_NAME);
  185. return FALSE;
  186. }
  187. ConvertToNetBIOSName((LPSTR) m_SNEntry.m_name.Name, st, uType);
  188. ModifyNameInfo(m_pIPXPropSheet->m_spNode, &m_SNEntry, &m_InitSNEntry);
  189. // Update the data in the UI
  190. m_SNEntry.SaveTo(m_pIPXPropSheet->m_pNodeData);
  191. m_pIPXPropSheet->m_spInterfaceInfo = m_SNEntry.m_spIf;
  192. // Force a refresh
  193. m_pIPXPropSheet->m_spNode->ChangeNode(RESULT_PANE_CHANGE_ITEM_DATA);
  194. fReturn = RtrPropertyPage::OnApply();
  195. return fReturn;
  196. }
  197. /*
  198. // --------------------------------------------------------------------------
  199. // IpxStaticNBNamePropertyPage::RemoveStaticService
  200. // -
  201. // Author: KennT
  202. // ---------------------------------------------------------------------------
  203. HRESULT IpxStaticNBNamePropertyPage::RemoveStaticService(SafeIPXSNListEntry *pSSEntry,
  204. IInfoBase *pInfoBase)
  205. {
  206. HRESULT hr = hrOK;
  207. InfoBlock * pBlock;
  208. PIPX_STATIC_SERVICE_INFO pRow;
  209. INT i;
  210. // Get the IPX_STATIC_SERVICE_INFO block from the interface
  211. CORg( pInfoBase->GetBlock(IPX_STATIC_SERVICE_INFO_TYPE, &pBlock, 0) );
  212. // Look for the removed route in the IPX_STATIC_SERVICE_INFO
  213. pRow = (IPX_STATIC_SERVICE_INFO*) pBlock->pData;
  214. for (i = 0; i < (INT)pBlock->dwCount; i++, pRow++)
  215. {
  216. // Compare this route to the removed one
  217. if (FAreTwoServicesEqual(pRow, &(pSSEntry->m_service)))
  218. {
  219. // This is the removed route, so modify this block
  220. // to exclude the route:
  221. // Decrement the number of Services
  222. --pBlock->dwCount;
  223. if (pBlock->dwCount && (i < (INT)pBlock->dwCount))
  224. {
  225. // Overwrite this route with the ones which follow it
  226. ::memmove(pRow,
  227. pRow + 1,
  228. (pBlock->dwCount - i) * sizeof(*pRow));
  229. }
  230. break;
  231. }
  232. }
  233. Error:
  234. return hr;
  235. }
  236. */
  237. /*--------------------------------------------------------------------------
  238. IpxStaticNBNamePropertyPage::ModifyNameInfo
  239. -
  240. Author: Deonb
  241. ---------------------------------------------------------------------------*/
  242. HRESULT IpxStaticNBNamePropertyPage::ModifyNameInfo(ITFSNode *pNode,
  243. SafeIPXSNListEntry *pSNEntryNew,
  244. SafeIPXSNListEntry *pSNEntryOld)
  245. {
  246. Assert(pSNEntryNew);
  247. Assert(pSNEntryOld);
  248. INT i;
  249. HRESULT hr = hrOK;
  250. InfoBlock* pBlock;
  251. SPIInfoBase spInfoBase;
  252. SPIRtrMgrInterfaceInfo spRmIf;
  253. SPITFSNode spNodeParent;
  254. IPXConnection * pIPXConn;
  255. IPX_STATIC_NETBIOS_NAME_INFO *psr, *psrOld;
  256. IPX_STATIC_NETBIOS_NAME_INFO IpxRow;
  257. CWaitCursor wait;
  258. pNode->GetParent(&spNodeParent);
  259. pIPXConn = GET_IPX_SN_NODEDATA(spNodeParent);
  260. Assert(pIPXConn);
  261. // Remove the old name if it is on another interface
  262. if (lstrcmpi(pSNEntryOld->m_spIf->GetId(), pSNEntryNew->m_spIf->GetId()) != 0)
  263. {
  264. // the outgoing interface for a name is to be changed.
  265. CORg( pSNEntryOld->m_spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) );
  266. CORg( spRmIf->GetInfoBase(pIPXConn->GetConfigHandle(),
  267. NULL,
  268. NULL,
  269. &spInfoBase));
  270. // Remove the old interface
  271. CORg( RemoveStaticNetBIOSName(pSNEntryOld, spInfoBase) );
  272. // Update the interface information
  273. CORg( spRmIf->Save(pSNEntryOld->m_spIf->GetMachineName(),
  274. pIPXConn->GetConfigHandle(),
  275. NULL,
  276. NULL,
  277. spInfoBase,
  278. 0));
  279. }
  280. spRmIf.Release();
  281. spInfoBase.Release();
  282. // Either
  283. // (a) a name is being modified (on the same interface)
  284. // (b) a name is being moved from one interface to another.
  285. // Retrieve the configuration for the interface to which the name
  286. // is now attached;
  287. CORg( pSNEntryNew->m_spIf->FindRtrMgrInterface(PID_IPX, &spRmIf) );
  288. CORg( spRmIf->GetInfoBase(pIPXConn->GetConfigHandle(),
  289. NULL,
  290. NULL,
  291. &spInfoBase));
  292. // Get the IPX_STATIC_NETBIOS_NAME_INFO block from the interface
  293. hr = spInfoBase->GetBlock(IPX_STATIC_NETBIOS_NAME_INFO_TYPE, &pBlock, 0);
  294. if (!FHrOK(hr))
  295. {
  296. //
  297. // No IPX_STATIC_NETBIOS_NAME_INFO block was found; we create a new block
  298. // with the new name, and add that block to the interface-info
  299. //
  300. CORg( AddStaticNetBIOSName(pSNEntryNew, spInfoBase, NULL) );
  301. }
  302. else
  303. {
  304. //
  305. // An IPX_STATIC_NETBIOS_NAME_INFO block was found.
  306. //
  307. // We are modifying an existing name.
  308. // If the name's interface was not changed when it was modified,
  309. // look for the existing name in the IPX_STATIC_NETBIOS_NAME_INFO, and then
  310. // update its parameters.
  311. // Otherwise, write a completely new name in the IPX_STATIC_NETBIOS_NAME_INFO;
  312. //
  313. if (lstrcmpi(pSNEntryOld->m_spIf->GetId(), pSNEntryNew->m_spIf->GetId()) == 0)
  314. {
  315. //
  316. // The name's interface was not changed when it was modified;
  317. // We now look for it amongst the existing Names
  318. // for this interface.
  319. // The name's original parameters are in 'preOld',
  320. // so those are the parameters with which we search
  321. // for a name to modify
  322. //
  323. psr = (IPX_STATIC_NETBIOS_NAME_INFO*)pBlock->pData;
  324. for (i = 0; i < (INT)pBlock->dwCount; i++, psr++)
  325. {
  326. // Compare this name to the re-configured one
  327. if (!FAreTwoNamesEqual(&(pSNEntryOld->m_name), psr))
  328. continue;
  329. // This is the name which was modified;
  330. // We can now modify the parameters for the name in-place.
  331. *psr = pSNEntryNew->m_name;
  332. break;
  333. }
  334. }
  335. else
  336. {
  337. CORg( AddStaticNetBIOSName(pSNEntryNew, spInfoBase, pBlock) );
  338. }
  339. // Save the updated information
  340. CORg( spRmIf->Save(pSNEntryNew->m_spIf->GetMachineName(),
  341. pIPXConn->GetConfigHandle(),
  342. NULL,
  343. NULL,
  344. spInfoBase,
  345. 0));
  346. }
  347. Error:
  348. return hr;
  349. }
  350. /*!--------------------------------------------------------------------------
  351. SafeIpxSNListEntry::LoadFrom
  352. -
  353. Author: Deonb
  354. ---------------------------------------------------------------------------*/
  355. void SafeIPXSNListEntry::LoadFrom(BaseIPXResultNodeData *pNodeData)
  356. {
  357. m_spIf = pNodeData->m_spIf;
  358. ConvertToNetBIOSName((LPSTR) m_name.Name,
  359. pNodeData->m_rgData[IPX_SN_SI_NETBIOS_NAME].m_stData,
  360. (USHORT) pNodeData->m_rgData[IPX_SN_SI_NETBIOS_TYPE].m_dwData);
  361. }
  362. /*!--------------------------------------------------------------------------
  363. SafeIpxSNListEntry::SaveTo
  364. -
  365. Author: Deonb
  366. ---------------------------------------------------------------------------*/
  367. void SafeIPXSNListEntry::SaveTo(BaseIPXResultNodeData *pNodeData)
  368. {
  369. TCHAR szName[32];
  370. TCHAR szType[32];
  371. CString st;
  372. USHORT uType;
  373. FormatNetBIOSName(szName, &uType,
  374. (LPCSTR) m_name.Name);
  375. st = szName;
  376. st.TrimLeft();
  377. st.TrimRight();
  378. pNodeData->m_spIf.Set(m_spIf);
  379. pNodeData->m_rgData[IPX_SN_SI_NAME].m_stData = m_spIf->GetTitle();
  380. pNodeData->m_rgData[IPX_SN_SI_NETBIOS_NAME].m_stData = st;
  381. wsprintf(szType, _T("%.2x"), uType);
  382. pNodeData->m_rgData[IPX_SN_SI_NETBIOS_TYPE].m_stData = szType;
  383. pNodeData->m_rgData[IPX_SN_SI_NETBIOS_TYPE].m_dwData = uType;
  384. }
  385. /*!--------------------------------------------------------------------------
  386. IpxStaticNetBIOSNameHandler::RemoveStaticNetBIOSName
  387. -
  388. Author: KennT
  389. ---------------------------------------------------------------------------*/
  390. HRESULT IpxStaticNBNamePropertyPage::RemoveStaticNetBIOSName(SafeIPXSNListEntry *pSNEntry,
  391. IInfoBase *pInfoBase)
  392. {
  393. HRESULT hr = hrOK;
  394. InfoBlock * pBlock;
  395. PIPX_STATIC_NETBIOS_NAME_INFO pRow;
  396. INT i;
  397. // Get the IPX_STATIC_NETBIOS_NAME_INFO block from the interface
  398. CORg( pInfoBase->GetBlock(IPX_STATIC_NETBIOS_NAME_INFO_TYPE, &pBlock, 0) );
  399. // Look for the removed name in the IPX_STATIC_NETBIOS_NAME_INFO
  400. pRow = (IPX_STATIC_NETBIOS_NAME_INFO*) pBlock->pData;
  401. for (i = 0; i < (INT)pBlock->dwCount; i++, pRow++)
  402. {
  403. // Compare this name to the removed one
  404. if (FAreTwoNamesEqual(pRow, &(pSNEntry->m_name)))
  405. {
  406. // This is the removed name, so modify this block
  407. // to exclude the name:
  408. // Decrement the number of Names
  409. --pBlock->dwCount;
  410. if (pBlock->dwCount && (i < (INT)pBlock->dwCount))
  411. {
  412. // Overwrite this name with the ones which follow it
  413. ::memmove(pRow,
  414. pRow + 1,
  415. (pBlock->dwCount - i) * sizeof(*pRow));
  416. }
  417. break;
  418. }
  419. }
  420. Error:
  421. return hr;
  422. }
  423. HRESULT AddStaticNetBIOSName(SafeIPXSNListEntry *pSNEntryNew,
  424. IInfoBase *pInfoBase,
  425. InfoBlock *pBlock)
  426. {
  427. IPX_STATIC_NETBIOS_NAME_INFO srRow;
  428. HRESULT hr = hrOK;
  429. if (pBlock == NULL)
  430. {
  431. //
  432. // No IPX_STATIC_NETBIOS_NAME_INFO block was found; we create a new block
  433. // with the new name, and add that block to the interface-info
  434. //
  435. CORg( pInfoBase->AddBlock(IPX_STATIC_NETBIOS_NAME_INFO_TYPE,
  436. sizeof(IPX_STATIC_NETBIOS_NAME_INFO),
  437. (LPBYTE) &(pSNEntryNew->m_name), 1, 0) );
  438. }
  439. else
  440. {
  441. // Either the name is completely new, or it is a name
  442. // which was moved from one interface to another.
  443. // Set a new block as the IPX_STATIC_NETBIOS_NAME_INFO,
  444. // and include the re-configured name in the new block.
  445. PIPX_STATIC_NETBIOS_NAME_INFO psrTable;
  446. psrTable = new IPX_STATIC_NETBIOS_NAME_INFO[pBlock->dwCount + 1];
  447. Assert(psrTable);
  448. // Copy the original table of Names
  449. ::memcpy(psrTable, pBlock->pData,
  450. pBlock->dwCount * sizeof(IPX_STATIC_NETBIOS_NAME_INFO));
  451. // Append the new name
  452. psrTable[pBlock->dwCount] = pSNEntryNew->m_name;
  453. // Replace the old name-table with the new one
  454. CORg( pInfoBase->SetData(IPX_STATIC_NETBIOS_NAME_INFO_TYPE,
  455. sizeof(IPX_STATIC_NETBIOS_NAME_INFO),
  456. (LPBYTE) psrTable, pBlock->dwCount + 1, 0) );
  457. }
  458. Error:
  459. return hr;
  460. }