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

📄 warsvrpath.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarSvrPath.h"   // class implemented#ifndef WAR_LOG#   include "WarLog.h"#endif/////////////////////////////// PUBLIC ///////////////////////////////////////WarSvrPath& operator << (WarSvrPath& path, const war_svrpath_t& from){    path.Add(from);    return path;}WarSvrPath& operator << (WarSvrPath& path, const WarPathE from){    path.Add(from);    return path;}//============================= LIFECYCLE ====================================WarSvrPath::WarSvrPath(): mPerms(0),mCmpMode(PCMP_AUTO){}WarSvrPath::WarSvrPath(const WarSvrPath& from): mAlias(from.mAlias), mUrl(from.mUrl), mPerms(from.mPerms),mCmpMode(from.mCmpMode)#if WAR_RFC2577,mIpAccessList(from.mIpAccessList)#endif{}WarSvrPath::WarSvrPath(const path_t& Alias,        const PathCmpTypeE CmpMode)        : mAlias(Alias),         mCmpMode(CmpMode){}WarSvrPath::WarSvrPath(const path_t& Alias,                       const WarUrl& Url,                       const war_uint32_t Perms,                       const PathCmpTypeE CmpMode)                       : mAlias(Alias),                        mUrl(Url),                        mPerms(Perms),                       mCmpMode(CmpMode){    if (!mUrl.IsEmpty() && (mCmpMode == PCMP_AUTO))        mCmpMode = PCMP_CASE_SENSITIVE; //mUrl.GetFilePath().GetCmpMode();}WarSvrPath::WarSvrPath(const war_ccstr_t utf8Alias,                       const war_ccstr_t utf8Url,                       const war_uint32_t Perms,                       const PathCmpTypeE CmpMode)                       : mAlias(utf8Alias),                        mUrl(utf8Url),                        mPerms(Perms),                       mCmpMode(CmpMode){}WarSvrPath::~WarSvrPath(){}// ~WarSvrPath//============================= OPERATORS ====================================WarSvrPath& WarSvrPath::operator = (const WarSvrPath& from){    mAlias = from.mAlias;    mUrl = from.mUrl;    mPerms = from.mPerms;    mCmpMode = from.mCmpMode;#if WAR_RFC2577    mIpAccessList = from.mIpAccessList;#endif    return *this;}bool WarSvrPath::operator == (const path_t& Alias) const {    return mAlias.CmpPath(Alias, mCmpMode, false);}bool WarSvrPath::operator == (const WarSvrPath& from) const {    return operator == (from.mAlias);}bool WarSvrPath::operator < (const WarSvrPath& from) const {    return PathCmp(from) < 0;}bool WarSvrPath::operator < (const path_t& Alias) const {        if (mCmpMode == PCMP_CASE_INSENSITIVE)        return mAlias.Stricmp(Alias.GetPath()) < 0;    return mAlias.Strcmp(Alias.GetPath()) < 0;//        return wcsicmp(mAlias.GetPath(), Alias.GetPath()) < 0;//    return wcscmp(mAlias.GetPath(), Alias.GetPath()) < 0;}int WarSvrPath::PathCmp(const WarSvrPath& other) const{    if (mCmpMode == PCMP_CASE_INSENSITIVE)        return mAlias.Stricmp(other.GetAlias().GetPath());    return mAlias.Strcmp(other.GetAlias().GetPath());//        return wcsicmp(mAlias.GetPath(), other.GetAlias().GetPath());//    return wcscmp(mAlias.GetPath(), other.GetAlias().GetPath());}//============================= OPERATIONS ===================================void WarSvrPath::Add(const path_t& from){    mAlias << from.GetPath();    mUrl << from;}void WarSvrPath::Add(const WarPathE from){    mAlias << (WarPathE)from;    mUrl << from;}//============================= ACCESS     ===================================//============================= INQUIRY    ===================================void WarSvrPath::VerifyAccesss() const throw(WarException){    if (mPerms & DENY_ALL)    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyAccesss()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()                << " Access denied. The DENY_ALL flag is set on this path."                << err                << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyChdir() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_CWD))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyAccesss()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()                << " Access denied. The user does not have CWD rights."                << err                << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyList() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_LIST))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyList()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have LIST rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void  WarSvrPath::VerifyRmd() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DIR_DELETE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyRmd()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DIR_DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void  WarSvrPath::VerifyMkd() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DIR_CREATE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyMkd()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DIR_CREATE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void  WarSvrPath::VerifyDelete() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DELETE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyDelete()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyRnfr() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DELETE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrR::VerifyRnfr()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyRnto() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_WRITE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyRnto()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyRnfrDir() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DIR_DELETE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrR::VerifyRnfrDir()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyRntoDir() const throw(WarException){    VerifyAccesss();    if (!(mPerms & ALLOW_DIR_CREATE))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyRntoDir()");        WarError err(WAR_ERR_ACCESS_DENIED);                if (debug_log)            debug_log << mAlias.GetPath()            << " Access denied. The user does not have DELETE rights."            << err            << war_endl;                WarThrow(err, NULL);    }}void WarSvrPath::VerifyPermissions(war_uint32_t WarFileOpenFlags) constthrow(WarException){    WarLog debug_log(WARLOG_DEBUG, "WarSvrPath::VerifyAccesss()");    WarError err(WAR_ERR_ACCESS_DENIED);    VerifyAccesss();        if (WarFileOpenFlags & F_APPEND)    {        if (!(mPerms & (ALLOW_WRITE|ALLOW_APPEND)))        {               if (debug_log)                debug_log << mAlias.GetPath()                << " Access denied. The user does not have WRITE or APPEND rights."                << err                << war_endl;                        WarThrow(err, NULL);        }    }    if (WarFileOpenFlags & F_READ)    {        if (!(mPerms & ALLOW_READ))        {             if (debug_log)                debug_log << mAlias.GetPath()                << " Access denied. The user does not have READ rights."                << err                << war_endl;                        WarThrow(err, NULL);        }    }    if (WarFileOpenFlags & (F_WRITE | F_CREATE))    {        if (!(mPerms & ALLOW_WRITE))        {            if (debug_log)                debug_log << mAlias.GetPath()                << " Access denied. The user does not have WRITE rights."                << err                << war_endl;                        WarThrow(err, NULL);        }    }}void WarSvrPath::VerifyHost(const struct in_addr& hostAddr) const throw(WarException){#if WAR_RFC2577    if (!mIpAccessList.IsAllowed(hostAddr))    {        WarLog debug_log(WARLOG_DEBUG, "WarSvrParh::VerifyHost();");        if (debug_log)        {            debug_log << "Denying access to path \""                << *this                << "\" because the host "                << hostAddr                << " is disallowed in the paths IP access list."                << war_endl;        }        WarThrow(WarError(WAR_ERR_ACCESS_DENIED), NULL);    }#endif}/////////////////////////////// PROTECTED  ////////////////////////////////////////////////////////////////// PRIVATE    ///////////////////////////////////

⌨️ 快捷键说明

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