static int ds_sds_register_sce(struct ds_sds_session *session, xmlNodePtr component_inner_root, const char* component_id, const char* target_filename_dirname, const char* relative_filepath) { // the cast is safe to do because we are using the GNU basename, it doesn't // modify the string const char* file_basename = basename((char*)relative_filepath); const char* sce_filename = oscap_sprintf("%s/%s/%s",ds_sds_session_get_target_dir(session), target_filename_dirname, file_basename); int ret = ds_sds_dump_component_sce(component_inner_root->children, component_id, sce_filename); oscap_free(sce_filename); return ret; }
static int ds_sds_dump_component(const char* component_id, struct ds_sds_session *session, const char *target_filename_dirname, const char *relative_filepath) { xmlDoc *doc = ds_sds_session_get_xmlDoc(session); xmlNodePtr component = _lookup_component_in_collection(doc, component_id); if (component == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Component of given id '%s' was not found in the document.", component_id); return -1; } xmlNodePtr inner_root = node_get_child_element(component, NULL); if (inner_root == NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "Found component (id='%s') but it has no element contents, nothing to dump, skipping...", component_id); return -1; } // If the inner root is script, we have to treat it in a special way if (strcmp((const char*)inner_root->name, "script") == 0) { // the cast is safe to do because we are using the GNU basename, it doesn't // modify the string const char* file_basename = basename((char*)relative_filepath); const char* sce_filename = oscap_sprintf("%s/%s/%s",ds_sds_session_get_target_dir(session), target_filename_dirname, file_basename); int ret = ds_sds_dump_component_sce(inner_root->children, component_id, sce_filename); oscap_free(sce_filename); if (ret != 0) { return ret; } } // Otherwise we create a new XML doc we will dump the contents to. // We can't just dump node "innerXML" because namespaces have to be // handled. else { xmlDoc *new_doc = ds_doc_from_foreign_node(inner_root, doc); if (new_doc == NULL) { return -1; } struct oscap_source *source = oscap_source_new_from_xmlDoc(new_doc, relative_filepath); ds_sds_session_register_component_source(session, relative_filepath, source); } return 0; }