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

📄 cat.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
}


/************************************************************************
 * catAdd
 * purpose: Add a new call into a CAT instance
 * input  : hCat    - CAT instance handle
 *          key     - Key structure to associate with the call
 *          hsCall  - Call handle to put
 * output : none
 * return : CAT call handle on success
 *          NULL on failure
 ************************************************************************/
RVHCATCALL catAdd(
    IN RVHCAT       hCat,
    IN catStruct*   key,
    IN HCALL        hsCall)
{
    catModule*      cat = (catModule *)hCat;
    catDataStruct*  call;
    catKeyStruct    hashKey;
    int             i, curKey;

    RvLockGet(&cat->lock);

    /* Allocate a call in the RA */
    if (raAdd(cat->calls, (RAElement*)&call) < 0)
    {
        RvLogError(&cat->log,
            (&cat->log, "catAdd: Error adding a new call"));
        RvLockRelease(&cat->lock);
        return NULL;
    }

    RvLogDebug(&cat->log,
        (&cat->log, "catAdd: flags=0x%x, hsCall=0x%p, cat=0x%p", key->flags, hsCall, call));

    if (cat->compare15bitCrv)
    {
        key->rasCRV &= 0x7fff;
    }

    catCheckDestCallSignalAddress(cat, key);

    /* Set the values we already know inside the CAT call data */
    memset(call, 0, sizeof(catDataStruct));
    memcpy(&call->key, key, sizeof(catStruct));
    call->hsCall = hsCall;
    hashKey.key = &call->key;

    /* Check to see which key combinations are set inside the key struct and update the hash
       table accordingly */
    curKey = 0;
    for (i = 0; i < CAT_KEY_TYPES; i++)
    {
        if ((key->flags & cat->keyTypes[i]) == cat->keyTypes[i])
        {
            /* We've got a new key to add - first let's make sure we're not out of bounds */
            if (curKey >= cat->numSimultKeys)
            {
                RvLogWarning(&cat->log,
                    (&cat->log,"catAdd: Too many simultaneous keys for hsCall=0x%p", hsCall));
                break;
            }

            /* Create a HASH key out of the value and add it in */
            hashKey.keyValue = cat->keyTypes[i];
            call->hashValues[curKey] = hashAdd(cat->hash, &hashKey, &call, RV_FALSE);
            if ( !(call->hashValues[curKey]) )
            {
                RvLogError(&cat->log,
                    (&cat->log, "catAdd: Counldn't add new call to hash table (hsCall=0x%p, cat=0x%p)", hsCall, call));
            }
            else
                curKey++;
        }
    }

    RvLockRelease(&cat->lock);
    return (RVHCATCALL)call;
}


/************************************************************************
 * catDelete
 * purpose: Delete a call from a CAT instance
 * input  : hCat        - CAT instance handle
 *          hCatCall    - CAT call handle
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int catDelete(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall)
{
    catModule*      cat = (catModule *)hCat;
    catDataStruct*  call = (catDataStruct *)hCatCall;
    int i, status;

    if (hCatCall == NULL) return 0;
    RvLockGet(&cat->lock);

    RvLogDebug(&cat->log,
        (&cat->log, "catDelete: cat=0x%p, hsCall=0x%p", call, call->hsCall));

    /* First we'll remove all hash elements */
    i = 0;
    while ((i < cat->numSimultKeys) && (call->hashValues[i] != NULL))
    {
        hashDelete(cat->hash, call->hashValues[i]);
        i++;
    }

    /* Then we remove the call from RA */
    status = raDelete(cat->calls, (RAElement)call);

    RvLockRelease(&cat->lock);
    return status;
}


/************************************************************************
 * catFind
 * purpose: Find a CAT call handle by a given key struct that can hold
 *          several different keys
 * input  : hCat        - CAT instance handle
 *          key         - Key structure to look for
 * return : CAT call handle on success
 *          NULL on failure or when a call wasn't found
 ************************************************************************/
RVHCATCALL catFind(
    IN  RVHCAT      hCat,
    IN  catStruct*  key)
{
    catModule*      cat = (catModule *)hCat;
    catKeyStruct    catKey;
    catDataStruct*  call;
    void*           location;
    RvUint32        crv;
    int             i;

    catKey.key = key;
    call = NULL;

    /* See if we compare 16bit CRV - we'll have to xor the MSB */
    crv = key->rasCRV;
    if ((key->flags & catRasCRV) && (cat->compare15bitCrv))
        key->rasCRV &= 0x7fff;

    catCheckDestCallSignalAddress(cat, key);

    RvLockGet(&cat->lock);

    /* see if any of the possible keys represent a match */
    for (i = 0; i < CAT_KEY_TYPES; i++)
    {
        if ((key->flags & cat->keyTypes[i]) == cat->keyTypes[i])
        {
            catKey.keyValue = cat->keyTypes[i];
            location = hashFind(cat->hash, &catKey);

            if (location != NULL)
            {
                /* found a match */
                call = *((catDataStruct**)hashGetElement(cat->hash, location));
                break;
            }
        }

    }

    RvLockRelease(&cat->lock);

    /* Make sure we didn't mess up with the CRV value */
    key->rasCRV = crv;

    RvLogDebug(&cat->log,
        (&cat->log, "catFind: cat=0x%p, from keys 0x%x", call, key->flags));

    return (RVHCATCALL)call;
}


/************************************************************************
 * catUpdate
 * purpose: Update a CAT call information with new keys
 * input  : hCat        - CAT instance handle
 *          hCatCall    - CAT call handle to update
 *          key         - Key structure with new information
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int catUpdate(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall,
    IN catStruct*   key)
{
    catModule*      cat = (catModule *)hCat;
    catDataStruct*  call = (catDataStruct *)hCatCall;
    catKeyStruct    hashKey;
    RvUint32        oldFlags;
    int             i, curKey;

    RvLogDebug(&cat->log,
        (&cat->log, "catUpdate: cat=0x%p, with 0x%x - adding 0x%x keys",
             call, call->key.flags, key->flags));

    if (cat->compare15bitCrv)
    {
        key->rasCRV &= 0x7fff;
    }

    catCheckDestCallSignalAddress(cat, key);

    RvLockGet(&cat->lock);

    /* See if there's any new information at all */
    if ((key->flags & call->key.flags) != key->flags)
    {
        /* We've got some updates in here... */

        /* Get all the new values that we need */
        if (((call->key.flags & catCallId) == 0) && ((key->flags & catCallId) != 0))
            memcpy(call->key.callID, key->callID, sizeof(key->callID));
        if (((call->key.flags & catAnswerCall) == 0) && ((key->flags & catAnswerCall) != 0))
            call->key.answerCall = key->answerCall;
        if (((call->key.flags & catCRV) == 0) && ((key->flags & catCRV) != 0))
            call->key.crv = key->crv;
        if (((call->key.flags & catRasCRV) == 0) && ((key->flags & catRasCRV) != 0))
            call->key.rasCRV = key->rasCRV;
        if (((call->key.flags & catDestCallSignalAddr) == 0) && ((key->flags & catDestCallSignalAddr) != 0))
            memcpy(&call->key.destCallSignalAddr, &key->destCallSignalAddr, sizeof(cmTransportAddress));
        if (((call->key.flags & catRasSrcAddr) == 0) && ((key->flags & catRasSrcAddr) != 0))
            memcpy(&call->key.rasSrcAddr, &key->rasSrcAddr, sizeof(cmTransportAddress));
        if (((call->key.flags & catSrcCallSignalAddr) == 0) && ((key->flags & catSrcCallSignalAddr) != 0))
            memcpy(&call->key.srcCallSignalAddr, &key->srcCallSignalAddr, sizeof(cmTransportAddress));
        if (((call->key.flags & catCID) == 0) && ((key->flags & catCID) != 0))
            memcpy(call->key.cid, key->cid, sizeof(key->cid));

        /* Make sure we also update the flags */
        oldFlags = call->key.flags;
        call->key.flags |= key->flags;

        /* Find out how many key combinations we currently have */
        curKey = 0;
        while ((curKey < cat->numSimultKeys) && (call->hashValues[curKey] != NULL)) curKey++;

        /* Insert the new available key combinations to the hash */
        for (i = 0; i < CAT_KEY_TYPES; i++)
        {
            if (((oldFlags & cat->keyTypes[i]) != cat->keyTypes[i]) &&
                ((key->flags & cat->keyTypes[i]) == cat->keyTypes[i]))
            {
                /* We've got a new key to add - first let's make sure we're not out of bounds */
                if (curKey >= cat->numSimultKeys)
                {
                    RvLogWarning(&cat->log,
                        (&cat->log, "catUpdate: Too many simultaneous keys for cat=0x%p, hsCall=0x%p", call, call->hsCall));
                    break;
                }

                /* Create a HASH key out of the value and add it in */
                hashKey.key = &call->key;
                hashKey.keyValue = cat->keyTypes[i];
                call->hashValues[curKey] = hashAdd(cat->hash, &hashKey, &call, RV_FALSE);
                if ( !(call->hashValues[curKey]) )
                {
                    RvLogError(&cat->log,
                        (&cat->log, "catUpdate: Counldn't add new call to hash table (hsCall=0x%p, cat=0x%p)", call->hsCall, call));
                }
                else
                    curKey++;
            }
        }
    }

    RvLockRelease(&cat->lock);

    return 0;
}


/************************************************************************
 * catGetCallHandle
 * purpose: Return the call handle of a CAT call handle
 * input  : hCat        - CAT instance handle
 *          hCatCall    - CAT call handle
 * output : none
 * return : HCALL for the CAT call handle on success
 *          NULL on failure
 ************************************************************************/
HCALL catGetCallHandle(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall)
{
    catDataStruct*  call = (catDataStruct *)hCatCall;
    if (hCat);
    if(call)
        return call->hsCall;
    return NULL;
}


/************************************************************************
 * catGetKey
 * purpose: Return the key struct stored inside a CAT call handle
 * input  : hCat        - CAT instance handle
 *          hCatCall    - CAT call handle
 * output : none
 * return : Key struct for the CAT call handle on success
 *          NULL on failure
 ************************************************************************/
catStruct* catGetKey(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall)
{
    catDataStruct*  call = (catDataStruct *)hCatCall;
    if (hCat);
    return &call->key;
}


/************************************************************************
 * catGetUnsolicitedIRR
 * purpose: Return the unsolicited IRR handle stored inside a CAT call handle
 * input  : hCat            - CAT instance handle
 *          hCatCall        - CAT call handle
 *          unsolicitedIRR  - Handle of the unsolicited IRR to set
 * output : none
 * return : Unsolicited IRR transaction handle for the CAT call handle on success
 *          NULL on failure
 ************************************************************************/
HRAS catGetUnsolicitedIRR(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall)
{
    HRAS    tx;
    catDataStruct*  call = (catDataStruct *)hCatCall;
    if (hCat);

    RvLockGet(&((catModule *)hCat)->lock);
    tx = call->unsolicitedIRR;
    RvLockRelease(&((catModule *)hCat)->lock);

    return tx;
}


/************************************************************************
 * catSetUnsolicitedIRR
 * purpose: Set the unsolicited IRR handle stored inside a CAT call handle
 * input  : hCat            - CAT instance handle
 *          hCatCall        - CAT call handle
 *          unsolicitedIRR  - Handle of the unsolicited IRR to set
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int catSetUnsolicitedIRR(
    IN RVHCAT       hCat,
    IN RVHCATCALL   hCatCall,
    IN HRAS         unsolicitedIRR)
{
    catDataStruct*  call = (catDataStruct *)hCatCall;
    if (hCat);

    RvLockGet(&((catModule *)hCat)->lock);
    call->unsolicitedIRR = unsolicitedIRR;
    RvLockRelease(&((catModule *)hCat)->lock);

    return 0;
}



#ifdef __cplusplus
}
#endif


⌨️ 快捷键说明

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