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

📄 sipmsg.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 4 页
字号:
	try	{	    sipMsg = new AckMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the ack msg");		}	break;    case SIP_STATUS:	try	{	    sipMsg = new StatusMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the status msg");	}	break;    case SIP_INFO:	try	{	    sipMsg = new InfoMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the info msg");		}	break;    case SIP_OPTIONS:	try	{	    sipMsg = new OptionsMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the options msg");	}	break;    case SIP_REGISTER:	try	{	    sipMsg = new RegisterMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the register msg");	}	break;    case SIP_TRANSFER:	try	{	    sipMsg = new TransferMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the transfer msg");	}	break;    case SIP_SUBSCRIBE:	try	{	    sipMsg = new SubscribeMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the subscribe msg");	}	break;    case SIP_REFER:	try	{	    sipMsg = new ReferMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the refer msg");	}	break;    case SIP_NOTIFY:	try	{	    sipMsg = new NotifyMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the notify msg");	}	break;    case SIP_UNKNOWN:	try	{	    sipMsg = new UnknownExtensionMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK,                   "Failed in creating the UnknownExtension msg");	}        break;    case SIP_MESSAGE:        try        {            sipMsg = new MessageMsg(data);        }        catch(SipParserException&)        {	    cpLog(LOG_DEBUG_STACK, "Failed in creating the MESSAGE msg");        }        break;    default:        cpLog(LOG_DEBUG_STACK, "NOT A KNOWN SIP MESSAGE");        cpLog(LOG_INFO, "NOT A KNOWN SIP MESSAGE");    }//end switch        //print it out here.    if(sipMsg != 0)    {	cpLog(LOG_DEBUG_STACK, 	      " In sipmsg:     after decoding: %s", 	      sipMsg->encode().logData());    }        return sipMsg;}voidSipMsg::encodeBody(Data* msg) const{    // need to encode body first to do calculations of length    Data body;    body.setBufferSize(800);    myMimeList.encode(&body);    Sptr <SipContentLength> contLen = myMimeList.getContentLength();    if (contLen != 0)    {        Sptr<SipContentLength> contentLength;        myHeaderList.getParsedHeader(contentLength, SIP_CONTENT_LENGTH_HDR);        *contentLength = *contLen;    }       Sptr <SipContentType> contType = myMimeList.getContentType();    if (contType != 0)    {        Sptr<SipContentType> contentType;        myHeaderList.getParsedHeader(contentType, SIP_CONTENT_TYPE_HDR);        *contentType = *(contType);    }        Sptr <SipContentDisposition> contDisp = myMimeList.getContentDisposition();    if (contDisp != 0)    {        Sptr<SipContentDisposition> contentDisposition;        myHeaderList.getParsedHeader(contentDisposition,                                      SIP_CONTENT_DISPOSITION_HDR);        *contentDisposition = *(contDisp);    }        // encode the body of the message    myHeaderList.encode(msg);    *msg += body;}Sptr<SipMsg>SipMsg::clone(){    return copyPtrtoSptr(this);}Sptr<SipMsg> Vocal::copyPtrtoSptr(SipMsg* sipMsg){    assert(sipMsg);    Sptr<SipMsg> sptrsipMsg;    switch(sipMsg->getType())    {    case SIP_INVITE:    {        InviteMsg* inviteMsg = dynamic_cast<InviteMsg*>(sipMsg);        if (inviteMsg)        {            sptrsipMsg = new InviteMsg(*inviteMsg);        }        break;    }    case SIP_ACK:    {        AckMsg* ackMsg = dynamic_cast<AckMsg*>(sipMsg);        if (ackMsg)        {            sptrsipMsg = new AckMsg(*ackMsg);        }        break;    }    case SIP_BYE:    {        ByeMsg* byeMsg = dynamic_cast<ByeMsg*>(sipMsg);        if (byeMsg)        {            sptrsipMsg = new ByeMsg (*byeMsg);        }        break;    }    case SIP_CANCEL:    {        CancelMsg* cancelMsg = dynamic_cast<CancelMsg*>(sipMsg);        if (cancelMsg)        {            sptrsipMsg = new CancelMsg (*cancelMsg);        }        break;    }    case SIP_STATUS:    {        StatusMsg* statusMsg = dynamic_cast<StatusMsg*>(sipMsg);        if (statusMsg)        {            sptrsipMsg = new StatusMsg (*statusMsg);        }        break;    }    case SIP_REFER:    {        ReferMsg* referMsg  = dynamic_cast<ReferMsg*>(sipMsg);        if (referMsg)        {            sptrsipMsg = new ReferMsg (*referMsg);        }        break;    }    case SIP_REGISTER:    {        RegisterMsg* registerMsg  = dynamic_cast<RegisterMsg*>(sipMsg);        if (registerMsg)        {            sptrsipMsg = new RegisterMsg (*registerMsg);        }        break;    }    case SIP_OPTIONS:    {        OptionsMsg* optionsMsg  = dynamic_cast<OptionsMsg*>(sipMsg);        if (optionsMsg)        {            sptrsipMsg = new OptionsMsg (*optionsMsg);        }        break;    }    case SIP_INFO:    {        InfoMsg* infoMsg  = dynamic_cast<InfoMsg*>(sipMsg);        if (infoMsg)        {            sptrsipMsg = new InfoMsg (*infoMsg);        }        break;    }    case SIP_TRANSFER:    {        TransferMsg* transferMsg  = dynamic_cast<TransferMsg*>(sipMsg);        if (transferMsg)        {            sptrsipMsg = new TransferMsg (*transferMsg);        }        break;    }    case SIP_SUBSCRIBE:    {        SubscribeMsg* subsMsg  = dynamic_cast<SubscribeMsg*>(sipMsg);        if (subsMsg)        {            sptrsipMsg = new SubscribeMsg (*subsMsg);        }        break;    }    case SIP_NOTIFY:    {        NotifyMsg* notifyMsg  = dynamic_cast<NotifyMsg*>(sipMsg);        if (notifyMsg)        {            sptrsipMsg = new NotifyMsg (*notifyMsg);        }        break;    }    case SIP_MESSAGE:    {        MessageMsg* msg  = dynamic_cast<MessageMsg*>(sipMsg);        if (msg)        {            sptrsipMsg = new MessageMsg (*msg);        }        break;    }    default:    {        UnknownExtensionMsg* unknownExtensionMsg             = dynamic_cast<UnknownExtensionMsg*>(sipMsg);        if (unknownExtensionMsg)        {            sptrsipMsg = new UnknownExtensionMsg (*unknownExtensionMsg);        }        break;    }    }    assert (sptrsipMsg != 0);    return sptrsipMsg;}// ----------------- ContentLength Header Methods  -----------------void SipMsg::setContentLength(const SipContentLength& item ) {    Sptr<SipContentLength> contentLength;    myHeaderList.getParsedHeader(contentLength, SIP_CONTENT_LENGTH_HDR);    *contentLength = item;}const SipContentLength&SipMsg::getContentLength( ) const{    Sptr<SipContentLength> contentLength;    myHeaderList.getParsedHeader(contentLength, SIP_CONTENT_LENGTH_HDR);    return *contentLength;}void SipMsg::setContentLength(const Data& item /* Default Arguments*/){    Sptr<SipContentLength> contentLength;    myHeaderList.getParsedHeader(contentLength, SIP_CONTENT_LENGTH_HDR);    contentLength->decode(item);}// ----------------------------------------------------------------------const SipContentDisposition&SipMsg::getContentDisposition( ) const{    Sptr<SipContentDisposition> contentDisposition;    myHeaderList.getParsedHeader(contentDisposition,                                  SIP_CONTENT_DISPOSITION_HDR);    return *contentDisposition;}    void SipMsg::setContentDisposition(const SipContentDisposition& item                               /* Default Arguments*/){    Sptr<SipContentDisposition> contentDisposition;    myHeaderList.getParsedHeader(contentDisposition,                                  SIP_CONTENT_DISPOSITION_HDR);    *contentDisposition = item;}        void SipMsg::setContentDisposition(const Data& item                               /* Default Arguments*/){    Sptr<SipContentDisposition> contentDisposition;    myHeaderList.getParsedHeader(contentDisposition,                                  SIP_CONTENT_DISPOSITION_HDR);    contentDisposition->decode(item);}       // ----------------- ContentType Header Methods  -----------------const  SipContentType&SipMsg::getContentType( ) const{        Sptr<SipContentType> contentType;    myHeaderList.getParsedHeader(contentType, SIP_CONTENT_TYPE_HDR);    return *contentType;    }void SipMsg::setContentType(const SipContentType& item /*default arguments*/ ){    Sptr<SipContentType> contentType;    myHeaderList.getParsedHeader(contentType, SIP_CONTENT_TYPE_HDR);    *contentType = item;}      // ----------------- ContentData Header Methods  -----------------int SipMsg::getNumContentData() const{    return myMimeList.getNumContentData();}Sptr<SipContentData>SipMsg::getContentData( int i/*default arguments*/) const{    return myMimeList.getContentData(i);}void SipMsg::setContentData(const SipContentData* item,                             int index /*default Arguments*/){    assert(item != 0);        myMimeList.setContentData( item->duplicate(), index);}void SipMsg::setNumContentData(int index){    assert(index >= 0);    myMimeList.setNumContentData(index);}void SipMsg::removeContentData(int index /*Default Agruments*/){    myMimeList.removeContentData(index);}voidSipMsg::flushContentData(){    myMimeList.setNumContentData(0);}// ----------------------------------------------------------------------voidSipMsg::forceParse(){    myHeaderList.forceParse();    myMimeList.forceParse();}    ostream&SipMsg::brief(ostream& strm) const{    assert(this);    switch (getType())    {        case SIP_UNKNOWN:        strm <<  "UNKNOWN";        break;        case SIP_INVITE:        strm <<  "INVITE";        break;        case SIP_ACK:        strm <<  "ACK";        break;        case SIP_OPTIONS:        strm <<  "OPTIONS";        break;        case SIP_BYE:        strm <<  "BYE";        break;        case SIP_CANCEL:        strm <<  "CANCEL";        break;        case SIP_REGISTER:        strm <<  "REGISTER";        break;        case SIP_INFO:        strm <<  "INFO";        break;        case SIP_TRANSFER:        strm <<  "TRANSFER";        break;        case SIP_REFER:        strm <<  "REFER";        break;        case SIP_NOTIFY:        strm <<  "NOTIFY";        break;        case SIP_SUBSCRIBE:        strm <<  "SUBSCRIBE";        break;    case SIP_STATUS:    {        const StatusMsg* p = dynamic_cast<const StatusMsg*>(this);        assert (p != 0);        strm << "STATUS (" << p->getStatusLine().getStatusCode() << ")";        break;    }    case SIP_MESSAGE:        strm <<  "MESSAGE ";        if (getNumContentData())        {            Sptr<SipContentData> data = getContentData(0);            int l;            strm << "(" << data->encodeBody(l) << ")";        }        break;    default:        strm << "TYPE NOT PRINTABLE";        break;    }    strm << " ["  << getCallId().getCallIdData() << " : " << getCSeq().getMethod() << " " << getCSeq().getCSeq() << "]";    return strm;}stringSipMsg::briefString() const{    char buff[256];    strstream s(buff, 256);    brief(s);    s << ends;        return s.str();}ostream&Vocal::operator<<(ostream& s, const SipMsg &msg){    s << msg.encode();    return s;}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */

⌨️ 快捷键说明

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