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

📄 cmras.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
int RVCALLCONV cmRASReject(
    IN  HRAS             hsRas,
    IN  cmRASReason      reason)
{
    rasModule*  ras;
    rasInTx*    tx;
    int         status;
    if (hsRas == NULL) return RV_ERROR_UNKNOWN;

    ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
    cmiAPIEnter(ras->app, "cmRASReject(hsRas=0x%p)", hsRas);

    /* Get the transaction */
    tx = rasGetIncoming(hsRas);
    if (tx != NULL)
        status = rasSendRejectMessage(ras, tx, reason);
    else
    {
        RvLogError(&ras->log,
            (&ras->log, "cmRASReject: Bad outgoing transaction handle (0x%p)", hsRas));
        status = RV_ERROR_UNKNOWN;
    }

    cmiAPIExit(ras->app, "cmRASReject(hsRas=0x%p,ret=%d)", hsRas, status);
    return status;
}


/************************************************************************
 * cmRASInProgress
 * purpose: Sends a RIP (ReplyInProgress) message on a transaction
 * input  : hsRas       - Stack's handle for the RAS transaction
 *          delay       - Delay to use in RIP message (in milliseconds)
 * 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 cmRASInProgress(
    IN  HRAS         hsRas,
    IN  int          delay)
{
    rasModule*  ras;
    rasInTx*    tx;
    int         status = 0;
    if (hsRas == NULL) return RV_ERROR_UNKNOWN;

    ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
    cmiAPIEnter(ras->app, "cmRASInProgress(hsRas=0x%p, delay=%d)", hsRas, delay);

    /* Get the transaction */
    tx = rasGetIncoming(hsRas);
    if (tx != NULL)
        status = rasSendRIP(ras, tx, delay, RV_TRUE);
    else
    {
        RvLogError(&ras->log,
            (&ras->log, "cmRASInProgress: Bad outgoing transaction handle (0x%p)", hsRas));
        status = RV_ERROR_UNKNOWN;
    }

    cmiAPIExit(ras->app, "cmRASInProgress(hsRas=0x%p,ret=%d)", hsRas, status);
    return status;
}


/************************************************************************
 * cmRASClose
 * purpose: Close a RAS transaction
 * input  : hsRas       - Stack's handle for the RAS transaction
 * 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 cmRASClose(
    IN  HRAS             hsRas)
{
    rasModule*  ras;
    int         status = 0;
    if (hsRas == NULL) return RV_ERROR_UNKNOWN;

    ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
    cmiAPIEnter(ras->app, "cmRASClose(hsRas=0x%p)", hsRas);
    
#if defined(RV_RAS_DEBUG)
    /* Make sure the application is not calling this function twice for the same handle */
    if (emaWasDeleted((EMAElement)hsRas))
    {
        RvLogError(&ras->log,
            (&ras->log, "cmRASClose: This transaction was already closed (0x%p)", hsRas));
        status = RV_ERROR_UNINITIALIZED;
    }
    else
#endif /* defined(RV_RAS_DEBUG) */

    /* Check if it's an incoming or an outgong transaction */
    switch (emaGetType((EMAElement)hsRas))
    {
        case RAS_OUT_TX:
        {
            rasOutTx* tx;
            tx = rasGetOutgoing(hsRas);

            if (tx != NULL)
                status = rasCloseOutTx(ras, tx);
            else
            {
                RvLogError(&ras->log,
                    (&ras->log, "cmRASClose: Bad outgoing transaction handle (0x%p)", hsRas));
                status = RV_ERROR_UNKNOWN;
            }
            break;
        }
        case RAS_IN_TX:
        {
            rasInTx* tx;
            tx = rasGetIncoming(hsRas);

            if (tx != NULL)
                status = rasCloseInTx(ras, tx);
            else
            {
                RvLogError(&ras->log,
                    (&ras->log, "cmRASClose: Bad incoming transaction handle (0x%p)", hsRas));
                status = RV_ERROR_UNKNOWN;
            }
            break;
        }
        default:
            status = RV_ERROR_UNKNOWN;
    }

    cmiAPIExit(ras->app, "cmRASClose(hsRas=0x%p,ret=%d)", hsRas, status);
    return status;
}






/************************************************************************
 * cmRASGetHandle
 * purpose: Returns the stack's handle of the transaction from the
 *          application's handle.
 *          This function is slow and should not be used frequently
 * input  : hApp        - Application's handle for a stack instance
 *          haRas       - Application's handle for the RAS transaction
 * output : lphsRas     - The stack's RAS transaction handle
 * 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 cmRASGetHandle(
    IN  HAPP    hApp,
    IN  HAPPRAS haRas,
    OUT LPHRAS  hsRas)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
    HRAS hRas;

    /* Search in incoming transactions */
    hRas = NULL;
    while ( (hRas = (HRAS)emaGetNext(ras->inRa, (EMAElement)hRas)) )
        if ((HAPPRAS)emaGetApplicationHandle((EMAElement)hRas) == haRas)
        {
            if (hsRas) *hsRas = hRas;
            return 0;
        }

    /* Search in outgoing transactions */
    while ( (hRas = (HRAS)emaGetNext(ras->outRa, (EMAElement)hRas)) )
        if ((HAPPRAS)emaGetApplicationHandle((EMAElement)hRas) == haRas)
        {
            if (hsRas) *hsRas = hRas;
            return 0;
        }

    /* If we're here, then we haven't found a matching transaction */
    return RV_ERROR_UNKNOWN;
}


/************************************************************************
 * cmRASGetTransaction
 * purpose: Returns the type of RAS transaction
 * input  : hsRas       - Stack's handle for the RAS transaction
 * output : transaction - The type of transaction
 * 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 cmRASGetTransaction(
    IN  HRAS                hsRas,
    OUT cmRASTransaction*   transaction)
{
    rasModule*  ras;
    int         status = 0;

    ras = (rasModule *)emaGetUserData((EMAElement)hsRas);
    cmiAPIEnter(ras->app, "cmRASGetTransaction(hsRas=0x%p)", hsRas);

    /* Get the transaction type */
    if(emaLock((EMAElement)hsRas))
    {
        /* Check if it's an incoming or an outgong transaction */
        switch (emaGetType((EMAElement)hsRas))
        {
        case RAS_OUT_TX:
            {
                rasOutTx* tx;
                tx = rasGetOutgoing(hsRas);

                if (tx != NULL)
                    *transaction = tx->transactionType;
                else
                {
                    RvLogError(&ras->log,
                        (&ras->log, "cmRASGetTransaction: Bad outgoing transaction handle (0x%p)", hsRas));
                    status = RV_ERROR_UNKNOWN;
                }
                break;
            }
        case RAS_IN_TX:
            {
                rasInTx* tx;
                tx = rasGetIncoming(hsRas);

                if (tx != NULL)
                    *transaction = tx->transactionType;
                else
                {
                    RvLogError(&ras->log,
                        (&ras->log, "cmRASGetTransaction: Bad incoming transaction handle (0x%p)", hsRas));
                    status = RV_ERROR_UNKNOWN;
                }
                break;
            }
        default:
            status = RV_ERROR_UNKNOWN;
        }

        emaUnlock((EMAElement)hsRas);
    }

    cmiAPIExit(ras->app, "cmRASGetTransaction(hsRas=0x%p,tx=%d,ret=%d)",
                        hsRas, *transaction, status);
    return status;
}


/************************************************************************
 * cmRASGetLastError
 * purpose: This function does absolutly nothing.
 *          It is only here for backward compatibility.
 * input  : hsRas       - Stack's handle for the RAS transaction
 * output : none
 * return : 0
 ************************************************************************/
RVAPI
cmRASError RVCALLCONV cmRASGetLastError(
    IN  HRAS             hsRas)
{
    if (hsRas);
    return (cmRASError)0;
}



/************************************************************************
 * cmRASSetEventHandler
 * purpose: Sets the callbacks the application wishes to use
 * input  : hApp        - Application's handle for a stack instance
 *          cmRASEvent  - RAS callbacks to set
 *          size        - Size of callbacks struct (*CMRASEVENT)
 * 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 cmRASSetEventHandler(
    IN  HAPP hApp,
    IN  CMRASEVENT cmRASEvent,
    IN  int size)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);

    if (hApp == NULL) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, "cmRASSetEventHandler(hApp=0x%p,size=%d)", hApp, size);

    memset(&ras->evApp, 0, sizeof(SCMRASEVENT));
    memcpy(&ras->evApp, cmRASEvent, (RvSize_t)RvMin(size, (int)sizeof(SCMRASEVENT)));

    cmiAPIExit(hApp, "cmRASSetEventHandler(hApp=0x%p,ret=0)", hApp);
    return 0;
}


/************************************************************************
 * cmAutoRASSetEventHandler
 * purpose: Sets the callbacks the application wishes to use for automatic
 *          RAS. Catching these callbacks allows the application to
 *          know about the messages that the automatic RAS receives.
 *          It doesn't allow the application to act on them - only to
 *          know about them.
 * input  : hApp            - Application's handle for a stack instance
 *          cmAutoRASEvent  - Automatic RAS callbacks to set
 *          size            - Size of callbacks struct (*CMRASEVENT)
 * 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 cmAutoRASSetEventHandler(
    IN  HAPP            hApp,
    IN  CMAUTORASEVENT  cmAutoRASEvent,
    IN  int             size)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);

    if (hApp == NULL) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, "cmAutoRASSetEventHandler(hApp=0x%p,size=%d)", hApp, size);

    memset(&ras->evAutoRas, 0, sizeof(SCMAUTORASEVENT));
    memcpy(&ras->evAutoRas, cmAutoRASEvent, (RvSize_t)RvMin(size, (int)sizeof(SCMAUTORASEVENT)));

    cmiAPIExit(hApp, "cmAutoRASSetEventHandler(hApp=0x%p,ret=0)", hApp);
    return 0;
}




RVAPI
RvInt32 RVCALLCONV cmGetGKCallSignalAddress(
                                        IN  HAPP             hApp,
                                        OUT     cmTransportAddress*  tr)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
    int rc;
    if (hApp == NULL) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, (char*)"cmGetGKCallSignalAddress: hApp=0x%p.", hApp);
    rc= cmVtToTA(ras->hVal,ras->gatekeeperCallSignalAddress, tr);
    cmiAPIExit(hApp, (char*)"cmGetGKCallSignalAddress: [%d].", rc);
    return rc;
}

RVAPI
RvInt32 RVCALLCONV cmGetGKRASAddress(
        IN  HAPP                hApp,
        OUT cmTransportAddress* tr)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
    int rc;
    if (hApp == NULL) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, (char*)"cmGetGKRASAddress: hApp=0x%p.", hApp);
    rc = cmVtToTA(ras->hVal,ras->gatekeeperRASAddress, tr);
    cmiAPIExit(hApp, (char*)"cmGetGKRASAddress: [%d].", rc);
    return rc;
}

/* todo: comment */
RVAPI
HPROTCONN RVCALLCONV cmGetRASConnectionHandle(
                IN  HAPP             hApp)
{
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
    if (hApp == NULL) return NULL;

    cmiAPIEnter(hApp, (char*)"cmGetRASConnectionHandle: hApp=0x%p.", hApp);
    cmiAPIExit(hApp, (char*)"cmGetRASConnectionHandle: [OK].");
    return (HPROTCONN)&(ras->unicastAppHandle);
}


RVAPI
HPROTCONN RVCALLCONV cmGetUdpChanHandle(    IN HCALL hsCall,cmUdpChanHandleType udpChanHandleType)
{
    HPROTCONN hProtCon=NULL;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)hsCall);
    rasModule* ras = (rasModule *)cmiGetRasHandle(hApp);
    if (hApp == NULL) return NULL;

    cmiAPIEnter(hApp,(char*)"cmGetUdpChanHandle: hsCall=0x%p udpChanHandleType = %d",hsCall,udpChanHandleType);
    switch(udpChanHandleType)
    {
        case    cmRasUdpChannel:
            hProtCon =  (HPROTCONN)&(ras->unicastAppHandle);
        break;
        case    cmRasUdpChannelMCast:
            hProtCon =  (HPROTCONN)&(ras->multicastAppHandle);
        break;
    }
    cmiAPIExit(hApp,(char*)"cmGetUdpChanHandle: hProtConn 0x%p",hProtCon);

    return hProtCon;
}

RVAPI
int RVCALLCONV cmSetUdpChanApplHandle(  IN HPROTCONN hCon,HAPPCONN hAppConn)
{
    *(HAPPCONN*)hCon=hAppConn;
    return RV_TRUE;
}

RVAPI
int RVCALLCONV cmGetUdpChanApplHandle(  IN HPROTCONN hCon,HAPPCONN * hAppConn)
{
    if (!hCon)
    {
        *hAppConn=NULL;
        return RV_ERROR_UNKNOWN;
    }

    *hAppConn = (HAPPCONN)*hAppConn;
    return 0;

}


#ifdef __cplusplus
}
#endif


⌨️ 快捷键说明

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