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