⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warsvrprotocolftpcmd.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarSvrProtocolFtpCmd.h"   // class implemented#ifndef WAR_LOG_H#   include "WarLog.h"#endif#ifndef WAR_SVR_PROTOCOL_FTP_H#   include "WarSvrProtocolFtp.h"#endif/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarSvrProtocolFtpCmd::WarSvrProtocolFtpCmd(war_ccstr_t commandName,         war_ccstr_t commandExplanation, /* Human help*/        war_ccstr_t commandSyntax, /* Formal */        war_ccstr_t commandReference, /* RFC */        WarSvrProtocolFtp& serverCompanion)        : mpReply(&serverCompanion.mReply),        mName(commandName),        mExplanation(commandExplanation),        mSyntax(commandSyntax),        mReference(commandReference),        mpCompanion(&serverCompanion),        mLastCommandResult(CMD_VOID){}// WarSvrProtocolFtpCmdWarSvrProtocolFtpCmd::WarSvrProtocolFtpCmd(war_ccstr_t commandName)        :   mpReply(NULL),        mName(commandName),        mpCompanion(NULL),        mLastCommandResult(CMD_VOID){}WarSvrProtocolFtpCmd::~WarSvrProtocolFtpCmd(){}// ~WarSvrProtocolFtpCmd//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarSvrProtocolFtpCmd::OnCommand(war_ccstr_t commandBuffer,                                      size_t bufferLength,                                     size_t commandLenght)                                     throw(WarException){    mStatus.Reset();    try    {        mLastCommandResult = CMD_VOID;        PreProcessCommand(commandBuffer, bufferLength, commandLenght);        mLastCommandResult = ExecuteCommand();    }    catch(WarException& ex)    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrProtocolFtpCmd::OnCommand()");        if ((ex.LocalError() != WAR_ERR_OK) && debug_log)        {            debug_log << "Caught exception. "                << ex.Explain()                << war_endl;        }                mStatus = ex;        HandleError(mStatus);    }    // The user is now notified about the result of the command!!    try    {        OnResetTimer();        PostProcessCommand();    }    catch(WarException& ex)    {                WarLog err_log(WARLOG_ERROR, "WarSvrProtocolFtpCmd::OnCommand()");        err_log << "Caught exception from PostProcessCommand()"            << ex.Explain()            << war_endl;        throw ex;    }}//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ///////////////////////////////////void WarSvrProtocolFtpCmd::PreProcessCommand(war_ccstr_t commandBuffer,                                              size_t bufferLength,                                             size_t commandLenght){    if (!commandBuffer || !*commandBuffer)        WarThrow(WarError(WAR_ERR_INVALID_ARGUMENT), NULL);    mCommandString = commandBuffer;    if (mCommandString.size() != bufferLength)        WarThrow(WarError(WAR_ERR_INVALID_ARGUMENT), NULL);    mpCommandArgument = mCommandString.c_str() + commandLenght;    if (*mpCommandArgument == ' ')        ++mpCommandArgument;    if (!*mpCommandArgument)        mpCommandArgument = NULL;    if (IsArgumentRequiered() && !mpCommandArgument)        WarThrow(WarError(WAR_FTPDERR_MISSING_ARGUMENT), NULL);    if (mpCommandArgument && !IsArgumentAllowed())        WarThrow(WarError(WAR_FTPDERR_ARGUMENT_NOT_ALLOWED), NULL);}void WarSvrProtocolFtpCmd::HandleError(const WarError& error){    if (GetServer().IsOpen())    {        switch(error.LocalError())        {        case WAR_FTPDERR_MISSING_ARGUMENT:            *mpReply << SM_MISSING_PARAMETER_IN_CMD << FTPR_ARG_SYNTAX_501;            break;        case WAR_FTPDERR_ARGUMENT_NOT_ALLOWED:            *mpReply << SM_UNKNOWN_PARAMETER << FTPR_ARG_SYNTAX_501;            break;        default:            *mpReply << SM_GENERIC_FAIL                 << " "                 << error.Explain()                << FTPR_ABORT_451;        }    }}void WarSvrProtocolFtpCmd::OnResetTimer(){    mpCompanion->ResetIdleTimer();}/////////////////////////////// PRIVATE    ////////////////////////////////////////////////////////////////// COMMANDS    ///////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -