HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/libsystemd/sd-bus/bus-match.c
Git blob: c365c5f3d844b64a7c75189c5911239fd52403ac
Lines 1001–1064 of 1,064
if (!node)
return;
fprintf(out, "%*s[%s]", 2 * (int) level, "", bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
if (node->type == BUS_MATCH_VALUE) {
if (node->parent->type == BUS_MATCH_MESSAGE_TYPE)
fprintf(out, " <%u>\n", node->value.u8);
else
fprintf(out, " <%s>\n", node->value.str);
} else if (node->type == BUS_MATCH_ROOT)
fputs(" root\n", out);
else if (node->type == BUS_MATCH_LEAF)
fprintf(out, " %p/%p\n", node->leaf.callback->callback,
container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
else
putc('\n', out);
if (BUS_MATCH_CAN_HASH(node->type)) {
BusMatchNode *c;
HASHMAP_FOREACH(c, node->compare.children)
bus_match_dump(out, c, level + 1);
}
for (BusMatchNode *c = node->child; c; c = c->next)
bus_match_dump(out, c, level + 1);
}
BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components) {
bool found_driver = false;
if (n_components <= 0)
return BUS_MATCH_GENERIC;
assert(components);
/* Checks whether the specified match can only match the
* pseudo-service for local messages, which we detect by
* sender, interface or path. If a match is not restricted to
* local messages, then we check if it only matches on the
* driver. */
for (size_t i = 0; i < n_components; i++) {
const BusMatchComponent *c = components + i;
if (c->type == BUS_MATCH_SENDER) {
if (streq_ptr(c->value_str, "org.freedesktop.DBus.Local"))
return BUS_MATCH_LOCAL;
if (streq_ptr(c->value_str, "org.freedesktop.DBus"))
found_driver = true;
}
if (c->type == BUS_MATCH_INTERFACE && streq_ptr(c->value_str, "org.freedesktop.DBus.Local"))
return BUS_MATCH_LOCAL;
if (c->type == BUS_MATCH_PATH && streq_ptr(c->value_str, "/org/freedesktop/DBus/Local"))
return BUS_MATCH_LOCAL;
}
return found_driver ? BUS_MATCH_DRIVER : BUS_MATCH_GENERIC;
}