[Libosinfo] [libosinfo PATCH 4/6] loader: Also load informations about images
Fabiano Fidêncio
fidencio at redhat.com
Wed Oct 31 21:45:36 UTC 2018
Now that we've OsinfoImage and OsinfoImageList objects in place, we can
properly load the images' informations 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 d1bf61d..ad7b989 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -38,6 +38,7 @@
#include "ignore-value.h"
#include "osinfo_install_script_private.h"
#include "osinfo_device_driver_private.h"
+#include "osinfo_image_private.h"
#ifndef USB_IDS
#define USB_IDS PKG_DATA_DIR "/usb.ids"
@@ -1238,6 +1239,27 @@ 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 },
+ { OSINFO_IMAGE_PROP_PRODUCT_NAME, G_TYPE_STRING },
+ { NULL, G_TYPE_INVALID }
+ };
+
+ gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
+ OsinfoImage *image = osinfo_image_new(id, arch);
+ xmlFree(arch);
+
+ 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,
@@ -1488,6 +1510,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