From 8dff2a3bb6831ff8aafc882130922b04331976c3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 29 Oct 2013 11:57:55 +0000 Subject: [PATCH 04/12] Rename default account-store backend from default to keyfile If we're going to change the default, leaving it called 'default' makes little sense! --- tests/Makefile.am | 4 +- tests/account-store-default.c | 122 --------------------- tests/account-store-default.h | 41 ------- tests/account-store-keyfile.c | 122 +++++++++++++++++++++ tests/account-store-keyfile.h | 41 +++++++ tests/account-store.c | 14 +-- .../account-storage/default-keyring-storage.py | 5 +- 7 files changed, 174 insertions(+), 175 deletions(-) delete mode 100644 tests/account-store-default.c delete mode 100644 tests/account-store-default.h create mode 100644 tests/account-store-keyfile.c create mode 100644 tests/account-store-keyfile.h diff --git a/tests/Makefile.am b/tests/Makefile.am index c6166fb..d349d7d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -37,8 +37,8 @@ tease_the_minotaur_LDADD = $(top_builddir)/src/libmcd-convenience.la account_store_LDADD = $(GLIB_LIBS) account_store_SOURCES = \ account-store.c \ - account-store-default.c \ - account-store-default.h + account-store-keyfile.c \ + account-store-keyfile.h if ENABLE_LIBACCOUNTS_SSO account_store_SOURCES += account-store-libaccounts.c account-store-libaccounts.h diff --git a/tests/account-store-default.c b/tests/account-store-default.c deleted file mode 100644 index 7f4c8c3..0000000 --- a/tests/account-store-default.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * MC account storage backend inspector, default backend - * - * 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 -#include - -#include "account-store-default.h" - -static const gchar *default_config (void) -{ - return g_build_filename (g_get_user_data_dir (), "telepathy", - "mission-control", "accounts.cfg", NULL); -} - -static GKeyFile * default_keyfile (void) -{ - GError *error = NULL; - static GKeyFile *keyfile = NULL; - const gchar *path = NULL; - - if (keyfile != NULL) - return keyfile; - - path = default_config (); - - keyfile = g_key_file_new (); - - if (!g_key_file_load_from_file (keyfile, path, 0, &error)) - { - if (error != NULL) - g_warning ("keyfile '%s' error: %s", path, error->message); - else - g_warning ("keyfile '%s' error: unknown error", path); - - g_key_file_free (keyfile); - g_error_free (error); - keyfile = NULL; - } - - return keyfile; -} - -static gboolean commit_changes (void) -{ - gsize n = 0; - gchar *data = NULL; - gboolean done = FALSE; - GKeyFile *keyfile = default_keyfile (); - const gchar *config = default_config (); - - data = g_key_file_to_data (keyfile, &n, NULL); - done = g_file_set_contents (config, data, n, NULL); - - g_free (data); - - return done; -} - -gchar * -default_get (const gchar *account, - const gchar *key) -{ - return g_key_file_get_string (default_keyfile (), account, key, NULL); -} - -gboolean -default_set (const gchar *account, - const gchar *key, - const gchar *value) -{ - GKeyFile *keyfile = NULL; - - keyfile = default_keyfile (); - - if (keyfile == NULL) - return FALSE; - - g_key_file_set_string (keyfile, account, key, value); - - return commit_changes (); -} - -gboolean -default_delete (const gchar *account) -{ - GKeyFile *keyfile = default_keyfile (); - - g_key_file_remove_group (keyfile, account, NULL); - - return commit_changes (); -} - -gboolean -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/tests/account-store-default.h b/tests/account-store-default.h deleted file mode 100644 index 739f95c..0000000 --- a/tests/account-store-default.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * MC account storage backend inspector, default backend - * - * 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 _ACCOUNT_STORE_DEFAULT_H_ -#define _ACCOUNT_STORE_DEFAULT_H_ - -#include -#include - -gchar * default_get (const gchar *account, - const gchar *key); - -gboolean default_set (const gchar *account, - const gchar *key, - const gchar *value); - -gboolean default_delete (const gchar *account); - -gboolean default_exists (const gchar *account); - -GStrv default_list (void); - -#endif diff --git a/tests/account-store-keyfile.c b/tests/account-store-keyfile.c new file mode 100644 index 0000000..efa96b0 --- /dev/null +++ b/tests/account-store-keyfile.c @@ -0,0 +1,122 @@ +/* + * MC account storage inspector: MC 5.0-compatible single keyfile backend + * + * 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 +#include + +#include "account-store-keyfile.h" + +static const gchar *default_config (void) +{ + return g_build_filename (g_get_user_data_dir (), "telepathy", + "mission-control", "accounts.cfg", NULL); +} + +static GKeyFile * default_keyfile (void) +{ + GError *error = NULL; + static GKeyFile *keyfile = NULL; + const gchar *path = NULL; + + if (keyfile != NULL) + return keyfile; + + path = default_config (); + + keyfile = g_key_file_new (); + + if (!g_key_file_load_from_file (keyfile, path, 0, &error)) + { + if (error != NULL) + g_warning ("keyfile '%s' error: %s", path, error->message); + else + g_warning ("keyfile '%s' error: unknown error", path); + + g_key_file_free (keyfile); + g_error_free (error); + keyfile = NULL; + } + + return keyfile; +} + +static gboolean commit_changes (void) +{ + gsize n = 0; + gchar *data = NULL; + gboolean done = FALSE; + GKeyFile *keyfile = default_keyfile (); + const gchar *config = default_config (); + + data = g_key_file_to_data (keyfile, &n, NULL); + done = g_file_set_contents (config, data, n, NULL); + + g_free (data); + + return done; +} + +gchar * +keyfile_get (const gchar *account, + const gchar *key) +{ + return g_key_file_get_string (default_keyfile (), account, key, NULL); +} + +gboolean +keyfile_set (const gchar *account, + const gchar *key, + const gchar *value) +{ + GKeyFile *keyfile = NULL; + + keyfile = default_keyfile (); + + if (keyfile == NULL) + return FALSE; + + g_key_file_set_string (keyfile, account, key, value); + + return commit_changes (); +} + +gboolean +keyfile_delete (const gchar *account) +{ + GKeyFile *keyfile = default_keyfile (); + + g_key_file_remove_group (keyfile, account, NULL); + + return commit_changes (); +} + +gboolean +keyfile_exists (const gchar *account) +{ + return g_key_file_has_group (default_keyfile (), account); +} + +GStrv +keyfile_list (void) +{ + return g_key_file_get_groups (default_keyfile (), NULL); +} diff --git a/tests/account-store-keyfile.h b/tests/account-store-keyfile.h new file mode 100644 index 0000000..a6ce217 --- /dev/null +++ b/tests/account-store-keyfile.h @@ -0,0 +1,41 @@ +/* + * MC account storage inspector: MC 5.0-compatible single keyfile backend + * + * 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 _ACCOUNT_STORE_KEYFILE_H_ +#define _ACCOUNT_STORE_KEYFILE_H_ + +#include +#include + +gchar * keyfile_get (const gchar *account, + const gchar *key); + +gboolean keyfile_set (const gchar *account, + const gchar *key, + const gchar *value); + +gboolean keyfile_delete (const gchar *account); + +gboolean keyfile_exists (const gchar *account); + +GStrv keyfile_list (void); + +#endif diff --git a/tests/account-store.c b/tests/account-store.c index 4482ea5..15e43ea 100644 --- a/tests/account-store.c +++ b/tests/account-store.c @@ -27,7 +27,7 @@ #include #include -#include "account-store-default.h" +#include "account-store-keyfile.h" #define DOCSTRING_A \ "%s OP BACKEND ACCOUNT [KEY [VALUE]]\n\n" \ @@ -63,12 +63,12 @@ typedef enum { } Operation; const Backend backends[] = { - { "default", - default_get, - default_set, - default_delete, - default_exists, - default_list }, + { "keyfile", + keyfile_get, + keyfile_set, + keyfile_delete, + keyfile_exists, + keyfile_list }, #if ENABLE_LIBACCOUNTS_SSO { "libaccounts", diff --git a/tests/twisted/account-storage/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py index a785718..74f3bd3 100644 --- a/tests/twisted/account-storage/default-keyring-storage.py +++ b/tests/twisted/account-storage/default-keyring-storage.py @@ -109,8 +109,7 @@ def test(q, bus, mc): assert kf[group]['Icon'] == 'im-jabber', kf assert kf[group]['Nickname'] == 'Joe Bloggs', kf - # This works wherever the password is stored - pwd = account_store('get', 'default', 'param-password') + pwd = account_store('get', 'keyfile', 'param-password') assert pwd == params['password'], pwd # We no longer use gnome-keyring, so the password is stored as clear-text. @@ -192,7 +191,7 @@ AutomaticPresence=2;available;; assert os.path.exists(low_prio_key_file_name) kf = keyfile_read(new_key_file_name) assert 'param-password' not in kf[group] - pwd = account_store('get', 'default', 'param-password') + pwd = account_store('get', 'keyfile', 'param-password') assertEquals(None, pwd) # Write out an account configuration in the old keyfile, to test -- 1.8.4.rc3