summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2010-11-17 13:18:39 (GMT)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2010-11-17 13:18:39 (GMT)
commit37c6ea25e0dcbfa7ec50a04f3929011d698e8461 (patch)
treebaced00a73c2d7307c319d9cd8bf259ffbecc4fe
parent0e41f320e6644951a0a22428cab22f0e4adcd90e (diff)
parent4a2f68a1b2c84940b844652566710ca2706cfc63 (diff)
downloadtelepathy-mission-control-37c6ea25e0dcbfa7ec50a04f3929011d698e8461.tar.gz
telepathy-mission-control-37c6ea25e0dcbfa7ec50a04f3929011d698e8461.tar.xz
Merge branch 'telepathy-mission-control-5.6'
Conflicts: NEWS configure.ac
-rw-r--r--NEWS21
-rw-r--r--src/mcd-account-manager-sso.c55
-rw-r--r--test/account-store-default.c6
-rw-r--r--test/account-store-default.h3
-rw-r--r--test/account-store-libaccounts.c391
-rw-r--r--test/account-store-libaccounts.h2
-rw-r--r--test/account-store.c32
7 files changed, 417 insertions, 93 deletions
diff --git a/NEWS b/NEWS
index c0437b4..b83a899 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,27 @@ telepathy-mission-control 5.7.0 (UNRELEASED)
+telepathy-mission-control 5.6.1 (2010-11-17)
+============================================
+
+The "I suppose Guinness is good for you" release.
+
+Enhancements:
+
+• Make mc-tool support object paths, and improve the help (wjt)
+
+Fixes:
+
+• fd.o #30447: don't "return x()", where x returns void, in void functions
+ (Jeff Cai)
+
+• fd.o #30448: make type of mcp_account_storage_get_restrictions consistent
+ with the header (smcv)
+
+• Fix support for libaccounts-glib (fledermaus)
+
+• Remove unnecessary use of _POSIX_C_SOURCE (Jeff Cai)
+
telepathy-mission-control 5.6.0 (2010-09-16)
============================================
diff --git a/src/mcd-account-manager-sso.c b/src/mcd-account-manager-sso.c
index 8e1796f..dc332db 100644
--- a/src/mcd-account-manager-sso.c
+++ b/src/mcd-account-manager-sso.c
@@ -48,6 +48,7 @@
"Account storage in the Maemo SSO store via libaccounts-glib API"
#define PLUGIN_PROVIDER "org.maemo.Telepathy.Account.Storage.LibAccounts"
+#define AG_SERVICE "IM"
#define MCPP "param-"
#define AGPP "parameters/"
#define LIBACCT_ID_KEY "libacct-uid"
@@ -61,6 +62,7 @@
#define AG_ACCOUNT_KEY "username"
#define MC_ACCOUNT_KEY "account"
#define PASSWORD_KEY "password"
+#define AG_ACCOUNT_ALT_KEY AGPP "account"
#define MC_CMANAGER_KEY "manager"
#define MC_PROTOCOL_KEY "protocol"
@@ -243,7 +245,7 @@ static gboolean
_ag_account_select_default_im_service (AgAccount *account)
{
gboolean have_im_service = FALSE;
- GList *first = ag_account_list_services_by_type (account, "IM");
+ GList *first = ag_account_list_services_by_type (account, AG_SERVICE);
if (first != NULL && first->data != NULL)
{
@@ -301,6 +303,36 @@ _ag_account_local_value (AgAccount *account,
return src;
}
+/* AG_ACCOUNT_ALT_KEY from service overrides global AG_ACCOUNT_KEY if set */
+static void
+_maybe_set_account_param_from_service (const McpAccountManager *am,
+ AgAccount *ag_account,
+ const gchar *mc_account)
+{
+ Setting *setting = setting_data (AG_ACCOUNT_KEY, SETTING_AG);
+ AgSettingSource source = AG_SETTING_SOURCE_NONE;
+ GValue ag_value = { 0 };
+
+ g_return_if_fail (setting != NULL);
+
+ g_value_init (&ag_value, G_TYPE_STRING);
+
+ source = _ag_account_local_value (ag_account, AG_ACCOUNT_ALT_KEY, &ag_value);
+
+ if (source != AG_SETTING_SOURCE_NONE)
+ {
+ gchar *value = _gvalue_to_string (&ag_value);
+
+ DEBUG ("overriding global %s param with %s: %s",
+ AG_ACCOUNT_KEY, AG_ACCOUNT_ALT_KEY, value);
+ mcp_account_manager_set_value (am, mc_account, setting->mc_name, value);
+ g_free (value);
+ }
+
+ g_value_unset (&ag_value);
+ clear_setting_data (setting);
+}
+
static WatchData *
make_watch_data (McdAccountManagerSso *sso,
const gchar *mc_key)
@@ -473,7 +505,7 @@ static void _sso_toggled (GObject *object,
{
const gchar *service_type = ag_service_get_service_type (service);
- if (!g_str_equal (service_type, "IM"))
+ if (!g_str_equal (service_type, AG_SERVICE))
return;
}
@@ -660,7 +692,7 @@ static void
mcd_account_manager_sso_init (McdAccountManagerSso *self)
{
DEBUG ("mcd_account_manager_sso_init");
- self->ag_manager = ag_manager_new ();
+ self->ag_manager = ag_manager_new_for_service_type (AG_SERVICE);
self->accounts =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
self->id_name_map =
@@ -778,8 +810,6 @@ _ag_accountid_to_mc_key (const McdAccountManagerSso *sso,
if (proto == NULL)
goto cleanup;
- g_hash_table_insert (params, g_strdup (MC_ACCOUNT_KEY), &value);
-
/* prepare the hash of MC param keys -> GValue */
/* NOTE: some AG bare settings map to MC parameters, *
* so we must iterate over all AG settings, parameters *
@@ -824,6 +854,9 @@ _ag_accountid_to_mc_key (const McdAccountManagerSso *sso,
clear_setting_data (setting);
}
+ /* we want this to override any other settings for uid generation */
+ g_hash_table_insert (params, g_strdup (MC_ACCOUNT_KEY), &value);
+
name = mcp_account_manager_get_unique_name (am, cman, proto, params);
cleanup:
@@ -1063,6 +1096,9 @@ _get (const McpAccountStorage *self,
g_free (val);
}
+ if (g_str_equal (key, MCPP MC_ACCOUNT_KEY))
+ _maybe_set_account_param_from_service (am, account, acct);
+
g_value_unset (&v);
clear_setting_data (setting);
}
@@ -1124,6 +1160,8 @@ _get (const McpAccountStorage *self,
/* special case, actually two separate but related flags in SSO */
on = _sso_account_enabled (account, NULL) ? "true" : "false";
mcp_account_manager_set_value (am, acct, MC_ENABLED_KEY, on);
+
+ _maybe_set_account_param_from_service (am, account, acct);
}
/* leave the selected service as we found it */
@@ -1207,7 +1245,7 @@ _load_from_libaccounts (McdAccountManagerSso *sso,
const McpAccountManager *am)
{
GList *ag_id;
- GList *ag_ids = ag_manager_list_by_service_type (sso->ag_manager, "IM");
+ GList *ag_ids = ag_manager_list_by_service_type (sso->ag_manager, AG_SERVICE);
for (ag_id = ag_ids; ag_id != NULL; ag_id = g_list_next (ag_id))
{
@@ -1295,6 +1333,7 @@ _load_from_libaccounts (McdAccountManagerSso *sso,
mcp_account_manager_set_value (am, name, MC_CMANAGER_KEY, mc_id[0]);
mcp_account_manager_set_value (am, name, MC_PROTOCOL_KEY, mc_id[1]);
mcp_account_manager_set_value (am, name, MC_IDENTITY_KEY, name);
+ _maybe_set_account_param_from_service (am, account, name);
/* force the services value to be synthesised + cached */
_get (MCP_ACCOUNT_STORAGE (sso), am, name, SERVICES_KEY);
@@ -1333,7 +1372,7 @@ _list (const McpAccountStorage *self,
if (!sso->loaded)
_load_from_libaccounts (sso, am);
- ag_ids = ag_manager_list_by_service_type (sso->ag_manager, "IM");
+ ag_ids = ag_manager_list_by_service_type (sso->ag_manager, AG_SERVICE);
for (ag_id = ag_ids; ag_id != NULL; ag_id = g_list_next (ag_id))
{
@@ -1411,7 +1450,7 @@ _find_account (McdAccountManagerSso *sso,
g_return_val_if_fail (account_id != NULL, found);
- ag_ids = ag_manager_list_by_service_type (sso->ag_manager, "IM");
+ ag_ids = ag_manager_list_by_service_type (sso->ag_manager, AG_SERVICE);
for (ag_id = ag_ids; ag_id != NULL; ag_id = g_list_next (ag_id))
{
diff --git a/test/account-store-default.c b/test/account-store-default.c
index 0d11995..464aa98 100644
--- a/test/account-store-default.c
+++ b/test/account-store-default.c
@@ -277,3 +277,9 @@ default_exists (const gchar *account)
{
return g_key_file_has_group (default_keyfile (), account);
}
+
+GStrv
+default_list (void)
+{
+ return g_key_file_get_groups (default_keyfile (), NULL);
+}
diff --git a/test/account-store-default.h b/test/account-store-default.h
index 7e0256d..739f95c 100644
--- a/test/account-store-default.h
+++ b/test/account-store-default.h
@@ -23,6 +23,7 @@
#define _ACCOUNT_STORE_DEFAULT_H_
#include <glib.h>
+#include <glib-object.h>
gchar * default_get (const gchar *account,
const gchar *key);
@@ -35,4 +36,6 @@ gboolean default_delete (const gchar *account);
gboolean default_exists (const gchar *account);
+GStrv default_list (void);
+
#endif
diff --git a/test/account-store-libaccounts.c b/test/account-store-libaccounts.c
index 28dde96..11c2400 100644
--- a/test/account-store-libaccounts.c
+++ b/test/account-store-libaccounts.c
@@ -23,38 +23,141 @@
#include <libaccounts-glib/ag-manager.h>
#include <libaccounts-glib/ag-account.h>
#include <glib.h>
+#include "account-store-libaccounts.h"
-#define PARAM_PREFIX_MC "param-"
-#define PARAM_PREFIX "parameters/"
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "account-store-libaccounts"
+
+/* MC <-> AG global/local setting meta data */
+#define MCPP "param-"
+#define AGPP "parameters/"
#define LIBACCT_ID_KEY "libacct-uid"
-#define AG_ACCOUNT_KEY "username"
-#define MC_ACCOUNT_KEY "account"
-#define PASSWORD_KEY "password"
-#define ENABLED_KEY "Enabled"
+#define MC_ENABLED_KEY "Enabled"
+#define AG_ENABLED_KEY "enabled"
+
+#define AG_LABEL_KEY "name"
+#define MC_LABEL_KEY "DisplayName"
+
+#define AG_ACCOUNT_KEY "username"
+#define MC_ACCOUNT_KEY "account"
+#define PASSWORD_KEY "password"
+#define AG_ACCOUNT_ALT_KEY AGPP "account"
#define MC_CMANAGER_KEY "manager"
#define MC_PROTOCOL_KEY "protocol"
#define MC_IDENTITY_KEY "tmc-uid"
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "account-store-libaccounts"
+#define SERVICES_KEY "sso-services"
+
+#define MC_SERVICE_KEY "Service"
+
+typedef struct {
+ gchar *mc_name;
+ gchar *ag_name;
+ gboolean global; /* global ag setting or service specific? */
+ gboolean readable; /* does the _standard_ read method copy this into MC? */
+ gboolean writable; /* does the _standard_ write method copy this into AG? */
+ gboolean freeable; /* should clear_setting_data deallocate the names? */
+} Setting;
+
+#define GLOBAL TRUE
+#define SERVICE FALSE
+#define READABLE TRUE
+#define UNREADABLE FALSE
+#define WRITABLE TRUE
+#define UNWRITABLE FALSE
+
+typedef enum {
+ SETTING_MC,
+ SETTING_AG,
+} SettingType;
+
+Setting setting_map[] = {
+ { MC_ENABLED_KEY , AG_ENABLED_KEY , GLOBAL , UNREADABLE, UNWRITABLE },
+ { MCPP MC_ACCOUNT_KEY, AG_ACCOUNT_KEY , GLOBAL , READABLE , UNWRITABLE },
+ { MCPP PASSWORD_KEY , PASSWORD_KEY , GLOBAL , READABLE , WRITABLE },
+ { MC_LABEL_KEY , AG_LABEL_KEY , GLOBAL , READABLE , WRITABLE },
+ { LIBACCT_ID_KEY , LIBACCT_ID_KEY , GLOBAL , UNREADABLE, UNWRITABLE },
+ { MC_IDENTITY_KEY , MC_IDENTITY_KEY, SERVICE, READABLE , WRITABLE },
+ { MC_CMANAGER_KEY , MC_CMANAGER_KEY, SERVICE, READABLE , UNWRITABLE },
+ { MC_PROTOCOL_KEY , MC_PROTOCOL_KEY, SERVICE, READABLE , UNWRITABLE },
+ { MC_SERVICE_KEY , MC_SERVICE_KEY , SERVICE, UNREADABLE, UNWRITABLE },
+ { SERVICES_KEY , SERVICES_KEY , GLOBAL , UNREADABLE, UNWRITABLE },
+ { NULL , NULL , SERVICE, UNREADABLE, UNWRITABLE }
+};
+
+static void
+clear_setting_data (Setting *setting)
+{
+ if (setting == NULL)
+ return;
+
+ if (!setting->freeable)
+ return;
+
+ g_free (setting->mc_name);
+ g_free (setting->ag_name);
+ setting->mc_name = NULL;
+ setting->ag_name = NULL;
+}
+
+static Setting *
+setting_data (const gchar *name, SettingType type)
+{
+ guint i = 0;
+ static Setting parameter = { NULL, NULL, SERVICE, READABLE, WRITABLE, TRUE };
+ const gchar *prefix;
+
+ for (; setting_map[i].mc_name != NULL; i++)
+ {
+ const gchar *setting_name = NULL;
+
+ if (type == SETTING_MC)
+ setting_name = setting_map[i].mc_name;
+ else
+ setting_name = setting_map[i].ag_name;
+
+ if (g_strcmp0 (name, setting_name) == 0)
+ return &setting_map[i];
+ }
+
+ prefix = (type == SETTING_MC) ? MCPP : AGPP;
+
+ if (!g_str_has_prefix (name, prefix))
+ { /* a non-parameter setting */
+ parameter.mc_name = g_strdup (name);
+ parameter.ag_name = g_strdup (name);
+ }
+ else
+ { /* a setting that is a parameter on both sides (AG & MC) */
+ const guint plength = strlen (prefix);
+
+ parameter.mc_name = g_strdup_printf ("%s%s", MCPP, name + plength);
+ parameter.ag_name = g_strdup_printf ("%s%s", AGPP, name + plength);
+ }
+ return &parameter;
+}
+
+
+/* logging helpers: */
static void
_g_log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer unused_data)
{
- if (log_domain != G_LOG_DOMAIN)
+ /* the libaccounts code is currently very chatty when debugging: *
+ * we are only interested in or own debugging output for now. */
+ if ((gchar *)log_domain != (gchar *)G_LOG_DOMAIN)
return;
g_log_default_handler (log_domain, log_level, message, unused_data);
}
-/* libaccounts is incredibly chatty */
static void
-toggle_mute ()
+toggle_mute (void)
{
static GLogFunc old = NULL;
@@ -192,85 +295,122 @@ _ag_account_select_default_im_service (AgAccount *account)
return have_im_service;
}
-static gchar *
-mc_to_ag_key (const gchar *mc_key)
+/* enabled is actually a tri-state<->boolean mapping */
+static gboolean _sso_account_enabled (AgAccount *account, AgService *service)
{
- if (g_str_has_prefix (mc_key, PARAM_PREFIX_MC))
+ gboolean local = FALSE;
+ gboolean global = FALSE;
+ AgService *original = ag_account_get_selected_service (account);
+
+ if (service == NULL)
+ {
+ _ag_account_select_default_im_service (account);
+ local = ag_account_get_enabled (account);
+ }
+ else
{
- const gchar *pkey = mc_key + strlen (PARAM_PREFIX_MC);
+ if (original != service)
+ ag_account_select_service (account, service);
- if (g_str_equal (pkey, MC_ACCOUNT_KEY))
- return g_strdup (AG_ACCOUNT_KEY);
+ local = ag_account_get_enabled (account);
+ }
- if (g_str_equal (pkey, PASSWORD_KEY))
- return g_strdup (PASSWORD_KEY);
+ ag_account_select_service (account, NULL);
+ global = ag_account_get_enabled (account);
- return g_strdup_printf (PARAM_PREFIX "%s", pkey);
- }
+ ag_account_select_service (account, original);
- return g_strdup (mc_key);
+ g_debug ("_sso_account_enabled: global:%d && local:%d", global, local);
+
+ return local && global;
}
-static gchar *
-ag_to_mc_key (const gchar *ag_key)
+static void _sso_account_enable (AgAccount *account,
+ AgService *service,
+ gboolean on)
{
- /* these two are parameters in MC but not in AG */
- if (g_str_equal (ag_key, AG_ACCOUNT_KEY))
- return g_strdup (PARAM_PREFIX_MC MC_ACCOUNT_KEY);
+ AgService *original = ag_account_get_selected_service (account);
- if (g_str_equal (ag_key, PASSWORD_KEY))
- return g_strdup (PARAM_PREFIX_MC PASSWORD_KEY);
+ /* turn the local enabled flag on/off as required */
+ if (service != NULL)
+ ag_account_select_service (account, service);
+ else
+ _ag_account_select_default_im_service (account);
- /* now check for regular params */
- if (g_str_has_prefix (ag_key, PARAM_PREFIX))
- return
- g_strdup_printf (PARAM_PREFIX_MC "%s", ag_key + strlen (PARAM_PREFIX));
+ ag_account_set_enabled (account, on);
- return g_strdup (ag_key);
+ /* if we are turning the account on, the global flag must also be set *
+ * NOTE: this isn't needed when turning the account off */
+ if (on)
+ {
+ ag_account_select_service (account, NULL);
+ ag_account_set_enabled (account, on);
+ }
+
+ ag_account_select_service (account, original);
}
-static gboolean key_is_global (const char *ag_key)
+/* saving settings other than the enabled tri-state */
+static void
+save_setting (AgAccount *account,
+ const Setting *setting,
+ const gchar *val)
{
- /* parameters and MC_IDENTITY_KEY are service specific */
- if (g_str_has_prefix (ag_key, PARAM_PREFIX))
- return FALSE;
+ AgService *service = ag_account_get_selected_service (account);
+
+ if (!setting->writable)
+ return;
+
+ if (setting->global)
+ ag_account_select_service (account, NULL);
+ else if (service == NULL)
+ _ag_account_select_default_im_service (account);
+
+ if (val != NULL)
+ {
+ GValue value = { 0 };
- if (g_str_equal (ag_key, MC_IDENTITY_KEY))
- return FALSE;
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, val);
+ ag_account_set_value (account, setting->ag_name, &value);
+ g_value_unset (&value);
+ }
+ else
+ {
+ ag_account_set_value (account, setting->ag_name, NULL);
+ }
- /* anything else is global */
- return TRUE;
+ /* leave the selected service as we found it: */
+ ag_account_select_service (account, service);
}
gchar *
-libaccounts_get (const gchar *mc_account,
- const gchar *key)
+libaccounts_get (const gchar *mc_account, const gchar *key)
{
gchar *rval = NULL;
AgAccount *ag_account = get_ag_account (mc_account);
+ Setting *setting = setting_data (key, SETTING_MC);
toggle_mute ();
if (ag_account != NULL)
{
- gchar *ag_key = mc_to_ag_key (key);
- g_debug ("MC key %s -> AG key %s", key, ag_key);
-
- if (g_str_equal (ag_key, ENABLED_KEY))
+ if (setting == NULL)
{
- gboolean on = FALSE;
+ g_debug ("setting %s is unknown/unmapped, aborting update", key);
+ rval = g_strdup ("");
+ goto done;
+ }
- ag_account_select_service (ag_account, NULL);
- on = ag_account_get_enabled (ag_account);
+ g_debug ("MC key %s -> AG key %s", key, setting->ag_name);
- if (on)
- {
- _ag_account_select_default_im_service (ag_account);
- on = ag_account_get_enabled (ag_account);
- }
+ if (g_str_equal (setting->ag_name, AG_ENABLED_KEY))
+ {
+ gboolean on = _sso_account_enabled (ag_account, NULL);
- rval = on ? g_strdup ("true") : g_strdup ("false");
+ rval = g_strdup (on ? "true" : "false");
+ goto done;
}
else
{
@@ -279,26 +419,41 @@ libaccounts_get (const gchar *mc_account,
g_value_init (&value, G_TYPE_STRING);
- if (key_is_global (ag_key))
+ /* the 'account' parameter is a special case for historical reasons */
+ if (g_str_equal (key, MCPP MC_ACCOUNT_KEY))
+ {
+ _ag_account_select_default_im_service (ag_account);
+ source =
+ ag_account_get_value (ag_account, AG_ACCOUNT_ALT_KEY, &value);
+
+ if (source != AG_SETTING_SOURCE_NONE)
+ goto found;
+ }
+
+ if (setting->global)
ag_account_select_service (ag_account, NULL);
else
_ag_account_select_default_im_service (ag_account);
- source = ag_account_get_value (ag_account, ag_key, &value);
+ source = ag_account_get_value (ag_account, setting->ag_name, &value);
+ found:
if (source != AG_SETTING_SOURCE_NONE)
{
rval = _gvalue_to_string (&value);
g_value_unset (&value);
}
}
-
- g_free (ag_key);
- g_object_unref (ag_account);
}
+ done:
toggle_mute ();
+ if (ag_account)
+ g_object_unref (ag_account);
+
+ clear_setting_data (setting);
+
return rval;
}
@@ -309,45 +464,45 @@ libaccounts_set (const gchar *mc_account,
{
gboolean done = FALSE;
AgAccount *ag_account = get_ag_account (mc_account);
+ Setting *setting = setting_data (key, SETTING_MC);
toggle_mute ();
if (ag_account != NULL)
{
- gchar *ag_key = mc_to_ag_key (key);
+ if (setting == NULL)
+ {
+ g_debug ("setting %s is unknown/unmapped, aborting update", key);
+ goto done;
+ }
- if (g_str_equal (ag_key, ENABLED_KEY))
+ if (g_str_equal (setting->ag_name, MC_ENABLED_KEY))
{
gboolean on = g_str_equal (value, "true");
- ag_account_select_service (ag_account, NULL);
- ag_account_set_enabled (ag_account, on);
- _ag_account_select_default_im_service (ag_account);
- ag_account_set_enabled (ag_account, on);
-
+ _sso_account_enable (ag_account, NULL, on);
done = TRUE;
+ goto done;
}
else
{
- GValue val = { 0 };
-
- g_value_init (&val, G_TYPE_STRING);
- g_value_set_string (&val, value);
- ag_account_set_value (ag_account, ag_key, &val);
- g_value_unset (&val);
-
+ save_setting (ag_account, setting, value);
done = TRUE;
}
if (done)
ag_account_store (ag_account, NULL, NULL);
- g_free (ag_key);
- g_object_unref (ag_account);
}
+ done:
toggle_mute ();
+ if (ag_account)
+ g_object_unref (ag_account);
+
+ clear_setting_data (setting);
+
return done;
}
@@ -390,3 +545,83 @@ libaccounts_exists (const gchar *mc_account)
return exists;
}
+
+GStrv
+libaccounts_list (void)
+{
+ AgManager *ag_manager = get_ag_manager ();
+ GList *ag_ids = ag_manager_list_by_service_type (ag_manager, "IM");
+ guint len = g_list_length (ag_ids);
+ GStrv rval = NULL;
+ GList *id;
+ guint i = 0;
+ Setting *setting = setting_data (MC_IDENTITY_KEY, SETTING_AG);
+
+ if (len == 0)
+ goto done;
+
+ rval = g_new (gchar *, len + 1);
+ rval[len] = NULL;
+
+ for (id = ag_ids; id && i < len; id = g_list_next (id))
+ {
+ GValue value = { 0 };
+ AgAccountId uid = GPOINTER_TO_UINT (id->data);
+ AgAccount *ag_account = ag_manager_get_account (ag_manager, uid);
+ AgSettingSource source = AG_SETTING_SOURCE_NONE;
+
+ if (ag_account)
+ {
+ if (setting->global)
+ ag_account_select_service (ag_account, NULL);
+ else
+ _ag_account_select_default_im_service (ag_account);
+
+ source = ag_account_get_value (ag_account, setting->ag_name, &value);
+ }
+
+ if (source != AG_SETTING_SOURCE_NONE)
+ {
+ rval[i++] = _gvalue_to_string (&value);
+ g_value_unset (&value);
+ }
+ else
+ {
+ GValue cmanager = { 0 };
+ GValue protocol = { 0 };
+ GValue account = { 0 };
+ const gchar *acct = NULL;
+ const gchar *cman = NULL;
+ const gchar *proto = NULL;
+
+ g_value_init (&cmanager, G_TYPE_STRING);
+ g_value_init (&protocol, G_TYPE_STRING);
+ g_value_init (&account, G_TYPE_STRING);
+
+ _ag_account_select_default_im_service (ag_account);
+
+ ag_account_get_value (ag_account, MC_CMANAGER_KEY, &cmanager);
+ cman = g_value_get_string (&cmanager);
+
+ ag_account_get_value (ag_account, MC_PROTOCOL_KEY, &protocol);
+ proto = g_value_get_string (&protocol);
+
+ ag_account_select_service (ag_account, NULL);
+ ag_account_get_value (ag_account, AG_ACCOUNT_KEY, &account);
+ acct = g_value_get_string (&account);
+
+ rval[i++] = g_strdup_printf ("unnamed account #%u (%s/%s/%s)",
+ uid, cman, proto, acct);
+
+ g_value_unset (&cmanager);
+ g_value_unset (&protocol);
+ g_value_unset (&account);
+ }
+ }
+
+ done:
+ g_list_free (ag_ids);
+ clear_setting_data (setting);
+
+ return rval;
+}
diff --git a/test/account-store-libaccounts.h b/test/account-store-libaccounts.h
index c580cd3..cb2352b 100644
--- a/test/account-store-libaccounts.h
+++ b/test/account-store-libaccounts.h
@@ -33,4 +33,6 @@ gboolean libaccounts_delete (const gchar *mc_account);
gboolean libaccounts_exists (const gchar *mc_account);
+GStrv libaccounts_list (void);
+
#endif
diff --git a/test/account-store.c b/test/account-store.c
index a601386..5483527 100644
--- a/test/account-store.c
+++ b/test/account-store.c
@@ -30,8 +30,8 @@
#include "account-store-default.h"
#define DOCSTRING_A \
- "%s OP BACKEND ACCOUNT [KEY [VALUE]]\n\n" \
- " OP := <get | set | del | has>\n" \
+ "%s OP BACKEND ACCOUNT [KEY [VALUE]]\n\n" \
+ " OP := <get | set | del | has | list>\n" \
" BACKEND := <"
#define DOCSTRING_B \
@@ -50,6 +50,7 @@ typedef struct {
gboolean (*set) (const gchar *account, const gchar *key, const gchar *value);
gboolean (*delete) (const gchar *account);
gboolean (*exists) (const gchar *account);
+ GStrv (*list) (void);
} Backend;
typedef enum {
@@ -58,6 +59,7 @@ typedef enum {
OP_SET,
OP_DELETE,
OP_EXISTS,
+ OP_LIST,
} Operation;
const Backend backends[] = {
@@ -65,14 +67,16 @@ const Backend backends[] = {
default_get,
default_set,
default_delete,
- default_exists },
+ default_exists,
+ default_list, },
#if ENABLE_LIBACCOUNTS_SSO
{ "libaccounts",
libaccounts_get,
libaccounts_set,
libaccounts_delete,
- libaccounts_exists },
+ libaccounts_exists,
+ libaccounts_list, },
#endif
{ NULL }
@@ -158,6 +162,8 @@ int main (int argc, char **argv)
op = OP_DELETE;
else if (g_str_equal (op_name, "has"))
op = OP_EXISTS;
+ else if (g_str_equal (op_name, "list"))
+ op = OP_LIST;
switch (op)
{
@@ -191,6 +197,11 @@ int main (int argc, char **argv)
account = argv[3];
break;
+ case OP_LIST:
+ if (argc < 3)
+ usage (argv[0], "op '%s' requires an backend", op_name);
+ break;
+
case OP_UNKNOWN:
usage (argv[0], "Unknown operation: %s", op_name);
}
@@ -198,6 +209,8 @@ int main (int argc, char **argv)
/* if we got this far, we have all the args we need: */
switch (op)
{
+ GStrv list;
+
case OP_GET:
output = store->get (account, setting);
success = output != NULL;
@@ -220,9 +233,14 @@ int main (int argc, char **argv)
output = g_strdup_printf ("Exists in %s", store->name);
break;
- case OP_UNKNOWN:
- /* if this is the case then we already exited */
- g_assert_not_reached ();
+ case OP_LIST:
+ list = store->list ();
+ output = g_strjoinv ("\n", list);
+ g_strfreev (list);
+ break;
+
+ default:
+ output = g_strdup ("Unknown operation");
}
if (output != NULL)