]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-bus/bus-internal.h
bus: add sd_bus_message_append_string_space() for zero-copy string appending
[thirdparty/systemd.git] / src / libsystemd-bus / bus-internal.h
CommitLineData
de1c301e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2013 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <sys/socket.h>
25#include <sys/un.h>
26#include <netinet/in.h>
27
28#include "hashmap.h"
e3017af9 29#include "prioq.h"
de1c301e
LP
30#include "list.h"
31#include "util.h"
32
33#include "sd-bus.h"
34#include "bus-error.h"
392d5b37 35#include "bus-match.h"
de1c301e
LP
36
37struct reply_callback {
52f3ba91 38 sd_bus_message_handler_t callback;
de1c301e
LP
39 void *userdata;
40 usec_t timeout;
41 uint64_t serial;
e3017af9 42 unsigned prioq_idx;
de1c301e
LP
43};
44
45struct filter_callback {
52f3ba91 46 sd_bus_message_handler_t callback;
de1c301e
LP
47 void *userdata;
48
7286037f
LP
49 unsigned last_iteration;
50
de1c301e
LP
51 LIST_FIELDS(struct filter_callback, callbacks);
52};
53
a652755d 54struct object_callback {
52f3ba91 55 sd_bus_message_handler_t callback;
a652755d
LP
56 void *userdata;
57
58 char *path;
59 bool is_fallback;
7286037f
LP
60
61 unsigned last_iteration;
a652755d
LP
62};
63
de1c301e 64enum bus_state {
021a1e78 65 BUS_UNSET,
de1c301e
LP
66 BUS_OPENING,
67 BUS_AUTHENTICATING,
68 BUS_HELLO,
89ffcd2a 69 BUS_RUNNING
de1c301e
LP
70};
71
2181a7f5
LP
72enum bus_auth {
73 _BUS_AUTH_INVALID,
74 BUS_AUTH_EXTERNAL,
75 BUS_AUTH_ANONYMOUS
76};
77
de1c301e
LP
78struct sd_bus {
79 unsigned n_ref;
80 enum bus_state state;
e82c9509 81 int input_fd, output_fd;
de1c301e 82 int message_version;
021a1e78 83
6629161f 84 bool is_kernel:1;
021a1e78 85 bool negotiate_fds:1;
de1c301e 86 bool can_fds:1;
94bbf1ba 87 bool bus_client:1;
2571ead1 88 bool ucred_valid:1;
2181a7f5
LP
89 bool is_server:1;
90 bool anonymous_auth:1;
15d5af81
LP
91 bool prefer_readv:1;
92 bool prefer_writev:1;
6807947e 93 bool processing:1;
7286037f
LP
94 bool match_callbacks_modified:1;
95 bool filter_callbacks_modified:1;
96 bool object_callbacks_modified:1;
de1c301e
LP
97
98 void *rbuffer;
99 size_t rbuffer_size;
100
101 sd_bus_message **rqueue;
102 unsigned rqueue_size;
103
104 sd_bus_message **wqueue;
105 unsigned wqueue_size;
106 size_t windex;
107
108 uint64_t serial;
109
110 char *unique_name;
111
392d5b37 112 struct bus_match_node match_callbacks;
e3017af9 113 Prioq *reply_callbacks_prioq;
de1c301e
LP
114 Hashmap *reply_callbacks;
115 LIST_HEAD(struct filter_callback, filter_callbacks);
a652755d 116 Hashmap *object_callbacks;
de1c301e
LP
117
118 union {
119 struct sockaddr sa;
120 struct sockaddr_un un;
121 struct sockaddr_in in;
122 struct sockaddr_in6 in6;
123 } sockaddr;
124 socklen_t sockaddr_size;
125
6629161f
LP
126 char *kernel;
127
98178d39 128 sd_id128_t server_id;
de1c301e
LP
129
130 char *address;
131 unsigned address_index;
132
133 int last_connect_error;
134
2181a7f5
LP
135 enum bus_auth auth;
136 size_t auth_rbegin;
de1c301e
LP
137 struct iovec auth_iovec[3];
138 unsigned auth_index;
2181a7f5 139 char *auth_buffer;
e3017af9 140 usec_t auth_timeout;
2571ead1
LP
141
142 struct ucred ucred;
143 char label[NAME_MAX];
2c93b4ef
LP
144
145 int *fds;
146 unsigned n_fds;
2fd9ae2e
LP
147
148 char *exec_path;
149 char **exec_argv;
9d373862
LP
150
151 uint64_t hello_serial;
7286037f 152 unsigned iteration_counter;
de1c301e 153};
89ffcd2a
LP
154
155static inline void bus_unrefp(sd_bus **b) {
156 sd_bus_unref(*b);
157}
158
159#define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp)))
b9bf7e2b 160#define _cleanup_bus_error_free_ __attribute__((cleanup(sd_bus_error_free)))
e3017af9
LP
161
162#define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
25220239
LP
163
164#define BUS_WQUEUE_MAX 128
165#define BUS_RQUEUE_MAX 128
166
167#define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
168#define BUS_AUTH_SIZE_MAX (64*1024)
ac89bf1d 169
ed205a6b
LP
170#define BUS_CONTAINER_DEPTH 128
171
ac89bf1d
LP
172/* Defined by the specification as maximum size of an array in
173 * bytes */
174#define BUS_ARRAY_MAX_SIZE 67108864
175
2c93b4ef
LP
176#define BUS_FDS_MAX 1024
177
2fd9ae2e
LP
178#define BUS_EXEC_ARGV_MAX 256
179
ac89bf1d 180bool object_path_is_valid(const char *p);
6693860f
LP
181bool interface_name_is_valid(const char *p);
182bool service_name_is_valid(const char *p);
183bool member_name_is_valid(const char *p);
184
392d5b37
LP
185bool namespace_complex_pattern(const char *pattern, const char *value);
186bool path_complex_pattern(const char *pattern, const char *value);
187
188bool namespace_simple_pattern(const char *pattern, const char *value);
189bool path_simple_pattern(const char *pattern, const char *value);
190
191int bus_message_type_from_string(const char *s, uint8_t *u);
a56f19c4 192const char *bus_message_type_to_string(uint8_t u);
392d5b37 193
6693860f 194#define error_name_is_valid interface_name_is_valid
20902f3e
LP
195
196int bus_ensure_running(sd_bus *bus);
a7e3212d
LP
197int bus_start_running(sd_bus *bus);
198int bus_next_address(sd_bus *bus);