## -*- c -*- ###################################################################### ## Do the .h file ###################################################################### @open ${name}.h@ /* * Note: this file originally auto-generated by mib2c using * $Id: mib2c.table_data.conf,v 1.3 2004/10/14 12:57:34 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.table_data.conf,v 1.3 2004/10/14 12:57:34 dts12 Exp $ */ #include #include #include #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_table_data *table_data; 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@ ); table_data = netsnmp_create_table_data( "$i" ); 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_register_table_data( reg, table_data, table_info ); /* Initialise the contents of the table here */ } /* Typical data structure for a row entry */ struct ${i}_entry { /* 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 */ netsnmp_table_row * ${i}_createEntry(netsnmp_table_data *table_data, @foreach $idx index@ $idx.decl $idx, @end@ ) { struct ${i}_entry *entry; netsnmp_table_row *row; entry = SNMP_TYPEDEF_MALLOC(struct ${i}_entry); if (!entry) return NULL; row = netsnmp_create_table_data_row(); if (!row) { SNMP_FREE(entry); return NULL; } row->data = entry; @foreach $idx index@ entry->$idx = $idx; netsnmp_table_row_add_index( row, $idx.type, &(entry->$idx), sizeof(entry->$idx)); @end@ netsnmp_table_data_add_row( table_data, row ); return row; } /* remove a row from the table */ void ${i}_removeEntry(netsnmp_table_data *table_data, netsnmp_table_row *row) { struct ${i}_entry *entry; if (!row) return; /* Nothing to remove */ entry = (struct ${i}_entry) netsnmp_table_data_remove_and_delete_row( table_data, row ); 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_table_row *table_row; 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_extract_table_row_data(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_extract_table_row_data(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) { table_row = (netsnmp_table_row *) netsnmp_extract_table_row( request); table_data = netsnmp_extract_table( 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_row = ${i}_createEntry(table_data @foreach $idx index@ , table_info->indexes->val.YYY @end@ ); if (table_row) { netsnmp_insert_table_row( request, table_row ); } 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_row ) { table_row = ${i}_createEntry(table_data @foreach $idx index@ , table_info->indexes->val.YYY @end@ ); if (table_row) { netsnmp_insert_table_row( request, table_row ); } 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) { table_entry = (struct ${i}_entry *) netsnmp_extract_table_row_data(request); table_row = (netsnmp_table_row *) netsnmp_extract_table_row( request); table_data = netsnmp_extract_table( 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(table_data, table_row ); } } @end@ @end@ @else@ @foreach $c column@ @if $c.creatable@ case COLUMN_$c.uc: @end@ @end@ if ( table_entry && !table_entry->valid ) { ${i}_removeEntry(table_data, table_row ); } break; @end@ } } @end@ break; case MODE_SET_ACTION: for (request=requests; request; request=request->next) { table_entry = (struct ${i}_entry *) netsnmp_extract_table_row_data(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_extract_table_row_data(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) { table_entry = (struct ${i}_entry *) netsnmp_extract_table_row_data(request); table_row = (netsnmp_table_row *) netsnmp_extract_table_row( request); table_data = netsnmp_extract_table( 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(table_data, table_row ); } } @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(table_data, table_row ); } 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) { table_entry = (struct ${i}_entry *) netsnmp_extract_table_row_data(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(table_data, table_row ); } @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@