chiark / gitweb /
bus: add basic implementation of a native bus client library
[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 "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,
53         BUS_RUNNING,
54         BUS_CLOSED
55 };
56
57 struct sd_bus {
58         unsigned n_ref;
59         enum bus_state state;
60         int fd;
61         int message_version;
62         bool can_fds:1;
63         bool send_hello:1;
64
65         void *rbuffer;
66         size_t rbuffer_size;
67
68         sd_bus_message **rqueue;
69         unsigned rqueue_size;
70
71         sd_bus_message **wqueue;
72         unsigned wqueue_size;
73         size_t windex;
74
75         uint64_t serial;
76
77         char *unique_name;
78
79         Hashmap *reply_callbacks;
80         LIST_HEAD(struct filter_callback, filter_callbacks);
81
82         union {
83                 struct sockaddr sa;
84                 struct sockaddr_un un;
85                 struct sockaddr_in in;
86                 struct sockaddr_in6 in6;
87         } sockaddr;
88         socklen_t sockaddr_size;
89
90         sd_id128_t peer;
91
92         char *address;
93         unsigned address_index;
94
95         int last_connect_error;
96
97         struct iovec auth_iovec[3];
98         unsigned auth_index;
99         size_t auth_size;
100         char *auth_uid;
101 };