]>
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" | |
35 | ||
36 | struct 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 | ||
44 | struct filter_callback { | |
45 | sd_message_handler_t callback; | |
46 | void *userdata; | |
47 | ||
48 | LIST_FIELDS(struct filter_callback, callbacks); | |
49 | }; | |
50 | ||
51 | enum bus_state { | |
52 | BUS_OPENING, | |
53 | BUS_AUTHENTICATING, | |
54 | BUS_HELLO, | |
89ffcd2a | 55 | BUS_RUNNING |
de1c301e LP |
56 | }; |
57 | ||
58 | struct sd_bus { | |
59 | unsigned n_ref; | |
60 | enum bus_state state; | |
61 | int fd; | |
62 | int message_version; | |
63 | bool can_fds:1; | |
89ffcd2a | 64 | bool sent_hello:1; |
de1c301e LP |
65 | |
66 | void *rbuffer; | |
67 | size_t rbuffer_size; | |
68 | ||
69 | sd_bus_message **rqueue; | |
70 | unsigned rqueue_size; | |
71 | ||
72 | sd_bus_message **wqueue; | |
73 | unsigned wqueue_size; | |
74 | size_t windex; | |
75 | ||
76 | uint64_t serial; | |
77 | ||
78 | char *unique_name; | |
79 | ||
e3017af9 | 80 | Prioq *reply_callbacks_prioq; |
de1c301e LP |
81 | Hashmap *reply_callbacks; |
82 | LIST_HEAD(struct filter_callback, filter_callbacks); | |
83 | ||
84 | union { | |
85 | struct sockaddr sa; | |
86 | struct sockaddr_un un; | |
87 | struct sockaddr_in in; | |
88 | struct sockaddr_in6 in6; | |
89 | } sockaddr; | |
90 | socklen_t sockaddr_size; | |
91 | ||
92 | sd_id128_t peer; | |
93 | ||
94 | char *address; | |
95 | unsigned address_index; | |
96 | ||
97 | int last_connect_error; | |
98 | ||
99 | struct iovec auth_iovec[3]; | |
100 | unsigned auth_index; | |
101 | size_t auth_size; | |
102 | char *auth_uid; | |
e3017af9 | 103 | usec_t auth_timeout; |
de1c301e | 104 | }; |
89ffcd2a LP |
105 | |
106 | static inline void bus_unrefp(sd_bus **b) { | |
107 | sd_bus_unref(*b); | |
108 | } | |
109 | ||
110 | #define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp))) | |
b9bf7e2b | 111 | #define _cleanup_bus_error_free_ __attribute__((cleanup(sd_bus_error_free))) |
e3017af9 LP |
112 | |
113 | #define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC)) | |
25220239 LP |
114 | |
115 | #define BUS_WQUEUE_MAX 128 | |
116 | #define BUS_RQUEUE_MAX 128 | |
117 | ||
118 | #define BUS_MESSAGE_SIZE_MAX (64*1024*1024) | |
119 | #define BUS_AUTH_SIZE_MAX (64*1024) |