static int calcSize(SmiModule *smiModule) { SmiNode *smiNode; SmiType *smiType; int size = 0; for (smiType = smiGetFirstType(smiModule); smiType; smiType = smiGetNextType(smiType)) { if (smiType->name) { size++; } } for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY); smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) { switch (smiNode->nodekind) { case SMI_NODEKIND_SCALAR: case SMI_NODEKIND_COLUMN: case SMI_NODEKIND_NOTIFICATION: size++; break; default: break; } } return size; }
static void fprintTypedefs(FILE *f, SmiModule *smiModule) { int i; SmiType *smiType; for(i = 0, smiType = smiGetFirstType(smiModule); smiType; i++, smiType = smiGetNextType(smiType)) { if (i == 0) { fprintSegment(f, INDENT, "<typedefs>\n", 0); } fprintTypedef(f, 2 * INDENT, smiType); } if (i) { fprintSegment(f, INDENT, "</typedefs>\n\n", 0); } }
static void fprintTypedefs(FILE *f, SmiModule *smiModule) { int i, j; SmiType *smiType; for(i = 0, smiType = smiGetFirstType(smiModule); smiType; smiType = smiGetNextType(smiType)) { if ((!(strcmp(smiModule->name, "SNMPv2-SMI"))) || (!(strcmp(smiModule->name, "RFC1155-SMI")))) { for(j=0; excludeType[j]; j++) { if (!strcmp(smiType->name, excludeType[j])) break; } if (excludeType[j]) break; } if (!i && !silent) { fprint(f, "//\n// TYPE DEFINITIONS\n//\n\n"); } fprintSegment(f, INDENT, "", 0); fprint(f, "typedef %s {\n", smiType->name); fprintSegment(f, 2 * INDENT, "type", INDENTVALUE); fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); if (smiType->value.basetype != SMI_BASETYPE_UNKNOWN) { fprintSegment(f, 2 * INDENT, "default", INDENTVALUE); fprint(f, "%s", getValueString(&smiType->value, smiType)); fprint(f, ";\n"); } if (smiType->format) { fprintSegment(f, 2 * INDENT, "format", INDENTVALUE); fprint(f, "\"%s\";\n", smiType->format); } if (smiType->units) { fprintSegment(f, 2 * INDENT, "units", INDENTVALUE); fprint(f, "\"%s\";\n", smiType->units); } if ((smiType->status != SMI_STATUS_CURRENT) && (smiType->status != SMI_STATUS_UNKNOWN) && (smiType->status != SMI_STATUS_MANDATORY) && (smiType->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, 2 * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiType->status)); } fprintSegment(f, 2 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiType->description); fprint(f, ";\n"); if (smiType->reference) { fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiType->reference); fprint(f, ";\n"); } fprintSegment(f, INDENT, "};\n\n", 0); i++; } }
static void addMetrics(Metrics *metrics, SmiModule *smiModule) { SmiNode *smiNode; SmiType *smiType; size_t len; for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY); smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) { len = smiNode->description ? strlen(smiNode->description) : 0; switch (smiNode->nodekind) { case SMI_NODEKIND_TABLE: incrStatusCounter(&metrics->statusTables, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); incrLengthCounter(&metrics->lengthTables, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrLengthCounter(&metrics->lengthAll, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); break; case SMI_NODEKIND_ROW: incrIndexCounter(&metrics->indexTables, smiNode->indexkind); incrLengthCounter(&metrics->lengthRows, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrLengthCounter(&metrics->lengthAll, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrRowStatusCounter(smiNode); { int cnt = 0; foreachIndexDo(NULL, smiNode, count, &cnt); incrIndexLenCounter(&metrics->indexLenTables, cnt); foreachIndexDo(NULL, smiNode, yadayada, smiModule); } { int cmplx = 0; foreachIndexDo(NULL, smiNode, complexity, &cmplx); incrIndexComplexityCounter(smiModule, smiNode, cmplx); incrIndexComplexityMetric(&metrics->indexComplexity, cmplx); } // count the childs ... { SmiModule *smiModule = smiGetModule("SNMPv2-TC"); SmiNode *childNode; SmiType *rowStatus = smiGetType(smiModule, "RowStatus"); SmiType *storageType = smiGetType(smiModule, "StorageType"); // include index elements not in table int n = 0; for (childNode = smiGetFirstChildNode(smiNode); childNode; childNode = smiGetNextChildNode(childNode)) { n++; if (rowStatus == smiGetNodeType(childNode)) { fprintf(stderr, "**** GEEEEEE - ROWSTATUS\n"); } if (storageType == smiGetNodeType(childNode)) { fprintf(stderr, "**** GEEEEEE - STORAGETYPE\n"); } } incrTableLenCounter(&metrics->tableLength, n); } break; case SMI_NODEKIND_COLUMN: incrBasetypeCounter(&metrics->basetypesColumns, smiNode); incrBasetypeCounter(&metrics->basetypesAll, smiNode); incrStatusCounter(&metrics->statusColumns, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); incrAccessCounter(&metrics->accessColumns, smiNode->access); incrAccessCounter(&metrics->accessAll, smiNode->access); incrLengthCounter(&metrics->lengthColumns, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrLengthCounter(&metrics->lengthAll, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrTypeAndNodeUsageCounter(smiModule, smiNode, INCR_TYPE); break; case SMI_NODEKIND_SCALAR: incrBasetypeCounter(&metrics->basetypesScalars, smiNode); incrBasetypeCounter(&metrics->basetypesAll, smiNode); incrStatusCounter(&metrics->statusScalars, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); incrAccessCounter(&metrics->accessScalars, smiNode->access); incrAccessCounter(&metrics->accessAll, smiNode->access); incrLengthCounter(&metrics->lengthScalars, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrLengthCounter(&metrics->lengthAll, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrTypeAndNodeUsageCounter(smiModule, smiNode, INCR_TYPE); break; case SMI_NODEKIND_NOTIFICATION: incrStatusCounter(&metrics->statusNotifications, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); incrLengthCounter(&metrics->lengthNotifications, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); incrLengthCounter(&metrics->lengthAll, smiNode->description, smiNode->reference, smiNode->units, smiNode->format); break; case SMI_NODEKIND_GROUP: incrStatusCounter(&metrics->statusGroups, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); break; case SMI_NODEKIND_COMPLIANCE: incrStatusCounter(&metrics->statusCompliances, smiNode->status); incrStatusCounter(&metrics->statusAll, smiNode->status); break; } } for (smiType = smiGetFirstType(smiModule); smiType; smiType = smiGetNextType(smiType)) { /* * Ignore all types with empty descriptions coming from the * "SNMPv2-SMI" module since they are not really defined * types but part of the language itself. */ if (! smiType->description) { SmiModule *m = smiGetTypeModule(smiType); if (m && strcmp(m->name, "SNMPv2-SMI") == 0) { continue; } } incrStatusCounter(&metrics->statusTypes, smiType->status); incrStatusCounter(&metrics->statusAll, smiType->status); incrLengthCounter(&metrics->lengthTypes, smiType->description, smiType->reference, smiType->units, smiType->format); incrLengthCounter(&metrics->lengthAll, smiType->description, smiType->reference, smiType->units, smiType->format); } }