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

📄 rasirr.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
    }
}



/************************************************************************
 *
 *                              Public functions
 *
 ************************************************************************/


/************************************************************************
 * rasHandleIrr
 * purpose: Handle an incoming IRR message.
 *          This function first has to determine if this is a solicited
 *          or an unsolicited IRR and then handle it through incoming or
 *          outgoing transactions.
 * input  : ras             - RAS module to use
 *          srcAddress      - Address of the sender
 *          messageBuf      - The message buffer to send
 *          messageLength   - The length of the message in bytes
 *          messageNodeId   - Node ID of message root. If negative, then
 *                            message is decoded from given buffer and hook
 *                            is called
 *          requestSeqNum   - Sequence number in decoded message after hook
 * output : hMsgContext     - Incoming message context. Used mostly by security
 *                            If the returned value is different than NULL,
 *                            then the message context is not used by the
 *                            transaction and should be released
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int rasHandleIrr(
    IN  rasModule*      ras,
    IN  cmRASTransport* srcAddress,
    IN  RvUint8*        messageBuf,
    IN  RvUint32        messageLength,
    IN  int             messageNodeId,
    IN  RvUint32        requestSeqNum,
    OUT void**          hMsgContext)
{
    int         status = 0;
    RvBool      isSolicited = RV_FALSE;
    rasMessages newType;
    RvUint32    newSeqNum;

    /* See if we have to decode this message or not */
    if (messageNodeId < 0)
    {
        status =
            rasDecodeAndRecv(ras, messageBuf, messageLength, RV_FALSE, srcAddress,
                             &messageNodeId, &newType, &newSeqNum, hMsgContext);

        /* Make sure the application didn't change the sequence number or type of message */
        if ((status >= 0) && ((newType != rasMsgInfoRequestResponse) || (newSeqNum != requestSeqNum)))
        {
            /* Reroute the message to check it again... */
            return rasRouteMessage(ras, rasChanUnicast, srcAddress, messageBuf, messageLength, messageNodeId, newType, newSeqNum, hMsgContext);
        }
    }

    /* Check if message is solicited or unsolicited */
    if (status >= 0)
        status = rasIsSolicited(ras, messageNodeId, srcAddress, requestSeqNum, &isSolicited);

    if (status < 0)
    {
        if (messageNodeId >= 0)
            pvtDelete(ras->hVal, messageNodeId);
        return status;
    }

    if (isSolicited)
    {
        /* We've got a Solicited IRR - just handle it as a regular reply message */
        return rasHandleReply(ras, srcAddress, messageBuf, messageLength, messageNodeId, rasMsgInfoRequestResponse, requestSeqNum, hMsgContext);
    }


    /* If we're here, then we've got an unsolicited IRR.
       The problem we're facing is deciding whether this IRR is for a dummy request
       which is handled by the outgoing transactions as responses, or an incoming
       request transaction. */

    {
        HRAS        tx;
        HCALL       hsCall;
        RVHCATCALL  hCatCall;

        /* Find the call handle for this unsolicited IRR */
        hsCall = rasFindCallHandleForIrr(ras, messageNodeId, srcAddress);
        if (hsCall == NULL)
        {
            /* No call was found for this IRR - ignore it at this point */
            RvLogError(&ras->log,
                (&ras->log, "rasHandleIrr: No call found for unsolicited IRR message - ignoring message (root=%d)", messageNodeId));
            return RV_ERROR_UNKNOWN;
        }

        hCatCall = cmiGetCatForCall(hsCall);

        /* Find out if this call has a dummy request on it */
        tx = catGetUnsolicitedIRR(ras->hCat, hCatCall);
        if (tx != NULL)
        {
            /* There's a dummy transaction - handle as a response to it */
            emaLock((EMAElement)tx);

            return rasHandleTxResponse(ras, (rasOutTx *)tx, messageNodeId, rasMsgInfoRequestResponse, hMsgContext);
        }
        else
        {
            /* No dummy transaction - handle as an incoming request */
            return rasHandleRequest(ras, rasChanUnicast, srcAddress, messageBuf, messageLength, messageNodeId, rasMsgInfoRequestResponse, requestSeqNum, hMsgContext);
        }
    }
}


/************************************************************************
 * rasSetIrrFields
 * purpose: Set the fields inside IRR messages, to be sent later on
 * input  : ras         - RAS module to use
 *          hsRas       - RAS transaction to set
 *          irrNode     - node on which to build the IRR
 *          hsCall      - Call related with the transaction
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int rasSetIrrFields(
    IN  rasModule*      ras,
    IN  HRAS            hsRas,
    IN  RvPvtNodeId     irrNode,
    IN  HCALL           hsCall)
{
    char                callid[16];
    RvInt32             rasCrv, callidLen, iVal;
    int                 ret;
    int                 rootId, destNodeId;
    RvBool              isOrigin;
    cmTransportAddress  addr;

    isOrigin = cmCallGetOrigin(hsCall,NULL);

    /* Make sure we've got a response node */
    rasSetParam(ras, hsRas, cmRASTrStageConfirm, cmRASParamEmpty, 0, 0, NULL);

    __pvtBuildByFieldIds(rootId, ras->hVal, irrNode,
        {_q931(infoRequestResponse) _q931(perCallInfo) _nul(1) LAST_TOKEN}, 0, NULL);

    /* callReferenceValue */
    if (cmCallGetParam(hsCall, cmParamRASCRV, 0, &rasCrv, NULL) >= 0)
        pvtAdd(ras->hVal, rootId, __q931(callReferenceValue), rasCrv, NULL, NULL);

    /* conferenceID */
    callidLen = sizeof(callid);
    if (cmCallGetParam(hsCall, cmParamCID, 0, &callidLen, callid) >= 0)
        pvtAdd(ras->hVal, rootId, __q931(conferenceID), callidLen, callid, NULL);

    /* callIdentifier */
    callidLen = sizeof(callid);
    if (cmCallGetParam(hsCall, cmParamCallID, 0, &callidLen, callid) >= 0)
    {
        __pvtBuildByFieldIds(ret, ras->hVal, rootId, {_q931(callIdentifier) _q931(guid) LAST_TOKEN}, callidLen, callid);
    }

    /* originator */
    pvtAdd(ras->hVal, rootId, __q931(originator), (RvInt32)isOrigin, NULL, NULL);

    /* callType */
    if (cmCallGetParam(hsCall, cmParamCallType, 0, &iVal, NULL) >= 0)
    {
        destNodeId = pvtAdd(ras->hVal, rootId, __q931(callType), 0, NULL, NULL);
        switch ((cmCallType)iVal)
        {
            case cmCallTypeP2P:     pvtAdd(ras->hVal, destNodeId, __q931(pointToPoint), 0, NULL, NULL); break;
            case cmCallTypeOne2N:   pvtAdd(ras->hVal, destNodeId, __q931(oneToN), 0, NULL, NULL); break;
            case cmCallTypeN2One:   pvtAdd(ras->hVal, destNodeId, __q931(nToOne), 0, NULL, NULL); break;
            case cmCallTypeN2Nw:    pvtAdd(ras->hVal, destNodeId, __q931(nToN), 0, NULL, NULL); break;
        }
    }

    /* bandWidth */
    if (cmCallGetParam(hsCall, cmParamRate, 0, &iVal, NULL) >= 0)
        pvtAdd(ras->hVal, rootId, __q931(bandWidth), iVal/50, NULL, NULL);

    /* callModel */
    destNodeId = pvtAdd(ras->hVal, rootId, __q931(callModel), 0, NULL, NULL);
    if (cmIsRoutedCall(hsCall))
        pvtAdd(ras->hVal, destNodeId, __q931(gatekeeperRouted), 0, NULL, NULL);
    else
        pvtAdd(ras->hVal, destNodeId, __q931(direct), 0, NULL, NULL);

    /* h245, substituteConfIDs */
    pvtAdd(ras->hVal, rootId, __q931(h245), 0, NULL, NULL);
    pvtAdd(ras->hVal, rootId, __q931(substituteConfIDs), 0, NULL, NULL);

    /* callSignaling */
    destNodeId = pvtAdd(ras->hVal, rootId, __q931(callSignaling), 0, NULL, NULL);
    if (isOrigin)
    {
        if (cmCallGetParam(hsCall, cmParamSrcCallSignalAddress, 0, NULL, (char*)&addr) >= 0)
            cmTAToVt(ras->hVal, pvtAdd(ras->hVal, destNodeId, __q931(recvAddress), 0, NULL, NULL), &addr);
        if (cmCallGetParam(hsCall, cmParamDestCallSignalAddress, 0, NULL, (char*)&addr) >= 0)
            cmTAToVt(ras->hVal, pvtAdd(ras->hVal, destNodeId, __q931(sendAddress), 0, NULL, NULL), &addr);
    }
    else
    {
        if (cmCallGetParam(hsCall, cmParamSrcCallSignalAddress, 0, NULL, (char*)&addr) >= 0)
            cmTAToVt(ras->hVal, pvtAdd(ras->hVal, destNodeId, __q931(sendAddress), 0, NULL, NULL), &addr);
        if (cmCallGetParam(hsCall, cmParamDestCallSignalAddress, 0, NULL, (char*)&addr) >= 0)
            cmTAToVt(ras->hVal, pvtAdd(ras->hVal, destNodeId, __q931(recvAddress), 0, NULL, NULL), &addr);
    }

    return 0;
}



#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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