📄 warsvrprotocolftpcommands.cpp
字号:
#include "StdAfx.h"#include "WarSvrProtocolFtpCommands.h" // class implemented#ifndef WAR_SVR_PROTOCOL_FTP_H# include "WarSvrProtocolFtp.h"#endif#ifndef WAR_LOG_H# include "WarLog.h"#endif/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarSvrProtocolFtpCommands::WarSvrProtocolFtpCommands(): mpPrevCommand(NULL),mpCurrentCommand(NULL){}// WarSvrProtocolFtpCommandsWarSvrProtocolFtpCommands::~WarSvrProtocolFtpCommands(){}// ~WarSvrProtocolFtpCommands//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarSvrProtocolFtpCommands::InnstallCommand(war_ftpcmd_ptr_t& command, bool doReplace){ if (doReplace) { war_ftpcmd_set_t::iterator P = mCommandSet.find(command); if (P != mCommandSet.end()) mCommandSet.erase(P); } mCommandSet.insert(command);}void WarSvrProtocolFtpCommands::OnCommand(war_ccstr_t cmdName, war_ccstr_t cmdBuffer, size_t bufferLength){ WarLog debug_log(WARLOG_DEBUG, "WarSvrProtocolFtpCommands::OnCommand()"); WarSvrProtocolFtpCmd *pCmd = GetCmdPtr(cmdName); size_t command_len = 0; if (pCmd == NULL) { // Try command alias (XCWD, ...) cmd_alias_t::const_iterator P = mCmdAliases.find( WarCmdAlias(cmdName, "")); if (P != mCmdAliases.end()) { pCmd = GetCmdPtr(P->mCommand.c_str()); command_len = P->mAlias.size(); } } else command_len = pCmd->GetName().size(); mpPrevCommand = mpCurrentCommand; mpCurrentCommand = pCmd; if (pCmd) { if (!pCmd->IsImplemented()) { mpCompanion->mReply << SM_CMD_NOT_IMPLEMENTERD << FTPR_NOT_IMPL_502; } else { switch(mpCompanion->GetConnectionState()) { case PRELOGIN: if (!pCmd->CanBePrelogin()) { if (debug_log) { debug_log << "Command " << cmdName << " dismissed. The user must first log in" << war_endl; } mpCompanion->mReply << SM_BAD_LEVEL << FTPR_NOT_LOGGED_IN_530; return; } break; case GETFILE: case PUTFILE: if (!pCmd->CanBeInTransfer()) { if (debug_log) { debug_log << "Command " << cmdName << " dismissed. The user is transfering a file" << war_endl; } mpCompanion->mReply << SM_CMD_NOT_ALLOWED_DURING_XMIT << FTPR_BAD_SEQ_503; return; } // Fall trough case IDLE: if (!pCmd->CanBeLoggedIn()) { if (debug_log) { debug_log << "Command " << cmdName << " dismissed. The user is logged in" << war_endl; } mpCompanion->mReply << SM_ALREADY_LOGGED_ON << FTPR_BAD_SEQ_503; return; } break; case QUITTING: if (debug_log) { debug_log << "Command " << cmdName << " dismissed. The user is quitting" << war_endl; } mpCompanion->mReply << SM_ERR_BYE << FTPR_BYE_421; return; } if (debug_log) { debug_log << "Executing command " << cmdName << war_endl; } pCmd->OnCommand(cmdBuffer, bufferLength, command_len); } } else { if (debug_log) { debug_log << "Dismissing command " << cmdName << ". Not installed" << war_endl; } mpCompanion->mReply << SM_UNKNOWN_CMD << FTPR_SYNTAX_ERR_500; }}//============================= ACCESS ===================================WarSvrProtocolFtpCmd *WarSvrProtocolFtpCommands::GetCmdPtr(war_ccstr_t cmdName){ war_ftpcmd_ptr_t key_ptr = new WarSvrProtocolFtpCmd(cmdName); war_ftpcmd_set_t::iterator P = mCommandSet.find(key_ptr); if (P == mCommandSet.end()) return NULL; return &(*(*P));}//============================= INQUIRY ===================================void WarSvrProtocolFtpCommands::GetCommandDefs(war_cmddef_set_t& returnVal) const{ // Add the real commands { for(war_ftpcmd_set_t::const_iterator P = mCommandSet.begin() ; P != mCommandSet.end() ; P++) { returnVal.insert(WarCmdDefinition((*P)->GetName(), (*P)->IsImplemented())); } } // Add aliases { for(cmd_alias_t::const_iterator P = mCmdAliases.begin() ; P != mCmdAliases.end() ; P++) { // Aliases are always implemented returnVal.insert(WarCmdDefinition(P->mAlias, true)); } }}#if WAR_RFC2389const std::string WarSvrProtocolFtpCommands::GetFeatures() const{ std::string my_features; for(war_ftpcmd_set_t::const_iterator P = mCommandSet.begin() ; P != mCommandSet.end() ; P++) { std::string my_line = (*P)->GetFeatureString(); if (!my_line.empty()) { my_features += '\n'; my_features += my_line; } } return my_features;}#endif // WAR_RFC2389/////////////////////////////// PROTECTED ////////////////////////////////////////////////////////////////// PRIVATE ///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -