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.

208 lines
5.3 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1999 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. bootppp.cpp
  7. The bootp properties page
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "bootppp.h"
  12. #include "nodes.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. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // CBootpProperties holder
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. CBootpProperties::CBootpProperties
  25. (
  26. ITFSNode * pNode,
  27. IComponentData * pComponentData,
  28. ITFSComponentData * pTFSCompData,
  29. LPCTSTR pszSheetName
  30. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  31. {
  32. //ASSERT(pFolderNode == GetContainerNode());
  33. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  34. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  35. Assert(pTFSCompData != NULL);
  36. m_spTFSCompData.Set(pTFSCompData);
  37. }
  38. CBootpProperties::~CBootpProperties()
  39. {
  40. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CBootpPropGeneral property page
  44. IMPLEMENT_DYNCREATE(CBootpPropGeneral, CPropertyPageBase)
  45. CBootpPropGeneral::CBootpPropGeneral() : CPropertyPageBase(CBootpPropGeneral::IDD)
  46. {
  47. //{{AFX_DATA_INIT(CBootpPropGeneral)
  48. m_strFileName = _T("");
  49. m_strFileServer = _T("");
  50. m_strImageName = _T("");
  51. //}}AFX_DATA_INIT
  52. }
  53. CBootpPropGeneral::~CBootpPropGeneral()
  54. {
  55. }
  56. void CBootpPropGeneral::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CPropertyPageBase::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CBootpPropGeneral)
  60. DDX_Text(pDX, IDC_EDIT_BOOTP_FILE_NAME, m_strFileName);
  61. DDX_Text(pDX, IDC_EDIT_BOOTP_FILE_SERVER, m_strFileServer);
  62. DDX_Text(pDX, IDC_EDIT_BOOTP_IMAGE_NAME, m_strImageName);
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CBootpPropGeneral, CPropertyPageBase)
  66. //{{AFX_MSG_MAP(CBootpPropGeneral)
  67. ON_EN_CHANGE(IDC_EDIT_BOOTP_FILE_NAME, OnChangeEditBootpFileName)
  68. ON_EN_CHANGE(IDC_EDIT_BOOTP_FILE_SERVER, OnChangeEditBootpFileServer)
  69. ON_EN_CHANGE(IDC_EDIT_BOOTP_IMAGE_NAME, OnChangeEditBootpImageName)
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CBootpPropGeneral message handlers
  74. BOOL CBootpPropGeneral::OnApply()
  75. {
  76. UpdateData();
  77. BOOL bRet = CPropertyPageBase::OnApply();
  78. if (bRet == FALSE)
  79. {
  80. // Something bad happened... grab the error code
  81. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  82. ::DhcpMessageBox(GetHolder()->GetError());
  83. }
  84. return bRet;
  85. }
  86. BOOL CBootpPropGeneral::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  87. {
  88. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  89. SPITFSNode spBootpNode, spBootpFolder;
  90. spBootpNode = GetHolder()->GetNode();
  91. CDhcpBootpEntry * pBootpEntry = GETHANDLER(CDhcpBootpEntry, spBootpNode);
  92. spBootpNode->GetParent(&spBootpFolder);
  93. // update the node's data
  94. pBootpEntry->SetBootImage(m_strImageName);
  95. pBootpEntry->SetFileServer(m_strFileServer);
  96. pBootpEntry->SetFileName(m_strFileName);
  97. *ChangeMask = RESULT_PANE_CHANGE_ITEM_DATA;
  98. // now we need to calculate how big of a string to allocate
  99. // for the bootp table
  100. int nBootpTableLength = 0;
  101. SPITFSNodeEnum spNodeEnum;
  102. SPITFSNode spCurrentNode;
  103. ULONG nNumReturned = 0;
  104. spBootpFolder->GetEnum(&spNodeEnum);
  105. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  106. while (nNumReturned)
  107. {
  108. CDhcpBootpEntry * pCurBootpEntry = GETHANDLER(CDhcpBootpEntry, spCurrentNode);
  109. nBootpTableLength += pCurBootpEntry->CchGetDataLength();
  110. spCurrentNode.Release();
  111. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  112. }
  113. // allocate the memory
  114. int nBootpTableLengthBytes = nBootpTableLength * sizeof(WCHAR);
  115. WCHAR * pBootpTable = (WCHAR *) _alloca(nBootpTableLengthBytes);
  116. WCHAR * pBootpTableTemp = pBootpTable;
  117. ZeroMemory(pBootpTable, nBootpTableLengthBytes);
  118. spNodeEnum->Reset();
  119. // now enumerate again and store the strings
  120. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  121. while (nNumReturned)
  122. {
  123. CDhcpBootpEntry * pCurBootpEntry = GETHANDLER(CDhcpBootpEntry, spCurrentNode);
  124. pBootpTableTemp = pCurBootpEntry->PchStoreData(pBootpTableTemp);
  125. spCurrentNode.Release();
  126. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  127. }
  128. // now write to the server
  129. DWORD dwError = 0;
  130. DHCP_SERVER_CONFIG_INFO_V4 dhcpServerInfo;
  131. ::ZeroMemory(&dhcpServerInfo, sizeof(dhcpServerInfo));
  132. dhcpServerInfo.cbBootTableString = (DWORD) ((pBootpTableTemp - pBootpTable) + 1) * sizeof(WCHAR);
  133. dhcpServerInfo.wszBootTableString = pBootpTable;
  134. CDhcpBootp * pBootpFolder = GETHANDLER(CDhcpBootp, spBootpFolder);
  135. BEGIN_WAIT_CURSOR;
  136. dwError = ::DhcpServerSetConfigV4(pBootpFolder->GetServerObject(spBootpFolder)->GetIpAddress(),
  137. Set_BootFileTable,
  138. &dhcpServerInfo);
  139. END_WAIT_CURSOR;
  140. if (dwError != ERROR_SUCCESS)
  141. {
  142. GetHolder()->SetError(dwError);
  143. return FALSE;
  144. }
  145. return FALSE;
  146. }
  147. void CBootpPropGeneral::OnChangeEditBootpFileName()
  148. {
  149. SetDirty(TRUE);
  150. }
  151. void CBootpPropGeneral::OnChangeEditBootpFileServer()
  152. {
  153. SetDirty(TRUE);
  154. }
  155. void CBootpPropGeneral::OnChangeEditBootpImageName()
  156. {
  157. SetDirty(TRUE);
  158. }