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

📄 gen-dec.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 5 页
字号:
}  /*  PrintCBerSeqDecodeCode *//* * Generates code for internally defined lists * eg: * TypeX = SET { foo INTEGER, bar SEQUENCE OF INTEGER } --> * BerDecodeTypeX (b, len, v, bytesDecoded, env) * { *    ... *         listLen1 = BerDecodeLen (b, &totalElmtsLen, env); *         retVal->bar = NewList(); *         for ( ; totalElmtsLen1 < listLen1 || listLen1== INDEFINITE_LEN;) *         { *              tagId1 = BerDecodeTag (b, &totalElmtsLen1, env); *               check for EOC *              elmtLen1 = BerDecodeLen (b, &totalElmtsLen1, env) *              tmpInt = Asn1Alloc (sizeof (int)); *              BerDecodeInteger (b, elmtLen1, tmpInt, &totalElmtsLen1, env); *              AppendList (retVal->bar, tmpInt); *         } *         totalElmtsLen += totalElmtsLen1; *    ... * } */static voidPrintCBerListDecoderCode PARAMS ((src, td, list, elmtLevel, totalLevel, tagLevel, varName),    FILE *src _AND_    TypeDef *td _AND_    Type *list _AND_    int elmtLevel _AND_    int totalLevel _AND_    int tagLevel _AND_ char *varName){    CTRI *ctri;    TagList *tags;    Tag  *tag;    Tag  *lastTag;    enum BasicTypeChoiceId builtinType;    char *classStr;    BER_FORM form;    char *formStr;    char *codeStr;    int   mandatoryCount = 0;    int   i;    char tmpVarName[MAX_VAR_REF];    int  stoleChoiceTags;    char *routineName;    int initialTagLevel;    int initialElmtLevel;    int taglessAny;    initialTagLevel = tagLevel;    initialElmtLevel = elmtLevel;    routineName = td->cTypeDefInfo->decodeRoutineName;    ctri = list->basicType->a.setOf->cTypeRefInfo;    tags  = GetTags (list->basicType->a.setOf, &stoleChoiceTags);    builtinType = GetBuiltinType (list->basicType->a.setOf);    taglessAny = (((tags == NULL) || LIST_EMPTY (tags)) &&                  ((builtinType == BASICTYPE_ANY) ||                   (builtinType == BASICTYPE_ANYDEFINEDBY)));    fprintf (src, "    for (totalElmtsLen%d = 0; (totalElmtsLen%d < elmtLen%d) || (elmtLen%d == INDEFINITE_LEN);)\n", totalLevel, totalLevel, elmtLevel, elmtLevel);    fprintf (src, "    {\n");    fprintf (src,"        %s **tmpVar;\n", ctri->cTypeName);    if (taglessAny)    {        fprintf (src, "    tagId%d = BufPeekByte (b);\n\n", ++tagLevel);        fprintf (src, "    if ((tagId%d == EOC_TAG_ID) && (elmtLen%d == INDEFINITE_LEN))\n", tagLevel, elmtLevel);        fprintf (src, "    {\n");        fprintf (src, "        BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel);        fprintf (src, "        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/\n");        fprintf (src, "    }\n");    }    else    {        fprintf (src, "    tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", ++tagLevel, totalLevel);        fprintf (src, "    if ((tagId%d == EOC_TAG_ID) && (elmtLen%d == INDEFINITE_LEN))\n", tagLevel, elmtLevel);        fprintf (src, "    {\n");        fprintf (src, "        BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel);        fprintf (src, "        break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/\n");        fprintf (src, "    }\n");    }    if ((tags == NULL) || LIST_EMPTY (tags))    {        if (!taglessAny)            fprintf (src, "<What? no tag on a SET OF/SEQ OF Elmt?>\n");/*        else        {            fprintf (src,"    if (tagId%d == MAKE_TAG_ID (?, ?, ?))",tagLevel);            fprintf (src,"    {\n");        }*/    }    else if (!stoleChoiceTags) /* choice decoder will check tag */    {        tag = (Tag*)FIRST_LIST_ELMT (tags);        classStr = Class2ClassStr (tag->tclass);        codeStr = Code2UnivCodeStr (tag->code);        formStr = Form2FormStr (tag->form);        if (tag->tclass == UNIV)        {            if (tag->form == ANY_FORM)            {                fprintf (src,"    if ((tagId%d == MAKE_TAG_ID (%s, %s, %s)) ||", tagLevel, classStr, Form2FormStr (PRIM), codeStr);                fprintf (src,"         (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (CONS), codeStr);            }            else                fprintf (src,"    if ((tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, formStr, codeStr);        }        else        {            if (tag->form == ANY_FORM)            {                fprintf (src,"    if ((tagId%d == MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), tag->code);                fprintf (src,"       (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, Form2FormStr (CONS), tag->code);            }            else                fprintf (src,"    if ((tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, formStr, tag->code);        }        fprintf (src,")\n");        fprintf (src, "    {\n");        fprintf (src, "        elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel);        AsnListFirst (tags);        AsnListNext (tags);        FOR_REST_LIST_ELMT (tag, tags)        {            tagLevel = initialTagLevel+2;            fprintf (src, "        tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, totalLevel);            classStr = Class2ClassStr (tag->tclass);            codeStr = Code2UnivCodeStr (tag->code);            formStr = Form2FormStr (tag->form);            if (tag->tclass == UNIV)            {                if (tag->form == ANY_FORM)                {                    fprintf (src,"    if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), codeStr);                    fprintf (src,"        (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel, classStr, Form2FormStr (CONS), codeStr);                }                else                    fprintf (src,"    if (tagId%d != MAKE_TAG_ID (%s, %s, %s))\n", tagLevel, classStr, formStr, codeStr);            }            else            {                if (tag->form == ANY_FORM)                {                    fprintf (src,"    if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), tag->code);                    fprintf (src,"        (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel, classStr, Form2FormStr (CONS), tag->code);                }                else                    fprintf (src,"    if (tagId%d != MAKE_TAG_ID (%s, %s, %d))\n", tagLevel, classStr, formStr, tag->code);            }            fprintf (src,"    {\n");            fprintf (src,"         Asn1Error (\"Unexpected Tag\\n\");\n");            fprintf (src,"         longjmp (env, %d);\n", (*longJmpValG)--);            fprintf (src,"    }\n\n");            fprintf (src,"    elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel);        }    }    if (stoleChoiceTags)    {        fprintf (src, "        elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel);    }    strcpy (tmpVarName, "(*tmpVar)");    fprintf (src,"    tmpVar = (%s**) AsnListAppend (%s);\n", ctri->cTypeName, varName);    fprintf (src, "    %s = (%s*) Asn1Alloc (sizeof (%s));\n", tmpVarName, ctri->cTypeName, ctri->cTypeName);    fprintf (src,"    CheckAsn1Alloc (%s, env);\n", tmpVarName);    PrintCBerElmtDecodeCode (src, td, list, list->basicType->a.setOf, elmtLevel, totalLevel, tagLevel, varName, tmpVarName, stoleChoiceTags);    /*     * must check for another EOC for ANYs     * Since the any decode routines     * decode their own first tag/len pair     */    if ((builtinType == BASICTYPE_ANY) ||        (builtinType == BASICTYPE_ANYDEFINEDBY))        PrintEocDecoders (src, elmtLevel, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG);        /*         * must check for another EOC for tagged CHOICEs         * since the choice decoder routines do not check         * for an EOC on the choice's overall length -         * they are only passed the tag/len of the choice's         * component.         */    else if ((builtinType == BASICTYPE_CHOICE) && (!stoleChoiceTags) &&             ((tags != NULL) && !LIST_EMPTY (tags)))        PrintEocDecoders (src, elmtLevel, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG);    else        PrintEocDecoders (src, elmtLevel-1, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG);    if ((!stoleChoiceTags) && (!taglessAny))    {        fprintf (src, "    }  /* end of tag check if */\n");        fprintf (src, "    else  /* wrong tag */\n");        fprintf (src,"    {\n");        fprintf (src,"         Asn1Error (\"Unexpected Tag\\n\");\n");        fprintf (src,"         longjmp (env, %d);\n", (*longJmpValG)--);        fprintf (src,"    }\n");    }    fprintf (src, "    } /* end of for */\n\n");    FreeTags (tags);}  /*  PrintCBerListDecodeCode *//* * t is the choice type pointer */static voidPrintCBerChoiceDecodeCode PARAMS ((src, td, t, elmtLevel, totalLevel, tagLevel, varName),    FILE *src _AND_    TypeDef *td _AND_    Type *t _AND_    int elmtLevel _AND_    int totalLevel _AND_    int tagLevel _AND_    char *varName){    NamedType *e;    CTRI *ctri;    TagList *tags;    Tag *tag;    Tag *lastTag;    enum BasicTypeChoiceId builtinType;    char *classStr;    BER_FORM form;    char *formStr;    char *codeStr;    int   mandatoryCount = 0;    int   i;    char  tmpVarName[MAX_VAR_REF];    char  choiceIdVarName[MAX_VAR_REF];    CTRI *parentCtri;    int   stoleChoiceTags;    void *tmp;    int initialTagLevel;    int initialElmtLevel;    initialTagLevel = tagLevel;    initialElmtLevel = elmtLevel;    parentCtri = t->cTypeRefInfo;    fprintf (src, "    switch (tagId%d)\n", tagLevel);    fprintf (src, "    {\n");    FOR_EACH_LIST_ELMT (e,  t->basicType->a.choice)    {        /* hack ! remember curr loc cause called routine hacks it */        tmp = (void*)CURR_LIST_NODE (t->basicType->a.choice);        tagLevel = initialTagLevel;        elmtLevel = initialElmtLevel;        if ((e->type == NULL) || (e->type->cTypeRefInfo == NULL))        {            fprintf (src, "< ERROR - no c type information - prob unsuported type>\n");            continue;        }        ctri =  e->type->cTypeRefInfo;        tags  = GetTags (e->type, &stoleChoiceTags);        builtinType = GetBuiltinType (e->type);        if ((tags == NULL) || LIST_EMPTY (tags))        {            if ((builtinType != BASICTYPE_ANY) &&                (builtinType != BASICTYPE_ANYDEFINEDBY))                fprintf (src, "<What? no tag on a CHOICE elmt?>\n");            else            {                fprintf (src, "    /* You must hand code ANY type refs */\n");                fprintf (src,"       case MAKE_TAG_ID (?, ?, ?):\n");            }        }        else        {            tag = (Tag*)FIRST_LIST_ELMT (tags);            classStr = Class2ClassStr (tag->tclass);            codeStr = Code2UnivCodeStr (tag->code);            formStr = Form2FormStr (tag->form);            if (tag->tclass == UNIV)            {                if (tag->form == ANY_FORM)                {                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);                }                else                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr);            }            else            {                if (tag->form == ANY_FORM)                {                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code);                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code);                }                else                    fprintf (src,"       case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code);            }	    AsnListFirst (tags);	    AsnListNext (tags); /* set curr ptr to 2nd elmt */            FOR_REST_LIST_ELMT (tag, tags)            {                classStr = Class2ClassStr (tag->tclass);                codeStr = Code2UnivCodeStr (tag->code);                formStr = Form2FormStr (tag->form);                if (stoleChoiceTags)                {                    if (tag->tclass == UNIV)                    {                        if (tag->form == ANY_FORM)                        {                            fprintf (src,"       case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);                            fprintf (src,"       case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);                        }                        else                            fprintf (src,"       case M

⌨️ 快捷键说明

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