chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / libelogind / sd-bus / bus-protocol.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5   Copyright 2013 Lennart Poettering
6 ***/
7
8 #include <endian.h>
9
10 #include "macro.h"
11
12 /* Packet header */
13
14 struct _packed_ bus_header {
15         /* The first four fields are identical for dbus1, and dbus2 */
16         uint8_t endian;
17         uint8_t type;
18         uint8_t flags;
19         uint8_t version;
20
21         union _packed_ {
22                 /* dbus1: Used for SOCK_STREAM connections */
23                 struct _packed_ {
24                         uint32_t body_size;
25
26                         /* Note that what the bus spec calls "serial" we'll call
27                            "cookie" instead, because we don't want to imply that the
28                            cookie was in any way monotonically increasing. */
29                         uint32_t serial;
30                         uint32_t fields_size;
31                 } dbus1;
32
33                 /* dbus2: Used for kdbus connections */
34                 struct _packed_ {
35                         uint32_t _reserved;
36                         uint64_t cookie;
37                 } dbus2;
38
39                 /* Note that both header versions have the same size! */
40         };
41 };
42
43 /* Endianness */
44
45 enum {
46         _BUS_INVALID_ENDIAN = 0,
47         BUS_LITTLE_ENDIAN   = 'l',
48         BUS_BIG_ENDIAN      = 'B',
49 #if __BYTE_ORDER == __BIG_ENDIAN
50         BUS_NATIVE_ENDIAN   = BUS_BIG_ENDIAN,
51         BUS_REVERSE_ENDIAN  = BUS_LITTLE_ENDIAN
52 #else
53         BUS_NATIVE_ENDIAN   = BUS_LITTLE_ENDIAN,
54         BUS_REVERSE_ENDIAN  = BUS_BIG_ENDIAN
55 #endif
56 };
57
58 /* Flags */
59
60 enum {
61         BUS_MESSAGE_NO_REPLY_EXPECTED = 1,
62         BUS_MESSAGE_NO_AUTO_START = 2,
63         BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION = 4,
64 };
65
66 /* Header fields */
67
68 enum {
69         _BUS_MESSAGE_HEADER_INVALID = 0,
70         BUS_MESSAGE_HEADER_PATH,
71         BUS_MESSAGE_HEADER_INTERFACE,
72         BUS_MESSAGE_HEADER_MEMBER,
73         BUS_MESSAGE_HEADER_ERROR_NAME,
74         BUS_MESSAGE_HEADER_REPLY_SERIAL,
75         BUS_MESSAGE_HEADER_DESTINATION,
76         BUS_MESSAGE_HEADER_SENDER,
77         BUS_MESSAGE_HEADER_SIGNATURE,
78         BUS_MESSAGE_HEADER_UNIX_FDS,
79         _BUS_MESSAGE_HEADER_MAX
80 };
81
82 /* RequestName parameters */
83
84 enum  {
85         BUS_NAME_ALLOW_REPLACEMENT = 1,
86         BUS_NAME_REPLACE_EXISTING = 2,
87         BUS_NAME_DO_NOT_QUEUE = 4
88 };
89
90 /* RequestName returns */
91 enum  {
92         BUS_NAME_PRIMARY_OWNER = 1,
93         BUS_NAME_IN_QUEUE = 2,
94         BUS_NAME_EXISTS = 3,
95         BUS_NAME_ALREADY_OWNER = 4
96 };
97
98 /* ReleaseName returns */
99 enum {
100         BUS_NAME_RELEASED = 1,
101         BUS_NAME_NON_EXISTENT = 2,
102         BUS_NAME_NOT_OWNER = 3,
103 };
104
105 /* StartServiceByName returns */
106 enum {
107         BUS_START_REPLY_SUCCESS = 1,
108         BUS_START_REPLY_ALREADY_RUNNING = 2,
109 };
110
111 #define BUS_INTROSPECT_DOCTYPE                                       \
112         "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" \
113         "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
114
115 #define BUS_INTROSPECT_INTERFACE_PEER                                \
116         " <interface name=\"org.freedesktop.DBus.Peer\">\n"             \
117         "  <method name=\"Ping\"/>\n"                                   \
118         "  <method name=\"GetMachineId\">\n"                            \
119         "   <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
120         "  </method>\n"                                                 \
121         " </interface>\n"
122
123 #define BUS_INTROSPECT_INTERFACE_INTROSPECTABLE                      \
124         " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"   \
125         "  <method name=\"Introspect\">\n"                              \
126         "   <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"        \
127         "  </method>\n"                                                 \
128         " </interface>\n"
129
130 #define BUS_INTROSPECT_INTERFACE_PROPERTIES                          \
131         " <interface name=\"org.freedesktop.DBus.Properties\">\n"       \
132         "  <method name=\"Get\">\n"                                     \
133         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
134         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
135         "   <arg name=\"value\" direction=\"out\" type=\"v\"/>\n"       \
136         "  </method>\n"                                                 \
137         "  <method name=\"GetAll\">\n"                                  \
138         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
139         "   <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
140         "  </method>\n"                                                 \
141         "  <method name=\"Set\">\n"                                     \
142         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
143         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
144         "   <arg name=\"value\" direction=\"in\" type=\"v\"/>\n"        \
145         "  </method>\n"                                                 \
146         "  <signal name=\"PropertiesChanged\">\n"                       \
147         "   <arg type=\"s\" name=\"interface\"/>\n"                     \
148         "   <arg type=\"a{sv}\" name=\"changed_properties\"/>\n"        \
149         "   <arg type=\"as\" name=\"invalidated_properties\"/>\n"       \
150         "  </signal>\n"                                                 \
151         " </interface>\n"
152
153 #define BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER                      \
154         " <interface name=\"org.freedesktop.DBus.ObjectManager\">\n"    \
155         "  <method name=\"GetManagedObjects\">\n"                       \
156         "   <arg type=\"a{oa{sa{sv}}}\" name=\"object_paths_interfaces_and_properties\" direction=\"out\"/>\n" \
157         "  </method>\n"                                                 \
158         "  <signal name=\"InterfacesAdded\">\n"                         \
159         "   <arg type=\"o\" name=\"object_path\"/>\n"                   \
160         "   <arg type=\"a{sa{sv}}\" name=\"interfaces_and_properties\"/>\n" \
161         "  </signal>\n"                                                 \
162         "  <signal name=\"InterfacesRemoved\">\n"                       \
163         "   <arg type=\"o\" name=\"object_path\"/>\n"                   \
164         "   <arg type=\"as\" name=\"interfaces\"/>\n"                   \
165         "  </signal>\n"                                                 \
166         " </interface>\n"