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

📄 smseq.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 C
📖 第 1 页 / 共 2 页
字号:

    /* return error */
    if ((pI->syn.usSizeRange == MIBSRfs) ||
            (pI->syn.usSizeRange == MIBSRvs)) {
        /* error - incompatible size */
        return(MIBSCKis);
    } else {
        /* error - incompatible range */
        return(MIBSCKir);
    }

} /* checkCompatibility */


/** checkSEQs - that that all SEQs for a module are defined
*               and that they have been referenced
*               Also check items in sequence to make sure
*               that they are defined and syntax matches.
*               And if they are not childern of the row
*               that is associated with the sequence, then that
*               the row that they are associated with has
*               the same indexs.
*
* call with:
*   pMod - module to check
*/
    VOID
#ifdef __STDC__
checkSEQs(MIBSYM *pMod)
#else
checkSEQs(pMod)
    MIBSYM *pMod;
#endif /* __STDC__ */
{
    MIBSYM *pT;
    MIBSEQI *pI;
    MIBSYM *pOid;
    MIBSYM *pRow;
    MIBSYM *pPar;
    MIBINDX *pX1;
    MIBINDX *pX2;


    for (pT = pSeqGHL; pT != NULL; pT = pT->pNext) {
        if (pT->pMod != pMod)
            continue;

        if (!isupper(*(pT->pszName))) {
            yyerror("Name of sequence \"%s\" must start with uppercase letter",
                    pT->pszName);
        }

        if (pT->usType & MIBSYMFR) {
            yyerror("Sequence \"%s\" referenced but not defined",
                    pT->pszName);
        } else if (pT->ut.seq.cUse == 0) {
            yyerror("Sequence \"%s\" defined but not referenced",
                    pT->pszName);
        } else if (pT->ut.seq.pRow == NULL) {
            yyerror("Sequence \"%s\" not used to define a row",
                    pT->pszName);
        }
        pRow = pT->ut.seq.pRow;

        /* check that all items in sequence are objects and
            have syntax matching the object definitions */
        for (pI = pT->ut.seq.pSeqIL; pI != NULL; pI = pI->pNext) {
            pOid = pI->pOid;
            if (pOid->usType & MIBSYMFR) {
                /* object not defined, skip check */
                continue;
            }
            /* check if item an object */
            /* but first, skip objects with problems */
            if (pOid->ut.oid.usOType == MIBOTunk) {
                /* unknown or bad type -- so skip */
                continue;
            }

            if (pOid->ut.oid.usOType != MIBOTobj) {
                yyerror("Item \"%s\" in sequence \"%s\" is not an object",
                        pOid->pszName, pT->pszName);
                continue;
            }

            /* check syntax */
            switch(checkCompatibility(pI)) {
            case MIBSCKok:
                /* syntax matches */
                break;

            case MIBSCKcn:
                /* syntax is conflicting */
                yyerror("Item \"%s\" in sequence \"%s\" has conflicting syntax specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKis:
                /* incompatible size */
                yyerror("Item \"%s\" in sequence \"%s\" has incompatible size specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKir:
                /* incompatible range */
                yyerror("Item \"%s\" in sequence \"%s\" has incompatible range specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKgr:
                /* gratuitous range */
                if (fCheckSEQ)
                    yywarning("Item \"%s\" in sequence \"%s\" has gratuitous range specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKgs:
                /* gratuitous size */
                if (fCheckSEQ)
                    yywarning("Item \"%s\" in sequence \"%s\" has gratuitous size specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKec:
                /* TC for enumerated with integer specified */
                if (!fNoSeqTcErr)
                    yyerror("Item \"%s\" in sequence \"%s\" has conflicting syntax specified",
                        pOid->pszName, pT->pszName);
                break;

            case MIBSCKtc:
                /* seq item has base type, but obj has TC */
                if (!fNoSeqTcErr)
                    yyerror("Item \"%s\" in sequence \"%s\" has conflicting syntax specified",
                            pOid->pszName, pT->pszName);
                break;

            default:
                /* an error */
                yyerror("checkSEQs: bad value from checkCompatibility");
            }

            /* check that item is in row */
            if (pRow == NULL)
                continue;
            
            if ((pPar = pOid->ut.oid.pPar) == NULL) {
                /* item has no parent */
                continue;
            } else if (pPar == pRow) {
                /* item in row using the sequence - nothing to do */
                continue;
            } else if (pPar->ut.oid.usOType != MIBOTrow) {
                /* item not in a row of a table */
                yywarning("Item \"%s\" in sequence \"%s\" is not a column for a row of a table",
                        pOid->pszName, pT->pszName);
                if (pOid->ut.oid.pDefSeq == NULL) {
                    /* item not in another sequence */
                    /* link to this sequence */
                    pOid->ut.oid.pDefSeq = pT;
                } else {
                    /* item in another sequence */
                    /* check that indexs in other sequence are
                        the same as this sequence */
                    if ((pOid->ut.oid.pDefSeq)->ut.seq.pRow == NULL)
                        /* sequence not attached to a row */
                        continue;
                    for (pX1 = pRow->ut.oid.pIndxL,
                            pX2 = ((pOid->ut.oid.pDefSeq)->ut.seq.pRow)->
                                    ut.oid.pIndxL;
                            (pX1 != NULL) && (pX2 != NULL);
                            pX1 = pX1->pNext, pX2 = pX2->pNext) {
                        if (pX1->usItype != pX2->usItype)
                            /* index not the same */
                            break;
                        if ((pX1->usItype == MIBITobj) ||
                                (pX1->usItype == MIBITnlobj)) {
                            /* object or no length object */
                            if (pX1->pOid != pX2->pOid)
                                /* index not the same */
                                break;
                        } else if (pX1->usItype == MIBITint) {
                            /* INTEGER */
                            if ((pX1->ulLow != pX2->ulLow) ||
                                    (pX1->ulHigh != pX2->ulHigh))
                                /* index not the same */
                                break;
                        } else if (pX1->usItype == MIBITfloct) {
                            /* fixed length OCTET STRING */
                            /* (size is in ulLow) */
                            if (pX1->ulLow != pX2->ulLow)
                                /* index not the same */
                                break;
                        }

                    }
                    if ((pX1 != NULL) || (pX2 != NULL)) {
                        /* indexes do not match */
                        yyerror("Sequence \"%s\" for row \"%s\" contains item \"%s\" used in sequence \"%s\" where indexes don't match",
                                pT->pszName, pRow->pszName,
                                pOid->pszName,
                                (pOid->ut.oid.pDefSeq)->pszName);
                    }
                }
            } else {
                /* item in row of another table */
                /* check if indexs equal */
                for (pX1 = pRow->ut.oid.pIndxL, pX2 = pPar->ut.oid.pIndxL;
                        (pX1 != NULL) && (pX2 != NULL);
                        pX1 = pX1->pNext, pX2 = pX2->pNext) {
                    if (pX1->usItype != pX2->usItype)
                        /* index not the same */
                        break;
                    if ((pX1->usItype == MIBITobj) ||
                            (pX1->usItype == MIBITnlobj)) {
                        /* object or no length object */
                        if (pX1->pOid != pX2->pOid)
                            /* index not the same */
                            break;
                    } else if (pX1->usItype == MIBITint) {
                        /* INTEGER */
                        if ((pX1->ulLow != pX2->ulLow) ||
                                (pX1->ulHigh != pX2->ulHigh))
                            /* index not the same */
                            break;
                    } else if (pX1->usItype == MIBITfloct) {
                        /* fixed length OCTET STRING */
                        /* (size is in ulLow) */
                        if (pX1->ulLow != pX2->ulLow)
                            /* index not the same */
                            break;
                    }
                }
                if ((pX1 != NULL) || (pX2 != NULL)) {
                    /* indexes do not match */
                    yyerror("Sequence \"%s\" for row \"%s\" contains item \"%s\" defined in row \"%s\" where indexes don't match",
                            pT->pszName, pRow->pszName,
                            pOid->pszName, pPar->pszName);
                }
            }
        }
    }

} /* checkSEQs */


/* end of file: SMSEQ.C */

⌨️ 快捷键说明

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