1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include <sys/socket.h>
10 #include "bus-creds.h"
11 #include "bus-protocol.h"
13 #include "time-util.h"
15 struct bus_container
{
19 /* Indexes into the signature string */
20 unsigned index
, saved_index
;
23 size_t before
, begin
, end
;
25 /* dbus1: pointer to the array size value, if this is a value */
28 /* gvariant: list of offsets to end of children if this is struct/dict entry/array */
29 size_t *offsets
, n_offsets
, offsets_allocated
, offset_index
;
32 char *peeked_signature
;
35 struct bus_body_part
{
36 struct bus_body_part
*next
;
42 uint64_t memfd_offset
;
50 struct sd_bus_message
{
55 uint64_t reply_cookie
;
58 const char *interface
;
60 const char *destination
;
71 uint64_t verify_destination_id
;
80 /* The first and last bytes of the message */
81 struct bus_header
*header
;
84 /* How many bytes are accessible in the above pointers */
85 size_t header_accessible
;
86 size_t footer_accessible
;
90 size_t user_body_size
;
92 struct bus_body_part body
;
93 struct bus_body_part
*body_end
;
94 unsigned n_body_parts
;
97 struct bus_body_part
*cached_rindex_part
;
98 size_t cached_rindex_part_begin
;
103 struct bus_container root_container
, *containers
;
105 size_t containers_allocated
;
108 struct iovec iovec_fixed
[2];
111 char *peeked_signature
;
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
;
120 size_t header_offsets
[_BUS_MESSAGE_HEADER_MAX
];
121 unsigned n_header_offsets
;
124 static inline bool BUS_MESSAGE_NEED_BSWAP(sd_bus_message
*m
) {
125 return m
->header
->endian
!= BUS_NATIVE_ENDIAN
;
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
;
132 static inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message
*m
, uint32_t u
) {
133 return BUS_MESSAGE_NEED_BSWAP(m
) ? bswap_32(u
) : u
;
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
;
140 static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message
*m
) {
141 if (m
->header
->version
== 2)
142 return BUS_MESSAGE_BSWAP64(m
, m
->header
->dbus2
.cookie
);
144 return BUS_MESSAGE_BSWAP32(m
, m
->header
->dbus1
.serial
);
147 static inline size_t BUS_MESSAGE_SIZE(sd_bus_message
*m
) {
149 sizeof(struct bus_header
) +
150 ALIGN8(m
->fields_size
) +
154 static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message
*m
) {
156 sizeof(struct bus_header
) +
157 ALIGN8(m
->fields_size
);
160 static inline void* BUS_MESSAGE_FIELDS(sd_bus_message
*m
) {
161 return (uint8_t*) m
->header
+ sizeof(struct bus_header
);
164 static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message
*m
) {
165 return m
->header
->version
== 2;
168 int bus_message_get_blob(sd_bus_message
*m
, void **buffer
, size_t *sz
);
169 int bus_message_read_strv_extend(sd_bus_message
*m
, char ***l
);
171 int bus_message_from_header(
174 size_t header_accessible
,
176 size_t footer_accessible
,
182 sd_bus_message
**ret
);
184 int bus_message_from_malloc(
191 sd_bus_message
**ret
);
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
);
196 int bus_message_parse_fields(sd_bus_message
*m
);
198 struct bus_body_part
*message_append_part(sd_bus_message
*m
);
200 #define MESSAGE_FOREACH_PART(part, i, m) \
201 for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next)
203 int bus_body_part_map(struct bus_body_part
*part
);
204 void bus_body_part_unmap(struct bus_body_part
*part
);
206 int bus_message_to_errno(sd_bus_message
*m
);
208 int bus_message_new_synthetic_error(sd_bus
*bus
, uint64_t serial
, const sd_bus_error
*e
, sd_bus_message
**m
);
210 int bus_message_remarshal(sd_bus
*bus
, sd_bus_message
**m
);
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
);