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

📄 mib2c.storage.conf

📁 开放源码实时操作系统源码.
💻 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:		OCTETSTR
storage:	    char   *${name};
storage:	    size_t  ${name}Len;
varlenname:	StorageTmp->${name}Len
vartest:	  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:	Len
tmpvar:		char *
casttmp:	strdup((char *) tmpvar);
#
type:		INTEGER
storage:	    long    $name;
storageret:	&
varlenname:	tmpint
sizeofstart:	sizeof(
sizeofend:	)
tmpvar:		int
action:	             tmpvar = StorageTmp->$name;
action:	             StorageTmp->${name} = *((long *) var_val);
undo:	             StorageTmp->${name} = tmpvar;
casttmp:	tmpvar;
#
type:		OBJECTID
storage:	    oid     *$name;
storage:	    size_t   ${name}Len
varlenname:	StorageTmp->${name}Len
vartest:	  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:	Len
tmpvar:		oid *
casttmp:	(oid *) tmpvar;
freetmp:	SNMP_FREE(tmpvar);
#
type:		COUNTER64
storage:	    struct counter64 $name;
varlenname:	tmpint
sizeofstart:	sizeof(
sizeofend:	)
tmpvar:		struct counter64 *
casttmp:	(struct counter64 *) tmpvar;

############################################################################
# source variable typing information:
include: mib2c.vartypes.conf

############################################################################
# The .h file
############################################################################
type:	code-dot-h
code:	/* This file was generated by mib2c and is intended for use as a mib module
code:	  for the ucd-snmp snmpd agent. */
code:
code:	#ifndef _MIBGROUP_${OUTPUTNAME}_H
code:	#define _MIBGROUP_${OUTPUTNAME}_H
code:	
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-table
processtable:	code-structure-per-table

code:	struct ${vtable}_data {
code:	$variables{$vtable}{'code-structure'}{'processed'}
code:	};

#
# Structure storage arrays, one per table
#
type:		code-structure-storage
processtable:	code-structure-storage

code:	static struct header_complex_index *${vtable}Storage = NULL;

#
# Structure definition line.
#
type:	code-structure
process: code-structure

code:	" . eval ("\"$variables{$mib->{'type'}}{'storage'}\"") . "
#$variables{$i}{'code'}\""evalstr(
#
# ENUM definitions
#
type:		code-enums
process:	code-enums
skipif: $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-part
code:	/* This file was generated by mib2c and is intended for use as
code:	   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_H
code:	#include <stdlib.h>
code:	#endif
code:	#if HAVE_STRING_H
code:	#include <string.h>
code:	#else
code:	#include <strings.h>
code:	#endif
code:	
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.  This
code:	 *   is essentially a prefix, with the suffix appearing in the
code:	 *   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-decl
processtable:	code-var-table-decl

code:	FindVarMethod var_$vtable;
code:	void parse_$vtable(char *, char *);

#
# .conf Parser Code per table
#
type:		code-parser-registration
processtable:	code-parser-registration
code:	  snmpd_register_config_handler(\"$vtable\", parse_$vtable, NULL,
code:	                                \"HELP STRING\");

type:		code-varlist-add
process:	code-varlist-add
skipif:		$variables{$vroutine}{$name}{'isanindex'} != 1
code:	  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-parser
processtable:	code-parser

code:	/* 
code:	 * ${vtable}_add(): adds a structure node to our data set 
code:	 */
code:	int
code:	${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:	void
code:	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:	void
code:	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 parser
type:		code-parser-sections
process:	code-parser-sections
skipif:		$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 + -