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