70#include <sys/socket.h>
73#include <netinet/in.h>
131#define SNMP_OPAQUE 12
142#define SNMP_STATUS 22
144#define SNMP_OPTIONAL 24
146#define RECOMMENDED 26
150#define LEFTBRACKET 30
151#define RIGHTBRACKET 31
156#define DESCRIPTION 35
169 {
"obsolete",
sizeof(
"obsolete") - 1,
OBSOLETE},
171 {
"recommended",
sizeof(
"recommended") - 1,
RECOMMENDED},
173 {
"mandatory",
sizeof(
"mandatory") - 1,
MANDATORY},
174 {
"current",
sizeof(
"current") - 1,
MANDATORY},
175 {
"not-accessible",
sizeof(
"not-accessible") - 1,
NOACCESS},
176 {
"write-only",
sizeof(
"write-only") - 1,
WRITEONLY},
177 {
"read-write",
sizeof(
"read-write") - 1,
READWRITE},
178 {
"TimeTicks",
sizeof(
"TimeTicks") - 1,
TIMETICKS},
179 {
"OBJECTIDENTIFIER",
sizeof(
"OBJECTIDENTIFIER") - 1,
OBJID},
184 {
"OBJECT",
sizeof(
"OBJECT") - 1,
CONTINUE},
185 {
"NetworkAddress",
sizeof(
"NetworkAddress") - 1,
NETADDR},
186 {
"Gauge",
sizeof(
"Gauge") - 1,
GAUGE},
187 {
"OCTETSTRING",
sizeof(
"OCTETSTRING") - 1,
OCTETSTR},
188 {
"OCTET",
sizeof(
"OCTET") - 1, -1},
189 {
"OF",
sizeof(
"OF") - 1,
OF},
190 {
"SEQUENCE",
sizeof(
"SEQUENCE") - 1,
SEQUENCE},
191 {
"NULL",
sizeof(
"NULL") - 1,
NUL},
192 {
"IpAddress",
sizeof(
"IpAddress") - 1,
IPADDR},
193 {
"INTEGER",
sizeof(
"INTEGER") - 1,
INTEGER},
194 {
"Counter",
sizeof(
"Counter") - 1,
COUNTER},
195 {
"read-only",
sizeof(
"read-only") - 1,
READONLY},
196 {
"ACCESS",
sizeof(
"ACCESS") - 1,
ACCESS},
197 {
"MAX-ACCESS",
sizeof(
"MAX-ACCESS") - 1,
ACCESS},
199 {
"SYNTAX",
sizeof(
"SYNTAX") - 1,
SYNTAX},
200 {
"OBJECT-TYPE",
sizeof(
"OBJECT-TYPE") - 1,
OBJTYPE},
203 {
"::=",
sizeof(
"::=") - 1,
EQUALS},
206 {
",",
sizeof(
",") - 1,
COMMA},
207 {
"DESCRIPTION",
sizeof(
"DESCRIPTION") - 1,
DESCRIPTION},
208 {
"INDEX",
sizeof(
"INDEX") - 1,
INDEX},
209 {
"\"",
sizeof(
"\"") - 1,
QUOTE},
212 {
"read-create",
sizeof(
"read-create") - 1,
READWRITE},
217#define BUCKET(x) (x & 0x01F)
224 register struct tok *tp;
225 register const char *cp;
231 for (h = 0, cp = tp->
name; *cp; cp++)
242#define NBUCKET(x) (x & 0x7F)
248 register struct node *np, *nextp;
253 for (np = nodes; np;) {
256 for (cp = np->
parent; *cp; cp++)
283 for (count = 0; count < 40; count++) {
338 for (cp = tp->
label; *cp; cp++)
345 for (np = *headp; np; np = np->
next) {
357 if (child_list ==
NULL) {
358 child_list = childp = np;
376 for (np = child_list; np; np = np->
next) {
411 int bucket, nodes_left = 0;
419 strcpy(tp->
label,
"iso");
428 for (bucket = 0; bucket <
NHASHSIZE; bucket++) {
435 snmplib_debug(0,
"The mib description doesn't seem to be consistent.\n");
436 snmplib_debug(0,
"Some nodes couldn't be linked under the \"iso\" tree.\n");
438 for (bucket = 0; bucket <
NHASHSIZE; bucket++) {
457 register char *cp = token;
458 register int hash = 0;
459 register struct tok *tp;
462 ch = (
unsigned char)
last;
480 if (
xisspace(ch) || ch ==
'(' || ch ==
')' ||
481 ch ==
'{' || ch ==
'}' || ch ==
',' ||
503 while ((ch = getc(fp)) != -1)
513 for (cp =
token; *cp; cp++)
524 }
while ((ch = getc(fp)) != -1);
537getoid(
register FILE *fp,
register struct subid *SubOid,
int length)
549 for (count = 0; count < length; count++, SubOid++) {
624 register struct subid *op, *nop;
626 struct subid SubOid[32];
627 struct node *np, *root, *oldnp =
NULL;
634 if ((length =
getoid(fp, SubOid, 32)) != 0) {
636 memset((
char *) np,
'\0',
sizeof(
struct node));
641 for (count = 0, op = SubOid, nop = SubOid + 1; count < (length - 2); count++,
644 if (op->label && (nop->
label || (nop->
subid != -1))) {
645 strncpy(np->parent, op->label,
sizeof(np->parent) - 1);
647 strncpy(np->label, nop->
label,
sizeof(np->label) - 1);
648 if (nop->
subid != -1)
649 np->subid = nop->
subid;
653 np->next = (
struct node *)
xmalloc(
sizeof(*np->next));
654 memset((
char *) np->next,
'\0',
sizeof(
struct node));
666 if (count == (length - 2)) {
668 strncpy(np->parent, op->label,
sizeof(np->parent)-1);
669 strncpy(np->label, name,
sizeof(np->label)-1);
670 if (nop->
subid != -1)
671 np->subid = nop->
subid;
691 for (count = 0, op = SubOid; count < length; count++, op++) {
735 struct subid SubOid[32];
744 print_error(
"Bad format for OBJECT TYPE", token, type);
755 strcpy(syntax, token);
756 if (nexttype ==
OF) {
758 strcat(syntax, nexttoken);
761 strcat(syntax, nexttoken);
766 strcpy(syntax, token);
774 if (np->
enums == 0) {
784 ep->
label = (
char *)
xmalloc((
unsigned) strlen(token) + 1);
785 strcpy(ep->
label, token);
798 ep->
value = atoi(token);
830 strcpy(syntax, token);
838 print_error(
"Should be ACCESS", nexttoken, nexttype);
845 print_error(
"Bad access type", nexttoken, nexttype);
868 print_error(
"Should be DESCRIPTION, INDEX, or EQUALS", token, nexttype);
876 print_error(
"Should be Description open quote", token, nexttype);
886 while ((ReadChar !=
'"') && (ReadChar != -1)) {
888 if (ReadChar ==
'\n')
897 print_error(
"Should be INDEX, or EQUALS", token, nexttype);
907 print_error(
"Should be INDEX left brace", token, type);
917 while ((ReadChar !=
'}') && (ReadChar != -1)) {
919 if (ReadChar ==
'\n')
932 length =
getoid(fp, SubOid, 32);
933 if (length > 1 && length <= 32) {
935 if (SubOid[length - 2].
label) {
941 if (SubOid[length - 1].
subid != -1)
951 for (count = 0; count < length; count++) {
952 if (SubOid[count].
label)
954 SubOid[count].
label = 0;
983 strncpy(name, token, 64);
1045 fp = fopen(filename,
"r");
1052 while ((p = fgets(mbuf, 256, fp)) && strncmp(mbuf,
"DUMMY",
1055 snmplib_debug(0,
"Bad MIB version or tag missing, install original!\n");
1059 if (!strcmp(mbuf,
"DUMMY")) {
struct node * nbuckets[NHASHSIZE]
static void build_translation_table(void)
static struct tok * buckets[HASHSIZE]
int translation_table[40]
static int getoid(register FILE *fp, register struct subid *SubOid, int length)
static int get_token(register FILE *fp, register char *token)
static void free_node(struct node *np)
static struct node * parse(FILE *fp)
static int parse_asntype(FILE *fp)
static void init_node_hash(struct node *nodes)
static void hash_init(void)
static struct node * parse_objectid(FILE *fp, char *name)
static struct node * parse_objecttype(register FILE *fp, char *name)
struct snmp_mib_tree * read_mib(char *filename)
static void free_node_list(struct node *nl)
static void print_error(const char *string, const char *token, int type)
static void do_subtree(struct snmp_mib_tree *root, struct node **nodes)
static struct snmp_mib_tree * build_tree(struct node *nodes)
SQUIDCEXTERN void snmplib_debug(int, const char *,...) PRINTF_FORMAT_ARG2
struct snmp_mib_tree * next_peer
struct snmp_mib_tree * parent
struct snmp_mib_tree * child_list
const char * xstrerr(int error)