| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "bus-forward.h" |
| 5 |
|
| 6 |
typedef enum BusMatchNodeType { |
| 7 |
BUS_MATCH_ROOT, |
| 8 |
BUS_MATCH_VALUE, |
| 9 |
BUS_MATCH_LEAF, |
| 10 |
|
| 11 |
/* The following are all different kinds of compare nodes */ |
| 12 |
BUS_MATCH_SENDER, |
| 13 |
BUS_MATCH_MESSAGE_TYPE, |
| 14 |
BUS_MATCH_DESTINATION, |
| 15 |
BUS_MATCH_INTERFACE, |
| 16 |
BUS_MATCH_MEMBER, |
| 17 |
BUS_MATCH_PATH, |
| 18 |
BUS_MATCH_PATH_NAMESPACE, |
| 19 |
BUS_MATCH_ARG, |
| 20 |
BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63, |
| 21 |
BUS_MATCH_ARG_PATH, |
| 22 |
BUS_MATCH_ARG_PATH_LAST = BUS_MATCH_ARG_PATH + 63, |
| 23 |
BUS_MATCH_ARG_NAMESPACE, |
| 24 |
BUS_MATCH_ARG_NAMESPACE_LAST = BUS_MATCH_ARG_NAMESPACE + 63, |
| 25 |
BUS_MATCH_ARG_HAS, |
| 26 |
BUS_MATCH_ARG_HAS_LAST = BUS_MATCH_ARG_HAS + 63, |
| 27 |
_BUS_MATCH_NODE_TYPE_MAX, |
| 28 |
_BUS_MATCH_NODE_TYPE_INVALID = -EINVAL, |
| 29 |
} BusMatchNodeType; |
| 30 |
|
| 31 |
typedef struct BusMatchCallback { |
| 32 |
sd_bus_message_handler_t callback; |
| 33 |
sd_bus_message_handler_t install_callback; |
| 34 |
|
| 35 |
sd_bus_slot *install_slot; /* The AddMatch() call */ |
| 36 |
|
| 37 |
unsigned last_iteration; |
| 38 |
|
| 39 |
/* Don't dispatch this slot with messages that arrived in any iteration before or at the this |
| 40 |
* one. We use this to ensure that matches don't apply "retroactively" and confuse the caller: |
| 41 |
* only messages received after the match was installed will be considered. */ |
| 42 |
uint64_t after; |
| 43 |
|
| 44 |
char *match_string; |
| 45 |
|
| 46 |
BusMatchNode *match_node; |
| 47 |
} BusMatchCallback; |
| 48 |
|
| 49 |
typedef struct BusMatchNode { |
| 50 |
BusMatchNodeType type; |
| 51 |
BusMatchNode *parent, *next, *prev, *child; |
| 52 |
|
| 53 |
union { |
| 54 |
struct { |
| 55 |
char *str; |
| 56 |
uint8_t u8; |
| 57 |
} value; |
| 58 |
struct { |
| 59 |
BusMatchCallback *callback; |
| 60 |
} leaf; |
| 61 |
struct { |
| 62 |
/* If this is set, then the child is NULL */ |
| 63 |
Hashmap *children; |
| 64 |
} compare; |
| 65 |
}; |
| 66 |
} BusMatchNode; |
| 67 |
|
| 68 |
typedef struct BusMatchComponent { |
| 69 |
BusMatchNodeType type; |
| 70 |
uint8_t value_u8; |
| 71 |
char *value_str; |
| 72 |
} BusMatchComponent; |
| 73 |
|
| 74 |
typedef enum BusMatchScope { |
| 75 |
BUS_MATCH_GENERIC, |
| 76 |
BUS_MATCH_LOCAL, |
| 77 |
BUS_MATCH_DRIVER, |
| 78 |
} BusMatchScope; |
| 79 |
|
| 80 |
int bus_match_run(sd_bus *bus, BusMatchNode *node, sd_bus_message *m); |
| 81 |
|
| 82 |
int bus_match_add(BusMatchNode *root, BusMatchComponent *components, size_t n_components, BusMatchCallback *callback); |
| 83 |
int bus_match_remove(BusMatchNode *root, BusMatchCallback *callback); |
| 84 |
|
| 85 |
void bus_match_free(BusMatchNode *node); |
| 86 |
|
| 87 |
void bus_match_dump(FILE *out, BusMatchNode *node, unsigned level); |
| 88 |
|
| 89 |
const char* bus_match_node_type_to_string(BusMatchNodeType t, char buf[], size_t l); |
| 90 |
BusMatchNodeType bus_match_node_type_from_string(const char *k, size_t n); |
| 91 |
|
| 92 |
int bus_match_parse(const char *match, BusMatchComponent **ret_components, size_t *ret_n_components); |
| 93 |
void bus_match_parse_free(BusMatchComponent *components, size_t n_components); |
| 94 |
char* bus_match_to_string(BusMatchComponent *components, size_t n_components); |
| 95 |
|
| 96 |
BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components); |