1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 Copyright 2013 Lennart Poettering
10 #include <sys/socket.h>
14 #include "bus-creds.h"
15 #include "bus-protocol.h"
17 #include "time-util.h"
19 struct bus_container {
23 /* Indexes into the signature string */
24 unsigned index, saved_index;
27 size_t before, begin, end;
29 /* dbus1: pointer to the array size value, if this is a value */
32 /* gvariant: list of offsets to end of children if this is struct/dict entry/array */
33 size_t *offsets, n_offsets, offsets_allocated, offset_index;
36 char *peeked_signature;
39 struct bus_body_part {
40 struct bus_body_part *next;
46 uint64_t memfd_offset;
54 struct sd_bus_message {
59 uint64_t reply_cookie;
62 const char *interface;
64 const char *destination;
75 uint64_t verify_destination_id;
84 /* The first and last bytes of the message */
85 struct bus_header *header;
88 /* How many bytes are accessible in the above pointers */
89 size_t header_accessible;
90 size_t footer_accessible;
94 size_t user_body_size;
96 struct bus_body_part body;
97 struct bus_body_part *body_end;
98 unsigned n_body_parts;
101 struct bus_body_part *cached_rindex_part;
102 size_t cached_rindex_part_begin;
107 struct bus_container root_container, *containers;
109 size_t containers_allocated;
112 struct iovec iovec_fixed[2];
115 char *peeked_signature;
117 /* If set replies to this message must carry the signature
118 * specified here to successfully seal. This is initialized
119 * from the vtable data */
120 const char *enforced_reply_signature;
124 size_t header_offsets[_BUS_MESSAGE_HEADER_MAX];
125 unsigned n_header_offsets;
128 static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message *m) {
129 return m->header->endian != BUS_NATIVE_ENDIAN;
132 static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) {
133 return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u;
136 static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) {
137 return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u;
140 static inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) {
141 return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u;
144 static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) {
145 if (m->header->version == 2)
146 return BUS_MESSAGE_BSWAP64(m, m->header->dbus2.cookie);
148 return BUS_MESSAGE_BSWAP32(m, m->header->dbus1.serial);
151 static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) {
153 sizeof(struct bus_header) +
154 ALIGN8(m->fields_size) +
158 static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) {
160 sizeof(struct bus_header) +
161 ALIGN8(m->fields_size);
164 static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) {
165 return (uint8_t*) m->header + sizeof(struct bus_header);
168 static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) {
169 return m->header->version == 2;
172 #if 0 /// UNNEEDED by elogind
173 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
175 int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
177 int bus_message_from_header(
180 size_t header_accessible,
182 size_t footer_accessible,
188 sd_bus_message **ret);
190 int bus_message_from_malloc(
197 sd_bus_message **ret);
199 int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str);
200 int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv);
202 int bus_message_parse_fields(sd_bus_message *m);
204 struct bus_body_part *message_append_part(sd_bus_message *m);
206 #define MESSAGE_FOREACH_PART(part, i, m) \
207 for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next)
209 int bus_body_part_map(struct bus_body_part *part);
210 void bus_body_part_unmap(struct bus_body_part *part);
212 int bus_message_to_errno(sd_bus_message *m);
214 int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m);
216 int bus_message_remarshal(sd_bus *bus, sd_bus_message **m);
218 #if 0 /// UNNEEDED by elogind
219 int bus_message_append_sender(sd_bus_message *m, const char *sender);
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);