📄 ttmth.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 1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: ttmth.c,v $ * Revision 1.7 2003/01/15 14:05:18 josh * directory structure shifting * * Revision 1.6 2001/12/07 22:13:33 josh * tthnd.h is dynamically generated and needs to be included locally * * Revision 1.5 2001/11/09 17:43:45 josh * updates for proper clean targets and paths for generated include files * * Revision 1.4 2001/11/08 22:18:36 meister * rework pathnames * * Revision 1.3 2001/11/06 21:50:55 josh * second (and hopefully final) pass of new path hacking * * Revision 1.2 2001/11/06 21:20:41 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:50 tneale * Tornado shuffle * * Revision 1.2 2001/04/16 19:38:44 josh * merging the kingfisher branch onto the trunk * * Revision 1.1.2.2 2001/03/12 22:11:37 tneale * Updated copyright * * Revision 1.1.2.1 2000/12/05 22:09:54 tneale * Method routines for the AgentX subagents test table mib * * Revision 1.2 2000/03/17 00:13:15 meister * Update copyright message * * Revision 1.1 1998/08/10 19:31:10 josh * AgentX subagent code * * *//* [clearcase]modification history-------------------01b,19apr05,job update copyright notices01a,02dec03,job update copyright information*/#include <wrn/wm/common/install.h>#include <snmptalk.h>#include <wrn/wm/common/types.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/agentx.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include "../tthnd.h"typedef struct testtable_s { OBJ_ID_T index; sbits32_t integer; bits32_t counter; bits32_t high64; bits32_t low64; int stringlen; bits8_t *string; OBJ_ID_T objectid; } testtable_t;typedef struct iandp_s { int count; bits8_t *buf; testtable_t *tab_entry; } iandp_t;#define LM_TT_INDEX 1#define LM_TT_INTEGER 2#define LM_TT_COUNTER 3#define LM_TT_COUNTER64 4#define LM_TT_STRING 5#define LM_TT_OBJECTID 6OIDC_T oidc1[] = {1, 1};OIDC_T oidc2[] = {1, 3};OIDC_T oidc3[] = {1, 5};OIDC_T oidc4[] = {2, 2};OIDC_T oidc5[] = {2, 4};OIDC_T oidc6[] = {2, 6};testtable_t testtable_list[] = {{{2, oidc1}, 1, 0, 0, 0, 0, 0, {0, 0}},{{2, oidc2}, -1, 1, 0, 1, 0, 0, {0, 0}},{{2, oidc3}, 0xFFFF, 0xFF, 0, 0xFFFF, 0, 0, {0, 0}},{{2, oidc4}, -0xFFFF, 0xFFFF, 0, 0xFFFFFFFFL, 0, 0, {0, 0}},{{2, oidc5}, 0x7FFFFFFFL, 0xFFFFFFL, 0xFFFF, 0, 0, 0, {0, 0}},{{2, oidc6}, 0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0, 0, {0, 0}}};int testtable_list_count = sizeof(testtable_list)/sizeof(testtable_t);/* Forward declarations of local functions */testtable_t * tt_find_entry (int tcount, OIDC_T *tlist);void tt_get_value (SNMP_PKT_T *pktp, VB_T *vbp, testtable_t *tab_entry);void tt_cleanup(ptr_t value);void tt_swap(VB_T *vbp);void tt_undoproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp);testtable_t * tt_find_entry(int tcount, OIDC_T *tlist){testtable_t *tab;int i;for(i = 0, tab = testtable_list; i < testtable_list_count; i++, tab++) { if (oidcmp2(tcount, tlist, tab->index.num_components, tab->index.component_list) == 0) { return(tab); } }return(0);}void tt_get_value(SNMP_PKT_T *pktp, VB_T *vbp, testtable_t *tab_entry){switch(vbp->vb_ml.ml_last_match) { case LM_TT_INTEGER: getproc_got_int32(pktp, vbp, tab_entry->integer); break; case LM_TT_COUNTER: getproc_got_uint32(pktp, vbp, tab_entry->counter, VT_COUNTER); break; case LM_TT_COUNTER64: getproc_got_uint64_high_low(pktp, vbp, tab_entry->high64, tab_entry->low64); break; case LM_TT_STRING: getproc_got_string(pktp, vbp, tab_entry->stringlen, tab_entry->string, 0, VT_STRING); break; case LM_TT_OBJECTID: getproc_got_object_id(pktp, vbp, tab_entry->objectid.num_components, tab_entry->objectid.component_list, 0); break; }return;}void tt_getproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){testtable_t *tab_entry;group_by_getproc_and_instance(pktp, vbp, tcount, tlist);tab_entry = tt_find_entry(tcount, tlist);if (tab_entry) { for(; vbp; vbp = vbp->vb_link) tt_get_value(pktp, vbp, tab_entry); }else { for(; vbp; vbp = vbp->vb_link) getproc_nosuchins(pktp, vbp); } return;}void tt_nextproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){testtable_t *tab_entry;int i;group_by_getproc_and_instance(pktp, vbp, tcount, tlist);for(i = 0, tab_entry = testtable_list; i < testtable_list_count; i++, tab_entry++) { if (oidcmp2(tcount, tlist, tab_entry->index.num_components, tab_entry->index.component_list) < 0) { for(; vbp; vbp = vbp->vb_link) { nextproc_next_instance(pktp, vbp, tab_entry->index.num_components, tab_entry->index.component_list); tt_get_value(pktp, vbp, tab_entry); } return; } }for(; vbp; vbp = vbp->vb_link) nextproc_no_next(pktp, vbp);return;}void tt_cleanup(ptr_t value){iandp_t *iandp;iandp = (iandp_t *)(((VB_T *)value)->vb_priv);if (iandp) { if (iandp->buf) SNMP_memory_free(iandp->buf); SNMP_memory_free(iandp); }}void tt_testproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){testtable_t *tab_entry;VB_T *tvbp;iandp_t *iandp;int str_flag = 0, oid_flag = 0, oneed;ALENGTH_T sneed;group_by_getproc_and_instance(pktp, vbp, tcount, tlist);testproc_good(pktp, vbp);for(tvbp = vbp->vb_link; tvbp; tvbp = tvbp->vb_link) setproc_all_bits(pktp, tvbp);tab_entry = tt_find_entry(tcount, tlist);if (tab_entry == 0) { testproc_error(pktp, vbp, NO_CREATION); return; }vbp->vb_free_priv = tt_cleanup;for(tvbp = vbp; tvbp; tvbp = tvbp->vb_link) { switch(tvbp->vb_ml.ml_last_match) { case LM_TT_STRING: sneed = EBufferUsed(VB_GET_STRING(tvbp)); if (sneed > 255) { testproc_error(pktp, tvbp, WRONG_LENGTH); return; } if (str_flag) continue; str_flag = 1; iandp = (iandp_t *)SNMP_memory_alloc(sizeof(iandp_t)); if (iandp == 0) { testproc_error(pktp, tvbp, RESOURCE_UNAVAILABLE); return; } if (sneed != 0) { iandp->buf = SNMP_memory_alloc(sneed); if (iandp->buf == 0) { SNMP_memory_free(iandp); testproc_error(pktp, tvbp, RESOURCE_UNAVAILABLE); return; } MEMCPY(iandp->buf, EBufferStart(VB_GET_STRING(tvbp)), sneed); } else iandp->buf = 0; iandp->count = (int)(sneed & 0xff); iandp->tab_entry = tab_entry; tvbp->vb_priv = (ptr_t)iandp; break; case LM_TT_OBJECTID: oneed = (VB_GET_OBJECT_ID(tvbp))->num_components; if (oneed > 128) { testproc_error(pktp, tvbp, WRONG_LENGTH); return; } if (oid_flag) continue; oid_flag = 1; iandp = (iandp_t *)SNMP_memory_alloc(sizeof(iandp_t)); if (iandp == 0) { testproc_error(pktp, tvbp, RESOURCE_UNAVAILABLE); return; } if (oneed != 0) { iandp->buf = SNMP_memory_alloc(oneed * sizeof(OIDC_T)); if (iandp->buf == 0) { SNMP_memory_free(iandp); testproc_error(pktp, tvbp, RESOURCE_UNAVAILABLE); return; } MEMCMP(iandp->buf, (VB_GET_OBJECT_ID(tvbp))->component_list, oneed * sizeof(OIDC_T)); } else iandp->buf = 0; iandp->count = (int)(oneed & 0xff); iandp->tab_entry = tab_entry; tvbp->vb_priv = (ptr_t)iandp; break; } }return;}void tt_swap(VB_T *vbp){testtable_t *tab_entry;iandp_t *iandp;int str_flag = 0, oid_flag = 0, temp_count;bits8_t *temp_buf;for(; vbp; vbp = vbp->vb_link) { iandp = (iandp_t *)vbp->vb_priv; switch(vbp->vb_ml.ml_last_match) { case LM_TT_STRING: if (str_flag) continue; str_flag = 1; tab_entry = iandp->tab_entry; temp_count = tab_entry->stringlen; temp_buf = tab_entry->string; tab_entry->stringlen = iandp->count; tab_entry->string = iandp->buf; iandp->count = temp_count; iandp->buf = temp_buf; break; case LM_TT_OBJECTID: if (oid_flag) continue; oid_flag = 1; tab_entry = iandp->tab_entry; temp_count = tab_entry->objectid.num_components; temp_buf = (bits8_t *)tab_entry->objectid.component_list; tab_entry->objectid.num_components = iandp->count; tab_entry->objectid.component_list = (OIDC_T *)iandp->buf; iandp->count = temp_count; iandp->buf = temp_buf; break; } }return;}void tt_undoproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){undoproc_good(pktp, vbp);tt_swap(vbp);return;}void tt_setproc(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){setproc_good(pktp, vbp);undoproc_set(pktp, vbp, tt_undoproc);tt_swap(vbp);return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -