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