www.pudn.com > warsrc.rar > FTPDaemonCore.h
// 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 : FTPDaemonCore.h
// PURPOSE : General entry point module for War Daemons
// PROGRAM :
// DATE : Sept. 19 1996
// AUTHOR : Jarle Aase
// ---
// REVISION HISTORY
//
#ifndef __FTPDAEMONCOREH
#define __FTPDAEMONCOREH
#ifndef __WARDAEMONH
#include "WarDaemon.h"
#endif
#ifdef DLL_WAR_FTPDAEMON_EXPORT
#define DLL_WAR_FTPDAEMON_EXPORT_ __declspec(dllexport)
#else
#define DLL_WAR_FTPDAEMON_EXPORT_ __declspec(dllimport)
#endif
extern "C" AFX_EXT_API void WINAPI InitFTPDaemonCoreDLL();
class CFTPDCoreCtrlSock;
class CFTPDFsys;
////////////////////////////////////////////////////////////////////
// FTPD Command parser
class CFTPDParser : public CCommandParser
{
public:
CFTPDParser();
virtual ParseCmd(LPCSTR CmdLine, CCmdArgs& Args, int Level, BOOL& DoParseCmdLine);
};
/////////////////////////////////////////////////////////////////////////////////
// FTP server control connection
class DLL_WAR_FTPDAEMON_EXPORT_ CFTPDCoreCtrlSock : public CTextSock
{
public:
DECLARE_DYNAMIC(CFTPDCoreCtrlSock);
CFTPDParser m_Parser;
CString m_ArgSave; // Used to store text from one to the next command.
int m_PrevCmdID;
FLEN m_Restart; // File restart marker
CFTPDFsys *m_Fsys;
CFTPDataSock *m_DataSock;
CCmdArgs m_Args; // Current line arguments
CCmdArgs m_UnixArgs; // Line aguments expanded
CString m_LastCommandText;
// FTP transfere options
int m_FTPmode;
int m_FTPtype;
int m_FTPstru;
int m_FTPform;
struct sockaddr m_Sockaddr; // Used to connect to remote data socket
public:
CFTPDCoreCtrlSock();
~CFTPDCoreCtrlSock();
virtual BOOL OnCommand(LPCSTR Text);
BOOL OnCommand(int CmdID);
virtual BOOL CallbackProcessList(int nErrorCode);;
// CAsyncSocket handlers
virtual void OnConnect( int nErrorCode );
virtual void OnClose( int nErrorCode );
virtual void OnReceive( int nErrorCode );
virtual void OnSend( int nErrorCode );
virtual void _OnConnect( int nErrorCode );
virtual void IncXferCnt(BOOL Add);
protected:
virtual void Virgin();
virtual BOOL ProcessTelnetNegotiation(int ch1, int ch2);
virtual void InsertPendingText();
virtual BOOL ExpandMacro(LPSTR *To, LPCSTR MacroName, int AvailBytes);
protected:
// FTP server implementation functions
virtual BOOL OnQuit(CCmdArgs& Args);
virtual BOOL OnLogin(CCmdArgs& Args);
virtual BOOL OnAcct(CCmdArgs& Args);
virtual BOOL OnRein(CCmdArgs& Args);
virtual BOOL OnPort(CCmdArgs& Args);
virtual BOOL OnPasv(CCmdArgs& Args);
virtual BOOL OnType(CCmdArgs& Args);
virtual BOOL OnStru(CCmdArgs& Args);
virtual BOOL OnMode(CCmdArgs& Args);
virtual BOOL OnRetr(CCmdArgs& Args);
virtual BOOL OnStor(CCmdArgs& Args);
virtual BOOL OnAppe(CCmdArgs& Args);
virtual BOOL OnAllo(CCmdArgs& Args);
virtual BOOL OnRest(CCmdArgs& Args);
virtual BOOL OnRnFr(CCmdArgs& Args);
virtual BOOL OnRnTo(CCmdArgs& Args);
virtual BOOL OnAbor(CCmdArgs& Args);
virtual BOOL OnDele(CCmdArgs& Args);
virtual BOOL OnCwd(CCmdArgs& Args);
virtual BOOL OnList(CCmdArgs& Args);
virtual BOOL OnNlst(CCmdArgs& Args);
virtual BOOL OnSite(CCmdArgs& Args);
virtual BOOL OnStat(CCmdArgs& Args);
virtual BOOL OnHelp(CCmdArgs& Args);
virtual BOOL OnNoop(CCmdArgs& Args);
virtual BOOL OnMkd(CCmdArgs& Args);
virtual BOOL OnRmd(CCmdArgs& Args);
virtual BOOL OnPwd(CCmdArgs& Args);
virtual BOOL OnCdUp(CCmdArgs& Args);
virtual BOOL OnStou(CCmdArgs& Args);
virtual BOOL OnSmnt(CCmdArgs& Args);
virtual BOOL OnSyst(CCmdArgs& Args);
virtual BOOL OnSize(CCmdArgs& Args);
virtual BOOL OnMdtm(CCmdArgs& Args);
// Support functions
virtual BOOL ProcessList(LPCSTR LineArguments, CCmdArgs& Args);
virtual BOOL DoChdir(LPCSTR Path);
virtual BOOL DoRetr(CCmdArgs& Args, DWORD Flags);
virtual BOOL DoStor(CCmdArgs& Args, DWORD Flags);
virtual BOOL DoDele(CCmdArgs& Args);
virtual BOOL MkUniquePath(CString& cFnameBuf);
virtual BOOL DoMkDir(CCmdArgs& Args);
// SITE
virtual BOOL OnSiteChmod(CCmdArgs &Args);
virtual BOOL OnSiteFsysstat(CCmdArgs &Args);
};
#define XMITF_TEMP 0x00000001 // Tmp file
#define XMITF_APPE 0x00000002 // Append
#define XMITF_UNIQUE 0x00000004 // Stor unique
/////////////////////////////////////////////////////////////////////////////////
// FTP server listen socket
class CFTPDCoreListenSock : public CDaemonServiceSocket
{
public:
virtual void OnAccept( int nErrorCode );
virtual void _OnAccept( int nErrorCode );
virtual BOOL Initialize(int PortNumber, LPCSTR ServiceName, LPCSTR ListenIP = NULL);
};
class DLL_WAR_FTPDAEMON_EXPORT_ CFtpDaemonCore
{
public:
CFTPDaemonCoreOptions m_Options; // Basic FTP server options
CFTPDCoreListenSock m_Listen; // Listening socket
CLog *m_Log;
static CFtpDaemonCore *m_pCFtpDaemonCore;
public:
CFtpDaemonCore();
~CFtpDaemonCore();
virtual BOOL Create(LPCSTR IniFile, CLog *Log);
virtual void LogMsg(int flag, LPCSTR Format, ...);
static CFtpDaemonCore *GetFtpSvr() {return m_pCFtpDaemonCore;}
};
//////////////////////////////////////////////////////////////////////////////////////////
// CFTPDFsys
class DLL_WAR_FTPDAEMON_EXPORT_ CFTPDFsys : public CUserFsys
{
public:
CFTPDFsys(LPVOID *pRef);
BOOL Create(CFTPDCoreCtrlSock *Sock); // Create user fsys
// Data members
CFTPDCoreCtrlSock *m_pSock;
DWORD m_AsyncSelectMaskSaved;
DWORD m_StateSaved;
DWORD m_CallbackID;
enum // Callback ID's
{
CB_CHDIR, // Normal CHDIR
CB_SIZE, // SIZE
CB_MDTM, // MDTM
};
LPARAM m_lParam; // Storage of data
// Hight level functions
public:
BOOL PrepereCommandLine(int CmdIDtoRemember);
CString GetFullPath(LPCSTR Path, DWORD AccessFlags);
BOOL RenamePath(LPCSTR OldName, LPCSTR NewName);
BOOL CheckPermission(LPCSTR Path, BOOL IsDir, int PermsWanted);
BOOL DeletePath(LPCSTR Path);
BOOL MkDir(LPCSTR Path);
BOOL ChDir(LPCSTR Path);
BOOL List();
BOOL Mdtm(LPCSTR Path);
BOOL Size(LPCSTR Path);
// Callback functions
protected:
virtual BOOL SetOnHold(); // Called when a callback needs to wait...
// Return FALSE to abort the operation
virtual void ReleaseHold(); // Release hold state - callback is not called.
virtual void CheckForZombie(); // Release resources and throw an execpion
virtual BOOL OnCreate(int nErrorCode); // Called after Create()
virtual BOOL OnChdir(int nErrorCode); // Called for all ChDir's
virtual BOOL CallbackChDir(int nErrorCode); // Called after FTP cmd CWD
virtual BOOL OnPrpCmdLine(int nErrorCode);
virtual BOOL OnList(int nErrorCode);
virtual BOOL OnChmod(int nErrorCode);
virtual BOOL OnFsysStat(int nErrorCode);
virtual BOOL OnCreateDirectory(int nErrorCode);
virtual BOOL OnDeleteDirectory(int nErrorCode);
virtual BOOL OnDeleteFile(int nErrorCode);
virtual BOOL OnDeleteGeneric(int nErrorCode);
BOOL OnDelete(int nErrorCode);
virtual BOOL OnMoveFile(int nErrorCode);
virtual BOOL OnStat(int nErrorCode);
BOOL OnStatSize(int nErrorCode);
BOOL OnStatMDTM(int nErrorCode);
};
#endif __FTPDAEMONCOREH