Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- osinfo/osinfo_loader.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c index 8f7b2bf..b4bad60 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,54 @@ static void osinfo_loader_device_link(OsinfoLoader *loader, g_free(related); } +static void osinfo_loader_features(OsinfoOs *os, + OsinfoLoader *loader, + xmlXPathContextPtr ctxt, + xmlNodePtr root, + const gchar *id, + GError **err) +{ + gchar *arch; + xmlNodePtr *nodes = NULL; + int nnodes, i; + + arch = (gchar *)xmlGetProp(root, BAD_CAST "arch"); + + nnodes = osinfo_loader_nodeset("./feature", loader, ctxt, &nodes, err); + if (error_is_set(err)) + goto cleanup; + + for (i = 0; i < nnodes; i++) { + gchar *supported; + gchar *feature_id; + const gchar *name; + + if (nodes[i]->children->type != XML_TEXT_NODE || + !g_str_equal((const gchar *)nodes[i]->name, "feature")) + continue; + + name = (const gchar *)nodes[i]->children->content; + feature_id = g_strdup_printf("%s:%u", id, i); + OsinfoFeature *feature = osinfo_feature_new(feature_id, name, arch); + osinfo_os_add_feature(os, feature); + + supported = (gchar *)xmlGetProp(nodes[i], + BAD_CAST OSINFO_FEATURE_PROP_SUPPORTED); + if (supported != NULL) { + osinfo_feature_set_supported(feature, + g_str_equal(supported, "true") ? TRUE: FALSE); + g_free(supported); + } + + g_free(feature_id); + g_object_unref(feature); + } + + cleanup: + g_free(nodes); + g_free(arch); +} + static void osinfo_loader_product_relshp(OsinfoLoader *loader, OsinfoProduct *product, OsinfoProductRelationship relshp, @@ -1515,6 +1564,28 @@ static void osinfo_loader_os(OsinfoLoader *loader, if (error_is_set(err)) goto cleanup; + nnodes = osinfo_loader_nodeset("./features", loader, ctxt, &nodes, err); + if (error_is_set(err)) + goto cleanup; + + for (i = 0; i < nnodes; i++) { + xmlNodePtr saved; + gchar *features_id; + + saved = ctxt->node; + ctxt->node = nodes[i]; + features_id = g_strdup_printf("%s:%u", id, i); + osinfo_loader_features(os, loader, ctxt, nodes[i], features_id, err); + g_free(features_id); + + ctxt->node = saved; + + if (error_is_set(err)) + goto cleanup; + } + + g_free(nodes); + 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