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

📄 sipmsg.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 4 页
字号:
void SipMsg::flushDiversionList(){    myHeaderList.setNumHeaders(SIP_DIVERSION_HDR, 0);}const SipDiversion&SipMsg::getDiversion( int i /*Default Arguments*/) const{    Sptr<SipDiversion> x;    myHeaderList.getParsedHeader(x, SIP_DIVERSION_HDR, i);    return *x;} void SipMsg::setDiversion(const SipDiversion& item, int index /*Default Arguments*/){     Sptr<SipHeader> x = new SipDiversion(item);     myHeaderList.appendHeader(SIP_DIVERSION_HDR, x, index);}void SipMsg::setNumDiversion(int index){    myHeaderList.setNumHeaders(SIP_DIVERSION_HDR, index);}  // ----------------------------------------------------------------------    void SipMsg::setVersion(const Data& ver){    version = ver;}Data SipMsg::getVersion() const {    return version;}// ----------------------------------------------------------------------bool SipMsg::isRetry() const{    return retry;}// ----------------------------------------------------------------------    const SipRetryAfter&SipMsg::getRetryAfter() const{    Sptr<SipRetryAfter> retryAfter;    myHeaderList.getParsedHeader(retryAfter, SIP_RETRY_AFTER_HDR);    return *retryAfter;}	    void SipMsg::setRetryAfter( const SipRetryAfter& newretry){    Sptr<SipRetryAfter> retryAfter;    myHeaderList.getParsedHeader(retryAfter, SIP_RETRY_AFTER_HDR);    *retryAfter  = newretry;    retry = true;}        void SipMsg::setRetryAfter( const Data& newretry){    Sptr<SipRetryAfter> retryAfter;    myHeaderList.getParsedHeader(retryAfter, SIP_RETRY_AFTER_HDR);    retryAfter->decode(newretry);    retry = true;}// ----------------------------------------------------------------------    voidSipMsg::setSendAddress(NetworkAddress & vaddress){    mySendAddress = vaddress;}const NetworkAddress &SipMsg::getSendAddress() const{    return  mySendAddress;}const Data& SipMsg::getReceivedIPName() const{    return recvdIPName;}void SipMsg::setReceivedIPName(const Data& ipName){    if (ipName.length())    {        recvdIPName = ipName;    }}const Data&  SipMsg::getReceivedIPPort(){    return  recvdIPPort;}    void  SipMsg::setReceivedIPPort(const Data& ipPort){    recvdIPPort = ipPort;}// ----------------------------------------------------------------------const SipTransferTo&SipMsg::getTransferTo() const{    Sptr<SipTransferTo> transferTo;    myHeaderList.getParsedHeader(transferTo, SIP_TRANSFER_TO_HDR);    return *transferTo;}void SipMsg::setTransferTo(const SipTransferTo& transTo){    Sptr<SipTransferTo> transferTo;    myHeaderList.getParsedHeader(transferTo, SIP_TRANSFER_TO_HDR);    *transferTo = transTo;}    void SipMsg::setTransferTo(const Data& transTo){    Sptr<SipTransferTo> transferTo;    myHeaderList.getParsedHeader(transferTo, SIP_TRANSFER_TO_HDR);    transferTo->decode(transTo);} // ----------------------------------------------------------------------void SipMsg::setReferredBy(const SipReferredBy& newreferredBy){    Sptr<SipReferredBy> referredBy;    myHeaderList.getParsedHeader(referredBy, SIP_REFERRED_BY_HDR);    *referredBy = newreferredBy;}    void SipMsg::setReferredBy(const Data& newreferredBy){    Sptr<SipReferredBy> referredBy;    myHeaderList.getParsedHeader(referredBy, SIP_REFERRED_BY_HDR);    referredBy->decode(newreferredBy);}boolSipMsg::hasReferredBy() const{    return myHeaderList.getNumHeaders(SIP_REFERRED_BY_HDR);}    const SipReferredBy&SipMsg::getReferredBy() const{    Sptr<SipReferredBy> referredBy;    myHeaderList.getParsedHeader(referredBy, SIP_REFERRED_BY_HDR);    return *referredBy;}// ----------------------------------------------------------------------void SipMsg::setReferTo(const SipReferTo& newreferTo){    Sptr<SipReferTo> referTo;    myHeaderList.getParsedHeader(referTo, SIP_REFER_TO_HDR);    *referTo = newreferTo;}    void SipMsg::setReferTo(const Data& newreferTo){    Sptr<SipReferTo> referTo;    myHeaderList.getParsedHeader(referTo, SIP_REFER_TO_HDR);    referTo->decode(newreferTo);}          const SipReferTo&SipMsg::getReferTo() const{    Sptr<SipReferTo> referTo;    myHeaderList.getParsedHeader(referTo, SIP_REFER_TO_HDR);    return *referTo;}// ----------------------------------------------------------------------void SipMsg::setReplaces(const SipReplaces& newreplaces){    Sptr<SipReplaces> replaces;    myHeaderList.getParsedHeader(replaces, SIP_REPLACES_HDR);    *replaces = newreplaces;}    void SipMsg::setReplaces(const Data& newreplaces){    Sptr<SipReplaces> replaces;    myHeaderList.getParsedHeader(replaces, SIP_REPLACES_HDR);    replaces->decode(newreplaces);}          const SipReplaces&SipMsg::getReplaces() const{    Sptr<SipReplaces> replaces;    myHeaderList.getParsedHeader(replaces, SIP_REPLACES_HDR);    return *replaces;}// ----------------------------------------------------------------------const SipUserAgent&SipMsg::getUserAgent() const{    Sptr<SipUserAgent> userAgent;    myHeaderList.getParsedHeader(userAgent, SIP_USER_AGENT_HDR);    return *userAgent;}    void SipMsg::setUserAgent( const SipUserAgent& newUserAgent){    Sptr<SipUserAgent> userAgent;    myHeaderList.getParsedHeader(userAgent, SIP_USER_AGENT_HDR);    *userAgent = newUserAgent;}    void SipMsg::setUserAgent( const Data& newUserAgent){    Sptr<SipUserAgent> userAgent;    myHeaderList.getParsedHeader(userAgent, SIP_USER_AGENT_HDR);    userAgent->decode(newUserAgent);}// ----------------------------------------------------------------------    void SipMsg::flushAllowList(){    myHeaderList.setNumHeaders(SIP_ALLOW_HDR, 0);    }void SipMsg::addAllow(SipAllow* sipallow){    assert(0); // this will not work, but is needed!}    void SipMsg::removeAllow(int index /*deafult Arguments*/){    myHeaderList.removeHeader(SIP_ALLOW_HDR, index);}const SipAllow&SipMsg::getAllow( int i /* Default Arguments */) const{    Sptr<SipAllow> x;    myHeaderList.getParsedHeader(x, SIP_ALLOW_HDR, i);    return *x;}void SipMsg::setAllow(const SipAllow& item, int index /* Default Arguments */ ){    Sptr<SipHeader> x = new SipAllow(item);    myHeaderList.appendHeader(SIP_ALLOW_HDR, x, index);}    void SipMsg::setAllow(const Data&item, int index /* Default Arguments */ ){    Sptr<SipHeader> x = new SipAllow(item);    myHeaderList.appendHeader(SIP_ALLOW_HDR, x, index);}int SipMsg::getNumAllow() const{     return myHeaderList.getNumHeaders(SIP_ALLOW_HDR);}void SipMsg::setNumAllow(int index){    myHeaderList.setNumHeaders(SIP_ALLOW_HDR, index);}// ----------------------------------------------------------------------#if 0    MethodSipMsg::getMethod(const Data& method){    Method type = SIP_UNKNOWN;    if (method == INVITE_METHOD)    {	type = SIP_INVITE;    }    else if (method == CANCEL_METHOD)    {	type = SIP_CANCEL;    }     else if (method == REFER_METHOD)    {	type = SIP_REFER;    }    else if (method == ACK_METHOD)    {	type = SIP_ACK;    }    else if (method == BYE_METHOD)    {	type = SIP_BYE;    }    else if (method == INFO_METHOD)    {	type = SIP_INFO;    }    else if (method == OPTIONS_METHOD)    {	type = SIP_OPTIONS;    }    else if (method == REGISTER_METHOD)    {	type = SIP_REGISTER;    }    else if (method == TRANSFER_METHOD)    {        type = SIP_TRANSFER;    }    else if (method == SUBSCRIBE_METHOD)    {	type = SIP_SUBSCRIBE;    }    else if (method == NOTIFY_METHOD)    {	type = SIP_NOTIFY;    }    else if (method == "SIP/2.0")    {        type = SIP_STATUS;    }        return type;}#endifboolSipMsg::parse(Data msg){    bool retVal = false;    retVal = parseHeaders(msg);    // at this point, msg should only contain the body, if any    parseMime(msg);    return retVal;}        bool SipMsg::parseHeaders(Data& msg){    return myHeaderList.decode(&msg);}    voidSipMsg::parseMime(Data msg){    //need to pass contentlength, contenttype, contentdisposition.    Sptr < SipContentLength> contlen =         new SipContentLength(getContentLength());    Sptr <SipContentType> contType =         new SipContentType(getContentType());    Sptr <SipContentDisposition> contDisp =         new SipContentDisposition(getContentDisposition());        myMimeList.decode(msg,contlen, contType, contDisp);}SipMsg*SipMsg::decode(Data data){    // skip any leading whitespace    int i = 0;    int maxlen = data.length();    bool done = false;    while(i < maxlen && !done)    {        char c = data[i];        switch(c)        {        case ' ':        case '\r':        case '\n':        case '\t':            ++i;            break;        default:            done = true;        }    }    data = data.substring(i, -1); // this is not implemented, so ....    SipMsg* sipMsg = NULL;    cpLog(LOG_DEBUG_STACK,"Going to decode a sip Msg");        data.removeLWS();    //new parser hooks.    data.removeSpaces();        //call expand.        int sipMethod;    Data tmp = data;    Data startline;    bool getLineFailed = false;    startline = tmp.getLine(&getLineFailed);    if(getLineFailed)    {	// this is a bad message	cpLog(LOG_DEBUG_STACK, "Parse failed.  no newlines found in message");	return 0;    }    char matchedChar = '\0';    Data method = startline.matchChar(" \t", &matchedChar);    sipMethod  = dataToMethod(method);    if(sipMethod == SIP_UNKNOWN)    {        cpLog(LOG_DEBUG_STACK, "failed to match method '%s'",               method.logData());    }    if(sipMethod != SIP_STATUS)    {        // make sure this is really a SIP message        matchedChar = '\0';        Data uri = startline.matchChar(" \t", &matchedChar);                if(matchedChar == '\0')        {            cpLog(LOG_DEBUG_STACK, "Could not split off protocol/version");            return 0;        }        Data version = startline;        matchedChar = '\0';        Data protocol = version.matchChar("/", &matchedChar);        if(matchedChar == '\0')        {            cpLog(LOG_DEBUG_STACK, "Could not find protocol version");            return 0;        }        if( !isEqualNoCase(protocol, "sip"))        {            cpLog(LOG_DEBUG_STACK, "protocol is not SIP");            return 0;        }    }    switch(sipMethod)    {    case SIP_INVITE:	try	{	    sipMsg = new InviteMsg(data);	}	catch (SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the invite msg");	}	break;    case SIP_BYE:	try	{	    sipMsg = new ByeMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the bye msg");	}	break;    case SIP_CANCEL:	try	{	    sipMsg = new CancelMsg(data);	}	catch(SipParserException&)	{	    cpLog(LOG_DEBUG_STACK, "Failed in creating the cancel msg");	}	break;    case SIP_ACK:

⌨️ 快捷键说明

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