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

📄 transstates.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/

#include "transStates.h"
#include "transportint.h"
#include "transutil.h"
#include "q931asn1.h"
#include "transnet.h"
#include "cmutils.h"
#include "emanag.h"
#include "prnutils.h"
#include "pvaltreeStackApi.h"
#include "psyntreeStackApi.h"
#include "msg.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus*/



/**************************************************************************************
 * setMultiplexedParams
 *
 * putrpose: to set the multiplexed parameters into an outgoing message. The parameters
 *           are taken from the host parameters which are constatntly updated by incoming
 *           messages and user API calls.
 *
 * Input: transGlobals - The global data of the module.
 *        session      - the session from which the message is sent.
 *        host         - the host on which the message is to be sent.
 *        pvtNode      - the message into which the parameters are to be set.
 *        msgType      - which message we are dealing with.
 *
 ***************************************************************************************/
void setMultiplexedParams(cmTransGlobals *transGlobals,
                          cmTransSession *session,
                          cmTransHost *host,
                          int pvtNode,
                          int msgType)
{
    int res;
    RvBool multipleCallsValue;
    RvBool maintainConnectionValue;

    switch (msgType)
    {
        case cmQ931alerting:
        case cmQ931callProceeding:
        case cmQ931connect:
        case cmQ931setup:
        case cmQ931facility:
        case cmQ931progress:
        {

            /* we want to put theses parameters just to non-annex E messages */
            if (host->annexEUsageMode == cmTransNoAnnexE)
            {
                /* regular TPKT connection */
                multipleCallsValue = ((host->isMultiplexed /*&& (host->remoteIsMultiplexed || msgType == cmQ931setup)*/));
                maintainConnectionValue =  ((!host->closeOnNoSessions)/*&& (!host->remoteCloseOnNoSessions)*/);
            }
            else
            if ( (msgType == cmQ931setup) && (session->Q931Connection) )
            {
                /* for SETUP message we want to put the parameters also when having both annex E host
                   and TPKT host, since we don't know who will win the race. We use the TPKT host params */
                multipleCallsValue = ((session->Q931Connection->isMultiplexed &&
                                       (session->Q931Connection->remoteIsMultiplexed || msgType == cmQ931setup)));
                maintainConnectionValue =  ((!session->Q931Connection->closeOnNoSessions) &&
                                            (!session->Q931Connection->remoteCloseOnNoSessions));
            }
            else
            {
                /* annex E host */
                multipleCallsValue      = RV_FALSE;
                maintainConnectionValue = RV_TRUE;
            }

            /* set the isMultiplexed element according to the host settings */
            __pvtBuildByFieldIds(res, transGlobals->hPvt, pvtNode,
                                    { _q931(message)
                                      _anyField
                                      _q931(userUser)
                                      _q931(h323_UserInformation)
                                      _q931(h323_uu_pdu)
                                      _q931(h323_message_body)
                                      _anyField
                                      _q931(multipleCalls)
                                      LAST_TOKEN
                                    },
                                 multipleCallsValue, NULL);

            /* set the maintainConnection element according to the host settings */
            __pvtBuildByFieldIds(res, transGlobals->hPvt, pvtNode,
                                    { _q931(message)
                                      _anyField
                                      _q931(userUser)
                                      _q931(h323_UserInformation)
                                      _q931(h323_uu_pdu)
                                      _q931(h323_message_body)
                                      _anyField
                                      _q931(maintainConnection)
                                      LAST_TOKEN
                                    },
                                 maintainConnectionValue, NULL);
        }

        break;

        default:
            break;
    }
}

/**************************************************************************************
 * setTheFastStartStateByMessage
 *
 * putrpose: to determine the faststart state of the session according to its previous
 *           state and the data within the outgoing message. This routine handles all
 *           outgoing messages (setup for outgoing calls and all the rest for incoming
 *           calls. The routine modifies the session state variables!
 *
 * Input: transGlobals      - The global data of the module.
 *        session           - the session on which the message is to be sent.
 *        messageBodyNode   - the UU-IE part of the message to be inspected.
 *        msgType           - The type of the message (setup or other)
 *
 ***************************************************************************************/
void setTheFastStartStateByMessage(cmTransGlobals *transGlobals,
                                   cmTransSession *session,
                                   int            messageBodyNode,
                                   int            msgType)
{
    int res;

    /* get the fastConnectRefuse element */
    __pvtGetNodeIdByFieldIds(   res,
                                transGlobals->hPvt,
                                messageBodyNode,
                                {   _q931(h323_message_body)
                                    _anyField
                                    _q931(fastConnectRefused)
                                    LAST_TOKEN
                                });

    if (res<0)
    {
        /* there was NO refusal, check if there was a fastStart elemnt in the message */
        __pvtGetNodeIdByFieldIds(   res,
                                    transGlobals->hPvt,
                                    messageBodyNode,
                                    {   _q931(h323_message_body)
                                        _anyField
                                        _q931(fastStart)
                                        LAST_TOKEN
                                    });
        if (msgType == cmQ931setup)
        {
            if (res < 0)
                /* there was no fastStart element in the message */
                /* for SETUP that means that no faststart on the call was even offered */
                session->faststartState = fsNo;
            else
                /* there WAS a fastStart element in the message */
                /* that means for SETUP that fast start was offered on the call */
                session->faststartState = fsOffered;
        }
        else
        {
            /* for all other messages */
            if (res < 0)
            {
                /* there WAS not a fastStart element in the message */
                /* this means that the fast start was not answered yet,
                   however, if we're already in the CONNECT message
                   and no response was given, that means a reject */
                if (msgType == cmQ931connect)
                    if (session->faststartState == fsOffered)
                        session->faststartState = fsRejected;
            }
            else
                /* there WAS a fastStart element in the message */
                /* this means that the fast start was approved */
                session->faststartState = fsApproved;
        }
    }
    else
    {
        /* There was a refusal, no fast start for this call */
        session->faststartState = fsRejected;
    }
}

/**************************************************************************************
 * setTheTunnelingStateByMessage
 *
 * putrpose: to determine the tunneling state of the session according to its previous
 *           state and the data within the incoming message. This routine handles all
 *           incoming messages (setup for incoming calls and all the rest for outgoing
 *           calls. The routine modifies the session state variables!
 *
 * Input: transGlobals      - The global data of the module.
 *        session           - the session on which the message is to be sent.
 *        messageBodyNode   - the UU-IE part of the message to be inspected.
 *        msgType           - The type of the message (setup or other)
 *
 ***************************************************************************************/
void setTheTunnelingStateByMessage(cmTransGlobals *transGlobals,
                                   cmTransSession *session,
                                   int            messageBodyNode,
                                   int            msgType)
{
    int res;
    int bTunneling, bProvisional;

    /* get the provisionalRespToH245Tunneling element */
    res = pvtGetChild(transGlobals->hPvt, messageBodyNode,
        __q931(provisionalRespToH245Tunneling), NULL);

    if (res < 0)
        bProvisional = RV_FALSE;
    else
        bProvisional = RV_TRUE;

    if (!bProvisional)
    {
        /* get the h245Tunneling element */
        res = pvtGetChildByFieldId(transGlobals->hPvt, messageBodyNode,
            __q931(h245Tunneling), (RvInt32 *)&bTunneling, NULL);

        if (res < 0)
            bTunneling = RV_FALSE;
    }
    else
        bTunneling = RV_FALSE;

    /* for incoming setup message: if tunneling exists in the message and the
       session supports it, approve the tunneling */
    if (msgType == cmQ931setup)
    {
        if (session->isTunnelingSupported)
        {
            if (bTunneling)
                session->tunnelingState = tunnApproved;
            else
                session->tunnelingState = tunnRejected;
        }
        else
            session->tunnelingState = tunnNo;
    }
    else
    {
        /* for all other messages (outgoing calls): if we offered tunneling and the message
           has it, approve it */
        if (!bProvisional)
        {
            if (bTunneling)
            {
                if (session->tunnelingState == tunnOffered)
                {
                    HRPOOLELEM nextMsg;
                    /* the element exists and is RV_TRUE */
                    session->tunnelingState = tunnApproved;

                    /* clean the saved but sent tunneled messages */
                    if (session->parallelTunnelingState != parllOffered)
                    {
                        nextMsg = session->firstMessage;
                        while (nextMsg)
                            nextMsg = extractMessageFromPool(transGlobals, session, RV_TRUE);
                    }
                }
            }
            else
                /* the element exists and is RV_FALSE */
                session->tunnelingState = tunnRejected;
        }
    }

    /* if we reached a CONNECT with no response that means a reject */
    if ( (session->tunnelingState == tunnOffered) && (msgType == cmQ931connect) )
        session->tunnelingState = tunnRejected;
}

⌨️ 快捷键说明

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