]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-bus/bus-internal.h
bus: add missing test-bus-server.c
[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"
35
36struct reply_callback {
37 sd_message_handler_t callback;
38 void *userdata;
39 usec_t timeout;
40 uint64_t serial;
e3017af9 41 unsigned prioq_idx;
de1c301e
LP
42};
43
44struct filter_callback {
45 sd_message_handler_t callback;
46 void *userdata;
47
48 LIST_FIELDS(struct filter_callback, callbacks);
49};
50
a652755d
LP
51struct object_callback {
52 sd_message_handler_t callback;
53 void *userdata;
54
55 char *path;
56 bool is_fallback;
57};
58
de1c301e 59enum bus_state {
021a1e78 60 BUS_UNSET,
de1c301e
LP
61 BUS_OPENING,
62 BUS_AUTHENTICATING,
63 BUS_HELLO,
89ffcd2a 64 BUS_RUNNING
de1c301e
LP
65};
66
2181a7f5
LP
67enum bus_auth {
68 _BUS_AUTH_INVALID,
69 BUS_AUTH_EXTERNAL,
70 BUS_AUTH_ANONYMOUS
71};
72
de1c301e
LP
73struct sd_bus {
74 unsigned n_ref;
75 enum bus_state state;
76 int fd;
77 int message_version;
021a1e78
LP
78
79 bool negotiate_fds:1;
de1c301e 80 bool can_fds:1;
94bbf1ba 81 bool bus_client:1;
2571ead1 82 bool ucred_valid:1;
2181a7f5
LP
83 bool is_server:1;
84 bool anonymous_auth:1;
de1c301e
LP
85
86 void *rbuffer;
87 size_t rbuffer_size;
88
89 sd_bus_message **rqueue;
90 unsigned rqueue_size;
91
92 sd_bus_message **wqueue;
93 unsigned wqueue_size;
94 size_t windex;
95
96 uint64_t serial;
97
98 char *unique_name;
99
e3017af9 100 Prioq *reply_callbacks_prioq;
de1c301e
LP
101 Hashmap *reply_callbacks;
102 LIST_HEAD(struct filter_callback, filter_callbacks);
a652755d 103 Hashmap *object_callbacks;
de1c301e
LP
104
105 union {
106 struct sockaddr sa;
107 struct sockaddr_un un;
108 struct sockaddr_in in;
109 struct sockaddr_in6 in6;
110 } sockaddr;
111 socklen_t sockaddr_size;
112
113 sd_id128_t peer;
114
115 char *address;
116 unsigned address_index;
117
118 int last_connect_error;
119
2181a7f5
LP
120 enum bus_auth auth;
121 size_t auth_rbegin;
de1c301e
LP
122 struct iovec auth_iovec[3];
123 unsigned auth_index;
2181a7f5 124 char *auth_buffer;
e3017af9 125 usec_t auth_timeout;
2571ead1
LP
126
127 struct ucred ucred;
128 char label[NAME_MAX];
2c93b4ef
LP
129
130 int *fds;
131 unsigned n_fds;
2fd9ae2e
LP
132
133 char *exec_path;
134 char **exec_argv;
9d373862
LP
135
136 uint64_t hello_serial;
de1c301e 137};
89ffcd2a
LP
138
139static inline void bus_unrefp(sd_bus **b) {
140 sd_bus_unref(*b);
141}
142
143#define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp)))
b9bf7e2b 144#define _cleanup_bus_error_free_ __attribute__((cleanup(sd_bus_error_free)))
e3017af9
LP
145
146#define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
25220239
LP
147
148#define BUS_WQUEUE_MAX 128
149#define BUS_RQUEUE_MAX 128
150
151#define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
152#define BUS_AUTH_SIZE_MAX (64*1024)
ac89bf1d 153
ed205a6b
LP
154#define BUS_CONTAINER_DEPTH 128
155
ac89bf1d
LP
156/* Defined by the specification as maximum size of an array in
157 * bytes */
158#define BUS_ARRAY_MAX_SIZE 67108864
159
2c93b4ef
LP
160#define BUS_FDS_MAX 1024
161
2fd9ae2e
LP
162#define BUS_EXEC_ARGV_MAX 256
163
ac89bf1d 164bool object_path_is_valid(const char *p);
6693860f
LP
165bool interface_name_is_valid(const char *p);
166bool service_name_is_valid(const char *p);
167bool member_name_is_valid(const char *p);
168
169#define error_name_is_valid interface_name_is_valid
20902f3e
LP
170
171int bus_ensure_running(sd_bus *bus);
a7e3212d
LP
172int bus_start_running(sd_bus *bus);
173int bus_next_address(sd_bus *bus);