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.

1279 lines
30 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(2*(MAX_PATH+1));
  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. ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT_COMPNAME), EM_LIMITTEXT, MAX_PATH, 0);
  537. if (((CStaticMappingProperties*)GetHolder())->m_bWizard)
  538. {
  539. // set control states for the wizard part
  540. HWND hWndSheet = ((CStaticMappingProperties*)GetHolder())->GetSheetWindow();
  541. CString strTitle;
  542. strTitle.LoadString(IDS_CREATE_STATIC_MAPPING);
  543. ::SetWindowText(hWndSheet, strTitle);
  544. SetDefaultControlStates();
  545. m_editScopeName.SetReadOnly(FALSE);
  546. m_comboType.SelectString(-1, g_strStaticTypeUnique);
  547. }
  548. else
  549. {
  550. m_editScopeName.SetReadOnly(TRUE);
  551. m_buttonAdd.ShowWindow(FALSE);
  552. m_buttonRemove.ShowWindow(FALSE);
  553. m_listIPAdd.ShowWindow(FALSE);
  554. SetRemoveButtonState();
  555. // owner only visible in properties mode
  556. WinsRecord ws = ((CStaticMappingProperties*)GetHolder())->m_wsRecord;
  557. if (ws.dwOwner != INVALID_OWNER_ID)
  558. {
  559. CString strOwner;
  560. MakeIPAddress(ws.dwOwner, strOwner);
  561. GetDlgItem(IDC_EDIT_OWNER)->SetWindowText(strOwner);
  562. }
  563. FillControls();
  564. }
  565. // load the correct icon
  566. for (int i = 0; i < ICON_IDX_MAX; i++)
  567. {
  568. if (g_uIconMap[i][1] == m_uImage)
  569. {
  570. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  571. if (hIcon)
  572. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  573. break;
  574. }
  575. }
  576. SetDirty(FALSE);
  577. return TRUE;
  578. }
  579. BOOL
  580. CStaticMappingProp::FillControls()
  581. {
  582. // get the actreg node
  583. BOOL fHasScope = FALSE;
  584. CActiveRegistrationsHandler * pActReg;
  585. SPITFSNode spNode;
  586. spNode = GetHolder()->GetNode();
  587. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  588. WinsRecord ws = ((CStaticMappingProperties*)GetHolder())->m_wsRecord;
  589. // name and the IP address ypu anyway fill. the reamining depending on
  590. // whether it's a static or dynamic record
  591. if (ws.dwNameLen > 16)
  592. {
  593. fHasScope = TRUE;
  594. }
  595. // build the name string
  596. CString strName, strScopeName;
  597. pActReg->CleanNetBIOSName(ws.szRecordName,
  598. strName,
  599. TRUE, // Expand
  600. TRUE, // Truncate
  601. pActReg->IsLanManCompatible(),
  602. TRUE, // name is OEM
  603. FALSE, // No double backslash
  604. ws.dwNameLen);
  605. // check if it has a scope name attached to it., looking for a period
  606. if (fHasScope)
  607. {
  608. LPSTR pScope = &ws.szRecordName[17];
  609. // INTL$ should this be OEMCP, not ACP
  610. MBCSToWide(pScope, strScopeName, WINS_NAME_CODE_PAGE);
  611. int nPos = strName.Find(strScopeName);
  612. // means that the scope name is attached
  613. if ( (nPos != -1) &&
  614. (!strScopeName.IsEmpty()) )
  615. {
  616. // all we want here is the name
  617. strName = strName.Left(nPos - 1);
  618. }
  619. }
  620. m_strName = strName;
  621. m_strScopeName = strScopeName;
  622. // IP address
  623. CString strIP;
  624. if (ws.dwState & WINSDB_REC_UNIQUE || ws.dwState & WINSDB_REC_NORM_GROUP)
  625. {
  626. for (DWORD i = 0; i < ws.dwNoOfAddrs; i++)
  627. {
  628. MakeIPAddress(ws.dwIpAdd[i], strIP);
  629. m_strArrayIPAdd.Add(strIP);
  630. m_dwArrayIPAdd.Add(ws.dwIpAdd[i]);
  631. }
  632. }
  633. // in this case the first IP address is that of the owner,
  634. else
  635. {
  636. DWORD dwPos = 1;
  637. for (DWORD i = 0; i < ws.dwNoOfAddrs/2; ++i)
  638. {
  639. ::MakeIPAddress(ws.dwIpAdd[dwPos], strIP);
  640. m_strArrayIPAdd.Add(strIP);
  641. m_dwArrayIPAdd.Add(ws.dwIpAdd[dwPos]);
  642. ++dwPos;
  643. ++dwPos;
  644. }
  645. }
  646. // text in the controls now
  647. m_editName.SetWindowText(m_strName);
  648. m_editScopeName.SetWindowText(m_strScopeName);
  649. //check if the record is static
  650. if (ws.dwState & WINSDB_REC_STATIC)
  651. {
  652. // active status
  653. CString strStaticType;
  654. pActReg->GetStaticTypeString(ws.dwState, strStaticType);
  655. if (strStaticType.CompareNoCase(g_strStaticTypeDomainName) == 0)
  656. {
  657. //could be either Internet Group or Domain Name
  658. // check for the 15th character , if 1C, then Domain Name
  659. // else Internet Group Name
  660. if ((BYTE)ws.szRecordName[15] == 0x1C)
  661. strStaticType = g_strStaticTypeDomainName;
  662. else
  663. strStaticType = g_strStaticTypeInternetGroup;
  664. }
  665. FillStaticRecData(strStaticType);
  666. //m_fStaticPropChanged = TRUE;
  667. m_strType = strStaticType;
  668. }
  669. else
  670. {
  671. }
  672. return TRUE;
  673. }
  674. void
  675. CStaticMappingProp::FillStaticRecData(CString& strType)
  676. {
  677. // hide the combobox too, show the IPAdd control
  678. m_editCustomIPAdd.ShowWindow(TRUE);
  679. // display the combobox
  680. m_comboType.ShowWindow(TRUE);
  681. // disable thew type combobox
  682. m_comboType.EnableWindow(FALSE);
  683. // get the type of record
  684. m_comboType.SelectString(-1, strType);
  685. // make the records read only.
  686. m_editName.SetReadOnly();
  687. // depending on the type, hide/show the list control
  688. // and the add remove buttons.
  689. if ( (strType.CompareNoCase(g_strStaticTypeUnique) == 0) || strType.CompareNoCase(g_strStaticTypeGroup) == 0)
  690. {
  691. m_listIPAdd.ShowWindow(FALSE);
  692. m_buttonAdd.ShowWindow(FALSE);
  693. m_buttonRemove.ShowWindow(FALSE);
  694. m_editCustomIPAdd.ShowWindow(TRUE);
  695. m_editCustomIPAdd.SetReadOnly(FALSE);
  696. // set it's text to that in the combo box
  697. CString strIP;
  698. strIP = m_strArrayIPAdd.GetAt(0);
  699. m_strOnInitIPAdd = strIP;
  700. m_ipControl.SetAddress(strIP);
  701. }
  702. else
  703. {
  704. m_listIPAdd.ShowWindow(TRUE);
  705. m_buttonAdd.ShowWindow(TRUE);
  706. m_buttonRemove.ShowWindow(TRUE);
  707. m_editCustomIPAdd.ShowWindow(TRUE);
  708. m_editCustomIPAdd.SetReadOnly(FALSE);
  709. // fill the contents with that from the combo box
  710. FillList();
  711. if (m_strArrayIPAdd.GetSize() > 0)
  712. m_strOnInitIPAdd = m_strArrayIPAdd.GetAt(0);
  713. }
  714. SetRemoveButtonState();
  715. }
  716. void
  717. CStaticMappingProp::FillList()
  718. {
  719. CString strIP;
  720. // clear the list box next
  721. for (int i = 0; i < m_listIPAdd.GetCount(); i++)
  722. m_listIPAdd.DeleteString(i);
  723. int nCount = (int) m_strArrayIPAdd.GetSize();
  724. for (i = 0; i < nCount; i++)
  725. {
  726. strIP = m_strArrayIPAdd.GetAt(i);
  727. m_listIPAdd.AddString(strIP);
  728. if (nCount == 1)
  729. m_ipControl.SetAddress(strIP);
  730. }
  731. m_ipControl.SetAddress(_T(""));
  732. m_editCustomIPAdd.SetWindowText(_T(""));
  733. SetRemoveButtonState();
  734. }
  735. void
  736. CStaticMappingProp::FillDynamicRecData(CString& strType, CString& strActive, CString& strExpiration, CString& strVersion)
  737. {
  738. }
  739. void
  740. CStaticMappingProp::SetDefaultControlStates()
  741. {
  742. m_comboType.EnableWindow(TRUE);
  743. m_comboType.ShowWindow(TRUE);
  744. m_editCustomIPAdd.ShowWindow(TRUE);
  745. SetRemoveButtonState();
  746. }
  747. void
  748. CStaticMappingProp::OnButtonAdd()
  749. {
  750. UpdateData();
  751. // add the IPAdd in the IPControl to the list box
  752. // if valid
  753. // check if broadcast address is being added
  754. if (m_strIPAdd.CompareNoCase(_T("255.255.255.255")) == 0)
  755. {
  756. AfxMessageBox(IDS_INVALID_IPADDRESS, MB_OK);
  757. m_editCustomIPAdd.SetFocus();
  758. return;
  759. }
  760. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  761. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  762. // check if the address is alreay in the list
  763. for (int i = 0; i < m_strArrayIPAdd.GetSize() ; i++)
  764. {
  765. if (m_strArrayIPAdd[i].CompareNoCase(m_strIPAdd) == 0)
  766. {
  767. AfxMessageBox(IDS_ERR_IP_EXISTS, MB_OK);
  768. m_editCustomIPAdd.SetFocus();
  769. m_editCustomIPAdd.SetSel(0,-1);
  770. return;
  771. }
  772. }
  773. if (m_dwArrayIPAdd.GetSize() == WINSINTF_MAX_MEM)
  774. {
  775. // cannot add any more addresses
  776. AfxMessageBox(IDS_ERR_TOOMANY_IP);
  777. return;
  778. }
  779. LONG lIPAdd = (LONG) MAKEIPADDRESS(dwIp1, dwIp2, dwIp3, dwIp4);
  780. // add to the list
  781. m_listIPAdd.AddString(m_strIPAdd);
  782. m_strArrayIPAdd.Add(m_strIPAdd);
  783. m_dwArrayIPAdd.Add(lIPAdd);
  784. //m_fStaticPropChanged = TRUE;
  785. m_editCustomIPAdd.SetWindowText(_T(""));
  786. SetDirty(TRUE);
  787. }
  788. void
  789. CStaticMappingProp::OnButtonRemove()
  790. {
  791. SPITFSNode spNode;
  792. spNode = GetHolder()->GetNode();
  793. CActiveRegistrationsHandler* pActReg;
  794. pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  795. // remove from the list
  796. int nSel = m_listIPAdd.GetCurSel();
  797. CString strSel;
  798. if (nSel != -1)
  799. {
  800. m_listIPAdd.GetText(nSel, strSel);
  801. m_listIPAdd.DeleteString(nSel);
  802. }
  803. // set the IP address in the IP Control
  804. m_ipControl.SetAddress(strSel);
  805. UpdateData();
  806. // delete from the CStringArray
  807. for (int i = 0; i < m_strArrayIPAdd.GetSize(); i++)
  808. {
  809. if (strSel == m_strArrayIPAdd.GetAt(i))
  810. {
  811. m_strArrayIPAdd.RemoveAt(i);
  812. m_dwArrayIPAdd.RemoveAt(i);
  813. break;
  814. }
  815. }
  816. // set the focus to the IP address control
  817. m_editCustomIPAdd.SetFocus();
  818. //m_fStaticPropChanged = TRUE;
  819. SetDirty(TRUE);
  820. }
  821. void
  822. CStaticMappingProp::OnSelchangeComboType()
  823. {
  824. SetDirty(TRUE);
  825. if (m_comboType.GetCurSel() == 2 || m_comboType.GetCurSel() == 3 || m_comboType.GetCurSel() == 4)
  826. {
  827. // show the list control and the add and the remove buttons
  828. m_buttonAdd.ShowWindow(TRUE);
  829. m_buttonRemove.ShowWindow(TRUE);
  830. m_listIPAdd.ShowWindow(TRUE);
  831. }
  832. // hide them
  833. else
  834. {
  835. m_buttonAdd.ShowWindow(FALSE);
  836. m_buttonRemove.ShowWindow(FALSE);
  837. m_listIPAdd.ShowWindow(FALSE);
  838. }
  839. SetRemoveButtonState();
  840. }
  841. void CStaticMappingProp::OnChangeEditCompname()
  842. {
  843. SetDirty(TRUE);
  844. }
  845. void
  846. CStaticMappingProp::SetRemoveButtonState()
  847. {
  848. UpdateData();
  849. if (m_listIPAdd.GetCurSel() == -1)
  850. {
  851. CWnd * pCurFocus = GetFocus();
  852. if (m_buttonRemove.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  853. {
  854. m_editCustomIPAdd.SetFocus();
  855. }
  856. m_buttonRemove.EnableWindow(FALSE);
  857. }
  858. else
  859. {
  860. m_buttonRemove.EnableWindow(TRUE);
  861. }
  862. DWORD dwIp1, dwIp2, dwIp3, dwIp4;
  863. int nAdd = m_ipControl.GetAddress(&dwIp1, &dwIp2, &dwIp3, &dwIp4);
  864. if (nAdd != 4)
  865. {
  866. CWnd * pCurFocus = GetFocus();
  867. if (m_buttonAdd.GetSafeHwnd() == pCurFocus->GetSafeHwnd())
  868. {
  869. m_editCustomIPAdd.SetFocus();
  870. }
  871. m_buttonAdd.EnableWindow(FALSE);
  872. }
  873. else
  874. {
  875. m_buttonAdd.EnableWindow(TRUE);
  876. }
  877. }
  878. void
  879. CStaticMappingProp::OnSelChangeListIpAdd()
  880. {
  881. SetRemoveButtonState();
  882. }
  883. BOOL
  884. CStaticMappingProp::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  885. {
  886. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  887. HRESULT hr = hrOK;
  888. SPITFSComponent spComponent;
  889. SPITFSNode spNode;
  890. spNode = GetHolder()->GetNode();
  891. CActiveRegistrationsHandler * pActReg = GETHANDLER(CActiveRegistrationsHandler, spNode);
  892. if (((CStaticMappingProperties*)GetHolder())->m_bWizard)
  893. {
  894. hr = pActReg->AddMapping(spNode);
  895. if (FAILED(hr))
  896. {
  897. GetHolder()->SetError(WIN32_FROM_HRESULT(hr));
  898. }
  899. else
  900. {
  901. *ChangeMask = RESULT_PANE_CHANGE_ITEM_DATA;
  902. }
  903. }
  904. else
  905. {
  906. ((CStaticMappingProperties *) GetHolder())->GetComponent(&spComponent);
  907. DWORD dwErr = pActReg->EditMapping(spNode, spComponent, pActReg->m_nSelectedIndex);
  908. if (dwErr != ERROR_SUCCESS)
  909. {
  910. GetHolder()->SetError(dwErr);
  911. }
  912. else
  913. {
  914. *ChangeMask = RESULT_PANE_CHANGE_ITEM_DATA;
  915. }
  916. }
  917. return FALSE;
  918. }
  919. CStaticMappingProperties::CStaticMappingProperties
  920. (
  921. ITFSNode * pNode,
  922. IComponent * pComponent,
  923. LPCTSTR pszSheetName,
  924. WinsRecord * pwRecord,
  925. BOOL bWizard
  926. ) : CPropertyPageHolderBase(pNode, pComponent, pszSheetName), m_bWizard(bWizard)
  927. {
  928. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  929. m_bTheme = TRUE;
  930. InitPage(bWizard);
  931. AddPageToList((CPropertyPageBase*) m_ppageGeneral);
  932. Init(pwRecord);
  933. }
  934. CStaticMappingProperties::CStaticMappingProperties
  935. (
  936. ITFSNode * pNode,
  937. IComponentData * pComponentData,
  938. LPCTSTR pszSheetName,
  939. WinsRecord * pwRecord,
  940. BOOL bWizard
  941. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName), m_bWizard(bWizard)
  942. {
  943. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  944. m_bTheme = TRUE;
  945. InitPage(bWizard);
  946. AddPageToList((CPropertyPageBase*) m_ppageGeneral);
  947. Init(pwRecord);
  948. }
  949. CStaticMappingProperties::~CStaticMappingProperties()
  950. {
  951. RemovePageFromList((CPropertyPageBase*) m_ppageGeneral, FALSE);
  952. delete m_ppageGeneral;
  953. m_ppageGeneral = NULL;
  954. }
  955. void
  956. CStaticMappingProperties::InitPage(BOOL fWizard)
  957. {
  958. if (fWizard)
  959. {
  960. m_ppageGeneral = new CStaticMappingProp(IDD_STATIC_MAPPING_WIZARD);
  961. }
  962. else
  963. {
  964. m_ppageGeneral = new CStaticMappingProp(IDD_STATIC_MAPPING_PROPERTIES);
  965. }
  966. }
  967. void
  968. CStaticMappingProperties::Init(WinsRecord * pwRecord)
  969. {
  970. if (pwRecord)
  971. {
  972. strcpy(m_wsRecord.szRecordName , pwRecord->szRecordName);
  973. m_wsRecord.dwExpiration = pwRecord->dwExpiration;
  974. m_wsRecord.dwExpiration = pwRecord->dwExpiration;
  975. m_wsRecord.dwNoOfAddrs = pwRecord->dwNoOfAddrs;
  976. for (DWORD i = 0; i < pwRecord->dwNoOfAddrs; i++)
  977. {
  978. m_wsRecord.dwIpAdd[i] = pwRecord->dwIpAdd[i];
  979. }
  980. m_wsRecord.liVersion = pwRecord->liVersion;
  981. m_wsRecord.dwNameLen = pwRecord->dwNameLen;
  982. m_wsRecord.dwOwner = pwRecord->dwOwner;
  983. m_wsRecord.dwState = pwRecord->dwState;
  984. m_wsRecord.dwType = pwRecord->dwType;
  985. }
  986. }
  987. HRESULT
  988. CStaticMappingProperties::SetComponent(ITFSComponent * pComponent)
  989. {
  990. m_spTFSComponent.Set(pComponent);
  991. return hrOK;
  992. }
  993. HRESULT
  994. CStaticMappingProperties::GetComponent(ITFSComponent ** ppComponent)
  995. {
  996. if (ppComponent)
  997. {
  998. *ppComponent = m_spTFSComponent;
  999. m_spTFSComponent->AddRef();
  1000. }
  1001. return hrOK;
  1002. }