From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 07/20] dbus-filter: Name owner change tracking support.
Date: Mon, 14 Mar 2016 13:03:34 -0500 [thread overview]
Message-ID: <56E6FCF6.5070505@gmail.com> (raw)
In-Reply-To: <1457926896-9843-7-git-send-email-andrew.zaborowski@intel.com>
[-- Attachment #1: Type: text/plain, Size: 7439 bytes --]
Hi Andrew,
On 03/13/2016 10:41 PM, Andrew Zaborowski wrote:
> This is needed because incoming message callbacks normally care what
> Well-known Bus Name the message comes from but the sender field of the
> message normally stores unique bus names in classic dbus. The
> Well-known names may be re-assigned to different unique names while the
> rule is in place.
> ---
> ell/dbus-filter.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> ell/dbus-private.h | 5 +++
> 2 files changed, 106 insertions(+), 1 deletion(-)
>
> diff --git a/ell/dbus-filter.c b/ell/dbus-filter.c
> index 2541374..f2cc023 100644
> --- a/ell/dbus-filter.c
> +++ b/ell/dbus-filter.c
> @@ -62,6 +62,12 @@ struct _dbus_filter {
> unsigned int signal_id;
> unsigned int last_id;
> const struct _dbus_filter_ops *driver;
> + struct l_hashmap *unique_names;
> +};
> +
> +struct unique_name_record {
> + int ref_count;
> + char *unique_name;
> };
>
> static void filter_subtree_free(struct filter_node *node)
> @@ -86,6 +92,14 @@ static void filter_subtree_free(struct filter_node *node)
> }
> }
>
> +static void unique_name_record_free(void *data)
> +{
> + struct unique_name_record *name_rec = data;
> +
> + l_free(name_rec->unique_name);
> + l_free(name_rec);
> +}
> +
> static void dbus_filter_destroy(void *data)
> {
> struct _dbus_filter *filter = data;
> @@ -93,6 +107,10 @@ static void dbus_filter_destroy(void *data)
> if (filter->root)
> filter_subtree_free(filter->root);
>
> + if (filter->unique_names)
> + l_hashmap_destroy(filter->unique_names,
> + unique_name_record_free);
> +
> l_free(filter);
> }
>
> @@ -101,6 +119,8 @@ static void filter_dispatch_match_recurse(struct _dbus_filter *filter,
> struct l_dbus_message *message)
> {
> const char *value = NULL;
> + const char *alt_value = NULL;
> + const struct unique_name_record *name_rec;
> struct filter_node *child;
>
> switch ((int) node->type) {
> @@ -141,7 +161,18 @@ static void filter_dispatch_match_recurse(struct _dbus_filter *filter,
> if (!value)
> return;
>
> - if (strcmp(value, node->match.value))
> + if ((node->type == L_DBUS_MATCH_SENDER ||
> + node->type == L_DBUS_MATCH_DESTINATION) &&
According to DBus specification, destination matches only match the
unique name:
"Matches messages which are being sent to the given unique name. An
example of a destination match is destination=':1.0'"
> + filter->unique_names) {
> + name_rec = l_hashmap_lookup(filter->unique_names,
> + node->match.value);
> +
> + if (name_rec)
> + alt_value = name_rec->unique_name;
> + }
> +
> + if (strcmp(value, node->match.value) &&
> + (!alt_value || strcmp(value, alt_value)))
> return;
>
> for (child = node->match.children; child; child = child->next)
> @@ -155,6 +186,21 @@ void _dbus_filter_dispatch(struct l_dbus_message *message, void *user_data)
> filter_dispatch_match_recurse(filter, filter->root, message);
> }
>
> +void _dbus_filter_name_owner_notify(struct _dbus_filter *filter,
> + const char *name, const char *owner)
> +{
> + if (_dbus_parse_unique_name(name, NULL))
> + return;
> +
> + name_rec = l_hashmap_lookup(filter->unique_names, name);
> + if (!name_rec)
> + return;
> +
> + l_free(name_rec->unique_name);
> +
> + name_rec->unique_name = (owner && *owner) ? l_strdup(owner) : NULL;
> +}
> +
> struct _dbus_filter *_dbus_filter_new(struct l_dbus *dbus,
> const struct _dbus_filter_ops *driver)
> {
> @@ -170,6 +216,9 @@ struct _dbus_filter *_dbus_filter_new(struct l_dbus *dbus,
> filter,
> dbus_filter_destroy);
>
> + if (filter->driver->track_name_owner_change)
Is this ever going to be false?
> + filter->unique_names = l_hashmap_string_new();
> +
> return filter;
> }
>
> @@ -184,6 +233,49 @@ void _dbus_filter_free(struct _dbus_filter *filter)
> dbus_filter_destroy(filter);
> }
>
> +static void filter_add_bus_name(struct _dbus_filter *filter, const char *name)
> +{
> + struct unique_name_record *name_rec;
> +
> + if (!filter->unique_names)
> + return;
> +
> + if (_dbus_parse_unique_name(name, NULL))
> + return;
Do you need to add a check for valid_bus_name?
Should this function return something?
> +
> + name_rec = l_hashmap_lookup(filter->unique_names, name);
> + if (!name_rec) {
> + name_rec = l_new(struct unique_name_record, 1);
> +
> + l_hashmap_insert(filter->unique_names, name, name_rec);
> +
> + filter->driver->get_name_owner(filter->dbus, name);
> + }
> +
> + name_rec->ref_count++;
> +}
> +
> +static void filter_remove_bus_name(struct _dbus_filter *filter,
> + const char *name)
> +{
> + struct unique_name_record *name_rec;
> +
> + if (!filter->unique_names)
> + return;
> +
> + if (_dbus_parse_unique_name(name, NULL))
> + return;
> +
> + name_rec = l_hashmap_lookup(filter->unique_names, name);
> +
> + if (--name_rec->ref_count)
> + return;
> +
> + l_hashmap_remove(filter->unique_names, name);
> +
> + unique_name_record_free(name_rec);
> +}
> +
> static int condition_compare(const void *a, const void *b)
> {
> const struct _dbus_filter_condition *condition_a = a, *condition_b = b;
> @@ -225,6 +317,10 @@ unsigned int _dbus_filter_add_rule(struct _dbus_filter *filter,
> node->match.value = l_strdup(condition->value);
>
> *node_ptr = node;
> +
> + if (node->type == L_DBUS_MATCH_SENDER ||
> + node->type == L_DBUS_MATCH_DESTINATION)
> + filter_add_bus_name(filter, node->match.value);
As mentioned before, L_DBUS_MATCH_DESTINATION does not seem to be
relevant here.
> }
>
> node_ptr = &node->match.children;
> @@ -286,6 +382,10 @@ static bool remove_recurse(struct _dbus_filter *filter,
> if (tmp->match.remote_rule)
> filter->driver->remove_match(filter->dbus, tmp->id);
>
> + if (tmp->type == L_DBUS_MATCH_SENDER ||
> + tmp->type == L_DBUS_MATCH_DESTINATION)
> + filter_remove_bus_name(filter, tmp->match.value);
> +
> filter_subtree_free(tmp);
> }
>
> diff --git a/ell/dbus-private.h b/ell/dbus-private.h
> index d4a4782..de4e706 100644
> --- a/ell/dbus-private.h
> +++ b/ell/dbus-private.h
> @@ -250,11 +250,13 @@ struct _dbus_filter_condition {
> };
>
> struct _dbus_filter_ops {
> + bool track_name_owner_change;
Do we really need this? I think we can safely assume that this is true
if get_name_owner implementation is provided.
> bool skip_register;
> bool (*add_match)(struct l_dbus *bus, unsigned int id,
> const struct _dbus_filter_condition *rule,
> int rule_len);
> bool (*remove_match)(struct l_dbus *bus, unsigned int id);
> + bool (*get_name_owner)(struct l_dbus *bus, const char *name);
> };
>
> struct _dbus_filter *_dbus_filter_new(struct l_dbus *dbus,
> @@ -270,7 +272,10 @@ bool _dbus_filter_remove_rule(struct _dbus_filter *filter, unsigned int id);
>
> char *_dbus_filter_rule_to_str(const struct _dbus_filter_condition *rule,
> int rule_len);
> +
> void _dbus_filter_dispatch(struct l_dbus_message *message, void *user_data);
> +void _dbus_filter_name_owner_notify(struct _dbus_filter *filter,
> + const char *name, const char *owner);
>
> struct dbus1_filter_data;
>
>
Regards,
-Denis
next prev parent reply other threads:[~2016-03-14 18:03 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 3:41 [PATCH 01/20] dbus: Add _dbus1_message_iter_skip_entry and gvariant variant Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 02/20] dbus: Add _dbus_message_get_nth_string_argument Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 03/20] dbus: Support 2+ arguments in l_dbus_message_get_error Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 04/20] dbus: Fix _dbus_kernel_calculate_bloom for multiple arguments Andrew Zaborowski
2016-03-14 16:49 ` Denis Kenzior
2016-03-14 22:11 ` Andrzej Zaborowski
2016-03-15 16:27 ` Denis Kenzior
2016-03-15 22:08 ` Andrzej Zaborowski
2016-03-16 2:06 ` Denis Kenzior
2016-03-14 3:41 ` [PATCH 05/20] dbus: Add message filter logic in dbus-filter.c Andrew Zaborowski
2016-03-14 17:37 ` Denis Kenzior
2016-03-14 22:25 ` Andrzej Zaborowski
2016-03-14 3:41 ` [PATCH 06/20] unit: Add dbus message filter tests Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 07/20] dbus-filter: Name owner change tracking support Andrew Zaborowski
2016-03-14 18:03 ` Denis Kenzior [this message]
2016-03-14 22:32 ` Andrzej Zaborowski
2016-03-14 3:41 ` [PATCH 08/20] dbus: Classic dbus filter_ops implementation Andrew Zaborowski
2016-03-14 18:18 ` Denis Kenzior
2016-03-14 22:36 ` Andrzej Zaborowski
2016-03-15 16:32 ` Denis Kenzior
2016-03-14 3:41 ` [PATCH 09/20] dbus: kdbus " Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 10/20] linux: Update kdbus.h to current github version Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 11/20] dbus-kernel: Update with kdbus API changes Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 12/20] dbus: Add message filter public API Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 13/20] unit: Use the message filter API in dbus tests Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 14/20] dbus: Don't send replies to messages with no reply flag Andrew Zaborowski
2016-03-14 17:11 ` Denis Kenzior
2016-03-14 22:15 ` Andrzej Zaborowski
2016-03-15 16:35 ` Denis Kenzior
2016-03-14 3:41 ` [PATCH 15/20] dbus: Rewrite service/disconnect watch APIs on top of filter API Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 16/20] dbus: Remove now unused filter functions Andrew Zaborowski
2016-03-14 19:12 ` Denis Kenzior
2016-03-14 3:41 ` [PATCH 17/20] dbus: kdbus driver->name_acquire implementation Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 18/20] dbus: Classic dbus driver->name_acquire and public API Andrew Zaborowski
2016-03-14 19:18 ` Denis Kenzior
2016-03-14 22:39 ` Andrzej Zaborowski
2016-03-15 16:38 ` Denis Kenzior
2016-03-14 3:41 ` [PATCH 19/20] unit: Use l_dbus_name_acquire to acquire well-known name Andrew Zaborowski
2016-03-14 3:41 ` [PATCH 20/20] examples: " Andrew Zaborowski
2016-03-14 16:50 ` [PATCH 01/20] dbus: Add _dbus1_message_iter_skip_entry and gvariant variant Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56E6FCF6.5070505@gmail.com \
--to=denkenz@gmail.com \
--cc=ell@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.