📄 warsvrprotocol.h
字号:
/** Base class for Internet servers. This class is used as the foundation of the clinet-request protocol (like the FTP control channel) and typically has one instance for each current connection.*/#ifndef WAR_SVR_PROTOCOL_H#define WAR_SVR_PROTOCOL_H/* SYSTEM INCLUDES *//* PROJECT INCLUDES */#ifndef WAR__TRANSFER_SOCKET_H# include "WarTransferSocket.h"#endif#ifndef WAR_USER_ENGINE_H# include "WarUserEngine.h"#endif#ifndef WAR_USER_AUTH_DATA_H# include "WarUserAuthData.h"#endif#ifndef WAR_SVR_ENUMS_H# include "WarSvrEnums.h"#endif#ifndef WAR_SVR_PROPERTIES_H# include "WarSvrProperties.h"#endif#ifndef WAR_SVR_FILE_H# include "WarSvrFile.h"#endif#ifndef WAR_PLUGIN_SUPPORT_H# include "WarPluginSupport.h"#endif#ifndef WAR_USER_ENGINE_H# include "WarUserEngine.h"#endif#ifndef WAR_CLIENT_SESSION_H# include "WarClientSession.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */class WarSvrEngine;class WarUserEngine;class WarSvrDefinition;class WarSvrPath;#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarSvrProtocol : public WarTransferSocket,public WarSvrEnums,public WarPluginSupport<WarSvrProtocol> // Extendable with plugins {public: typedef std::set<WarSvrPath> ownfiles_t; enum ProtocolTypeE { PROT_FTP, PROT_HTTP, PROT_INVALID }; typedef struct ProtCmdPrp {public: ProtCmdPrp(WarSvrProtocol *pprot) : mpProt(pprot) { mpProt->PreProtocolCommand(); } ~ProtCmdPrp() { mpProt->PostProtocolCommand(); }private: WarSvrProtocol *mpProt; } prot_cmd_prp_t; enum PluginEventsE { PLUGIN_ON_CLIENT_CONNECT, PLUGIN_ON_LOGIN_PRE_AUTH, PLUGIN_ON_LOGIN_POST_AUTH, PLUGIN_ON_LOGOUT, PLUGIN_EVENT_INVALID }; enum ConstantsE { IO_BUFFER_LEN = 1024 * 4 // 4 KB buffer limit }; typedef WarPtrWrapper<WarTransferBuffer> buf_ptr_t; //typedef std::list<buf_ptr_t> buf_list_t; // LIFECYCLE /** * Default constructor. */ WarSvrProtocol( war_socket_io_ptr_t& companionPtr, WarSvrDefinition& svrDefinition); /** * Destructor. */ ~WarSvrProtocol(void); // OPERATORS // OPERATIONS // Kill the current connection now! virtual void Abort(const WarError& reason) throw(WarException) = 0; /** sets the current working directory. * "/" is always root. * NULL will change to the home directory * if it exist, and default to root. * * @exception WarException on error */ void SetCwd(war_ccstr_t newCwd = NULL) throw(WarException); /** Send data to the client. Send() does not flush, * unless the send buffer is full. * * @see FlushOut() */ virtual void Send(const std::string& from); virtual void Send(const war_ccstr_t from, size_t length); /** Flushes the output buffer */ virtual void FlushOut(); /// Set the state of the connection void SetConnectionState(ConnectionStatesE newState); WarLoginResultE Login(war_ccstr_t virtualHost, war_ccstr_t userName, war_ccstr_t userPasswd) throw(WarException); void Logout(); void Login(war_auth_ptr_t& authPtr, war_authdata_ptr_t& authDataPtr); /** Tries to open the specified file */ war_svrfile_ptr_t OpenFile(const WarSvrPath& filePath, const war_uint32_t openFlags) throw(WarException); void ResolvPath(war_ccstr_t filePath, WarSvrPath& resolvedPath) const throw(WarException); void ResolvPath(war_ccstr_t filePath, bool useSecondPath = false) throw(WarException); void ResolvPath(const war_svrpath_t& fromPath, WarSvrPath& resolvedPath) const throw(WarException); /** Add a file to the list of files owned by this * session */ void AddToSessionFiles(const WarSvrPath& filePath); /** Delete from list over owned files. Does not * toutch the diskfile */ void DeleteFromSessionFiles(const WarSvrPath& filePath); /** Verify the remote host with the current IP access-list. * @exception WarException(WAR_ERR_IP_IS_DENIED) if the * access-check fails. */ virtual void VerifyRemoteIpAddress() const throw(WarException); // ACCESS /// WarSvrEngine& GetEngine() const throw(WarException); /// WarUserEngine& GetAuth() throw(WarException); const WarUserEngine& GetAuth() const throw(WarException); /// ConnectionStatesE GetConnectionState(); /// bool IsTransfering() { ConnectionStatesE my_state = GetConnectionState(); return ((GETFILE == my_state) || (PUTFILE == my_state)); } /** Returns the auth-handle used by the current * authenticated (logged in) session. */ war_auth_ptr_t GetLoginAuth() { return mAuthPtr; } const WarSvrProperties& GetProperties() const { return mProperties; } /** Returns the session-spesiffic auth data container * for current (logged in) session. * This has nothing to do with the War Session Manager! */ war_authdata_ptr_t GetLoginAuthData() { return mAuthDataPtr; } const std::string GetOption(war_ccstr_t optName) const { return mProperties.mOptions.GetOption( std::string(optName)); } int GetIntOption(war_ccstr_t optName) const { return mProperties.mOptions.GetIntOption( std::string(optName)); } bool GetBoolOption(war_ccstr_t optName) const { return GetIntOption(optName) != 0; } const WarNetAddress& GetLocalAddress() const { return mLocalAddress; } const WarNetAddress& GetRemoteAddress() const { return mRemoteAddress; } const WarSvrDefinition& GetSvrDefinition() const { return mrSvrDefinition; } // INQUIRY const WarSvrPath& GetCwd() const { if (mCwd.GetAlias().IsEmpty()) WarThrow(WarError(WAR_ERR_INTERNAL_DATA_NOT_INITIALIZED), NULL); return mCwd; } const std::string& GetLoginName() const { return mLoginName; } const std::string& GetUserFancyName() const { return mUserFancyName; } const std::string& GetLoginVirtualHost() const { return mLoginVirtualHost; } /// Return the name of the site, like Jgaas's Fan club ... const std::string GetSiteName() const; /// Return the unique, internal name, like Default Site const std::string GetNativeSiteName() const; bool IsFileOwnedBySession(const WarSvrPath& filePath) const; /** Checks IP access list */ bool IsAllowed(const struct in_addr& hostAddr) const; ProtocolTypeE GetProtocolType() const { return mProtocolType; } // The path of the current file operation WarSvrPath mCurrentFile; WarSvrPath mCurrentFile2; war_client_session_ptr_t mSessionPtr; protected: friend struct ProtCmdPrp; friend class WarSvrEngine; friend class WarSvrDefinition; /// Entry point when a client have connected to the server virtual void OnClientConnect(); virtual void OnSent(const WarError& status, war_transfer_buffer_ptr_t& buffer); virtual void OnReceived(const WarError& status, war_transfer_buffer_ptr_t& buffer); // Override to add special handling // NB: Add filePath to path. path may // already contain the path to the current // directory. void DoResolvPath(war_ccstr_t filePath, war_svrpath_t& path) const throw(WarException); /** Prepare for the processing of a command on the protocol * level (like FTP XCWD or HTTP GET). * * MUST be called before the command is processed * at the protocol level! */ void PreProtocolCommand() throw(WarException); /** Clean up the resources allocated by PreProtocolCommand() * * MUST be called when a command is processed! */ void PostProtocolCommand() throw(WarException); WarSvrProperties mProperties; WarNetAddress mLocalAddress; WarNetAddress mRemoteAddress; buf_ptr_t mIoOutBufferPtr; // Current out buffer buf_ptr_t mIoInBufferPtr; // Current in buffer WarSvrPath mCwd; // Current working directory std::string mUserFancyName; // The username we usually display std::string mLoginName; // The login name std::string mLoginVirtualHost; // The login virtual host std::string mMimeType; // Current mime-type. ProtocolTypeE mProtocolType;private: void IoQueueOut(war_ccstr_t buffer, size_t length); void IoAllocateOutputBuffer(); void IoFlushOut(); ConnectionStatesE mConnectionState; war_auth_ptr_t mAuthPtr; war_authdata_ptr_t mAuthDataPtr; WarSvrDefinition& mrSvrDefinition; bool mIsLoggedIn; ownfiles_t mOwnFiles;};/* INLINE METHODS *//* EXTERNAL REFERENCES *//* PLUGIN INTERFACE */class WarSvrProtocol_OnClientConnect : public WarPlugin{public: static WarSvrProtocol::PluginEventsE GetId() { return WarSvrProtocol::PLUGIN_ON_CLIENT_CONNECT; } virtual void OnProcess(WarSvrProtocol *pSvrProtocol) throw (WarException) = 0;};class WarSvrProtocol_OnLoginPreAuth : public WarPlugin{public: static WarSvrProtocol::PluginEventsE GetId() { return WarSvrProtocol::PLUGIN_ON_LOGIN_PRE_AUTH; } // WAR_ERR_PLUGIN_DONE is not supported here virtual void OnProcess(WarSvrProtocol *pSvrProtocol, war_ccstr_t virtualHost, // Supplied by client war_ccstr_t userName, // Supplied by client war_ccstr_t userPasswd, // Supplied by client std::string& useUserName, // To be used during authentication WarCollector<char>& useUserPasswd, // To be used during authentication std::string& useVirtualHost) // To be used during authentication throw (WarException) = 0;};class WarSvrProtocol_OnLoginPostAuth : public WarPlugin{public: static WarSvrProtocol::PluginEventsE GetId() { return WarSvrProtocol::PLUGIN_ON_LOGIN_POST_AUTH; } // WAR_ERR_PLUGIN_DONE is not supported here // Set the value in loginResult if login must // be denied! virtual void OnProcess(WarSvrProtocol *pSvrProtocol, war_ccstr_t virtualHost, // Supplied by client war_ccstr_t userName, // Supplied by client war_ccstr_t userPasswd, // Supplied by client std::string& useUserName, // Used during authentication WarCollector<char>& useUserPasswd, // Used during authentication std::string& useVirtualHost, // Used during authentication WarSvrEnums::WarLoginResultE& loginResult, // Result from authentication war_auth_ptr_t& auth_module_ptr, // Result from authentication war_authdata_ptr_t& session_data_ptr) // Result from authentication throw (WarException) = 0;};class WarSvrProtocol_OnLogout : public WarPlugin{public: static WarSvrProtocol::PluginEventsE GetId() { return WarSvrProtocol::PLUGIN_ON_LOGOUT; } // WAR_ERR_PLUGIN_DONE is not supported here // Set the value in loginResult if login must // be denied! virtual void OnProcess(WarSvrProtocol *pSvrProtocol) throw (WarException) = 0;};typedef WarPtrWrapper<WarSvrProtocol> war_svr_protocol_ptr_t;#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* WAR_SVR_PROTOCOL_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -