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

📄 warsvrprotocolftpmacros.cpp

📁 ftpserver very good sample
💻 CPP
📖 第 1 页 / 共 2 页
字号:
std::string MacroTrafficinbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_TMPTRANS_BYTES_IN)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_CNTR_BYTES_IN));}//////////////////////////// MacroTrafficoutbytes //////////////////////////MacroTrafficoutbytes::MacroTrafficoutbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("trafficoutbytes", "Returns the bytes sent in tmp file transfers and over the control channel during the current session"),mrStat(rStat){}std::string MacroTrafficoutbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_TMPTRANS_BYTES_OUT)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_CNTR_BYTES_OUT));}//////////////////////////// MacroTrafficnumbytes //////////////////////////MacroTrafficnumbytes::MacroTrafficnumbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("trafficnumbytes", "Returns the bytes sent and received in tmp file transfers and over the control channel during the current session"),mrStat(rStat){}std::string MacroTrafficnumbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_TMPTRANS_BYTES_IN)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_CNTR_BYTES_IN)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_TMPTRANS_BYTES_OUT)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_CNTR_BYTES_OUT));}//////////////////////////// MacroRcvtransfers //////////////////////////MacroRcvtransfers::MacroRcvtransfers(const WarSvrProtocolFtpStat& rStat): WarTextMacro("rcvtransfers", "Returns the number of incoming tmp file transfers during the current session"),mrStat(rStat){}std::string MacroRcvtransfers::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FAILED_TMPTRANS_FILES_IN));}//////////////////////////// MacroSndtransfers //////////////////////////MacroSndtransfers::MacroSndtransfers(const WarSvrProtocolFtpStat& rStat): WarTextMacro("sndtransfers", "Returns the number of outgoing tmp file transfers during the current session"),mrStat(rStat){}std::string MacroSndtransfers::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FAILED_TMPTRANS_FILES_OUT));}//////////////////////////// MacroNumtransfers //////////////////////////MacroNumtransfers::MacroNumtransfers(const WarSvrProtocolFtpStat& rStat): WarTextMacro("numtransfers", "Returns the number of tmp file transfers during the current session"),mrStat(rStat){}std::string MacroNumtransfers::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FAILED_TMPTRANS_FILES_OUT)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FAILED_TMPTRANS_FILES_IN));}//////////////////////////// MacroFeatures //////////////////////////#if WAR_RFC2389MacroFeatures::MacroFeatures(const WarSvrProtocolFtp& rSvr): WarTextMacro("features", "Features response to the FEAT command"),mrSvr(rSvr){}std::string MacroFeatures::Expand(war_ccstr_t argument) throw(WarException){    return mrSvr.GetFeatures();}#endif //////////////////////////// MacroLocaltime //////////////////////////MacroLocaltime::MacroLocaltime()        : WarTextMacro("localtime", "Prints the local time.")    {}std::string MacroLocaltime::Expand(war_ccstr_t argument) throw(WarException)    {        WarTime now;        return now.FormatLT();    }//////////////////////////// MacroGmttime //////////////////////////MacroGmttime::MacroGmttime()        : WarTextMacro("gmttime", "Prints the current GMT (Greenwhich Mean Time) time.")    {}std::string MacroGmttime::Expand(war_ccstr_t argument) throw(WarException)    {        WarTime now;        return now.FormatGMT();    }//////////////////////////// MacroCurrentcmd //////////////////////////MacroCurrentcmd::MacroCurrentcmd(const WarSvrProtocolFtpCommands& cmdRef)        : WarTextMacro("currentcmd", "Prints the command currently executing."),        mrCmdRef(cmdRef)    {}std::string MacroCurrentcmd::Expand(war_ccstr_t argument) throw(WarException)    {        return mrCmdRef.GetCurrentCommand().GetName();    }//////////////////////////// MacroCurrentfilelen //////////////////////////MacroCurrentfilelen::MacroCurrentfilelen(const war_flen_t& fileLen)        : WarTextMacro("currentfilelen", "Length of the current file in bytes."),        mrLength(fileLen)    {}std::string MacroCurrentfilelen::Expand(war_ccstr_t argument) throw(WarException)    {        WarCollector<char> buf;        if (mrLength > 0)        {            buf << mrLength;                    if (!buf.GetValue().empty() && argument)                buf << ' ' << argument;        }        return buf.GetValue();    }//////////////////////////// MacroCurrenttransbytes //////////////////////////MacroCurrenttransbytes::MacroCurrenttransbytes(const war_flen_t& fileLen)        : WarTextMacro("currenttransbytes", "Bytes transfered in the last transfer."),        mrLength(fileLen)    {}std::string MacroCurrenttransbytes::Expand(war_ccstr_t argument) throw(WarException)    {        WarCollector<char> buf;        buf << mrLength;                return buf.GetValue();    }//////////////////////////// MacroCurrenttransrate //////////////////////////MacroCurrenttransrate::MacroCurrenttransrate(const war_int64_t& fileCps)        : WarTextMacro("currenttransrate", "Speed (characters/sec) of the last transfer."),        mrCps(fileCps)    {}std::string MacroCurrenttransrate::Expand(war_ccstr_t argument) throw(WarException)    {           if (argument && ('k' == *argument))        {            double speed = mrCps;            char buf[32];            sprintf(buf, "%.02lf", speed / 1024.0);            return buf;        }        else if (argument && ('m' == *argument))        {            double speed = mrCps;            char buf[32];            sprintf(buf, "%.03lf", speed / (1024.0 * 1024.0));            return buf;        }        else if (argument && ('g' == *argument))        {            double speed = mrCps;            char buf[32];            sprintf(buf, "%.03lf", speed / (1024.0 * 1024.0 * 1024.0));            return buf;        }                // Just show bytes/sec        WarCollector<char> buf;        buf << mrCps;        return buf.GetValue();    }//////////////////////////// MacroCurrenttranstime //////////////////////////MacroCurrenttranstime::MacroCurrenttranstime(const WarTime& transTime)        : WarTextMacro("currenttranstime", "Prints the time used by the last transfer."),        mrTime(transTime)    {}std::string MacroCurrenttranstime::Expand(war_ccstr_t argument) throw(WarException)    {        WarCollector<char> buf;        buf << (mrTime.mTime / 1000);                return buf.GetValue();    }//////////////////////////// MacroDirmsg //////////////////////////MacroDirmsg::MacroDirmsg(const WarSvrProtocol& rsvrProtocol)        : WarTextMacro("dirmsg", "Enter directory message (from file)", false),        mrSvrProtocol(rsvrProtocol)    {}std::string MacroDirmsg::Expand(war_ccstr_t argument) throw(WarException)    {        try        {            std::string msg_file_name = mrSvrProtocol.GetOption("ftpd_DIRMSG");            if (msg_file_name.empty())                return "";            war_syspath_t my_path;            my_path << mrSvrProtocol.GetCwd().GetPath()                << WAR_SYSSLASH                << msg_file_name;            war_file_ptr_t my_file_ptr = WarFile::Create(my_path);            my_file_ptr->Open(WarFileEnums::F_READ                | WarFileEnums::F_SHREAD                | WarFileEnums::F_MUSTEXIST);            war_flen_t file_len;            if ((file_len = my_file_ptr->GetLength()) > (1024 * 32))            {                WarLog warn_log(WARLOG_WARNINGS, "MacroDirmsg::Expand()");                warn_log << "The dir change file \""                    << my_path                    << "\" is more than 32 kbytes long. I don't think it's a good idea to "                    << "throw textfiles this size to the client, - so I don't."                    << war_endl;                return "";            }            std::string buffer;            buffer.resize(file_len);            my_file_ptr->Read(&buffer[0], file_len);            my_file_ptr = NULL;            return buffer;        }        catch(WarException)        {            ;        }                return "";    }//////////////////////////// MacroEmail //////////////////////////MacroEmail::MacroEmail(const WarSvrProtocol& rsvrProtocol)        : WarTextMacro("email", "Rrints the email address to the FTP site administrator.", true),        mrSvrProtocol(rsvrProtocol)    {}std::string MacroEmail::Expand(war_ccstr_t argument) throw(WarException)    {        return mrSvrProtocol.GetOption("ftpd_EMAIL");    }//////////////////////////// MacroExplainerr //////////////////////////MacroExplainerr::MacroExplainerr(const WarError& lastError)        : WarTextMacro("explainerr", "Enter directory message (from file)", false),        mrLastError(lastError)    {}std::string MacroExplainerr::Expand(war_ccstr_t argument) throw(WarException)    {        return mrLastError.Explain();    }//////////////////////////// MacroProgramversion //////////////////////////MacroGreeting::MacroGreeting(const WarSvrProtocol& rsvrProtocol)        : WarTextMacro("greeting", "Placeholder for greeting message.", false),        mrSvrProtocol(rsvrProtocol)    {}std::string MacroGreeting::Expand(war_ccstr_t argumentNULL) throw(WarException)    {        return "";    }//////////////////////////// MacroDiskfree //////////////////////////MacroDiskfree::MacroDiskfree(const WarSvrProtocol& rsvrProtocol)        : WarTextMacro("diskfree", "Reports the free space on the current drive",  true),        mrSvrProtocol(rsvrProtocol)    {}std::string MacroDiskfree::Expand(war_ccstr_t argument) throw(WarException)    {        WarCollector<char> buf;        try        {            buf << WarGetFreeSpaceOnPath(mrSvrProtocol.GetCwd().GetUrl());        }        catch(WarException)        {            ;        }                return buf.GetValue();    }//////////////////////////// MacroIdletimelm //////////////////////////MacroIdletimelm::MacroIdletimelm(const int& idleLimit)        : WarTextMacro("idletimelm", "The current idle time limit for the client.",  true),        mrIdleLimit(idleLimit)    {}std::string MacroIdletimelm::Expand(war_ccstr_t argument) throw(WarException)    {        WarCollector<char> buf;        buf << mrIdleLimit;                return buf.GetValue();    }//////////////////////////// MacroSystemname //////////////////////////MacroSystemname::MacroSystemname(const std::string& siteName)    : WarTextMacro("systemname", "The name of the site"),        mSiteName(siteName)    {}std::string MacroSystemname::Expand(war_ccstr_t argument) throw(WarException)    {        return mSiteName;    }//////////////////////////// MacroRfc1700OsName //////////////////////////MacroRfc1700OsName::MacroRfc1700OsName(const WarSvrProtocol& rsvrProtocol): WarTextMacro("rfc1700osname", "The current working directory", true),mrSvrProtocol(rsvrProtocol){}std::string MacroRfc1700OsName::Expand(war_ccstr_t argument) throw(WarException){    return mrSvrProtocol.GetOption("ftpd_ANOSN");}//////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion ////////////////////////////////////////////////////// MacroProgramversion //////////////////////////

⌨️ 快捷键说明

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