]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
392d5b37 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2013 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
392d5b37 LP |
23 | #include "sd-bus.h" |
24 | ||
07630cea LP |
25 | #include "hashmap.h" |
26 | ||
392d5b37 LP |
27 | enum bus_match_node_type { |
28 | BUS_MATCH_ROOT, | |
29 | BUS_MATCH_VALUE, | |
30 | BUS_MATCH_LEAF, | |
31 | ||
32 | /* The following are all different kinds of compare nodes */ | |
392d5b37 | 33 | BUS_MATCH_SENDER, |
ae7bed3f | 34 | BUS_MATCH_MESSAGE_TYPE, |
392d5b37 LP |
35 | BUS_MATCH_DESTINATION, |
36 | BUS_MATCH_INTERFACE, | |
37 | BUS_MATCH_MEMBER, | |
38 | BUS_MATCH_PATH, | |
39 | BUS_MATCH_PATH_NAMESPACE, | |
40 | BUS_MATCH_ARG, | |
41 | BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63, | |
42 | BUS_MATCH_ARG_PATH, | |
43 | BUS_MATCH_ARG_PATH_LAST = BUS_MATCH_ARG_PATH + 63, | |
44 | BUS_MATCH_ARG_NAMESPACE, | |
45 | BUS_MATCH_ARG_NAMESPACE_LAST = BUS_MATCH_ARG_NAMESPACE + 63, | |
eccd47c5 LP |
46 | BUS_MATCH_ARG_HAS, |
47 | BUS_MATCH_ARG_HAS_LAST = BUS_MATCH_ARG_HAS + 63, | |
392d5b37 LP |
48 | _BUS_MATCH_NODE_TYPE_MAX, |
49 | _BUS_MATCH_NODE_TYPE_INVALID = -1 | |
50 | }; | |
51 | ||
52 | struct bus_match_node { | |
53 | enum bus_match_node_type type; | |
54 | struct bus_match_node *parent, *next, *prev, *child; | |
55 | ||
56 | union { | |
57 | struct { | |
392d5b37 | 58 | char *str; |
7286037f | 59 | uint8_t u8; |
392d5b37 LP |
60 | } value; |
61 | struct { | |
19befb2d | 62 | struct match_callback *callback; |
392d5b37 LP |
63 | } leaf; |
64 | struct { | |
65 | /* If this is set, then the child is NULL */ | |
66 | Hashmap *children; | |
67 | } compare; | |
68 | }; | |
69 | }; | |
70 | ||
c7819669 LP |
71 | struct bus_match_component { |
72 | enum bus_match_node_type type; | |
73 | uint8_t value_u8; | |
74 | char *value_str; | |
75 | }; | |
76 | ||
cc65fe5e LP |
77 | enum bus_match_scope { |
78 | BUS_MATCH_GENERIC, | |
79 | BUS_MATCH_LOCAL, | |
80 | BUS_MATCH_DRIVER, | |
81 | }; | |
82 | ||
eb01ba5d | 83 | int bus_match_run(sd_bus *bus, struct bus_match_node *root, sd_bus_message *m); |
392d5b37 | 84 | |
19befb2d LP |
85 | int bus_match_add(struct bus_match_node *root, struct bus_match_component *components, unsigned n_components, struct match_callback *callback); |
86 | int bus_match_remove(struct bus_match_node *root, struct match_callback *callback); | |
87 | ||
88 | int bus_match_find(struct bus_match_node *root, struct bus_match_component *components, unsigned n_components, sd_bus_message_handler_t callback, void *userdata, struct match_callback **ret); | |
392d5b37 LP |
89 | |
90 | void bus_match_free(struct bus_match_node *node); | |
91 | ||
92 | void bus_match_dump(struct bus_match_node *node, unsigned level); | |
93 | ||
94 | const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l); | |
95 | enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n); | |
c7819669 LP |
96 | |
97 | int bus_match_parse(const char *match, struct bus_match_component **_components, unsigned *_n_components); | |
98 | void bus_match_parse_free(struct bus_match_component *components, unsigned n_components); | |
53461b74 | 99 | char *bus_match_to_string(struct bus_match_component *components, unsigned n_components); |
cc65fe5e LP |
100 | |
101 | enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components); |