/*
 * Note: this file originally auto-generated by mib2c using
 *       version $ of $ 
 *
 * $Id:$
 */
/*
 * *********************************************************************
 * *********************************************************************
 * *********************************************************************
 * ***                                                               ***
 * ***  NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE  ***
 * ***                                                               ***
 * ***                                                               ***
 * ***       THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE.      ***
 * ***                                                               ***
 * ***                                                               ***
 * ***       THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND      ***
 * ***                                                               ***
 * ***                                                               ***
 * ***    IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES.   ***
 * ***                                                               ***
 * ***                                                               ***
 * *********************************************************************
 * *********************************************************************
 * *********************************************************************
 */

/* standard Net-SNMP includes */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-features.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

/* include our parent header */
#include "dot1qTpFdbTable.h"


#include <net-snmp/agent/table_container.h>
#include <net-snmp/library/container.h>

#include "dot1qTpFdbTable_interface.h"

netsnmp_feature_require(baby_steps);
netsnmp_feature_require(row_merge);
netsnmp_feature_require(check_all_requests_error);

#include <ctype.h>

/**********************************************************************
 **********************************************************************
 ***
 *** Table dot1qTpFdbTable
 ***
 **********************************************************************
 **********************************************************************/
/*
 * Q-BRIDGE-MIB::dot1qTpFdbTable is subid 2 of dot1qTp.
 * Its status is Current.
 * OID: .1.3.6.1.2.1.17.7.1.2.2, length: 11
*/
typedef struct dot1qTpFdbTable_interface_ctx_s {

   netsnmp_container              *container;
   netsnmp_cache                  *cache;

   dot1qTpFdbTable_registration *      user_ctx;
   
   netsnmp_table_registration_info  tbl_info;

   netsnmp_baby_steps_access_methods access_multiplexer;

} dot1qTpFdbTable_interface_ctx;

static dot1qTpFdbTable_interface_ctx dot1qTpFdbTable_if_ctx;

static void _dot1qTpFdbTable_container_init(
    dot1qTpFdbTable_interface_ctx *if_ctx);
static void _dot1qTpFdbTable_container_shutdown(
    dot1qTpFdbTable_interface_ctx *if_ctx);


netsnmp_container *
dot1qTpFdbTable_container_get( void )
{
    return dot1qTpFdbTable_if_ctx.container;
}

dot1qTpFdbTable_registration *
dot1qTpFdbTable_registration_get( void )
{
    return dot1qTpFdbTable_if_ctx.user_ctx;
}

dot1qTpFdbTable_registration *
dot1qTpFdbTable_registration_set( dot1qTpFdbTable_registration * newreg )
{
    dot1qTpFdbTable_registration * old = dot1qTpFdbTable_if_ctx.user_ctx;
    dot1qTpFdbTable_if_ctx.user_ctx = newreg;
    return old;
}

int
dot1qTpFdbTable_container_size( void )
{
    return CONTAINER_SIZE(dot1qTpFdbTable_if_ctx.container);
}

/*
 * mfd multiplexer modes
 */
static Netsnmp_Node_Handler _mfd_dot1qTpFdbTable_pre_request;
static Netsnmp_Node_Handler _mfd_dot1qTpFdbTable_post_request;
static Netsnmp_Node_Handler _mfd_dot1qTpFdbTable_object_lookup;
static Netsnmp_Node_Handler _mfd_dot1qTpFdbTable_get_values;
/**
 * @internal
 * Initialize the table dot1qTpFdbTable 
 *    (Define its contents and how it's structured)
 */
void
_dot1qTpFdbTable_initialize_interface(dot1qTpFdbTable_registration * reg_ptr,  u_long flags)
{
    netsnmp_baby_steps_access_methods *access_multiplexer =
        &dot1qTpFdbTable_if_ctx.access_multiplexer;
    netsnmp_table_registration_info *tbl_info = &dot1qTpFdbTable_if_ctx.tbl_info;
    netsnmp_handler_registration *reginfo;
    netsnmp_mib_handler *handler;
    int    mfd_modes = 0;

    DEBUGMSGTL(("internal:dot1qTpFdbTable:_dot1qTpFdbTable_initialize_interface","called\n"));


    /*************************************************
     *
     * save interface context for dot1qTpFdbTable
     */
        /* Don't use netsnmp_table_helper_add_indexes as in the generated code because MacAddress is
     * mapped into ASN_OCTET_STR, which has a length as a first byte, then the content of MAC/string.
     * With this behaviour of ASN_OCTET_STR, the index was 1 byte longer. It is not needed to carry
     * the length of MacAddress since it is defined with a fixed length in the MIB.
     */
    /* netsnmp_table_helper_add_indexes(tbl_info,
     *                            ASN_UNSIGNED,    // index: dot1qFdbId
     *                            ASN_OCTET_STR,   // index: dot1qTpFdbAddress
     *                           0);
     */
    snmp_varlist_add_variable(&tbl_info->indexes,
                                  NULL,
                                  0,
                                  ASN_INTEGER,
                                  NULL,
                                  0);
    snmp_varlist_add_variable(&tbl_info->indexes,
                                  NULL,
                                  0,
                                  ASN_PRIV_IMPLIED_OCTET_STR,
                                  "XXXXXX",
                                  6);

    /*  Define the minimum and maximum accessible columns.  This
        optimizes retrieval. */
    tbl_info->min_column = DOT1QTPFDBTABLE_MIN_COL;
    tbl_info->max_column = DOT1QTPFDBTABLE_MAX_COL;

    /*
     * save users context
     */
    dot1qTpFdbTable_if_ctx.user_ctx = reg_ptr;

    /*
     * call data access initialization code
     */
    dot1qTpFdbTable_init_data(reg_ptr);

    /*
     * set up the container
     */
    _dot1qTpFdbTable_container_init(&dot1qTpFdbTable_if_ctx);
    if (NULL == dot1qTpFdbTable_if_ctx.container) {
        snmp_log(LOG_ERR,"could not initialize container for dot1qTpFdbTable\n");
        return;
    }
    
    /*
     * access_multiplexer: REQUIRED wrapper for get request handling
     */
    access_multiplexer->object_lookup = _mfd_dot1qTpFdbTable_object_lookup;
    access_multiplexer->get_values = _mfd_dot1qTpFdbTable_get_values;

    /*
     * no wrappers yet
     */
    access_multiplexer->pre_request = _mfd_dot1qTpFdbTable_pre_request;
    access_multiplexer->post_request = _mfd_dot1qTpFdbTable_post_request;

#ifndef NETSNMP_DISABLE_SET_SUPPORT
#endif

    /*************************************************
     *
     * Create a registration, save our reg data, register table.
     */
    DEBUGMSGTL(("dot1qTpFdbTable:init_dot1qTpFdbTable",
                "Registering dot1qTpFdbTable as a mibs-for-dummies table.\n"));		 
    handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer);
    reginfo = netsnmp_handler_registration_create("dot1qTpFdbTable", handler,
                                                  dot1qTpFdbTable_oid,
                                                  dot1qTpFdbTable_oid_size,
                                                  HANDLER_CAN_BABY_STEP |
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
                                                  HANDLER_CAN_RONLY
#else
                                                  HANDLER_CAN_RONLY
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
                                                  );
    if(NULL == reginfo) {
        snmp_log(LOG_ERR,"error registering table dot1qTpFdbTable\n");
        return;
    }
    reginfo->my_reg_void = &dot1qTpFdbTable_if_ctx;

    /*************************************************
     *
     * set up baby steps handler, create it and inject it
     */
    if( access_multiplexer->object_lookup )
        mfd_modes |= BABY_STEP_OBJECT_LOOKUP;
    if( access_multiplexer->pre_request )
        mfd_modes |= BABY_STEP_PRE_REQUEST;
    if( access_multiplexer->post_request )
        mfd_modes |= BABY_STEP_POST_REQUEST;
    
#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT))
    if( access_multiplexer->set_values )
        mfd_modes |= BABY_STEP_SET_VALUES;
    if( access_multiplexer->irreversible_commit )
        mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT;
    if( access_multiplexer->object_syntax_checks )
        mfd_modes |= BABY_STEP_CHECK_OBJECT;

    if( access_multiplexer->undo_setup )
        mfd_modes |= BABY_STEP_UNDO_SETUP;
    if( access_multiplexer->undo_cleanup )
        mfd_modes |= BABY_STEP_UNDO_CLEANUP;
    if( access_multiplexer->undo_sets )
        mfd_modes |= BABY_STEP_UNDO_SETS;
    
    if( access_multiplexer->row_creation )
        mfd_modes |= BABY_STEP_ROW_CREATE;
    if( access_multiplexer->consistency_checks )
        mfd_modes |= BABY_STEP_CHECK_CONSISTENCY;
    if( access_multiplexer->commit )
        mfd_modes |= BABY_STEP_COMMIT;
    if( access_multiplexer->undo_commit )
        mfd_modes |= BABY_STEP_UNDO_COMMIT;
#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */
    
    handler = netsnmp_baby_steps_handler_get(mfd_modes);
    netsnmp_inject_handler(reginfo, handler);

    /*************************************************
     *
     * inject row_merge helper with prefix rootoid_len + 2 (entry.col)
     */
    handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2);
    netsnmp_inject_handler(reginfo, handler);

    /*************************************************
     *
     * inject container_table helper
     */
    handler =
        netsnmp_container_table_handler_get(tbl_info,
                                            dot1qTpFdbTable_if_ctx.container,
                                            TABLE_CONTAINER_KEY_NETSNMP_INDEX);
    netsnmp_inject_handler( reginfo, handler );

    /*************************************************
     *
     * inject cache helper
     */
    if(NULL != dot1qTpFdbTable_if_ctx.cache) {
        handler = netsnmp_cache_handler_get(dot1qTpFdbTable_if_ctx.cache);
        netsnmp_inject_handler( reginfo, handler );
    }

    /*
     * register table
     */
    netsnmp_register_table(reginfo, tbl_info);

} /* _dot1qTpFdbTable_initialize_interface */

/**
 * @internal
 * Shutdown the table dot1qTpFdbTable
 */
void
_dot1qTpFdbTable_shutdown_interface(dot1qTpFdbTable_registration * reg_ptr)
{
    /*
     * shutdown the container
     */
    _dot1qTpFdbTable_container_shutdown(&dot1qTpFdbTable_if_ctx);
}

void
dot1qTpFdbTable_valid_columns_set(netsnmp_column_info *vc)
{
    dot1qTpFdbTable_if_ctx.tbl_info.valid_columns = vc;
} /* dot1qTpFdbTable_valid_columns_set */

/**
 * @internal
 * convert the index component stored in the context to an oid
 */
int
dot1qTpFdbTable_index_to_oid(netsnmp_index *oid_idx,
                         dot1qTpFdbTable_mib_index *mib_idx)
{
    int err = SNMP_ERR_NOERROR;
    
    /*
     * temp storage for parsing indexes
     */
    /*
     * dot1qFdbId(1)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/a/w/e/r/d/h
     */
    netsnmp_variable_list var_dot1qFdbId;
    /*
     * dot1qTpFdbAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H
     */
    netsnmp_variable_list var_dot1qTpFdbAddress;

    /*
     * set up varbinds
     */
    memset( &var_dot1qFdbId, 0x00, sizeof(var_dot1qFdbId) );
    var_dot1qFdbId.type = ASN_UNSIGNED;
    memset( &var_dot1qTpFdbAddress, 0x00, sizeof(var_dot1qTpFdbAddress) );
    var_dot1qTpFdbAddress.type = ASN_PRIV_IMPLIED_OCTET_STR;

    /*
     * chain temp index varbinds together
     */
    var_dot1qFdbId.next_variable =  &var_dot1qTpFdbAddress; var_dot1qTpFdbAddress.next_variable =  NULL;


    DEBUGMSGTL(("verbose:dot1qTpFdbTable:dot1qTpFdbTable_index_to_oid","called\n"));

        /* dot1qFdbId(1)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/a/w/e/r/d/h */
    snmp_set_var_value(&var_dot1qFdbId, &mib_idx->dot1qFdbId, sizeof(mib_idx->dot1qFdbId));

        /* dot1qTpFdbAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */
    snmp_set_var_value(&var_dot1qTpFdbAddress, &mib_idx->dot1qTpFdbAddress,
                       mib_idx->dot1qTpFdbAddress_len * sizeof(mib_idx->dot1qTpFdbAddress[0]));


    err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len,
                           NULL, 0, &var_dot1qFdbId);
    if(err)
        snmp_log(LOG_ERR,"error %d converting index to oid\n", err);

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_dot1qFdbId );

    return err;
} /* dot1qTpFdbTable_index_to_oid */

/**
 * extract dot1qTpFdbTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
dot1qTpFdbTable_index_from_oid(netsnmp_index *oid_idx,
                         dot1qTpFdbTable_mib_index *mib_idx)
{
    int err = SNMP_ERR_NOERROR;
    
    /*
     * temp storage for parsing indexes
     */
    /*
     * dot1qFdbId(1)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/a/w/e/r/d/h
     */
    netsnmp_variable_list var_dot1qFdbId;
    /*
     * dot1qTpFdbAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H
     */
    netsnmp_variable_list var_dot1qTpFdbAddress;

    /*
     * set up varbinds
     */
    memset( &var_dot1qFdbId, 0x00, sizeof(var_dot1qFdbId) );
    var_dot1qFdbId.type = ASN_UNSIGNED;
    memset( &var_dot1qTpFdbAddress, 0x00, sizeof(var_dot1qTpFdbAddress) );
    var_dot1qTpFdbAddress.type = ASN_OCTET_STR;

    /*
     * chain temp index varbinds together
     */
    var_dot1qFdbId.next_variable =  &var_dot1qTpFdbAddress; var_dot1qTpFdbAddress.next_variable =  NULL;


    DEBUGMSGTL(("verbose:dot1qTpFdbTable:dot1qTpFdbTable_index_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_dot1qFdbId );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
    mib_idx->dot1qFdbId = *((u_long *)var_dot1qFdbId.val.string);
    /*
     * NOTE: val_len is in bytes, dot1qTpFdbAddress_len might not be
     */
         if(var_dot1qTpFdbAddress.val_len > sizeof(mib_idx->dot1qTpFdbAddress))
             err = SNMP_ERR_GENERR;
         else {
             memcpy(mib_idx->dot1qTpFdbAddress, var_dot1qTpFdbAddress.val.string, var_dot1qTpFdbAddress.val_len);
             mib_idx->dot1qTpFdbAddress_len = var_dot1qTpFdbAddress.val_len / sizeof(mib_idx->dot1qTpFdbAddress[0]);
         }


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_dot1qFdbId );

    return err;
} /* dot1qTpFdbTable_index_from_oid */


/* *********************************************************************
 * @internal
 * allocate resources for a dot1qTpFdbTable_rowreq_ctx
 */
dot1qTpFdbTable_rowreq_ctx *
dot1qTpFdbTable_allocate_rowreq_ctx(void *user_init_ctx)
{
    dot1qTpFdbTable_rowreq_ctx *rowreq_ctx =
                  SNMP_MALLOC_TYPEDEF(dot1qTpFdbTable_rowreq_ctx);

    DEBUGMSGTL(("internal:dot1qTpFdbTable:dot1qTpFdbTable_allocate_rowreq_ctx","called\n"));

    if(NULL == rowreq_ctx) {
        snmp_log(LOG_ERR,"Couldn't allocate memory for a "
                 "dot1qTpFdbTable_rowreq_ctx.\n");
        return NULL;
    }

    rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;

    rowreq_ctx->dot1qTpFdbTable_data_list = NULL;

    /*
     * if we allocated data, call init routine
     */
    if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {
        if(SNMPERR_SUCCESS !=
            dot1qTpFdbTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) {
           dot1qTpFdbTable_release_rowreq_ctx(rowreq_ctx);
           rowreq_ctx = NULL;
        }
    }

    return rowreq_ctx;
} /* dot1qTpFdbTable_allocate_rowreq_ctx */

/*
 * @internal
 * release resources for a dot1qTpFdbTable_rowreq_ctx
 */
void
dot1qTpFdbTable_release_rowreq_ctx(dot1qTpFdbTable_rowreq_ctx *rowreq_ctx)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:dot1qTpFdbTable_release_rowreq_ctx","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);
    
    dot1qTpFdbTable_rowreq_ctx_cleanup(rowreq_ctx);

    /*
     * free index oid pointer
     */
    if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp)
        free(rowreq_ctx->oid_idx.oids);

    SNMP_FREE(rowreq_ctx);
} /* dot1qTpFdbTable_release_rowreq_ctx */

/**
 * @internal
 * wrapper
 */
static int
_mfd_dot1qTpFdbTable_pre_request(netsnmp_mib_handler *handler,
                            netsnmp_handler_registration *reginfo,
                            netsnmp_agent_request_info *agtreq_info,
                            netsnmp_request_info *requests)
{
    int rc;

    DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_pre_request",
                "called\n"));
    
    if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) {
        DEBUGMSGTL(("internal:dot1qTpFdbTable",
                    "skipping additional pre_request\n"));
        return SNMP_ERR_NOERROR;
    }
        
    rc = dot1qTpFdbTable_pre_request(dot1qTpFdbTable_if_ctx.user_ctx);
    if (MFD_SUCCESS != rc) {
        /*
         * nothing we can do about it but log it
         */
        DEBUGMSGTL(("dot1qTpFdbTable","error %d from "
                    "dot1qTpFdbTable_pre_request\n", rc));
        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
    }
    
    return SNMP_ERR_NOERROR;
} /* _mfd_dot1qTpFdbTable_pre_request */

/**
 * @internal
 * wrapper
 */
static int
_mfd_dot1qTpFdbTable_post_request(netsnmp_mib_handler *handler,
                             netsnmp_handler_registration *reginfo,
                             netsnmp_agent_request_info *agtreq_info,
                             netsnmp_request_info *requests)
{
    dot1qTpFdbTable_rowreq_ctx *rowreq_ctx = (dot1qTpFdbTable_rowreq_ctx*)
                  netsnmp_container_table_row_extract(requests);
    int rc, packet_rc;

    DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_post_request",
                "called\n"));

    /*
     * release row context, if deleted
     */
    if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))
        dot1qTpFdbTable_release_rowreq_ctx(rowreq_ctx);

    /*
     * wait for last call before calling user
     */
    if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {
        DEBUGMSGTL(("internal:dot1qTpFdbTable",
                    "waiting for last post_request\n"));
        return SNMP_ERR_NOERROR;
    }
    
    packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);
    rc = dot1qTpFdbTable_post_request(dot1qTpFdbTable_if_ctx.user_ctx,packet_rc);
    if (MFD_SUCCESS != rc) {
        /*
         * nothing we can do about it but log it
         */
        DEBUGMSGTL(("dot1qTpFdbTable","error %d from "
                    "dot1qTpFdbTable_post_request\n", rc));
    }
    
    return SNMP_ERR_NOERROR;
} /* _mfd_dot1qTpFdbTable_post_request */

/**
 * @internal
 * wrapper
 */
static int
_mfd_dot1qTpFdbTable_object_lookup(netsnmp_mib_handler *handler,
                         netsnmp_handler_registration *reginfo,
                         netsnmp_agent_request_info *agtreq_info,
                         netsnmp_request_info *requests)
{
    int                    rc = SNMP_ERR_NOERROR;
    dot1qTpFdbTable_rowreq_ctx *rowreq_ctx = (dot1qTpFdbTable_rowreq_ctx*)
                  netsnmp_container_table_row_extract(requests);
    
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_object_lookup","called\n"));

    /*
     * get our context from mfd
     * dot1qTpFdbTable_interface_ctx *if_ctx =
     *             (dot1qTpFdbTable_interface_ctx *)reginfo->my_reg_void;
     */

    if(NULL == rowreq_ctx) {
        rc = SNMP_ERR_NOCREATION;
    }

    if (MFD_SUCCESS != rc)
        netsnmp_request_set_error_all(requests, rc);
    else
        dot1qTpFdbTable_row_prep(rowreq_ctx);

    return SNMP_VALIDATE_ERR(rc);
} /* _mfd_dot1qTpFdbTable_object_lookup */

/***********************************************************************
 *
 * GET processing
 *
 ***********************************************************************/
/*
 * @internal
 * Retrieve the value for a particular column
 */
NETSNMP_STATIC_INLINE int
_dot1qTpFdbTable_get_column( dot1qTpFdbTable_rowreq_ctx *rowreq_ctx,
                       netsnmp_variable_list *var, int column )
{
    int rc = SNMPERR_SUCCESS;
    
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_get_column",
                "called for %d\n", column));


    netsnmp_assert(NULL != rowreq_ctx);

    switch(column) {

    /* dot1qTpFdbPort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h */
    case COLUMN_DOT1QTPFDBPORT:
    var->val_len = sizeof(long);
    var->type = ASN_INTEGER;
rc = dot1qTpFdbPort_get(rowreq_ctx, (long *)var->val.string );
        break;

    /* dot1qTpFdbStatus(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */
    case COLUMN_DOT1QTPFDBSTATUS:
    var->val_len = sizeof(u_long);
    var->type = ASN_INTEGER;
rc = dot1qTpFdbStatus_get(rowreq_ctx, (u_long *)var->val.string );
        break;

     default:
        if (DOT1QTPFDBTABLE_MIN_COL <= column && column <= DOT1QTPFDBTABLE_MAX_COL) {
            DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_get_column",
                "assume column %d is reserved\n", column));
            rc = MFD_SKIP;
        } else {
            snmp_log(LOG_ERR,
                "unknown column %d in _dot1qTpFdbTable_get_column\n", column);
        }
        break;
    }

    return rc;
} /* _dot1qTpFdbTable_get_column */

int
_mfd_dot1qTpFdbTable_get_values(netsnmp_mib_handler *handler,
                         netsnmp_handler_registration *reginfo,
                         netsnmp_agent_request_info *agtreq_info,
                         netsnmp_request_info *requests)
{
    dot1qTpFdbTable_rowreq_ctx *rowreq_ctx = (dot1qTpFdbTable_rowreq_ctx*)
                  netsnmp_container_table_row_extract(requests);
    netsnmp_table_request_info * tri;
    u_char                     * old_string;
    void                      (*dataFreeHook)(void *);
    int                        rc;

    DEBUGMSGTL(("internal:dot1qTpFdbTable:_mfd_dot1qTpFdbTable_get_values","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);
    
    for(;requests; requests = requests->next) {
        /*
         * save old pointer, so we can free it if replaced
         */
        old_string = requests->requestvb->val.string;
        dataFreeHook = requests->requestvb->dataFreeHook;
        if(NULL == requests->requestvb->val.string) {
            requests->requestvb->val.string = requests->requestvb->buf;
            requests->requestvb->val_len = sizeof(requests->requestvb->buf);
        }
        else if(requests->requestvb->buf == requests->requestvb->val.string) {
            if(requests->requestvb->val_len != sizeof(requests->requestvb->buf))
                requests->requestvb->val_len = sizeof(requests->requestvb->buf);
        }

        /*
         * get column data
         */
        tri = netsnmp_extract_table_info(requests);
        if(NULL == tri)
            continue;
        
        rc = _dot1qTpFdbTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum);
        if(rc) {
            if(MFD_SKIP == rc) {
                requests->requestvb->type = SNMP_NOSUCHINSTANCE;
                rc = SNMP_ERR_NOERROR;
            }
        }
        else if (NULL == requests->requestvb->val.string) {
            snmp_log(LOG_ERR,"NULL varbind data pointer!\n");
            rc = SNMP_ERR_GENERR;
        }
        if(rc)
            netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));

        /*
         * if the buffer wasn't used previously for the old data (i.e. it
         * was allcoated memory)  and the get routine replaced the pointer,
         * we need to free the previous pointer.
         */
        if(old_string && (old_string != requests->requestvb->buf) &&
           (requests->requestvb->val.string != old_string)) {
            if(dataFreeHook)
                (*dataFreeHook)(old_string);
            else
                free(old_string);
        }
    } /* for results */

    return SNMP_ERR_NOERROR;
} /* _mfd_dot1qTpFdbTable_get_values */

/***********************************************************************
 *
 * SET processing
 *
 ***********************************************************************/

/*
 * SET PROCESSING NOT APPLICABLE (per MIB or user setting)
 */
/***********************************************************************
 *
 * DATA ACCESS
 *
 ***********************************************************************/
static void _container_free(netsnmp_container *container);

/**
 * @internal
 */
static int
_cache_load(netsnmp_cache *cache, void *vmagic)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_cache_load","called\n"));

    if((NULL == cache) || (NULL == cache->magic)) {
        snmp_log(LOG_ERR, "invalid cache for dot1qTpFdbTable_cache_load\n");
        return -1;
    }

    /** should only be called for an invalid or expired cache */
    netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
    
    /*
     * call user code
     */
    return dot1qTpFdbTable_container_load((netsnmp_container*)cache->magic);
} /* _cache_load */

/**
 * @internal
 */
static void
_cache_free(netsnmp_cache *cache, void *magic)
{
    netsnmp_container *container;

    DEBUGMSGTL(("internal:dot1qTpFdbTable:_cache_free","called\n"));

    if((NULL == cache) || (NULL == cache->magic)) {
        snmp_log(LOG_ERR, "invalid cache in dot1qTpFdbTable_cache_free\n");
        return;
    }

    container = (netsnmp_container*)cache->magic;

    _container_free(container);
} /* _cache_free */

/**
 * @internal
 */
static void
_container_item_free(dot1qTpFdbTable_rowreq_ctx *rowreq_ctx, void *context)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_container_item_free","called\n"));

    if(NULL == rowreq_ctx)
        return;

    dot1qTpFdbTable_release_rowreq_ctx(rowreq_ctx);
} /* _container_item_free */

/**
 * @internal
 */
static void
_container_free(netsnmp_container *container)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_container_free","called\n"));

    if (NULL == container) {
        snmp_log(LOG_ERR, "invalid container in dot1qTpFdbTable_container_free\n");
        return;
    }

    /*
     * call user code
     */
    dot1qTpFdbTable_container_free(container);
    
    /*
     * free all items. inefficient, but easy.
     */
    CONTAINER_CLEAR(container,
                    (netsnmp_container_obj_func *)_container_item_free,
                    NULL);
} /* _container_free */

/**
 * @internal
 * initialize the container with functions or wrappers
 */
void
_dot1qTpFdbTable_container_init(dot1qTpFdbTable_interface_ctx *if_ctx)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_dot1qTpFdbTable_container_init","called\n"));

    /*
     * cache init
     */
    if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
                                         _cache_load, _cache_free,
                                         dot1qTpFdbTable_oid,
                                         dot1qTpFdbTable_oid_size);

    if(NULL == if_ctx->cache) {
        snmp_log(LOG_ERR, "error creating cache for dot1qTpFdbTable\n");
        return;
    }

    if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;

    dot1qTpFdbTable_container_init(&if_ctx->container, if_ctx->cache);
    if(NULL == if_ctx->container)
        if_ctx->container = netsnmp_container_find("dot1qTpFdbTable:table_container");
    if(NULL == if_ctx->container) {
        snmp_log(LOG_ERR,"error creating container in "
                 "dot1qTpFdbTable_container_init\n");
        return;
    }

    if (NULL != if_ctx->cache)
        if_ctx->cache->magic = (void*)if_ctx->container;
} /* _dot1qTpFdbTable_container_init */

/**
 * @internal
 * shutdown the container with functions or wrappers
 */
void
_dot1qTpFdbTable_container_shutdown(dot1qTpFdbTable_interface_ctx *if_ctx)
{
    DEBUGMSGTL(("internal:dot1qTpFdbTable:_dot1qTpFdbTable_container_shutdown","called\n"));

    dot1qTpFdbTable_container_shutdown(if_ctx->container);

    _container_free(if_ctx->container);

} /* _dot1qTpFdbTable_container_shutdown */


dot1qTpFdbTable_rowreq_ctx *
dot1qTpFdbTable_row_find_by_mib_index(dot1qTpFdbTable_mib_index *mib_idx)
{
    dot1qTpFdbTable_rowreq_ctx   *rowreq_ctx;
    oid                      oid_tmp[MAX_OID_LEN];
    netsnmp_index            oid_idx;
    int                      rc;

    /*
     * set up storage for OID
     */
    oid_idx.oids = oid_tmp;
    oid_idx.len = sizeof(oid_tmp)/sizeof(oid);

    /*
     * convert
     */
    rc = dot1qTpFdbTable_index_to_oid(&oid_idx, mib_idx);
    if (MFD_SUCCESS != rc)
        return NULL;

    rowreq_ctx = (dot1qTpFdbTable_rowreq_ctx*)CONTAINER_FIND(dot1qTpFdbTable_if_ctx.container, &oid_idx);

    return rowreq_ctx;
}

