float xccdf_get_final_weight(const struct xccdf_rule* rule, const struct xccdf_refine_rule_internal* r_rule) { if (r_rule != NULL){ if (xccdf_weight_defined(r_rule->weight) ) { return r_rule->weight; } } return xccdf_rule_get_weight(rule); }
void xccdf_rule_to_dom(struct xccdf_rule *rule, xmlNode *rule_node, xmlDoc *doc, xmlNode *parent) { const struct xccdf_version_info* version_info = xccdf_item_get_schema_version(XITEM(rule)); xmlNs *ns_xccdf = lookup_xccdf_ns(doc, parent, version_info); /* Handle Attributes */ const char *extends = xccdf_rule_get_extends(rule); if (extends) xmlNewProp(rule_node, BAD_CAST "extends", BAD_CAST extends); if (xccdf_rule_get_multiple(rule)) xmlNewProp(rule_node, BAD_CAST "multiple", BAD_CAST "true"); if (xccdf_rule_get_selected(rule)) xmlNewProp(rule_node, BAD_CAST "selected", BAD_CAST "true"); else xmlNewProp(rule_node, BAD_CAST "selected", BAD_CAST "false"); if (XITEM(rule)->item.defined_flags.weight) { char *weight_str = oscap_sprintf("%f", xccdf_rule_get_weight(rule)); xmlNewProp(rule_node, BAD_CAST "weight", BAD_CAST weight_str); free(weight_str); } xccdf_role_t role = xccdf_rule_get_role(rule); if (role != 0) xmlNewProp(rule_node, BAD_CAST "role", BAD_CAST XCCDF_ROLE_MAP[role - 1].string); xccdf_level_t severity = xccdf_rule_get_severity(rule); if (severity != XCCDF_LEVEL_NOT_DEFINED) xmlNewProp(rule_node, BAD_CAST "severity", BAD_CAST XCCDF_LEVEL_MAP[severity - 1].string); /* Handle Child Nodes */ xccdf_texts_to_dom(xccdf_rule_get_rationale(rule), rule_node, "rationale"); struct oscap_string_iterator *platforms = xccdf_rule_get_platforms(rule); while (oscap_string_iterator_has_more(platforms)) { const char *platform = oscap_string_iterator_next(platforms); xmlNode * child = xmlNewTextChild(rule_node, ns_xccdf, BAD_CAST "platform", BAD_CAST NULL); xmlNewProp(child, BAD_CAST "idref", BAD_CAST platform); } oscap_string_iterator_free(platforms); struct oscap_stringlist_iterator *lists = xccdf_rule_get_requires(rule); while (oscap_stringlist_iterator_has_more(lists)) { struct oscap_stringlist *list = oscap_stringlist_iterator_next(lists); struct oscap_string_iterator *strings = oscap_stringlist_get_strings(list); while (oscap_string_iterator_has_more(strings)) { const char *requires = oscap_string_iterator_next(strings); xmlNode * child = xmlNewTextChild(rule_node, ns_xccdf, BAD_CAST "requires", BAD_CAST NULL); xmlNewProp(child, BAD_CAST "idref", BAD_CAST requires); } oscap_string_iterator_free(strings); } oscap_stringlist_iterator_free(lists); struct oscap_string_iterator *conflicts = xccdf_rule_get_conflicts(rule); while (oscap_string_iterator_has_more(conflicts)) { const char *conflict = oscap_string_iterator_next(conflicts); xmlNode * child = xmlNewTextChild(rule_node, ns_xccdf, BAD_CAST "conflicts", BAD_CAST NULL); xmlNewProp(child, BAD_CAST "idref", BAD_CAST conflict); } oscap_string_iterator_free(conflicts); struct xccdf_ident_iterator *idents = xccdf_rule_get_idents(rule); while (xccdf_ident_iterator_has_more(idents)) { struct xccdf_ident *ident = xccdf_ident_iterator_next(idents); xccdf_ident_to_dom(ident, doc, rule_node, version_info); } xccdf_ident_iterator_free(idents); struct xccdf_profile_note_iterator *notes = xccdf_rule_get_profile_notes(rule); while (xccdf_profile_note_iterator_has_more(notes)) { struct xccdf_profile_note *note = xccdf_profile_note_iterator_next(notes); xccdf_profile_note_to_dom(note, doc, rule_node); } xccdf_profile_note_iterator_free(notes); struct xccdf_fixtext_iterator *fixtexts = xccdf_rule_get_fixtexts(rule); while (xccdf_fixtext_iterator_has_more(fixtexts)) { struct xccdf_fixtext *fixtext = xccdf_fixtext_iterator_next(fixtexts); xccdf_fixtext_to_dom(fixtext, doc, rule_node); } xccdf_fixtext_iterator_free(fixtexts); struct xccdf_fix_iterator *fixes = xccdf_rule_get_fixes(rule); while (xccdf_fix_iterator_has_more(fixes)) { struct xccdf_fix *fix = xccdf_fix_iterator_next(fixes); xccdf_fix_to_dom(fix, doc, rule_node, version_info); } xccdf_fix_iterator_free(fixes); struct xccdf_check_iterator *checks = xccdf_rule_get_checks(rule); while (xccdf_check_iterator_has_more(checks)) { struct xccdf_check *check = xccdf_check_iterator_next(checks); xccdf_check_to_dom(check, doc, rule_node, version_info); } xccdf_check_iterator_free(checks); }