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

📄 rasutils.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************
 * rasRouteMessage
 * purpose: Route the message to the right transaction, making sure if
 *          it's incoming, outgoing or IRR.
 * input  : ras             - RAS instance handle
 *          srcAddr         - Source address
 *          chanType        - Type of channel to send through
 *          messageBuf      - Message buffer
 *          messageLength   - Length of received message
 *          messageNodeId   - Node ID of the message.
 *                            If this value is negative, the message is
 *                            decoded and checked, otherwise, the decoded
 *                            message will be processed without calling the
 *                            hook functions.
 *          messageType     - Message type after hook
 *          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 rasRouteMessage(
    IN  rasModule*          ras,
    IN  rasChanType         chanType,
    IN  cmTransportAddress* srcAddr,
    IN  RvUint8*            messageBuf,
    IN  RvUint32            messageLength,
    IN  int                 messageNodeId,
    IN  rasMessages         messageType,
    IN  RvUint32            requestSeqNum,
    OUT void**              hMsgContext)
{
    /* IRR messages are handled differently */
    if (messageType == rasMsgInfoRequestResponse)
        return rasHandleIrr(ras, srcAddr, messageBuf, messageLength, messageNodeId, requestSeqNum, hMsgContext);

    /* Check if it's an incoming or outgoing message */
    switch (rasMessageInfo[messageType].trType)
    {
        case RAS_OUT_TX:
            /* Outgoing transaction reply */
            return rasHandleReply(ras, srcAddr, messageBuf, messageLength, messageNodeId, messageType, requestSeqNum, hMsgContext);
        case RAS_IN_TX:
            /* Incoming transaction request */
            return rasHandleRequest(ras, chanType, srcAddr, messageBuf, messageLength, messageNodeId, messageType, requestSeqNum, hMsgContext);
        default:
            RvLogExcep(&ras->log,
                (&ras->log, "rasRouteMessage: Transaction type unknown for %d", messageType));
            return RV_ERROR_UNKNOWN;
    }
}


/************************************************************************
 * rasCreateCatKey
 * purpose: Create the key struct for CAT from an incoming message
 *          transaction.
 * input  : ras     - RAS instance handle
 *          tx      - Incoming transaction to use
 * output : catKey  - Filled CAT key struct for this transaction
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int rasCreateCatKey(
    IN  rasModule*  ras,
    IN  rasInTx*    tx,
    OUT catStruct*  catKey)
{
    /* Make sure we start empty handed with this CAT key */
    memset(catKey, 0, sizeof(catStruct));

    /* Clear the flags */
    catKey->flags = catRasSrcAddr;

    /* RAS source address */
    memcpy(&catKey->rasSrcAddr, &tx->destAddress, sizeof(cmTransportAddress));

    /* RAS-CRV */
    switch (tx->transactionType)
    {
        int crv;
        case cmRASAdmission:
        case cmRASDisengage:
        case cmRASBandwidth:
        case cmRASInfo:
            if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCRV,
                            0, &crv, NULL) >= 0)
            {
                catKey->rasCRV = (RvUint32)(0x8000^crv);
                catKey->flags |= catRasCRV;
                break;
            }

        case cmRASServiceControl:
        default:
            break;
    }

    /* CallID */
    if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCallID,
                    0, NULL, (char*)catKey->callID) >= 0)
        catKey->flags |= catCallId;

    if (tx->transactionType == cmRASAdmission)
    {
        /* SourceCallSignalAddress */
        if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamSrcCallSignalAddress,
                        0, NULL, (char*)&catKey->srcCallSignalAddr) >= 0)
            catKey->flags |= catSrcCallSignalAddr;

        /* DestCallSignalAddress */
        if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamDestCallSignalAddress,
                        0, NULL, (char*)&catKey->destCallSignalAddr) >= 0)
            catKey->flags |= catDestCallSignalAddr;
    }

    switch (tx->transactionType)
    {
        case cmRASAdmission:
        case cmRASDisengage:
        case cmRASBandwidth:
        case cmRASServiceControl:
        {
            int answerCall;

            /* CID */
            if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamCID,
                            0, NULL, (char*)catKey->cid) >= 0)
                catKey->flags |= catCID;

            /* answerCall */
            if (rasGetParam(ras, (HRAS)tx, cmRASTrStageRequest, cmRASParamAnswerCall,
                            0, &answerCall, NULL) >= 0)
            {
                if (ras->isGatekeeper)
                {
                    catKey->answerCall = !answerCall;
                }
                else
                {
                    /* If we're not a GK, we should take the side the GK is informing us */
                    catKey->answerCall = answerCall;
                }
                catKey->flags |= catAnswerCall;
            }
        }

        case cmRASInfo:
        default:
            break;
    }

    /* Just an address will not be considered as CAT keys by us */
    if (catKey->flags == catRasSrcAddr)
        return RV_ERROR_UNKNOWN;

    return 0;
}


/************************************************************************
 * rasUpdateRegInfo
 * purpose: Update the registration information of our RAS configuration
 *          from an incoming RCF message
 * input  : ras             - RAS instance handle
 *          messageNodeId   - Incoming message that caused this call
 *                            For unregistration, this value will be negative
 * output : none
 * return : none
 ************************************************************************/
void rasUpdateRegInfo(
    IN  rasModule*  ras,
    IN  int         messageNodeId)
{
    int srcNode;

    /* GK addresses - remove if we have to */
    if (!RV_PVT_NODEID_IS_VALID(messageNodeId))
    {
        if (RV_PVT_NODEID_IS_VALID(ras->gatekeeperRASAddress))
        {
            pvtDelete(ras->hVal, ras->gatekeeperRASAddress);
            ras->gatekeeperRASAddress = RV_PVT_INVALID_NODEID;
        }
        if (RV_PVT_NODEID_IS_VALID(ras->gatekeeperCallSignalAddress))
        {
            pvtDelete(ras->hVal, ras->gatekeeperCallSignalAddress);
            ras->gatekeeperCallSignalAddress = RV_PVT_INVALID_NODEID;
        }

        /* Reset terminalAlias list - we're not registered anymore */
        if (RV_PVT_NODEID_IS_VALID(ras->termAliasesNode))
        {
            pvtDelete(ras->hVal, ras->termAliasesNode);
            ras->termAliasesNode = RV_PVT_INVALID_NODEID;
        }
    }

    /* GK callSignalAddress*/
    if (messageNodeId >= 0)
    {
        if (ras->gatekeeperCallSignalAddress < 0)
            ras->gatekeeperCallSignalAddress = pvtAddRoot(ras->hVal, NULL, 0, NULL);
        __pvtGetNodeIdByFieldIds(srcNode,ras->hVal,messageNodeId, {_anyField _q931(callSignalAddress) _anyField LAST_TOKEN});
        pvtSetTree(ras->hVal, ras->gatekeeperCallSignalAddress, ras->hVal, srcNode);
    }

    /* terminalAlias */
    if (!RV_PVT_NODEID_IS_VALID(messageNodeId))
    {
        /* Delete the terminal's aliases for now */
        if (ras->termAliasesNode >= 0)
            pvtDelete(ras->hVal, ras->termAliasesNode);
        ras->termAliasesNode = RV_PVT_INVALID_NODEID;
    }
    else
    {
        if (ras->termAliasesNode < 0)
        {
            ras->termAliasesNode = pvtAddRoot(ras->hVal, NULL, 0, NULL);
            __pvtGetNodeIdByFieldIds(srcNode, ras->hVal, ras->confNode, {_q931(registrationInfo) _q931(terminalAlias) LAST_TOKEN});
            if (srcNode >= 0)
                pvtSetTree(ras->hVal, ras->termAliasesNode, ras->hVal, srcNode);
        }
        __pvtGetNodeIdByFieldIds(srcNode, ras->hVal, messageNodeId, {_anyField _q931(terminalAlias) LAST_TOKEN});
        pvtAddChildsIfDiffer(ras->hVal, ras->termAliasesNode, ras->hVal, srcNode, RV_FALSE);
    }

    /* endpointIdentifier */
    __pvtGetByFieldIds(srcNode, ras->hVal, messageNodeId, {_anyField _q931(endpointIdentifier) LAST_TOKEN}, NULL, &ras->epIdLen, NULL);
    if (srcNode >= 0)
        pvtGetString(ras->hVal, srcNode, ras->epIdLen, ras->epId);
    else
        ras->epIdLen = 0;

    /* gatekeeperIdentifier */
    if(messageNodeId >= 0)
    {
        __pvtGetByFieldIds(srcNode, ras->hVal, messageNodeId, {_anyField _q931(gatekeeperIdentifier) LAST_TOKEN}, NULL, (RvInt32 *)&ras->gkIdLen, NULL);
        if (srcNode >= 0)
            pvtGetString(ras->hVal, srcNode, ras->gkIdLen, ras->gkId);
        else
            ras->gkIdLen = 0;
    }
    else
    {
        __pvtGetByFieldIds(srcNode, ras->hVal, ras->confNode, {_q931(registrationInfo) _q931(gatekeeperIdentifier) LAST_TOKEN}, NULL, (RvInt32 *)&ras->gkIdLen, NULL);
        if (srcNode >= 0)
            pvtGetString(ras->hVal, srcNode, ras->gkIdLen, ras->gkId);
        else
            ras->gkIdLen = 0;
    }

    /* Make sure the default messages of the RAS are also updated */
    cmiRASUpdateRegInfo((HRASMGR)ras, RV_FALSE);
}


/************************************************************************
 * rasUpdatePartUnreg
 * purpose: Update the registration information of our RAS configuration
 *          from an outgoing partial URQ message.
 * input  : ras             - RAS instance handle
 *          messageNodeId   - Outgoing message whose approval caused this
 *                            function to be called.
 * output : none
 * return : none
 ************************************************************************/
void rasUpdatePartUnreg(
    IN  rasModule*  ras,
    IN  int         messageNodeId)
{
    int removedAliases, currentAlias, aliasToRemove;;

    if (ras->termAliasesNode < 0)
        /* no aliases, one wonders how we got here. anyway, let's return before anyone notices */
        return;
    __pvtGetNodeIdByFieldIds(removedAliases, ras->hVal, messageNodeId, {_q931(unregistrationRequest) _q931(endpointAlias) LAST_TOKEN});

    for(aliasToRemove=pvtChild(ras->hVal, removedAliases); aliasToRemove>=0; aliasToRemove=pvtBrother(ras->hVal, aliasToRemove))
        for(currentAlias=pvtChild(ras->hVal, ras->termAliasesNode); currentAlias>=0; currentAlias=pvtBrother(ras->hVal, currentAlias))
            if(pvtCompareTree(ras->hVal, currentAlias, ras->hVal, aliasToRemove)>=0)
            {
                pvtDelete(ras->hVal, currentAlias);
                break; /* only from the first loop */
            }
}




#ifdef __cplusplus
}
#endif


⌨️ 快捷键说明

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