diff --git a/libfwupd/fwupd-security-attr-private.h b/libfwupd/fwupd-security-attr-private.h index 3fe6c2f18..72f434e00 100644 --- a/libfwupd/fwupd-security-attr-private.h +++ b/libfwupd/fwupd-security-attr-private.h @@ -276,5 +276,7 @@ void fwupd_security_attr_to_json(FwupdSecurityAttr *self, JsonBuilder *builder); gboolean fwupd_security_attr_from_json(FwupdSecurityAttr *self, JsonNode *json_node, GError **error); +FwupdSecurityAttr * +fwupd_security_attr_copy(FwupdSecurityAttr *self); G_END_DECLS diff --git a/libfwupd/fwupd-security-attr.c b/libfwupd/fwupd-security-attr.c index ea35a5fd8..c73407047 100644 --- a/libfwupd/fwupd-security-attr.c +++ b/libfwupd/fwupd-security-attr.c @@ -1253,6 +1253,53 @@ fwupd_security_attr_array_from_variant(GVariant *value) return array; } +/** + * fwupd_security_attr_copy: + * @self: (nullable): a #FwupdSecurityAttr + * + * Makes a full (deep) copy of a security attribute. + * + * Returns: (transfer full): a new #FwupdSecurityAttr + * + * Since: 1.7.1 + **/ +FwupdSecurityAttr * +fwupd_security_attr_copy(FwupdSecurityAttr *self) +{ + g_autoptr(FwupdSecurityAttr) new = g_object_new(FWUPD_TYPE_SECURITY_ATTR, NULL); + FwupdSecurityAttrPrivate *priv = GET_PRIVATE(self); + + g_return_val_if_fail(FWUPD_IS_SECURITY_ATTR(self), NULL); + + fwupd_security_attr_set_appstream_id(new, priv->appstream_id); + fwupd_security_attr_set_name(new, priv->name); + fwupd_security_attr_set_plugin(new, priv->plugin); + fwupd_security_attr_set_url(new, priv->url); + fwupd_security_attr_set_level(new, priv->level); + fwupd_security_attr_set_flags(new, priv->flags); + fwupd_security_attr_set_result(new, priv->result); + fwupd_security_attr_set_created(new, priv->created); + for (guint i = 0; i < priv->guids->len; i++) { + const gchar *guid = g_ptr_array_index(priv->guids, i); + fwupd_security_attr_add_guid(new, guid); + } + for (guint i = 0; i < priv->obsoletes->len; i++) { + const gchar *obsolete = g_ptr_array_index(priv->obsoletes, i); + fwupd_security_attr_add_obsolete(new, obsolete); + } + if (priv->metadata != NULL) { + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init(&iter, priv->metadata); + while (g_hash_table_iter_next(&iter, &key, &value)) { + fwupd_security_attr_add_metadata(new, + (const gchar *)key, + (const gchar *)value); + } + } + return g_steal_pointer(&new); +} + /** * fwupd_security_attr_new: * @appstream_id: (nullable): the AppStream component ID, e.g. `com.intel.BiosGuard` diff --git a/libfwupd/fwupd.map b/libfwupd/fwupd.map index c3eb07901..2ecafbb51 100644 --- a/libfwupd/fwupd.map +++ b/libfwupd/fwupd.map @@ -713,6 +713,7 @@ LIBFWUPD_1.7.0 { LIBFWUPD_1.7.1 { global: fwupd_client_add_hint; + fwupd_security_attr_copy; fwupd_security_attr_flag_from_string; fwupd_security_attr_from_json; fwupd_security_attr_get_created;