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

📄 mpcommon.cxx

📁 一个SIP协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/********************************************************************* $Id: MpCommon.cxx,v 1.3 1999/08/31 02:06:22 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: MpCommon.cxx,v $ Revision 1.3  1999/08/31 02:06:22  cullen added header **********************************************************************/#include "MpCommon.h"#include "MpError.h"namespace msip{    const char sipProtoName[] = "SIP";    const char sipPlusProtoName[] = "SIP+";    const char sipVersion[] = "2.0";    const char sipPlusVersion[] = "0.0";    const char sipProtoNameL[] = "sip";    const char sipContactAllowedPrefixes[] = "sip|mailto|mail";    ///SIP request methods    const char mtdINVITE[]   = "INVITE";    const char mtdOPTIONS[]  = "OPTIONS";    const char mtdREGISTER[] = "REGISTER";    const char mtdACK[]      = "ACK";    const char mtdCANCEL[]   = "CANCEL";    const char mtdBYE[]      = "BYE";    const char mtdSIGNAL[]   = "SIGNAL";    const char mpiHostPort[]    = "hostport";    const char mpiUserInfo[]    = "userinfo";    const char mpiUrl[]         = "url";    const char mpiParm[]        = "parm";    const char mpiUrlParm[]     = "urlparm";    const char mpiUrlHdr[]      = "urlhdr";    const char mpiStartLine[]   = "startline";    const char mpiCallID[]      = "callid";    const char mpiContactParm[] = "contact";     const char mpiFromParm[]    = "from";    const char mpiToParm[]      = "to";    const char mpiRetryAfter[]  = "retryafter";    const char mpiTimestamp[]   = "tmstamp";    const char mpiVia[]         = "via";    const char mpiSentBy[]      = "sentby";    const char mpiWarning[]     = "warning";    const char mpnHost[]            = "host";    const char mpnPort[]            = "port";    const char mpnUser[]            = "user";    const char mpnPhone[]           = "phone";    const char mpnPasswd[]          = "passwd";    const char mpnISub[]            = "isub";    const char mpnPostD[]           = "postd";    const char mpnTransport[]       = "transport";    const char mpnMethod[]          = "method";    const char mpnTtl[]             = "ttl";    const char mpnMaddr[]           = "maddr";    const char mpnTag[]             = "tag";    const char mpnHidden[]          = "\1hidden";    const char mpnReceived[]        = "received";    const char mpnBranch[]          = "branch";    const char mpnMsgType[]         = "msgtype";    const char mpnMsgReasonPhrase[] = "msgreasonphrase";    const char mpnValue[]           = "value";     const char mpnSubVal[]          = "subval";    const char mpnDispName[]        = "dispname";    const char mpnComment[]         = "comment";    const char mpnQ[]               = "q";    const char mpnAction[]          = "action";    const char mpnExpires[]         = "expires";    const char mpnContentLen[]      = "contlen";    const char mpnCSeq[]            = "cseq";    const char mpnHide[]            = "hide";    const char mpnMaxForw[]         = "maxforw";    const char mpnPriority[]        = "prior";    const char mpnDate[]            = "date";    const char mpnSeconds[]         = "seconds";    const char mpnDuration[]        = "duration";    const char mpnDelay[]           = "delay";    const char mpnProto[]           = "proto";    const char mpnVersion[]         = "version";    const char mpnCode[]            = "code";    const char mpnAgent[]           = "agent";    const char mpnText[]            = "text";    const char hdrnAccept[]             = "Accept";               // Section 6.7    const char hdrnAcceptEncoding[]     = "Accept-Encoding";      // Section 6.8    const char hdrnAcceptLanguage[]     = "Accept-Language";      // Section 6.9    const char hdrnCallID[]             = "Call-ID|i";            // Section 6.12    const char hdrnContact[]            = "Contact|m";            // Section 6.13    const char hdrnCSeq[]               = "CSeq";                 // Section 6.17    const char hdrnDate[]               = "Date";                 // Section 6.18    const char hdrnEncryption[]         = "Encryption";           // Section 6.19    const char hdrnExpires[]            = "Expires";              // Section 6.20    const char hdrnFrom[]               = "From|f";               // Section 6.21    const char hdrnRecordRoute[]        = "Record-Route";         // Section 6.29    const char hdrnTimestamp[]          = "Timestamp";            // Section 6.36    const char hdrnTo[]                 = "To|t";                 // Section 6.37    const char hdrnVia[]                = "Via|v";                // Section 6.40    const char hdrnContentEncoding[]    = "Content-Encoding|e";   // Section 6.14    const char hdrnContentLength[]      = "Content-Length|l";     // Section 6.15    const char hdrnContentType[]        = "Content-Type|c";       // Section 6.16    const char hdrnAuthorization[]      = "Authorization";        // Section 6.11    const char hdrnHide[]               = "Hide";                 // Section 6.22    const char hdrnMaxForwards[]        = "Max-Forwards";         // Section 6.23    const char hdrnOrganization[]       = "Organization";         // Section 6.24    const char hdrnPriority[]           = "Priority";             // Section 6.25    const char hdrnProxyAuthorization[] = "Proxy-Authorization";  // Section 6.27    const char hdrnProxyRequire[]       = "Proxy-Require";        // Section 6.28    const char hdrnRoute[]              = "Route";                // Section 6.33    const char hdrnRequire[]            = "Require";              // Section 6.30    const char hdrnResponseKey[]        = "Response-Key";         // Section 6.31    const char hdrnSubject[]            = "Subject|s";            // Section 6.35    const char hdrnUserAgent[]          = "User-Agent";           // Section 6.39    const char hdrnAllow[]              = "Allow";                // Section 6.10    const char hdrnProxyAuthenticate[]  = "Proxy-Authenticate";   // Section 6.26    const char hdrnRetryAfter[]         = "Retry-After";          // Section 6.32    const char hdrnServer[]             = "Server";               // Section 6.34    const char hdrnUnsupported[]        = "Unsupported";          // Section 6.38    const char hdrnWarning[]            = "Warning";              // Section 6.41    const char hdrnWWWAuthenticate[]    = "WWW-Authenticate";     // Section 6.42    const ValAssistant::ValRestriction ValAssistant::vaRestrict[] =     {//       item           name          cat        value           def_val        min    max   case_flag        {mpiHostPort,   mpnHost,      vcAlNum,   ".-_",          "",            0,     0,    false},        {mpiHostPort,   mpnPort,      vcNumeric, "",             "5060",        0,     65535,false},        {mpiUserInfo,   mpnUser,      vcAlNum,   "%-_.!~*'&+$",  "",            0,     0,    false},        {mpiUserInfo,   mpnPhone,     vcDigits,  "+-.pw*#ABCD",  "",            0,     0,    false},        {mpiUserInfo,   mpnISub,      vcDigits,  "-.",           "",            0,     0,    false},        {mpiUserInfo,   mpnPostD,     vcDigits,  "-.pw*#ABCD",   "",            0,     0,    false},        {mpiUrlParm,    mpnTransport, vcList,    "tcp|udp",      "udp",         0,     0,    false},        {mpiUrlParm,    mpnMaddr,     vcAlNum,   ".-_",          "",            0,     0,    false},        {mpiUrlParm,    mpnTtl,       vcNumeric, "",             "1",           0,     255,  false},        {mpiUrlParm,    mpnMethod,    vcList,    "INVITE|ACK|OPTIONS|REGISTER|CANCEL|BYE", "INVITE", 0, 0, true},         {mpiUrlParm,    mpnTag,       vcHex,     "-",            "",            0,     0,    false},        {mpiFromParm,   mpnTag,       vcHex,     "-",            "",            0,     0,    false},        {mpiToParm,     mpnTag,       vcHex,     "-",            "",            0,     0,    false},        {mpiUrlParm,    mpnUser,      vcList,    "phone|ip",     "ip",          0,     0,    false},        {mpiCallID,     mpnValue,     vcHex,     "-",            "",            0,     0,    false},        {mpiContactParm,mpnQ,         vcNumeric, ".:\"",         "",            0.0,   1.0,  false},        {mpiContactParm,mpnAction,    vcList,    "proxy|redirect","",           0,     0,    true},        {mpiContactParm,mpnExpires,   vcAlNum,   ",: ",          "",            0,     0,    false},        {mpiParm,       mpnContentLen,vcNumeric, "",             "",            0,     4096, false},        {mpiParm,       mpnCSeq,      vcNumeric, "",             "",            0,     2147483647, false},        {mpiParm,       mpnHide,      vcList,    "hop|route",    "",            0,     0,    true},        {mpiParm,       mpnMaxForw,   vcNumeric, "",             "",            0,     65535, false},        {mpiParm,       mpnPriority,  vcList,    "emergency|urgent|normal|non-urgent", "", 0, 0, true},        {mpiRetryAfter, mpnSeconds,   vcNumeric, "",             "",            0,     65535,false},        {mpiRetryAfter, mpnDuration,  vcNumeric, "",             "",            0,     65535,false},        {mpiRetryAfter, mpnDate,      vcAlNum,   ",: ",          "",            0,     0,    false},        {mpiTimestamp,  mpnValue,     vcNumeric, ".",            "",            0,     0,    false},        {mpiVia,        mpnProto,     vcList,    "SIP|SIP+",     "",            0,     0,    false},        {mpiVia,        mpnVersion,   vcList,    "2.0|0.0",      "",            0,     0,    false},        {mpiVia,        mpnTransport, vcAlpha,   "",             "",            0,     0,    false},        {mpiWarning,    mpnCode,      vcNumeric, "",             "",            100,   999,  false},        {mpiWarning,    mpnAgent,     vcAlNum,   ".-_",          "",            0,     0,    false},               {0,             0,            vcAny,     0,              0,             0,     0,    false}    };       const char QuoteSymb[] = "\"";    //=======================================================================================    //Auxilliary functions        //---------------------------------------------------------------------------------------    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::string::size_type end = src.token(dst, start, sep,                                                QuoteSymb,                                                QPairSymb,                                               flag);        if(dst) dst->atrim();        return end;    }    //=======================================================================================    //ParmVal implementation    //---------------------------------------------------------------------------------------    ParmVal & ParmVal::operator = (const ParmVal &pv)    {        if(&pv != this)        {            pv_Parm = pv.pv_Parm;            pv_Val = pv.pv_Val;          }        return *this;     }    //---------------------------------------------------------------------------------------    ParmVal & ParmVal::decode(const std::mstring &parm_val, char separator, bool trim_flag)    {        pv_Parm.erase();        pv_Val.erase();        std::string::size_type pos = parm_val.find(separator);        if(pos != std::string::npos)        {            pv_Parm.assign(parm_val, 0, pos);            pv_Val.assign(parm_val, pos+1, std::string::npos);            if(trim_flag)            {                pv_Parm.atrim();                pv_Val.atrim();            }        }        else        {            std::mstring ts = parm_val;            if(trim_flag) ts.atrim();            pv_Parm = "\1" + ts;            pv_Val = "1";        }        return *this;    }        //---------------------------------------------------------------------------------------    std::mstring ParmVal::encode(char separator) const    {        std::mstring ret;        if(!pv_Parm.empty() && !pv_Val.empty())        {            if(pv_Parm[0] == '\1')            {                ret += (pv_Parm.c_str()) + 1;            }            else            {                ret += pv_Parm;                ret += separator;                ret += pv_Val;            }        }        return ret;    }            //---------------------------------------------------------------------------------------    bool ParmVal::chk_name(const std::mstring &name, bool case_flag) const    {        if(pv_Parm.empty()) return false;        std::string::size_type start = 0;        std::mstring tmp;        while((start = name.token(&tmp, start, "|", "", 0)) != std::string::npos)        {            if(case_flag)            {                if(pv_Parm.compare(tmp) == 0) return true;            }            else            {                if(pv_Parm.comparei(tmp) == 0) return true;            }        }

⌨️ 快捷键说明

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