📄 ax_index.c
字号:
/* * 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 1994-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: ax_index.c,v $ * Revision 1.4 2001/11/06 21:50:43 josh * second (and hopefully final) pass of new path hacking * * Revision 1.3 2001/11/06 21:20:02 josh * revised new path hacking * * Revision 1.2 2001/11/06 20:11:13 josh * updating include paths to include proper path to layout directory * * Revision 1.1.1.1 2001/11/05 17:47:41 tneale * Tornado shuffle * * Revision 9.3 2001/04/11 20:12:01 josh * merging changes from the kingfisher branch back onto * the trunk * * Revision 9.2 2001/01/19 22:22:16 paul * Update copyright. * * Revision 9.1.2.2 2001/03/12 22:08:07 tneale * Updated copyright * * Revision 9.1.2.1 2000/10/13 21:17:34 josh * function prototypes and static declarations to eliminate warnings * from the Tornado compiler * * Revision 9.1 2000/03/17 00:18:52 meister * Update copyright message * * Revision 9.0 1998/10/16 22:10:50 sar * Update version stamp to match release * * Revision 8.3 1998/06/19 20:07:06 sar * Save a pointer to the index data when building an entry * Add incudes for asn1conf and snmp to make sure we get all * of the common stuff. * * Revision 8.2 1998/06/09 21:46:40 sar * Cleaned up some code that might have called alloc or memcmp with * 0 lenght strings * * Revision 8.1 1998/02/25 04:51:12 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:37 sar * Updated revision to 8.0 * * Revision 1.5 1997/10/31 03:48:04 sar * cleanup index comparisons and allocation of unused indexes * * Revision 1.4 1997/10/22 23:46:55 sar * initialize the right stat variable * * Revision 1.3 1997/10/22 17:12:37 sar * initialize a variable (stat) to keep compilers happy * * Revision 1.2 1997/10/18 01:51:38 sar * several changes, moslty dealing with getting the comparisons to * be correct, also getting the linked list correct and making sure * we always set the session id for new entries. * * Revision 1.1 1997/10/16 00:32:32 sar * The base files for the agentx protocol. * ax_core.c - core encoding and decoding routines, both master and sub * ax_chunk.c - transform a byte stream into agentx packets, both * ax_index.c - support for the index reservation scheme, master * ax_ma.c - master side routines, master * ax_mth.c - method routines for the agentx mib, master * ax_sa.c - sub agent side routines, sub * ax_sa_cr.c - packet creation code, mostly will be used on sub * *//* [clearcase]modification history-------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/agentx.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/tree.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/util/layout/ldbglue.h>#include <wrn/wm/util/layout/agentx.h>/****************************************************************************NAME: ax_ma_compare_indexesPURPOSE: compare an the value from a vbp with the value from an index structure, this returns -1, 0 or 1 as the vbp is less than, equal to or greater than the index. notice that we don't use the standard lexicographical order instead we order all strings or object ids of length n as less than strings or objects ids of length n+1 we do this to allow the ordering of the list to make it easy to find a short next index for "new" requests.PARAMETERS: int if 0 use the vbp as first index, otherwise use the first ax_index VB_T * if flag is 0 the first index ENVOY_AX_INDEX_DATA_T * if flag is !0 the first index ENVOY_AX_INDEX_DATA_T * the second index RETURNS: int -1 first index less than second, 0 = equal, 1 greater than****************************************************************************/static int ax_ma_compare_indexes(int first_flag, VB_T *vbp, ENVOY_AX_INDEX_DATA_T *first_idata, ENVOY_AX_INDEX_DATA_T *second_idata){bits32_t bits32_value;ALENGTH_T vlen;bits8_t *vbuf, *ibuf;int vlen2;OIDC_T *voidc, *ioidc;switch(vbp->vb_data_flags_n_type) { case VT_NUMBER: if (first_flag == 0) bits32_value = vbp->value_u.v_number; else bits32_value = first_idata->data.bits32; if (bits32_value < second_idata->data.bits32) return(-1); if (bits32_value == second_idata->data.bits32) return(0); return(1); case VT_STRING: if (first_flag == 0) { vlen = EBufferUsed(&vbp->value_u.v_string); vbuf = EBufferStart(&vbp->value_u.v_string); } else { vlen = first_idata->data.string.length; vbuf = first_idata->data.string.buffer; } if (vlen < second_idata->data.string.length) return(-1); if (vlen > second_idata->data.string.length) return(1); ibuf = second_idata->data.string.buffer; for(; vlen; vlen--, vbuf++, ibuf++) { if (*vbuf < *ibuf) return(-1); if (*vbuf > *ibuf) return(1); } return(0); case VT_OBJECT: if (first_flag == 0) { vlen2 = vbp->value_u.v_object.num_components; voidc = vbp->value_u.v_object.component_list; } else { vlen2 = first_idata->data.objid.num_components; voidc = first_idata->data.objid.component_list; } if (vlen2 < second_idata->data.objid.num_components) return(-1); if (vlen2 > second_idata->data.objid.num_components) return(1); ioidc = second_idata->data.objid.component_list; for(; vlen2; vlen2--, voidc++, ioidc++) { if (*voidc < *ioidc) return(-1); if (*voidc > *ioidc) return(1); } return(0); case VT_IPADDRESS: vlen = 4; if (first_flag == 0) vbuf = (bits8_t *)&vbp->value_u.v_network_address; else vbuf = first_idata->data.ipaddr; ibuf = second_idata->data.ipaddr; for(; vlen; vlen--, vbuf++, ibuf++) { if (*vbuf < *ibuf) return(-1); if (*vbuf > *ibuf) return(1); } return(0); }/*should never get here */return(1);}/****************************************************************************NAME: ax_ma_build_new_indexPURPOSE: determine that the next new instance is and try to build an index entry using that instance.PARAMETERS: ENVOY_AX_INDEX_HDR_T * header for the list VB_T * var bind with the information on the index RETURNS: ENVOY_AX_INDEX_DATA_T *****************************************************************************/static ENVOY_AX_INDEX_DATA_T * ax_ma_build_new_index(ENVOY_AX_INDEX_HDR_T *ihdr, VB_T *vbp){ENVOY_AX_INDEX_DATA_T *idata, **idatap = 0;int stat;OIDC_T *oidc, *oidc2;bits8_t *buf;idata = (ENVOY_AX_INDEX_DATA_T *) SNMP_memory_alloc(sizeof(ENVOY_AX_INDEX_DATA_T));if (idata == 0) return(0);switch(vbp->vb_data_flags_n_type) { case VT_NUMBER: for (idata->data.bits32 = 1, idatap = &ihdr->data; *idatap; idatap = &(*idatap)->next) { stat = ax_ma_compare_indexes(1, vbp, idata, *idatap); if (stat == -1) break; if (stat == 1) continue; if (++idata->data.bits32) continue; SNMP_memory_free(idata); return(0); } break; case VT_IPADDRESS: buf = idata->data.ipaddr; buf[0] = buf[1] = buf[2] = 0; for (buf[3] = 1, idatap = &ihdr->data; *idatap; idatap = &(*idatap)->next) { stat = ax_ma_compare_indexes(1, vbp, idata, *idatap); if (stat == -1) break; if (stat == 1) continue; if (++buf[3] != 0) continue; if (++buf[2] != 0) continue; if (++buf[1] != 0) continue; if (++buf[0] != 0) continue; SNMP_memory_free(idata); return(0); } break; case VT_STRING: buf = SNMP_memory_alloc(4); if (buf == 0) { SNMP_memory_free(idata); return(0); } idata->data.string.length = 4; idata->data.string.buffer = buf; buf[0] = buf[1] = buf[2] = 0; for (buf[3] = 1, idatap = &ihdr->data; *idatap; idatap = &(*idatap)->next) { stat = ax_ma_compare_indexes(1, vbp, idata, *idatap); if (stat == -1) break; if (stat == 1) continue; if (++buf[3] != 0) continue; if (++buf[2] != 0) continue; if (++buf[1] != 0) continue; if (++buf[0] != 0) continue; SNMP_memory_free(buf); SNMP_memory_free(idata); return(0); } break; case VT_OBJECT: oidc = (OIDC_T *)SNMP_memory_alloc(sizeof(OIDC_T) * 2); if (oidc == 0) { SNMP_memory_free(idata); return(0); } idata->data.objid.num_components = 2; idata->data.objid.component_list = oidc; *oidc = 1; oidc2 = oidc+1; for (*oidc2 = 1, idatap = &ihdr->data; *idatap; idatap = &(*idatap)->next) { stat = ax_ma_compare_indexes(1, vbp, idata, *idatap); if (stat == -1) break; if (stat == 1) continue; (*oidc2)++; if (*oidc2) continue; SNMP_memory_free(oidc); SNMP_memory_free(idata); return(0); } break; }idata->next = *idatap;*idatap = idata;return(idata);}/****************************************************************************NAME: ax_ma_find_indexPURPOSE: find an index in the listPARAMETERS: ENVOY_AX_INDEX_DATA_T * first entry in the list VB_T * var bind with the information on the index RETURNS: ENVOY_AX_INDEX_DATA_T *****************************************************************************/static ENVOY_AX_INDEX_DATA_T * ax_ma_find_index(ENVOY_AX_INDEX_DATA_T *first, VB_T *vbp, bits32_t session_id){ENVOY_AX_INDEX_DATA_T *idata;for (idata = first; idata; idata = idata->next) { if (idata->session_id != session_id) continue; switch(ax_ma_compare_indexes(0, vbp, 0, idata)) { case -1: return(0); case 0: return(idata); case 1: continue; } }return(0);}/****************************************************************************NAME: ax_ma_cleanup_indexesPURPOSE: Routine to cleanup any indexes that have been registered by a sub agent when it decided to close the sessionPARAMETERS: bits32_t id of the session to close RETURNS: void****************************************************************************/void ax_ma_cleanup_indexes(bits32_t session_id){TREENODE_T *tnode;ENVOY_AX_CONTEXT_T *context;ENVOY_AX_INDEX_HDR_T *ihdr;ENVOY_AX_INDEX_DATA_T *idata;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -