]>
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" | |
29 | #include "list.h" | |
30 | #include "util.h" | |
31 | ||
32 | #include "sd-bus.h" | |
33 | #include "bus-error.h" | |
34 | ||
35 | struct reply_callback { | |
36 | sd_message_handler_t callback; | |
37 | void *userdata; | |
38 | usec_t timeout; | |
39 | uint64_t serial; | |
40 | }; | |
41 | ||
42 | struct filter_callback { | |
43 | sd_message_handler_t callback; | |
44 | void *userdata; | |
45 | ||
46 | LIST_FIELDS(struct filter_callback, callbacks); | |
47 | }; | |
48 | ||
49 | enum bus_state { | |
50 | BUS_OPENING, | |
51 | BUS_AUTHENTICATING, | |
52 | BUS_HELLO, | |
89ffcd2a | 53 | BUS_RUNNING |
de1c301e LP |
54 | }; |
55 | ||
56 | struct sd_bus { | |
57 | unsigned n_ref; | |
58 | enum bus_state state; | |
59 | int fd; | |
60 | int message_version; | |
61 | bool can_fds:1; | |
89ffcd2a | 62 | bool sent_hello:1; |
de1c301e LP |
63 | |
64 | void *rbuffer; | |
65 | size_t rbuffer_size; | |
66 | ||
67 | sd_bus_message **rqueue; | |
68 | unsigned rqueue_size; | |
69 | ||
70 | sd_bus_message **wqueue; | |
71 | unsigned wqueue_size; | |
72 | size_t windex; | |
73 | ||
74 | uint64_t serial; | |
75 | ||
76 | char *unique_name; | |
77 | ||
78 | Hashmap *reply_callbacks; | |
79 | LIST_HEAD(struct filter_callback, filter_callbacks); | |
80 | ||
81 | union { | |
82 | struct sockaddr sa; | |
83 | struct sockaddr_un un; | |
84 | struct sockaddr_in in; | |
85 | struct sockaddr_in6 in6; | |
86 | } sockaddr; | |
87 | socklen_t sockaddr_size; | |
88 | ||
89 | sd_id128_t peer; | |
90 | ||
91 | char *address; | |
92 | unsigned address_index; | |
93 | ||
94 | int last_connect_error; | |
95 | ||
96 | struct iovec auth_iovec[3]; | |
97 | unsigned auth_index; | |
98 | size_t auth_size; | |
99 | char *auth_uid; | |
100 | }; | |
89ffcd2a LP |
101 | |
102 | static inline void bus_unrefp(sd_bus **b) { | |
103 | sd_bus_unref(*b); | |
104 | } | |
105 | ||
106 | #define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp))) |