WarDaemon.h
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:9k
源码类别:
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 : WarDaemon.h
- // PURPOSE : General entry point module for War Daemons
- // PROGRAM :
- // DATE : Sept. 19 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #ifndef __WARDAEMONH
- #define __WARDAEMONH
- #ifndef __WARSOFTWAREH
- #include "WarSoftware.h"
- #endif
- #ifndef __USERH
- #include "User.h"
- #endif
- #include "UnixFsysTypes.h"
- #include "parser.h"
- class CNTService;
- class CRAFsys;
- extern "C" AFX_EXT_API void WINAPI InitWarDaemonLibDLL();
- /////////////////////////////////////////////////////////////////////////////////
- // Some pre-declarations
- class CLog;
- class CWarTimer;
- class CDaemonServiceSocket;
- class CDaemonLog;
- class CFsys;
- class DLL_WAR_DAEMON_ CDaemonNotificationWnd : public CWnd
- {
- public:
- static CWnd *m_pWnd;
- static CWinThread *m_pThread;
- // Construction
- public:
- CDaemonNotificationWnd();
- ~CDaemonNotificationWnd();
- static CWnd *GetWin() {return m_pWnd;}
- static HWND GetHwnd() {return m_pWnd->m_hWnd;}
- static BOOL IsSameThread() {return m_pThread == AfxGetThread();}
- LONG (* m_OnTrayIconMessage)(WPARAM WParam, LPARAM LParam);
- protected:
- //{{AFX_MSG(CNotificationWnd)
- LONG OnTrayIconMessage(WPARAM WParam, LPARAM LParam);
- afx_msg void OnStopandquit();
- afx_msg void OnGoOnline();
- afx_msg void OnGoOffline();
- afx_msg void OnRestart();
- afx_msg void OnStartManager();
- LRESULT OnDNS(WPARAM WParam, LPARAM LParam);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- ////////////////////////////////////////////////////////////////////
- // Admin Command parser
- class CAdminParser : public CCommandParser
- {
- public:
- CAdminParser();
- //virtual ParseCmd(LPCSTR CmdLine, CCmdArgs& Args, int Level);
- };
- ///////////////////////////////////////////////////////////////////////////////////////
- // CDaemonServiceSocket
- // Listening socket
- // Handles the basics of listening and accepting connections
- // Keeps a linst of connections.
- class DLL_WAR_DAEMON_ CDaemonServiceSocket : public CSock
- {
- public:
- CDaemonServiceSocket();
- ~CDaemonServiceSocket();
- int m_PortNumber; // Listening port
- virtual BOOL Initialize(int PortNumber, LPCSTR ServiceName, LPCSTR ListenIP = NULL);
- protected:
- virtual BOOL DoAccept(CSock *NewSocket );
- };
- ///////////////////////////////////////////////////////////////////////////////////////
- // CDaemonMaintananceSocket
- // Base class for the maintainance socket interface on the server side.
- // Can be used as a template for other server based socket classes.
- class DLL_WAR_DAEMON_ CDaemonMaintananceSocket : public CTextSock
- {
- public:
- DECLARE_DYNAMIC(CDaemonMaintananceSocket);
- CAdminParser m_Parser;
- CString m_ArgSave;
- CRAFsys *m_pFsys;
- public:
- CDaemonMaintananceSocket();
- ~CDaemonMaintananceSocket();
- virtual BOOL OnCommand(LPCSTR Text);
- // CAsyncSocket event handlers
- virtual void OnConnect( int nErrorCode );
- virtual void _OnConnect( int nErrorCode );
- virtual void OnClose( int nErrorCode );
- virtual void OnSend( int nErrorCode );
- virtual void OnOutOfBandData( int nErrorCode );
- virtual void OnReceive( int nErrorCode );
- protected:
- virtual void Virgin();
- virtual BOOL ProcessTelnetNegotiation(int ch1, int ch2);
- virtual void InsertPendingText();
- virtual BOOL ExpandMacro(LPSTR *To, LPCSTR MacroName, int AvailBytes);
- };
- class DLL_WAR_DAEMON_ CRAFsys : public CUserFsys
- {
- public:
- CRAFsys(LPVOID *pRef = NULL);
- BOOL List(LPCSTR Path, CDaemonMaintananceSocket *pSock);
- BOOL ChMod(CCmdArgs& Args, CDaemonMaintananceSocket *pSock);
- // Low level & overrides
- virtual BOOL SetOnHold();
- virtual void ReleaseHold();
- virtual void CheckForZombie();
- virtual BOOL Create(CDaemonMaintananceSocket *pSock);
- BOOL NextStep();
- BOOL DoList();
- BOOL DoChmod();
- virtual BOOL OnWlist(int nErrorCode);
- virtual BOOL OnCreate(int nErrorCode);
- virtual BOOL OnChmod(int nErrorCode);
- protected:
- CCmdArgs m_UnixArgs;
- int m_SockID;
- DWORD m_AsyncSelectMaskSaved;
- int m_StateSaved;
- CDaemonMaintananceSocket *m_pSock;
- int m_NextStep;
- CString m_Path; // Stored path
- CCmdArgs m_CmdArgStore;
- enum // Steps
- {
- // List
- DOLIST = 1,
- DOCHMOD,
- };
- };
- ///////////////////////////////////////////////////////////////////////////////////////
- // CDaemonStatusSvr
- // Server side status update
- class DLL_WAR_DAEMON_ CDaemonStatusSvr : public CDaemonStatus
- {
- public:
- HANDLE m_EventHandle;
- public:
- CDaemonStatusSvr();
- ~CDaemonStatusSvr();
- LPCSTR FormatStats(CString& cBuf, BOOL IsInteractive = TRUE);
- static LPCSTR GetStats(CString& cBuf);
- static void SendStat(LPVOID pOrigin, CDaemonEvent *pCliEv);
- static void SendStatToAll();
- static void IncUserCnt(BOOL Add);
- static void IncOperatorCnt(BOOL Add);
- static void IncXferCnt(BOOL Add);
- static void SetOnline(BOOL IsOnline);
- protected:
- static void IncCounter(int& Current, int& Total, BOOL Add);
- };
- /////////////////////////////////////////////////////////////////////////////////
- // Daemon startup code
- // Initiates NT service mode and start the main thread
- // that is derivered from CDaemonBase
- class DLL_WAR_DAEMON_ CDaemon : public CObject
- {
- DECLARE_DYNCREATE(CDaemon)
- public:
- CNTService *m_Service; // NT service class
- CWinThread *m_MainThread;
- CWnd *m_pWnd;
- CDaemonNTSOptions *m_NTSoptions;
- public:
- CDaemon();
- ~CDaemon();
- void Process(LPCSTR SvrType, LPCSTR ProgramName, LPCSTR ProgramVersion, LPCSTR ProgramCopyright, CRuntimeClass *MainThreadClass);
- //{{AFX_MSG(CDaemon)
- //}}AFX_MSG
- };
- /////////////////////////////////////////////////////////////////////////////
- // CDaemonBase thread
- // Base class for all daemons
- // Never used in its native form.
- class DLL_WAR_DAEMON_ CDaemonBase : public CWinThread
- {
- DECLARE_DYNCREATE(CDaemonBase)
- protected:
- CDaemonBase(); // protected constructor used by dynamic creation
- // Attributes
- public:
- CWnd *m_pWnd;
- UINT m_TimerID;
- CDaemonLog *m_Log; // Initialized by derived top-level class
- CDaemonServiceSocket *m_RemoteAdminListenSocket;
- CUsr *m_User;
- CDaemonStatusSvr m_ServerStat;
- static CDaemonBase *m_pDaemonBase;
- CRemoteAdminOptions m_RAOptions;
- CAdvancedOptions m_AdvancedOptions; // Overlapped IO and priority
- BOOL m_TrayIsInitialized;
- HICON m_hIcon;
- HICON m_SysTrayIdle;
- HICON m_SysTrayOnline;
- HICON m_SysTrayOffline;
- CAPIHandler *m_pExtModules;
- public:
- virtual void RefreshStats();
- static void Shutdown(BOOL DoSave = TRUE, BOOL Force = FALSE, BOOL Critcal = FALSE);
- static LRESULT GenericProcessMessage(WPARAM WParam, LPARAM LParam);
- virtual void LogMsg(int flag, LPCSTR Format, ...);
- virtual BOOL OnIdle( LONG lCount );
- static CDaemonBase *GetSvr() {return m_pDaemonBase;}
- static CDaemonStatusSvr *GetSvrStat() {return &(GetSvr()->m_ServerStat);}
- BOOL UpdateSystemTray(LPCSTR ToolTip);
- static LONG OnTrayIconMessage(WPARAM WParam, LPARAM LParam);
- virtual BOOL GoOnline(BOOL Online);
- BOOL StartManager();
- // Operations
- public:
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDaemonBase)
- public:
- virtual BOOL InitInstance();
- virtual int ExitInstance();
- virtual BOOL PreTranslateMessage(MSG* pMsg);
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- virtual ~CDaemonBase();
- // Generated message map functions
- //{{AFX_MSG(CDaemonBase)
- // NOTE - the ClassWizard will add and remove member functions here.
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- /////////////////////////////////////////////////////////////////////////////
- // CDaemonLog - Spesific routines for logging to daemons
- class DLL_WAR_DAEMON_ CDaemonLog : public CLog
- {
- public:
- CWnd *m_LogWin;
- CDaemonLog();
- protected:
- virtual void LoggedLine(int LogType, LPCSTR Line);
- };
- ///////////////////////
- // WM_USER messages
- enum // Main thread general messages
- {
- PPT_SHUTDOWN, // Ordinary stop
- PPT_SHUTDOWN_FAST, // System shutdown. max 20 sec.
- PPT_PAUSE, // Go offline
- PPT_CONTINUE, // Go online
- PPT_INVALID
- };
- #endif // __WARDAEMONH