bus-message.h revision 392d5b378ceae5e1fd7c91ca545fcf4cd105744a
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
220a21d38f675eb835f5758e3d23e896573aa5eaLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering#pragma once
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers/***
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers This file is part of systemd.
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers Copyright 2013 Lennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
07cd4fc16806783d3b6b3008db222ac6a024805cKay Sievers systemd is free software; you can redistribute it and/or modify it
91cf7e5c37f97c6eb29966fac0afcbaa6662e05dTollef Fog Heen under the terms of the GNU Lesser General Public License as published by
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers the Free Software Foundation; either version 2.1 of the License, or
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers (at your option) any later version.
64661ee70d5a10c6208a1cb66ecd8b158e2d8bc5Kay Sievers
2d13da8821b8197e62f819b5b996750800e910abKay Sievers systemd is distributed in the hope that it will be useful, but
2d13da8821b8197e62f819b5b996750800e910abKay Sievers WITHOUT ANY WARRANTY; without even the implied warranty of
2d13da8821b8197e62f819b5b996750800e910abKay Sievers MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2d13da8821b8197e62f819b5b996750800e910abKay Sievers Lesser General Public License for more details.
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers You should have received a copy of the GNU Lesser General Public License
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers along with systemd; If not, see <http://www.gnu.org/licenses/>.
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers***/
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers#include <stdbool.h>
194bbe33382f5365be3865ed1779147cb680f1d3Kay Sievers#include <byteswap.h>
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers#include <sys/socket.h>
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers#include "macro.h"
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers#include "sd-bus.h"
f13b388f97bc3ba8db844bd3413d510e2466a0b6Kay Sievers
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstruct bus_container {
c195956988799837b763ab1b9f078e5f0b7f26e6Kay Sievers char enclosing;
c195956988799837b763ab1b9f078e5f0b7f26e6Kay Sievers
c195956988799837b763ab1b9f078e5f0b7f26e6Kay Sievers char *signature;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering unsigned index;
c195956988799837b763ab1b9f078e5f0b7f26e6Kay Sievers
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t *array_size;
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers size_t begin;
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers};
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sieversstruct bus_header {
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers uint8_t endian;
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers uint8_t type;
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sievers uint8_t flags;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint8_t version;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t body_size;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t serial;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t fields_size;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering} _packed_;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstruct sd_bus_message {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering unsigned n_ref;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t reply_serial;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *path;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *interface;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *member;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *destination;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *sender;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering sd_bus_error error;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uid_t uid;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering gid_t gid;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering pid_t pid;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering pid_t tid;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool sealed:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool dont_send:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool allow_fds:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool uid_valid:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool gid_valid:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool free_header:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool free_fields:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool free_body:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering bool free_fds:1;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering struct bus_header *header;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering void *fields;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering void *body;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering char *label;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering size_t rindex;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering uint32_t n_fds;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering int *fds;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering struct bus_container root_container, *containers;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering unsigned n_containers;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering struct iovec iovec[4];
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering unsigned n_iovec;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering size_t size;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering char *peeked_signature;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering};
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering#define BUS_MESSAGE_NEED_BSWAP(m) ((m)->header->endian != SD_BUS_NATIVE_ENDIAN)
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint32_t BUS_MESSAGE_BSWAP32(sd_bus_message *m, uint32_t u) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_32(u) : u;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint64_t BUS_MESSAGE_BSWAP64(sd_bus_message *m, uint64_t u) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_64(u) : u;
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint32_t BUS_MESSAGE_SERIAL(sd_bus_message *m) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_BSWAP32(m, m->header->serial);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint32_t BUS_MESSAGE_BODY_SIZE(sd_bus_message *m) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_BSWAP32(m, m->header->body_size);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline uint32_t BUS_MESSAGE_FIELDS_SIZE(sd_bus_message *m) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering return BUS_MESSAGE_BSWAP32(m, m->header->fields_size);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringstatic inline void bus_message_unrefp(sd_bus_message **m) {
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering sd_bus_message_unref(*m);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering}
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering#define _cleanup_bus_message_unref_ __attribute__((cleanup(bus_message_unrefp)))
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringint bus_message_seal(sd_bus_message *m, uint64_t serial);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringint bus_message_dump(sd_bus_message *m);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringint bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringint bus_message_read_strv_extend(sd_bus_message *m, char ***l);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringint bus_message_from_malloc(
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering void *buffer,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering size_t length,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering int *fds,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering unsigned n_fds,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const struct ucred *ucred,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering const char *label,
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering sd_bus_message **ret);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poetteringconst char* bus_message_get_arg(sd_bus_message *m, unsigned i);
ea5943d3862cc690daa76e2ad336737407ec711cLennart Poettering