[gnome-software] Add gs_plugin_get_auth_by_id()



commit f016041d2128ebc0952703fdfa90ac1184b912f5
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jul 4 11:21:12 2016 +0100

    Add gs_plugin_get_auth_by_id()
    
    This allows plugins to get a specific GsAuth object from all methods that
    could require authentication.

 src/gs-plugin.c |   24 ++++++++++++++++++++++++
 src/gs-plugin.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 07e33ca..302d107 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -509,6 +509,30 @@ gs_plugin_add_auth (GsPlugin *plugin, GsAuth *auth)
 }
 
 /**
+ * gs_plugin_get_auth_by_id:
+ * @plugin: a #GsPlugin
+ * @provider_id: an ID, e.g. "dummy-sso"
+ *
+ * Gets a specific authentication object.
+ *
+ * Returns: the #GsAuth, or %NULL if not found
+ **/
+GsAuth *
+gs_plugin_get_auth_by_id (GsPlugin *plugin, const gchar *provider_id)
+{
+       GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+       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_get_profile:
  * @plugin: a #GsPlugin
  *
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 28347b9..fc8d9fa 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -249,6 +249,8 @@ AsProfile   *gs_plugin_get_profile                  (GsPlugin       *plugin);
 SoupSession    *gs_plugin_get_soup_session             (GsPlugin       *plugin);
 void            gs_plugin_add_auth                     (GsPlugin       *plugin,
                                                         GsAuth         *auth);
+GsAuth         *gs_plugin_get_auth_by_id               (GsPlugin       *plugin,
+                                                        const gchar    *provider_id);
 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]