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

📄 cmautorascall.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 4 页
字号:
                   we're not working on anything right now, but we may have perm Alt GKs */
                if (autoRasIsInSearch(autoras,call) || autoRasGotPermList(autoras))
                {
                    /* So let's try the next GK */
                    if(autoRasCallSendToNextGK(autoras, call) >= 0)
                    {
                        emaUnlock((EMAElement)hsCall);
                        return 0;
                    }
                }

                if(call->wasRejected)
                {
                    /* We got SOME response. */
                    call->wasRejected = RV_FALSE;
                    call->isTempRdrn = RV_FALSE;
                    break;
                }

                /* See if we should try to register again */
                if(call->isTempRdrn)
                {
                    /* It's just a temporary redirection. forget it. */
                    call->isTempRdrn = RV_FALSE;
                }
                else if (pvtGetChild(app->hVal, app->rasConf, __q931(dontRegisterOnTimeout), NULL) < 0)
                {
                    /* We should change the status to not registered */
                    autoras->state = cmIdle;
                    autoRasCallIdleState(autoras, call);

                    /* Make sure we're trying to register again */
                    if ((autoras->internalState != autorasRegTrying) && (autoras->internalState != autorasRegFailed))
                        cmRegister(autoras->hApp);
                }

                /* Make sure we close this transaction if it wasn't already closed */
                if (call->tx == hsRas)
                {
                    cmRASClose(hsRas);
                    call->tx = NULL;
                }
                emaUnlock((EMAElement)hsCall);
                /* exit here, do not raise cmiAutoRasEvRateChanged - it needs a response node */
                return 0;
            }

            default:
            {
                /* Shouldn't happen */

                /* 2004.11.03, added. make sure we unlock the mutex */
                emaUnlock((EMAElement)hsCall);
				
                return RV_ERROR_UNKNOWN;
            }
        }

        /* Notify the application about this one */
        rv = autoras->event(hsCall, hsRas, cmiAutoRasEvRateChanged);

        /* Make sure we close this transaction if it wasn't already closed */
        if (call->tx == hsRas)
        {
            cmRASClose(hsRas);
            call->tx = NULL;
        }
        emaUnlock((EMAElement)hsCall);
    }
    return rv;
}



/************************************************************************
 * autoRasDisengageResponse
 * purpose: Callback function invoked when a response for DRQ arrives
 * input  : haRas   - Application's handle (autoras in this context)
 *          hsRas   - RAS Transaction handle
 *          trStage - Stage of response
 * output : none
 * return : non-negative value on success
 *          negative value on failure
 ************************************************************************/
int RVCALLCONV autoRasDisengageResponse
(
    IN  HAPPRAS          haRas,
    IN  HRAS             hsRas,
    IN  cmRASTrStage     trStage)
{
    autorasEndpoint* autoras;
    autorasCall* call = (autorasCall *)haRas;
    HCALL hsCall;
    int rv = RV_ERROR_UNKNOWN;
    int responseId = cmiRASGetResponse(hsRas);

    if (trStage);

    hsCall = cmiGetByAutoRas((HAUTORASCALL)call);
    if (emaLock((EMAElement)hsCall))
    {
        autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));

        /* See what we've got for the BRQ */
        switch(trStage)
        {
            case cmRASTrStageConfirm:
            {
                /* this function will set the new GK if needed, and get the new AltGKs list */
                setRasAlternateGatekeeper(autoras, call,
                    pvtGetChild(autoras->hVal, responseId, __q931(alternateGatekeeper), NULL));
                break;
            }

            case cmRASTrStageReject:
            {
                int chNodeId;

                /* See if this is a redirection */
                __pvtGetNodeIdByFieldIds(chNodeId, autoras->hVal, responseId, {_anyField _q931(altGKInfo) LAST_TOKEN});
                if (chNodeId >= 0)
                {
                    /* Se we are redirected to an AltGK.*/
                    RvInt32 isPerm;
                    int newAltGKs;

                    call->wasRejected = RV_TRUE;

                    /* maybe we are already working on a redirection */
                    if(!autoRasIsInSearch(autoras,call))
                    {
                        /* We're not working on anything right now  - we start redirection */
                        /* Let's see if permanently of temporeraly */
                        newAltGKs = pvtGetChild(autoras->hVal, chNodeId, __q931(alternateGatekeeper), NULL);
                        pvtGetChildByFieldId(autoras->hVal, chNodeId, __q931(altGKisPermanent), &isPerm, NULL);
                        if(isPerm)
                            autoRasSetPermList(autoras, newAltGKs);
                        else
                        {
                            call->isTempRdrn = RV_TRUE;
                            autoRasSetTempList(autoras, newAltGKs);
                        }
                    }
                    /* ok, let's send the old messsage to a new GK */
                    if(autoRasCallSendToNextGK(autoras, call) >= 0)
                    {
                        /* Sent ok */
                        /* Make sure we close this transaction if it wasn't already closed */
                        emaUnlock((EMAElement)hsCall);
                        return 0;
                    }
                    else
                    { /* Otherwise we are rejected for good */
                        call->isTempRdrn = RV_FALSE;
                        call->wasRejected = RV_FALSE;
                        autoRasResetSearch(autoras,NULL);
                    }
                }
                else
                    setRasAlternateGatekeeper(autoras, call, -1);
                break;
            }

            case cmRASTrStageTimeout:
            {
                /* timedout... */
                cmElem* app = (cmElem *)emaGetInstance((EMAElement)hsCall);

                /* maybe we are already working on a redirection, or
                   we're not working on anything right now, but we may have perm Alt GKs */
                if( autoRasIsInSearch(autoras,call) || autoRasGotPermList(autoras))
                {
                    /* So let's try the next GK */
                    if(autoRasCallSendToNextGK(autoras, call) >= 0)
                    {
                        emaUnlock((EMAElement)hsCall);
                        return 0;
                    }
                }

                if(call->wasRejected)
                {
                    /* We got SOME response. */
                    call->wasRejected = RV_FALSE;
                    call->isTempRdrn = RV_FALSE;
                    break;
                }

                /* See if we should try to register again */
                if(call->isTempRdrn)
                {
                    /* It's just a temporary redirection. forget it. */
                    call->isTempRdrn = RV_FALSE;
                    break;
                }
                if (pvtGetChild(app->hVal, app->rasConf, __q931(dontRegisterOnTimeout), NULL) < 0)
                {
                    /* We should change the status to not registered */
                    autoras->state = cmIdle;
                    autoRasCallIdleState(autoras, call);

                    /* Make sure we're trying to register again */
                    if ((autoras->internalState != autorasRegTrying) && (autoras->internalState != autorasRegFailed))
                        cmRegister(autoras->hApp);
                }
                break;
            }

            default:
                /* This shouldn't happen... */
                break;
        }

        /* Make sure call is IDLE */
        autoRasCallIdleState(autoras, call);

        /* Notify the application about this one - ras was closed, we don't need it */
        rv = autoras->event(hsCall, NULL, cmiAutoRasEvCallDropped);
        emaUnlock((EMAElement)hsCall);
    }
    return rv;
}


/************************************************************************
 * autoRasAdmissionResponse
 * purpose: Callback function invoked when a response for ARQ arrives
 * input  : haRas   - Application's handle (autoras in this context)
 *          hsRas   - RAS Transaction handle
 *          trStage - Stage of response
 * output : none
 * return : non-negative value on success
 *          negative value on failure
 ************************************************************************/
int RVCALLCONV autoRasAdmissionResponse(
    IN  HAPPRAS          haRas,
    IN  HRAS             hsRas,
    IN  cmRASTrStage     trStage)
{
    autorasEndpoint* autoras;
    autorasCall* call = (autorasCall *)haRas;
    HCALL hsCall;
    int responseId = cmiRASGetResponse(hsRas);

    hsCall = cmiGetByAutoRas((HAUTORASCALL)call);

    if (emaLock((EMAElement)hsCall))
    {

        autoras = (autorasEndpoint *)cmiGetAutoRasHandle((HAPP)emaGetInstance((EMAElement)hsCall));

        /* See what we've got for the ARQ */
        switch(trStage)
        {
            case cmRASTrStageConfirm:
            {
                /* ACF - go on with the call */
                int irrFrequency;


                /* Notify the CM */
                autoras->event(hsCall, hsRas, cmiAutoRasEvGotACF);

                /* Make sure the application was kind enough to leave this transaction and
                   not drop this call barbarically. */
                if (!emaWasDeleted((EMAElement)hsRas))
                {
                    /* Get inside the request message */
                    responseId = pvtChild(autoras->hVal, responseId);                   
		#if 0			
                    /* Check if we have an IRR frequency to work with */
                    RvH323TimerCancel(autoras->hTimers, &call->irrTimer);
                    if (pvtGetChildValue(autoras->hVal, responseId, __q931(irrFrequency), &irrFrequency, NULL) >= 0)
                    {
                        call->irrTimer = RvH323TimerStartPeriodic(autoras->hTimers, autoRasIrrTimeout, (void*)hsCall, irrFrequency * 1000);
                        /*cmiAutoRASCallSetUnsolicitedIRR(hsCall, irrFrequency);*/
                    }
                    else
                    { 
                        /* 2004.11.24. If there is no irrFrequency in ACF,
                            we set the irrFrequency to default value 60. */
                        /*cmiAutoRASCallSetUnsolicitedIRR(hsCall, 60);*/
                        call->irrTimer = RvH323TimerStartPeriodic(autoras->hTimers, autoRasIrrTimeout, (void*)hsCall, 60 * 1000);
                    }
		#endif 
                    /* this function will set the new GK if needed, and get the new AltGKs list */
                    setRasAlternateGatekeeper(autoras, call,
                        pvtGetChild(autoras->hVal, responseId, __q931(alternateGatekeeper), NULL));

                    call->callState = autorasCallConnected;

                    if (((callElem*)hsCall)->state != cmCallStateWaitAddressAck)
                        cmSetupEnd((callElem *)hsCall);
                }
                break;
            }

            case cmRASTrStageReject:
            {
                int chNodeId;


                /* See if this is a redirection */
                __pvtGetNodeIdByFieldIds(chNodeId, autoras->hVal, responseId, {_anyField _q931(altGKInfo) LAST_TOKEN});
                if (chNodeId >= 0)
                {
                    /* Se we are redirected to an AltGK.*/
                    RvInt32 isPerm;
                    int newAltGKs;

                    call->wasRejected = RV_TRUE;

                    /* maybe we are already working on a redirection */
                    if(!autoRasIsInSearch(autoras,call))
                    {
                        /* We're not working on anything right now  - we start redirection */
                        /* Let's see if permanently of temporeraly */
                        newAltGKs = pvtGetChild(autoras->hVal, chNodeId, __q931(alternateGatekeeper), NULL);
                        pvtGetChildByFieldId(autoras->hVal, chNodeId, __q931(altGKisPermanent), &isPerm, NULL);
                        if(isPerm)
                            autoRasSetPermList(autoras, newAltGKs);
                        else
                        {
                            call->isTempRdrn = RV_TRUE;
                            autoRasSetTempList(autoras, newAltGKs);
                        }
                    }
                    /* ok, let's send the old transaction to a new GK */
                    if(autoRasCallSendToNextGK(autoras, call) >= 0)
                    {
                        /* Sent OK */
                        break;
                    }
                    else
                    { /* Otherwise we are rejected for good */
                        call->isTempRdrn = RV_FALSE;
                        call->wasRejected = RV_FALSE;
                        autoRasResetSearch(autoras,NULL);
                    }
                }
                else
                    setRasAlternateGatekeeper(autoras, call, -1);
                /* ARJ - notify the CM about it */
                autoras->event(hsCall, hsRas, cmiAutoRasEvCallRejected);
                break;
            }

            case cmRASTrStageTimeout:
            {
                /* timedout... */
	
                cmElem* app = (cmElem *)emaGetInstance((EMAElement)hsCall);
		
                /* maybe we are already working on a redirection, or
                   we're not working on anything right now, but we may have perm Alt GKs */
                if( autoRasIsInSearch(autoras,call) || autoRasGotPermList(autoras))
                {
                    /* So let's try the next GK */
                    if(autoRasCallSendToNextGK(autoras, call)>=0)
                        break;
                }

                if(call->wasRejected)
                {
                    /* ARJ - notify the CM about it */
                    call->wasRejected = RV_FALSE;
                    call->isTempRdrn = RV_FALSE;
                    autoras->event(hsCall, hsRas, cmiAutoRasEvCallRejected);
                    break;
                }

                autoras->event(hsCall, hsRas, cmiAutoRasEvTimedout);
                if (call->tx == hsRas)
                {
			cmRASClose(hsRas);
                    call->tx = NULL;
                }

                /* See if we should try to register again */
                if(call->isTempRdrn)
                {
                    /* It's just a temporary redirection. forget it. */
                    call->isTempRdrn = RV_FALSE;
                    break;
                }
                /* If we're here, we were either not redirected, or redirected permanently, and timed
                   out. we may need to register again */
                if (pvtGetChild(app->hVal, app->rasConf, __q931(dontRegisterOnTimeout), NULL) < 0)
                {
                    /* We should change the status to not registered */
                    autoras->state = cmIdle;
                    autoRasCallIdleState(autoras, call);

⌨️ 快捷键说明

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