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

📄 mpcommon.h

📁 一个SIP协议栈
💻 H
📖 第 1 页 / 共 2 页
字号:
    extern const char hdrnUnsupported[];    extern const char hdrnWarning[];    extern const char hdrnWWWAuthenticate[];    ///Special indices for the ParmVal::insertBefore() function    const unsigned idxBeforeFirst = 0;    const unsigned idxAfterLast   = 0x7FFFFFFFu;    //===================================================================================    ///Get token and trim    std::string::size_type toktrim(const std::mstring &src, std::mstring *dst,                                    std::string::size_type start, const std::string & sep,                                   std::mstring::sep_flag flag=std::mstring::sep_single);    //===================================================================================    ///Parameter and Value container    class ParmVal    {        ///Parameter name string        std::mstring pv_Parm;        ///Parameter nalue string        std::mstring pv_Val;    public:        ///Default constructor         ParmVal() {}        ///Copy constructor        ParmVal(const ParmVal &pv);        ///Constructor from name and value strings        ParmVal(const std::mstring &parm, const std::mstring &val);        ///Assign from ParmVal        ParmVal & operator = (const ParmVal &pv);        ///Assign value        ParmVal & operator = (const std::mstring &val);        ///Assign name and value strings        ParmVal & Assign(const std::mstring &parm, const std::mstring &val);        ///Erase pvParm and pvVal;        void erase() { pv_Parm.erase(); pv_Val.erase(); }        ///Parse string into two pieces - name and value        ParmVal & decode(const std::mstring &parm_val, char separator, bool trim_flag=false);        ///Build a new string         std::mstring encode(char separator) const;        ///Check, whether parameter has one of names. Name synax: name1|name2|name3        bool chk_name(const std::mstring &name, bool case_flag=true) const;        ///Returns parameter name        const std::mstring & parm() { return pv_Parm; }        ///Returns parameter name        const std::mstring & parm() const { return pv_Parm; }        ///Returns parameter value        std::mstring & val() { return pv_Val; }        ///Returns const parameter value        const std::mstring & val() const { return pv_Val; }        ///Returns parameter value        operator std::mstring() { return pv_Val; }    };    inline ParmVal::ParmVal(const ParmVal &pv)         : pv_Parm(pv.pv_Parm),          pv_Val(pv.pv_Val)    {}    inline ParmVal::ParmVal(const std::mstring &parm, const std::mstring &val)         : pv_Parm(parm),          pv_Val(val)    {}    inline ParmVal & ParmVal::operator = (const std::mstring &val)     {         pv_Val = val;         return *this;     }    inline ParmVal & ParmVal::Assign(const std::mstring &parm, const std::mstring &val)     {        pv_Parm = parm;        pv_Val = val;         return *this;     }    typedef std::vector<ParmVal> ParmValArray;    //===================================================================================    ///ParmVal container (an array)    class ParmValContainer    {        ///Separator char inside ParmVal, usually '='        char         pvc_Separator;          ///Prefix, ';' for URL-params, '?' for URL-headers        char         pvc_Prefix;             ///Char between params, ';' for URL-params, '&' for URL-headers        char         pvc_Between;            ///Postfix after all list        char         pvc_Postfix;            ///Case sensitivity flag        bool         pvc_CaseFlag;           ///Array of params        ParmValArray pvc_Array;    public:        ///Default constructor        ParmValContainer()            : pvc_Separator('='),              pvc_Prefix(';'),              pvc_Between(';'),              pvc_Postfix(0),              pvc_CaseFlag(true)        {}        ///Copy constructor        ParmValContainer(const ParmValContainer &pvc);        ///Special constructor        ParmValContainer(char separator, char prefix, char between, char postfix, bool case_flag=true)            : pvc_Separator(separator),              pvc_Prefix(prefix),              pvc_Between(between),              pvc_Postfix(postfix),              pvc_CaseFlag(case_flag)        {}        ///Assignment        ParmValContainer & operator = (const ParmValContainer &pvc);        ///Returns the total number of params        unsigned count() const { return pvc_Array.size(); }        /**Access by index. If there is no element with such index,            all necessary elenents will be added automatically */        ParmVal & operator [] (unsigned index);        /**Access by index. Const value will be returned. */        const ParmVal & operator [] (unsigned index) const;         /**Access by name. If there is no element with such name,           an empty element will be added automatically */        ParmVal & operator [] (const std::string &name);        ///Erase all        void erase() { pvc_Array.clear(); }        ///Parse string into parms        void decode(const std::mstring &str);        ///Check Empty, consider all 'pvRemoved'        bool ParmValContainer::empty() const;        ///Build a new string        std::mstring encode() const;        /**Insert a new parameter before index.           InsBefore(idxBeforeFirst) inserts an empty parameter at the begin of array           InsBefore(idxAfterLast)   inserts an empty parameter at the end of array           InsGefore(index)          inserts an empty parameter before index. */        ParmVal & insertBefore(unsigned index, const std::mstring & name);    };    ///Value assistant categories    enum ValCategory    {        vcAny,        //Any value        vcNumeric,    //Numeric value, check range        vcDigits,     //0...9, without checking range        vcHex,        //Hexdecimal value, without checking range        vcAlpha,      //a...z, A...Z        vcAlNum,      //a...z, A...Z, 0...9        vcList        //List of values, separated by '|'    };    ///Value assistant class (static functions only) - validate fields, default values    class ValAssistant    {        ///Restrictions and default values        const static struct ValRestriction        {            ///Parse item name            const char  *item;            ///Parameter name            const char  *name;            ///Category, see ValCategory            ValCategory  cat;            ///Value, depends on category            const char  *value;            ///Default value            const char  *def_val;            ///Minimum numeric value            double       min;            ///Maximum numeric value            double       max;            ///Case sensitivity flag            bool         case_flag;        }         vaRestrict[];    public:        ///Check value        static void check(const char *item,                           const char *name,                           const std::mstring &val);        ///Get default value        static const char * getDefaultVal(const char *item,                                         const char *name,                                         const std::mstring &val);    private:        ///Get default value        static void check(const ValRestriction & restrict, const std::mstring &val);        ///Generate 'Illegal character' throw         static void throwChar(const char * name, const std::mstring &val);    };}#endif

⌨️ 快捷键说明

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