]>
Commit | Line | Data |
---|---|---|
a032b68d | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
663996b3 MS |
2 | #pragma once |
3 | ||
663996b3 | 4 | #include <byteswap.h> |
db2df898 | 5 | #include <stdbool.h> |
663996b3 MS |
6 | #include <sys/socket.h> |
7 | ||
663996b3 | 8 | #include "sd-bus.h" |
db2df898 | 9 | |
60f067b4 JS |
10 | #include "bus-creds.h" |
11 | #include "bus-protocol.h" | |
db2df898 MP |
12 | #include "macro.h" |
13 | #include "time-util.h" | |
663996b3 MS |
14 | |
15 | struct bus_container { | |
16 | char enclosing; | |
60f067b4 | 17 | bool need_offsets:1; |
663996b3 | 18 | |
60f067b4 | 19 | /* Indexes into the signature string */ |
14228c0d | 20 | unsigned index, saved_index; |
663996b3 | 21 | char *signature; |
663996b3 | 22 | |
60f067b4 JS |
23 | size_t before, begin, end; |
24 | ||
25 | /* dbus1: pointer to the array size value, if this is a value */ | |
663996b3 | 26 | uint32_t *array_size; |
60f067b4 JS |
27 | |
28 | /* gvariant: list of offsets to end of children if this is struct/dict entry/array */ | |
8b3d4ff0 | 29 | size_t *offsets, n_offsets, offset_index; |
60f067b4 JS |
30 | size_t item_size; |
31 | ||
32 | char *peeked_signature; | |
663996b3 MS |
33 | }; |
34 | ||
14228c0d MB |
35 | struct bus_body_part { |
36 | struct bus_body_part *next; | |
37 | void *data; | |
f47781d8 | 38 | void *mmap_begin; |
14228c0d MB |
39 | size_t size; |
40 | size_t mapped; | |
60f067b4 | 41 | size_t allocated; |
f47781d8 | 42 | uint64_t memfd_offset; |
14228c0d MB |
43 | int memfd; |
44 | bool free_this:1; | |
45 | bool munmap_this:1; | |
46 | bool sealed:1; | |
47 | bool is_zero:1; | |
48 | }; | |
49 | ||
663996b3 | 50 | struct sd_bus_message { |
bb4f798a MB |
51 | /* Caveat: a message can be referenced in two different ways: the main (user-facing) way will also |
52 | * pin the bus connection object the message is associated with. The secondary way ("queued") is used | |
53 | * when a message is in the read or write queues of the bus connection object, which will not pin the | |
54 | * bus connection object. This is necessary so that we don't have to have a pair of cyclic references | |
55 | * between a message that is queued and its connection: as soon as a message is only referenced by | |
56 | * the connection (by means of being queued) and the connection itself has no other references it | |
57 | * will be freed. */ | |
58 | ||
59 | unsigned n_ref; /* Counter of references that pin the connection */ | |
60 | unsigned n_queued; /* Counter of references that do not pin the connection */ | |
663996b3 | 61 | |
14228c0d MB |
62 | sd_bus *bus; |
63 | ||
60f067b4 | 64 | uint64_t reply_cookie; |
663996b3 MS |
65 | |
66 | const char *path; | |
67 | const char *interface; | |
68 | const char *member; | |
69 | const char *destination; | |
70 | const char *sender; | |
71 | ||
72 | sd_bus_error error; | |
73 | ||
60f067b4 JS |
74 | sd_bus_creds creds; |
75 | ||
663996b3 MS |
76 | usec_t monotonic; |
77 | usec_t realtime; | |
60f067b4 | 78 | uint64_t seqnum; |
f47781d8 | 79 | uint64_t verify_destination_id; |
663996b3 MS |
80 | |
81 | bool sealed:1; | |
82 | bool dont_send:1; | |
83 | bool allow_fds:1; | |
663996b3 | 84 | bool free_header:1; |
663996b3 | 85 | bool free_fds:1; |
14228c0d | 86 | bool poisoned:1; |
46cdbd49 | 87 | bool sensitive:1; |
663996b3 | 88 | |
e735f4d4 | 89 | /* The first and last bytes of the message */ |
663996b3 | 90 | struct bus_header *header; |
e735f4d4 MP |
91 | void *footer; |
92 | ||
93 | /* How many bytes are accessible in the above pointers */ | |
94 | size_t header_accessible; | |
95 | size_t footer_accessible; | |
96 | ||
97 | size_t fields_size; | |
98 | size_t body_size; | |
99 | size_t user_body_size; | |
100 | ||
14228c0d MB |
101 | struct bus_body_part body; |
102 | struct bus_body_part *body_end; | |
103 | unsigned n_body_parts; | |
663996b3 | 104 | |
663996b3 | 105 | size_t rindex; |
14228c0d MB |
106 | struct bus_body_part *cached_rindex_part; |
107 | size_t cached_rindex_part_begin; | |
663996b3 MS |
108 | |
109 | uint32_t n_fds; | |
110 | int *fds; | |
111 | ||
112 | struct bus_container root_container, *containers; | |
e735f4d4 | 113 | size_t n_containers; |
663996b3 | 114 | |
14228c0d MB |
115 | struct iovec *iovec; |
116 | struct iovec iovec_fixed[2]; | |
663996b3 MS |
117 | unsigned n_iovec; |
118 | ||
119 | char *peeked_signature; | |
120 | ||
60f067b4 JS |
121 | /* If set replies to this message must carry the signature |
122 | * specified here to successfully seal. This is initialized | |
123 | * from the vtable data */ | |
124 | const char *enforced_reply_signature; | |
125 | ||
663996b3 MS |
126 | usec_t timeout; |
127 | ||
60f067b4 JS |
128 | size_t header_offsets[_BUS_MESSAGE_HEADER_MAX]; |
129 | unsigned n_header_offsets; | |
f2dec872 BR |
130 | |
131 | uint64_t read_counter; | |
663996b3 MS |
132 | }; |
133 | ||
e735f4d4 MP |
134 | static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) { |
135 | return m->header->endian != BUS_NATIVE_ENDIAN; | |
136 | } | |
663996b3 MS |
137 | |
138 | static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) { | |
139 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u; | |
140 | } | |
141 | ||
142 | static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) { | |
143 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u; | |
144 | } | |
145 | ||
146 | static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) { | |
147 | return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u; | |
148 | } | |
149 | ||
60f067b4 | 150 | static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) { |
e735f4d4 MP |
151 | if (m->header->version == 2) |
152 | return BUS_MESSAGE_BSWAP64(m, m->header->dbus2.cookie); | |
663996b3 | 153 | |
e735f4d4 | 154 | return BUS_MESSAGE_BSWAP32(m, m->header->dbus1.serial); |
663996b3 MS |
155 | } |
156 | ||
e735f4d4 | 157 | static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) { |
663996b3 MS |
158 | return |
159 | sizeof(struct bus_header) + | |
e735f4d4 MP |
160 | ALIGN8(m->fields_size) + |
161 | m->body_size; | |
663996b3 MS |
162 | } |
163 | ||
e735f4d4 | 164 | static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) { |
14228c0d MB |
165 | return |
166 | sizeof(struct bus_header) + | |
e735f4d4 | 167 | ALIGN8(m->fields_size); |
14228c0d MB |
168 | } |
169 | ||
170 | static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) { | |
171 | return (uint8_t*) m->header + sizeof(struct bus_header); | |
172 | } | |
173 | ||
60f067b4 JS |
174 | static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) { |
175 | return m->header->version == 2; | |
663996b3 MS |
176 | } |
177 | ||
663996b3 MS |
178 | int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz); |
179 | int bus_message_read_strv_extend(sd_bus_message *m, char ***l); | |
180 | ||
181 | int bus_message_from_header( | |
60f067b4 | 182 | sd_bus *bus, |
663996b3 | 183 | void *header, |
e735f4d4 MP |
184 | size_t header_accessible, |
185 | void *footer, | |
186 | size_t footer_accessible, | |
187 | size_t message_size, | |
663996b3 | 188 | int *fds, |
b012e921 | 189 | size_t n_fds, |
663996b3 MS |
190 | const char *label, |
191 | size_t extra, | |
192 | sd_bus_message **ret); | |
193 | ||
194 | int bus_message_from_malloc( | |
60f067b4 | 195 | sd_bus *bus, |
663996b3 MS |
196 | void *buffer, |
197 | size_t length, | |
198 | int *fds, | |
b012e921 | 199 | size_t n_fds, |
663996b3 MS |
200 | const char *label, |
201 | sd_bus_message **ret); | |
202 | ||
13d276d0 MP |
203 | int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str); |
204 | int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv); | |
663996b3 | 205 | |
663996b3 MS |
206 | int bus_message_parse_fields(sd_bus_message *m); |
207 | ||
14228c0d MB |
208 | struct bus_body_part *message_append_part(sd_bus_message *m); |
209 | ||
210 | #define MESSAGE_FOREACH_PART(part, i, m) \ | |
211 | for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next) | |
212 | ||
213 | int bus_body_part_map(struct bus_body_part *part); | |
214 | void bus_body_part_unmap(struct bus_body_part *part); | |
215 | ||
216 | int bus_message_to_errno(sd_bus_message *m); | |
217 | ||
218 | int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m); | |
60f067b4 JS |
219 | |
220 | int bus_message_remarshal(sd_bus *bus, sd_bus_message **m); | |
221 | ||
e735f4d4 MP |
222 | void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m); |
223 | void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m); | |
bb4f798a MB |
224 | |
225 | sd_bus_message* bus_message_ref_queued(sd_bus_message *m, sd_bus *bus); | |
226 | sd_bus_message* bus_message_unref_queued(sd_bus_message *m, sd_bus *bus); |