📄 axmth.c
字号:
/* * Copyright 2002-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. *//* * $Log: axmth.c,v $ * Revision 1.10 2002/07/11 21:54:32 josh * clean up a memory leak in AgentX method routines * * Revision 1.9 2002/05/17 19:48:34 tneale * Fixed get value for ConnTransportDomain.component_list * * Revision 1.8 2002/04/09 14:16:56 tneale * AgentX registration changed from tree to list to better store ranges * * Revision 1.7 2002/04/02 19:37:32 josh * fix instance checking on scalar get routines * * Revision 1.6 2002/04/02 14:50:11 andre * Connection table work * * Revision 1.5 2002/03/18 20:18:52 tneale * Changed declarations to conform to correct tcount type * * Revision 1.4 2002/03/18 16:27:44 tneale * Added support for Agentx Session table * * Revision 1.3 2002/03/12 15:50:32 tneale * Added the Registration table of the Agentx MIB * * Revision 1.2 2002/02/26 18:38:59 josh * cleanup and nits * * *//* [clearcase]modification history-------------------01b,18apr05,job update copyright notices01a,24nov03,job update copyright information*/#include <stdlib.h>#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/mib.h>#include <wrn/wm/snmp/engine/localio.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/axapi.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/agentx.h>/*** Method routines for the GENERAL group*/static bits32_t agentxGeneral_get_value (OIDC_T lastmatch, SNMP_PKT_T *pktp, VB_T *vbp, AX_GEN_T *genData){ switch (lastmatch) { case LEAF_agentxDefaultTimeout: { getproc_got_int32 (pktp, vbp, genData -> agentxDefaultTimeout); break; } case LEAF_agentxMasterAgentXVer: { getproc_got_int32 (pktp, vbp, genData -> agentxMasterAgentXVer); break; } default: return GEN_ERR; } return NO_ERROR;}void agentxGeneral_get (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ bits32_t error; AX_GEN_T genData; /* Find all the varbinds that share the same getproc and instance */ group_by_getproc_and_instance (pktp, vbp, tcount, tlist); /* Scalar: Check that the instance is exactly .0 */ if (!((tcount == 1) && (*tlist == 0))) for (; vbp; vbp = vbp -> vb_link) getproc_nosuchins (pktp, vbp); /* Get the actual data for this variable. */ else { if (AxGetScalar (AX_GEN_DEFTO, &genData.agentxDefaultTimeout) && AxGetScalar (AX_GEN_VER, &genData.agentxMasterAgentXVer)) { /* Retrieve all the values from the same data structure */ for (; vbp; vbp = vbp -> vb_link) { if ((error = agentxGeneral_get_value (vbp -> vb_ml.ml_last_match, pktp, vbp, &genData)) != NO_ERROR) getproc_error (pktp, vbp, error); } } else { for (; vbp; vbp = vbp -> vb_link) getproc_error (pktp, vbp, GEN_ERR); } }}void agentxGeneral_next (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ AX_GEN_T genData; OIDC_T instance = 0; /* The only time there's a next for a scalar is if we're given no instance at all. */ if (tcount != 0) nextproc_no_next (pktp, vbp); else { if (AxGetScalar (AX_GEN_DEFTO, &genData.agentxDefaultTimeout) && AxGetScalar (AX_GEN_VER, &genData.agentxMasterAgentXVer)) { /* Find all the varbinds in this group and retrieve their values from the same data structure */ for (group_by_getproc_and_instance (pktp, vbp, tcount, tlist); vbp; vbp = vbp -> vb_link) { nextproc_next_instance (pktp, vbp, 1, &instance); agentxGeneral_get_value (vbp -> vb_ml.ml_last_match, pktp, vbp, &genData); } } else { getproc_error (pktp, vbp, GEN_ERR); } }}/*** Method routines for the CONNECTION group*/static bits32_t agentxConnectionEntry_get_value (OIDC_T lastmatch, SNMP_PKT_T *pktp, VB_T *vbp, AX_CONNENT_T *connEntry){ switch (lastmatch) { case LEAF_agentxConnTransportTime: { getproc_got_uint32 (pktp, vbp, connEntry -> agentxConnTransportTime, VT_TIMETICKS); break; } case LEAF_agentxConnTransportDomain: { getproc_got_object_id (pktp, vbp, connEntry -> agentxConnTransportDomain.num_components, (OIDC_T *) connEntry -> agentxConnTransportDomain.component_list, 0); break; } case LEAF_agentxConnTransportAddress: { getproc_got_string (pktp, vbp, EBufferUsed (&connEntry -> agentxConnTransportAddress), EBufferStart (&connEntry -> agentxConnTransportAddress), 0, VT_STRING); break; } default: return GEN_ERR; } return NO_ERROR;}void agentxConnectionEntry_get (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ bits32_t error; AX_CONNENT_T *connEntry; /* Find all the varbinds that share the same getproc and instance */ group_by_getproc_and_instance (pktp, vbp, tcount, tlist); /* Make sure we have exactly one component in tlist */ if (tcount != agentxConnectionEntry_INSTANCE_LEN || tlist[0] == 0) { /* Error */ for (; vbp; vbp = vbp -> vb_link) getproc_nosuchins (pktp, vbp); return; } if ((connEntry = AxConnGetEntry (tcount, tlist))) { /* Fill in the vb_priv and vb_free fields */ vbp -> vb_priv = connEntry; vbp -> vb_free_priv = agentxFreeConnEntry; /* Retrieve all the values from the same data structure */ for (; vbp; vbp = vbp -> vb_link) { if ((error = agentxConnectionEntry_get_value (vbp -> vb_ml.ml_last_match, pktp, vbp, connEntry)) != NO_ERROR) getproc_error (pktp, vbp, error); } } else for (; vbp; vbp = vbp -> vb_link) getproc_nosuchins (pktp, vbp);}void agentxConnectionEntry_next (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ AX_CONNENT_T *nextEntry = 0; bits32_t error; OIDC_T bestInstance[agentxConnectionEntry_INSTANCE_LEN]; /* Find all the varbinds that share the same getproc and instance. Then get the next instance, if any. */ group_by_getproc_and_instance (pktp, vbp, tcount, tlist); if ((nextEntry = AxConnGetNext (tcount, tlist))) { /* Fill in the vb_priv and vb_free fields */ vbp -> vb_priv = nextEntry; vbp -> vb_free_priv = agentxFreeConnEntry; /* We found the next instance. Get the values and set the */ /* instance for all the varbinds for this row of this table. */ bestInstance[0] = nextEntry -> agentxConnIndex; for (; vbp ; vbp = vbp -> vb_link) { if ((error = agentxConnectionEntry_get_value (vbp -> vb_ml.ml_last_match, pktp, vbp, nextEntry)) == NO_ERROR) nextproc_next_instance (pktp, vbp, agentxConnectionEntry_INSTANCE_LEN, bestInstance); else nextproc_error (pktp, vbp, error); } } else { /* There's no more in this table */ for (; vbp ; vbp = vbp -> vb_link) nextproc_no_next (pktp, vbp); }}void agentxConnection_get (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ /* Find all the varbinds that share the same getproc and instance */ group_by_getproc_and_instance (pktp, vbp, tcount, tlist); /* Scalar: Make sure that the instance is exactly .0 */ if (!((tcount == 1) && (*tlist == 0))) { for (; vbp; vbp = vbp -> vb_link) getproc_nosuchins (pktp, vbp); } else { /* Grab the actual data for this variable. */ /* Retrieve all the values from the same data structure */ for (; vbp; vbp = vbp -> vb_link) { bits32_t lastChangeTimeStamp; if (!AxGetScalar (AX_CONN_LASTCHG, &lastChangeTimeStamp)) getproc_error (pktp, vbp, GEN_ERR); else getproc_got_uint32 (pktp, vbp, lastChangeTimeStamp, VT_TIMETICKS); } }}void agentxConnection_next (OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){ OIDC_T instance = 0; /* The only time there's a next scalar is if we're given no instance at all. */ if (tcount != 0) nextproc_no_next (pktp, vbp); else { /* Find all the varbinds in this group and retrieve their values from the same data structure */ for (group_by_getproc_and_instance (pktp, vbp, tcount, tlist); vbp; vbp = vbp -> vb_link) { bits32_t lastChangeTimeStamp; nextproc_next_instance (pktp, vbp, 1, &instance); if (!AxGetScalar (AX_CONN_LASTCHG, &lastChangeTimeStamp)) getproc_error (pktp, vbp, GEN_ERR); else getproc_got_uint32 (pktp, vbp, lastChangeTimeStamp, VT_TIMETICKS); } }}void agentxFreeConnEntry (ptr_t value)/*** NAME**** agentxFreeConnEntry - This routine frees the memory associated with an** AX_CONNENT_T struture, and is called when a PKT_T structure that contains** a pointer to a connection entry is about to be freed.**** PARAMETERS**** pConnEntry -- Pointer to a VB_T structure.**** DESCRIPTION**** Free's the memory associated with an AX_CONNENT_T structure.**** RETURNS**** <Nothing>*/{ VB_T *pVB = (VB_T *) value; AX_CONNENT_T *pConnEntry = pVB -> vb_priv; if (pConnEntry) { Clean_Obj_ID (&pConnEntry -> agentxConnTransportDomain); EBufferClean (&pConnEntry -> agentxConnTransportAddress); SNMP_memory_free (pConnEntry); }}/*** Method routines for the SESSION group*//****************************************************************************NAME: agentxSessionEntry_get_valuePURPOSE: Routine to extract information about a sessionPARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed. AX_SESSENT_T * session structureRETURNS: error code or NO_ERROR****************************************************************************/static bits32_t agentxSessionEntry_get_value (OIDC_T lastmatch, SNMP_PKT_T *pktp, VB_T *vbp, AX_SESSENT_T *sessData){ switch (lastmatch) { case LEAF_agentxSessionObjectID: /* * If the data being returned is in dynamic storage and * needs to be free'd, change the 0 argument to a 1. */ getproc_got_object_id (pktp, vbp, sessData->agentxSessObjectID.num_components, sessData->agentxSessObjectID.component_list, 0); break; case LEAF_agentxSessionDescr: getproc_got_string (pktp, vbp, EBufferUsed (&sessData -> agentxSessDescr), EBufferStart (&sessData -> agentxSessDescr), 0, VT_STRING); break; case LEAF_agentxSessionAdminStatus: /* * Values:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -