int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
	int rc = SEPOL_ERR;
	struct cil_defaultrange *def = NULL;
	char *object;
	char *range;
	enum cil_syntax syntax[] = {
		CIL_SYN_STRING,
		CIL_SYN_STRING | CIL_SYN_LIST,
		CIL_SYN_STRING,
		CIL_SYN_STRING | CIL_SYN_END,
		CIL_SYN_END
	};
	int syntax_len = sizeof(syntax)/sizeof(*syntax);

	rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
	if (rc != SEPOL_OK) {
		goto exit;
	}

	cil_defaultrange_init(&def);

	if (parse_current->next->cl_head == NULL) {
		cil_list_init(&def->class_strs, CIL_CLASS);
		cil_list_append(def->class_strs, CIL_STRING, parse_current->next->data);
	} else {
		rc = cil_fill_list(parse_current->next->cl_head, CIL_CLASS, &def->class_strs);
		if (rc != SEPOL_OK) {
			goto exit;
		}
	}

	object = parse_current->next->next->data;
	if (object == CIL_KEY_SOURCE) {
		range = parse_current->next->next->next->data;
		if (range == CIL_KEY_LOW) {
			def->object_range = CIL_DEFAULT_SOURCE_LOW;
		} else if (range == CIL_KEY_HIGH) {
			def->object_range = CIL_DEFAULT_SOURCE_HIGH;
		} else if (range == CIL_KEY_LOW_HIGH) {
			def->object_range = CIL_DEFAULT_SOURCE_LOW_HIGH;
		} else {
			cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
			rc = SEPOL_ERR;
			goto exit;
		}
	} else if (object == CIL_KEY_TARGET) {
		range = parse_current->next->next->next->data;
		if (range == CIL_KEY_LOW) {
			def->object_range = CIL_DEFAULT_TARGET_LOW;
		} else if (range == CIL_KEY_HIGH) {
			def->object_range = CIL_DEFAULT_TARGET_HIGH;
		} else if (range == CIL_KEY_LOW_HIGH) {
			def->object_range = CIL_DEFAULT_TARGET_LOW_HIGH;
		} else {
			cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
			rc = SEPOL_ERR;
			goto exit;
		}
	} else if (object == CIL_KEY_GLBLUB) {
		def->object_range = CIL_DEFAULT_GLBLUB;
	} else {
		cil_log(CIL_ERR,"Expected \'source\', \'target\', or \'glblub\'\n");
		rc = SEPOL_ERR;
		goto exit;
	}

	ast_node->data = def;
	ast_node->flavor = CIL_DEFAULTRANGE;

	return SEPOL_OK;

exit:
	cil_tree_log(parse_current, CIL_ERR, "Bad defaultrange declaration");
	cil_destroy_defaultrange(def);
	return rc;
}
int cil_gen_defaultrange(struct cil_tree_node *parse_current, struct cil_tree_node *ast_node)
{
	int rc = SEPOL_ERR;
	struct cil_defaultrange *def = NULL;
	char *object;
	char *range;
	enum cil_syntax syntax[] = {
		CIL_SYN_STRING,
		CIL_SYN_STRING | CIL_SYN_LIST,
		CIL_SYN_STRING,
		CIL_SYN_STRING | CIL_SYN_END,
		CIL_SYN_END
	};
	int syntax_len = sizeof(syntax)/sizeof(*syntax);

	rc = __cil_verify_syntax(parse_current, syntax, syntax_len);
	if (rc != SEPOL_OK) {
		goto exit;
	}

	cil_defaultrange_init(&def);

	if (parse_current->next->cl_head == NULL) {
		cil_list_init(&def->class_strs, CIL_CLASS);
		cil_list_append(def->class_strs, CIL_STRING, parse_current->next->data);
	} else {
		rc = cil_fill_list(parse_current->next->cl_head, CIL_CLASS, &def->class_strs);
		if (rc != SEPOL_OK) {
			goto exit;
		}
	}

	object = parse_current->next->next->data;
	if (object == CIL_KEY_SOURCE) {
		range = parse_current->next->next->next->data;
		if (range == CIL_KEY_LOW) {
			def->object_range = CIL_DEFAULT_SOURCE_LOW;
		} else if (range == CIL_KEY_HIGH) {
			def->object_range = CIL_DEFAULT_SOURCE_HIGH;
		} else if (range == CIL_KEY_LOW_HIGH) {
			def->object_range = CIL_DEFAULT_SOURCE_LOW_HIGH;
		} else {
			cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
			rc = SEPOL_ERR;
			goto exit;
		}
	} else if (object == CIL_KEY_TARGET) {
		range = parse_current->next->next->next->data;
		if (range == CIL_KEY_LOW) {
			def->object_range = CIL_DEFAULT_TARGET_LOW;
		} else if (range == CIL_KEY_HIGH) {
			def->object_range = CIL_DEFAULT_TARGET_HIGH;
		} else if (range == CIL_KEY_LOW_HIGH) {
			def->object_range = CIL_DEFAULT_TARGET_LOW_HIGH;
		} else {
			cil_log(CIL_ERR,"Expected 'low', 'high', or 'low-high'\n");
			rc = SEPOL_ERR;
			goto exit;
		}
	} else if (object == CIL_KEY_GLBLUB) {
		def->object_range = CIL_DEFAULT_GLBLUB;
	} else {
		cil_log(CIL_ERR,"Expected \'source\', \'target\', or \'glblub\'\n");
		rc = SEPOL_ERR;
		goto exit;
	}

	ast_node->data = def;
	ast_node->flavor = CIL_DEFAULTRANGE;

	return SEPOL_OK;

exit:
	cil_tree_log(parse_current, CIL_ERR, "Bad defaultrange declaration");
	cil_destroy_defaultrange(def);
	return rc;
}