[libosinfo PATCH v2 07/12] loader: Make loader aware of Guest Features

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

 



Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/osinfo_loader.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 8f7b2bf..aca3b4c 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -39,6 +39,7 @@
 #include "osinfo_install_script_private.h"
 #include "osinfo_device_driver_private.h"
 #include "osinfo_resources_private.h"
+#include "osinfo_feature_private.h"
 
 #ifndef USB_IDS
 #define USB_IDS PKG_DATA_DIR "/usb.ids"
@@ -658,6 +659,47 @@ static void osinfo_loader_device_link(OsinfoLoader *loader,
     g_free(related);
 }
 
+static void osinfo_loader_features(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);
+        osinfo_os_add_feature(OSINFO_OS(entity), feature);
+
+        gchar *supported = (gchar *)xmlGetProp(nodes[i], BAD_CAST "supported");
+        if (supported != NULL) {
+            osinfo_feature_set_supported(feature,
+                                         g_str_equal(supported, "true") ? TRUE : FALSE);
+            xmlFree(supported);
+        }
+
+        xmlNodePtr saved = ctxt->node;
+        ctxt->node = nodes[i];
+        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,
@@ -1515,6 +1557,11 @@ static void osinfo_loader_os(OsinfoLoader *loader,
     if (error_is_set(err))
         goto cleanup;
 
+    osinfo_loader_features(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.2

_______________________________________________
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