}
int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) {
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
size_t msglen, caplen, pad;
uint32_t length;
uint64_t ts;
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "forward.h"
+
+typedef enum BusAuth BusAuth;
+typedef enum BusSlotType BusSlotType;
+typedef enum BusState BusState;
+
+typedef struct BusFilterCallback BusFilterCallback;
+
+typedef struct BusMatchCallback BusMatchCallback;
+typedef struct BusMatchComponent BusMatchComponent;
+typedef struct BusMatchNode BusMatchNode;
+typedef enum BusMatchNodeType BusMatchNodeType;
+typedef enum BusMatchScope BusMatchScope;
+
+typedef struct BusNode BusNode;
+typedef struct BusNodeCallback BusNodeCallback;
+typedef struct BusNodeEnumerator BusNodeEnumerator;
+typedef struct BusNodeObjectManager BusNodeObjectManager;
+typedef struct BusNodeVTable BusNodeVTable;
+typedef struct BusVTableMember BusVTableMember;
+
+typedef struct BusReplyCallback BusReplyCallback;
+
+typedef struct BusMessageBodyPart BusMessageBodyPart;
+typedef struct BusMessageContainer BusMessageContainer;
+typedef struct BusMessageHeader BusMessageHeader;
+
+typedef struct BusIntrospect BusIntrospect;
#include "sd-id128.h"
+#include "bus-forward.h"
#include "bus-kernel.h"
#include "bus-match.h"
#include "constants.h"
-#include "forward.h"
#include "list.h"
#include "runtime-scope.h"
#include "socket-util.h"
#define DEFAULT_SYSTEM_BUS_ADDRESS "unix:path=/run/dbus/system_bus_socket"
#define DEFAULT_USER_BUS_ADDRESS_FMT "unix:path=%s/bus"
-struct reply_callback {
+typedef struct BusReplyCallback {
sd_bus_message_handler_t callback;
usec_t timeout_usec; /* this is a relative timeout until we reach the BUS_HELLO state, and an absolute one right after */
uint64_t cookie;
unsigned prioq_idx;
-};
+} BusReplyCallback;
-struct filter_callback {
+typedef struct BusFilterCallback {
sd_bus_message_handler_t callback;
unsigned last_iteration;
- LIST_FIELDS(struct filter_callback, callbacks);
-};
+ LIST_FIELDS(BusFilterCallback, callbacks);
+} BusFilterCallback;
-struct match_callback {
- sd_bus_message_handler_t callback;
- sd_bus_message_handler_t install_callback;
-
- sd_bus_slot *install_slot; /* The AddMatch() call */
-
- unsigned last_iteration;
-
- /* Don't dispatch this slot with messages that arrived in any iteration before or at the this
- * one. We use this to ensure that matches don't apply "retroactively" and confuse the caller:
- * only messages received after the match was installed will be considered. */
- uint64_t after;
-
- char *match_string;
-
- struct bus_match_node *match_node;
-};
-
-struct node {
+typedef struct BusNode {
char *path;
- struct node *parent;
- LIST_HEAD(struct node, child);
- LIST_FIELDS(struct node, siblings);
+ BusNode *parent;
+ LIST_HEAD(BusNode, child);
+ LIST_FIELDS(BusNode, siblings);
- LIST_HEAD(struct node_callback, callbacks);
- LIST_HEAD(struct node_vtable, vtables);
- LIST_HEAD(struct node_enumerator, enumerators);
- LIST_HEAD(struct node_object_manager, object_managers);
-};
+ LIST_HEAD(BusNodeCallback, callbacks);
+ LIST_HEAD(BusNodeVTable, vtables);
+ LIST_HEAD(BusNodeEnumerator, enumerators);
+ LIST_HEAD(BusNodeObjectManager, object_managers);
+} BusNode;
-struct node_callback {
- struct node *node;
+typedef struct BusNodeCallback {
+ BusNode *node;
bool is_fallback;
unsigned last_iteration;
sd_bus_message_handler_t callback;
- LIST_FIELDS(struct node_callback, callbacks);
-};
+ LIST_FIELDS(BusNodeCallback, callbacks);
+} BusNodeCallback;
-struct node_enumerator {
- struct node *node;
+typedef struct BusNodeEnumerator {
+ BusNode *node;
sd_bus_node_enumerator_t callback;
unsigned last_iteration;
- LIST_FIELDS(struct node_enumerator, enumerators);
-};
+ LIST_FIELDS(BusNodeEnumerator, enumerators);
+} BusNodeEnumerator;
-struct node_object_manager {
- struct node *node;
+typedef struct BusNodeObjectManager {
+ BusNode *node;
- LIST_FIELDS(struct node_object_manager, object_managers);
-};
+ LIST_FIELDS(BusNodeObjectManager, object_managers);
+} BusNodeObjectManager;
-struct node_vtable {
- struct node *node;
+typedef struct BusNodeVTable {
+ BusNode *node;
bool is_fallback;
unsigned last_iteration;
const sd_bus_vtable *vtable;
sd_bus_object_find_t find;
- LIST_FIELDS(struct node_vtable, vtables);
-};
+ LIST_FIELDS(BusNodeVTable, vtables);
+} BusNodeVTable;
-struct vtable_member {
+typedef struct BusVTableMember {
const char *path;
const char *interface;
const char *member;
- struct node_vtable *parent;
+ BusNodeVTable *parent;
unsigned last_iteration;
const sd_bus_vtable *vtable;
-};
+} BusVTableMember;
typedef enum BusSlotType {
BUS_REPLY_CALLBACK,
LIST_FIELDS(sd_bus_slot, slots);
union {
- struct reply_callback reply_callback;
- struct filter_callback filter_callback;
- struct match_callback match_callback;
- struct node_callback node_callback;
- struct node_enumerator node_enumerator;
- struct node_object_manager node_object_manager;
- struct node_vtable node_vtable;
+ BusReplyCallback reply_callback;
+ BusFilterCallback filter_callback;
+ BusMatchCallback match_callback;
+ BusNodeCallback node_callback;
+ BusNodeEnumerator node_enumerator;
+ BusNodeObjectManager node_object_manager;
+ BusNodeVTable node_vtable;
};
} sd_bus_slot;
-enum bus_state {
+typedef enum BusState {
BUS_UNSET,
BUS_WATCH_BIND, /* waiting for the socket to appear via inotify */
BUS_OPENING, /* the kernel's connect() is still not ready */
BUS_CLOSING,
BUS_CLOSED,
_BUS_STATE_MAX,
-};
+} BusState;
-static inline bool BUS_IS_OPEN(enum bus_state state) {
+static inline bool BUS_IS_OPEN(BusState state) {
return state > BUS_UNSET && state < BUS_CLOSING;
}
-enum bus_auth {
+typedef enum BusAuth {
_BUS_AUTH_INVALID,
BUS_AUTH_EXTERNAL,
BUS_AUTH_ANONYMOUS
-};
+} BusAuth;
typedef struct sd_bus {
unsigned n_ref;
- enum bus_state state;
+ BusState state;
int input_fd, output_fd;
int inotify_fd;
int message_version;
char *unique_name;
uint64_t unique_id;
- struct bus_match_node match_callbacks;
+ BusMatchNode match_callbacks;
Prioq *reply_callbacks_prioq;
OrderedHashmap *reply_callbacks;
- LIST_HEAD(struct filter_callback, filter_callbacks);
+ LIST_HEAD(BusFilterCallback, filter_callbacks);
Hashmap *nodes;
Set *vtable_methods;
int last_connect_error;
- enum bus_auth auth;
+ BusAuth auth;
unsigned auth_index;
struct iovec auth_iovec[3];
size_t auth_rbegin;
void bus_enter_closing(sd_bus *bus);
-void bus_set_state(sd_bus *bus, enum bus_state state);
+void bus_set_state(sd_bus *bus, BusState state);
" </signal>\n" \
" </interface>\n"
-int introspect_begin(struct introspect *i, bool trusted) {
+int introspect_begin(BusIntrospect *i, bool trusted) {
FILE *f;
assert(i);
- *i = (struct introspect) {
+ *i = (BusIntrospect) {
.trusted = trusted,
};
return 0;
}
-int introspect_write_default_interfaces(struct introspect *i, bool object_manager) {
+int introspect_write_default_interfaces(BusIntrospect *i, bool object_manager) {
assert(i);
assert(i->m.f);
return 0;
}
-static int set_interface_name(struct introspect *i, const char *interface_name) {
+static int set_interface_name(BusIntrospect *i, const char *interface_name) {
assert(i);
assert(i->m.f);
return free_and_strdup(&i->interface_name, interface_name);
}
-int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix) {
+int introspect_write_child_nodes(BusIntrospect *i, OrderedSet *s, const char *prefix) {
char *node;
assert(i);
return 0;
}
-static void introspect_write_flags(struct introspect *i, int type, uint64_t flags) {
+static void introspect_write_flags(BusIntrospect *i, int type, uint64_t flags) {
assert(i);
assert(i->m.f);
/* Note that "names" is both an input and an output parameter. It initially points to the first argument name in a
NULL-separated list of strings, and is then advanced with each argument, and the resulting pointer is returned. */
-static int introspect_write_arguments(struct introspect *i, const char *signature, const char **names, const char *direction) {
+static int introspect_write_arguments(BusIntrospect *i, const char *signature, const char **names, const char *direction) {
int r;
assert(i);
}
int introspect_write_interface(
- struct introspect *i,
+ BusIntrospect *i,
const char *interface_name,
const sd_bus_vtable *v) {
return 0;
}
-int introspect_finish(struct introspect *i, char **ret) {
+int introspect_finish(BusIntrospect *i, char **ret) {
assert(i);
assert(i->m.f);
return memstream_finalize(&i->m, ret, NULL);
}
-void introspect_done(struct introspect *i) {
+void introspect_done(BusIntrospect *i) {
assert(i);
/* Normally introspect_finish() does all the work, this is just a backup for error paths */
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include "forward.h"
+#include "bus-forward.h"
#include "memstream-util.h"
-struct introspect {
+typedef struct BusIntrospect {
MemStream m;
char *interface_name;
bool trusted;
-};
+} BusIntrospect;
-int introspect_begin(struct introspect *i, bool trusted);
-int introspect_write_default_interfaces(struct introspect *i, bool object_manager);
-int introspect_write_child_nodes(struct introspect *i, OrderedSet *s, const char *prefix);
+int introspect_begin(BusIntrospect *i, bool trusted);
+int introspect_write_default_interfaces(BusIntrospect *i, bool object_manager);
+int introspect_write_child_nodes(BusIntrospect *i, OrderedSet *s, const char *prefix);
int introspect_write_interface(
- struct introspect *i,
+ BusIntrospect *i,
const char *interface_name,
const sd_bus_vtable *v);
-int introspect_finish(struct introspect *i, char **ret);
-void introspect_done(struct introspect *i);
+int introspect_finish(BusIntrospect *i, char **ret);
+void introspect_done(BusIntrospect *i);
* ` BUS_MATCH_LEAF: E
*/
-static bool BUS_MATCH_IS_COMPARE(enum bus_match_node_type t) {
+static bool BUS_MATCH_IS_COMPARE(BusMatchNodeType t) {
return t >= BUS_MATCH_SENDER && t <= BUS_MATCH_ARG_HAS_LAST;
}
-static bool BUS_MATCH_CAN_HASH(enum bus_match_node_type t) {
+static bool BUS_MATCH_CAN_HASH(BusMatchNodeType t) {
return (t >= BUS_MATCH_MESSAGE_TYPE && t <= BUS_MATCH_PATH) ||
(t >= BUS_MATCH_ARG && t <= BUS_MATCH_ARG_LAST) ||
(t >= BUS_MATCH_ARG_HAS && t <= BUS_MATCH_ARG_HAS_LAST);
}
-static void bus_match_node_free(struct bus_match_node *node) {
+static void bus_match_node_free(BusMatchNode *node) {
assert(node);
assert(node->parent);
assert(!node->child);
free(node);
}
-static bool bus_match_node_maybe_free(struct bus_match_node *node) {
+static bool bus_match_node_maybe_free(BusMatchNode *node) {
assert(node);
if (node->type == BUS_MATCH_ROOT)
}
static bool value_node_test(
- struct bus_match_node *node,
- enum bus_match_node_type parent_type,
+ BusMatchNode *node,
+ BusMatchNodeType parent_type,
uint8_t value_u8,
const char *value_str,
char **value_strv,
}
static bool value_node_same(
- struct bus_match_node *node,
- enum bus_match_node_type parent_type,
+ BusMatchNode *node,
+ BusMatchNodeType parent_type,
uint8_t value_u8,
const char *value_str) {
int bus_match_run(
sd_bus *bus,
- struct bus_match_node *node,
+ BusMatchNode *node,
sd_bus_message *m) {
_cleanup_strv_free_ char **test_strv = NULL;
}
if (BUS_MATCH_CAN_HASH(node->type)) {
- struct bus_match_node *found;
+ BusMatchNode *found;
/* Lookup via hash table, nice! So let's jump directly. */
}
} else
/* No hash table, so let's iterate manually... */
- for (struct bus_match_node *c = node->child; c; c = c->next) {
+ for (BusMatchNode *c = node->child; c; c = c->next) {
if (!value_node_test(c, node->type, test_u8, test_str, test_strv, m))
continue;
}
static int bus_match_add_compare_value(
- struct bus_match_node *where,
- enum bus_match_node_type t,
+ BusMatchNode *where,
+ BusMatchNodeType t,
uint8_t value_u8,
const char *value_str,
- struct bus_match_node **ret) {
+ BusMatchNode **ret) {
- struct bus_match_node *c, *n = NULL;
+ BusMatchNode *c, *n = NULL;
int r;
assert(where);
} else {
/* Comparison node, doesn't exist yet? Then let's create it. */
- c = new0(struct bus_match_node, 1);
+ c = new0(BusMatchNode, 1);
if (!c) {
r = -ENOMEM;
goto fail;
}
}
- n = new0(struct bus_match_node, 1);
+ n = new0(BusMatchNode, 1);
if (!n) {
r = -ENOMEM;
goto fail;
}
static int bus_match_add_leaf(
- struct bus_match_node *where,
- struct match_callback *callback) {
+ BusMatchNode *where,
+ BusMatchCallback *callback) {
- struct bus_match_node *n;
+ BusMatchNode *n;
assert(where);
assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE));
assert(callback);
- n = new0(struct bus_match_node, 1);
+ n = new0(BusMatchNode, 1);
if (!n)
return -ENOMEM;
return 1;
}
-enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n) {
+BusMatchNodeType bus_match_node_type_from_string(const char *k, size_t n) {
assert(k);
if (n == 4 && startswith(k, "type"))
if (n == 5 && startswith(k, "arg")) {
int a, b;
- enum bus_match_node_type t;
+ BusMatchNodeType t;
a = undecchar(k[3]);
b = undecchar(k[4]);
}
if (n == 9 && startswith(k, "arg") && startswith(k + 5, "path")) {
- enum bus_match_node_type t;
+ BusMatchNodeType t;
int a, b;
a = undecchar(k[3]);
}
if (n == 14 && startswith(k, "arg") && startswith(k + 5, "namespace")) {
- enum bus_match_node_type t;
+ BusMatchNodeType t;
int a, b;
a = undecchar(k[3]);
}
if (n == 8 && startswith(k, "arg") && startswith(k + 5, "has")) {
- enum bus_match_node_type t;
+ BusMatchNodeType t;
int a, b;
a = undecchar(k[3]);
return -EINVAL;
}
-static int match_component_compare(const struct bus_match_component *a, const struct bus_match_component *b) {
+static int match_component_compare(const BusMatchComponent *a, const BusMatchComponent *b) {
return CMP(a->type, b->type);
}
-void bus_match_parse_free(struct bus_match_component *components, size_t n_components) {
+void bus_match_parse_free(BusMatchComponent *components, size_t n_components) {
for (size_t i = 0; i < n_components; i++)
free(components[i].value_str);
int bus_match_parse(
const char *match,
- struct bus_match_component **ret_components,
+ BusMatchComponent **ret_components,
size_t *ret_n_components) {
- struct bus_match_component *components = NULL;
+ BusMatchComponent *components = NULL;
size_t n_components = 0;
int r;
while (*match != '\0') {
const char *eq, *q;
- enum bus_match_node_type t;
+ BusMatchNodeType t;
size_t j = 0;
_cleanup_free_ char *value = NULL;
bool escaped = false, quoted;
if (!GREEDY_REALLOC(components, n_components + 1))
return -ENOMEM;
- components[n_components++] = (struct bus_match_component) {
+ components[n_components++] = (BusMatchComponent) {
.type = t,
.value_str = TAKE_PTR(value),
.value_u8 = u,
return 0;
}
-char* bus_match_to_string(struct bus_match_component *components, size_t n_components) {
+char* bus_match_to_string(BusMatchComponent *components, size_t n_components) {
_cleanup_(memstream_done) MemStream m = {};
FILE *f;
int r;
}
int bus_match_add(
- struct bus_match_node *root,
- struct bus_match_component *components,
+ BusMatchNode *root,
+ BusMatchComponent *components,
size_t n_components,
- struct match_callback *callback) {
+ BusMatchCallback *callback) {
int r;
}
int bus_match_remove(
- struct bus_match_node *root,
- struct match_callback *callback) {
+ BusMatchNode *root,
+ BusMatchCallback *callback) {
- struct bus_match_node *node, *pp;
+ BusMatchNode *node, *pp;
assert(root);
assert(callback);
return 1;
}
-void bus_match_free(struct bus_match_node *node) {
- struct bus_match_node *c;
+void bus_match_free(BusMatchNode *node) {
+ BusMatchNode *c;
if (!node)
return;
bus_match_node_free(node);
}
-const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l) {
+const char* bus_match_node_type_to_string(BusMatchNodeType t, char buf[], size_t l) {
switch (t) {
case BUS_MATCH_ROOT:
}
}
-void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) {
+void bus_match_dump(FILE *out, BusMatchNode *node, unsigned level) {
char buf[32];
if (!node)
putc('\n', out);
if (BUS_MATCH_CAN_HASH(node->type)) {
- struct bus_match_node *c;
+ BusMatchNode *c;
HASHMAP_FOREACH(c, node->compare.children)
bus_match_dump(out, c, level + 1);
}
- for (struct bus_match_node *c = node->child; c; c = c->next)
+ for (BusMatchNode *c = node->child; c; c = c->next)
bus_match_dump(out, c, level + 1);
}
-enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, size_t n_components) {
+BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components) {
bool found_driver = false;
if (n_components <= 0)
* driver. */
for (size_t i = 0; i < n_components; i++) {
- const struct bus_match_component *c = components + i;
+ const BusMatchComponent *c = components + i;
if (c->type == BUS_MATCH_SENDER) {
if (streq_ptr(c->value_str, "org.freedesktop.DBus.Local"))
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include "forward.h"
+#include "bus-forward.h"
-enum bus_match_node_type {
+typedef enum BusMatchNodeType {
BUS_MATCH_ROOT,
BUS_MATCH_VALUE,
BUS_MATCH_LEAF,
BUS_MATCH_ARG_HAS_LAST = BUS_MATCH_ARG_HAS + 63,
_BUS_MATCH_NODE_TYPE_MAX,
_BUS_MATCH_NODE_TYPE_INVALID = -EINVAL,
-};
+} BusMatchNodeType;
-struct bus_match_node {
- enum bus_match_node_type type;
- struct bus_match_node *parent, *next, *prev, *child;
+typedef struct BusMatchCallback {
+ sd_bus_message_handler_t callback;
+ sd_bus_message_handler_t install_callback;
+
+ sd_bus_slot *install_slot; /* The AddMatch() call */
+
+ unsigned last_iteration;
+
+ /* Don't dispatch this slot with messages that arrived in any iteration before or at the this
+ * one. We use this to ensure that matches don't apply "retroactively" and confuse the caller:
+ * only messages received after the match was installed will be considered. */
+ uint64_t after;
+
+ char *match_string;
+
+ BusMatchNode *match_node;
+} BusMatchCallback;
+
+typedef struct BusMatchNode {
+ BusMatchNodeType type;
+ BusMatchNode *parent, *next, *prev, *child;
union {
struct {
uint8_t u8;
} value;
struct {
- struct match_callback *callback;
+ BusMatchCallback *callback;
} leaf;
struct {
/* If this is set, then the child is NULL */
Hashmap *children;
} compare;
};
-};
+} BusMatchNode;
-struct bus_match_component {
- enum bus_match_node_type type;
+typedef struct BusMatchComponent {
+ BusMatchNodeType type;
uint8_t value_u8;
char *value_str;
-};
+} BusMatchComponent;
-enum bus_match_scope {
+typedef enum BusMatchScope {
BUS_MATCH_GENERIC,
BUS_MATCH_LOCAL,
BUS_MATCH_DRIVER,
-};
+} BusMatchScope;
-int bus_match_run(sd_bus *bus, struct bus_match_node *root, sd_bus_message *m);
+int bus_match_run(sd_bus *bus, BusMatchNode *root, sd_bus_message *m);
-int bus_match_add(struct bus_match_node *root, struct bus_match_component *components, size_t n_components, struct match_callback *callback);
-int bus_match_remove(struct bus_match_node *root, struct match_callback *callback);
+int bus_match_add(BusMatchNode *root, BusMatchComponent *components, size_t n_components, BusMatchCallback *callback);
+int bus_match_remove(BusMatchNode *root, BusMatchCallback *callback);
-void bus_match_free(struct bus_match_node *node);
+void bus_match_free(BusMatchNode *node);
-void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level);
+void bus_match_dump(FILE *out, BusMatchNode *node, unsigned level);
-const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l);
-enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n);
+const char* bus_match_node_type_to_string(BusMatchNodeType t, char buf[], size_t l);
+BusMatchNodeType bus_match_node_type_from_string(const char *k, size_t n);
-int bus_match_parse(const char *match, struct bus_match_component **ret_components, size_t *ret_n_components);
-void bus_match_parse_free(struct bus_match_component *components, size_t n_components);
-char* bus_match_to_string(struct bus_match_component *components, size_t n_components);
+int bus_match_parse(const char *match, BusMatchComponent **ret_components, size_t *ret_n_components);
+void bus_match_parse_free(BusMatchComponent *components, size_t n_components);
+char* bus_match_to_string(BusMatchComponent *components, size_t n_components);
-enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, size_t n_components);
+BusMatchScope bus_match_get_scope(const BusMatchComponent *components, size_t n_components);
return (uint8_t*) new_base + ((uint8_t*) p - (uint8_t*) old_base);
}
-static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
+static void message_free_part(sd_bus_message *m, BusMessageBodyPart *part) {
assert(m);
assert(part);
}
static void message_reset_parts(sd_bus_message *m) {
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
assert(m);
part = &m->body;
while (m->n_body_parts > 0) {
- struct bus_body_part *next = part->next;
+ BusMessageBodyPart *next = part->next;
message_free_part(m, part);
part = next;
m->n_body_parts--;
m->cached_rindex_part_begin = 0;
}
-static struct bus_container *message_get_last_container(sd_bus_message *m) {
+static BusMessageContainer *message_get_last_container(sd_bus_message *m) {
assert(m);
if (m->n_containers == 0)
}
static void message_free_last_container(sd_bus_message *m) {
- struct bus_container *c;
+ BusMessageContainer *c;
c = message_get_last_container(m);
if (m->poisoned)
return NULL;
- old_size = sizeof(struct bus_header) + m->fields_size;
+ old_size = sizeof(BusMessageHeader) + m->fields_size;
start = ALIGN8(old_size);
new_size = start + sz;
if (!np)
goto poison;
- memcpy(np, m->header, sizeof(struct bus_header));
+ memcpy(np, m->header, sizeof(BusMessageHeader));
}
/* Zero out padding */
op = m->header;
m->header = np;
- m->fields_size = new_size - sizeof(struct bus_header);
+ m->fields_size = new_size - sizeof(BusMessageHeader);
/* Adjust quick access pointers */
m->path = adjust_pointer(m->path, op, old_size, m->header);
if (m->n_header_offsets >= ELEMENTSOF(m->header_offsets))
goto poison;
- m->header_offsets[m->n_header_offsets++] = new_size - sizeof(struct bus_header);
+ m->header_offsets[m->n_header_offsets++] = new_size - sizeof(BusMessageHeader);
}
return (uint8_t*) np + start;
sd_bus_message **ret) {
_cleanup_free_ sd_bus_message *m = NULL;
- struct bus_header *h;
+ BusMessageHeader *h;
size_t a, label_sz = 0; /* avoid false maybe-uninitialized warning */
assert(bus);
assert(fds || n_fds <= 0);
assert(ret);
- if (message_size < sizeof(struct bus_header))
+ if (message_size < sizeof(BusMessageHeader))
return -EBADMSG;
h = buffer;
m->fields_size = BUS_MESSAGE_BSWAP32(m, h->fields_size);
m->body_size = BUS_MESSAGE_BSWAP32(m, h->body_size);
- assert(message_size >= sizeof(struct bus_header));
- if (ALIGN8(m->fields_size) > message_size - sizeof(struct bus_header) ||
- m->body_size != message_size - sizeof(struct bus_header) - ALIGN8(m->fields_size))
+ assert(message_size >= sizeof(BusMessageHeader));
+ if (ALIGN8(m->fields_size) > message_size - sizeof(BusMessageHeader) ||
+ m->body_size != message_size - sizeof(BusMessageHeader) - ALIGN8(m->fields_size))
return -EBADMSG;
m->fds = fds;
if (r < 0)
return r;
- sz = length - sizeof(struct bus_header) - ALIGN8(m->fields_size);
+ sz = length - sizeof(BusMessageHeader) - ALIGN8(m->fields_size);
if (sz > 0) {
m->n_body_parts = 1;
- m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(m->fields_size);
+ m->body.data = (uint8_t*) buffer + sizeof(BusMessageHeader) + ALIGN8(m->fields_size);
m->body.size = sz;
m->body.sealed = true;
m->body.memfd = -EBADF;
/* Creation of messages with _SD_BUS_MESSAGE_TYPE_INVALID is allowed. */
assert_return(type < _SD_BUS_MESSAGE_TYPE_MAX, -EINVAL);
- sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(struct bus_header));
+ sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader));
if (!t)
return -ENOMEM;
t->n_ref = 1;
t->creds = (sd_bus_creds) { SD_BUS_CREDS_INIT_FIELDS };
t->bus = sd_bus_ref(bus);
- t->header = (struct bus_header*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message)));
+ t->header = (BusMessageHeader*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message)));
t->header->endian = BUS_NATIVE_ENDIAN;
t->header->type = type;
t->header->version = bus->message_version;
return 0;
}
-static struct bus_body_part *message_append_part(sd_bus_message *m) {
- struct bus_body_part *part;
+static BusMessageBodyPart *message_append_part(sd_bus_message *m) {
+ BusMessageBodyPart *part;
assert(m);
} else {
assert(m->body_end);
- part = new0(struct bus_body_part, 1);
+ part = new0(BusMessageBodyPart, 1);
if (!part) {
m->poisoned = true;
return NULL;
return part;
}
-static void part_zero(struct bus_body_part *part, size_t sz) {
+static void part_zero(BusMessageBodyPart *part, size_t sz) {
assert(part);
assert(sz > 0);
assert(sz < 8);
static int part_make_space(
struct sd_bus_message *m,
- struct bus_body_part *part,
+ BusMessageBodyPart *part,
size_t sz,
void **q) {
return;
/* Update counters */
- for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++)
+ for (BusMessageContainer *c = m->containers; c < m->containers + m->n_containers; c++)
if (c->array_size)
*c->array_size += expand;
}
}
if (added > 0) {
- struct bus_body_part *part = NULL;
+ BusMessageBodyPart *part = NULL;
bool add_new_part;
add_new_part =
/* Readjust pointers */
if (m->n_containers > 0)
- for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++)
+ for (BusMessageContainer *c = m->containers; c < m->containers + m->n_containers; c++)
c->array_size = adjust_pointer(c->array_size, op, os, part->data);
m->error.message = (const char*) adjust_pointer(m->error.message, op, os, part->data);
int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored) {
_cleanup_close_ int fd = -EBADF;
- struct bus_container *c;
+ BusMessageContainer *c;
ssize_t align, sz;
uint32_t u32;
void *a;
size_t size,
char **s) {
- struct bus_container *c;
+ BusMessageContainer *c;
void *a;
assert_return(m, -EINVAL);
static int bus_message_open_array(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents,
uint32_t **array_size,
size_t *begin) {
int alignment;
void *a, *op;
size_t os;
- struct bus_body_part *o;
+ BusMessageBodyPart *o;
assert(m);
assert(c);
static int bus_message_open_variant(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents) {
size_t l;
static int bus_message_open_struct(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents,
size_t *begin) {
static int bus_message_open_dict_entry(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents,
size_t *begin) {
char type,
const char *contents) {
- struct bus_container *c;
+ BusMessageContainer *c;
uint32_t *array_size = NULL;
_cleanup_free_ char *signature = NULL;
size_t before, begin = 0;
return r;
/* OK, let's fill it in */
- m->containers[m->n_containers++] = (struct bus_container) {
+ m->containers[m->n_containers++] = (BusMessageContainer) {
.enclosing = type,
.signature = TAKE_PTR(signature),
.array_size = array_size,
}
_public_ int sd_bus_message_close_container(sd_bus_message *m) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
return 0;
}
-typedef struct {
+typedef struct BusTypeStack {
const char *types;
unsigned n_struct;
unsigned n_array;
-} TypeStack;
+} BusTypeStack;
-static int type_stack_push(TypeStack *stack, unsigned max, unsigned *i, const char *types, unsigned n_struct, unsigned n_array) {
+static int type_stack_push(BusTypeStack *stack, unsigned max, unsigned *i, const char *types, unsigned n_struct, unsigned n_array) {
assert(stack);
assert(max > 0);
return 0;
}
-static int type_stack_pop(TypeStack *stack, unsigned max, unsigned *i, const char **types, unsigned *n_struct, unsigned *n_array) {
+static int type_stack_pop(BusTypeStack *stack, unsigned max, unsigned *i, const char **types, unsigned *n_struct, unsigned *n_array) {
assert(stack);
assert(max > 0);
assert(types);
va_list ap) {
unsigned n_array, n_struct;
- TypeStack stack[BUS_CONTAINER_DEPTH];
+ BusTypeStack stack[BUS_CONTAINER_DEPTH];
unsigned stack_ptr = 0;
int r;
uint64_t size) {
_cleanup_close_ int copy_fd = -EBADF;
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
ssize_t align, sz;
uint64_t real_size;
void *a;
uint64_t size) {
_cleanup_close_ int copy_fd = -EBADF;
- struct bus_body_part *part;
- struct bus_container *c;
+ BusMessageBodyPart *part;
+ BusMessageContainer *c;
uint64_t real_size;
void *a;
int r;
}
_public_ int sd_bus_message_seal(sd_bus_message *m, uint64_t cookie, uint64_t timeout_usec) {
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
size_t a;
unsigned i;
int r;
return 0;
}
-int bus_body_part_map(struct bus_body_part *part) {
+int bus_body_part_map(BusMessageBodyPart *part) {
void *p;
size_t psz, shift;
return 0;
}
-void bus_body_part_unmap(struct bus_body_part *part) {
+void bus_body_part_unmap(BusMessageBodyPart *part) {
assert_se(part);
}
static bool message_end_of_signature(sd_bus_message *m) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert(m);
}
static bool message_end_of_array(sd_bus_message *m, size_t index) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert(m);
return false;
}
-static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) {
- struct bus_body_part *part;
+static BusMessageBodyPart* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) {
+ BusMessageBodyPart *part;
size_t begin;
int r;
void **ret) {
size_t k, start, end, padding;
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
uint8_t *q;
assert(m);
}
_public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
- struct bus_container *c;
+ BusMessageContainer *c;
size_t rindex;
void *q;
int r;
static int bus_message_enter_array(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents,
uint32_t **array_size) {
static int bus_message_enter_variant(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents) {
size_t rindex;
static int bus_message_enter_struct(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents) {
size_t l;
static int bus_message_enter_dict_entry(
sd_bus_message *m,
- struct bus_container *c,
+ BusMessageContainer *c,
const char *contents) {
size_t l;
_public_ int sd_bus_message_enter_container(sd_bus_message *m,
char type,
const char *contents) {
- struct bus_container *c;
+ BusMessageContainer *c;
uint32_t *array_size = NULL;
_cleanup_free_ char *signature = NULL;
size_t before;
return r;
/* OK, let's fill it in */
- m->containers[m->n_containers++] = (struct bus_container) {
+ m->containers[m->n_containers++] = (BusMessageContainer) {
.enclosing = type,
.signature = TAKE_PTR(signature),
}
_public_ int sd_bus_message_exit_container(sd_bus_message *m) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
}
static void message_quit_container(sd_bus_message *m) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert(m);
assert(m->sealed);
}
_public_ int sd_bus_message_peek_type(sd_bus_message *m, char *ret_type, const char **ret_contents) {
- struct bus_container *c;
+ BusMessageContainer *c;
int r;
assert_return(m, -EINVAL);
}
_public_ int sd_bus_message_rewind(sd_bus_message *m, int complete) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
va_list ap) {
unsigned n_array, n_struct;
- TypeStack stack[BUS_CONTAINER_DEPTH];
+ BusTypeStack stack[BUS_CONTAINER_DEPTH];
unsigned stack_ptr = 0;
unsigned n_loop = 0;
int r;
/* If types is NULL, read exactly one element */
if (!types) {
- struct bus_container *c;
+ BusMessageContainer *c;
size_t l;
if (message_end_of_signature(m))
const void **ptr,
size_t *size) {
- struct bus_container *c;
+ BusMessageContainer *c;
void *p;
size_t sz;
ssize_t align;
size_t total;
void *p, *e;
size_t i;
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
assert(m);
assert(buffer);
}
_public_ const char* sd_bus_message_get_signature(sd_bus_message *m, int complete) {
- struct bus_container *c;
+ BusMessageContainer *c;
assert_return(m, NULL);
#include "sd-bus-protocol.h"
#include "bus-creds.h"
+#include "bus-forward.h"
#include "bus-protocol.h"
-#include "forward.h"
#include "memory-util.h"
-struct bus_container {
+typedef struct BusMessageHeader {
+ uint8_t endian;
+ uint8_t type;
+ uint8_t flags;
+ uint8_t version;
+ uint32_t body_size;
+ /* Note that what the bus spec calls "serial" we'll call "cookie" instead, because we don't
+ * want to imply that the cookie was in any way monotonically increasing. */
+ uint32_t serial;
+ uint32_t fields_size;
+} _packed_ BusMessageHeader;
+
+typedef struct BusMessageContainer {
char enclosing;
/* Indexes into the signature string */
uint32_t *array_size;
char *peeked_signature;
-};
+} BusMessageContainer;
-struct bus_body_part {
- struct bus_body_part *next;
+typedef struct BusMessageBodyPart {
+ BusMessageBodyPart *next;
void *data;
void *mmap_begin;
size_t size;
bool munmap_this:1;
bool sealed:1;
bool is_zero:1;
-};
+} BusMessageBodyPart;
typedef struct sd_bus_message {
/* Caveat: a message can be referenced in two different ways: the main (user-facing) way will also
bool sensitive:1;
/* The first bytes of the message */
- struct bus_header *header;
+ BusMessageHeader *header;
size_t fields_size;
size_t body_size;
size_t user_body_size;
- struct bus_body_part body;
- struct bus_body_part *body_end;
+ BusMessageBodyPart body;
+ BusMessageBodyPart *body_end;
unsigned n_body_parts;
size_t rindex;
- struct bus_body_part *cached_rindex_part;
+ BusMessageBodyPart *cached_rindex_part;
size_t cached_rindex_part_begin;
uint32_t n_fds;
int *fds;
- struct bus_container root_container, *containers;
+ BusMessageContainer root_container, *containers;
size_t n_containers;
struct iovec *iovec;
static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) {
return
- sizeof(struct bus_header) +
+ sizeof(BusMessageHeader) +
ALIGN8(m->fields_size) +
m->body_size;
}
static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) {
return
- sizeof(struct bus_header) +
+ sizeof(BusMessageHeader) +
ALIGN8(m->fields_size);
}
static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) {
- return (uint8_t*) m->header + sizeof(struct bus_header);
+ return (uint8_t*) m->header + sizeof(BusMessageHeader);
}
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
#define MESSAGE_FOREACH_PART(part, i, m) \
for ((i) = 0, (part) = &(m)->body; (i) < (m)->n_body_parts; (i)++, (part) = (part)->next)
-int bus_body_part_map(struct bus_body_part *part);
-void bus_body_part_unmap(struct bus_body_part *part);
+int bus_body_part_map(BusMessageBodyPart *part);
+void bus_body_part_unmap(BusMessageBodyPart *part);
int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_error *e, sd_bus_message **m);
static int node_vtable_get_userdata(
sd_bus *bus,
const char *path,
- struct node_vtable *c,
+ BusNodeVTable *c,
void **userdata,
sd_bus_error *error) {
static int vtable_property_get_userdata(
sd_bus *bus,
const char *path,
- struct vtable_member *p,
+ BusVTableMember *p,
void **userdata,
sd_bus_error *error) {
static int add_enumerated_to_set(
sd_bus *bus,
const char *prefix,
- struct node_enumerator *first,
+ BusNodeEnumerator *first,
OrderedSet *s,
sd_bus_error *error) {
static int add_subtree_to_set(
sd_bus *bus,
const char *prefix,
- struct node *n,
+ BusNode *n,
unsigned flags,
OrderedSet *s,
sd_bus_error *error) {
static int get_child_nodes(
sd_bus *bus,
const char *prefix,
- struct node *n,
+ BusNode *n,
unsigned flags,
OrderedSet **ret,
sd_bus_error *error) {
static int node_callbacks_run(
sd_bus *bus,
sd_bus_message *m,
- struct node_callback *first,
+ BusNodeCallback *first,
bool require_fallback,
bool *found_object) {
#define CAPABILITY_SHIFT(x) (((x) >> __builtin_ctzll(_SD_BUS_VTABLE_CAPABILITY_MASK)) & 0xFFFF)
-static int check_access(sd_bus *bus, sd_bus_message *m, struct vtable_member *c, sd_bus_error *error) {
+static int check_access(sd_bus *bus, sd_bus_message *m, BusVTableMember *c, sd_bus_error *error) {
uint64_t cap;
int r;
static int method_callbacks_run(
sd_bus *bus,
sd_bus_message *m,
- struct vtable_member *c,
+ BusVTableMember *c,
bool require_fallback,
bool *found_object) {
static int property_get_set_callbacks_run(
sd_bus *bus,
sd_bus_message *m,
- struct vtable_member *c,
+ BusVTableMember *c,
bool require_fallback,
bool is_get,
bool *found_object) {
sd_bus *bus,
sd_bus_message *reply,
const char *path,
- struct node_vtable *c,
+ BusNodeVTable *c,
const sd_bus_vtable *v,
void *userdata,
sd_bus_error *error) {
sd_bus *bus,
sd_bus_message *reply,
const char *path,
- struct node_vtable *c,
+ BusNodeVTable *c,
void *userdata,
sd_bus_error *error) {
static int property_get_all_callbacks_run(
sd_bus *bus,
sd_bus_message *m,
- struct node_vtable *first,
+ BusNodeVTable *first,
bool require_fallback,
const char *iface,
bool *found_object) {
static int bus_node_exists(
sd_bus *bus,
- struct node *n,
+ BusNode *n,
const char *path,
bool require_fallback) {
int introspect_path(
sd_bus *bus,
const char *path,
- struct node *n,
+ BusNode *n,
bool require_fallback,
bool ignore_nodes_modified,
bool *found_object,
sd_bus_error *error) {
_cleanup_ordered_set_free_ OrderedSet *s = NULL;
- _cleanup_(introspect_done) struct introspect intro = {};
+ _cleanup_(introspect_done) BusIntrospect intro = {};
bool empty;
int r;
static int process_introspect(
sd_bus *bus,
sd_bus_message *m,
- struct node *n,
+ BusNode *n,
bool require_fallback,
bool *found_object) {
const char *previous_interface = NULL;
bool found_something = false;
- struct node *n;
+ BusNode *n;
int r;
assert(bus);
static int process_get_managed_objects(
sd_bus *bus,
sd_bus_message *m,
- struct node *n,
+ BusNode *n,
bool require_fallback,
bool *found_object) {
bool require_fallback,
bool *found_object) {
- struct node *n;
- struct vtable_member vtable_key, *v;
+ BusNode *n;
+ BusVTableMember vtable_key, *v;
int r;
assert(bus);
return 1;
}
-static struct node* bus_node_allocate(sd_bus *bus, const char *path) {
- struct node *n, *parent;
+static BusNode* bus_node_allocate(sd_bus *bus, const char *path) {
+ BusNode *n, *parent;
const char *e;
_cleanup_free_ char *s = NULL;
char *p;
return NULL;
}
- n = new0(struct node, 1);
+ n = new0(BusNode, 1);
if (!n)
return NULL;
return n;
}
-void bus_node_gc(sd_bus *b, struct node *n) {
+void bus_node_gc(sd_bus *b, BusNode *n) {
assert(b);
if (!n)
free(n);
}
-static int bus_find_parent_object_manager(sd_bus *bus, struct node **out, const char *path, bool* path_has_object_manager) {
- struct node *n;
+static int bus_find_parent_object_manager(sd_bus *bus, BusNode **out, const char *path, bool* path_has_object_manager) {
+ BusNode *n;
assert(bus);
assert(path);
void *userdata) {
sd_bus_slot *s;
- struct node *n;
+ BusNode *n;
int r;
assert_return(bus, -EINVAL);
if (!n)
return -ENOMEM;
- s = bus_slot_allocate(bus, !slot, BUS_NODE_CALLBACK, sizeof(struct node_callback), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_NODE_CALLBACK, sizeof(BusNodeCallback), userdata);
if (!s) {
r = -ENOMEM;
goto fail;
return bus_add_object(bus, slot, true, prefix, callback, userdata);
}
-static void vtable_member_hash_func(const struct vtable_member *m, struct siphash *state) {
+static void vtable_member_hash_func(const BusVTableMember *m, struct siphash *state) {
assert(m);
string_hash_func(m->path, state);
string_hash_func(m->member, state);
}
-static int vtable_member_compare_func(const struct vtable_member *x, const struct vtable_member *y) {
+static int vtable_member_compare_func(const BusVTableMember *x, const BusVTableMember *y) {
int r;
assert(x);
DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
vtable_member_hash_ops,
- struct vtable_member, vtable_member_hash_func, vtable_member_compare_func, free);
+ BusVTableMember, vtable_member_hash_func, vtable_member_compare_func, free);
typedef enum {
NAMES_FIRST_PART = 1 << 0, /* first part of argument name list (input names). It is reset by names_are_valid() */
void *userdata) {
sd_bus_slot *s = NULL;
- struct node_vtable *existing = NULL;
+ BusNodeVTable *existing = NULL;
const sd_bus_vtable *v;
- struct node *n;
+ BusNode *n;
int r;
const char *names = "";
names_flags nf;
}
}
- s = bus_slot_allocate(bus, !slot, BUS_NODE_VTABLE, sizeof(struct node_vtable), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_NODE_VTABLE, sizeof(BusNodeVTable), userdata);
if (!s) {
r = -ENOMEM;
goto fail;
switch (v->type) {
case _SD_BUS_VTABLE_METHOD: {
- struct vtable_member *m;
+ BusVTableMember *m;
nf = NAMES_FIRST_PART;
if (bus_vtable_has_names(vtable))
goto fail;
}
- m = new0(struct vtable_member, 1);
+ m = new0(BusVTableMember, 1);
if (!m) {
r = -ENOMEM;
goto fail;
_fallthrough_;
case _SD_BUS_VTABLE_PROPERTY: {
- struct vtable_member *m;
+ BusVTableMember *m;
if (!member_name_is_valid(v->x.property.member) ||
!signature_is_single(v->x.property.signature, false) ||
goto fail;
}
- m = new0(struct vtable_member, 1);
+ m = new0(BusVTableMember, 1);
if (!m) {
r = -ENOMEM;
goto fail;
void *userdata) {
sd_bus_slot *s;
- struct node *n;
+ BusNode *n;
int r;
assert_return(bus, -EINVAL);
if (!n)
return -ENOMEM;
- s = bus_slot_allocate(bus, !slot, BUS_NODE_ENUMERATOR, sizeof(struct node_enumerator), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_NODE_ENUMERATOR, sizeof(BusNodeEnumerator), userdata);
if (!s) {
r = -ENOMEM;
goto fail;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
bool has_invalidating = false, has_changing = false;
- struct vtable_member key = {};
- struct node *n;
+ BusVTableMember key = {};
+ BusNode *n;
void *u = NULL;
int r;
* PropertiesChanged message */
STRV_FOREACH(property, names) {
- struct vtable_member *v;
+ BusVTableMember *v;
assert_return(member_name_is_valid(*property), -EINVAL);
if (names) {
STRV_FOREACH(property, names) {
- struct vtable_member *v;
+ BusVTableMember *v;
key.member = *property;
assert_se(v = set_get(bus->vtable_properties, &key));
bool require_fallback) {
const char *previous_interface = NULL;
- struct node *n;
+ BusNode *n;
int r;
assert(bus);
_public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- struct node *object_manager;
+ BusNode *object_manager;
int r;
/*
bool require_fallback) {
const char *previous_interface = NULL;
- struct node *n;
+ BusNode *n;
int r;
assert(bus);
_public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- struct node *object_manager;
+ BusNode *object_manager;
int r;
/*
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
bool found_interface = false;
- struct node *n;
+ BusNode *n;
void *u = NULL;
int r;
_public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- struct node *object_manager;
+ BusNode *object_manager;
int r;
assert_return(bus, -EINVAL);
_public_ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- struct node *object_manager;
+ BusNode *object_manager;
int r;
assert_return(bus, -EINVAL);
_public_ int sd_bus_add_object_manager(sd_bus *bus, sd_bus_slot **slot, const char *path) {
sd_bus_slot *s;
- struct node *n;
+ BusNode *n;
int r;
assert_return(bus, -EINVAL);
if (!n)
return -ENOMEM;
- s = bus_slot_allocate(bus, !slot, BUS_NODE_OBJECT_MANAGER, sizeof(struct node_object_manager), NULL);
+ s = bus_slot_allocate(bus, !slot, BUS_NODE_OBJECT_MANAGER, sizeof(BusNodeObjectManager), NULL);
if (!s) {
r = -ENOMEM;
goto fail;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include "forward.h"
-
-struct node;
+#include "bus-forward.h"
const sd_bus_vtable* bus_vtable_next(const sd_bus_vtable *vtable, const sd_bus_vtable *v);
bool bus_vtable_has_names(const sd_bus_vtable *vtable);
int bus_process_object(sd_bus *bus, sd_bus_message *m);
-void bus_node_gc(sd_bus *b, struct node *n);
+void bus_node_gc(sd_bus *b, BusNode *n);
int introspect_path(
sd_bus *bus,
const char *path,
- struct node *n,
+ BusNode *n,
bool require_fallback,
bool ignore_nodes_modified,
bool *found_object,
#include <endian.h>
-#include "forward.h"
-
-/* Packet header */
-
-struct _packed_ bus_header {
- uint8_t endian;
- uint8_t type;
- uint8_t flags;
- uint8_t version;
- uint32_t body_size;
- /* Note that what the bus spec calls "serial" we'll call "cookie" instead, because we don't
- * want to imply that the cookie was in any way monotonically increasing. */
- uint32_t serial;
- uint32_t fields_size;
-};
-
/* Endianness */
enum {
#include "alloc-util.h"
#include "bus-control.h"
+#include "bus-internal.h"
#include "bus-objects.h"
#include "bus-slot.h"
#include "prioq.h"
const sd_bus_vtable *v;
for (v = slot->node_vtable.vtable; v->type != _SD_BUS_VTABLE_END; v = bus_vtable_next(slot->node_vtable.vtable, v)) {
- struct vtable_member *x = NULL;
+ BusVTableMember *x = NULL;
switch (v->type) {
case _SD_BUS_VTABLE_METHOD: {
- struct vtable_member key;
+ BusVTableMember key;
key.path = slot->node_vtable.node->path;
key.interface = slot->node_vtable.interface;
case _SD_BUS_VTABLE_PROPERTY:
case _SD_BUS_VTABLE_WRITABLE_PROPERTY: {
- struct vtable_member key;
+ BusVTableMember key;
key.path = slot->node_vtable.node->path;
key.interface = slot->node_vtable.interface;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include "bus-internal.h"
-#include "forward.h"
+#include "bus-forward.h"
sd_bus_slot *bus_slot_allocate(sd_bus *bus, bool floating, BusSlotType type, size_t extra, void *userdata);
}
static int bus_message_setup_iovec(sd_bus_message *m) {
- struct bus_body_part *part;
+ BusMessageBodyPart *part;
unsigned n, i;
int r;
assert(need);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
- if (bus->rbuffer_size < sizeof(struct bus_header)) {
- *need = sizeof(struct bus_header) + 8;
+ if (bus->rbuffer_size < sizeof(BusMessageHeader)) {
+ *need = sizeof(BusMessageHeader) + 8;
/* Minimum message size:
*
} else
return -EBADMSG;
- sum = (uint64_t) sizeof(struct bus_header) + (uint64_t) ALIGN8(b) + (uint64_t) a;
+ sum = (uint64_t) sizeof(BusMessageHeader) + (uint64_t) ALIGN8(b) + (uint64_t) a;
if (sum >= BUS_MESSAGE_SIZE_MAX)
return -ENOBUFS;
#include "log.h"
#include "string-util.h"
-struct track_item {
+typedef struct BusTrackItem {
unsigned n_ref;
char *name;
sd_bus_slot *slot;
-};
+} BusTrackItem;
struct sd_bus_track {
unsigned n_ref;
"member='NameOwnerChanged'," \
"arg0='", name, "'")
-static struct track_item* track_item_free(struct track_item *i) {
+static BusTrackItem* track_item_free(BusTrackItem *i) {
if (!i)
return NULL;
return mfree(i);
}
-DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(struct track_item, track_item, track_item_free);
-DEFINE_TRIVIAL_CLEANUP_FUNC(struct track_item*, track_item_unref);
+DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(BusTrackItem, track_item, track_item_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(BusTrackItem*, track_item_unref);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(track_item_hash_ops, char, string_hash_func, string_compare_func,
- struct track_item, track_item_free);
+ BusTrackItem, track_item_free);
static void bus_track_add_to_queue(sd_bus_track *track) {
assert(track);
}
static int bus_track_remove_name_fully(sd_bus_track *track, const char *name) {
- struct track_item *i;
+ BusTrackItem *i;
assert(track);
assert(name);
}
_public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
- _cleanup_(track_item_unrefp) struct track_item *n = NULL;
- struct track_item *i;
+ _cleanup_(track_item_unrefp) BusTrackItem *n = NULL;
+ BusTrackItem *i;
const char *match;
int r;
if (r < 0)
return r;
- n = new(struct track_item, 1);
+ n = new(BusTrackItem, 1);
if (!n)
return -ENOMEM;
- *n = (struct track_item) {
+ *n = (BusTrackItem) {
.n_ref = 1,
};
}
_public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) {
- struct track_item *i;
+ BusTrackItem *i;
assert_return(name, -EINVAL);
}
_public_ int sd_bus_track_count_name(sd_bus_track *track, const char *name) {
- struct track_item *i;
+ BusTrackItem *i;
assert_return(service_name_is_valid(name), -EINVAL);
r = sd_bus_new(&bus);
assert_se(r >= 0);
- _cleanup_(bus_match_free) struct bus_match_node root = {
+ _cleanup_(bus_match_free) BusMatchNode root = {
.type = BUS_MATCH_ROOT,
};
offset = end ? (size_t) (end - (char*) data + 1) : size;
- struct bus_match_component *components;
+ BusMatchComponent *components;
size_t n_components;
r = bus_match_parse(line, &components, &n_components);
if (IN_SET(r, -EINVAL, -ENOMEM)) {
return 0;
}
-void bus_set_state(sd_bus *bus, enum bus_state state) {
+void bus_set_state(sd_bus *bus, BusState state) {
static const char* const table[_BUS_STATE_MAX] = {
[BUS_UNSET] = "UNSET",
[BUS_WATCH_BIND] = "WATCH_BIND",
}
int bus_start_running(sd_bus *bus) {
- struct reply_callback *c;
+ BusReplyCallback *c;
usec_t n;
int r;
}
static int timeout_compare(const void *a, const void *b) {
- const struct reply_callback *x = a, *y = b;
+ const BusReplyCallback *x = a, *y = b;
if (x->timeout_usec != 0 && y->timeout_usec == 0)
return -1;
return r;
if (slot || callback) {
- s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(struct reply_callback), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_REPLY_CALLBACK, sizeof(BusReplyCallback), userdata);
if (!s)
return -ENOMEM;
}
_public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
- struct reply_callback *c;
+ BusReplyCallback *c;
assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
static int process_timeout(sd_bus *bus) {
_cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message* m = NULL;
- struct reply_callback *c;
+ BusReplyCallback *c;
sd_bus_slot *slot;
bool is_hello;
usec_t n;
static int process_reply(sd_bus *bus, sd_bus_message *m) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *synthetic_reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
- struct reply_callback *c;
+ BusReplyCallback *c;
sd_bus_slot *slot;
bool is_hello;
int r;
assert_not_reached();
}
-static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c) {
+static int process_closing_reply_callback(sd_bus *bus, BusReplyCallback *c) {
_cleanup_(sd_bus_error_free) sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
sd_bus_slot *slot;
static int process_closing(sd_bus *bus, sd_bus_message **ret) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
- struct reply_callback *c;
+ BusReplyCallback *c;
int r;
assert(bus);
assert_return(callback, -EINVAL);
assert_return(!bus_origin_changed(bus), -ECHILD);
- s = bus_slot_allocate(bus, !slot, BUS_FILTER_CALLBACK, sizeof(struct filter_callback), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_FILTER_CALLBACK, sizeof(BusFilterCallback), userdata);
if (!s)
return -ENOMEM;
void *userdata,
uint64_t timeout_usec) {
- struct bus_match_component *components = NULL;
+ BusMatchComponent *components = NULL;
size_t n_components = 0;
_cleanup_(sd_bus_slot_unrefp) sd_bus_slot *s = NULL;
int r;
if (r < 0)
return r;
- s = bus_slot_allocate(bus, !slot, BUS_MATCH_CALLBACK, sizeof(struct match_callback), userdata);
+ s = bus_slot_allocate(bus, !slot, BUS_MATCH_CALLBACK, sizeof(BusMatchCallback), userdata);
if (!s)
return -ENOMEM;
s->match_callback.install_callback = install_callback;
if (bus->bus_client) {
- enum bus_match_scope scope;
+ BusMatchScope scope;
scope = bus_match_get_scope(components, n_components);
#include "tests.h"
static void test_manual_introspection_one(const sd_bus_vtable vtable[]) {
- struct introspect intro = {};
+ BusIntrospect intro = {};
_cleanup_free_ char *s = NULL;
log_info("/* %s */", __func__);
return true;
}
-static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char *match, int value) {
- struct bus_match_component *components;
+static int match_add(sd_bus_slot *slots, BusMatchNode *root, const char *match, int value) {
+ BusMatchComponent *components;
size_t n_components;
sd_bus_slot *s;
int r;
return bus_match_add(root, components, n_components, &s->match_callback);
}
-static void test_match_scope(const char *match, enum bus_match_scope scope) {
- struct bus_match_component *components = NULL;
+static void test_match_scope(const char *match, BusMatchScope scope) {
+ BusMatchComponent *components = NULL;
size_t n_components = 0;
CLEANUP_ARRAY(components, n_components, bus_match_parse_free);
}
int main(int argc, char *argv[]) {
- struct bus_match_node root = {
+ BusMatchNode root = {
.type = BUS_MATCH_ROOT,
};
assert_se(bus_match_run(NULL, &root, m) == 0);
assert_se(mask_contains((unsigned[]) { 9, 5, 10, 12, 14, 7, 15, 16, 17 }, 9));
- for (enum bus_match_node_type i = 0; i < _BUS_MATCH_NODE_TYPE_MAX; i++) {
+ for (BusMatchNodeType i = 0; i < _BUS_MATCH_NODE_TYPE_MAX; i++) {
char buf[32];
const char *x;
}
static int bus_introspect_implementation(
- struct introspect *intro,
+ BusIntrospect *intro,
const BusObjectImplementation *impl) {
int r;
return 0;
}
- struct introspect intro = {};
+ BusIntrospect intro = {};
bool is_interface = sd_bus_interface_name_is_valid(pattern);
impl = find_implementation(pattern, bus_objects);