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

📄 cmautorasep.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 4 页
字号:
                if((newAltGKs = autoRasGetNextAltGkNode(autoras, NULL)) >= 0)
                { /* We have an Alt GK */
                    /* Clean this */
                    cmRASClose(hsRas);
                    /* And now we send an RRQ to the next GK*/
                    if(autoRasPrepareRRQ(autoras, newAltGKs)>=0)
                        return 0;
                }
                else
                { /* no more GKs in AltGKs list - get rid of it */
                    autoRasRemovePermList(autoras);
                    autoRasResetSearch(autoras,NULL);
                }
            }

            /* or maybe this was just a partial URQ */
            __pvtGetNodeIdByFieldIds(nodeId, autoras->hVal, requestId , {_q931(unregistrationRequest) _q931(endpointAlias) LAST_TOKEN});
            if(nodeId >= 0)
            {
                /* just remove these aliases */
                rasUpdatePartUnreg((rasModule *)emaGetUserData((EMAElement)hsRas), requestId);
                cmRASClose(hsRas);
                break;
            }

            cmRASClose(hsRas);

            /* We're unregistered - we might try to register again :-) */
            if(autoras->internalState == autorasRegNotTried)
                /* someone decided to unregister in the "unregistered" event above */
                break;
            autoRasIdleAndRegister(autoras);
            break;
        }

        case cmRASNonStandard:
        {
            /* NSM message - notify the state to application and close it */
            autorasEndpoint* autoras;
            autoras = (autorasEndpoint *)cmiGetAutoRasHandle(cmiRASGetHAPP(hsRas));
            autoRasChangeState(autoras, cmNonStandardMessage, cmiRASGetResponse(hsRas));
            cmRASClose(hsRas);
            break;
        }

        case cmRASInfo:
        {
            /* IRQ message - send back an IRR and close the transaction */
            cmRASConfirm(hsRas);
            cmRASClose(hsRas);
            break;
        }

        default:
            /* Not processed by automatic RAS */
            return RV_FALSE;
    }

    /* Make sure manual RAS knowns we have processed this mesage */
    return RV_TRUE;
}




/************************************************************************
 *
 *                              Public functions
 *
 ************************************************************************/


/************************************************************************
 * cmiAutoRASEPStart
 * purpose: Start the endpoint part of the automatic RAS.
 *          This function sets internal callbacks with the RAS module and
 *          initializes some autoRAS related variables.
 * input  : hAutoRas - Automatic RAS instance
 * output : none
 * return : none
 ************************************************************************/
void cmiAutoRASEPStart(IN HAUTORASMGR  hAutoRas)
{
    autorasEndpoint* autoras = (autorasEndpoint *)hAutoRas;

    /* Set the event handler for the endpoint related RAS transactions */
    cmiRASSetEPTrEventHandler(autoras->hApp, autoRasEPTransaction);

    autoras->discoveryRequired = RV_FALSE;
}



/************************************************************************
 * cmiAutoRASGetEndpointID
 * purpose: Retrieves the EndpointID stored in the ras
 *
 * input  : hApp    - Application's stack handle
 *          eId     - pointer to the buffer for endpoint ID
 *                    buffer should be big enough for longest EID
 *                    possible (256 byte)
 * output : none
 * return : The length of EID in bytes on success
 *          Negative value on failure
 ************************************************************************/
int cmiAutoRASGetEndpointID(
    IN  HAPP    hApp,
    IN  void*   eId)
{
    HRASMGR ras=cmiGetRasHandle(hApp);
    return cmiRASGetEndpointID(ras,eId);
}


/************************************************************************
 * autoRasChangeState
 * purpose: Notify the application about the state of the registration
 * input  : autoras     - Automatic RAS instance
 *          regEvent    - Registration event being notified
 *                        can be a negative value if event is not caused
 *                        by any message but by a timeout
 *          message     - Message that caused the event, or node ID of
 *                        the new permanent alternate GK in such an event.
 *                        Negative value if not applicable
 * output : none
 * return : non-negative value on success
 *          negative value on failure
 ************************************************************************/
int autoRasChangeState(
    IN  autorasEndpoint*    autoRas,
    IN  cmRegEvent          regEvent,
    IN  RvPvtNodeId         message)
{
    /* todo: get cmElem from somewhere else */
    cmEvRegEventT   evFunc;

    /* Notify the application through the callback */
    evFunc = ((cmElem *)autoRas->hApp)->cmMyEvent.cmEvRegEvent;
    if (evFunc != NULL)
    {
        int status;
        if (regEvent == RV_ERROR_UNKNOWN) message = RV_ERROR_UNKNOWN;

#if (RV_LOGMASK_COMPILEMASK & RV_LOGLEVEL_ENTER)
        {
            static const char *autorasStates[] = {"cmIdle", "cmDiscovered", "cmRegistered"};
            static const char *autorasEvents[] =
            {
                "cmGatekeeperConfirm",
                "cmGatekeeperReject",
                "cmRegistrationConfirm",
                "cmRegistrationReject",
                "cmUnregistrationRequest",
                "cmUnregistrationConfirm",
                "cmUnregistrationReject",
                "cmNonStandardMessage",
                "cmResourceAvailabilityConfirmation",
                "cmPermanentAlternateGatekeeperConfirmation"
            };
            cmiCBEnter(autoRas->hApp,
                       "cmEvRegEvent(hApp=0x%p, regState=%s, regEvent=%s, regEventHandle=%d)",
                       autoRas->hApp,
                       nprn(autorasStates[autoRas->state]),
                       nprn(autorasEvents[regEvent]),
                       message);
        }
#endif
        status = evFunc(autoRas->hApp, autoRas->state, regEvent, message);
        cmiCBExit(autoRas->hApp, "cmEvRegEvent=%d", status);
    }

    return 0;
}



/************************************************************************
 *
 *                          Public API functions
 *
 ************************************************************************/

/************************************************************************
 * cmRegister
 * purpose: Registers the endpoint with the gatekeeper.
 *          It is only applicable when the RAS.manualRAS key is not
 *          defined in the configuration (automatic RAS mode).
 *          It reads registration information from RAS.registrationInfo
 *          configuration key.
 * input  : hApp    - Application's handle of the stack
 * output : none
 * return : If an error occurs, the function returns a negative value.
 *          If no error occurs, the function returns a non-negative value.
 ************************************************************************/
RVAPI
int RVCALLCONV cmRegister(
        IN  HAPP        hApp)
{
    autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle(hApp);
    int status;

    if (!hApp || !autoras) return RV_ERROR_UNKNOWN;
    cmiAPIEnter(hApp, "cmRegister(hApp=0x%p)", hApp);

    autoras->regTries = 0;
    cmiRASUpdateRegInfo(cmiGetRasHandle(hApp), RV_TRUE);
    status = autoRasTryToRegister(autoras);

    if (status < 0)
    {
        /* Make sure the timer is not started... */
        RvH323TimerCancel(autoras->hTimers, &autoras->regTimer);
    }

    cmiAPIExit(hApp, "cmRegister: %d", status);
    return status;
}


/************************************************************************
 * cmUnregister
 * purpose: Unregisters the endpoint from the Gatekeeper
 *          It is only applicable when the RAS.manualRAS key is not
 *          defined in the configuration (automatic RAS mode).
 *          It reads registration information from RAS.registrationInfo
 *          configuration key.
 * input  : hApp    - Application's handle of the stack
 * output : none
 * return : If an error occurs, the function returns a negative value.
 *          If no error occurs, the function returns a non-negative value.
 ************************************************************************/
RVAPI
int RVCALLCONV cmUnregister(
        IN  HAPP        hApp)
{
    autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle(hApp);
    int status = 0;

    if (!hApp || !autoras) return RV_ERROR_UNKNOWN;
    cmiAPIEnter(hApp, "cmUnregister(hApp=0x%p)", hApp);

    /* Stop the registration timer if we have one */
    RvH323TimerCancel(autoras->hTimers, &autoras->regTimer);

    /* Make sure we have no pending transactions */
    if (autoras->registrationTx != NULL)
    {
        cmRASClose(autoras->registrationTx);
        autoras->registrationTx = NULL;
    }

    /* If we're registered - we should unregister... */
    if (autoras->state == cmRegistered)
    {
        status = cmRASStartTransaction(autoras->hApp, (HAPPRAS)autoras, &autoras->registrationTx, cmRASUnregistration, NULL, NULL);
        if (status >= 0)
        {
            cmiRASSetTrEventHandler(autoras->registrationTx, autoRasUnregistrationResponse);
            status = cmRASRequest(autoras->registrationTx);
        }
    }

    autoras->internalState = autorasRegNotTried;
    autoras->regTries = 0;

    cmiAPIExit(hApp, "cmUnregister: %d", status);
    return status;

}


/************************************************************************
 * cmSendNonStandardMessage
 * purpose: Sends a nonstandard message to the Gatekeeper
 *          It is only applicable when the RAS.manualRAS key is not
 *          defined in the configuration (automatic RAS mode).
 *          It reads registration information from RAS.registrationInfo
 *          configuration key.
 * input  : hApp    - Application's handle of the stack
 *          nsParam - Nonstandard parameter to be used in non standard message
 * output : none
 * return : If an error occurs, the function returns a negative value.
 *          If no error occurs, the function returns a non-negative value.
 ************************************************************************/
RVAPI
int RVCALLCONV cmSendNonStandardMessage(
     IN      HAPP                hApp,
     IN      cmNonStandardParam* nsParam)
{
    autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle(hApp);
    int status;
    HRAS hRas;

    if (!hApp || !autoras) return RV_ERROR_UNKNOWN;
    cmiAPIEnter(hApp, "cmSendNonStandardMessage(hApp=0x%p)", hApp);

    /* Start the transaction and set the non standard information */
    status = cmRASStartTransaction(autoras->hApp, NULL, &hRas, cmRASNonStandard, NULL, NULL);

    if (status >= 0)
    {
        status = cmRASSetParam(hRas, cmRASTrStageRequest, cmRASParamNonStandard, 0, 0, (char*)nsParam);

        if(status >= 0)
        {
            /* Send the request */
            status = cmRASRequest(hRas);
        }

        /* Close the transaction - it's not waiting for any reply */
        cmRASClose(hRas);
    }


    cmiAPIExit(hApp, "cmSendNonStandardMessage: %d", status);
    return status;
}


/************************************************************************
 * cmSendRAI
 * purpose: Sends a RAI message to the gatekeeper.
 *          It is only applicable when the RAS.manualRAS key is not
 *          defined in the configuration (automatic RAS mode).
 *          It reads registration information from RAS.registrationInfo
 *          configuration key.
 * input  : hApp                    - Application's handle of the stack
 *          almoustOutOfResources   - Indicates that it is or is not almost
 *                                    out of resources
 * output : none
 * return : If an error occurs, the function returns a negative value.
 *          If no error occurs, the function returns a non-negative value.
 ************************************************************************/
RVAPI int RVCALLCONV
cmSendRAI(
       IN      HAPP             hApp,
       IN      RvBool           almostOutOfResources)
{
    autorasEndpoint* autoras = (autorasEndpoint *)cmiGetAutoRasHandle(hApp);
    int status;

    if (!hApp || !autoras) return RV_ERROR_UNKNOWN;
    cmiAPIEnter(hApp, "cmSendRAI(hApp=0x%p, almostOutOfResources=%d)", hApp, almostOutOfResources);

    /* Make sure we're already registered */
    if (autoras->state == cmRegistered)
    {
        HRAS hRas;

        /* Send a RAI transaction */
        status = cmRASStartTransaction(autoras->hApp, (HAPPRAS)autoras, &hRas, cmRASResourceAvailability, NULL, NULL);
        if (status >= 0)
        {
            cmRASSetParam(hRas, cmRASTrStageRequest, cmRASParamAlmostOutOfResources, 0, (RvInt32)almostOutOfResources, NULL);
            cmiRASSetTrEventHandler(hRas, autoRasRaiResponse);
            status = cmRASRequest(hRas);
        }
    }
    else
        status = RV_ERROR_UNKNOWN;

    cmiAPIExit(hApp, "cmSendRAI: %d", status);
    return status;
}




#ifdef __cplusplus
}
#endif


⌨️ 快捷键说明

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