static unsigned long getMaxSize(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 = getMaxSize(parentType); if (psize < size) { size = psize; } } return size; }
static SmiInteger32 getAbsMaxEnum(SmiType *smiType) { SmiNamedNumber *nn; SmiInteger32 max = 0; for (nn = smiGetFirstNamedNumber(smiType); nn; nn = smiGetNextNamedNumber(nn)) { if (abs(nn->value.value.integer32) > max) { max = abs(nn->value.value.integer32); } } return max; }
static SmiInteger32 getAbsMinEnum(SmiType *smiType) { SmiNamedNumber *nn; SmiInteger32 min = SMI_BASETYPE_INTEGER32_MAX; for (nn = smiGetFirstNamedNumber(smiType); nn; nn = smiGetNextNamedNumber(nn)) { if (abs(nn->value.value.integer32) < min) { min = abs(nn->value.value.integer32); } } return min; }
static void fprintSubtype(FILE *f, SmiType *smiType) { SmiRange *range; SmiNamedNumber *nn; char s[100]; int i; if ((smiType->basetype == SMI_BASETYPE_ENUM) || (smiType->basetype == SMI_BASETYPE_BITS)) { for(i = 0, nn = smiGetFirstNamedNumber(smiType); nn ; i++, nn = smiGetNextNamedNumber(nn)) { if (i) { fprint(f, ", "); } else { fprint(f, " ("); } sprintf(s, "%s(%s)", nn->name, getValueString(&nn->value, smiType)); fprintWrapped(f, INDENTVALUE + INDENT, s); } if (i) { fprint(f, ")"); } } else { for(i = 0, range = smiGetFirstRange(smiType); range ; i++, range = smiGetNextRange(range)) { if (i) { fprint(f, " | "); } else { fprint(f, " ("); } if (memcmp(&range->minValue, &range->maxValue, sizeof(SmiValue))) { sprintf(s, "%s", getValueString(&range->minValue, smiType)); sprintf(&s[strlen(s)], "..%s", getValueString(&range->maxValue, smiType)); } else { sprintf(s, "%s", getValueString(&range->minValue, smiType)); } fprintWrapped(f, INDENTVALUE + INDENT, s); } if (i) { fprint(f, ")"); } } }
static void fprintNamedNumbers(FILE *f, int indent, SmiType *smiType) { SmiNamedNumber *nn; if ((smiType->basetype != SMI_BASETYPE_ENUM) && (smiType->basetype != SMI_BASETYPE_BITS)) { return; } for (nn = smiGetFirstNamedNumber(smiType); nn; nn = smiGetNextNamedNumber(nn)) { fprintSegment(f, indent, "<namednumber", 0); fprint(f, " name=\"%s\"", nn->name); fprint(f, " number=\"%s\"", getValueString(&nn->value, smiType)); fprint(f, "/>\n"); } }
static char *getValueString(SmiValue *valuePtr, SmiType *typePtr) { static char s[1024]; char ss[9]; int n; unsigned int i; SmiNamedNumber *nn; s[0] = 0; switch (valuePtr->basetype) { case SMI_BASETYPE_UNSIGNED32: sprintf(s, "%lu", valuePtr->value.unsigned32); break; case SMI_BASETYPE_INTEGER32: sprintf(s, "%ld", valuePtr->value.integer32); break; case SMI_BASETYPE_UNSIGNED64: sprintf(s, UINT64_FORMAT, valuePtr->value.unsigned64); break; case SMI_BASETYPE_INTEGER64: sprintf(s, INT64_FORMAT, valuePtr->value.integer64); break; case SMI_BASETYPE_FLOAT32: case SMI_BASETYPE_FLOAT64: case SMI_BASETYPE_FLOAT128: break; case SMI_BASETYPE_ENUM: for (nn = smiGetFirstNamedNumber(typePtr); nn; nn = smiGetNextNamedNumber(nn)) { if (nn->value.value.unsigned32 == valuePtr->value.unsigned32) break; } if (nn) { sprintf(s, "%s", nn->name); } else { sprintf(s, "%ld", valuePtr->value.integer32); } break; case SMI_BASETYPE_OCTETSTRING: for (i = 0; i < valuePtr->len; i++) { if (!isprint((int)valuePtr->value.ptr[i])) break; } if (i == valuePtr->len) { sprintf(s, "\"%s\"", valuePtr->value.ptr); } else { sprintf(s, "0x%*s", 2 * valuePtr->len, ""); for (i=0; i < valuePtr->len; i++) { sprintf(ss, "%02x", valuePtr->value.ptr[i]); strncpy(&s[2+2*i], ss, 2); } } break; case SMI_BASETYPE_BITS: sprintf(s, "("); for (i = 0, n = 0; i < valuePtr->len * 8; i++) { if (valuePtr->value.ptr[i/8] & (1 << (7-(i%8)))) { if (n) sprintf(&s[strlen(s)], ", "); n++; for (nn = smiGetFirstNamedNumber(typePtr); nn; nn = smiGetNextNamedNumber(nn)) { if (nn->value.value.unsigned32 == i) break; } if (nn) { sprintf(&s[strlen(s)], "%s", nn->name); } else { sprintf(s, "%d", i); } } } sprintf(&s[strlen(s)], ")"); break; case SMI_BASETYPE_UNKNOWN: break; case SMI_BASETYPE_POINTER: break; case SMI_BASETYPE_OBJECTIDENTIFIER: for (i = 0; i < valuePtr->len; i++) { sprintf(&s[strlen(s)], i ? ".%u" : "%u", valuePtr->value.oid[i]); } break; } return s; }