int cil_add_decl_to_symtab(struct cil_db *db, symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node)
{
	int rc;

	if (symtab == NULL || datum == NULL || node == NULL) {
		return SEPOL_ERR;
	}

	rc = cil_symtab_insert(symtab, key, datum, node);
	if (rc == SEPOL_EEXIST) {
		struct cil_symtab_datum *prev;
		rc = cil_symtab_get_datum(symtab, key, &prev);
		if (rc != SEPOL_OK) {
			cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(node), key);
			return SEPOL_ERR;
		}
		if (!cil_allow_multiple_decls(db, node->flavor, FLAVOR(prev))) {
			/* multiple_decls not ok, ret error */
			struct cil_tree_node *n = NODE(prev);
			cil_log(CIL_ERR, "Re-declaration of %s %s\n",
				cil_node_to_string(node), key);
			cil_tree_log(node, CIL_ERR, "Previous declaration of %s",
				     cil_node_to_string(n));
			return SEPOL_ERR;
		}
		/* multiple_decls is enabled and works for this datum type, add node */
		cil_list_append(prev->nodes, CIL_NODE, node);
		node->data = prev;
		cil_symtab_datum_destroy(datum);
		free(datum);
	}

	return SEPOL_OK;
}
int cil_add_decl_to_symtab(struct cil_db *db, symtab_t *symtab, hashtab_key_t key, struct cil_symtab_datum *datum, struct cil_tree_node *node)
{
	int rc;

	if (symtab == NULL || datum == NULL || node == NULL) {
		return SEPOL_ERR;
	}

	rc = cil_symtab_insert(symtab, key, datum, node);
	if (rc == SEPOL_EEXIST) {
		struct cil_symtab_datum *prev;
		rc = cil_symtab_get_datum(symtab, key, &prev);
		if (rc != SEPOL_OK) {
			cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(node), key);
			return SEPOL_ERR;
		}
		if (!cil_allow_multiple_decls(db, node->flavor, FLAVOR(prev))) {
			 
			struct cil_tree_node *n = NODE(prev);
			cil_log(CIL_ERR, "Re-declaration of %s %s\n",
				cil_node_to_string(node), key);
			cil_tree_log(node, CIL_ERR, "Previous declaration of %s",
				     cil_node_to_string(n));
			return SEPOL_ERR;
		}
		 
		cil_list_append(prev->nodes, CIL_NODE, node);
		node->data = prev;
		cil_symtab_datum_destroy(datum);
		free(datum);
	}

	return SEPOL_OK;
}