예제 #1
0
파일: zone-tree.c 프로젝트: idtek/knot
int zone_tree_delete_empty_node(zone_tree_t *tree, zone_node_t *node)
{
	if (!tree || !node) {
		return KNOT_EINVAL;
	}

	if (node->rrset_count == 0 && node->children == 0) {
		zone_node_t *parent_node = node->parent;
		if (parent_node) {
			parent_node->children--;
			fix_wildcard_child(parent_node, node->owner);
			if (parent_node->parent != NULL) { /* Is not apex */
				// Recurse using the parent node, do not delete possibly empty parent.
				int ret = zone_tree_delete_empty_node(tree, parent_node);
				if (ret != KNOT_EOK) {
					return ret;
				}
			}
		}

		// Delete node
		zone_node_t *removed_node = NULL;
		zone_tree_remove(tree, node->owner, &removed_node);
		UNUSED(removed_node);
		node_free(&node, NULL);
	}

	return KNOT_EOK;
}
예제 #2
0
/*----------------------------------------------------------------------------*/

int zone_contents_remove_node(zone_contents_t *contents, const knot_dname_t *owner)
{
	if (contents == NULL || owner == NULL) {
		return KNOT_EINVAL;
	}

dbg_zone_exec_verb(
	char *name = knot_dname_to_str_alloc(owner);
	dbg_zone_verb("Removing zone node: %s\n", name);
	free(name);
);
	zone_node_t *removed_node = NULL;
	int ret = zone_tree_remove(contents->nodes, owner, &removed_node);
	if (ret != KNOT_EOK) {
		return KNOT_ENONODE;
	}
	assert(removed_node);

	return KNOT_EOK;
}

/*----------------------------------------------------------------------------*/

int zone_contents_remove_nsec3_node(zone_contents_t *contents, const knot_dname_t *owner)
{
	if (contents == NULL || owner == NULL) {
		return KNOT_EINVAL;
	}