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