WarFTPDaemon.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:6k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : WarFTPDaemon.cpp
- // PURPOSE : Windows entry point
- // PROGRAM : War FTP Daemon
- // DATE : Sept. 19 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #include "stdafx.h"
- #define EXT // Link external vars to this module
- #define MAIN_MODULE // Link and initialize static data structures to this module
- #include "WarFTPDaemon.h" // Project header file
- #include "FTPDaemon.h" // FTP Daemon thread class
- #include "WarSoftware.h" // Standard lib
- #include "WarDaemon.h" // Standrad Daemon lib
- #include "FTPDaemonCore.h" // FTP server implementation
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWarFTPDaemonApp
- BEGIN_MESSAGE_MAP(CWarFTPDaemonApp, CWinApp)
- //{{AFX_MSG_MAP(CWarFTPDaemonApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWarFTPDaemonApp construction
- CWarFTPDaemonApp::CWarFTPDaemonApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CWarFTPDaemonApp object
- CWarFTPDaemonApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CWarFTPDaemonApp initialization
- BOOL CWarFTPDaemonApp::InitInstance()
- {
- InitWarSoftwareLibDLL();
- InitWarDaemonLibDLL();
- InitFTPDaemonCoreDLL();
- CDaemon MyDaemon;
- COptions::SetDefaultIniFile(".\FtpDaemon.ini");
- MyDaemon.Process("FTP",I_PROGRAM, I_VERSION, I_COPYRIGHT, RUNTIME_CLASS(CFTPDaemon));
- return FALSE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFTPDaemon
- IMPLEMENT_DYNCREATE(CFTPDaemon, CDaemonBase)
- CFTPDaemon::CFTPDaemon()
- {
- m_Log = gLog = new CFTPDLog;
- m_RemoteAdminListenSocket = new CFTPDRemoteListen;
- m_User = new CUsr;
- m_FTPD = NULL;
- // Initialize program version info
- CProgramInfo::m_PROGRAM = I_PROGRAM;
- CProgramInfo::m_VERSION = I_VERSION;
- CProgramInfo::m_COPYRIGHT = I_COPYRIGHT;
- CProgramInfo::m_SVRTYPE = CProgramInfo::stFTP;
- }
- CFTPDaemon::~CFTPDaemon()
- {
- delete m_User;
- if (m_Log)
- {
- LogMsg(LOGF_DEBUG,"~CFTPDaemon(): - Last goodbye. Closing down the log module.");
- delete gLog;
- }
- m_Log = NULL;
- }
- BOOL CFTPDaemon::InitInstance()
- {
- m_SysTrayIdle = AfxGetApp()->LoadIcon(IDR_WARFTPD);
- m_SysTrayOnline = AfxGetApp()->LoadIcon(IDI_SYSONLINE);
- m_SysTrayOffline = AfxGetApp()->LoadIcon(IDI_SYSOFFLINE);
- m_ServerStat.m_ServerType = "FTP";
- if (!CDaemonBase::InitInstance())
- return FALSE;
- return TRUE;
- }
- BOOL CFTPDaemon::GoOnline(BOOL Online)
- {
- if (m_FTPD)
- {
- delete m_FTPD;
- m_FTPD = NULL;
- }
- if (Online)
- {
- m_FTPD = new CFtpDaemonCore;
- if (!m_FTPD->Create(NULL, m_Log))
- {
- LogMsg(LOGF_SYSTEM,"CDaemonBase::GoOnline() - Failed to start FTP Server subsystem.");
- delete m_FTPD;
- m_FTPD = NULL;
- Online = FALSE;
- }
- }
- CDaemonStatusSvr::SetOnline(Online);
- return TRUE;
- }
- int CFTPDaemon::ExitInstance()
- {
- LogMsg(LOGF_SYSTEM,"Server terminating. Stopping all services...");
- delete m_FTPD;
- return CDaemonBase::ExitInstance();
- }
- /////////////////////////////////////////////////////////////////////////////
- // RefreshStats
- // Derived to update the lower level daemon status information fro what
- // we know..
- void CFTPDaemon::RefreshStats()
- {
- CFtpDaemonCore *pFtp = CFtpDaemonCore::GetFtpSvr();
- ASSERT(AfxIsValidAddress(pFtp, sizeof(CFtpDaemonCore)));
- m_ServerStat.m_ServerName = pFtp->m_Options.m_ServerName;
- m_ServerStat.m_ServerEmail = pFtp->m_Options.m_ServerEmail;
- m_ServerStat.m_ServerPort = pFtp->m_Options.m_Port;
- m_ServerStat.m_ServerListeningIP = pFtp->m_Options.m_IPname;
- CDaemonBase::RefreshStats();
- }
- BEGIN_MESSAGE_MAP(CFTPDaemon, CDaemonBase)
- //{{AFX_MSG_MAP(CFTPDaemon)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFTPDaemon message handlers
- void CFTPDRemoteListen::OnAccept( int nErrorCode )
- {
- CSock::OnAccept(nErrorCode);
- if (nErrorCode)
- return;
- CFTPDRemoteAdmin *NewSocket = new CFTPDRemoteAdmin;
- try
- {
- if (!DoAccept(NewSocket))
- {
- delete NewSocket;
- return;
- }
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CFTPDRemoteListen::OnAccept - Caught exception '%s' from %s. New connection terminated.",
- pExc->m_ErrorText, pExc->m_FromModule);
- if (pExc->m_pSock == NewSocket)
- delete NewSocket;
- delete pExc;
- return;
- }
- catch(...)
- {
- LogMsg(LOGF_ERROR,"CFTPDRemoteListen::OnAccept(%d) - Caught unknown exception. New connection terminated.", nErrorCode);
- return;
- }
- // Intitialize connection
- // Note: ":<sp>" is valid as end of line marker on last line for
- // the remote admin interface.
- CString cBuf;
- cBuf.Format("%s readynLogin: ", m_SocketName);
- NewSocket->SendCtrlMsg(220, cBuf, FALSE, FALSE);
- }
- BOOL CFTPDRemoteListen::Initialize(int PortNumber, LPCSTR ServiceName, LPCSTR ListenIP)
- {
- if (!PortNumber)
- PortNumber = 22; // FTP remote admin port
- if (!ServiceName)
- ServiceName = "FTP Remote Admin";
- m_Type = LT_REMOTE;
- return CDaemonServiceSocket::Initialize(PortNumber, ServiceName, ListenIP);
- }