Exemplo n.º 1
0
/* Remove sub-node(s) in mib-tree. */
static void
__mib_tree_delete(struct node_pair *pair)
{
  struct node_backlog *p_nbl;
  struct node_backlog nbl_stack[ASN1_OID_MAX_LEN];
  struct node_backlog *top;

  struct mib_node *node = pair->child;
  struct mib_group_node *gn;
  struct mib_instance_node *in;

  if (node == (struct mib_node *)&mib_dummy_node) {
    SMARTSNMP_LOG(L_WARNING, "MIB dummy root node cannot be deleted!\n");
    return;
  }

  /* Init something */
  p_nbl = NULL;
  top = nbl_stack;

  for (; ;) {

    if (node != NULL)
    switch (node->type) {
    case MIB_OBJ_GROUP:
      gn = (struct mib_group_node *)node;

      /* Fetch the sub-id of the backlogged node. */
      int i = p_nbl != NULL ? p_nbl->n_idx : 0;
      /* n_idx is not reusable */
      p_nbl = NULL;

      if (i == -1) {
        /* Sub-tree is empty, delete this node and go on backtracking */
        mib_group_node_delete(gn);
        break;
      }

      /* If last sub-id, mark n_idx = -1. */
      top->n_idx = i + 1 >= gn->sub_id_cnt ? -1 : i + 1;
      top->node = node;
      top++;

      node = gn->sub_ptr[i++];
      continue;

    case MIB_OBJ_INSTANCE:
      in = (struct mib_instance_node *)node;
      mib_instance_node_delete(in);
      break;

    default :
      assert(0);
    }

    /* Backtracking */
    p_nbl = top == nbl_stack ? NULL : --top;
    if (p_nbl == NULL) {
      /* End of traversal. */
      group_node_shrink((struct mib_group_node *)pair->parent, pair->sub_idx);
      return;
    }
    node = p_nbl->node;
  }
}
Exemplo n.º 2
0
/* Remove sub-node(s) in mib-tree. */
static void
__mib_tree_delete(struct node_pair *pair)
{
  struct node_backlog nbl, *p_nbl;
  struct node_backlog nbl_stk[MIB_OID_MAX_LEN];
  struct node_backlog *stk_top, *stk_buttom;

  struct mib_node *node = pair->child;
  struct mib_group_node *gn;
  struct mib_instance_node *in;

  if (node == (struct mib_node *)&mib_dummy_node) {
    SMARTSNMP_LOG(L_WARNING, "MIB dummy root node cannot be deleted!\n");
    return;
  }

  /* Init something */
  p_nbl = NULL;
  stk_top = stk_buttom = nbl_stk;

  for (; ;) {

    if (node != NULL)
    switch (node->type) {

      case MIB_OBJ_GROUP:
        gn = (struct mib_group_node *)node;

        int i;
        if (p_nbl != NULL) {
          /* Fetch the sub-id next to the pop-up backlogged one. */
          i = p_nbl->n_idx;
          p_nbl = NULL;
        } else {
          /* Fetch the first sub-id. */
          i = 0;
        }

        if (i == -1) {
          /* Sub-tree is empty, delete this node and go on backtracking */
          mib_group_node_delete(gn);
          break;
        }

        if (i + 1 >= gn->sub_id_cnt) {
          /* Last sub-id, mark n_idx = -1. */
          nbl.n_idx = -1;
        } else {
          nbl.n_idx = i + 1;
        }
        nbl.node = node;

        /* Backlog the current node and move down. */
        nbl_push(&nbl, &stk_top, &stk_buttom);
        node = gn->sub_ptr[i++];
        continue;

      case MIB_OBJ_INSTANCE:
        in = (struct mib_instance_node *)node;
        mib_instance_node_delete(in);
        break;

      default :
        assert(0);
    }

    /* Backtracking */
    p_nbl = nbl_pop(&stk_top, &stk_buttom);
    if (p_nbl == NULL) {
      /* End of traversal. */
      group_node_shrink((struct mib_group_node *)pair->parent, pair->sub_idx);
      return;
    }
    node = p_nbl->node;
  }
}
Exemplo n.º 3
0
/* Remove specified node int mib-tree. */
static void
__mib_tree_delete(struct node_pair *pair)
{
  struct node_backlog nbl, *p_nbl;
  struct node_backlog nbl_stk[NBL_STACK_SIZE];
  struct node_backlog *stk_top, *stk_buttom;

  struct mib_node *node = pair->child;
  struct mib_group_node *gn;
  struct mib_instance_node *in;

  /* Internet group is the dummy root node */
  if (node == (struct mib_node *)&internet_group) {
    CREDO_SNMP_LOG(SNMP_LOG_WARNING, "OID .1.3.6.1 is the dummy root node in this mib tree which cannot be deleted.\n");
    return;
  }

  /* Init something */
  p_nbl = NULL;
  stk_top = stk_buttom = nbl_stk;

  for (; ;) {

    if (node != NULL)
    switch (node->type) {

      case MIB_OBJ_GROUP:
        gn = (struct mib_group_node *)node;

        int i;
        if (p_nbl != NULL) {
          /* That pop-up backlog recorded the next index. */
          i = p_nbl->n_idx;
          p_nbl = NULL;
        } else {
          /* Else we get the first sub-id. */
          i = 0;
        }

        if (i == -1) {
          /* All sub-trees empty, free this node and go on backtracking */
          mib_group_node_delete(gn);
          break;
        }

        do {
          if (i + 1 >= gn->sub_id_cnt) {
            /* Last sub-id, mark n_idx = -1. */
            nbl.n_idx = -1;
          } else {
            nbl.n_idx = i + 1;
          }
          nbl.node = node;
          node = gn->sub_ptr[i++];
        } while (node == NULL && i < gn->sub_id_cnt);

        /* Backlog the current node and move down. */
        nbl_push(&nbl, &stk_top, &stk_buttom);
        continue;

      case MIB_OBJ_INSTANCE:
        in = (struct mib_instance_node *)node;
        mib_instance_node_delete(in);
        break;

      default :
        assert(0);
        break;
    }

    /* Backtracking */
    p_nbl = nbl_pop(&stk_top, &stk_buttom);
    if (p_nbl == NULL) {
      /* End of traversal. */
      group_node_shrink((struct mib_group_node *)pair->parent, pair->sub_idx);
      return;
    }
    node = p_nbl->node;
  }
}