Debian Codegraph @

src/dbus/connection.h

raw
1 #pragma once
2
3 /*
4 * Connection
5 */
6
7 #include <c-stdaux.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include "dbus/sasl.h"
11 #include "dbus/socket.h"
12 #include "util/dispatch.h"
13
14 typedef struct Connection Connection;
15 typedef struct Message Message;
16 typedef struct User User;
17
18 enum {
19 _CONNECTION_E_SUCCESS,
20
21 CONNECTION_E_SASL_FAILURE,
22 CONNECTION_E_SASL_VIOLATION,
23
24 CONNECTION_E_EOF,
25 CONNECTION_E_QUOTA,
26 CONNECTION_E_UNEXPECTED_FDS,
27 };
28
29 struct Connection {
30 Socket socket;
31 DispatchFile socket_file;
32 SASLServer sasl_server;
33 SASLClient sasl_client;
34
35 bool server : 1;
36 bool authenticated : 1;
37 };
38
39 #define CONNECTION_NULL(_x) { \
40 .socket = SOCKET_NULL((_x).socket), \
41 .socket_file = DISPATCH_FILE_NULL((_x).socket_file), \
42 .sasl_server = SASL_SERVER_NULL, \
43 .sasl_client = SASL_CLIENT_NULL, \
44 }
45
46 int connection_init_server(Connection *connection,
47 DispatchContext *dispatch_ctx,
48 DispatchFn dispatch_fn,
49 User *user,
50 const char *guid,
51 int fd);
52 int connection_init_client(Connection *connection,
53 DispatchContext *dispatch_ctx,
54 DispatchFn dispatch_fn,
55 User *user,
56 int fd);
57 void connection_deinit(Connection *connection);
58
59 void connection_get_stats(Connection *connection,
60 unsigned int *n_in_bytesp,
61 unsigned int *n_in_fdsp,
62 unsigned int *n_out_bytesp,
63 unsigned int *n_out_fdsp);
64 int connection_open(Connection *connection);
65 void connection_shutdown(Connection *connection);
66 void connection_close(Connection *connection);
67 int connection_dispatch(Connection *connection, uint32_t events);
68
69 int connection_dequeue(Connection *connection, Message **messagep);
70 int connection_queue(Connection *connection, User *user, Message *message);
71
72 C_DEFINE_CLEANUP(Connection *, connection_deinit);
73
74 /* inline helpers */
75
76 static inline bool connection_is_running(Connection *connection) {
77 return socket_is_running(&connection->socket);
78 }