static void fprintModule(FILE *f, SmiModule *smiModule) { SmiRevision *smiRevision; SmiNode *smiNode; int i; char *lang; lang = getStringLanguage(smiModule->language); fprintSegment(f, INDENT, "", 0); if (lang) { fprint(f, "<module name=\"%s\" language=\"%s\">\n", smiModule->name, lang); } else { fprint(f, "<module name=\"%s\">\n", smiModule->name); } if (smiModule->organization) { fprintSegment(f, 2 * INDENT, "<organization>", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiModule->organization); fprint(f, "\n"); fprintSegment(f, 2 * INDENT, "</organization>\n", 0); } if (smiModule->contactinfo) { fprintSegment(f, 2 * INDENT, "<contact>", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiModule->contactinfo); fprint(f, "\n"); fprintSegment(f, 2 * INDENT, "</contact>\n", 0); } fprintDescription(f, 2 * INDENT, smiModule->description); fprintReference(f, 2 * INDENT, smiModule->reference); for(i = 0, smiRevision = smiGetFirstRevision(smiModule); smiRevision; smiRevision = smiGetNextRevision(smiRevision)) { fprintSegment(f, 2 * INDENT, "", 0); fprint(f, "<revision date=\"%s\">\n", getTimeString(smiRevision->date)); fprintDescription(f, 3 * INDENT, smiRevision->description); fprintSegment(f, 2 * INDENT, "</revision>\n", 0); i++; } smiNode = smiGetModuleIdentityNode(smiModule); if (smiNode) { fprintSegment(f, 2 * INDENT, "", 0); fprint(f, "<identity node=\"%s\"/>\n", smiNode->name); } fprintSegment(f, INDENT, "</module>\n\n", 0); }
static void fprintReference(FILE *f, int indent, const char *reference) { if (reference) { fprintSegment(f, indent, "<reference>\n", 0); fprintMultilineString(f, indent, reference); fprint(f, "\n"); fprintSegment(f, indent, "</reference>\n", 0); } }
static void fprintDescription(FILE *f, int indent, const char *description) { if (description) { fprintSegment(f, indent, "<description>\n", 0); fprintMultilineString(f, indent, description); fprint(f, "\n"); fprintSegment(f, indent, "</description>\n", 0); } }
static void fprintRevisions(FILE *f, SmiModule *smiModule) { int i; SmiRevision *smiRevision; for(i = 0, smiRevision = smiGetFirstRevision(smiModule); smiRevision; smiRevision = smiGetNextRevision(smiRevision)) { fprintSegment(f, INDENT, "revision {\n", 0); fprintSegment(f, 2 * INDENT, "date", INDENTVALUE); fprint(f, "\"%s\";\n", getStringTime(smiRevision->date)); fprintSegment(f, 2 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiRevision->description); fprint(f, ";\n"); fprintSegment(f, INDENT, "};\n", 0); i++; } if (i) { fprint(f, "\n"); } }
static void fprintNotifications(FILE *f, SmiModule *smiModule) { int i, j; SmiNode *smiNode; SmiElement *smiElement; for(i = 0, smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_NOTIFICATION); smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_NOTIFICATION)) { if (!i && !silent) { fprint(f, "//\n// NOTIFICATION DEFINITIONS\n//\n\n"); } fprintSegment(f, INDENT, "", 0); fprint(f, "notification %s {\n", smiNode->name); if (smiNode->oid) { fprintSegment(f, 2 * INDENT, "oid", INDENTVALUE); fprint(f, "%s;\n", getOidString(smiNode, 0)); } if ((smiElement = smiGetFirstElement(smiNode))) { fprintSegment(f, 2 * INDENT, "objects", INDENTVALUE); fprint(f, "("); for (j = 0; smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } if ((smiNode->status != SMI_STATUS_CURRENT) && (smiNode->status != SMI_STATUS_UNKNOWN) && (smiNode->status != SMI_STATUS_MANDATORY) && (smiNode->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, 2 * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiNode->status)); } if (smiNode->description) { fprintSegment(f, 2 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiNode->description); fprint(f, ";\n"); } if (smiNode->reference) { fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiNode->reference); fprint(f, ";\n"); } fprintSegment(f, INDENT, "", 0); fprint(f, "};\n\n"); i++; } }
static void fprintObjects(FILE *f, SmiModule *smiModule) { int i, j; SmiNode *smiNode, *relatedNode; SmiElement *smiElement; SmiType *smiType; int indent = 0; int lastindent = -1; char *s = NULL; SmiNodekind nodekinds; nodekinds = SMI_NODEKIND_NODE | SMI_NODEKIND_TABLE | SMI_NODEKIND_ROW | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR | SMI_NODEKIND_CAPABILITIES; for(i = 0, smiNode = smiGetFirstNode(smiModule, nodekinds); smiNode; smiNode = smiGetNextNode(smiNode, nodekinds)) { if (smiNode->nodekind == SMI_NODEKIND_NODE) { indent = 0; s = "node"; } else if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) { indent = 0; s = "node"; } else if (smiNode->nodekind == SMI_NODEKIND_TABLE) { indent = 0; s = "table"; } else if (smiNode->nodekind == SMI_NODEKIND_ROW) { indent = 1; s = "row"; } else if (smiNode->nodekind == SMI_NODEKIND_COLUMN) { indent = 2; s = "column"; } else if (smiNode->nodekind == SMI_NODEKIND_SCALAR) { indent = 0; s = "scalar"; } if (!i && !silent) { fprint(f, "//\n// OBJECT DEFINITIONS\n//\n\n"); } for (j = lastindent; j >= indent; j--) { fprintSegment(f, (1 + j) * INDENT, "", 0); fprint(f, "};\n"); } fprint(f, "\n"); lastindent = indent; if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) { fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "-- This has been an SMIv2 AGENT-CAPABILITIES node:\n"); } fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "%s %s {\n", s, smiNode->name); if (smiNode->oid) { fprintSegment(f, (2 + indent) * INDENT, "oid", INDENTVALUE); fprint(f, "%s;\n", getOidString(smiNode, 0)); } smiType = smiGetNodeType(smiNode); if (smiType && (smiType->basetype != SMI_BASETYPE_UNKNOWN)) { fprintSegment(f, (2 + indent) * INDENT, "type", INDENTVALUE); if (!smiType->name) { /* * an implicitly restricted type. */ fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); } else { fprint(f, "%s;\n", getTypeString(smiType->basetype, smiType)); } } if ((smiNode->nodekind != SMI_NODEKIND_TABLE) && (smiNode->nodekind != SMI_NODEKIND_ROW) && (smiNode->nodekind != SMI_NODEKIND_CAPABILITIES) && (smiNode->nodekind != SMI_NODEKIND_NODE)) { if (smiNode->access != SMI_ACCESS_UNKNOWN) { fprintSegment(f, (2 + indent) * INDENT, "access", INDENTVALUE); fprint(f, "%s;\n", getAccessString(smiNode->access)); } } relatedNode = smiGetRelatedNode(smiNode); switch (smiNode->indexkind) { case SMI_INDEX_INDEX: if (smiNode->implied) { fprintSegment(f, (2 + indent) * INDENT, "index implied", INDENTVALUE); } else { fprintSegment(f, (2 + indent) * INDENT, "index", INDENTVALUE); } fprint(f, "("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); break; case SMI_INDEX_AUGMENT: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "augments", INDENTVALUE); fprint(f, "%s;\n", relatedNode->name); /* TODO: non-local name if non-local */ } /* TODO: else print error */ break; case SMI_INDEX_REORDER: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "", 0); fprint(f, "reorders %s", relatedNode->name); /* TODO: non-local name if non-local */ if (smiNode->implied) { fprint(f, " implied"); } fprint(f, " ("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } /* TODO: else print error */ break; case SMI_INDEX_SPARSE: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "sparse", INDENTVALUE); fprint(f, "%s;\n", relatedNode->name); /* TODO: non-local name if non-local */ } /* TODO: else print error */ break; case SMI_INDEX_EXPAND: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "", 0); fprint(f, "expands %s", relatedNode->name); /* TODO: non-local name if non-local */ if (smiNode->implied) { fprint(f, " implied"); } fprint(f, " ("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } /* TODO: else print error */ break; case SMI_INDEX_UNKNOWN: break; } if (smiNode->create) { fprintSegment(f, (2 + indent) * INDENT, "create", INDENTVALUE); /* TODO: create list */ fprint(f, ";\n"); } if (smiNode->value.basetype != SMI_BASETYPE_UNKNOWN) { fprintSegment(f, (2 + indent) * INDENT, "default", INDENTVALUE); fprint(f, "%s", getValueString(&smiNode->value, smiType)); fprint(f, ";\n"); } if (smiNode->format) { fprintSegment(f, (2 + indent) * INDENT, "format", INDENTVALUE); fprint(f, "\"%s\";\n",smiNode->format); } if (smiNode->units) { fprintSegment(f, (2 + indent) * INDENT, "units", INDENTVALUE); fprint(f, "\"%s\";\n", smiNode->units); } if ((smiNode->status != SMI_STATUS_CURRENT) && (smiNode->status != SMI_STATUS_UNKNOWN) && (smiNode->status != SMI_STATUS_MANDATORY) && (smiNode->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, (2 + indent) * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiNode->status)); } if (smiNode->description) { fprintSegment(f, (2 + indent) * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, (2 + indent) * INDENT, smiNode->description); fprint(f, ";\n"); } if (smiNode->reference) { fprintSegment(f, (2 + indent) * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, (2 + indent) * INDENT, smiNode->reference); fprint(f, ";\n"); } i++; } if (i) { fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "};\n\n"); } }
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 dumpSming(int modc, SmiModule **modv, int flags, char *output) { SmiModule *smiModule; SmiNode *smiNode; int i; FILE *f = stdout; silent = (flags & SMIDUMP_FLAG_SILENT); if (output) { f = fopen(output, "w"); if (!f) { fprintf(stderr, "smidump: cannot open %s for writing: ", output); perror(NULL); exit(1); } } for (i = 0; i < modc; i++) { smiModule = modv[i]; fprint(f, "//\n"); fprint(f, "// This module has been generated by smidump " SMI_VERSION_STRING ". Do not edit.\n"); fprint(f, "//\n"); fprint(f, "module %s ", smiModule->name); fprint(f, "{\n"); fprint(f, "\n"); fprintImports(f, smiModule); if (! silent) { fprint(f, "//\n// MODULE META INFORMATION\n//\n\n"); } fprintSegment(f, INDENT, "organization", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, INDENT, smiModule->organization); fprint(f, ";\n\n"); fprintSegment(f, INDENT, "contact", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, INDENT, smiModule->contactinfo); fprint(f, ";\n\n"); fprintSegment(f, INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, INDENT, smiModule->description); fprint(f, ";\n\n"); if (smiModule->reference) { fprintSegment(f, INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, INDENT, smiModule->reference); fprint(f, ";\n\n"); } fprintRevisions(f, smiModule); smiNode = smiGetModuleIdentityNode(smiModule); if (smiNode) { fprintSegment(f, INDENT, "identity", INDENTVALUE); fprint(f, "%s;\n\n", smiNode->name); } fprintTypedefs(f, smiModule); fprintObjects(f, smiModule); fprintNotifications(f, smiModule); fprintGroups(f, smiModule); fprintCompliances(f, smiModule); fprint(f, "}; // end of module %s.\n", smiModule->name); } if (fflush(f) || ferror(f)) { perror("smidump: write error"); exit(1); } if (output) { fclose(f); } }
static void fprintCompliances(FILE *f, SmiModule *smiModule) { int i, j; SmiNode *smiNode, *smiNode2; SmiType *smiType; SmiOption *smiOption; SmiRefinement *smiRefinement; SmiElement *smiElement; for(i = 0, smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_COMPLIANCE); smiNode; smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_COMPLIANCE)) { if (!i && !silent) { fprint(f, "//\n// COMPLIANCE DEFINITIONS\n//\n\n"); } fprintSegment(f, INDENT, "", 0); fprint(f, "compliance %s {\n", smiNode->name); if (smiNode->oid) { fprintSegment(f, 2 * INDENT, "oid", INDENTVALUE); fprint(f, "%s;\n", getOidString(smiNode, 0)); } if ((smiNode->status != SMI_STATUS_CURRENT) && (smiNode->status != SMI_STATUS_UNKNOWN) && (smiNode->status != SMI_STATUS_MANDATORY) && (smiNode->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, 2 * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiNode->status)); } if (smiNode->description) { fprintSegment(f, 2 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiNode->description); fprint(f, ";\n"); } if (smiNode->reference) { fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiNode->reference); fprint(f, ";\n"); } if ((smiElement = smiGetFirstElement(smiNode))) { fprint(f, "\n"); fprintSegment(f, 2 * INDENT, "mandatory", INDENTVALUE); fprint(f, "("); for (j = 0; smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } if ((smiOption = smiGetFirstOption(smiNode))) { fprint(f, "\n"); for(; smiOption; smiOption = smiGetNextOption(smiOption)) { smiNode2 = smiGetOptionNode(smiOption); fprintSegment(f, 2 * INDENT, "", 0); fprint(f, "optional %s {\n", smiNode2->name); fprintSegment(f, 3 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 3 * INDENT, smiOption->description); fprint(f, ";\n"); fprintSegment(f, 2 * INDENT, "};\n", 0); } } if ((smiRefinement = smiGetFirstRefinement(smiNode))) { fprint(f, "\n"); for(; smiRefinement; smiRefinement = smiGetNextRefinement(smiRefinement)) { fprintSegment(f, 2 * INDENT, "", 0); fprint(f, "refine %s {\n", smiGetRefinementNode(smiRefinement)->name); smiType = smiGetRefinementType(smiRefinement); if (smiType) { fprintSegment(f, 3 * INDENT, "type", INDENTVALUE); fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); } smiType = smiGetRefinementWriteType(smiRefinement); if (smiType) { fprintSegment(f, 3 * INDENT, "writetype", INDENTVALUE); fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); } if (smiRefinement->access != SMI_ACCESS_UNKNOWN) { fprintSegment(f, 3 * INDENT, "access", INDENTVALUE); fprint(f, "%s;\n", getAccessString(smiRefinement->access)); } fprintSegment(f, 3 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 3 * INDENT, smiRefinement->description); fprint(f, ";\n"); fprintSegment(f, 2 * INDENT, "};\n", 0); } } fprintSegment(f, INDENT, "", 0); fprint(f, "};\n\n"); i++; } }