home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / interface / OptionsPasvPage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-08-03  |  5.7 KB  |  176 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // OptionsPasvPage.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "filezilla server.h"
  24. #include "OptionsDlg.h"
  25. #include "OptionsPage.h"
  26. #include "OptionsPasvPage.h"
  27.  
  28. #if defined(_DEBUG) && !defined(MMGR)
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Dialogfeld COptionsPasvPage 
  36.  
  37.  
  38. COptionsPasvPage::COptionsPasvPage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  39.     : COptionsPage(pOptionsDlg, COptionsPasvPage::IDD, pParent)
  40. {
  41.     //{{AFX_DATA_INIT(COptionsPasvPage)
  42.     m_URL = _T("");
  43.     m_IP = _T("");
  44.     m_nIPType = -1;
  45.     m_bUseCustomPort = FALSE;
  46.     m_PortMin = _T("");
  47.     m_PortMax = _T("");
  48.     m_Text = CString((LPCTSTR)IDC_OPTIONS_PASV_TEXT);
  49.     //}}AFX_DATA_INIT
  50. }
  51.  
  52.  
  53. void COptionsPasvPage::DoDataExchange(CDataExchange* pDX)
  54. {
  55.     COptionsPage::DoDataExchange(pDX);
  56.     //{{AFX_DATA_MAP(COptionsPasvPage)
  57.     DDX_Control(pDX, IDC_OPTIONS_PASV_PORTMIN, m_cPortMin);
  58.     DDX_Control(pDX, IDC_OPTIONS_PASV_PORTMAX, m_cPortMax);
  59.     DDX_Control(pDX, IDC_OPTIONS_PASV_IP, m_cIP);
  60.     DDX_Control(pDX, IDC_OPTIONS_PASV_URL, m_cURL);
  61.     DDX_Text(pDX, IDC_OPTIONS_PASV_URL, m_URL);
  62.     DDX_Text(pDX, IDC_OPTIONS_PASV_IP, m_IP);
  63.     DDX_Radio(pDX, IDC_OPTIONS_PASV_IPTYPE1, m_nIPType);
  64.     DDX_Check(pDX, IDD_OPTIONS_PASV_USEPORTRANGE, m_bUseCustomPort);
  65.     DDX_Text(pDX, IDC_OPTIONS_PASV_PORTMIN, m_PortMin);
  66.     DDV_MaxChars(pDX, m_PortMin, 5);
  67.     DDX_Text(pDX, IDC_OPTIONS_PASV_PORTMAX, m_PortMax);
  68.     DDV_MaxChars(pDX, m_PortMax, 5);
  69.     DDX_Text(pDX, IDC_OPTIONS_PASV_TEXT, m_Text);
  70.     //}}AFX_DATA_MAP
  71. }
  72.  
  73.  
  74. BEGIN_MESSAGE_MAP(COptionsPasvPage, COptionsPage)
  75.     //{{AFX_MSG_MAP(COptionsPasvPage)
  76.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE2, OnOptionsPasvIptype)
  77.     ON_BN_CLICKED(IDD_OPTIONS_PASV_USEPORTRANGE, OnOptionsPasvUseportrange)
  78.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE3, OnOptionsPasvIptype)
  79.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE1, OnOptionsPasvIptype)
  80.     //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Behandlungsroutinen fⁿr Nachrichten COptionsPasvPage 
  85.  
  86. void COptionsPasvPage::OnOptionsPasvIptype() 
  87. {
  88.     UpdateData(TRUE);
  89.     m_cIP.EnableWindow(m_nIPType == 1);
  90.     m_cURL.EnableWindow(m_nIPType == 2);    
  91. }
  92.  
  93. void COptionsPasvPage::OnOptionsPasvUseportrange() 
  94. {
  95.     UpdateData(TRUE);
  96.     m_cPortMin.EnableWindow(m_bUseCustomPort);
  97.     m_cPortMax.EnableWindow(m_bUseCustomPort);
  98. }
  99.  
  100. BOOL COptionsPasvPage::OnInitDialog() 
  101. {
  102.     COptionsPage::OnInitDialog();
  103.     
  104.     OnOptionsPasvIptype();
  105.     OnOptionsPasvUseportrange();
  106.  
  107.     return TRUE;  // return TRUE unless you set the focus to a control
  108.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  109. }
  110.  
  111. BOOL COptionsPasvPage::IsDataValid()
  112. {
  113.     if (m_nIPType == 1)
  114.     {
  115.         //Ensure a valid IP address has been entered
  116.         if (m_IP == "")
  117.         {
  118.             m_pOptionsDlg->ShowPage(this);
  119.             GetDlgItem(IDC_OPTIONS_PASV_IP)->SetFocus();
  120.             AfxMessageBox("Please enter a valid IP address or hostname!");
  121.             return FALSE;
  122.         }
  123.     }
  124.     else if (m_nIPType == 2)
  125.     {
  126.         CString address = m_URL;
  127.         if (address.Left(7) == "http://")
  128.             address = address.Mid(7);
  129.         int pos = address.Find('/');
  130.         if (pos != -1)
  131.             address = address.Left(pos);
  132.  
  133.         if (address == "" || address.Find(' ') != -1)
  134.         {
  135.             m_pOptionsDlg->ShowPage(this);
  136.             GetDlgItem(IDC_OPTIONS_PASV_URL)->SetFocus();
  137.             AfxMessageBox("Please enter the complete URL of the IP autodetect server!");
  138.             return FALSE;
  139.         }
  140.     }
  141.  
  142.     if (m_bUseCustomPort)
  143.     {
  144.         int nPortMin = _ttoi(m_PortMin);
  145.         int nPortMax = _ttoi(m_PortMax);
  146.         if (nPortMin<1 || nPortMin>65535 || nPortMax<1 || nPortMax>65535 || nPortMin>nPortMax)
  147.         {
  148.             m_pOptionsDlg->ShowPage(this);
  149.             GetDlgItem(IDC_OPTIONS_PASV_PORTMIN)->SetFocus();
  150.             AfxMessageBox("The port values have to be in the range from 1 to 65535. Also, the first value has to be lower than or equal to the second one.");            
  151.             return FALSE;
  152.         }
  153.     }
  154.  
  155.     return TRUE;
  156. }
  157.  
  158. void COptionsPasvPage::LoadData()
  159. {
  160.     m_nIPType = (int)m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVIPTYPE);
  161.     m_IP = m_pOptionsDlg->GetOption(OPTION_CUSTOMPASVIP);
  162.     m_URL = m_pOptionsDlg->GetOption(OPTION_CUSTOMPASVIPSERVER);
  163.     m_bUseCustomPort = m_pOptionsDlg->GetOptionVal(OPTION_USECUSTOMPASVPORT) != 0;
  164.     m_PortMin.Format("%d", m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVMINPORT));
  165.     m_PortMax.Format("%d", m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVMAXPORT));
  166. }
  167.  
  168. void COptionsPasvPage::SaveData()
  169. {
  170.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIPTYPE, m_nIPType);
  171.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIP, m_IP);
  172.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIPSERVER, m_URL);
  173.     m_pOptionsDlg->SetOption(OPTION_USECUSTOMPASVPORT, m_bUseCustomPort);
  174.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVMINPORT, _ttoi(m_PortMin));
  175.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVMAXPORT, _ttoi(m_PortMax));
  176. }