[Libosinfo] [libosinfo PATCH 26/31] loader: Make loader aware of Guest Features

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


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

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index d809137..6a15c37 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -659,6 +659,52 @@ static void osinfo_loader_device_link(OsinfoLoader *loader,
     g_free(related);
 }
 
+static void osinfo_loader_feature_link(OsinfoLoader *loader,
+                                       OsinfoEntity *entity,
+                                       const gchar *xpath,
+                                       xmlXPathContextPtr ctxt,
+                                       xmlNodePtr root,
+                                       GError **err)
+{
+    xmlNodePtr *nodes = NULL;
+    int nnodes = osinfo_loader_nodeset(xpath, loader, ctxt, &nodes, err);
+    int i;
+    if (error_is_set(err))
+        return;
+
+    for (i = 0; i < nnodes; i++) {
+        if (!nodes[i]->children ||
+            nodes[i]->children->type != XML_TEXT_NODE ||
+            !g_str_equal((const gchar *)nodes[i]->name, "feature"))
+            continue;
+
+        const gchar *name = (const gchar *)nodes[i]->children->content;
+        OsinfoFeature *feature = osinfo_feature_new(name);
+
+        OsinfoFeatureLink *featurelink = NULL;
+        featurelink = osinfo_os_add_feature(OSINFO_OS(entity), feature);
+
+        gchar *supported = (gchar *)xmlGetProp(nodes[i],
+                                               BAD_CAST OSINFO_LINK_PROP_SUPPORTED);
+        if (supported != NULL) {
+            osinfo_entity_set_param_boolean(OSINFO_ENTITY(featurelink),
+                                            OSINFO_LINK_PROP_SUPPORTED,
+                                            g_str_equal(supported, "false") ? FALSE : TRUE);
+            xmlFree(supported);
+        }
+
+        xmlNodePtr saved = ctxt->node;
+        ctxt->node = nodes[i];
+        osinfo_loader_entity(loader, OSINFO_ENTITY(featurelink), NULL, ctxt, root, err);
+        ctxt->node = saved;
+        if (error_is_set(err))
+            goto cleanup;
+    }
+
+ cleanup:
+    g_free(nodes);
+}
+
 static void osinfo_loader_product_relshp(OsinfoLoader *loader,
                                          OsinfoProduct *product,
                                          OsinfoProductRelationship relshp,
@@ -1470,6 +1516,11 @@ static void osinfo_loader_os(OsinfoLoader *loader,
     if (error_is_set(err))
         goto cleanup;
 
+    osinfo_loader_feature_link(loader, OSINFO_ENTITY(os),
+                               "./features/feature", ctxt, root, err);
+    if (error_is_set(err))
+        goto cleanup;
+
     nnodes = osinfo_loader_nodeset("./media", loader, ctxt, &nodes, err);
     if (error_is_set(err))
         goto cleanup;
-- 
2.19.1




More information about the Libosinfo mailing list