コード例 #1
0
ファイル: oval_test.c プロジェクト: GovReady/openscap
int oval_test_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *usr)
{
	int ret = 0;
	char *comm = NULL;
	char *version = NULL;
	struct oval_definition_model *model = context->definition_model;

	char *id = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
	struct oval_test *test = oval_definition_model_get_new_test(model, id);

	oval_subtype_t subtype = oval_subtype_parse(reader);
        if ( subtype == OVAL_SUBTYPE_UNKNOWN) {
		oscap_seterr(OSCAP_EFAMILY_OVAL, "Unknown test type %s.", id);
		ret = -1;
		goto cleanup;
        }
	oval_test_set_subtype(test, subtype);

	oval_operator_t ste_operator = oval_operator_parse(reader, "state_operator", OVAL_OPERATOR_AND);
	oval_test_set_state_operator(test, ste_operator);

	oval_check_t check = oval_check_parse(reader, "check", OVAL_CHECK_UNKNOWN);
	if (check == OVAL_CHECK_NONE_EXIST) {
		dW("The 'none exist' CheckEnumeration value has been deprecated. "
		   "Converted to check='none satisfy' and check_existence='none exist'.\n");
		oval_test_set_check(test, OVAL_CHECK_NONE_SATISFY);
		oval_test_set_existence(test, OVAL_NONE_EXIST);
	} else {
		oval_existence_t existence;

		oval_test_set_check(test, check);
		existence = oval_existence_parse(reader, "check_existence", OVAL_AT_LEAST_ONE_EXISTS);
		oval_test_set_existence(test, existence);
	}

	comm = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "comment");
	if (comm != NULL) {
		oval_test_set_comment(test, comm);
	}

	int deprecated = oval_parser_boolean_attribute(reader, "deprecated", 0);
	oval_test_set_deprecated(test, deprecated);

	version = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version");
	oval_test_set_version(test, atoi(version));


	ret = oval_parser_parse_tag(reader, context, &_oval_test_parse_tag, test);

cleanup:
	oscap_free(version);
	oscap_free(comm);
	oscap_free(id);
	return ret;
}
コード例 #2
0
ファイル: oval_test.c プロジェクト: savon-noir/openscap
struct oval_test *oval_test_clone(struct oval_definition_model *new_model, struct oval_test *old_test) {
	__attribute__nonnull__(old_test);

	struct oval_state_iterator *ste_itr;
	struct oval_test *new_test = oval_definition_model_get_test(new_model, old_test->id);
	if (new_test == NULL) {
		new_test = oval_test_new(new_model, old_test->id);
		oval_test_set_deprecated(new_test, old_test->deprecated);
		oval_test_set_version(new_test, old_test->version);
		oval_test_set_check(new_test, old_test->check);
		oval_test_set_existence(new_test, old_test->existence);
		oval_test_set_state_operator(new_test, old_test->state_operator);
		oval_test_set_subtype(new_test, old_test->subtype);
		oval_test_set_comment(new_test, old_test->comment);

		if (old_test->object) {
			struct oval_object *object = oval_object_clone(new_model, old_test->object);
			oval_test_set_object(new_test, object);
		}

		ste_itr = oval_test_get_states(old_test);
		while (oval_state_iterator_has_more(ste_itr)) {
			struct oval_state *ste;

			ste = oval_state_iterator_next(ste_itr);
			ste = oval_state_clone(new_model, ste);
			oval_test_add_state(new_test, ste);
		}
		oval_state_iterator_free(ste_itr);

		struct oval_string_iterator *notes = oval_test_get_notes(old_test);
		while (oval_string_iterator_has_more(notes)) {
			char *note = oval_string_iterator_next(notes);
			oval_test_add_note(new_test, note);
		}
		oval_string_iterator_free(notes);
	}
	return new_test;
}