From 419abb0e376f046624827f9730713096ab6f2b38 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 20:25:56 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/lib/data.c b/lib/data.c index 23e9c55..b3868cc 100644 --- a/lib/data.c +++ b/lib/data.c @@ -79,7 +79,6 @@ static Handle *lastHandlePtr = NULL; *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Handle *addHandle(const char *name) { Handle *handlePtr; @@ -114,7 +113,7 @@ Handle *addHandle(const char *name) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) + void removeHandle(Handle *handlePtr) { if (handlePtr->prevPtr) { @@ -151,7 +150,6 @@ void removeHandle(Handle *handlePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Handle *findHandleByName(const char *name) { Handle *handlePtr; @@ -188,7 +186,7 @@ Handle *findHandleByName(const char *name) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) + View *addView(const char *modulename) { View *viewPtr; @@ -223,7 +221,6 @@ View *addView(const char *modulename) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) int isInView(const char *modulename) { View *viewPtr; @@ -260,7 +257,6 @@ int isInView(const char *modulename) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Module *addModule(char *modulename, char *path, ModuleFlags flags, Parser *parserPtr) { @@ -324,7 +320,6 @@ Module *addModule(char *modulename, char *path, ModuleFlags flags, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleIdentityObject(Module *modulePtr, Object *objectPtr) { modulePtr->objectPtr = objectPtr; @@ -348,7 +343,6 @@ void setModuleIdentityObject(Module *modulePtr, Object *objectPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleLastUpdated(Module *modulePtr, time_t lastUpdated) { modulePtr->lastUpdated = lastUpdated; @@ -372,7 +366,6 @@ void setModuleLastUpdated(Module *modulePtr, time_t lastUpdated) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleOrganization(Module *modulePtr, char *organization) { modulePtr->export.organization = organization; @@ -399,7 +392,6 @@ void setModuleOrganization(Module *modulePtr, char *organization) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleContactInfo(Module *modulePtr, char *contactinfo) { modulePtr->export.contactinfo = contactinfo; @@ -423,7 +415,6 @@ void setModuleContactInfo(Module *modulePtr, char *contactinfo) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleDescription(Module *modulePtr, char *description, Parser *parserPtr) { @@ -455,7 +446,6 @@ void setModuleDescription(Module *modulePtr, char *description, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setModuleReference(Module *modulePtr, char *reference, Parser *parserPtr) { if (modulePtr->export.reference) @@ -487,7 +477,6 @@ void setModuleReference(Module *modulePtr, char *reference, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Module *findModuleByName(const char *modulename) { Module *modulePtr; @@ -521,7 +510,6 @@ Module *findModuleByName(const char *modulename) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Revision *addRevision(time_t date, char *description, Parser *parserPtr) { Revision *revisionPtr, *r; @@ -586,7 +574,6 @@ Revision *addRevision(time_t date, char *description, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setRevisionLine(Revision *revisionPtr, int line, Parser *parserPtr) { if (line) { @@ -616,7 +603,6 @@ void setRevisionLine(Revision *revisionPtr, int line, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Import *addImport(char *name, Parser *parserPtr) { Import *importPtr; @@ -663,7 +649,6 @@ Import *addImport(char *name, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void addImportFlags(Import *importPtr, ImportFlags flags) { importPtr->flags |= flags; @@ -687,7 +672,6 @@ void addImportFlags(Import *importPtr, ImportFlags flags) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setImportModulename(Import *importPtr, char *modulename) { if (importPtr->export.module) { @@ -716,7 +700,6 @@ void setImportModulename(Import *importPtr, char *modulename) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) int checkImports(Module *modulePtr, Parser *parserPtr) { int n = 0; @@ -784,7 +767,6 @@ int checkImports(Module *modulePtr, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Import *findImportByName(const char *name, Module *modulePtr) { Import *importPtr; @@ -824,7 +806,6 @@ Import *findImportByName(const char *name, Module *modulePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Import *findImportByModulenameAndName(const char *modulename, const char *name, Module *modulePtr) { @@ -862,7 +843,6 @@ Import *findImportByModulenameAndName(const char *modulename, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *addObject(char *objectname, Node *parentNodePtr, SmiSubid subid, ObjectFlags flags, Parser *parserPtr) { @@ -960,7 +940,6 @@ Object *addObject(char *objectname, Node *parentNodePtr, SmiSubid subid, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *duplicateObject(Object *templatePtr, ObjectFlags flags, Parser *parserPtr) { @@ -1041,7 +1020,6 @@ Object *duplicateObject(Object *templatePtr, ObjectFlags flags, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *addNode (Node *parentNodePtr, SmiSubid subid, NodeFlags flags, Parser *parserPtr) { @@ -1119,7 +1097,6 @@ Node *addNode (Node *parentNodePtr, SmiSubid subid, NodeFlags flags, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *createNodes(unsigned int oidlen, SmiSubid *oid) { Node *parentNodePtr, *nodePtr; @@ -1157,7 +1134,6 @@ Node *createNodes(unsigned int oidlen, SmiSubid *oid) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *createNodesByOidString(const char *oid) { char *p, *elements; @@ -1200,7 +1176,6 @@ Node *createNodesByOidString(const char *oid) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *getParentNode(Node *nodePtr) { return nodePtr->parentPtr; @@ -1225,7 +1200,6 @@ Node *getParentNode(Node *nodePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) static void mergeNodeTrees(Node *toNodePtr, Node *fromNodePtr, Parser *parserPtr) { @@ -1326,7 +1300,6 @@ static void mergeNodeTrees(Node *toNodePtr, Node *fromNodePtr, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *setObjectName(Object *objectPtr, char *name, Parser *parserPtr) { Node *nodePtr, *nextPtr; @@ -1427,7 +1400,6 @@ Object *setObjectName(Object *objectPtr, char *name, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectType(Object *objectPtr, Type *typePtr) { objectPtr->typePtr = typePtr; @@ -1451,7 +1423,6 @@ void setObjectType(Object *objectPtr, Type *typePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectAccess(Object *objectPtr, SmiAccess access) { objectPtr->export.access = access; @@ -1475,7 +1446,6 @@ void setObjectAccess(Object *objectPtr, SmiAccess access) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectStatus(Object *objectPtr, SmiStatus status) { objectPtr->export.status = status; @@ -1499,7 +1469,6 @@ void setObjectStatus(Object *objectPtr, SmiStatus status) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectDescription(Object *objectPtr, char *description, Parser *parserPtr) { @@ -1531,7 +1500,6 @@ void setObjectDescription(Object *objectPtr, char *description, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectReference(Object *objectPtr, char *reference, Parser *parserPtr) { if (objectPtr->export.reference) @@ -1561,7 +1529,6 @@ void setObjectReference(Object *objectPtr, char *reference, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectFormat(Object *objectPtr, char *format) { if (objectPtr->export.format) smiFree(objectPtr->export.format); @@ -1586,7 +1553,6 @@ void setObjectFormat(Object *objectPtr, char *format) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectUnits(Object *objectPtr, char *units) { if (objectPtr->export.units) smiFree(objectPtr->export.units); @@ -1611,7 +1577,6 @@ void setObjectUnits(Object *objectPtr, char *units) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectDecl(Object *objectPtr, SmiDecl decl) { objectPtr->export.decl = decl; @@ -1635,7 +1600,6 @@ void setObjectDecl(Object *objectPtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectLine(Object *objectPtr, int line, Parser *parserPtr) { if (line) { @@ -1663,7 +1627,6 @@ void setObjectLine(Object *objectPtr, int line, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectNodekind(Object *objectPtr, SmiNodekind nodekind) { objectPtr->export.nodekind = nodekind; @@ -1687,7 +1650,6 @@ void setObjectNodekind(Object *objectPtr, SmiNodekind nodekind) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void addObjectFlags(Object *objectPtr, ObjectFlags flags) { objectPtr->flags |= flags; @@ -1711,7 +1673,6 @@ void addObjectFlags(Object *objectPtr, ObjectFlags flags) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void deleteObjectFlags(Object *objectPtr, ObjectFlags flags) { objectPtr->flags &= ~flags; @@ -1735,7 +1696,6 @@ void deleteObjectFlags(Object *objectPtr, ObjectFlags flags) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) int checkObjectFlags(Object *objectPtr, ObjectFlags flags) { return ((objectPtr->flags & flags) == flags); @@ -1786,7 +1746,6 @@ void setObjectIndex(Object *objectPtr, Index *indexPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectList(Object *objectPtr, List *listPtr) { objectPtr->listPtr = listPtr; @@ -1810,7 +1769,6 @@ void setObjectList(Object *objectPtr, List *listPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectRelated(Object *objectPtr, Object *relatedPtr) { objectPtr->relatedPtr = relatedPtr; @@ -1834,7 +1792,6 @@ void setObjectRelated(Object *objectPtr, Object *relatedPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectImplied(Object *objectPtr, int implied) { objectPtr->export.implied = implied; @@ -1858,7 +1815,6 @@ void setObjectImplied(Object *objectPtr, int implied) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectCreate(Object *objectPtr, int create) { objectPtr->export.create = create; @@ -1882,7 +1838,6 @@ void setObjectCreate(Object *objectPtr, int create) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectIndexkind(Object *objectPtr, SmiIndexkind indexkind) { objectPtr->export.indexkind = indexkind; @@ -1906,7 +1861,6 @@ void setObjectIndexkind(Object *objectPtr, SmiIndexkind indexkind) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectValue(Object *objectPtr, SmiValue *valuePtr) { objectPtr->export.value = *valuePtr; @@ -1931,7 +1885,6 @@ void setObjectValue(Object *objectPtr, SmiValue *valuePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setObjectUniqueness(Object *objectPtr, List *listPtr) { objectPtr->uniquenessPtr = listPtr; @@ -1979,7 +1932,6 @@ void setObjectUniqueness(Object *objectPtr, List *listPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *findNodeByParentAndSubid(Node *parentNodePtr, SmiSubid subid) { Node *nodePtr; @@ -2016,7 +1968,6 @@ Node *findNodeByParentAndSubid(Node *parentNodePtr, SmiSubid subid) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *findNodeByOid(unsigned int oidlen, SmiSubid *oid) { Node *nodePtr; @@ -2049,7 +2000,6 @@ Node *findNodeByOid(unsigned int oidlen, SmiSubid *oid) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Node *findNodeByOidString(char *oid) { Node *nodePtr; @@ -2087,7 +2037,6 @@ Node *findNodeByOidString(char *oid) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByNode(Node *nodePtr) { Object *objectPtr; @@ -2130,7 +2079,6 @@ Object *findObjectByNode(Node *nodePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByModuleAndNode(Module *modulePtr, Node *nodePtr) { Object *objectPtr; @@ -2166,7 +2114,6 @@ Object *findObjectByModuleAndNode(Module *modulePtr, Node *nodePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByModulenameAndNode(const char *modulename, Node *nodePtr) { Object *objectPtr; @@ -2202,7 +2149,6 @@ Object *findObjectByModulenameAndNode(const char *modulename, Node *nodePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByName(const char *objectname) { Module *modulePtr; @@ -2247,7 +2193,6 @@ Object *findObjectByName(const char *objectname) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findNextObjectByName(const char *objectname, Object *prevObjectPtr) { Module *modulePtr; @@ -2291,7 +2236,6 @@ Object *findNextObjectByName(const char *objectname, Object *prevObjectPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByModulenameAndName(const char *modulename, const char *objectname) { @@ -2341,7 +2285,6 @@ Object *findObjectByModulenameAndName(const char *modulename, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Object *findObjectByModuleAndName(Module *modulePtr, const char *objectname) { Object *objectPtr; @@ -2391,7 +2334,6 @@ Object *findObjectByModuleAndName(Module *modulePtr, const char *objectname) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *addType(char *type_name, SmiBasetype basetype, TypeFlags flags, Parser *parserPtr) { @@ -2453,7 +2395,6 @@ Type *addType(char *type_name, SmiBasetype basetype, TypeFlags flags, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *duplicateType(Type *templatePtr, TypeFlags flags, Parser *parserPtr) { Type *typePtr; @@ -2510,7 +2451,6 @@ Type *duplicateType(Type *templatePtr, TypeFlags flags, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *setTypeName(Type *typePtr, char *name) { Type *type2Ptr; @@ -2603,7 +2543,6 @@ Type *setTypeName(Type *typePtr, char *name) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeParent(Type *typePtr, Type *parentPtr) { typePtr->parentPtr = parentPtr; @@ -2627,7 +2566,6 @@ void setTypeParent(Type *typePtr, Type *parentPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeStatus(Type *typePtr, SmiStatus status) { typePtr->export.status = status; @@ -2651,7 +2589,6 @@ void setTypeStatus(Type *typePtr, SmiStatus status) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeBasetype(Type *typePtr, SmiBasetype basetype) { typePtr->export.basetype = basetype; @@ -2675,7 +2612,6 @@ void setTypeBasetype(Type *typePtr, SmiBasetype basetype) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeDescription(Type *typePtr, char *description, Parser *parserPtr) { if (typePtr->export.description) @@ -2706,7 +2642,6 @@ void setTypeDescription(Type *typePtr, char *description, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeReference(Type *typePtr, char *reference, Parser *parserPtr) { if (typePtr->export.reference) @@ -2741,7 +2676,6 @@ void setTypeReference(Type *typePtr, char *reference, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeList(Type *typePtr, List *listPtr) { if (!typePtr->listPtr) { @@ -2767,7 +2701,6 @@ void setTypeList(Type *typePtr, List *listPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeFormat(Type *typePtr, char *format) { if (typePtr->export.format) smiFree(typePtr->export.format); @@ -2793,7 +2726,6 @@ void setTypeFormat(Type *typePtr, char *format) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeUnits(Type *typePtr, char *units) { if (typePtr->export.units) smiFree(typePtr->export.units); @@ -2818,7 +2750,6 @@ void setTypeUnits(Type *typePtr, char *units) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeDecl(Type *typePtr, SmiDecl decl) { typePtr->export.decl = decl; @@ -2842,7 +2773,6 @@ void setTypeDecl(Type *typePtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeLine(Type *typePtr, int line, Parser *parserPtr) { if (line) { @@ -2870,7 +2800,6 @@ void setTypeLine(Type *typePtr, int line, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setTypeValue(Type *typePtr, SmiValue *valuePtr) { typePtr->export.value = *valuePtr; @@ -2894,7 +2823,6 @@ void setTypeValue(Type *typePtr, SmiValue *valuePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void addTypeFlags(Type *typePtr, TypeFlags flags) { typePtr->flags |= flags; @@ -2918,7 +2846,6 @@ void addTypeFlags(Type *typePtr, TypeFlags flags) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void deleteTypeFlags(Type *typePtr, TypeFlags flags) { typePtr->flags &= ~flags; @@ -2943,7 +2870,6 @@ void deleteTypeFlags(Type *typePtr, TypeFlags flags) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type * findTypeByName(const char *type_name) { Module *modulePtr; @@ -2982,7 +2908,6 @@ Type * findTypeByName(const char *type_name) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *findNextTypeByName(const char *type_name, Type *prevTypePtr) { Module *modulePtr; @@ -3021,7 +2946,6 @@ Type *findNextTypeByName(const char *type_name, Type *prevTypePtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *findTypeByModulenameAndName(const char *modulename, const char *type_name) { @@ -3061,7 +2985,6 @@ Type *findTypeByModulenameAndName(const char *modulename, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Type *findTypeByModuleAndName(Module *modulePtr, const char *type_name) { Type *typePtr; @@ -3094,7 +3017,6 @@ Type *findTypeByModuleAndName(Module *modulePtr, const char *type_name) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) NamedNumber *findTypeNamedNumber(Type *typePtr, SmiInteger32 number) { @@ -3128,7 +3050,6 @@ NamedNumber *findTypeNamedNumber(Type *typePtr, * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Identity *addIdentity(char *identityname, Parser *parserPtr) { Identity *identityPtr; @@ -3175,7 +3096,6 @@ Identity *addIdentity(char *identityname, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setIdentityDecl(Identity *identityPtr, SmiDecl decl) { identityPtr->export.decl = decl; @@ -3197,7 +3117,6 @@ void setIdentityDecl(Identity *identityPtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setIdentityStatus(Identity *identityPtr, SmiStatus status) { identityPtr->export.status = status; @@ -3221,7 +3140,6 @@ void setIdentityStatus(Identity *identityPtr, SmiStatus status) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setIdentityDescription(Identity *identityPtr, char *description, Parser *parserPtr) { if (identityPtr->export.description) smiFree(identityPtr->export.description); @@ -3251,7 +3169,6 @@ void setIdentityDescription(Identity *identityPtr, char *description, Parser *pa *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setIdentityReference(Identity *identityPtr, char *reference, Parser *parserPtr) { if (identityPtr->export.reference) @@ -3280,7 +3197,6 @@ void setIdentityReference(Identity *identityPtr, char *reference, Parser *parser *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setIdentityParent(Identity *identityPtr, Identity *parentPtr) { if(identityPtr) identityPtr->parentPtr = parentPtr; @@ -3304,7 +3220,6 @@ void setIdentityParent(Identity *identityPtr, Identity *parentPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Identity *findIdentityByName(const char *identityname) { Module *modulePtr; @@ -3341,7 +3256,6 @@ Identity *findIdentityByName(const char *identityname) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Identity *findIdentityByModuleAndName(Module *modulePtr, const char *identityname) { @@ -3377,7 +3291,6 @@ Identity *findIdentityByModuleAndName(Module *modulePtr, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Identity *findIdentityByModulenameAndName(const char *modulename, const char *identity_name) { @@ -3416,7 +3329,6 @@ Identity *findIdentityByModulenameAndName(const char *modulename, * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Class *addClass(char *classname, Parser *parserPtr) { Class *classPtr; @@ -3468,7 +3380,6 @@ Class *addClass(char *classname, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setClassDecl(Class *classPtr, SmiDecl decl) { classPtr->export.decl = decl; @@ -3490,7 +3401,6 @@ void setClassDecl(Class *classPtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setClassStatus(Class *classPtr, SmiStatus status) { classPtr->export.status = status; @@ -3514,7 +3424,6 @@ void setClassStatus(Class *classPtr, SmiStatus status) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setClassDescription(Class *classPtr, char *description, Parser *parserPtr) { if (classPtr->export.description) smiFree(classPtr->export.description); @@ -3544,7 +3453,6 @@ void setClassDescription(Class *classPtr, char *description, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setClassReference(Class *classPtr, char *reference, Parser *parserPtr) { if (classPtr->export.reference) @@ -3573,7 +3481,6 @@ void setClassReference(Class *classPtr, char *reference, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setClassParent(Class *classPtr, Class *parentPtr) { if(classPtr) classPtr->parentPtr = parentPtr; @@ -3595,7 +3502,6 @@ void setClassParent(Class *classPtr, Class *parentPtr) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Class *findClassByModuleAndName(Module *modulePtr,char *name) { Class *classPtr; @@ -3628,7 +3534,6 @@ Class *findClassByModuleAndName(Module *modulePtr,char *name) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Class *findClassByModulenameAndName(const char *modulename, const char *class_name) { @@ -3667,7 +3572,6 @@ Class *findClassByModulenameAndName(const char *modulename, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Attribute *duplicateTypeToAttribute(Type *templatePtr, Class *classPtr, Parser *parserPtr) { Attribute *attributePtr; @@ -3722,7 +3626,6 @@ Attribute *duplicateTypeToAttribute(Type *templatePtr, Class *classPtr, Parser * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Attribute *addAttribute(char *attribute_name, Class *classPtr, Parser *parserPtr) { @@ -3777,7 +3680,6 @@ Attribute *addAttribute(char *attribute_name, *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeDecl(Attribute *attributePtr, SmiDecl decl) { attributePtr->export.decl = decl; @@ -3799,7 +3701,6 @@ void setAttributeDecl(Attribute *attributePtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeParentType(Attribute *attributePtr, Type *parentPtr) { attributePtr->parentTypePtr = parentPtr; @@ -3821,7 +3722,6 @@ void setAttributeParentType(Attribute *attributePtr, Type *parentPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeParentClass(Attribute *attributePtr, Class *parentPtr) { attributePtr->parentClassPtr = parentPtr; @@ -3846,7 +3746,6 @@ void setAttributeParentClass(Attribute *attributePtr, Class *parentPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeList(Attribute *attributePtr, List *listPtr) { if (!attributePtr->listPtr) { @@ -3870,7 +3769,6 @@ void setAttributeList(Attribute *attributePtr, List *listPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeName(Attribute *attributePtr, char *name) { @@ -3892,7 +3790,6 @@ void setAttributeName(Attribute *attributePtr, char *name) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setAttributeAccess(Attribute *attributePtr,SmiAccess access) { attributePtr->export.access = access; @@ -3915,7 +3812,6 @@ void setAttributeAccess(Attribute *attributePtr,SmiAccess access) * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Event *addEvent(char *eventname, Class *classPtr, Parser *parserPtr) { @@ -3965,7 +3861,6 @@ Event *addEvent(char *eventname, Class *classPtr, * *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Macro *addMacro(char *macroname, MacroFlags flags, Parser *parserPtr) { Macro *macroPtr; @@ -4015,7 +3910,6 @@ Macro *addMacro(char *macroname, MacroFlags flags, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroStatus(Macro *macroPtr, SmiStatus status) { macroPtr->export.status = status; @@ -4039,7 +3933,6 @@ void setMacroStatus(Macro *macroPtr, SmiStatus status) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroDescription(Macro *macroPtr, char *description, Parser *parserPtr) { if (macroPtr->export.description) smiFree(macroPtr->export.description); @@ -4069,7 +3962,6 @@ void setMacroDescription(Macro *macroPtr, char *description, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroReference(Macro *macroPtr, char *reference, Parser *parserPtr) { if (macroPtr->export.reference) @@ -4098,7 +3990,6 @@ void setMacroReference(Macro *macroPtr, char *reference, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroAbnf(Macro *macroPtr, char *abnf, Parser *parserPtr) { if (macroPtr->export.abnf) @@ -4129,7 +4020,6 @@ void setMacroAbnf(Macro *macroPtr, char *abnf, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroDecl(Macro *macroPtr, SmiDecl decl) { macroPtr->export.decl = decl; @@ -4153,7 +4043,6 @@ void setMacroDecl(Macro *macroPtr, SmiDecl decl) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) void setMacroLine(Macro *macroPtr, int line, Parser *parserPtr) { if (line) { @@ -4182,7 +4071,6 @@ void setMacroLine(Macro *macroPtr, int line, Parser *parserPtr) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Macro *findMacroByName(const char *macroname) { Module *modulePtr; @@ -4221,7 +4109,6 @@ Macro *findMacroByName(const char *macroname) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Macro *findMacroByModuleAndName(Module *modulePtr, const char *macroname) { Macro *macroPtr; @@ -4257,7 +4144,6 @@ Macro *findMacroByModuleAndName(Module *modulePtr, const char *macroname) *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) NamedNumber *findNamedNumberByName(Type *typePtr,const char *name) { List *listPtr; @@ -4694,7 +4580,6 @@ void smiFreeData() *---------------------------------------------------------------------- */ -__attribute__ ((visibility ("internal"))) Module *loadModule(const char *modulename, Parser *parserPtr) { Parser parser; diff --git a/lib/data.c.clash b/lib/data.c.clash deleted file mode 100644 index b3868cc..0000000 --- a/lib/data.c.clash +++ /dev/null @@ -1,4802 +0,0 @@ -/* - * data.c -- - * - * Operations on the main data structures. - * - * Copyright (c) 1999-2002 Frank Strauss, Technical University of Braunschweig. - * - * See the file "COPYING" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * @(#) $Id: data.c 7822 2008-03-01 13:22:42Z schoenw $ - */ - -#include - -#include -#include -#include -#include -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_WIN_H -#include "win.h" -#endif - -#include "error.h" -#include "util.h" -#include "data.h" -#include "smi.h" - -#ifdef HAVE_DMALLOC_H -#include -#endif - - - -#ifdef BACKEND_SMI -#include "scanner-smi.h" -extern int smiparse(); -#endif - -#ifdef BACKEND_SMING -#include "scanner-sming.h" -extern int smingparse(); -#endif - -#define stringKind(kind) ( \ - (kind == KIND_ANY) ? "ANY" : \ - (kind == KIND_MODULE) ? "MODULE" : \ - (kind == KIND_MACRO) ? "MACRO" : \ - (kind == KIND_TYPE) ? "TYPE" : \ - (kind == KIND_OBJECT) ? "OBJECT" : \ - (kind == KIND_IMPORT) ? "IMPORT" : \ - "unknown" ) - - -int smiDepth = 0; -static Handle *firstHandlePtr = NULL; -static Handle *lastHandlePtr = NULL; - - -/* - *---------------------------------------------------------------------- - * - * addHandle -- - * - * Adds a libsmi handle with a given name. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Handle *addHandle(const char *name) -{ - Handle *handlePtr; - - handlePtr = (Handle *) smiMalloc(sizeof(Handle)); - - handlePtr->name = smiStrdup(name); - - handlePtr->nextPtr = NULL; - handlePtr->prevPtr = lastHandlePtr; - if (!firstHandlePtr) firstHandlePtr = handlePtr; - if (lastHandlePtr) lastHandlePtr->nextPtr = handlePtr; - lastHandlePtr = handlePtr; - - return (handlePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * removeHandle -- - * - * Removes a given libsmi handle. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void removeHandle(Handle *handlePtr) -{ - if (handlePtr->prevPtr) { - handlePtr->prevPtr->nextPtr = handlePtr->nextPtr; - } else { - firstHandlePtr = handlePtr->nextPtr; - } - if (handlePtr->nextPtr) { - handlePtr->nextPtr->prevPtr = handlePtr->prevPtr; - } else { - lastHandlePtr = handlePtr->prevPtr; - } - - smiFree(handlePtr->name); - smiFree(handlePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * findHandleByName -- - * - * Lookup an libsmi handle by its name. - * - * Results: - * A pointer to the Handle structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Handle *findHandleByName(const char *name) -{ - Handle *handlePtr; - - if (!name) - return NULL; - - for (handlePtr = firstHandlePtr; handlePtr; - handlePtr = handlePtr->nextPtr) { - if (!strcmp(handlePtr->name, name)) { - return (handlePtr); - } - } - - return NULL; - -} - - - -/* - *---------------------------------------------------------------------- - * - * addView -- - * - * Add a module to the `view' (the list of modules, seen by the user). - * - * Results: - * A pointer to the new View structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -View *addView(const char *modulename) -{ - View *viewPtr; - - viewPtr = (View *) smiMalloc(sizeof(View)); - - viewPtr->name = smiStrdup(modulename); - viewPtr->nextPtr = NULL; - viewPtr->prevPtr = smiHandle->lastViewPtr; - if (!smiHandle->firstViewPtr) smiHandle->firstViewPtr = viewPtr; - if (smiHandle->lastViewPtr) smiHandle->lastViewPtr->nextPtr = viewPtr; - smiHandle->lastViewPtr = viewPtr; - - return (viewPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * isInView -- - * - * Check, whether a given module is in the current view. - * - * Results: - * != 0 if in view, 0 otherwise. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -int isInView(const char *modulename) -{ - View *viewPtr; - -#if 0 - if (smiHandle->flags & SMI_FLAG_VIEWALL) { - return 1; - } -#endif - - for (viewPtr = smiHandle->firstViewPtr; viewPtr; viewPtr = viewPtr->nextPtr) { - if (!strcmp(modulename, viewPtr->name)) { - return 1; - } - } - return 0; -} - - -/* - *---------------------------------------------------------------------- - * - * addModule -- - * - * Create a new MIB module. - * - * Results: - * A pointer to the new Module structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Module *addModule(char *modulename, char *path, ModuleFlags flags, - Parser *parserPtr) -{ - Module *modulePtr; - - modulePtr = (Module *) smiMalloc(sizeof(Module)); - - modulePtr->export.name = modulename; - modulePtr->export.path = path; - modulePtr->export.language = SMI_LANGUAGE_UNKNOWN; - modulePtr->export.organization = NULL; - modulePtr->export.contactinfo = NULL; - modulePtr->export.description = NULL; - modulePtr->export.reference = NULL; - modulePtr->export.conformance = 0; - - modulePtr->lastUpdated = 0; - modulePtr->flags = flags; - modulePtr->objectPtr = NULL; - - modulePtr->prefixNodePtr = NULL; - modulePtr->firstObjectPtr = NULL; - modulePtr->lastObjectPtr = NULL; - modulePtr->firstTypePtr = NULL; - modulePtr->lastTypePtr = NULL; - modulePtr->firstMacroPtr = NULL; - modulePtr->lastMacroPtr = NULL; - modulePtr->firstImportPtr = NULL; - modulePtr->lastImportPtr = NULL; - modulePtr->firstRevisionPtr = NULL; - modulePtr->lastRevisionPtr = NULL; - - modulePtr->numImportedIdentifiers = 0; - modulePtr->numStatements = 0; - modulePtr->numModuleIdentities = 0; - - modulePtr->nextPtr = NULL; - modulePtr->prevPtr = smiHandle->lastModulePtr; - if (!smiHandle->firstModulePtr) smiHandle->firstModulePtr = modulePtr; - if (smiHandle->lastModulePtr) smiHandle->lastModulePtr->nextPtr = modulePtr; - smiHandle->lastModulePtr = modulePtr; - - return (modulePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleIdentityObject -- - * - * Set the objectPtr of a given Module to the OBJECT-IDENTITY object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleIdentityObject(Module *modulePtr, Object *objectPtr) -{ - modulePtr->objectPtr = objectPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleLastUpdated -- - * - * Set the lastUpdated time_t value of a given Module. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleLastUpdated(Module *modulePtr, time_t lastUpdated) -{ - modulePtr->lastUpdated = lastUpdated; -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleOrganization -- - * - * Set the organization string of a given Module. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleOrganization(Module *modulePtr, char *organization) -{ - modulePtr->export.organization = organization; - while (strlen(organization) && organization[strlen(organization)-1] == '\n') { - organization[strlen(organization) - 1] = 0; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleContactInfo -- - * - * Set the contactInfo string of a given Module. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleContactInfo(Module *modulePtr, char *contactinfo) -{ - modulePtr->export.contactinfo = contactinfo; -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleDescription -- - * - * Set the description string of a given Module. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleDescription(Module *modulePtr, char *description, - Parser *parserPtr) -{ - if (modulePtr->export.description) - smiFree(modulePtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - modulePtr->export.description = NULL; - } else { - modulePtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setModuleReference -- - * - * Set the reference string of a given Module. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setModuleReference(Module *modulePtr, char *reference, Parser *parserPtr) -{ - if (modulePtr->export.reference) - smiFree(modulePtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - modulePtr->export.reference = NULL; - } else { - modulePtr->export.reference = reference; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * findModuleByName -- - * - * Lookup a Module by a given name. - * - * Results: - * A pointer to the Module structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Module *findModuleByName(const char *modulename) -{ - Module *modulePtr; - - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - if ((modulePtr->export.name) && - !strcmp(modulePtr->export.name, modulename)) { - return (modulePtr); - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * addRevision -- - * - * Adds a revision entry for the given module. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Revision *addRevision(time_t date, char *description, Parser *parserPtr) -{ - Revision *revisionPtr, *r; - Module *modulePtr; - - revisionPtr = (Revision *) smiMalloc(sizeof(Revision)); - - modulePtr = parserPtr->modulePtr; - - revisionPtr->modulePtr = modulePtr; - revisionPtr->export.date = date; - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - revisionPtr->export.description = NULL; - } else { - revisionPtr->export.description = description; - } - revisionPtr->line = parserPtr ? parserPtr->line : -1; - - for (r = modulePtr->lastRevisionPtr; r; r = r->prevPtr) { - if (r->export.date > date) break; - } - if (r) { - revisionPtr->nextPtr = r->nextPtr; - revisionPtr->prevPtr = r; - if (r->nextPtr) { - r->nextPtr->prevPtr = revisionPtr; - } else { - modulePtr->lastRevisionPtr = revisionPtr; - } - r->nextPtr = revisionPtr; - } else { - revisionPtr->prevPtr = NULL; - if (modulePtr->firstRevisionPtr) { - modulePtr->firstRevisionPtr->prevPtr = revisionPtr; - revisionPtr->nextPtr = modulePtr->firstRevisionPtr; - } else { - modulePtr->lastRevisionPtr = revisionPtr; - revisionPtr->nextPtr = NULL; - } - modulePtr->firstRevisionPtr = revisionPtr; - } - - return (revisionPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setRevisionLine -- - * - * Set the line of definition of a given Revision. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setRevisionLine(Revision *revisionPtr, int line, Parser *parserPtr) -{ - if (line) { - revisionPtr->line = line; - } else { - revisionPtr->line = parserPtr ? parserPtr->line : -1; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * addImport -- - * - * Adds a descriptor to the actual module's list of imported - * descriptors. This list may be checked by checkImports() - * afterwards. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Import *addImport(char *name, Parser *parserPtr) -{ - Import *importPtr; - Module *modulePtr; - - importPtr = (Import *) smiMalloc(sizeof(Import)); - - modulePtr = parserPtr->modulePtr; - - importPtr->modulePtr = modulePtr; - importPtr->export.name = name; - importPtr->export.module = NULL; /* not yet known */ - importPtr->kind = KIND_UNKNOWN; /* not yet known */ - importPtr->use = 0; - importPtr->flags = 0; - importPtr->line = parserPtr ? parserPtr->line : -1; - - importPtr->nextPtr = NULL; - importPtr->prevPtr = modulePtr->lastImportPtr; - if (!modulePtr->firstImportPtr) - modulePtr->firstImportPtr = importPtr; - if (modulePtr->lastImportPtr) - modulePtr->lastImportPtr->nextPtr = importPtr; - modulePtr->lastImportPtr = importPtr; - - return (importPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * addImportFlags -- - * - * Add flags to the flags of a given Import struct. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void addImportFlags(Import *importPtr, ImportFlags flags) -{ - importPtr->flags |= flags; -} - - - -/* - *---------------------------------------------------------------------- - * - * setImportModulename -- - * - * Set the modulename part of a given Import struct. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setImportModulename(Import *importPtr, char *modulename) -{ - if (importPtr->export.module) { - smiFree(importPtr->export.module); - } - importPtr->export.module = modulename; -} - - - -/* - *---------------------------------------------------------------------- - * - * checkImports -- - * - * Check wheather all descriptors in the actual module's list - * are imported by a given Module. Implicitly set all Imports' - * module names. - * - * Results: - * 0 on success or -1 on an error or number of descriptors not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -int checkImports(Module *modulePtr, Parser *parserPtr) -{ - int n = 0; - Import *importPtr; - SmiNode *smiNode; - SmiType *smiType; - SmiMacro *smiMacro; - - for (importPtr = parserPtr->modulePtr->firstImportPtr; - importPtr; importPtr = importPtr->nextPtr) { - - if (importPtr->kind == KIND_UNKNOWN) { - if (modulePtr) { - if ((smiNode = smiGetNode(&modulePtr->export, - importPtr->export.name))) { - importPtr->export.module = - smiStrdup(modulePtr->export.name); - importPtr->kind = KIND_OBJECT; - } else if ((smiType = smiGetType(&modulePtr->export, - importPtr->export.name))) { - importPtr->export.module = - smiStrdup(modulePtr->export.name); - importPtr->kind = KIND_TYPE; - } else if ((smiMacro = smiGetMacro(&modulePtr->export, - importPtr->export.name))) { - importPtr->export.module = - smiStrdup(modulePtr->export.name); - importPtr->kind = KIND_MACRO; - } else { - n++; - importPtr->export.module = - smiStrdup(modulePtr->export.name); - smiPrintError(parserPtr, ERR_IDENTIFIER_NOT_IN_MODULE, - importPtr->export.name, - modulePtr->export.name); - importPtr->kind = KIND_NOTFOUND; - } - } else { - n++; - importPtr->export.module = smiStrdup(""); - importPtr->kind = KIND_NOTFOUND; - } - } - } - - return (n); -} - - - -/* - *---------------------------------------------------------------------- - * - * findImportByName -- - * - * Lookup an import descriptor by its name and the module to look in. - * - * Results: - * A pointer to the Import structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Import *findImportByName(const char *name, Module *modulePtr) -{ - Import *importPtr; - - if (!name) - return NULL; - - for (importPtr = modulePtr->firstImportPtr; importPtr; - importPtr = importPtr->nextPtr) { - if ((!strcmp(importPtr->export.name, name)) && - (!(importPtr->flags & FLAG_INCOMPLIANCE))) { - return (importPtr); - } - } - - return NULL; - -} - - - -/* - *---------------------------------------------------------------------- - * - * findImportByModulenameAndName -- - * - * Lookup an import descriptor by its name and the modulename - * it is imported from and the module to look in. - * - * Results: - * A pointer to the Import structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Import *findImportByModulenameAndName(const char *modulename, - const char *name, Module *modulePtr) -{ - Import *importPtr; - - for (importPtr = modulePtr->firstImportPtr; importPtr; - importPtr = importPtr->nextPtr) { - if ((!strcmp(importPtr->export.name, name)) && - (!strcmp(importPtr->export.module, modulename))) { - return (importPtr); - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * addObject -- - * - * Create a new Object and Node or update an existing one. - * Also updates other Objects and Nodes according - * to the PendingNode information. - * - * Results: - * A pointer to the new Object structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *addObject(char *objectname, Node *parentNodePtr, SmiSubid subid, - ObjectFlags flags, Parser *parserPtr) -{ - Object *objectPtr; - Node *nodePtr; - Module *modulePtr; - - - objectPtr = (Object *) smiMalloc(sizeof(Object)); - - modulePtr = parserPtr ? parserPtr->modulePtr : NULL; - - objectPtr->export.name = objectname; - objectPtr->export.decl = SMI_DECL_UNKNOWN; - objectPtr->export.access = SMI_ACCESS_UNKNOWN; - objectPtr->export.status = SMI_STATUS_UNKNOWN; - objectPtr->export.format = NULL; - objectPtr->export.value.basetype = SMI_BASETYPE_UNKNOWN; - objectPtr->export.units = NULL; - objectPtr->export.description = NULL; - objectPtr->export.reference = NULL; - objectPtr->export.indexkind = SMI_INDEX_UNKNOWN; - objectPtr->export.implied = 0; - objectPtr->export.create = 0; - objectPtr->export.nodekind = SMI_NODEKIND_UNKNOWN; - - objectPtr->modulePtr = modulePtr; - objectPtr->nodePtr = NULL; - objectPtr->prevSameNodePtr = NULL; - objectPtr->nextSameNodePtr = NULL; - objectPtr->typePtr = NULL; - objectPtr->listPtr = NULL; - objectPtr->flags = flags; - objectPtr->line = parserPtr ? parserPtr->line : -1; - - objectPtr->uniquenessPtr = NULL; - - objectPtr->export.oidlen = 0; /* filled in by */ - objectPtr->export.oid = NULL; /* second pass. */ - - objectPtr->nextPtr = NULL; - if (modulePtr) { - objectPtr->prevPtr = modulePtr->lastObjectPtr; - if (!modulePtr->firstObjectPtr) - modulePtr->firstObjectPtr = objectPtr; - if (modulePtr->lastObjectPtr) - modulePtr->lastObjectPtr->nextPtr = objectPtr; - modulePtr->lastObjectPtr = objectPtr; - } else { - objectPtr->prevPtr = NULL; - } - - /* - * Link it into the tree. - */ - nodePtr = findNodeByParentAndSubid(parentNodePtr, subid); - if ((parentNodePtr == parserPtr->pendingNodePtr) || (!nodePtr)) { - - /* a new Node has to be created for this Object */ - nodePtr = addNode(parentNodePtr, subid, flags, parserPtr); - nodePtr->firstObjectPtr = objectPtr; - nodePtr->lastObjectPtr = objectPtr; - } else { - - objectPtr->prevSameNodePtr = nodePtr->lastObjectPtr; - if (!nodePtr->firstObjectPtr) - nodePtr->firstObjectPtr = objectPtr; - if (nodePtr->lastObjectPtr) - nodePtr->lastObjectPtr->nextSameNodePtr = objectPtr; - nodePtr->lastObjectPtr = objectPtr; - } - objectPtr->nodePtr = nodePtr; - - return (objectPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * duplicateObject -- - * - * Create a new Object as a duplicate of a given one but with - * an affiliation to another module with new flags and with - * uninitialzied values. - * - * Results: - * A pointer to the new Object structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *duplicateObject(Object *templatePtr, ObjectFlags flags, - Parser *parserPtr) -{ - Object *objectPtr; - Node *nodePtr; - Module *modulePtr; - - objectPtr = (Object *) smiMalloc(sizeof(Object)); - - modulePtr = parserPtr->modulePtr; - nodePtr = templatePtr->nodePtr; - - objectPtr->export.name = NULL; - objectPtr->export.decl = SMI_DECL_UNKNOWN; - objectPtr->export.access = SMI_ACCESS_UNKNOWN; - objectPtr->export.status = SMI_STATUS_UNKNOWN; - objectPtr->export.format = NULL; - objectPtr->export.value.basetype = SMI_BASETYPE_UNKNOWN; - objectPtr->export.units = NULL; - objectPtr->export.description = NULL; - objectPtr->export.reference = NULL; - objectPtr->export.indexkind = SMI_INDEX_UNKNOWN; - objectPtr->export.implied = 0; - objectPtr->export.create = 0; - objectPtr->export.nodekind = SMI_NODEKIND_UNKNOWN; - - objectPtr->modulePtr = modulePtr; - objectPtr->nodePtr = nodePtr; - objectPtr->prevSameNodePtr = NULL; - objectPtr->nextSameNodePtr = NULL; - objectPtr->typePtr = NULL; - objectPtr->listPtr = NULL; - objectPtr->flags = flags; - objectPtr->line = parserPtr ? parserPtr->line : -1; - - objectPtr->export.oidlen = 0; /* filled in by */ - objectPtr->export.oid = NULL; /* second pass. */ - - objectPtr->nextPtr = NULL; - if (modulePtr) { - objectPtr->prevPtr = modulePtr->lastObjectPtr; - if (!modulePtr->firstObjectPtr) - modulePtr->firstObjectPtr = objectPtr; - if (modulePtr->lastObjectPtr) - modulePtr->lastObjectPtr->nextPtr = objectPtr; - modulePtr->lastObjectPtr = objectPtr; - } else { - objectPtr->prevPtr = NULL; - } - - objectPtr->prevSameNodePtr = nodePtr->lastObjectPtr; - if (!nodePtr->firstObjectPtr) - nodePtr->firstObjectPtr = objectPtr; - if (nodePtr->lastObjectPtr) - nodePtr->lastObjectPtr->nextSameNodePtr = objectPtr; - nodePtr->lastObjectPtr = objectPtr; - objectPtr->nodePtr = nodePtr; - - return (objectPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * addNode -- - * - * Create a new Node by a given parent Node and subid. - * - * Results: - * A pointer to the new Node structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *addNode (Node *parentNodePtr, SmiSubid subid, NodeFlags flags, - Parser *parserPtr) -{ - Node *nodePtr; - Node *c; - - nodePtr = (Node *) smiMalloc(sizeof(Node)); - - nodePtr->flags = flags; - nodePtr->subid = subid; - nodePtr->parentPtr = parentNodePtr; - nodePtr->firstChildPtr = NULL; - nodePtr->lastChildPtr = NULL; - nodePtr->firstObjectPtr = NULL; - nodePtr->lastObjectPtr = NULL; - - /* - * this cannot be set in all situations (pending sub trees). - * we delay it to the second pass. - */ - nodePtr->oidlen = 0; - nodePtr->oid = NULL; - - if (parentNodePtr) { - if (parentNodePtr->firstChildPtr) { - for (c = parentNodePtr->firstChildPtr; - c && (c->subid < subid); - c = c->nextPtr); - if (c) { - if (c != parentNodePtr->firstChildPtr) { - c->prevPtr->nextPtr = nodePtr; - nodePtr->prevPtr = c->prevPtr; - c->prevPtr = nodePtr; - nodePtr->nextPtr = c; - } else { - c->prevPtr = nodePtr; - nodePtr->nextPtr = c; - nodePtr->prevPtr = NULL; - parentNodePtr->firstChildPtr = nodePtr; - } - } else { - nodePtr->nextPtr = NULL; - nodePtr->prevPtr = parentNodePtr->lastChildPtr; - parentNodePtr->lastChildPtr->nextPtr = nodePtr; - parentNodePtr->lastChildPtr = nodePtr; - } - } else { - parentNodePtr->firstChildPtr = nodePtr; - parentNodePtr->lastChildPtr = nodePtr; - nodePtr->nextPtr = NULL; - nodePtr->prevPtr = NULL; - } - } - - return nodePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * createNodes -- - * - * Create all missing Nodes down the tree along all subids of - * a given Oid. - * - * Results: - * A pointer to the leaf Node structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *createNodes(unsigned int oidlen, SmiSubid *oid) -{ - Node *parentNodePtr, *nodePtr; - unsigned int i; - - parentNodePtr = smiHandle->rootNodePtr; - - for(i = 0; i < oidlen; i++) { - if (!(nodePtr = findNodeByParentAndSubid(parentNodePtr, oid[i]))) { - nodePtr = addNode(parentNodePtr, oid[i], 0, NULL); - } - parentNodePtr = nodePtr; - } - - return parentNodePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * createNodesByOidString -- - * - * Create all missing Nodes down the tree along all subids of - * a given Oid. - * - * Results: - * A pointer to the leaf Node structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *createNodesByOidString(const char *oid) -{ - char *p, *elements; - Node *parentNodePtr, *nodePtr; - SmiSubid subid; - - parentNodePtr = smiHandle->rootNodePtr; - elements = smiStrdup(oid); - - p = strtok(elements, "."); - do { - subid = (unsigned int)strtoul(p, NULL, 0); - if (!(nodePtr = findNodeByParentAndSubid(parentNodePtr, - subid))) { - nodePtr = addNode(parentNodePtr, subid, 0, NULL); - } - parentNodePtr = nodePtr; - } while ((p = strtok(NULL, "."))); - - smiFree(elements); - - return parentNodePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * getParentNode -- - * - * Return the parent of a given Node. - * - * Results: - * A pointer to the parent Node structure. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *getParentNode(Node *nodePtr) -{ - return nodePtr->parentPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * mergeNodeTrees -- - * - * Merge the subtree rooted at `from' into the `to' tree recursively - * and release the `from' tree. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static void mergeNodeTrees(Node *toNodePtr, Node *fromNodePtr, - Parser *parserPtr) -{ - Node *nodePtr, *toChildPtr, *nextPtr; - Object *objectPtr; - - /* (1) merge lists of Objects for this node */ - if (fromNodePtr->firstObjectPtr) { - if (!toNodePtr->firstObjectPtr) { - toNodePtr->firstObjectPtr = fromNodePtr->firstObjectPtr; - toNodePtr->lastObjectPtr = fromNodePtr->lastObjectPtr; - } else { - fromNodePtr->firstObjectPtr->prevSameNodePtr = - toNodePtr->lastObjectPtr; - toNodePtr->lastObjectPtr->nextSameNodePtr = - fromNodePtr->firstObjectPtr; - toNodePtr->lastObjectPtr = fromNodePtr->lastObjectPtr; - } - } - for (objectPtr = fromNodePtr->firstObjectPtr; - objectPtr; objectPtr = objectPtr->nextSameNodePtr) { - objectPtr->nodePtr = toNodePtr; - - } - - /* (2) loop: merge all first-level `from' sub-trees to `to' */ - /* adjust all `from' sub-nodes' parentPtrs */ - for (nodePtr = fromNodePtr->firstChildPtr; nodePtr; - nodePtr = nodePtr->nextPtr) { - nodePtr->parentPtr = toNodePtr; - } - if (!toNodePtr->firstChildPtr) { - /* - * if `to' has no sub-nodes, just move the `from' sub-nodes. - */ - toNodePtr->firstChildPtr = fromNodePtr->firstChildPtr; - toNodePtr->lastChildPtr = fromNodePtr->lastChildPtr; - } else { - /* - * otherwise, we really have to merge both trees... - */ - for (nodePtr = fromNodePtr->firstChildPtr; nodePtr; ) { - nextPtr = nodePtr->nextPtr; - if ((toChildPtr = findNodeByParentAndSubid(toNodePtr, - nodePtr->subid))) { - /* - * if a sub-node with the same subid is already present - * in `to', merge them recursively. - */ - mergeNodeTrees(toChildPtr, nodePtr, parserPtr); - } else { - /* - * otherwise, move the sub-tree from `from' to `to'. - */ - if (nodePtr->subid < toNodePtr->firstChildPtr->subid) { - /* move to the head. */ - nodePtr->nextPtr = toNodePtr->firstChildPtr; - toNodePtr->firstChildPtr = nodePtr; - } else if (nodePtr->subid > toNodePtr->lastChildPtr->subid) { - /* move to the end. */ - nodePtr->prevPtr = toNodePtr->lastChildPtr; - toNodePtr->lastChildPtr->nextPtr = nodePtr; - toNodePtr->lastChildPtr = nodePtr; - } else { - /* move to the appropriate place in the `to' list. */ - for (toChildPtr = toNodePtr->firstChildPtr; - toChildPtr->nextPtr->subid < nodePtr->subid; - toChildPtr = toChildPtr->nextPtr); - toChildPtr->nextPtr->prevPtr = nodePtr; - nodePtr->nextPtr = toChildPtr->nextPtr; - nodePtr->prevPtr = toChildPtr; - toChildPtr->nextPtr = nodePtr; - } - } - nodePtr = nextPtr; - } - } - - smiFree(fromNodePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectName -- - * - * Set the name of a given Object. Combine two Objects if the name - * already exists. - * - * Results: - * (Object *) of the potentially combined object. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *setObjectName(Object *objectPtr, char *name, Parser *parserPtr) -{ - Node *nodePtr, *nextPtr; - Module *modulePtr; - Object *newObjectPtr; - - if (objectPtr->export.name) { - smiFree(objectPtr->export.name); - } - objectPtr->export.name = name; - /* - * If this name is found on the pending list (at depth==1 in - * pendingRootNode), we have to move the corresponding subtree to - * the main tree. - */ - for (nodePtr = parserPtr->pendingNodePtr->firstChildPtr; nodePtr; - nodePtr = nextPtr) { - - /* - * probably we change the contents of `pending', so remember - * the next pointer. - */ - nextPtr = nodePtr->nextPtr; - - if (!strcmp(nodePtr->firstObjectPtr->export.name, name)) { - - /* - * remove nodePtr from the pendingRootNode tree. - */ - if (nodePtr->prevPtr) { - nodePtr->prevPtr->nextPtr = nodePtr->nextPtr; - } else { - parserPtr->pendingNodePtr->firstChildPtr = nodePtr->nextPtr; - } - if (nodePtr->nextPtr) { - nodePtr->nextPtr->prevPtr = nodePtr->prevPtr; - } else { - parserPtr->pendingNodePtr->lastChildPtr = nodePtr->prevPtr; - } - -#if 0 - objectPtr->nodePtr->firstObjectPtr = NULL; - objectPtr->nodePtr->lastObjectPtr = NULL; -#else - if (objectPtr->nodePtr->lastObjectPtr != NULL) { - if (objectPtr->nodePtr->lastObjectPtr->export.oid == NULL) { - objectPtr->nodePtr->lastObjectPtr = - objectPtr->nodePtr->lastObjectPtr->prevSameNodePtr; - if (objectPtr->nodePtr->lastObjectPtr == NULL) { - objectPtr->nodePtr->firstObjectPtr = NULL; - } - } - } -#endif - - newObjectPtr = nodePtr->firstObjectPtr; - if (newObjectPtr) { - modulePtr = newObjectPtr->modulePtr; - if (modulePtr->objectPtr == objectPtr) { - modulePtr->objectPtr = newObjectPtr; - } - if (modulePtr->firstObjectPtr == objectPtr) { - modulePtr->firstObjectPtr = objectPtr->nextPtr; - modulePtr->firstObjectPtr->prevPtr = NULL; - } - if (modulePtr->lastObjectPtr == objectPtr) { - modulePtr->lastObjectPtr = objectPtr->prevPtr; - modulePtr->lastObjectPtr->nextPtr = NULL; - } - - mergeNodeTrees(objectPtr->nodePtr, nodePtr, parserPtr); - smiFree(objectPtr->export.name); - smiFree(objectPtr); - return newObjectPtr; - } else { - return objectPtr; - } - } - } - return objectPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectType -- - * - * Set the type (pointer to a Type struct) of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectType(Object *objectPtr, Type *typePtr) -{ - objectPtr->typePtr = typePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectAccess -- - * - * Set the access of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectAccess(Object *objectPtr, SmiAccess access) -{ - objectPtr->export.access = access; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectStatus -- - * - * Set the status of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectStatus(Object *objectPtr, SmiStatus status) -{ - objectPtr->export.status = status; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectDescription -- - * - * Set the description of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectDescription(Object *objectPtr, char *description, - Parser *parserPtr) -{ - if (objectPtr->export.description) - smiFree(objectPtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - objectPtr->export.description = NULL; - } else { - objectPtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectReference -- - * - * Set the reference of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectReference(Object *objectPtr, char *reference, Parser *parserPtr) -{ - if (objectPtr->export.reference) - smiFree(objectPtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - objectPtr->export.reference = NULL; - } else { - objectPtr->export.reference = reference; - } -} - - -/* - *---------------------------------------------------------------------- - * - * setObjectFormat -- - * - * Set the format of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectFormat(Object *objectPtr, char *format) -{ - if (objectPtr->export.format) smiFree(objectPtr->export.format); - objectPtr->export.format = format; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectUnits -- - * - * Set the units of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectUnits(Object *objectPtr, char *units) -{ - if (objectPtr->export.units) smiFree(objectPtr->export.units); - objectPtr->export.units = units; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectDecl -- - * - * Set the declaring macro of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectDecl(Object *objectPtr, SmiDecl decl) -{ - objectPtr->export.decl = decl; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectLine -- - * - * Set the line of definition of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectLine(Object *objectPtr, int line, Parser *parserPtr) -{ - if (line) { - objectPtr->line = line; - } else { - objectPtr->line = parserPtr ? parserPtr->line : -1; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectNodekind -- - * - * Set the language independant SmiNodekind of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectNodekind(Object *objectPtr, SmiNodekind nodekind) -{ - objectPtr->export.nodekind = nodekind; -} - - - -/* - *---------------------------------------------------------------------- - * - * addObjectFlags -- - * - * Add flags to the flags of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void addObjectFlags(Object *objectPtr, ObjectFlags flags) -{ - objectPtr->flags |= flags; -} - - - -/* - *---------------------------------------------------------------------- - * - * deleteObjectFlags -- - * - * Delete flags from the flags of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void deleteObjectFlags(Object *objectPtr, ObjectFlags flags) -{ - objectPtr->flags &= ~flags; -} - - - -/* - *---------------------------------------------------------------------- - * - * checkObjectFlag -- - * - * Check whether a given set of flags of a given Object are all set. - * - * Results: - * true if all named flags are set. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -int checkObjectFlags(Object *objectPtr, ObjectFlags flags) -{ - return ((objectPtr->flags & flags) == flags); -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectIndex -- - * - * Set the list of INDEX elements of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -/* TODO remove me -void setObjectIndex(Object *objectPtr, Index *indexPtr) - Object *objectPtr; - Index *indexPtr; -{ - objectPtr->indexPtr = indexPtr; -} -*/ - - -/* - *---------------------------------------------------------------------- - * - * setObjectList -- - * - * Set the list of objects of a notification type or object group - * or the list of notifications of a notification group. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectList(Object *objectPtr, List *listPtr) -{ - objectPtr->listPtr = listPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectRelated -- - * - * Set the related object of a given object (e.g. SMIv2 AUGMENTS) - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectRelated(Object *objectPtr, Object *relatedPtr) -{ - objectPtr->relatedPtr = relatedPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectImplied -- - * - * Set the implied flag of a given object - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectImplied(Object *objectPtr, int implied) -{ - objectPtr->export.implied = implied; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectCreate -- - * - * Set the create flag of a given (table entry) object - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectCreate(Object *objectPtr, int create) -{ - objectPtr->export.create = create; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectIndexkind -- - * - * Set the indexkind of a given (table entry) object - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectIndexkind(Object *objectPtr, SmiIndexkind indexkind) -{ - objectPtr->export.indexkind = indexkind; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectValue -- - * - * Set the default value pointer of a given Object. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectValue(Object *objectPtr, SmiValue *valuePtr) -{ - objectPtr->export.value = *valuePtr; - smiFree(valuePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectUniqueness -- - * - * Set the uniqueness entry of an object - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setObjectUniqueness(Object *objectPtr, List *listPtr) -{ - objectPtr->uniquenessPtr = listPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setObjectInstallErrors -- - * - * Set the install errors entry of an object - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -/*void setObjectInstallErrors(Object *objectPtr, List *listPtr) -{ - objectPtr->installErrorsPtr = listPtr; -}*/ - - - -/* - *---------------------------------------------------------------------- - * - * findNodeByParentAndSubid -- - * - * Lookup a Node by a given parent and subid value. - * - * Results: - * A pointer to the Node structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *findNodeByParentAndSubid(Node *parentNodePtr, SmiSubid subid) -{ - Node *nodePtr; - - if (parentNodePtr && - (parentNodePtr != smiHandle->parserPtr->pendingNodePtr)) { - for (nodePtr = parentNodePtr->firstChildPtr; nodePtr; - nodePtr = nodePtr->nextPtr) { - if (nodePtr->subid == subid) { - return (nodePtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findNodeByOid -- - * - * Lookup a Node by a given array of numerical subids. - * - * Results: - * A pointer to the Node structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *findNodeByOid(unsigned int oidlen, SmiSubid *oid) -{ - Node *nodePtr; - unsigned int i; - - nodePtr = smiHandle->rootNodePtr; - for(i = 0; i < oidlen && nodePtr; i++) { - nodePtr = findNodeByParentAndSubid(nodePtr, oid[i]); - } - - return (nodePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * findNodeByOidString -- - * - * Lookup a Node by a given string of concatinated numerical subids. - * - * Results: - * A pointer to the Node structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Node *findNodeByOidString(char *oid) -{ - Node *nodePtr; - char *s; - char *p; - - s = smiStrdup(oid); - nodePtr = smiHandle->rootNodePtr; - for(p = strtok(s, ". "); p && nodePtr; p = strtok(NULL, ". ")) { - nodePtr = findNodeByParentAndSubid(nodePtr, atoi(p)); - } - - smiFree(s); - return (nodePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByNode -- - * - * Lookup an Object by a given Node. Note, that there might be - * multiple definitions for one node. - * - * Results: - * A pointer to the first Object structure in the current View or - * a pointer to the first Object if none is in the current View or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByNode(Node *nodePtr) -{ - Object *objectPtr; - Object *goodObjectPtr = NULL; - - /* first, try to find an object in the current view. */ - for (objectPtr = nodePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextSameNodePtr) { - if (isInView(objectPtr->modulePtr->export.name)) { - if (! goodObjectPtr) { - goodObjectPtr = objectPtr; - } else if (objectPtr->modulePtr->export.language - > goodObjectPtr->modulePtr->export.language) { - goodObjectPtr = objectPtr; - } - } - } - - return goodObjectPtr ? goodObjectPtr : nodePtr->firstObjectPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByModuleAndNode -- - * - * Lookup an Object by a given Node and Module. This is necessary - * since there might be different declarations in different modules - * for the same OID. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByModuleAndNode(Module *modulePtr, Node *nodePtr) -{ - Object *objectPtr; - - for (objectPtr = nodePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextSameNodePtr) { - if (objectPtr->modulePtr == modulePtr) { - return (objectPtr); - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByModulenameAndNode -- - * - * Lookup an Object by a given Node and Modulename. This is necessary - * since there might be different declarations in different modules - * for the same OID. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByModulenameAndNode(const char *modulename, Node *nodePtr) -{ - Object *objectPtr; - - for (objectPtr = nodePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextSameNodePtr) { - if (!strcmp(objectPtr->modulePtr->export.name, modulename)) { - return (objectPtr); - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByName -- - * - * Lookup an Object by a given name. Note, that - * there might be more than one Object with the same name. - * In this case, it is undefined which Object is returned. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByName(const char *objectname) -{ - Module *modulePtr; - Object *objectPtr; - - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (objectPtr = modulePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextPtr) { - if ((objectPtr->export.name) && - !strcmp(objectPtr->export.name, objectname)) { - /* - * We return the first matching object. - * TODO: probably we should check if there are more matching - * objects, and give a warning if there's another one. - */ - return (objectPtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findNextObjectByName -- - * - * Lookup the next Object by a given name. Note, that - * there might be more than one Object with the same name. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findNextObjectByName(const char *objectname, Object *prevObjectPtr) -{ - Module *modulePtr; - Object *objectPtr; - - for (modulePtr = prevObjectPtr->modulePtr->nextPtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (objectPtr = modulePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextPtr) { - if ((objectPtr->export.name) - && !strcmp(objectPtr->export.name, objectname)) { - /* - * We return the first matching object. - * TODO: probably we should check if there are more matching - * objects, and give a warning if there's another one. - */ - return (objectPtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByModulenameAndName -- - * - * Lookup a Object by a given Module and name. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByModulenameAndName(const char *modulename, - const char *objectname) -{ - Module *modulePtr; - Object *objectPtr; - - modulePtr = findModuleByName(modulename); - - if (modulePtr) { - for (objectPtr = modulePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextPtr) { - if ((objectPtr->export.name) && - !strcmp(objectPtr->export.name, objectname)) { - return (objectPtr); - } - } - } - - /* - * Some toplevel Objects seem to be always known. - */ - if ((!strcmp(objectname, "iso")) || - (!strcmp(objectname, "ccitt")) || - (!strcmp(objectname, "joint-iso-ccitt"))) { - return findObjectByName(objectname); - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findObjectByModuleAndName -- - * - * Lookup a Object by a given Module and name. - * - * Results: - * A pointer to the Object structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Object *findObjectByModuleAndName(Module *modulePtr, const char *objectname) -{ - Object *objectPtr; - - if (! objectname) { - return NULL; - } - - if (modulePtr) { - for (objectPtr = modulePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextPtr) { - if ((objectPtr->export.name) && - !strcmp(objectPtr->export.name, objectname)) { - return (objectPtr); - } - } - } - - /* - * Some toplevel Objects seem to be always known. - */ - if ((!strcmp(objectname, "iso")) || - (!strcmp(objectname, "ccitt")) || - (!strcmp(objectname, "joint-iso-ccitt"))) { - return findObjectByName(objectname); - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * addType -- - * - * Create a new Type structure. - * - * Results: - * A pointer to the new Type structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *addType(char *type_name, SmiBasetype basetype, TypeFlags flags, - Parser *parserPtr) -{ - Type *typePtr; - Module *modulePtr; - - modulePtr = parserPtr ? parserPtr->modulePtr : NULL; - - typePtr = smiMalloc(sizeof(Type)); - - typePtr->export.name = type_name; - typePtr->export.basetype = basetype; - typePtr->export.decl = SMI_DECL_UNKNOWN; - typePtr->export.format = NULL; - typePtr->export.value.basetype = SMI_BASETYPE_UNKNOWN; - typePtr->export.units = NULL; - typePtr->export.status = SMI_STATUS_UNKNOWN; - typePtr->export.description = NULL; - typePtr->export.reference = NULL; - - typePtr->modulePtr = modulePtr; - typePtr->listPtr = NULL; - typePtr->flags = flags; - typePtr->parentPtr = NULL; - typePtr->line = parserPtr ? parserPtr->line : -1; - - typePtr->nextPtr = NULL; - if (modulePtr) { - typePtr->prevPtr = modulePtr->lastTypePtr; - if (!modulePtr->firstTypePtr) - modulePtr->firstTypePtr = typePtr; - if (modulePtr->lastTypePtr) - modulePtr->lastTypePtr->nextPtr = typePtr; - modulePtr->lastTypePtr = typePtr; - } else { - typePtr->prevPtr = NULL; - } - - return (typePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * duplicateType -- - * - * Create a new Type as a duplicate of a given one but with - * an affiliation to the current module. - * - * Results: - * A pointer to the new Type structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *duplicateType(Type *templatePtr, TypeFlags flags, Parser *parserPtr) -{ - Type *typePtr; - Module *modulePtr; - - typePtr = (Type *) smiMalloc(sizeof(Type)); - - modulePtr = parserPtr->modulePtr; - - typePtr->export.name = NULL; - typePtr->export.basetype = templatePtr->export.basetype; - typePtr->export.decl = SMI_DECL_IMPLICIT_TYPE; - typePtr->export.format = NULL; - typePtr->export.value.basetype = SMI_BASETYPE_UNKNOWN; - typePtr->export.units = NULL; - typePtr->export.status = templatePtr->export.status; - typePtr->export.description = NULL; - typePtr->export.reference = NULL; - - typePtr->modulePtr = modulePtr; - typePtr->listPtr = NULL; - typePtr->flags = templatePtr->flags; - typePtr->line = parserPtr ? parserPtr->line : -1; - - typePtr->nextPtr = NULL; - typePtr->prevPtr = modulePtr->lastTypePtr; - if (!modulePtr->firstTypePtr) - modulePtr->firstTypePtr = typePtr; - if (modulePtr->lastTypePtr) - modulePtr->lastTypePtr->nextPtr = typePtr; - modulePtr->lastTypePtr = typePtr; - - setTypeParent(typePtr, templatePtr); - - return (typePtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeName -- - * - * Set the name of a given Type. If it already exists, merge the - * two types. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *setTypeName(Type *typePtr, char *name) -{ - Type *type2Ptr; - List *listPtr; - - if (typePtr->export.name) { - smiFree(typePtr->export.name); - } - typePtr->export.name = smiStrdup(name); - - if (! typePtr->export.name) { - return typePtr; - } - - /* - * If a type with this name already exists, it must be a forward - * reference and both types have to be merged. - */ - for (type2Ptr = typePtr->modulePtr->firstTypePtr; type2Ptr; - type2Ptr = type2Ptr->nextPtr) { - - if (type2Ptr->export.name && - (!strcmp(type2Ptr->export.name, name)) && - (type2Ptr != typePtr)) { - - /* - * remove typePtr from the type list. - */ - if (typePtr->prevPtr) { - typePtr->prevPtr->nextPtr = typePtr->nextPtr; - } else { - typePtr->modulePtr->firstTypePtr = typePtr->nextPtr; - } - if (typePtr->nextPtr) { - typePtr->nextPtr->prevPtr = typePtr->prevPtr; - } else { - typePtr->modulePtr->lastTypePtr = typePtr->prevPtr; - } - - type2Ptr->export.basetype = typePtr->export.basetype; - type2Ptr->export.decl = typePtr->export.decl; - type2Ptr->export.format = typePtr->export.format; - type2Ptr->export.value = typePtr->export.value; - type2Ptr->export.units = typePtr->export.units; - type2Ptr->export.status = typePtr->export.status; - type2Ptr->export.description = typePtr->export.description; - type2Ptr->export.reference = typePtr->export.reference; - - type2Ptr->parentPtr = typePtr->parentPtr; - type2Ptr->listPtr = typePtr->listPtr; - type2Ptr->flags = typePtr->flags; - type2Ptr->line = typePtr->line; - - /* - * if it's an enum or bits type, we also have to adjust - * the references from the named numbers back to the type. - */ - if ((type2Ptr->export.basetype == SMI_BASETYPE_ENUM) || - (type2Ptr->export.basetype == SMI_BASETYPE_BITS)) { - for (listPtr = type2Ptr->listPtr; listPtr; - listPtr = listPtr->nextPtr) { - ((NamedNumber *)(listPtr->ptr))->typePtr = type2Ptr; - } - } - - smiFree(typePtr->export.name); - smiFree(typePtr); - - return type2Ptr; - } - } - return typePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeParent -- - * - * Set the parent of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeParent(Type *typePtr, Type *parentPtr) -{ - typePtr->parentPtr = parentPtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeStatus -- - * - * Set the status of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeStatus(Type *typePtr, SmiStatus status) -{ - typePtr->export.status = status; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeBasetype -- - * - * Set the basetype of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeBasetype(Type *typePtr, SmiBasetype basetype) -{ - typePtr->export.basetype = basetype; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeDescription -- - * - * Set the description of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeDescription(Type *typePtr, char *description, Parser *parserPtr) -{ - if (typePtr->export.description) - smiFree(typePtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - typePtr->export.description = NULL; - } else { - typePtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeReference -- - * - * Set the reference of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeReference(Type *typePtr, char *reference, Parser *parserPtr) -{ - if (typePtr->export.reference) - smiFree(typePtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - typePtr->export.reference = NULL; - } else { - typePtr->export.reference = reference; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeList -- - * - * Set the pointer to a struct list. This used for - * - columns of a SEQUENCE type, - * - enumeration items of an enumeration integer type, - * - min-max pair items of a range restricted type, - * - min-max pars items of a size restricted type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeList(Type *typePtr, List *listPtr) -{ - if (!typePtr->listPtr) { - typePtr->listPtr = listPtr; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeFormat -- - * - * Set the format (displayHint) of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeFormat(Type *typePtr, char *format) -{ - if (typePtr->export.format) smiFree(typePtr->export.format); - typePtr->export.format = format; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeUnits -- - * - * Set the units of a given Type. Note: units of types are only - * present in SMIng, not in SMIv2. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeUnits(Type *typePtr, char *units) -{ - if (typePtr->export.units) smiFree(typePtr->export.units); - typePtr->export.units = units; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeDecl -- - * - * Set the declaring macro of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeDecl(Type *typePtr, SmiDecl decl) -{ - typePtr->export.decl = decl; -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeLine -- - * - * Set the line of definition of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeLine(Type *typePtr, int line, Parser *parserPtr) -{ - if (line) { - typePtr->line = line; - } else { - typePtr->line = parserPtr ? parserPtr->line : -1; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setTypeValue -- - * - * Set the default value pointer of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setTypeValue(Type *typePtr, SmiValue *valuePtr) -{ - typePtr->export.value = *valuePtr; -} - - - -/* - *---------------------------------------------------------------------- - * - * addTypeFlags -- - * - * Add flags to the flags of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void addTypeFlags(Type *typePtr, TypeFlags flags) -{ - typePtr->flags |= flags; -} - - - -/* - *---------------------------------------------------------------------- - * - * deleteTypeFlags -- - * - * Delete flags from the flags of a given Type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void deleteTypeFlags(Type *typePtr, TypeFlags flags) -{ - typePtr->flags &= ~flags; -} - - - -/* - *---------------------------------------------------------------------- - * - * findTypeByName -- - * - * Lookup a Type by a given name. - * - * Results: - * A pointer to the Type structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type * findTypeByName(const char *type_name) -{ - Module *modulePtr; - Type *typePtr; - - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (typePtr = modulePtr->firstTypePtr; typePtr; - typePtr = typePtr->nextPtr) { - if ((typePtr->export.name) && - !strcmp(typePtr->export.name, type_name)) { - return (typePtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findNextTypeByName -- - * - * Lookup the next Type by a given name. - * - * Results: - * A pointer to the Type structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *findNextTypeByName(const char *type_name, Type *prevTypePtr) -{ - Module *modulePtr; - Type *typePtr; - - for (modulePtr = prevTypePtr->modulePtr->nextPtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (typePtr = modulePtr->firstTypePtr; typePtr; - typePtr = typePtr->nextPtr) { - if ((typePtr->export.name) && - !strcmp(typePtr->export.name, type_name)) { - return (typePtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findTypeByModulenameAndName -- - * - * Lookup a Type by a given Module and name. - * - * Results: - * A pointer to the Type structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *findTypeByModulenameAndName(const char *modulename, - const char *type_name) -{ - Type *typePtr; - Module *modulePtr; - - modulePtr = findModuleByName(modulename); - - if (modulePtr) { - for (typePtr = modulePtr->firstTypePtr; typePtr; - typePtr = typePtr->nextPtr) { - if ((typePtr->export.name) && !strcmp(typePtr->export.name, type_name)) { - return (typePtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findTypeByModuleAndName -- - * - * Lookup a Type by a given Module and name. - * - * Results: - * A pointer to the Type structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Type *findTypeByModuleAndName(Module *modulePtr, const char *type_name) -{ - Type *typePtr; - - if (modulePtr) { - for (typePtr = modulePtr->firstTypePtr; typePtr; - typePtr = typePtr->nextPtr) { - if ((typePtr->export.name) && - !strcmp(typePtr->export.name, type_name)) { - return (typePtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findTypeNamedNumber -- - * - * - * - * Results: - * - * Side effects: - * - *---------------------------------------------------------------------- */ - -NamedNumber *findTypeNamedNumber(Type *typePtr, - SmiInteger32 number) -{ - List *listPtr; - - for (listPtr = typePtr->listPtr; - listPtr; listPtr = listPtr->nextPtr) { - if (((NamedNumber *)(listPtr->ptr))->export.value.value.integer32 == - number) - break; - } - - return (NamedNumber *)(listPtr->ptr); -} - - - -/* - *---------------------------------------------------------------------- - * - * addIdentity -- - * - * Create a new Identity structure. - * - * Results: - * A pointer to the new Identity structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- */ - -Identity *addIdentity(char *identityname, Parser *parserPtr) -{ - Identity *identityPtr; - Module *modulePtr; - - modulePtr = parserPtr->modulePtr; - - identityPtr = (Identity*) smiMalloc(sizeof(Identity)); - - identityPtr->export.name = identityname; - identityPtr->export.status = SMI_STATUS_UNKNOWN; - identityPtr->export.description = NULL; - identityPtr->export.reference = NULL; - identityPtr->parentPtr = NULL; - - identityPtr->modulePtr = parserPtr->modulePtr; - identityPtr->line = parserPtr ? parserPtr->line : -1; - - identityPtr->nextPtr = NULL; - identityPtr->prevPtr = modulePtr->lastIdentityPtr; - if (!modulePtr->firstIdentityPtr) - modulePtr->firstIdentityPtr = identityPtr; - if (modulePtr->lastIdentityPtr) - modulePtr->lastIdentityPtr->nextPtr = identityPtr; - modulePtr->lastIdentityPtr = identityPtr; - - return (identityPtr); - -} - -/* - *---------------------------------------------------------------------- - * - * setIdentityDecl -- - * - * Set the declaring macro of a given Identity. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setIdentityDecl(Identity *identityPtr, SmiDecl decl) -{ - identityPtr->export.decl = decl; -} - -/* - *---------------------------------------------------------------------- - * - * setIdentityStatus -- - * - * Set the status of a given Identity. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setIdentityStatus(Identity *identityPtr, SmiStatus status) -{ - identityPtr->export.status = status; -} - - - -/* - *---------------------------------------------------------------------- - * - * setIdentityDescription -- - * - * Set the description of a given Identity. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setIdentityDescription(Identity *identityPtr, char *description, Parser *parserPtr) -{ - if (identityPtr->export.description) smiFree(identityPtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - identityPtr->export.description = NULL; - } else { - identityPtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setIdentityReference -- - * - * Set the reference of a given Identity. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setIdentityReference(Identity *identityPtr, char *reference, Parser *parserPtr) -{ - if (identityPtr->export.reference) - smiFree(identityPtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - identityPtr->export.reference = NULL; - } else { - identityPtr->export.reference = reference; - } -} - -/* - *---------------------------------------------------------------------- - * - * setIdentityParent -- - * - * Set the parent of a given Identity to given Identity pointer. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setIdentityParent(Identity *identityPtr, Identity *parentPtr) -{ - if(identityPtr) identityPtr->parentPtr = parentPtr; -} - - -/* - *---------------------------------------------------------------------- - * - * findIdentityByName -- - * - * Lookup a Identity by a given name. - * - * Results: - * A pointer to the Identity structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Identity *findIdentityByName(const char *identityname) -{ - Module *modulePtr; - Identity *identityPtr; - - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (identityPtr = modulePtr->firstIdentityPtr; identityPtr; - identityPtr = identityPtr->nextPtr) { - if ((identityPtr->export.name) && - !strcmp(identityPtr->export.name, identityname)) { - return (identityPtr); - } - } - } - - return (NULL); -} - -/* - *---------------------------------------------------------------------- - * - * findIdentityByModuleAndName -- - * - * Lookup a Identity by a given name and Module. - * - * Results: - * A pointer to the Identity structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Identity *findIdentityByModuleAndName(Module *modulePtr, - const char *identityname) -{ - Identity *identityPtr; - - - for (identityPtr = modulePtr->firstIdentityPtr; identityPtr; - identityPtr = identityPtr->nextPtr) { - if ((identityPtr->export.name) && - !strcmp(identityPtr->export.name, identityname)) { - return (identityPtr); - } - } - - - return (NULL); -} - -/* - *---------------------------------------------------------------------- - * - * findIdentityByModulenameAndName -- - * - * Lookup a Identity by a given Module and name. - * - * Results: - * A pointer to the Identity structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Identity *findIdentityByModulenameAndName(const char *modulename, - const char *identity_name) -{ - Identity *identityPtr; - Module *modulePtr; - - modulePtr = findModuleByName(modulename); - - if (modulePtr) { - for (identityPtr = modulePtr->firstIdentityPtr; identityPtr; - identityPtr = identityPtr->nextPtr) { - if ((identityPtr->export.name) && !strcmp(identityPtr->export.name, identity_name)) { - return (identityPtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * addClass -- - * - * Create a new Class structure. - * - * Results: - * A pointer to the new Class structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- */ - -Class *addClass(char *classname, Parser *parserPtr) -{ - Class *classPtr; - Module *modulePtr; - - modulePtr = parserPtr->modulePtr; - - classPtr = (Class*) smiMalloc(sizeof(Class)); - - classPtr->export.name = classname; - classPtr->export.status = SMI_STATUS_UNKNOWN; - classPtr->export.description = NULL; - classPtr->export.reference = NULL; - - classPtr->modulePtr = parserPtr->modulePtr; - classPtr->line = parserPtr ? parserPtr->line : -1; - - classPtr->parentPtr = NULL; - classPtr->firstAttributePtr = NULL; - classPtr->lastAttributePtr = NULL; - classPtr->firstEventPtr = NULL; - classPtr->lastEventPtr = NULL; - - classPtr->nextPtr = NULL; - classPtr->prevPtr = modulePtr->lastClassPtr; - if (!modulePtr->firstClassPtr) - modulePtr->firstClassPtr = classPtr; - if (modulePtr->lastClassPtr) - modulePtr->lastClassPtr->nextPtr = classPtr; - modulePtr->lastClassPtr = classPtr; - - return (classPtr); - -} - -/* - *---------------------------------------------------------------------- - * - * setClassDecl -- - * - * Set the declaring macro of a given Class. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setClassDecl(Class *classPtr, SmiDecl decl) -{ - classPtr->export.decl = decl; -} - -/* - *---------------------------------------------------------------------- - * - * setClassStatus -- - * - * Set the status of a given Class. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setClassStatus(Class *classPtr, SmiStatus status) -{ - classPtr->export.status = status; -} - - - -/* - *---------------------------------------------------------------------- - * - * setClassDescription -- - * - * Set the description of a given Class. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setClassDescription(Class *classPtr, char *description, Parser *parserPtr) -{ - if (classPtr->export.description) smiFree(classPtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - classPtr->export.description = NULL; - } else { - classPtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setClassReference -- - * - * Set the reference of a given Class. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setClassReference(Class *classPtr, char *reference, Parser *parserPtr) -{ - if (classPtr->export.reference) - smiFree(classPtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - classPtr->export.reference = NULL; - } else { - classPtr->export.reference = reference; - } -} - -/* - *---------------------------------------------------------------------- - * - * setClassParent -- - * - * Set the parent of a given Class to given Class pointer. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setClassParent(Class *classPtr, Class *parentPtr) -{ - if(classPtr) classPtr->parentPtr = parentPtr; -} - -/* - *---------------------------------------------------------------------- - * - * findClassByModuleAndName -- - * - * Lookup a Class by a given name. - * - * Results: - * A pointer to the Class structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -Class *findClassByModuleAndName(Module *modulePtr,char *name) -{ - Class *classPtr; - - for (classPtr = modulePtr->firstClassPtr; classPtr; - classPtr = classPtr->nextPtr) { - if ((classPtr->export.name) && - !strcmp(classPtr->export.name, name)) { - return (classPtr); - } - } - - return NULL; -} - -/* - *---------------------------------------------------------------------- - * - * findClassByModulenameAndName -- - * - * Lookup a Class by a given Module and name. - * - * Results: - * A pointer to the Class structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Class *findClassByModulenameAndName(const char *modulename, - const char *class_name) -{ - Class *classPtr; - Module *modulePtr; - - modulePtr = findModuleByName(modulename); - - if (modulePtr) { - for (classPtr = modulePtr->firstClassPtr; classPtr; - classPtr = classPtr->nextPtr) { - if ((classPtr->export.name) && !strcmp(classPtr->export.name, class_name)) { - return (classPtr); - } - } - } - - return (NULL); -} - -/* - *---------------------------------------------------------------------- - * - * duplicateTypeToAttribute -- - * - * Create a new Attribute as a duplicate of a given type but with - * an affiliation to the given Class. - * - * Results: - * A pointer to the new Attribute structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Attribute *duplicateTypeToAttribute(Type *templatePtr, Class *classPtr, Parser *parserPtr) -{ - Attribute *attributePtr; - - if(!classPtr) return NULL; - - attributePtr = (Attribute *) smiMalloc(sizeof(Attribute)); - - - attributePtr->export.name = NULL; - attributePtr->export.basetype = templatePtr->export.basetype; - attributePtr->export.decl = SMI_DECL_ATTRIBUTE; - attributePtr->export.format = NULL; - attributePtr->export.value.basetype = templatePtr->export.basetype; - attributePtr->export.units = NULL; - attributePtr->export.status = templatePtr->export.status; - attributePtr->export.description = NULL; - attributePtr->export.reference = NULL; - - attributePtr->classPtr = classPtr; - attributePtr->listPtr = NULL; - attributePtr->line = parserPtr ? parserPtr->line : -1; - - attributePtr->nextPtr = NULL; - attributePtr->prevPtr = classPtr->lastAttributePtr; - if (!classPtr->firstAttributePtr) - classPtr->firstAttributePtr = attributePtr; - if (classPtr->lastAttributePtr) - classPtr->lastAttributePtr->nextPtr = attributePtr; - classPtr->lastAttributePtr = attributePtr; - - setAttributeParentType(attributePtr, templatePtr); - - return (attributePtr); -} - - -/* - *---------------------------------------------------------------------- - * - * addAttribute -- - * - * Create a new Attribute structure and tie it to the given Class. - * - * Results: - * A pointer to the new Attribute structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Attribute *addAttribute(char *attribute_name, - Class *classPtr, Parser *parserPtr) -{ - Attribute *attributePtr; - - attributePtr = smiMalloc(sizeof(Attribute)); - - attributePtr->export.name = attribute_name; - attributePtr->export.basetype = SMI_BASETYPE_UNKNOWN; - attributePtr->export.decl = SMI_DECL_UNKNOWN; - attributePtr->export.format = NULL; - attributePtr->export.value.basetype = SMI_BASETYPE_UNKNOWN; - attributePtr->export.units = NULL; - attributePtr->export.status = SMI_STATUS_UNKNOWN; - attributePtr->export.description = NULL; - attributePtr->export.reference = NULL; - - attributePtr->classPtr = classPtr; - attributePtr->listPtr = NULL; - attributePtr->parentTypePtr = NULL; - attributePtr->parentClassPtr = NULL; - attributePtr->line = parserPtr ? parserPtr->line : -1; - - attributePtr->nextPtr = NULL; - if (classPtr) { - attributePtr->prevPtr = classPtr->lastAttributePtr; - if (!classPtr->firstAttributePtr) - classPtr->firstAttributePtr = attributePtr; - if (classPtr->lastAttributePtr) - classPtr->lastAttributePtr->nextPtr = attributePtr; - classPtr->lastAttributePtr = attributePtr; - } else { - attributePtr->prevPtr = NULL; - } - - return (attributePtr); -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeDecl -- - * - * Set the declaring macro of a given Attribute. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setAttributeDecl(Attribute *attributePtr, SmiDecl decl) -{ - attributePtr->export.decl = decl; -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeParentType -- - * - * Set the parent of a given attribute. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setAttributeParentType(Attribute *attributePtr, Type *parentPtr) -{ - attributePtr->parentTypePtr = parentPtr; -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeParentClass -- - * - * Set the parent Class of a given attribute. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setAttributeParentClass(Attribute *attributePtr, Class *parentPtr) -{ - attributePtr->parentClassPtr = parentPtr; -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeList -- - * - * Set the pointer to a struct list. This used for - * - enumeration items of an enumeration integer type, - * - min-max pair items of a range restricted type, - * - min-max pars items of a size restricted type. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setAttributeList(Attribute *attributePtr, List *listPtr) -{ - if (!attributePtr->listPtr) { - attributePtr->listPtr = listPtr; - } -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeName -- - * - * Set the name of a given Attribute. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setAttributeName(Attribute *attributePtr, char *name) -{ - - attributePtr->export.name = smiStrdup(name); -} - -/* - *---------------------------------------------------------------------- - * - * setAttributeAccess -- - * - * Set the access of a given Attribute. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -void setAttributeAccess(Attribute *attributePtr,SmiAccess access) -{ - attributePtr->export.access = access; -} - - -/* - *---------------------------------------------------------------------- - * - * addEvent -- - * - * Create a new Event structure and tie it to the given Class. - * - * Results: - * A pointer to the new Event structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -Event *addEvent(char *eventname, Class *classPtr, - Parser *parserPtr) -{ - Event *eventPtr; - - eventPtr = smiMalloc(sizeof(Event)); - - eventPtr->export.name = eventname; - eventPtr->export.decl = SMI_DECL_EVENT; - eventPtr->export.status = SMI_STATUS_UNKNOWN; - eventPtr->export.description = NULL; - eventPtr->export.reference = NULL; - - eventPtr->classPtr = classPtr; - eventPtr->line = parserPtr ? parserPtr->line : -1; - - eventPtr->nextPtr = NULL; - if (classPtr) { - eventPtr->prevPtr = classPtr->lastEventPtr; - if (!classPtr->firstEventPtr) - classPtr->firstEventPtr = eventPtr; - if (classPtr->lastEventPtr) - classPtr->lastEventPtr->nextPtr = eventPtr; - classPtr->lastEventPtr = eventPtr; - } else { - eventPtr->prevPtr = NULL; - } - - return (eventPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * addMacro -- - * - * Create a new Macro structure. - * - * Results: - * A pointer to the new Macro structure or - * NULL if terminated due to an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- */ - -Macro *addMacro(char *macroname, MacroFlags flags, Parser *parserPtr) -{ - Macro *macroPtr; - Module *modulePtr; - - modulePtr = parserPtr->modulePtr; - - /* TODO: Check wheather this macro already exists?? */ - - macroPtr = (Macro *) smiMalloc(sizeof(Macro)); - - macroPtr->export.name = macroname; - macroPtr->export.status = SMI_STATUS_UNKNOWN; - macroPtr->export.description = NULL; - macroPtr->export.reference = NULL; - - macroPtr->modulePtr = parserPtr->modulePtr; - macroPtr->flags = flags; - macroPtr->line = parserPtr ? parserPtr->line : -1; - - macroPtr->nextPtr = NULL; - macroPtr->prevPtr = modulePtr->lastMacroPtr; - if (!modulePtr->firstMacroPtr) - modulePtr->firstMacroPtr = macroPtr; - if (modulePtr->lastMacroPtr) - modulePtr->lastMacroPtr->nextPtr = macroPtr; - modulePtr->lastMacroPtr = macroPtr; - - return (macroPtr); -} - - - -/* - *---------------------------------------------------------------------- - * - * setMacroStatus -- - * - * Set the status of a given Macro. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroStatus(Macro *macroPtr, SmiStatus status) -{ - macroPtr->export.status = status; -} - - - -/* - *---------------------------------------------------------------------- - * - * setMacroDescription -- - * - * Set the description of a given Macro. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroDescription(Macro *macroPtr, char *description, Parser *parserPtr) -{ - if (macroPtr->export.description) smiFree(macroPtr->export.description); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(description); - macroPtr->export.description = NULL; - } else { - macroPtr->export.description = description; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setMacroReference -- - * - * Set the reference of a given Macro. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroReference(Macro *macroPtr, char *reference, Parser *parserPtr) -{ - if (macroPtr->export.reference) - smiFree(macroPtr->export.reference); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(reference); - macroPtr->export.reference = NULL; - } else { - macroPtr->export.reference = reference; - } -} - -/* - *---------------------------------------------------------------------- - * - * setMacroAbnf -- - * - * Set the abnf string of a given extension(SMIng only). - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroAbnf(Macro *macroPtr, char *abnf, Parser *parserPtr) -{ - if (macroPtr->export.abnf) - smiFree(macroPtr->export.abnf); - if (parserPtr->flags & SMI_FLAG_NODESCR) { - smiFree(abnf); - macroPtr->export.abnf = NULL; - } else { - macroPtr->export.abnf = abnf; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * setMacroDecl -- - * - * Set the declaring macro of a given Macro. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroDecl(Macro *macroPtr, SmiDecl decl) -{ - macroPtr->export.decl = decl; -} - - - -/* - *---------------------------------------------------------------------- - * - * setMacroLine -- - * - * Set the line of definition of a given Macro. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void setMacroLine(Macro *macroPtr, int line, Parser *parserPtr) -{ - if (line) { - macroPtr->line = line; - } else { - macroPtr->line = parserPtr ? parserPtr->line : -1; - } -} - - - -/* - *---------------------------------------------------------------------- - * - * findMacroByName -- - * - * Lookup a Macro by a given name. - * - * Results: - * A pointer to the Macro structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Macro *findMacroByName(const char *macroname) -{ - Module *modulePtr; - Macro *macroPtr; - - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = modulePtr->nextPtr) { - for (macroPtr = modulePtr->firstMacroPtr; macroPtr; - macroPtr = macroPtr->nextPtr) { - if ((macroPtr->export.name) && - !strcmp(macroPtr->export.name, macroname)) { - return (macroPtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findMacroByModuleAndName -- - * - * Lookup a Macro by a given Module and name. - * - * Results: - * A pointer to the Macro structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Macro *findMacroByModuleAndName(Module *modulePtr, const char *macroname) -{ - Macro *macroPtr; - - if (modulePtr) { - for (macroPtr = modulePtr->firstMacroPtr; macroPtr; - macroPtr = macroPtr->nextPtr) { - if (!strcmp(macroPtr->export.name, macroname)) { - return (macroPtr); - } - } - } - - return (NULL); -} - - - -/* - *---------------------------------------------------------------------- - * - * findNamedNumberByName -- - * - * Lookup the value of a namev nuber in a given typ. - * - * Results: - * A pointer to the NamedNumber structure or - * NULL if it is not found. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -NamedNumber *findNamedNumberByName(Type *typePtr,const char *name) -{ - List *listPtr; - - if(typePtr->export.basetype != SMI_BASETYPE_ENUM && - typePtr->export.basetype != SMI_BASETYPE_BITS) return NULL; - - for (listPtr = typePtr->listPtr; - listPtr; listPtr = listPtr->nextPtr) { - if (!strcmp(((NamedNumber *)(listPtr->ptr))->export.name - , name)) - return (NamedNumber *)(listPtr->ptr); - } - - return NULL; -} - - - - - -/* - *---------------------------------------------------------------------- - * - * smiInitData -- - * - * Initialize all need data structures at program start. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -int smiInitData() -{ - Object *objectPtr; - Parser parser; - - smiHandle->flags = 0; - - smiHandle->firstModulePtr = NULL; - smiHandle->lastModulePtr = NULL; - smiHandle->firstViewPtr = NULL; - smiHandle->lastViewPtr = NULL; - - /* - * Initialize a root Node for the main MIB tree. - */ - smiHandle->rootNodePtr = addNode(NULL, 0, NODE_FLAG_ROOT, NULL); - - /* - * Initialize a root Node for pending (forward referenced) nodes. - */ - smiHandle->parserPtr = &parser; - parser.pendingNodePtr = addNode(NULL, 0, NODE_FLAG_ROOT, NULL); - - /* - * Initialize the top level well-known nodes, ccitt, iso, joint-iso-ccitt - * belonging to a dummy module "". This is needed for SMIv1/v2. SMIng - * defines it in a special SMIng module. - */ - parser.path = NULL; - parser.flags = smiHandle->flags; - parser.file = NULL; - parser.line = -1; - parser.modulePtr = addModule(smiStrdup(""), smiStrdup(""), 0, NULL); - - addView(""); - - objectPtr = addObject(smiStrdup("ccitt"), smiHandle->rootNodePtr, 0, 0, &parser); - objectPtr->export.oid = objectPtr->nodePtr->oid = - smiMalloc(sizeof(int)); - objectPtr->export.oidlen = objectPtr->nodePtr->oidlen = 1; - objectPtr->nodePtr->oid[0] = 0; - objectPtr->export.nodekind = SMI_NODEKIND_NODE; - objectPtr = addObject(smiStrdup("iso"), smiHandle->rootNodePtr, 1, 0, &parser); - objectPtr->export.oid = objectPtr->nodePtr->oid = - smiMalloc(sizeof(int)); - objectPtr->export.oidlen = objectPtr->nodePtr->oidlen = 1; - objectPtr->nodePtr->oid[0] = 1; - objectPtr->export.nodekind = SMI_NODEKIND_NODE; - objectPtr = addObject(smiStrdup("joint-iso-ccitt"), smiHandle->rootNodePtr, 2, 0, &parser); - objectPtr->export.oid = objectPtr->nodePtr->oid = - smiMalloc(sizeof(int)); - objectPtr->export.oidlen = objectPtr->nodePtr->oidlen = 1; - objectPtr->nodePtr->oid[0] = 2; - objectPtr->export.nodekind = SMI_NODEKIND_NODE; - - - smiHandle->typeOctetStringPtr = - addType(smiStrdup("OctetString"), - SMI_BASETYPE_OCTETSTRING, 0, &parser); - smiHandle->typeObjectIdentifierPtr = - addType(smiStrdup("ObjectIdentifier"), - SMI_BASETYPE_OBJECTIDENTIFIER, 0, &parser); - smiHandle->typeInteger32Ptr = - addType(smiStrdup("Integer32"), - SMI_BASETYPE_INTEGER32, 0, &parser); - smiHandle->typeUnsigned32Ptr = - addType(smiStrdup("Unsigned32"), - SMI_BASETYPE_UNSIGNED32, 0, &parser); - smiHandle->typeInteger64Ptr = - addType(smiStrdup("Integer64"), - SMI_BASETYPE_INTEGER64, 0, &parser); - smiHandle->typeUnsigned64Ptr = - addType(smiStrdup("Unsigned64"), - SMI_BASETYPE_UNSIGNED64, 0, &parser); - smiHandle->typeFloat32Ptr = - addType(smiStrdup("Float32"), - SMI_BASETYPE_FLOAT32, 0, &parser); - smiHandle->typeFloat64Ptr = - addType(smiStrdup("Float64"), - SMI_BASETYPE_FLOAT64, 0, &parser); - smiHandle->typeFloat128Ptr = - addType(smiStrdup("Float128"), - SMI_BASETYPE_FLOAT128, 0, &parser); - smiHandle->typeEnumPtr = - addType(smiStrdup("Enumeration"), - SMI_BASETYPE_ENUM, 0, &parser); - smiHandle->typeBitsPtr = - addType(smiStrdup("Bits"), - SMI_BASETYPE_BITS, 0, &parser); - smiHandle->typePointerPtr = - addType(smiStrdup("Pointer"), - SMI_BASETYPE_POINTER, 0, &parser); - - return (0); -} - - - -/* - *---------------------------------------------------------------------- - * - * freeNodeTree -- - * - * Free all node of a node (sub)tree. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static void freeNodeTree(Node *rootPtr) -{ - Node *nodePtr, *nextPtr; - - for (nodePtr = rootPtr->firstChildPtr; nodePtr; nodePtr = nextPtr) { - nextPtr = nodePtr->nextPtr; - freeNodeTree(nodePtr); - smiFree(nodePtr->oid); - smiFree(nodePtr); - } - rootPtr->firstChildPtr = NULL; - rootPtr->lastChildPtr = NULL; - rootPtr->firstObjectPtr = NULL; - rootPtr->lastObjectPtr = NULL; - rootPtr->nextPtr = NULL; - rootPtr->prevPtr = NULL; - rootPtr->parentPtr = NULL; -} - - - -/* - *---------------------------------------------------------------------- - * - * smiFreeData -- - * - * Free all data structures. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void smiFreeData() -{ - View *viewPtr, *nextViewPtr; - Macro *macroPtr, *nextMacroPtr; - Module *modulePtr, *nextModulePtr; - Import *importPtr, *nextImportPtr; - Identity *identityPtr, *nextIdentityPtr; - Revision *revisionPtr, *nextRevisionPtr; - List *listPtr, *nextListPtr; - Type *typePtr, *nextTypePtr; - Class *classPtr, *nextClassPtr; - Attribute *attributePtr, *nextAttributePtr; - Event *eventPtr, *nextEventPtr; - Object *objectPtr, *nextObjectPtr; - - for (viewPtr = smiHandle->firstViewPtr; viewPtr; viewPtr = nextViewPtr) { - nextViewPtr = viewPtr->nextPtr; - smiFree(viewPtr->name); - smiFree(viewPtr); - } - - /* - * In this first module loop we remove each module's imports, - * revisions, macros, and objects. - */ - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = nextModulePtr) { - nextModulePtr = modulePtr->nextPtr; - - for (importPtr = modulePtr->firstImportPtr; importPtr; - importPtr = nextImportPtr) { - nextImportPtr = importPtr->nextPtr; - smiFree(importPtr->export.module); - smiFree(importPtr->export.name); - smiFree(importPtr); - } - - for (revisionPtr = modulePtr->firstRevisionPtr; revisionPtr; - revisionPtr = nextRevisionPtr) { - nextRevisionPtr = revisionPtr->nextPtr; - smiFree(revisionPtr->export.description); - smiFree(revisionPtr); - } - - for (macroPtr = modulePtr->firstMacroPtr; macroPtr; - macroPtr = nextMacroPtr) { - nextMacroPtr = macroPtr->nextPtr; - smiFree(macroPtr->export.name); - smiFree(macroPtr->export.abnf); - smiFree(macroPtr->export.reference); - smiFree(macroPtr->export.description); - smiFree(macroPtr); - - } - for (identityPtr = modulePtr->firstIdentityPtr; identityPtr; - identityPtr = nextIdentityPtr) { - nextIdentityPtr = identityPtr->nextPtr; - smiFree(identityPtr->export.name); - smiFree(identityPtr->export.reference); - smiFree(identityPtr->export.description); - smiFree(identityPtr); - } - - for (objectPtr = modulePtr->firstObjectPtr; objectPtr; - objectPtr = nextObjectPtr) { - - nextObjectPtr = objectPtr->nextPtr; - smiFree(objectPtr->export.name); - smiFree(objectPtr->export.description); - smiFree(objectPtr->export.reference); - smiFree(objectPtr->export.format); - smiFree(objectPtr->export.units); - for (listPtr = objectPtr->listPtr; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - smiFree(listPtr); - } - for (listPtr = objectPtr->optionlistPtr; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - smiFree(((Option *)(listPtr->ptr))->export.description); - smiFree((Option *)(listPtr->ptr)); - smiFree(listPtr); - } - for (listPtr = objectPtr->refinementlistPtr; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - smiFree(((Refinement *)(listPtr->ptr))->export.description); - smiFree((Refinement *)(listPtr->ptr)); - smiFree(listPtr); - } - if (objectPtr->typePtr) { - if ((objectPtr->typePtr->export.basetype == - SMI_BASETYPE_OCTETSTRING || - objectPtr->typePtr->export.basetype == - SMI_BASETYPE_BITS)) { - smiFree(objectPtr->export.value.value.ptr); - } else if ((objectPtr->typePtr->export.basetype == - SMI_BASETYPE_OBJECTIDENTIFIER) && - (objectPtr->export.value.basetype == - objectPtr->typePtr->export.basetype)) { - smiFree(objectPtr->export.value.value.oid); - } - - } - smiFree(objectPtr); - - - - - } - - - for (classPtr = modulePtr->firstClassPtr; classPtr; - classPtr = nextClassPtr) { - - nextClassPtr = classPtr->nextPtr; - for (attributePtr = classPtr->firstAttributePtr; attributePtr; - attributePtr = nextAttributePtr) { - - nextAttributePtr = attributePtr->nextPtr; - - for (listPtr = attributePtr->listPtr; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - if ((attributePtr->export.basetype == SMI_BASETYPE_BITS) || - (attributePtr->export.basetype == SMI_BASETYPE_ENUM)) { - smiFree(((NamedNumber *)(listPtr->ptr))->export.name); - smiFree((NamedNumber *)(listPtr->ptr)); - } else if ((attributePtr->export.basetype == SMI_BASETYPE_INTEGER32) || - (attributePtr->export.basetype == SMI_BASETYPE_INTEGER64) || - (attributePtr->export.basetype == SMI_BASETYPE_UNSIGNED32) || - (attributePtr->export.basetype == SMI_BASETYPE_UNSIGNED64) || - (attributePtr->export.basetype == SMI_BASETYPE_FLOAT32) || - (attributePtr->export.basetype == SMI_BASETYPE_FLOAT64) || - (attributePtr->export.basetype == SMI_BASETYPE_FLOAT128) || - (attributePtr->export.basetype == SMI_BASETYPE_OCTETSTRING)) { - smiFree((Range *)(listPtr->ptr)); - } - smiFree(listPtr); - } - smiFree(attributePtr->export.name); - smiFree(attributePtr->export.format); - smiFree(attributePtr->export.units); - smiFree(attributePtr->export.description); - smiFree(attributePtr->export.reference); - smiFree(attributePtr); - - } - - for (eventPtr = classPtr->firstEventPtr; eventPtr; - eventPtr = nextEventPtr) { - - nextEventPtr = eventPtr->nextPtr; - smiFree(eventPtr->export.name); - smiFree(eventPtr->export.reference); - smiFree(eventPtr->export.description); - } - - - for (listPtr = classPtr->uniqueList; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - smiFree(listPtr); - } - - smiFree(classPtr->export.name); - smiFree(classPtr->export.description); - smiFree(classPtr->export.reference); - smiFree(classPtr); - - } - } - - /* - * In this second module loop we remove each module's types - * and the modules themselves. This separation is required, because - * we reference some types of foreign modules in the first loop. - */ - for (modulePtr = smiHandle->firstModulePtr; modulePtr; - modulePtr = nextModulePtr) { - nextModulePtr = modulePtr->nextPtr; - - for (typePtr = modulePtr->firstTypePtr; typePtr; - typePtr = nextTypePtr) { - nextTypePtr = typePtr->nextPtr; - for (listPtr = typePtr->listPtr; listPtr; - listPtr = nextListPtr) { - nextListPtr = listPtr->nextPtr; - if ((typePtr->export.basetype == SMI_BASETYPE_BITS) || - (typePtr->export.basetype == SMI_BASETYPE_ENUM)) { - smiFree(((NamedNumber *)(listPtr->ptr))->export.name); - smiFree((NamedNumber *)(listPtr->ptr)); - } else if ((typePtr->export.basetype == SMI_BASETYPE_INTEGER32) || - (typePtr->export.basetype == SMI_BASETYPE_INTEGER64) || - (typePtr->export.basetype == SMI_BASETYPE_UNSIGNED32) || - (typePtr->export.basetype == SMI_BASETYPE_UNSIGNED64) || - (typePtr->export.basetype == SMI_BASETYPE_FLOAT32) || - (typePtr->export.basetype == SMI_BASETYPE_FLOAT64) || - (typePtr->export.basetype == SMI_BASETYPE_FLOAT128) || - (typePtr->export.basetype == SMI_BASETYPE_OCTETSTRING)) { - smiFree((Range *)(listPtr->ptr)); - } - smiFree(listPtr); - } - smiFree(typePtr->export.name); - smiFree(typePtr->export.format); - smiFree(typePtr->export.units); - smiFree(typePtr->export.description); - smiFree(typePtr->export.reference); - smiFree(typePtr); - } - - smiFree(modulePtr->export.name); - smiFree(modulePtr->export.path); - smiFree(modulePtr->export.organization); - smiFree(modulePtr->export.contactinfo); - smiFree(modulePtr->export.description); - smiFree(modulePtr->export.reference); - smiFree(modulePtr); - } - - freeNodeTree(smiHandle->rootNodePtr); - smiFree(smiHandle->rootNodePtr); - - return; -} - - - -/* - *---------------------------------------------------------------------- - * - * loadModule -- - * - * Load a MIB module. If modulename is a plain name, the file is - * search along the SMIPATH environment variable. If modulename - * contains a `.' or DIR_SEPARATOR it is assumed to be the path. - * - * Results: - * 0 on success or -1 on an error. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -Module *loadModule(const char *modulename, Parser *parserPtr) -{ - Parser parser; - Parser *parentParserPtr; - char *path = NULL, *dir, *smipath; - int sming = 0; - int c, i; - FILE *file; - char sep[2]; - - static const char *ext[] = { - "", ".my", ".smiv1", ".smiv2", ".sming", ".mib", ".txt", NULL - }; - - if ((!modulename) || !strlen(modulename)) { - return NULL; - } - - if (!smiIsPath(modulename)) { - /* - * A plain modulename. Lookup the path along SMIPATH... - */ - if (!smiHandle->path) { - return NULL; - } - - smipath = smiStrdup(smiHandle->path); - sep[0] = PATH_SEPARATOR; sep[1] = 0; - for (dir = strtok(smipath, sep); - dir; dir = strtok(NULL, sep)) { - for (i = 0; ext[i]; i++) { - smiAsprintf(&path, "%s%c%s%s", dir, DIR_SEPARATOR, - modulename, ext[i]); - if (! access(path, R_OK)) { - break; - } - smiFree(path); - } - if (ext[i]) break; - { - char *newmodulename = smiStrdup(modulename); - for (i = 0; newmodulename[i]; i++) { - newmodulename[i] = tolower(newmodulename[i]); - } - for (i = 0; ext[i]; i++) { - smiAsprintf(&path, "%s%c%s%s", dir, DIR_SEPARATOR, - newmodulename, ext[i]); - if (! access(path, R_OK)) { - break; - } - smiFree(path); - } - smiFree(newmodulename); - if (ext[i]) break; - } - - path = NULL; - } - smiFree(smipath); - } else { - /* - * A full path. Take it. - */ - path = smiStrdup(modulename); - } - -#if !defined(_MSC_VER) && !defined(__MINGW32__) - if (!path && smiHandle->cache && smiHandle->cacheProg) { - /* Not found in the path; now try to fetch & cache the module. */ - int pid; - char *argv[4]; - char *cmd; - int status; - smiAsprintf(&path, "%s%c%s", - smiHandle->cache, DIR_SEPARATOR, modulename); - if (access(path, R_OK)) { - smiAsprintf(&cmd, "%s %s", smiHandle->cacheProg, modulename); - pid = fork(); - if (pid != -1) { - if (!pid) { - argv[0] = "sh"; argv[1] = "-c"; argv[2] = cmd; argv[3] = 0; - execv("/bin/sh", argv); - exit(127); - } - waitpid(pid, &status, 0); - } - smiFree(cmd); - if (access(path, R_OK)) { - smiFree(path); - path = NULL; - } - } - } -#endif - - if (!path) { - smiPrintError(parserPtr, ERR_MODULE_NOT_FOUND, modulename); - return NULL; - } - - parser.path = path; - - /* - * Look into the file to determine whether it contains - * SMIv1/SMIv2 or SMIng definitions. - */ - - file = fopen(path, "r"); - if (! file) { - smiPrintError(parserPtr, ERR_OPENING_INPUTFILE, path, strerror(errno)); - smiFree(path); - return NULL; - } - while ((c = fgetc(file))) { - if (c == '-' || isupper(c)) { - sming = 0; - break; - } else if (c == '/' || c == 'm') { - sming = 1; - break; - } else if (c == EOF || ! isspace(c)) { - smiPrintError(parserPtr, ERR_ILLEGAL_INPUTFILE, path); - smiFree(path); - fclose(file); - return NULL; - } - } - rewind(file); - - - if (sming == 0) { -#ifdef BACKEND_SMI - parentParserPtr = smiHandle->parserPtr; - smiHandle->parserPtr = &parser; - parser.path = path; - parser.flags = smiHandle->flags; - parser.modulePtr = NULL; - parser.complianceModulePtr = NULL; - parser.capabilitiesModulePtr = NULL; - parser.currentDecl = SMI_DECL_UNKNOWN; - parser.firstStatementLine = 0; - parser.firstNestedStatementLine = 0; - parser.firstRevisionLine = 0; - parser.file = file; - - /* - * Initialize a root Node for pending (forward referenced) nodes. - */ - parser.pendingNodePtr = addNode(NULL, 0, NODE_FLAG_ROOT, NULL); - - if (smiEnterLexRecursion(parser.file) < 0) { - smiPrintError(&parser, ERR_MAX_LEX_DEPTH); - fclose(parser.file); - } - smiDepth++; - parser.line = 1; - smiparse((void *)&parser); - freeNodeTree(parser.pendingNodePtr); - smiFree(parser.pendingNodePtr); - smiLeaveLexRecursion(); - smiDepth--; - fclose(parser.file); - smiFree(path); - smiHandle->parserPtr = parentParserPtr; - return parser.modulePtr; -#else - smiPrintError(parserPtr, ERR_SMI_NOT_SUPPORTED, path); - smiFree(path); - fclose(file); - return NULL; -#endif - } - - if (sming == 1) { -#ifdef BACKEND_SMING - parentParserPtr = smiHandle->parserPtr; - smiHandle->parserPtr = &parser; - parser.path = path; - parser.flags = smiHandle->flags; - parser.modulePtr = NULL; - parser.complianceModulePtr = NULL; - parser.capabilitiesModulePtr = NULL; - parser.currentDecl = SMI_DECL_UNKNOWN; - parser.firstStatementLine = 0; - parser.firstNestedStatementLine = 0; - parser.firstRevisionLine = 0; - parser.file = file; - - /* - * Initialize a root Node for pending (forward referenced) nodes. - */ - parser.pendingNodePtr = addNode(NULL, 0, NODE_FLAG_ROOT, NULL); - - if (smingEnterLexRecursion(parser.file) < 0) { - smiPrintError(&parser, ERR_MAX_LEX_DEPTH); - fclose(parser.file); - } - smiDepth++; - parser.line = 1; - smingparse((void *)&parser); - freeNodeTree(parser.pendingNodePtr); - smiFree(parser.pendingNodePtr); - smingLeaveLexRecursion(); - smiDepth--; - fclose(parser.file); - smiFree(path); - smiHandle->parserPtr = parentParserPtr; - return parser.modulePtr; -#else - smiPrintError(parserPtr, ERR_SMING_NOT_SUPPORTED, path); - smiFree(path); - fclose(file); - return NULL; -#endif - } - - smiFree(path); - fclose(file); - return NULL; -} diff --git a/lib/smi.c b/lib/smi.c index d6a8ebe..244629e 100644 --- a/lib/smi.c +++ b/lib/smi.c @@ -1314,15 +1314,10 @@ SmiNode *smiGetNode(SmiModule *smiModulePtr, const char *node) } if (isdigit((int)node2[0])) { - for (oidlen = 0, p = strtok(node2, ". "); - p && oidlen < sizeof(oid)/sizeof(oid[0]); + for (oidlen = 0, p = strtok(node2, ". "); p; oidlen++, p = strtok(NULL, ". ")) { oid[oidlen] = strtoul(p, NULL, 0); } - if (p) { - /* the numeric OID is too long */ - return NULL; - } nodePtr = getNode(oidlen, oid); if (nodePtr) { if (modulePtr) { diff --git a/lib/smi.c.CVE-2010-2891 b/lib/smi.c.CVE-2010-2891 deleted file mode 100644 index 244629e..0000000 --- a/lib/smi.c.CVE-2010-2891 +++ /dev/null @@ -1,2667 +0,0 @@ -/* - * smi.c -- - * - * Interface Implementation of libsmi. - * - * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig. - * - * See the file "COPYING" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * @(#) $Id: smi.c 8071 2008-04-17 11:14:46Z schoenw $ - */ - -#include - -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif - -#include "smi.h" -#include "data.h" -#include "error.h" -#include "util.h" -#include "snprintf.h" - -#ifdef BACKEND_SMI -#include "scanner-smi.h" -#include "parser-smi.h" -#endif - -#ifdef BACKEND_SMING -#include "scanner-sming.h" -#include "parser-sming.h" -#endif - -#ifdef HAVE_DMALLOC_H -#include -#endif - - - -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) < (b) ? (b) : (a)) -#endif - - - -const char *smi_library_version = SMI_LIBRARY_VERSION; -const char *smi_version_string = SMI_VERSION_STRING; - -Handle *smiHandle = NULL; - - - -/* - * Internal functions. - */ - -static void getModulenameAndName(const char *arg1, const char *arg2, - char **module, char **name) -{ - char *p; - int l; - - if ((!arg1) && (!arg2)) { - *module = NULL; - *name = NULL; - } else if (!arg2) { - if (isupper((int)arg1[0])) { - if ((p = strstr(arg1, "::"))) { - /* SMIng style module/label separator */ - *name = smiStrdup(&p[2]); - l = strcspn(arg1, "::"); - *module = smiStrndup(arg1, l); - } else if ((p = strchr(arg1, '!'))) { - /* old scotty style module/label separator */ - *name = smiStrdup(&p[1]); - l = strcspn(arg1, "!"); - *module = smiStrndup(arg1, l); - } else if ((p = strchr(arg1, '.'))) { - /* SMIv1/v2 style module/label separator */ - *name = smiStrdup(&p[1]); - l = strcspn(arg1, "."); - *module = smiStrndup(arg1, l); - } else { - *name = smiStrdup(arg1); - *module = smiStrdup(""); - } - } else { - *name = smiStrdup(arg1); - *module = smiStrdup(""); - } - } else if (!arg1) { - if (isupper((int)arg2[0])) { - if ((p = strstr(arg2, "::"))) { - /* SMIng style module/label separator */ - *name = smiStrdup(&p[2]); - l = strcspn(arg2, "::"); - *module = smiStrndup(arg2, l); - } else if ((p = strchr(arg2, '!'))) { - /* old scotty style module/label separator */ - *name = smiStrdup(&p[1]); - l = strcspn(arg2, "!"); - *module = smiStrndup(arg2, l); - } else if ((p = strchr(arg2, '.'))) { - /* SMIv1/v2 style module/label separator */ - *name = smiStrdup(&p[1]); - l = strcspn(arg2, "."); - *module = smiStrndup(arg2, l); - } else { - *name = smiStrdup(arg2); - *module = smiStrdup(""); - } - } else { - *name = smiStrdup(arg2); - *module = smiStrdup(""); - } - } else { - *module = smiStrdup(arg1); - *name = smiStrdup(arg2); - } -} - - - -static Node *getNode(unsigned int oidlen, SmiSubid oid[]) -{ - Node *nodePtr, *parentPtr; - unsigned int i; - - for(nodePtr = smiHandle->rootNodePtr, i=0; i < oidlen; i++) { - parentPtr = nodePtr; - nodePtr = findNodeByParentAndSubid(parentPtr, oid[i]); - if (!nodePtr) { - return parentPtr; - } - } - - return nodePtr; -} - - - -static Object *getNextChildObject(Node *startNodePtr, Module *modulePtr, - SmiNodekind nodekind) -{ - Node *nodePtr; - Object *objectPtr = NULL; - - if (!startNodePtr || !modulePtr) - return NULL; - - for (nodePtr = startNodePtr; nodePtr; nodePtr = nodePtr->nextPtr) { - for (objectPtr = nodePtr->firstObjectPtr; objectPtr; - objectPtr = objectPtr->nextSameNodePtr) { - if (((!modulePtr) || (objectPtr->modulePtr == modulePtr)) && - ((nodekind == SMI_NODEKIND_ANY) || - (nodekind & objectPtr->export.nodekind))) { - break; - } - } - if (objectPtr) break; - objectPtr = getNextChildObject(nodePtr->firstChildPtr, - modulePtr, nodekind); - if (objectPtr) break; - } - - return objectPtr; -} - - - -/* - * Interface Functions. - */ - -int smiInit(const char *tag) -{ - char *p, *pp, *tag2; -#ifdef HAVE_PWD_H - struct passwd *pw; -#endif - - smiHandle = findHandleByName(tag); - if (smiHandle) { - return 0; - } - smiHandle = addHandle(tag); - - smiDepth = 0; - - smiHandle->errorLevel = DEFAULT_ERRORLEVEL; - smiHandle->errorHandler = smiErrorHandler; -#if !defined(_MSC_VER) - smiHandle->cache = NULL; - smiHandle->cacheProg = NULL; -#endif - - if (smiInitData()) { - return -1; - } - - /* - * Setup the SMI MIB module search path: - * 1. set to builtin DEFAULT_SMIPATH - * 2. read global config file if present (append/prepend/replace) - * 3. read user config file if present (append/prepend/replace) - * 4. evaluate SMIPATH env-var if set (append/prepend/replace) - */ - - /* 1. set to builtin DEFAULT_SMIPATH */ - smiHandle->path = smiStrdup(DEFAULT_SMIPATH); - - tag2 = smiStrdup(tag); - if (tag2) tag2 = strtok(tag2, ":"); - if (tag2) { - /* 2. read global config file if present (append/prepend/replace) */ - smiReadConfig(DEFAULT_GLOBALCONFIG, tag2); -#ifdef HAVE_PWD_H - pw = getpwuid(getuid()); - if (pw && pw->pw_dir) { - /* 3. read user config file if present (append/prepend/replace) */ - smiAsprintf(&p, "%s%c%s", - pw->pw_dir, DIR_SEPARATOR, DEFAULT_USERCONFIG); - smiReadConfig(p, tag2); - smiFree(p); - } -#endif - } - smiFree(tag2); - - /* 4. evaluate SMIPATH env-var if set (append/prepend/replace) */ - p = getenv("SMIPATH"); - if (p) { - if (p[0] == PATH_SEPARATOR) { - smiAsprintf(&pp, "%s%s", smiHandle->path, p); - smiFree(smiHandle->path); - smiHandle->path = pp; - } else if (p[strlen(p)-1] == PATH_SEPARATOR) { - smiAsprintf(&pp, "%s%s", p, smiHandle->path); - smiFree(smiHandle->path); - smiHandle->path = pp; - } else { - smiHandle->path = smiStrdup(p); - } - } - - if (!smiHandle->path) { - return -1; - } - - return 0; -} - - - -void smiExit() -{ - if (!smiHandle) - return; - - smiFreeData(); - - smiFree(smiHandle->path); -#if !defined(_MSC_VER) - smiFree(smiHandle->cache); - smiFree(smiHandle->cacheProg); -#endif - - removeHandle(smiHandle); - - smiHandle = NULL; - return; -} - - - -char *smiGetPath() -{ - if (smiHandle->path) { - return smiStrdup(smiHandle->path); - } else { - return NULL; - } -} - - - -int smiSetPath(const char *s) -{ - char *s2; - - if (!smiHandle) smiInit(NULL); - - if (!s) { - smiFree(smiHandle->path); - smiHandle->path = NULL; - return 0; - } - - s2 = smiStrdup(s); - if (s2) { - smiFree(smiHandle->path); - smiHandle->path = s2; - return 0; - } else { - return -1; - } - -} - - - -void smiSetSeverity(char *pattern, int severity) -{ - smiSetErrorSeverity(pattern, severity); -} - - - -int smiReadConfig(const char *filename, const char *tag) -{ - FILE *file; - char buf[201]; - char *cmd, *arg, *s; - - file = fopen(filename, "r"); - if (file) { - while (!feof(file)) { - if (!fgets(buf, 200, file)) continue; - if ((!strlen(buf)) || (buf[0] == '#')) continue; - cmd = strtok(buf, " \t\n\r"); - if (!cmd) continue; - if (cmd[0] == '#') continue; - if (cmd[strlen(cmd)-1] == ':') { - if (!tag) continue; - cmd[strlen(cmd)-1] = 0; - if (strcmp(cmd, tag)) continue; - cmd = strtok(NULL, " \t\n\r"); - } - arg = strtok(NULL, " \t\n\r"); - if (!strcmp(cmd, "load")) { - smiLoadModule(arg); - } else if (!strcmp(cmd, "path")) { - if (arg) { - if (arg[0] == PATH_SEPARATOR) { - smiAsprintf(&s, "%s%s", smiHandle->path, arg); - smiFree(smiHandle->path); - smiHandle->path = s; - } else if (arg[strlen(arg)-1] == PATH_SEPARATOR) { - smiAsprintf(&s, "%s%s", arg, smiHandle->path); - smiFree(smiHandle->path); - smiHandle->path = s; - } else { - smiHandle->path = smiStrdup(arg); - } - } - } else if (!strcmp(cmd, "cache")) { -#if !defined(_MSC_VER) - smiFree(smiHandle->cache); - smiFree(smiHandle->cacheProg); -#endif - if (arg && strcmp(arg, "off")) { -#if !defined(_MSC_VER) - smiHandle->cache = smiStrdup(arg); - arg = strtok(NULL, "\n\r"); - smiHandle->cacheProg = smiStrdup(arg); -#else - smiPrintError(NULL, ERR_CACHE_CONFIG_NOT_SUPPORTED, - filename); -#endif - } - } else if (!strcmp(cmd, "level")) { - smiSetErrorLevel(atoi(arg)); - } else if (!strcmp(cmd, "hide")) { - smiSetSeverity(arg, 9); - } else { - smiPrintError(NULL, ERR_UNKNOWN_CONFIG_CMD, cmd, filename); - } - } - fclose(file); - return 0; - } - return -1; -} - - - -int smiIsLoaded(const char *module) -{ - if (!module) - return 0; - - return isInView(module); -} - - - -char *smiLoadModule(const char *module) -{ - Module *modulePtr; - - if (!smiHandle) smiInit(NULL); - - if (smiIsPath(module)) { - - modulePtr = loadModule(module, NULL); - - if (modulePtr) { - if (!isInView(modulePtr->export.name)) { - addView(modulePtr->export.name); - } - return modulePtr->export.name; - } else { - return NULL; - } - - } else { - - if ((modulePtr = findModuleByName(module))) { - /* already loaded. */ - if (!isInView(module)) { - addView(module); - } - return modulePtr->export.name; - } else { - if ((modulePtr = loadModule(module, NULL))) { - if (!isInView(module)) { - addView(module); - } - return modulePtr->export.name; - } else { - return NULL; - } - } - } -} - - - -void smiSetErrorLevel(int level) -{ - if (!smiHandle) smiInit(NULL); - - smiHandle->errorLevel = level; -} - - - -void smiSetFlags(int userflags) -{ - if (!smiHandle) smiInit(NULL); - - smiHandle->flags = (smiHandle->flags & ~SMI_FLAG_MASK) | userflags; -} - - - -int smiGetFlags() -{ - if (!smiHandle) smiInit(NULL); - - return smiHandle->flags & SMI_FLAG_MASK; -} - - - -SmiModule *smiGetModule(const char *module) -{ - Module *modulePtr; - - if (!module) { - return NULL; - } - - modulePtr = findModuleByName(module); - - if (!modulePtr) { - modulePtr = loadModule(module, NULL); - } - - return &modulePtr->export; -} - - - -SmiModule *smiGetFirstModule() -{ - Module *modulePtr; - - for (modulePtr = smiHandle->firstModulePtr; - modulePtr && modulePtr->export.name && - (strlen(modulePtr->export.name) == 0); - modulePtr = modulePtr->nextPtr); - - return &modulePtr->export; -} - - - -SmiModule *smiGetNextModule(SmiModule *smiModulePtr) -{ - Module *modulePtr; - - if (!smiModulePtr) { - return NULL; - } - - - for (modulePtr = ((Module *)smiModulePtr)->nextPtr; - modulePtr && modulePtr->export.name && - (strlen(modulePtr->export.name) == 0); - modulePtr = modulePtr->nextPtr); - - return &modulePtr->export; -} - - - -SmiImport *smiGetFirstImport(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return &((Module *)smiModulePtr)->firstImportPtr->export; -} - - - -SmiImport *smiGetNextImport(SmiImport *smiImportPtr) -{ - if (!smiImportPtr) { - return NULL; - } - - return &((Import *)smiImportPtr)->nextPtr->export; -} - - - -int smiIsImported(SmiModule *smiModulePtr, - SmiModule *importedModulePtr, - char *importedName) -{ - Import *importPtr; - Module *modulePtr; - char *importedModule; - - if ((!smiModulePtr) || (!importedName)) { - return 0; - } - - modulePtr = (Module *)smiModulePtr; - - if (importedModulePtr) { - importedModule = importedModulePtr->name; - } else { - importedModule = NULL; - } - - for (importPtr = modulePtr->firstImportPtr; importPtr; - importPtr = importPtr->nextPtr) { - if ((!strcmp(importedName, importPtr->export.name)) && - ((!importedModule) || - (!strcmp(importedModule, importPtr->export.module)))) { - return 1; - } - } - - return 0; -} - - - -SmiRevision *smiGetFirstRevision(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return &((Module *)smiModulePtr)->firstRevisionPtr->export; -} - - - -SmiRevision *smiGetNextRevision(SmiRevision *smiRevisionPtr) -{ - if (!smiRevisionPtr) { - return NULL; - } - - return &((Revision *)smiRevisionPtr)->nextPtr->export; -} - - - -int smiGetRevisionLine(SmiRevision *smiRevisionPtr) -{ - return ((Revision *)smiRevisionPtr)->line; -} - - - -SmiType *smiGetType(SmiModule *smiModulePtr, char *type) -{ - Type *typePtr = NULL; - Module *modulePtr = NULL; - char *module2, *type2; - - if (!type) { - return NULL; - } - - modulePtr = (Module *)smiModulePtr; - - getModulenameAndName(smiModulePtr ? smiModulePtr->name : NULL, type, - &module2, &type2); - - if (!modulePtr && module2 && strlen(module2)) { - if (!(modulePtr = findModuleByName(module2))) { - modulePtr = loadModule(module2, NULL); - } - } - - if (modulePtr) { - typePtr = findTypeByModuleAndName(modulePtr, type2); - } else { - typePtr = findTypeByName(type2); - } - - smiFree(module2); - smiFree(type2); - - if (!typePtr || - typePtr->export.basetype == SMI_BASETYPE_UNKNOWN) { - return NULL; - } - - return &typePtr->export; -} - - - -SmiType *smiGetFirstType(SmiModule *smiModulePtr) -{ - Type *typePtr; - - if (!smiModulePtr) { - return NULL; - } - - for (typePtr = ((Module *)smiModulePtr)->firstTypePtr; typePtr; - typePtr = typePtr->nextPtr) { - /* loop until we found a `real' type */ - if (typePtr->export.name && - typePtr->export.basetype != SMI_BASETYPE_UNKNOWN) { - break; - } - } - - return &typePtr->export; -} - - - -SmiType *smiGetNextType(SmiType *smiTypePtr) -{ - Type *typePtr; - - if (!smiTypePtr) { - return NULL; - } - - for (typePtr = ((Type *)smiTypePtr)->nextPtr; typePtr; - typePtr = typePtr->nextPtr) { - /* loop until we found a `real' type */ - if (typePtr->export.name && - typePtr->export.basetype != SMI_BASETYPE_UNKNOWN) { - break; - } - } - - return &typePtr->export; -} - - -SmiType *smiGetParentType(SmiType *smiTypePtr) -{ - Type *typePtr; - - if (!smiTypePtr) { - return NULL; - } - - typePtr = ((Type *)smiTypePtr)->parentPtr; - - if (!typePtr || - typePtr->export.basetype == SMI_BASETYPE_UNKNOWN) { - return NULL; - } - - return &typePtr->export; -} - - - -SmiModule *smiGetTypeModule(SmiType *smiTypePtr) -{ - return &((Type *)smiTypePtr)->modulePtr->export; -} - -int smiGetTypeLine(SmiType *smiTypePtr) -{ - return ((Type *)smiTypePtr)->line; -} - - - -SmiNamedNumber *smiGetFirstNamedNumber(SmiType *smiTypePtr) -{ - Type *typePtr; - - typePtr = (Type *)smiTypePtr; - - if ((!typePtr) || (!typePtr->listPtr) || - ((typePtr->export.basetype != SMI_BASETYPE_ENUM) && - (typePtr->export.basetype != SMI_BASETYPE_BITS) && - (typePtr->export.basetype != SMI_BASETYPE_POINTER))) { - return NULL; - } - - return &((NamedNumber *)typePtr->listPtr->ptr)->export; -} - - - -SmiNamedNumber *smiGetNextNamedNumber(SmiNamedNumber *smiNamedNumberPtr) -{ - Type *typePtr; - List *listPtr; - - if (!smiNamedNumberPtr) { - return NULL; - } - - typePtr = ((NamedNumber *)smiNamedNumberPtr)->typePtr; - - - if ((!typePtr) || (!typePtr->listPtr) || - ((typePtr->export.basetype != SMI_BASETYPE_ENUM) && - (typePtr->export.basetype != SMI_BASETYPE_BITS))) { - return NULL; - } - - for (listPtr = typePtr->listPtr; listPtr; listPtr = listPtr->nextPtr) { - if (((NamedNumber *)(listPtr->ptr))->export.name == - smiNamedNumberPtr->name) - break; - } - - if ((!listPtr) || (!listPtr->nextPtr)) { - return NULL; - } - - return &((NamedNumber *)listPtr->nextPtr->ptr)->export; -} - -SmiNamedNumber *smiGetAttributeFirstNamedNumber(SmiAttribute *smiAttributePtr) -{ - Attribute *attributePtr; - - attributePtr = (Attribute *)smiAttributePtr; - - if ((!attributePtr) || (!attributePtr->listPtr) || - ((attributePtr->export.basetype != SMI_BASETYPE_ENUM) && - (attributePtr->export.basetype != SMI_BASETYPE_BITS) && - (attributePtr->export.basetype != SMI_BASETYPE_POINTER))) { - return NULL; - } - - return &((NamedNumber *)attributePtr->listPtr->ptr)->export; -} - - - -SmiNamedNumber *smiGetAttributeNextNamedNumber(SmiNamedNumber *smiNamedNumberPtr) -{ - Attribute *attributePtr; - List *listPtr; - - if (!smiNamedNumberPtr) { - return NULL; - } - - attributePtr = (Attribute*)(((NamedNumber *)smiNamedNumberPtr)->typePtr); - - - if ((!attributePtr) || (!attributePtr->listPtr) || - ((attributePtr->export.basetype != SMI_BASETYPE_ENUM) && - (attributePtr->export.basetype != SMI_BASETYPE_BITS))) { - return NULL; - } - - for (listPtr = attributePtr->listPtr; listPtr; listPtr = listPtr->nextPtr) { - if (((NamedNumber *)(listPtr->ptr))->export.name == - smiNamedNumberPtr->name) - break; - } - - if ((!listPtr) || (!listPtr->nextPtr)) { - return NULL; - } - - return &((NamedNumber *)listPtr->nextPtr->ptr)->export; -} - -SmiRange *smiGetFirstRange(SmiType *smiTypePtr) -{ - Type *typePtr; - - typePtr = (Type *)smiTypePtr; - - if ((!typePtr) || (!typePtr->listPtr) || - (typePtr->export.basetype == SMI_BASETYPE_ENUM) || - (typePtr->export.basetype == SMI_BASETYPE_BITS)) { - return NULL; - } - - return &((Range *)typePtr->listPtr->ptr)->export; -} - - - -SmiRange *smiGetNextRange(SmiRange *smiRangePtr) -{ - Type *typePtr; - List *listPtr; - - if (!smiRangePtr) { - return NULL; - } - - typePtr = ((Range *)smiRangePtr)->typePtr; - - if ((!typePtr) || (!typePtr->listPtr) || - (typePtr->export.basetype == SMI_BASETYPE_ENUM) || - (typePtr->export.basetype == SMI_BASETYPE_BITS)) { - return NULL; - } - - for (listPtr = typePtr->listPtr; listPtr; listPtr = listPtr->nextPtr) { - if (!memcmp(&((Range *)listPtr->ptr)->export.minValue, - &smiRangePtr->minValue, sizeof(struct SmiValue))) - break; - } - - if ((!listPtr) || (!listPtr->nextPtr)) { - return NULL; - } - - return &((Range *)listPtr->nextPtr->ptr)->export; -} - -SmiRange *smiGetAttributeFirstRange(SmiAttribute *smiAttributePtr) -{ - Attribute *attributePtr; - - attributePtr = (Attribute *)smiAttributePtr; - - if ((!attributePtr) || (!attributePtr->listPtr) || - (attributePtr->export.basetype == SMI_BASETYPE_ENUM) || - (attributePtr->export.basetype == SMI_BASETYPE_BITS)) { - return NULL; - } - - return &((Range *)attributePtr->listPtr->ptr)->export; -} - - - -SmiRange *smiGetAttributeNextRange(SmiRange *smiRangePtr) -{ - Attribute *attributePtr; - List *listPtr; - - if (!smiRangePtr) { - return NULL; - } - - attributePtr = (Attribute*)((Range *)smiRangePtr)->typePtr; - - if ((!attributePtr) || (!attributePtr->listPtr) || - (attributePtr->export.basetype == SMI_BASETYPE_ENUM) || - (attributePtr->export.basetype == SMI_BASETYPE_BITS)) { - return NULL; - } - - for (listPtr = attributePtr->listPtr; listPtr; listPtr = listPtr->nextPtr) { - if (!memcmp(&((Range *)listPtr->ptr)->export.minValue, - &smiRangePtr->minValue, sizeof(struct SmiValue))) - break; - } - - if ((!listPtr) || (!listPtr->nextPtr)) { - return NULL; - } - - return &((Range *)listPtr->nextPtr->ptr)->export; -} - - -SmiIdentity *smiGetFirstIdentity(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return ((Module *)smiModulePtr)->firstIdentityPtr ? - &((Module *)smiModulePtr)->firstIdentityPtr->export : NULL; - -} - -SmiIdentity *smiGetNextIdentity(SmiIdentity *smiIdentityPtr) -{ - if (!smiIdentityPtr) { - return NULL; - } - - return ((Identity *)smiIdentityPtr)->nextPtr ? - &((Identity *)smiIdentityPtr)->nextPtr->export : NULL; -} - -SmiModule *smiGetIdentityModule(SmiIdentity *smiIdentityPtr) -{ - return &((Identity *)smiIdentityPtr)->modulePtr->export; -} - -SmiIdentity *smiGetParentIdentity(SmiIdentity *smiIdentityPtr) -{ - return (SmiIdentity*)(((Identity *)smiIdentityPtr)->parentPtr); -} - -SmiIdentity *smiGetIdentity(SmiModule *smiModulePtr, char *identity) -{ - - if (!smiModulePtr) { - return NULL; - } - else - { - SmiIdentity *ide; - - for(ide = smiGetFirstIdentity(smiModulePtr); - ide; - ide = smiGetNextIdentity(ide)) - if(!strncmp(ide->name,identity,64))return ide; - - return NULL; - } - -} - -int smiGetIdentityLine(SmiIdentity *smiIdentityPtr) -{ - return ((Identity *)smiIdentityPtr)->line; -} - - -SmiClass *smiGetFirstClass(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return ((Module *)smiModulePtr)->firstClassPtr ? - &((Module *)smiModulePtr)->firstClassPtr->export : NULL; - -} - -SmiClass *smiGetNextClass(SmiClass *smiClassPtr) -{ - if (!smiClassPtr) { - return NULL; - } - - return ((Class *)smiClassPtr)->nextPtr ? - &((Class *)smiClassPtr)->nextPtr->export : NULL; -} - -SmiModule *smiGetClassModule(SmiClass *smiClassPtr) -{ - return &((Class *)smiClassPtr)->modulePtr->export; -} - -SmiClass *smiGetParentClass(SmiClass *smiClassPtr) -{ - return (SmiClass*)(((Class *)smiClassPtr)->parentPtr); -} - -SmiClass *smiGetClass(SmiModule *smiModulePtr, char *class) -{ - - if (!smiModulePtr) { - return NULL; - } - else - { - SmiClass *cl; - - for(cl = smiGetFirstClass(smiModulePtr); - cl; - cl = smiGetNextClass(cl)) - if(!strncmp(cl->name,class,64))return cl; - - return NULL; - } - -} - -int smiGetClassLine(SmiClass *smiClassPtr) -{ - return ((Class *)smiClassPtr)->line; -} - -SmiAttribute *smiGetFirstAttribute(SmiClass *smiClassPtr) -{ - Attribute *attributePtr; - - if (!smiClassPtr) { - return NULL; - } - - attributePtr = ((Class *)smiClassPtr)->firstAttributePtr; - - return &attributePtr->export; -} - - SmiAttribute *smiGetNextAttribute( SmiAttribute *smiTypePtr) -{ - Attribute *attributePtr; - - if (!smiTypePtr) { - return NULL; - } - - attributePtr = ((Attribute *)smiTypePtr)->nextPtr; - - return &attributePtr->export; -} - -SmiAttribute *smiGetAttribute(SmiClass *smiClassPtr, char *attribute) -{ - Attribute *attributePtr; - - if (! smiClassPtr) { - return NULL; - } - - attributePtr = ((Class *)smiClassPtr)->firstAttributePtr; - - for (attributePtr = ((Class *)smiClassPtr)->firstAttributePtr; - attributePtr; attributePtr = attributePtr->nextPtr) - { - if (!strncmp(attributePtr->export.name, attribute,64)) { - return &attributePtr->export; - } - } - - /* - * attribute might belong to the parent so check parent if - * attribute not found - */ - - smiClassPtr = smiGetParentClass(smiClassPtr); - attributePtr = (Attribute*)smiGetAttribute(smiClassPtr , attribute); - - return &attributePtr->export; -} - -SmiType *smiGetAttributeParentType(SmiAttribute *smiAttributePtr) -{ - Type *parentTypePtr; - - if (! smiAttributePtr) { - return NULL; - } - - parentTypePtr = ((Attribute*)smiAttributePtr)->parentTypePtr; - - return (parentTypePtr) ? &parentTypePtr->export : NULL; -} - -SmiClass *smiGetAttributeParentClass( SmiAttribute *smiAttributePtr) -{ - Class *parentClassPtr; - - if (! smiAttributePtr) { - return NULL; - } - - parentClassPtr = ((Attribute*)smiAttributePtr)->parentClassPtr; - - return parentClassPtr ? &parentClassPtr->export : NULL; -} - -SmiAttribute *smiGetFirstUniqueAttribute(SmiClass *smiClassPtr) -{ - Class *classPtr; - - if (! smiClassPtr) { - return NULL; - } - - classPtr = (Class*)smiClassPtr; - - if (! classPtr->uniqueList) { - return NULL; - } - - if (classPtr->uniqueList->ptr == classPtr) { - return NULL; /* scalar class */ - } - - return (SmiAttribute*)(classPtr->uniqueList->ptr); -} - -SmiAttribute *smiGetNextUniqueAttribute( SmiAttribute *smiTypePtr) -{ - Class *classPtr; - List *listPtr; - - if (! smiTypePtr) { - return NULL; - } - - classPtr = ((Attribute*)smiTypePtr)->classPtr; - - if (classPtr && classPtr->uniqueList) { - for (listPtr=classPtr->uniqueList;listPtr; listPtr=listPtr->nextPtr) { - if (&((Attribute*)(listPtr->ptr))->export == smiTypePtr) { - if (listPtr->nextPtr) { - return &((Attribute*)(listPtr->nextPtr->ptr))->export; - } - } - } - } - return NULL; -} - - - -int smiGetAttributeLine(SmiAttribute *smiAttributePtr) -{ - return ((Attribute *)smiAttributePtr)->line; -} - - - -int smiIsClassScalar(SmiClass *smiClassPtr) -{ - Class *classPtr; - - if (! smiClassPtr) { - return 0; - } - - classPtr = (Class*)smiClassPtr; - - if (! classPtr->uniqueList) { - return 0; - } - - return (classPtr->uniqueList->ptr == classPtr); -} - - - -SmiEvent *smiGetFirstEvent(SmiClass *smiClassPtr) -{ - Event *eventPtr; - - if (! smiClassPtr) { - return NULL; - } - - eventPtr = ((Class *)smiClassPtr)->firstEventPtr; - return &(eventPtr->export); -} - - - -SmiEvent *smiGetNextEvent(SmiEvent *smiEventPtr) -{ - Event *eventPtr; - - if (! smiEventPtr) { - return NULL; - } - - eventPtr = ((Event *)smiEventPtr)->nextPtr; - return &eventPtr->export; -} - - - -int smiGetEventLine(SmiEvent *smiEventPtr) -{ - return ((Event *)smiEventPtr)->line; -} - - - -SmiMacro *smiGetMacro(SmiModule *smiModulePtr, char *macro) -{ - Macro *macroPtr = NULL; - Module *modulePtr = NULL; - char *module2, *macro2; - - if (!macro) { - return NULL; - } - - modulePtr = (Module *)smiModulePtr; - - getModulenameAndName(smiModulePtr ? smiModulePtr->name : NULL, macro, - &module2, ¯o2); - - if (!modulePtr && module2 && strlen(module2)) { - if (!(modulePtr = findModuleByName(module2))) { - modulePtr = loadModule(module2, NULL); - } - } - - if (modulePtr) { - macroPtr = findMacroByModuleAndName(modulePtr, macro2); - } else { - macroPtr = findMacroByName(macro2); - } - - smiFree(module2); - smiFree(macro2); - return macroPtr ? ¯oPtr->export : NULL; -} - - - -SmiMacro *smiGetFirstMacro(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return ((Module *)smiModulePtr)->firstMacroPtr ? - &((Module *)smiModulePtr)->firstMacroPtr->export : NULL; -} - - - -SmiMacro *smiGetNextMacro(SmiMacro *smiMacroPtr) -{ - if (!smiMacroPtr) { - return NULL; - } - - return ((Macro *)smiMacroPtr)->nextPtr ? - &((Macro *)smiMacroPtr)->nextPtr->export : NULL; -} - - -SmiModule *smiGetMacroModule(SmiMacro *smiMacroPtr) -{ - return &((Macro *)smiMacroPtr)->modulePtr->export; -} - - -int smiGetMacroLine(SmiMacro *smiMacroPtr) -{ - return ((Macro *)smiMacroPtr)->line; -} - - -SmiNode *smiGetNode(SmiModule *smiModulePtr, const char *node) -{ - Object *objectPtr = NULL; - Module *modulePtr = NULL; - Node *nodePtr; - char *module2, *node2, *p; - unsigned int oidlen; - SmiSubid oid[128]; - - if (!node) { - return NULL; - } - - modulePtr = (Module *)smiModulePtr; - - getModulenameAndName(smiModulePtr ? smiModulePtr->name : NULL, node, - &module2, &node2); - - if (!modulePtr && module2 && strlen(module2)) { - if (!(modulePtr = findModuleByName(module2))) { - modulePtr = loadModule(module2, NULL); - } - } - - if (isdigit((int)node2[0])) { - for (oidlen = 0, p = strtok(node2, ". "); p; - oidlen++, p = strtok(NULL, ". ")) { - oid[oidlen] = strtoul(p, NULL, 0); - } - nodePtr = getNode(oidlen, oid); - if (nodePtr) { - if (modulePtr) { - objectPtr = findObjectByModuleAndNode(modulePtr, nodePtr); - } else { - objectPtr = findObjectByNode(nodePtr); - } - } - } else { - p = strtok(node2, ". "); - if (modulePtr) { - objectPtr = findObjectByModuleAndName(modulePtr, p); - } else { - objectPtr = findObjectByName(p); - } - } - - smiFree(module2); - smiFree(node2); - return objectPtr ? &objectPtr->export : NULL; -} - - - -SmiNode *smiGetNodeByOID(unsigned int oidlen, SmiSubid oid[]) -{ - Node *nodePtr; - Object *objectPtr; - - if (!oidlen) { - return NULL; - } - - nodePtr = getNode(oidlen, oid); - - if (!nodePtr) { - return NULL; - } - - objectPtr = findObjectByNode(nodePtr); - - return objectPtr ? &objectPtr->export : NULL; -} - - - -SmiNode *smiGetFirstNode(SmiModule *smiModulePtr, SmiNodekind nodekind) -{ - Module *modulePtr; - Node *nodePtr = NULL; - Object *objectPtr; - - if (!smiModulePtr) { - return NULL; - } - - modulePtr = (Module *)smiModulePtr; - - if (modulePtr && modulePtr->prefixNodePtr) { - /* start at the common oid prefix of this module */ - nodePtr = modulePtr->prefixNodePtr; - } else { - nodePtr = smiHandle->rootNodePtr->firstChildPtr; - } - - do { - objectPtr = getNextChildObject(nodePtr, modulePtr, nodekind); - - if (objectPtr) - return &objectPtr->export; - - if (nodePtr->firstChildPtr) { - nodePtr = nodePtr->firstChildPtr; - } else if (nodePtr->nextPtr) { - nodePtr = nodePtr->nextPtr; - } else { - for (nodePtr = nodePtr->parentPtr; - nodePtr && (nodePtr->parentPtr) && (!nodePtr->nextPtr); - nodePtr = nodePtr->parentPtr); - if (nodePtr) nodePtr = nodePtr->nextPtr; - } - } while (nodePtr); - - return NULL; -} - - - -SmiNode *smiGetNextNode(SmiNode *smiNodePtr, SmiNodekind nodekind) -{ - Module *modulePtr; - Object *objectPtr; - Node *nodePtr; - int i; - - if (!smiNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiNodePtr; - nodePtr = objectPtr->nodePtr; - modulePtr = objectPtr->modulePtr; - - if (!modulePtr) { - return NULL; - } - - if (!nodePtr) { - return NULL; - } - - do { - if (nodePtr->firstChildPtr) { - nodePtr = nodePtr->firstChildPtr; - } else if (nodePtr->nextPtr) { - nodePtr = nodePtr->nextPtr; - } else { - for (nodePtr = nodePtr->parentPtr; - (nodePtr->parentPtr) && (!nodePtr->nextPtr); - nodePtr = nodePtr->parentPtr); - nodePtr = nodePtr->nextPtr; - /* did we move outside the common oid prefix of this module? */ - for (i = 0; i < modulePtr->prefixNodePtr->oidlen; i++) - if ((!nodePtr) || (!nodePtr->oid) || - (nodePtr->oid[i] != modulePtr->prefixNodePtr->oid[i])) - return NULL; - } - - objectPtr = getNextChildObject(nodePtr, modulePtr, nodekind); - - if (objectPtr) - return &objectPtr->export; - - } while (nodePtr); - - return NULL; -} - - - -SmiNode *smiGetParentNode(SmiNode *smiNodePtr) -{ - Module *modulePtr; - Object *objectPtr; - Import *importPtr; - Node *nodePtr; - - if (!smiNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiNodePtr; - nodePtr = objectPtr->nodePtr; - modulePtr = objectPtr->modulePtr; - - if (!nodePtr) { - return NULL; - } - - if (nodePtr == smiHandle->rootNodePtr) { - return NULL; - } - - nodePtr = nodePtr->parentPtr; - if (! nodePtr) { - return NULL; - } - - /* - * First, try to find a definition in the same module. - */ - objectPtr = NULL; - if (modulePtr) { - objectPtr = findObjectByModuleAndNode(modulePtr, nodePtr); - } - - /* - * If found, check if it's imported. In case, get the original definition. - */ - if (objectPtr) { - importPtr = findImportByName(objectPtr->export.name, - objectPtr->modulePtr); - if (importPtr) { - objectPtr = findObjectByModulenameAndNode(importPtr->export.module, - nodePtr); - } else { - objectPtr = NULL; - } - } - - /* - * If not yet found, try to find any definition. - */ - if (!objectPtr) { - objectPtr = findObjectByNode(nodePtr); - - if ((!objectPtr) && (nodePtr->parentPtr)) { - /* an implicitly created node, e.g. gaga.0 in an object - * definition with oid == gaga.0.1. - */ - objectPtr = addObject(SMI_UNKNOWN_LABEL, - nodePtr->parentPtr, nodePtr->subid, - 0, NULL); - objectPtr->nodePtr = nodePtr; - objectPtr->modulePtr = modulePtr; - } - } - - return objectPtr ? &objectPtr->export : NULL; -} - - - -SmiNode *smiGetRelatedNode(SmiNode *smiNodePtr) -{ - if (!smiNodePtr) { - return NULL; - } - - return &((Object *)smiNodePtr)->relatedPtr->export; -} - - - -SmiNode *smiGetFirstChildNode(SmiNode *smiNodePtr) -{ - Module *modulePtr; - Object *objectPtr; - Node *nodePtr; - - if (!smiNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiNodePtr; - nodePtr = objectPtr->nodePtr; - modulePtr = objectPtr->modulePtr; - - if (!nodePtr) { - return NULL; - } - - nodePtr = nodePtr->firstChildPtr; - - if (!nodePtr) { - return NULL; - } - - objectPtr = findObjectByModuleAndNode(modulePtr, nodePtr); - if (!objectPtr) objectPtr = findObjectByNode(nodePtr); - - return objectPtr ? &objectPtr->export : NULL; -} - - - -SmiNode *smiGetNextChildNode(SmiNode *smiNodePtr) -{ - Module *modulePtr; - Object *objectPtr; - Node *nodePtr; - - if (!smiNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiNodePtr; - nodePtr = objectPtr->nodePtr; - modulePtr = objectPtr->modulePtr; - - if (!nodePtr) { - return NULL; - } - - nodePtr = nodePtr->nextPtr; - - if (!nodePtr) { - return NULL; - } - - objectPtr = findObjectByModuleAndNode(modulePtr, nodePtr); - if (!objectPtr) objectPtr = findObjectByNode(nodePtr); - - return objectPtr ? &objectPtr->export : NULL; -} - - - -SmiNode *smiGetModuleIdentityNode(SmiModule *smiModulePtr) -{ - if (!smiModulePtr) { - return NULL; - } - - return &((Module *)smiModulePtr)->objectPtr->export; -} - - - -SmiModule *smiGetNodeModule(SmiNode *smiNodePtr) -{ - return &((Object *)smiNodePtr)->modulePtr->export; -} - - - -SmiType *smiGetNodeType(SmiNode *smiNodePtr) -{ - Type *typePtr; - - typePtr = ((Object *)smiNodePtr)->typePtr; - - if (!typePtr || - typePtr->export.basetype == SMI_BASETYPE_UNKNOWN) { - return NULL; - } - - return &typePtr->export; -} - - - -int smiGetNodeLine(SmiNode *smiNodePtr) -{ - return ((Object *)smiNodePtr)->line; -} - - - -SmiElement *smiGetFirstElement(SmiNode *smiNodePtr) -{ - List *listPtr; - - if (!smiNodePtr) { - return NULL; - } - - listPtr = ((Object *)smiNodePtr)->listPtr; - - return (SmiElement *)listPtr; -} - - - -SmiElement *smiGetNextElement(SmiElement *smiElementPtr) -{ - List *listPtr; - - if (!smiElementPtr) { - return NULL; - } - - listPtr = ((List *)smiElementPtr)->nextPtr; - - return (SmiElement *)listPtr; -} - - - -SmiNode *smiGetElementNode(SmiElement *smiElementPtr) -{ - if ((Object *)((List *)smiElementPtr)->ptr) - return &((Object *)((List *)smiElementPtr)->ptr)->export; - else - return NULL; -} - - - -SmiOption *smiGetFirstOption(SmiNode *smiComplianceNodePtr) -{ - Object *objectPtr; - - if (!smiComplianceNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiComplianceNodePtr; - - if (!objectPtr->optionlistPtr) { - return NULL; - } - - if (objectPtr->export.nodekind != SMI_NODEKIND_COMPLIANCE) { - return NULL; - } - - return &((Option *)objectPtr->optionlistPtr->ptr)->export; -} - - - -SmiOption *smiGetNextOption(SmiOption *smiOptionPtr) -{ - List *listPtr; - - if (!smiOptionPtr) { - return NULL; - } - - for (listPtr = - ((Option *)smiOptionPtr)->compliancePtr->optionlistPtr; - listPtr; - listPtr = listPtr->nextPtr) { - if ((Option *)(listPtr->ptr) == (Option *)smiOptionPtr) { - if (listPtr->nextPtr) { - return &((Option *)listPtr->nextPtr->ptr)->export; - } else { - return NULL; - } - } - } - - return NULL; -} - - - -SmiNode *smiGetOptionNode(SmiOption *smiOptionPtr) -{ - return &((Option *)smiOptionPtr)->objectPtr->export; -} - - - -int smiGetOptionLine(SmiOption *smiOptionPtr) -{ - return ((Option *)smiOptionPtr)->line; -} - - - -SmiRefinement *smiGetFirstRefinement(SmiNode *smiComplianceNodePtr) -{ - Object *objectPtr; - - if (!smiComplianceNodePtr) { - return NULL; - } - - objectPtr = (Object *)smiComplianceNodePtr; - - if (!objectPtr->refinementlistPtr) { - return NULL; - } - - if (objectPtr->export.nodekind != SMI_NODEKIND_COMPLIANCE) { - return NULL; - } - - return &((Refinement *)objectPtr->refinementlistPtr->ptr)->export; -} - - - -SmiRefinement *smiGetNextRefinement(SmiRefinement *smiRefinementPtr) -{ - List *listPtr; - - if (!smiRefinementPtr) { - return NULL; - } - - for (listPtr = - ((Refinement *)smiRefinementPtr)->compliancePtr->refinementlistPtr; - listPtr; - listPtr = listPtr->nextPtr) { - if ((Refinement *)(listPtr->ptr) == (Refinement *)smiRefinementPtr) { - if (listPtr->nextPtr) { - return &((Refinement *)listPtr->nextPtr->ptr)->export; - } else { - return NULL; - } - } - } - - return NULL; -} - - - -SmiNode *smiGetRefinementNode(SmiRefinement *smiRefinementPtr) -{ - return &((Refinement *)smiRefinementPtr)->objectPtr->export; -} - - - -SmiType *smiGetRefinementType(SmiRefinement *smiRefinementPtr) -{ - Type *typePtr; - - typePtr = ((Refinement *)smiRefinementPtr)->typePtr; - - if (!typePtr || - typePtr->export.basetype == SMI_BASETYPE_UNKNOWN) { - return NULL; - } - - return &typePtr->export; -} - - - -SmiType *smiGetRefinementWriteType(SmiRefinement *smiRefinementPtr) -{ - Type *typePtr; - - typePtr = ((Refinement *)smiRefinementPtr)->writetypePtr; - - if (!typePtr || - typePtr->export.basetype == SMI_BASETYPE_UNKNOWN) { - return NULL; - } - - return &typePtr->export; -} - - - -int smiGetRefinementLine(SmiRefinement *smiRefinementPtr) -{ - return ((Refinement *)smiRefinementPtr)->line; -} - - - -SmiElement *smiGetFirstUniquenessElement(SmiNode *smiNodePtr) -{ - List *listPtr; - - if (!smiNodePtr) { - return NULL; - } - - listPtr = ((Object *)smiNodePtr)->uniquenessPtr; - - return (SmiElement *)listPtr; -} - - - -char *smiRenderOID(unsigned int oidlen, SmiSubid *oid, int flags) -{ - SmiNode *nodePtr = NULL; - SmiModule *modulePtr = NULL; - unsigned int i = 0; - char *ss, *s = NULL; - - if (!oid) { - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - return s; - } - - if (flags & (SMI_RENDER_NAME | SMI_RENDER_QUALIFIED)) { - int len; - for (len = oidlen; len; len--) { - nodePtr = smiGetNodeByOID(len, oid); - if (! nodePtr || nodePtr->name) break; - } - if (nodePtr && nodePtr->name) { - i = nodePtr->oidlen; - if (flags & SMI_RENDER_QUALIFIED) { - modulePtr = smiGetNodeModule(nodePtr); - } - if (modulePtr) { - smiAsprintf(&s, "%s::%s", - modulePtr->name, nodePtr->name); - } else { - smiAsprintf(&s, "%s", nodePtr->name); - } - } - } - - for (; i < oidlen; i++) { - ss = s; - smiAsprintf(&s, "%s%s%u", ss ? ss : "", i ? "." : "", oid[i]); - smiFree(ss); - } - - if ((!s) && (flags & SMI_RENDER_UNKNOWN)) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } - - return s; -} - - - -char *smiRenderValue(SmiValue *smiValuePtr, SmiType *smiTypePtr, int flags) -{ - unsigned int i, pfx; - int j, k, n, have_pfx; - char *last_fmt, *fmt; - SmiUnsigned64 vv; - int xlen; - SmiNamedNumber *nn; - char *s, *ss; - char f[8]; - SmiUnsigned32 v32; - SmiUnsigned64 v64; - - if (!smiValuePtr) { - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - return s; - } - - switch (smiValuePtr->basetype) { - case SMI_BASETYPE_UNSIGNED32: - if (!(flags & SMI_RENDER_FORMAT) || - !smiTypePtr || !smiTypePtr->format || - !strlen(smiTypePtr->format) || smiTypePtr->format[0] == 'd') { - if (smiTypePtr->format && (strlen(smiTypePtr->format) >= 3) && - (smiTypePtr->format[1] == '-')) { - i = atoi(&smiTypePtr->format[2]); - if (i < 0) i = 0; - if (i > 20) i = 20; - smiAsprintf(&s, "%0*lu.", - 1 + i, - smiValuePtr->value.unsigned32); - if (s) { - for (j = strlen(s) - 1; i > 0; i--, j--) { - s[j] = s[j-1]; - } - s[j] = '.'; - } - } else { - smiAsprintf(&s, "%lu", smiValuePtr->value.unsigned32); - } - } else if (smiTypePtr->format[0] == 'x') { - smiAsprintf(&s, "%lx", smiValuePtr->value.unsigned32); - } else if (smiTypePtr->format[0] == 'o') { - smiAsprintf(&s, "%lo", smiValuePtr->value.unsigned32); - } else if (smiTypePtr->format[0] == 'b') { - for (i = 32 - 1; - i > 0 && !(smiValuePtr->value.unsigned32 & (1 << i)); i--); - s = smiMalloc(i + 1 + 1); - if (s) { - for (j = 0; i >= 0; i--, j++) { - s[j] = smiValuePtr->value.unsigned32 & (1<format || - !strlen(smiTypePtr->format) || smiTypePtr->format[0] == 'd') { - if (smiTypePtr->format && (strlen(smiTypePtr->format) >= 3) && - (smiTypePtr->format[1] == '-')) { - i = atoi(&smiTypePtr->format[2]); - if (i < 0) i = 0; - if (i > 20) i = 20; - sprintf(f, "%%0%s.", UINT64_FORMAT); - f[2] = '*'; - smiAsprintf(&s, f, - 1 + i, - smiValuePtr->value.unsigned64); - if (s) { - for (j = strlen(s) - 1; i > 0; i--, j--) { - s[j] = s[j-1]; - } - s[j] = '.'; - } - } else { - smiAsprintf(&s, UINT64_FORMAT, smiValuePtr->value.unsigned64); - } - } else if (smiTypePtr->format[0] == 'x') { - strcpy(f, UINT64_FORMAT); - f[strlen(f)-1] = 'x'; - smiAsprintf(&s, f, smiValuePtr->value.unsigned64); - } else if (smiTypePtr->format[0] == 'o') { - strcpy(f, UINT64_FORMAT); - f[strlen(f)-1] = 'o'; - smiAsprintf(&s, f, smiValuePtr->value.unsigned64); - } else if (smiTypePtr->format[0] == 'b') { - for (i = 64 - 1; - i > 0 && !(smiValuePtr->value.unsigned64 & (1 << i)); i--); - s = smiMalloc(i + 1 + 1); - if (s) { - for (j = 0; i >= 0; i--, j++) { - s[j] = smiValuePtr->value.unsigned64 & (1<format || - !strlen(smiTypePtr->format) || smiTypePtr->format[0] == 'd') { - if (smiTypePtr->format && (strlen(smiTypePtr->format) >= 3) && - (smiTypePtr->format[1] == '-')) { - i = atoi(&smiTypePtr->format[2]); - if (i < 0) i = 0; - if (i > 20) i = 20; - smiAsprintf(&s, "%0*ld.", - 1 + i + (smiValuePtr->value.integer32 < 0 ? 1 : 0), - smiValuePtr->value.integer32); - if (s) { - for (j = strlen(s) - 1; i > 0; i--, j--) { - s[j] = s[j-1]; - } - s[j] = '.'; - } - } else { - smiAsprintf(&s, "%ld", smiValuePtr->value.integer32); - } - } else if (smiTypePtr->format[0] == 'x') { - if (smiValuePtr->value.integer32 >= 0) { - smiAsprintf(&s, "%lx", smiValuePtr->value.integer32); - } else { - smiAsprintf(&s, "-%lx", - smiValuePtr->value.integer32); - } - } else if (smiTypePtr->format[0] == 'o') { - if (smiValuePtr->value.integer32 >= 0) { - smiAsprintf(&s, "%lo", smiValuePtr->value.integer32); - } else { - smiAsprintf(&s, "-%lo", - smiValuePtr->value.integer32); - } - } else if (smiTypePtr->format[0] == 'b') { - if (smiValuePtr->value.integer32 >= 0) { - v32 = smiValuePtr->value.integer32; - j = 0; - } else { - v32 = - smiValuePtr->value.integer32; - j = 1; - } - for (i = 32 - 1; - i > 0 && !(v32 & (1 << i)); i--); - s = smiMalloc(i + j + 1 + 1); - if (s) { - s[0] = '-'; - for (; i >= 0; i--, j++) { - s[j] = v32 & (1<format || - !strlen(smiTypePtr->format) || smiTypePtr->format[0] == 'd') { - if (smiTypePtr->format && (strlen(smiTypePtr->format) >= 3) && - (smiTypePtr->format[1] == '-')) { - i = atoi(&smiTypePtr->format[2]); - if (i < 0) i = 0; - if (i > 20) i = 20; - sprintf(f, "%%0%s.", INT64_FORMAT); - f[2] = '*'; - smiAsprintf(&s, f, - 1 + i + (smiValuePtr->value.integer64 < 0 ? 1 : 0), - smiValuePtr->value.integer64); - if (s) { - for (j = strlen(s) - 1; i > 0; i--, j--) { - s[j] = s[j-1]; - } - s[j] = '.'; - } - } else { - smiAsprintf(&s, INT64_FORMAT, smiValuePtr->value.integer64); - } - } else if (smiTypePtr->format[0] == 'x') { - if (smiValuePtr->value.integer64 >= 0) { - strcpy(f, UINT64_FORMAT); - f[strlen(f)-1] = 'x'; - smiAsprintf(&s, f, smiValuePtr->value.integer64); - } else { - sprintf(f, "-%s", UINT64_FORMAT); - f[strlen(f)-1] = 'x'; - smiAsprintf(&s, f, - smiValuePtr->value.integer64); - } - } else if (smiTypePtr->format[0] == 'o') { - if (smiValuePtr->value.integer64 >= 0) { - strcpy(f, UINT64_FORMAT); - sprintf(f, "-%s", UINT64_FORMAT); - f[strlen(f)-1] = 'o'; - smiAsprintf(&s, f, smiValuePtr->value.integer64); - } else { - smiAsprintf(&s, f, - smiValuePtr->value.integer64); - } - } else if (smiTypePtr->format[0] == 'b') { - if (smiValuePtr->value.integer64 >= 0) { - v64 = smiValuePtr->value.integer64; - j = 0; - } else { - v64 = - smiValuePtr->value.integer64; - j = 1; - } - for (i = 64 - 1; - i > 0 && !(v64 & (1 << i)); i--); - s = smiMalloc(i + j + 1 + 1); - if (s) { - s[0] = '-'; - for (; i >= 0; i--, j++) { - s[j] = v64 & (1<len, smiValuePtr->value.oid, flags); - break; - case SMI_BASETYPE_OCTETSTRING: - if (!(flags & SMI_RENDER_FORMAT) || - (!smiTypePtr->format && - (smiTypePtr->name && strcmp( smiTypePtr->name, "IpAddress")) ) ) { - for (i = 0; i < smiValuePtr->len; i++) { - if (!isprint((int)smiValuePtr->value.ptr[i])) break; - } - if ((i < smiValuePtr->len) || - !(flags & SMI_RENDER_PRINTABLE)) { - smiAsprintf(&s, ""); - for (i=0; i < smiValuePtr->len; i++) { - ss = s; - smiAsprintf(&s, "%s%02x", ss, smiValuePtr->value.ptr[i]); - smiFree(ss); - } - } else { - smiAsprintf(&s, "%s", smiValuePtr->value.ptr); - } - } else { - i = 0; - smiAsprintf(&s, ""); - /* SNMPv2-SMI:IpAddress does not have a display hint. - ==> let's use this one: "1d." if we have an IpAddress here */ - fmt = (smiTypePtr->name && - strcmp( smiTypePtr->name, "IpAddress" ) ) ? - smiTypePtr->format : "1d."; - while (*fmt && i < smiValuePtr->len) { - last_fmt = fmt; - have_pfx = pfx = 0; /* scan prefix: */ - while (*fmt && isdigit((int)*fmt)) { - pfx = pfx * 10 + *fmt - '0', have_pfx = 1, fmt++; - } - if (! have_pfx) { - pfx = 1; - } - switch (*fmt) { - case 't': - /* XXX UTF-8 not implemented, fall through to ASCII (a) */ - case 'a': - n = (pfx < (smiValuePtr->len - i)) ? - pfx : smiValuePtr->len - i; - for (k = 0; k < n; k++) { - if (! isascii((int) smiValuePtr->value.ptr[i+k])) { - smiFree(s); - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - return s; - } - ss = s; - smiAsprintf(&s, "%s%c", ss, smiValuePtr->value.ptr[i+k]); - smiFree(ss); - } - i += n; - break; - case 'b': - case 'd': - case 'o': - case 'x': - /* XXX: limited to no more than - sizeof(SmiUnsigned64) octets */ - vv = 0; - xlen = pfx * 2; - while (pfx > 0 && i < smiValuePtr->len) { - vv = vv * 256 + - ((unsigned char)smiValuePtr->value.ptr[i]); - i++; - pfx--; - } - switch (*fmt) { - case 'd': - ss = s; - sprintf(f, "%%s%s", UINT64_FORMAT); - smiAsprintf(&s, f, ss, vv); - smiFree(ss); - break; - case 'o': - ss = s; - sprintf(f, "%%s%s", UINT64_FORMAT); - f[strlen(f)-1] = 'o'; - smiAsprintf(&s, f, ss, vv); - smiFree(ss); - break; - case 'x': - ss = s; - sprintf(f, "%%s%%0%s", UINT64_FORMAT); - f[4] = '*'; - f[strlen(f)-1] = 'x'; - smiAsprintf(&s, f, ss, xlen, vv); - smiFree(ss); - break; - case 'b': - k = pfx * 8 - 1; - if (k > sizeof(SmiUnsigned64) * 8 - 1) - k = sizeof(SmiUnsigned64) * 8 - 1; - for (j = 0; k >= 0; k--, j++) { - ss = s; - smiAsprintf(&s, "%s%c", - ss, vv & (1 << k) ? '1' : '0'); - smiFree(ss); - } - break; - } - break; - default: - smiFree(s); - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - return s; - } - fmt++; - - /* - * Check for a separator and repeat with last format if - * data is still available. - */ - if (*fmt && ! isdigit((int) *fmt) && *fmt != '*') { - if (i < smiValuePtr->len) { - ss = s; - smiAsprintf(&s, "%s%c", ss, fmt[0]); - smiFree(ss); - } - fmt++; - } - - if (! *fmt && (i < smiValuePtr->len)) { - fmt = last_fmt; - } - } - } - break; - case SMI_BASETYPE_ENUM: - if ((flags & SMI_RENDER_NAME) && (smiTypePtr)) { - for (nn = smiGetFirstNamedNumber(smiTypePtr); nn; - nn = smiGetNextNamedNumber(nn)) { - if (nn->value.value.integer32 == smiValuePtr->value.integer32) - break; - } - if (nn) { - if (flags & SMI_RENDER_NUMERIC) { - smiAsprintf(&s, "%s(%ld)", - nn->name, nn->value.value.integer32); - } else { - smiAsprintf(&s, "%s", nn->name); - } - } else { - smiAsprintf(&s, "%ld", smiValuePtr->value.integer32); - } - } else { - smiAsprintf(&s, "%ld", smiValuePtr->value.integer32); - } - break; - case SMI_BASETYPE_BITS: - smiAsprintf(&s, ""); - for (i = 0, nn = NULL; i < smiValuePtr->len * 8; i++) { - if (smiValuePtr->value.ptr[i/8] & (1 << (7-(i%8)))) { - if ((flags & SMI_RENDER_NAME) && (smiTypePtr)) { - for (nn = smiGetFirstNamedNumber(smiTypePtr); nn; - nn = smiGetNextNamedNumber(nn)) { - if (nn->value.value.unsigned32 == i) - break; - } - } - ss = s; - if ((flags & SMI_RENDER_NAME) && - (flags & SMI_RENDER_NUMERIC) && nn) { - smiAsprintf(&s, "%s%s%s(%d)", - ss, strlen(ss) ? " " : "", nn->name, i); - } else if (nn) { - smiAsprintf(&s, "%s%s%s", - ss, strlen(ss) ? " " : "", nn->name); - } else { - smiAsprintf(&s, "%s%s%d", - ss, strlen(ss) ? " " : "", i); - } - smiFree(ss); - } - } - break; - case SMI_BASETYPE_FLOAT32: - case SMI_BASETYPE_FLOAT64: - case SMI_BASETYPE_FLOAT128: - case SMI_BASETYPE_UNKNOWN: - default: - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - break; - } - - return s; -} - -char *smiRenderNode(SmiNode *smiNodePtr, int flags) -{ - char *s; - SmiModule *modulePtr; - - if ((!smiNodePtr) || (smiNodePtr->name == NULL)) { - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - } else { - modulePtr = smiGetNodeModule(smiNodePtr); - if ((!(flags & SMI_RENDER_QUALIFIED)) || - (!modulePtr) || - (!strlen(modulePtr->name))) { - smiAsprintf(&s, "%s", smiNodePtr->name); - } else { - smiAsprintf(&s, "%s::%s", modulePtr->name, smiNodePtr->name); - } - } - return s; -} - - - -char *smiRenderType(SmiType *smiTypePtr, int flags) -{ - char *s; - SmiModule *modulePtr; - - if ((!smiTypePtr) || (smiTypePtr->name == NULL)) { - if (flags & SMI_RENDER_UNKNOWN) { - smiAsprintf(&s, SMI_UNKNOWN_LABEL); - } else { - s = NULL; - } - } else { - modulePtr = smiGetTypeModule(smiTypePtr); - if ((!(flags & SMI_RENDER_QUALIFIED)) || - (!modulePtr) || - (!strlen(modulePtr->name))) { - smiAsprintf(&s, "%s", smiTypePtr->name); - } else { - smiAsprintf(&s, "%s::%s", modulePtr->name, smiTypePtr->name); - } - } - return s; -} - - - -unsigned int smiGetMinSize(SmiType *smiType) -{ - SmiRange *smiRange; - SmiType *parentType; - unsigned int min = 65535, size; - - switch (smiType->basetype) { - case SMI_BASETYPE_BITS: - return 0; - case SMI_BASETYPE_OCTETSTRING: - case SMI_BASETYPE_OBJECTIDENTIFIER: - size = 0; - break; - default: - return 0; - } - - for (smiRange = smiGetFirstRange(smiType); - smiRange ; smiRange = smiGetNextRange(smiRange)) { - if (smiRange->minValue.value.unsigned32 < min) { - min = smiRange->minValue.value.unsigned32; - } - } - if (min < 65535 && min > size) { - size = min; - } - - parentType = smiGetParentType(smiType); - if (parentType) { - unsigned int psize = smiGetMinSize(parentType); - if (psize > size) { - size = psize; - } - } - - return size; -} - - - -unsigned int smiGetMaxSize(SmiType *smiType) -{ - SmiRange *smiRange; - SmiType *parentType; - SmiNamedNumber *nn; - unsigned int max = 0, size; - - switch (smiType->basetype) { - case SMI_BASETYPE_BITS: - case SMI_BASETYPE_OCTETSTRING: - size = 65535; - break; - case SMI_BASETYPE_OBJECTIDENTIFIER: - size = 128; - break; - default: - return 0xffffffff; - } - - if (smiType->basetype == SMI_BASETYPE_BITS) { - for (nn = smiGetFirstNamedNumber(smiType); - nn; - nn = smiGetNextNamedNumber(nn)) { - if (nn->value.value.unsigned32 > max) { - max = nn->value.value.unsigned32; - } - } - size = (max / 8) + 1; - return size; - } - - for (smiRange = smiGetFirstRange(smiType); - smiRange ; smiRange = smiGetNextRange(smiRange)) { - if (smiRange->maxValue.value.unsigned32 > max) { - max = smiRange->maxValue.value.unsigned32; - } - } - if (max > 0 && max < size) { - size = max; - } - - parentType = smiGetParentType(smiType); - if (parentType) { - unsigned int psize = smiGetMaxSize(parentType); - if (psize < size) { - size = psize; - } - } - - return size; -} - - - -int smiUnpack(SmiNode *row, SmiSubid *oid, unsigned int oidlen, - SmiValue **vals, int *valslen) -{ - SmiNode *indexNode = NULL; - SmiElement *smiElement; - SmiNode *iNode; - SmiType *iType; - int i, j, last = 0; - - if (!vals || !valslen || !row || !oid) { - return 0; - } - - switch (row->indexkind) { - case SMI_INDEX_INDEX: - case SMI_INDEX_REORDER: - indexNode = row; - break; - case SMI_INDEX_EXPAND: /* TODO: we have to do more work here! */ - indexNode = NULL; - break; - case SMI_INDEX_AUGMENT: - case SMI_INDEX_SPARSE: - indexNode = smiGetRelatedNode(row); - break; - case SMI_INDEX_UNKNOWN: - indexNode = NULL; - break; - } - - *valslen = 0; - for (smiElement = smiGetFirstElement(indexNode); - smiElement; smiElement = smiGetNextElement(smiElement)) { - iNode = smiGetElementNode(smiElement); - if (iNode) { - iType = smiGetNodeType(iNode); - if (! iType) break; - (*valslen)++; - } - } - if (smiElement) { - return 0; - } - - *vals = smiMalloc(*valslen * sizeof(SmiValue)); - - for (smiElement = smiGetFirstElement(indexNode), i = 0, j = 0; - smiElement; smiElement = smiGetNextElement(smiElement), i++) { - iNode = smiGetElementNode(smiElement); - last = (smiGetNextElement(smiElement) == NULL); - iType = smiGetNodeType(iNode); - fprintf(stderr, "** %s (%s)\n", iNode->name, iType->name); - (*vals)[i].basetype = iType->basetype; - switch (iType->basetype) { - case SMI_BASETYPE_ENUM: - case SMI_BASETYPE_INTEGER32: - (*vals)[i].value.integer32 = oid[j]; j++; - break; - case SMI_BASETYPE_UNSIGNED32: - (*vals)[i].value.unsigned32 = oid[j]; j++; - break; - case SMI_BASETYPE_OCTETSTRING: - /* need to know whether implied/fixed length or not */ - break; - case SMI_BASETYPE_OBJECTIDENTIFIER: - /* need to know whether implied/fixed length or not */ - break; - default: - return 0; - } - } - - return *valslen; -} - - - -int smiAsprintf(char **strp, const char *format, ...) -{ - int rc; - va_list ap; - - va_start(ap, format); - rc = vasprintf(strp, format, ap); - va_end(ap); - if (! strp) { - smiPrintError(NULL, ERR_OUT_OF_MEMORY); - } - return rc; -} - - - -int smiVasprintf(char **strp, const char *format, va_list ap) -{ - int rc; - - rc = vasprintf(strp, format, ap); - if (! strp) { - smiPrintError(NULL, ERR_OUT_OF_MEMORY); - } - return rc; -} - - -int smiGetMinMaxRange(SmiType *smiType, SmiValue *min, SmiValue *max) -{ - SmiBasetype basetype = SMI_BASETYPE_UNKNOWN; - SmiRange *range; - - min->basetype = max->basetype = SMI_BASETYPE_UNKNOWN; - min->len = max->len = 0; - - range = smiGetFirstRange(smiType); - if (!range) { - return 0; - } - - basetype = range->minValue.basetype; - min->basetype = max->basetype = basetype; - - switch (basetype) { - case SMI_BASETYPE_INTEGER32: - min->value.integer32 = SMI_BASETYPE_INTEGER32_MAX; - max->value.integer32 = SMI_BASETYPE_INTEGER32_MIN; - break; - case SMI_BASETYPE_INTEGER64: - min->value.integer64 = SMI_BASETYPE_INTEGER64_MAX; - max->value.integer64 = SMI_BASETYPE_INTEGER64_MIN; - break; - case SMI_BASETYPE_UNSIGNED32: - min->value.unsigned32 = SMI_BASETYPE_UNSIGNED32_MAX; - max->value.unsigned32 = SMI_BASETYPE_UNSIGNED32_MIN; - break; - case SMI_BASETYPE_UNSIGNED64: - min->value.unsigned64 = SMI_BASETYPE_UNSIGNED64_MAX; - max->value.unsigned64 = SMI_BASETYPE_UNSIGNED32_MIN; - break; - default: - fprintf(stderr, "smidump: unexpected basetype %d\n", basetype); - return -1; - } - - for (range = smiGetFirstRange(smiType); - range; - range = smiGetNextRange(range)) { - switch (basetype) { - case SMI_BASETYPE_INTEGER32: - if (range->minValue.value.integer32 < min->value.integer32) { - min->value.integer32 = range->minValue.value.integer32; - } - if (range->maxValue.value.integer32 > max->value.integer32) { - max->value.integer32 = range->maxValue.value.integer32; - } - break; - case SMI_BASETYPE_INTEGER64: - if (range->minValue.value.integer64 < min->value.integer64) { - min->value.integer64 = range->minValue.value.integer64; - } - if (range->maxValue.value.integer64 > max->value.integer64) { - max->value.integer64 = range->maxValue.value.integer64; - } - break; - case SMI_BASETYPE_UNSIGNED32: - if (range->minValue.value.unsigned32 < min->value.unsigned32) { - min->value.unsigned32 = range->minValue.value.unsigned32; - } - if (range->maxValue.value.unsigned32 > max->value.unsigned32) { - max->value.unsigned32 = range->maxValue.value.unsigned32; - } - break; - case SMI_BASETYPE_UNSIGNED64: - if (range->minValue.value.unsigned64 < min->value.unsigned64) { - min->value.unsigned64 = range->minValue.value.unsigned64; - } - if (range->maxValue.value.unsigned64 > max->value.unsigned64) { - max->value.unsigned64 = range->maxValue.value.unsigned64; - } - break; - default: - fprintf(stderr, "smidump: unexpected basetype %d\n", basetype); - return -1; - } - } - - return 0; -} diff --git a/tools/dump-tree.c b/tools/dump-tree.c index 4c1950f..3db2265 100644 --- a/tools/dump-tree.c +++ b/tools/dump-tree.c @@ -117,7 +117,7 @@ static void fprintIndex(FILE *f, SmiNode *smiNode) smiElement; smiElement = smiGetNextElement(smiElement), i++) { if (i > 0) fprintf(f, ","); if (indexname) { - fprintf(f, "%s", indexname); + fprintf(f, indexname); } indexname = smiGetElementNode(smiElement)->name; } @@ -143,7 +143,7 @@ static void fprintObjects(FILE *f, SmiNode *smiNode) smiElement = smiGetNextElement(smiElement), i++) { if (i > 0) fprintf(f, ","); if (objectname) { - fprintf(f, "%s", objectname); + fprintf(f, objectname); } objectname = smiGetElementNode(smiElement)->name; } diff --git a/tools/dump-tree.c.format-security b/tools/dump-tree.c.format-security deleted file mode 100644 index 3db2265..0000000 --- a/tools/dump-tree.c.format-security +++ /dev/null @@ -1,540 +0,0 @@ -/* - * dump-tree.c -- - * - * Operations to dump the OID tree in a human readable format. - * - * Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig. - * Copyright (c) 1999 J. Schoenwaelder, Technical University of Braunschweig. - * Copyright (c) 2002 J. Schoenwaelder, University of Osnabrueck. - * - * See the file "COPYING" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * @(#) $Id: dump-tree.c 8090 2008-04-18 12:56:29Z strauss $ - */ - -#include - -#include -#include - -#include "smi.h" -#include "smidump.h" - - -static int pmodc = 0; -static SmiModule **pmodv = NULL; - -static int ignoreconformance = 0; -static int ignoreleafs = 0; -static int full = 0; -static int compact = 0; - -static char *getFlags(SmiNode *smiNode) -{ - - switch (smiNode->access) { - case SMI_ACCESS_UNKNOWN: - return "---"; - case SMI_ACCESS_NOT_ACCESSIBLE: - return "---"; - case SMI_ACCESS_EVENT_ONLY: - return "---"; - case SMI_ACCESS_NOTIFY: - return "--n"; - case SMI_ACCESS_READ_ONLY: - return "r-n"; - case SMI_ACCESS_READ_WRITE: - return "rwn"; - case SMI_ACCESS_NOT_IMPLEMENTED: - return "---"; - case SMI_ACCESS_INSTALL: - return "-i-"; - case SMI_ACCESS_INSTALL_NOTIFY: - return "-in"; - case SMI_ACCESS_REPORT_ONLY: - return "--r"; - } - - return ""; -} - - - -static char getStatusChar(SmiStatus status) -{ - switch (status) { - case SMI_STATUS_UNKNOWN: - return '+'; - case SMI_STATUS_CURRENT: - return '+'; - case SMI_STATUS_DEPRECATED: - return 'x'; - case SMI_STATUS_MANDATORY: - return '+'; - case SMI_STATUS_OPTIONAL: - return '+'; - case SMI_STATUS_OBSOLETE: - return 'o'; - } - - return ' '; -} - - - -static char *getTypeName(SmiNode *smiNode) -{ - char *type; - SmiType *smiType, *parentType; - - smiType = smiGetNodeType(smiNode); - - if (!smiType || smiNode->nodekind == SMI_NODEKIND_TABLE) - return NULL; - - if (smiType->decl == SMI_DECL_IMPLICIT_TYPE) { - parentType = smiGetParentType(smiType); - if (!parentType) - return NULL; - smiType = parentType; - } - - type = xstrdup(smiType->name); - return type; -} - - - -static void fprintIndex(FILE *f, SmiNode *smiNode) -{ - char *indexname; - int i; - SmiElement *smiElement; - - indexname = NULL; - for (i = -1, smiElement = smiGetFirstElement(smiNode); - smiElement; smiElement = smiGetNextElement(smiElement), i++) { - if (i > 0) fprintf(f, ","); - if (indexname) { - fprintf(f, indexname); - } - indexname = smiGetElementNode(smiElement)->name; - } - if (indexname) { - fprintf(f, "%s%s%s", - (i > 0) ? "," : "", - (smiNode->implied) ? "*" : "", - indexname); - } -} - - - -static void fprintObjects(FILE *f, SmiNode *smiNode) -{ - char *objectname; - int i; - SmiElement *smiElement; - - objectname = NULL; - for (i = -1, smiElement = smiGetFirstElement(smiNode); - smiElement; - smiElement = smiGetNextElement(smiElement), i++) { - if (i > 0) fprintf(f, ","); - if (objectname) { - fprintf(f, objectname); - } - objectname = smiGetElementNode(smiElement)->name; - } - if (objectname) { - fprintf(f, "%s%s", (i > 0) ? "," : "", objectname); - } -} - - - -static int isPartOfLoadedModules(SmiNode *smiNode) -{ - SmiModule *smiModule; - int i; - - smiModule = smiGetNodeModule(smiNode); - - for (i = 0; i < pmodc; i++) { - if (strcmp(pmodv[i]->name, smiModule->name) == 0) { - return 1; - } - } - return 0; -} - -/* - * The following function pruneSubTree() is tricky. There are some - * interactions between the supported options. See the detailed - * comments below. Good examples to test the implemented behaviour - * are: - * - * smidump -u -f tree --tree-no-leaf IF-MIB ETHER-CHIPSET-MIB - * - * (And the example above does _not_ work in combination with - * --tree-no-conformance so the code below is still broken.) - */ - -static int pruneSubTree(SmiNode *smiNode) -{ - SmiNode *childNode; - - const int confmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE); - const int leafmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE - | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR - | SMI_NODEKIND_ROW | SMI_NODEKIND_NOTIFICATION); - - if (! smiNode) { - return 1; - } - - /* - * First, prune all nodes which the user has told us to ignore. - * In the case of ignoreleafs, we have to special case nodes with - * an unknown status (which actually represent OBJECT-IDENTITY - * definitions). More special case code is needed to exclude - * module identity nodes. - */ - - if (ignoreconformance && (smiNode->nodekind & confmask)) { - return 1; - } - - if (ignoreleafs) { - if (smiNode->nodekind & leafmask) { - return 1; - } - if (smiNode->nodekind == SMI_NODEKIND_NODE - && smiNode->status != SMI_STATUS_UNKNOWN) { - SmiModule *smiModule = smiGetNodeModule(smiNode); - if (smiModule && smiNode != smiGetModuleIdentityNode(smiModule)) { - return 1; - } - } - } - - /* - * Next, generally do not prune nodes that belong to the set of - * modules we are looking at. - */ - - if (isPartOfLoadedModules(smiNode)) { - if (!ignoreconformance || !smiGetFirstChildNode(smiNode)) { - return 0; - } - } - - /* - * Finally, prune all nodes where all child nodes are pruned. - */ - - for (childNode = smiGetFirstChildNode(smiNode); - childNode; - childNode = smiGetNextChildNode(childNode)) { - - /* - * In the case of ignoreleafs, we have to peek at the child - * nodes. Otherwise, we would prune too much. we still want to - * see the path to the leafs we have pruned away. This also - * interact with the semantics of ignoreconformance since we - * still want in combination with ignoreleafs to see the path - * to the pruned conformance leafs. - */ - - if (ignoreleafs && (childNode->nodekind & leafmask)) { - if (isPartOfLoadedModules(childNode)) { - if (ignoreconformance && (childNode->nodekind & confmask)) { - return 1; - } - return 0; - } - } - - if (! pruneSubTree(childNode)) { - return 0; - } - } - - return 1; -} - - - -static void fprintSubTree(FILE *f, SmiNode *smiNode, - char *prefix, size_t typefieldlen) -{ - SmiNode *childNode, *indexNode; - SmiNodekind lastNodeKind = SMI_NODEKIND_UNKNOWN; - SmiType *type; - int i = 0, cnt, prefixlen; - size_t newtypefieldlen = 9; - char c = 0; - char *type_name; - - if (smiNode) { - prefixlen = strlen(prefix); - switch (smiNode->nodekind) { - case SMI_NODEKIND_SCALAR: - case SMI_NODEKIND_COLUMN: - if (prefixlen > 0) { - c = prefix[prefixlen-1]; - prefix[prefixlen-1] = getStatusChar(smiNode->status); - } - type_name = getTypeName(smiNode); - if (type_name) { - fprintf(f, "%s-- %s %-*s %s(%u)\n", - prefix, - getFlags(smiNode), - typefieldlen, - type_name, - smiNode->name, - smiNode->oid[smiNode->oidlen-1]); - xfree(type_name); - } - if (prefixlen > 0 && c) { - prefix[prefixlen-1] = c; - } - break; - case SMI_NODEKIND_ROW: - if (prefixlen > 0) { - c = prefix[prefixlen-1]; - prefix[prefixlen-1] = getStatusChar(smiNode->status); - } - fprintf(f, "%s--%s(%u) [", prefix, - smiNode->name, - smiNode->oid[smiNode->oidlen-1]); - switch (smiNode->indexkind) { - case SMI_INDEX_INDEX: - case SMI_INDEX_REORDER: - fprintIndex(f, smiNode); - break; - case SMI_INDEX_EXPAND: /* TODO: we have to do more work here! */ - break; - case SMI_INDEX_AUGMENT: - case SMI_INDEX_SPARSE: - indexNode = smiGetRelatedNode(smiNode); - if (indexNode) { - fprintIndex(f, indexNode); - } - break; - case SMI_INDEX_UNKNOWN: - break; - } - fprintf(f, "]\n"); - if (prefixlen > 0 && c) { - prefix[prefixlen-1] = c; - } - break; - case SMI_NODEKIND_NOTIFICATION: - if (prefixlen > 0) { - c = prefix[prefixlen-1]; - prefix[prefixlen-1] = getStatusChar(smiNode->status); - } - fprintf(f, "%s--%s(%u) [", prefix, - smiNode->name, - smiNode->oid[smiNode->oidlen-1]); - fprintObjects(f, smiNode); - fprintf(f, "]\n"); - if (prefixlen > 0 && c) { - prefix[prefixlen-1] = c; - } - break; - default: - if (prefixlen > 0) { - c = prefix[prefixlen-1]; - prefix[prefixlen-1] = getStatusChar(smiNode->status); - } - if (smiNode->oid) - if (prefixlen > 0) { - fprintf(f, "%s--%s(%u)\n", prefix, - smiNode->name ? smiNode->name : " ", - smiNode->oid[smiNode->oidlen-1]); - } else { - unsigned int j; - fprintf(f, "%s--%s(", prefix, - smiNode->name ? smiNode->name : " "); - for (j = 0; j < smiNode->oidlen; j++) { - fprintf(f, "%s%u", j ? "." : "", smiNode->oid[j]); - } - fprintf(f, ")\n"); - } - else - fprintf(f, "%s--%s(?)\n", prefix, - smiNode->name ? smiNode->name : " "); - if (prefixlen > 0 && c) { - prefix[prefixlen-1] = c; - } - } - for (childNode = smiGetFirstChildNode(smiNode), cnt = 0; - childNode; - childNode = smiGetNextChildNode(childNode)) { - if (! pruneSubTree(childNode)) { - type = smiGetNodeType(childNode); - if (type) { - type_name = getTypeName(childNode); - if (type_name) { - if (strlen(type_name) > newtypefieldlen) { - newtypefieldlen = strlen(type_name); - } - xfree(type_name); - } - } - cnt++; - } - } - for (childNode = smiGetFirstChildNode(smiNode); - childNode; - childNode = smiGetNextChildNode(childNode)) { - char *newprefix; - if (pruneSubTree(childNode)) { - continue; - } - i++; - if (! compact && - ((childNode->nodekind != SMI_NODEKIND_COLUMN - && childNode->nodekind != SMI_NODEKIND_SCALAR) - || (lastNodeKind != childNode->nodekind))) { - fprintf(f, "%s |\n", prefix); - } - newprefix = xmalloc(strlen(prefix)+10); - strcpy(newprefix, prefix); - if (cnt == 1 || cnt == i) { - strcat(newprefix, " "); - } else { - strcat(newprefix, " |"); - } - fprintSubTree(f, childNode, newprefix, newtypefieldlen); - xfree(newprefix); - lastNodeKind = childNode->nodekind; - } - } -} - - - -static void fprintTree(FILE *f) -{ - SmiNode *smiNode; - SmiNode *childNode; - SmiNode *nextNode; - int cnt; - - smiNode = smiGetNode(NULL, "iso"); - - if (! full) { - do { - for (childNode = smiGetFirstChildNode(smiNode), cnt = 0, nextNode = NULL; - childNode; - childNode = smiGetNextChildNode(childNode)) { - if (! pruneSubTree(childNode)) { - cnt++; - if (! nextNode) { - nextNode = childNode; - } - } - } - if (cnt == 1) { - smiNode = nextNode; - } - } while (cnt == 1); - } - - if (smiNode) { - fprintSubTree(f, smiNode, "", 0); - } -} - - - -static void dumpTree(int modc, SmiModule **modv, int flags, char *output) -{ - int i; - FILE *f = stdout; - - if (output) { - f = fopen(output, "w"); - if (!f) { - fprintf(stderr, "smidump: cannot open %s for writing: ", output); - perror(NULL); - exit(1); - } - } - - if (flags & SMIDUMP_FLAG_UNITE) { - - pmodc = modc; - pmodv = modv; - - if (! (flags & SMIDUMP_FLAG_SILENT)) { - fprintf(f, "# united registration tree (generated by smidump " - SMI_VERSION_STRING ")\n\n"); - } - if (! (flags & SMIDUMP_FLAG_SILENT) && (flags & SMIDUMP_FLAG_ERROR)) { - fprintf(f, "# WARNING: this output may be incorrect due to " - "significant parse errors\n\n"); - } - fprintTree(f); - - } else { - - for (i = 0; i < modc; i++) { - - pmodc = 1; - pmodv = &(modv[i]); - - if (! (flags & SMIDUMP_FLAG_SILENT)) { - fprintf(f, "# %s registration tree (generated by smidump " - SMI_VERSION_STRING ")\n\n", modv[i]->name); - } - if (! (flags & SMIDUMP_FLAG_SILENT) && (flags & SMIDUMP_FLAG_ERROR)) { - fprintf(f, "# WARNING: this output may be incorrect due to " - "significant parse errors\n\n"); - } - fprintTree(f); - } - } - - if (fflush(f) || ferror(f)) { - perror("smidump: write error"); - exit(1); - } - - if (output) { - fclose(f); - } -} - - - -void initTree() -{ - static SmidumpDriverOption opt[] = { - { "no-conformance", OPT_FLAG, &ignoreconformance, 0, - "do not show conformance nodes"}, - { "no-leafs", OPT_FLAG, &ignoreleafs, 0, - "do not show leaf nodes"}, - { "full-root", OPT_FLAG, &full, 0, - "generate the full path to the root"}, - { "compact", OPT_FLAG, &compact, 0, - "generate a more compact representation"}, - { 0, OPT_END, 0, 0 } - }; - - static SmidumpDriver driver = { - "tree", - dumpTree, - SMI_FLAG_NODESCR, - 0, - "structure of the OID tree", - opt, - NULL - }; - - smidumpRegisterDriver(&driver); -} diff --git a/tools/smicache.in b/tools/smicache.in index 5ebee93..fa83eb5 100644 --- a/tools/smicache.in +++ b/tools/smicache.in @@ -44,7 +44,7 @@ do_usage () { do_fetch () { - $WGET -q -e "timestamping = off" -O "$dir/$1" "$prefix/$1" + $WGET -q -O "$dir/$1" "$prefix/$1" } diff --git a/tools/smicache.in.wget111 b/tools/smicache.in.wget111 deleted file mode 100644 index fa83eb5..0000000 --- a/tools/smicache.in.wget111 +++ /dev/null @@ -1,80 +0,0 @@ -#!@SH@ -# -# smicache -- -# -# A simple caching method, used by the config file `cache' directive. -# -# Copyright (c) 2001 Frank Strauss, Technical University of Braunschweig. -# -# See the file "COPYING" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# $Id: smicache.in 8090 2008-04-18 12:56:29Z strauss $ -# -# NOTE, that this script relies on wget and getopts -# (shell builtin like in bash or standalone). -# -# NOTE, that smicache has just been an experiment. It is NOT suggested -# to use it in a production environment. - -WGET=@WGET@ -GETOPTS=getopts -VERSION=@VERSION@ - -prefix=http://www.ibr.cs.tu-bs.de/projects/libsmi/smicache/ -dir=/tmp - - - -do_version () { - echo "smicache $VERSION" -} - - - -do_usage () { - echo "Usage: smicache [-Vh] [-d dir] [-p prefix] mib" - echo "-V show version and license information" - echo "-h show usage information" - echo "-d dir use dir as the caching directory" - echo "-p prefix use prefix as the URL prefix for fetching modules" - echo "mib name of the module to be fetched" -} - - - -do_fetch () { - $WGET -q -O "$dir/$1" "$prefix/$1" -} - - - -while $GETOPTS Vhd:p: c ; do - case $c in - d) dir="$OPTARG" - ;; - p) prefix="$OPTARG" - ;; - h) do_usage - exit 0 - ;; - V) do_version - exit 0 - ;; - *) do_usage - exit 1 - ;; - esac -done - -shift `expr $OPTIND - 1` - - - -if [ $# -eq 1 ] ; then - do_fetch $1 -else - do_usage -fi - -exit 0