From 0461f8cdc1d7b4afee2f2ff40fcaa3c7e26c662c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 3 Dec 2013 18:13:48 +0100 Subject: bus: internalize a lot of protocol definitions We shouldn export what isn't necessary or useful to clients, so let's add the protocol definitions we only need internally into a private header. --- Makefile.am | 3 +- src/libsystemd-bus/bus-control.c | 12 ++-- src/libsystemd-bus/bus-convenience.c | 10 +-- src/libsystemd-bus/bus-introspect.c | 11 +-- src/libsystemd-bus/bus-kernel.c | 4 +- src/libsystemd-bus/bus-message.c | 84 +++++++++++----------- src/libsystemd-bus/bus-message.h | 3 +- src/libsystemd-bus/bus-protocol.h | 133 +++++++++++++++++++++++++++++++++++ src/libsystemd-bus/bus-socket.c | 4 +- src/libsystemd-bus/bus-util.c | 2 +- src/libsystemd-bus/sd-bus.c | 9 +-- src/systemd/sd-bus-protocol.h | 112 +---------------------------- 12 files changed, 208 insertions(+), 179 deletions(-) create mode 100644 src/libsystemd-bus/bus-protocol.h diff --git a/Makefile.am b/Makefile.am index 7c6241440c..acf511bc4f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2004,7 +2004,8 @@ libsystemd_bus_la_SOURCES = \ src/libsystemd-bus/bus-util.h \ src/libsystemd-bus/sd-utf8.c \ src/libsystemd-bus/sd-event.c \ - src/libsystemd-bus/event-util.h + src/libsystemd-bus/event-util.h \ + src/libsystemd-bus/bus-protocol.h libsystemd_bus_la_LIBADD = \ libsystemd-id128-internal.la \ diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c index de5c20e3f8..ed10f5a683 100644 --- a/src/libsystemd-bus/bus-control.c +++ b/src/libsystemd-bus/bus-control.c @@ -104,11 +104,11 @@ static int bus_request_name_dbus1(sd_bus *bus, const char *name, unsigned flags) if (r < 0) return r; - if (ret == SD_BUS_NAME_ALREADY_OWNER) + if (ret == BUS_NAME_ALREADY_OWNER) return -EALREADY; - else if (ret == SD_BUS_NAME_EXISTS) + else if (ret == BUS_NAME_EXISTS) return -EEXIST; - else if (ret == SD_BUS_NAME_IN_QUEUE) + else if (ret == BUS_NAME_IN_QUEUE) return 0; else return -EIO; @@ -177,11 +177,11 @@ static int bus_release_name_dbus1(sd_bus *bus, const char *name) { r = sd_bus_message_read(reply, "u", &ret); if (r < 0) return r; - if (ret == SD_BUS_NAME_NON_EXISTENT) + if (ret == BUS_NAME_NON_EXISTENT) return -ENOENT; - if (ret == SD_BUS_NAME_NOT_OWNER) + if (ret == BUS_NAME_NOT_OWNER) return -EADDRNOTAVAIL; - if (ret == SD_BUS_NAME_RELEASED) + if (ret == BUS_NAME_RELEASED) return 0; return -EINVAL; diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c index d4c1929ff7..3964960fab 100644 --- a/src/libsystemd-bus/bus-convenience.c +++ b/src/libsystemd-bus/bus-convenience.c @@ -103,7 +103,7 @@ _public_ int sd_bus_reply_method_return( assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN); assert_return(!bus_pid_changed(call->bus), -ECHILD); - if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; r = sd_bus_message_new_method_return(call, &m); @@ -137,7 +137,7 @@ _public_ int sd_bus_reply_method_error( assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN); assert_return(!bus_pid_changed(call->bus), -ECHILD); - if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; r = sd_bus_message_new_method_error(call, e, &m); @@ -162,7 +162,7 @@ _public_ int sd_bus_reply_method_errorf( assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN); assert_return(!bus_pid_changed(call->bus), -ECHILD); - if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; va_start(ap, format); @@ -185,7 +185,7 @@ _public_ int sd_bus_reply_method_errno( assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN); assert_return(!bus_pid_changed(call->bus), -ECHILD); - if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; if (sd_bus_error_is_set(p)) @@ -211,7 +211,7 @@ _public_ int sd_bus_reply_method_errnof( assert_return(call->bus && BUS_IS_OPEN(call->bus->state), -ENOTCONN); assert_return(!bus_pid_changed(call->bus), -ECHILD); - if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; va_start(ap, format); diff --git a/src/libsystemd-bus/bus-introspect.c b/src/libsystemd-bus/bus-introspect.c index 1965364cd0..115b3ceae8 100644 --- a/src/libsystemd-bus/bus-introspect.c +++ b/src/libsystemd-bus/bus-introspect.c @@ -24,6 +24,7 @@ #include "bus-introspect.h" #include "bus-signature.h" #include "bus-internal.h" +#include "bus-protocol.h" int introspect_begin(struct introspect *i) { assert(i); @@ -34,7 +35,7 @@ int introspect_begin(struct introspect *i) { if (!i->f) return -ENOMEM; - fputs(SD_BUS_INTROSPECT_DOCTYPE + fputs(BUS_INTROSPECT_DOCTYPE "\n", i->f); return 0; @@ -43,12 +44,12 @@ int introspect_begin(struct introspect *i) { int introspect_write_default_interfaces(struct introspect *i, bool object_manager) { assert(i); - fputs(SD_BUS_INTROSPECT_INTERFACE_PEER - SD_BUS_INTROSPECT_INTERFACE_INTROSPECTABLE - SD_BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f); + fputs(BUS_INTROSPECT_INTERFACE_PEER + BUS_INTROSPECT_INTERFACE_INTROSPECTABLE + BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f); if (object_manager) - fputs(SD_BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f); + fputs(BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f); return 0; } diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index ca36eb8638..b85a10dd38 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -248,8 +248,8 @@ static int bus_message_setup_kmsg(sd_bus *b, sd_bus_message *m) { memset(m->kdbus, 0, sz); m->kdbus->flags = - ((m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) ? 0 : KDBUS_MSG_FLAGS_EXPECT_REPLY) | - ((m->header->flags & SD_BUS_MESSAGE_NO_AUTO_START) ? KDBUS_MSG_FLAGS_NO_AUTO_START : 0); + ((m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) ? 0 : KDBUS_MSG_FLAGS_EXPECT_REPLY) | + ((m->header->flags & BUS_MESSAGE_NO_AUTO_START) ? KDBUS_MSG_FLAGS_NO_AUTO_START : 0); m->kdbus->dst_id = well_known ? 0 : m->destination ? unique : KDBUS_DST_ID_BROADCAST; diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index dc85694471..0cfbf5a65b 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -332,8 +332,8 @@ int bus_message_from_header( if (h->type == _SD_BUS_MESSAGE_TYPE_INVALID) return -EBADMSG; - if (h->endian != SD_BUS_LITTLE_ENDIAN && - h->endian != SD_BUS_BIG_ENDIAN) + if (h->endian != BUS_LITTLE_ENDIAN && + h->endian != BUS_BIG_ENDIAN) return -EBADMSG; a = ALIGN(sizeof(sd_bus_message)) + ALIGN(extra); @@ -436,7 +436,7 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) { m->n_ref = 1; m->header = (struct bus_header*) ((uint8_t*) m + ALIGN(sizeof(struct sd_bus_message))); - m->header->endian = SD_BUS_NATIVE_ENDIAN; + m->header->endian = BUS_NATIVE_ENDIAN; m->header->type = type; m->header->version = bus ? bus->message_version : 1; m->allow_fds = !bus || bus->can_fds || (bus->state != BUS_HELLO && bus->state != BUS_RUNNING); @@ -467,15 +467,15 @@ _public_ int sd_bus_message_new_signal( if (!t) return -ENOMEM; - t->header->flags |= SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path); if (r < 0) goto fail; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface); if (r < 0) goto fail; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member); if (r < 0) goto fail; @@ -509,21 +509,21 @@ _public_ int sd_bus_message_new_method_call( if (!t) return -ENOMEM; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path); if (r < 0) goto fail; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member); if (r < 0) goto fail; if (interface) { - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface); if (r < 0) goto fail; } if (destination) { - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &t->destination); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &t->destination); if (r < 0) goto fail; } @@ -554,20 +554,20 @@ static int message_new_reply( if (!t) return -ENOMEM; - t->header->flags |= SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED; t->reply_serial = BUS_MESSAGE_SERIAL(call); - r = message_append_field_uint32(t, SD_BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial); + r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial); if (r < 0) goto fail; if (call->sender) { - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, call->sender, &t->destination); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, call->sender, &t->destination); if (r < 0) goto fail; } - t->dont_send = !!(call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED); + t->dont_send = !!(call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED); t->enforced_reply_signature = call->enforced_reply_signature; *m = t; @@ -600,7 +600,7 @@ _public_ int sd_bus_message_new_method_error( if (r < 0) return r; - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name); if (r < 0) goto fail; @@ -689,20 +689,20 @@ int bus_message_new_synthetic_error( if (!t) return -ENOMEM; - t->header->flags |= SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED; t->reply_serial = serial; - r = message_append_field_uint32(t, SD_BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial); + r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_serial); if (r < 0) goto fail; if (bus && bus->unique_name) { - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, bus->unique_name, &t->destination); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, bus->unique_name, &t->destination); if (r < 0) goto fail; } - r = message_append_field_string(t, SD_BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name); + r = message_append_field_string(t, BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name); if (r < 0) goto fail; @@ -772,13 +772,13 @@ _public_ int sd_bus_message_get_reply_serial(sd_bus_message *m, uint64_t *serial _public_ int sd_bus_message_get_no_reply(sd_bus_message *m) { assert_return(m, -EINVAL); - return m->header->type == SD_BUS_MESSAGE_METHOD_CALL ? !!(m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) : 0; + return m->header->type == SD_BUS_MESSAGE_METHOD_CALL ? !!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) : 0; } _public_ int sd_bus_message_get_no_auto_start(sd_bus_message *m) { assert_return(m, -EINVAL); - return !!(m->header->flags & SD_BUS_MESSAGE_NO_AUTO_START); + return !!(m->header->flags & BUS_MESSAGE_NO_AUTO_START); } _public_ const char *sd_bus_message_get_path(sd_bus_message *m) { @@ -897,9 +897,9 @@ _public_ int sd_bus_message_set_no_reply(sd_bus_message *m, int b) { assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EPERM); if (b) - m->header->flags |= SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED; else - m->header->flags &= ~SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + m->header->flags &= ~BUS_MESSAGE_NO_REPLY_EXPECTED; return 0; } @@ -909,9 +909,9 @@ _public_ int sd_bus_message_set_no_auto_start(sd_bus_message *m, int b) { assert_return(!m->sealed, -EPERM); if (b) - m->header->flags |= SD_BUS_MESSAGE_NO_AUTO_START; + m->header->flags |= BUS_MESSAGE_NO_AUTO_START; else - m->header->flags &= ~SD_BUS_MESSAGE_NO_AUTO_START; + m->header->flags &= ~BUS_MESSAGE_NO_AUTO_START; return 0; } @@ -3764,10 +3764,10 @@ int bus_message_parse_fields(sd_bus_message *m) { return r; switch (*header) { - case _SD_BUS_MESSAGE_HEADER_INVALID: + case _BUS_MESSAGE_HEADER_INVALID: return -EBADMSG; - case SD_BUS_MESSAGE_HEADER_PATH: + case BUS_MESSAGE_HEADER_PATH: if (m->path) return -EBADMSG; @@ -3778,7 +3778,7 @@ int bus_message_parse_fields(sd_bus_message *m) { r = message_peek_field_string(m, object_path_is_valid, &ri, &m->path); break; - case SD_BUS_MESSAGE_HEADER_INTERFACE: + case BUS_MESSAGE_HEADER_INTERFACE: if (m->interface) return -EBADMSG; @@ -3789,7 +3789,7 @@ int bus_message_parse_fields(sd_bus_message *m) { r = message_peek_field_string(m, interface_name_is_valid, &ri, &m->interface); break; - case SD_BUS_MESSAGE_HEADER_MEMBER: + case BUS_MESSAGE_HEADER_MEMBER: if (m->member) return -EBADMSG; @@ -3800,7 +3800,7 @@ int bus_message_parse_fields(sd_bus_message *m) { r = message_peek_field_string(m, member_name_is_valid, &ri, &m->member); break; - case SD_BUS_MESSAGE_HEADER_ERROR_NAME: + case BUS_MESSAGE_HEADER_ERROR_NAME: if (m->error.name) return -EBADMSG; @@ -3814,7 +3814,7 @@ int bus_message_parse_fields(sd_bus_message *m) { break; - case SD_BUS_MESSAGE_HEADER_DESTINATION: + case BUS_MESSAGE_HEADER_DESTINATION: if (m->destination) return -EBADMSG; @@ -3825,7 +3825,7 @@ int bus_message_parse_fields(sd_bus_message *m) { r = message_peek_field_string(m, service_name_is_valid, &ri, &m->destination); break; - case SD_BUS_MESSAGE_HEADER_SENDER: + case BUS_MESSAGE_HEADER_SENDER: if (m->sender) return -EBADMSG; @@ -3843,7 +3843,7 @@ int bus_message_parse_fields(sd_bus_message *m) { break; - case SD_BUS_MESSAGE_HEADER_SIGNATURE: { + case BUS_MESSAGE_HEADER_SIGNATURE: { const char *s; char *c; @@ -3866,7 +3866,7 @@ int bus_message_parse_fields(sd_bus_message *m) { break; } - case SD_BUS_MESSAGE_HEADER_REPLY_SERIAL: + case BUS_MESSAGE_HEADER_REPLY_SERIAL: if (m->reply_serial != 0) return -EBADMSG; @@ -3882,7 +3882,7 @@ int bus_message_parse_fields(sd_bus_message *m) { break; - case SD_BUS_MESSAGE_HEADER_UNIX_FDS: + case BUS_MESSAGE_HEADER_UNIX_FDS: if (unix_fds != 0) return -EBADMSG; @@ -3972,13 +3972,13 @@ int bus_message_seal(sd_bus_message *m, uint64_t serial) { /* If there's a non-trivial signature set, then add it in here */ if (!isempty(m->root_container.signature)) { - r = message_append_field_signature(m, SD_BUS_MESSAGE_HEADER_SIGNATURE, m->root_container.signature, NULL); + r = message_append_field_signature(m, BUS_MESSAGE_HEADER_SIGNATURE, m->root_container.signature, NULL); if (r < 0) return r; } if (m->n_fds > 0) { - r = message_append_field_uint32(m, SD_BUS_MESSAGE_HEADER_UNIX_FDS, m->n_fds); + r = message_append_field_uint32(m, BUS_MESSAGE_HEADER_UNIX_FDS, m->n_fds); if (r < 0) return r; } @@ -4017,7 +4017,7 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti assert_return(!m->sealed, -EPERM); assert_return(!m->destination, -EEXIST); - return message_append_field_string(m, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination); + return message_append_field_string(m, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination); } int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) { @@ -4138,7 +4138,7 @@ bool bus_header_is_complete(struct bus_header *h, size_t size) { return false; full = sizeof(struct bus_header) + - (h->endian == SD_BUS_NATIVE_ENDIAN ? h->fields_size : bswap_32(h->fields_size)); + (h->endian == BUS_NATIVE_ENDIAN ? h->fields_size : bswap_32(h->fields_size)); return size >= full; } @@ -4149,10 +4149,10 @@ int bus_header_message_size(struct bus_header *h, size_t *sum) { assert(h); assert(sum); - if (h->endian == SD_BUS_NATIVE_ENDIAN) { + if (h->endian == BUS_NATIVE_ENDIAN) { fs = h->fields_size; bs = h->body_size; - } else if (h->endian == SD_BUS_REVERSE_ENDIAN) { + } else if (h->endian == BUS_REVERSE_ENDIAN) { fs = bswap_32(h->fields_size); bs = bswap_32(h->body_size); } else diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h index 34dbc5d563..55956adf1d 100644 --- a/src/libsystemd-bus/bus-message.h +++ b/src/libsystemd-bus/bus-message.h @@ -30,6 +30,7 @@ #include "kdbus.h" #include "time-util.h" #include "bus-creds.h" +#include "bus-protocol.h" struct bus_container { char enclosing; @@ -127,7 +128,7 @@ struct sd_bus_message { char destination_buffer[3 + DECIMAL_STR_MAX(uint64_t) + 1]; }; -#define BUS_MESSAGE_NEED_BSWAP(m) ((m)->header->endian != SD_BUS_NATIVE_ENDIAN) +#define BUS_MESSAGE_NEED_BSWAP(m) ((m)->header->endian != BUS_NATIVE_ENDIAN) static inline uint16_t BUS_MESSAGE_BSWAP16(sd_bus_message *m, uint16_t u) { return BUS_MESSAGE_NEED_BSWAP(m) ? bswap_16(u) : u; diff --git a/src/libsystemd-bus/bus-protocol.h b/src/libsystemd-bus/bus-protocol.h new file mode 100644 index 0000000000..982461bd9d --- /dev/null +++ b/src/libsystemd-bus/bus-protocol.h @@ -0,0 +1,133 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2013 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + + +/* Endianness */ + +enum { + _BUS_INVALID_ENDIAN = 0, + BUS_LITTLE_ENDIAN = 'l', + BUS_BIG_ENDIAN = 'B', +#if __BYTE_ORDER == __BIG_ENDIAN + BUS_NATIVE_ENDIAN = BUS_BIG_ENDIAN, + BUS_REVERSE_ENDIAN = BUS_LITTLE_ENDIAN +#else + BUS_NATIVE_ENDIAN = BUS_LITTLE_ENDIAN, + BUS_REVERSE_ENDIAN = BUS_BIG_ENDIAN +#endif +}; + +/* Flags */ + +enum { + BUS_MESSAGE_NO_REPLY_EXPECTED = 1, + BUS_MESSAGE_NO_AUTO_START = 2 +}; + +/* Header fields */ + +enum { + _BUS_MESSAGE_HEADER_INVALID = 0, + BUS_MESSAGE_HEADER_PATH, + BUS_MESSAGE_HEADER_INTERFACE, + BUS_MESSAGE_HEADER_MEMBER, + BUS_MESSAGE_HEADER_ERROR_NAME, + BUS_MESSAGE_HEADER_REPLY_SERIAL, + BUS_MESSAGE_HEADER_DESTINATION, + BUS_MESSAGE_HEADER_SENDER, + BUS_MESSAGE_HEADER_SIGNATURE, + BUS_MESSAGE_HEADER_UNIX_FDS, + _BUS_MESSAGE_HEADER_MAX +}; + +/* RequestName returns */ +enum { + BUS_NAME_PRIMARY_OWNER = 1, + BUS_NAME_IN_QUEUE = 2, + BUS_NAME_EXISTS = 3, + BUS_NAME_ALREADY_OWNER = 4 +}; + +/* ReleaseName returns */ +enum { + BUS_NAME_RELEASED = 1, + BUS_NAME_NON_EXISTENT = 2, + BUS_NAME_NOT_OWNER = 3, +}; + +#define BUS_INTROSPECT_DOCTYPE \ + "\n" + +#define BUS_INTROSPECT_INTERFACE_PEER \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" + +#define BUS_INTROSPECT_INTERFACE_INTROSPECTABLE \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" + +#define BUS_INTROSPECT_INTERFACE_PROPERTIES \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" + +#define BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c index d7d3b4dac5..69f78c9a58 100644 --- a/src/libsystemd-bus/bus-socket.c +++ b/src/libsystemd-bus/bus-socket.c @@ -874,10 +874,10 @@ static int bus_socket_read_message_need(sd_bus *bus, size_t *need) { b = ((const uint32_t*) bus->rbuffer)[3]; e = ((const uint8_t*) bus->rbuffer)[0]; - if (e == SD_BUS_LITTLE_ENDIAN) { + if (e == BUS_LITTLE_ENDIAN) { a = le32toh(a); b = le32toh(b); - } else if (e == SD_BUS_BIG_ENDIAN) { + } else if (e == BUS_BIG_ENDIAN) { a = be32toh(a); b = be32toh(b); } else diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c index bd005262eb..1945f47994 100644 --- a/src/libsystemd-bus/bus-util.c +++ b/src/libsystemd-bus/bus-util.c @@ -66,7 +66,7 @@ int bus_async_unregister_and_quit(sd_event *e, sd_bus *bus, const char *name) { if (r < 0) return r; - if (r != SD_BUS_NAME_RELEASED) + if (r != BUS_NAME_RELEASED) return -EIO; return 0; diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c index a86e33ce27..fef122bf3e 100644 --- a/src/libsystemd-bus/sd-bus.c +++ b/src/libsystemd-bus/sd-bus.c @@ -47,6 +47,7 @@ #include "bus-objects.h" #include "bus-util.h" #include "bus-container.h" +#include "bus-protocol.h" static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec); @@ -1408,7 +1409,7 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial) { /* If the serial number isn't kept, then we know that no reply * is expected */ if (!serial && !m->sealed) - m->header->flags |= SD_BUS_MESSAGE_NO_REPLY_EXPECTED; + m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED; r = bus_seal_message(bus, m); if (r < 0) @@ -1524,7 +1525,7 @@ _public_ int sd_bus_call_async( assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(m, -EINVAL); assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL); - assert_return(!(m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); + assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); assert_return(callback, -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); @@ -1634,7 +1635,7 @@ _public_ int sd_bus_call( assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); assert_return(m, -EINVAL); assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EINVAL); - assert_return(!(m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); + assert_return(!(m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED), -EINVAL); assert_return(!bus_error_is_dirty(error), -EINVAL); assert_return(!bus_pid_changed(bus), -ECHILD); @@ -1976,7 +1977,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) { if (!streq_ptr(m->interface, "org.freedesktop.DBus.Peer")) return 0; - if (m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) + if (m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 1; if (streq_ptr(m->member, "Ping")) diff --git a/src/systemd/sd-bus-protocol.h b/src/systemd/sd-bus-protocol.h index 07fade6039..b2db7e46b8 100644 --- a/src/systemd/sd-bus-protocol.h +++ b/src/systemd/sd-bus-protocol.h @@ -66,125 +66,17 @@ enum { SD_BUS_TYPE_DICT_ENTRY_END = '}', }; -/* Endianness */ - -enum { - _SD_BUS_INVALID_ENDIAN = 0, - SD_BUS_LITTLE_ENDIAN = 'l', - SD_BUS_BIG_ENDIAN = 'B', -#if __BYTE_ORDER == __BIG_ENDIAN - SD_BUS_NATIVE_ENDIAN = SD_BUS_BIG_ENDIAN, - SD_BUS_REVERSE_ENDIAN = SD_BUS_LITTLE_ENDIAN -#else - SD_BUS_NATIVE_ENDIAN = SD_BUS_LITTLE_ENDIAN, - SD_BUS_REVERSE_ENDIAN = SD_BUS_BIG_ENDIAN -#endif -}; - -/* Flags */ - -enum { - SD_BUS_MESSAGE_NO_REPLY_EXPECTED = 1, - SD_BUS_MESSAGE_NO_AUTO_START = 2 -}; - -/* Header fields */ - -enum { - _SD_BUS_MESSAGE_HEADER_INVALID = 0, - SD_BUS_MESSAGE_HEADER_PATH, - SD_BUS_MESSAGE_HEADER_INTERFACE, - SD_BUS_MESSAGE_HEADER_MEMBER, - SD_BUS_MESSAGE_HEADER_ERROR_NAME, - SD_BUS_MESSAGE_HEADER_REPLY_SERIAL, - SD_BUS_MESSAGE_HEADER_DESTINATION, - SD_BUS_MESSAGE_HEADER_SENDER, - SD_BUS_MESSAGE_HEADER_SIGNATURE, - SD_BUS_MESSAGE_HEADER_UNIX_FDS, - _SD_BUS_MESSAGE_HEADER_MAX -}; - /* RequestName parameters */ + enum { SD_BUS_NAME_ALLOW_REPLACEMENT = 1, SD_BUS_NAME_REPLACE_EXISTING = 2, SD_BUS_NAME_DO_NOT_QUEUE = 4 }; -/* RequestName returns */ -enum { - SD_BUS_NAME_PRIMARY_OWNER = 1, - SD_BUS_NAME_IN_QUEUE = 2, - SD_BUS_NAME_EXISTS = 3, - SD_BUS_NAME_ALREADY_OWNER = 4 -}; - -/* ReleaseName returns */ -enum { - SD_BUS_NAME_RELEASED = 1, - SD_BUS_NAME_NON_EXISTENT = 2, - SD_BUS_NAME_NOT_OWNER = 3, -}; - -#define SD_BUS_INTROSPECT_DOCTYPE \ - "\n" - -#define SD_BUS_INTROSPECT_INTERFACE_PEER \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" - -#define SD_BUS_INTROSPECT_INTERFACE_INTROSPECTABLE \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" - -#define SD_BUS_INTROSPECT_INTERFACE_PROPERTIES \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" - -#define SD_BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" \ - " \n" - /* Well-known errors. Note that this is only a sanitized subset of the * errors that the reference implementation generates. */ + #define SD_BUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed" #define SD_BUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory" #define SD_BUS_ERROR_SERVICE_UNKNOWN "org.freedesktop.DBus.Error.ServiceUnknown" -- cgit v1.2.3-54-g00ecf