]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
de1c301e LP |
2 | #pragma once |
3 | ||
de1c301e | 4 | #include <byteswap.h> |
07630cea | 5 | #include <stdbool.h> |
2c35d880 | 6 | #include <sys/socket.h> |
de1c301e | 7 | |
de1c301e | 8 | #include "sd-bus.h" |
07630cea | 9 | |
5b12334d | 10 | #include "bus-creds.h" |
0461f8cd | 11 | #include "bus-protocol.h" |
07630cea LP |
12 | #include "macro.h" |
13 | #include "time-util.h" | |
de1c301e LP |
14 | |
15 | struct bus_container { | |
16 | char enclosing; | |
6647dc66 | 17 | bool need_offsets:1; |
de1c301e | 18 | |
6647dc66 | 19 | /* Indexes into the signature string */ |
b3af9646 | 20 | unsigned index, saved_index; |
453a0c29 LP |
21 | char *signature; |
22 | ||
6647dc66 | 23 | size_t before, begin, end; |
c1b9d935 | 24 | |
6647dc66 LP |
25 | /* dbus1: pointer to the array size value, if this is a value */ |
26 | uint32_t *array_size; | |
c1b9d935 | 27 | |
6647dc66 | 28 | /* gvariant: list of offsets to end of children if this is struct/dict entry/array */ |
306f07be | 29 | size_t *offsets, n_offsets, offsets_allocated, offset_index; |
6647dc66 | 30 | size_t item_size; |
3798fd4c LP |
31 | |
32 | char *peeked_signature; | |
de1c301e LP |
33 | }; |
34 | ||
bc7fd8cd | 35 | struct bus_body_part { |
453a0c29 | 36 | struct bus_body_part *next; |
bc7fd8cd | 37 | void *data; |
7dcd79c2 | 38 | void *mmap_begin; |
bc7fd8cd LP |
39 | size_t size; |
40 | size_t mapped; | |
8e959fbf | 41 | size_t allocated; |
7dcd79c2 | 42 | uint64_t memfd_offset; |
bc7fd8cd LP |
43 | int memfd; |
44 | bool free_this:1; | |
453a0c29 | 45 | bool munmap_this:1; |
bc7fd8cd | 46 | bool sealed:1; |
453a0c29 | 47 | bool is_zero:1; |
bc7fd8cd LP |
48 | }; |
49 | ||
de1c301e LP |
50 | struct sd_bus_message { |
51 | unsigned n_ref; | |
52 | ||
fd8d62d9 LP |
53 | sd_bus *bus; |
54 | ||
42c4ebcb | 55 | uint64_t reply_cookie; |
de1c301e LP |
56 | |
57 | const char *path; | |
58 | const char *interface; | |
59 | const char *member; | |
60 | const char *destination; | |
61 | const char *sender; | |
de1c301e LP |
62 | |
63 | sd_bus_error error; | |
64 | ||
5b12334d LP |
65 | sd_bus_creds creds; |
66 | ||
69aec65c LP |
67 | usec_t monotonic; |
68 | usec_t realtime; | |
6a0e376c | 69 | uint64_t seqnum; |
ca7b42c8 | 70 | int64_t priority; |
022fb855 | 71 | uint64_t verify_destination_id; |
de1c301e LP |
72 | |
73 | bool sealed:1; | |
2c93b4ef LP |
74 | bool dont_send:1; |
75 | bool allow_fds:1; | |
de1c301e | 76 | bool free_header:1; |
2c93b4ef | 77 | bool free_fds:1; |
bc7fd8cd | 78 | bool poisoned:1; |
de1c301e | 79 | |
2ac7c17f | 80 | /* The first and last bytes of the message */ |
de1c301e | 81 | struct bus_header *header; |
2ac7c17f LP |
82 | void *footer; |
83 | ||
84 | /* How many bytes are accessible in the above pointers */ | |
85 | size_t header_accessible; | |
86 | size_t footer_accessible; | |
87 | ||
88 | size_t fields_size; | |
89 | size_t body_size; | |
90 | size_t user_body_size; | |
91 | ||
bc7fd8cd LP |
92 | struct bus_body_part body; |
93 | struct bus_body_part *body_end; | |
94 | unsigned n_body_parts; | |
de1c301e | 95 | |
9a17484d | 96 | size_t rindex; |
bc7fd8cd LP |
97 | struct bus_body_part *cached_rindex_part; |
98 | size_t cached_rindex_part_begin; | |
9a17484d | 99 | |
de1c301e LP |
100 | uint32_t n_fds; |
101 | int *fds; | |
102 | ||
9a17484d | 103 | struct bus_container root_container, *containers; |
2ac7c17f | 104 | size_t n_containers; |
306f07be | 105 | size_t containers_allocated; |
de1c301e | 106 | |
bc7fd8cd | 107 | struct iovec *iovec; |
c91cb83c | 108 | struct iovec iovec_fixed[2]; |
de1c301e | 109 | unsigned n_iovec; |
9a17484d LP |
110 | |
111 | char *peeked_signature; | |
6629161f | 112 | |
6717d473 LP |
113 | /* If set replies to this message must carry the signature |
114 | * specified here to successfully seal. This is initialized | |
115 | * from the vtable data */ | |
116 | const char *enforced_reply_signature; | |
117 | ||
6629161f | 118 | usec_t timeout; |
51038c03 | 119 | |
c1b9d935 LP |
120 | size_t header_offsets[_BUS_MESSAGE_HEADER_MAX]; |
121 | unsigned n_header_offsets; | |
de1c301e LP |
122 | }; |
123 | ||
2ac7c17f LP |
124 | static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { |
125 | return m->header->endian != BUS_NATIVE_ENDIAN; | |
126 | } | |
de1c301e | 127 | |
9a17484d LP |
128 | static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) { |
129 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u; | |
130 | } | |
131 | ||
132 | static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) { | |
de1c301e LP |
133 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u; |
134 | } | |
135 | ||
9a17484d LP |
136 | static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) { |
137 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u; | |
138 | } | |
139 | ||
42c4ebcb | 140 | static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) { |
2ac7c17f LP |
141 | if (m->header->version == 2) |
142 | return BUS_MESSAGE_BSWAP64(m, m->header->dbus2.cookie); | |
de1c301e | 143 | |
2ac7c17f | 144 | return BUS_MESSAGE_BSWAP32(m, m->header->dbus1.serial); |
de1c301e LP |
145 | } |
146 | ||
2ac7c17f | 147 | static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) { |
6629161f LP |
148 | return |
149 | sizeof(struct bus_header) + | |
2ac7c17f LP |
150 | ALIGN8(m->fields_size) + |
151 | m->body_size; | |
6629161f LP |
152 | } |
153 | ||
2ac7c17f | 154 | static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) { |
c91cb83c LP |
155 | return |
156 | sizeof(struct bus_header) + | |
2ac7c17f | 157 | ALIGN8(m->fields_size); |
c91cb83c LP |
158 | } |
159 | ||
160 | static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) { | |
161 | return (uint8_t*) m->header + sizeof(struct bus_header); | |
162 | } | |
163 | ||
6647dc66 LP |
164 | static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) { |
165 | return m->header->version == 2; | |
166 | } | |
167 | ||
de1c301e | 168 | int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz); |
89ffcd2a | 169 | int bus_message_read_strv_extend(sd_bus_message *m, char ***l); |
2c93b4ef | 170 | |
6629161f | 171 | int bus_message_from_header( |
df2d202e | 172 | sd_bus *bus, |
6629161f | 173 | void *header, |
2ac7c17f LP |
174 | size_t header_accessible, |
175 | void *footer, | |
176 | size_t footer_accessible, | |
177 | size_t message_size, | |
6629161f | 178 | int *fds, |
da6053d0 | 179 | size_t n_fds, |
6629161f LP |
180 | const char *label, |
181 | size_t extra, | |
182 | sd_bus_message **ret); | |
183 | ||
2c93b4ef | 184 | int bus_message_from_malloc( |
df2d202e | 185 | sd_bus *bus, |
2c93b4ef LP |
186 | void *buffer, |
187 | size_t length, | |
188 | int *fds, | |
da6053d0 | 189 | size_t n_fds, |
2c93b4ef LP |
190 | const char *label, |
191 | sd_bus_message **ret); | |
392d5b37 | 192 | |
eccd47c5 LP |
193 | int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str); |
194 | int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv); | |
917b5dc7 | 195 | |
6629161f LP |
196 | int bus_message_parse_fields(sd_bus_message *m); |
197 | ||
bc7fd8cd | 198 | struct bus_body_part *message_append_part(sd_bus_message *m); |
9b29bb68 LP |
199 | |
200 | #define MESSAGE_FOREACH_PART(part, i, m) \ | |
201 | for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next) | |
a392d361 LP |
202 | |
203 | int bus_body_part_map(struct bus_body_part *part); | |
204 | void bus_body_part_unmap(struct bus_body_part *part); | |
eb01ba5d LP |
205 | |
206 | int bus_message_to_errno(sd_bus_message *m); | |
207 | ||
208 | int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m); | |
e1c433c6 LP |
209 | |
210 | int bus_message_remarshal(sd_bus *bus, sd_bus_message **m); | |
a7639e37 | 211 | |
d29ae291 LP |
212 | void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m); |
213 | void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m); |