#############################################################  -*- c -*-
## generic include for XXX. Do not use directly.
##
## $Id: generic-table-indexes-from-oid.m2i 11300 2004-10-08 23:39:17Z rstory $
########################################################################
@if $m2c_mark_boundary == 1@
/** START code generated by $RCSfile$ $Revision: 11300 $ */
@end@
########################################################################
##
/**
 * extract ${context} indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
${context}_index_from_oid(netsnmp_index *oid_idx,
                         ${context}_mib_index *mib_idx)
{
@include generic-table-indexes-varbind-setup.m2i@

    DEBUGMSGTL(("verbose:${context}:${context}_index_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_$m2c_dii_first );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
@    eval $m2c_node_name = ""@ # purge node name to re-eval $m2c_node_var_name
@    foreach $node index@
@        eval $m2c_node_var_name = "var_${node}."@
@        include m2c_setup_node.m2i@
@        if $m2c_node_needlength == 1@
    /*
     * NOTE: val_len is in bytes, ${node}_len might not be
     */
         if(var_${node}.val_len > sizeof(mib_idx->$node))
             err = SNMP_ERR_GENERR;
         else {
             memcpy(mib_idx->${node}, var_${node}.val.string, var_${node}.val_len);
             mib_idx->${node}_len = var_${node}.val_len / sizeof(mib_idx->${node}[0]);
         }
@        else@
    mib_idx->$node = $m2c_node_var_val;
@        end@
@    end@ # foreach
@    eval $m2c_node_var_name = ""@ #reset custom name
@    eval $m2c_node_name = ""@ # purge node name to re-eval $m2c_node_var_name


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_$m2c_dii_first );

    return err;
} /* ${context}_index_from_oid */

##
########################################################################
@if $m2c_mark_boundary == 1@
/** END code generated by $RCSfile$ $Revision: 11300 $ */
@end@
