📄 mpitems.h
字号:
#ifndef __MPITEMS_H__ #define __MPITEMS_H__/********************************************************************* $Id: MpItems.h,v 1.3 1999/08/31 02:22:05 cullen Exp $ ********************************************************************* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to the terms and conditions set forth in the GNU Lesser General Public License, as a condition of using this library you are required to grant to all users of this library or any implementation utilizing or derived from this library a reciprocal, no cost, worldwide, perpetual, non-exclusive, non-transferable, unrestricted license to your claims of all patents and patent applications throughout the world that are infringed by the library or any implementation utilizing or derived from this library. In the event you redistribute this library or any implementation utilizing or derived from this library, you must prominently display the foregoing terms and conditions with the library or the implementation utilizing or derived from this library. In the event of a conflict of terms between the foregoing license grant and the terms set forth in the GNU Lesser General Public License, the foregoing terms and conditions shall be deemed to govern. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not; write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Copyright 1999 Vovida Networks, Inc. All Rights Reserved. ********************************************************************* $Log: MpItems.h,v $ Revision 1.3 1999/08/31 02:22:05 cullen updated header **********************************************************************/#include <string>#include <vector>#include "mstring.h"#include "MpCommon.h"namespace msip{ ///Parser Item Interface Class (abstract) class MpParseItem { protected: ///Default Constructor MpParseItem() {} public: /**@name Virtual Accessors and Modificators */ //@{ ///Destructor virtual ~MpParseItem() {} ///Build a String from Pieces virtual std::mstring encode(bool chk_syntax_flag=true) const = 0; ///Parse a String into Pieces virtual void decode(const std::mstring & str, bool chk_syntax_flag=true) = 0; ///Check Syntax. Generate an Exception MpSyntaxError virtual void checkSyntax() const = 0; ///Erase All the Values and Nested Parser Items virtual void erase() = 0; ///Check - Whether It Is Empty virtual bool empty() const = 0; ///Access To Nested Items virtual MpParseItem & operator [] (const char * name) = 0; ///Access To Parameter Values virtual std::mstring & val(const char * name) = 0; ///Returns Number of Parameters virtual unsigned valCount() const = 0; ///Returns Number of Parameters virtual unsigned itemCount() const { return 0; } ///Get Parameter Name and Value virtual void get(unsigned i, std::mstring *name, std::mstring *value) const = 0; ///Get Item and Item Name virtual MpParseItem & item(unsigned i, std::mstring *name); //@} /**@name Auxilliary Operators */ //@{ ///Assign from String (decode) void operator = (const std::mstring & str) { decode(str); } ///Convert to String (encode) operator std::mstring() const { return encode(); } ///Assign from String (decode) void operator << (const std::mstring &str) { decode(str); } ///Convert to String (encode) void operator >> (std::mstring &str) { str = encode(); } ///Build header name virtual std::string encodeHeaderName() const { return std::string(); } ///Dump all the parameters and items void dump(std::mstring * str, unsigned indent=0); //@} private: MpParseItem(const MpParseItem &); MpParseItem & operator = (const MpParseItem &); }; ///Header Interface Class (abstract) class MpHeader : public MpParseItem { ///Current Header Name std::mstring mp_CurHdrName; ///Pointer to possible header names, syntax: "From|f" const char * mp_HdrNames; ///Multiple Header Flag bool mp_MultiFlag; ///What is preferable: to make particular headers (false) or unite then in one (true) bool mp_UniteMulti; protected: ///Default Constructor MpHeader() : mp_MultiFlag(false), mp_UniteMulti(false), mp_HdrNames(0) {} protected: ///Set Header Info - Header Name and flags void setHeaderInfo(const char * hdr_name, bool multi, bool unite=false); public: ///Set the same header properties void setHeaderProperties(const MpHeader & header); ///Create the Same Object virtual MpHeader * clone() const { return 0; } ///Is multiple header bool is_multiple_hdr() const { return mp_MultiFlag; } ///Unite multiple headers into one is preferable bool uniteDesired() const; ///Check header name and Set current name void setHeaderName(const std::mstring & hdr_name); ///Build header name virtual std::string encodeHeaderName() const; ///Check header name bool isHeader(const std::mstring &name) const; ///Check header name static bool isHeader(const std::mstring &name, const char * names); ///Create a new header object static MpHeader * headerFactory(const char * name); ///Get curren header name const std::mstring & getHeaderName() const { return mp_CurHdrName; } private: MpHeader(const MpHeader &); MpHeader & operator = (const MpHeader &); }; /**Host and Port Item "host:port" Does Not Contain any Nested Items * host_port.val(mpnHost) * host_port.val(mpnPort) */ class MpHostPort : public MpParseItem { std::mstring mp_Host; std::mstring mp_Port; public: MpHostPort() {} virtual ~MpHostPort() {} virtual std::mstring encode(bool chk_syntax_flag=true) const; virtual void decode(const std::mstring & str, bool chk_syntax_flag=true); virtual void checkSyntax() const; virtual void erase(); virtual bool empty() const { return mp_Host.empty(); } virtual MpParseItem & operator [] (const char * name); virtual std::mstring & val(const char * name); virtual unsigned valCount() const { return 2; } virtual void get(unsigned i, std::mstring *name, std::mstring *value) const; void operator = (const std::mstring & str) { decode(str); } private: MpHostPort(const MpHostPort &); MpHostPort & operator = (const MpHostPort &); }; /**User info Item "name:passd;isub=;postd=" Does Not Contain any Nested Items * user_info.val(mpnUser) * user_info.val(mpnPasswd) * user_info.val(mpnISub) * user_info.val(mpnPostD) */ class MpUserInfo : public MpParseItem { std::mstring mp_User; std::mstring mp_Passwd; std::mstring mp_ISub; std::mstring mp_PostD; public: MpUserInfo() {} virtual ~MpUserInfo() {} virtual std::mstring encode(bool chk_syntax_flag=true) const; virtual void decode(const std::mstring & str, bool chk_syntax_flag=true); virtual void checkSyntax() const; virtual void erase(); virtual bool empty() const { return mp_User.empty(); } virtual MpParseItem & operator [] (const char * name); virtual std::mstring & val(const char * name); virtual unsigned valCount() const { return 4; } virtual void get(unsigned i, std::mstring *name, std::mstring *value) const; void operator = (const std::mstring & str) { decode(str); } private: MpUserInfo(const MpUserInfo &); MpUserInfo & operator = (const MpUserInfo &); }; /**Parameters Container Abstract class (UrlParm and UrlHdr) * parm.val(...) */ class MpParm : public MpParseItem { ParmValContainer mp_Array; const char * mp_ItemName; public: MpParm(char separator, char prefix, char between, char postfix, bool case_flag, const char *itm_name) : mp_Array(separator, prefix, between, postfix, case_flag), mp_ItemName(itm_name) {} virtual ~MpParm() {} virtual std::mstring encode(bool chk_syntax_flag=true) const; virtual void decode(const std::mstring & str, bool chk_syntax_flag=true); virtual void checkSyntax() const; virtual void erase(); virtual bool empty() const { return mp_Array.empty(); } virtual MpParseItem & operator [] (const char * name); virtual std::mstring & val(const char * name); virtual unsigned valCount() const { return mp_Array.count(); } virtual void get(unsigned i, std::mstring *name, std::mstring *value) const; void operator = (const std::mstring & str) { decode(str); } private: MpParm(const MpParm &); MpParm & operator = (const MpParm &); }; /**URL Parameters class ";ttl=;transport=;etc=..." * url_parm.val(...) */ class MpUrlParm : public MpParm { public: MpUrlParm() : MpParm('=', ';', ';', 0, true, mpiUrlParm) {} virtual ~MpUrlParm() {} void operator = (const std::mstring & str) { decode(str); } private: MpUrlParm(const MpUrlParm &); MpUrlParm & operator = (const MpUrlParm &); }; /**URL Headers class "?parm1=val1&parm2=val2..." * url_hdr.val(...) */ class MpUrlHdr : public MpParm { public: MpUrlHdr() : MpParm('=', '?', '&', 0, true, mpiUrlHdr) {} virtual ~MpUrlHdr() {} void operator = (const std::mstring & str) { decode(str); } private: MpUrlHdr(const MpUrlHdr &); MpUrlHdr & operator = (const MpUrlHdr &); }; /**URL Item, Contains MpUserInfo, MpHostPort, MpParm, mp_Hdr items * url[mpiHostPort].val(mpnHost) * url[mpiHostPort].val(mpnPort) * url[mpiUserInfo].val(mpnUser) * url[mpiUserInfo].val(mpnPasswd) * url[mpiUserInfo].val(mpnISub) * url[mpiUserInfo].val(mpnPostD) * url[mpiUrlParm].val(...) * url[mpiUrlHdr].val(...) */ class MpUrl : public MpParseItem { MpUserInfo mp_UserInfo; MpHostPort mp_HostPort; MpUrlParm mp_Parm; MpUrlHdr mp_Hdr; std::mstring mp_CurPrefix; const char * mp_AllowedPrefixes; public: MpUrl(const char * allowed_url_prefixes) { set_allowed_prefixes(allowed_url_prefixes); } void set_allowed_prefixes(const char * prefixes); virtual ~MpUrl() {} virtual std::mstring encode(bool chk_syntax_flag=true) const; virtual void decode(const std::mstring & str, bool chk_syntax_flag=true); virtual void checkSyntax() const; virtual void erase(); virtual bool empty() const { return mp_HostPort.empty(); } virtual MpParseItem & operator [] (const char * name); const MpParseItem & operator [] (const char * name) const; virtual std::mstring & val(const char * name); virtual unsigned valCount() const { return 0; } virtual unsigned itemCount() const { return 4; } virtual void get(unsigned i, std::mstring *name, std::mstring *value) const; virtual MpParseItem & item(unsigned i, std::mstring *name); void operator = (const std::mstring & str) { decode(str); } private: MpUrl(const MpUrl &); MpUrl & operator = (const MpUrl &); }; /**Message Start Line. "METHOD MpUrl SIP/2.0" or "SIP/2.0 NNN Message" * start_line.val(mpnProto) * start_line.val(mpnVersion) * start_line.val(mpnMsgType) * start_line.val(mpnMsgReasonPhrase) * start_line[mpiUrl][mpiHostPort].val(mpnHost) * start_line[mpiUrl][mpiHostPort].val(mpnPort) * start_line[mpiUrl][mpiUserInfo].val(mpnUser) * start_line[mpiUrl][mpiUserInfo].val(mpnPasswd) * start_line[mpiUrl][mpiUserInfo].val(mpnISub) * start_line[mpiUrl][mpiUserInfo].val(mpnPostD) * start_line[mpiUrl][mpiUserInfo].val(mpnISub) * start_line[mpiUrl][mpiUrlParm].val(...) * start_line[mpiUrl][mpiUrlHdr].val(...) */ class MpStartLine : public MpHeader { //sl = "Start Line" abbreviation ///Response Reason Text const static struct ReasonText { MpResponseCode code; const char * text; } mp_ReasonText[]; ///Method String const static struct MethodString { MpMsgType type; const char * str; } mp_MethodString[]; ///Request Method or Response Code std::mstring mp_Type; ///Last Response Reason text std::mstring mp_ReasonPhrase; ///SIP-URL MpUrl mp_Url; ///Protocol name std::mstring mp_Proto; ///Proto Version std::mstring mp_Version; public: MpStartLine() : mp_Url(sipProtoNameL) {} virtual ~MpStartLine() {} virtual MpHeader * clone() const { return new MpStartLine; }; virtual std::mstring encode(bool chk_syntax_flag=true) const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -