#include "bus-internal.h"
#include "bus-message.h"
#include "bus-match.h"
+#include "bus-error.h"
+#include "bus-util.h"
/* Example:
*
*/
static inline bool BUS_MATCH_IS_COMPARE(enum bus_match_node_type t) {
- return t >= BUS_MATCH_MESSAGE_TYPE && t <= BUS_MATCH_ARG_NAMESPACE_LAST;
+ return t >= BUS_MATCH_SENDER && t <= BUS_MATCH_ARG_NAMESPACE_LAST;
}
static inline bool BUS_MATCH_CAN_HASH(enum bus_match_node_type t) {
case BUS_MATCH_SENDER:
case BUS_MATCH_DESTINATION:
+ if (streq_ptr(node->value.str, value_str))
+ return true;
+
+ /* FIXME: So here's an ugliness: if the match is for a
+ * well-known name then we cannot actually check this
+ * correctly here. This doesn't matter much for dbus1
+ * where no false positives exist, hence we just
+ * ignore this case here. For kdbus the messages
+ * should contain all well-known names of the sender,
+ * hence we can fix things there correctly. */
+
+ if (node->value.str[0] != ':' && value_str && value_str[0] == ':')
+ return true;
+
+ return false;
+
case BUS_MATCH_INTERFACE:
case BUS_MATCH_MEMBER:
case BUS_MATCH_PATH:
/* Run the callback. And then invoke siblings. */
if (node->leaf.callback) {
- r = node->leaf.callback(bus, m, node->leaf.userdata);
+ _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
+ r = node->leaf.callback(bus, m, node->leaf.userdata, &error_buffer);
+ r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
}
enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n) {
assert(k);
- if (n == 4 && hasprefix(k, "type"))
+ if (n == 4 && startswith(k, "type"))
return BUS_MATCH_MESSAGE_TYPE;
- if (n == 6 && hasprefix(k, "sender"))
+ if (n == 6 && startswith(k, "sender"))
return BUS_MATCH_SENDER;
- if (n == 11 && hasprefix(k, "destination"))
+ if (n == 11 && startswith(k, "destination"))
return BUS_MATCH_DESTINATION;
- if (n == 9 && hasprefix(k, "interface"))
+ if (n == 9 && startswith(k, "interface"))
return BUS_MATCH_INTERFACE;
- if (n == 6 && hasprefix(k, "member"))
+ if (n == 6 && startswith(k, "member"))
return BUS_MATCH_MEMBER;
- if (n == 4 && hasprefix(k, "path"))
+ if (n == 4 && startswith(k, "path"))
return BUS_MATCH_PATH;
- if (n == 14 && hasprefix(k, "path_namespace"))
+ if (n == 14 && startswith(k, "path_namespace"))
return BUS_MATCH_PATH_NAMESPACE;
- if (n == 4 && hasprefix(k, "arg")) {
+ if (n == 4 && startswith(k, "arg")) {
int j;
j = undecchar(k[3]);
return BUS_MATCH_ARG + j;
}
- if (n == 5 && hasprefix(k, "arg")) {
+ if (n == 5 && startswith(k, "arg")) {
int a, b;
enum bus_match_node_type t;
return t;
}
- if (n == 8 && hasprefix(k, "arg") && hasprefix(k + 4, "path")) {
+ if (n == 8 && startswith(k, "arg") && startswith(k + 4, "path")) {
int j;
j = undecchar(k[3]);
return BUS_MATCH_ARG_PATH + j;
}
- if (n == 9 && hasprefix(k, "arg") && hasprefix(k + 5, "path")) {
+ if (n == 9 && startswith(k, "arg") && startswith(k + 5, "path")) {
enum bus_match_node_type t;
int a, b;
return t;
}
- if (n == 13 && hasprefix(k, "arg") && hasprefix(k + 4, "namespace")) {
+ if (n == 13 && startswith(k, "arg") && startswith(k + 4, "namespace")) {
int j;
j = undecchar(k[3]);
return BUS_MATCH_ARG_NAMESPACE + j;
}
- if (n == 14 && hasprefix(k, "arg") && hasprefix(k + 5, "namespace")) {
+ if (n == 14 && startswith(k, "arg") && startswith(k + 5, "namespace")) {
enum bus_match_node_type t;
int a, b;
}
/* Order the whole thing, so that we always generate the same tree */
- qsort(components, n_components, sizeof(struct bus_match_component), match_component_compare);
+ qsort_safe(components, n_components, sizeof(struct bus_match_component), match_component_compare);
/* Check for duplicates */
for (i = 0; i+1 < n_components; i++)