if (r != 0)
return r;
}
- } else {
- struct bus_match_node *c;
-
+ } else
/* No hash table, so let's iterate manually... */
-
- for (c = node->child; c; c = c->next) {
+ for (struct bus_match_node *c = node->child; c; c = c->next) {
if (!value_node_test(c, node->type, test_u8, test_str, test_strv, m))
continue;
if (bus && bus->match_callbacks_modified)
return 0;
}
- }
if (bus && bus->match_callbacks_modified)
return 0;
const char *value_str,
struct bus_match_node **ret) {
- struct bus_match_node *c = NULL, *n = NULL;
+ struct bus_match_node *c, *n = NULL;
int r;
assert(where);
;
if (c) {
- /* Comparison node already exists? Then let's see if
- * the value node exists too. */
+ /* Comparison node already exists? Then let's see if the value node exists too. */
if (t == BUS_MATCH_MESSAGE_TYPE)
n = hashmap_get(c->compare.children, UINT_TO_PTR(value_u8));
else if (BUS_MATCH_CAN_HASH(t))
n = hashmap_get(c->compare.children, value_str);
- else {
+ else
for (n = c->child; n && !value_node_same(n, t, value_u8, value_str); n = n->next)
;
- }
if (n) {
*ret = n;
return 0;
}
} else {
- /* Comparison node, doesn't exist yet? Then let's
- * create it. */
+ /* Comparison node, doesn't exist yet? Then let's create it. */
c = new0(struct bus_match_node, 1);
if (!c) {
}
void bus_match_parse_free(struct bus_match_component *components, unsigned n_components) {
- unsigned i;
-
- for (i = 0; i < n_components; i++)
+ for (unsigned i = 0; i < n_components; i++)
free(components[i].value_str);
free(components);
const char *p = match;
struct bus_match_component *components = NULL;
size_t components_allocated = 0;
- unsigned n_components = 0, i;
+ unsigned n_components = 0;
_cleanup_free_ char *value = NULL;
int r;
typesafe_qsort(components, n_components, match_component_compare);
/* Check for duplicates */
- for (i = 0; i+1 < n_components; i++)
+ for (unsigned i = 0; i+1 < n_components; i++)
if (components[i].type == components[i+1].type) {
r = -EINVAL;
goto fail;
}
char *bus_match_to_string(struct bus_match_component *components, unsigned n_components) {
- _cleanup_fclose_ FILE *f = NULL;
char *buffer = NULL;
size_t size = 0;
- unsigned i;
int r;
if (n_components <= 0)
assert(components);
- f = open_memstream_unlocked(&buffer, &size);
+ _cleanup_fclose_ FILE *f = open_memstream_unlocked(&buffer, &size);
if (!f)
return NULL;
- for (i = 0; i < n_components; i++) {
+ for (unsigned i = 0; i < n_components; i++) {
char buf[32];
if (i != 0)
unsigned n_components,
struct match_callback *callback) {
- unsigned i;
- struct bus_match_node *n;
int r;
assert(root);
assert(callback);
- n = root;
- for (i = 0; i < n_components; i++) {
- r = bus_match_add_compare_value(
- n, components[i].type,
- components[i].value_u8, components[i].value_str, &n);
+ for (unsigned i = 0; i < n_components; i++) {
+ r = bus_match_add_compare_value(root,
+ components[i].type,
+ components[i].value_u8,
+ components[i].value_str,
+ &root);
if (r < 0)
return r;
}
- return bus_match_add_leaf(n, callback);
+ return bus_match_add_leaf(root, callback);
}
int bus_match_remove(
}
void bus_match_dump(struct bus_match_node *node, unsigned level) {
- struct bus_match_node *c;
_cleanup_free_ char *pfx = NULL;
char buf[32];
} else if (node->type == BUS_MATCH_ROOT)
puts(" root");
else if (node->type == BUS_MATCH_LEAF)
- printf(" %p/%p\n", node->leaf.callback->callback, container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
+ printf(" %p/%p\n", node->leaf.callback->callback,
+ container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
else
putchar('\n');
if (BUS_MATCH_CAN_HASH(node->type)) {
-
+ struct bus_match_node *c;
HASHMAP_FOREACH(c, node->compare.children)
bus_match_dump(c, level + 1);
}
- for (c = node->child; c; c = c->next)
+ for (struct bus_match_node *c = node->child; c; c = c->next)
bus_match_dump(c, level + 1);
}
enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components) {
bool found_driver = false;
- unsigned i;
if (n_components <= 0)
return BUS_MATCH_GENERIC;
* local messages, then we check if it only matches on the
* driver. */
- for (i = 0; i < n_components; i++) {
+ for (unsigned i = 0; i < n_components; i++) {
const struct bus_match_component *c = components + i;
if (c->type == BUS_MATCH_SENDER) {
}
return found_driver ? BUS_MATCH_DRIVER : BUS_MATCH_GENERIC;
-
}