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

📄 cmutils.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 3 页
字号:
           string itself. This kind of thing isn't the best of choices, but it allows
           us to support existing applications that don't supply the length of their
           buffer and instead give (hopefully) a big enough buffer. */
        alias->length=(RvUint16)length;
        if (isString)
            pvtGetString(hVal,chNodeId,length,alias->string);

        /* For numbers we put a NULL termination. Other types don't get such treatment
           since we're not sure if the user gave us a buffer of 512 bytes or 513 bytes
           for it */
        if (alias->type==cmAliasTypeE164 || alias->type==cmAliasTypePartyNumber)
        {
            alias->string[length]=0;
            alias->length=(RvUint16)strlen(alias->string);
        }
    }
    return 0;
}


RVAPI int RVCALLCONV cmAlias2Vt(IN  HPVT    hVal,
                                IN  cmAlias*alias,
                                IN  int     nodeId)
{
    return aliasToVt(hVal,alias,nodeId);
}

/************************************************************************
 * cmVt2Alias
 * purpose: Converts a PVT subtree of AliasAddress type into an Alias
 * input  : hVal    - The PVT handle
 *          nodeId  - PVT subtree of AliasAddress type we want to convert
 * output : alias   - Alias struct converted. The application is responsible
 *                    to supply the string field inside the cmAlias struct
 *                    with enough allocated size.
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI int RVCALLCONV cmVt2Alias(
    IN  HPVT       hVal,
    OUT cmAlias*   alias,
    IN  int        nodeId)
{
    return vtToAlias(hVal,alias,nodeId);

}


int cmVtToTA(HPVT hVal,int nodeId, cmTransportAddress* ta)
{
    /* We can't use _q931() macros here since this function can be used for H450 ASN.1, which
       has different values for those fieldIDs. */
    RvUint32 p;
    int vNodeId, addrNodeId;
    int len;
    static const cmTransportType asn2type[]={
        cmTransportTypeIP,
        cmTransportTypeIPStrictRoute,
        (cmTransportType)-1,
        (cmTransportType)-1,
        (cmTransportType)-1,
        cmTransportTypeNSAP,
        (cmTransportType)-1};

    memset(ta,0,sizeof(cmTransportAddress));
    if (nodeId<0)
        return RV_ERROR_UNKNOWN;
    addrNodeId = pvtChild(hVal,nodeId);
    if (addrNodeId<0) return RV_ERROR_UNKNOWN;

    ta->type=asn2type[pvtGetSyntaxIndex(hVal,addrNodeId)-1];
    switch(ta->type)
    {
        case cmTransportTypeIP:
            /* ASN.1:
                ipAddress   SEQUENCE
                {
                    ip          OCTET STRING (SIZE(4)),
                    port            INTEGER(0..65535)
                },
            */
            vNodeId = pvtChild(hVal, addrNodeId); /* ip */
            if (pvtGet(hVal, vNodeId, NULL, NULL, &len, NULL) < 0)
                return RV_ERROR_UNKNOWN;
            if (len != sizeof(RvUint32))
                ta->ip = 0;
            else
                pvtGetString(hVal, vNodeId, sizeof(RvUint32), (char*)&(ta->ip));

            vNodeId = pvtBrother(hVal, vNodeId); /* port */
            if (pvtGet(hVal, vNodeId, NULL, NULL, (RvInt32*)&p, NULL) < 0)
                return RV_ERROR_UNKNOWN;
            ta->port = (RvUint16)p;
            break;
        default:
            return RV_ERROR_UNKNOWN;
    }
    return 0;
}

int cmTAToVt(HPVT hVal,int nodeId, cmTransportAddress* ta)
{
    /* We can't use _q931() macros here since this function can be used for H450 ASN.1, which
       has different values for those fieldIDs. */
    int addrNodeId;
    int iPort;

    addrNodeId = pvtBuildByPath(hVal, nodeId, "ipAddress", 0, NULL);
    pvtBuildByPath(hVal, addrNodeId, "ip", sizeof(RvUint32), (ta->ip)?((char*)&(ta->ip)):(char*)"\0\0\0");
    iPort = ta->port;
    return pvtBuildByPath(hVal, addrNodeId, "port", iPort, NULL);
}

int cmVtToTA_H245(HPVT hVal,int nodeId, cmTransportAddress* ta)
{
    RvUint32 p;
    int vNodeId, addrNodeId;
    int len;
    int result = RV_OK;

    static const cmTransportType asn2typeU[]={
        cmTransportTypeIP,
        (cmTransportType)-1,
        (cmTransportType)-1,
        (cmTransportType)-1,
        cmTransportTypeIPStrictRoute,
        cmTransportTypeNSAP,
        (cmTransportType)-1};
    static const cmTransportType asn2typeM[]={
        cmTransportTypeIP,
        (cmTransportType)-1,
        cmTransportTypeNSAP,
        (cmTransportType)-1};

    memset(ta,0,sizeof(cmTransportAddress));
    if (nodeId<0)
        return RV_ERROR_UNKNOWN;
    addrNodeId=pvtChild(hVal,nodeId);

    ta->distribution=(cmDistribution)(pvtGetSyntaxIndex(hVal,addrNodeId)-1);
    addrNodeId=pvtChild(hVal,addrNodeId);
    ta->type=(ta->distribution==cmDistributionMulticast)?
        asn2typeM[pvtGetSyntaxIndex(hVal,addrNodeId)-1]:
        asn2typeU[pvtGetSyntaxIndex(hVal,addrNodeId)-1];
    switch(ta->type)
    {
        case cmTransportTypeIP:
            if (pvtGetChild(hVal, addrNodeId, __h245(network), &vNodeId)<0) return RV_ERROR_UNKNOWN;
            if (pvtGet(hVal, vNodeId,NULL,NULL,&len,NULL)<0) return RV_ERROR_UNKNOWN;
            if (len!=sizeof(RvUint32)) ta->ip=0;
            else pvtGetString(hVal,vNodeId,sizeof(RvUint32),(char*)&(ta->ip));

            if (pvtGetChild(hVal, addrNodeId, __h245(tsapIdentifier), &vNodeId)<0) return RV_ERROR_UNKNOWN;

            if (pvtGet(hVal, vNodeId,NULL,NULL,(RvInt32*)&p,NULL)<0) return RV_ERROR_UNKNOWN;
            ta->port=(RvUint16)p;
        break;

#if (RV_H323_TRANSPORT_ADDRESS != RV_H323_TRANSPORT_ADDRESS_IPV4_ONLY)
        case cmTransportTypeNSAP:
            ta->length=(RvUint16)pvtGetString(hVal,addrNodeId,20,(char*)ta->route);
        break;
#endif

        default:
            result = RV_ERROR_UNKNOWN;
        break;
    }
    return result;
}

int cmTAToVt_H245(HPVT hVal,int nodeId, cmTransportAddress* ta)
{
    int addrNodeId;
    int iPort;
    addrNodeId= pvtAddBranch(hVal,nodeId,(ta->distribution)?__h245(multicastAddress):__h245(unicastAddress));
    addrNodeId= pvtAddBranch(hVal, addrNodeId, __h245(iPAddress));
    pvtAdd(hVal, addrNodeId, __h245(network),sizeof(RvUint32),(ta->ip)?((char*)&(ta->ip)):(char*)"\0\0\0", NULL);
    iPort = ta->port;
    return pvtAdd(hVal, addrNodeId,__h245(tsapIdentifier),iPort,NULL,NULL);
}

/**************************************************************************************
 * RvH323CoreToCmAddress
 *
 * Purpose: Convert a core address into a CM address.
 *
 * Input:   coreAddress - Core adress to convert
 * Output:  cmAddress   - CM address to create
 * Returns: RV_OK on success, other on failure
 **************************************************************************************/
RvStatus RvH323CoreToCmAddress(
    IN  RvAddress*          coreAddress,
    OUT cmTransportAddress* cmAddress)
{
    RvStatus res = RV_ERROR_UNKNOWN;

    switch (RvAddressGetType(coreAddress))
    {
    case RV_ADDRESS_TYPE_IPV4:
        {
            const RvAddressIpv4* ipv4;
            cmAddress->type = cmTransportTypeIP;

            ipv4 = RvAddressGetIpv4(coreAddress);
            if (ipv4 != NULL)
            {
                if (RvAddressIsMulticastIp(coreAddress))
                    cmAddress->distribution = cmDistributionMulticast;
                else
                    cmAddress->distribution = cmDistributionUnicast;

                cmAddress->ip = RvAddressIpv4GetIp(ipv4);
                cmAddress->port = RvAddressGetIpPort(coreAddress);
                res = RV_OK;
            }
        }
#ifdef RV_IPV6
    case RV_ADDRESS_TYPE_IPV6:
        {
        }
#endif /* RV_IPV6 */
    default:
        break;
    }

    if (res != RV_OK)
    {
        /* Make sure we trash the CM address */
        cmAddress->type = (cmTransportType)0xffff;
    }

    return res;
}


/**************************************************************************************
 * RvH323CmToCoreAddress
 *
 * Purpose: Convert a CM address into a core address.
 *
 * Input:   cmAddress   - CM address to create
 * Output:  coreAddress - Core adress to convert. This address must be destructed
 *                        by the caller to this function
 * Returns: RV_OK on success, other on failure
 **************************************************************************************/
RvStatus RvH323CmToCoreAddress(
    IN  cmTransportAddress* cmAddress,
    OUT RvAddress*          coreAddress)
{
    RvStatus res = RV_ERROR_UNKNOWN;

    switch (cmAddress->type)
    {
    case cmTransportTypeIP:
        {
            if (RvAddressConstructIpv4(coreAddress, cmAddress->ip, cmAddress->port) != NULL)
            res = RV_OK;
        }
        break;

    default:
        res = RV_ERROR_UNKNOWN;
        break;
    }

    return res;
}


/**************************************************************************************
 * RvH323CmPrintMessage
 *
 * Purpose: Print an incoming or an outgoing message to the logfile.
 *
 * Input:   logSource           - Log source to print into
 *          messageStr          - String to use before printing the message
 *          hVal                - Value tree to use
 *          messageNodeId       - Message root node to print. Shout be set to -1 if decoding
 *                                of the buffer failed for incoming messages.
 *          messageBuffer       - Message buffer to print
 *          messageBufferSize   - Size of the message buffer. Should be set to -1 if encoding
 *                                of the nodeId failed for outgoing messages.
 *          isIncoming          - RV_TRUE if the message is incoming, RV_FALSE for outgoing
 * Output:  None
 * Returns: None
 **************************************************************************************/
#if (RV_LOGMASK_COMPILEMASK & (RV_LOGLEVEL_DEBUG | RV_LOGLEVEL_ERROR))
void RvH323CmPrintMessage(
    IN RvLogSource*     logSource,
    IN const RvChar*    messageStr,
    IN HPVT             hVal,
    IN RvPvtNodeId      messageNodeId,
    IN RvUint8*         messageBuffer,
    IN int              messageBufferSize,
    IN RvBool           isIncoming)
{
    int debugLevel;
    RvBool printAll;

    debugLevel = msGetDebugLevel();

    /* Make sure debug level is high enough */
    printAll = ((debugLevel > 1) && RvLogIsSelected(logSource, RV_LOGLEVEL_DEBUG));

    if (isIncoming)
    {
        /* Incoming */
        if (printAll)
        {
            RvLogTextDebug(logSource, messageStr);
            printHexBuff(messageBuffer, messageBufferSize, logSource);
        }

        if (messageNodeId >= 0)
        {
            if (printAll)
            {
                RvLogTextDebug(logSource, "Message:");
                pvtPrintInternal(hVal, messageNodeId, logSource, debugLevel);
            }
        }
        else
        {
            RvLogError(logSource, (logSource, "Decoding problems (%d)", messageNodeId));
        }
    }
    else
    {
        /* Outgoing */
        if (printAll)
        {
            RvLogTextDebug(logSource, messageStr);
            pvtPrintInternal(hVal , messageNodeId, logSource, debugLevel);
        }

        if (messageBufferSize >= 0)
        {
            if (printAll)
            {
                RvLogTextDebug(logSource, "Binary:");
                printHexBuff(messageBuffer, messageBufferSize, logSource);
            }
        }
        else
        {
            RvLogError(logSource, (logSource, "Encoding problems (nodeId=%d)", messageNodeId));
        }
    }

⌨️ 快捷键说明

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