home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / interface / OptionsCompressionPage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-11-02  |  3.7 KB  |  120 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 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. #include "stdafx.h"
  20. #include "filezilla server.h"
  21. #include "OptionsDlg.h"
  22. #include "OptionsPage.h"
  23. #include "OptionsCompressionPage.h"
  24. #include "../iputils.h"
  25.  
  26. COptionsCompressionPage::COptionsCompressionPage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  27.     : COptionsPage(pOptionsDlg, COptionsCompressionPage::IDD, pParent)
  28. {
  29. }
  30.  
  31. COptionsCompressionPage::~COptionsCompressionPage()
  32. {
  33. }
  34.  
  35. void COptionsCompressionPage::DoDataExchange(CDataExchange* pDX)
  36. {
  37.     COptionsPage::DoDataExchange(pDX);
  38.     DDX_Text(pDX, IDC_OPTIONS_COMPRESSION_DISALLOWED_IPS, m_disallowedIPs);
  39.     DDX_Check(pDX, IDC_OPTIONS_COMPRESSION_USE, m_UseModeZ);
  40.     DDX_Text(pDX, IDC_OPTIONS_COMPRESSION_LEVELMAX, m_LevelMax);
  41.     DDV_MaxChars(pDX, m_LevelMax, 1);
  42.     DDX_Text(pDX, IDC_OPTIONS_COMPRESSION_LEVELMIN, m_LevelMin);
  43.     DDV_MaxChars(pDX, m_LevelMin, 1);
  44.     DDX_Check(pDX, IDC_OPTIONS_EXCLUDELOCAL, m_DisallowLocal);
  45. }
  46.  
  47.  
  48. BEGIN_MESSAGE_MAP(COptionsCompressionPage, COptionsPage)
  49. END_MESSAGE_MAP()
  50.  
  51. BOOL COptionsCompressionPage::IsDataValid()
  52. {
  53.     UpdateData();
  54.  
  55.     if (atoi(m_LevelMin) < 1 || atoi(m_LevelMin) > 8)
  56.     {
  57.         m_pOptionsDlg->ShowPage(this);
  58.         GetDlgItem(IDC_OPTIONS_COMPRESSION_LEVELMIN)->SetFocus();
  59.         AfxMessageBox(_T("Minimum compression level must be between 1 and 8"));
  60.         return false;
  61.     }
  62.  
  63.     if (atoi(m_LevelMax) < 8 || atoi(m_LevelMax) > 9)
  64.     {
  65.         m_pOptionsDlg->ShowPage(this);
  66.         GetDlgItem(IDC_OPTIONS_COMPRESSION_LEVELMAX)->SetFocus();
  67.         AfxMessageBox(_T("Maximum compression level must be between 8 and 9"));
  68.         return false;
  69.     }
  70.  
  71.  
  72.  
  73.     CString str = m_disallowedIPs;
  74.     str.Replace('\r', ' ');
  75.     str.Replace('\n', ' ');
  76.     str.Replace('\r', ' ');
  77.     while (str.Replace("  ", " "));
  78.     if (str != "")
  79.         str += " ";
  80.  
  81.     CString ips;
  82.  
  83.     int pos = str.Find(' ');
  84.     while (pos != -1)
  85.     {
  86.         CString sub = str.Left(pos);
  87.         str = str.Mid(pos + 1);
  88.         str.TrimLeft(' ');
  89.  
  90.         if (!IsValidAddressFilter(sub))
  91.         {
  92.             m_pOptionsDlg->ShowPage(this);
  93.             GetDlgItem(IDC_OPTIONS_COMPRESSION_DISALLOWED_IPS)->SetFocus();
  94.             AfxMessageBox(_T("Invalid IP address (range/mask) enterd."));
  95.             return false;
  96.         }
  97.         pos = str.Find(' ');
  98.     }
  99.  
  100.     return TRUE;
  101. }
  102.  
  103. void COptionsCompressionPage::SaveData()
  104. {
  105.     m_pOptionsDlg->SetOption(OPTION_MODEZ_USE, m_UseModeZ);
  106.     m_pOptionsDlg->SetOption(OPTION_MODEZ_LEVELMIN, atoi(m_LevelMin));
  107.     m_pOptionsDlg->SetOption(OPTION_MODEZ_LEVELMAX, atoi(m_LevelMax));
  108.     m_pOptionsDlg->SetOption(OPTION_MODEZ_ALLOWLOCAL, !m_DisallowLocal);
  109.     m_pOptionsDlg->SetOption(OPTION_MODEZ_DISALLOWED_IPS, m_disallowedIPs);
  110. }
  111.  
  112. void COptionsCompressionPage::LoadData()
  113. {
  114.     m_LevelMin.Format("%d", m_pOptionsDlg->GetOptionVal(OPTION_MODEZ_LEVELMIN));
  115.     m_LevelMax.Format("%d", m_pOptionsDlg->GetOptionVal(OPTION_MODEZ_LEVELMAX));
  116.     m_UseModeZ = m_pOptionsDlg->GetOptionVal(OPTION_MODEZ_USE) != 0;
  117.     m_DisallowLocal = !m_pOptionsDlg->GetOptionVal(OPTION_MODEZ_ALLOWLOCAL);
  118.     m_disallowedIPs =  m_pOptionsDlg->GetOption(OPTION_MODEZ_DISALLOWED_IPS);
  119. }
  120.