Title: Help required for table iterator

Hi All,
     I am new to net-snmp.
I generated code using mib2c.iterate.conf for adslMIB. In create entry I am hardcoding the node value(for testing purpose only.) The problem is that
 1. It is retriving first row only. and i am facing problem in the table switch over.
 2.  What should I need to do to stop it when the retrival of first row is over.
I am sending generated code
Thanks in advance
 Regards
 Shree Kant

===============================================================================================================

/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.iterate.conf,v 5.14 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 "adslLineTable.h"

    /*
     * Typical data structure for a row entry
     */
struct adslLineTable_entry {
    /*
     * Index values
     */
    long            ifIndex;

    /*
     * Column values
     */
    long            adslLineCoding;
    long            adslLineType;
    oid             adslLineSpecific;
    char            adslLineConfProfile[10];
    char            old_adslLineConfProfile;
    char            adslLineAlarmConfProfile[20];
    char            old_adslLineAlarmConfProfile[20];

    /*
     * Illustrate using a simple linked list
     */
    int             valid;
    struct adslLineTable_entry *next;
};
struct adslLineTable_entry *adslLineTable_head = NULL;
void filldata(void)
{
     struct adslLineTable_entry *firstEntry;
     int a=11;
     firstEntry = SNMP_MALLOC_TYPEDEF(struct adslLineTable_entry);
     if(NULL == firstEntry)
     {
        return NULL;
     }
     firstEntry->ifIndex = 1;
    
     adslLineTable_head = firstEntry;
     if(NULL == adslLineTable_head)
     {
       return NULL;
     }
     adslLineTable_head->next = NULL;
}

/** Initializes the adslLineTable module */
void
init_adslLineTable(void)
{
    /*
     * here we initialize all the tables we're planning on supporting
     */
    initialize_table_adslLineTable();
}

/** Initialize the adslLineTable table by defining its contents and how it's structured */
void
initialize_table_adslLineTable(void)
{
    static oid      adslLineTable_oid[] =
        { 1, 3, 6, 1, 2, 1, 10, 94, 1, 1, 1 };
    size_t          adslLineTable_oid_len = OID_LENGTH(adslLineTable_oid);
    netsnmp_handler_registration *reg;
    netsnmp_iterator_info *iinfo;
    netsnmp_table_registration_info *table_info;

    reg =
        netsnmp_create_handler_registration("adslLineTable",
                                            adslLineTable_handler,
                                            adslLineTable_oid,
                                            adslLineTable_oid_len,
                                            HANDLER_CAN_RWRITE);

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: ifIndex */
                                     0);
    table_info->min_column = 1;
    table_info->max_column = 5;

    iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
    iinfo->get_first_data_point = adslLineTable_get_first_data_point;
    iinfo->get_next_data_point = adslLineTable_get_next_data_point;
    iinfo->table_reginfo = table_info;

    netsnmp_register_table_iterator(reg, iinfo);
    /*
     * Initialise the contents of the table here
     */
    adslLineTable_head = adslLineTable_createEntry(1);
}


/*
 * create a new row in the (unsorted) table
 */
struct adslLineTable_entry *
adslLineTable_createEntry(long ifIndex)
{
    struct adslLineTable_entry *entry= NULL;
   int a = 11;
    entry = SNMP_MALLOC_TYPEDEF(struct adslLineTable_entry);
    if (!entry)
        return NULL;

    entry->ifIndex = ifIndex;
     entry->adslLineCoding = 1;
     entry->adslLineType = 1;
     snmp_parse_oid("1.0.1.2.2.3", &entry->adslLineSpecific , &a);
     strcpy(entry->adslLineConfProfile ,"SNMP");
     strcpy(entry->adslLineAlarmConfProfile,"SNMP Alarm");
    adslLineTable_head = entry;
    entry->next = NULL;
    return entry;
}

/*
 * remove a row from the table
 */
void
adslLineTable_removeEntry(struct adslLineTable_entry *entry)
{
    struct adslLineTable_entry *ptr, *prev;

    if (!entry)
        return;                 /* Nothing to remove */

    for (ptr = adslLineTable_head, prev = NULL;
         ptr != NULL; prev = ptr, ptr = ptr->next) {
        if (ptr == entry)
            break;
    }
    if (!ptr)
        return;                 /* Can't find it */

    if (prev == NULL)
        adslLineTable_head = ptr->next;
    else
        prev->next = ptr->next;

    SNMP_FREE(entry);           /* XXX - release any other internal resources */
}

/*
 * Example iterator hook routines - using 'get_next' to do most of the work
 */
netsnmp_variable_list *
adslLineTable_get_first_data_point(void **my_loop_context,
                                   void **my_data_context,
                                   netsnmp_variable_list * put_index_data,
                                   netsnmp_iterator_info *mydata)
{
     *my_loop_context = adslLineTable_head;
    return adslLineTable_get_next_data_point(my_loop_context,
                                             my_data_context,
                                             put_index_data, mydata);
}

netsnmp_variable_list *
adslLineTable_get_next_data_point(void **my_loop_context,
                void **my_data_context,
                netsnmp_variable_list * put_index_data,
                netsnmp_iterator_info *mydata)
{
        struct adslLineTable_entry *entry =
                (struct adslLineTable_entry *) *my_loop_context;
        netsnmp_variable_list *idx = put_index_data;
        if (entry!=NULL)
        {
                snmp_set_var_value(idx, &(entry->ifIndex), sizeof(entry->ifIndex));
                idx = idx->next_variable;
                *my_data_context = (void *) entry;
                *my_loop_context = (void *) entry->next;
        }


        if(NULL == entry)

        {
                return NULL;
        }
        return put_index_data;
}


/** handles requests for the adslLineTable table */
int
adslLineTable_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;
    struct adslLineTable_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 adslLineTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_ADSLLINECODING:
                snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                        (const char *) &(table_entry->adslLineCoding),
                                         sizeof(table_entry->
                                                adslLineCoding));
                break;
            case COLUMN_ADSLLINETYPE:
                snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                            (const char *)&(table_entry->adslLineType),
                                         sizeof(table_entry->
                                                adslLineType));
                break;
            case COLUMN_ADSLLINESPECIFIC:
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
                                        (const char *)&(table_entry->adslLineSpecific),
                                         sizeof(table_entry->
                                                adslLineSpecific));
                break;
            case COLUMN_ADSLLINECONFPROFILE:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (const char *)&(table_entry->adslLineConfProfile),
                                         sizeof(table_entry->
                                                adslLineConfProfile));
                break;
            case COLUMN_ADSLLINEALARMCONFPROFILE:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (const char *)&(table_entry->
                                         adslLineAlarmConfProfile),
                                         sizeof(table_entry->
                                                adslLineAlarmConfProfile));
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            table_entry = (struct adslLineTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_ADSLLINECONFPROFILE:
                if (request->requestvb->type != ASN_OCTET_STR) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Also may need to check size/value
                 */
                break;
            case COLUMN_ADSLLINEALARMCONFPROFILE:
                if (request->requestvb->type != ASN_OCTET_STR) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Also may need to check size/value
                 */
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        break;

    case MODE_SET_ACTION:
        for (request = requests; request; request = request->next) {
            table_entry = (struct adslLineTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {

            case COLUMN_ADSLLINECONFPROFILE:
 //               /*
   //              * Need to save old 'table_entry->adslLineConfProfile' value.
     //            * May need to use 'memcpy'
       //          */
         //       table_entry->old_adslLineConfProfile =
           //         table_entry->adslLineConfProfile;
             //  // table_entry->adslLineConfProfile =
               //  //   request->requestvb->val.YYY;
 //               break;
   //         case COLUMN_ADSLLINEALARMCONFPROFILE:
     //           /*
       //          * Need to save old 'table_entry->adslLineAlarmConfProfile' value.
         //        * May need to use 'memcpy'
      //           */
    //            table_entry->old_adslLineAlarmConfProfile =
  //                  table_entry->adslLineAlarmConfProfile;
               // table_entry->adslLineAlarmConfProfile =
                 //   request->requestvb->val.YYY;
//                break;
            }
        }
        break;

    case MODE_SET_UNDO:
        for (request = requests; request; request = request->next) {
            table_entry = (struct adslLineTable_entry *)
                netsnmp_extract_iterator_context(request);
            table_info = netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case COLUMN_ADSLLINECONFPROFILE:
                /*
                 * Need to restore old 'table_entry->adslLineConfProfile' value.
                 * May need to use 'memcpy'
                 */
           //     table_entry->adslLineConfProfile =
             //       table_entry->old_adslLineConfProfile;
                break;
            case COLUMN_ADSLLINEALARMCONFPROFILE:
                /*
                 * Need to restore old 'table_entry->adslLineAlarmConfProfile' value.
                 * May need to use 'memcpy'
                 */
          //      table_entry->adslLineAlarmConfProfile =
            //        table_entry->old_adslLineAlarmConfProfile;
                break;
            }
        }
        break;

    case MODE_SET_COMMIT:
        break;
    }
    return SNMP_ERR_NOERROR;
}

Reply via email to