[Libosinfo] [libosinfo PATCH 6/7] loader: Load Firmwares to OSes

Fabiano Fidêncio fidencio at redhat.com
Tue May 7 13:16:52 UTC 2019


Let's read the <firmware> attribute from the XMLs and store this into
our OS representation.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/osinfo_loader.c | 45 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 522162f..9d2aa77 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1312,6 +1312,33 @@ static OsinfoTree *osinfo_loader_tree(OsinfoLoader *loader,
     return tree;
 }
 
+static OsinfoFirmware *osinfo_loader_firmware(OsinfoLoader *loader,
+                                              xmlXPathContextPtr ctxt,
+                                              xmlNodePtr root,
+                                              const gchar *id,
+                                              GError **err)
+{
+    gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
+    gchar *type = (gchar *)xmlGetProp(root, BAD_CAST "type");
+    gchar *supported = (gchar *)xmlGetProp(root, BAD_CAST "supported");
+    gboolean is_supported = TRUE;
+
+    OsinfoFirmware *firmware = osinfo_firmware_new(id, arch, type);
+    xmlFree(arch);
+    xmlFree(type);
+
+    if (supported != NULL) {
+        is_supported = g_str_equal(supported, "true");
+        xmlFree(supported);
+    }
+
+    osinfo_entity_set_param_boolean(OSINFO_ENTITY(firmware),
+                                    OSINFO_FIRMWARE_PROP_SUPPORTED,
+                                    is_supported);
+
+    return firmware;
+}
+
 static OsinfoImage *osinfo_loader_image(OsinfoLoader *loader,
                                         xmlXPathContextPtr ctxt,
                                         xmlNodePtr root,
@@ -1591,6 +1618,24 @@ static void osinfo_loader_os(OsinfoLoader *loader,
     if (error_is_set(err))
         goto cleanup;
 
+    nnodes = osinfo_loader_nodeset("./firmware", loader, ctxt, &nodes, err);
+    if (error_is_set(err))
+        goto cleanup;
+
+    for (i = 0; i < nnodes; i++) {
+        xmlNodePtr saved = ctxt->node;
+        ctxt->node = nodes[i];
+        gchar *firmware_id = g_strdup_printf("%s:%u", id, i);
+        OsinfoFirmware *firmware = osinfo_loader_firmware(loader, ctxt, nodes[i], firmware_id, err);
+        g_free(firmware_id);
+        ctxt->node = saved;
+        if (error_is_set(err))
+            goto cleanup;
+
+        osinfo_os_add_firmware(os, firmware);
+        g_object_unref(firmware);
+    }
+
     nnodes = osinfo_loader_nodeset("./media", loader, ctxt, &nodes, err);
     if (error_is_set(err))
         goto cleanup;
-- 
2.21.0




More information about the Libosinfo mailing list