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.

1275 lines
29 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. statmapp.cpp
  7. Property Page for Active Registrations Record
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "winssnap.h"
  12. #include "statmapp.h"
  13. #include "server.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. // Static Record Types
  20. CString g_strStaticTypeUnique;
  21. CString g_strStaticTypeDomainName;
  22. CString g_strStaticTypeMultihomed;
  23. CString g_strStaticTypeGroup;
  24. CString g_strStaticTypeInternetGroup;
  25. CString g_strStaticTypeUnknown;
  26. /////////////////////////////////////////////////////////////////////////////
  27. static const char rgchHex[16*2+1] = "00112233445566778899aAbBcCdDeEfF";
  28. /*---------------------------------------------------------------------------
  29. FGetByte()
  30. Return the byte value of a string.
  31. Return TRUE pbNum is set to the byte value (only if the string contains
  32. valid digits)
  33. Return FALSE if string has unrecognized digits or byte overflow.
  34. eg:
  35. szNum = "xFF" => return TRUE
  36. szNum = "255" => return TRUE
  37. szNum = "256" => return FALSE (overflow)
  38. szNum = "26a" => return TRUE (*pbNum = 26, *ppchNext = "a")
  39. szNum = "ab" => return FALSE (unrecognized digits)
  40. ---------------------------------------------------------------------------*/
  41. BOOL
  42. FGetByte(IN const char szNum[], OUT BYTE * pbNum, OUT const char ** ppchNext)
  43. {
  44. ASSERT(szNum);
  45. ASSERT(pbNum);
  46. ASSERT(ppchNext);
  47. int nResult;
  48. char * pchNum = (char *)szNum;
  49. int iBase = 10; // Assume a decimal base
  50. if (*pchNum == 'x' || *pchNum == 'X') // Check if we are using hexadecimal base
  51. {
  52. iBase = 16;
  53. pchNum++;
  54. }
  55. char * pchDigit = strchr(rgchHex, *pchNum++);
  56. if (pchDigit == NULL)
  57. return FALSE;
  58. int iDigit = (int) ((pchDigit - rgchHex) >> 1);
  59. if (iDigit >= iBase)
  60. {
  61. // Hexadecimal character in a decimal integer
  62. return FALSE;
  63. }
  64. nResult = iDigit;
  65. pchDigit = strchr(rgchHex, *pchNum);
  66. iDigit = (int) ((pchDigit - rgchHex) >> 1);
  67. if (pchDigit == NULL || iDigit >= iBase)
  68. {
  69. // Only one character was valid
  70. *pbNum = (BYTE) nResult;
  71. *ppchNext = pchNum;
  72. return TRUE;
  73. }
  74. pchNum++;
  75. nResult = (nResult * iBase) + iDigit;
  76. ASSERT(nResult < 256);
  77. if (iBase == 16)
  78. {
  79. // Hexadecimal value, stop there
  80. *pbNum = (BYTE) nResult;
  81. *ppchNext = pchNum;
  82. return TRUE;
  83. }
  84. // Decimal digit, so search for an optional third character
  85. pchDigit = strchr(rgchHex, *pchNum);
  86. iDigit = (int) ((pchDigit - rgchHex) >> 1);
  87. if (pchDigit == NULL || iDigit >= iBase)
  88. {
  89. *pbNum = (BYTE) nResult;
  90. *ppchNext = pchNum;
  91. return TRUE;
  92. }
  93. nResult = (nResult * iBase) + iDigit;
  94. if (nResult >= 256)
  95. return FALSE;
  96. pchNum++;
  97. *pbNum = (BYTE) nResult;
  98. *ppchNext = pchNum;
  99. return TRUE;
  100. } // FGetByte
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CStaticMappingProp property page
  103. IMPLEMENT_DYNCREATE(CStaticMappingProp, CPropertyPageBase)
  104. CStaticMappingProp::CStaticMappingProp(UINT uIDD)
  105. : CPropertyPageBase(uIDD),
  106. m_fStaticPropChanged (TRUE),
  107. m_uIDD(uIDD)
  108. {
  109. //{{AFX_DATA_INIT(CStaticMappingProp)
  110. m_strName = _T("");
  111. m_strType = _T("");
  112. m_strScopeName = _T("");
  113. //}}AFX_DATA_INIT
  114. }
  115. CStaticMappingProp::~CStaticMappingProp()
  116. {
  117. }
  118. void
  119. CStaticMappingProp::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CPropertyPageBase::DoDataExchange(pDX);
  122. //{{AFX_DATA_MAP(CStaticMappingProp)
  123. DDX_Control(pDX, IDC_EDIT_SCOPE_NAME, m_editScopeName);
  124. DDX_Control(pDX, IDC_LIST_IPADD, m_listIPAdd);
  125. DDX_Control(pDX, IDC_BUTTON_REMOVE, m_buttonRemove);
  126. DDX_Control(pDX, IDC_BUTTON_ADD, m_buttonAdd);
  127. DDX_Control(pDX, IDC_EDIT_COMPNAME, m_editName);
  128. DDX_Control(pDX, IDC_COMBO_STATIC_TYPE, m_comboType);
  129. DDX_Text(pDX, IDC_EDIT_COMPNAME, m_strName);
  130. DDX_CBString(pDX, IDC_COMBO_STATIC_TYPE, m_strType);
  131. DDX_Text(pDX, IDC_EDIT_SCOPE_NAME, m_strScopeName);
  132. //}}AFX_DATA_MAP
  133. DDX_Control(pDX, IDC_IPADD, m_editCustomIPAdd);
  134. //DDX_Control(pDX, IDC_IPADD, m_ipControl);
  135. DDX_Text(pDX, IDC_IPADD, m_strIPAdd);
  136. }
  137. BEGIN_MESSAGE_MAP(CStaticMappingProp, CPropertyPageBase)
  138. //{{AFX_MSG_MAP(CStaticMappingProp)
  139. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  140. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  141. ON_CBN_SELCHANGE(IDC_COMBO_STATIC_TYPE, OnSelchangeComboType)
  142. ON_EN_CHANGE(IDC_EDIT_COMPNAME, OnChangeEditCompname)
  143. ON_LBN_SELCHANGE(IDC_LIST_IPADD, OnSelChangeListIpAdd)
  144. //}}AFX_MSG_MAP
  145. // IP Address control
  146. ON_EN_CHANGE(IDC_IPADD, OnChangeIpAddress)
  147. END_MESSAGE_MAP()
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CStaticMappingProp message handlers
  150. void CStaticMappingProp::OnOK()
  151. {
  152. CPropertyPageBase::OnOK();
  153. }
  154. BOOL
  155. CStaticMappingProp::OnApply()
  156. {
  157. HRESULT hr = hrOK;
  158. BOOL bRet = TRUE;
  159. // if not dirtied return
  160. if (!IsDirty())
  161. return TRUE;
  162. if (((CStaticMappingProperties*)GetHolder())->m_bWizard)
  163. {
  164. UpdateData();
  165. CActiveRegistrationsHandler *pActReg;
  166. SPITFSNode spNode;
  167. spNode = GetHolder()->GetNode();
  168. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  169. m_strName.TrimLeft();
  170. m_strName.TrimRight();
  171. int nMax = (pActReg->IsLanManCompatible()) ? 15 : 16;
  172. if (m_strName.IsEmpty())
  173. {
  174. CString strMessage, strTemp;
  175. strTemp.Format(_T("%d"), nMax);
  176. AfxFormatString1(strMessage, IDS_INVALID_NAME, strTemp);
  177. AfxMessageBox(strMessage);
  178. m_editName.SetFocus();
  179. m_editName.SetSel(0, -1);
  180. return FALSE;
  181. }
  182. else
  183. if (m_strType.IsEmpty())
  184. {
  185. AfxMessageBox(IDS_INVALID_TYPE, MB_OK);
  186. m_comboType.SetFocus();
  187. return FALSE;
  188. }
  189. CString strTemp;
  190. // check this only for Unique and Normal Group addresses,
  191. // for the rest, the ipcontrol is balnk and the list box holds the IP a
  192. // IP addresses for them.
  193. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  194. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  195. LONG lIPAdd = (LONG) MAKEIPADDRESS(dwIp1, dwIp2, dwIp3, dwIp4);
  196. // it's so bcoz' only in the case of Unique and Normal Group names,
  197. // IP address is read from the IP control, else from the list box
  198. if ( (m_strType.CompareNoCase(g_strStaticTypeUnique) == 0) || (m_strType.CompareNoCase(g_strStaticTypeGroup) == 0) )
  199. {
  200. if (nAdd != 4)
  201. {
  202. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  203. m_editCustomIPAdd.SetFocus();
  204. return FALSE;
  205. }
  206. // check if broadcast address has been entered
  207. if (m_strIPAdd.CompareNoCase(_T("255.255.255.255")) == 0)
  208. {
  209. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  210. m_editCustomIPAdd.SetFocus();
  211. return FALSE;
  212. }
  213. // check to make sure something was entered
  214. if ( (m_strIPAdd.IsEmpty()) ||
  215. (m_strIPAdd.CompareNoCase(_T("0.0.0.0")) == 0) )
  216. {
  217. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  218. m_editCustomIPAdd.SetFocus();
  219. m_editCustomIPAdd.SetSel(0,-1);
  220. return FALSE;
  221. }
  222. }
  223. else
  224. {
  225. if (m_listIPAdd.GetCount() == 0)
  226. {
  227. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  228. m_editCustomIPAdd.SetFocus();
  229. m_editCustomIPAdd.SetSel(0,-1);
  230. return FALSE;
  231. }
  232. }
  233. BOOL fInternetGroup = FALSE;
  234. if (m_strType.CompareNoCase(g_strStaticTypeInternetGroup) == 0)
  235. fInternetGroup = TRUE;
  236. // Parse the string
  237. BOOL fValid = TRUE;
  238. BOOL fBrackets = FALSE;
  239. BYTE rgbData[100];
  240. BYTE bDataT;
  241. int cbData = 0;
  242. LPSTR szTemp = (char*) alloca(100);
  243. // just use ACP here because we are just looking at the string
  244. // we will do the OEM conversion later.
  245. WideToMBCS(m_strName, szTemp);
  246. const char * pch = (LPCSTR)szTemp;
  247. while (*pch)
  248. {
  249. if (fBrackets)
  250. {
  251. fValid = FALSE;
  252. goto Done;
  253. }
  254. if (cbData > 16)
  255. goto Done;
  256. switch (*pch)
  257. {
  258. case '\\':
  259. pch++;
  260. if (*pch == '\\' || *pch == '[')
  261. {
  262. rgbData[cbData++] = *pch++;
  263. break;
  264. }
  265. if (!FGetByte(pch, &bDataT, &pch) || !bDataT)
  266. {
  267. fValid = FALSE;
  268. goto Done;
  269. }
  270. rgbData[cbData++] = bDataT;
  271. break;
  272. case '[':
  273. {
  274. char szT[4] = { 0 };
  275. const char * pchT;
  276. fBrackets = TRUE;
  277. pch++;
  278. if (*(pch + 1) == 'h' || *(pch + 1) == 'H')
  279. {
  280. szT[0] = 'x';
  281. szT[1] = *pch;
  282. pch += 2;
  283. }
  284. else if (*(pch + 2) == 'h' || *(pch + 2) == 'H')
  285. {
  286. szT[0] = 'x';
  287. szT[1] = *pch;
  288. szT[2] = *(pch + 1);
  289. pch += 3;
  290. }
  291. if (szT[0])
  292. {
  293. if (!FGetByte(szT, &bDataT, &pchT) || !bDataT || *pchT)
  294. {
  295. fValid = FALSE;
  296. goto Done;
  297. }
  298. }
  299. else if (!FGetByte(pch, &bDataT, &pch) || !bDataT)
  300. {
  301. fValid = FALSE;
  302. goto Done;
  303. }
  304. if (*pch++ != ']')
  305. {
  306. fValid = FALSE;
  307. goto Done;
  308. }
  309. while (cbData < 15)
  310. rgbData[cbData++] = ' ';
  311. rgbData[cbData++] = bDataT;
  312. }
  313. break;
  314. default:
  315. #ifdef FE_SB
  316. if (::IsDBCSLeadByte(*pch))
  317. rgbData[cbData++] = *pch++;
  318. #endif
  319. rgbData[cbData++] = *pch++;
  320. } // switch
  321. }
  322. Done:
  323. // Put a null-terminator at end of string
  324. rgbData[cbData] = 0;
  325. if (!cbData || cbData > nMax)
  326. {
  327. CString strMessage, strTemp;
  328. strTemp.Format(_T("%d"), nMax);
  329. AfxFormatString1(strMessage, IDS_INVALID_NAME, strTemp);
  330. AfxMessageBox(strMessage);
  331. m_editName.SetFocus();
  332. m_editName.SetSel(0,-1);
  333. return FALSE;
  334. }
  335. if (!fValid)
  336. {
  337. CString strMessage, strTemp;
  338. strTemp.Format(_T("%d"), nMax);
  339. AfxFormatString1(strMessage, IDS_INVALID_NAME, strTemp);
  340. AfxMessageBox(strMessage);
  341. m_editName.SetFocus();
  342. m_editName.SetSel(0,-1);
  343. return FALSE;
  344. }
  345. if (fInternetGroup && rgbData[15] == 0x1C)
  346. {
  347. AfxMessageBox(IDS_INVALID_INTERNET_GROUP_NAME);
  348. m_editName.SetFocus();
  349. m_editName.SetSel(0,-1);
  350. return FALSE;
  351. }
  352. if (fInternetGroup)
  353. {
  354. while (cbData <= 15)
  355. rgbData[cbData++] = ' ';
  356. rgbData[cbData] = 0;
  357. }
  358. szTemp = (LPSTR)rgbData;
  359. // convert our touched up string back to unicode for use later
  360. MBCSToWide(szTemp, pActReg->m_strStaticMappingName);
  361. //pActReg->m_strStaticMappingName = rgbData;
  362. pActReg->m_strStaticMappingScope = m_strScopeName;
  363. pActReg->m_strStaticMappingType = m_strType;
  364. AssignMappingType();
  365. pActReg->m_nStaticMappingType = m_fType;
  366. // clear the IP adress array maintained in theactreg handler first
  367. pActReg->m_strArrayStaticMappingIPAddress.RemoveAll();
  368. pActReg->m_lArrayIPAddress.RemoveAll();
  369. if ( (m_strType.CompareNoCase(g_strStaticTypeUnique) == 0) || (m_strType.CompareNoCase(g_strStaticTypeGroup) == 0) )
  370. {
  371. pActReg->m_strArrayStaticMappingIPAddress.Add(m_strIPAdd);
  372. pActReg->m_lArrayIPAddress.Add(lIPAdd);
  373. }
  374. // copy from the array
  375. else
  376. {
  377. for (int i = 0; i < m_strArrayIPAdd.GetSize(); i++)
  378. {
  379. pActReg->m_strArrayStaticMappingIPAddress.Add(m_strArrayIPAdd.GetAt(i));
  380. pActReg->m_lArrayIPAddress.Add(m_dwArrayIPAdd.GetAt(i));
  381. }
  382. }
  383. // do the thread context switch so we can update the UI as well
  384. bRet = CPropertyPageBase::OnApply();
  385. if (bRet == FALSE)
  386. {
  387. // Something bad happened... grab the error code
  388. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  389. ::WinsMessageBox(GetHolder()->GetError());
  390. }
  391. else
  392. {
  393. // set back the defaults for the controls
  394. m_comboType.SelectString(-1, g_strStaticTypeUnique);
  395. m_editCustomIPAdd.ShowWindow(TRUE);
  396. m_editCustomIPAdd.SetWindowText(_T(""));
  397. m_editName.SetWindowText(_T(""));
  398. m_editScopeName.SetWindowText(_T(""));
  399. // clear and hide the list box and the Add and Remove buttons
  400. m_buttonAdd.ShowWindow(FALSE);
  401. m_buttonRemove.ShowWindow(FALSE);
  402. int nCount = m_listIPAdd.GetCount();
  403. for (int i= 0; i < nCount; i++)
  404. {
  405. m_listIPAdd.DeleteString(i);
  406. }
  407. m_listIPAdd.ShowWindow(FALSE);
  408. m_listIPAdd.ResetContent();
  409. m_strArrayIPAdd.RemoveAll();
  410. m_dwArrayIPAdd.RemoveAll();
  411. SetRemoveButtonState();
  412. SetDirty(FALSE);
  413. }
  414. }
  415. // if static mapping properties are modified, we need to do this
  416. else
  417. {
  418. // validate the data and copy to ActReg node
  419. UpdateData();
  420. SPITFSNode spNode;
  421. spNode = GetHolder()->GetNode();
  422. CActiveRegistrationsHandler *pActReg;
  423. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  424. // clear the array of IP addresses maintained in the act reg handler
  425. pActReg->m_strArrayStaticMappingIPAddress.RemoveAll();
  426. pActReg->m_lArrayIPAddress.RemoveAll();
  427. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  428. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  429. if ( (m_strType.CompareNoCase(g_strStaticTypeUnique) == 0)|| (m_strType.CompareNoCase(g_strStaticTypeGroup) == 0))
  430. {
  431. if (nAdd != 4)
  432. {
  433. AfxMessageBox(IDS_ERR_INVALID_IP, MB_OK);
  434. // set focus to the IP address control
  435. m_editCustomIPAdd.SetFocus();
  436. return hrFalse;
  437. }
  438. }
  439. LONG lIPAdd = (LONG) MAKEIPADDRESS(dwIp1, dwIp2, dwIp3, dwIp4);
  440. pActReg->m_strStaticMappingName = m_strName;
  441. pActReg->m_strStaticMappingType = m_strType;
  442. AssignMappingType();
  443. pActReg->m_nStaticMappingType = m_fType;
  444. if ( (m_strType.CompareNoCase(g_strStaticTypeUnique) == 0)|| (m_strType.CompareNoCase(g_strStaticTypeGroup) == 0))
  445. {
  446. pActReg->m_strArrayStaticMappingIPAddress.Add(m_strIPAdd);
  447. pActReg->m_lArrayIPAddress.Add(lIPAdd);
  448. }
  449. // copy from the array
  450. else
  451. {
  452. for (int i = 0; i < m_strArrayIPAdd.GetSize(); i++)
  453. {
  454. pActReg->m_strArrayStaticMappingIPAddress.Add(m_strArrayIPAdd.GetAt(i));
  455. pActReg->m_lArrayIPAddress.Add(m_dwArrayIPAdd.GetAt(i));
  456. }
  457. }
  458. // do the thread context switch so we can update the UI as well
  459. bRet = CPropertyPageBase::OnApply();
  460. if (bRet == FALSE)
  461. {
  462. // Something bad happened... grab the error code
  463. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  464. ::WinsMessageBox(GetHolder()->GetError());
  465. }
  466. }
  467. return bRet;
  468. }
  469. void
  470. CStaticMappingProp::AssignMappingType()
  471. {
  472. if (m_strType.CompareNoCase(g_strStaticTypeInternetGroup) == 0)
  473. m_fType = WINSINTF_E_SPEC_GROUP;
  474. else
  475. if (m_strType.CompareNoCase(g_strStaticTypeUnique) == 0)
  476. m_fType = WINSINTF_E_UNIQUE;
  477. else
  478. if (m_strType.CompareNoCase(g_strStaticTypeMultihomed) == 0)
  479. m_fType = WINSINTF_E_MULTIHOMED;
  480. else
  481. if (m_strType.CompareNoCase(g_strStaticTypeGroup) == 0)
  482. m_fType = WINSINTF_E_NORM_GROUP;
  483. else
  484. if (m_strType.CompareNoCase(g_strStaticTypeDomainName)== 0)
  485. m_fType = WINSINTF_E_SPEC_GROUP;
  486. }
  487. void
  488. CStaticMappingProp::OnChangeIpAddress()
  489. {
  490. SetDirty(TRUE);
  491. CString strText;
  492. m_editCustomIPAdd.GetWindowText(strText);
  493. if (strText.IsEmpty())
  494. {
  495. // disable the Add and Remove buttons
  496. CWnd * pCurFocus = GetFocus();
  497. if (m_buttonAdd.GetSafeHwnd() == pCurFocus->GetSafeHwnd() ||
  498. m_buttonRemove.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  499. {
  500. m_editCustomIPAdd.SetFocus();
  501. }
  502. m_buttonAdd.EnableWindow(FALSE);
  503. m_buttonRemove.EnableWindow(FALSE);
  504. }
  505. UpdateData();
  506. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  507. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  508. if (nAdd != 4)
  509. {
  510. CWnd * pCurFocus = GetFocus();
  511. if (m_buttonAdd.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  512. {
  513. m_editCustomIPAdd.SetFocus();
  514. }
  515. m_buttonAdd.EnableWindow(FALSE);
  516. }
  517. else
  518. {
  519. m_buttonAdd.EnableWindow(TRUE);
  520. }
  521. SetRemoveButtonState();
  522. }
  523. BOOL
  524. CStaticMappingProp::OnInitDialog()
  525. {
  526. // Initialize the IP address controls
  527. m_ipControl.Create(m_hWnd, IDC_IPADD);
  528. m_ipControl.SetFieldRange(0, 0, 255);
  529. CPropertyPageBase::OnInitDialog();
  530. // fill in the type strings
  531. m_comboType.AddString(g_strStaticTypeUnique);
  532. m_comboType.AddString(g_strStaticTypeGroup);
  533. m_comboType.AddString(g_strStaticTypeDomainName);
  534. m_comboType.AddString(g_strStaticTypeInternetGroup);
  535. m_comboType.AddString(g_strStaticTypeMultihomed);
  536. if (((CStaticMappingProperties*)GetHolder())->m_bWizard)
  537. {
  538. // set control states for the wizard part
  539. HWND hWndSheet = ((CStaticMappingProperties*)GetHolder())->GetSheetWindow();
  540. CString strTitle;
  541. strTitle.LoadString(IDS_CREATE_STATIC_MAPPING);
  542. ::SetWindowText(hWndSheet, strTitle);
  543. SetDefaultControlStates();
  544. m_editScopeName.SetReadOnly(FALSE);
  545. m_comboType.SelectString(-1, g_strStaticTypeUnique);
  546. }
  547. else
  548. {
  549. m_editScopeName.SetReadOnly(TRUE);
  550. m_buttonAdd.ShowWindow(FALSE);
  551. m_buttonRemove.ShowWindow(FALSE);
  552. m_listIPAdd.ShowWindow(FALSE);
  553. SetRemoveButtonState();
  554. // owner only visible in properties mode
  555. WinsRecord ws = ((CStaticMappingProperties*)GetHolder())->m_wsRecord;
  556. if (ws.dwOwner != INVALID_OWNER_ID)
  557. {
  558. CString strOwner;
  559. MakeIPAddress(ws.dwOwner, strOwner);
  560. GetDlgItem(IDC_EDIT_OWNER)->SetWindowText(strOwner);
  561. }
  562. FillControls();
  563. }
  564. // load the correct icon
  565. for (int i = 0; i < ICON_IDX_MAX; i++)
  566. {
  567. if (g_uIconMap[i][1] == m_uImage)
  568. {
  569. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  570. if (hIcon)
  571. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  572. break;
  573. }
  574. }
  575. SetDirty(FALSE);
  576. return TRUE;
  577. }
  578. BOOL
  579. CStaticMappingProp::FillControls()
  580. {
  581. // get the actreg node
  582. BOOL fHasScope = FALSE;
  583. CActiveRegistrationsHandler * pActReg;
  584. SPITFSNode spNode;
  585. spNode = GetHolder()->GetNode();
  586. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  587. WinsRecord ws = ((CStaticMappingProperties*)GetHolder())->m_wsRecord;
  588. // name and the IP address ypu anyway fill. the reamining depending on
  589. // whether it's a static or dynamic record
  590. if (ws.dwNameLen > 16)
  591. {
  592. fHasScope = TRUE;
  593. }
  594. // build the name string
  595. CString strName, strScopeName;
  596. pActReg->CleanNetBIOSName(ws.szRecordName,
  597. strName,
  598. TRUE, // Expand
  599. TRUE, // Truncate
  600. pActReg->IsLanManCompatible(),
  601. TRUE, // name is OEM
  602. FALSE, // No double backslash
  603. ws.dwNameLen);
  604. // check if it has a scope name attached to it., looking for a period
  605. if (fHasScope)
  606. {
  607. LPSTR pScope = &ws.szRecordName[17];
  608. // INTL$ should this be OEMCP, not ACP
  609. MBCSToWide(pScope, strScopeName, WINS_NAME_CODE_PAGE);
  610. int nPos = strName.Find(strScopeName);
  611. // means that the scope name is attached
  612. if ( (nPos != -1) &&
  613. (!strScopeName.IsEmpty()) )
  614. {
  615. // all we want here is the name
  616. strName = strName.Left(nPos - 1);
  617. }
  618. }
  619. m_strName = strName;
  620. m_strScopeName = strScopeName;
  621. // IP address
  622. CString strIP;
  623. if (ws.dwState & WINSDB_REC_UNIQUE || ws.dwState & WINSDB_REC_NORM_GROUP)
  624. {
  625. for (DWORD i = 0; i < ws.dwNoOfAddrs; i++)
  626. {
  627. MakeIPAddress(ws.dwIpAdd[i], strIP);
  628. m_strArrayIPAdd.Add(strIP);
  629. m_dwArrayIPAdd.Add(ws.dwIpAdd[i]);
  630. }
  631. }
  632. // in this case the first IP address is that of the owner,
  633. else
  634. {
  635. DWORD dwPos = 1;
  636. for (DWORD i = 0; i < ws.dwNoOfAddrs/2; ++i)
  637. {
  638. ::MakeIPAddress(ws.dwIpAdd[dwPos], strIP);
  639. m_strArrayIPAdd.Add(strIP);
  640. m_dwArrayIPAdd.Add(ws.dwIpAdd[dwPos]);
  641. ++dwPos;
  642. ++dwPos;
  643. }
  644. }
  645. // text in the controls now
  646. m_editName.SetWindowText(m_strName);
  647. m_editScopeName.SetWindowText(m_strScopeName);
  648. //check if the record is static
  649. if (ws.dwState & WINSDB_REC_STATIC)
  650. {
  651. // active status
  652. CString strStaticType;
  653. pActReg->GetStaticTypeString(ws.dwState, strStaticType);
  654. if (strStaticType.CompareNoCase(g_strStaticTypeDomainName) == 0)
  655. {
  656. //could be either Internet Group or Domain Name
  657. // check for the 15th character , if 1C, then Domain Name
  658. // else Internet Group Name
  659. if ((BYTE)ws.szRecordName[15] == 0x1C)
  660. strStaticType = g_strStaticTypeDomainName;
  661. else
  662. strStaticType = g_strStaticTypeInternetGroup;
  663. }
  664. FillStaticRecData(strStaticType);
  665. //m_fStaticPropChanged = TRUE;
  666. m_strType = strStaticType;
  667. }
  668. else
  669. {
  670. }
  671. return TRUE;
  672. }
  673. void
  674. CStaticMappingProp::FillStaticRecData(CString& strType)
  675. {
  676. // hide the combobox too, show the IPAdd control
  677. m_editCustomIPAdd.ShowWindow(TRUE);
  678. // display the combobox
  679. m_comboType.ShowWindow(TRUE);
  680. // disable thew type combobox
  681. m_comboType.EnableWindow(FALSE);
  682. // get the type of record
  683. m_comboType.SelectString(-1, strType);
  684. // make the records read only.
  685. m_editName.SetReadOnly();
  686. // depending on the type, hide/show the list control
  687. // and the add remove buttons.
  688. if ( (strType.CompareNoCase(g_strStaticTypeUnique) == 0) || strType.CompareNoCase(g_strStaticTypeGroup) == 0)
  689. {
  690. m_listIPAdd.ShowWindow(FALSE);
  691. m_buttonAdd.ShowWindow(FALSE);
  692. m_buttonRemove.ShowWindow(FALSE);
  693. m_editCustomIPAdd.ShowWindow(TRUE);
  694. m_editCustomIPAdd.SetReadOnly(FALSE);
  695. // set it's text to that in the combo box
  696. CString strIP;
  697. strIP = m_strArrayIPAdd.GetAt(0);
  698. m_strOnInitIPAdd = strIP;
  699. m_ipControl.SetAddress(strIP);
  700. }
  701. else
  702. {
  703. m_listIPAdd.ShowWindow(TRUE);
  704. m_buttonAdd.ShowWindow(TRUE);
  705. m_buttonRemove.ShowWindow(TRUE);
  706. m_editCustomIPAdd.ShowWindow(TRUE);
  707. m_editCustomIPAdd.SetReadOnly(FALSE);
  708. // fill the contents with that from the combo box
  709. FillList();
  710. if (m_strArrayIPAdd.GetSize() > 0)
  711. m_strOnInitIPAdd = m_strArrayIPAdd.GetAt(0);
  712. }
  713. SetRemoveButtonState();
  714. }
  715. void
  716. CStaticMappingProp::FillList()
  717. {
  718. CString strIP;
  719. // clear the list box next
  720. for (int i = 0; i < m_listIPAdd.GetCount(); i++)
  721. m_listIPAdd.DeleteString(i);
  722. int nCount = (int) m_strArrayIPAdd.GetSize();
  723. for (i = 0; i < nCount; i++)
  724. {
  725. strIP = m_strArrayIPAdd.GetAt(i);
  726. m_listIPAdd.AddString(strIP);
  727. if (nCount == 1)
  728. m_ipControl.SetAddress(strIP);
  729. }
  730. m_ipControl.SetAddress(_T(""));
  731. m_editCustomIPAdd.SetWindowText(_T(""));
  732. SetRemoveButtonState();
  733. }
  734. void
  735. CStaticMappingProp::FillDynamicRecData(CString& strType, CString& strActive, CString& strExpiration, CString& strVersion)
  736. {
  737. }
  738. void
  739. CStaticMappingProp::SetDefaultControlStates()
  740. {
  741. m_comboType.EnableWindow(TRUE);
  742. m_comboType.ShowWindow(TRUE);
  743. m_editCustomIPAdd.ShowWindow(TRUE);
  744. SetRemoveButtonState();
  745. }
  746. void
  747. CStaticMappingProp::OnButtonAdd()
  748. {
  749. UpdateData();
  750. // add the IPAdd in the IPControl to the list box
  751. // if valid
  752. // check if broadcast address is being added
  753. if (m_strIPAdd.CompareNoCase(_T("255.255.255.255")) == 0)
  754. {
  755. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  756. m_editCustomIPAdd.SetFocus();
  757. return;
  758. }
  759. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  760. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  761. // check if the address is alreay in the list
  762. for (int i = 0; i < m_strArrayIPAdd.GetSize() ; i++)
  763. {
  764. if (m_strArrayIPAdd[i].CompareNoCase(m_strIPAdd) == 0)
  765. {
  766. AfxMessageBox(IDS_ERR_IP_EXISTS, MB_OK);
  767. m_editCustomIPAdd.SetFocus();
  768. m_editCustomIPAdd.SetSel(0,-1);
  769. return;
  770. }
  771. }
  772. if (m_dwArrayIPAdd.GetSize() == WINSINTF_MAX_MEM)
  773. {
  774. // cannot add any more addresses
  775. AfxMessageBox(IDS_ERR_TOOMANY_IP);
  776. return;
  777. }
  778. LONG lIPAdd = (LONG) MAKEIPADDRESS(dwIp1, dwIp2, dwIp3, dwIp4);
  779. // add to the list
  780. m_listIPAdd.AddString(m_strIPAdd);
  781. m_strArrayIPAdd.Add(m_strIPAdd);
  782. m_dwArrayIPAdd.Add(lIPAdd);
  783. //m_fStaticPropChanged = TRUE;
  784. m_editCustomIPAdd.SetWindowText(_T(""));
  785. SetDirty(TRUE);
  786. }
  787. void
  788. CStaticMappingProp::OnButtonRemove()
  789. {
  790. SPITFSNode spNode;
  791. spNode = GetHolder()->GetNode();
  792. CActiveRegistrationsHandler* pActReg;
  793. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  794. // remove from the list
  795. int nSel = m_listIPAdd.GetCurSel();
  796. CString strSel;
  797. if (nSel != -1)
  798. {
  799. m_listIPAdd.GetText(nSel, strSel);
  800. m_listIPAdd.DeleteString(nSel);
  801. }
  802. // set the IP address in the IP Control
  803. m_ipControl.SetAddress(strSel);
  804. UpdateData();
  805. // delete from the CStringArray
  806. for (int i = 0; i < m_strArrayIPAdd.GetSize(); i++)
  807. {
  808. if (strSel == m_strArrayIPAdd.GetAt(i))
  809. {
  810. m_strArrayIPAdd.RemoveAt(i);
  811. m_dwArrayIPAdd.RemoveAt(i);
  812. break;
  813. }
  814. }
  815. // set the focus to the IP address control
  816. m_editCustomIPAdd.SetFocus();
  817. //m_fStaticPropChanged = TRUE;
  818. SetDirty(TRUE);
  819. }
  820. void
  821. CStaticMappingProp::OnSelchangeComboType()
  822. {
  823. SetDirty(TRUE);
  824. if (m_comboType.GetCurSel() == 2 || m_comboType.GetCurSel() == 3 || m_comboType.GetCurSel() == 4)
  825. {
  826. // show the list control and the add and the remove buttons
  827. m_buttonAdd.ShowWindow(TRUE);
  828. m_buttonRemove.ShowWindow(TRUE);
  829. m_listIPAdd.ShowWindow(TRUE);
  830. }
  831. // hide them
  832. else
  833. {
  834. m_buttonAdd.ShowWindow(FALSE);
  835. m_buttonRemove.ShowWindow(FALSE);
  836. m_listIPAdd.ShowWindow(FALSE);
  837. }
  838. SetRemoveButtonState();
  839. }
  840. void CStaticMappingProp::OnChangeEditCompname()
  841. {
  842. SetDirty(TRUE);
  843. }
  844. void
  845. CStaticMappingProp::SetRemoveButtonState()
  846. {
  847. UpdateData();
  848. if (m_listIPAdd.GetCurSel() == -1)
  849. {
  850. CWnd * pCurFocus = GetFocus();
  851. if (m_buttonRemove.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  852. {
  853. m_editCustomIPAdd.SetFocus();
  854. }
  855. m_buttonRemove.EnableWindow(FALSE);
  856. }
  857. else
  858. {
  859. m_buttonRemove.EnableWindow(TRUE);
  860. }
  861. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  862. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  863. if (nAdd != 4)
  864. {
  865. CWnd * pCurFocus = GetFocus();
  866. if (m_buttonAdd.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  867. {
  868. m_editCustomIPAdd.SetFocus();
  869. }
  870. m_buttonAdd.EnableWindow(FALSE);
  871. }
  872. else
  873. {
  874. m_buttonAdd.EnableWindow(TRUE);
  875. }
  876. }
  877. void
  878. CStaticMappingProp::OnSelChangeListIpAdd()
  879. {
  880. SetRemoveButtonState();
  881. }
  882. BOOL
  883. CStaticMappingProp::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  884. {
  885. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  886. HRESULT hr = hrOK;
  887. SPITFSComponent spComponent;
  888. SPITFSNode spNode;
  889. spNode = GetHolder()->GetNode();
  890. CActiveRegistrationsHandler * pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  891. if (((CStaticMappingProperties*)GetHolder())->m_bWizard)
  892. {
  893. hr = pActReg->AddMapping(spNode);
  894. if (FAILED(hr))
  895. {
  896. GetHolder()->SetError(WIN32_FROM_HRESULT(hr));
  897. }
  898. else
  899. {
  900. *ChangeMask = RESULT_PANE_CHANGE_ITEM_DATA;
  901. }
  902. }
  903. else
  904. {
  905. ((CStaticMappingProperties *) GetHolder())->GetComponent(&spComponent);
  906. DWORD dwErr = pActReg->EditMapping(spNode, spComponent, pActReg->m_nSelectedIndex);
  907. if (dwErr != ERROR_SUCCESS)
  908. {
  909. GetHolder()->SetError(dwErr);
  910. }
  911. else
  912. {
  913. *ChangeMask = RESULT_PANE_CHANGE_ITEM_DATA;
  914. }
  915. }
  916. return FALSE;
  917. }
  918. CStaticMappingProperties::CStaticMappingProperties
  919. (
  920. ITFSNode * pNode,
  921. IComponent * pComponent,
  922. LPCTSTR pszSheetName,
  923. WinsRecord * pwRecord,
  924. BOOL bWizard
  925. ) : CPropertyPageHolderBase(pNode, pComponent, pszSheetName), m_bWizard(bWizard)
  926. {
  927. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  928. InitPage(bWizard);
  929. AddPageToList((CPropertyPageBase*) m_ppageGeneral);
  930. Init(pwRecord);
  931. }
  932. CStaticMappingProperties::CStaticMappingProperties
  933. (
  934. ITFSNode * pNode,
  935. IComponentData * pComponentData,
  936. LPCTSTR pszSheetName,
  937. WinsRecord * pwRecord,
  938. BOOL bWizard
  939. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName), m_bWizard(bWizard)
  940. {
  941. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  942. InitPage(bWizard);
  943. AddPageToList((CPropertyPageBase*) m_ppageGeneral);
  944. Init(pwRecord);
  945. }
  946. CStaticMappingProperties::~CStaticMappingProperties()
  947. {
  948. RemovePageFromList((CPropertyPageBase*) m_ppageGeneral, FALSE);
  949. delete m_ppageGeneral;
  950. m_ppageGeneral = NULL;
  951. }
  952. void
  953. CStaticMappingProperties::InitPage(BOOL fWizard)
  954. {
  955. if (fWizard)
  956. {
  957. m_ppageGeneral = new CStaticMappingProp(IDD_STATIC_MAPPING_WIZARD);
  958. }
  959. else
  960. {
  961. m_ppageGeneral = new CStaticMappingProp(IDD_STATIC_MAPPING_PROPERTIES);
  962. }
  963. }
  964. void
  965. CStaticMappingProperties::Init(WinsRecord * pwRecord)
  966. {
  967. if (pwRecord)
  968. {
  969. strcpy(m_wsRecord.szRecordName , pwRecord->szRecordName);
  970. m_wsRecord.dwExpiration = pwRecord->dwExpiration;
  971. m_wsRecord.dwExpiration = pwRecord->dwExpiration;
  972. m_wsRecord.dwNoOfAddrs = pwRecord->dwNoOfAddrs;
  973. for (DWORD i = 0; i < pwRecord->dwNoOfAddrs; i++)
  974. {
  975. m_wsRecord.dwIpAdd[i] = pwRecord->dwIpAdd[i];
  976. }
  977. m_wsRecord.liVersion = pwRecord->liVersion;
  978. m_wsRecord.dwNameLen = pwRecord->dwNameLen;
  979. m_wsRecord.dwOwner = pwRecord->dwOwner;
  980. m_wsRecord.dwState = pwRecord->dwState;
  981. m_wsRecord.dwType = pwRecord->dwType;
  982. }
  983. }
  984. HRESULT
  985. CStaticMappingProperties::SetComponent(ITFSComponent * pComponent)
  986. {
  987. m_spTFSComponent.Set(pComponent);
  988. return hrOK;
  989. }
  990. HRESULT
  991. CStaticMappingProperties::GetComponent(ITFSComponent ** ppComponent)
  992. {
  993. if (ppComponent)
  994. {
  995. *ppComponent = m_spTFSComponent;
  996. m_spTFSComponent->AddRef();
  997. }
  998. return hrOK;
  999. }