⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mib2c.storage.conf

📁 eCos操作系统源码
💻 CONF
📖 第 1 页 / 共 2 页
字号:
# mib2c.storage.conf:##  This is a special mib2c.conf file that assumes that you want to do#  all storage of information locally rather than pulling the#  information from another source outside the agent (EG, the#  kernel).  To accomplish this, it defines a structure for the#  storage of tables and assumes you want to use the header_complex#  functions for retrieving and storing that data in a local data#  store.  It even writes a .conf file parser for you and sets you up#  for being able to do persistant storage fairly simply.##  In short:  it trys to do almost all of the work for you...  Almost...# # Define types of data by mib type, and translate into needed C code.## We need to get some extra stuff into the variable declarations# before sourcing the main mib2c.vartypes.conf file below.type:		OCTETSTRstorage:	    char   *${name};storage:	    size_t  ${name}Len;varlenname:	StorageTmp->${name}Lenvartest:	  if (StorageTmp->${name} == NULL) {vartest:	    config_perror(\"invalid specification for ${name}\");vartest:	    return;vartest:	  }vartest:action:	             tmpvar = StorageTmp->$name;action:	             tmplen = StorageTmp->${name}Len;action:	             memdup((u_char **) &StorageTmp->$name, var_val, var_val_len);action:	             StorageTmp->${name}Len = var_val_len;undo:	             SNMP_FREE(StorageTmp->${name});undo:	             StorageTmp->${name} = tmpvar;undo:	             StorageTmp->${name}Len = tmplen;commit:		     SNMP_FREE(tmpvar);sizeofstart:	sizeofend:	Lentmpvar:		char *casttmp:	strdup((char *) tmpvar);#type:		INTEGERstorage:	    long    $name;storageret:	&varlenname:	tmpintsizeofstart:	sizeof(sizeofend:	)tmpvar:		intaction:	             tmpvar = StorageTmp->$name;action:	             StorageTmp->${name} = *((long *) var_val);undo:	             StorageTmp->${name} = tmpvar;casttmp:	tmpvar;#type:		OBJECTIDstorage:	    oid     *$name;storage:	    size_t   ${name}Lenvarlenname:	StorageTmp->${name}Lenvartest:	  if (StorageTmp->${name} == NULL) {vartest:	    config_perror(\"invalid specification for ${name}\");vartest:	    return;vartest:	  }vartest:action:	             tmpvar = StorageTmp->$name;action:	             tmplen = StorageTmp->${name}Len;action:	             memdup((u_char **) &StorageTmp->$name, var_val, var_val_len);action:	             StorageTmp->${name}Len = var_val_len/sizeof(oid);undo:	             SNMP_FREE(StorageTmp->${name});undo:	             StorageTmp->${name} = tmpvar;undo:	             StorageTmp->${name}Len = tmplen;commit:		     SNMP_FREE(tmpvar);sizeofstart:	sizeofend:	Lentmpvar:		oid *casttmp:	(oid *) tmpvar;freetmp:	SNMP_FREE(tmpvar);#type:		COUNTER64storage:	    struct counter64 $name;varlenname:	tmpintsizeofstart:	sizeof(sizeofend:	)tmpvar:		struct counter64 *casttmp:	(struct counter64 *) tmpvar;############################################################################# source variable typing information:include: mib2c.vartypes.conf############################################################################# The .h file############################################################################type:	code-dot-hcode:	/* This file was generated by mib2c and is intended for use as a mib modulecode:	  for the ucd-snmp snmpd agent. */code:code:	#ifndef _MIBGROUP_${OUTPUTNAME}_Hcode:	#define _MIBGROUP_${OUTPUTNAME}_Hcode:	code:	/* we may use header_complex from the header_complex module */code:	code:	config_require(header_complex)code:code:	/* our storage structure(s) */code:	$variables{'code-structure-per-table'}{'processed'}code:code:	/* enum definitions from the covered mib sections */code:code:	$variables{'code-enums'}{'processed'}code:code:	/* function prototypes */code:	code:	void   init_$outputName(void);code:	$variables{'code-var-table-decl'}{'processed'}code:	$variables{'code-write-func-decl'}{'processed'}code:	$variables{'code-write-rowstatus-decl'}{'processed'}code:	code:	#endif /* _MIBGROUP_${OUTPUTNAME}_H */## Structure definition, one per table#type:		code-structure-per-tableprocesstable:	code-structure-per-tablecode:	struct ${vtable}_data {code:	$variables{$vtable}{'code-structure'}{'processed'}code:	};## Structure storage arrays, one per table#type:		code-structure-storageprocesstable:	code-structure-storagecode:	static struct header_complex_index *${vtable}Storage = NULL;## Structure definition line.#type:	code-structureprocess: code-structurecode:	" . eval ("\"$variables{$mib->{'type'}}{'storage'}\"") . "#$variables{$i}{'code'}\""evalstr(## ENUM definitions#type:		code-enumsprocess:	code-enumsskipif: $mib->{'textualConvention'} eq "RowStatus" || $mib->{'textualConvention'} eq "StorageType"code:	" . eval{ my ($i, $x); foreach $i (sort {$mib->{'enums'}{$a} <=> $mib->{'enums'}{$b}} keys(%{$mib->{'enums'}})) { $x .= sprintf("#define %-40s %d\n","${NAME}_" . uc($i),$mib->{'enums'}{$i}); } $x; } . "############################################################################# The .c file, top############################################################################type:	code-main-partcode:	/* This file was generated by mib2c and is intended for use ascode:	   a mib module for the ucd-snmp snmpd agent. */code:	code:	/* This should always be included first before anything else */code:	#include <config.h>code:	#if HAVE_STDLIB_Hcode:	#include <stdlib.h>code:	#endifcode:	#if HAVE_STRING_Hcode:	#include <string.h>code:	#elsecode:	#include <strings.h>code:	#endifcode:	code:	/* minimal include directives */code:	#include \"mibincl.h\"code:	#include \"header_complex.h\"code:	#include \"$outputName.h\"code:	#include \"snmp-tc.h\"code:	code:	/* code:	 * ${outputName}_variables_oid:code:	 *   this is the top level oid that we want to register under.  Thiscode:	 *   is essentially a prefix, with the suffix appearing in thecode:	 *   variable below.code:	 */code:	code:	oid ${outputName}_variables_oid[] = { $commaoid };code:	code:	/* code:	 * variable$varlen ${outputName}_variables:code:	 *   this variable defines function callbacks and type return information code:	 *   for the $outputName mib section code:	 */code:	code:	struct variable$varlen ${outputName}_variables[] = {code:	/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */code:	$variables{'variable-structure-info'}{'processed'}code:	};code:	/*    (L = length of the oidsuffix) */code:	code:	/* global storage of our data, saved in and configured by header_complex() */code:	$variables{'code-structure-storage'}{'processed'}code:code:	/*code:	 * init_$outputName():code:	 *   Initialization routine.  This is called when the agent starts up.code:	 *   At a minimum, registration of your variables should take place here.code:	 */code:	void init_$outputName(void) {code:	  DEBUGMSGTL((\"$outputName\", \"initializing...  \"));code:	code:	  /* register ourselves with the agent to handle our mib tree */code:	  REGISTER_MIB(\"$outputName\", ${outputName}_variables, variable$varlen,\code:	               ${outputName}_variables_oid);code:code:	  /* register our config handler(s) to deal with registrations */code:	$variables{'code-parser-registration'}{'processed'}code:code:	  /* place any other initialization junk you need here */code:	code:	  DEBUGMSGTL((\"$outputName\", \"done.\\n\"));code:	}code:	code:	$variables{'code-parser'}{'processed'}code:	code:	$variables{'code-var_table'}{'processed'}code:code:	$variables{'code-write-func'}{'processed'}code:code:	$variables{'code-write-rowstatus'}{'processed'}############################################################################# var_ function for tables, which is handled specially and used above##   Note: $vtable is set to the table name in the processtable loop.############################################################################## header file defs first#type:		code-var-table-declprocesstable:	code-var-table-declcode:	FindVarMethod var_$vtable;code:	void parse_$vtable(char *, char *);## .conf Parser Code per table#type:		code-parser-registrationprocesstable:	code-parser-registrationcode:	  snmpd_register_config_handler(\"$vtable\", parse_$vtable, NULL,code:	                                \"HELP STRING\");type:		code-varlist-addprocess:	code-varlist-addskipif:		$variables{$vroutine}{$name}{'isanindex'} != 1code:	  snmp_varlist_add_variable(&vars, NULL, 0, $variables{$mib->{type}}{asnType}, ($variables{$mib->{type}}{'cast'}) thedata->$name, $variables{$mib->{type}}{'sizeofstart'}thedata->$name$variables{$mib->{type}}{'sizeofend'}); /* $name */type:		code-parserprocesstable:	code-parsercode:	/* code:	 * ${vtable}_add(): adds a structure node to our data set code:	 */code:	intcode:	${vtable}_add(struct ${vtable}_data *thedata) {code:	  struct variable_list *vars = NULL;code:code:	  DEBUGMSGTL((\"$outputName\", \"adding data...  \"));code:	 /* add the index variables to the varbind list, which is code:	    used by header_complex to index the data */code:code:	$variables{$vtable}{'code-varlist-add'}{'processed'}code:code:	  header_complex_add_data(&${vtable}Storage, vars, thedata);code:	  DEBUGMSGTL((\"$vtable\",\"registered an entry\\n\"));code:	code:	  DEBUGMSGTL((\"$outputName\", \"done.\\n\"));code:	  return SNMPERR_SUCCESS;code:	}code:code:	/*code:	 * parse_$vtable():code:	 *   parses .conf file entries needed to configure the mib.code:	 */code:	voidcode:	parse_$vtable(char *token, char *line) {code:	  size_t tmpint;code:	  struct ${vtable}_data *StorageTmp = SNMP_MALLOC_STRUCT(${vtable}_data);code:	  struct variable_list *vars = NULL;code:code:	    DEBUGMSGTL((\"$outputName\", \"parsing config...  \"));code:code:	  if (StorageTmp == NULL) {code:	    config_perror(\"malloc failure\");code:	    return;code:	  }code:code:	$variables{$vtable}{'code-parser-sections'}{'processed'}code:code:	  ${vtable}_add(StorageTmp);code:	    code:	  DEBUGMSGTL((\"$outputName\", \"done.\\n\"));code:	}code:	code:	code:	/*code:	 * store_$vtable():code:	 *   stores .conf file entries needed to configure the mib.code:	 */code:	voidcode:	store_$vtable(void) {code:	  char line[SNMP_MAXBUF];code:	  char *cptr;code:	  size_t tmpint;code:	  struct ${vtable}_data *StorageTmp;code:	  struct header_complex_index *hcindex;code:	code:	  DEBUGMSGTL((\"$outputName\", \"storing data...  \"));code:	code:	  memset(line,0,sizeof(line));code:	code:	  strcat(line, \"$vtable\");code:	  cptr = line + strlen(line);code:code:	  for(hcindex=${vtable}Storage; hcindex != NULL; code:	      hcindex = hcindex->next) {code:	    StorageTmp = (struct ${vtable}_data *) hcindex->data;code:code:	$variables{$vtable}{'code-persistent-sections'}{'processed'}code:code:	    snmpd_store_config(line);code:	  }code:	  DEBUGMSGTL((\"$outputName\", \"done.\\n\"));code:	}# individual sections for the parsertype:		code-parser-sectionsprocess:	code-parser-sectionsskipif:		$mib->{'access'} =~ /NoAccess/code:	  line = read_config_read_data($variables{$mib->{type}}{asnType}, line, &StorageTmp->$name, &" . eval ("\"$variables{$mib->{type}}{varlenname}\"") . ");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -