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

📄 mpitems.cxx

📁 一个SIP协议栈
💻 CXX
📖 第 1 页 / 共 5 页
字号:
/********************************************************************* $Id: MpItems.cxx,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.cxx,v $ Revision 1.3  1999/08/31 02:22:05  cullen updated header **********************************************************************/#include <string>#include <vector>#include <stdio.h>#include "mstring.h"#include "MpItems.h"#include "MpCommon.h"#include "MpError.h"namespace msip{    //=======================================================================================    //MpParseItem Implementation    //---------------------------------------------------------------------------------------    MpParseItem & MpParseItem::item(unsigned i, std::mstring *name)    {        throw MpAccessError("MpParseItem: Out of item index");    }    //---------------------------------------------------------------------------------------    void MpParseItem::dump(std::mstring * str, unsigned indent)    {        unsigned i;        std::mstring name;        std::mstring value;        MpParseItem *pitem;        name = encodeHeaderName();        if(!name.empty())        {            str->append(indent, ' ');            str->append("\n***HEADER ");            str->append(name + "\n");        }        for(i = 0; i < valCount(); i++)        {            get(i, &name, &value);            str->append(indent, ' ');            str->append(name + "=" + value + "\n");        }        for(i = 0; i < itemCount(); i++)        {            pitem = &item(i, &name);            str->append(indent, ' ');            str->append(std::string("[") + name + "]\n");            pitem->dump(str, indent + 4);        }    }    //=======================================================================================    //MpHeader Implementation    //---------------------------------------------------------------------------------------    bool MpHeader::isHeader(const std::mstring & name, const char * names)    {        std::string::size_type s0 = 0;        std::string::size_type start = 0;        std::mstring t0;        std::mstring tmp;        std::mstring tnames = names;        while((s0 = name.token(&t0, s0, "|", "", 0)) != std::string::npos)        {            while((start = tnames.token(&tmp, start, "|", "", 0)) != std::string::npos)            {                if(t0.comparei(tmp) == 0)                 {                    return true;                }            }        }        return false;    }    //---------------------------------------------------------------------------------------    bool MpHeader::isHeader(const std::mstring &name) const    {        const char * hdr_names = mp_HdrNames;        if(mp_HdrNames == 0)        {            hdr_names = mp_CurHdrName.c_str();        }        return isHeader(name, hdr_names);    }    //---------------------------------------------------------------------------------------    MpHeader * MpHeader::headerFactory(const char * name)    {        MpHeader * p_hdr = 0;        std::mstring nm;        std::mstring(name).token(&nm, 0, "|", "", 0);        do         {            if(isHeader(nm, hdrnAccept))             { p_hdr = new MpAccept;            break; }            if(isHeader(nm, hdrnAcceptEncoding))     { p_hdr = new MpAcceptEncoding;    break; }            if(isHeader(nm, hdrnAcceptLanguage))     { p_hdr = new MpAcceptLanguage;    break; }            if(isHeader(nm, hdrnCallID))             { p_hdr = new MpCallID;            break; }            if(isHeader(nm, hdrnContact))            { p_hdr = new MpContact;           break; }            if(isHeader(nm, hdrnCSeq))               { p_hdr = new MpCSeq;              break; }            if(isHeader(nm, hdrnDate))               { p_hdr = new MpDate;              break; }            if(isHeader(nm, hdrnEncryption))         { p_hdr = new MpEncryption;        break; }            if(isHeader(nm, hdrnExpires))            { p_hdr = new MpExpires;           break; }            if(isHeader(nm, hdrnFrom))               { p_hdr = new MpFrom;              break; }            if(isHeader(nm, hdrnRecordRoute))        { p_hdr = new MpRecordRoute;       break; }            if(isHeader(nm, hdrnTimestamp))          { p_hdr = new MpTimestamp;         break; }            if(isHeader(nm, hdrnTo))                 { p_hdr = new MpTo;                break; }            if(isHeader(nm, hdrnVia))                { p_hdr = new MpVia;               break; }            if(isHeader(nm, hdrnContentEncoding))    { p_hdr = new MpContentEncoding;   break; }            if(isHeader(nm, hdrnContentLength))      { p_hdr = new MpContentLength;     break; }            if(isHeader(nm, hdrnContentType))        { p_hdr = new MpContentType;       break; }            if(isHeader(nm, hdrnAuthorization))      { p_hdr = new MpAuthorization;     break; }            if(isHeader(nm, hdrnHide))               { p_hdr = new MpHide;              break; }            if(isHeader(nm, hdrnMaxForwards))        { p_hdr = new MpMaxForwards;       break; }            if(isHeader(nm, hdrnOrganization))       { p_hdr = new MpOrganization;      break; }            if(isHeader(nm, hdrnPriority))           { p_hdr = new MpPriority;          break; }            if(isHeader(nm, hdrnProxyAuthorization)) { p_hdr = new MpProxyAuthorization;break; }            if(isHeader(nm, hdrnProxyRequire))       { p_hdr = new MpProxyRequire;      break; }            if(isHeader(nm, hdrnRoute))              { p_hdr = new MpRoute;             break; }            if(isHeader(nm, hdrnRequire))            { p_hdr = new MpRequire;           break; }            if(isHeader(nm, hdrnResponseKey))        { p_hdr = new MpResponseKey;       break; }            if(isHeader(nm, hdrnSubject))            { p_hdr = new MpSubject;           break; }            if(isHeader(nm, hdrnUserAgent))          { p_hdr = new MpUserAgent;         break; }            if(isHeader(nm, hdrnAllow))              { p_hdr = new MpAllow;             break; }            if(isHeader(nm, hdrnProxyAuthenticate))  { p_hdr = new MpProxyAuthenticate; break; }            if(isHeader(nm, hdrnRetryAfter))         { p_hdr = new MpRetryAfter;        break; }            if(isHeader(nm, hdrnServer))             { p_hdr = new MpServer;            break; }            if(isHeader(nm, hdrnUnsupported))        { p_hdr = new MpUnsupported;       break; }            if(isHeader(nm, hdrnWarning))            { p_hdr = new MpWarning;           break; }            if(isHeader(nm, hdrnWWWAuthenticate))    { p_hdr = new MpWWWAuthenticate;   break; }        }         while(0);          if(p_hdr == 0) p_hdr = new MpValue;        p_hdr->setHeaderName(nm);        return p_hdr;    }        //---------------------------------------------------------------------------------------    bool MpHeader::uniteDesired() const    {        if(!mp_MultiFlag) return false;        return mp_UniteMulti;    }    //---------------------------------------------------------------------------------------    void MpHeader::setHeaderInfo(const char * hdr_name, bool multi, bool unite)    {        mp_HdrNames = hdr_name;        mp_MultiFlag = multi;        mp_UniteMulti = multi ? unite : false;        if(hdr_name)        {            std::mstring ts = hdr_name;            ts.token(&mp_CurHdrName, 0, "|", "", 0);        }        else        {            mp_CurHdrName = "";        }    }    //---------------------------------------------------------------------------------------    std::string MpHeader::encodeHeaderName() const    {        std::mstring ret;        if(!mp_CurHdrName.empty())        {            ret = mp_CurHdrName + ": ";        }        return ret;    }    //---------------------------------------------------------------------------------------    void MpHeader::setHeaderName(const std::mstring & hdr_name)    {        if(mp_HdrNames == 0)  //There are no header names, use current         {            mp_CurHdrName = hdr_name;            return;        }        //Otherwise, check possible names        if(isHeader(hdr_name, mp_HdrNames))         {            mp_CurHdrName = hdr_name;            return;        }        throw MpSyntaxError(std::string("Invalid header name: '") + hdr_name + "' Required: '" + mp_HdrNames + "'");    }    //---------------------------------------------------------------------------------------    void MpHeader::setHeaderProperties(const MpHeader & header)    {        mp_CurHdrName = header.mp_CurHdrName;        mp_HdrNames   = header.mp_HdrNames;        mp_MultiFlag  = header.mp_MultiFlag;        mp_UniteMulti = header.mp_UniteMulti;    }    //=======================================================================================    //MpHostPort Implementation    //---------------------------------------------------------------------------------------    std::mstring MpHostPort::encode(bool chk_syntax_flag) const    {        std::mstring ret;        if(!empty())        {            if(chk_syntax_flag) checkSyntax();            ret = mp_Host;            if(!mp_Port.empty())            {                ret += ':';                ret += mp_Port;            }        }        return ret;    }       //---------------------------------------------------------------------------------------    void MpHostPort::decode(const std::mstring & str, bool chk_syntax_flag)    {        std::string::size_type start = 0;        erase();        start = toktrim(str, &mp_Host, start, ":");        start = toktrim(str, &mp_Port, start, ":");        if(chk_syntax_flag) checkSyntax();    }    //---------------------------------------------------------------------------------------    void MpHostPort::checkSyntax() const    {        ValAssistant::check(mpiHostPort, mpnHost, mp_Host);        ValAssistant::check(mpiHostPort, mpnPort, mp_Port);    }    //---------------------------------------------------------------------------------------    void MpHostPort::erase()    {        mp_Host = "";        mp_Port = "";    }    //---------------------------------------------------------------------------------------    MpParseItem & MpHostPort::operator [] (const char * name)    {        throw MpAccessError("MpHostPort: No nested items");    }    //---------------------------------------------------------------------------------------    std::mstring & MpHostPort::val(const char * name)    {        if(strcmp(name, mpnHost) == 0) return mp_Host;        if(strcmp(name, mpnPort) == 0) return mp_Port;        throw MpAccessError(std::mstring("MpHostPort: Illegal Parameter: ") + name);    }    //---------------------------------------------------------------------------------------    void MpHostPort::get(unsigned i, std::mstring *name, std::mstring *value) const    {        if(i == 0)        {            if(name)  *name  = mpnHost;            if(value) *value = mp_Host;            return;        }        if(i == 1)        {            if(name)  *name  = mpnPort;            if(value) *value = mp_Port;            return;        }        throw MpAccessError("MpHostPort: Out of index");    }    //=======================================================================================    //MpUserInfo Implementation    //---------------------------------------------------------------------------------------    std::mstring MpUserInfo::encode(bool chk_syntax_flag) const    {        std::mstring ret;        if(!empty())        {            if(chk_syntax_flag) checkSyntax();            ret += mp_User;            if(!mp_Passwd.empty())            {                ret += ':';                ret += mp_Passwd;            }            if(!mp_ISub.empty())            {                ret += ";isub=";                ret += mp_ISub;            }            if(!mp_PostD.empty())            {                ret += ";postd=";                ret += mp_PostD;            }            ret += '@';        }        return ret;    }        //---------------------------------------------------------------------------------------    void MpUserInfo::decode(const std::mstring & str, bool chk_syntax_flag)    {        erase();

⌨️ 快捷键说明

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