home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / interface / OptionsDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-13  |  9.9 KB  |  379 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. // Options.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "version.h"
  24. #include "filezilla server.h"
  25. #include "OptionsDlg.h"
  26. #include "..\OptionTypes.h"
  27. #include "Options.h"
  28.  
  29. #if defined(_DEBUG) && !defined(MMGR)
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. #include "OptionsPage.h"
  36. #include "OptionsGeneralPage.h"
  37. #include "OptionsGeneralWelcomemessagePage.h"
  38. #include "OptionsPasvPage.h"
  39. #include "OptionsSecurityPage.h"
  40. #include "OptionsMiscPage.h"
  41. #include "OptionsAdminInterfacePage.h"
  42. #include "OptionsLoggingPage.h"
  43. #include "OptionsGSSPage.h"
  44. #include "OptionsSpeedLimitPage.h"
  45. #include "OptionsCompressionPage.h"
  46. #include "OptionsGeneralIpbindingsPage.h"
  47. #include "OptionsIpFilterPage.h"
  48. #include "OptionsSslPage.h"
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Dialogfeld COptionsDlg 
  52.  
  53. COptionsDlg::COptionsDlg(COptions *pInterfaceOptions, bool localConnection)
  54.     : m_localConnection(localConnection)
  55. {
  56.     ASSERT(pInterfaceOptions);
  57.     m_pInterfaceOptions = pInterfaceOptions;
  58.  
  59.     //Add options pages
  60.     COptionsPage *page;
  61.  
  62.     page = new COptionsGeneralPage(this);
  63.     AddPage(*page, IDS_OPTIONSPAGE_GENERAL);
  64.     m_PageList.push_back(page);
  65.  
  66.         page = new COptionsGeneralWelcomemessagePage(this);
  67.         AddPage(*page, IDS_OPTIONSPAGE_GENERAL_WELCOMEMESSAGE, m_PageList.back());
  68.         m_PageList.push_back(page);
  69.  
  70.         page = new COptionsGeneralIpbindingsPage(this);
  71.         AddPage(*page, IDS_OPTIONSPAGE_GENERAL_IPBINDINGS, *--(--m_PageList.end()));
  72.         m_PageList.push_back(page);
  73.  
  74.         page = new COptionsIpFilterPage(this);
  75.         AddPage(*page, IDS_OPTIONSPAGE_GENERAL_IPFILTER, m_PageList.front());
  76.         m_PageList.push_back(page);
  77.  
  78.     page = new COptionsPasvPage(this);
  79.     AddPage(*page, IDS_OPTIONSPAGE_PASV);
  80.     m_PageList.push_back(page);
  81.  
  82.     page = new COptionsSecurityPage(this);
  83.     AddPage(*page, IDS_OPTIONSPAGE_SECURITY);
  84.     m_PageList.push_back(page);
  85.  
  86.     page = new COptionsMiscPage(this);
  87.     AddPage(*page, IDS_OPTIONSPAGE_MISC);
  88.     m_PageList.push_back(page);
  89.  
  90.     page = new COptionsAdminInterfacePage(this);
  91.     AddPage(*page, IDS_OPTIONSPAGE_ADMININTERFACE);
  92.     m_PageList.push_back(page);
  93.  
  94.     page = new COptionsLoggingPage(this);
  95.     AddPage(*page, IDS_OPTIONSPAGE_LOGGING);
  96.     m_PageList.push_back(page);
  97.  
  98.     page = new COptionsGSSPage(this);
  99.     AddPage(*page, IDS_OPTIONSPAGE_GSS);
  100.     m_PageList.push_back(page);
  101.  
  102.     m_pOptionsSpeedLimitPage = new COptionsSpeedLimitPage(this);
  103.     AddPage(*m_pOptionsSpeedLimitPage, IDS_OPTIONSPAGE_SPEEDLIMIT);
  104.     m_PageList.push_back(m_pOptionsSpeedLimitPage);
  105.  
  106.     page = new COptionsCompressionPage(this);
  107.     AddPage(*page, IDS_OPTIONSPAGE_COMPRESSION);
  108.     m_PageList.push_back(page);
  109.  
  110.     page = new COptionsSslPage(this);
  111.     AddPage(*page, IDS_OPTIONSPAGE_SSL);
  112.     m_PageList.push_back(page);
  113. }
  114.  
  115. COptionsDlg::~COptionsDlg()
  116. {
  117.     for (std::list<COptionsPage *>::iterator iter = m_PageList.begin(); iter != m_PageList.end(); iter++)
  118.         delete *iter;
  119. }
  120.  
  121. void COptionsDlg::DoDataExchange(CDataExchange* pDX)
  122. {
  123.     CSAPrefsDialog::DoDataExchange(pDX);
  124.     //{{AFX_DATA_MAP(COptionsDlg)
  125.         // HINWEIS: Der Klassen-Assistent fⁿgt hier DDX- und DDV-Aufrufe ein
  126.     //}}AFX_DATA_MAP
  127. }
  128.  
  129. BEGIN_MESSAGE_MAP(COptionsDlg, CSAPrefsDialog)
  130.     //{{AFX_MSG_MAP(COptionsDlg)
  131.     //}}AFX_MSG_MAP
  132. END_MESSAGE_MAP()
  133.  
  134. /////////////////////////////////////////////////////////////////////////////
  135. // Behandlungsroutinen fⁿr Nachrichten COptionsDlg 
  136.  
  137. BOOL COptionsDlg::Show()
  138. {
  139.     SetConstantText("FileZilla Server");
  140.  
  141.     std::list<COptionsPage *>::iterator iter;
  142.     for (iter = m_PageList.begin(); iter != m_PageList.end(); iter++)
  143.         (*iter)->LoadData();
  144.  
  145.     if (DoModal()!=IDOK)
  146.         return FALSE;
  147.  
  148.     for (iter = m_PageList.begin(); iter != m_PageList.end(); iter++)
  149.         (*iter)->SaveData();
  150.  
  151.     return TRUE;
  152. }
  153.  
  154. BOOL COptionsDlg::OnInitDialog() 
  155. {
  156.     CSAPrefsDialog::OnInitDialog();
  157.         
  158.     return TRUE;  // return TRUE unless you set the focus to a control
  159.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  160. }
  161.  
  162. void COptionsDlg::SetOption(int nOptionID, __int64 value)
  163. {
  164.     m_OptionsCache[nOptionID-1].nType = 1;
  165.     m_OptionsCache[nOptionID-1].value = value;
  166. }
  167.  
  168. void COptionsDlg::SetOption(int nOptionID, CString value)
  169. {
  170.     m_OptionsCache[nOptionID-1].nType = 0;
  171.     m_OptionsCache[nOptionID-1].str = value;
  172. }
  173.  
  174. CString COptionsDlg::GetOption(int nOptionID)
  175. {
  176.     ASSERT(nOptionID>0 && nOptionID<=OPTIONS_NUM);
  177.     ASSERT(!m_Options[nOptionID-1].nType);
  178.  
  179.     return m_OptionsCache[nOptionID-1].str;
  180. }
  181.  
  182. __int64 COptionsDlg::GetOptionVal(int nOptionID)
  183. {
  184.     ASSERT(nOptionID>0 && nOptionID<=OPTIONS_NUM);
  185.     ASSERT(m_Options[nOptionID-1].nType == 1);
  186.     
  187.     return m_OptionsCache[nOptionID-1].value;
  188. }
  189.  
  190. void COptionsDlg::OnOK() 
  191. {
  192.     if (!UpdateData(true))
  193.         return;
  194.     if (!GetCurPage()->UpdateData(TRUE))
  195.         return;
  196.  
  197.     for (std::list<COptionsPage *>::iterator iter = m_PageList.begin(); iter != m_PageList.end(); iter++)
  198.         if (!(*iter)->IsDataValid())
  199.             return;
  200.         
  201.     CSAPrefsDialog::OnOK();
  202. }
  203.  
  204. CSAPrefsSubDlg* COptionsDlg::GetCurPage()
  205. {
  206.     int iPage = m_iCurPage;
  207.     // show the new one
  208.     if ((iPage >= 0) && (iPage < (int)m_pages.size()))
  209.     {
  210.         pageStruct *pPS = m_pages[iPage];
  211.         ASSERT(pPS);
  212.  
  213.         if (pPS)
  214.         {
  215.             ASSERT(pPS->pDlg);
  216.             if (pPS->pDlg)
  217.             {
  218.                 return pPS->pDlg;
  219.             }
  220.         }
  221.     }
  222.     return NULL;
  223. }
  224.  
  225. bool COptionsDlg::AddPage(CSAPrefsSubDlg &page, UINT nCaptionID, CSAPrefsSubDlg *pDlgParent /*= NULL*/)
  226. {
  227.     CString str;
  228.     str.LoadString(nCaptionID);
  229.     return CSAPrefsDialog::AddPage(page,str,pDlgParent);
  230. }
  231.  
  232. bool COptionsDlg::IsNumeric(LPCTSTR str)
  233. {
  234.     if (!str)
  235.         return false;
  236.     LPCTSTR p=str;
  237.     while(*p)
  238.     {
  239.         if (*p<'0' || *p>'9')
  240.         {
  241.             return false;
  242.         }
  243.         p++;
  244.     }
  245.     return true;
  246. }
  247.  
  248. BOOL COptionsDlg::Init(unsigned char *pData, DWORD dwDataLength)
  249. {
  250.     unsigned char *p = pData;
  251.     int i;
  252.     int num = *p * 256 + p[1];
  253.     p+=2;
  254.     if (num!=OPTIONS_NUM)
  255.         return FALSE;
  256.     
  257.     for (i=0; i<num; i++)
  258.     {
  259.         if (static_cast<DWORD>(p-pData) >= dwDataLength)
  260.             return FALSE;
  261.         int nType = *p++;
  262.         if (!nType)
  263.         {
  264.             if (static_cast<DWORD>(p-pData+2) >= dwDataLength)
  265.                 return 2;
  266.             int len= *p * 256 + p[1];
  267.             p+=2;
  268.             if (static_cast<DWORD>(p-pData+len)>dwDataLength)
  269.                 return FALSE;
  270.             m_OptionsCache[i].nType = 0;
  271.             char *pBuffer = m_OptionsCache[i].str.GetBuffer(len);
  272.             memcpy(pBuffer, p, len);
  273.             m_OptionsCache[i].str = p;
  274.             m_OptionsCache[i].str.ReleaseBuffer(len);
  275.             p+=len;
  276.         }
  277.         else if (nType == 1)
  278.         {
  279.             if (static_cast<DWORD>(p-pData+8)>dwDataLength)
  280.                 return FALSE;
  281.             m_OptionsCache[i].nType = 1;
  282.             memcpy(&m_OptionsCache[i].value, p, 8);
  283.             p+=8;
  284.         }
  285.         else
  286.             return FALSE;
  287.     }
  288.  
  289.     if (static_cast<DWORD>(p-pData+2) > dwDataLength)
  290.         return FALSE;
  291.     num = *p++ << 8;
  292.     num |= *p++;
  293.     for (i=0; i<num; i++)
  294.     {
  295.         CSpeedLimit limit;
  296.         p = limit.ParseBuffer(p, dwDataLength - (p - pData));
  297.         if (!p)
  298.             return FALSE;
  299.         m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.push_back(limit);
  300.     }
  301.     
  302.     if (static_cast<DWORD>(p-pData+2) > dwDataLength)
  303.         return FALSE;
  304.     num = *p++ << 8;
  305.     num |= *p++;
  306.     for (i=0; i<num; i++)
  307.     {
  308.         CSpeedLimit limit;
  309.         p = limit.ParseBuffer(p, dwDataLength - (p - pData));
  310.         if (!p)
  311.             return FALSE;
  312.         m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.push_back(limit);
  313.     }
  314.     return TRUE;
  315. }
  316.  
  317. BOOL COptionsDlg::GetAsCommand(char **pBuffer, DWORD *nBufferLength)
  318. {
  319.     DWORD len = 2;
  320.     int i;
  321.     for (i = 0; i < OPTIONS_NUM; i++)
  322.     {
  323.         len+=1;
  324.         if (!m_Options[i].nType)
  325.             len+=GetOption(i+1).GetLength()+2;
  326.         else
  327.             len+=8;
  328.     }
  329.     len += 4; //Number of rules
  330.     SPEEDLIMITSLIST::const_iterator iter;
  331.     for (iter = m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.begin(); iter != m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.end(); iter++)
  332.         len += iter->GetRequiredBufferLen();
  333.     for (iter = m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.begin(); iter != m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.end(); iter++)
  334.         len += iter->GetRequiredBufferLen();
  335.  
  336.     *pBuffer = new char[len];
  337.     char *p=*pBuffer;
  338.     *p++ = OPTIONS_NUM/256;
  339.     *p++ = OPTIONS_NUM%256;
  340.     for (i=0; i<OPTIONS_NUM; i++)
  341.     {
  342.         *p++ = m_Options[i].nType;
  343.         switch(m_Options[i].nType) {
  344.         case 0:
  345.             {
  346.                 CString str = GetOption(i+1);
  347.                 *p++ = str.GetLength() / 256;
  348.                 *p++ = str.GetLength() % 256;
  349.                 memcpy(p, str, str.GetLength());
  350.                 p+=str.GetLength();
  351.             }
  352.             break;
  353.         case 1:
  354.             {
  355.                 _int64 value = GetOptionVal(i+1);
  356.                 memcpy(p, &value, 8);
  357.                 p+=8;
  358.             }
  359.             break;
  360.         default:
  361.             ASSERT(FALSE);
  362.         }
  363.     }
  364.  
  365.     *p++ = m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.size() >> 8;
  366.     *p++ = m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.size() % 256;
  367.     for (iter = m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.begin(); iter != m_pOptionsSpeedLimitPage->m_DownloadSpeedLimits.end(); iter++)
  368.         p = iter->FillBuffer(p);
  369.     
  370.     *p++ = m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.size() >> 8;
  371.     *p++ = m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.size() % 256;
  372.     for (iter = m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.begin(); iter != m_pOptionsSpeedLimitPage->m_UploadSpeedLimits.end(); iter++)
  373.         p = iter->FillBuffer(p);
  374.  
  375.     *nBufferLength = len;
  376.  
  377.     return TRUE;
  378. }
  379.