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

📄 psyntree.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
RVAPI pstNodeType RVCALLCONV /* type of node */
pstGetNodeType(
           IN  HPST         hSyn,
           IN  RvPstNodeId  nodeId)
{
    stNodeExt* node;

    if (hSyn != NULL)
    {
        node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
        if (node != NULL)
            return (pstNodeType)m_type(node);
    }

    return (pstNodeType)RV_ERROR_UNKNOWN;
}


RVAPI RvPstNodeId RVCALLCONV /* type of node */
pstGetNodeOfId(
           IN  HPST         hSyn,
           IN  RvPstNodeId  nodeId)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node != NULL)
        return (RvPstNodeId)m_ofId(node);
    else
        return RV_PST_ERROR_UNKNOWN;
}

RVAPI int RVCALLCONV /*the tag of the node or negative value on failure*/
pstGetTag(
         IN  HPST           hSyn,
         IN  RvPstNodeId    nodeId,
         OUT pstTagClass*   tagClass)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node != NULL)
    {
        if (tagClass)
            *tagClass = (pstTagClass)m_tagClass(node);
        return m_tag(node);
    }
    else
        return RV_ERROR_UNKNOWN;
}

RVAPI int RVCALLCONV /*is not extended or negative value on failure*/
pstGetIsExtended(
     IN  HPST           hSyn,
     IN  RvPstNodeId    nodeId)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node != NULL)
        return m_isExtension(node);
    else
        return RV_ERROR_UNKNOWN;
}

RVAPI int RVCALLCONV /*is not extended or negative value on failure*/
pstGetIsOpenType(
     IN  HPST           hSyn,
     IN  RvPstNodeId    nodeId)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node != NULL)
        return m_flags(node) & isOpenType;
    else
        return RV_ERROR_UNKNOWN;
}


RVAPI int RVCALLCONV /* type of node */
pstGetNodeRange(
        IN  HPST        hSyn,
        IN  RvPstNodeId nodeId,
        OUT int*        from,
        OUT int*        to)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node == NULL) return RV_ERROR_UNKNOWN;

    if (from)  *from = m_from(node);
    if (to)    *to   = m_to(node);

    return (m_to(node) == 0)? RV_ERROR_UNKNOWN : 0;
}


RVAPI RvInt32 RVCALLCONV /* Field enumeration or negative value on failure */
pstGetFieldId(
          /* convert field name to internal id */
          IN  HPST hSyn,
          IN  const char *fieldName /* null terminated string */
          )
{
    if (hSyn == NULL) return RV_ERROR_UNKNOWN;

    return stGetNameIdByName(hSyn, (char *)fieldName);
}

RVAPI int RVCALLCONV /* Real length of field name (exluding null) or negative value on failure */
pstGetFieldName(
        /* convert field internal id to field name */
        IN  HPST hSyn,
        IN  RvInt32 fieldId,
        IN  int fieldNameLength, /* num. of bytes in string allocation */
        OUT char* fieldName /* null terminated. user allocated */
        )
{
    char* string;
    int   length;

    string = stGetNameByNameId(hSyn, fieldId, &length);

    /* Check if we've got a valid string to pass on */
    if ((fieldName != NULL) && (fieldNameLength > 0)) fieldName[0] = 0;
    if (string == NULL) return RV_ERROR_UNKNOWN;

    /* Copy the result to the user's buffer */
    if ((fieldName != NULL) && (fieldNameLength > 0))
        strncpy(fieldName, string, (RvSize_t)fieldNameLength);

    return length;
}



RVAPI  int RVCALLCONV /* actual length of the fromString or negative value on failure */
pstGetFROMString(
         /* Get the character constraints of the syntax node */
         IN  HPST hSyn,
         IN  RvPstNodeId nodeId,
         IN  int fromStringLength, /* num. of bytes in string allocation */
         OUT char* fromString /* null terminated. user allocated */
          )
{
    char *string;
    int actualLength;

    if (fromString && fromStringLength>0) fromString[0]=0;
    string=pstGetFROMStringPtr(hSyn, nodeId, &actualLength);
    if (!string || actualLength<0) return RV_ERROR_UNKNOWN;

    if (fromString && fromStringLength>0)
        strncpy(fromString, string, (RvSize_t)fromStringLength);
    return actualLength;
}


RVAPI RvPstNodeId RVCALLCONV /* Internal node id or negative value on failure */
pstGetNodeIdByPath(
           /* get internal node id from specified node path.
              Path to node should start at root, and correspond to the
              ASN module syntax structure. */
           IN  HPST hSyn,
           IN  const char *path  /* format: "a.b.c" */
           )
{
    char name[RV_MAX_PATH];
    RvChar *ptr=NULL, *nameptr=name;
    RvInt32 fieldEnum;
    stChildExt *child = NULL;
    stNodeExt *sNode;
    RvPstNodeId sNodeId;

    if (!hSyn) return RV_PST_ERROR_UNKNOWN;
    if (!path) return pstGetRoot(hSyn);
    strncpy(name, path, RV_MAX_PATH);
    sNodeId = pstGetRoot(hSyn);

    for(;;)
    {
        ptr=(RvChar*) strchr(nameptr,'.');
        if (ptr != NULL) *ptr=0;

        if (nameptr[0] != '\0')
        {
            if (isNumber(nameptr))
            {   /* sequence of index */
                sNode = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)sNodeId);
                sNodeId = (RvPstNodeId)m_ofId(sNode);
            }
            else
            {  /* other */
                if ( (fieldEnum=pstGetFieldId(hSyn, nameptr)) <0) return RV_PST_ERROR_UNKNOWN;
                if (stGetField(hSyn, (int)sNodeId, fieldEnum, &child) <0) return RV_PST_ERROR_UNKNOWN;
                sNodeId = (RvPstNodeId)m_structId(child);
            }
        }

        nameptr=ptr+1;
        if (ptr == NULL)
            break;
    }

    return sNodeId;
}

RVAPI int RVCALLCONV /* get root name */
pstGetRootName(
               IN  HPST  hSyn,
               IN  int   bufferLength,
               OUT char *buffer)
{
    char* string;
    int length;
    synStruct *syn = (synStruct *)hSyn;

    if (syn == NULL) return RV_ERROR_UNKNOWN;
    string = stGetNameByNameId(hSyn, syn->rootNameId, &length);

    if (string == NULL)
    {
        if ((buffer != NULL) && (bufferLength > 0)) buffer[0] = 0;
        return RV_ERROR_UNKNOWN;
    }

    if ((buffer != NULL) && (bufferLength > 0))
        strncpy(buffer, string, (RvSize_t)bufferLength);

    return length;
}

RVAPI int RVCALLCONV
pstGetNumberOfChildren(
        IN HPST         hSyn,
        IN RvPstNodeId  nodeId)
{
    stNodeExt* node;

    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
    if (node != NULL)
        return m_numOfChilds(node);
    else
        return RV_ERROR_UNKNOWN;
}


RVAPI RvPstNodeId RVCALLCONV
pstGetChild(
            IN  HPST        hSyn,
            IN  RvPstNodeId nodeId,      /* node id of parent */
            IN  int         childIndex,  /* index of child */
            OUT pstChild*   child)
{
    stChildExt* fieldInfo;
    RvUint32* err;

    if (child)
        child->index = RV_ERROR_UNKNOWN;  /* assume the worst */

    /* Get the information */
    err = stGetChildByIndex(hSyn, (int)nodeId, childIndex, &fieldInfo);
    if (err == NULL)
        return RV_PST_ERROR_UNKNOWN;

    /* Convert it to something readable */
    if (child)
    {
        child->index      = childIndex;
        child->nodeId     = (RvPstNodeId)m_structId(fieldInfo);
        child->fieldId    = m_fieldId(fieldInfo);
        child->isOptional = m_isOptional(fieldInfo);
    }

    /* We have to return back the nodeId we got on this one */
    return child->nodeId;
}


RVAPI RvBool RVCALLCONV
pstIsStringNode(
       IN  HPST         hSyn,
       IN  RvPstNodeId  nodeId)
{
    pstNodeType type = pstGetNodeType(hSyn, nodeId);
    if (type <0) return RV_FALSE;

    switch (type)
    {
        case pstObjectIdentifier:
        case pstOctetString:
        case pstBitString:
        case pstGeneralString:
        case pstUniversalString:
        case pstBMPString:
        case pstIA5String:
        case pstVisibleString:
        case pstNumericString:
        case pstPrintableString:  return RV_TRUE;
        default:                  break;
    }
    return RV_FALSE;
}




#ifdef __cplusplus
}
#endif



⌨️ 快捷键说明

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