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

📄 transstates.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
                connectH245(transGlobals, session, msgType);

                /* check if the above message caused a startH245 facility message, if so send it */
                if (!emaWasDeleted((EMAElement)session))
                    sendStartH245Facility(transGlobals, session);
            }
        }

        /* unlock the h245 host */
        emaUnlock((EMAElement)session->H245Connection);
    }

    return RV_TRUE;
}


/**************************************************************************************
 * reportH245
 *
 * putrpose: This routine checks if it is necessary to report to the user that an H.245 is opened.
 *           It bases its decision accrding to the state of the session in regard to tunneling
 *           and parallel tunneling and to the faststart state of the session as well.
 *           If the connection was already reported, we eliminate the notification.
 *           The routine handles both incoming and outgoing messages.
 *
 * Input: outgoing          - RV_TRUE - if an outgoing message, RV_FALSE - if incoming one.
 *        transGlobals      - The global data of the module.
 *        session           - the session on which the message is to be sent.
 *        messageBodyNode   - The body of the message (incoming or outgoing)
 *        msgType           - The type of the message (setup or other)
 *
 ***************************************************************************************/
void reportH245(RvBool          outgoing,
                cmTransGlobals  *transGlobals,
                cmTransSession  *session,
                int             messageBodyNode,
                int             msgType)
{
    RvBool needToReport = RV_FALSE;

    if (outgoing)
    {
        /* handling outgoing messages */
        if (msgType == cmQ931setup)
        {
            /* in case of outgoing setup (outgoing call), we need to tell
               the user of a H.245 connection if we have tunneling without
               faststart, or in case of parallel tunneling, so the user
               may send H.245 tunneled messages before the setup is sent */
            if (session->parallelTunnelingState == parllOffered)
                needToReport = RV_TRUE;
            else
            switch (session->tunnelingState)
            {
                case tunnPossible:
                case tunnOffered:
                case tunnApproved:
                {
                    if (session->faststartState == fsNo)
                        needToReport = RV_TRUE;
                }
                break;

                default:
                    break;
            }
        }
        else
        {
            /* all other outgoing messages (incoming calls) */

            /* if we got some response for our faststart offering and tunneling
               was accepted by the remote we need to check if there is a need to
               report the H.245.
               in case of parallel we may notify the user. If not, that means
               that it's a 'simple' tunneling after faststart and we need to report
               only if the user explicitly requested to open a control session or
               if the faststart was refused */
            if ( (
                   (session->faststartState == fsApproved) ||
                   (session->faststartState == fsRejected)
                 )
                 &&
                 (session->tunnelingState == tunnApproved)
               )
            {
                if (session->parallelTunnelingState == parllApproved)
                    needToReport = RV_TRUE;
                else
                    if ( (session->faststartState == fsRejected) || (session->openControlWasAsked) )
                        needToReport = RV_TRUE;
            }
        }
    }
    else
    {
        /* incoming mesages */
        if (msgType == cmQ931setup)
        {
            /* in case of incoming SETUP message (new incoming call)
               we need to report H.245 in case that parallel was offered */
            if (session->parallelTunnelingState == parllApproved)
            {
                needToReport = RV_TRUE;
            }
            else
            /* in case that no parallel was offered BUT we have a 'normal'
               tunneling WITHOUT faststart we can report that H.245 too */
            if ( (session->tunnelingState == tunnApproved) &&
                (session->faststartState != fsOffered) &&
                (session->faststartState != fsApproved) )
            {
                needToReport = RV_TRUE;
            }
        }
        else
        {
            int tunnMsgNode;

            /* check if there are normal tunneled messages in the message */
            tunnMsgNode = pvtGetChild(transGlobals->hPvt, messageBodyNode, __q931(h245Control), NULL);

            /* all other incoming messages (outgoing calls) */
            /* if the tunneling was approved and no fast start
               or the other side started sending tunneling messages,
               we need to open the H.245 */
            if (session->tunnelingState == tunnApproved)
            {
                if ((session->faststartState == fsRejected) ||
                    (session->faststartState == fsNo)       ||
                    (tunnMsgNode >= 0)
                   )
                needToReport = RV_TRUE;
            }
        }
    }

    /* if we need to report the H.245 connection and we haven't done so yet */
    if (needToReport)
        reportH245Establishment(transGlobals, session);
}

/**************************************************************************************
 * insertH245TunnelingFlag
 *
 * putrpose: This routine fills the H.245 tunneling flag 'h245Tunneling' into the outgoing Q.931 message.
 *
 * Input: transGlobals      - The global data of the module.
 *        session           - the session on which the message is to be sent.
 *        msgBodyNode       - The messages UU-IE part.
 *        msgType           - The message type into which the tunneled messages are inserted
 *
 ***************************************************************************************/
void insertH245TunnelingFlag(cmTransGlobals  *transGlobals,
                             cmTransSession  *session,
                             int             messageBodyNode,
                             int             msgType)
{
    /* set tunneling flag only if we are in a good tunneling state,
       i.e. it's allowed and not rejected yet, and we've never offered it yet */
    if ( (session->tunnelingState != tunnNo) &&
         (session->tunnelingState != tunnRejected) &&
         (session->tunnelingState != tunnOffered) )
    {
        /* mark the message as having tunneled messages */
        pvtAdd(transGlobals->hPvt, messageBodyNode, __q931(h245Tunneling), RV_TRUE, NULL, NULL);

        /* for the following messages, do not insert tunneled messages but
           mark as provisional, so that the other side will not know yet whether
           we aproved the tunneling (just like previous version are when receiving
           these messages) */
        if ( (msgType == cmQ931setupAck) ||
             (msgType == cmQ931information) ||
             (msgType == cmQ931progress) ||
             (msgType == cmQ931status) ||
             (msgType == cmQ931statusInquiry)
           )
        {
            /* set the provisionalRespToH245Tunneling element */
            pvtAdd(transGlobals->hPvt, messageBodyNode, __q931(provisionalRespToH245Tunneling), 0, NULL, NULL);
            return;
        }

        /* after sending for the first time, we must wait to see if the other
           side supports tunneling, until it does we may not continue using tunneling  */
        if (session->tunnelingState == tunnPossible)
            session->tunnelingState = tunnOffered;
    }
    else
    {
        RvBool useTunneling;

        if( (session->tunnelingState == tunnOffered) ||
            ( (msgType == cmQ931setup) && (session->tunnelingState == tunnNo) && (session->isTunnelingSupported) ) )
        {
            /* mark the message as supporting tunneled messages (we are either in tunnOffered
               state that was not answered yet, or supporting tunneling without having processed
               any messages yet. */
            useTunneling = RV_TRUE;
        }
        else
        {
            /* mark the message as not supporting tunneled messages */
            useTunneling = RV_FALSE;
        }

        pvtAdd(transGlobals->hPvt, messageBodyNode, __q931(h245Tunneling), useTunneling, NULL, NULL);
    }
}

#include "cmcall.h"
/**************************************************************************************
 * insertH245TunneledMessages
 *
 * putrpose: This routine fills the H.245 tunneled messages into the outgoing Q.931 message.
 *
 * Input: transGlobals      - The global data of the module.
 *        session           - the session on which the message is to be sent.
 *        msgBodyNode       - The messages UU-IE part.
 *        msgType           - The message type into which the tunneled messages are inserted
 *
 ***************************************************************************************/
void insertH245TunneledMessages(cmTransGlobals  *transGlobals,
                                cmTransSession  *session,
                                int             messageBodyNode,
                                int             msgType)
{
    HRPOOLELEM nextMsg = session->firstMessage;
    int  node;

    /* 2004.07.16. fujiangdong. Do not send tunneling tcs and msd message
         before the CONNECT message sent or received. */
    HATRANSSESSION haTransSession =
         (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);
    callElem *elem = (callElem*)haTransSession;
    if (elem->state != cmCallStateConnected &&
            elem->state != cmCallStateDisconnected &&
/*            elem->state != cmCallStateDialtone &&*/
            elem->state != cmCallStateTransfering)
    {
        return;
    }
	
    /* See if we have a cool message to send tunneling on */
    if ( (msgType == cmQ931setupAck) ||
        (msgType == cmQ931information) ||
        (msgType == cmQ931progress) ||
        (msgType == cmQ931status) ||
        (msgType == cmQ931statusInquiry)
        )
    {
        /* the above messages suck. No tunneling for you! */
        return;
    }

    /* send tunneled messages only if we are in a good tunneling state,
       i.e. it's allowed and not rejected yet, and not offered (unless we
       were offering it in this very message which may be only first outgoing
       setup message */
    if ( (session->tunnelingState != tunnNo) &&
         (session->tunnelingState != tunnRejected) &&
         ((session->tunnelingState != tunnOffered) || (msgType == cmQ931setup)) )
    {
        /* go over all saved tunneled messages and put them into the Q.931 message */
        while (nextMsg)
        {
            RvUint8 *buffer;
            int  msgSize;

            /* read the next tunneled message */
            getEncodeDecodeBuffer(transGlobals->codingBufferSize, &buffer);

            rpoolCopyToExternal(transGlobals->messagesRPool,
                                (void *)buffer,
                                nextMsg,
                                0,
                                transGlobals->codingBufferSize);

            msgSize = rpoolChunkSize(transGlobals->messagesRPool, nextMsg)
                                     -MSG_HEADER_SIZE-TPKT_HEADER_SIZE;

            /* if it was not sent yet, insert it to the Q.931 message */
            node = 0;

            if((session->parallelTunnelingState == parllApproved) && (session->faststartState == fsOffered))
            {
                /* hopefully, this will cover the case where we work in parallel mode, but did not
                ack the FS channels yet. In such a case, we should delay the sending of tunneled H.245 messages
                untill the FS channels are ready. cool? */
                RvLogInfo(&transGlobals->hLog,
                    (&transGlobals->hLog, "insertH245TunneledMessages delaying parellel tunneling untill FS ack"));
                return;
            }

⌨️ 快捷键说明

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