⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ax_mmutl.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* *  Copyright 2001-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: ax_mmutl.c,v $ * Revision 1.2  2001/11/06 21:20:03  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:41  tneale * Tornado shuffle * * Revision 1.1.2.2  2001/08/07 21:53:30  meister * reworked to use dynamic component configuration macros, to allow * separate vxworks agentx components * * Revision 1.1.2.1  2001/08/07 21:43:44  meister * This file contains functions formerly in mib_utils.c * but were agentX specific: Find_Leaf_From_Root, * AX_Add_Leaf_From_Root, AX_Remove_Leaf_From_Root * *//* [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/asn1.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/mib.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/view.h>/* in mibutils.c */extern void branch_free(MIBNODE_T *startnode, MIBNODE_T *endnode);/****************************************************************************NAME:  Find_Leaf_From_RootPURPOSE: find the leaf for the node returned from find_node_from_root	 if there isn't set the mibleaf pointer to 0.	PARAMETERS: MIBNODE_T * the root node to use	    OBJ_ID_T  * the object id that names the leaf	    MIBLEAF_T ** return area for mibleaf pointer, 0 if no leafRETURNS: 0 if we consumed all subids	 1 if a leaf node was found before all subids were consumed	 2 if no node was found ****************************************************************************/sbits32_t  Find_Leaf_From_Root(MIBNODE_T *mibroot,		      OBJ_ID_T  *objid,		      MIBLEAF_T **mibleaf){MIBNODE_T *mnode;sbits32_t err_ret;err_ret = Find_Node_From_Root(mibroot, objid, &mnode);if (mnode) {    if ((mnode->node_type & NODE_TYPE) == INNER_NODE)        *mibleaf = mnode->leaf;    else        *mibleaf = (MIBLEAF_T *)mnode;    }else    *mibleaf = 0;return(err_ret);}/****************************************************************************NAME:  AX_Add_Leaf_From_RootPURPOSE: Attempt to add a leaf to the tree at the given position	 If the leaf already exists and is replaceable we replace it	 If the node already exists and is replaceable we add the leaf	 Otherwise we try and insert the leaf and any necessary branchesPARAMETERS: MIBNODE_T * root of the mibtree	    OBJ_ID_T  * name of the point where the leaf should go	    MIBLEAF_T * the leaf to add	    MIBLEAF_T ** the removed leaf (if any) RETURNS: int 0 failure             1 success, added to tree             2 success, not added to tree, this might occur if the leaf	     we are trying to replace isn't an agentx leaf.****************************************************************************/int  AX_Add_Leaf_From_Root(MIBNODE_T  *mibroot,			OBJ_ID_T   *objp,			MIBLEAF_T  *add_leaf,			MIBLEAF_T **rem_leaf){MIBNODE_T       *np, *newnode;MIBARC_T        *ap = 0, *newarc, *savearc;OIDC_T          *compp;         /* Current object id component of interest */int             comp_num;       /* Index of current object id component    */int             num_arcs;       /* number of arcs, for allocating more space */int             comp_end;       /* last comp to use when building new branch *//* make sure we have a root node */if (mibroot == 0)    return(0);np = mibroot;/* Make sure the objid is acceptable */if (objp->num_components < 1)    return(1);/* Set the replaced leaf to be 0 in case we don't have a leaf to return */*rem_leaf = 0;/* find the last matching node in the given object id */for(comp_num = objp->num_components, compp = objp->component_list;    ((np->node_type & NODE_TYPE) == INNER_NODE) && (comp_num > 0);    comp_num--, compp++, np = (MIBNODE_T *)(ap->nodep))   {   for(ap = np->arcs; ap->nodep != 0; ap++) {      if (ap->id == *compp)         break;      }   /* If we are out of arcs we use the current node else we had a matching      arc and we continue to the next level */   if (ap->nodep == 0)       break;   }/* If the node is a non-agentx leaf we don't allow it to be replaced.   This isn't classed as a failure */if ((np->node_type & (NODE_TYPE | AGENTX_LEAF)) == LEAF_NODE)    return(2);if (comp_num == 0) {    if ((np->node_type & NODE_TYPE) == LEAF_NODE) {        if ((np->node_type & REPLACEABLE) == 0)            return(0);        *rem_leaf = (MIBLEAF_T *)np;        ap->nodep = (MIBARC_T *)add_leaf;        return(1);        }    if (np->leaf)  {        if ((np->leaf->node_type & REPLACEABLE) == 0)	    return(0);	if ((np->leaf->node_type & AGENTX_LEAF) == 0)	    return(2);	*rem_leaf = np->leaf;	np->leaf = add_leaf;	return(1);        }    if ((np->node_type & REPLACEABLE) == 0) {        np->leaf = add_leaf;	return(1);        }    }/* If we are here we have more sub ids left, start building the subtree.   We work from the leaf back to the current tree, allocate the arc space   fill it in (including the terminator), allocate the next level node,   connect the arcs to it and repeat */if ((np->node_type & NODE_TYPE) == LEAF_NODE)    comp_end = 0;else    comp_end = 1;for (newnode = (MIBNODE_T *)add_leaf; comp_num > comp_end; comp_num--) {    newarc = (MIBARC_T *)SNMP_memory_alloc(sizeof(MIBARC_T) * 2);    if (newarc == 0) {        /* free any memory allocated for this branch */        branch_free(newnode, (MIBNODE_T *)add_leaf);        return(0);        }    newarc[0].id = compp[comp_num - 1];    newarc[0].nodep = (MIBARC_T *)newnode;    newarc[1].id = 0;    newarc[1].nodep = 0;    if ((newnode = (MIBNODE_T *)SNMP_memory_alloc(sizeof(MIBNODE_T))) == 0) {        /* free any memory allocated for this branch */        newnode = (MIBNODE_T *)(newarc->nodep);        SNMP_memory_free(newarc);        branch_free(newnode, (MIBNODE_T *)add_leaf);        return(0);        }    MEMSET(newnode, 0, sizeof(MIBNODE_T));    newnode->node_type = INNER_NODE | NODE_DYNAMIC | ARC_DYNAMIC |                         SYSTEM_OWNED;    newnode->arcs = newarc;    }/* if we found a leaf node we attach the leaf to the start of the   new branch and then attach the branch to the arc list in the same   place the leaf was */if ((np->node_type & NODE_TYPE) == LEAF_NODE) {    newnode->leaf = (MIBLEAF_T *)np;    ap->nodep = (MIBARC_T *)newnode;    return(1);    }/* num_arcs is the number of arcs in the current list */for(num_arcs = 1, ap = np->arcs; (MIBNODE_T *)(ap->nodep) != 0; ap++)    num_arcs++;/* add one to num_arcs for the new arc we are adding */newarc = (MIBARC_T *)SNMP_memory_alloc(sizeof(MIBARC_T) * (num_arcs + 1));if (newarc == 0) {    /* free the branch */    branch_free(newnode, (MIBNODE_T *)add_leaf);    return(0);    }/* copy all arcs less then the new arc, then add the new arc    then copy all the arcs after the new arc, there will always   be at least one, the terminator */savearc = newarc;for(ap = np->arcs;    (ap->id < *compp) && ((MIBNODE_T *)(ap->nodep) != 0);    ap++, newarc++, num_arcs--)     MEMCPY(newarc, ap, sizeof(MIBARC_T));newarc->id = *compp;newarc->nodep = (MIBARC_T *)newnode;newarc++;MEMCPY(newarc, ap, sizeof(MIBARC_T) * num_arcs);/* now clean up, if necessary free the old arc list then tag the node so that   the new arc list will be freed when released */ap = np->arcs;np->arcs = savearc;if (np->node_type & ARC_DYNAMIC)    SNMP_memory_free(ap);np->node_type |= ARC_DYNAMIC;return(1);}/****************************************************************************NAME:  AX_Remove_Leaf_From_RootPURPOSE: remove a leaf from the given mibtree removing any branches that	 are no longer neededPARAMETERS: MIBNODE_T * the root of the mib tree	    OBJ_ID_T  * the name of the node to remove the leaf fromRETURNS: MIBLEAF_T * the leaf that was removed 0 if there wasn't a  	 	     a leaf to remove or the leaf wasn't an agentx leaf****************************************************************************/MIBLEAF_T *  AX_Remove_Leaf_From_Root(MIBNODE_T  *mibroot,			   OBJ_ID_T   *objid){MIBNODE_T *mnode;MIBLEAF_T *mleaf;if ((mibroot == 0) || Find_Node_From_Root(mibroot, objid, &mnode))    return(0);if ((mnode->node_type & NODE_TYPE) == LEAF_NODE) {    if (mnode->node_type & AGENTX_LEAF)        return((MIBLEAF_T *)Remove_Node_From_Root(mibroot, objid));    else        return(0);    }mleaf = mnode->leaf;      if ((mleaf == 0) ||    ((mleaf->node_type & (REMOVABLE | AGENTX_LEAF)) !=     (REMOVABLE | AGENTX_LEAF)))    return(0);mnode->leaf = 0;if ((mnode->arcs == 0) || (mnode->arcs->nodep == 0)) {    mnode = Remove_Node_From_Root(mibroot, objid);    if (mnode && (mnode->node_type & NODE_DYNAMIC))        SNMP_memory_free(mnode);    }return(mleaf);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -