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

📄 transnet.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
                                {
                                    /* This session was closed somewhere in-between - we
                                       should continue as if we have no session */
                                    session = NULL;
                                }
                            }

                            /* check what type of Q.931 message we have here */
                            msgType = pvtGetChildTagByPath(transGlobals->hPvt, pvtNode, "message", 1);

                            /* determine that the TPKT host has won and got the first response */
                            if (session)
                                ok = determineWinningHost(transGlobals, session, (tpkt == NULL));

                            /* report the new session */
                            if ( (transGlobals->sessionEventHandlers.cmEvTransNewSession) &&
                                 (session) &&
                                 (ok) &&
                                 (msgType == cmQ931setup) )
                            {
                                TRANSERR     err;
                                int          cause;
                                RvPstFieldId reasonNameId;
                                int          sessNumOfLocks;

                                RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
                                    "cmEvTransNewSession(hAppTrans=%p, hAppATrans=%p, hsSession=%d-%p)",
                                        transGlobals, transGlobals->hAppATrans, emaGetIndex((EMAElement)session), session));

                                sessNumOfLocks = emaPrepareForCallback((EMAElement)session);
                                hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
                                err = transGlobals->sessionEventHandlers.cmEvTransNewSession(
                                                    (HAPPTRANS) transGlobals,
                                                    (HAPPATRANS) transGlobals->hAppATrans,
                                                    (HSTRANSSESSION)session,
                                                    &haTransSession,
                                                    pvtNode,
                                                    &cause,
                                                    &reasonNameId);
                                emaReturnFromCallback((EMAElement)session, sessNumOfLocks);
                                emaReturnFromCallback((EMAElement)host, hostNumOfLocks);

                                if (err != cmTransOK)
                                {
                                    sendReleaseCompleteMessage(transGlobals,
                                                               host,
                                                               session->CRV,
                                                               session->callId,
                                                               cause,
                                                               reasonNameId);

                                    /* Delete the Session */
                                    if (!emaWasDeleted((EMAElement)session))
                                        cmTransCloseSession((HSTRANSSESSION)session);

                                    RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
                                        "transQ931Handler new session was refused by user"));
                                    ok = RV_FALSE;
                                }
                                else
                                {
                                    emaSetApplicationHandle((EMAElement)session, (void *)haTransSession);
                                    session->reportedQ931Connect = RV_TRUE;
                                }

                            }

                            /* process the message being received */
                            if(ok)
                            {
                                if (session)
                                    /* hold the sending of tunneled messages until all incoming ones are reported */
                                    session->holdTunneling = RV_TRUE;
                                msgType = processQ931IncomingMessage(host, session, pvtNode);
                            }

                            if (ok)
                            {
                                /* report the message to the user */
                                if ( (session) && (!emaWasDeleted((EMAElement)session)) )
                                {
                                    HATRANSSESSION haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);

                                    /* report the new message on the session */
                                    if (transGlobals->sessionEventHandlers.cmEvTransNewMessage)
                                    {
                                        int sessNumOfLocks;
                                        RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
                                            "cmEvTransNewMessage(session = %d(%p), haTransSession=%p, type=cmTransQ931Type, pvtNode = %d, hMsgContext=%p)",
                                                emaGetIndex((EMAElement)session), session, haTransSession, pvtNode, hMsgContext));

                                        sessNumOfLocks = emaPrepareForCallback((EMAElement)session);
                                        hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
                                        transGlobals->sessionEventHandlers.cmEvTransNewMessage(
                                                                    (HSTRANSSESSION) session,
                                                                    (HATRANSSESSION) haTransSession,
                                                                    cmTransQ931Type,
                                                                    pvtNode,
                                                                    hMsgContext);
                                        emaReturnFromCallback((EMAElement)session, sessNumOfLocks);
                                        emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
                                    }

                                    /* release the hold from sending tunneled messages */
                                    session->holdTunneling = RV_FALSE;

                                    /* check if we need to send facility for the newly sent tunneled messages */
                                    if (!emaWasDeleted((EMAElement)session))
                                        initiateTunnelingFacility(transGlobals, session, host);
                                }
                                else
                                if (!session)
                                {
                                    HATRANSHOST haTransHost = (HATRANSHOST)emaGetApplicationHandle((EMAElement)host);

                                    /* report the new message on the host */
                                    if (transGlobals->hostEventHandlers.cmEvTransHostNewMessage)
                                    {
                                        RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
                                            "cmEvTransHostNewMessage(hsHost = %d(%p), haHost=%p, type=cmTransQ931Conn, pvtNode = %d)",
                                                emaGetIndex((EMAElement)host), host, haTransHost, pvtNode));

                                        hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
                                        transGlobals->hostEventHandlers.cmEvTransHostNewMessage(
                                                                    (HSTRANSHOST) host,
                                                                    haTransHost,
                                                                    cmTransQ931Type,
                                                                    pvtNode,
                                                                    hMsgContext);
                                        emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
                                    }
                                }
                            }
                        }
                        else
                        /* this message has no session, if it's possible
                           terminate the connection, i.e. if it's not a multiplexed host,
                           or alternativly it's a multiplexed host that may be closed on
                           no sessions, and indeed none is connected to it */
                        if ( (acceptedCall) &&
                             (  (!host->isMultiplexed) ||
                                (   (host->isMultiplexed) &&
                                    (host->closeOnNoSessions) &&
                                    (!host->firstSession)
                                )
                             )
                           )

                            /* force a close on the host */
                            event = RvSelectClose;

                        /* get rid of the decoded message */
                        if (pvtNode >= 0)
                            pvtDelete(transGlobals->hPvt, pvtNode);
                    }

                    if ( (event == RvSelectClose) && (!emaWasDeleted((EMAElement)host)) &&
                         (host->state != hostClosing) && (host->state != hostClosed) )
                    {
                        /* the host connection was closed, report it for non annex E hosts */
                        if ( (transGlobals->hostEventHandlers.cmEvTransHostClosed) &&
                             (host->reported) &&
                             (host->annexEUsageMode == cmTransNoAnnexE) )
                        {
                            RvBool wasConnected       = ( (host->state == hostConnected) ||
                                                          (host->state == hostBusy) );
                            HATRANSHOST haTransHost = (HATRANSHOST)emaGetApplicationHandle((EMAElement)host);
                            int hostNumOfLocks;

                            host->state = hostClosing;
                            RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
                                "cmEvTransHostClosed(hsHost = %d(%p), haHost=%p, wasConnected = %d)",
                                    emaGetIndex((EMAElement)host), host, haTransHost, wasConnected));

                            hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
                            transGlobals->hostEventHandlers.cmEvTransHostClosed((HSTRANSHOST)host,
                                                                                haTransHost,
                                                                                wasConnected);
                            emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
                        }
                        else
                        {
                            if (!emaWasDeleted((EMAElement)host))
                            {
                                host->state = hostClosed;
                                transHostClose((HSTRANSHOST)host, RV_TRUE);
                            }
                        }
                    }

                    if (sessionWasLocked)
                        emaUnlock((EMAElement)session);

                    break;
                }

                case RvSelectWrite:
                {
                    TRANSERR res;

                    /* for TPKT the last send was completed */
                    /* remove the message from the pool (for annex E
                       we must resend the last message that got WOULDBLOCK error) */
                    if (host->annexEUsageMode == cmTransNoAnnexE)
                        extractMessageFromPool(transGlobals, host, RV_FALSE);

                    /* mark the host as not busy and try sending the remaining messages */
                    host->state = hostConnected;
                    res = sendMessageOnHost(transGlobals, host);
                    if ( (res != cmTransOK) && (res != cmTransConnectionBusy) )
                    {
                        RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
                            "transQ931Handler Failed on send for host %d(%p)",
                                emaGetIndex((EMAElement)host), host));
                    }
                    break;
                }
            }
        }

        /* unlock and release the marked host */
        emaUnlock((EMAElement)host);
     }
     else
     {
         RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
            "transQ931Handler got no context on event %d", event));
     }

}


/**************************************************************************************
 * connectH245Connection
 *
 * Purpose: Simulates a connect from the network on the H.245 connection. It is used
 *          when a dummy control session is built which does not actually connect to
 *          the network.
 *
 * input   : session - The handle to the session on which we need to report the connect.
 *
 * Output:  None.
 *
 **************************************************************************************/
static void connectH245Connection(
    IN cmTransSession*  session)
{
    cmTransHost *host = session->H245Connection;

    if (emaLock((EMAElement)host))
    {
        /* if it's an existing and connected host, just report it and return OK */
        if (host->state == hostConnecting)
        {
           /* all ok we can use that connection */
           host->state = hostConnected;

           /* the H.245 connection is established, notify the user */
           transReportConnect(host, NULL, RV_TRUE);
        }
        emaUnlock((EMAElement)host);
    }
}

/**************************************************************************************
 * connectQ931Connection
 *
 * Purpose: Simulates a connect from the network on the Q.931 connection. It is used
 *          when a multiplexed host is already connected and we just want to simulate
 *          its connection event so the call signaling procedure will proceed.
 *
 * input   : session - The handle to the session on which we need to report the connect.
 *
 * Output:  None.
 *
 **************************************************************************************/
static void connectQ931Connection(
    IN cmTransSession*  session)
{
    cmTransHost *host;

    host = session->Q931Connection;

    if (emaLock((EMAElement)host))
    {
        /* if it's an existing and connected host, just report it and return OK */
        if ( (host->state == hostConnected) || (host->state == hostBusy) )
        {
            /* report to the session that the connection is established, no need
               to do anything with th

⌨️ 快捷键说明

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