4cfb6d161e4ca5cf518859561acfdddf7ad77522
[platform/upstream/dbus.git] / dbus / dbus-protocol.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-protocol.h  D-Bus protocol constants
3  *
4  * Copyright (C) 2002, 2003  CodeFactory AB
5  * Copyright (C) 2004, 2005 Red Hat, Inc.
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  */
24
25 #ifndef DBUS_PROTOCOL_H
26 #define DBUS_PROTOCOL_H
27
28 /* Don't include anything in here from anywhere else. It's
29  * intended for use by any random library.
30  */
31
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35
36 /* Normally docs are in .c files, but there isn't a .c file for this. */
37 /**
38  * @defgroup DBusProtocol Protocol constants
39  * @ingroup  DBus
40  *
41  * D-Bus protocol constants
42  *
43  * @brief  Defines constants which are part of the D-Bus protocol
44  * @{
45  */
46
47
48 /* Message byte order */
49 #define DBUS_LITTLE_ENDIAN ('l')  /**< LSB first */
50 #define DBUS_BIG_ENDIAN    ('B')  /**< MSB first */
51
52 /** Protocol version */
53 #define DBUS_MAJOR_PROTOCOL_VERSION 1
54
55 /** Never a legitimate type */
56 #define DBUS_TYPE_INVALID       ((int) '\0')
57 #define DBUS_TYPE_INVALID_AS_STRING        "\0"
58
59 /* Primitive types */
60 #define DBUS_TYPE_BYTE          ((int) 'y')
61 #define DBUS_TYPE_BYTE_AS_STRING           "y"
62 #define DBUS_TYPE_BOOLEAN       ((int) 'b')
63 #define DBUS_TYPE_BOOLEAN_AS_STRING        "b"
64 #define DBUS_TYPE_INT16         ((int) 'n')
65 #define DBUS_TYPE_INT16_AS_STRING          "n"
66 #define DBUS_TYPE_UINT16        ((int) 'q')
67 #define DBUS_TYPE_UINT16_AS_STRING         "q"
68 #define DBUS_TYPE_INT32         ((int) 'i')
69 #define DBUS_TYPE_INT32_AS_STRING          "i"
70 #define DBUS_TYPE_UINT32        ((int) 'u')
71 #define DBUS_TYPE_UINT32_AS_STRING         "u"
72 #define DBUS_TYPE_INT64         ((int) 'x')
73 #define DBUS_TYPE_INT64_AS_STRING          "x"
74 #define DBUS_TYPE_UINT64        ((int) 't')
75 #define DBUS_TYPE_UINT64_AS_STRING         "t"
76 #define DBUS_TYPE_DOUBLE        ((int) 'd')
77 #define DBUS_TYPE_DOUBLE_AS_STRING         "d"
78 #define DBUS_TYPE_STRING        ((int) 's')
79 #define DBUS_TYPE_STRING_AS_STRING         "s"
80 #define DBUS_TYPE_OBJECT_PATH   ((int) 'o')
81 #define DBUS_TYPE_OBJECT_PATH_AS_STRING    "o"
82 #define DBUS_TYPE_SIGNATURE     ((int) 'g')
83 #define DBUS_TYPE_SIGNATURE_AS_STRING      "g"
84
85 /* Compound types */
86 #define DBUS_TYPE_ARRAY         ((int) 'a')
87 #define DBUS_TYPE_ARRAY_AS_STRING          "a"
88 #define DBUS_TYPE_VARIANT       ((int) 'v')
89 #define DBUS_TYPE_VARIANT_AS_STRING        "v"
90
91 /** STRUCT and DICT_ENTRY are sort of special since their codes can't
92  * appear in a type string, instead
93  * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear
94  */
95 #define DBUS_TYPE_STRUCT        ((int) 'r')
96 #define DBUS_TYPE_STRUCT_AS_STRING         "r"
97 #define DBUS_TYPE_DICT_ENTRY    ((int) 'e')
98 #define DBUS_TYPE_DICT_ENTRY_AS_STRING     "e"
99
100 /** Does not count INVALID */
101 #define DBUS_NUMBER_OF_TYPES    (16)
102
103 /* characters other than typecodes that appear in type signatures */
104 #define DBUS_STRUCT_BEGIN_CHAR   ((int) '(')
105 #define DBUS_STRUCT_BEGIN_CHAR_AS_STRING   "("
106 #define DBUS_STRUCT_END_CHAR     ((int) ')')
107 #define DBUS_STRUCT_END_CHAR_AS_STRING     ")"
108 #define DBUS_DICT_ENTRY_BEGIN_CHAR   ((int) '{')
109 #define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING   "{"
110 #define DBUS_DICT_ENTRY_END_CHAR     ((int) '}')
111 #define DBUS_DICT_ENTRY_END_CHAR_AS_STRING     "}"
112
113 /** Max length in bytes of a bus name, interface, or member (not object
114  * path, paths are unlimited). This is limited because lots of stuff
115  * is O(n) in this number, plus it would be obnoxious to type in a
116  * paragraph-long method name so most likely something like that would
117  * be an exploit.
118  */
119 #define DBUS_MAXIMUM_NAME_LENGTH 255
120
121 /** This one is 255 so it fits in a byte */
122 #define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
123
124 /** Max length of a match rule string; to keep people from hosing the
125  * daemon with some huge rule
126  */
127 #define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024
128
129 /** Max arg number you can match on in a match rule, e.g.
130  * arg0='hello' is OK, arg3489720987='hello' is not
131  */
132 #define DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER 63
133   
134 /** Max length of a marshaled array in bytes (64M, 2^26) We use signed
135  * int for lengths so must be INT_MAX or less.  We need something a
136  * bit smaller than INT_MAX because the array is inside a message with
137  * header info, etc.  so an INT_MAX array wouldn't allow the message
138  * overhead.  The 64M number is an attempt at a larger number than
139  * we'd reasonably ever use, but small enough that your bus would chew
140  * through it fairly quickly without locking up forever. If you have
141  * data that's likely to be larger than this, you should probably be
142  * sending it in multiple incremental messages anyhow.
143  */
144 #define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
145 /** Number of bits you need in an unsigned to store the max array size */
146 #define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
147
148 /** The maximum total message size including header and body; similar
149  * rationale to max array size.
150  */
151 #define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
152 /** Number of bits you need in an unsigned to store the max message size */
153 #define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
154
155 /** Depth of recursion in the type tree. This is automatically limited
156  * to DBUS_MAXIMUM_SIGNATURE_LENGTH since you could only have an array
157  * of array of array of ... that fit in the max signature.  But that's
158  * probably a bit too large.
159  */
160 #define DBUS_MAXIMUM_TYPE_RECURSION_DEPTH 32
161
162 /* Types of message */
163 #define DBUS_MESSAGE_TYPE_INVALID       0
164 #define DBUS_MESSAGE_TYPE_METHOD_CALL   1
165 #define DBUS_MESSAGE_TYPE_METHOD_RETURN 2
166 #define DBUS_MESSAGE_TYPE_ERROR         3
167 #define DBUS_MESSAGE_TYPE_SIGNAL        4
168
169 /* Header flags */
170 #define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1
171 #define DBUS_HEADER_FLAG_NO_AUTO_START     0x2
172
173 /* Header fields */
174 #define DBUS_HEADER_FIELD_INVALID        0
175 #define DBUS_HEADER_FIELD_PATH           1
176 #define DBUS_HEADER_FIELD_INTERFACE      2
177 #define DBUS_HEADER_FIELD_MEMBER         3
178 #define DBUS_HEADER_FIELD_ERROR_NAME     4
179 #define DBUS_HEADER_FIELD_REPLY_SERIAL   5
180 #define DBUS_HEADER_FIELD_DESTINATION    6
181 #define DBUS_HEADER_FIELD_SENDER         7
182 #define DBUS_HEADER_FIELD_SIGNATURE      8
183
184 #define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_SIGNATURE
185
186 /** Header format is defined as a signature:
187  *   byte                            byte order
188  *   byte                            message type ID
189  *   byte                            flags
190  *   byte                            protocol version
191  *   uint32                          body length
192  *   uint32                          serial
193  *   array of struct (byte,variant)  (field name, value)
194  *
195  * The length of the header can be computed as the
196  * fixed size of the initial data, plus the length of
197  * the array at the end, plus padding to an 8-boundary.
198  */
199 #define DBUS_HEADER_SIGNATURE                   \
200      DBUS_TYPE_BYTE_AS_STRING                   \
201      DBUS_TYPE_BYTE_AS_STRING                   \
202      DBUS_TYPE_BYTE_AS_STRING                   \
203      DBUS_TYPE_BYTE_AS_STRING                   \
204      DBUS_TYPE_UINT32_AS_STRING                 \
205      DBUS_TYPE_UINT32_AS_STRING                 \
206      DBUS_TYPE_ARRAY_AS_STRING                  \
207      DBUS_STRUCT_BEGIN_CHAR_AS_STRING           \
208      DBUS_TYPE_BYTE_AS_STRING                   \
209      DBUS_TYPE_VARIANT_AS_STRING                \
210      DBUS_STRUCT_END_CHAR_AS_STRING
211
212
213 /**
214  * The smallest header size that can occur.  (It won't be valid due to
215  * missing required header fields.) This is 4 bytes, two uint32, an
216  * array length. This isn't any kind of resource limit, just the
217  * necessary/logical outcome of the header signature.
218  */
219 #define DBUS_MINIMUM_HEADER_SIZE 16
220
221 /* Errors */
222 /* WARNING these get autoconverted to an enum in dbus-glib.h. Thus,
223  * if you change the order it breaks the ABI. Keep them in order.
224  * Also, don't change the formatting since that will break the sed
225  * script.
226  */
227 #define DBUS_ERROR_FAILED                     "org.freedesktop.DBus.Error.Failed"
228 #define DBUS_ERROR_NO_MEMORY                  "org.freedesktop.DBus.Error.NoMemory"
229 #define DBUS_ERROR_SERVICE_UNKNOWN            "org.freedesktop.DBus.Error.ServiceUnknown"
230 #define DBUS_ERROR_NAME_HAS_NO_OWNER          "org.freedesktop.DBus.Error.NameHasNoOwner"
231 #define DBUS_ERROR_NO_REPLY                   "org.freedesktop.DBus.Error.NoReply"
232 #define DBUS_ERROR_IO_ERROR                   "org.freedesktop.DBus.Error.IOError"
233 #define DBUS_ERROR_BAD_ADDRESS                "org.freedesktop.DBus.Error.BadAddress"
234 #define DBUS_ERROR_NOT_SUPPORTED              "org.freedesktop.DBus.Error.NotSupported"
235 #define DBUS_ERROR_LIMITS_EXCEEDED            "org.freedesktop.DBus.Error.LimitsExceeded"
236 #define DBUS_ERROR_ACCESS_DENIED              "org.freedesktop.DBus.Error.AccessDenied"
237 #define DBUS_ERROR_AUTH_FAILED                "org.freedesktop.DBus.Error.AuthFailed"
238 #define DBUS_ERROR_NO_SERVER                  "org.freedesktop.DBus.Error.NoServer"
239 #define DBUS_ERROR_TIMEOUT                    "org.freedesktop.DBus.Error.Timeout"
240 #define DBUS_ERROR_NO_NETWORK                 "org.freedesktop.DBus.Error.NoNetwork"
241 #define DBUS_ERROR_ADDRESS_IN_USE             "org.freedesktop.DBus.Error.AddressInUse"
242 #define DBUS_ERROR_DISCONNECTED               "org.freedesktop.DBus.Error.Disconnected"
243 #define DBUS_ERROR_INVALID_ARGS               "org.freedesktop.DBus.Error.InvalidArgs"
244 #define DBUS_ERROR_FILE_NOT_FOUND             "org.freedesktop.DBus.Error.FileNotFound"
245 #define DBUS_ERROR_FILE_EXISTS                "org.freedesktop.DBus.Error.FileExists"
246 #define DBUS_ERROR_UNKNOWN_METHOD             "org.freedesktop.DBus.Error.UnknownMethod"
247 #define DBUS_ERROR_TIMED_OUT                  "org.freedesktop.DBus.Error.TimedOut"
248 #define DBUS_ERROR_MATCH_RULE_NOT_FOUND       "org.freedesktop.DBus.Error.MatchRuleNotFound"
249 #define DBUS_ERROR_MATCH_RULE_INVALID         "org.freedesktop.DBus.Error.MatchRuleInvalid"
250 #define DBUS_ERROR_SPAWN_EXEC_FAILED          "org.freedesktop.DBus.Error.Spawn.ExecFailed"
251 #define DBUS_ERROR_SPAWN_FORK_FAILED          "org.freedesktop.DBus.Error.Spawn.ForkFailed"
252 #define DBUS_ERROR_SPAWN_CHILD_EXITED         "org.freedesktop.DBus.Error.Spawn.ChildExited"
253 #define DBUS_ERROR_SPAWN_CHILD_SIGNALED       "org.freedesktop.DBus.Error.Spawn.ChildSignaled"
254 #define DBUS_ERROR_SPAWN_FAILED               "org.freedesktop.DBus.Error.Spawn.Failed"
255 #define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN    "org.freedesktop.DBus.Error.UnixProcessIdUnknown"
256 #define DBUS_ERROR_INVALID_SIGNATURE          "org.freedesktop.DBus.Error.InvalidSignature"
257 #define DBUS_ERROR_INVALID_FILE_CONTENT       "org.freedesktop.DBus.Error.InvalidFileContent"
258 #define DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN    "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown"
259
260 #define DBUS_INTROSPECT_1_0_XML_NAMESPACE         "http://www.freedesktop.org/standards/dbus"
261 #define DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
262 #define DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"
263 #define DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "<!DOCTYPE node PUBLIC \""DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER"\"\n\""DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER"\">\n"
264
265 /** @} */
266
267 #ifdef __cplusplus
268 }
269 #endif
270
271 #endif /* DBUS_PROTOCOL_H */