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

📄 warsvrprotocolftpmacros.cpp

📁 ftpserver very good sample
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "StdAfx.h"#include "WarSvrProtocolFtpMacros.h"   // class implemented#ifndef WAR_OS_H#   include "WarOs.h"#endif#ifndef WAR_ESCAPE_STR_H#   include "WarEscapeStr.h"#endif#ifndef WAR_FSYS_H#   include "WarFsys.h"#endif//////////////////////////// MacroProgramname //////////////////////////MacroProgramname::MacroProgramname(): WarTextMacro("programname", "Name of the FTP daemon software"){}std::string MacroProgramname::Expand(war_ccstr_t argument) throw(WarException){    return WAR_LIBRARY_NAME;}//////////////////////////// MacroProgramversion //////////////////////////MacroProgramversion::MacroProgramversion(): WarTextMacro("programversion", ""){}std::string MacroProgramversion::Expand(war_ccstr_t argument) throw(WarException){    return WAR_LIBRARY_VERSION;}//////////////////////////// MacroPrgcopyright //////////////////////////MacroPrgcopyright::MacroPrgcopyright(): WarTextMacro("prgcopyright", "Copyright notification of the FTP daemon software"){}std::string MacroPrgcopyright::Expand(war_ccstr_t argument) throw(WarException){    WarCollector<char> msg;    msg << WAR_LIBRARY_COPYRIGHT        << WAR_FTPD_DISCLAIMER        << war_endl;        return msg.GetValue();}//////////////////////////// MacroOrigin //////////////////////////MacroOrigin::MacroOrigin(const WarNetAddress& address): WarTextMacro("origin", "IP address of the current user"),mrAddress(address){}std::string MacroOrigin::Expand(war_ccstr_t argument) throw(WarException){    return mrAddress.Explain();}//////////////////////////// MacroOsname //////////////////////////MacroOsname::MacroOsname(): WarTextMacro("osname", "The name of the operating system (Linux, Unix, Win95, NT etc...)", true){}std::string MacroOsname::Expand(war_ccstr_t argument) throw(WarException){    return WarOs::GetOs().GetOsName();}//////////////////////////// MacroPwd //////////////////////////MacroPwd::MacroPwd(const WarSvrProtocol& rsvrProtocol): WarTextMacro("pwd", "The current working directory", true),mrSvrProtocol(rsvrProtocol){}std::string MacroPwd::Expand(war_ccstr_t argument) throw(WarException){    WarUtf8 my_cwd = (argument && *argument)         ? WarEscapeStr<wchar_t>(mrSvrProtocol.GetCwd().GetAlias().GetPath(), *argument).c_str()        : mrSvrProtocol.GetCwd().GetAlias().GetPath();        return my_cwd.GetUtf8();}//////////////////////////// MacroCurrentfilename //////////////////////////MacroCurrentfilename::MacroCurrentfilename(const WarSvrPath& nameBuf): WarTextMacro("currentfilename", "The file name used by the current command"),mrPath(nameBuf){}std::string MacroCurrentfilename::Expand(war_ccstr_t argument) throw(WarException){    WarUtf8 my_filename = (argument && *argument)         ? WarEscapeStr<wchar_t>(mrPath.GetAlias().GetFilename().GetPath(), *argument).c_str()        : mrPath.GetAlias().GetFilename().GetPath();        return my_filename;}//////////////////////////// MacroCurrentpath //////////////////////////MacroCurrentpath::MacroCurrentpath(const WarSvrPath& nameBuf): WarTextMacro("currentpath", "The Path used by the current command"),mrPath(nameBuf){}std::string MacroCurrentpath::Expand(war_ccstr_t argument) throw(WarException){    WarUtf8 my_path = (argument && *argument)         ? WarEscapeStr<wchar_t>(mrPath.GetAlias().GetPath(), *argument).c_str()        : mrPath.GetAlias().GetPath();            return my_path;}//////////////////////////// MacroRest //////////////////////////MacroRest::MacroRest(const WarSvrProtocolFtpMode& ftpMode): WarTextMacro("rest", "Show the current restart offset"),mrMode(ftpMode){}std::string MacroRest::Expand(war_ccstr_t argument) throw(WarException){    WarCollector<char> buf;    buf << mrMode.mRestartPos;    return buf.GetValue();}//////////////////////////// MacroHelpcmds //////////////////////////MacroHelpcmds::MacroHelpcmds(const WarSvrProtocolFtpCommands& rCmds): WarTextMacro("helpcmds", "Show the commands listed by the HELP function"),mrCmds(rCmds){}std::string MacroHelpcmds::Expand(war_ccstr_t argument) throw(WarException){    int row = 1;    std::string return_val;        war_cmddef_set_t my_cmds;    mrCmds.GetCommandDefs(my_cmds);        for(war_cmddef_set_t::const_iterator P         = my_cmds.begin()        ; P !=  my_cmds.end()        ; P++)    {        static const char spaces[] = "        ";        std::string cmd_name = P->GetName();        if (!P->IsImplemented())            cmd_name += "*";                return_val += cmd_name;                if (!(row++ % 8) && (row != 2))        {            return_val += "\n";        }        else        {            return_val += spaces + (cmd_name.length() % sizeof(spaces));        }    }        if ((++row % 8))        return_val += "\n";        return return_val;}//////////////////////////// MacroCurrenttype //////////////////////////MacroCurrenttype::MacroCurrenttype(const WarSvrProtocolFtpMode& ftpMode): WarTextMacro("currenttype", "Show the current file type"),mrMode(ftpMode){}std::string MacroCurrenttype::Expand(war_ccstr_t argument) throw(WarException){    return mrMode.GetTypeName();}//////////////////////////// MacroCurrentform //////////////////////////MacroCurrentform::MacroCurrentform(const WarSvrProtocolFtpMode& ftpMode): WarTextMacro("currentform", "Show the current file form"),mrMode(ftpMode){}std::string MacroCurrentform::Expand(war_ccstr_t argument) throw(WarException){    return mrMode.GetFormName();}//////////////////////////// MacroCurrentstructure //////////////////////////MacroCurrentstructure::MacroCurrentstructure(const WarSvrProtocolFtpMode& ftpMode): WarTextMacro("currentstructure", "Show the current structure type"),mrMode(ftpMode){}std::string MacroCurrentstructure::Expand(war_ccstr_t argument) throw(WarException){    return mrMode.GetStructureName();}//////////////////////////// MacroCurrentmode //////////////////////////MacroCurrentmode::MacroCurrentmode(const WarSvrProtocolFtpMode& ftpMode): WarTextMacro("currentmode", "Show the current file mode"),mrMode(ftpMode){}std::string MacroCurrentmode::Expand(war_ccstr_t argument) throw(WarException){    return mrMode.GetModeName();}//////////////////////////// MacroHostdomainname //////////////////////////MacroHostdomainname::MacroHostdomainname(const WarNetAddress& rNet): WarTextMacro("hostdomainname", "Show the domain name for the server"),mrNet(rNet){}std::string MacroHostdomainname::Expand(war_ccstr_t argument) throw(WarException){    return mrNet.GetDomainname();}//////////////////////////// MacroRemotedomainname //////////////////////////MacroRemotedomainname::MacroRemotedomainname(const WarNetAddress& rNet): WarTextMacro("remotedomainname", "Show the domain name for the client"),mrNet(rNet){}std::string MacroRemotedomainname::Expand(war_ccstr_t argument) throw(WarException){    return mrNet.GetDomainname();}//////////////////////////// MacroHostaddress //////////////////////////MacroHostaddress::MacroHostaddress(const WarNetAddress& rNet): WarTextMacro("hostaddress", "Show the Ip address for the server"),mrNet(rNet){}std::string MacroHostaddress::Expand(war_ccstr_t argument) throw(WarException){    return mrNet.GetDottedStr();}//////////////////////////// MacroRemoteaddress //////////////////////////MacroRemoteaddress::MacroRemoteaddress(const WarNetAddress& rNet): WarTextMacro("remoteaddress", "Show the IP address for the client"),mrNet(rNet){}std::string MacroRemoteaddress::Expand(war_ccstr_t argument) throw(WarException){    return mrNet.GetDottedStr();}//////////////////////////// MacroUser //////////////////////////MacroUser::MacroUser(const WarSvrProtocol& rSvr): WarTextMacro("user", "Returns the login-name for the current user"),mrSvr(rSvr){}std::string MacroUser::Expand(war_ccstr_t argument) throw(WarException){    return mrSvr.GetLoginName();}//////////////////////////// MacroDataconn //////////////////////////MacroDataconn::MacroDataconn(const WarSvrProtocolFtp& rSvr): WarTextMacro("dataconn", "returns argument 2 if a dataconnection is active. Else, argument 1 is returned."),mrSvr(rSvr){}std::string MacroDataconn::Expand(war_ccstr_t argument) throw(WarException){    // Deparse the argument    war_ccstr_t p = argument;    std::string yes, no;        if (!argument)        WarThrow(WarError(WAR_ERR_INVALID_ARGUMENT), NULL);        while(*p)    {        if (*p == ',')        {            ++p;            break;        }        no += *p++;    }        while(*p)    {        yes += *p++;    }        if (!mrSvr.mDataConnectionPtr.IsEmpty()        && mrSvr.mDataConnectionPtr->IsOpen())    {        return yes;    }    else    {        return no;    }}//////////////////////////// MacroRcvbytes //////////////////////////MacroRcvbytes::MacroRcvbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("rcvbytes", "Returns the bytes reveived in normal file transfers during the current session"),mrStat(rStat){}std::string MacroRcvbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_BYTES_IN));}//////////////////////////// MacroSndbytes //////////////////////////MacroSndbytes::MacroSndbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("sndbytes", "Returns the bytes sent in normal file transfers during the current session"),mrStat(rStat){}std::string MacroSndbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_BYTES_OUT));}//////////////////////////// MacroRcvfiles //////////////////////////MacroRcvfiles::MacroRcvfiles(const WarSvrProtocolFtpStat& rStat): WarTextMacro("rcvfiles", "Returns the number of incoming file transfers during the current session"),mrStat(rStat){}std::string MacroRcvfiles::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_FILES_IN));}//////////////////////////// MacroSndfiles //////////////////////////MacroSndfiles::MacroSndfiles(const WarSvrProtocolFtpStat& rStat): WarTextMacro("sndfiles", "Returns the number of outgoing file transfers during the current session"),mrStat(rStat){}std::string MacroSndfiles::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_FILES_OUT));}//////////////////////////// MacroNumbytes //////////////////////////MacroNumbytes::MacroNumbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("numbytes", "Returns the bytes sent and received in normal file transfers during the current session"),mrStat(rStat){}std::string MacroNumbytes::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_BYTES_IN)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_BYTES_OUT));}//////////////////////////// MacroNumfiles //////////////////////////MacroNumfiles::MacroNumfiles(const WarSvrProtocolFtpStat& rStat): WarTextMacro("numfiles", "Returns the files sent and received in normal file transfers during the current session"),mrStat(rStat){}std::string MacroNumfiles::Expand(war_ccstr_t argument) throw(WarException){    std::string num_buf;    return WarItoa(num_buf, mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_FILES_IN)        + mrStat.GetValue(        WarSvrProtocolFtpStat::ST_FILETRANS_FILES_OUT));}//////////////////////////// MacroTrafficinbytes //////////////////////////MacroTrafficinbytes::MacroTrafficinbytes(const WarSvrProtocolFtpStat& rStat): WarTextMacro("trafficinbytes", "Returns the bytes received in tmp file transfers and over the control channel during the current session"),mrStat(rStat){}

⌨️ 快捷键说明

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