gplugin/gplugin

b584814d5f13
Parents 0f07cacab39d
Children 90d067db1688
Add gplugin_plugin_info_get_id_normalized. Fixes GPLUGIN-128

Testing Done:
Ran the new unit tests

Reviewed at https://reviews.imfreedom.org/r/131/
--- a/gplugin/gplugin-plugin-info.c Tue Sep 22 00:30:00 2020 -0500
+++ b/gplugin/gplugin-plugin-info.c Tue Sep 22 00:42:26 2020 -0500
@@ -794,6 +794,38 @@
}
/**
+ * gplugin_info_get_id_normalized:
+ * @info: The #GPluginPluginInfo instance.
+ *
+ * Gets the normalized version of the id from @info. That is, a version where
+ * only alpha-numeric and -'s are in the id.
+ *
+ * Returns: (transfer full): The normalized id of @info.
+ */
+gchar *
+gplugin_info_get_id_normalized(GPluginPluginInfo *info)
+{
+ GPluginPluginInfoPrivate *priv = NULL;
+ gchar *copy = NULL;
+
+ g_return_val_if_fail(GPLUGIN_IS_PLUGIN_INFO(info), NULL);
+
+ priv = gplugin_plugin_info_get_instance_private(info);
+
+ /* this only happens if an id wasn't passed, but that should be caught by
+ * loader and then the manager, but that doesn't stop someone from just
+ * creating a GPluginPluginInfo and doing dumb shit with it.
+ */
+ if(priv->id == NULL) {
+ return NULL;
+ }
+
+ copy = g_strdup(priv->id);
+
+ return g_strcanon(copy, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
+}
+
+/**
* gplugin_plugin_info_get_abi_version:
* @info: The #GPluginPluginInfo instance.
*
--- a/gplugin/gplugin-plugin-info.h Tue Sep 22 00:30:00 2020 -0500
+++ b/gplugin/gplugin-plugin-info.h Tue Sep 22 00:42:26 2020 -0500
@@ -55,6 +55,7 @@
/* clang-format on */
const gchar *gplugin_plugin_info_get_id(GPluginPluginInfo *info);
+gchar *gplugin_info_get_id_normalized(GPluginPluginInfo *info);
guint32 gplugin_plugin_info_get_abi_version(GPluginPluginInfo *info);
gboolean gplugin_plugin_info_get_internal(GPluginPluginInfo *info);
gboolean gplugin_plugin_info_get_load_on_query(GPluginPluginInfo *info);
--- a/gplugin/tests/meson.build Tue Sep 22 00:30:00 2020 -0500
+++ b/gplugin/tests/meson.build Tue Sep 22 00:42:26 2020 -0500
@@ -34,6 +34,10 @@
dependencies : [gplugin_dep, GLIB, GOBJECT])
test('Find Plugins', e)
+e = executable('test-id-normalize', 'test-id-normalize.c',
+ dependencies : [gplugin_dep, GLIB, GOBJECT])
+test('ID Normalization', e)
+
e = executable('test-loader-registration', 'test-loader-registration.c',
dependencies : [gplugin_dep, GLIB, GOBJECT])
test('Loader Registration', e)