1 <!doctype article PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
5 <title>D-BUS Protocol Specification</title>
6 <releaseinfo>Version 0.4</releaseinfo>
7 <date>17 February 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.
76 <sect1 id="message-protocol">
77 <title>Message Protocol</title>
79 A <firstterm>message</firstterm> consists of a
80 <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
81 think of a message as a package, the header is the address, and the body
82 contains the package contents. The message delivery system uses the header
83 information to figure out where to send the message and how to interpret
84 it; the recipient inteprets the body of the message.
88 The body of the message is made up of zero or more
89 <firstterm>arguments</firstterm>, which are typed
90 values, such as an integer or a byte array.
93 <sect2 id="message-protocol-header-encoding">
94 <title>Header Encoding</title>
96 Following the mandatory fields, there are zero or more named fields (see
97 <xref linkend="message-protocol-header-fields">), and then nul bytes
98 padding the header such that its total length in bytes is a multiple of
102 The header MUST begin with the following mandatory fields in the following
109 <entry>Description</entry>
114 <entry>1 byte</entry>
115 <entry>Endianness flag; ASCII 'l' for little-endian
116 or ASCII 'B' for big-endian.</entry>
119 <entry>1 byte</entry>
120 <entry>Bitwise OR of flags. Unknown flags
121 MUST be ignored. Currently-defined flags are described below.
125 <entry>1 byte</entry>
126 <entry>Major protocol version of the sending application. If
127 the major protocol version of the receiving application does not
128 match, the applications will not be able to communicate and the
129 D-BUS connection MUST be disconnected. The major protocol
130 version for this version of the specification is 0.
134 <entry>1 byte</entry>
135 <entry>A nul byte, reserved for future use.
136 Any value for this byte MUST be accepted.
140 <entry>4 bytes</entry>
141 <entry>An unsigned 32-bit integer in the
142 message's byte order, indicating the total length in bytes of
143 the header including named fields and any alignment padding.
144 MUST be a multiple of 8.
148 <entry>4 bytes</entry>
149 <entry>An unsigned 32-bit integer in the
150 message's byte order, indicating the total length in bytes of
155 <entry>4 bytes</entry>
156 <entry>The message's serial number, a signed 32-bit integer in
157 the message's byte order. Applications MUST NOT reuse the same
158 serial number for different messages more often than 32-bit
159 integer wraparound. Serial numbers must be greater than
168 Flags that can appear in the second byte of the header:
173 <entry>Hex value</entry>
174 <entry>Description</entry>
180 <entry>This message is an error reply.</entry>
188 <sect2 id="message-protocol-header-fields">
189 <title>Header Fields</title>
191 In addition to the required header information mentioned
192 in <xref linkend="message-protocol-header-encoding">,
193 the header may contain zero or more named
194 header fields. These fields are named to allow
195 future versions of this protocol specification to
196 add new fields; implementations must ignore fields
197 they do not understand. Implementations must not
198 invent their own header fields; only changes to
199 this specification may introduce new header fields.
203 Header field names MUST consist of 4 non-nul bytes. The field name is
204 NOT nul terminated; it occupies exactly 4 bytes. Following the name,
205 the field MUST have a type code, and then a properly-aligned value
207 See <xref linkend="message-protocol-arguments"> for a description
208 of how each type is encoded. If an implementation sees a header
209 field name that it does not understand, it MUST ignore
214 Here are the currently-defined named header fields:
221 <entry>Description</entry>
227 <entry>STRING</entry>
228 <entry>The name of the message, such as org.freedesktop.Peer.Ping</entry>
233 <entry>The serial number of the message this message is a reply
234 to. (The serial number is one of the mandatory header fields,
235 see <xref linkend="message-protocol-header-encoding">.)</entry>
239 <entry>STRING</entry>
240 <entry>The name of the service this message should be routed to.
241 Only used in combination with the message bus, see
242 <xref linkend="message-bus">.</entry>
246 <entry>STRING</entry>
247 <entry>The name of the base service that sent this message.
248 The message bus fills in this field; the field is
249 only meaningful in combination with the message bus.</entry>
257 <sect2 id="message-protocol-header-padding">
258 <title>Header Alignment Padding</title>
260 To allow implementations to keep the header and the body in a single
261 buffer while keeping data types aligned, the total length of the header
262 must be a multiple of 8 bytes. To achieve this, the header MUST be padded
263 with nul bytes to align its total length on an 8-byte boundary.
264 The minimum number of padding bytes MUST be used. Because all possible
265 named fields use at least 8 bytes, implementations can distinguish
266 padding (which must be less than 8 bytes) from additional named fields
267 (which must be at least 8 bytes).
271 <sect2 id="message-protocol-arguments">
272 <title>Message Arguments</title>
274 The message body is made up of arguments. Each argument
275 is a type code, followed by the value of the argument
276 in a type-dependent format.
279 [FIXME perhaps we should add type BYTE with the primary
280 advantage being that it occupies 1 byte vs. 7 for UINT32,
281 or perhaps space savings aren't worth the complexity]
282 [FIXME perhaps we should add type BOOL with the primary
283 advantage being better type safety vs. overloading of
285 The type codes are as follows:
290 <entry>Type name</entry>
292 <entry>Description</entry>
297 <entry>INVALID</entry>
299 <entry>Not a valid type code (error if it appears in a message)</entry>
303 <entry>Marks an "unset" or "nonexistent" argument</entry>
307 <entry>32-bit signed integer</entry>
309 <entry>UINT32</entry>
311 <entry>32-bit unsigned integer</entry>
313 <entry>DOUBLE</entry>
315 <entry>IEEE 754 double</entry>
317 <entry>STRING</entry>
319 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8)</entry>
321 <entry>INT32_ARRAY</entry>
323 <entry>Array of INT32</entry>
325 <entry>UINT32_ARRAY</entry>
327 <entry>Array of UINT32</entry>
329 <entry>DOUBLE_ARRAY</entry>
331 <entry>Array of DOUBLE</entry>
333 <entry>BYTE_ARRAY</entry>
335 <entry>Array of bytes</entry>
337 <entry>STRING_ARRAY</entry>
339 <entry>Array of STRING</entry>
346 The types are encoded as follows:
351 <entry>Type name</entry>
352 <entry>Encoding</entry>
357 <entry>INVALID</entry>
358 <entry>Not applicable; cannot be encoded.</entry>
361 <entry>No data is encoded; the type code is followed immediately
362 by the type code of the next argument.</entry>
365 <entry>32-bit signed integer in the message's byte order, aligned to 4-byte boundary.</entry>
367 <entry>UINT32</entry>
368 <entry>32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary.</entry>
370 <entry>DOUBLE</entry>
371 <entry>64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary.</entry>
373 <entry>STRING</entry>
374 <entry>UINT32 aligned to 4-byte boundary indicating the string's
375 length in bytes excluding its terminating nul, followed by
376 string data of the given length, followed by a terminating nul
380 <entry>INT32_ARRAY</entry>
381 <entry>UINT32 giving the number of values in the array,
382 followed by the given number of INT32 values.
385 <entry>UINT32_ARRAY</entry>
386 <entry>UINT32 giving the number of values in the array,
387 followed by the given number of UINT32 values.
390 <entry>DOUBLE_ARRAY</entry>
391 <entry>UINT32 giving the number of values in the array,
392 followed by the given number of DOUBLE values aligned
396 <entry>BYTE_ARRAY</entry>
397 <entry>UINT32 giving the number of values in the array,
398 followed by the given number of one-byte values.
401 <entry>STRING_ARRAY</entry>
402 <entry>UINT32 giving the number of values in the array,
403 followed by the given number of STRING values.
413 <sect1 id="auth-protocol">
414 <title>Authentication Protocol</title>
416 Before the flow of messages begins, two applications
417 must authenticate. A simple text protocol is used
418 for authentication; this protocol is a SASL profile,
419 and maps fairly directly from the SASL specification.
422 In examples, "C:" and "S:" indicate lines sent by the client and
425 <sect2 id="auth-protocol-overview">
426 <title>Protocol Overview</title>
428 The protocol is a line-based protocol, where each line ends with
429 \r\n. Each line begins with an all-caps ASCII command name containing
430 only the character range [A-Z], a space, then any arguments for the
431 command, then the \r\n ending the line. The protocol is
432 case-sensitive. All bytes must be in the ASCII character set.
434 Commands from the client to the server are as follows:
437 <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
438 <listitem><para>CANCEL</para></listitem
439 <listitem><para>BEGIN</para></listitem>
440 <listitem><para>DATA <data in base 64 encoding></para></listitem>
441 <listitem><para>ERROR [human-readable error explanation]</para></listitem>
444 From server to client are as follows:
447 <listitem><para>REJECTED <space-separated list of mechanism names></para></listitem>
448 <listitem><para>OK</para></listitem>
449 <listitem><para>DATA <data in base 64 encoding></para></listitem>
450 <listitem><para>ERROR</para></listitem>
454 <sect2 id="auth-nul-byte">
455 <title>Special credentials-passing nul byte</title>
457 Immediately after connecting to the server, the client must send a
458 single nul byte. This byte may be accompanied by credentials
459 information on some operating systems that use sendmsg() with
460 SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
461 sockets. However, the nul byte MUST be sent even on other kinds of
462 socket, and even on operating systems that do not require a byte to be
463 sent in order to transmit credentials. The text protocol described in
464 this document begins after the single nul byte. If the first byte
465 received from the client is not a nul byte, the server may disconnect
469 A nul byte in any context other than the initial byte is an error;
470 the protocol is ASCII-only.
473 The credentials sent along with the nul byte may be used with the
474 SASL mechanism EXTERNAL.
478 <sect2 id="auth-command-auth">
479 <title>AUTH command</title>
481 If an AUTH command has no arguments, it is a request to list
482 available mechanisms. The server SHOULD respond with a REJECTED
483 command listing the mechanisms it understands.
486 If an AUTH command specifies a mechanism, and the server supports
487 said mechanism, the server SHOULD begin exchanging SASL
488 challenge-response data with the client using DATA commands.
491 If the server does not support the mechanism given in the AUTH
492 command, it SHOULD send a REJECTED command listing the mechanisms
496 If the [initial-response] argument is provided, it is intended for
497 use with mechanisms that have no initial challenge (or an empty
498 initial challenge), as if it were the argument to an initial DATA
499 command. If the selected mechanism has an initial challenge, the
500 server should reject authentication by sending REJECTED.
503 If authentication succeeds after exchanging DATA commands,
504 an OK command should be sent to the client.
507 The first octet received by the client after the \r\n of the OK
508 command MUST be the first octet of the authenticated/encrypted
509 stream of D-BUS messages.
512 The first octet received by the server after the \r\n of the BEGIN
513 command from the client MUST be the first octet of the
514 authenticated/encrypted stream of D-BUS messages.
517 <sect2 id="auth-command-cancel">
518 <title>CANCEL Command</title>
520 At any time up to sending the BEGIN command, the client may send a
521 CANCEL command. On receiving the CANCEL command, the server MUST
522 send a REJECTED command and abort the current authentication
526 <sect2 id="auth-command-data">
527 <title>DATA Command</title>
529 The DATA command may come from either client or server, and simply
530 contains a base64-encoded block of data to be interpreted
531 according to the SASL mechanism in use.
534 Some SASL mechanisms support sending an "empty string";
535 FIXME we need some way to do this.
538 <sect2 id="auth-command-begin">
539 <title>BEGIN Command</title>
541 The BEGIN command acknowledges that the client has received an
542 OK command from the server, and that the stream of messages
546 The first octet received by the server after the \r\n of the BEGIN
547 command from the client MUST be the first octet of the
548 authenticated/encrypted stream of D-BUS messages.
551 <sect2 id="auth-command-rejected">
552 <title>REJECTED Command</title>
554 The REJECTED command indicates that the current authentication
555 exchange has failed, and further exchange of DATA is inappropriate.
556 The client would normally try another mechanism, or try providing
557 different responses to challenges.
559 Optionally, the REJECTED command has a space-separated list of
560 available auth mechanisms as arguments. If a server ever provides
561 a list of supported mechanisms, it MUST provide the same list
562 each time it sends a REJECTED message. Clients are free to
563 ignore all lists received after the first.
566 <sect2 id="auth-command-ok">
567 <title>OK Command</title>
569 The OK command indicates that the client has been authenticated,
570 and that further communication will be a stream of D-BUS messages
571 (optionally encrypted, as negotiated) rather than this protocol.
574 The first octet received by the client after the \r\n of the OK
575 command MUST be the first octet of the authenticated/encrypted
576 stream of D-BUS messages.
579 The client MUST respond to the OK command by sending a BEGIN
580 command, followed by its stream of messages, or by disconnecting.
581 The server MUST NOT accept additional commands using this protocol
582 after the OK command has been sent.
585 <sect2 id="auth-command-error">
586 <title>ERROR Command</title>
588 The ERROR command indicates that either server or client did not
589 know a command, does not accept the given command in the current
590 context, or did not understand the arguments to the command. This
591 allows the protocol to be extended; a client or server can send a
592 command present or permitted only in new protocol versions, and if
593 an ERROR is received instead of an appropriate response, fall back
594 to using some other technique.
596 If an ERROR is sent, the server or client MUST continue as if the
597 command causing the ERROR had never been received.
600 <sect2 id="auth-examples">
601 <title>Authentication examples</title>
605 <title>Example of successful magic cookie authentication</title>
607 (MAGIC_COOKIE is a made up mechanism)
609 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
615 <title>Example of finding out mechanisms then picking one</title>
618 S: REJECTED KERBEROS_V4 SKEY
619 C: AUTH SKEY bW9yZ2Fu
620 S: DATA OTUgUWE1ODMwOA==
621 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
627 <title>Example of client sends unknown command then falls back to regular auth</title>
631 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
637 <title>Example of server doesn't support initial auth mechanism</title>
639 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
640 S: REJECTED KERBEROS_V4 SKEY
641 C: AUTH SKEY bW9yZ2Fu
642 S: DATA OTUgUWE1ODMwOA==
643 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
649 <title>Example of wrong password or the like followed by successful retry</title>
651 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
652 S: REJECTED KERBEROS_V4 SKEY
653 C: AUTH SKEY bW9yZ2Fu
654 S: DATA OTUgUWE1ODMwOA==
655 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
657 C: AUTH SKEY bW9yZ2Fu
658 S: DATA OTUgUWE1ODMwOA==
659 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
665 <title>Example of skey cancelled and restarted</title>
667 C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
668 S: REJECTED KERBEROS_V4 SKEY
669 C: AUTH SKEY bW9yZ2Fu
670 S: DATA OTUgUWE1ODMwOA==
673 C: AUTH SKEY bW9yZ2Fu
674 S: DATA OTUgUWE1ODMwOA==
675 C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
683 <sect1 id="addresses">
684 <title>Server Addresses</title>
686 Server addresses consist of a transport name followed by a colon, and
687 then an optional, comma-separated list of keys and values in the form key=value.
688 [FIXME how do you escape colon, comma, and semicolon in the values of the key=value pairs?]
692 <programlisting>unix:path=/tmp/dbus-test</programlisting>
693 Which is the address to a unix socket with the path /tmp/dbus-test.
696 [FIXME clarify if attempting to connect to each is a requirement
697 or just a suggestion]
698 When connecting to a server, multiple server addresses can be
699 separated by a semi-colon. The library will then try to connect
700 to the first address and if that fails, it'll try to connect to
701 the next one specified, and so forth. For example
702 <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
705 [FIXME we need to specify in detail each transport and its possible arguments]
706 Currently, a transport over local UNIX sockets exists, a debug
707 transport that only works in-process and therefore can be used
708 for for unit testing also exists. It is possible that other
709 transports are added, such as a TCP/IP transport, and a
710 transport that works over X11.
714 <sect1 id="message-conventions">
715 <title>Message Conventions</title>
717 This section documents conventions that are not essential to D-BUS
718 functionality, but should generally be followed in order to simplify
721 <sect2 id="message-conventions-naming">
722 <title>Message Naming</title>
724 Messages are normally named in the form
725 "org.freedesktop.Peer.Ping", which has three
729 <term>Namespace e.g. <literal>org.freedesktop</literal></term>
732 Message names have a Java-style namespace: a reversed domain
733 name. The components of the domain are normally lowercase.
738 <term>Package or object e.g. <literal>Peer</literal></term>
741 The next part of the message name can be thought of as the name
742 of a singleton object, or as the name of a package of related
743 messages. More than one dot-separated component might be used
744 here. (Note that D-BUS does not define any idea of object
745 instances or object references.) The package or object name is
746 capitalized LikeThis.
751 <term>Method or operation e.g. <literal>Ping</literal></term>
754 The final part of the message name is the most specific, and
755 should be a verb indicating an operation to be performed on the
756 object. The method or operation name is capitalized LikeThis.
763 A reply to a message conventionally has the same name as the message
764 being replied to. When following method call conventions (see <xref
765 linkend="message-conventions-method">), this convention is mandatory,
766 because a message with multiple possible replies can't be mapped
767 to method call semantics without special-case code.
770 <sect2 id="message-conventions-method">
771 <title>Method Call Mapping</title>
773 Some implementations of D-BUS may present an API that translates object
774 method calls into D-BUS messages. This document does not specify in
775 detail how such an API should look or work. However, it does specify how
776 message-based protocols should be designed to be friendly to such an
780 Remember that D-BUS does not have object references or object instances.
781 So when one application sends the message
782 <literal>org.freedesktop.Peer.Ping</literal>, it sends it to another
783 application, not to any kind of sub-portion of that application.
784 However, a convenience API used within the recipient application may
785 route all messages that start with
786 <literal>org.freedesktop.Peer</literal> to a particular object instance,
787 and may invoke the <literal>Ping()</literal> method on said instance in
788 order to handle the message. This is a convenience API based on
792 A "method call" consists of a message and, optionally, a reply to that
793 message. The name of the "method" is the last component of the message,
794 for example, <literal>org.freedesktop.Peer.Ping</literal> would map to
795 the method <literal>Ping()</literal> on some object.
798 Arguments to a method may be considered "in" (processed by the
799 recipient of the message), or "out" (returned to the sender of the
800 message in the reply). "inout" arguments are both sent and received,
801 i.e. the caller passes in a value which is modified. An "inout" argument
802 is equivalent to an "in" argument, followed by an "out" argument.
805 Given a method with zero or one return values, followed by zero or more
806 arguments, where each argument may be "in", "out", or "inout", the
807 caller constructs a message by appending each "in" or "inout" argument,
808 in order. "out" arguments are not represented in the caller's message.
811 The recipient constructs a reply by appending first the return value
812 if any, then each "out" or "inout" argument, in order.
813 "in" arguments are not represented in the reply message.
816 The standard reply message MUST have the same name as the message being
817 replied to, and MUST set the "rply" header field to the serial
818 number of the message being replied to.
821 If an error occurs, an error reply may be sent in place of the
822 standard reply. Error replies can be identified by a special
823 header flag, see <xref linkend="message-protocol-header-encoding">.
824 Error replies have a name which reflects the type of
825 error that occurred. Error replies would generally
826 be mapped to exceptions in a programming language.
829 [FIXME discuss mapping of broadcast messages + matching rules
830 to signals and slots]
835 <sect1 id="standard-messages">
836 <title>Standard Peer-to-Peer Messages</title>
838 In the following message definitions, "method call notation" is presented
839 in addition to simply listing the message names and arguments. The special
840 type name ANY means any type other than NIL, and the special type name
841 ANY_OR_NIL means any valid type.
842 [FIXME the messages here are just made up to illustrate the
843 format for defining them]
845 <sect2 id="standard-messages-ping">
846 <title><literal>org.freedesktop.Peer.Ping</literal></title>
854 On receipt of the message <literal>org.freedesktop.Peer.Ping</literal>,
855 an application should reply with
856 <literal>org.freedesktop.Peer.Ping</literal>. Neither the
857 message nor its reply have any arguments.
858 [FIXME the messages here are just made up to illustrate the
859 format for defining them]
862 <sect2 id="standard-messages-get-props">
863 <title><literal>org.freedesktop.Props.Get</literal></title>
867 ANY_OR_NIL Get (in STRING property_name)
874 <entry>Argument</entry>
876 <entry>Description</entry>
882 <entry>STRING</entry>
883 <entry>Name of the property to get</entry>
893 <entry>Argument</entry>
895 <entry>Description</entry>
901 <entry>ANY_OR_NIL</entry>
902 <entry>The value of the property. The type depends on the property.</entry>
910 [FIXME the messages here are just made up to illustrate the
911 format for defining them]
916 <sect1 id="message-bus">
917 <title>Message Bus Specification</title>
918 <sect2 id="message-bus-overview">
919 <title>Message Bus Overview</title>
921 The message bus accepts connections from one or more applications.
922 Once connected, applications can send and receive messages from
923 the message bus, as in the peer-to-peer case.
926 The message bus keeps track of a set of
927 <firstterm>services</firstterm>. A service is simply a name, such
928 as <literal>com.yoyodyne.Screensaver</literal>, which can be
929 <firstterm>owned</firstterm> by one of the connected applications.
930 The message bus itself always owns the special service
931 <literal>org.freedesktop.DBus</literal>.
934 Messages may have a <literal>srvc</literal> field (see <xref
935 linkend="message-protocol-header-fields">). When the message bus
936 receives a message, if the <literal>srvc</literal> field is absent, the
937 message is taken to be a standard peer-to-peer message and interpreted
938 by the message bus itself. For example, sending
939 an <literal>org.freedesktop.Peer.Ping</literal> message with no
940 <literal>srvc</literal> will cause the message bus itself to reply
941 to the ping immediately; the message bus would never make
942 this message visible to other applications.
945 If the <literal>srvc</literal> field is present, then it indicates a
946 request for the message bus to route the message. In the usual case,
947 messages are routed to the owner of the named service.
948 Messages may also be <firstterm>broadcast</firstterm>
949 by sending them to the special service
950 <literal>org.freedesktop.Broadcast</literal>. Broadcast messages are
951 sent to all applications with <firstterm>message matching
952 rules</firstterm> that match the message.
955 Continuing the <literal>org.freedesktop.Peer.Ping</literal> example, if
956 the ping message were sent with a <literal>srvc</literal> name of
957 <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
958 forwarded, and the Yoyodyne Corporation screensaver application would be
959 expected to reply to the ping. If
960 <literal>org.freedesktop.Peer.Ping</literal> were sent to
961 <literal>org.freedesktop.Broadcast</literal>, then multiple applications
962 might receive the ping, and all would normally reply to it.
966 <sect2 id="message-bus-services">
967 <title>Message Bus Services</title>
969 A service is a name that identifies a certain application. Each
970 application connected to the message bus has at least one service name
971 assigned at connection time and returned in response to the
972 <literal>org.freedesktop.DBus.Hello</literal> message.
973 This automatically-assigned service name is called
974 the application's <firstterm>base service</firstterm>.
975 Base service names are unique and MUST never be reused for two different
979 [FIXME I think we should define the format of the base service name,
980 and specify that a regular service name can never be in that
981 format; this allows us to categorically prevent "spoofing" - for
982 example perhaps the base service name starts with a certain
983 character that no real service name can start with]
986 An application can request additional service names to be associated
988 <literal>org.freedesktop.DBus.AcquireService</literal>
989 message. [FIXME what service names are allowed; ASCII or unicode;
993 [FIXME this needs more detail, and should move the service-related message
994 descriptions up into this section perhaps]
995 Service ownership handling can be specified in the flags part
996 of the <literal>org.freedesktop.DBus.AcquireService</literal>
997 message. If an application specifies the
998 DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT flag, then all applications
999 trying to acquire the service will be put in a queue. When the
1000 primary owner disconnects from the bus or removes ownership
1001 from the service, the next application in the queue will be the
1002 primary owner. If the DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT
1003 flag is not specified, then the primary owner will lose
1004 ownership whenever another application requests ownership of the
1008 <sect2 id="message-bus-routing">
1009 <title>Message Bus Message Routing</title>
1011 When a message is received by the message bus, the message's
1012 <literal>sndr</literal> header field MUST be set to the base service of
1013 the application which sent the message. If the service already has
1014 a <literal>sndr</literal> field, the pre-existing field is replaced.
1015 This rule means that a replies are always sent to the base service name,
1016 i.e. to the same application that sent the message being replied to.
1019 [FIXME go into detail about broadcast, multicast, unicast, etc.]
1022 <sect2 id="message-bus-activation">
1023 <title>Message Bus Service Activation</title>
1025 <firstterm>Activation</firstterm> means to locate a service
1026 owner for a service that is currently unowned. For now, it
1027 means to launch an executable that will take ownership of
1028 a particular service.
1031 To find an executable corresponding to a particular service, the bus
1032 daemon looks for <firstterm>service description files</firstterm>.
1033 Service description files define a mapping from service names to
1034 executables. Different kinds of message bus will look for these files
1035 in different places, see <xref linkend="message-bus-types">.
1038 [FIXME the file format should be much better specified than
1039 "similar to .desktop entries" esp. since desktop entries
1040 are already badly-specified. ;-)]
1041 Service description files have the ".service" file
1042 extension. The message bus will only load service description
1043 files ending with .service; all other files will be ignored.
1044 The file format is similar to that of <ulink
1045 url="http://www.freedesktop.org/standards/desktop-entry-spec/desktop-entry-spec.html">desktop
1046 entries</ulink>. All service description files must be in
1050 <title>Example service description file</title>
1052 # Sample service description file
1054 Name=org.gnome.ConfigurationDatabase
1060 When an application requests a service to be activated, the bus
1061 daemon tries to find it in the list of activation entries. It
1062 then tries to spawn the executable associated with it. If this
1063 fails, it will report an error. [FIXME what happens if two
1064 .service files offer the same service; what kind of error is reported]
1067 The executable launched will have the environment variable
1068 <literal>DBUS_BUS_ADDRESS</literal> set to the address of the
1069 message bus so it can connect and register the appropriate services.
1073 <sect2 id="message-bus-types">
1074 <title>Standard Message Bus Instances</title>
1076 Two standard message bus instances are defined here, along with how
1077 to locate them and where their service files live.
1079 <sect3 id="message-bus-types-login">
1080 <title>Login session message bus</title>
1082 Each time a user logs in, a <firstterm>login session message
1083 bus</firstterm> may be started. All applications in the user's login
1084 session may interact with one another using this message bus. [specify
1085 how to find the address of the login session message bus via
1086 environment variable and/or X property]
1089 [FIXME specify location of .service files, probably using
1090 DESKTOP_DIRS etc. from basedir specification, though login session
1091 bus is not really desktop-specific]
1094 <sect3 id="message-bus-types-system">
1095 <title>System message bus</title>
1097 A computer may have a <firstterm>system message bus</firstterm>,
1098 accessible to all applications on the system. This message bus may be
1099 used to broadcast system events, such as adding new hardware devices.
1100 [specify how to find the address of the system message bus]
1103 [FIXME specify location of system bus .service files]
1108 <sect2 id="message-bus-messages">
1109 <title>Message Bus Messages</title>
1111 The special message bus service <literal>org.freedesktop.DBus</literal>
1112 responds to a number of messages, allowing applications to
1113 interact with the message bus.
1116 <sect3 id="bus-messages-hello">
1117 <title><literal>org.freedesktop.DBus.Hello</literal></title>
1128 <entry>Argument</entry>
1130 <entry>Description</entry>
1136 <entry>STRING</entry>
1137 <entry>Name of the service assigned to the application</entry>
1144 Before an application is able to send messages to other applications it
1145 must send the <literal>org.freedesktop.DBus.Hello</literal>
1146 message to the message bus service. If an application tries to send
1147 a message to another application, or a message to the message bus
1148 service that isn't the
1149 <literal>org.freedesktop.DBus.Hello</literal> message, it will
1150 be disconnected from the bus.
1153 The reply message contains the name of the application's base service.
1156 <sect3 id="bus-messages-list-services">
1157 <title><literal>org.freedesktop.DBus.ListServices</literal></title>
1161 STRING_ARRAY ListServices ()
1168 <entry>Argument</entry>
1170 <entry>Description</entry>
1176 <entry>STRING_ARRAY</entry>
1177 <entry>Array of strings where each string is the name of a service</entry>
1184 Returns a list of all existing services registered with the message bus.
1187 <sect3 id="bus-messages-service-exists">
1188 <title><literal>org.freedesktop.DBus.ServiceExists</literal></title>
1192 UINT32 ServiceExists (in STRING service_name)
1199 <entry>Argument</entry>
1201 <entry>Description</entry>
1207 <entry>STRING</entry>
1208 <entry>Name of the service</entry>
1218 <entry>Argument</entry>
1220 <entry>Description</entry>
1226 <entry>UINT32</entry>
1227 <entry>Return value, 1 if the service exists and 0 otherwise</entry>
1234 Checks if a service with a specified name exists.
1238 <sect3 id="bus-messages-acquire-service">
1239 <title><literal>org.freedesktop.DBus.AcquireService</literal></title>
1243 UINT32 AcquireService (in STRING service_name)
1250 <entry>Argument</entry>
1252 <entry>Description</entry>
1258 <entry>STRING</entry>
1259 <entry>Name of the service</entry>
1263 <entry>UINT32</entry>
1264 <entry>Flags</entry>
1274 <entry>Argument</entry>
1276 <entry>Description</entry>
1282 <entry>UINT32</entry>
1283 <entry>Return value</entry>
1290 Tries to become owner of a specific service. The flags
1291 specified can be the following values logically ORed together:
1297 <entry>Identifier</entry>
1298 <entry>Value</entry>
1299 <entry>Description</entry>
1304 <entry>DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT</entry>
1307 If the application succeeds in being the owner of the specified service,
1308 then ownership of the service can't be transferred until the service
1309 disconnects. If this flag is not set, then any application trying to become
1310 the owner of the service will succeed and the previous owner will be
1311 sent a <literal>org.freedesktop.DBus.ServiceLost</literal> message.
1315 <entry>DBUS_SERVICE_FLAGS_REPLACE_EXISTING</entry>
1317 <entry>Only become the owner of the service if there is no current owner.</entry>
1323 [FIXME if it's one of the following values, why are the values
1324 done as flags instead of just 0, 1, 2, 3, 4]
1325 The return value can be one of the following values:
1331 <entry>Identifier</entry>
1332 <entry>Value</entry>
1333 <entry>Description</entry>
1338 <entry>DBUS_SERVICE_REPLY_PRIMARY_OWNER</entry>
1340 <entry>The application is now the primary owner of the service.</entry>
1343 <entry>DBUS_SERVICE_REPLY_IN_QUEUE</entry>
1345 <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>
1348 <entry>DBUS_SERVICE_REPLY_SERVICE_EXISTS</entry>
1350 <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>
1353 <entry>DBUS_SERVICE_REPLY_ALREADY_OWNER</entry>
1355 <entry>The application trying to request ownership of the service is already the owner of it.</entry>
1362 <sect3 id="bus-messages-service-acquired">
1363 <title><literal>org.freedesktop.DBus.ServiceAcquired</literal></title>
1367 ServiceAcquired (in STRING service_name)
1374 <entry>Argument</entry>
1376 <entry>Description</entry>
1382 <entry>STRING</entry>
1383 <entry>Name of the service</entry>
1387 <entry>UINT32</entry>
1388 <entry>Flags</entry>
1395 This message is sent to a specific application when it becomes the
1396 primary owner of a service.
1399 <sect3 id="bus-messages-service-lost">
1400 <title><literal>org.freedesktop.DBus.ServiceLost</literal></title>
1404 ServiceLost (in STRING service_name)
1411 <entry>Argument</entry>
1413 <entry>Description</entry>
1419 <entry>STRING</entry>
1420 <entry>Name of the service</entry>
1424 <entry>UINT32</entry>
1425 <entry>Flags</entry>
1432 This message is sent to a specific application when it loses primary
1433 ownership of a service.
1435 [FIXME instead of ServiceLost/ServiceCreated going only to
1436 a specific app, why not just OwnerChanged that covers both
1437 lost and created and changed owner and deleted]
1441 <sect3 id="bus-messages-service-created">
1442 <title><literal>org.freedesktop.DBus.ServiceCreated</literal></title>
1446 ServiceCreated (in STRING service_name)
1453 <entry>Argument</entry>
1455 <entry>Description</entry>
1461 <entry>STRING</entry>
1462 <entry>Name of the service</entry>
1466 <entry>UINT32</entry>
1467 <entry>Flags</entry>
1474 This message is broadcast to all applications when a service has been
1475 successfully registered on the message bus.
1479 <sect3 id="bus-messages-service-deleted">
1480 <title><literal>org.freedesktop.DBus.ServiceDeleted</literal></title>
1484 ServiceDeleted (in STRING service_name)
1491 <entry>Argument</entry>
1493 <entry>Description</entry>
1499 <entry>STRING</entry>
1500 <entry>Name of the service</entry>
1504 <entry>UINT32</entry>
1505 <entry>Flags</entry>
1512 This message is broadcast to all applications when a service has been
1513 deleted from the message bus.
1517 <sect3 id="bus-messages-activate-service">
1518 <title><literal>org.freedesktop.DBus.ActivateService</literal></title>
1522 void ActivateService (in STRING service_name, in UINT32 flags)
1529 <entry>Argument</entry>
1531 <entry>Description</entry>
1537 <entry>STRING</entry>
1538 <entry>Name of the service to activate</entry>
1542 <entry>UINT32</entry>
1543 <entry>Flags (currently not used)</entry>
1550 Tries to launch the executable associated with a service. For more information, see <xref linkend="message-bus-activation">.
1552 [FIXME need semantics in much more detail here; for example,
1553 if I activate a service then send it a message, is the message
1554 queued for the new service or is there a race]
1561 <appendix id="implementation-notes">
1562 <title>Implementation notes</title>
1563 <sect1 id="implementation-notes-subsection">
1571 <glossary><title>Glossary</title>
1573 This glossary defines some of the terms used in this specification.
1576 <glossentry id="term-activation"><glossterm>Activation</glossterm>
1579 The process of creating an owner for a particular service,
1580 typically by launching an executable.
1585 <glossentry id="term-base-service"><glossterm>Base Service</glossterm>
1588 The special service automatically assigned to an application by the
1589 message bus. This service may never change owner, and the service
1590 name will be unique (never reused during the lifetime of the
1596 <glossentry id="term-broadcast"><glossterm>Broadcast</glossterm>
1599 A message sent to the special <literal>org.freedesktop.Broadcast</literal>
1600 service; the message bus will forward the broadcast message
1601 to all applications that have expressed interest in it.
1606 <glossentry id="term-message"><glossterm>Message</glossterm>
1609 A message is the atomic unit of communication via the D-BUS
1610 protocol. It consists of a <firstterm>header</firstterm> and a
1611 <firstterm>body</firstterm>; the body is made up of
1612 <firstterm>arguments</firstterm>.
1617 <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
1620 The message bus is a special application that forwards
1621 or broadcasts messages between a group of applications
1622 connected to the message bus. It also manages
1623 <firstterm>services</firstterm>.
1628 <glossentry id="term-service"><glossterm>Service</glossterm>
1631 A service is simply a named application that other
1632 applications can refer to. For example, the
1633 hypothetical <literal>com.yoyodyne.Screensaver</literal>
1634 service might accept messages that affect
1635 a screensaver from Yoyodyne Corporation.
1636 An application is said to <firstterm>own</firstterm>
1637 a service if the message bus has associated the
1638 application with the service name.
1643 <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
1646 ".service files" tell the bus how to activate a particular service.
1647 See <xref linkend="term-activation">