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

📄 transutil.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* lock the rpool */
    RvLockGet(&transGlobals->lockHash);

    /* get the pointer to the next message */
    rpoolCopyToExternal(transGlobals->messagesRPool, (void*)&nextMsg, firstMsg, 0, MSG_HEADER_SIZE);

    /* delete the first message */
    rpoolFree(transGlobals->messagesRPool, firstMsg);

    /* set the next message as the new first message */
    if (isTunneled)
        session->firstMessage = nextMsg;
    else
        host->firstMessage = nextMsg;

    if (rpoolStatistics(transGlobals->messagesRPool, &poolSize, NULL, &allocatedSize) == RV_OK)
    {

        RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
                "extractMessageFromPool[isTunneled=%d] statistics: max=%d, available=%d, allocated=%d",
                isTunneled, poolSize, allocatedSize));

        if (transGlobals->pendingList)
        {
            int numOfSessionsToRelease;
            if ((numOfSessionsToRelease = (poolSize-allocatedSize)/transGlobals->codingBufferSize) > 0)
                notifyPendingSessions(transGlobals, numOfSessionsToRelease);
        }
    }

    RvLogDebug(&transGlobals->hLog, (&transGlobals->hLog,
                  "extractMessageFromPool[isTunneled=%d] first = %x last = %x",
                  isTunneled, host->firstMessage, host->lastMessage));

    /* update num of messages kept in rpool for sending */
    transGlobals->curUsedNumOfMessagesInRpool--;

    /* unlock the rpool */
    RvLockRelease(&transGlobals->lockHash);

    return nextMsg;
}

/**************************************************************************************
 * processQ931OutgoingMessage
 *
 * Purpose: This routine gets a decoded outgoing Q.931 message and modifies it according to
 *          the different tasks at hand:
 *          - Add fields such as multiplexing flags.
 *          - Insert H.245 addresses, if necessary to the messages.
 *          - Insert tunneled messages (H.245, Annex M, Annex L).
 * Input:   session     - The session which wants to send the message.
 *          host        - The host on which the message is to be sent.
 *          pvtNode     - The message.
 *
 * Output:  None.
 *
 * Returned Value: RV_TRUE - send the message, RV_FALSE - don't send it.
 *
 **************************************************************************************/
RvBool processQ931OutgoingMessage(
    IN    cmTransSession    *session,
    IN    cmTransHost       *host,
    INOUT int               pvtNode)
{
    cmTransGlobals  *transGlobals;
    int             messageBodyNode;
    int             msgType;

    /* retrieve the transport module global area */
    transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);

    /* check what type of Q.931 message we have here */
    msgType = pvtGetChildTagByPath(transGlobals->hPvt, pvtNode, "message", 1);
    if (msgType < 0)
    {
        RvLogError(&transGlobals->hLog,
            (&transGlobals->hLog,
                "processQ931OutgoingMessage failed to get message type tag"));
        return RV_FALSE;
    }

    /* position on the UU-IE part of the message */
    __pvtGetNodeIdByFieldIds(   messageBodyNode,
                                transGlobals->hPvt,
                                pvtNode,
                                {   _q931(message)
                                    _anyField
                                    _q931(userUser)
                                    _q931(h323_UserInformation)
                                    _q931(h323_uu_pdu)
                                    LAST_TOKEN
                                });
    /* if the message doesn't have UU-IE part, we have nothing to do with it, just
       send it */
    if (messageBodyNode < 0)
        return RV_TRUE;

    /***********************************************************************************/
    /* for first message on the session get the CRV and callID and insert to the hash  */
    /***********************************************************************************/
    if (!session->firstMessageSent)
    {
        if (!findSessionByMessage(transGlobals, host, pvtNode, RV_FALSE, &session))
        {
            RvLogError(&transGlobals->hLog,
                (&transGlobals->hLog,
                    "processQ931OutgoingMessage failed to locate session in HASH, ignore emssage"));
            return RV_FALSE;
        }
        else
        if (session)
        {
            /* if session is NULL here this means that we are sending a CRV==0
               message so no session is associated with it */
            if ( (msgType != cmQ931setupAck) &&
                 (msgType != cmQ931information) &&
                 (msgType != cmQ931progress) &&
                 (msgType != cmQ931status) &&
                 (msgType != cmQ931statusInquiry)
                )
                /* mark that we've already sent a call that could have approved tunneling */
                session->firstMessageSent = RV_TRUE;
        }
    }

    /***********************************************************************/
    /* set the multipleCalls and maintainConnection parameters (multiplexing stuff) */
    /***********************************************************************/
    setMultiplexedParams(transGlobals, session, host, pvtNode, msgType);

    /***********************************************************************/
    /* check the fast start state of the session */
    /***********************************************************************/
    if ( (session) && !emaWasDeleted((EMAElement)session) )
        setTheFastStartStateByMessage(transGlobals, session, messageBodyNode, msgType);

    /***********************************************************************/
    /* check the parallel tunneling state of the session  */
    /***********************************************************************/
    if ( (session) && !emaWasDeleted((EMAElement)session) )
        setTheParallelTunnelingStateByMessage(transGlobals,
                                              session,
                                              msgType,
                                              messageBodyNode,
                                              RV_TRUE /* outgoing */);

    /***********************************************************************/
    /* handling whether to start listenning or establish connection for H.245 */
    /***********************************************************************/
    if ( (session) && !emaWasDeleted((EMAElement)session) )
        if (!session->notEstablishControl)
            if (!determineIfToOpenH245(RV_TRUE /* outgoing message */,
                                       transGlobals,
                                       session,
                                       messageBodyNode,
                                       msgType))
                return RV_FALSE;

    /***********************************************************************/
    /* handle reporting of a new H.245 connection to the user    */
    /***********************************************************************/
    if ( (session) && !emaWasDeleted((EMAElement)session) )
        if (!session->notEstablishControl)
            reportH245(RV_TRUE /* outgoing message */,
            transGlobals,
            session,
            messageBodyNode,
            msgType);

    /***********************************************************************/
    /* handle insertion of tunneled H.245 messages to the Q.931 message    */
    /***********************************************************************/
    if ( (session) && !emaWasDeleted((EMAElement)session) )
    {
        insertH245TunnelingFlag(transGlobals, session, messageBodyNode, msgType);
        if (!session->notEstablishControl)
            insertH245TunneledMessages(transGlobals, session, messageBodyNode, msgType);
        insertH450TunneledMessages(transGlobals, session, messageBodyNode, msgType);
        insertAnnexLTunneledMessages(transGlobals, session, messageBodyNode);
        insertAnnexMTunneledMessages(transGlobals, session, messageBodyNode);
    }

    return RV_TRUE;
}

/**************************************************************************************
 * processH245OutgoingMessage
 *
 * Purpose: This routine gets a decoded outgoing H.245 message and modifies it according to
 *          the different tasks at hand:
 *          - If tunneling: encodes it and puts it into the H.245 tunneled messages sylo
 *                          and inhibits its sending.
 *          - If not tunneling: do nothing.
 *
 * Input:   session     - The session which wants to send the message.
 *          host        - The host on which the message is to be sent.
 *          pvtNode     - The message.
 *
 * Output:  None.
 *
 * Returned Value: RV_TRUE - send the message, RV_FALSE - don't send it.
 *
 **************************************************************************************/
RvBool processH245OutgoingMessage(IN    cmTransSession    *session,
                                IN    cmTransHost       *host,
                                INOUT int               pvtNode)
{
    cmTransGlobals  *transGlobals;
    TRANSERR        res;
    HRPOOLELEM      msg;
    RvUint8         *buffer;
    int             encMsgSize;

    /* retrieve the transport module global area */
    transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);

    /* find out if we are still in tunneling procedure */
    if (!host)
    {
        RvBool addToTop;
        int  node;

        /* determine if this is a TCS Ack in parallel tunneling response,
           in that case put it first */
        __pvtGetNodeIdByFieldIds(node, transGlobals->hPvt, pvtNode,
                                { _h245(response)
                                  _h245(terminalCapabilitySetAck)
                                  LAST_TOKEN});

        if ( (node >=0) && (session->parallelTunnelingState == parllApproved) )
            addToTop = RV_TRUE;
        else
            addToTop = RV_FALSE;

        /* Start the encoding process */
        getEncodeDecodeBuffer(transGlobals->codingBufferSize, &buffer);
        res = transEncodeMessage(host,
                                 session,
                                 transGlobals,
                                 pvtNode,
                                 buffer,
                                 &encMsgSize);
        if (res != cmTransOK)
            return RV_FALSE;

        /* save the tunneled encoded message for later transmit */
        msg = saveMessageToPool(transGlobals,
                                (void *)session,
                                buffer,
                                encMsgSize,
                                RV_TRUE,
                                addToTop,
                                session->CRV);
        if (!msg)
        {
            RvLogInfo(&transGlobals->hLog,
                (&transGlobals->hLog,
                    "processH245OutgoingMessage failed on tunneled message - no buffers"));
            return RV_FALSE;
        }

    }
    else
        return RV_TRUE;

    return RV_FALSE;
}
/**************************************************************************************
 * processOutgoingMessage
 *
 * Purpose: This routine gets a decoded outgoing message and modifies it according to
 *          the different tasks at hand:
 *          - Add fields to Q.931 messages, such as multiplexing flags.
 *          - Save H.245 tunneled messages and eliminate their actual sending
 *          - Insert H.245 addresses, if necessary to the messages.
 *          - Insert H.245 tunneled messages.
 * Input:   session     - The session which wants to send the message.
 *          host        - The host on which the message is to be sent.
 *          pvtNode     - The message.
 *          type        - The type of the message (Q.931/H.245)
 *
 * Output:  None.
 *
 * Returned Value: RV_TRUE - send the message, RV_FALSE - don't send it.
 *
 **************************************************************************************/
RvBool processOutgoingMessage(IN    cmTransSession    *session,
                            IN    cmTransHost       *host,
                            INOUT int               pvtNode,
                            IN    TRANSTYPE         type)
{
    cmTransGlobals  *transGlobals;
    RvBool          sendMessage = RV_TRUE;

    /* retrieve the transport module global area */
    transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);

    switch (type)
    {
        /* handle Q.931 messages */
        case cmTransQ931Type:
        {
            sendMessage = processQ931OutgoingMessage(session, host, pvtNode);
            break;
        }

        /* handle H.245 messages */
        case cmTransH245Type:
        {
            sendMessage = processH245OutgoingMessage(session, host, pvtNode);
            break;
        }

        default:
            break;
    }

    return sendMessage;
}

/**************************************************************************************
 * transSessionClose
 *
 * Purpose: This routine closes a session and breaks all its associations.
 *
 * Input/Output:   hsTransSession - The session to be closed.
 *
 * Output:  None.

⌨️ 快捷键说明

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