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

📄 warurl.h

📁 ftpserver very good sample
💻 H
字号:
/** */#ifndef WAR_URL_H#define WAR_URL_H/* SYSTEM INCLUDES */#ifndef WAR_LIST_INCLUDED#   define WAR_LIST_INCLUDED#   include <list>#endif/* PROJECT INCLUDES */#ifndef WAR_PATH_H#   include "WarPath.h"#endif#ifndef WAR_URL_TYPE_H#   include "WarUrlType.h"#endif#ifndef WAR_UTF8_H#   include "WarUtf8.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarUrl{public:    typedef std::list<std::string> query_list_t;    typedef WarCollector<char> passwd_t;    enum EncodeModeE    {        ENC_DEFAULT,        ENC_PATH    };    // LIFECYCLE    WarUrl()        : mPassword(passwd_t::SM_ERASE)    {        Reset();    }    WarUrl(const WarUrl& from)        : mPassword(passwd_t::SM_ERASE)    {        Reset();        operator = (from);    }    template <class charT, class slashT>    WarUrl(const WarPath<charT, slashT>& from)        : mPassword(passwd_t::SM_ERASE)    {        Reset();        operator = (from);    }    WarUrl(war_ccstr_t from)        : mPassword(passwd_t::SM_ERASE)    {        Reset();        operator = (from);    }    // OPERATORS    WarUrl& WarUrl::operator = (const WarUrl& from)    {        Reset();        mUrlType = from.mUrlType;        mPort = from.mPort;        mUserName = from.mUserName;        mPassword = from.mPassword;        mHostName = from.mHostName;        mUrlPath = from.mUrlPath;        mUrl = from.mUrl;        mSafeUrl = from.mSafeUrl;        mCommand = from.mCommand;        mFilePath = from.mFilePath;        mQueryList = from.mQueryList;                return *this;    }    WarUrl& WarUrl::operator =         (const WarPath<char, WarSlash>& from)    {        ParseString(from.GetPath());        return *this;    }     WarUrl& WarUrl::operator =         (const WarPath<char, WarSysSlash>& from)    {        ParseString(from.GetPath());        return *this;    }    WarUrl& WarUrl::operator =         (const WarPath<wchar_t, WarSlash>& from)    {        std::string buf = WarUtf8(from.GetPath());        return operator = (buf);    }    WarUrl& WarUrl::operator =         (const WarPath<wchar_t, WarSysSlash>& from)    {        std::string buf = WarUtf8(from.GetPath());        return operator = (buf);    }        WarUrl& WarUrl::operator = (war_ccstr_t from)    {        ParseString((NULL != from) ? from : "");        return *this;    }    WarUrl& WarUrl::operator = (const std::string& from)    {        ParseString(from.c_str());        return *this;    }    // OPERATIONS        /** Create a RFC 1738 compliant URL        If some arguments are UNICODE, they must be        converted to UTF8 prior to calling this function.        NULL arguments will be omitted. In File URL's, the        hostname is teh machine. Use NULL or "localhost" for        the current machine.    */    void Create(const WarUrlType& Type,        war_ccstr_t UserName = NULL,        war_ccstr_t Password = NULL,        war_port_t Port = 0,        war_ccstr_t Host = NULL,        war_ccstr_t UrlPath = NULL,        war_ccstr_t Command = NULL)        throw(WarException);         /** Create a RFC 1738 compliant URL        If some arguments are UNICODE, they must be        converted to UTF8 prior to calling this function.        NULL arguments will be omitted. In File URL's, the        hostname is teh machine. Use NULL or "localhost" for        the current machine.        The type-name must be in the  'http://' form.    */    void Create(war_ccstr_t type_name,        war_ccstr_t UserName = NULL,        war_ccstr_t Password = NULL,        war_port_t Port = 0,        war_ccstr_t Host = NULL,        war_ccstr_t UrlPath = NULL,        war_ccstr_t Command = NULL)        throw(WarException);    /** Parse down a full or relative URL, and use      * the values in the default URL for missing      * parts.       */    void Create(const WarUrl& defaultUrl,         war_ccstr_t strUrl)        throw(WarException);    void Reset();    void Add(const war_svrpath_t& from)    {        war_svrpath_t new_url;        new_url << mUrl << from.GetPath();        operator = (WarUtf8(new_url.GetPath()).GetUtf8());    }    void Add(const WarPathE from)    {        war_svrpath_t new_url;        new_url << mUrl << (WarPathE)from;        operator = (WarUtf8(new_url.GetPath()).GetUtf8());    }    /// Erase the path from the URL    void ErasePath();    /** Sets the hostname.      * @param newHost hostname and optionally a colomn      * and port-number to replace the current host      * and port      */    void SetHost(war_ccstr_t newHost)        throw (WarException);    void Normalize();    template <class charT, class charTT>    static std::basic_string<charT>&     Decode(std::basic_string<charT>& Dst,     const charTT * Src)    throw(WarException)    {        const charTT * p = Src;        size_t len = 1;        while(*p++)            ++len;        p = Src;                charT * buffer = (charT *)alloca(len * sizeof(charT));        charT * pp = buffer;                while(*p)        {            if (*p == '%')            {                ++p;                if (!isxdigit(p[0]) || !isxdigit(p[1]))                    WarThrow(WarError(WAR_ERR_INVALID_URL), NULL);                                unsigned uc = msWarHexToCharMap[*p++] * 0x10;                uc += msWarHexToCharMap[*p++];                                if (sizeof(charT) == sizeof(char))                    *pp++ = (unsigned char)uc;                else                    *pp++ = uc;            }            else                *pp++ = *p++;        }        *pp = 0;        Dst = buffer;        return Dst;    }    // ACCESS    const query_list_t& GetQueries() const    {        return mQueryList;    }    // INQUIRY    const std::string& GetDriverName() const    {        return mUrlType.GetUrlTag();    }    const std::string GetTypeName() const    {        return mUrlType.GetUrlName();    }    const std::string& GetUrl(bool doHidePasswd = true) const    {        return doHidePasswd ? mSafeUrl : mUrl.GetValue();    }    const std::string& GetUserName() const    {        return mUserName;    }    const std::string& GetPassword() const    {        return mPassword.GetValue();    }    const std::string& GetHostName() const    {        return mHostName;    }    const std::string& GetUrlPath() const    {        return mUrlPath;    }    const std::string& GetCommand() const    {        return mCommand;    }    const war_port_t GetPort() const    {        return mPort;    }    const war_syspath_t& GetFilePath() const    {        return mFilePath;    }    bool IsEmpty()    {        return mUrl.GetValue().empty();    }    bool HavePassword() const    {        return mPassword.GetValue().empty() == false;    }    protected:    static const char msWarHexToCharMap[127];private:    void ParseString(war_ccstr_t Scr, bool doRelative = false)         throw(WarException);    void BuildUrl() throw(WarException);    std::string& WarUrl::Encode(std::string& Dst,                             war_ccstr_t Src,                             const EncodeModeE Mode = ENC_DEFAULT);    void ParseHttp(war_ccstr_t str);    void ParseFtp(war_ccstr_t str);    void ParseGeneric(war_ccstr_t str);    void SetFlagsFromValues();        WarUrlType mUrlType;    war_port_t mPort; // In machine byte order    std::string mUserName;    passwd_t mPassword;    std::string mHostName;    std::string mUrlPath;    passwd_t mUrl; // Fully encoded URL    std::string mSafeUrl;    std::string mCommand;    war_syspath_t mFilePath; // System file path    query_list_t mQueryList;    bool mHavePort;    bool mHaveUserName;    bool mHavePassword;    bool mHaveHostName;    bool mHaveUrlPath;    bool mHaveCommand;};/* INLINE METHODS */template <class T>WarCollector<T>& operator << (WarCollector<T>& o,                               const WarUrl& from){    o << from.GetUrl();    return o;}/* EXTERNAL REFERENCES */WarUrl& operator << (WarUrl& path, const war_svrpath_t& from);WarUrl& operator << (WarUrl& path, const WarPathE from);#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_URL_H_ */

⌨️ 快捷键说明

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