chiark / gitweb /
c25a208aea35ed59f5a76160d84329788ef6cd80
[elogind.git] / src / libsystemd-bus / bus-internal.h
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"
29 #include "prioq.h"
30 #include "list.h"
31 #include "util.h"
32
33 #include "sd-bus.h"
34 #include "bus-error.h"
35
36 struct reply_callback {
37         sd_message_handler_t callback;
38         void *userdata;
39         usec_t timeout;
40         uint64_t serial;
41         unsigned prioq_idx;
42 };
43
44 struct filter_callback {
45         sd_message_handler_t callback;
46         void *userdata;
47
48         LIST_FIELDS(struct filter_callback, callbacks);
49 };
50
51 struct object_callback {
52         sd_message_handler_t callback;
53         void *userdata;
54
55         char *path;
56         bool is_fallback;
57 };
58
59 enum bus_state {
60         BUS_UNSET,
61         BUS_OPENING,
62         BUS_AUTHENTICATING,
63         BUS_HELLO,
64         BUS_RUNNING
65 };
66
67 struct sd_bus {
68         unsigned n_ref;
69         enum bus_state state;
70         int fd;
71         int message_version;
72
73         bool negotiate_fds:1;
74         bool can_fds:1;
75         bool bus_client:1;
76         bool ucred_valid:1;
77
78         void *rbuffer;
79         size_t rbuffer_size;
80
81         sd_bus_message **rqueue;
82         unsigned rqueue_size;
83
84         sd_bus_message **wqueue;
85         unsigned wqueue_size;
86         size_t windex;
87
88         uint64_t serial;
89
90         char *unique_name;
91
92         Prioq *reply_callbacks_prioq;
93         Hashmap *reply_callbacks;
94         LIST_HEAD(struct filter_callback, filter_callbacks);
95         Hashmap *object_callbacks;
96
97         union {
98                 struct sockaddr sa;
99                 struct sockaddr_un un;
100                 struct sockaddr_in in;
101                 struct sockaddr_in6 in6;
102         } sockaddr;
103         socklen_t sockaddr_size;
104
105         sd_id128_t peer;
106
107         char *address;
108         unsigned address_index;
109
110         int last_connect_error;
111
112         struct iovec auth_iovec[3];
113         unsigned auth_index;
114         size_t auth_size;
115         char *auth_uid;
116         usec_t auth_timeout;
117
118         struct ucred ucred;
119         char label[NAME_MAX];
120
121         int *fds;
122         unsigned n_fds;
123
124         char *exec_path;
125         char **exec_argv;
126 };
127
128 static inline void bus_unrefp(sd_bus **b) {
129         sd_bus_unref(*b);
130 }
131
132 #define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp)))
133 #define _cleanup_bus_error_free_ __attribute__((cleanup(sd_bus_error_free)))
134
135 #define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
136
137 #define BUS_WQUEUE_MAX 128
138 #define BUS_RQUEUE_MAX 128
139
140 #define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
141 #define BUS_AUTH_SIZE_MAX (64*1024)
142
143 #define BUS_CONTAINER_DEPTH 128
144
145 /* Defined by the specification as maximum size of an array in
146  * bytes */
147 #define BUS_ARRAY_MAX_SIZE 67108864
148
149 #define BUS_FDS_MAX 1024
150
151 #define BUS_EXEC_ARGV_MAX 256
152
153 bool object_path_is_valid(const char *p);
154 bool interface_name_is_valid(const char *p);
155 bool service_name_is_valid(const char *p);
156 bool member_name_is_valid(const char *p);
157
158 #define error_name_is_valid interface_name_is_valid
159
160 int bus_ensure_running(sd_bus *bus);
161 int bus_start_running(sd_bus *bus);
162 int bus_next_address(sd_bus *bus);