1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
9 <title>D-BUS Specification</title>
10 <releaseinfo>Version 0.9</releaseinfo>
11 <date>17 January 2005</date>
14 <firstname>Havoc</firstname>
15 <surname>Pennington</surname>
17 <orgname>Red Hat, Inc.</orgname>
19 <email>hp@pobox.com</email>
24 <firstname>Anders</firstname>
25 <surname>Carlsson</surname>
27 <orgname>CodeFactory AB</orgname>
29 <email>andersca@codefactory.se</email>
34 <firstname>Alexander</firstname>
35 <surname>Larsson</surname>
37 <orgname>Red Hat, Inc.</orgname>
39 <email>alexl@redhat.com</email>
46 <sect1 id="introduction">
47 <title>Introduction</title>
49 D-BUS is a system for low-latency, low-overhead, easy to use
50 interprocess communication (IPC). In more detail:
54 D-BUS is <emphasis>low-latency</emphasis> because it is designed
55 to avoid round trips and allow asynchronous operation, much like
61 D-BUS is <emphasis>low-overhead</emphasis> because it uses a
62 binary protocol, and does not have to convert to and from a text
63 format such as XML. Because D-BUS is intended for potentially
64 high-resolution same-machine IPC, not primarily for Internet IPC,
65 this is an interesting optimization.
70 D-BUS is <emphasis>easy to use</emphasis> because it works in terms
71 of <firstterm>messages</firstterm> rather than byte streams, and
72 automatically handles a lot of the hard IPC issues. Also, the D-BUS
73 library is designed to be wrapped in a way that lets developers use
74 their framework's existing object/type system, rather than learning
75 a new one specifically for IPC.
82 The base D-BUS protocol is a one-to-one (peer-to-peer or client-server)
83 protocol, specified in <xref linkend="message-protocol"/>. That is, it is
84 a system for one application to talk to a single other
85 application. However, the primary intended application of D-BUS is the
86 D-BUS <firstterm>message bus</firstterm>, specified in <xref
87 linkend="message-bus"/>. The message bus is a special application that
88 accepts connections from multiple other applications, and forwards
93 Uses of D-BUS include notification of system changes (notification of when
94 a camera is plugged in to a computer, or a new version of some software
95 has been installed), or desktop interoperability, for example a file
96 monitoring service or a configuration service.
101 <sect1 id="message-protocol">
102 <title>Message Protocol</title>
105 A <firstterm>message</firstterm> consists of a
106 <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
107 think of a message as a package, the header is the address, and the body
108 contains the package contents. The message delivery system uses the header
109 information to figure out where to send the message and how to interpret
110 it; the recipient inteprets the body of the message.
114 The body of the message is made up of zero or more
115 <firstterm>arguments</firstterm>, which are typed values, such as an
116 integer or a byte array.
120 Both header and body use the same type system and format for
121 serializing data. Each type of value has a wire format.
122 Converting a value from some other representation into the wire
123 format is called <firstterm>marshaling</firstterm> and converting
124 it back from the wire format is <firstterm>unmarshaling</firstterm>.
127 <sect2 id="message-protocol-signatures">
128 <title>Type Signatures</title>
131 The D-BUS protocol does not include type tags in the marshaled data; a
132 block of marshaled values must have a known <firstterm>type
133 signature</firstterm>. The type signature is made up of <firstterm>type
134 codes</firstterm>. A type code is an ASCII character representing the
135 type of a value. Because ASCII characters are used, the type signature
136 will always form a valid ASCII string. A simple string compare
137 determines whether two type signatures are equivalent.
141 As a simple example, the type code for 32-bit integer (INT32) is
142 the ASCII character 'i'. So the signature for a block of values
143 containing a single INT32 would be:
147 A block of values containing two INT32 would have this signature:
154 All <firstterm>basic</firstterm> types work like
155 INT32 in this example. To marshal and unmarshal
156 basic types, you simply read one value from the data
157 block corresponding to each type code in the signature.
158 In addition to basic types, there are three <firstterm>container</firstterm>
159 types: STRUCT, ARRAY, and VARIANT.
163 STRUCT has a type code, ASCII character 'r', but this type
164 code does not appear in signatures. Instead, ASCII characters
165 '(' and ')' are used to mark the beginning and end of the struct.
166 So for example, a struct containing two integers would have this
171 Structs can be nested, so for example a struct containing
172 an integer and another struct:
176 The value block storing that struct would contain three integers; the
177 type signature allows you to distinguish "(i(ii))" from "((ii)i)" or
182 ARRAY has ASCII character 'a' as type code. The array type code must be
183 followed by a <firstterm>single complete type</firstterm>. The single
184 complete type following the array is the type of each array element. So
185 the simple example is:
189 which is an array of 32-bit integers. But an array can be of any type,
190 such as this array-of-struct-with-two-int32-fields:
194 Or this array of array of integer:
201 The phrase <firstterm>single complete type</firstterm> deserves some
202 definition. A single complete type is a basic type code, a variant type code,
203 an array with its element type, or a struct with its fields.
204 So the following signatures are not single complete types:
214 And the following signatures contain multiple complete types:
224 Note however that a single complete type may <emphasis>contain</emphasis>
225 multiple other single complete types.
229 VARIANT has ASCII character 'v' as its type code. A marshaled value of
230 type VARIANT will have the signature of a single complete type as part
231 of the <emphasis>value</emphasis>. This signature will be followed by a
232 marshaled value of that type.
236 The following table summarizes the D-BUS types.
241 <entry>Type name</entry>
243 <entry>Description</entry>
248 <entry>INVALID</entry>
249 <entry>0 (ASCII NUL)</entry>
250 <entry>Not a valid type code, used to terminate signatures</entry>
253 <entry>121 (ASCII 'y')</entry>
254 <entry>8-bit unsigned integer</entry>
256 <entry>BOOLEAN</entry>
257 <entry>98 (ASCII 'b')</entry>
258 <entry>Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.</entry>
261 <entry>105 (ASCII 'i')</entry>
262 <entry>32-bit signed integer</entry>
264 <entry>UINT32</entry>
265 <entry>117 (ASCII 'u')</entry>
266 <entry>32-bit unsigned integer</entry>
269 <entry>120 (ASCII 'x')</entry>
270 <entry>64-bit signed integer</entry>
272 <entry>UINT64</entry>
273 <entry>116 (ASCII 't')</entry>
274 <entry>64-bit unsigned integer</entry>
276 <entry>DOUBLE</entry>
277 <entry>100 (ASCII 'd')</entry>
278 <entry>IEEE 754 double</entry>
280 <entry>STRING</entry>
281 <entry>115 (ASCII 's')</entry>
282 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be nul terminated.</entry>
284 <entry>OBJECT_PATH</entry>
285 <entry>111 (ASCII 'o')</entry>
286 <entry>Name of an object instance</entry>
288 <entry>SIGNATURE</entry>
289 <entry>103 (ASCII 'g')</entry>
290 <entry>A type signature</entry>
293 <entry>97 (ASCII 'a')</entry>
296 <entry>STRUCT</entry>
297 <entry>114 (ASCII 'r'), 40 (ASCII '('), 41 (ASCII ')')</entry>
298 <entry>Struct</entry>
300 <entry>VARIANT</entry>
301 <entry>118 (ASCII 'v') </entry>
302 <entry>Variant type (the type of the value is part of the value itself)</entry>
311 <sect2 id="message-protocol-marshaling">
312 <title>Marshaling (Wire Format)</title>
315 Given a type signature, a block of bytes can be converted into typed
316 values. This section describes the format of the block of bytes. Byte
317 order and alignment issues are handled uniformly for all D-BUS types.
321 A block of bytes has an associated byte order. The byte order
322 has to be discovered in some way; for D-BUS messages, the
323 byte order is part of the message header as described in
324 <xref linkend="message-protocol-messages"/>. For now, assume
325 that the byte order is known to be either little endian or big
330 Each value in a block of bytes is aligned "naturally," for example
331 4-byte values are aligned to a 4-byte boundary, and 8-byte values to an
332 8-byte boundary. To properly align a value, <firstterm>alignment
333 padding</firstterm> may be necessary. The alignment padding must always
334 be the minimum required padding to properly align the following value;
335 and it must always be made up of nul bytes. The alignment padding must
336 not be left uninitialized (it can't contain garbage), and more padding
337 than required must not be used.
341 Given all this, the types are marshaled on the wire as follows:
346 <entry>Type name</entry>
347 <entry>Encoding</entry>
348 <entry>Alignment</entry>
353 <entry>INVALID</entry>
354 <entry>Not applicable; cannot be marshaled.</entry>
358 <entry>A single 8-bit byte.</entry>
361 <entry>BOOLEAN</entry>
362 <entry>As for UINT32, but only 0 and 1 are valid values.</entry>
366 <entry>32-bit signed integer in the message's byte order.</entry>
369 <entry>UINT32</entry>
370 <entry>32-bit unsigned integer in the message's byte order.</entry>
374 <entry>64-bit signed integer in the message's byte order.</entry>
377 <entry>UINT64</entry>
378 <entry>64-bit unsigned integer in the message's byte order.</entry>
381 <entry>DOUBLE</entry>
382 <entry>64-bit IEEE 754 double in the message's byte order.</entry>
385 <entry>STRING</entry>
386 <entry>A UINT32 indicating the string's
387 length in bytes excluding its terminating nul, followed by
388 string data of the given length, followed by a terminating nul
395 <entry>OBJECT_PATH</entry>
396 <entry>Exactly the same as STRING.
402 <entry>SIGNATURE</entry>
403 <entry>The same as STRING except the length is a single
404 byte (thus signatures have a maximum length of 255).
412 A UINT32 giving the length of the array data in bytes, followed by
413 alignment padding to the alignment boundary of the array element type,
414 followed by each array element. The array length is from the
415 end of the alignment padding to the end of the last element,
416 i.e. it does not include the padding after the length,
417 or any padding after the last element.
423 <entry>STRUCT</entry>
425 A struct must start on an 8-byte boundary regardless of the
426 type of the struct fields. The struct value consists of each
427 field marshaled in sequence starting from that 8-byte
434 <entry>VARIANT</entry>
436 A variant type has a marshaled SIGNATURE
437 followed by a marshaled value with the type
438 given in the signature.
439 Unlike a message signature, the variant signature
440 can contain only a single complete type.
441 So "i" is OK, "ii" is not.
444 1 (alignment of the signature)
453 <sect2 id="message-protocol-messages">
454 <title>Message Format</title>
457 A message consists of a header and a body. The header is a block of
458 values with a fixed signature and meaning. The body is a separate block
459 of values, with a signature specified in the header.
463 The length of the header must be a multiple of 8, allowing the body to
464 begin on an 8-byte boundary when storing the entire message in a single
465 buffer. If the header does not naturally end on an 8-byte boundary
466 up to 7 bytes of nul-initialized alignment padding must be added.
470 The message body need not end on an 8-byte boundary.
474 The signature of the header is:
478 Written out more readably, this is:
480 BYTE, BYTE, BYTE, BYTE, UINT32, UINT32, ARRAY of STRUCT of (BYTE,VARIANT)
485 These values have the following meanings:
491 <entry>Description</entry>
496 <entry>1st BYTE</entry>
497 <entry>Endianness flag; ASCII 'l' for little-endian
498 or ASCII 'B' for big-endian.</entry>
501 <entry>2nd BYTE</entry>
502 <entry><firstterm>Message type</firstterm>. Unknown types MUST be ignored.
503 Currently-defined types are described below.
507 <entry>3rd BYTE</entry>
508 <entry>Bitwise OR of flags. Unknown flags
509 MUST be ignored. Currently-defined flags are described below.
513 <entry>4th BYTE</entry>
514 <entry>Major protocol version of the sending application. If
515 the major protocol version of the receiving application does not
516 match, the applications will not be able to communicate and the
517 D-BUS connection MUST be disconnected. The major protocol
518 version for this version of the specification is 0.
519 FIXME this field is stupid and pointless to put in
524 <entry>1st UINT32</entry>
525 <entry>Length in bytes of the message body, starting
526 from the end of the header. The header ends after
527 its alignment padding to an 8-boundary.
531 <entry>2nd UINT32</entry>
532 <entry>The serial of this message, used as a cookie
533 by the sender to identify the reply corresponding
538 <entry>ARRAY of STRUCT of (BYTE,VARIANT)</entry>
539 <entry>An array of zero or more <firstterm>header
540 fields</firstterm> where the byte is the field code, and the
541 variant is the field value. The message type determines
542 which fields are required.
550 <firstterm>Message types</firstterm> that can appear in the second byte
556 <entry>Conventional name</entry>
557 <entry>Decimal value</entry>
558 <entry>Description</entry>
563 <entry>INVALID</entry>
565 <entry>This is an invalid type, if seen in a message
566 the connection should be dropped immediately.</entry>
569 <entry>METHOD_CALL</entry>
571 <entry>Method call.</entry>
574 <entry>METHOD_RETURN</entry>
576 <entry>Method reply with returned data.</entry>
581 <entry>Error reply. If the first argument exists and is a
582 string, it is an error message.</entry>
585 <entry>SIGNAL</entry>
587 <entry>Signal emission.</entry>
594 Flags that can appear in the third byte of the header:
599 <entry>Conventional name</entry>
600 <entry>Hex value</entry>
601 <entry>Description</entry>
606 <entry>NO_REPLY_EXPECTED</entry>
608 <entry>This message does not expect method return replies or
609 error replies; the reply can be omitted as an
610 optimization. However, it is compliant with this specification
611 to return the reply despite this flag.</entry>
614 <entry>AUTO_ACTIVATION</entry>
616 <entry>This message automatically activates the
617 addressed service before the message is delivered.</entry>
624 <sect3 id="message-protocol-header-fields">
625 <title>Header Fields</title>
628 A header must contain the required named header fields for the given
629 message type, and zero or more of any optional named header
630 fields. Future versions of this protocol specification may add new
631 fields. Implementations must ignore fields they do not
632 understand. Implementations must not invent their own header fields;
633 only changes to this specification may introduce new header fields.
637 Again, if an implementation sees a header field name that it does not
638 understand, it MUST ignore that field, as it will be part of a new
639 (but compatible) version of this specification.
643 Here are the currently-defined named header fields:
648 <entry>Conventional Name</entry>
649 <entry>Decimal Value</entry>
651 <entry>Required In</entry>
652 <entry>Description</entry>
657 <entry>INVALID</entry>
659 <entry>INVALID</entry>
660 <entry>not allowed</entry>
661 <entry>Not a valid field name (error if it appears in a message)</entry>
666 <entry>OBJECT_PATH</entry>
667 <entry>METHOD_CALL, SIGNAL</entry>
668 <entry>The object to send a call to,
669 or the object a signal is emitted from.
673 <entry>INTERFACE</entry>
675 <entry>STRING</entry>
676 <entry>SIGNAL</entry>
678 The interface to invoke a method call on, or
679 that a signal is emitted from. Optional for
680 method calls, required for signals.
684 <entry>MEMBER</entry>
686 <entry>STRING</entry>
687 <entry>METHOD_CALL, SIGNAL</entry>
688 <entry>The member, either the method name or signal name.</entry>
691 <entry>ERROR_NAME</entry>
693 <entry>STRING</entry>
695 <entry>The name of the error that occurred, for errors</entry>
698 <entry>REPLY_SERIAL</entry>
700 <entry>UINT32</entry>
701 <entry>ERROR, METHOD_RETURN</entry>
702 <entry>The serial number of the message this message is a reply
703 to. (The serial number is the second UINT32 in the header.)</entry>
706 <entry>DESTINATION</entry>
708 <entry>STRING</entry>
709 <entry>optional</entry>
710 <entry>The name of the service this message should be routed to.
711 Only used in combination with the message bus, see
712 <xref linkend="message-bus"/>.</entry>
715 <entry>SENDER</entry>
717 <entry>STRING</entry>
718 <entry>optional</entry>
719 <entry>Sender service. The name of the base service that sent
720 this message. The message bus fills in this field; the field is
721 only meaningful in combination with the message bus.</entry>
724 <entry>SIGNATURE</entry>
726 <entry>SIGNATURE</entry>
727 <entry>optional</entry>
728 <entry>The signature of the message body.
729 If omitted, it is assumed to be the
730 empty signature "" (i.e. the body is 0-length).</entry>
739 <sect2 id="message-protocol-arguments">
740 <title>Message Arguments</title>
742 The message body is made up of arguments. Each argument is a type code,
743 represented by a single unsigned byte, followed by the aligned value of
744 the argument in a type-dependent format. Alignment padding between the
745 typecode and the value is initialized to zero.
752 <entry>Type name</entry>
754 <entry>Description</entry>
759 <entry>INVALID</entry>
760 <entry>0 (ASCII NUL)</entry>
761 <entry>Not a valid type code (error if it appears in a message)</entry>
764 <entry>118 (ASCII 'v') </entry>
765 <entry>Marks a "void"/"unset"/"nonexistent"/"null" argument</entry>
768 <entry>121 (ASCII 'y')</entry>
769 <entry>8-bit unsigned integer</entry>
771 <entry>BOOLEAN</entry>
772 <entry>98 (ASCII 'b')</entry>
773 <entry>Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.</entry>
776 <entry>105 (ASCII 'i')</entry>
777 <entry>32-bit signed integer</entry>
779 <entry>UINT32</entry>
780 <entry>117 (ASCII 'u')</entry>
781 <entry>32-bit unsigned integer</entry>
784 <entry>120 (ASCII 'x')</entry>
785 <entry>64-bit signed integer</entry>
787 <entry>UINT64</entry>
788 <entry>116 (ASCII 't')</entry>
789 <entry>64-bit unsigned integer</entry>
791 <entry>DOUBLE</entry>
792 <entry>100 (ASCII 'd')</entry>
793 <entry>IEEE 754 double</entry>
795 <entry>STRING</entry>
796 <entry>115 (ASCII 's')</entry>
797 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be zero terminated. </entry>
799 <entry>CUSTOM</entry>
800 <entry>99 (ASCII 'c')</entry>
801 <entry>A named byte array, used for custom types</entry>
804 <entry>97 (ASCII 'a')</entry>
808 <entry>109 (ASCII 'm')</entry>
809 <entry>A dictionary of key/value pairs</entry>
811 <entry>OBJECT_PATH</entry>
812 <entry>111 (ASCII 'o')</entry>
813 <entry>Name of an object</entry>
820 The types are encoded as follows:
825 <entry>Type name</entry>
826 <entry>Encoding</entry>
831 <entry>INVALID</entry>
832 <entry>Not applicable; cannot be encoded.</entry>
835 <entry>No data is encoded; the type code is followed immediately
836 by the type code of the next argument.</entry>
839 <entry>A byte.</entry>
841 <entry>BOOLEAN</entry>
842 <entry>A byte, with valid values 0 and 1.</entry>
845 <entry>32-bit signed integer in the message's byte order, aligned to 4-byte boundary.</entry>
847 <entry>UINT32</entry>
848 <entry>32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary.</entry>
851 <entry>64-bit signed integer in the message's byte order, aligned to 8-byte boundary.</entry>
853 <entry>UINT64</entry>
854 <entry>64-bit unsigned integer in the message's byte order, aligned to 8-byte boundary.</entry>
856 <entry>DOUBLE</entry>
857 <entry>64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary.</entry>
859 <entry>STRING</entry>
860 <entry>UINT32 aligned to 4-byte boundary indicating the string's
861 length in bytes excluding its terminating nul, followed by
862 string data of the given length, followed by a terminating nul
866 <entry>CUSTOM</entry>
867 <entry>A string (encoded as the STRING type above) giving the
868 name of the type followed by an UINT32 aligned to 4-byte boundary
869 indicating the data length in bytes, followed by the data.
870 The string has some restrictions on its content, see
871 <xref linkend="message-protocol-names"/>.
875 <entry>A sequence of bytes giving the element type of the array, terminated
876 by a type different from ARRAY (just one byte for one-dimensional arrays, but
877 larger for multi-dimensional arrays), followed by an UINT32 (aligned to 4 bytes)
878 giving the length of the array data in bytes. This is followed by each array entry
879 encoded the way it would normally be encoded, except arrays, which are encoded
880 without the type information, since that is already declared above. Arrays containing
885 <entry>UINT32 giving the length of the dictionary data in bytes.
886 This is followed by a number of keyname/value pairs, where the
887 keyname is encoded as a STRING above, and the value is encoded
888 as a byte with typecode and how that type normally would be encoded
892 <entry>OBJECT_PATH</entry>
893 <entry>Encoded as if it were a STRING.
902 <sect2 id="message-protocol-names">
903 <title>Valid names</title>
905 The various names in D-BUS messages have some restrictions.
907 <sect3 id="message-protocol-names-interface">
908 <title>Interface names</title>
910 Interfaces have names with type STRING, meaning that
911 they must be valid UTF-8. However, there are also some
912 additional restrictions that apply to interface names
915 <listitem><para>They are composed of 1 or more elements separated by
916 a period ('.') character. All elements must contain at least
920 <listitem><para>Each element must only contain the ASCII characters
921 "[A-Z][a-z][0-9]_" and must not begin with a digit.
925 <listitem><para>They must contain at least one '.' (period)
926 character (and thus at least two elements).
929 <listitem><para>They must not begin with a '.' (period) character.</para></listitem>
930 <listitem><para>They must not exceed 256 bytes in length.</para></listitem>
931 <listitem><para>They must be at least 1 byte in length.</para></listitem>
935 <sect3 id="message-protocol-names-service">
936 <title>Service names</title>
938 Service names have the same restrictions as interface names, with a
939 special exception for base services. A base service name's first
940 element must start with a colon (':') character. After the colon, any
941 characters in the range "[A-Z][a-z][0-9]_" may appear. Elements after
942 the first must follow the usual rules, except that they may start with
943 a digit. Service names not starting with a colon have none of these
944 exceptions and follow the same rules as interface names.
947 <sect3 id="message-protocol-names-method">
948 <title>Method names</title>
952 <listitem><para>Must only contain the ASCII characters
953 "[A-Z][a-z][0-9]_" and may not begin with a
954 digit.</para></listitem>
955 <listitem><para>Must not contain the '.' (period) character</para></listitem>
956 <listitem><para>Must not exceed 256 bytes in length</para></listitem>
957 <listitem><para>Must be at least 1 byte in length</para></listitem>
961 <sect3 id="message-protocol-names-path">
962 <title>Path names</title>
964 A path (type OBJECT_PATH) must begin with an ASCII '/' (slash)
965 character. Paths may not end with a slash character unless the path is
966 the one-byte string "/". Two slash characters may not appear adjacent
967 to one another (the empty string is not a valid "subdirectory"). Paths
968 may not exceed 256 bytes in length.
971 <sect3 id="message-protocol-names-error">
972 <title>Error names</title>
974 Error names have the same restrictions as interface names.
977 <sect3 id="message-protocol-names-custom">
978 <title>Custom types</title>
980 Custom type names for values of type CUSTOM follow the same
981 restrictions as interface names.
986 <sect2 id="message-protocol-types">
987 <title>Message types</title>
989 Each of the message types (METHOD_CALL, METHOD_RETURN, ERROR, and
990 SIGNAL) has its own expected usage conventions and header fields.
992 <sect3 id="message-protocol-types-method">
993 <title>Method Calls, Returns, and Errors</title>
995 Some messages invoke an operation on a remote object. These are
996 called method call messages and have the type tag METHOD_CALL. Such
997 messages map naturally to methods on objects in a typical program.
1000 A method call message is expected to have a MEMBER header field
1001 indicating the name of the method. Optionally, the message has an
1002 INTERFACE field giving the interface the method is a part of. In the
1003 absence of an INTERFACE field, if two interfaces on the same object have
1004 a method with the same name, it is undefined which of the two methods
1005 will be invoked. Implementations may also choose to return an error in
1006 this ambiguous case. However, if a method name is unique
1007 implementations should not require an interface field.
1010 Method call messages also include a PATH field indicating the
1011 object to invoke the method on. If the call is passing through
1012 a message bus, the message will also have a SERVICE field giving
1013 the service to receive the message.
1016 When an application handles a method call message, it is expected to
1017 return a reply. The reply is identified by a REPLY_SERIAL header field
1018 indicating the serial number of the METHOD_CALL being replied to. The
1019 reply can have one of two types; either METHOD_RETURN or ERROR.
1022 If the reply has type METHOD_RETURN, the arguments to the reply message
1023 are the return value(s) or "out parameters" of the method call.
1024 If the reply has type ERROR, then an "exception" has been thrown,
1025 and the call fails; no return value will be provided. It makes
1026 no sense to send multiple replies to the same method call.
1029 Even if a method call has no return values, a METHOD_RETURN
1030 reply is expected, so the caller will know the method
1031 was successfully processed.
1034 The METHOD_RETURN or ERROR reply message MUST have the REPLY_SERIAL
1035 header field. If this field is missing, it should be treated as
1039 If a METHOD_CALL message has the flag NO_REPLY_EXPECTED,
1040 then as an optimization the application receiving the method
1041 call may choose to omit the reply message (regardless of
1042 whether the reply would have been METHOD_RETURN or ERROR).
1043 However, it is also acceptable to ignore the NO_REPLY_EXPECTED
1044 flag and reply anyway.
1047 If a message has the flag AUTO_ACTIVATION, then the addressed
1048 service will be activated before the message is delivered, if
1049 not already active. The message will be held until the service
1050 is successfully activated or has failed to activate; in case
1051 of failure, an activation error will be returned.
1053 <sect4 id="message-protocol-types-method-apis">
1054 <title>Mapping method calls to native APIs</title>
1056 APIs for D-BUS may map method calls to a method call in a specific
1057 programming language, such as C++, or may map a method call written
1058 in an IDL to a D-BUS message.
1061 In APIs of this nature, arguments to a method are often termed "in"
1062 (which implies sent in the METHOD_CALL), or "out" (which implies
1063 returned in the METHOD_RETURN). Some APIs such as CORBA also have
1064 "inout" arguments, which are both sent and received, i.e. the caller
1065 passes in a value which is modified. Mapped to D-BUS, an "inout"
1066 argument is equivalent to an "in" argument, followed by an "out"
1067 argument. You can't pass things "by reference" over the wire, so
1068 "inout" is purely an illusion of the in-process API.
1071 Given a method with zero or one return values, followed by zero or more
1072 arguments, where each argument may be "in", "out", or "inout", the
1073 caller constructs a message by appending each "in" or "inout" argument,
1074 in order. "out" arguments are not represented in the caller's message.
1077 The recipient constructs a reply by appending first the return value
1078 if any, then each "out" or "inout" argument, in order.
1079 "in" arguments are not represented in the reply message.
1085 <sect3 id="message-protocol-types-signal">
1086 <title>Signal Emission</title>
1088 Unlike method calls, signal emissions have no replies.
1089 A signal emission is simply a single message of type SIGNAL.
1090 It must have three header fields: PATH giving the object
1091 the signal was emitted from, plus INTERFACE and MEMBER giving
1092 the fully-qualified name of the signal.
1096 <sect3 id="message-protocol-types-notation">
1097 <title>Notation in this document</title>
1099 This document uses a simple pseudo-IDL to describe particular method
1100 calls and signals. Here is an example of a method call:
1102 org.freedesktop.DBus.ActivateService (in STRING service_name, in UINT32 flags,
1103 out UINT32 resultcode)
1105 This means INTERFACE = org.freedesktop.DBus, MEMBER = ActivateService,
1106 METHOD_CALL arguments are STRING and UINT32, METHOD_RETURN argument
1107 is UINT32. Remember that the MEMBER field can't contain any '.' (period)
1108 characters so it's known that the last part of the name in
1109 the "IDL" is the member name.
1112 In C++ that might end up looking like this:
1114 unsigned int org::freedesktop::DBus::ActivateService (const char *service_name,
1115 unsigned int flags);
1117 or equally valid, the return value could be done as an argument:
1119 void org::freedesktop::DBus::ActivateService (const char *service_name,
1121 unsigned int *resultcode);
1123 It's really up to the API designer how they want to make
1124 this look. You could design an API where the namespace wasn't used
1125 in C++, using STL or Qt, using varargs, or whatever you wanted.
1128 Signals are written as follows:
1130 org.freedesktop.DBus.ServiceLost (STRING service_name)
1132 Signals don't specify "in" vs. "out" because only
1133 a single direction is possible.
1136 In this ad hoc notation, the special type name ANY means any type
1137 other than NIL, and the special type name ANY_OR_NIL means any valid
1141 It isn't especially encouraged to use this lame pseudo-IDL in actual
1142 API implementations; you might use the native notation for the
1143 language you're using, or you might use COM or CORBA IDL, for example.
1150 <sect1 id="auth-protocol">
1151 <title>Authentication Protocol</title>
1153 Before the flow of messages begins, two applications must
1154 authenticate. A simple plain-text protocol is used for
1155 authentication; this protocol is a SASL profile, and maps fairly
1156 directly from the SASL specification. The message encoding is
1157 NOT used here, only plain text messages.
1160 In examples, "C:" and "S:" indicate lines sent by the client and
1161 server respectively.
1163 <sect2 id="auth-protocol-overview">
1164 <title>Protocol Overview</title>
1166 The protocol is a line-based protocol, where each line ends with
1167 \r\n. Each line begins with an all-caps ASCII command name containing
1168 only the character range [A-Z], a space, then any arguments for the
1169 command, then the \r\n ending the line. The protocol is
1170 case-sensitive. All bytes must be in the ASCII character set.
1172 Commands from the client to the server are as follows:
1175 <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
1176 <listitem><para>CANCEL</para></listitem>
1177 <listitem><para>BEGIN</para></listitem>
1178 <listitem><para>DATA <data in hex encoding></para></listitem>
1179 <listitem><para>ERROR [human-readable error explanation]</para></listitem>
1182 From server to client are as follows:
1185 <listitem><para>REJECTED <space-separated list of mechanism names></para></listitem>
1186 <listitem><para>OK</para></listitem>
1187 <listitem><para>DATA <data in hex encoding></para></listitem>
1188 <listitem><para>ERROR</para></listitem>
1192 <sect2 id="auth-nul-byte">
1193 <title>Special credentials-passing nul byte</title>
1195 Immediately after connecting to the server, the client must send a
1196 single nul byte. This byte may be accompanied by credentials
1197 information on some operating systems that use sendmsg() with
1198 SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
1199 sockets. However, the nul byte MUST be sent even on other kinds of
1200 socket, and even on operating systems that do not require a byte to be
1201 sent in order to transmit credentials. The text protocol described in
1202 this document begins after the single nul byte. If the first byte
1203 received from the client is not a nul byte, the server may disconnect
1207 A nul byte in any context other than the initial byte is an error;
1208 the protocol is ASCII-only.
1211 The credentials sent along with the nul byte may be used with the
1212 SASL mechanism EXTERNAL.
1215 <sect2 id="auth-command-auth">
1216 <title>AUTH command</title>
1218 If an AUTH command has no arguments, it is a request to list
1219 available mechanisms. The server SHOULD respond with a REJECTED
1220 command listing the mechanisms it understands.
1223 If an AUTH command specifies a mechanism, and the server supports
1224 said mechanism, the server SHOULD begin exchanging SASL
1225 challenge-response data with the client using DATA commands.
1228 If the server does not support the mechanism given in the AUTH
1229 command, it SHOULD send a REJECTED command listing the mechanisms
1233 If the [initial-response] argument is provided, it is intended for
1234 use with mechanisms that have no initial challenge (or an empty
1235 initial challenge), as if it were the argument to an initial DATA
1236 command. If the selected mechanism has an initial challenge, the
1237 server should reject authentication by sending REJECTED.
1240 If authentication succeeds after exchanging DATA commands,
1241 an OK command should be sent to the client.
1244 The first octet received by the client after the \r\n of the OK
1245 command MUST be the first octet of the authenticated/encrypted
1246 stream of D-BUS messages.
1249 The first octet received by the server after the \r\n of the BEGIN
1250 command from the client MUST be the first octet of the
1251 authenticated/encrypted stream of D-BUS messages.
1254 <sect2 id="auth-command-cancel">
1255 <title>CANCEL Command</title>
1257 At any time up to sending the BEGIN command, the client may send a
1258 CANCEL command. On receiving the CANCEL command, the server MUST
1259 send a REJECTED command and abort the current authentication
1263 <sect2 id="auth-command-data">
1264 <title>DATA Command</title>
1266 The DATA command may come from either client or server, and simply
1267 contains a hex-encoded block of data to be interpreted
1268 according to the SASL mechanism in use.
1271 Some SASL mechanisms support sending an "empty string";
1272 FIXME we need some way to do this.
1275 <sect2 id="auth-command-begin">
1276 <title>BEGIN Command</title>
1278 The BEGIN command acknowledges that the client has received an
1279 OK command from the server, and that the stream of messages
1283 The first octet received by the server after the \r\n of the BEGIN
1284 command from the client MUST be the first octet of the
1285 authenticated/encrypted stream of D-BUS messages.
1288 <sect2 id="auth-command-rejected">
1289 <title>REJECTED Command</title>
1291 The REJECTED command indicates that the current authentication
1292 exchange has failed, and further exchange of DATA is inappropriate.
1293 The client would normally try another mechanism, or try providing
1294 different responses to challenges.
1296 Optionally, the REJECTED command has a space-separated list of
1297 available auth mechanisms as arguments. If a server ever provides
1298 a list of supported mechanisms, it MUST provide the same list
1299 each time it sends a REJECTED message. Clients are free to
1300 ignore all lists received after the first.
1303 <sect2 id="auth-command-ok">
1304 <title>OK Command</title>
1306 The OK command indicates that the client has been authenticated,
1307 and that further communication will be a stream of D-BUS messages
1308 (optionally encrypted, as negotiated) rather than this protocol.
1311 The first octet received by the client after the \r\n of the OK
1312 command MUST be the first octet of the authenticated/encrypted
1313 stream of D-BUS messages.
1316 The client MUST respond to the OK command by sending a BEGIN
1317 command, followed by its stream of messages, or by disconnecting.
1318 The server MUST NOT accept additional commands using this protocol
1319 after the OK command has been sent.
1322 <sect2 id="auth-command-error">
1323 <title>ERROR Command</title>
1325 The ERROR command indicates that either server or client did not
1326 know a command, does not accept the given command in the current
1327 context, or did not understand the arguments to the command. This
1328 allows the protocol to be extended; a client or server can send a
1329 command present or permitted only in new protocol versions, and if
1330 an ERROR is received instead of an appropriate response, fall back
1331 to using some other technique.
1334 If an ERROR is sent, the server or client that sent the
1335 error MUST continue as if the command causing the ERROR had never been
1336 received. However, the the server or client receiving the error
1337 should try something other than whatever caused the error;
1338 if only canceling/rejecting the authentication.
1341 <sect2 id="auth-examples">
1342 <title>Authentication examples</title>
1346 <title>Example of successful magic cookie authentication</title>
1348 (MAGIC_COOKIE is a made up mechanism)
1350 C: AUTH MAGIC_COOKIE 3138363935333137393635383634
1356 <title>Example of finding out mechanisms then picking one</title>
1359 S: REJECTED KERBEROS_V4 SKEY
1360 C: AUTH SKEY 7ab83f32ee
1361 S: DATA 8799cabb2ea93e
1362 C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1368 <title>Example of client sends unknown command then falls back to regular auth</title>
1372 C: AUTH MAGIC_COOKIE 3736343435313230333039
1378 <title>Example of server doesn't support initial auth mechanism</title>
1380 C: AUTH MAGIC_COOKIE 3736343435313230333039
1381 S: REJECTED KERBEROS_V4 SKEY
1382 C: AUTH SKEY 7ab83f32ee
1383 S: DATA 8799cabb2ea93e
1384 C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1390 <title>Example of wrong password or the like followed by successful retry</title>
1392 C: AUTH MAGIC_COOKIE 3736343435313230333039
1393 S: REJECTED KERBEROS_V4 SKEY
1394 C: AUTH SKEY 7ab83f32ee
1395 S: DATA 8799cabb2ea93e
1396 C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1398 C: AUTH SKEY 7ab83f32ee
1399 S: DATA 8799cabb2ea93e
1400 C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1406 <title>Example of skey cancelled and restarted</title>
1408 C: AUTH MAGIC_COOKIE 3736343435313230333039
1409 S: REJECTED KERBEROS_V4 SKEY
1410 C: AUTH SKEY 7ab83f32ee
1411 S: DATA 8799cabb2ea93e
1414 C: AUTH SKEY 7ab83f32ee
1415 S: DATA 8799cabb2ea93e
1416 C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1423 <sect2 id="auth-states">
1424 <title>Authentication state diagrams</title>
1427 This section documents the auth protocol in terms of
1428 a state machine for the client and the server. This is
1429 probably the most robust way to implement the protocol.
1432 <sect3 id="auth-states-client">
1433 <title>Client states</title>
1436 To more precisely describe the interaction between the
1437 protocol state machine and the authentication mechanisms the
1438 following notation is used: MECH(CHALL) means that the
1439 server challenge CHALL was fed to the mechanism MECH, which
1445 CONTINUE(RESP) means continue the auth conversation
1446 and send RESP as the response to the server;
1452 OK(RESP) means that after sending RESP to the server
1453 the client side of the auth conversation is finished
1454 and the server should return "OK";
1460 ERROR means that CHALL was invalid and could not be
1466 Both RESP and CHALL may be empty.
1470 The Client starts by getting an initial response from the
1471 default mechanism and sends AUTH MECH RESP, or AUTH MECH if
1472 the mechanism did not provide an initial response. If the
1473 mechanism returns CONTINUE, the client starts in state
1474 <emphasis>WaitingForData</emphasis>, if the mechanism
1475 returns OK the client starts in state
1476 <emphasis>WaitingForOK</emphasis>.
1480 The client should keep track of available mechanisms and
1481 which it mechanisms it has already attempted. This list is
1482 used to decide which AUTH command to send. When the list is
1483 exhausted, the client should give up and close the
1488 <title><emphasis>WaitingForData</emphasis></title>
1496 MECH(CHALL) returns CONTINUE(RESP) → send
1498 <emphasis>WaitingForData</emphasis>
1502 MECH(CHALL) returns OK(RESP) → send DATA
1503 RESP, goto <emphasis>WaitingForOK</emphasis>
1507 MECH(CHALL) returns ERROR → send ERROR
1508 [msg], goto <emphasis>WaitingForData</emphasis>
1516 Receive REJECTED [mechs] →
1517 send AUTH [next mech], goto
1518 WaitingForData or <emphasis>WaitingForOK</emphasis>
1523 Receive ERROR → send
1525 <emphasis>WaitingForReject</emphasis>
1530 Receive OK → send
1531 BEGIN, terminate auth
1532 conversation, authenticated
1537 Receive anything else → send
1539 <emphasis>WaitingForData</emphasis>
1547 <title><emphasis>WaitingForOK</emphasis></title>
1552 Receive OK → send BEGIN, terminate auth
1553 conversation, <emphasis>authenticated</emphasis>
1558 Receive REJECT [mechs] → send AUTH [next mech],
1559 goto <emphasis>WaitingForData</emphasis> or
1560 <emphasis>WaitingForOK</emphasis>
1566 Receive DATA → send CANCEL, goto
1567 <emphasis>WaitingForReject</emphasis>
1573 Receive ERROR → send CANCEL, goto
1574 <emphasis>WaitingForReject</emphasis>
1580 Receive anything else → send ERROR, goto
1581 <emphasis>WaitingForOK</emphasis>
1589 <title><emphasis>WaitingForReject</emphasis></title>
1594 Receive REJECT [mechs] → send AUTH [next mech],
1595 goto <emphasis>WaitingForData</emphasis> or
1596 <emphasis>WaitingForOK</emphasis>
1602 Receive anything else → terminate auth
1603 conversation, disconnect
1612 <sect3 id="auth-states-server">
1613 <title>Server states</title>
1616 For the server MECH(RESP) means that the client response
1617 RESP was fed to the the mechanism MECH, which returns one of
1622 CONTINUE(CHALL) means continue the auth conversation and
1623 send CHALL as the challenge to the client;
1629 OK means that the client has been successfully
1636 REJECT means that the client failed to authenticate or
1637 there was an error in RESP.
1642 The server starts out in state
1643 <emphasis>WaitingForAuth</emphasis>. If the client is
1644 rejected too many times the server must disconnect the
1649 <title><emphasis>WaitingForAuth</emphasis></title>
1655 Receive AUTH → send REJECTED [mechs], goto
1656 <emphasis>WaitingForAuth</emphasis>
1662 Receive AUTH MECH RESP
1666 MECH not valid mechanism → send REJECTED
1668 <emphasis>WaitingForAuth</emphasis>
1672 MECH(RESP) returns CONTINUE(CHALL) → send
1674 <emphasis>WaitingForData</emphasis>
1678 MECH(RESP) returns OK → send OK, goto
1679 <emphasis>WaitingForBegin</emphasis>
1683 MECH(RESP) returns REJECT → send REJECTED
1685 <emphasis>WaitingForAuth</emphasis>
1693 Receive BEGIN → terminate
1694 auth conversation, disconnect
1700 Receive ERROR → send REJECTED [mechs], goto
1701 <emphasis>WaitingForAuth</emphasis>
1707 Receive anything else → send
1709 <emphasis>WaitingForAuth</emphasis>
1718 <title><emphasis>WaitingForData</emphasis></title>
1726 MECH(RESP) returns CONTINUE(CHALL) → send
1728 <emphasis>WaitingForData</emphasis>
1732 MECH(RESP) returns OK → send OK, goto
1733 <emphasis>WaitingForBegin</emphasis>
1737 MECH(RESP) returns REJECT → send REJECTED
1739 <emphasis>WaitingForAuth</emphasis>
1747 Receive BEGIN → terminate auth conversation,
1754 Receive CANCEL → send REJECTED [mechs], goto
1755 <emphasis>WaitingForAuth</emphasis>
1761 Receive ERROR → send REJECTED [mechs], goto
1762 <emphasis>WaitingForAuth</emphasis>
1768 Receive anything else → send ERROR, goto
1769 <emphasis>WaitingForData</emphasis>
1777 <title><emphasis>WaitingForBegin</emphasis></title>
1782 Receive BEGIN → terminate auth conversation,
1783 client authenticated
1789 Receive CANCEL → send REJECTED [mechs], goto
1790 <emphasis>WaitingForAuth</emphasis>
1796 Receive ERROR → send REJECTED [mechs], goto
1797 <emphasis>WaitingForAuth</emphasis>
1803 Receive anything else → send ERROR, goto
1804 <emphasis>WaitingForBegin</emphasis>
1814 <sect2 id="auth-mechanisms">
1815 <title>Authentication mechanisms</title>
1817 This section describes some new authentication mechanisms.
1818 D-BUS also allows any standard SASL mechanism of course.
1820 <sect3 id="auth-mechanisms-sha">
1821 <title>DBUS_COOKIE_SHA1</title>
1823 The DBUS_COOKIE_SHA1 mechanism is designed to establish that a client
1824 has the ability to read a private file owned by the user being
1825 authenticated. If the client can prove that it has access to a secret
1826 cookie stored in this file, then the client is authenticated.
1827 Thus the security of DBUS_COOKIE_SHA1 depends on a secure home
1831 Authentication proceeds as follows:
1835 The client sends the username it would like to authenticate
1841 The server sends the name of its "cookie context" (see below); a
1842 space character; the integer ID of the secret cookie the client
1843 must demonstrate knowledge of; a space character; then a
1844 hex-encoded randomly-generated challenge string.
1849 The client locates the cookie, and generates its own hex-encoded
1850 randomly-generated challenge string. The client then
1851 concatentates the server's hex-encoded challenge, a ":"
1852 character, its own hex-encoded challenge, another ":" character,
1853 and the hex-encoded cookie. It computes the SHA-1 hash of this
1854 composite string. It sends back to the server the client's
1855 hex-encoded challenge string, a space character, and the SHA-1
1861 The server generates the same concatenated string used by the
1862 client and computes its SHA-1 hash. It compares the hash with
1863 the hash received from the client; if the two hashes match, the
1864 client is authenticated.
1870 Each server has a "cookie context," which is a name that identifies a
1871 set of cookies that apply to that server. A sample context might be
1872 "org_freedesktop_session_bus". Context names must be valid ASCII,
1873 nonzero length, and may not contain the characters slash ("/"),
1874 backslash ("\"), space (" "), newline ("\n"), carriage return ("\r"),
1875 tab ("\t"), or period ("."). There is a default context,
1876 "org_freedesktop_global" that's used by servers that do not specify
1880 Cookies are stored in a user's home directory, in the directory
1881 <filename>~/.dbus-keyrings/</filename>. This directory must
1882 not be readable or writable by other users. If it is,
1883 clients and servers must ignore it. The directory
1884 contains cookie files named after the cookie context.
1887 A cookie file contains one cookie per line. Each line
1888 has three space-separated fields:
1892 The cookie ID number, which must be a non-negative integer and
1893 may not be used twice in the same file.
1898 The cookie's creation time, in UNIX seconds-since-the-epoch
1904 The cookie itself, a hex-encoded random block of bytes.
1910 Only server processes modify the cookie file.
1911 They must do so with this procedure:
1915 Create a lockfile name by appending ".lock" to the name of the
1916 cookie file. The server should attempt to create this file
1917 using <literal>O_CREAT | O_EXCL</literal>. If file creation
1918 fails, the lock fails. Servers should retry for a reasonable
1919 period of time, then they may choose to delete an existing lock
1920 to keep users from having to manually delete a stale
1921 lock. <footnote><para>Lockfiles are used instead of real file
1922 locking <literal>fcntl()</literal> because real locking
1923 implementations are still flaky on network
1924 filesystems.</para></footnote>
1929 Once the lockfile has been created, the server loads the cookie
1930 file. It should then delete any cookies that are old (the
1931 timeout can be fairly short), or more than a reasonable
1932 time in the future (so that cookies never accidentally
1933 become permanent, if the clock was set far into the future
1934 at some point). If no recent keys remain, the
1935 server may generate a new key.
1940 The pruned and possibly added-to cookie file
1941 must be resaved atomically (using a temporary
1942 file which is rename()'d).
1947 The lock must be dropped by deleting the lockfile.
1953 Clients need not lock the file in order to load it,
1954 because servers are required to save the file atomically.
1959 <sect1 id="addresses">
1960 <title>Server Addresses</title>
1962 Server addresses consist of a transport name followed by a colon, and
1963 then an optional, comma-separated list of keys and values in the form key=value.
1964 [FIXME how do you escape colon, comma, and semicolon in the values of the key=value pairs?]
1968 <programlisting>unix:path=/tmp/dbus-test</programlisting>
1969 Which is the address to a unix socket with the path /tmp/dbus-test.
1972 [FIXME clarify if attempting to connect to each is a requirement
1973 or just a suggestion]
1974 When connecting to a server, multiple server addresses can be
1975 separated by a semi-colon. The library will then try to connect
1976 to the first address and if that fails, it'll try to connect to
1977 the next one specified, and so forth. For example
1978 <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
1981 [FIXME we need to specify in detail each transport and its possible arguments]
1982 Current transports include: unix domain sockets (including
1983 abstract namespace on linux), TCP/IP, and a debug/testing transport using
1984 in-process pipes. Future possible transports include one that
1985 tunnels over X11 protocol.
1989 <sect1 id="standard-messages">
1990 <title>Standard Peer-to-Peer Messages</title>
1992 See <xref linkend="message-protocol-types-notation"/> for details on
1993 the notation used in this section.
1995 <sect2 id="standard-messages-ping">
1996 <title><literal>org.freedesktop.Peer.Ping</literal></title>
1999 org.freedesktop.Peer.Ping ()
2003 On receipt of the METHOD_CALL
2004 message <literal>org.freedesktop.Peer.Ping</literal>, an application
2005 should do nothing other than reply with a METHOD_RETURN as usual.
2009 <sect2 id="standard-messages-get-props">
2010 <title><literal>org.freedesktop.Props.Get</literal></title>
2012 [FIXME this is just a bogus made-up method that isn't implemented
2013 or thought through, to save an example of table formatting for the
2014 argument descriptions]
2016 org.freedesktop.Props.Get (in STRING property_name,
2017 out ANY_OR_NIL property_value)
2024 <entry>Argument</entry>
2026 <entry>Description</entry>
2032 <entry>in STRING</entry>
2033 <entry>Name of the property to get</entry>
2037 <entry>out ANY_OR_NIL</entry>
2038 <entry>The value of the property. The type depends on the property.</entry>
2047 <sect1 id="message-bus">
2048 <title>Message Bus Specification</title>
2049 <sect2 id="message-bus-overview">
2050 <title>Message Bus Overview</title>
2052 The message bus accepts connections from one or more applications.
2053 Once connected, applications can send and receive messages from
2054 the message bus, as in the peer-to-peer case.
2057 The message bus keeps track of a set of
2058 <firstterm>services</firstterm>. A service is simply a name, such as
2059 <literal>com.yoyodyne.Screensaver</literal>, which can be
2060 <firstterm>owned</firstterm> by one or more of the connected
2061 applications. The message bus itself always owns the special service
2062 <literal>org.freedesktop.DBus</literal>.
2065 Services may have <firstterm>secondary owners</firstterm>. Secondary owners
2066 of a service are kept in a queue; if the primary owner of a service
2067 disconnects, or releases the service, the next secondary owner becomes
2068 the new owner of the service.
2071 Messages may have a <literal>SERVICE</literal> field (see <xref
2072 linkend="message-protocol-header-fields"/>). When the message bus
2073 receives a message, if the <literal>SERVICE</literal> field is absent, the
2074 message is taken to be a standard peer-to-peer message and interpreted
2075 by the message bus itself. For example, sending
2076 an <literal>org.freedesktop.Peer.Ping</literal> message with no
2077 <literal>SERVICE</literal> will cause the message bus itself to reply
2078 to the ping immediately; the message bus would never make
2079 this message visible to other applications.
2082 If the <literal>SERVICE</literal> field is present, then it indicates a
2083 request for the message bus to route the message. In the usual case,
2084 messages are routed to the owner of the named service.
2085 Messages may also be <firstterm>broadcast</firstterm>
2086 by sending them to the special service
2087 <literal>org.freedesktop.DBus.Broadcast</literal>. Broadcast messages are
2088 sent to all applications with <firstterm>message matching
2089 rules</firstterm> that match the message.
2092 Continuing the <literal>org.freedesktop.Peer.Ping</literal> example, if
2093 the ping message were sent with a <literal>SERVICE</literal> name of
2094 <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
2095 forwarded, and the Yoyodyne Corporation screensaver application would be
2096 expected to reply to the ping. If
2097 <literal>org.freedesktop.Peer.Ping</literal> were sent to
2098 <literal>org.freedesktop.DBus.Broadcast</literal>, then multiple applications
2099 might receive the ping, and all would normally reply to it.
2103 <sect2 id="message-bus-services">
2104 <title>Message Bus Services</title>
2106 A service is a name that identifies a certain application. Each
2107 application connected to the message bus has at least one service name
2108 assigned at connection time and returned in response to the
2109 <literal>org.freedesktop.DBus.Hello</literal> message.
2110 This automatically-assigned service name is called
2111 the application's <firstterm>base service</firstterm>.
2112 Base service names are unique and MUST never be reused for two different
2116 Ownership of the base service is a prerequisite for interaction with
2117 the message bus. It logically follows that the base service is always
2118 the first service that an application comes to own, and the last
2119 service that it loses ownership of.
2122 Base service names must begin with the character ':' (ASCII colon
2123 character); service names that are not base service names must not begin
2124 with this character. (The bus must reject any attempt by an application
2125 to manually create a service name beginning with ':'.) This restriction
2126 categorically prevents "spoofing"; messages sent to a base service name
2127 will always go to a single application instance and that instance only.
2130 An application can request additional service names to be associated
2132 <literal>org.freedesktop.DBus.AcquireService</literal>
2133 message. [FIXME what service names are allowed; ASCII or unicode;
2137 [FIXME this needs more detail, and should move the service-related message
2138 descriptions up into this section perhaps]
2139 Service ownership handling can be specified in the flags part
2140 of the <literal>org.freedesktop.DBus.AcquireService</literal>
2141 message. If an application specifies the
2142 DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT flag, then all applications
2143 trying to acquire the service will be put in a queue. When the
2144 primary owner disconnects from the bus or removes ownership
2145 from the service, the next application in the queue will be the
2146 primary owner. If the DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT
2147 flag is not specified, then the primary owner will lose
2148 ownership whenever another application requests ownership of the
2152 When a client disconnects from the bus, all the services that
2153 the clients own are deleted, or in the case of a service that
2154 prohibits replacement, ownership is transferred to the next
2155 client in the queue, if any.
2158 <sect2 id="message-bus-routing">
2159 <title>Message Bus Message Routing</title>
2161 When a message is received by the message bus, the message's
2162 <literal>sndr</literal> header field MUST be set to the base service of
2163 the application which sent the message. If the service already has
2164 a <literal>sndr</literal> field, the pre-existing field is replaced.
2165 This rule means that a replies are always sent to the base service name,
2166 i.e. to the same application that sent the message being replied to.
2169 [FIXME go into detail about broadcast, multicast, unicast, etc.]
2172 <sect2 id="message-bus-activation">
2173 <title>Message Bus Service Activation</title>
2175 <firstterm>Activation</firstterm> means to locate a service
2176 owner for a service that is currently unowned. For now, it
2177 means to launch an executable that will take ownership of
2178 a particular service.
2181 To find an executable corresponding to a particular service, the bus
2182 daemon looks for <firstterm>service description files</firstterm>.
2183 Service description files define a mapping from service names to
2184 executables. Different kinds of message bus will look for these files
2185 in different places, see <xref linkend="message-bus-types"/>.
2188 [FIXME the file format should be much better specified than
2189 "similar to .desktop entries" esp. since desktop entries are
2190 already badly-specified. ;-)] Service description files have
2191 the ".service" file extension. The message bus will only load
2192 service description files ending with .service; all other
2193 files will be ignored. The file format is similar to that of
2195 url="http://www.freedesktop.org/standards/desktop-entry-spec/desktop-entry-spec.html">desktop
2196 entries</ulink>. All service description files must be in
2197 UTF-8 encoding. To ensure that there will be no name
2198 collisions, service files must be namespaced using the same
2199 mechanism as messages and service names.
2202 <title>Example service description file</title>
2204 # Sample service description file
2206 Name=org.gnome.ConfigurationDatabase
2207 Exec=/usr/libexec/gconfd-2
2212 When an application requests a service to be activated, the
2213 bus daemon tries to find it in the list of activation
2214 entries. It then tries to spawn the executable associated with
2215 it. If this fails, it will report an error. [FIXME what
2216 happens if two .service files offer the same service; what
2217 kind of error is reported, should we have a way for the client
2221 The executable launched will have the environment variable
2222 <literal>DBUS_ACTIVATION_ADDRESS</literal> set to the address of the
2223 message bus so it can connect and register the appropriate services.
2226 The executable being launched may want to know whether the message bus
2227 activating it is one of the well-known message buses (see <xref
2228 linkend="message-bus-types"/>). To facilitate this, the bus MUST also set
2229 the <literal>DBUS_ACTIVATION_BUS_TYPE</literal> environment variable if it is one
2230 of the well-known buses. The currently-defined values for this variable
2231 are <literal>system</literal> for the systemwide message bus,
2232 and <literal>session</literal> for the per-login-session message
2233 bus. The activated executable must still connect to the address given
2234 in <literal>DBUS_ACTIVATION_ADDRESS</literal>, but may assume that the
2235 resulting connection is to the well-known bus.
2238 [FIXME there should be a timeout somewhere, either specified
2239 in the .service file, by the client, or just a global value
2240 and if the client being activated fails to connect within that
2241 timeout, an error should be sent back.]
2245 <sect2 id="message-bus-types">
2246 <title>Well-known Message Bus Instances</title>
2248 Two standard message bus instances are defined here, along with how
2249 to locate them and where their service files live.
2251 <sect3 id="message-bus-types-login">
2252 <title>Login session message bus</title>
2254 Each time a user logs in, a <firstterm>login session message
2255 bus</firstterm> may be started. All applications in the user's login
2256 session may interact with one another using this message bus.
2259 The address of the login session message bus is given
2260 in the <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment
2261 variable. If that variable is not set, applications may
2262 also try to read the address from the X Window System root
2263 window property <literal>_DBUS_SESSION_BUS_ADDRESS</literal>.
2264 The root window property must have type <literal>STRING</literal>.
2265 The environment variable should have precedence over the
2266 root window property.
2269 [FIXME specify location of .service files, probably using
2270 DESKTOP_DIRS etc. from basedir specification, though login session
2271 bus is not really desktop-specific]
2274 <sect3 id="message-bus-types-system">
2275 <title>System message bus</title>
2277 A computer may have a <firstterm>system message bus</firstterm>,
2278 accessible to all applications on the system. This message bus may be
2279 used to broadcast system events, such as adding new hardware devices,
2280 changes in the printer queue, and so forth.
2283 The address of the login session message bus is given
2284 in the <literal>DBUS_SYSTEM_BUS_ADDRESS</literal> environment
2285 variable. If that variable is not set, applications should try
2286 to connect to the well-known address
2287 <literal>unix:path=/var/run/dbus/system_bus_socket</literal>.
2290 The D-BUS reference implementation actually honors the
2291 <literal>$(localstatedir)</literal> configure option
2292 for this address, on both client and server side.
2297 [FIXME specify location of system bus .service files]
2302 <sect2 id="message-bus-messages">
2303 <title>Message Bus Messages</title>
2305 The special message bus service <literal>org.freedesktop.DBus</literal>
2306 responds to a number of messages, allowing applications to
2307 interact with the message bus.
2310 <sect3 id="bus-messages-hello">
2311 <title><literal>org.freedesktop.DBus.Hello</literal></title>
2322 <entry>Argument</entry>
2324 <entry>Description</entry>
2330 <entry>STRING</entry>
2331 <entry>Name of the service assigned to the application</entry>
2338 Before an application is able to send messages to other
2339 applications it must send the
2340 <literal>org.freedesktop.DBus.Hello</literal> message to the
2341 message bus service. If an application tries to send a
2342 message to another application, or a message to the message
2343 bus service that isn't the
2344 <literal>org.freedesktop.DBus.Hello</literal> message, it
2345 will be disconnected from the bus. If a client wishes to
2346 disconnect from the bus, it just has to disconnect from the
2347 transport used. No de-registration message is necessary.
2350 The reply message contains the name of the application's base service.
2353 <sect3 id="bus-messages-list-services">
2354 <title><literal>org.freedesktop.DBus.ListServices</literal></title>
2358 STRING_ARRAY ListServices ()
2365 <entry>Argument</entry>
2367 <entry>Description</entry>
2373 <entry>STRING_ARRAY</entry>
2374 <entry>Array of strings where each string is the name of a service</entry>
2381 Returns a list of all existing services registered with the message bus.
2384 <sect3 id="bus-messages-service-exists">
2385 <title><literal>org.freedesktop.DBus.ServiceExists</literal></title>
2389 BOOLEAN ServiceExists (in STRING service_name)
2396 <entry>Argument</entry>
2398 <entry>Description</entry>
2404 <entry>STRING</entry>
2405 <entry>Name of the service</entry>
2415 <entry>Argument</entry>
2417 <entry>Description</entry>
2423 <entry>BOOLEAN</entry>
2424 <entry>Return value, true if the service exists</entry>
2431 Checks if a service with a specified name exists.
2435 <sect3 id="bus-messages-acquire-service">
2436 <title><literal>org.freedesktop.DBus.AcquireService</literal></title>
2440 UINT32 AcquireService (in STRING service_name)
2447 <entry>Argument</entry>
2449 <entry>Description</entry>
2455 <entry>STRING</entry>
2456 <entry>Name of the service</entry>
2460 <entry>UINT32</entry>
2461 <entry>Flags</entry>
2471 <entry>Argument</entry>
2473 <entry>Description</entry>
2479 <entry>UINT32</entry>
2480 <entry>Return value</entry>
2487 Tries to become owner of a specific service. The flags
2488 specified can be the following values logically ORed together:
2494 <entry>Identifier</entry>
2495 <entry>Value</entry>
2496 <entry>Description</entry>
2501 <entry>DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT</entry>
2504 If the application succeeds in being the owner of the specified service,
2505 then ownership of the service can't be transferred until the service
2506 disconnects. If this flag is not set, then any application trying to become
2507 the owner of the service will succeed and the previous owner will be
2508 sent a <literal>org.freedesktop.DBus.ServiceLost</literal> message.
2512 <entry>DBUS_SERVICE_FLAGS_REPLACE_EXISTING</entry>
2514 <entry>Try to replace the current owner if there is one. If this flag
2515 is not set the application will only become the owner of the service if
2516 there is no current owner.</entry>
2522 [FIXME if it's one of the following values, why are the values
2523 done as flags instead of just 0, 1, 2, 3, 4]
2524 The return value can be one of the following values:
2530 <entry>Identifier</entry>
2531 <entry>Value</entry>
2532 <entry>Description</entry>
2537 <entry>DBUS_SERVICE_REPLY_PRIMARY_OWNER</entry>
2539 <entry>The application is now the primary owner of the service.</entry>
2542 <entry>DBUS_SERVICE_REPLY_IN_QUEUE</entry>
2544 <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>
2547 <entry>DBUS_SERVICE_REPLY_SERVICE_EXISTS</entry>
2549 <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>
2552 <entry>DBUS_SERVICE_REPLY_ALREADY_OWNER</entry>
2554 <entry>The application trying to request ownership of the service is already the owner of it.</entry>
2561 <sect3 id="bus-messages-service-acquired">
2562 <title><literal>org.freedesktop.DBus.ServiceAcquired</literal></title>
2566 ServiceAcquired (in STRING service_name)
2573 <entry>Argument</entry>
2575 <entry>Description</entry>
2581 <entry>STRING</entry>
2582 <entry>Name of the service</entry>
2586 <entry>UINT32</entry>
2587 <entry>Flags</entry>
2594 This message is sent to a specific application when it becomes the
2595 primary owner of a service.
2598 <sect3 id="bus-messages-service-lost">
2599 <title><literal>org.freedesktop.DBus.ServiceLost</literal></title>
2603 ServiceLost (in STRING service_name)
2610 <entry>Argument</entry>
2612 <entry>Description</entry>
2618 <entry>STRING</entry>
2619 <entry>Name of the service</entry>
2623 <entry>UINT32</entry>
2624 <entry>Flags</entry>
2631 This message is sent to a specific application when it loses primary
2632 ownership of a service.
2636 <sect3 id="bus-messages-service-owner-changed">
2637 <title><literal>org.freedesktop.DBus.ServiceOwnerChanged</literal></title>
2640 ServiceOwnerChanged (STRING service_name, STRING old_owner, STRING new_owner)
2647 <entry>Argument</entry>
2649 <entry>Description</entry>
2655 <entry>STRING</entry>
2656 <entry>Name of the service</entry>
2660 <entry>STRING</entry>
2661 <entry>Base service of previous owner, empty string if the
2662 service is newly created</entry>
2666 <entry>STRING</entry>
2667 <entry>Base service of new owner, empty string if the
2668 service is no longer available</entry>
2675 This message is broadcast to all applications when a service has been
2676 successfully registered on the message bus, has been deleted
2677 or its primary owner has changed.
2681 <sect3 id="bus-messages-activate-service">
2682 <title><literal>org.freedesktop.DBus.ActivateService</literal></title>
2686 UINT32 ActivateService (in STRING service_name, in UINT32 flags)
2693 <entry>Argument</entry>
2695 <entry>Description</entry>
2701 <entry>STRING</entry>
2702 <entry>Name of the service to activate</entry>
2706 <entry>UINT32</entry>
2707 <entry>Flags (currently not used)</entry>
2717 <entry>Argument</entry>
2719 <entry>Description</entry>
2725 <entry>UINT32</entry>
2726 <entry>Return value</entry>
2731 Tries to launch the executable associated with a service. For more information, see <xref linkend="message-bus-activation"/>.
2733 [FIXME need semantics in much more detail here; for example,
2734 if I activate a service then send it a message, is the message
2735 queued for the new service or is there a race]
2738 The return value can be one of the following values:
2743 <entry>Identifier</entry>
2744 <entry>Value</entry>
2745 <entry>Description</entry>
2750 <entry>DBUS_ACTIVATION_REPLY_ACTIVATED</entry>
2752 <entry>The service was activated successfully.</entry>
2755 <entry>DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE</entry>
2757 <entry>The service is already active.</entry>
2766 <sect3 id="bus-messages-get-service-owner">
2767 <title><literal>org.freedesktop.DBus.GetServiceOwner</literal></title>
2771 STRING GetServiceOwner (in STRING service_name)
2778 <entry>Argument</entry>
2780 <entry>Description</entry>
2786 <entry>STRING</entry>
2787 <entry>Name of the service to query</entry>
2797 <entry>Argument</entry>
2799 <entry>Description</entry>
2805 <entry>STRING</entry>
2806 <entry>Return value, a base service name</entry>
2811 Returns the base service name of the primary owner of the
2812 service in argument. If the requested service isn't active,
2814 <literal>org.freedesktop.DBus.Error.ServiceHasNoOwner</literal> error.
2818 <sect3 id="bus-messages-get-connection-unix-user">
2819 <title><literal>org.freedesktop.DBus.GetConnectionUnixUser</literal></title>
2823 UINT32 GetConnectionUnixUser (in STRING connection_name)
2830 <entry>Argument</entry>
2832 <entry>Description</entry>
2838 <entry>STRING</entry>
2839 <entry>Name of the connection/service to query</entry>
2849 <entry>Argument</entry>
2851 <entry>Description</entry>
2857 <entry>UINT32</entry>
2858 <entry>unix user id</entry>
2863 Returns the unix uid of the process connected to the server. If unable to
2864 determine it, a <literal>org.freedesktop.DBus.Error.Failed</literal>
2869 <sect3 id="bus-messages-out-of-memory">
2870 <title><literal>org.freedesktop.DBus.Error.NoMemory</literal></title>
2878 Sent by the message bus when it can't process a message due to an out of memory failure.
2882 <sect3 id="bus-messages-service-does-not-exist">
2883 <title><literal>org.freedesktop.DBus.Error.ServiceDoesNotExist</literal></title>
2887 void ServiceDoesNotExist (in STRING error)
2891 Sent by the message bus as a reply to a client that tried to send a message to a service that doesn't exist.
2898 <appendix id="implementation-notes">
2899 <title>Implementation notes</title>
2900 <sect1 id="implementation-notes-subsection">
2908 <glossary><title>Glossary</title>
2910 This glossary defines some of the terms used in this specification.
2913 <glossentry id="term-activation"><glossterm>Activation</glossterm>
2916 The process of creating an owner for a particular service,
2917 typically by launching an executable.
2922 <glossentry id="term-base-service"><glossterm>Base Service</glossterm>
2925 The special service automatically assigned to an application by the
2926 message bus. This service may never change owner, and the service
2927 name will be unique (never reused during the lifetime of the
2933 <glossentry id="term-broadcast"><glossterm>Broadcast</glossterm>
2936 A message sent to the special <literal>org.freedesktop.DBus.Broadcast</literal>
2937 service; the message bus will forward the broadcast message
2938 to all applications that have expressed interest in it.
2943 <glossentry id="term-message"><glossterm>Message</glossterm>
2946 A message is the atomic unit of communication via the D-BUS
2947 protocol. It consists of a <firstterm>header</firstterm> and a
2948 <firstterm>body</firstterm>; the body is made up of
2949 <firstterm>arguments</firstterm>.
2954 <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
2957 The message bus is a special application that forwards
2958 or broadcasts messages between a group of applications
2959 connected to the message bus. It also manages
2960 <firstterm>services</firstterm>.
2965 <glossentry id="namespace"><glossterm>Namespace</glossterm>
2968 Used to prevent collisions when defining message and service
2969 names. The convention used is the same as Java uses for
2970 defining classes: a reversed domain name.
2975 <glossentry id="term-object"><glossterm>Object</glossterm>
2978 Each application contains <firstterm>objects</firstterm>,
2979 which have <firstterm>interfaces</firstterm> and
2980 <firstterm>methods</firstterm>. Objects are referred to
2981 by a name, called a <firstterm>path</firstterm> or
2982 <firstterm>object reference</firstterm>.
2987 <glossentry id="term-path"><glossterm>Path</glossterm>
2990 Object references (object names) in D-BUS are
2991 organized into a filesystem-style hierarchy, so
2992 each object is named by a path. As in LDAP,
2993 there's no difference between "files" and "directories";
2994 a path can refer to an object, while still having
2995 child objects below it.
3000 <glossentry id="peer-to-peer"><glossterm>Peer-to-peer</glossterm>
3003 An application talking directly to another application, without going through a message bus.
3007 <glossentry id="term-secondary-owner"><glossterm>Secondary service owner</glossterm>
3010 Each service has a primary owner; messages sent to the service name
3011 go to the primary owner. However, certain services also maintain
3012 a queue of secondary owners "waiting in the wings." If
3013 the primary owner releases the service, then the first secondary
3014 owner in the queue automatically becomes the primary owner.
3018 <glossentry id="term-service"><glossterm>Service</glossterm>
3021 A service is simply a named list of applications. For example, the
3022 hypothetical <literal>com.yoyodyne.Screensaver</literal> service might
3023 accept messages that affect a screensaver from Yoyodyne Corporation.
3024 An application is said to <firstterm>own</firstterm> a service if the
3025 message bus has associated the application with the service name.
3026 Services may also have <firstterm>secondary owners</firstterm> (see
3027 <xref linkend="term-secondary-owner"/>).
3031 <glossentry id="term-service-name"><glossterm>Service name</glossterm>
3034 The name used when referring to a service. If the service is
3035 a base service it has a unique service name, for example
3036 ":1-20", and otherwise it should be namespaced.
3040 <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
3043 ".service files" tell the bus how to activate a particular service.
3044 See <xref linkend="term-activation"/>