2003-04-16 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / doc / dbus-specification.sgml
1 <!doctype article PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
2 ]>
3 <article id="index">
4   <artheader>
5     <title>D-BUS Specification</title>
6     <releaseinfo>Version 0.7</releaseinfo>
7     <date>26 March 2003</date>
8     <authorgroup>
9       <author>
10         <firstname>Havoc</firstname>
11         <surname>Pennington</surname>
12         <affiliation>
13           <orgname>Red Hat, Inc</orgname>
14           <address>
15             <email>hp@pobox.com</email>
16           </address>
17         </affiliation>
18       </author>
19       <author>
20         <firstname>Anders</firstname>
21         <surname>Carlsson</surname>
22         <affiliation>
23           <orgname>CodeFactory AB</orgname>
24           <address>
25             <email>andersca@codefactory.se</email>
26           </address>
27         </affiliation>
28       </author>
29       <author>
30         <firstname>Alexander</firstname>
31         <surname>Larsson</surname>
32         <affiliation>
33           <orgname>Red Hat, Inc</orgname>
34           <address>
35             <email>alexl@redhat.com</email>
36           </address>
37         </affiliation>
38       </author>
39     </authorgroup>
40   </artheader>
41
42   <sect1 id="introduction">
43     <title>Introduction</title>
44     <para>
45       D-BUS is a system for low-latency, low-overhead, easy to use
46       interprocess communication (IPC). In more detail:
47       <itemizedlist>
48         <listitem>
49           <para>
50             D-BUS is <emphasis>low-latency</emphasis> because it is designed 
51             to avoid round trips and allow asynchronous operation, much like 
52             the X protocol.
53           </para>
54         </listitem>
55         <listitem>
56           <para>
57             D-BUS is <emphasis>low-overhead</emphasis> because it uses a
58             binary protocol, and does not have to convert to and from a text
59             format such as XML. Because D-BUS is intended for potentially
60             high-resolution same-machine IPC, not primarily for Internet IPC,
61             this is an interesting optimization.
62           </para>
63         </listitem>
64         <listitem>
65           <para>
66             D-BUS is <emphasis>easy to use</emphasis> because it works in terms
67             of <firstterm>messages</firstterm> rather than byte streams, and
68             does not require users to understand any complex concepts such as a
69             new type system or elaborate APIs. Libraries implementing D-BUS 
70             may choose to abstract messages as "method calls" (see 
71             <xref linkend="message-conventions-method">).
72           </para>
73         </listitem>
74       </itemizedlist>
75     </para>
76     <para>
77       The base D-BUS protocol is a peer-to-peer protocol, specified in <xref
78       linkend="message-protocol">. That is, it is a system for one application
79       to talk to a single other application. However, the primary intended
80       application of D-BUS is the D-BUS <firstterm>message bus</firstterm>,
81       specified in <xref linkend="message-bus">. The message bus is a special
82       application that accepts connections from multiple other applications, and
83       forwards messages among them.
84     </para>
85     <para>
86       Things that D-BUS can be used for is for example notification of
87       system changes (notification of when a camera is plugged in to a
88       computer, or a new version of some software has been installed),
89       or desktop interoperablity, for example a file monitoring
90       service or a configuration service.
91     </para>
92   </sect1>
93
94   <sect1 id="message-protocol">
95     <title>Message Protocol</title>
96     <para>
97       A <firstterm>message</firstterm> consists of a
98       <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
99       think of a message as a package, the header is the address, and the body
100       contains the package contents. The message delivery system uses the header
101       information to figure out where to send the message and how to interpret
102       it; the recipient inteprets the body of the message.
103     </para>
104     
105     <para>
106       The body of the message is made up of zero or more
107       <firstterm>arguments</firstterm>, which are typed 
108       values, such as an integer or a byte array.
109     </para>
110
111     <sect2 id="message-protocol-header-encoding">
112       <title>Header Encoding</title>
113       <para>
114         Following the mandatory fields, there are zero or more named fields (see
115         <xref linkend="message-protocol-header-fields">), and then nul bytes
116         padding the header such that its total length in bytes is a multiple of
117         8.
118       </para>
119       <para>
120         The header MUST begin with the following mandatory fields in the following
121         order:
122         <informaltable>
123           <tgroup cols=2>
124             <thead>
125               <row>
126                 <entry>Size</entry>
127                 <entry>Description</entry>
128               </row>
129             </thead>
130             <tbody>
131               <row>
132                 <entry>1 byte</entry>
133                 <entry>Endianness flag; ASCII 'l' for little-endian 
134                   or ASCII 'B' for big-endian.</entry>
135               </row>
136               <row>
137                 <entry>1 byte</entry>
138                 <entry>Bitwise OR of flags. Unknown flags
139                   MUST be ignored. Currently-defined flags are described below.
140                 </entry>
141               </row>
142               <row>
143                 <entry>1 byte</entry>
144                 <entry>Major protocol version of the sending application.  If
145                 the major protocol version of the receiving application does not
146                 match, the applications will not be able to communicate and the
147                 D-BUS connection MUST be disconnected. The major protocol
148                 version for this version of the specification is 0.
149                 </entry>
150               </row>
151               <row>
152                 <entry>1 byte</entry>
153                 <entry>A nul byte, reserved for future use.
154                   Any value for this byte MUST be accepted.
155                 </entry>
156               </row>
157               <row>
158                 <entry>4 bytes</entry>
159                 <entry>An unsigned 32-bit integer in the
160                   message's byte order, indicating the total length in bytes of
161                   the header including named fields and any alignment padding.
162                   MUST be a multiple of 8.
163                 </entry>
164               </row>
165               <row>
166                 <entry>4 bytes</entry>
167                 <entry>An unsigned 32-bit integer in the
168                   message's byte order, indicating the total length in bytes of
169                   the message body.
170                 </entry>
171               </row>      
172               <row>
173                 <entry>4 bytes</entry>
174                 <entry>The message's serial number, an unsigned 32-bit integer in
175                   the message's byte order. Applications MUST NOT reuse the same
176                   serial number for different messages more often than 32-bit
177                   unsigned integer wraparound. Zero is not a valid serial number.
178                 </entry>
179               </row>
180             </tbody>
181           </tgroup>
182         </informaltable>
183       </para>
184       <para>
185         Flags that can appear in the second byte of the header:
186         <informaltable>
187           <tgroup cols=2>
188             <thead>
189               <row>
190                 <entry>Hex value</entry>
191                 <entry>Description</entry>
192               </row>
193             </thead>
194             <tbody>
195               <row>
196                 <entry>0x1</entry>
197                 <entry>This message is an error reply. If the first argument exists and is a string, it is an error message.</entry>
198               </row>
199             </tbody>
200           </tgroup>
201         </informaltable>
202       </para>
203     </sect2>
204
205     <sect2 id="message-protocol-header-fields">
206       <title>Header Fields</title>
207       <para>
208         In addition to the required header information mentioned 
209         in <xref linkend="message-protocol-header-encoding">, 
210           the header may contain zero or more named 
211           header fields. These fields are named to allow 
212           future versions of this protocol specification to 
213           add new fields; implementations must ignore fields 
214           they do not understand. Implementations must not 
215           invent their own header fields; only changes to 
216           this specification may introduce new header fields.
217       </para>
218
219       <para>
220         Header field names MUST consist of 4 non-nul bytes.  The field name is
221         NOT nul terminated; it occupies exactly 4 bytes. Following the name, 
222         the field MUST have a type code, and then a properly-aligned value 
223         of that type. 
224         See <xref linkend="message-protocol-arguments"> for a description 
225           of how each type is encoded. If an implementation sees a header 
226           field name that it does not understand, it MUST ignore 
227           that field.
228       </para>
229
230       <para>
231         Here are the currently-defined named header fields:
232         <informaltable>
233           <tgroup cols=3>
234             <thead>
235               <row>
236                 <entry>Name</entry>
237                 <entry>Type</entry>
238                 <entry>Description</entry>
239               </row>
240             </thead>
241             <tbody>
242               <row>
243                 <entry>name</entry>
244                 <entry>STRING</entry>
245                 <entry>The name of the message, such as org.freedesktop.Peer.Ping</entry>
246               </row>
247               <row>
248                 <entry>rply</entry>
249                 <entry>UINT32</entry>
250                 <entry>The serial number of the message this message is a reply
251                 to. (The serial number is one of the mandatory header fields,
252                 see <xref linkend="message-protocol-header-encoding">.)</entry>
253               </row>
254               <row>
255                 <entry>srvc</entry>
256                 <entry>STRING</entry>
257                 <entry>The name of the service this message should be routed to. 
258                 Only used in combination with the message bus, see 
259                 <xref linkend="message-bus">.</entry>
260               </row>
261               <row>
262                 <entry>sndr</entry>
263                 <entry>STRING</entry>
264                 <entry>The name of the base service that sent this message. 
265                 The message bus fills in this field; the field is 
266                 only meaningful in combination with the message bus.</entry>
267               </row>
268             </tbody>
269           </tgroup>
270         </informaltable>
271       </para>
272       
273     </sect2>
274     <sect2 id="message-protocol-header-padding">
275       <title>Header Alignment Padding</title>
276       <para>
277         To allow implementations to keep the header and the body in a single
278         buffer while keeping data types aligned, the total length of the header
279         must be a multiple of 8 bytes.  To achieve this, the header MUST be padded
280         with nul bytes to align its total length on an 8-byte boundary. 
281         The minimum number of padding bytes MUST be used. Because all possible 
282         named fields use at least 8 bytes, implementations can distinguish 
283         padding (which must be less than 8 bytes) from additional named fields
284         (which must be at least 8 bytes).
285       </para>
286     </sect2>
287
288     <sect2 id="message-protocol-arguments">
289       <title>Message Arguments</title>
290       <para>
291         The message body is made up of arguments. Each argument
292         is a type code, followed by the value of the argument 
293         in a type-dependent format.
294       </para>
295       <para>
296         <informaltable>
297           <tgroup cols=3>
298             <thead>
299               <row>
300                 <entry>Type name</entry>
301                 <entry>Code</entry>
302                 <entry>Description</entry>
303               </row>
304             </thead>
305             <tbody>
306               <row>
307                 <entry>INVALID</entry>
308                 <entry>0</entry>
309                 <entry>Not a valid type code (error if it appears in a message)</entry>
310               </row><row>
311                 <entry>NIL</entry>
312                 <entry>1</entry>
313                 <entry>Marks an "unset" or "nonexistent" argument</entry>
314               </row><row>
315                 <entry>BYTE</entry>
316                 <entry>2</entry>
317                 <entry>8-bit unsigned integer</entry>
318               </row><row>
319                 <entry>BOOLEAN</entry>
320                 <entry>3</entry>
321                 <entry>Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.</entry>
322               </row><row>
323                 <entry>INT32</entry>
324                 <entry>4</entry>
325                 <entry>32-bit signed integer</entry>
326               </row><row>
327                 <entry>UINT32</entry>
328                 <entry>5</entry>
329                 <entry>32-bit unsigned integer</entry>
330               </row><row>
331                 <entry>DOUBLE</entry>
332                 <entry>6</entry>
333                 <entry>IEEE 754 double</entry>
334               </row><row>
335                 <entry>STRING</entry>
336                 <entry>7</entry>
337                 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be zero terminated. </entry>
338               </row><row>
339                 <entry>NAMED</entry>
340                 <entry>8</entry>
341                 <entry>A named byte array, used for custom types</entry>
342               </row><row>
343                 <entry>ARRAY</entry>
344                 <entry>9</entry>
345                 <entry>Array</entry>
346               </row><row>
347                 <entry>DICT</entry>
348                 <entry>10</entry>
349                 <entry>A dictionary of key/value pairs</entry>
350               </row>
351             </tbody>
352           </tgroup>
353         </informaltable>
354       </para>
355       <para>
356         The types are encoded as follows:
357         <informaltable>
358           <tgroup cols=2>
359             <thead>
360               <row>
361                 <entry>Type name</entry>
362                 <entry>Encoding</entry>
363               </row>
364             </thead>
365             <tbody>
366               <row>
367                 <entry>INVALID</entry>
368                 <entry>Not applicable; cannot be encoded.</entry>
369               </row><row>
370                 <entry>NIL</entry>
371                 <entry>No data is encoded; the type code is followed immediately 
372                 by the type code of the next argument.</entry>
373               </row><row>
374                 <entry>BYTE</entry>
375                 <entry>A byte.</entry>
376               </row><row>
377                 <entry>BOOLEAN</entry>
378                 <entry>A byte, with valid values 0 and 1.</entry>
379               </row><row>
380                 <entry>INT32</entry>
381                 <entry>32-bit signed integer in the message's byte order, aligned to 4-byte boundary.</entry>
382               </row><row>
383                 <entry>UINT32</entry>
384                 <entry>32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary.</entry>
385               </row><row>
386                 <entry>DOUBLE</entry>
387                 <entry>64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary.</entry>
388               </row><row>
389                 <entry>STRING</entry>
390                 <entry>UINT32 aligned to 4-byte boundary indicating the string's 
391                   length in bytes excluding its terminating nul, followed by 
392                   string data of the given length, followed by a terminating nul 
393                   byte.
394                 </entry>
395               </row><row>
396                 <entry>NAMED</entry>
397                 <entry>A string (encoded as the STRING type above) giving the
398                   name of the type followed by an UINT32 aligned to 4-byte boundary
399                   indicating the data length in bytes, followed by the data.
400                 </entry>
401               </row><row>
402                 <entry>ARRAY</entry>
403                 <entry>A sequence of bytes giving the element type of the array, terminated
404                 by a type different from ARRAY (just one byte for one-dimensional arrays, but
405                 larger for multi-dimensional arrays), followed by an UINT32 (aligned to 4 bytes)
406                 giving the length of the array data in bytes. This is followed by each array entry
407                 encoded the way it would normally be encoded, except arrays, which are encoded
408                 without the type information, since that is already declared above. Arrays containing
409                 NIL are not allowed.
410                 </entry>
411               </row><row>
412                 <entry>DICT</entry>
413                 <entry>UINT32 giving the length of the dictionary data in bytes.
414                 This is followed by a number of keyname/value pairs, where the
415                 keyname is encoded as a STRING above, and the value is encoded
416                 as a byte with typecode and how that type normally would be encoded
417                 alone.
418                 </entry>
419               </row>
420             </tbody>
421           </tgroup>
422         </informaltable>
423       </para>
424     </sect2>
425   </sect1>
426
427   <sect1 id="auth-protocol">
428     <title>Authentication Protocol</title>
429     <para>
430       Before the flow of messages begins, two applications must
431       authenticate. A simple plain-text protocol is used for
432       authentication; this protocol is a SASL profile, and maps fairly
433       directly from the SASL specification. The message encoding is
434       NOT used here, only plain text messages.
435     </para>
436     <para>
437       In examples, "C:" and "S:" indicate lines sent by the client and
438       server respectively.
439     </para>
440     <sect2 id="auth-protocol-overview">
441       <title>Protocol Overview</title>
442       <para>
443         The protocol is a line-based protocol, where each line ends with
444         \r\n. Each line begins with an all-caps ASCII command name containing
445         only the character range [A-Z], a space, then any arguments for the
446         command, then the \r\n ending the line. The protocol is
447         case-sensitive. All bytes must be in the ASCII character set.
448
449         Commands from the client to the server are as follows:
450
451         <itemizedlist>
452           <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
453           <listitem><para>CANCEL</para></listitem
454                                           <listitem><para>BEGIN</para></listitem>
455                                           <listitem><para>DATA &lt;data in base 64 encoding&gt;</para></listitem>
456                                           <listitem><para>ERROR [human-readable error explanation]</para></listitem>
457         </itemizedlist>
458
459         From server to client are as follows:
460
461         <itemizedlist>
462           <listitem><para>REJECTED &lt;space-separated list of mechanism names&gt;</para></listitem>
463           <listitem><para>OK</para></listitem>
464           <listitem><para>DATA &lt;data in base 64 encoding&gt;</para></listitem>
465           <listitem><para>ERROR</para></listitem>
466         </itemizedlist>
467       </para>
468     </sect2>
469     <sect2 id="auth-nul-byte">
470       <title>Special credentials-passing nul byte</title>
471       <para>
472         Immediately after connecting to the server, the client must send a
473         single nul byte. This byte may be accompanied by credentials
474         information on some operating systems that use sendmsg() with
475         SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
476         sockets. However, the nul byte MUST be sent even on other kinds of
477         socket, and even on operating systems that do not require a byte to be
478         sent in order to transmit credentials. The text protocol described in
479         this document begins after the single nul byte. If the first byte
480         received from the client is not a nul byte, the server may disconnect 
481         that client.
482       </para>
483       <para>
484         A nul byte in any context other than the initial byte is an error; 
485         the protocol is ASCII-only.
486       </para>
487       <para>
488         The credentials sent along with the nul byte may be used with the 
489         SASL mechanism EXTERNAL.
490       </para>
491     </sect2>
492     <sect2 id="auth-command-auth">
493       <title>AUTH command</title>
494       <para>
495         If an AUTH command has no arguments, it is a request to list
496         available mechanisms. The server SHOULD respond with a REJECTED
497         command listing the mechanisms it understands.
498       </para>
499       <para>
500         If an AUTH command specifies a mechanism, and the server supports
501         said mechanism, the server SHOULD begin exchanging SASL
502         challenge-response data with the client using DATA commands.
503       </para>
504       <para>
505         If the server does not support the mechanism given in the AUTH
506         command, it SHOULD send a REJECTED command listing the mechanisms
507         it does support.
508       </para>
509       <para>
510         If the [initial-response] argument is provided, it is intended for
511         use with mechanisms that have no initial challenge (or an empty
512         initial challenge), as if it were the argument to an initial DATA
513         command. If the selected mechanism has an initial challenge, the
514         server should reject authentication by sending REJECTED.
515       </para>
516       <para>
517         If authentication succeeds after exchanging DATA commands, 
518         an OK command should be sent to the client. 
519       </para>
520       <para>
521         The first octet received by the client after the \r\n of the OK
522         command MUST be the first octet of the authenticated/encrypted 
523         stream of D-BUS messages.
524       </para>
525       <para>
526         The first octet received by the server after the \r\n of the BEGIN
527         command from the client MUST be the first octet of the
528         authenticated/encrypted stream of D-BUS messages.
529       </para>
530     </sect2>
531     <sect2 id="auth-command-cancel">
532       <title>CANCEL Command</title>
533       <para>
534         At any time up to sending the BEGIN command, the client may send a
535         CANCEL command. On receiving the CANCEL command, the server MUST
536         send a REJECTED command and abort the current authentication
537         exchange.
538       </para>
539     </sect2>
540     <sect2 id="auth-command-data">
541       <title>DATA Command</title>
542       <para>
543         The DATA command may come from either client or server, and simply 
544         contains a base64-encoded block of data to be interpreted 
545         according to the SASL mechanism in use.
546       </para>
547       <para>
548         Some SASL mechanisms support sending an "empty string"; 
549         FIXME we need some way to do this.
550       </para>
551     </sect2>
552     <sect2 id="auth-command-begin">
553       <title>BEGIN Command</title>
554       <para>
555         The BEGIN command acknowledges that the client has received an 
556         OK command from the server, and that the stream of messages
557         is about to begin. 
558       </para>
559       <para>
560         The first octet received by the server after the \r\n of the BEGIN
561         command from the client MUST be the first octet of the
562         authenticated/encrypted stream of D-BUS messages.
563       </para>
564     </sect2>
565     <sect2 id="auth-command-rejected">
566       <title>REJECTED Command</title>
567       <para>
568         The REJECTED command indicates that the current authentication
569         exchange has failed, and further exchange of DATA is inappropriate.
570         The client would normally try another mechanism, or try providing
571         different responses to challenges.
572       </para><para>
573         Optionally, the REJECTED command has a space-separated list of
574         available auth mechanisms as arguments. If a server ever provides
575         a list of supported mechanisms, it MUST provide the same list 
576         each time it sends a REJECTED message. Clients are free to 
577         ignore all lists received after the first.
578       </para>
579     </sect2>
580     <sect2 id="auth-command-ok">
581       <title>OK Command</title>
582       <para>
583         The OK command indicates that the client has been authenticated,
584         and that further communication will be a stream of D-BUS messages
585         (optionally encrypted, as negotiated) rather than this protocol.
586       </para>
587       <para>
588         The first octet received by the client after the \r\n of the OK
589         command MUST be the first octet of the authenticated/encrypted 
590         stream of D-BUS messages.
591       </para>
592       <para>
593         The client MUST respond to the OK command by sending a BEGIN
594         command, followed by its stream of messages, or by disconnecting.
595         The server MUST NOT accept additional commands using this protocol 
596         after the OK command has been sent.
597       </para>
598     </sect2>
599     <sect2 id="auth-command-error">
600       <title>ERROR Command</title>
601       <para>
602         The ERROR command indicates that either server or client did not
603         know a command, does not accept the given command in the current
604         context, or did not understand the arguments to the command. This
605         allows the protocol to be extended; a client or server can send a
606         command present or permitted only in new protocol versions, and if
607         an ERROR is received instead of an appropriate response, fall back
608         to using some other technique.
609       </para><para>
610         If an ERROR is sent, the server or client MUST continue as if the
611         command causing the ERROR had never been received.
612       </para>
613     </sect2>
614     <sect2 id="auth-examples">
615       <title>Authentication examples</title>
616       
617       <para>
618         <figure>
619           <title>Example of successful magic cookie authentication</title>
620           <programlisting>
621             (MAGIC_COOKIE is a made up mechanism)
622
623             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
624             S: OK
625             C: BEGIN
626           </programlisting>
627         </figure>
628         <figure>
629           <title>Example of finding out mechanisms then picking one</title>
630           <programlisting>
631             C: AUTH
632             S: REJECTED KERBEROS_V4 SKEY
633             C: AUTH SKEY bW9yZ2Fu
634             S: DATA OTUgUWE1ODMwOA==
635             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
636             S: OK
637             C: BEGIN
638           </programlisting>
639         </figure>
640         <figure>
641           <title>Example of client sends unknown command then falls back to regular auth</title>
642           <programlisting>
643             C: FOOBAR
644             S: ERROR
645             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
646             S: OK
647             C: BEGIN
648           </programlisting>
649         </figure>
650         <figure>
651           <title>Example of server doesn't support initial auth mechanism</title>
652           <programlisting>
653             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
654             S: REJECTED KERBEROS_V4 SKEY
655             C: AUTH SKEY bW9yZ2Fu
656             S: DATA OTUgUWE1ODMwOA==
657             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
658             S: OK
659             C: BEGIN
660           </programlisting>
661         </figure>
662         <figure>
663           <title>Example of wrong password or the like followed by successful retry</title>
664           <programlisting>
665             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
666             S: REJECTED KERBEROS_V4 SKEY
667             C: AUTH SKEY bW9yZ2Fu
668             S: DATA OTUgUWE1ODMwOA==
669             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
670             S: REJECTED
671             C: AUTH SKEY bW9yZ2Fu
672             S: DATA OTUgUWE1ODMwOA==
673             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
674             S: OK
675             C: BEGIN
676           </programlisting>
677         </figure>
678         <figure>
679           <title>Example of skey cancelled and restarted</title>
680           <programlisting>
681             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
682             S: REJECTED KERBEROS_V4 SKEY
683             C: AUTH SKEY bW9yZ2Fu
684             S: DATA OTUgUWE1ODMwOA==
685             C: CANCEL
686             S: REJECTED
687             C: AUTH SKEY bW9yZ2Fu
688             S: DATA OTUgUWE1ODMwOA==
689             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
690             S: OK
691             C: BEGIN
692           </programlisting>
693         </figure>
694       </para>
695     </sect2>
696     <sect2 id="auth-mechanisms">
697       <title>Authentication mechanisms</title>
698       <para>
699         This section describes some new authentication mechanisms.
700         D-BUS also allows any standard SASL mechanism of course.
701       </para>
702       <sect3 id="auth-mechanisms-sha">
703         <title>DBUS_COOKIE_SHA1</title>
704         <para>
705           The DBUS_COOKIE_SHA1 mechanism is designed to establish that a client
706           has the ability to read a private file owned by the user being
707           authenticated. If the client can prove that it has access to a secret
708           cookie stored in this file, then the client is authenticated. 
709           Thus the security of DBUS_COOKIE_SHA1 depends on a secure home 
710           directory.
711         </para>
712         <para>
713           Authentication proceeds as follows:
714           <itemizedlist>
715             <listitem>
716               <para>
717                 The client sends the username it would like to authenticate 
718                 as.
719               </para>
720             </listitem>
721             <listitem>
722               <para>
723                 The server sends the name of its "cookie context" (see below); a
724                 space character; the integer ID of the secret cookie the client
725                 must demonstrate knowledge of; a space character; then a
726                 hex-encoded randomly-generated challenge string.
727               </para>
728             </listitem>
729             <listitem>
730               <para>
731                 The client locates the cookie, and generates its own hex-encoded
732                 randomly-generated challenge string.  The client then
733                 concatentates the server's hex-encoded challenge, a ":"
734                 character, its own hex-encoded challenge, another ":" character,
735                 and the hex-encoded cookie.  It computes the SHA-1 hash of this
736                 composite string.  It sends back to the server the client's
737                 hex-encoded challenge string, a space character, and the SHA-1
738                 hash.
739               </para>
740             </listitem>
741             <listitem>
742               <para>
743                 The server generates the same concatenated string used by the
744                 client and computes its SHA-1 hash. It compares the hash with
745                 the hash received from the client; if the two hashes match, the
746                 client is authenticated.
747               </para>
748             </listitem>
749           </itemizedlist>
750         </para>
751         <para>
752           Each server has a "cookie context," which is a name that identifies a
753           set of cookies that apply to that server. A sample context might be
754           "org_freedesktop_session_bus". Context names must be valid ASCII,
755           nonzero length, and may not contain the characters slash ("/"),
756           backslash ("\"), space (" "), newline ("\n"), carriage return ("\r"),
757           tab ("\t"), or period ("."). There is a default context,
758           "org_freedesktop_global" that's used by servers that do not specify
759           otherwise.
760         </para>
761         <para>
762           Cookies are stored in a user's home directory, in the directory
763           <filename>~/.dbus-keyrings/</filename>. This directory must 
764           not be readable or writable by other users. If it is, 
765           clients and servers must ignore it. The directory 
766           contains cookie files named after the cookie context.
767         </para>
768         <para>
769           A cookie file contains one cookie per line. Each line 
770           has three space-separated fields:
771           <itemizedlist>
772             <listitem>
773               <para>
774                 The cookie ID number, which must be a non-negative integer and
775                 may not be used twice in the same file.
776               </para>
777             </listitem>
778             <listitem>
779               <para>
780                 The cookie's creation time, in UNIX seconds-since-the-epoch
781                 format.
782               </para>
783             </listitem>
784             <listitem>
785               <para>
786                 The cookie itself, a hex-encoded random block of bytes.
787               </para>
788             </listitem>
789           </itemizedlist>
790         </para>
791         <para>
792           Only server processes modify the cookie file. 
793           They must do so with this procedure:
794           <itemizedlist>
795             <listitem>
796               <para>
797                 Create a lockfile name by appending ".lock" to the name of the
798                 cookie file.  The server should attempt to create this file
799                 using <literal>O_CREAT | O_EXCL</literal>.  If file creation
800                 fails, the lock fails. Servers should retry for a reasonable
801                 period of time, then they may choose to delete an existing lock
802                 to keep users from having to manually delete a stale
803                 lock. <footnote><para>Lockfiles are used instead of real file
804                 locking <literal>fcntl()</literal> because real locking
805                 implementations are still flaky on network
806                 filesystems.</para></footnote>
807               </para>
808             </listitem>
809             <listitem>
810               <para>
811                 Once the lockfile has been created, the server loads the cookie
812                 file. It should then delete any cookies that are old (the
813                 timeout can be fairly short), or more than a reasonable
814                 time in the future (so that cookies never accidentally 
815                 become permanent, if the clock was set far into the future 
816                 at some point). If no recent keys remain, the 
817                 server may generate a new key.
818               </para>
819             </listitem>
820             <listitem>
821               <para>
822                 The pruned and possibly added-to cookie file 
823                 must be resaved atomically (using a temporary 
824                 file which is rename()'d).
825               </para>
826             </listitem>
827             <listitem>
828               <para>
829                 The lock must be dropped by deleting the lockfile.
830               </para>
831             </listitem>
832           </itemizedlist>
833         </para>
834         <para>
835           Clients need not lock the file in order to load it, 
836           because servers are required to save the file atomically.          
837         </para>
838       </sect3>
839     </sect2>
840   </sect1>
841   <sect1 id="addresses">
842     <title>Server Addresses</title>
843     <para>
844       Server addresses consist of a transport name followed by a colon, and
845       then an optional, comma-separated list of keys and values in the form key=value.
846       [FIXME how do you escape colon, comma, and semicolon in the values of the key=value pairs?]
847     </para>
848     <para>
849       For example: 
850       <programlisting>unix:path=/tmp/dbus-test</programlisting>
851       Which is the address to a unix socket with the path /tmp/dbus-test.
852     </para>
853     <para>
854       [FIXME clarify if attempting to connect to each is a requirement 
855       or just a suggestion]
856       When connecting to a server, multiple server addresses can be
857       separated by a semi-colon. The library will then try to connect
858       to the first address and if that fails, it'll try to connect to
859       the next one specified, and so forth. For example
860       <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
861     </para>
862     <para>
863       [FIXME we need to specify in detail each transport and its possible arguments]
864       Currently, a transport over local UNIX sockets exists, a debug
865       transport that only works in-process and therefore can be used
866       for for unit testing also exists. It is possible that other
867       transports are added, such as a TCP/IP transport, and a
868       transport that works over X11.
869     </para>
870   </sect1>
871
872   <sect1 id="message-conventions">
873     <title>Message Conventions</title>
874     <para>
875       This section documents conventions that are not essential to D-BUS
876       functionality, but should generally be followed in order to simplify
877       programmer's lives.
878     </para>
879     <sect2 id="message-conventions-naming">
880       <title>Message Naming</title>
881       <para>
882         Messages are normally named in the form 
883         "org.freedesktop.Peer.Ping", which has three 
884         distinct components:
885         <variablelist>
886           <varlistentry>
887             <term>Namespace e.g. <literal>org.freedesktop</literal></term>
888             <listitem>
889               <para>
890                 Message names have a Java-style namespace: a reversed domain
891                 name. The components of the domain are normally lowercase.
892               </para>
893             </listitem>
894           </varlistentry>
895           <varlistentry>
896             <term>Package or object e.g. <literal>Peer</literal></term>
897             <listitem>
898               <para>
899                 The next part of the message name can be thought of as the name
900                 of a singleton object, or as the name of a package of related
901                 messages.  More than one dot-separated component might be used
902                 here. (Note that D-BUS does not define any idea of object
903                 instances or object references.)  The package or object name is
904                 capitalized LikeThis.
905               </para>
906             </listitem>
907           </varlistentry>
908           <varlistentry>
909             <term>Method or operation e.g. <literal>Ping</literal></term>
910             <listitem>
911               <para>
912                 The final part of the message name is the most specific, and
913                 should be a verb indicating an operation to be performed on the
914                 object.  The method or operation name is capitalized LikeThis.
915               </para>
916             </listitem>
917           </varlistentry>
918         </variablelist>
919       </para>
920       <para>
921         A reply to a message conventionally has the same name as the message
922         being replied to. When following method call conventions (see <xref
923                                                                          linkend="message-conventions-method">), this convention is mandatory, 
924           because a message with multiple possible replies can't be mapped
925           to method call semantics without special-case code.
926       </para>
927     </sect2>
928     <sect2 id="message-conventions-method">
929       <title>Method Call Mapping</title>
930       <para>
931         Some implementations of D-BUS may present an API that translates object
932         method calls into D-BUS messages. This document does not specify in
933         detail how such an API should look or work. However, it does specify how
934         message-based protocols should be designed to be friendly to such an
935         API.
936       </para>
937       <para>
938         Remember that D-BUS does not have object references or object instances.
939         So when one application sends the message
940         <literal>org.freedesktop.Peer.Ping</literal>, it sends it to another
941         application, not to any kind of sub-portion of that application.
942         However, a convenience API used within the recipient application may
943         route all messages that start with
944         <literal>org.freedesktop.Peer</literal> to a particular object instance,
945         and may invoke the <literal>Ping()</literal> method on said instance in
946         order to handle the message. This is a convenience API based on 
947         method calls.
948       </para>
949       <para>
950         A "method call" consists of a message and, optionally, a reply to that
951         message. The name of the "method" is the last component of the message,
952         for example, <literal>org.freedesktop.Peer.Ping</literal> would map to
953         the method <literal>Ping()</literal> on some object.
954       </para>
955       <para>
956         Arguments to a method may be considered "in" (processed by the
957         recipient of the message), or "out" (returned to the sender of the
958         message in the reply). "inout" arguments are both sent and received,
959         i.e. the caller passes in a value which is modified. An "inout" argument 
960         is equivalent to an "in" argument, followed by an "out" argument.
961       </para>
962       <para>
963         Given a method with zero or one return values, followed by zero or more
964         arguments, where each argument may be "in", "out", or "inout", the
965         caller constructs a message by appending each "in" or "inout" argument,
966         in order. "out" arguments are not represented in the caller's message.
967       </para>
968       <para>
969         The recipient constructs a reply by appending first the return value 
970         if any, then each "out" or "inout" argument, in order. 
971         "in" arguments are not represented in the reply message.
972       </para>
973       <para>
974         The standard reply message MUST have the same name as the message being 
975         replied to, and MUST set the "rply" header field to the serial 
976         number of the message being replied to.
977       </para>
978       <para>
979         If an error occurs, an error reply may be sent in place of the standard
980         reply. Error replies can be identified by a special header flag, see
981         <xref linkend="message-protocol-header-encoding">.  Error replies have a
982         name which reflects the type of error that occurred. Error replies would
983         generally be mapped to exceptions in a programming language.  If an
984         error reply has a first argument, and that argument has type STRING,
985         then the argument must be an error message.
986       </para>
987       <para>
988         [FIXME discuss mapping of broadcast messages + matching rules 
989         to signals and slots]
990       </para>
991     </sect2>
992   </sect1>
993
994   <sect1 id="standard-messages">
995     <title>Standard Peer-to-Peer Messages</title>
996     <para>
997       In the following message definitions, "method call notation" is presented
998       in addition to simply listing the message names and arguments. The special
999       type name ANY means any type other than NIL, and the special type name
1000       ANY_OR_NIL means any valid type.
1001       [FIXME the messages here are just made up to illustrate the 
1002       format for defining them]
1003     </para>
1004     <sect2 id="standard-messages-ping">
1005       <title><literal>org.freedesktop.Peer.Ping</literal></title>
1006       <para>        
1007         As a method:
1008         <programlisting>
1009           void Ping ()
1010         </programlisting>
1011       </para>
1012       <para>
1013         On receipt of the message <literal>org.freedesktop.Peer.Ping</literal>,
1014         an application should reply with
1015         <literal>org.freedesktop.Peer.Ping</literal>. Neither the 
1016         message nor its reply have any arguments.
1017         [FIXME the messages here are just made up to illustrate the 
1018         format for defining them]
1019       </para>
1020     </sect2>
1021     <sect2 id="standard-messages-get-props">
1022       <title><literal>org.freedesktop.Props.Get</literal></title>
1023       <para>
1024         As a method:
1025         <programlisting>
1026           ANY_OR_NIL Get (in STRING property_name)
1027         </programlisting>
1028         Message arguments:
1029         <informaltable>
1030           <tgroup cols=3>
1031             <thead>
1032               <row>
1033                 <entry>Argument</entry>
1034                 <entry>Type</entry>
1035                 <entry>Description</entry>
1036               </row>
1037             </thead>
1038             <tbody>
1039               <row>
1040                 <entry>0</entry>
1041                 <entry>STRING</entry>
1042                 <entry>Name of the property to get</entry>
1043               </row>
1044             </tbody>
1045           </tgroup>
1046         </informaltable>
1047         Reply arguments:
1048         <informaltable>
1049           <tgroup cols=3>
1050             <thead>
1051               <row>
1052                 <entry>Argument</entry>
1053                 <entry>Type</entry>
1054                 <entry>Description</entry>
1055               </row>
1056             </thead>
1057             <tbody>
1058               <row>
1059                 <entry>0</entry>
1060                 <entry>ANY_OR_NIL</entry>
1061                 <entry>The value of the property. The type depends on the property.</entry>
1062               </row>
1063             </tbody>
1064           </tgroup>
1065         </informaltable>
1066       </para>
1067       <para>
1068         
1069         [FIXME the messages here are just made up to illustrate the 
1070         format for defining them]
1071       </para>
1072     </sect2>
1073   </sect1>
1074
1075   <sect1 id="message-bus">
1076     <title>Message Bus Specification</title>
1077     <sect2 id="message-bus-overview">
1078       <title>Message Bus Overview</title>
1079       <para>
1080         The message bus accepts connections from one or more applications. 
1081         Once connected, applications can send and receive messages from 
1082         the message bus, as in the peer-to-peer case.
1083       </para>
1084       <para>
1085         The message bus keeps track of a set of
1086         <firstterm>services</firstterm>. A service is simply a name, such as
1087         <literal>com.yoyodyne.Screensaver</literal>, which can be
1088         <firstterm>owned</firstterm> by one or more of the connected
1089         applications.  The message bus itself always owns the special service
1090         <literal>org.freedesktop.DBus</literal>.
1091       </para>
1092       <para>
1093         Services may have <firstterm>secondary owners</firstterm>. Secondary owners
1094         of a service are kept in a queue; if the primary owner of a service 
1095         disconnects, or releases the service, the next secondary owner becomes
1096         the new owner of the service.
1097       </para>
1098       <para>
1099         Messages may have a <literal>srvc</literal> field (see <xref
1100                                                                   linkend="message-protocol-header-fields">).  When the message bus
1101           receives a message, if the <literal>srvc</literal> field is absent, the
1102           message is taken to be a standard peer-to-peer message and interpreted
1103           by the message bus itself. For example, sending
1104           an <literal>org.freedesktop.Peer.Ping</literal> message with no 
1105           <literal>srvc</literal> will cause the message bus itself to reply 
1106           to the ping immediately; the message bus would never make 
1107           this message visible to other applications.
1108       </para>
1109       <para>
1110         If the <literal>srvc</literal> field is present, then it indicates a
1111         request for the message bus to route the message. In the usual case,
1112         messages are routed to the owner of the named service.
1113         Messages may also be <firstterm>broadcast</firstterm>
1114         by sending them to the special service 
1115         <literal>org.freedesktop.DBus.Broadcast</literal>. Broadcast messages are
1116         sent to all applications with <firstterm>message matching
1117           rules</firstterm> that match the message.
1118       </para>
1119       <para>
1120         Continuing the <literal>org.freedesktop.Peer.Ping</literal> example, if
1121         the ping message were sent with a <literal>srvc</literal> name of
1122         <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
1123         forwarded, and the Yoyodyne Corporation screensaver application would be
1124         expected to reply to the ping. If
1125         <literal>org.freedesktop.Peer.Ping</literal> were sent to
1126         <literal>org.freedesktop.DBus.Broadcast</literal>, then multiple applications
1127         might receive the ping, and all would normally reply to it.
1128       </para>
1129     </sect2>
1130
1131     <sect2 id="message-bus-services">
1132       <title>Message Bus Services</title>
1133       <para>
1134         A service is a name that identifies a certain application. Each
1135         application connected to the message bus has at least one service name
1136         assigned at connection time and returned in response to the
1137         <literal>org.freedesktop.DBus.Hello</literal> message.
1138         This automatically-assigned service name is called 
1139         the application's <firstterm>base service</firstterm>. 
1140         Base service names are unique and MUST never be reused for two different 
1141         applications.
1142       </para>
1143       <para>
1144         Ownership of the base service is a prerequisite for interaction with 
1145         the message bus. It logically follows that the base service is always 
1146         the first service that an application comes to own, and the last 
1147         service that it loses ownership of.
1148       </para>
1149       <para>
1150         Base service names must begin with the character ':' (ASCII colon
1151         character); service names that are not base service names must not begin
1152         with this character. (The bus must reject any attempt by an application
1153         to manually create a service name beginning with ':'.) This restriction
1154         categorically prevents "spoofing"; messages sent to a base service name
1155         will always go to a single application instance and that instance only.
1156       </para>
1157       <para>
1158         An application can request additional service names to be associated
1159         with it using the
1160         <literal>org.freedesktop.DBus.AcquireService</literal>
1161         message. [FIXME what service names are allowed; ASCII or unicode; 
1162         length limit; etc.]
1163       </para>
1164       <para>
1165         [FIXME this needs more detail, and should move the service-related message 
1166         descriptions up into this section perhaps]
1167         Service ownership handling can be specified in the flags part
1168         of the <literal>org.freedesktop.DBus.AcquireService</literal>
1169         message. If an application specifies the
1170         DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT flag, then all applications
1171         trying to acquire the service will be put in a queue. When the
1172         primary owner disconnects from the bus or removes ownership
1173         from the service, the next application in the queue will be the
1174         primary owner. If the DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT
1175         flag is not specified, then the primary owner will lose
1176         ownership whenever another application requests ownership of the
1177         service.
1178       </para>
1179       <para>
1180         When a client disconnects from the bus, all the services that
1181         the clients own are deleted, or in the case of a service that
1182         prohibits replacement, ownership is transferred to the next
1183         client in the queue, if any.
1184       </para>
1185     </sect2>
1186     <sect2 id="message-bus-routing">
1187       <title>Message Bus Message Routing</title>
1188       <para>
1189         When a message is received by the message bus, the message's 
1190         <literal>sndr</literal> header field MUST be set to the base service of
1191         the application which sent the message.  If the service already has
1192         a <literal>sndr</literal> field, the pre-existing field is replaced.
1193         This rule means that a replies are always sent to the base service name,
1194         i.e. to the same application that sent the message being replied to.
1195       </para>
1196       <para>
1197         [FIXME go into detail about broadcast, multicast, unicast, etc.]
1198       </para>
1199     </sect2>
1200     <sect2 id="message-bus-activation">
1201       <title>Message Bus Service Activation</title>
1202       <para>
1203         <firstterm>Activation</firstterm> means to locate a service 
1204         owner for a service that is currently unowned. For now, it 
1205         means to launch an executable that will take ownership of 
1206         a particular service.
1207       </para>
1208       <para>
1209         To find an executable corresponding to a particular service, the bus
1210         daemon looks for <firstterm>service description files</firstterm>.
1211         Service description files define a mapping from service names to
1212         executables. Different kinds of message bus will look for these files
1213         in different places, see <xref linkend="message-bus-types">.
1214       </para>
1215       <para>
1216         [FIXME the file format should be much better specified than
1217         "similar to .desktop entries" esp. since desktop entries are
1218         already badly-specified. ;-)] Service description files have
1219         the ".service" file extension. The message bus will only load
1220         service description files ending with .service; all other
1221         files will be ignored.  The file format is similar to that of
1222         <ulink
1223         url="http://www.freedesktop.org/standards/desktop-entry-spec/desktop-entry-spec.html">desktop
1224         entries</ulink>. All service description files must be in
1225         UTF-8 encoding. To ensure that there will be no name
1226         collisions, service files must be namespaced using the same
1227         mechanism as messages and service names.
1228
1229         <figure>
1230           <title>Example service description file</title>
1231           <programlisting>
1232             # Sample service description file
1233             [D-BUS Service]
1234             Name=org.gnome.ConfigurationDatabase
1235             Exec=/usr/libexec/gconfd-2
1236           </programlisting>
1237         </figure>
1238       </para>
1239       <para>
1240         When an application requests a service to be activated, the
1241         bus daemon tries to find it in the list of activation
1242         entries. It then tries to spawn the executable associated with
1243         it. If this fails, it will report an error. [FIXME what
1244         happens if two .service files offer the same service; what
1245         kind of error is reported, should we have a way for the client
1246         to choose one?]
1247       </para>
1248       <para>
1249         The executable launched will have the environment variable
1250         <literal>DBUS_ACTIVATION_ADDRESS</literal> set to the address of the
1251         message bus so it can connect and register the appropriate services.
1252       </para>
1253       <para>
1254         The executable being launched may want to know whether the message bus
1255         activating it is one of the well-known message buses (see <xref
1256         linkend="message-bus-types">). To facilitate this, the bus MUST also set
1257         the <literal>DBUS_ACTIVATION_BUS_TYPE</literal> environment variable if it is one
1258         of the well-known buses. The currently-defined values for this variable
1259         are <literal>system</literal> for the systemwide message bus,
1260         and <literal>session</literal> for the per-login-session message
1261         bus. The activated executable must still connect to the address given
1262         in <literal>DBUS_ACTIVATION_ADDRESS</literal>, but may assume that the
1263         resulting connection is to the well-known bus.
1264       </para>
1265       <para>
1266         [FIXME there should be a timeout somewhere, either specified
1267         in the .service file, by the client, or just a global value
1268         and if the client being activated fails to connect within that
1269         timeout, an error should be sent back.]
1270       </para>
1271     </sect2>
1272
1273     <sect2 id="message-bus-types">
1274       <title>Well-known Message Bus Instances</title>
1275       <para>
1276         Two standard message bus instances are defined here, along with how 
1277         to locate them and where their service files live.
1278       </para>
1279       <sect3 id="message-bus-types-login">
1280         <title>Login session message bus</title>
1281         <para>
1282           Each time a user logs in, a <firstterm>login session message
1283             bus</firstterm> may be started. All applications in the user's login
1284           session may interact with one another using this message bus.
1285         </para>
1286         <para>
1287           The address of the login session message bus is given 
1288           in the <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment 
1289           variable. If that variable is not set, applications may 
1290           also try to read the address from the X Window System root 
1291           window property <literal>_DBUS_SESSION_BUS_ADDRESS</literal>.
1292           The root window property must have type <literal>STRING</literal>.
1293           The environment variable should have precedence over the 
1294           root window property.
1295         </para>
1296         <para>
1297           [FIXME specify location of .service files, probably using 
1298           DESKTOP_DIRS etc. from basedir specification, though login session 
1299           bus is not really desktop-specific]
1300         </para>
1301       </sect3>
1302       <sect3 id="message-bus-types-system">
1303         <title>System message bus</title>
1304         <para>
1305           A computer may have a <firstterm>system message bus</firstterm>,
1306           accessible to all applications on the system. This message bus may be
1307           used to broadcast system events, such as adding new hardware devices, 
1308           changes in the printer queue, and so forth.
1309         </para>
1310         <para>
1311           The address of the login session message bus is given 
1312           in the <literal>DBUS_SYSTEM_BUS_ADDRESS</literal> environment 
1313           variable. If that variable is not set, applications should try 
1314           to connect to the well-known address
1315           <literal>unix:path=/var/run/dbus/system_bus_socket</literal>.
1316           <footnote>
1317             <para>
1318               The D-BUS reference implementation actually honors the 
1319               <literal>$(localstatedir)</literal> configure option 
1320               for this address, on both client and server side.
1321             </para>
1322           </footnote>
1323         </para>
1324         <para>
1325           [FIXME specify location of system bus .service files]
1326         </para>
1327       </sect3>
1328     </sect2>
1329
1330     <sect2 id="message-bus-messages">
1331       <title>Message Bus Messages</title>
1332       <para>
1333         The special message bus service <literal>org.freedesktop.DBus</literal>
1334         responds to a number of messages, allowing applications to 
1335         interact with the message bus.
1336       </para>
1337
1338       <sect3 id="bus-messages-hello">
1339         <title><literal>org.freedesktop.DBus.Hello</literal></title>
1340         <para>
1341           As a method:
1342           <programlisting>
1343             STRING Hello ()
1344           </programlisting>
1345           Reply arguments:
1346           <informaltable>
1347             <tgroup cols=3>
1348               <thead>
1349                 <row>
1350                   <entry>Argument</entry>
1351                   <entry>Type</entry>
1352                   <entry>Description</entry>
1353                 </row>
1354               </thead>
1355               <tbody>
1356                 <row>
1357                   <entry>0</entry>
1358                   <entry>STRING</entry>
1359                   <entry>Name of the service assigned to the application</entry>
1360                 </row>
1361               </tbody>
1362             </tgroup>
1363           </informaltable>
1364         </para>
1365         <para>
1366           Before an application is able to send messages to other
1367           applications it must send the
1368           <literal>org.freedesktop.DBus.Hello</literal> message to the
1369           message bus service. If an application tries to send a
1370           message to another application, or a message to the message
1371           bus service that isn't the
1372           <literal>org.freedesktop.DBus.Hello</literal> message, it
1373           will be disconnected from the bus. If a client wishes to
1374           disconnect from the bus, it just has to disconnect from the
1375           transport used. No de-registration message is necessary.
1376         </para>
1377         <para>
1378           The reply message contains the name of the application's base service.
1379         </para>
1380       </sect3>
1381       <sect3 id="bus-messages-list-services">
1382         <title><literal>org.freedesktop.DBus.ListServices</literal></title>
1383         <para>
1384           As a method:
1385           <programlisting>
1386             STRING_ARRAY ListServices ()
1387           </programlisting>
1388           Reply arguments:
1389           <informaltable>
1390             <tgroup cols=3>
1391               <thead>
1392                 <row>
1393                   <entry>Argument</entry>
1394                   <entry>Type</entry>
1395                   <entry>Description</entry>
1396                 </row>
1397               </thead>
1398               <tbody>
1399                 <row>
1400                   <entry>0</entry>
1401                   <entry>STRING_ARRAY</entry>
1402                   <entry>Array of strings where each string is the name of a service</entry>
1403                 </row>
1404               </tbody>
1405             </tgroup>
1406           </informaltable>
1407         </para>
1408         <para>
1409           Returns a list of all existing services registered with the message bus. 
1410         </para>
1411       </sect3>
1412       <sect3 id="bus-messages-service-exists">
1413         <title><literal>org.freedesktop.DBus.ServiceExists</literal></title>
1414         <para>
1415           As a method:
1416           <programlisting>
1417             BOOLEAN ServiceExists (in STRING service_name)
1418           </programlisting>
1419           Message arguments:
1420           <informaltable>
1421             <tgroup cols=3>
1422               <thead>
1423                 <row>
1424                   <entry>Argument</entry>
1425                   <entry>Type</entry>
1426                   <entry>Description</entry>
1427                 </row>
1428               </thead>
1429               <tbody>
1430                 <row>
1431                   <entry>0</entry>
1432                   <entry>STRING</entry>
1433                   <entry>Name of the service</entry>
1434                 </row>
1435               </tbody>
1436             </tgroup>
1437           </informaltable>
1438           Reply arguments:
1439           <informaltable>
1440             <tgroup cols=3>
1441               <thead>
1442                 <row>
1443                   <entry>Argument</entry>
1444                   <entry>Type</entry>
1445                   <entry>Description</entry>
1446                 </row>
1447               </thead>
1448               <tbody>
1449                 <row>
1450                   <entry>0</entry>
1451                   <entry>BOOLEAN</entry>
1452                   <entry>Return value, true if the service exists</entry>
1453                 </row>
1454               </tbody>
1455             </tgroup>
1456           </informaltable>
1457         </para>
1458         <para>
1459           Checks if a service with a specified name exists.
1460         </para>
1461       </sect3>
1462
1463       <sect3 id="bus-messages-acquire-service">
1464         <title><literal>org.freedesktop.DBus.AcquireService</literal></title>
1465         <para>
1466           As a method:
1467           <programlisting>
1468             UINT32 AcquireService (in STRING service_name)
1469           </programlisting>
1470           Message arguments:
1471           <informaltable>
1472             <tgroup cols=3>
1473               <thead>
1474                 <row>
1475                   <entry>Argument</entry>
1476                   <entry>Type</entry>
1477                   <entry>Description</entry>
1478                 </row>
1479               </thead>
1480               <tbody>
1481                 <row>
1482                   <entry>0</entry>
1483                   <entry>STRING</entry>
1484                   <entry>Name of the service</entry>
1485                 </row>
1486                 <row>
1487                   <entry>1</entry>
1488                   <entry>UINT32</entry>
1489                   <entry>Flags</entry>
1490                 </row>
1491               </tbody>
1492             </tgroup>
1493           </informaltable>
1494           Reply arguments:
1495           <informaltable>
1496             <tgroup cols=3>
1497               <thead>
1498                 <row>
1499                   <entry>Argument</entry>
1500                   <entry>Type</entry>
1501                   <entry>Description</entry>
1502                 </row>
1503               </thead>
1504               <tbody>
1505                 <row>
1506                   <entry>0</entry>
1507                   <entry>UINT32</entry>
1508                   <entry>Return value</entry>
1509                 </row>
1510               </tbody>
1511             </tgroup>
1512           </informaltable>
1513         </para>
1514         <para>
1515           Tries to become owner of a specific service. The flags
1516           specified can be the following values logically ORed together:
1517
1518           <informaltable>
1519             <tgroup cols=3>
1520               <thead>
1521                 <row>
1522                   <entry>Identifier</entry>
1523                   <entry>Value</entry>
1524                   <entry>Description</entry>
1525                 </row>
1526               </thead>
1527               <tbody>
1528                 <row>
1529                   <entry>DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT</entry>
1530                   <entry>0x1</entry>
1531                   <entry>
1532                     If the application succeeds in being the owner of the specified service,
1533                     then ownership of the service can't be transferred until the service
1534                     disconnects. If this flag is not set, then any application trying to become
1535                     the owner of the service will succeed and the previous owner will be
1536                     sent a <literal>org.freedesktop.DBus.ServiceLost</literal> message.
1537                   </entry>
1538                 </row>
1539                 <row>
1540                   <entry>DBUS_SERVICE_FLAGS_REPLACE_EXISTING</entry>
1541                   <entry>0x2</entry>
1542                   <entry>Try to replace the current owner if there is one. If this flag
1543                   is not set the application will only become the owner of the service if
1544                   there is no current owner.</entry>
1545                 </row>
1546               </tbody>
1547             </tgroup>
1548           </informaltable>
1549
1550           [FIXME if it's one of the following values, why are the values
1551           done as flags instead of just 0, 1, 2, 3, 4]
1552           The return value can be one of the following values:
1553
1554           <informaltable>
1555             <tgroup cols=3>
1556               <thead>
1557                 <row>
1558                   <entry>Identifier</entry>
1559                   <entry>Value</entry>
1560                   <entry>Description</entry>
1561                 </row>
1562               </thead>
1563               <tbody>
1564                 <row>
1565                   <entry>DBUS_SERVICE_REPLY_PRIMARY_OWNER</entry>
1566                   <entry>0x1</entry>
1567                   <entry>The application is now the primary owner of the service.</entry>
1568                 </row>
1569                 <row>
1570                   <entry>DBUS_SERVICE_REPLY_IN_QUEUE</entry>
1571                   <entry>0x2</entry>
1572                   <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>
1573                 </row>
1574                 <row>
1575                   <entry>DBUS_SERVICE_REPLY_SERVICE_EXISTS</entry>
1576                   <entry>0x4</entry>
1577                   <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>
1578                 </row>
1579                 <row>
1580                   <entry>DBUS_SERVICE_REPLY_ALREADY_OWNER</entry>
1581                   <entry>0x8</entry>
1582                   <entry>The application trying to request ownership of the service is already the owner of it.</entry>
1583                 </row>
1584               </tbody>
1585             </tgroup>
1586           </informaltable>
1587         </para>
1588       </sect3>
1589       <sect3 id="bus-messages-service-acquired">
1590         <title><literal>org.freedesktop.DBus.ServiceAcquired</literal></title>
1591         <para>
1592           As a method:
1593           <programlisting>
1594             ServiceAcquired (in STRING service_name)
1595           </programlisting>
1596           Message arguments:
1597           <informaltable>
1598             <tgroup cols=3>
1599               <thead>
1600                 <row>
1601                   <entry>Argument</entry>
1602                   <entry>Type</entry>
1603                   <entry>Description</entry>
1604                 </row>
1605               </thead>
1606               <tbody>
1607                 <row>
1608                   <entry>0</entry>
1609                   <entry>STRING</entry>
1610                   <entry>Name of the service</entry>
1611                 </row>
1612                 <row>
1613                   <entry>1</entry>
1614                   <entry>UINT32</entry>
1615                   <entry>Flags</entry>
1616                 </row>
1617               </tbody>
1618             </tgroup>
1619           </informaltable>
1620         </para>
1621         <para>
1622           This message is sent to a specific application when it becomes the
1623           primary owner of a service.
1624         </para>
1625       </sect3>
1626       <sect3 id="bus-messages-service-lost">
1627         <title><literal>org.freedesktop.DBus.ServiceLost</literal></title>
1628         <para>
1629           As a method:
1630           <programlisting>
1631             ServiceLost (in STRING service_name)
1632           </programlisting>
1633           Message arguments:
1634           <informaltable>
1635             <tgroup cols=3>
1636               <thead>
1637                 <row>
1638                   <entry>Argument</entry>
1639                   <entry>Type</entry>
1640                   <entry>Description</entry>
1641                 </row>
1642               </thead>
1643               <tbody>
1644                 <row>
1645                   <entry>0</entry>
1646                   <entry>STRING</entry>
1647                   <entry>Name of the service</entry>
1648                 </row>
1649                 <row>
1650                   <entry>1</entry>
1651                   <entry>UINT32</entry>
1652                   <entry>Flags</entry>
1653                 </row>
1654               </tbody>
1655             </tgroup>
1656           </informaltable>
1657         </para>
1658         <para>
1659           This message is sent to a specific application when it loses primary
1660           ownership of a service.
1661
1662           [FIXME instead of ServiceLost/ServiceCreated going only to 
1663           a specific app, why not just OwnerChanged that covers both 
1664           lost and created and changed owner and deleted]
1665         </para>
1666       </sect3>
1667
1668       <sect3 id="bus-messages-service-created">
1669         <title><literal>org.freedesktop.DBus.ServiceCreated</literal></title>
1670         <para>
1671           As a method:
1672           <programlisting>
1673             ServiceCreated (in STRING service_name)
1674           </programlisting>
1675           Message arguments:
1676           <informaltable>
1677             <tgroup cols=3>
1678               <thead>
1679                 <row>
1680                   <entry>Argument</entry>
1681                   <entry>Type</entry>
1682                   <entry>Description</entry>
1683                 </row>
1684               </thead>
1685               <tbody>
1686                 <row>
1687                   <entry>0</entry>
1688                   <entry>STRING</entry>
1689                   <entry>Name of the service</entry>
1690                 </row>
1691                 <row>
1692                   <entry>1</entry>
1693                   <entry>UINT32</entry>
1694                   <entry>Flags</entry>
1695                 </row>
1696               </tbody>
1697             </tgroup>
1698           </informaltable>
1699         </para>
1700         <para>
1701           This message is broadcast to all applications when a service has been
1702           successfully registered on the message bus.
1703         </para>
1704       </sect3>
1705
1706       <sect3 id="bus-messages-service-deleted">
1707         <title><literal>org.freedesktop.DBus.ServiceDeleted</literal></title>
1708         <para>
1709           As a method:
1710           <programlisting>
1711             ServiceDeleted (in STRING service_name)
1712           </programlisting>
1713           Message arguments:
1714           <informaltable>
1715             <tgroup cols=3>
1716               <thead>
1717                 <row>
1718                   <entry>Argument</entry>
1719                   <entry>Type</entry>
1720                   <entry>Description</entry>
1721                 </row>
1722               </thead>
1723               <tbody>
1724                 <row>
1725                   <entry>0</entry>
1726                   <entry>STRING</entry>
1727                   <entry>Name of the service</entry>
1728                 </row>
1729                 <row>
1730                   <entry>1</entry>
1731                   <entry>UINT32</entry>
1732                   <entry>Flags</entry>
1733                 </row>
1734               </tbody>
1735             </tgroup>
1736           </informaltable>
1737         </para>
1738         <para>
1739           This message is broadcast to all applications when a service has been
1740           deleted from the message bus.
1741         </para>
1742       </sect3>
1743
1744       <sect3 id="bus-messages-activate-service">
1745         <title><literal>org.freedesktop.DBus.ActivateService</literal></title>
1746         <para>
1747           As a method:
1748           <programlisting>
1749             UINT32 ActivateService (in STRING service_name, in UINT32 flags)
1750           </programlisting>
1751           Message arguments:
1752           <informaltable>
1753             <tgroup cols=3>
1754               <thead>
1755                 <row>
1756                   <entry>Argument</entry>
1757                   <entry>Type</entry>
1758                   <entry>Description</entry>
1759                 </row>
1760               </thead>
1761               <tbody>
1762                 <row>
1763                   <entry>0</entry>
1764                   <entry>STRING</entry>
1765                   <entry>Name of the service to activate</entry>
1766                 </row>
1767                 <row>
1768                   <entry>1</entry>
1769                   <entry>UINT32</entry>
1770                   <entry>Flags (currently not used)</entry>
1771                 </row>
1772               </tbody>
1773             </tgroup>
1774           </informaltable>
1775         Reply arguments:
1776         <informaltable>
1777           <tgroup cols=3>
1778             <thead>
1779               <row>
1780                 <entry>Argument</entry>
1781                 <entry>Type</entry>
1782                 <entry>Description</entry>
1783               </row>
1784             </thead>
1785             <tbody>
1786               <row>
1787                 <entry>0</entry>
1788                 <entry>UINT32</entry>
1789                 <entry>Result code; DBUS_ACTIVATION_REPLY_ACTIVATED if
1790                 the service was activated successfully or
1791                 DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE if the service is
1792                 already active.</entry>
1793               </row>
1794             </tbody>
1795           </tgroup>
1796         </informaltable>
1797         </para>
1798         <para>
1799           Tries to launch the executable associated with a service. For more information, see <xref linkend="message-bus-activation">.
1800
1801             [FIXME need semantics in much more detail here; for example, 
1802             if I activate a service then send it a message, is the message 
1803             queued for the new service or is there a race]
1804         </para>
1805       </sect3>
1806
1807       <sect3 id="bus-messages-out-of-memory">
1808         <title><literal>org.freedesktop.DBus.Error.NoMemory</literal></title>
1809         <para>
1810           As a method:
1811           <programlisting>
1812             void NoMemory ()
1813           </programlisting>
1814         </para>
1815         <para>
1816           Sent by the message bus when it can't process a message due to an out of memory failure.
1817         </para>
1818       </sect3>
1819
1820       <sect3 id="bus-messages-service-does-not-exist">
1821         <title><literal>org.freedesktop.DBus.Error.ServiceDoesNotExist</literal></title>
1822         <para>
1823           As a method:
1824           <programlisting>
1825             void ServiceDoesNotExist (in STRING error)
1826           </programlisting>
1827         </para>
1828         <para>
1829           Sent by the message bus as a reply to a client that tried to send a message to a service that doesn't exist.
1830         </para>
1831       </sect3>
1832     </sect2>
1833
1834   </sect1>
1835 <!--
1836   <appendix id="implementation-notes">
1837     <title>Implementation notes</title>
1838     <sect1 id="implementation-notes-subsection">
1839       <title></title>
1840       <para>
1841       </para>
1842     </sect1>
1843   </appendix>
1844 -->
1845
1846   <glossary><title>Glossary</title>
1847     <para>
1848       This glossary defines some of the terms used in this specification.
1849     </para>
1850
1851     <glossentry id="term-activation"><glossterm>Activation</glossterm>
1852       <glossdef>
1853         <para>
1854           The process of creating an owner for a particular service, 
1855           typically by launching an executable.
1856         </para>
1857       </glossdef>
1858     </glossentry>
1859
1860     <glossentry id="term-base-service"><glossterm>Base Service</glossterm>
1861       <glossdef>
1862         <para>
1863           The special service automatically assigned to an application by the 
1864           message bus. This service may never change owner, and the service 
1865           name will be unique (never reused during the lifetime of the 
1866           message bus).
1867         </para>
1868       </glossdef>
1869     </glossentry>
1870
1871     <glossentry id="term-broadcast"><glossterm>Broadcast</glossterm>
1872       <glossdef>
1873         <para>
1874           A message sent to the special <literal>org.freedesktop.DBus.Broadcast</literal>
1875           service; the message bus will forward the broadcast message 
1876           to all applications that have expressed interest in it.
1877         </para>
1878       </glossdef>
1879     </glossentry>
1880       
1881     <glossentry id="term-message"><glossterm>Message</glossterm>
1882       <glossdef>
1883         <para>
1884           A message is the atomic unit of communication via the D-BUS
1885           protocol. It consists of a <firstterm>header</firstterm> and a
1886           <firstterm>body</firstterm>; the body is made up of
1887           <firstterm>arguments</firstterm>.
1888         </para>
1889       </glossdef>
1890     </glossentry>
1891
1892     <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
1893       <glossdef>
1894         <para>
1895           The message bus is a special application that forwards 
1896           or broadcasts messages between a group of applications
1897           connected to the message bus. It also manages 
1898           <firstterm>services</firstterm>.
1899         </para>
1900       </glossdef>
1901     </glossentry>
1902
1903     <glossentry id="namespace"><glossterm>Namespace</glossterm>
1904       <glossdef>
1905         <para>
1906           Used to prevent collisions when defining message and service
1907           names. The convention used is the same as Java uses for
1908           defining classes: a reversed domain name.
1909         </para>
1910       </glossdef>
1911     </glossentry>
1912     <glossentry id="peer-to-peer"><glossterm>Peer-to-peer</glossterm>
1913       <glossdef>
1914         <para>
1915           An application talking directly to another application, without going through a message bus. 
1916         </para>
1917       </glossdef>
1918     </glossentry>
1919     <glossentry id="term-secondary-owner"><glossterm>Secondary service owner</glossterm>
1920       <glossdef>
1921         <para>
1922           Each service has a primary owner; messages sent to the service name 
1923           go to the primary owner. However, certain services also maintain 
1924           a queue of secondary owners "waiting in the wings." If 
1925           the primary owner releases the service, then the first secondary 
1926           owner in the queue automatically becomes the primary owner.
1927         </para>
1928       </glossdef>
1929     </glossentry>
1930     <glossentry id="term-service"><glossterm>Service</glossterm>
1931       <glossdef>
1932         <para>
1933           A service is simply a named list of applications. For example, the
1934           hypothetical <literal>com.yoyodyne.Screensaver</literal> service might
1935           accept messages that affect a screensaver from Yoyodyne Corporation.
1936           An application is said to <firstterm>own</firstterm> a service if the
1937           message bus has associated the application with the service name.
1938           Services may also have <firstterm>secondary owners</firstterm> (see
1939           <xref linkend="term-secondary-owner">).
1940         </para>
1941       </glossdef>
1942     </glossentry>
1943     <glossentry id="term-service-name"><glossterm>Service name</glossterm>
1944       <glossdef>
1945         <para>
1946           The name used when referring to a service. If the service is
1947           a base service it has a unique service name, for example
1948           ":1-20", and otherwise it should be namespaced.
1949         </para>
1950       </glossdef>
1951     </glossentry>
1952     <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
1953       <glossdef>
1954         <para>
1955           ".service files" tell the bus how to activate a particular service.
1956           See <xref linkend="term-activation">
1957         </para>
1958       </glossdef>
1959     </glossentry>
1960
1961   </glossary>
1962 </article>
1963