From 8e4d6ea41b43bc91d96878afe58df5385183b1a7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 27 Aug 2012 19:01:35 +0100 Subject: [PATCH 4/5] McdStorage, McdPluginAccountManager: squash into one class The Storage name stays, to make the diff more readable. The header is mcd-storage.h but the implementation is still plugin-account.c, for the same reason. Signed-off-by: Simon McVittie --- src/Makefile.am | 2 - src/mcd-account-manager.c | 61 ++++++------- src/mcd-storage.c | 95 -------------------- src/mcd-storage.h | 31 +++++-- src/plugin-account.c | 210 +++++++++++++++++++++++++-------------------- src/plugin-account.h | 81 ----------------- 6 files changed, 174 insertions(+), 306 deletions(-) delete mode 100644 src/mcd-storage.c delete mode 100644 src/plugin-account.h diff --git a/src/Makefile.am b/src/Makefile.am index cb94760..0d09b7d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -159,7 +159,6 @@ libmcd_convenience_la_SOURCES = \ mcd-slacker.c \ mcd-slacker.h \ mcd-transport.c \ - mcd-storage.c \ mcd-storage.h \ plugin-dispatch-operation.c \ plugin-dispatch-operation.h \ @@ -168,7 +167,6 @@ libmcd_convenience_la_SOURCES = \ plugin-request.c \ plugin-request.h \ plugin-account.c \ - plugin-account.h \ request.c \ request.h \ sp_timestamp.h \ diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 4c11da9..17f2e3f 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -44,9 +44,9 @@ #include "mcd-dbusprop.h" #include "mcd-master-priv.h" #include "mcd-misc.h" +#include "mcd-storage.h" #include "mission-control-plugins/mission-control-plugins.h" #include "mission-control-plugins/implementation.h" -#include "plugin-account.h" #include "plugin-loader.h" #include "_gen/interfaces.h" @@ -91,7 +91,7 @@ struct _McdAccountManagerPrivate /* DBUS connection */ TpDBusDaemon *dbus_daemon; - McdPluginAccountManager *plugin_manager; + McdStorage *storage; GHashTable *accounts; gchar *account_connections_dir; /* directory for temporary file */ @@ -103,7 +103,7 @@ struct _McdAccountManagerPrivate typedef struct { McdAccountManager *account_manager; - McpAccountStorage *storage; + McpAccountStorage *storage_plugin; McdAccount *account; gint account_lock; } McdLoadAccountsData; @@ -290,7 +290,7 @@ async_created_manager_cb (McdManager *cm, const GError *error, gpointer data) McdLoadAccountsData *lad = data; McdAccount *account = lad->account; McdAccountManager *am = lad->account_manager; - McpAccountStorage *plugin = lad->storage; + McpAccountStorage *plugin = lad->storage_plugin; const gchar *name = NULL; if (cm != NULL) @@ -319,25 +319,28 @@ async_created_manager_cb (McdManager *cm, const GError *error, gpointer data) * to fetch the named account explicitly at this point (ie it's a read, not * * not a write, from the plugin's POV: */ static void -created_cb (GObject *storage, const gchar *name, gpointer data) +created_cb (GObject *storage_plugin_obj, + const gchar *name, + gpointer data) { - McpAccountStorage *plugin = MCP_ACCOUNT_STORAGE (storage); + McpAccountStorage *plugin = MCP_ACCOUNT_STORAGE (storage_plugin_obj); McdAccountManager *am = MCD_ACCOUNT_MANAGER (data); McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (am); McdAccountManagerClass *mclass = MCD_ACCOUNT_MANAGER_GET_CLASS (am); McdLoadAccountsData *lad = g_slice_new (McdLoadAccountsData); McdAccount *account = NULL; - McdPluginAccountManager *pa = priv->plugin_manager; + McdStorage *storage = priv->storage; McdMaster *master = mcd_master_get_default (); McdManager *cm = NULL; const gchar *cm_name = NULL; lad->account_manager = am; - lad->storage = plugin; + lad->storage_plugin = plugin; lad->account_lock = 1; /* will be released at the end of this function */ /* actually fetch the data into our cache from the plugin: */ - if (mcp_account_storage_get (plugin, MCP_ACCOUNT_MANAGER (pa), name, NULL)) + if (mcp_account_storage_get (plugin, MCP_ACCOUNT_MANAGER (storage), + name, NULL)) { account = mclass->account_new (am, name); lad->account = account; @@ -381,7 +384,7 @@ finish: static void toggled_cb (GObject *plugin, const gchar *name, gboolean on, gpointer data) { - McpAccountStorage *storage = MCP_ACCOUNT_STORAGE (plugin); + McpAccountStorage *storage_plugin = MCP_ACCOUNT_STORAGE (plugin); McdAccountManager *manager = MCD_ACCOUNT_MANAGER (data); McdAccount *account = NULL; GError *error = NULL; @@ -389,12 +392,12 @@ toggled_cb (GObject *plugin, const gchar *name, gboolean on, gpointer data) account = mcd_account_manager_lookup_account (manager, name); DEBUG ("%s plugin reports %s became %sabled", - mcp_account_storage_name (storage), name, on ? "en" : "dis"); + mcp_account_storage_name (storage_plugin), name, on ? "en" : "dis"); if (account == NULL) { g_warning ("%s: Unknown account %s from %s plugin", - G_STRFUNC, name, mcp_account_storage_name (storage)); + G_STRFUNC, name, mcp_account_storage_name (storage_plugin)); return; } @@ -419,14 +422,14 @@ _mcd_account_delete_cb (McdAccount *account, const GError *error, gpointer data) static void deleted_cb (GObject *plugin, const gchar *name, gpointer data) { - McpAccountStorage *storage = MCP_ACCOUNT_STORAGE (plugin); + McpAccountStorage *storage_plugin = MCP_ACCOUNT_STORAGE (plugin); McdAccountManager *manager = MCD_ACCOUNT_MANAGER (data); McdAccount *account = NULL; account = g_hash_table_lookup (manager->priv->accounts, name); DEBUG ("%s reported deletion of %s (%p)", - mcp_account_storage_name (storage), name, account); + mcp_account_storage_name (storage_plugin), name, account); if (account != NULL) { @@ -610,7 +613,7 @@ static void on_account_removed (McdAccount *account, McdAccountManager *account_manager) { McdAccountManagerPrivate *priv = account_manager->priv; - McdStorage *storage = MCD_STORAGE (priv->plugin_manager); + McdStorage *storage = priv->storage; const gchar *name, *object_path; object_path = mcd_account_get_object_path (account); @@ -851,7 +854,7 @@ _mcd_account_manager_create_account (McdAccountManager *account_manager, GDestroyNotify destroy) { McdAccountManagerPrivate *priv = account_manager->priv; - McdStorage *storage = MCD_STORAGE (priv->plugin_manager); + McdStorage *storage = priv->storage; McdCreateAccountData *cad; McdAccount *account; gchar *unique_name = NULL; @@ -1143,7 +1146,7 @@ uncork_storage_plugins (McdAccountManager *account_manager) McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (account_manager); mcd_account_manager_write_conf_async (account_manager, NULL, NULL, NULL); - _mcd_plugin_account_manager_ready (priv->plugin_manager); + mcd_storage_ready (priv->storage); } typedef struct @@ -1372,7 +1375,7 @@ void _mcd_account_manager_setup (McdAccountManager *account_manager) { McdAccountManagerPrivate *priv = account_manager->priv; - McdStorage *storage = MCD_STORAGE (priv->plugin_manager); + McdStorage *storage = priv->storage; McdLoadAccountsData *lad; gchar **accounts, **name; @@ -1516,11 +1519,11 @@ _mcd_account_manager_finalize (GObject *object) if (write_conf_id) { - write_conf (priv->plugin_manager); + write_conf (priv->storage); g_assert (write_conf_id == 0); } - tp_clear_object (&priv->plugin_manager); + tp_clear_object (&priv->storage); g_free (priv->account_connections_dir); remove (priv->account_connections_file); g_free (priv->account_connections_file); @@ -1599,7 +1602,7 @@ mcd_account_manager_init (McdAccountManager *account_manager) McdAccountManagerPrivate); account_manager->priv = priv; - priv->plugin_manager = mcd_plugin_account_manager_new (); + priv->storage = mcd_storage_new (); priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, unref_account); @@ -1609,13 +1612,14 @@ mcd_account_manager_init (McdAccountManager *account_manager) NULL); DEBUG ("loading plugins"); - mcd_storage_load (MCD_STORAGE (priv->plugin_manager)); + mcd_storage_load (priv->storage); /* hook up all the storage plugin signals to their handlers: */ for (i = 0; sig[i].name != NULL; i++) - _mcd_plugin_account_manager_connect_signal (sig[i].name, - sig[i].handler, - account_manager); + { + mcd_storage_connect_signal (sig[i].name, sig[i].handler, + account_manager); + } /* initializes the interfaces */ mcd_dbus_init_interfaces_instances (account_manager); @@ -1626,13 +1630,12 @@ _mcd_account_manager_constructed (GObject *obj) { McdAccountManager *manager = MCD_ACCOUNT_MANAGER (obj); McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (manager); - McdPluginAccountManager *pa = priv->plugin_manager; /* FIXME: I'm pretty sure we should just move most of the above code out of * _init() to here and then mcd_plugin_account_manager_new() could take the * TpDBusDaemon * as it should and everyone wins. */ - _mcd_plugin_account_manager_set_dbus_daemon (pa, priv->dbus_daemon); + mcd_storage_set_dbus_daemon (priv->storage, priv->dbus_daemon); } McdAccountManager * @@ -1691,7 +1694,7 @@ mcd_account_manager_write_conf_async (McdAccountManager *account_manager, g_return_if_fail (MCD_IS_ACCOUNT_MANAGER (account_manager)); - storage = MCD_STORAGE (account_manager->priv->plugin_manager); + storage = account_manager->priv->storage; if (account != NULL) { @@ -1797,6 +1800,6 @@ _mcd_account_manager_store_account_connections (McdAccountManager *manager) McdStorage * mcd_account_manager_get_storage (McdAccountManager *account_manager) { - return MCD_STORAGE (account_manager->priv->plugin_manager); + return account_manager->priv->storage; } diff --git a/src/mcd-storage.c b/src/mcd-storage.c deleted file mode 100644 index aa5f43d..0000000 --- a/src/mcd-storage.c +++ /dev/null @@ -1,95 +0,0 @@ -/* Mission Control storage API - interface which provides access to account - * parameter/setting storage - * - * Copyright © 2010 Nokia Corporation - * Copyright © 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "mcd-storage.h" -#include "mcd-master.h" -#include "mcd-account-manager-priv.h" - -GType -mcd_storage_get_type (void) -{ - static gsize once = 0; - static GType type = 0; - - if (g_once_init_enter (&once)) - { - static const GTypeInfo info = { - sizeof (McdStorageIface), - NULL, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, /* instance_size */ - 0, /* n_preallocs */ - NULL, /* instance_init */ - NULL /* value_table */ - }; - - type = g_type_register_static (G_TYPE_INTERFACE, "McdStorage", &info, 0); - g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); - g_once_init_leave (&once, 1); - } - - return type; -} - -/** - * mcd_storage_set_strv: - * @storage: An object implementing the #McdStorage interface - * @account: the unique name of an account - * @key: the key (name) of the parameter or setting - * @strv: the string vector to be stored (where %NULL is treated as equivalent - * to an empty vector) - * @secret: whether the value is confidential (might get stored in the - * keyring, for example) - * - * Copies and stores the supplied string vector to the internal cache. - * - * Returns: a #gboolean indicating whether the cache actually required an - * update (so that the caller can decide whether to request a commit to - * long term storage or not). %TRUE indicates the cache was updated and - * may not be in sync with the store any longer, %FALSE indicates we already - * held the value supplied. - */ -gboolean -mcd_storage_set_strv (McdStorage *storage, - const gchar *account, - const gchar *key, - const gchar * const *strv, - gboolean secret) -{ - GValue v = { 0, }; - static const gchar * const *empty = { NULL }; - gboolean ret; - - g_return_val_if_fail (MCD_IS_STORAGE (storage), FALSE); - g_return_val_if_fail (account != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - g_value_init (&v, G_TYPE_STRV); - g_value_set_static_boxed (&v, strv == NULL ? empty : strv); - ret = mcd_storage_set_value (storage, account, key, &v, secret); - g_value_unset (&v); - return ret; -} diff --git a/src/mcd-storage.h b/src/mcd-storage.h index 7a17f7e..5a09155 100644 --- a/src/mcd-storage.h +++ b/src/mcd-storage.h @@ -27,26 +27,43 @@ G_BEGIN_DECLS -typedef struct _McdStorage McdStorage; -typedef struct _McdStorageIface McdStorageIface; +typedef struct { + GObject parent; + TpDBusDaemon *dbusd; + GKeyFile *keyfile; + GKeyFile *secrets; +} McdStorage; -struct _McdStorageIface { - GTypeInterface parent; -}; +typedef struct _McdStorageClass McdStorageClass; +typedef struct _McdStoragePrivate McdStoragePrivate; #define MCD_TYPE_STORAGE (mcd_storage_get_type ()) #define MCD_STORAGE(o) \ (G_TYPE_CHECK_INSTANCE_CAST ((o), MCD_TYPE_STORAGE, McdStorage)) +#define MCD_STORAGE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST ((cls), MCD_TYPE_STORAGE, McdStorageClass)) + #define MCD_IS_STORAGE(o) \ (G_TYPE_CHECK_INSTANCE_TYPE ((o), MCD_TYPE_STORAGE)) -#define MCD_STORAGE_GET_IFACE(o) \ - (G_TYPE_INSTANCE_GET_INTERFACE ((o), MCD_TYPE_STORAGE, McdStorageIface)) +#define MCD_IS_STORAGE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE ((cls), MCD_TYPE_STORAGE)) + +#define MCD_STORAGE_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), MCD_TYPE_STORAGE, McdStorageClass)) GType mcd_storage_get_type (void); +McdStorage *mcd_storage_new (void); +void mcd_storage_set_dbus_daemon (McdStorage *self, + TpDBusDaemon *dbusd); +void mcd_storage_ready (McdStorage *self); +void mcd_storage_connect_signal (const gchar *signal, + GCallback func, + gpointer user_data); + void mcd_storage_load (McdStorage *storage); GStrv mcd_storage_dup_accounts (McdStorage *storage, gsize *n); diff --git a/src/plugin-account.c b/src/plugin-account.c index 8e99ba7..e786eed 100644 --- a/src/plugin-account.c +++ b/src/plugin-account.c @@ -21,9 +21,12 @@ * */ #include "config.h" +#include "mcd-storage.h" +#include "mcd-account.h" +#include "mcd-account-config.h" +#include "mcd-debug.h" #include "plugin-loader.h" -#include "plugin-account.h" #include @@ -48,31 +51,30 @@ enum { PROP_DBUS_DAEMON = 1, }; -struct _McdPluginAccountManagerClass { +struct _McdStorageClass { GObjectClass parent; }; static void plugin_iface_init (McpAccountManagerIface *iface, gpointer unused G_GNUC_UNUSED); -G_DEFINE_TYPE_WITH_CODE (McdPluginAccountManager, mcd_plugin_account_manager, \ +G_DEFINE_TYPE_WITH_CODE (McdStorage, mcd_storage, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (MCD_TYPE_STORAGE, NULL); G_IMPLEMENT_INTERFACE (MCP_TYPE_ACCOUNT_MANAGER, plugin_iface_init)) static void -mcd_plugin_account_manager_init (McdPluginAccountManager *self) +mcd_storage_init (McdStorage *self) { self->keyfile = g_key_file_new (); self->secrets = g_key_file_new (); } static void -plugin_account_manager_finalize (GObject *object) +storage_finalize (GObject *object) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (object); + McdStorage *self = MCD_STORAGE (object); GObjectFinalizeFunc finalize = - G_OBJECT_CLASS (mcd_plugin_account_manager_parent_class)->finalize; + G_OBJECT_CLASS (mcd_storage_parent_class)->finalize; g_key_file_free (self->keyfile); g_key_file_free (self->secrets); @@ -84,11 +86,11 @@ plugin_account_manager_finalize (GObject *object) } static void -plugin_account_manager_dispose (GObject *object) +storage_dispose (GObject *object) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (object); + McdStorage *self = MCD_STORAGE (object); GObjectFinalizeFunc dispose = - G_OBJECT_CLASS (mcd_plugin_account_manager_parent_class)->dispose; + G_OBJECT_CLASS (mcd_storage_parent_class)->dispose; tp_clear_object (&self->dbusd); @@ -97,10 +99,10 @@ plugin_account_manager_dispose (GObject *object) } static void -plugin_account_manager_set_property (GObject *obj, guint prop_id, +storage_set_property (GObject *obj, guint prop_id, const GValue *val, GParamSpec *pspec) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (obj); + McdStorage *self = MCD_STORAGE (obj); switch (prop_id) { @@ -116,10 +118,10 @@ plugin_account_manager_set_property (GObject *obj, guint prop_id, } static void -plugin_account_manager_get_property (GObject *obj, guint prop_id, +storage_get_property (GObject *obj, guint prop_id, GValue *val, GParamSpec *pspec) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (obj); + McdStorage *self = MCD_STORAGE (obj); switch (prop_id) { @@ -133,7 +135,7 @@ plugin_account_manager_get_property (GObject *obj, guint prop_id, } static void -mcd_plugin_account_manager_class_init (McdPluginAccountManagerClass *cls) +mcd_storage_class_init (McdStorageClass *cls) { GObjectClass *object_class = (GObjectClass *) cls; GParamSpec *spec = g_param_spec_object ("dbus-daemon", @@ -142,23 +144,23 @@ mcd_plugin_account_manager_class_init (McdPluginAccountManagerClass *cls) TP_TYPE_DBUS_DAEMON, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - object_class->set_property = plugin_account_manager_set_property; - object_class->get_property = plugin_account_manager_get_property; - object_class->dispose = plugin_account_manager_dispose; - object_class->finalize = plugin_account_manager_finalize; + object_class->set_property = storage_set_property; + object_class->get_property = storage_get_property; + object_class->dispose = storage_dispose; + object_class->finalize = storage_finalize; g_object_class_install_property (object_class, PROP_DBUS_DAEMON, spec); } -McdPluginAccountManager * -mcd_plugin_account_manager_new () +McdStorage * +mcd_storage_new () { - return g_object_new (MCD_TYPE_PLUGIN_ACCOUNT_MANAGER, + return g_object_new (MCD_TYPE_STORAGE, NULL); } void -_mcd_plugin_account_manager_set_dbus_daemon (McdPluginAccountManager *self, +mcd_storage_set_dbus_daemon (McdStorage *self, TpDBusDaemon *dbusd) { GValue value = { 0 }; @@ -174,7 +176,7 @@ get_value (const McpAccountManager *ma, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); return g_key_file_get_value (self->keyfile, account, key, NULL); } @@ -184,7 +186,7 @@ set_value (const McpAccountManager *ma, const gchar *key, const gchar *value) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); if (value != NULL) g_key_file_set_value (self->keyfile, account, key, value); @@ -196,7 +198,7 @@ static GStrv list_keys (const McpAccountManager *ma, const gchar * account) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); return g_key_file_get_keys (self->keyfile, account, NULL, NULL); } @@ -206,7 +208,7 @@ is_secret (const McpAccountManager *ma, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); return g_key_file_get_boolean (self->secrets, account, key, NULL); } @@ -216,7 +218,7 @@ make_secret (const McpAccountManager *ma, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); DEBUG ("flagging %s.%s as secret", account, key); g_key_file_set_boolean (self->secrets, account, key, TRUE); } @@ -227,7 +229,7 @@ unique_name (const McpAccountManager *ma, const gchar *protocol, const GHashTable *params) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (ma); + McdStorage *self = MCD_STORAGE (ma); const gchar *base = NULL; gchar *esc_manager, *esc_protocol, *esc_base; guint i; @@ -335,7 +337,7 @@ sort_and_cache_plugins () } void -_mcd_plugin_account_manager_connect_signal (const gchar *signame, +mcd_storage_connect_signal (const gchar *signame, GCallback func, gpointer user_data) { @@ -365,7 +367,7 @@ mcd_storage_load (McdStorage *self) McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); GList *store = NULL; - g_return_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (self)); + g_return_if_fail (MCD_IS_STORAGE (self)); sort_and_cache_plugins (); @@ -407,12 +409,10 @@ mcd_storage_load (McdStorage *self) * which must be freed by the caller with g_strfreev(). */ GStrv -mcd_storage_dup_accounts (McdStorage *storage, +mcd_storage_dup_accounts (McdStorage *self, gsize *n) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); return g_key_file_get_groups (self->keyfile, n); } @@ -428,13 +428,11 @@ mcd_storage_dup_accounts (McdStorage *storage, * freed by the caller with g_strfreev(). */ GStrv -mcd_storage_dup_settings (McdStorage *storage, +mcd_storage_dup_settings (McdStorage *self, const gchar *account, gsize *n) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); return g_key_file_get_keys (self->keyfile, account, n, NULL); } @@ -453,14 +451,14 @@ mcd_storage_dup_settings (McdStorage *storage, * probably safer not to) */ McpAccountStorage * -mcd_storage_get_plugin (McdStorage *storage, const gchar *account) +mcd_storage_get_plugin (McdStorage *self, + const gchar *account) { GList *store = stores; - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); McpAccountStorage *owner = NULL; - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); g_return_val_if_fail (account != NULL, NULL); for (; store != NULL && owner == NULL; store = g_list_next (store)) @@ -483,14 +481,13 @@ mcd_storage_get_plugin (McdStorage *storage, const gchar *account) * Returns: a newly allocated gchar * which must be freed with g_free(). */ gchar * -mcd_storage_dup_string (McdStorage *storage, +mcd_storage_dup_string (McdStorage *self, const gchar *account, const gchar *key) { gchar *value = NULL; - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); g_return_val_if_fail (account != NULL, NULL); value = g_key_file_get_string (self->keyfile, account, key, NULL); @@ -508,13 +505,11 @@ mcd_storage_dup_string (McdStorage *storage, * %FALSE otherwise. */ gboolean -mcd_storage_has_value (McdStorage *storage, +mcd_storage_has_value (McdStorage *self, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), FALSE); + g_return_val_if_fail (MCD_IS_STORAGE (self), FALSE); g_return_val_if_fail (account != NULL, FALSE); g_return_val_if_fail (key != NULL, FALSE); @@ -539,7 +534,7 @@ mcd_storage_has_value (McdStorage *storage, * value for @type has been returned. */ GValue * -mcd_storage_dup_value (McdStorage *storage, +mcd_storage_dup_value (McdStorage *self, const gchar *account, const gchar *key, GType type, @@ -551,32 +546,29 @@ mcd_storage_dup_value (McdStorage *storage, guint64 v_uint = 0; gboolean v_bool = FALSE; double v_double = 0.0; - GKeyFile *keyfile; - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); g_return_val_if_fail (account != NULL, NULL); - keyfile = MCD_PLUGIN_ACCOUNT_MANAGER (storage)->keyfile; - switch (type) { case G_TYPE_STRING: - v_string = g_key_file_get_string (keyfile, account, key, error); + v_string = g_key_file_get_string (self->keyfile, account, key, error); value = tp_g_value_slice_new_take_string (v_string); break; case G_TYPE_INT: - v_int = g_key_file_get_integer (keyfile, account, key, error); + v_int = g_key_file_get_integer (self->keyfile, account, key, error); value = tp_g_value_slice_new_int (v_int); break; case G_TYPE_INT64: - v_int = tp_g_key_file_get_int64 (keyfile, account, key, error); + v_int = tp_g_key_file_get_int64 (self->keyfile, account, key, error); value = tp_g_value_slice_new_int64 (v_int); break; case G_TYPE_UINT: - v_uint = tp_g_key_file_get_uint64 (keyfile, account, key, error); + v_uint = tp_g_key_file_get_uint64 (self->keyfile, account, key, error); if (v_uint > 0xFFFFFFFFU) g_set_error (error, MCD_ACCOUNT_ERROR, @@ -587,7 +579,7 @@ mcd_storage_dup_value (McdStorage *storage, break; case G_TYPE_UCHAR: - v_int = g_key_file_get_integer (keyfile, account, key, error); + v_int = g_key_file_get_integer (self->keyfile, account, key, error); if (v_int < 0 || v_int > 0xFF) { @@ -603,31 +595,32 @@ mcd_storage_dup_value (McdStorage *storage, break; case G_TYPE_UINT64: - v_uint = tp_g_key_file_get_uint64 (keyfile, account, key, error); + v_uint = tp_g_key_file_get_uint64 (self->keyfile, account, key, error); value = tp_g_value_slice_new_uint64 (v_uint); break; case G_TYPE_BOOLEAN: - v_bool = g_key_file_get_boolean (keyfile, account, key, error); + v_bool = g_key_file_get_boolean (self->keyfile, account, key, error); value = tp_g_value_slice_new_boolean (v_bool); break; case G_TYPE_DOUBLE: - v_double = g_key_file_get_double (keyfile, account, key, error); + v_double = g_key_file_get_double (self->keyfile, account, key, error); value = tp_g_value_slice_new_double (v_double); break; default: if (type == G_TYPE_STRV) { - gchar **v = - g_key_file_get_string_list (keyfile, account, key, NULL, error); + gchar **v = g_key_file_get_string_list (self->keyfile, account, + key, NULL, error); value = tp_g_value_slice_new_take_boxed (G_TYPE_STRV, v); } else if (type == DBUS_TYPE_G_OBJECT_PATH) { - v_string = g_key_file_get_string (keyfile, account, key, NULL); + v_string = g_key_file_get_string (self->keyfile, account, key, + NULL); if (v_string == NULL) { @@ -649,8 +642,8 @@ mcd_storage_dup_value (McdStorage *storage, } else if (type == TP_ARRAY_TYPE_OBJECT_PATH_LIST) { - gchar **v = - g_key_file_get_string_list (keyfile, account, key, NULL, error); + gchar **v = g_key_file_get_string_list (self->keyfile, account, + key, NULL, error); gchar **iter; GPtrArray *arr = g_ptr_array_new (); @@ -712,13 +705,11 @@ mcd_storage_dup_value (McdStorage *storage, * Returns: a #gboolean. Unset/unparseable values are returned as %FALSE */ gboolean -mcd_storage_get_boolean (McdStorage *storage, +mcd_storage_get_boolean (McdStorage *self, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), FALSE); + g_return_val_if_fail (MCD_IS_STORAGE (self), FALSE); g_return_val_if_fail (account != NULL, FALSE); return g_key_file_get_boolean (self->keyfile, account, key, NULL); @@ -733,20 +724,18 @@ mcd_storage_get_boolean (McdStorage *storage, * Returns: a #gint. Unset or non-numeric values are returned as 0 */ gint -mcd_storage_get_integer (McdStorage *storage, +mcd_storage_get_integer (McdStorage *self, const gchar *account, const gchar *key) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); - - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), 0); + g_return_val_if_fail (MCD_IS_STORAGE (self), 0); g_return_val_if_fail (account != NULL, 0); return g_key_file_get_integer (self->keyfile, account, key, NULL); } static void -update_storage (McdPluginAccountManager *self, +update_storage (McdStorage *self, const gchar *account, const gchar *key) { @@ -805,17 +794,16 @@ update_storage (McdPluginAccountManager *self, * held the value supplied. */ gboolean -mcd_storage_set_string (McdStorage *storage, +mcd_storage_set_string (McdStorage *self, const gchar *account, const gchar *key, const gchar *val, gboolean secret) { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); gboolean updated = FALSE; gchar *old = g_key_file_get_string (self->keyfile, account, key, NULL); - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), FALSE); + g_return_val_if_fail (MCD_IS_STORAGE (self), FALSE); g_return_val_if_fail (account != NULL, FALSE); g_return_val_if_fail (key != NULL, FALSE); @@ -861,23 +849,22 @@ mcd_storage_set_string (McdStorage *storage, * held the value supplied. */ gboolean -mcd_storage_set_value (McdStorage *storage, +mcd_storage_set_value (McdStorage *self, const gchar *name, const gchar *key, const GValue *value, gboolean secret) { - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), FALSE); + g_return_val_if_fail (MCD_IS_STORAGE (self), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (key != NULL, FALSE); if (value == NULL) { - return mcd_storage_set_string (storage, name, key, NULL, secret); + return mcd_storage_set_string (self, name, key, NULL, secret); } else { - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); gboolean updated = FALSE; gchar *old = g_key_file_get_value (self->keyfile, name, key, NULL); gchar *new = NULL; @@ -995,7 +982,7 @@ mcd_storage_set_value (McdStorage *storage, * Returns: the unique name to use for the new account, or %NULL on error. */ gchar * -mcd_storage_create_account (McdStorage *storage, +mcd_storage_create_account (McdStorage *self, const gchar *provider, const gchar *manager, const gchar *protocol, @@ -1003,10 +990,9 @@ mcd_storage_create_account (McdStorage *storage, GError **error) { GList *store; - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); - g_return_val_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage), NULL); + g_return_val_if_fail (MCD_IS_STORAGE (self), NULL); g_return_val_if_fail (!tp_str_empty (manager), NULL); g_return_val_if_fail (!tp_str_empty (protocol), NULL); @@ -1101,13 +1087,13 @@ mcd_storage_create_account (McdStorage *storage, * in long term storage once mcd_storage_commit() has been called. */ void -mcd_storage_delete_account (McdStorage *storage, const gchar *account) +mcd_storage_delete_account (McdStorage *self, + const gchar *account) { GList *store; - McdPluginAccountManager *self = MCD_PLUGIN_ACCOUNT_MANAGER (storage); McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); - g_return_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (storage)); + g_return_if_fail (MCD_IS_STORAGE (self)); g_return_if_fail (account != NULL); g_key_file_remove_group (self->keyfile, account, NULL); @@ -1134,7 +1120,7 @@ mcd_storage_commit (McdStorage *self, const gchar *account) GList *store; McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); - g_return_if_fail (MCD_IS_PLUGIN_ACCOUNT_MANAGER (self)); + g_return_if_fail (MCD_IS_STORAGE (self)); for (store = stores; store != NULL; store = g_list_next (store)) { @@ -1154,8 +1140,48 @@ mcd_storage_commit (McdStorage *self, const gchar *account) } } +/* + * mcd_storage_set_strv: + * @storage: An object implementing the #McdStorage interface + * @account: the unique name of an account + * @key: the key (name) of the parameter or setting + * @strv: the string vector to be stored (where %NULL is treated as equivalent + * to an empty vector) + * @secret: whether the value is confidential (might get stored in the + * keyring, for example) + * + * Copies and stores the supplied string vector to the internal cache. + * + * Returns: a #gboolean indicating whether the cache actually required an + * update (so that the caller can decide whether to request a commit to + * long term storage or not). %TRUE indicates the cache was updated and + * may not be in sync with the store any longer, %FALSE indicates we already + * held the value supplied. + */ +gboolean +mcd_storage_set_strv (McdStorage *storage, + const gchar *account, + const gchar *key, + const gchar * const *strv, + gboolean secret) +{ + GValue v = { 0, }; + static const gchar * const *empty = { NULL }; + gboolean ret; + + g_return_val_if_fail (MCD_IS_STORAGE (storage), FALSE); + g_return_val_if_fail (account != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + + g_value_init (&v, G_TYPE_STRV); + g_value_set_static_boxed (&v, strv == NULL ? empty : strv); + ret = mcd_storage_set_value (storage, account, key, &v, secret); + g_value_unset (&v); + return ret; +} + void -_mcd_plugin_account_manager_ready (McdPluginAccountManager *self) +mcd_storage_ready (McdStorage *self) { GList *store; McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); diff --git a/src/plugin-account.h b/src/plugin-account.h deleted file mode 100644 index 27fb731..0000000 --- a/src/plugin-account.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Representation of the account manager as presented to plugins. This is - * deliberately a "smaller" API than McdAccountManager. - * - * Copyright © 2010 Nokia Corporation - * Copyright © 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef MCD_PLUGIN_ACCOUNT_MANAGER_H -#define MCD_PLUGIN_ACCOUNT_MANAGER_H - -#include - -#include "mcd-account-manager.h" - -G_BEGIN_DECLS - -typedef struct { - GObject parent; - TpDBusDaemon *dbusd; - GKeyFile *keyfile; - GKeyFile *secrets; -} McdPluginAccountManager; - -typedef struct _McdPluginAccountManagerClass McdPluginAccountManagerClass; -typedef struct _McdPluginAccountManagerPrivate McdPluginAccountManagerPrivate; - -G_GNUC_INTERNAL GType mcd_plugin_account_manager_get_type (void); - -#define MCD_TYPE_PLUGIN_ACCOUNT_MANAGER (mcd_plugin_account_manager_get_type ()) - -#define MCD_PLUGIN_ACCOUNT_MANAGER(o) \ - (G_TYPE_CHECK_INSTANCE_CAST ((o), MCD_TYPE_PLUGIN_ACCOUNT_MANAGER, \ - McdPluginAccountManager)) - -#define MCD_PLUGIN_ACCOUNT_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), MCD_TYPE_PLUGIN_ACCOUNT_MANAGER, \ - McdPluginAccountManagerClass)) - -#define MCD_IS_PLUGIN_ACCOUNT_MANAGER(o) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((o), MCD_TYPE_PLUGIN_ACCOUNT_MANAGER)) - -#define MCD_IS_PLUGIN_ACCOUNT_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), MCD_TYPE_PLUGIN_ACCOUNT_MANAGER)) - -#define MCD_PLUGIN_ACCOUNT_MANAGER_GET_CLASS(o) \ - (G_TYPE_INSTANCE_GET_CLASS ((o), MCD_TYPE_PLUGIN_ACCOUNT_MANAGER, \ - McdPluginAccountManagerClass)) - -McdPluginAccountManager *mcd_plugin_account_manager_new (void); - -G_GNUC_INTERNAL -void _mcd_plugin_account_manager_set_dbus_daemon (McdPluginAccountManager *self, - TpDBusDaemon *dbusd); - -G_GNUC_INTERNAL -void _mcd_plugin_account_manager_ready (McdPluginAccountManager *self); - -G_GNUC_INTERNAL -void _mcd_plugin_account_manager_connect_signal (const gchar *signal, - GCallback func, - gpointer user_data); - -G_END_DECLS - -#endif -- 1.7.10.4