init ems server code
This commit is contained in:
4152
plat/snmp/src/mib_parser/snmp_mib.c
Normal file
4152
plat/snmp/src/mib_parser/snmp_mib.c
Normal file
File diff suppressed because it is too large
Load Diff
171
plat/snmp/src/mib_parser/snmp_mib.h
Normal file
171
plat/snmp/src/mib_parser/snmp_mib.h
Normal file
@@ -0,0 +1,171 @@
|
||||
/********************************************************************
|
||||
Copyright ?2007 LGC Wireless, Inc. All rights reserved
|
||||
File Name: snmp_mib.h
|
||||
Description: header file of snmp mib parser
|
||||
Version: v9.0.0
|
||||
Author: Roy Jiang
|
||||
Create Date: 2007-6-9
|
||||
|
||||
History:
|
||||
2007-6-9 v9.0.0 Create
|
||||
|
||||
BEWARE: Portions of this file are subject to the copyrights of
|
||||
open-source project Net-SNMP.See the Net-SNMP's COPYING file
|
||||
for more details
|
||||
*********************************************************************/
|
||||
#ifndef __WXC2_SNMP_MIB_H_
|
||||
#define __WXC2_SNMP_MIB_H_
|
||||
|
||||
#define MAXLABEL 64 /* maximum characters in a label */
|
||||
#define MAXTOKEN 128 /* maximum characters in a token */
|
||||
#define MAXQUOTESTR 20480 /* maximum characters in a quoted string */
|
||||
|
||||
struct variable_list;
|
||||
|
||||
/*
|
||||
* A linked list of tag-value pairs for enumerated integers.
|
||||
*/
|
||||
struct enum_list {
|
||||
struct enum_list *next;
|
||||
int value;
|
||||
char *label;
|
||||
};
|
||||
|
||||
/*
|
||||
* A linked list of ranges
|
||||
*/
|
||||
struct range_list {
|
||||
struct range_list *next;
|
||||
int low, high;
|
||||
};
|
||||
|
||||
/*
|
||||
* A linked list of indexes
|
||||
*/
|
||||
struct index_list {
|
||||
struct index_list *next;
|
||||
char *ilabel;
|
||||
char isimplied;
|
||||
};
|
||||
|
||||
/*
|
||||
* A linked list of varbinds
|
||||
*/
|
||||
struct varbind_list {
|
||||
struct varbind_list *next;
|
||||
char *vblabel;
|
||||
};
|
||||
|
||||
/*
|
||||
* A tree in the format of the tree structure of the MIB.
|
||||
*/
|
||||
struct tree {
|
||||
struct tree *child_list; /* list of children of this node */
|
||||
struct tree *next_peer; /* Next node in list of peers */
|
||||
struct tree *next; /* Next node in hashed list of names */
|
||||
struct tree *parent;
|
||||
char *label; /* This node's textual name */
|
||||
int subid; /* This node's integer subidentifier */
|
||||
int modid; /* The module containing this node */
|
||||
int number_modules;
|
||||
int *module_list; /* To handle multiple modules */
|
||||
int tc_index; /* index into tclist (-1 if NA) */
|
||||
int type; /* This node's object type */
|
||||
int access; /* This nodes access */
|
||||
int status; /* This nodes status */
|
||||
struct enum_list *enums; /* (optional) list of enumerated integers */
|
||||
struct range_list *ranges;
|
||||
struct index_list *indexes;
|
||||
char *augments;
|
||||
struct varbind_list *varbinds;
|
||||
char *hint;
|
||||
char *units;
|
||||
char *description; /* description (a quoted string) */
|
||||
char *reference; /* references (a quoted string) */
|
||||
int reported; /* 1=report started in print_subtree... */
|
||||
char *defaultValue;
|
||||
int oid[32];
|
||||
int oid_len;
|
||||
};
|
||||
|
||||
/*
|
||||
* Information held about each MIB module
|
||||
*/
|
||||
struct module_import {
|
||||
char *label; /* The descriptor being imported */
|
||||
int modid; /* The module imported from */
|
||||
};
|
||||
|
||||
struct module {
|
||||
char *name; /* This module's name */
|
||||
char *file; /* The file containing the module */
|
||||
struct module_import *imports; /* List of descriptors being imported */
|
||||
int no_imports; /* The number of such import descriptors */
|
||||
/*
|
||||
* -1 implies the module hasn't been read in yet
|
||||
*/
|
||||
int modid; /* The index number of this module */
|
||||
struct module *next; /* Linked list pointer */
|
||||
};
|
||||
|
||||
struct module_compatability {
|
||||
const char *old_module;
|
||||
const char *new_module;
|
||||
const char *tag; /* NULL implies unconditional replacement,
|
||||
* otherwise node identifier or prefix */
|
||||
size_t tag_len; /* 0 implies exact match (or unconditional) */
|
||||
struct module_compatability *next; /* linked list */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* non-aggregate types for tree end nodes
|
||||
*/
|
||||
#define TYPE_OTHER 0
|
||||
#define TYPE_OBJID 1
|
||||
#define TYPE_OCTETSTR 2
|
||||
#define TYPE_INTEGER 3
|
||||
#define TYPE_NETADDR 4
|
||||
#define TYPE_IPADDR 5
|
||||
#define TYPE_COUNTER 6
|
||||
#define TYPE_GAUGE 7
|
||||
#define TYPE_TIMETICKS 8
|
||||
#define TYPE_OPAQUE 9
|
||||
#define TYPE_NULL 10
|
||||
#define TYPE_COUNTER64 11
|
||||
#define TYPE_BITSTRING 12
|
||||
#define TYPE_NSAPADDRESS 13
|
||||
#define TYPE_UINTEGER 14
|
||||
#define TYPE_UNSIGNED32 15
|
||||
#define TYPE_INTEGER32 16
|
||||
|
||||
#define TYPE_SIMPLE_LAST 16
|
||||
|
||||
#define TYPE_TRAPTYPE 20
|
||||
#define TYPE_NOTIFTYPE 21
|
||||
#define TYPE_OBJGROUP 22
|
||||
#define TYPE_NOTIFGROUP 23
|
||||
#define TYPE_MODID 24
|
||||
#define TYPE_AGENTCAP 25
|
||||
#define TYPE_MODCOMP 26
|
||||
#define TYPE_OBJIDENTITY 27
|
||||
|
||||
#define MIB_ACCESS_READONLY 18
|
||||
#define MIB_ACCESS_READWRITE 19
|
||||
#define MIB_ACCESS_WRITEONLY 20
|
||||
#define MIB_ACCESS_NOACCESS 21
|
||||
#define MIB_ACCESS_NOTIFY 67
|
||||
#define MIB_ACCESS_CREATE 48
|
||||
|
||||
#define MIB_STATUS_MANDATORY 23
|
||||
#define MIB_STATUS_OPTIONAL 24
|
||||
#define MIB_STATUS_OBSOLETE 25
|
||||
#define MIB_STATUS_DEPRECATED 39
|
||||
#define MIB_STATUS_CURRENT 57
|
||||
|
||||
#define ANON "anonymous#"
|
||||
#define ANON_LEN strlen(ANON)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
122
plat/snmp/src/mib_parser/snmp_mib_api.c
Normal file
122
plat/snmp/src/mib_parser/snmp_mib_api.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/***********************************************************************
|
||||
Copyright ?2007 LGC Wireless, Inc. All rights reserved
|
||||
File Name: snmp_mib_api.c
|
||||
Description: API for SNMP MIB parser
|
||||
Version: v9.0.0
|
||||
Author: Roy Jiang
|
||||
Create Date: 2007-6-19
|
||||
|
||||
History:
|
||||
2007-6-9 v9.0.0 Create
|
||||
***********************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include "snmp_mib.h"
|
||||
#include "snmp_mib_api.h"
|
||||
|
||||
const char *mib_dir = "./mib";
|
||||
const char *index_file = "index";
|
||||
|
||||
extern struct tree *tree_head;
|
||||
extern struct module *module_head;
|
||||
extern void new_module(const char *name, const char *file);
|
||||
extern struct tree *read_module(const char *name);
|
||||
extern int get_token(FILE * fp, char *token, int maxtlen);
|
||||
extern void print_subtree(FILE * f, struct tree *tree, int count);
|
||||
extern struct tree *find_tree_node(const char *name, int modid);
|
||||
extern void free_tree(struct tree *Tree);
|
||||
|
||||
//return 0 on success
|
||||
int init_mib()
|
||||
{
|
||||
//open dir and check mib files in the dir
|
||||
{
|
||||
FILE *ip, *fp;
|
||||
char tmpstr[300];
|
||||
int count = 0;
|
||||
char token[MAXTOKEN];
|
||||
char newline;
|
||||
struct stat dir_stat, idx_stat;
|
||||
char tmpstr1[300];
|
||||
|
||||
printf("Scanning directory %s\n", mib_dir);
|
||||
|
||||
snprintf(token, sizeof(token), "%s/%s", mib_dir, index_file);
|
||||
token[ sizeof(token)-1 ] = 0;
|
||||
if (stat(token, &idx_stat) == 0 && stat(mib_dir, &dir_stat) == 0) {
|
||||
if ((ip = fopen(token, "r")) != NULL) {
|
||||
while (fscanf(ip, "%256s%c", tmpstr, &newline) == 2)
|
||||
{
|
||||
/*
|
||||
* If an overflow of the token or tmpstr buffers has been
|
||||
* found log a message and break out of the while loop,
|
||||
* thus the rest of the file tokens will be ignored.
|
||||
*/
|
||||
if (newline != '\n') {
|
||||
printf("add_mibdir: strings scanned in from %s/%s " \
|
||||
"are too large. count = %d\n ", mib_dir,
|
||||
".index", count);
|
||||
break;
|
||||
}
|
||||
|
||||
snprintf(tmpstr1, sizeof(tmpstr1), "%s/%s", mib_dir, tmpstr);
|
||||
tmpstr1[ sizeof(tmpstr1)-1 ] = 0;
|
||||
fp = fopen(tmpstr1, "r");
|
||||
if (fp == NULL) {
|
||||
printf("Can not open mib file: %s\n", tmpstr1);
|
||||
continue;
|
||||
}
|
||||
get_token(fp, token, MAXTOKEN);
|
||||
fclose(fp);
|
||||
new_module(token, tmpstr1);
|
||||
count++;
|
||||
}
|
||||
fclose(ip);
|
||||
}
|
||||
else
|
||||
printf("Can't read index\n");
|
||||
}
|
||||
else
|
||||
printf("No index\n");
|
||||
}
|
||||
|
||||
//read all mibs
|
||||
{
|
||||
struct module *mp;
|
||||
for (mp = module_head; mp; mp = mp->next)
|
||||
if (mp->no_imports == -1)
|
||||
read_module(mp->name);
|
||||
}
|
||||
|
||||
#ifdef _TEST_
|
||||
{
|
||||
//for debug
|
||||
// print_subtree(stdout, tree_head, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tree *getLGCroot()
|
||||
{
|
||||
return find_tree_node("lgcNS", -1);
|
||||
}
|
||||
|
||||
void close_mib()
|
||||
{
|
||||
free_tree(tree_head);
|
||||
return;
|
||||
}
|
||||
|
||||
//test----------------------------------------------------------------------------
|
||||
#ifdef _TEST_
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
init_mib();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
//end of test---------------------------------------------------------------------
|
||||
|
||||
49
plat/snmp/src/mib_parser/snmp_mib_api.h
Normal file
49
plat/snmp/src/mib_parser/snmp_mib_api.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/***********************************************************************
|
||||
Copyright ?2007 LGC Wireless, Inc. All rights reserved
|
||||
File Name: snmp_mib.h
|
||||
Description: header file of snmp mib parser
|
||||
Version: v9.0.0
|
||||
Author: Roy Jiang
|
||||
Create Date: 2007-6-9
|
||||
|
||||
History:
|
||||
2007-6-9 v9.0.0 Create
|
||||
***********************************************************************/
|
||||
#ifndef _WXC2_SNMP_MIB_API_H_
|
||||
#define _WXC2_SNMP_MIB_API_H_
|
||||
|
||||
#include "snmp_mib.h"
|
||||
|
||||
/*
|
||||
*Purpose: Init mib parser, read all mib files listed in ./mib/index,
|
||||
* you should config which mib file you want to parse in the file./mib/index
|
||||
*Input: None
|
||||
*Output: None
|
||||
*/
|
||||
extern int init_mib();
|
||||
|
||||
/*
|
||||
*Purpose: get the LGC root node of mib tree
|
||||
*Input: None
|
||||
*Output: LGC root tree node
|
||||
*/
|
||||
extern struct tree *getLGCroot();
|
||||
|
||||
/*
|
||||
*Purpose: Close mib parser and release all resources used in parsing mib files
|
||||
*Input: None
|
||||
*Output: None
|
||||
*/
|
||||
extern void close_mib();
|
||||
|
||||
/*
|
||||
*Purpose: Get tree node from oid
|
||||
*Input: const int oid: oid of the tree node to get
|
||||
int oidlen: the length of the oid
|
||||
struct tree *subtree: tree node from which the search start
|
||||
*Output: tree node
|
||||
*/
|
||||
extern struct tree *get_tree(const int *oid, int oidlen, struct tree *subtree);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user