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

📄 ospasn1parse.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 5 页
字号:
        /* Update parse result */        OSPM_MEMSET(parseResult->DataReference, 0xff,             OSPC_ASN1_DATAREF_MAXLENGTH);        if (ospvDataRef != 0)        {            parseResult->DataReference[0] = ospvDataRef;        }        /* Attach the element info object */        parseResult->ElementInfo = ospvElementInfo;    }    if (errorcode != OSPC_ERR_NO_ERROR)    {        PTPResultsDelete(ospvParseResult);    }    else    {        *ospvParseResult = parseResult;    }    return errorcode;}intPTPTableGet(    OSPEASN1PARSETABLEID ospvParseTableId,    OSPTASN1PARSETABLE *ospvParseTable[]){       int errorcode = OSPC_ERR_NO_ERROR;    *ospvParseTable = ospgParseTableIndex[ospvParseTableId];     return errorcode ;}int PTPTableGetRule(    OSPEASN1PARSETABLEID ospvParseTableId,     OSPTASN1PARSERULE   **ospvParseRule,    unsigned int *ospvRuleIndex)        /* Updated to point to next rule */{    int errorcode = OSPC_ERR_NO_ERROR;    OSPTASN1PARSETABLE *parseTable = OSPC_OSNULL;    errorcode = PTPTableGet(ospvParseTableId, &parseTable );    if (errorcode == OSPC_ERR_NO_ERROR)    {        *ospvParseRule = &(parseTable[*ospvRuleIndex]);         (*ospvRuleIndex)++;        if ( *ospvParseRule != OSPC_OSNULL )        {            if ((*ospvParseRule)->Name == OSPC_OSNULL)            {                *ospvParseRule = OSPC_OSNULL;                errorcode = OSPC_ERR_ASN1_PARSE_COMPLETE;            }        }    }    return errorcode ;}intPTPRuleIsOptional(    OSPTASN1PARSERULE *ospvParseRule){    return (ospvParseRule->MinimumCount == 0);}int                                     /* Boolean */PTPRuleIsPrimitive(    OSPTASN1PARSERULE *ospvParseRule){    int is_primitive = 0;    switch(ospvParseRule->Tag)     {        case OSPC_TAG_TYPE_SEQUENCE:        case OSPC_TAG_TYPE_SET:        /* These types are always NOT primitive */        is_primitive = 0;        break;        case OSPC_TAG_TYPE_DER_FORMAT:        /* This one is always primitive - used to stop parsing for             a construct */        is_primitive = 1;        break;        default:        /* Probably primitive unless tag type is EXPLICIT */        is_primitive = !(OSPM_IS_EXPLICIT(ospvParseRule->Tag));        break;    }               return is_primitive;}intPTPRuleIsDerived(    OSPTASN1PARSERULE *ospvParseRule){    return(ospvParseRule->Tag == OSPC_TAG_TYPE_DERIVED);}intPTPRuleIsDERFormat(    OSPTASN1PARSERULE *ospvParseRule){    return(ospvParseRule->Tag == OSPC_TAG_TYPE_DER_FORMAT);}int PTPRuleGetParseTableId(     OSPTASN1PARSERULE *ospvParseRule,     OSPEASN1PARSETABLEID *ospvParseTableId){    int errorcode = OSPC_ERR_NO_ERROR;    *ospvParseTableId = ospvParseRule->ParseTableId;    return errorcode;}voidPTPResultsDelete(     OSPTASN1PARSERESULT **ospvParseResult){    OSPTASN1PARSERESULT *thisResult = OSPC_OSNULL;    OSPTASN1PARSERESULT *nextResult = OSPC_OSNULL;    if (ospvParseResult != OSPC_OSNULL)     {        for (   thisResult = *ospvParseResult;             thisResult != OSPC_OSNULL;             thisResult = nextResult)        {            /* Point at the next element */            nextResult = thisResult->NextResult;            /* Remove the current list node */            OSPM_FREE(thisResult);        }        *ospvParseResult = OSPC_OSNULL;    }}int PTPDataReferencesMatch(    unsigned char *ospvDataReferenceId1,    unsigned char *ospvDataReferenceId2){    unsigned char *ptr1 = OSPC_OSNULL;    unsigned char *ptr2 = OSPC_OSNULL;    /* Data reference ids are unsigned char arrays terminated with 0xff */    for(ptr1 = ospvDataReferenceId1, ptr2 = ospvDataReferenceId2;        ptr1 && ptr2 && (*ptr1 == *ptr2) && (*ptr1 != 0xff) && (*ptr2 != 0xff);        ptr1++, ptr2++);    return ((*ptr1 == 0xff) && (*ptr2 == 0xff));}intPTPResultIsRuleComponent(    unsigned char *ospvRuleDataReference,    unsigned char *ospvResultDataReference){    unsigned char *ptr1 = OSPC_OSNULL;    unsigned char *ptr2 = OSPC_OSNULL;    /* Data reference ids are unsigned char arrays terminated with 0xff, if    hit the end of the rule DataReference, then the result data reference    must match up to the end of the rule data reference.  */    for(ptr1 = ospvRuleDataReference, ptr2 = ospvResultDataReference;        ptr1 && ptr2 && (*ptr1 == *ptr2) && (*ptr1 != 0xff) && (*ptr2 != 0xff);        ptr1++, ptr2++);    return (*ptr1 == 0xff);}intPTPDataRefIdGetValue(    OSPEASN1DATAREFID ospvDataRefId,    unsigned char **ospvDataRefValue){    int errorcode = OSPC_ERR_NO_ERROR;    if (ospvDataRefId >= OSPEDRID_LAST_DRID)    {        errorcode = OSPC_ERR_ASN1_INVALID_DATAREFID;        OSPM_DBGERRORLOG(errorcode, "Invalid data reference id value");    }    else    {        *ospvDataRefValue = ospgDataRefIdIndex[ospvDataRefId];    }    return errorcode;}intPTPResultsGetElement(    OSPEASN1DATAREFID   ospvDataReferenceId,    OSPTASN1PARSERESULT *ospvParseResult,    OSPTASN1ELEMENTINFO **ospvFoundElement){    int errorcode = OSPC_ERR_NO_ERROR;    OSPTASN1PARSERESULT *thisResult = OSPC_OSNULL;    unsigned char *dataReference = OSPC_OSNULL;    errorcode = PTPDataRefIdGetValue(ospvDataReferenceId, &dataReference);    if (errorcode == OSPC_ERR_NO_ERROR)    {        for (   thisResult = ospvParseResult, *ospvFoundElement = OSPC_OSNULL;            (thisResult != OSPC_OSNULL) &&             (*ospvFoundElement == OSPC_OSNULL);            thisResult = thisResult->NextResult)        {            if (PTPDataReferencesMatch(dataReference,                 thisResult->DataReference))            {                *ospvFoundElement = thisResult->ElementInfo;                break;            }        }    }    return errorcode;}voidPTPResultUpdateDataRef(    unsigned char ospvParentDataRef,    OSPTASN1PARSERESULT *ospvParseResult){    int i = 0;    unsigned char *ucptr = OSPC_OSNULL;    OSPTASN1PARSERESULT *nextResult = OSPC_OSNULL;    /* Updates the data references in all of the parse results from the    head to the tail by prefixing them with the value retrieved for the    supplied DataRefId. */    if (ospvParseResult == OSPC_OSNULL)    {        OSPM_DBGERRORLOG(-1, "WARNING: ospvParseResult=NULL in UpdateDataRef");    }    else    {        for (nextResult = ospvParseResult ; nextResult != OSPC_OSNULL;            nextResult = nextResult->NextResult)        {            ucptr = nextResult->DataReference;            /* Make space for the new reference */            for (i = (OSPC_ASN1_DATAREF_MAXLENGTH-1) ; ucptr && (i > 0) ; i--)            {                ucptr[i] = ucptr[i-1];            }            *ucptr = ospvParentDataRef;            /* Test Data Reference to make sure it is terminated,                trash it if not */            if (ucptr[OSPC_ASN1_DATAREF_MAXLENGTH-1] != 0xff)            {                /* The Data Reference overflowed - should always                terminate with 0xff, set to 0xff when adding result */                ucptr[0] = 0xff;            }        }    }           return;}intPTPResultsCreate(    OSPTASN1PARSERESULT **ospvParseResult,    OSPTASN1ELEMENTINFO *ospvElement,    OSPEASN1DATAREFID   ospvDataRefId){    int errorcode = OSPC_ERR_NO_ERROR;    OSPTASN1PARSERESULT *parseResults = OSPC_OSNULL;    unsigned char *dataReference = OSPC_OSNULL;    OSPM_MALLOC(parseResults, OSPTASN1PARSERESULT, sizeof(OSPTASN1PARSERESULT));     if (parseResults == OSPC_OSNULL)    {        errorcode = OSPC_ERR_ASN1_UNABLE_TO_ALLOCATE_SPACE;        OSPM_DBGERRORLOG(errorcode,             "Unable to allocate 

⌨️ 快捷键说明

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