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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 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

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux