[Libosinfo] [libosinfo PATCH v4 08/10] loader: Load Images information

Fabiano Fidêncio fidencio at redhat.com
Fri Nov 23 10:54:42 UTC 2018


Now that we've OsinfoImage and OsinfoImageList objects in place and
OsinfoOs already provides us an API to add an OsinfoImage to an
OsinfoOS, let's properly load the images' information present in
osinfo-db.

https://gitlab.com/libosinfo/osinfo-db/issues/10

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

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 030062b..b17c09d 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1248,6 +1248,28 @@ static OsinfoTree *osinfo_loader_tree(OsinfoLoader *loader,
     return tree;
 }
 
+static OsinfoImage *osinfo_loader_image(OsinfoLoader *loader,
+                                        xmlXPathContextPtr ctxt,
+                                        xmlNodePtr root,
+                                        const gchar *id,
+                                        GError **err)
+{
+    const OsinfoEntityKey keys[] = {
+        { OSINFO_IMAGE_PROP_URL, G_TYPE_STRING },
+        { NULL, G_TYPE_INVALID }
+    };
+
+    gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
+    gchar *format = (gchar *)xmlGetProp(root, BAD_CAST "format");
+    OsinfoImage *image = osinfo_image_new(id, arch, format);
+    xmlFree(arch);
+    xmlFree(format);
+
+    osinfo_loader_entity(loader, OSINFO_ENTITY(image), keys, ctxt, root, err);
+
+    return image;
+}
+
 static OsinfoOsVariant *osinfo_loader_os_variant(OsinfoLoader *loader,
                                                  xmlXPathContextPtr ctxt,
                                                  xmlNodePtr root,
@@ -1510,6 +1532,26 @@ static void osinfo_loader_os(OsinfoLoader *loader,
 
     g_free(nodes);
 
+    nnodes = osinfo_loader_nodeset("./image", 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 *image_id = g_strdup_printf("%s:%u", id, i);
+        OsinfoImage *image = osinfo_loader_image(loader, ctxt, nodes[i], image_id, err);
+        g_free(image_id);
+        ctxt->node = saved;
+        if (error_is_set(err))
+            goto cleanup;
+
+        osinfo_os_add_image(os, image);
+        g_object_unref(G_OBJECT(image));
+    }
+
+    g_free(nodes);
+
     nnodes = osinfo_loader_nodeset("./variant", loader, ctxt, &nodes, err);
     if (error_is_set(err))
         goto cleanup;
-- 
2.19.1




More information about the Libosinfo mailing list