[gnome-online-accounts/rhel-7.1: 34/34] Add a whitelist for providers



commit 2d9f667964bf75396acd7f694e74d0637e90f7ed
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 29 14:21:26 2014 +0200

    Add a whitelist for providers
    
    The whitelist is a GSetting where you can either list the names of the
    providers that should be enabled or use 'all' to have everything.
    
    Bump minimum intltool version to 0.50.1 for GSettings XML support.
    
    Modelled off gnome-settings-daemon whitelist.
    
    Fixes: https://bugzilla.gnome.org/729173

 configure.ac                                  |    4 +-
 data/Makefile.am                              |    8 ++
 data/org.gnome.online-accounts.gschema.xml.in |   11 +++
 po/POTFILES.in                                |    1 +
 src/goabackend/goaprovider.c                  |   96 +++++++++++++++++++-----
 src/goabackend/goautils.h                     |    5 +-
 6 files changed, 103 insertions(+), 22 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6fb3525..eb00a98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,7 @@ AC_DEFINE(GOA_MICRO_VERSION,
 # Initialization
 #
 
+GLIB_GSETTINGS
 GNOME_DEBUG_CHECK
 GNOME_COMPILE_WARNINGS([maximum])
 GNOME_MAINTAINER_MODE_DEFINES
@@ -321,7 +322,7 @@ fi
 # Internationalization
 #
 
-IT_PROG_INTLTOOL
+IT_PROG_INTLTOOL([0.50.1])
 GETTEXT_PACKAGE=gnome-online-accounts
 AC_SUBST([GETTEXT_PACKAGE])
 AM_GLIB_GNU_GETTEXT
@@ -381,6 +382,7 @@ data/icons/24x24/Makefile
 data/icons/32x32/Makefile
 data/icons/48x48/Makefile
 data/icons/256x256/Makefile
+data/org.gnome.online-accounts.gschema.xml
 src/Makefile
 src/goa/Makefile
 src/goa/goa-1.0.pc
diff --git a/data/Makefile.am b/data/Makefile.am
index 49004b8..cb30eb8 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -6,6 +6,12 @@ SUBDIRS = icons
 cssdir = $(pkgdatadir)
 css_DATA = goawebview.css
 
+gsettings_in_files = org.gnome.online-accounts.gschema.xml.in
+gsettings_SCHEMAS = $(gsettings_in_files:.xml.in=.xml)
+
+ INTLTOOL_XML_RULE@
+ GSETTINGS_RULES@
+
 servicedir       = $(datadir)/dbus-1/services
 service_in_files = org.gnome.OnlineAccounts.service.in
 service_DATA     = $(service_in_files:.service.in=.service)
@@ -15,11 +21,13 @@ $(service_DATA): $(service_in_files) Makefile
 
 EXTRA_DIST =                                           \
        $(css_DATA)                                     \
+       $(gsettings_in_files)                           \
        $(service_in_files)                             \
        dbus-interfaces.xml                             \
        $(NULL)
 
 DISTCLEANFILES =                                       \
+       $(gsettings_SCHEMAS)                            \
        org.gnome.OnlineAccounts.service                \
        $(NULL)
 
diff --git a/data/org.gnome.online-accounts.gschema.xml.in b/data/org.gnome.online-accounts.gschema.xml.in
new file mode 100644
index 0000000..e42845a
--- /dev/null
+++ b/data/org.gnome.online-accounts.gschema.xml.in
@@ -0,0 +1,11 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+  <schema id="org.gnome.online-accounts" path="/org/gnome/online-accounts/">
+    <key name="whitelisted-providers" type="as">
+      <default>['all']</default>
+      <summary>List of providers that are allowed to be loaded</summary>
+      <description>
+        A list of strings representing the providers that are allowed to be loaded (default: 'all'). This is 
only evaluated on startup.
+      </description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8a8279e..6435ed4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
 [encoding: UTF-8]
 # List of source files containing translatable strings.
 # Please keep this file sorted alphabetically.
+data/org.gnome.online-accounts.gschema.xml.in
 src/daemon/goadaemon.c
 src/goabackend/goaewsclient.c
 src/goabackend/goaexchangeprovider.c
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 89c3ff0..e40a9bb 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -644,44 +644,100 @@ goa_provider_ensure_extension_points_registered (void)
     }
 }
 
-static void
-ensure_builtins_loaded (void)
-{
-  static gsize once_init_value = 0;
-
-  goa_provider_ensure_extension_points_registered ();
+/* ---------------------------------------------------------------------------------------------------- */
 
-  if (g_once_init_enter (&once_init_value))
-    {
-      /* The order is in which the providers' types are created is
-       * important because it affects the order in which they are
-       * returned by goa_provider_get_all.
-       */
+static struct
+{
+  const gchar *name;
+  GType (*get_type) (void);
+} ordered_builtins_map[] = {
+  /* The order is in which the providers' types are created is
+   * important because it affects the order in which they are
+   * returned by goa_provider_get_all.
+   */
 #ifdef GOA_GOOGLE_ENABLED
-      g_type_ensure (GOA_TYPE_GOOGLE_PROVIDER);
+  { GOA_GOOGLE_NAME, goa_google_provider_get_type },
 #endif
 #ifdef GOA_OWNCLOUD_ENABLED
-      g_type_ensure (GOA_TYPE_OWNCLOUD_PROVIDER);
+  { GOA_OWNCLOUD_NAME, goa_owncloud_provider_get_type },
 #endif
 #ifdef GOA_FACEBOOK_ENABLED
-      g_type_ensure (GOA_TYPE_FACEBOOK_PROVIDER);
+  { GOA_FACEBOOK_NAME, goa_facebook_provider_get_type },
 #endif
 #ifdef GOA_FLICKR_ENABLED
-      g_type_ensure (GOA_TYPE_FLICKR_PROVIDER);
+  { GOA_FLICKR_NAME, goa_flickr_provider_get_type },
 #endif
 #ifdef GOA_WINDOWS_LIVE_ENABLED
-      g_type_ensure (GOA_TYPE_WINDOWS_LIVE_PROVIDER);
+  { GOA_WINDOWS_LIVE_NAME, goa_windows_live_provider_get_type },
 #endif
 #ifdef GOA_EXCHANGE_ENABLED
-      g_type_ensure (GOA_TYPE_EXCHANGE_PROVIDER);
+  { GOA_EXCHANGE_NAME, goa_exchange_provider_get_type },
 #endif
 #ifdef GOA_IMAP_SMTP_ENABLED
-      g_type_ensure (GOA_TYPE_IMAP_SMTP_PROVIDER);
+  { GOA_IMAP_SMTP_NAME, goa_imap_smtp_provider_get_type },
 #endif
 #ifdef GOA_KERBEROS_ENABLED
-      g_type_ensure (GOA_TYPE_KERBEROS_PROVIDER);
+  { GOA_KERBEROS_NAME, goa_kerberos_provider_get_type },
 #endif
+  { NULL, NULL }
+};
+
+static void
+ensure_builtins_loaded (void)
+{
+  static gsize once_init_value = 0;
+
+  goa_provider_ensure_extension_points_registered ();
 
+  if (g_once_init_enter (&once_init_value))
+    {
+      GSettings *settings;
+      gchar **whitelisted_providers;
+      guint i;
+      guint j;
+      gboolean all = FALSE;
+
+      settings = g_settings_new (GOA_SETTINGS_SCHEMA);
+      whitelisted_providers = g_settings_get_strv (settings, GOA_SETTINGS_WHITELISTED_PROVIDERS);
+
+      /* Enable everything if there is 'all'. */
+      for (i = 0; whitelisted_providers[i] != NULL; i++)
+        {
+          if (g_strcmp0 (whitelisted_providers[i], "all") == 0)
+            {
+              g_debug ("Loading all providers: ");
+              for (j = 0; ordered_builtins_map[j].name != NULL; j++)
+                {
+                  g_debug (" - %s", ordered_builtins_map[j].name);
+                  g_type_ensure ((*ordered_builtins_map[j].get_type) ());
+                }
+
+              all = TRUE;
+              break;
+            }
+        }
+
+      if (all)
+        goto cleanup;
+
+      /* Otherwise try them one by one. */
+      g_debug ("Loading whitelisted providers: ");
+      for (i = 0; ordered_builtins_map[i].name != NULL; i++)
+        {
+          for (j = 0; whitelisted_providers[j] != NULL; j++)
+            {
+              if (g_strcmp0 (whitelisted_providers[j], ordered_builtins_map[i].name) == 0)
+                {
+                  g_debug (" - %s", ordered_builtins_map[j].name);
+                  g_type_ensure ((*ordered_builtins_map[i].get_type) ());
+                  break;
+                }
+            }
+        }
+
+    cleanup:
+      g_strfreev (whitelisted_providers);
+      g_object_unref (settings);
       g_once_init_leave (&once_init_value, 1);
     }
 }
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index ab593e0..dec2363 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2012, 2013 Red Hat, Inc.
+ * Copyright (C) 2012, 2013, 2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -36,6 +36,9 @@ G_BEGIN_DECLS
 
 #define GOA_OAUTH2_ACCESS_DENIED "access_denied"
 
+#define GOA_SETTINGS_SCHEMA "org.gnome.online-accounts"
+#define GOA_SETTINGS_WHITELISTED_PROVIDERS "whitelisted-providers"
+
 typedef gpointer (*GoaPeekInterfaceFunc)   (GoaObject *);
 
 gboolean         goa_utils_check_duplicate (GoaClient              *client,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]