[gnome-software] trivial: Allow plugins to register authentication providers
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Allow plugins to register authentication providers
- Date: Fri, 10 Jun 2016 15:02:07 +0000 (UTC)
commit 2e82a59a4b949d47fbed2caa03f8647363aa3fad
Author: Richard Hughes <richard hughsie com>
Date: Fri Jun 10 15:38:37 2016 +0100
trivial: Allow plugins to register authentication providers
The idea in the future is that plugins will create a GsAuth and add it to the
plugin, which gets added to an array on the plugin loader.
This would allow anything with access to the plugin loader to get the GsAuth
using the provider-id.
src/gs-plugin-loader.c | 23 +++++++++++++++++++++++
src/gs-plugin-loader.h | 3 +++
src/gs-plugin-private.h | 2 ++
src/gs-plugin.c | 30 ++++++++++++++++++++++++++++++
src/gs-plugin.h | 3 +++
5 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index b5eb72d..00ed3cd 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -43,6 +43,7 @@ typedef struct
GsPluginStatus status_last;
AsProfile *profile;
SoupSession *soup_session;
+ GPtrArray *auth_array;
GMutex pending_apps_mutex;
GPtrArray *pending_apps;
@@ -3314,6 +3315,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
G_CALLBACK (gs_plugin_loader_status_changed_cb),
plugin_loader);
gs_plugin_set_soup_session (plugin, priv->soup_session);
+ gs_plugin_set_auth_array (plugin, priv->auth_array);
gs_plugin_set_profile (plugin, priv->profile);
gs_plugin_set_locale (plugin, priv->locale);
gs_plugin_set_scale (plugin, gs_plugin_loader_get_scale (plugin_loader));
@@ -3352,6 +3354,25 @@ gs_plugin_loader_get_scale (GsPluginLoader *plugin_loader)
}
/**
+ * gs_plugin_loader_get_auth_by_id:
+ */
+GsAuth *
+gs_plugin_loader_get_auth_by_id (GsPluginLoader *plugin_loader,
+ const gchar *provider_id)
+{
+ GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+ guint i;
+
+ /* match on ID */
+ for (i = 0; i < priv->auth_array->len; i++) {
+ GsAuth *auth = g_ptr_array_index (priv->auth_array, i);
+ if (g_strcmp0 (gs_auth_get_provider_id (auth), provider_id) == 0)
+ return auth;
+ }
+ return NULL;
+}
+
+/**
* gs_plugin_loader_set_location:
*/
void
@@ -3654,6 +3675,7 @@ gs_plugin_loader_dispose (GObject *object)
g_clear_object (&priv->soup_session);
g_clear_object (&priv->profile);
g_clear_object (&priv->settings);
+ g_clear_pointer (&priv->auth_array, g_ptr_array_unref);
g_clear_pointer (&priv->pending_apps, g_ptr_array_unref);
G_OBJECT_CLASS (gs_plugin_loader_parent_class)->dispose (object);
@@ -3725,6 +3747,7 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
priv->plugins = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->status_last = GS_PLUGIN_STATUS_LAST;
priv->pending_apps = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
+ priv->auth_array = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
priv->profile = as_profile_new ();
priv->settings = g_settings_new ("org.gnome.software");
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 6e2bbdb..cb31511 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -25,6 +25,7 @@
#include <glib-object.h>
#include "gs-app.h"
+#include "gs-auth.h"
#include "gs-category.h"
#include "gs-plugin.h"
@@ -190,6 +191,8 @@ gboolean gs_plugin_loader_get_enabled (GsPluginLoader *plugin_loader,
const gchar *plugin_name);
void gs_plugin_loader_set_location (GsPluginLoader *plugin_loader,
const gchar *location);
+GsAuth *gs_plugin_loader_get_auth_by_id (GsPluginLoader *plugin_loader,
+ const gchar *provider_id);
gint gs_plugin_loader_get_scale (GsPluginLoader *plugin_loader);
void gs_plugin_loader_set_scale (GsPluginLoader *plugin_loader,
gint scale);
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index ea318f2..42f55f9 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -47,6 +47,8 @@ void gs_plugin_set_locale (GsPlugin *plugin,
const gchar *locale);
void gs_plugin_set_profile (GsPlugin *plugin,
AsProfile *profile);
+void gs_plugin_set_auth_array (GsPlugin *plugin,
+ GPtrArray *auth_array);
void gs_plugin_set_soup_session (GsPlugin *plugin,
SoupSession *soup_session);
void gs_plugin_set_running_other (GsPlugin *plugin,
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index c0fce0c..321c624 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -55,6 +55,7 @@
typedef struct
{
AsProfile *profile;
+ GPtrArray *auth_array;
GHashTable *cache;
GMutex cache_mutex;
GModule *module;
@@ -184,6 +185,7 @@ gs_plugin_finalize (GObject *object)
g_free (priv->locale);
g_rw_lock_clear (&priv->rwlock);
g_object_unref (priv->profile);
+ g_ptr_array_unref (priv->auth_array);
g_object_unref (priv->soup_session);
g_hash_table_unref (priv->cache);
g_mutex_clear (&priv->cache_mutex);
@@ -452,6 +454,34 @@ gs_plugin_set_locale (GsPlugin *plugin, const gchar *locale)
}
/**
+ * gs_plugin_set_auth_array:
+ * @plugin: a #GsPlugin
+ * @auth_array: (element-type GsAuth): an array
+ *
+ * Sets the authentication objects that can be added by the plugin.
+ **/
+void
+gs_plugin_set_auth_array (GsPlugin *plugin, GPtrArray *auth_array)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ priv->auth_array = g_ptr_array_ref (auth_array);
+}
+
+/**
+ * gs_plugin_add_auth:
+ * @plugin: a #GsPlugin
+ * @auth: a #GsAuth
+ *
+ * Adds an authentication object that can be used for all the plugins.
+ **/
+void
+gs_plugin_add_auth (GsPlugin *plugin, GsAuth *auth)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_ptr_array_add (priv->auth_array, g_object_ref (auth));
+}
+
+/**
* gs_plugin_get_profile:
* @plugin: a #GsPlugin
*
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index c534f80..74758cf 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -30,6 +30,7 @@
#include "gs-app.h"
#include "gs-app-list.h"
+#include "gs-auth.h"
#include "gs-category.h"
G_BEGIN_DECLS
@@ -237,6 +238,8 @@ guint gs_plugin_get_scale (GsPlugin *plugin);
const gchar *gs_plugin_get_locale (GsPlugin *plugin);
AsProfile *gs_plugin_get_profile (GsPlugin *plugin);
SoupSession *gs_plugin_get_soup_session (GsPlugin *plugin);
+void gs_plugin_add_auth (GsPlugin *plugin,
+ GsAuth *auth);
void gs_plugin_add_rule (GsPlugin *plugin,
GsPluginRule rule,
const gchar *name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]