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.

102 lines
2.8 KiB

  1. #include "stdafx.h"
  2. #include "natobjs.h"
  3. #include "resource.h"
  4. //-------------------------------------------------------------------------
  5. CNATGroup::CNATGroup( CNATServerComputer* pNatComputer, LPCTSTR pszIP,
  6. LPCTSTR pszName, DWORD dwSticky, DWORD type ):
  7. m_pNatComputer(pNatComputer),
  8. m_dwSticky(dwSticky),
  9. m_type(type)
  10. {
  11. m_csIP = pszIP;
  12. m_csName = pszName;
  13. }
  14. //-------------------------------------------------------------------------
  15. CNATGroup::~CNATGroup()
  16. {
  17. // clean up the site array
  18. EmptySites();
  19. }
  20. //-------------------------------------------------------------------------
  21. // Edit the properties of this Site - true if OK
  22. BOOL CNATGroup::OnProperties()
  23. {
  24. return TRUE;
  25. }
  26. //-------------------------------------------------------------------------
  27. // This is just a handy way to get the nat machine object to commit
  28. void CNATGroup::Commit()
  29. {
  30. if ( m_pNatComputer )
  31. m_pNatComputer->Commit();
  32. }
  33. //-------------------------------------------------------------------------
  34. // adds a new site to the list.
  35. // think about making this a wizard
  36. CNATSite* CNATGroup::NewSite()
  37. {
  38. CNATSiteComputer* pSC = NULL;
  39. // ask the nat server object for a site computer
  40. pSC = m_pNatComputer->NewComputer();
  41. if ( !pSC )
  42. return NULL;
  43. // for now, make a site with the defaults
  44. CNATSite* pS = new CNATSite( this, pSC );
  45. if ( pS == NULL )
  46. {
  47. AfxMessageBox( IDS_LOWMEM );
  48. return NULL;
  49. }
  50. // Ask the user to edit the group's properties.
  51. // Do not add it if they cancel
  52. if ( !pS->OnProperties() )
  53. {
  54. delete pS;
  55. return NULL;
  56. }
  57. // add the object to the end of the array
  58. m_rgbSites.Add( pS );
  59. return pS;
  60. }
  61. //-------------------------------------------------------------------------
  62. // adds an existing site to the list - to be called during a refresh.
  63. // this checks the visiblity of the machine on the net as it adds it
  64. void CNATGroup::AddSite( CNATSiteComputer* pSiteComputer, LPCTSTR pszPrivateIP, IN LPCTSTR pszName )
  65. {
  66. // create the new Site Computer object
  67. CNATSite* pS = new CNATSite( this, pSiteComputer, pszPrivateIP, pszName );
  68. if ( pS == NULL )
  69. {
  70. AfxMessageBox( IDS_LOWMEM );
  71. return;
  72. }
  73. // add the object to the end of the array
  74. m_rgbSites.Add( pS );
  75. }
  76. //-------------------------------------------------------------------------
  77. // empties and frees all the groups/sites in the groups list
  78. void CNATGroup::EmptySites()
  79. {
  80. DWORD numSites = m_rgbSites.GetSize();
  81. // loop the array and free all the group objects
  82. for ( DWORD i = 0; i < numSites; i++ )
  83. {
  84. delete m_rgbSites[i];
  85. }
  86. // empty the array itself
  87. m_rgbSites.RemoveAll();
  88. }