mib2c.container.conf
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:15k
- ## -*- c -*-
- ######################################################################
- ## Do the .h file
- ######################################################################
- @open ${name}.h@
- /*
- * Note: this file originally auto-generated by mib2c using
- * $Id: mib2c.container.conf,v 1.3 2004/10/14 12:57:33 dts12 Exp $
- */
- #ifndef $name.uc_H
- #define $name.uc_H
- /* function declarations */
- void init_$name(void);
- @foreach $i table@
- void initialize_table_$i(void);
- Netsnmp_Node_Handler ${i}_handler;
- @end@
- @foreach $i table@
- /* column number definitions for table $i */
- @foreach $c column@
- #define COLUMN_$c.uc $c.subid
- @end@
- @end@
- #endif /* $name.uc_H */
- ######################################################################
- ## Do the .c file
- ######################################################################
- @open ${name}.c@
- /*
- * Note: this file originally auto-generated by mib2c using
- * $Id: mib2c.container.conf,v 1.3 2004/10/14 12:57:33 dts12 Exp $
- */
- #include <net-snmp/net-snmp-config.h>
- #include <net-snmp/net-snmp-includes.h>
- #include <net-snmp/agent/net-snmp-agent-includes.h>
- #include "${name}.h"
- /** Initializes the $name module */
- void
- init_$name(void)
- {
- /* here we initialize all the tables we're planning on supporting */
- @foreach $i table@
- initialize_table_$i();
- @end@
- }
- @foreach $i table@
- /** Initialize the $i table by defining its contents and how it's structured */
- void
- initialize_table_$i(void)
- {
- static oid ${i}_oid[] = {$i.commaoid};
- size_t ${i}_oid_len = OID_LENGTH(${i}_oid);
- netsnmp_handler_registration *reg;
- netsnmp_container *container;
- netsnmp_table_registration_info *table_info;
- reg = netsnmp_create_handler_registration(
- "$i", ${i}_handler,
- ${i}_oid, ${i}_oid_len,
- @if $i.settable@
- HANDLER_CAN_RWRITE
- @else@
- HANDLER_CAN_RONLY
- @end@
- );
- container = netsnmp_container_find( "table_container" );
- table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
- netsnmp_table_helper_add_indexes(table_info,
- @foreach $idx index@
- $idx.type, /* index: $idx */
- @end@
- 0);
- table_info->min_column = XXX;
- table_info->min_column = YYY;
-
- netsnmp_container_table_register( reg, table_info, container, 0 );
- /* Initialise the contents of the table here */
- }
- /* Typical data structure for a row entry */
- struct ${i}_entry {
- netsnmp_index oid_index;
- /* Index values */
- @foreach $idx index@
- $idx.decl $idx;
- @end@
- /* Column values */
- @foreach $c column@
- @if $c.readable@
- $c.decl $c;
- @if $c.settable@
- @if !$c.rowstatus@
- $c.decl old_$c;
- @end@
- @end@
- @end@
- @end@
- int valid;
- };
- /* create a new row in the table */
- struct ${i}_entry *
- ${i}_createEntry(netsnmp_container *container,
- @foreach $idx index@
- $idx.decl $idx,
- @end@
- ) {
- struct ${i}_entry *entry;
- entry = SNMP_TYPEDEF_MALLOC(struct ${i}_entry);
- if (!entry)
- return NULL;
- @foreach $idx index@
- entry->$idx = $idx;
- @end@
- entry->oid_index.len = XXX;
- entry->oid_index.oids = YYY;
- CONTAINER_INSERT( container, entry );
- return entry;
- }
- /* remove a row from the table */
- void
- ${i}_removeEntry(netsnmp_container *container,
- struct ${i}_entry *entry) {
- if (!entry)
- return; /* Nothing to remove */
- CONTAINER_REMOVE( container, entry );
- if (entry)
- SNMP_FREE( entry ); /* XXX - release any other internal resources */
- }
- /** handles requests for the $i table */
- int
- ${i}_handler(
- netsnmp_mib_handler *handler,
- netsnmp_handler_registration *reginfo,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests) {
- netsnmp_request_info *request;
- netsnmp_table_request_info *table_info;
- netsnmp_table_data *table_data;
- netsnmp_container *container;
- struct ${i}_entry *table_entry;
- switch (reqinfo->mode) {
- /*
- * Read-support (also covers GetNext requests)
- */
- case MODE_GET:
- for (request=requests; request; request=request->next) {
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @foreach $c column@
- @if $c.readable@
- case COLUMN_$c.uc:
- snmp_set_var_typed_value( request->requestvb, $c.type,
- table_entry->$c,
- sizeof(table_entry->$c));
- break;
- @end@
- @end@
- }
- }
- break;
- @if $i.settable@
- /*
- * Write-support
- */
- case MODE_SET_RESERVE1:
- for (request=requests; request; request=request->next) {
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @foreach $c column@
- @if $c.settable@
- case COLUMN_$c.uc:
- if ( request->requestvb->type != $c.type ) {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_WRONGTYPE );
- return SNMP_ERR_NOERROR;
- }
- /* Also may need to check size/value */
- @if $c.rowstatus@
- switch (*request->requestvb->val.integer) {
- case RS_ACTIVE:
- case RS_NOTINSERVICE:
- if (!table_entry) {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_INCONSISTENTVALUE );
- return SNMP_ERR_NOERROR;
- }
- break;
- case RS_CREATEANDGO:
- case RS_CREATEANDWAIT:
- if (table_entry) {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_INCONSISTENTVALUE );
- return SNMP_ERR_NOERROR;
- }
- break;
- case RS_DESTROY:
- /* Valid in all circumstances */
- break;
- case RS_NOTREADY:
- default:
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_WRONGVALUE );
- return SNMP_ERR_NOERROR;
- break;
- }
- @end@
- break;
- @end@
- @end@
- default:
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_NOTWRITABLE );
- return SNMP_ERR_NOERROR;
- }
- }
- break;
- case MODE_SET_RESERVE2:
- @if $i.creatable@
- for (request=requests; request; request=request->next) {
- container = netsnmp_container_table_extract(request);
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @if $i.rowstatus@
- @foreach $c column@
- @if $c.rowstatus@
- case COLUMN_$c.uc:
- switch (*request->requestvb->val.integer) {
- case RS_CREATEANDGO:
- case RS_CREATEANDWAIT:
- table_entry = ${i}_createEntry(container
- @foreach $idx index@
- , table_info->indexes->val.YYY
- @end@
- );
- if (table_entry) {
- netsnmp_container_table_insert_row( request, table_entry );
- } else {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_RESOURCEUNAVAILABLE );
- return SNMP_ERR_NOERROR;
- }
- }
- @end@
- @end@
- @else@
- @foreach $c column@
- @if $c.creatable@
- case COLUMN_$c.uc:
- @end@
- @end@
- if ( !table_entry ) {
- table_entry = ${i}_createEntry(container
- @foreach $idx index@
- , table_info->indexes->val.YYY
- @end@
- );
- if (table_entry) {
- netsnmp_container_table_insert_row( request, table_entry );
- } else {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_RESOURCEUNAVAILABLE );
- return SNMP_ERR_NOERROR;
- }
- }
- break;
- @end@
- }
- }
- @end@
- break;
- case MODE_SET_FREE:
- @if $i.creatable@
- for (request=requests; request; request=request->next) {
- container = netsnmp_container_table_extract(request);
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @if $i.rowstatus@
- @foreach $c column@
- @if $c.rowstatus@
- case COLUMN_$c.uc:
- switch (*request->requestvb->val.integer) {
- case RS_CREATEANDGO:
- case RS_CREATEANDWAIT:
- if (table_entry && !table_entry->valid) {
- ${i}_removeEntry(container, table_entry );
- }
- }
- @end@
- @end@
- @else@
- @foreach $c column@
- @if $c.creatable@
- case COLUMN_$c.uc:
- @end@
- @end@
- if ( table_entry && !table_entry->valid ) {
- ${i}_removeEntry(container, table_entry );
- }
- break;
- @end@
- }
- }
- @end@
- break;
- case MODE_SET_ACTION:
- for (request=requests; request; request=request->next) {
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @foreach $c column@
- @if $c.settable@
- @if !$c.rowstatus@
- case COLUMN_$c.uc:
- /* Need to save old 'table_entry->$c' value.
- May need to use 'memcpy' */
- table_entry->old_$c = table_entry->$c;
- table_entry->$c = request->requestvb->val.YYY;
- break;
- @end@
- @end@
- @end@
- }
- }
- @if $i.rowstatus@
- /* Check the internal consistency of an active row */
- for (request=requests; request; request=request->next) {
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @foreach $c column@
- @if $c.rowstatus@
- case COLUMN_$c.uc:
- switch (*request->requestvb->val.integer) {
- case RS_ACTIVE:
- case RS_CREATEANDGO:
- if (/* XXX */) {
- netsnmp_set_request_error( reqinfo, request,
- SNMP_ERR_INCONSISTENTVALUE );
- return SNMP_ERR_NOERROR;
- }
- }
- @end@
- @end@
- }
- }
- @end@
- break;
- case MODE_SET_UNDO:
- for (request=requests; request; request=request->next) {
- container = netsnmp_container_table_extract(request);
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @foreach $c column@
- @if $c.settable@
- case COLUMN_$c.uc:
- @if $i.rowstatus@
- @if $c.rowstatus@
- switch (*request->requestvb->val.integer) {
- case RS_CREATEANDGO:
- case RS_CREATEANDWAIT:
- if (table_entry && !table_entry->valid) {
- ${i}_removeEntry(container, table_entry );
- }
- }
- @else@
- /* Need to restore old 'table_entry->$c' value.
- May need to use 'memcpy' */
- table_entry->$c = table_entry->old_$c;
- @end@
- @else@
- @if $c.creatable@
- if ( table_entry && !table_entry->valid ) {
- ${i}_removeEntry(container, table_entry );
- } else {
- /* Need to restore old 'table_entry->$c' value.
- May need to use 'memcpy' */
- table_entry->$c = table_entry->old_$c;
- }
- @else@
- /* Need to restore old 'table_entry->$c' value.
- May need to use 'memcpy' */
- table_entry->$c = table_entry->old_$c;
- @end@
- @end@
- break;
- @end@
- @end@
- }
- }
- break;
- case MODE_SET_COMMIT:
- @if $i.creatable@
- for (request=requests; request; request=request->next) {
- container = netsnmp_container_table_extract(request);
- table_entry = (struct ${i}_entry *)
- netsnmp_container_table_extract_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- switch (table_info->colnum) {
- @if $i.rowstatus@
- @foreach $c column@
- @if $c.rowstatus@
- case COLUMN_$c.uc:
- switch (*request->requestvb->val.integer) {
- case RS_CREATEANDGO:
- table_entry->valid = 1;
- /* Fall-through */
- case RS_ACTIVE:
- table_entry->$c = RS_ACTIVE;
- break;
- case RS_CREATEANDWAIT:
- table_entry->valid = 1;
- /* Fall-through */
- case RS_NOTINSERVICE:
- table_entry->$c = RS_NOTINSERVICE;
- break;
- case RS_DESTROY:
- ${i}_removeEntry(container, table_entry );
- }
- @end@
- @end@
- @else@
- @foreach $c column@
- @if $c.creatable@
- case COLUMN_$c.uc:
- @end@
- @end@
- if ( table_entry && !table_entry->valid ) {
- table_entry->valid = 1;
- }
- @end@
- }
- }
- @end@
- break;
- @end@
- }
- return SNMP_ERR_NOERROR;
- }
- @end@