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

📄 sipconnection.cpp

📁 基于sipfoundy 公司开发的sipx协议API
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    return(responseSent);}UtlBoolean SipConnection::redirect(const char* forwardAddress){    UtlBoolean redirectSent = FALSE;    if(inviteMsg && !inviteFromThisSide &&        (getState() == CONNECTION_OFFERING ||        getState() == CONNECTION_ALERTING))    {        UtlString targetUrl;        UtlString dummyFrom;        const char* callerDisplayName = NULL;        const char* targetCallId = NULL;        buildFromToAddresses(forwardAddress, targetCallId, callerDisplayName,            dummyFrom, targetUrl);        // Send a redirect message        SipMessage redirectResponse;        redirectResponse.setForwardResponseData(inviteMsg,            targetUrl.data());        redirectSent = send(redirectResponse);        setState(CONNECTION_DISCONNECTED, CONNECTION_REMOTE, CONNECTION_CAUSE_REDIRECTED);        setState(CONNECTION_DISCONNECTED, CONNECTION_LOCAL, CONNECTION_CAUSE_REDIRECTED);        fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_REDIRECTED) ;        targetUrl = OsUtil::NULL_OS_STRING;        dummyFrom = OsUtil::NULL_OS_STRING;    }    return(redirectSent);}UtlBoolean SipConnection::hangUp(){    return(doHangUp());}UtlBoolean SipConnection::hold(){    UtlBoolean messageSent = FALSE;    SdpSrtpParameters srtpParams;    // If the call is connected and we are not in the middle of a SIP transaction    if(mpMediaInterface != NULL &&             inviteMsg && getState() == CONNECTION_ESTABLISHED &&            reinviteState == ACCEPT_INVITE &&            mTerminalConnState!=PtTerminalConnection::HELD)    {        UtlString rtpAddress;        int receiveRtpPort;        int receiveRtcpPort;        int receiveVideoRtpPort;        int receiveVideoRtcpPort;        SdpCodecFactory supportedCodecs;        mpMediaInterface->getCapabilities(mConnectionId,            rtpAddress,            receiveRtpPort,            receiveRtcpPort,            receiveVideoRtpPort,    // VIDEO: TODO            receiveVideoRtcpPort,            supportedCodecs,            srtpParams);        int numCodecs = 0;        SdpCodec** codecsArray = NULL;        supportedCodecs.getCodecs(numCodecs, codecsArray);        // Build an INVITE with the RTP address in the SDP of 0.0.0.0        SipMessage holdMessage;        holdMessage.setReinviteData(inviteMsg,            mRemoteContact,            mLocalContact.data(),            inviteFromThisSide,            mRouteField,            "0.0.0.0",            receiveRtpPort,            receiveRtcpPort,            receiveVideoRtpPort,            receiveVideoRtcpPort,            ++lastLocalSequenceNumber,            numCodecs,            codecsArray,            &srtpParams,            mDefaultSessionReinviteTimer);        // Set the asserted Identity if provided        if(!mLocalPAssertedIdentity.isNull())        {            holdMessage.addPAssertedIdentityField(mLocalPAssertedIdentity);        }        if(inviteMsg)         {            delete inviteMsg;        }        inviteMsg = new SipMessage(holdMessage);        inviteFromThisSide = TRUE;        if(send(holdMessage))        {            messageSent = TRUE;            // Disallow INVITEs while this transaction is taking place            reinviteState = REINVITING;            mFarEndHoldState = TERMCONNECTION_HOLDING;        }        // Free up the codec copies and array        for(int codecIndex = 0; codecIndex < numCodecs; codecIndex++)        {            delete codecsArray[codecIndex];            codecsArray[codecIndex] = NULL;        }        delete[] codecsArray;        codecsArray = NULL;    }    return(messageSent);}UtlBoolean SipConnection::offHold(){    return(doOffHold(FALSE));}UtlBoolean SipConnection::renegotiateCodecs(){    return(doOffHold(TRUE));}UtlBoolean SipConnection::changeLocalIdentity(const UtlString& newLocalIdentity,                                              const UtlBoolean& shouldSignalIdentityChangeNow){    UtlBoolean returnStatus = TRUE;    mLocalPAssertedIdentity = newLocalIdentity;    if(shouldSignalIdentityChangeNow)    {        // Send a reINVITE now, the new identity will get picked up in        // the construction of the INVITE        returnStatus = renegotiateCodecs();    }    return(returnStatus);}UtlBoolean SipConnection::doOffHold(UtlBoolean forceReInvite){    UtlBoolean messageSent = FALSE;    SdpSrtpParameters srtpParams;    // If the call is connected and    // we are not in the middle of a SIP transaction    if(mpMediaInterface != NULL &&             inviteMsg && getState() == CONNECTION_ESTABLISHED &&            reinviteState == ACCEPT_INVITE &&            (mTerminalConnState == PtTerminalConnection::HELD ||            (forceReInvite &&            mTerminalConnState == PtTerminalConnection::TALKING)))    {        UtlString rtpAddress;        int receiveRtpPort;        int receiveRtcpPort;        int receiveVideoRtpPort;        int receiveVideoRtcpPort;        SdpCodecFactory supportedCodecs;        mpMediaInterface->getCapabilities(mConnectionId,            rtpAddress,            receiveRtpPort,            receiveRtcpPort,            receiveVideoRtpPort,    // VIDEO: TODO            receiveVideoRtcpPort,            supportedCodecs,            srtpParams);        int numCodecs = 0;        SdpCodec** rtpCodecs = NULL;        supportedCodecs.getCodecs(numCodecs, rtpCodecs);        // Build an INVITE with the RTP address in the SDP        // as the real address#ifdef TEST_PRINT        osPrintf("SipConnection::offHold rtpAddress: %s\n",            rtpAddress.data());#endif        SipMessage offHoldMessage;        offHoldMessage.setReinviteData(inviteMsg,            mRemoteContact,            mLocalContact.data(),            inviteFromThisSide,            mRouteField,            rtpAddress.data(),            receiveRtpPort,            receiveRtcpPort,            receiveVideoRtpPort,            receiveVideoRtcpPort,            ++lastLocalSequenceNumber,            numCodecs,            rtpCodecs,            &srtpParams,            mDefaultSessionReinviteTimer);        // Set the asserted Identity if provided        if(!mLocalPAssertedIdentity.isNull())        {            offHoldMessage.addPAssertedIdentityField(mLocalPAssertedIdentity);        }        // Free up the codec copies and array        for(int codecIndex = 0; codecIndex < numCodecs; codecIndex++)        {            delete rtpCodecs[codecIndex];            rtpCodecs[codecIndex] = NULL;        }        delete[] rtpCodecs;        rtpCodecs = NULL;        if(inviteMsg)        {            delete inviteMsg;        }        inviteMsg = new SipMessage(offHoldMessage);        inviteFromThisSide = TRUE;        if(send(offHoldMessage))        {            messageSent = TRUE;            // Disallow INVITEs while this transaction is taking place            reinviteState = REINVITING;            // If we are doing a forced reINVITE            // there are no state changes            // Otherwise signal the offhold state changes            if(!forceReInvite)            {                mFarEndHoldState = TERMCONNECTION_TALKING;                if (mpCall->getCallType() != CpCall::CP_NORMAL_CALL)                {                    mpCall->setCallType(CpCall::CP_NORMAL_CALL);                }                setState(CONNECTION_ESTABLISHED, CONNECTION_REMOTE, CONNECTION_CAUSE_UNHOLD);                // fireSipXEvent(CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE) ;            }        }    }    return(messageSent);}UtlBoolean SipConnection::originalCallTransfer(UtlString& dialString,                                               const char* transferControllerAddress,                                               const char* targetCallId,                                               bool        holdBeforeTransfer                                               ){    UtlBoolean ret = FALSE;    mIsReferSent = FALSE;#ifdef TEST_PRINT    UtlString remoteAddr;    getRemoteAddress(&remoteAddr);    UtlString conState;    getStateString(getState(), &conState);    osPrintf("SipConnection::originalCallTransfer on %s %x %x:\"%s\" state: %d\n",        remoteAddr.data(), inviteMsg, dialString.data(),        dialString.length() ? dialString.data() : "", conState.data());#endif    if(inviteMsg && dialString && *dialString &&        getState() == CONNECTION_ESTABLISHED)    {        // If the transferee (the party at the other end of this        // connection) supports the REFER method        const char* callerDisplayName = NULL;        // If blind transfer        {            UtlString targetUrl;            UtlString dummyFrom;            buildFromToAddresses(dialString, targetCallId, callerDisplayName,                dummyFrom, targetUrl);            dialString = targetUrl;            //alsoUri.append(";token1");        }        if(isMethodAllowed(SIP_REFER_METHOD))        {            fireSipXEvent(CALLSTATE_TRANSFER, CALLSTATE_TRANSFER_INITIATED) ;            mTargetCallConnectionAddress = dialString;            mTargetCallId = targetCallId;            if (    holdBeforeTransfer                && (   mFarEndHoldState == TERMCONNECTION_TALKING                    || mFarEndHoldState == TERMCONNECTION_NONE                    ))            {               // If the connection is not already on hold, do a hold               // first and then do the REFER transfer                mHoldCompleteAction = CpCallManager::CP_BLIND_TRANSFER;                //need to do a remote hold first                // Then after that is complete do the REFER                hold();                ret = TRUE;            }            else            {                // Send a REFER to tell the transferee to                // complete a blind transfer                doBlindRefer();                ret = mIsReferSent;            }        }                else        {            fireSipXEvent(CALLSTATE_TRANSFER, CALLSTATE_TRANSFER_FAILURE) ;#if 0            // Use the old BYE Also method of transfer            doHangUp(dialString.data(),                transferControllerAddress);            mTargetCallConnectionAddress = dialString;            ret = TRUE;#endif                    }    }    return(ret);}void SipConnection::doBlindRefer(){    // Send a REFER message    SipMessage referRequest;    lastLocalSequenceNumber++;    referRequest.setReferData(inviteMsg,        inviteFromThisSide,        lastLocalSequenceNumber,        mRouteField.data(),        mLocalContact.data(),        mRemoteContact.data(),        mTargetCallConnectionAddress.data(),        // The following keeps the target call id on the        // transfer target the same as the consultative call        //mTargetCallId);        // The following does not set the call Id on the xfer target        "");    mIsReferSent = send(referRequest);}UtlBoolean SipConnection::targetCallBlindTransfer(const char* dialString,                                                  const char* transferControllerAddress){    // This should never get here    unimplemented("SipConnection::targetCallBlindTransfer");    return(FALSE);}UtlBoolean SipConnection::transferControllerStatus(int connectionState, int response){    if (connectionState == Connection::CONNECTION_FAILED)    {        setState(connectionState, CONNECTION_REMOTE);    }       // It should never get here    unimplemented("SipConnection::transferControllerStatus");    return(FALSE);}UtlBoolean SipConnection::transfereeStatus(int callState, int returnCode){    UtlBoolean referResponseSent = FALSE;#ifdef TEST_PRINT    osPrintf("SipConnection::transfereeStatus callType: %d referMessage: %x\n",        mpCall->getCallType(), mReferMessage);#endif    // If this call and connection received a REFER request    if(mpCall->getCallType() ==        CpCall::CP_TRANSFEREE_ORIGINAL_CALL &&        mReferMessage)    {        UtlString transferMethod;        mReferMessage->getRequestMethod(&transferMethod);        // REFER type transfer        if(transferMethod.compareTo(SIP_REFER_METHOD) == 0)        {            int num;

⌨️ 快捷键说明

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