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

📄 mib2c.storage.conf

📁 开放源码实时操作系统源码.
💻 CONF
📖 第 1 页 / 共 2 页
字号:
code:	" . eval ("\"$variables{$mib->{type}}{vartest}\"") . "

#
# .conf persistent save Code per table
#
type:		code-persistent-sections
process:	code-persistent-sections
skipif:		$mib->{'access'} =~ /NoAccess/
code:	    cptr = read_config_store_data($variables{$mib->{type}}{asnType}, cptr, &StorageTmp->$name, &" . eval ("\"$variables{$mib->{type}}{varlenname}\"") . ");

#
# Code code per table
#
type:		code-var_table
processtable:	code-var_table

code:	/*
code:	 * var_$vtable():
code:	 *   Handle this table separately from the scalar value case.
code:	 *   The workings of this are basically the same as for var_$outputName above.
code:	 */
code:	unsigned char *
code:	var_$vtable(struct variable *vp,
code:	    	    oid     *name,
code:	    	    size_t  *length,
code:	    	    int     exact,
code:	    	    size_t  *var_len,
code:	    	    WriteMethod **write_method)
code:	{
code:
code:	struct ${vtable}_data *StorageTmp = NULL;
code:	
code:	  DEBUGMSGTL((\"$outputName\", \"var_$vtable: Entering...  \\n\"));
code:	  /* 
code:	   * this assumes you have registered all your data properly
cdoe:	   * with header_complex_add() somewhere before this
code:	   */
code:	  if ((StorageTmp =
code:	       header_complex(${vtable}Storage, vp,name,length,exact,
code:	                           var_len,write_method)) == NULL)
code:	    return NULL;
code:	
code:	  /* 
code:	   * this is where we do the value assignments for the mib results.
code:	   */
code:	  switch(vp->magic) {\n\n
code:	$variables{$vtable}{'code-case-statements'}{'processed'}
code:	    default:
code:	      ERROR_MSG(\"\");
code:	  }
code:	  return NULL;
code:	}


############################################################################
# case statement sections
############################################################################
type:		code-case-statements
process:	code-case-statements
skipif:		$mib->{'access'} =~ /NoAccess/

code:		    case $NAME:
code:		        " . (($mib->{'access'} =~ /ReadWrite|WriteOnly|Create/) ? "*write_method = write_$mib->{label};" : "") . "
code:		        *var_len = $variables{$mib->{'type'}}{'sizeofstart'}StorageTmp->$mib->{label}$variables{$mib->{'type'}}{'sizeofend'};
code:		        return (u_char *) $variables{$mib->{'type'}}{'storageret'}StorageTmp->$mib->{label};
code:		

############################################################################
# storage structure information
############################################################################
type:		variable-structure-info
process:	variable-structure-info
skipif:		$mib->{'access'} =~ /NoAccess/
code:		" . sprintf("#define   %-20s  $count", $NAME) . "
code:		" . sprintf("  { %-20s, %-14s, %-6.6s, %s, %d, { %s } },", $NAME, $variables{$mib->{'type'}}{'asnType'}, $accessToUCD{$mib->{'access'}}, "var_$vroutine", $depth-1, $subid) . "

############################################################################
# write function definition, also appended to the end of the .c file.
############################################################################
#
# Header info: declair write functions for set processing
#
process:	code-write-func-decl
type:		code-write-func-decl
skipif:		$mib->{'access'} !~ /Write|Create/
code:		WriteMethod write_$name;
#
# C code
#
type:		code-write-func
process:	code-write-func
skipif:		$mib->{'textualConvention'} eq "RowStatus" || $mib->{'access'} !~ /Write|Create/
code:	int
code:	write_$name(int      action,
code:	            u_char   *var_val,
code:	            u_char   var_val_type,
code:	            size_t   var_val_len,
code:	            u_char   *statP,
code:	            oid      *name,
code:	            size_t    name_len)
code:	{
code:	  static $variables{$mib->{'type'}}{tmpvar} tmpvar;
code:	  struct ${vroutine}_data *StorageTmp = NULL;
code:	  static size_t tmplen;
code:	  size_t newlen=name_len - (sizeof(${outputName}_variables_oid)/sizeof(oid) + $depth - 1);
code:
code:	  DEBUGMSGTL((\"$outputName\", \"write_$name entering action=%d...  \\n\", action));
code:	  if ((StorageTmp =
code:	       header_complex(${vroutine}Storage, NULL,
code:	                      &name[sizeof(${outputName}_variables_oid)/sizeof(oid) + $depth - 1], 
code:	                      &newlen, 1, NULL, NULL)) == NULL)
code:	      return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
code:	
code:	  switch ( action ) {
code:	        case RESERVE1:
code:	          if (var_val_type != $variables{$mib->{'type'}}{asnType}){
code:	              fprintf(stderr, \"write to $name not $variables{$mib->{'type'}}{asnType}\\n\");
code:	              return SNMP_ERR_WRONGTYPE;
code:	          }
code:	          break;
code:	
code:	        case RESERVE2:
code:	             /* memory reseveration, final preparation... */
code:	          break;
code:	
code:	        case FREE:
code:	             /* Release any resources that have been allocated */
code:	          break;
code:	
code:	        case ACTION:
code:	             /* The variable has been stored in $variables{$mib->{'type'}}{variable} for
code:	             you to use, and you have just been asked to do something with
code:	             it.  Note that anything done here must be reversable in the UNDO case */
code:		".eval ("\"$variables{$mib->{type}}{action}\"")."
code:	          break;
code:	
code:	        case UNDO:
code:	             /* Back out any changes made in the ACTION case */
code:		".eval ("\"$variables{$mib->{type}}{undo}\"")."
code:	          break;
code:	
code:	        case COMMIT:
code:	             /* Things are working well, so it's now safe to make the change
code:	             permanently.  Make sure that anything done here can't fail! */
code:		".eval ("\"$variables{$mib->{'type'}}{'commit'}\"")."
code:	          break;
code:	  }
code:	  return SNMP_ERR_NOERROR;
code:	}
code:
code:
############################################################################
# copy memory from varlist
############################################################################
type:		code-varlist-copy
process:	code-varlist-copy
skipif:		$variables{$vroutine}{$name}{'isanindex'} != 1
code:	            memdup((u_char **) &(StorageNew->$name), 
code:	                   vp->val.$variables{$mib->{'type'}}{variable},
code:	                   vp->val_len);
code:	            StorageNew->${name}Len = vp->val_len;
code:	            vp = vp->next_variable;
############################################################################
# add null pointers to a varlist; value to be parsed later
############################################################################
type:		code-varlist-add-null
process:	code-varlist-add-null
skipif:		$variables{$vroutine}{$name}{'isanindex'} != 1
code:	  	  snmp_varlist_add_variable(&vars, NULL, 0, $variables{$mib->{'type'}}{asnType}, NULL, 0); /* $name */
############################################################################
# write function definition for a RowStatus object, 
#   - allows for creation/deletion.
############################################################################
#
# Header info: declair write functions for set processing
#
process:	code-write-rowstatus-decl
type:		code-write-rowstatus-decl
skipif:		$mib->{'textualConvention'} ne "RowStatus"
code:		WriteMethod write_$name;
#
# code
#
type:		code-write-rowstatus
process:	code-write-rowstatus
skipif:		$mib->{'textualConvention'} ne "RowStatus"
code:	int
code:	write_$name(int      action,
code:	            u_char   *var_val,
code:	            u_char   var_val_type,
code:	            size_t   var_val_len,
code:	            u_char   *statP,
code:	            oid      *name,
code:	            size_t    name_len)
code:	{
code:	  struct ${vroutine}_data *StorageTmp = NULL;
code:	  static struct ${vroutine}_data *StorageNew, *StorageDel;
code:	  size_t newlen=name_len - (sizeof(${vroutine}_variables_oid)/sizeof(oid) + 3 - 1);
code:	  static int old_value;
code:	  int set_value;
code:	  static struct variable_list *vars, *vp;
code:	  struct header_complex_index *hciptr;
code:	  char who[MAX_OID_LEN], flagName[MAX_OID_LEN];
code:	
code:	  StorageTmp =
code:	    header_complex(${vroutine}Storage, NULL,
code:	                   &name[sizeof(${vroutine}_variables_oid)/sizeof(oid) + 3 - 1], 
code:	                   &newlen, 1, NULL, NULL);
code:	  
code:	  
code:	  if (var_val_type != ASN_INTEGER || var_val == NULL){
code:	    fprintf(stderr, \"write to $name not ASN_INTEGER\\n\");
code:	    return SNMP_ERR_WRONGTYPE;
code:	  }
code:	  set_value = *((long *) var_val);
code:	
code:	  /* check legal range, and notReady is reserved for us, not a user */
code:	  if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
code:	    return SNMP_ERR_INCONSISTENTVALUE;
code:	    
code:	  switch ( action ) {
code:	        case RESERVE1:
code:		  /* stage one: test validity */
code:	          if (StorageTmp == NULL) {
code:	            /* create the row now? */
code:	
code:	            /* ditch illegal values now */
code:	            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
code:	              return SNMP_ERR_INCONSISTENTVALUE;
code:	    
code:	            /* destroying a non-existent row is actually legal */
code:	            if (set_value == RS_DESTROY) {
code:	              return SNMP_ERR_NOERROR;
code:	            }
code:	
code:	            /* illegal creation values */
code:	            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
code:	              return SNMP_ERR_INCONSISTENTVALUE;
code:	            }
code:	          } else {
code:	            /* row exists.  Check for a valid state change */
code:	            if (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT) {
code:	              /* can't create a row that exists */
code:	              return SNMP_ERR_INCONSISTENTVALUE;
code:	            }
code:		    /* XXX: interaction with row storage type needed */
code:	          }
code:	          break;
code:	
code:	
code:	        case RESERVE2:
code:	          /* memory reseveration, final preparation... */
code:	          if (StorageTmp == NULL) {
code:	            /* creation */
code:	            vars = NULL;
code:	
code:	$variables{'code-varlist-add-null'}{'processed'}
code:	                    
code:	            if (header_complex_parse_oid(&(name[sizeof(${vroutine}_variables_oid)/sizeof(oid)+2]), newlen,
code:	                                         vars) != SNMPERR_SUCCESS) {
code:	              /* XXX: free, zero vars */
code:	              return SNMP_ERR_INCONSISTENTNAME;
code:	            }
code:	            vp = vars;
code:	
code:	            StorageNew = SNMP_MALLOC_STRUCT(${vroutine}_data);
code:	$variables{'code-varlist-copy'}{'processed'}
code:	
code:	            StorageNew->$name = set_value;
code:	            /* XXX: free, zero vars, no longer needed? */
code:	          }
code:	          
code:	          break;
code:	
code:	
code:	        case FREE:
code:	          /* XXX: free, zero vars */
code:	          /* Release any resources that have been allocated */
code:	          break;
code:	
code:	
code:	        case ACTION:
code:	             /* The variable has been stored in set_value for you to
code:	             use, and you have just been asked to do something with
code:	             it.  Note that anything done here must be reversable in
code:	             the UNDO case */
code:	             
code:	             if (StorageTmp == NULL) {
code:	               /* row creation, so add it */
code:	               if (StorageNew != NULL)
code:	                 ${vroutine}_add(StorageNew);
code:	               /* XXX: ack, and if it is NULL? */
code:	             } else if (set_value != RS_DESTROY) {
code:	               /* set the flag? */
code:	               old_value = StorageTmp->$name;
code:	               StorageTmp->$name = *((long *) var_val);
code:	             } else {
code:	               /* destroy...  extract it for now */
code:	               hciptr =
code:	                 header_complex_find_entry(${vroutine}Storage,
code:	                                           StorageTmp);
code:	               StorageDel =
code:	                 header_complex_extract_entry(&${vroutine}Storage,
code:	                                              hciptr);
code:	             }
code:	          break;
code:	
code:	
code:	        case UNDO:
code:	             /* Back out any changes made in the ACTION case */
code:	             if (StorageTmp == NULL) {
code:	               /* row creation, so remove it again */
code:	               hciptr =
code:	                 header_complex_find_entry(${vroutine}Storage,
code:	                                           StorageTmp);
code:	               StorageDel =
code:	                 header_complex_extract_entry(&${vroutine}Storage,
code:	                                              hciptr);
code:	               /* XXX: free it */
code:	             } else if (StorageDel != NULL) {
code:	               /* row deletion, so add it again */
code:	               ${vroutine}_add(StorageDel);
code:	             } else {
code:	               StorageTmp->$name = old_value;
code:	             }
code:	          break;
code:	
code:	
code:	        case COMMIT:
code:	             /* Things are working well, so it's now safe to make the change
code:	             permanently.  Make sure that anything done here can't fail! */
code:	          if (StorageDel != NULL) {
code:	            StorageDel == 0;
code:	            /* XXX: free it, its dead */
code:	          }
code:	          break;
code:	  }
code:	  return SNMP_ERR_NOERROR;
code:	}
code:	

⌨️ 快捷键说明

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