📄 row.c
字号:
/* row.c - row.c routines *//* * Copyright 2000-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * Copyright 1991-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: row.c,v $ * Revision 1.2 2001/11/06 21:20:21 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:40 tneale * Tornado shuffle * * Revision 9.3 2001/01/19 22:21:58 paul * Update copyright. * * Revision 9.2 2000/03/17 00:17:42 meister * Update copyright message * * Revision 9.1 1999/05/24 20:12:06 josh * 'compc' and 'compl' have been replaced by 'tcount' and 'tlist' * to avoid C++ compiler errors. * * Revision 9.0 1998/10/16 22:09:37 sar * Update version stamp to match release * * Revision 8.3 1998/06/08 20:02:22 sar * Modify var bind check to make sure we have a leaf and to check * all of the flags before the oid compare * * Revision 8.2 1998/06/05 18:52:57 sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.1 1998/02/25 04:49:57 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:13 sar * Updated revision to 8.0 * * Revision 7.3 1997/03/20 06:50:20 sra * DFARS-safe copyright text. Zap! * * Revision 7.2 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.1 1996/10/06 03:46:13 sar * Corrected ending condition in scan_vb_for_leaf, switched from * vbl_count to vbl_count - 1 * * Revision 7.0 1996/03/15 22:21:24 sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.1 1996/01/05 19:02:18 sar * Removed no_pp style definitions as well as unnecessary include files * * Revision 6.0 1995/05/31 21:50:52 sra * Release 6.0. * * Revision 5.1 1995/03/16 21:13:45 sar * Modified internal calls to use a var bind pointer instead of an index. * * Revision 5.0 1994/05/16 15:29:57 sar * Updated revision to 5.0 and copyright to 1994 * * Revision 4.0 1993/06/24 15:58:43 sar * Updated rev to 4.0 and copyright to 93 * * Revision 3.4 1993/06/02 23:07:24 dab * Changed #ifdef's to #if's for things from install.h * * Revision 3.3 1993/04/27 20:52:51 sar * moved index_to_vbp to snmp/buildpkt.c (where a copy already existed). * updated the makefile to ignore indx_vbp.c. * update row.c to use buildpkt.h to find index_to_vbp. * * Revision 3.2 1993/04/26 20:22:55 sar * Added ifdefs to allow clean version 1 or version 2 makes. * * Revision 3.1 1993/02/26 17:25:51 sar * made scan_for_leaf_and_match and scan_vb_for_leaf useable by outside * routines (removed the static declaration).\ * * Revision 3.0 1992/04/03 19:53:01 dab * Release 3.0 * * Revision 1.6 92/03/31 12:23:55 dab * Changed flags in the create_row structure again. * * Revision 1.5 92/03/31 11:17:11 dab * Use flags in create_row structure instead of just needed field. * * Revision 1.4 92/03/26 15:08:00 dab * Fixed bug where scan_for_leaf_and_match went into an infinte loop if * it hit an error. * * Revision 1.3 92/03/05 16:37:25 romkey * corrected 'tatic' to 'static' * * Revision 1.2 92/02/27 16:48:56 dab * Changed to use MIBLEAF_T* instead of a locator value. * * Revision 1.1 91/11/06 14:42:36 dab * Initial revision * *//* [clearcase]modification history-------------------01d,12may05,job fix apigen comments01c,18apr05,job update copyright notices01b,23feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains row.c routines.INCLUDE FILES: snmp.h, auxfuncs.h*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>/* Scans the varbind list of the packet, starting at vb_index, looking for a * varbind that references the MIB node leaf. Returns a pointer to the * varbind or 0 if it doesn't find any. */VB_T * scan_vb_for_leaf(SNMP_PKT_T *pktp, VB_T *vbp, MIBLEAF_T *leaf){VB_T *last_vbp;VBL_T *vblp; #if INSTALL_ENVOY_SNMP_VERSION_1if (pktp->pdu_type == TRAP_PDU) vblp = &(pktp->pdu.trap_pdu.trap_vbl); else#endif /* find the last vblp, which is always the one we are working on */ for (vblp = &(pktp->pdu.std_pdu.std_vbl); vblp->vblp; vblp = vblp->vblp) ; for (last_vbp = &vblp->vblist[vblp->vbl_count - 1]; vbp <= last_vbp; vbp++) { if (vbp->vb_ml.ml_leaf == leaf) return vbp; } return 0; /* Not found */}/* Look for the varbind matching leaf node and also having the same instance * as tcount/tlist. */VB_T * scan_for_leaf_and_match(SNMP_PKT_T *pkt, VB_T *vbp, MIBLEAF_T *leaf, int tcount, OIDC_T *tlist){vbp--; /* set up vbp so scan_vb_for_leaf starts at vbp */while (1) { vbp = scan_vb_for_leaf(pkt, vbp + 1, leaf); if (vbp == 0) return 0; /* we didn't find a match */ /* Check the instance */ if (((vbp->vb_flags & (VFLAG_SET_STARTED | VFLAG_SET_DONE | VFLAG_TEST_STARTED | VFLAG_TEST_DONE)) == 0) && (tcount == vbp->vb_ml.ml_remaining_objid.num_components) && (oidorder(vbp->vb_ml.ml_remaining_objid.component_list, tlist, tcount) == 0)) return vbp; }}/********************************************************************************* vb_extract_row - group similar 'VarBinds' to create a row in a table* SYNOPSIS** \cs* struct create_row * {* MIBLEAF_T * leaf * OCTET_T flags; * } ** #define ROW_FLAG_NEEDED 0x01 * #define ROW_FLAG_CALL_SET 0x02 ** VB_T * vb_extract_row * ( * SNMP_PKT_T * pktp, * int start_index, * int instance_length, * OIDC_T * instance, * int row_structure_length, * struct create_row * row * )* \ce** DESCRIPTION** This routine is often used by the 'testproc' routine to create a row in a * table. It scans the SNMP packet for all the pieces that go together. It * searches the 'VarBinds' in the packet for any 'VarBinds' that match the MIB * leaf pointer specified in the <row> array and <instance>.* This routine links the VarBinds from the first MIB leaf node in the row * array, marks them as tested and as already set, except for the first entry. * After this is done, Envoy only needs to call the set routine associated with * the first MIB leaf in the row array. If you want to call another entry\抯 set * routine separately, set the entry\抯 flag to ROW_FLAG_CALL_SET.** \&NOTE: This routine is obsolete and maintained for backward compatibility. * Use group_by_getproc_and_instance() for new applications.** PARAMETERS* \is* \i <leaf>* Specify a MIB leaf entry* \i <flags>* Indicate if this variable (column) in the table is required.* \i <*pktp>* Specify an SNMP packet.* \i <start_index>* Specify the first 'VarBind'. This 'VarBind' must be in the packet whether it * is marked as needed or not.* \i <instance_length>* Specify the length in bytes of <instance>.* \i <*instance>* Specify the instance to match.* \i <row_structure_length>* Specify the length of the <row> array.* \i <*row>* Specify a list of MIB leaf pointers referring to variables in the table.* \ie** RETURNS: If successful, this routine returns the first 'VarBind' in the * packet. If this routine does not find a matching 'VarBind' and the leaf is * flagged as 'ROW_FLAG_NEEDED' in the <row> array, it returns 0.** ERRNO: N/A** SEE ALSO: group_by_getproc_and_instance(), vb_extract_row_loose()*/VB_T * vb_extract_row(SNMP_PKT_T *pkt, int start_indx, int tcount, OIDC_T *tlist, int row_len, struct create_row *row){VB_T *start_vbp, *first_vb, *vbp;VB_T **vb_linkp;/* set up the starting vbp */start_vbp = index_to_vbp(pkt, start_indx);/* Look up the first one and set it up as the first in the linked * list and as the only one whos set method will be called. */first_vb = scan_for_leaf_and_match(pkt, start_vbp, row->leaf, tcount, tlist);if (first_vb == 0) return 0;first_vb->vb_link = 0;vb_linkp = &first_vb->vb_link;first_vb->vb_flags |= VFLAG_ALREADY_TEST;/* Now get all the rest of the row, returning 0 if needed elements * are missing. */for (row++, row_len--; row_len; row++, row_len--) { vbp = scan_for_leaf_and_match(pkt, start_vbp, row->leaf, tcount, tlist); if (vbp != 0) { /* Link it in and mark it done. */ vbp->vb_link = 0; *vb_linkp = vbp; vb_linkp = &vbp->vb_link; vbp->vb_flags |= (row->flags & ROW_FLAG_CALL_SET) ? VFLAG_ALREADY_TEST : VFLAG_ALREADY_TEST | VFLAG_ALREADY_SET; } else if (row->flags & ROW_FLAG_NEEDED) return 0; /* needed piece is missing */ }return first_vb;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -