From 5d3c3298061a8cfbef2dff5703fba1c97829afa2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 11 Oct 2013 12:25:56 +0100 Subject: [PATCH 4/4] Remove Conditions interface I was never sure about the design, and the supporting code was removed when I refactored connectivity for 5.16. If it's needed in future, we can bring it back, hopefully with a simpler design. --- src/Makefile.am | 5 - src/mcd-account-conditions.c | 160 --------------------- src/mcd-account-conditions.h | 34 ----- src/mcd-account-config.h | 2 +- src/mcd-account-manager.c | 1 - src/mcd-account-priv.h | 6 - src/mcd-account.c | 4 - src/mcd-master.c | 1 - src/mcd-storage.c | 4 - src/mcd.xml | 1 - tests/twisted/account-manager/account-basics.py | 37 ----- .../account-manager/create-with-properties.py | 8 -- tests/twisted/constants.py | 1 - xml/Account_Interface_Conditions.xml | 99 ------------- xml/Makefile.am | 1 - xml/nmc5.xml | 1 - 16 files changed, 1 insertion(+), 364 deletions(-) delete mode 100644 src/mcd-account-conditions.c delete mode 100644 src/mcd-account-conditions.h delete mode 100644 xml/Account_Interface_Conditions.xml diff --git a/src/Makefile.am b/src/Makefile.am index e00e033..315e0ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,6 @@ AM_CFLAGS = $(ERROR_CFLAGS) mc_headers = \ mcd-account.h \ - mcd-account-conditions.h \ mcd-account-manager.h \ mcd-account-manager-default.h \ mcd-debug.h \ @@ -46,7 +45,6 @@ mc_gen_headers = \ _gen/enums.h \ _gen/gtypes.h \ _gen/interfaces.h \ - _gen/svc-Account_Interface_Conditions.h \ _gen/svc-Account_Interface_External_Password_Storage.h \ _gen/svc-Account_Interface_Hidden.h \ _gen/svc-Account_Manager_Interface_Hidden.h \ @@ -60,7 +58,6 @@ nodist_libmcd_convenience_la_SOURCES = \ _gen/signals-marshal.c \ _gen/signals-marshal.h \ _gen/signals-marshal.list \ - _gen/svc-Account_Interface_Conditions.c \ _gen/svc-Account_Interface_External_Password_Storage.c \ _gen/svc-Account_Interface_Hidden.c \ _gen/svc-Account_Manager_Interface_Hidden.c \ @@ -78,7 +75,6 @@ CLEANFILES = \ _gen/cli-Connection_Manager_Interface_Account_Storage-gtk-doc.h \ _gen/svc-Account_Interface_Hidden-gtk-doc.h \ _gen/svc-Account_Interface_External_Password_Storage-gtk-doc.h \ - _gen/svc-Account_Interface_Conditions-gtk-doc.h \ _gen/svc-Account_Manager_Interface_Hidden-gtk-doc.h \ _gen/gtypes-gtk-doc.h \ $(NULL) @@ -107,7 +103,6 @@ noinst_LTLIBRARIES = libmcd-convenience.la libmcd_convenience_la_SOURCES = \ mcd-account.c \ mcd-account-addressing.h \ - mcd-account-conditions.c \ mcd-account-config.h \ mcd-account-connection.c \ mcd-account-requests.c \ diff --git a/src/mcd-account-conditions.c b/src/mcd-account-conditions.c deleted file mode 100644 index e40dccf..0000000 --- a/src/mcd-account-conditions.c +++ /dev/null @@ -1,160 +0,0 @@ -/* vi: set et sw=4 ts=8 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ -/* - * This file is part of mission-control - * - * Copyright (C) 2008-2009 Nokia Corporation. - * Copyright (C) 2009 Collabora Ltd. - * - * Contact: Alberto Mardegan - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * 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 - -#include -#include - -#include "mcd-account.h" -#include "mcd-account-priv.h" -#include "mcd-account-conditions.h" -#include "mcd-account-manager.h" - - -static void -store_condition (gpointer key, gpointer value, gpointer userdata) -{ - McdAccount *account = MCD_ACCOUNT (userdata); - McdStorage *storage = _mcd_account_get_storage (account); - const gchar *account_name = mcd_account_get_unique_name (account); - const gchar *name = key, *condition = value; - gchar condition_key[256]; - - g_snprintf (condition_key, sizeof (condition_key), "condition-%s", name); - mcd_storage_set_string (storage, account_name, condition_key, condition); -} - -static gboolean -set_condition (TpSvcDBusProperties *self, - const gchar *name, - const GValue *value, - McdDBusPropSetFlags flags, - GError **error) -{ - McdAccount *account = MCD_ACCOUNT (self); - McdStorage *storage = _mcd_account_get_storage (account); - const gchar *account_name = mcd_account_get_unique_name (account); - gchar **keys, **key; - GHashTable *conditions; - - /* FIXME: some sort of validation beyond just the type? */ - - if (!G_VALUE_HOLDS (value, TP_HASH_TYPE_STRING_STRING_MAP)) - { - g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Expected a{s:s} for Condition, but got %s", - G_VALUE_TYPE_NAME (value)); - return FALSE; - } - - if (_mcd_account_get_always_on (account)) - { - g_set_error (error, TP_ERROR, TP_ERROR_PERMISSION_DENIED, - "Account %s conditions cannot be changed", - mcd_account_get_unique_name (account)); - return FALSE; - } - - conditions = g_value_get_boxed (value); - - /* first, delete existing conditions */ - keys = mcd_storage_dup_attributes (storage, account_name, NULL); - - for (key = keys; *key != NULL; key++) - { - if (strncmp (*key, "condition-", 10) != 0) - continue; - - mcd_storage_set_attribute (storage, account_name, *key, NULL); - } - - g_strfreev (keys); - - if (!(flags & MCD_DBUS_PROP_SET_FLAG_ALREADY_IN_STORAGE)) - { - g_hash_table_foreach (conditions, store_condition, account); - - mcd_storage_commit (storage, account_name); - } - - return TRUE; -} - -static void -get_condition (TpSvcDBusProperties *self, const gchar *name, GValue *value) -{ - GHashTable *conditions; - - conditions = mcd_account_get_conditions (MCD_ACCOUNT (self)); - - g_value_init (value, DBUS_TYPE_G_STRING_STRING_HASHTABLE); - g_value_take_boxed (value, conditions); -} - - -const McdDBusProp account_conditions_properties[] = { - { "Condition", set_condition, get_condition }, - { 0 }, -}; - -void -account_conditions_iface_init (McSvcAccountInterfaceConditionsClass *iface, - gpointer iface_data) -{ -} - -GHashTable *mcd_account_get_conditions (McdAccount *account) -{ - gchar **keys, **key, *condition; - GHashTable *conditions; - McdStorage *storage = _mcd_account_get_storage (account); - const gchar *account_name = mcd_account_get_unique_name (account); - - conditions = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, g_free); - - keys = mcd_storage_dup_attributes (storage, account_name, NULL); - - for (key = keys; *key != NULL; key++) - { - if (strncmp (*key, "condition-", 10) != 0) - continue; - - condition = mcd_storage_dup_string (storage, account_name, *key); - DEBUG ("Condition: %s = %s", *key, condition); - g_hash_table_insert (conditions, g_strdup (*key + 10), condition); - } - - g_strfreev (keys); - - return conditions; -} - diff --git a/src/mcd-account-conditions.h b/src/mcd-account-conditions.h deleted file mode 100644 index cd8f75b..0000000 --- a/src/mcd-account-conditions.h +++ /dev/null @@ -1,34 +0,0 @@ -/* vi: set et sw=4 ts=8 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ -/* - * mcd-account.h - the Telepathy Account D-Bus interface (service side) - * - * Copyright (C) 2008 Collabora Ltd. - * Copyright (C) 2008 Nokia Corporation - * - * 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_ACCOUNT_CONDITIONS_H__ -#define __MCD_ACCOUNT_CONDITIONS_H__ - -#include "mcd-account.h" - -G_BEGIN_DECLS - -GHashTable *mcd_account_get_conditions (McdAccount *account); - -G_END_DECLS -#endif diff --git a/src/mcd-account-config.h b/src/mcd-account-config.h index fc7a9ea..c692e0e 100644 --- a/src/mcd-account-config.h +++ b/src/mcd-account-config.h @@ -46,7 +46,6 @@ #define MC_ACCOUNTS_KEY_ICON "Icon" #define MC_ACCOUNTS_KEY_NICKNAME "Nickname" #define MC_ACCOUNTS_KEY_SERVICE "Service" -/* ... also "condition-*" reserved by mcd-account-conditions.c */ /* unsigned 32-bit integer, 'u' */ /* obsoleted by MC_ACCOUNTS_KEY_AUTOMATIC_PRESENCE */ @@ -78,5 +77,6 @@ #define MC_OLD_ACCOUNTS_KEY_PRESETS "presets" #define MC_OLD_ACCOUNTS_KEY_PROFILE "profile" #define MC_OLD_ACCOUNTS_KEY_SECONDARY_VCARD_FIELDS "secondary_vcard_fields" +/* ... also "condition-*" formerly reserved by Nokia Conditions interface */ #endif /* __MCD_ACCOUNT_CONFIG_H__ */ diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 66cc851..dc9ff20 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -1004,7 +1004,6 @@ get_supported_account_properties (TpSvcDBusProperties *svc, TP_IFACE_ACCOUNT ".Supersedes", TP_PROP_ACCOUNT_SERVICE, TP_IFACE_ACCOUNT_INTERFACE_AVATAR ".Avatar", - MC_IFACE_ACCOUNT_INTERFACE_CONDITIONS ".Condition", TP_PROP_ACCOUNT_INTERFACE_STORAGE_STORAGE_PROVIDER, MC_IFACE_ACCOUNT_INTERFACE_HIDDEN ".Hidden", NULL diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h index 7225d3e..f2f386e 100644 --- a/src/mcd-account-priv.h +++ b/src/mcd-account-priv.h @@ -36,7 +36,6 @@ #include /* auto-generated stubs */ -#include "_gen/svc-Account_Interface_Conditions.h" #include "_gen/svc-Account_Interface_External_Password_Storage.h" #include "_gen/svc-Account_Interface_Hidden.h" @@ -150,11 +149,6 @@ typedef void (*McdAccountDupParametersCb) (McdAccount *account, G_GNUC_INTERNAL G_GNUC_WARN_UNUSED_RESULT GHashTable *_mcd_account_dup_parameters (McdAccount *account); -extern const McdDBusProp account_conditions_properties[]; - -void account_conditions_iface_init (McSvcAccountInterfaceConditionsClass *iface, - gpointer iface_data); - G_GNUC_INTERNAL gboolean _mcd_account_check_request_real (McdAccount *account, GHashTable *request, GError **error); diff --git a/src/mcd-account.c b/src/mcd-account.c index f9e874e..1eac421 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -34,7 +34,6 @@ #include #include "mcd-account-priv.h" -#include "mcd-account-conditions.h" #include "mcd-account-manager-priv.h" #include "mcd-account-addressing.h" #include "mcd-connection-priv.h" @@ -81,9 +80,6 @@ static const McdInterfaceData account_interfaces[] = { MCD_IMPLEMENT_IFACE (tp_svc_account_interface_avatar_get_type, account_avatar, TP_IFACE_ACCOUNT_INTERFACE_AVATAR), - MCD_IMPLEMENT_IFACE (mc_svc_account_interface_conditions_get_type, - account_conditions, - MC_IFACE_ACCOUNT_INTERFACE_CONDITIONS), MCD_IMPLEMENT_IFACE (tp_svc_account_interface_storage_get_type, account_storage, TP_IFACE_ACCOUNT_INTERFACE_STORAGE), diff --git a/src/mcd-master.c b/src/mcd-master.c index 37c127b..d4b53cf 100644 --- a/src/mcd-master.c +++ b/src/mcd-master.c @@ -71,7 +71,6 @@ #include "mcd-dispatcher.h" #include "mcd-account-manager.h" #include "mcd-account-manager-priv.h" -#include "mcd-account-conditions.h" #include "mcd-account-priv.h" #include "plugin-loader.h" diff --git a/src/mcd-storage.c b/src/mcd-storage.c index 6522e7b..4fab25d 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -347,10 +347,6 @@ mcd_storage_get_attribute_type (const gchar *attribute) return known_attributes[i].type; } - /* special case for mcd-account-conditions.c */ - if (g_str_has_prefix (attribute, "condition-")) - return "s"; - return NULL; } diff --git a/src/mcd.xml b/src/mcd.xml index b4bb2de..79fdc9b 100644 --- a/src/mcd.xml +++ b/src/mcd.xml @@ -6,7 +6,6 @@ - diff --git a/tests/twisted/account-manager/account-basics.py b/tests/twisted/account-manager/account-basics.py index 18b35cb..cff3a3f 100644 --- a/tests/twisted/account-manager/account-basics.py +++ b/tests/twisted/account-manager/account-basics.py @@ -83,7 +83,6 @@ def test(q, bus, mc): interfaces = properties.get('Interfaces') assert cs.ACCOUNT_IFACE_AVATAR in interfaces, interfaces - assert cs.ACCOUNT_IFACE_NOKIA_CONDITIONS in interfaces, interfaces # sanity check for k in properties: @@ -174,32 +173,6 @@ def test(q, bus, mc): ) assert account_props.Get(cs.ACCOUNT, 'Nickname') == 'Joe Bloggs' - call_async(q, account_props, 'Set', cs.ACCOUNT_IFACE_NOKIA_CONDITIONS, - 'Condition', - dbus.Dictionary({':foo': 'bar'}, signature='ss')) - # there's no change notification for the Condition - q.expect_many( - EventPattern('dbus-return', method='Set'), - EventPattern('dbus-signal', - interface=cs.TEST_DBUS_ACCOUNT_PLUGIN_IFACE, - signal='DeferringSetAttribute', - args=[account_path, 'condition-:foo', 'bar']), - EventPattern('dbus-signal', - interface=cs.TEST_DBUS_ACCOUNT_PLUGIN_IFACE, - signal='CommittingOne', - args=[account_path]), - EventPattern('dbus-method-call', - interface=cs.TEST_DBUS_ACCOUNT_SERVICE_IFACE, - method='UpdateAttributes', - args=[account_path[len(cs.ACCOUNT_PATH_PREFIX):], - {'condition-:foo': 'bar'}, - {'condition-:foo': 0}, # flags - []], - ), - ) - assert account_props.Get(cs.ACCOUNT_IFACE_NOKIA_CONDITIONS, - 'Condition') == {':foo': 'bar'} - assertEquals(dbus.Array(signature='o'), account_props.Get(cs.ACCOUNT, 'Supersedes')) call_async(q, account_props, 'Set', cs.ACCOUNT, 'Supersedes', @@ -271,16 +244,6 @@ def test(q, bus, mc): else: raise AssertionError('Setting %s with wrong type should fail' % p) - for p in ('Condition',): - try: - account_props.Set(cs.ACCOUNT_IFACE_NOKIA_CONDITIONS, p, - badly_typed) - except dbus.DBusException, e: - assert e.get_dbus_name() == cs.INVALID_ARGUMENT, \ - (p, e.get_dbus_name()) - else: - raise AssertionError('Setting %s with wrong type should fail' % p) - # Make sure MC hasn't crashed yet, and make sure some properties are what # we expect them to be diff --git a/tests/twisted/account-manager/create-with-properties.py b/tests/twisted/account-manager/create-with-properties.py index 6da44aa..128ac94 100644 --- a/tests/twisted/account-manager/create-with-properties.py +++ b/tests/twisted/account-manager/create-with-properties.py @@ -45,7 +45,6 @@ def test(q, bus, mc): assert (cs.ACCOUNT + '.Nickname') in supported assert (cs.ACCOUNT + '.ConnectAutomatically') in supported assert (cs.ACCOUNT_IFACE_AVATAR + '.Avatar') in supported - assert (cs.ACCOUNT_IFACE_NOKIA_CONDITIONS + '.Condition') in supported assert (cs.ACCOUNT + '.RequestedPresence') in supported assert (cs.ACCOUNT + '.Supersedes') in supported @@ -70,8 +69,6 @@ def test(q, bus, mc): cs.ACCOUNT + '.ConnectAutomatically': True, cs.ACCOUNT_IFACE_AVATAR + '.Avatar': (dbus.ByteArray('foo'), 'image/jpeg'), - cs.ACCOUNT_IFACE_NOKIA_CONDITIONS + '.Condition': - dbus.Dictionary({ 'has-quad-damage': ':y' }, signature='ss'), cs.ACCOUNT + '.Supersedes': dbus.Array([ cs.ACCOUNT_PATH_PREFIX + 'q1/q1/Ranger', cs.ACCOUNT_PATH_PREFIX + 'q2/q2/Grunt', @@ -135,11 +132,6 @@ def test(q, bus, mc): assert properties.get('Avatar') == ([ord('f'), ord('o'), ord('o')], 'image/jpeg') - properties = account_props.GetAll(cs.ACCOUNT_IFACE_NOKIA_CONDITIONS) - assert properties.get('Condition') == { - 'has-quad-damage': ':y', - } - # tests for errors when creating an account creation_properties2 = creation_properties.copy() diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py index 68c458a..0c7bc57 100644 --- a/tests/twisted/constants.py +++ b/tests/twisted/constants.py @@ -592,7 +592,6 @@ ACCOUNT = PREFIX + '.Account' ACCOUNT_IFACE_AVATAR = ACCOUNT + '.Interface.Avatar' ACCOUNT_IFACE_ADDRESSING = ACCOUNT + '.Interface.Addressing' ACCOUNT_IFACE_HIDDEN = ACCOUNT + '.Interface.Hidden.DRAFT1' -ACCOUNT_IFACE_NOKIA_CONDITIONS = 'com.nokia.Account.Interface.Conditions' ACCOUNT_PATH_PREFIX = PATH_PREFIX + '/Account/' AM = PREFIX + '.AccountManager' diff --git a/xml/Account_Interface_Conditions.xml b/xml/Account_Interface_Conditions.xml deleted file mode 100644 index eb38482..0000000 --- a/xml/Account_Interface_Conditions.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - Copyright (C) 2008 Nokia Corporation - -

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 Street, Fifth Floor, Boston, MA 02110-1301, USA.

-
- - - -

The Conditions interface specifies under what conditions an account - can be put online. When the conditions are met and the - ConnectAutomatically property on the account is set to True, then the - account will automatically try to connect. On the other hand, if the - conditions are not met, the account won't attempt to connect, not even if - requested so.

- - -

The main goal is to bind accounts to connectivity: most TCP and UDP - based protocols require a network route to be present, while link-local - does not; some protocol might be specifically designed to work only over - bluetooth, in which case we don't want to attempt a connection if - bluetooth is not available. Then, some accounts might work only in certain - VPNs.

- -

There is also the case of user preferences: one might want to activate - a certain account only when he is at home (in that case, he could set a - rule on the network ESSID) or when he is not at work (this requires the - possibility of negating rules).

- -

The proposed format of a rule is (name, value), where name is a string - (which is typically a connectivity parameter, such as "ip-address", - "vpn-name", "essid", maybe prefixed with some namespacing convention) - and value is the value the parameter must assume for the rule to be met. - The value, it will be specified as a string, but we want to be - able to specify multiple alternatives (for instance a rule might be - "connect if ESSID is HOME or WORK"), as well as negative matches. The - proposed syntax is simple yet expressive enough.

- -
- -

Conditions consists of a list of rules, which take the form of a - struct (name, value), where:

-
    -
  • name is a string which names the rule
  • -
  • value is the value
  • -
-
- - - -

The condition is a list of rules, consisting of a name and of a value, - both strings. - The syntax for the value is:

- - value ::= [logic] (":" singlevalue | "[" listvalue)
- logic ::= ("!" | <possibly other operators>)
- singlevalue ::= <possibly any ASCII string>
- listvalue ::= separator list
- separator ::= <any non-blank ASCII character>
- list ::= singlevaluenonsep (separator singlevaluenonsep)*
- singlevaluenonsep ::= <ASCII string not containing the separator character>
-
- -

Some examples of values:

- - :my_essid_name
- !:my_essid_name
- [,my_essid_name,his_essid_name
- ![,my_essid_name,his_essid_name
-
- - -

- Questions:

-
    -
  • Should it be a(ss) or a{ss}?
  • -
  • Should we specify namespacing rules for the name?
  • -
  • Should we allow wildcards in the values?
  • -
-
-
-
- -
-
- diff --git a/xml/Makefile.am b/xml/Makefile.am index 998bd2d..9c7f866 100644 --- a/xml/Makefile.am +++ b/xml/Makefile.am @@ -6,7 +6,6 @@ DROP_TPTYPE = sed -e 's@tp:type="[^"]*"@@g' SPECS = \ Account_Manager_Interface_Hidden.xml \ - Account_Interface_Conditions.xml \ Account_Interface_External_Password_Storage.xml \ Account_Interface_Hidden.xml \ Connection_Manager_Interface_Account_Storage.xml \ diff --git a/xml/nmc5.xml b/xml/nmc5.xml index 130fd3f..bb4a590 100644 --- a/xml/nmc5.xml +++ b/xml/nmc5.xml @@ -4,7 +4,6 @@ Copyright (C) 2008 Nokia Corporation - -- 1.8.4.rc3