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

📄 wardirlist.h

📁 ftpserver very good sample
💻 H
字号:
/** Primitive to list a single directory for a     server. See WarSvrDirListing.*/#ifndef WAR_DIRLIST_H#define WAR_DIRLIST_H/* SYSTEM INCLUDES */#ifndef WAR_SET_INCLUDED#   define WAR_SET_INCLUDED#   include <set>#endif#ifndef WAR_LIST_INCLUDED#   define WAR_LIST_INCLUDED#   include <list>#endif#ifndef WAR_MATH_H_INCLUDED#   define WAR_MATH_H_INCLUDED#   include <math.h>#endif/* PROJECT INCLUDES */#ifndef WAR_SVR_ENUMS_H#   include "WarSvrEnums.h"#endif#ifndef WAR_FILE_ENUMS_H#   include "WarFileEnums.h"#endif#ifndef WAR_SIMPLE_PTR_WRAPPER_H#   include "WarSimplePtrWrapper.h"#endif#ifndef WAR_DIRLIST_NODE_H#   include "WarDirListNode.h"#endif#ifndef WAR_UTF8_H#   include "WarUtf8.h"#endif#ifndef WAR_FILE_DRIVER#   include "WarFileDriver.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */class WarSvrProtocol;#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarDirList :    public WarSvrEnums,    public WarFileEnums{public:    typedef WarPtrWrapper<WarFileDriver> driver_ptr_t;    typedef std::list<war_svrpath_t> patterns_t;        /** Node list type.        Implemented as:        {\tttypedef std::set<WarSimplePtrWrapper<WarDirListNode> > nodelist_t;}    */    typedef std::set<WarSimplePtrWrapper<WarDirListNode> > nodelist_t;    // LIFECYCLE        /** Contructor */    WarDirList(const war_uint32_t flags = 0);    // OPERATORS    // OPERATIONS        /** Helper function for the low-level file-system        driver to add files while scanning the dir.    */    template <class dirdataT>    void AddFile(war_cwstr_t fileName,        dirdataT* dirData)    {        if (!fileName || !*fileName)            return;                if (*fileName == '.')        {            // Handle directories            if ((fileName[1] == 0)                || (fileName[1] == '.' && fileName[2] == 0))            {                if (mFlags & DIRF_HIDE_DOT_DOTDOT)                    return;            }            // Handle files            else if (mFlags & DIRF_HIDE_DOT_FILES)                return;        }                // Convert the buffer to UTF8        war_cstr_t pname_buffer = NULL;        war_cwstr_t p = fileName;        size_t name_len = 0;                while(*p)        {            // Only do UTF8 conversion when requiered!            if ((unsigned int)*p >= 0x80)            {                WarUtf8 utf_buffer(fileName);                name_len = utf_buffer.GetUtf8().size();                pname_buffer = (war_cstr_t)mMem.Malloc(name_len + 1);                memcpy(pname_buffer,                     utf_buffer.GetUtf8().c_str(),                     name_len * sizeof(wchar_t));                goto done_alloced_buffer;            }            ++p;        }                name_len = (p - fileName);        pname_buffer = (war_cstr_t)mMem.Malloc(name_len + 1);                {            char *pp = pname_buffer;             const wchar_t *ppp = fileName;            while(*ppp)                *pp++ = (char)*ppp++;        }    done_alloced_buffer:                pname_buffer[name_len] = 0;        WarDirListNode *pnew_node =             new (&mMem) WarDirListNode(pname_buffer, name_len);        #ifdef WIN32        // Remove .lnk and mark the type as link.        if ((pnew_node->mNameLen > 4)             && !stricmp(&pnew_node->mName[pnew_node->mNameLen - 4], ".lnk"))        {            pnew_node->mName[pnew_node->mNameLen - 4] = 0;            pnew_node->mNameLen -= 4;            pnew_node->mType = WarDirListNode::FT_LINK;        }#endif                if (mDoNeedStat && dirData)        {            *pnew_node = *dirData;                        mTotalBytes += pnew_node->mSize;            size_t block_len = (size_t)log10(abs(pnew_node->mSize / 1024));            if ((block_len <= 7)                && (mBlockSizeLen < block_len))            {                mBlockSizeLen = block_len;            }        }                if (pnew_node->mNameLen > mLongestName)            mLongestName = pnew_node->mNameLen;                 mList.insert(pnew_node);    }         /** Performs the directory listing.         @Param Svr The physical paths and security             information to take into consideration are             extracted from the server handle.         @Param VirtPath the virtual path to the             directory        @Param bNeedStat If true, file dates,             size etc. is fetched.            This slows down processing on Unix             systems significantly, as each file             needs to be stat'ed manually.    *//*    void Create(const WarSvrProtocol& Svr,         const war_ccstr_t& VirtPath,         bool bNeedStat = false);*/    /** Perform a directory listing based on the         paths in VirtPaths.         VirtPaths is normally expanded from a         command/line, and may contain dirs        and/or files. If it contain files, the         files are listed, and extracted        from VirtPaths. Else, the first dir is         listed and extracted from VirtPaths.    *//*    void Create(const WarSvrProtocol& Svr,          seq_file_list_t& VirtPaths,         bool bNeedStat = false,         bool bTestForFiles = false);*/    /** Perform a directory-listing        This mode takes a native pathname and         scans the directory.    */    void Create(const WarUrl& listUrl, bool bNeedStat);    // ACCESS        /** Return the node-list */    inline const nodelist_t& GetList() const    {        return mList;    }    // INQUIRY    /** Return the number og 1024 KB 'blocks'         in the directory. Used by the unix LS command.    */    inline size_t GetBlocks() const    {        return mTotalBytes / 1024;    }    /** Return the longest filename in bytes    */    inline size_t GetLongestNameLen() const    {        return mLongestName;    }    /** Return the 'block lenght' */    inline const size_t GetBlockSizeLen() const    {        return mBlockSizeLen;    }    /** Get UTF8 path */    const WarUrl& GetUrl() const    {        return mUrl;    }    /** Checks mPatternList and mExcludeList       *      * @param doIgnorePatterns Used by file-drivers to      *     indicate that they have already filtred      *     based on patterns      */    bool IsFileExcluded(war_svrpath_ccstr_t fileName,        bool doIgnorePatterns = false) const;    /// Node list    nodelist_t mList;    war_uint32_t mFlags;    patterns_t mPatternList; // Names to include. If empty, all names are matched    patterns_t mExcludeList; // Names to exclude    bool DoesNeedStat() const    {        return mDoNeedStat;    }protected:    void ScanDir(const WarUrl& listUrl);    //void ScanPaths(const WarUserHandle& User,  WarSvrFile& Dir);    //void SetRelativePath(const war_syspath_t& CurrentDir);    /// Memory buffer for pathnames    WarMemoryBuffer<char> mMem;    bool mIsCreated;    bool mDoNeedStat;    size_t mLongestName;    size_t mBlockSizeLen;    war_uint32_t mCntHidden;    war_flen_t mTotalBytes;    WarUrl mUrl;private:};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_DIRLIST_H_ */

⌨️ 快捷键说明

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