1 <!doctype article PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
5 <title>D-BUS Specification</title>
6 <releaseinfo>Version 0.7</releaseinfo>
7 <date>26 March 2003</date>
10 <firstname>Havoc</firstname>
11 <surname>Pennington</surname>
14 <email>hp@pobox.com</email>
19 <firstname>Anders</firstname>
20 <surname>Carlsson</surname>
22 <orgname>CodeFactory AB</orgname>
24 <email>andersca@codefactory.se</email>
31 <sect1 id="introduction">
32 <title>Introduction</title>
34 D-BUS is a system for low-latency, low-overhead, easy to use
35 interprocess communication (IPC). In more detail:
39 D-BUS is <emphasis>low-latency</emphasis> because it is designed
40 to avoid round trips and allow asynchronous operation, much like
46 D-BUS is <emphasis>low-overhead</emphasis> because it uses a
47 binary protocol, and does not have to convert to and from a text
48 format such as XML. Because D-BUS is intended for potentially
49 high-resolution same-machine IPC, not primarily for Internet IPC,
50 this is an interesting optimization.
55 D-BUS is <emphasis>easy to use</emphasis> because it works in terms
56 of <firstterm>messages</firstterm> rather than byte streams, and
57 does not require users to understand any complex concepts such as a
58 new type system or elaborate APIs. Libraries implementing D-BUS
59 may choose to abstract messages as "method calls" (see
60 <xref linkend="message-conventions-method">).
66 The base D-BUS protocol is a peer-to-peer protocol, specified in <xref
67 linkend="message-protocol">. That is, it is a system for one application
68 to talk to a single other application. However, the primary intended
69 application of D-BUS is the D-BUS <firstterm>message bus</firstterm>,
70 specified in <xref linkend="message-bus">. The message bus is a special
71 application that accepts connections from multiple other applications, and
72 forwards messages among them.
75 Things that D-BUS can be used for is for example notification of
76 system changes (notification of when a camera is plugged in to a
77 computer, or a new version of some software has been installed),
78 or desktop interoperablity, for example a file monitoring
79 service or a configuration service.
83 <sect1 id="message-protocol">
84 <title>Message Protocol</title>
86 A <firstterm>message</firstterm> consists of a
87 <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
88 think of a message as a package, the header is the address, and the body
89 contains the package contents. The message delivery system uses the header
90 information to figure out where to send the message and how to interpret
91 it; the recipient inteprets the body of the message.
95 The body of the message is made up of zero or more
96 <firstterm>arguments</firstterm>, which are typed
97 values, such as an integer or a byte array.
100 <sect2 id="message-protocol-header-encoding">
101 <title>Header Encoding</title>
103 Following the mandatory fields, there are zero or more named fields (see
104 <xref linkend="message-protocol-header-fields">), and then nul bytes
105 padding the header such that its total length in bytes is a multiple of
109 The header MUST begin with the following mandatory fields in the following
116 <entry>Description</entry>
121 <entry>1 byte</entry>
122 <entry>Endianness flag; ASCII 'l' for little-endian
123 or ASCII 'B' for big-endian.</entry>
126 <entry>1 byte</entry>
127 <entry>Bitwise OR of flags. Unknown flags
128 MUST be ignored. Currently-defined flags are described below.
132 <entry>1 byte</entry>
133 <entry>Major protocol version of the sending application. If
134 the major protocol version of the receiving application does not
135 match, the applications will not be able to communicate and the
136 D-BUS connection MUST be disconnected. The major protocol
137 version for this version of the specification is 0.
141 <entry>1 byte</entry>
142 <entry>A nul byte, reserved for future use.
143 Any value for this byte MUST be accepted.
147 <entry>4 bytes</entry>
148 <entry>An unsigned 32-bit integer in the
149 message's byte order, indicating the total length in bytes of
150 the header including named fields and any alignment padding.
151 MUST be a multiple of 8.
155 <entry>4 bytes</entry>
156 <entry>An unsigned 32-bit integer in the
157 message's byte order, indicating the total length in bytes of
162 <entry>4 bytes</entry>
163 <entry>The message's serial number, a signed 32-bit integer in
164 the message's byte order. Applications MUST NOT reuse the same
165 serial number for different messages more often than 32-bit
166 integer wraparound. Serial numbers must be greater than
175 Flags that can appear in the second byte of the header:
180 <entry>Hex value</entry>
181 <entry>Description</entry>
187 <entry>This message is an error reply. If the first argument exists and is a string, it is an error message.</entry>
195 <sect2 id="message-protocol-header-fields">
196 <title>Header Fields</title>
198 In addition to the required header information mentioned
199 in <xref linkend="message-protocol-header-encoding">,
200 the header may contain zero or more named
201 header fields. These fields are named to allow
202 future versions of this protocol specification to
203 add new fields; implementations must ignore fields
204 they do not understand. Implementations must not
205 invent their own header fields; only changes to
206 this specification may introduce new header fields.
210 Header field names MUST consist of 4 non-nul bytes. The field name is
211 NOT nul terminated; it occupies exactly 4 bytes. Following the name,
212 the field MUST have a type code, and then a properly-aligned value
214 See <xref linkend="message-protocol-arguments"> for a description
215 of how each type is encoded. If an implementation sees a header
216 field name that it does not understand, it MUST ignore
221 Here are the currently-defined named header fields:
228 <entry>Description</entry>
234 <entry>STRING</entry>
235 <entry>The name of the message, such as org.freedesktop.Peer.Ping</entry>
240 <entry>The serial number of the message this message is a reply
241 to. (The serial number is one of the mandatory header fields,
242 see <xref linkend="message-protocol-header-encoding">.)</entry>
246 <entry>STRING</entry>
247 <entry>The name of the service this message should be routed to.
248 Only used in combination with the message bus, see
249 <xref linkend="message-bus">.</entry>
253 <entry>STRING</entry>
254 <entry>The name of the base service that sent this message.
255 The message bus fills in this field; the field is
256 only meaningful in combination with the message bus.</entry>
264 <sect2 id="message-protocol-header-padding">
265 <title>Header Alignment Padding</title>
267 To allow implementations to keep the header and the body in a single
268 buffer while keeping data types aligned, the total length of the header
269 must be a multiple of 8 bytes. To achieve this, the header MUST be padded
270 with nul bytes to align its total length on an 8-byte boundary.
271 The minimum number of padding bytes MUST be used. Because all possible
272 named fields use at least 8 bytes, implementations can distinguish
273 padding (which must be less than 8 bytes) from additional named fields
274 (which must be at least 8 bytes).
278 <sect2 id="message-protocol-arguments">
279 <title>Message Arguments</title>
281 The message body is made up of arguments. Each argument
282 is a type code, followed by the value of the argument
283 in a type-dependent format.
286 [FIXME perhaps we should add type BYTE with the primary
287 advantage being that it occupies 1 byte vs. 7 for UINT32,
288 or perhaps space savings aren't worth the complexity]
293 <entry>Type name</entry>
295 <entry>Description</entry>
300 <entry>INVALID</entry>
302 <entry>Not a valid type code (error if it appears in a message)</entry>
306 <entry>Marks an "unset" or "nonexistent" argument</entry>
310 <entry>8-bit unsigned integer.</entry>
312 <entry>BOOLEAN</entry>
314 <entry>Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.</entry>
318 <entry>32-bit signed integer</entry>
320 <entry>UINT32</entry>
322 <entry>32-bit unsigned integer</entry>
324 <entry>DOUBLE</entry>
326 <entry>IEEE 754 double</entry>
328 <entry>STRING</entry>
330 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be zero terminated. </entry>
334 <entry>A named byte array, used for custom types</entry>
342 <entry>A dictionary of key/value pairs</entry>
349 The types are encoded as follows:
354 <entry>Type name</entry>
355 <entry>Encoding</entry>
360 <entry>INVALID</entry>
361 <entry>Not applicable; cannot be encoded.</entry>
364 <entry>No data is encoded; the type code is followed immediately
365 by the type code of the next argument.</entry>
368 <entry>a byte.</entry>
370 <entry>BOOLEAN</entry>
371 <entry>a byte, with valid values 0 and 1.</entry>
374 <entry>32-bit signed integer in the message's byte order, aligned to 4-byte boundary.</entry>
376 <entry>UINT32</entry>
377 <entry>32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary.</entry>
379 <entry>DOUBLE</entry>
380 <entry>64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary.</entry>
382 <entry>STRING</entry>
383 <entry>UINT32 aligned to 4-byte boundary indicating the string's
384 length in bytes excluding its terminating nul, followed by
385 string data of the given length, followed by a terminating nul
390 <entry>A string (encoded as the STRING type above) giving the
391 name of the type followed by an UINT32 aligned to 4-byte boundary
392 indicating the data length in bytes, followed by the data.
396 <entry>a byte giving the element type of the array followed
397 by an UINT32 (aligned to 4 bytes) giving the length of the
398 array data in bytes. This is then followed by a number of
399 entires with the same type, encoded like that type normally
400 would be encoded alone.
404 <entry>UINT32 giving the length of the dictionary data in bytes.
405 This is followed by a number of keyname/value pairs, where the
406 keyname is encoded as a STRING above, and the value is encoded
407 as a byte with typecode and how that type normally would be encoded
418 <sect1 id="auth-protocol">
419 <title>Authentication Protocol</title>
421 Before the flow of messages begins, two applications must
422 authenticate. A simple plain-text protocol is used for
423 authentication; this protocol is a SASL profile, and maps fairly
424 directly from the SASL specification. The message encoding is
425 NOT used here, only plain text messages.
428 In examples, "C:" and "S:" indicate lines sent by the client and
431 <sect2 id="auth-protocol-overview">
432 <title>Protocol Overview</title>
434 The protocol is a line-based protocol, where each line ends with
435 \r\n. Each line begins with an all-caps ASCII command name containing
436 only the character range [A-Z], a space, then any arguments for the
437 command, then the \r\n ending the line. The protocol is
438 case-sensitive. All bytes must be in the ASCII character set.
440 Commands from the client to the server are as follows:
443 <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
444 <listitem><para>CANCEL</para></listitem
445 <listitem><para>BEGIN</para></listitem>
446 <listitem><para>DATA <data in base 64 encoding></para></listitem>
447 <listitem><para>ERROR [human-readable error explanation]</para></listitem>
450 From server to client are as follows:
453 <listitem><para>REJECTED <space-separated list of mechanism names></para></listitem>
454 <listitem><para>OK</para></listitem>
455 <listitem><para>DATA <data in base 64 encoding></para></listitem>
456 <listitem><para>ERROR</para></listitem>
460 <sect2 id="auth-nul-byte">
461 <title>Special credentials-passing nul byte</title>
463 Immediately after connecting to the server, the client must send a
464 single nul byte. This byte may be accompanied by credentials
465 information on some operating systems that use sendmsg() with
466 SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
467 sockets. However, the nul byte MUST be sent even on other kinds of
468 socket, and even on operating systems that do not require a byte to be
469 sent in order to transmit credentials. The text protocol described in
470 this document begins after the single nul byte. If the first byte
471 received from the client is not a nul byte, the server may disconnect
475 A nul byte in any context other than the initial byte is an error;
476 the protocol is ASCII-only.
479 The credentials sent along with the nul byte may be used with the
480 SASL mechanism EXTERNAL.
483 <sect2 id="auth-command-auth">
484 <title>AUTH command</title>
486 If an AUTH command has no arguments, it is a request to list
487 available mechanisms. The server SHOULD respond with a REJECTED
488 command listing the mechanisms it understands.
491 If an AUTH command specifies a mechanism, and the server supports
492 said mechanism, the server SHOULD begin exchanging SASL
493 challenge-response data with the client using DATA commands.
496 If the server does not support the mechanism given in the AUTH
497 command, it SHOULD send a REJECTED command listing the mechanisms
501 If the [initial-response] argument is provided, it is intended for
502 use with mechanisms that have no initial challenge (or an empty
503 initial challenge), as if it were the argument to an initial DATA
504 command. If the selected mechanism has an initial challenge, the
505 server should reject authentication by sending REJECTED.
508 If authentication succeeds after exchanging DATA commands,
509 an OK command should be sent to the client.
512 The first octet received by the client after the \r\n of the OK
513 command MUST be the first octet of the authenticated/encrypted
514 stream of D-BUS messages.
517 The first octet received by the server after the \r\n of the BEGIN
518 command from the client MUST be the first octet of the
519 authenticated/encrypted stream of D-BUS messages.
522 <sect2 id="auth-command-cancel">
523 <title>CANCEL Command</title>
525 At any time up to sending the BEGIN command, the client may send a
526 CANCEL command. On receiving the CANCEL command, the server MUST
527 send a REJECTED command and abort the current authentication
531 <sect2 id="auth-command-data">
532 <title>DATA Command</title>
534 The DATA command may come from either client or server, and simply
535 contains a base64-encoded block of data to be interpreted
536 according to the SASL mechanism in use.
539 Some SASL mechanisms support sending an "empty string";
540 FIXME we need some way to do this.
543 <sect2 id="auth-command-begin">
544 <title>BEGIN Command</title>
546 The BEGIN command acknowledges that the client has received an
547 OK command from the server, and that the stream of messages
551 The first octet received by the server after the \r\n of the BEGIN
552 command from the client MUST be the first octet of the
553 authenticated/encrypted stream of D-BUS messages.
556 <sect2 id="auth-command-rejected">
557 <title>REJECTED Command</title>
559 The REJECTED command indicates that the current authentication
560 exchange has failed, and further exchange of DATA is inappropriate.
561 The client would normally try another mechanism, or try providing
562 different responses to challenges.
564 Optionally, the REJECTED command has a space-separated list of
565 available auth mechanisms as arguments. If a server ever provides
566 a list of supported mechanisms, it MUST provide the same list
567 each time it sends a REJECTED message. Clients are free to
568 ignore all lists received after the first.
571 <sect2 id="auth-command-ok">
572 <title>OK Command</title>
574 The OK command indicates that the client has been authenticated,
575 and that further communication will be a stream of D-BUS messages
576 (optionally encrypted, as negotiated) rather than this protocol.
579 The first octet received by the client after the \r\n of the OK
580 command MUST be the first octet of the authenticated/encrypted
581 stream of D-BUS messages.
584 The client MUST respond to the OK command by sending a BEGIN
585 command, followed by its stream of messages, or by disconnecting.
586 The server MUST NOT accept additional commands using this protocol
587 after the OK command has been sent.
590 <sect2 id="auth-command-error">
591 <title>ERROR Command</title>
593 The ERROR command indicates that either server or client did not
594 know a command, does not accept the given command in the current
595 context, or did not understand the arguments to the command. This
596 allows the protocol to be extended; a client or server can send a
597 command present or permitted only in new protocol versions, and if
598 an ERROR is received instead of an appropriate response, fall back
599 to using some other technique.
601 If an ERROR is sent, the server or client MUST continue as if the
602 command causing the ERROR had never been received.
605 <sect2 id="auth-examples">
606 <title>Authentication examples</title>
610 <title>Example of successful magic cookie authentication</title>
612 (MAGIC_COOKIE is a made up mechanism)
614 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
620 <title>Example of finding out mechanisms then picking one</title>
623 S: REJECTED KERBEROS_V4 SKEY
624 C: AUTH SKEY bW9yZ2Fu
625 S: DATA OTUgUWE1ODMwOA==
626 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
632 <title>Example of client sends unknown command then falls back to regular auth</title>
636 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
642 <title>Example of server doesn't support initial auth mechanism</title>
644 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
645 S: REJECTED KERBEROS_V4 SKEY
646 C: AUTH SKEY bW9yZ2Fu
647 S: DATA OTUgUWE1ODMwOA==
648 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
654 <title>Example of wrong password or the like followed by successful retry</title>
656 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
657 S: REJECTED KERBEROS_V4 SKEY
658 C: AUTH SKEY bW9yZ2Fu
659 S: DATA OTUgUWE1ODMwOA==
660 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
662 C: AUTH SKEY bW9yZ2Fu
663 S: DATA OTUgUWE1ODMwOA==
664 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
670 <title>Example of skey cancelled and restarted</title>
672 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
673 S: REJECTED KERBEROS_V4 SKEY
674 C: AUTH SKEY bW9yZ2Fu
675 S: DATA OTUgUWE1ODMwOA==
678 C: AUTH SKEY bW9yZ2Fu
679 S: DATA OTUgUWE1ODMwOA==
680 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
687 <sect2 id="auth-mechanisms">
688 <title>Authentication mechanisms</title>
690 This section describes some new authentication mechanisms.
691 D-BUS also allows any standard SASL mechanism of course.
693 <sect3 id="auth-mechanisms-sha">
694 <title>DBUS_COOKIE_SHA1</title>
696 The DBUS_COOKIE_SHA1 mechanism is designed to establish that a client
697 has the ability to read a private file owned by the user being
698 authenticated. If the client can prove that it has access to a secret
699 cookie stored in this file, then the client is authenticated.
700 Thus the security of DBUS_COOKIE_SHA1 depends on a secure home
704 Authentication proceeds as follows:
708 The client sends the username it would like to authenticate
714 The server sends the name of its "cookie context" (see below); a
715 space character; the integer ID of the secret cookie the client
716 must demonstrate knowledge of; a space character; then a
717 hex-encoded randomly-generated challenge string.
722 The client locates the cookie, and generates its own hex-encoded
723 randomly-generated challenge string. The client then
724 concatentates the server's hex-encoded challenge, a ":"
725 character, its own hex-encoded challenge, another ":" character,
726 and the hex-encoded cookie. It computes the SHA-1 hash of this
727 composite string. It sends back to the server the client's
728 hex-encoded challenge string, a space character, and the SHA-1
734 The server generates the same concatenated string used by the
735 client and computes its SHA-1 hash. It compares the hash with
736 the hash received from the client; if the two hashes match, the
737 client is authenticated.
743 Each server has a "cookie context," which is a name that identifies a
744 set of cookies that apply to that server. A sample context might be
745 "org_freedesktop_session_bus". Context names must be valid ASCII,
746 nonzero length, and may not contain the characters slash ("/"),
747 backslash ("\"), space (" "), newline ("\n"), carriage return ("\r"),
748 tab ("\t"), or period ("."). There is a default context,
749 "org_freedesktop_global" that's used by servers that do not specify
753 Cookies are stored in a user's home directory, in the directory
754 <filename>~/.dbus-keyrings/</filename>. This directory must
755 not be readable or writable by other users. If it is,
756 clients and servers must ignore it. The directory
757 contains cookie files named after the cookie context.
760 A cookie file contains one cookie per line. Each line
761 has three space-separated fields:
765 The cookie ID number, which must be a non-negative integer and
766 may not be used twice in the same file.
771 The cookie's creation time, in UNIX seconds-since-the-epoch
777 The cookie itself, a hex-encoded random block of bytes.
783 Only server processes modify the cookie file.
784 They must do so with this procedure:
788 Create a lockfile name by appending ".lock" to the name of the
789 cookie file. The server should attempt to create this file
790 using <literal>O_CREAT | O_EXCL</literal>. If file creation
791 fails, the lock fails. Servers should retry for a reasonable
792 period of time, then they may choose to delete an existing lock
793 to keep users from having to manually delete a stale
794 lock. <footnote><para>Lockfiles are used instead of real file
795 locking <literal>fcntl()</literal> because real locking
796 implementations are still flaky on network
797 filesystems.</para></footnote>
802 Once the lockfile has been created, the server loads the cookie
803 file. It should then delete any cookies that are old (the
804 timeout can be fairly short), or more than a reasonable
805 time in the future (so that cookies never accidentally
806 become permanent, if the clock was set far into the future
807 at some point). If no recent keys remain, the
808 server may generate a new key.
813 The pruned and possibly added-to cookie file
814 must be resaved atomically (using a temporary
815 file which is rename()'d).
820 The lock must be dropped by deleting the lockfile.
826 Clients need not lock the file in order to load it,
827 because servers are required to save the file atomically.
832 <sect1 id="addresses">
833 <title>Server Addresses</title>
835 Server addresses consist of a transport name followed by a colon, and
836 then an optional, comma-separated list of keys and values in the form key=value.
837 [FIXME how do you escape colon, comma, and semicolon in the values of the key=value pairs?]
841 <programlisting>unix:path=/tmp/dbus-test</programlisting>
842 Which is the address to a unix socket with the path /tmp/dbus-test.
845 [FIXME clarify if attempting to connect to each is a requirement
846 or just a suggestion]
847 When connecting to a server, multiple server addresses can be
848 separated by a semi-colon. The library will then try to connect
849 to the first address and if that fails, it'll try to connect to
850 the next one specified, and so forth. For example
851 <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
854 [FIXME we need to specify in detail each transport and its possible arguments]
855 Currently, a transport over local UNIX sockets exists, a debug
856 transport that only works in-process and therefore can be used
857 for for unit testing also exists. It is possible that other
858 transports are added, such as a TCP/IP transport, and a
859 transport that works over X11.
863 <sect1 id="message-conventions">
864 <title>Message Conventions</title>
866 This section documents conventions that are not essential to D-BUS
867 functionality, but should generally be followed in order to simplify
870 <sect2 id="message-conventions-naming">
871 <title>Message Naming</title>
873 Messages are normally named in the form
874 "org.freedesktop.Peer.Ping", which has three
878 <term>Namespace e.g. <literal>org.freedesktop</literal></term>
881 Message names have a Java-style namespace: a reversed domain
882 name. The components of the domain are normally lowercase.
887 <term>Package or object e.g. <literal>Peer</literal></term>
890 The next part of the message name can be thought of as the name
891 of a singleton object, or as the name of a package of related
892 messages. More than one dot-separated component might be used
893 here. (Note that D-BUS does not define any idea of object
894 instances or object references.) The package or object name is
895 capitalized LikeThis.
900 <term>Method or operation e.g. <literal>Ping</literal></term>
903 The final part of the message name is the most specific, and
904 should be a verb indicating an operation to be performed on the
905 object. The method or operation name is capitalized LikeThis.
912 A reply to a message conventionally has the same name as the message
913 being replied to. When following method call conventions (see <xref
914 linkend="message-conventions-method">), this convention is mandatory,
915 because a message with multiple possible replies can't be mapped
916 to method call semantics without special-case code.
919 <sect2 id="message-conventions-method">
920 <title>Method Call Mapping</title>
922 Some implementations of D-BUS may present an API that translates object
923 method calls into D-BUS messages. This document does not specify in
924 detail how such an API should look or work. However, it does specify how
925 message-based protocols should be designed to be friendly to such an
929 Remember that D-BUS does not have object references or object instances.
930 So when one application sends the message
931 <literal>org.freedesktop.Peer.Ping</literal>, it sends it to another
932 application, not to any kind of sub-portion of that application.
933 However, a convenience API used within the recipient application may
934 route all messages that start with
935 <literal>org.freedesktop.Peer</literal> to a particular object instance,
936 and may invoke the <literal>Ping()</literal> method on said instance in
937 order to handle the message. This is a convenience API based on
941 A "method call" consists of a message and, optionally, a reply to that
942 message. The name of the "method" is the last component of the message,
943 for example, <literal>org.freedesktop.Peer.Ping</literal> would map to
944 the method <literal>Ping()</literal> on some object.
947 Arguments to a method may be considered "in" (processed by the
948 recipient of the message), or "out" (returned to the sender of the
949 message in the reply). "inout" arguments are both sent and received,
950 i.e. the caller passes in a value which is modified. An "inout" argument
951 is equivalent to an "in" argument, followed by an "out" argument.
954 Given a method with zero or one return values, followed by zero or more
955 arguments, where each argument may be "in", "out", or "inout", the
956 caller constructs a message by appending each "in" or "inout" argument,
957 in order. "out" arguments are not represented in the caller's message.
960 The recipient constructs a reply by appending first the return value
961 if any, then each "out" or "inout" argument, in order.
962 "in" arguments are not represented in the reply message.
965 The standard reply message MUST have the same name as the message being
966 replied to, and MUST set the "rply" header field to the serial
967 number of the message being replied to.
970 If an error occurs, an error reply may be sent in place of the standard
971 reply. Error replies can be identified by a special header flag, see
972 <xref linkend="message-protocol-header-encoding">. Error replies have a
973 name which reflects the type of error that occurred. Error replies would
974 generally be mapped to exceptions in a programming language. If an
975 error reply has a first argument, and that argument has type STRING,
976 then the argument must be an error message.
979 [FIXME discuss mapping of broadcast messages + matching rules
980 to signals and slots]
985 <sect1 id="standard-messages">
986 <title>Standard Peer-to-Peer Messages</title>
988 In the following message definitions, "method call notation" is presented
989 in addition to simply listing the message names and arguments. The special
990 type name ANY means any type other than NIL, and the special type name
991 ANY_OR_NIL means any valid type.
992 [FIXME the messages here are just made up to illustrate the
993 format for defining them]
995 <sect2 id="standard-messages-ping">
996 <title><literal>org.freedesktop.Peer.Ping</literal></title>
1004 On receipt of the message <literal>org.freedesktop.Peer.Ping</literal>,
1005 an application should reply with
1006 <literal>org.freedesktop.Peer.Ping</literal>. Neither the
1007 message nor its reply have any arguments.
1008 [FIXME the messages here are just made up to illustrate the
1009 format for defining them]
1012 <sect2 id="standard-messages-get-props">
1013 <title><literal>org.freedesktop.Props.Get</literal></title>
1017 ANY_OR_NIL Get (in STRING property_name)
1024 <entry>Argument</entry>
1026 <entry>Description</entry>
1032 <entry>STRING</entry>
1033 <entry>Name of the property to get</entry>
1043 <entry>Argument</entry>
1045 <entry>Description</entry>
1051 <entry>ANY_OR_NIL</entry>
1052 <entry>The value of the property. The type depends on the property.</entry>
1060 [FIXME the messages here are just made up to illustrate the
1061 format for defining them]
1066 <sect1 id="message-bus">
1067 <title>Message Bus Specification</title>
1068 <sect2 id="message-bus-overview">
1069 <title>Message Bus Overview</title>
1071 The message bus accepts connections from one or more applications.
1072 Once connected, applications can send and receive messages from
1073 the message bus, as in the peer-to-peer case.
1076 The message bus keeps track of a set of
1077 <firstterm>services</firstterm>. A service is simply a name, such
1078 as <literal>com.yoyodyne.Screensaver</literal>, which can be
1079 <firstterm>owned</firstterm> by one of the connected applications.
1080 The message bus itself always owns the special service
1081 <literal>org.freedesktop.DBus</literal>.
1084 Messages may have a <literal>srvc</literal> field (see <xref
1085 linkend="message-protocol-header-fields">). When the message bus
1086 receives a message, if the <literal>srvc</literal> field is absent, the
1087 message is taken to be a standard peer-to-peer message and interpreted
1088 by the message bus itself. For example, sending
1089 an <literal>org.freedesktop.Peer.Ping</literal> message with no
1090 <literal>srvc</literal> will cause the message bus itself to reply
1091 to the ping immediately; the message bus would never make
1092 this message visible to other applications.
1095 If the <literal>srvc</literal> field is present, then it indicates a
1096 request for the message bus to route the message. In the usual case,
1097 messages are routed to the owner of the named service.
1098 Messages may also be <firstterm>broadcast</firstterm>
1099 by sending them to the special service
1100 <literal>org.freedesktop.Broadcast</literal>. Broadcast messages are
1101 sent to all applications with <firstterm>message matching
1102 rules</firstterm> that match the message.
1105 Continuing the <literal>org.freedesktop.Peer.Ping</literal> example, if
1106 the ping message were sent with a <literal>srvc</literal> name of
1107 <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
1108 forwarded, and the Yoyodyne Corporation screensaver application would be
1109 expected to reply to the ping. If
1110 <literal>org.freedesktop.Peer.Ping</literal> were sent to
1111 <literal>org.freedesktop.Broadcast</literal>, then multiple applications
1112 might receive the ping, and all would normally reply to it.
1116 <sect2 id="message-bus-services">
1117 <title>Message Bus Services</title>
1119 A service is a name that identifies a certain application. Each
1120 application connected to the message bus has at least one service name
1121 assigned at connection time and returned in response to the
1122 <literal>org.freedesktop.DBus.Hello</literal> message.
1123 This automatically-assigned service name is called
1124 the application's <firstterm>base service</firstterm>.
1125 Base service names are unique and MUST never be reused for two different
1129 Ownership of the base service is a prerequisite for interaction with
1130 the message bus. It logically follows that the base service is always
1131 the first service that an application comes to own, and the last
1132 service that it loses ownership of.
1135 Base service names must begin with the character ':' (ASCII colon
1136 character); service names that are not base service names must not begin
1137 with this character. (The bus must reject any attempt by an application
1138 to manually create a service name beginning with ':'.) This restriction
1139 categorically prevents "spoofing"; messages sent to a base service name
1140 will always go to a single application instance and that instance only.
1143 An application can request additional service names to be associated
1145 <literal>org.freedesktop.DBus.AcquireService</literal>
1146 message. [FIXME what service names are allowed; ASCII or unicode;
1150 [FIXME this needs more detail, and should move the service-related message
1151 descriptions up into this section perhaps]
1152 Service ownership handling can be specified in the flags part
1153 of the <literal>org.freedesktop.DBus.AcquireService</literal>
1154 message. If an application specifies the
1155 DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT flag, then all applications
1156 trying to acquire the service will be put in a queue. When the
1157 primary owner disconnects from the bus or removes ownership
1158 from the service, the next application in the queue will be the
1159 primary owner. If the DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT
1160 flag is not specified, then the primary owner will lose
1161 ownership whenever another application requests ownership of the
1165 When a client disconnects from the bus, all the services that
1166 the clients own are deleted, or in the case of a service that
1167 prohibits replacement, ownership is transferred to the next
1168 client in the queue, if any.
1171 <sect2 id="message-bus-routing">
1172 <title>Message Bus Message Routing</title>
1174 When a message is received by the message bus, the message's
1175 <literal>sndr</literal> header field MUST be set to the base service of
1176 the application which sent the message. If the service already has
1177 a <literal>sndr</literal> field, the pre-existing field is replaced.
1178 This rule means that a replies are always sent to the base service name,
1179 i.e. to the same application that sent the message being replied to.
1182 [FIXME go into detail about broadcast, multicast, unicast, etc.]
1185 <sect2 id="message-bus-activation">
1186 <title>Message Bus Service Activation</title>
1188 <firstterm>Activation</firstterm> means to locate a service
1189 owner for a service that is currently unowned. For now, it
1190 means to launch an executable that will take ownership of
1191 a particular service.
1194 To find an executable corresponding to a particular service, the bus
1195 daemon looks for <firstterm>service description files</firstterm>.
1196 Service description files define a mapping from service names to
1197 executables. Different kinds of message bus will look for these files
1198 in different places, see <xref linkend="message-bus-types">.
1201 [FIXME the file format should be much better specified than
1202 "similar to .desktop entries" esp. since desktop entries are
1203 already badly-specified. ;-)] Service description files have
1204 the ".service" file extension. The message bus will only load
1205 service description files ending with .service; all other
1206 files will be ignored. The file format is similar to that of
1208 url="http://www.freedesktop.org/standards/desktop-entry-spec/desktop-entry-spec.html">desktop
1209 entries</ulink>. All service description files must be in
1210 UTF-8 encoding. To ensure that there will be no name
1211 collisions, service files must be namespaced using the same
1212 mechanism as messages and service names.
1215 <title>Example service description file</title>
1217 # Sample service description file
1219 Name=org.gnome.ConfigurationDatabase
1220 Exec=/usr/libexec/gconfd-2
1225 When an application requests a service to be activated, the
1226 bus daemon tries to find it in the list of activation
1227 entries. It then tries to spawn the executable associated with
1228 it. If this fails, it will report an error. [FIXME what
1229 happens if two .service files offer the same service; what
1230 kind of error is reported, should we have a way for the client
1234 The executable launched will have the environment variable
1235 <literal>DBUS_ACTIVATION_ADDRESS</literal> set to the address of the
1236 message bus so it can connect and register the appropriate services.
1239 The executable being launched may want to know whether the message bus
1240 activating it is one of the well-known message buses (see <xref
1241 linkend="message-bus-types">). To facilitate this, the bus MUST also set
1242 the <literal>DBUS_ACTIVATION_BUS_TYPE</literal> environment variable if it is one
1243 of the well-known buses. The currently-defined values for this variable
1244 are <literal>system</literal> for the systemwide message bus,
1245 and <literal>session</literal> for the per-login-session message
1246 bus. The activated executable must still connect to the address given
1247 in <literal>DBUS_ACTIVATION_ADDRESS</literal>, but may assume that the
1248 resulting connection is to the well-known bus.
1251 [FIXME there should be a timeout somewhere, either specified
1252 in the .service file, by the client, or just a global value
1253 and if the client being activated fails to connect within that
1254 timeout, an error should be sent back.]
1258 <sect2 id="message-bus-types">
1259 <title>Well-known Message Bus Instances</title>
1261 Two standard message bus instances are defined here, along with how
1262 to locate them and where their service files live.
1264 <sect3 id="message-bus-types-login">
1265 <title>Login session message bus</title>
1267 Each time a user logs in, a <firstterm>login session message
1268 bus</firstterm> may be started. All applications in the user's login
1269 session may interact with one another using this message bus.
1272 The address of the login session message bus is given
1273 in the <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment
1274 variable. If that variable is not set, applications may
1275 also try to read the address from the X Window System root
1276 window property <literal>_DBUS_SESSION_BUS_ADDRESS</literal>.
1277 The root window property must have type <literal>STRING</literal>.
1278 The environment variable should have precedence over the
1279 root window property.
1282 [FIXME specify location of .service files, probably using
1283 DESKTOP_DIRS etc. from basedir specification, though login session
1284 bus is not really desktop-specific]
1287 <sect3 id="message-bus-types-system">
1288 <title>System message bus</title>
1290 A computer may have a <firstterm>system message bus</firstterm>,
1291 accessible to all applications on the system. This message bus may be
1292 used to broadcast system events, such as adding new hardware devices,
1293 changes in the printer queue, and so forth.
1296 The address of the login session message bus is given
1297 in the <literal>DBUS_SYSTEM_BUS_ADDRESS</literal> environment
1298 variable. If that variable is not set, applications should try
1299 to connect to the well-known address
1300 <literal>unix:path=/var/run/dbus/system_bus_socket</literal>.
1303 The D-BUS reference implementation actually honors the
1304 <literal>$(localstatedir)</literal> configure option
1305 for this address, on both client and server side.
1310 [FIXME specify location of system bus .service files]
1315 <sect2 id="message-bus-messages">
1316 <title>Message Bus Messages</title>
1318 The special message bus service <literal>org.freedesktop.DBus</literal>
1319 responds to a number of messages, allowing applications to
1320 interact with the message bus.
1323 <sect3 id="bus-messages-hello">
1324 <title><literal>org.freedesktop.DBus.Hello</literal></title>
1335 <entry>Argument</entry>
1337 <entry>Description</entry>
1343 <entry>STRING</entry>
1344 <entry>Name of the service assigned to the application</entry>
1351 Before an application is able to send messages to other
1352 applications it must send the
1353 <literal>org.freedesktop.DBus.Hello</literal> message to the
1354 message bus service. If an application tries to send a
1355 message to another application, or a message to the message
1356 bus service that isn't the
1357 <literal>org.freedesktop.DBus.Hello</literal> message, it
1358 will be disconnected from the bus. If a client wishes to
1359 disconnect from the bus, it just has to disconnect from the
1360 transport used. No de-registration message is necessary.
1363 The reply message contains the name of the application's base service.
1366 <sect3 id="bus-messages-list-services">
1367 <title><literal>org.freedesktop.DBus.ListServices</literal></title>
1371 STRING_ARRAY ListServices ()
1378 <entry>Argument</entry>
1380 <entry>Description</entry>
1386 <entry>STRING_ARRAY</entry>
1387 <entry>Array of strings where each string is the name of a service</entry>
1394 Returns a list of all existing services registered with the message bus.
1397 <sect3 id="bus-messages-service-exists">
1398 <title><literal>org.freedesktop.DBus.ServiceExists</literal></title>
1402 UINT32 ServiceExists (in STRING service_name)
1409 <entry>Argument</entry>
1411 <entry>Description</entry>
1417 <entry>STRING</entry>
1418 <entry>Name of the service</entry>
1428 <entry>Argument</entry>
1430 <entry>Description</entry>
1436 <entry>UINT32</entry>
1437 <entry>Return value, 1 if the service exists and 0 otherwise</entry>
1444 Checks if a service with a specified name exists.
1448 <sect3 id="bus-messages-acquire-service">
1449 <title><literal>org.freedesktop.DBus.AcquireService</literal></title>
1453 UINT32 AcquireService (in STRING service_name)
1460 <entry>Argument</entry>
1462 <entry>Description</entry>
1468 <entry>STRING</entry>
1469 <entry>Name of the service</entry>
1473 <entry>UINT32</entry>
1474 <entry>Flags</entry>
1484 <entry>Argument</entry>
1486 <entry>Description</entry>
1492 <entry>UINT32</entry>
1493 <entry>Return value</entry>
1500 Tries to become owner of a specific service. The flags
1501 specified can be the following values logically ORed together:
1507 <entry>Identifier</entry>
1508 <entry>Value</entry>
1509 <entry>Description</entry>
1514 <entry>DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT</entry>
1517 If the application succeeds in being the owner of the specified service,
1518 then ownership of the service can't be transferred until the service
1519 disconnects. If this flag is not set, then any application trying to become
1520 the owner of the service will succeed and the previous owner will be
1521 sent a <literal>org.freedesktop.DBus.ServiceLost</literal> message.
1525 <entry>DBUS_SERVICE_FLAGS_REPLACE_EXISTING</entry>
1527 <entry>Only become the owner of the service if there is no current owner.</entry>
1533 [FIXME if it's one of the following values, why are the values
1534 done as flags instead of just 0, 1, 2, 3, 4]
1535 The return value can be one of the following values:
1541 <entry>Identifier</entry>
1542 <entry>Value</entry>
1543 <entry>Description</entry>
1548 <entry>DBUS_SERVICE_REPLY_PRIMARY_OWNER</entry>
1550 <entry>The application is now the primary owner of the service.</entry>
1553 <entry>DBUS_SERVICE_REPLY_IN_QUEUE</entry>
1555 <entry>The service already has an owner which do not want to give up ownership and therefore the application has been put in a queue.</entry>
1558 <entry>DBUS_SERVICE_REPLY_SERVICE_EXISTS</entry>
1560 <entry>The service does already have a primary owner, and DBUS_SERVICE_FLAG_REPLACE_EXISTING was not specified when trying to acquire the service.</entry>
1563 <entry>DBUS_SERVICE_REPLY_ALREADY_OWNER</entry>
1565 <entry>The application trying to request ownership of the service is already the owner of it.</entry>
1572 <sect3 id="bus-messages-service-acquired">
1573 <title><literal>org.freedesktop.DBus.ServiceAcquired</literal></title>
1577 ServiceAcquired (in STRING service_name)
1584 <entry>Argument</entry>
1586 <entry>Description</entry>
1592 <entry>STRING</entry>
1593 <entry>Name of the service</entry>
1597 <entry>UINT32</entry>
1598 <entry>Flags</entry>
1605 This message is sent to a specific application when it becomes the
1606 primary owner of a service.
1609 <sect3 id="bus-messages-service-lost">
1610 <title><literal>org.freedesktop.DBus.ServiceLost</literal></title>
1614 ServiceLost (in STRING service_name)
1621 <entry>Argument</entry>
1623 <entry>Description</entry>
1629 <entry>STRING</entry>
1630 <entry>Name of the service</entry>
1634 <entry>UINT32</entry>
1635 <entry>Flags</entry>
1642 This message is sent to a specific application when it loses primary
1643 ownership of a service.
1645 [FIXME instead of ServiceLost/ServiceCreated going only to
1646 a specific app, why not just OwnerChanged that covers both
1647 lost and created and changed owner and deleted]
1651 <sect3 id="bus-messages-service-created">
1652 <title><literal>org.freedesktop.DBus.ServiceCreated</literal></title>
1656 ServiceCreated (in STRING service_name)
1663 <entry>Argument</entry>
1665 <entry>Description</entry>
1671 <entry>STRING</entry>
1672 <entry>Name of the service</entry>
1676 <entry>UINT32</entry>
1677 <entry>Flags</entry>
1684 This message is broadcast to all applications when a service has been
1685 successfully registered on the message bus.
1689 <sect3 id="bus-messages-service-deleted">
1690 <title><literal>org.freedesktop.DBus.ServiceDeleted</literal></title>
1694 ServiceDeleted (in STRING service_name)
1701 <entry>Argument</entry>
1703 <entry>Description</entry>
1709 <entry>STRING</entry>
1710 <entry>Name of the service</entry>
1714 <entry>UINT32</entry>
1715 <entry>Flags</entry>
1722 This message is broadcast to all applications when a service has been
1723 deleted from the message bus.
1727 <sect3 id="bus-messages-activate-service">
1728 <title><literal>org.freedesktop.DBus.ActivateService</literal></title>
1732 UINT32 ActivateService (in STRING service_name, in UINT32 flags)
1739 <entry>Argument</entry>
1741 <entry>Description</entry>
1747 <entry>STRING</entry>
1748 <entry>Name of the service to activate</entry>
1752 <entry>UINT32</entry>
1753 <entry>Flags (currently not used)</entry>
1763 <entry>Argument</entry>
1765 <entry>Description</entry>
1771 <entry>UINT32</entry>
1772 <entry>Result code; DBUS_ACTIVATION_REPLY_ACTIVATED if
1773 the service was activated successfully or
1774 DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE if the service is
1775 already active.</entry>
1782 Tries to launch the executable associated with a service. For more information, see <xref linkend="message-bus-activation">.
1784 [FIXME need semantics in much more detail here; for example,
1785 if I activate a service then send it a message, is the message
1786 queued for the new service or is there a race]
1790 <sect3 id="bus-messages-out-of-memory">
1791 <title><literal>org.freedesktop.DBus.Error.NoMemory</literal></title>
1799 Sent by the message bus when it can't process a message due to an out of memory failure.
1803 <sect3 id="bus-messages-service-does-not-exist">
1804 <title><literal>org.freedesktop.DBus.Error.ServiceDoesNotExist</literal></title>
1808 void ServiceDoesNotExist (in STRING error)
1812 Sent by the message bus as a reply to a client that tried to send a message to a service that doesn't exist.
1819 <appendix id="implementation-notes">
1820 <title>Implementation notes</title>
1821 <sect1 id="implementation-notes-subsection">
1829 <glossary><title>Glossary</title>
1831 This glossary defines some of the terms used in this specification.
1834 <glossentry id="term-activation"><glossterm>Activation</glossterm>
1837 The process of creating an owner for a particular service,
1838 typically by launching an executable.
1843 <glossentry id="term-base-service"><glossterm>Base Service</glossterm>
1846 The special service automatically assigned to an application by the
1847 message bus. This service may never change owner, and the service
1848 name will be unique (never reused during the lifetime of the
1854 <glossentry id="term-broadcast"><glossterm>Broadcast</glossterm>
1857 A message sent to the special <literal>org.freedesktop.Broadcast</literal>
1858 service; the message bus will forward the broadcast message
1859 to all applications that have expressed interest in it.
1864 <glossentry id="term-message"><glossterm>Message</glossterm>
1867 A message is the atomic unit of communication via the D-BUS
1868 protocol. It consists of a <firstterm>header</firstterm> and a
1869 <firstterm>body</firstterm>; the body is made up of
1870 <firstterm>arguments</firstterm>.
1875 <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
1878 The message bus is a special application that forwards
1879 or broadcasts messages between a group of applications
1880 connected to the message bus. It also manages
1881 <firstterm>services</firstterm>.
1886 <glossentry id="namespace"><glossterm>Namespace</glossterm>
1889 Used to prevent collisions when defining message and service
1890 names. The convention used is the same as Java uses for
1891 defining classes: a reversed domain name.
1895 <glossentry id="peer-to-peer"><glossterm>Peer-to-peer</glossterm>
1898 An application talking directly to another application, without going through a message bus.
1902 <glossentry id="term-service"><glossterm>Service</glossterm>
1905 A service is simply a named application that other
1906 applications can refer to. For example, the
1907 hypothetical <literal>com.yoyodyne.Screensaver</literal>
1908 service might accept messages that affect
1909 a screensaver from Yoyodyne Corporation.
1910 An application is said to <firstterm>own</firstterm>
1911 a service if the message bus has associated the
1912 application with the service name.
1916 <glossentry id="term-service-name"><glossterm>Service name</glossterm>
1919 The name used when referring to a service. If the service is
1920 a base service it has a unique service name, for example
1921 ":1-20", and otherwise it should be namespaced.
1925 <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
1928 ".service files" tell the bus how to activate a particular service.
1929 See <xref linkend="term-activation">