Revert all changes since a36d4918a6f646e085
[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 <article id="index">
7   <articleinfo>
8     <title>D-Bus Specification</title>
9     <releaseinfo>Version 0.15</releaseinfo>
10     <date>3 November 2010</date>
11     <authorgroup>
12       <author>
13         <firstname>Havoc</firstname>
14         <surname>Pennington</surname>
15         <affiliation>
16           <orgname>Red Hat, Inc.</orgname>
17           <address>
18             <email>hp@pobox.com</email>
19           </address>
20         </affiliation>
21       </author>
22       <author>
23         <firstname>Anders</firstname>
24         <surname>Carlsson</surname>
25         <affiliation>
26           <orgname>CodeFactory AB</orgname>
27           <address>
28             <email>andersca@codefactory.se</email>
29           </address>
30         </affiliation>
31       </author>
32       <author>
33         <firstname>Alexander</firstname>
34         <surname>Larsson</surname>
35         <affiliation>
36           <orgname>Red Hat, Inc.</orgname>
37           <address>
38             <email>alexl@redhat.com</email>
39           </address>
40         </affiliation>
41       </author>
42       <author>
43         <firstname>Sven</firstname>
44         <surname>Herzberg</surname>
45         <affiliation>
46           <orgname>Imendio AB</orgname>
47           <address>
48             <email>sven@imendio.com</email>
49           </address>
50         </affiliation>
51       </author>
52     </authorgroup>
53    <revhistory>
54      <revision>
55        <revnumber>current</revnumber>
56        <date><ulink url='http://cgit.freedesktop.org/dbus/dbus/log/doc/dbus-specification.xml'>commit log</ulink></date>
57        <authorinitials></authorinitials>
58        <revremark></revremark>
59      </revision>
60      <revision>
61        <revnumber>0.15</revnumber>
62        <date>3 November 2010</date>
63        <authorinitials></authorinitials>
64        <revremark></revremark>
65      </revision>
66      <revision>
67        <revnumber>0.14</revnumber>
68        <date>12 May 2010</date>
69        <authorinitials></authorinitials>
70        <revremark></revremark>
71      </revision>
72      <revision>
73        <revnumber>0.13</revnumber>
74        <date>23 Dezember 2009</date>
75        <authorinitials></authorinitials>
76        <revremark></revremark>
77      </revision>
78      <revision>
79        <revnumber>0.12</revnumber>
80        <date>7 November, 2006</date>
81        <authorinitials></authorinitials>
82        <revremark></revremark>
83      </revision>
84      <revision>
85        <revnumber>0.11</revnumber>
86        <date>6 February 2005</date>
87        <authorinitials></authorinitials>
88        <revremark></revremark>
89      </revision>
90      <revision>
91        <revnumber>0.10</revnumber>
92        <date>28 January 2005</date>
93        <authorinitials></authorinitials>
94        <revremark></revremark>
95      </revision>
96      <revision>
97        <revnumber>0.9</revnumber>
98        <date>7 Januar 2005</date>
99        <authorinitials></authorinitials>
100        <revremark></revremark>
101      </revision>
102      <revision>
103        <revnumber>0.8</revnumber>
104        <date>06 September 2003</date>
105        <authorinitials></authorinitials>
106        <revremark>First released document.</revremark>
107      </revision>
108    </revhistory>
109   </articleinfo>
110
111   <sect1 id="introduction">
112     <title>Introduction</title>
113     <para>
114       D-Bus is a system for low-latency, low-overhead, easy to use
115       interprocess communication (IPC). In more detail:
116       <itemizedlist>
117         <listitem>
118           <para>
119             D-Bus is <emphasis>low-latency</emphasis> because it is designed 
120             to avoid round trips and allow asynchronous operation, much like 
121             the X protocol.
122           </para>
123         </listitem>
124         <listitem>
125           <para>
126             D-Bus is <emphasis>low-overhead</emphasis> because it uses a
127             binary protocol, and does not have to convert to and from a text
128             format such as XML. Because D-Bus is intended for potentially
129             high-resolution same-machine IPC, not primarily for Internet IPC,
130             this is an interesting optimization.
131           </para>
132         </listitem>
133         <listitem>
134           <para>
135             D-Bus is <emphasis>easy to use</emphasis> because it works in terms
136             of <firstterm>messages</firstterm> rather than byte streams, and
137             automatically handles a lot of the hard IPC issues. Also, the D-Bus
138             library is designed to be wrapped in a way that lets developers use
139             their framework's existing object/type system, rather than learning
140             a new one specifically for IPC.
141           </para>
142         </listitem>
143       </itemizedlist>
144     </para>
145
146     <para>
147       The base D-Bus protocol is a one-to-one (peer-to-peer or client-server)
148       protocol, specified in <xref linkend="message-protocol"/>. That is, it is
149       a system for one application to talk to a single other
150       application. However, the primary intended application of the protocol is the
151       D-Bus <firstterm>message bus</firstterm>, specified in <xref
152       linkend="message-bus"/>. The message bus is a special application that
153       accepts connections from multiple other applications, and forwards
154       messages among them.
155     </para>
156
157     <para>
158       Uses of D-Bus include notification of system changes (notification of when
159       a camera is plugged in to a computer, or a new version of some software
160       has been installed), or desktop interoperability, for example a file
161       monitoring service or a configuration service.
162     </para>
163
164     <para>
165       D-Bus is designed for two specific use cases:
166       <itemizedlist>
167         <listitem>
168           <para>
169             A "system bus" for notifications from the system to user sessions,
170             and to allow the system to request input from user sessions.
171           </para>
172         </listitem>
173         <listitem>
174           <para>
175             A "session bus" used to implement desktop environments such as 
176             GNOME and KDE.
177           </para>
178         </listitem>
179       </itemizedlist>
180       D-Bus is not intended to be a generic IPC system for any possible 
181       application, and intentionally omits many features found in other 
182       IPC systems for this reason.
183     </para>
184
185     <para>
186       At the same time, the bus daemons offer a number of features not found in
187       other IPC systems, such as single-owner "bus names" (similar to X
188       selections), on-demand startup of services, and security policies.
189       In many ways, these features are the primary motivation for developing 
190       D-Bus; other systems would have sufficed if IPC were the only goal.
191     </para>
192
193     <para>
194       D-Bus may turn out to be useful in unanticipated applications, but future
195       versions of this spec and the reference implementation probably will not
196       incorporate features that interfere with the core use cases.
197     </para>
198
199     <para>
200       The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
201       "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
202       document are to be interpreted as described in RFC 2119. However, the
203       document could use a serious audit to be sure it makes sense to do
204       so. Also, they are not capitalized.
205     </para>
206
207     <sect2 id="stability">
208       <title>Protocol and Specification Stability</title>
209       <para>
210         The D-Bus protocol is frozen (only compatible extensions are allowed) as
211         of November 8, 2006.  However, this specification could still use a fair
212         bit of work to make interoperable reimplementation possible without
213         reference to the D-Bus reference implementation. Thus, this
214         specification is not marked 1.0. To mark it 1.0, we'd like to see
215         someone invest significant effort in clarifying the specification
216         language, and growing the specification to cover more aspects of the
217         reference implementation's behavior.
218       </para>
219       <para>
220         Until this work is complete, any attempt to reimplement D-Bus will 
221         probably require looking at the reference implementation and/or asking
222         questions on the D-Bus mailing list about intended behavior. 
223         Questions on the list are very welcome.
224       </para>
225       <para>
226         Nonetheless, this document should be a useful starting point and is 
227         to our knowledge accurate, though incomplete.
228       </para>
229     </sect2>
230     
231   </sect1>
232
233   <sect1 id="message-protocol">
234     <title>Message Protocol</title>
235
236     <para>
237       A <firstterm>message</firstterm> consists of a
238       <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
239       think of a message as a package, the header is the address, and the body
240       contains the package contents. The message delivery system uses the header
241       information to figure out where to send the message and how to interpret
242       it; the recipient interprets the body of the message.
243     </para>
244     
245     <para>
246       The body of the message is made up of zero or more
247       <firstterm>arguments</firstterm>, which are typed values, such as an
248       integer or a byte array.
249     </para>
250
251     <para>
252       Both header and body use the same type system and format for 
253       serializing data. Each type of value has a wire format. 
254       Converting a value from some other representation into the wire
255       format is called <firstterm>marshaling</firstterm> and converting
256       it back from the wire format is <firstterm>unmarshaling</firstterm>.
257     </para>
258
259     <sect2 id="message-protocol-signatures">
260       <title>Type Signatures</title>
261
262       <para>
263         The D-Bus protocol does not include type tags in the marshaled data; a
264         block of marshaled values must have a known <firstterm>type
265         signature</firstterm>.  The type signature is made up of <firstterm>type
266         codes</firstterm>. A type code is an ASCII character representing the
267         type of a value. Because ASCII characters are used, the type signature
268         will always form a valid ASCII string. A simple string compare 
269         determines whether two type signatures are equivalent.
270       </para>
271
272       <para>
273         As a simple example, the type code for 32-bit integer (<literal>INT32</literal>) is
274         the ASCII character 'i'. So the signature for a block of values 
275         containing a single <literal>INT32</literal> would be:
276         <programlisting>
277           "i"
278         </programlisting>
279         A block of values containing two <literal>INT32</literal> would have this signature:
280         <programlisting>
281           "ii"
282         </programlisting>        
283       </para>
284
285       <para>
286         All <firstterm>basic</firstterm> types work like 
287         <literal>INT32</literal> in this example. To marshal and unmarshal 
288         basic types, you simply read one value from the data
289         block corresponding to each type code in the signature.
290         In addition to basic types, there are four <firstterm>container</firstterm> 
291         types: <literal>STRUCT</literal>, <literal>ARRAY</literal>, <literal>VARIANT</literal>, 
292         and <literal>DICT_ENTRY</literal>.
293       </para>
294
295       <para>
296         <literal>STRUCT</literal> has a type code, ASCII character 'r', but this type 
297         code does not appear in signatures. Instead, ASCII characters
298         '(' and ')' are used to mark the beginning and end of the struct.
299         So for example, a struct containing two integers would have this 
300         signature:
301         <programlisting>
302           "(ii)"
303         </programlisting>
304         Structs can be nested, so for example a struct containing 
305         an integer and another struct:
306         <programlisting>
307           "(i(ii))"
308         </programlisting>
309         The value block storing that struct would contain three integers; the
310         type signature allows you to distinguish "(i(ii))" from "((ii)i)" or
311         "(iii)" or "iii".
312       </para>
313
314       <para>
315         The <literal>STRUCT</literal> type code 'r' is not currently used in the D-Bus protocol,
316         but is useful in code that implements the protocol. This type code 
317         is specified to allow such code to interoperate in non-protocol contexts.
318       </para>
319
320       <para>
321         Empty structures are not allowed; there must be at least one
322         type code between the parentheses.
323       </para>
324
325       <para>
326         <literal>ARRAY</literal> has ASCII character 'a' as type code. The array type code must be
327         followed by a <firstterm>single complete type</firstterm>. The single
328         complete type following the array is the type of each array element. So
329         the simple example is:
330         <programlisting>
331           "ai"
332         </programlisting>
333         which is an array of 32-bit integers. But an array can be of any type, 
334         such as this array-of-struct-with-two-int32-fields:
335         <programlisting>
336           "a(ii)"
337         </programlisting>
338         Or this array of array of integer:
339         <programlisting>
340           "aai"
341         </programlisting>
342       </para>
343
344       <para>
345         The phrase <firstterm>single complete type</firstterm> deserves some 
346         definition. A single complete type is a basic type code, a variant type code, 
347         an array with its element type, or a struct with its fields. 
348         So the following signatures are not single complete types:
349         <programlisting>
350           "aa"
351         </programlisting>
352         <programlisting>
353           "(ii"
354         </programlisting>
355         <programlisting>
356           "ii)"
357         </programlisting>
358         And the following signatures contain multiple complete types:
359         <programlisting>
360           "ii"
361         </programlisting>
362         <programlisting>
363           "aiai"
364         </programlisting>
365         <programlisting>
366           "(ii)(ii)"
367         </programlisting>
368         Note however that a single complete type may <emphasis>contain</emphasis>
369         multiple other single complete types.
370       </para>
371
372       <para>
373         <literal>VARIANT</literal> has ASCII character 'v' as its type code. A marshaled value of
374         type <literal>VARIANT</literal> will have the signature of a single complete type as part
375         of the <emphasis>value</emphasis>.  This signature will be followed by a
376         marshaled value of that type.
377       </para>
378
379       <para>
380         A <literal>DICT_ENTRY</literal> works exactly like a struct, but rather
381         than parentheses it uses curly braces, and it has more restrictions.
382         The restrictions are: it occurs only as an array element type; it has
383         exactly two single complete types inside the curly braces; the first
384         single complete type (the "key") must be a basic type rather than a
385         container type. Implementations must not accept dict entries outside of
386         arrays, must not accept dict entries with zero, one, or more than two
387         fields, and must not accept dict entries with non-basic-typed keys. A
388         dict entry is always a key-value pair.
389       </para>
390       
391       <para>
392         The first field in the <literal>DICT_ENTRY</literal> is always the key.
393         A message is considered corrupt if the same key occurs twice in the same
394         array of <literal>DICT_ENTRY</literal>. However, for performance reasons
395         implementations are not required to reject dicts with duplicate keys.
396       </para>
397
398       <para>
399         In most languages, an array of dict entry would be represented as a 
400         map, hash table, or dict object.
401       </para>
402
403       <para>
404         The following table summarizes the D-Bus types.
405         <informaltable>
406           <tgroup cols="3">
407             <thead>
408               <row>
409                 <entry>Conventional Name</entry>
410                 <entry>Code</entry>
411                 <entry>Description</entry>
412               </row>
413             </thead>
414             <tbody>
415               <row>
416                 <entry><literal>INVALID</literal></entry>
417                 <entry>0 (ASCII NUL)</entry>
418                 <entry>Not a valid type code, used to terminate signatures</entry>
419               </row><row>
420                 <entry><literal>BYTE</literal></entry>
421                 <entry>121 (ASCII 'y')</entry>
422                 <entry>8-bit unsigned integer</entry>
423               </row><row>
424                 <entry><literal>BOOLEAN</literal></entry>
425                 <entry>98 (ASCII 'b')</entry>
426                 <entry>Boolean value, 0 is <literal>FALSE</literal> and 1 is <literal>TRUE</literal>. Everything else is invalid.</entry>
427               </row><row>
428                 <entry><literal>INT16</literal></entry>
429                 <entry>110 (ASCII 'n')</entry>
430                 <entry>16-bit signed integer</entry>
431               </row><row>
432                 <entry><literal>UINT16</literal></entry>
433                 <entry>113 (ASCII 'q')</entry>
434                 <entry>16-bit unsigned integer</entry>
435               </row><row>
436                 <entry><literal>INT32</literal></entry>
437                 <entry>105 (ASCII 'i')</entry>
438                 <entry>32-bit signed integer</entry>
439               </row><row>
440                 <entry><literal>UINT32</literal></entry>
441                 <entry>117 (ASCII 'u')</entry>
442                 <entry>32-bit unsigned integer</entry>
443               </row><row>
444                 <entry><literal>INT64</literal></entry>
445                 <entry>120 (ASCII 'x')</entry>
446                 <entry>64-bit signed integer</entry>
447               </row><row>
448                 <entry><literal>UINT64</literal></entry>
449                 <entry>116 (ASCII 't')</entry>
450                 <entry>64-bit unsigned integer</entry>
451               </row><row>
452                 <entry><literal>DOUBLE</literal></entry>
453                 <entry>100 (ASCII 'd')</entry>
454                 <entry>IEEE 754 double</entry>
455               </row><row>
456                 <entry><literal>STRING</literal></entry>
457                 <entry>115 (ASCII 's')</entry>
458                 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be nul terminated and contain no other nul bytes.</entry>
459               </row><row>
460                 <entry><literal>OBJECT_PATH</literal></entry>
461                 <entry>111 (ASCII 'o')</entry>
462                 <entry>Name of an object instance</entry>
463               </row><row>
464                 <entry><literal>SIGNATURE</literal></entry>
465                 <entry>103 (ASCII 'g')</entry>
466                 <entry>A type signature</entry>
467               </row><row>
468                 <entry><literal>ARRAY</literal></entry>
469                 <entry>97 (ASCII 'a')</entry>
470                 <entry>Array</entry>
471               </row><row>
472                 <entry><literal>STRUCT</literal></entry>
473                 <entry>114 (ASCII 'r'), 40 (ASCII '('), 41 (ASCII ')')</entry>
474                 <entry>Struct</entry>
475               </row><row>
476                 <entry><literal>VARIANT</literal></entry>
477                 <entry>118 (ASCII 'v') </entry>
478                 <entry>Variant type (the type of the value is part of the value itself)</entry>
479               </row><row>
480                 <entry><literal>DICT_ENTRY</literal></entry>
481                 <entry>101 (ASCII 'e'), 123 (ASCII '{'), 125 (ASCII '}') </entry>
482                 <entry>Entry in a dict or map (array of key-value pairs)</entry>
483               </row><row>
484                 <entry><literal>UNIX_FD</literal></entry>
485                 <entry>104 (ASCII 'h')</entry>
486                 <entry>Unix file descriptor</entry>
487               </row>
488             </tbody>
489           </tgroup>
490         </informaltable>
491       </para>
492
493     </sect2>
494
495     <sect2 id="message-protocol-marshaling">
496       <title>Marshaling (Wire Format)</title>
497
498       <para>
499         Given a type signature, a block of bytes can be converted into typed
500         values. This section describes the format of the block of bytes.  Byte
501         order and alignment issues are handled uniformly for all D-Bus types.
502       </para>
503
504       <para>
505         A block of bytes has an associated byte order. The byte order 
506         has to be discovered in some way; for D-Bus messages, the 
507         byte order is part of the message header as described in 
508         <xref linkend="message-protocol-messages"/>. For now, assume 
509         that the byte order is known to be either little endian or big 
510           endian.
511       </para>
512
513       <para>
514         Each value in a block of bytes is aligned "naturally," for example
515         4-byte values are aligned to a 4-byte boundary, and 8-byte values to an
516         8-byte boundary. To properly align a value, <firstterm>alignment
517         padding</firstterm> may be necessary. The alignment padding must always
518         be the minimum required padding to properly align the following value;
519         and it must always be made up of nul bytes. The alignment padding must
520         not be left uninitialized (it can't contain garbage), and more padding
521         than required must not be used.
522       </para>
523
524       <para>
525         Given all this, the types are marshaled on the wire as follows:
526         <informaltable>
527           <tgroup cols="3">
528             <thead>
529               <row>
530                 <entry>Conventional Name</entry>
531                 <entry>Encoding</entry>
532                 <entry>Alignment</entry>
533               </row>
534             </thead>
535             <tbody>
536               <row>
537                 <entry><literal>INVALID</literal></entry>
538                 <entry>Not applicable; cannot be marshaled.</entry>
539                 <entry>N/A</entry>
540               </row><row>
541                 <entry><literal>BYTE</literal></entry>
542                 <entry>A single 8-bit byte.</entry>
543                 <entry>1</entry>
544               </row><row>
545                 <entry><literal>BOOLEAN</literal></entry>
546                 <entry>As for <literal>UINT32</literal>, but only 0 and 1 are valid values.</entry>
547                 <entry>4</entry>
548               </row><row>
549                 <entry><literal>INT16</literal></entry>
550                 <entry>16-bit signed integer in the message's byte order.</entry>
551                 <entry>2</entry>
552               </row><row>
553                 <entry><literal>UINT16</literal></entry>
554                 <entry>16-bit unsigned integer in the message's byte order.</entry>
555                 <entry>2</entry>
556               </row><row>
557                 <entry><literal>INT32</literal></entry>
558                 <entry>32-bit signed integer in the message's byte order.</entry>
559                 <entry>4</entry>
560               </row><row>
561                 <entry><literal>UINT32</literal></entry>
562                 <entry>32-bit unsigned integer in the message's byte order.</entry>
563                 <entry>4</entry>
564               </row><row>
565                 <entry><literal>INT64</literal></entry>
566                 <entry>64-bit signed integer in the message's byte order.</entry>
567                 <entry>8</entry>
568               </row><row>
569                 <entry><literal>UINT64</literal></entry>
570                 <entry>64-bit unsigned integer in the message's byte order.</entry>
571                 <entry>8</entry>
572               </row><row>
573                 <entry><literal>DOUBLE</literal></entry>
574                 <entry>64-bit IEEE 754 double in the message's byte order.</entry>
575                 <entry>8</entry>
576               </row><row>
577                 <entry><literal>STRING</literal></entry>
578                 <entry>A <literal>UINT32</literal> indicating the string's 
579                   length in bytes excluding its terminating nul, followed by 
580                   non-nul string data of the given length, followed by a terminating nul 
581                   byte.
582                 </entry>
583                 <entry>
584                   4 (for the length)
585                 </entry>
586               </row><row>
587                 <entry><literal>OBJECT_PATH</literal></entry>
588                 <entry>Exactly the same as <literal>STRING</literal> except the 
589                   content must be a valid object path (see below).
590                 </entry>
591                 <entry>
592                   4 (for the length)
593                 </entry>
594               </row><row>
595                 <entry><literal>SIGNATURE</literal></entry>
596                 <entry>The same as <literal>STRING</literal> except the length is a single 
597                   byte (thus signatures have a maximum length of 255)
598                   and the content must be a valid signature (see below).
599                 </entry>
600                 <entry>
601                   1
602                 </entry>
603               </row><row>
604                 <entry><literal>ARRAY</literal></entry>
605                 <entry>
606                   A <literal>UINT32</literal> giving the length of the array data in bytes, followed by 
607                   alignment padding to the alignment boundary of the array element type, 
608                   followed by each array element. The array length is from the 
609                   end of the alignment padding to the end of the last element,
610                   i.e. it does not include the padding after the length,
611                   or any padding after the last element.
612                   Arrays have a maximum length defined to be 2 to the 26th power or
613                   67108864. Implementations must not send or accept arrays exceeding this
614                   length.
615                 </entry>
616                 <entry>
617                   4 (for the length)
618                 </entry>
619               </row><row>
620                 <entry><literal>STRUCT</literal></entry>
621                 <entry>
622                   A struct must start on an 8-byte boundary regardless of the
623                   type of the struct fields. The struct value consists of each
624                   field marshaled in sequence starting from that 8-byte
625                   alignment boundary.
626                 </entry>
627                 <entry>
628                   8
629                 </entry>
630               </row><row>
631                 <entry><literal>VARIANT</literal></entry>
632                 <entry>
633                   A variant type has a marshaled
634                   <literal>SIGNATURE</literal> followed by a marshaled
635                   value with the type given in the signature.  Unlike
636                   a message signature, the variant signature can
637                   contain only a single complete type.  So "i", "ai"
638                   or "(ii)" is OK, but "ii" is not.  Use of variants may not
639                   cause a total message depth to be larger than 64, including
640                   other container types such as structures.
641                 </entry>
642                 <entry>
643                   1 (alignment of the signature)
644                 </entry>
645               </row><row>
646                 <entry><literal>DICT_ENTRY</literal></entry>
647                 <entry>
648                   Identical to STRUCT.
649                 </entry>
650                 <entry>
651                   8
652                 </entry>
653               </row><row>
654                 <entry><literal>UNIX_FD</literal></entry>
655                 <entry>32-bit unsigned integer in the message's byte
656                 order. The actual file descriptors need to be
657                 transferred out-of-band via some platform specific
658                 mechanism. On the wire, values of this type store the index to the
659                 file descriptor in the array of file descriptors that
660                 accompany the message.</entry>
661                 <entry>4</entry>
662               </row>
663             </tbody>
664           </tgroup>
665         </informaltable>
666       </para>
667       
668       <sect3 id="message-protocol-marshaling-object-path">
669         <title>Valid Object Paths</title>
670         
671         <para>
672           An object path is a name used to refer to an object instance.
673           Conceptually, each participant in a D-Bus message exchange may have
674           any number of object instances (think of C++ or Java objects) and each
675           such instance will have a path. Like a filesystem, the object
676           instances in an application form a hierarchical tree.
677         </para>
678         
679         <para>
680           The following rules define a valid object path. Implementations must 
681           not send or accept messages with invalid object paths.
682           <itemizedlist>
683             <listitem>
684               <para>
685                 The path may be of any length.
686               </para>
687             </listitem>
688             <listitem>
689               <para>
690                 The path must begin with an ASCII '/' (integer 47) character, 
691                 and must consist of elements separated by slash characters.
692               </para>
693             </listitem>
694             <listitem>
695               <para>
696                 Each element must only contain the ASCII characters 
697                 "[A-Z][a-z][0-9]_"
698               </para>
699             </listitem>
700             <listitem>
701               <para>
702                 No element may be the empty string.
703               </para>
704             </listitem>
705             <listitem>
706               <para>
707                 Multiple '/' characters cannot occur in sequence.
708               </para>
709             </listitem>
710             <listitem>
711               <para>
712                 A trailing '/' character is not allowed unless the 
713                 path is the root path (a single '/' character).
714               </para>
715             </listitem>
716           </itemizedlist>
717         </para>
718
719       </sect3>
720
721       
722       <sect3 id="message-protocol-marshaling-signature">
723         <title>Valid Signatures</title>
724         <para>
725           An implementation must not send or accept invalid signatures.
726           Valid signatures will conform to the following rules:
727           <itemizedlist>
728             <listitem>
729               <para>
730                 The signature ends with a nul byte.
731               </para>
732             </listitem>
733             <listitem>
734               <para>
735                 The signature is a list of single complete types. 
736                 Arrays must have element types, and structs must 
737                 have both open and close parentheses.
738               </para>
739             </listitem>
740             <listitem>
741               <para>
742                 Only type codes and open and close parentheses are 
743                 allowed in the signature. The <literal>STRUCT</literal> type code
744                 is not allowed in signatures, because parentheses
745                 are used instead.
746               </para>
747             </listitem>
748             <listitem>
749               <para>
750                 The maximum depth of container type nesting is 32 array type
751                 codes and 32 open parentheses. This implies that the maximum
752                 total depth of recursion is 64, for an "array of array of array
753                 of ... struct of struct of struct of ..."  where there are 32
754                 array and 32 struct.
755               </para>
756             </listitem>
757             <listitem>
758               <para>
759                 The maximum length of a signature is 255.
760               </para>
761             </listitem>
762             <listitem>
763               <para>
764                 Signatures must be nul-terminated.
765               </para>
766             </listitem>
767           </itemizedlist>
768         </para>
769       </sect3>
770       
771     </sect2>
772
773     <sect2 id="message-protocol-messages">
774       <title>Message Format</title>
775
776       <para>
777         A message consists of a header and a body. The header is a block of
778         values with a fixed signature and meaning.  The body is a separate block
779         of values, with a signature specified in the header.
780       </para>
781
782       <para>
783         The length of the header must be a multiple of 8, allowing the body to
784         begin on an 8-byte boundary when storing the entire message in a single
785         buffer. If the header does not naturally end on an 8-byte boundary 
786         up to 7 bytes of nul-initialized alignment padding must be added.
787       </para>
788
789       <para>
790         The message body need not end on an 8-byte boundary.
791       </para>
792
793       <para>
794         The maximum length of a message, including header, header alignment padding, 
795         and body is 2 to the 27th power or 134217728. Implementations must not 
796         send or accept messages exceeding this size.
797       </para>
798       
799       <para>
800         The signature of the header is:
801         <programlisting>
802           "yyyyuua(yv)"
803         </programlisting>
804         Written out more readably, this is:
805         <programlisting>
806           BYTE, BYTE, BYTE, BYTE, UINT32, UINT32, ARRAY of STRUCT of (BYTE,VARIANT)
807         </programlisting>
808       </para>
809
810       <para>
811         These values have the following meanings:
812         <informaltable>
813           <tgroup cols="2">
814             <thead>
815               <row>
816                 <entry>Value</entry>
817                 <entry>Description</entry>
818               </row>
819             </thead>
820             <tbody>
821               <row>
822                 <entry>1st <literal>BYTE</literal></entry>
823                 <entry>Endianness flag; ASCII 'l' for little-endian 
824                   or ASCII 'B' for big-endian. Both header and body are 
825                 in this endianness.</entry>
826               </row>
827               <row>
828                 <entry>2nd <literal>BYTE</literal></entry>
829                 <entry><firstterm>Message type</firstterm>. Unknown types must be ignored. 
830                   Currently-defined types are described below.
831                 </entry>
832               </row>
833               <row>
834                 <entry>3rd <literal>BYTE</literal></entry>
835                 <entry>Bitwise OR of flags. Unknown flags
836                   must be ignored. Currently-defined flags are described below.
837                 </entry>
838               </row>
839               <row>
840                 <entry>4th <literal>BYTE</literal></entry>
841                 <entry>Major protocol version of the sending application.  If
842                 the major protocol version of the receiving application does not
843                 match, the applications will not be able to communicate and the
844                 D-Bus connection must be disconnected. The major protocol
845                 version for this version of the specification is 1.
846                 </entry>
847               </row>
848               <row>
849                 <entry>1st <literal>UINT32</literal></entry>
850                 <entry>Length in bytes of the message body, starting 
851                   from the end of the header. The header ends after 
852                   its alignment padding to an 8-boundary.
853                 </entry>
854               </row>
855               <row>
856                 <entry>2nd <literal>UINT32</literal></entry>
857                 <entry>The serial of this message, used as a cookie 
858                   by the sender to identify the reply corresponding
859                   to this request. This must not be zero.
860                 </entry>
861               </row>      
862               <row>
863                 <entry><literal>ARRAY</literal> of <literal>STRUCT</literal> of (<literal>BYTE</literal>,<literal>VARIANT</literal>)</entry>
864                 <entry>An array of zero or more <firstterm>header
865                   fields</firstterm> where the byte is the field code, and the
866                   variant is the field value. The message type determines 
867                   which fields are required.
868                 </entry>
869               </row>
870             </tbody>
871           </tgroup>
872         </informaltable>
873       </para>
874       <para>
875         <firstterm>Message types</firstterm> that can appear in the second byte
876         of the header are:
877         <informaltable>
878           <tgroup cols="3">
879             <thead>
880               <row>
881                 <entry>Conventional name</entry>
882                 <entry>Decimal value</entry>
883                 <entry>Description</entry>
884               </row>
885             </thead>
886             <tbody>
887               <row>
888                 <entry><literal>INVALID</literal></entry>
889                 <entry>0</entry>
890                 <entry>This is an invalid type.</entry>
891               </row>
892               <row>
893                 <entry><literal>METHOD_CALL</literal></entry>
894                 <entry>1</entry>
895                 <entry>Method call.</entry>
896               </row>
897               <row>
898                 <entry><literal>METHOD_RETURN</literal></entry>
899                 <entry>2</entry>
900                 <entry>Method reply with returned data.</entry>
901               </row>
902               <row>
903                 <entry><literal>ERROR</literal></entry>
904                 <entry>3</entry>
905                 <entry>Error reply. If the first argument exists and is a
906                 string, it is an error message.</entry>
907               </row>
908               <row>
909                 <entry><literal>SIGNAL</literal></entry>
910                 <entry>4</entry>
911                 <entry>Signal emission.</entry>
912               </row>
913             </tbody>
914           </tgroup>
915         </informaltable>
916       </para>
917       <para>
918         Flags that can appear in the third byte of the header:
919         <informaltable>
920           <tgroup cols="3">
921             <thead>
922               <row>
923                 <entry>Conventional name</entry>
924                 <entry>Hex value</entry>
925                 <entry>Description</entry>
926               </row>
927             </thead>
928             <tbody>
929               <row>
930                 <entry><literal>NO_REPLY_EXPECTED</literal></entry>
931                 <entry>0x1</entry>
932                 <entry>This message does not expect method return replies or
933                 error replies; the reply can be omitted as an
934                 optimization. However, it is compliant with this specification
935                 to return the reply despite this flag and the only harm 
936                   from doing so is extra network traffic.
937                 </entry>
938               </row>
939               <row>
940                 <entry><literal>NO_AUTO_START</literal></entry>
941                 <entry>0x2</entry>
942                 <entry>The bus must not launch an owner
943                   for the destination name in response to this message.
944                 </entry>
945               </row>
946             </tbody>
947           </tgroup>
948         </informaltable>
949       </para>
950
951       <sect3 id="message-protocol-header-fields">
952         <title>Header Fields</title>
953
954         <para>
955           The array at the end of the header contains <firstterm>header
956           fields</firstterm>, where each field is a 1-byte field code followed
957           by a field value. A header must contain the required header fields for
958           its message type, and zero or more of any optional header
959           fields. Future versions of this protocol specification may add new
960           fields. Implementations must ignore fields they do not
961           understand. Implementations must not invent their own header fields;
962           only changes to this specification may introduce new header fields.
963         </para>
964
965         <para>
966           Again, if an implementation sees a header field code that it does not
967           expect, it must ignore that field, as it will be part of a new
968           (but compatible) version of this specification. This also applies 
969           to known header fields appearing in unexpected messages, for 
970           example: if a signal has a reply serial it must be ignored
971           even though it has no meaning as of this version of the spec.
972         </para>
973
974         <para>
975           However, implementations must not send or accept known header fields
976           with the wrong type stored in the field value. So for example a
977           message with an <literal>INTERFACE</literal> field of type
978           <literal>UINT32</literal> would be considered corrupt.
979         </para>
980
981         <para>
982           Here are the currently-defined header fields:
983           <informaltable>
984             <tgroup cols="5">
985               <thead>
986                 <row>
987                   <entry>Conventional Name</entry>
988                   <entry>Decimal Code</entry>
989                   <entry>Type</entry>
990                   <entry>Required In</entry>
991                   <entry>Description</entry>
992                 </row>
993               </thead>
994               <tbody>
995                 <row>
996                   <entry><literal>INVALID</literal></entry>
997                   <entry>0</entry>
998                   <entry>N/A</entry>
999                   <entry>not allowed</entry>
1000                   <entry>Not a valid field name (error if it appears in a message)</entry>
1001                 </row>
1002                 <row>
1003                   <entry><literal>PATH</literal></entry>
1004                   <entry>1</entry>
1005                   <entry><literal>OBJECT_PATH</literal></entry>
1006                   <entry><literal>METHOD_CALL</literal>, <literal>SIGNAL</literal></entry>
1007                   <entry>The object to send a call to,
1008                     or the object a signal is emitted from.
1009                     The special path
1010                     <literal>/org/freedesktop/DBus/Local</literal> is reserved;
1011                     implementations should not send messages with this path,
1012                     and the reference implementation of the bus daemon will
1013                     disconnect any application that attempts to do so.
1014                   </entry>
1015                 </row>
1016                 <row>
1017                   <entry><literal>INTERFACE</literal></entry>
1018                   <entry>2</entry>
1019                   <entry><literal>STRING</literal></entry>
1020                   <entry><literal>SIGNAL</literal></entry>
1021                   <entry>
1022                     The interface to invoke a method call on, or 
1023                     that a signal is emitted from. Optional for 
1024                     method calls, required for signals.
1025                     The special interface
1026                     <literal>org.freedesktop.DBus.Local</literal> is reserved;
1027                     implementations should not send messages with this
1028                     interface, and the reference implementation of the bus
1029                     daemon will disconnect any application that attempts to
1030                     do so.
1031                   </entry>
1032                 </row>
1033                 <row>
1034                   <entry><literal>MEMBER</literal></entry>
1035                   <entry>3</entry>
1036                   <entry><literal>STRING</literal></entry>
1037                   <entry><literal>METHOD_CALL</literal>, <literal>SIGNAL</literal></entry>
1038                   <entry>The member, either the method name or signal name.</entry>
1039                 </row>
1040                 <row>
1041                   <entry><literal>ERROR_NAME</literal></entry>
1042                   <entry>4</entry>
1043                   <entry><literal>STRING</literal></entry>
1044                   <entry><literal>ERROR</literal></entry>
1045                   <entry>The name of the error that occurred, for errors</entry>
1046                 </row>
1047                 <row>
1048                   <entry><literal>REPLY_SERIAL</literal></entry>
1049                   <entry>5</entry>
1050                   <entry><literal>UINT32</literal></entry>
1051                   <entry><literal>ERROR</literal>, <literal>METHOD_RETURN</literal></entry>
1052                   <entry>The serial number of the message this message is a reply
1053                     to. (The serial number is the second <literal>UINT32</literal> in the header.)</entry>
1054                 </row>
1055                 <row>
1056                   <entry><literal>DESTINATION</literal></entry>
1057                   <entry>6</entry>
1058                   <entry><literal>STRING</literal></entry>
1059                   <entry>optional</entry>
1060                   <entry>The name of the connection this message is intended for.
1061                     Only used in combination with the message bus, see 
1062                     <xref linkend="message-bus"/>.</entry>
1063                 </row>
1064                 <row>
1065                   <entry><literal>SENDER</literal></entry>
1066                   <entry>7</entry>
1067                   <entry><literal>STRING</literal></entry>
1068                   <entry>optional</entry>
1069                   <entry>Unique name of the sending connection.
1070                     The message bus fills in this field so it is reliable; the field is
1071                     only meaningful in combination with the message bus.</entry>
1072                 </row>
1073                 <row>
1074                   <entry><literal>SIGNATURE</literal></entry>
1075                   <entry>8</entry>
1076                   <entry><literal>SIGNATURE</literal></entry>
1077                   <entry>optional</entry>
1078                   <entry>The signature of the message body.
1079                   If omitted, it is assumed to be the 
1080                   empty signature "" (i.e. the body must be 0-length).</entry>
1081                 </row>
1082                 <row>
1083                   <entry><literal>UNIX_FDS</literal></entry>
1084                   <entry>9</entry>
1085                   <entry><literal>UINT32</literal></entry>
1086                   <entry>optional</entry>
1087                   <entry>The number of Unix file descriptors that
1088                   accompany the message.  If omitted, it is assumed
1089                   that no Unix file descriptors accompany the
1090                   message. The actual file descriptors need to be
1091                   transferred via platform specific mechanism
1092                   out-of-band. They must be sent at the same time as
1093                   part of the message itself. They may not be sent
1094                   before the first byte of the message itself is
1095                   transferred or after the last byte of the message
1096                   itself.</entry>
1097                 </row>
1098               </tbody>
1099             </tgroup>
1100           </informaltable>
1101         </para>
1102       </sect3>
1103     </sect2>
1104
1105     <sect2 id="message-protocol-names">
1106       <title>Valid Names</title>
1107       <para>
1108         The various names in D-Bus messages have some restrictions.
1109       </para>
1110       <para>
1111         There is a <firstterm>maximum name length</firstterm> 
1112         of 255 which applies to bus names, interfaces, and members. 
1113       </para>
1114       <sect3 id="message-protocol-names-interface">
1115         <title>Interface names</title>
1116         <para>
1117           Interfaces have names with type <literal>STRING</literal>, meaning that 
1118           they must be valid UTF-8. However, there are also some 
1119           additional restrictions that apply to interface names 
1120           specifically:
1121           <itemizedlist>
1122             <listitem><para>Interface names are composed of 1 or more elements separated by
1123                 a period ('.') character. All elements must contain at least 
1124                 one character.
1125                 </para>
1126             </listitem>
1127             <listitem><para>Each element must only contain the ASCII characters 
1128                 "[A-Z][a-z][0-9]_" and must not begin with a digit.
1129                 </para>
1130             </listitem>
1131
1132             <listitem><para>Interface names must contain at least one '.' (period)
1133               character (and thus at least two elements).
1134               </para></listitem>
1135
1136             <listitem><para>Interface names must not begin with a '.' (period) character.</para></listitem>
1137             <listitem><para>Interface names must not exceed the maximum name length.</para></listitem>
1138           </itemizedlist>
1139         </para>
1140       </sect3>
1141       <sect3 id="message-protocol-names-bus">
1142         <title>Bus names</title>
1143         <para>
1144           Connections have one or more bus names associated with them.
1145           A connection has exactly one bus name that is a unique connection
1146           name. The unique connection name remains with the connection for
1147           its entire lifetime.
1148           A bus name is of type <literal>STRING</literal>,
1149           meaning that it must be valid UTF-8. However, there are also
1150           some additional restrictions that apply to bus names 
1151           specifically:
1152           <itemizedlist>
1153             <listitem><para>Bus names that start with a colon (':')
1154                 character are unique connection names.
1155                 </para>
1156             </listitem>
1157             <listitem><para>Bus names are composed of 1 or more elements separated by
1158                 a period ('.') character. All elements must contain at least 
1159                 one character.
1160                 </para>
1161             </listitem>
1162             <listitem><para>Each element must only contain the ASCII characters 
1163                 "[A-Z][a-z][0-9]_-". Only elements that are part of a unique
1164                 connection name may begin with a digit, elements in
1165                 other bus names must not begin with a digit.
1166                 </para>
1167             </listitem>
1168
1169             <listitem><para>Bus names must contain at least one '.' (period)
1170               character (and thus at least two elements).
1171               </para></listitem>
1172
1173             <listitem><para>Bus names must not begin with a '.' (period) character.</para></listitem>
1174             <listitem><para>Bus names must not exceed the maximum name length.</para></listitem>
1175           </itemizedlist>
1176         </para>
1177         <para>
1178           Note that the hyphen ('-') character is allowed in bus names but
1179           not in interface names.
1180         </para>
1181       </sect3>
1182       <sect3 id="message-protocol-names-member">
1183         <title>Member names</title>
1184         <para>
1185           Member (i.e. method or signal) names:
1186           <itemizedlist>
1187             <listitem><para>Must only contain the ASCII characters
1188                 "[A-Z][a-z][0-9]_" and may not begin with a
1189                 digit.</para></listitem>
1190             <listitem><para>Must not contain the '.' (period) character.</para></listitem>
1191             <listitem><para>Must not exceed the maximum name length.</para></listitem>
1192             <listitem><para>Must be at least 1 byte in length.</para></listitem>
1193           </itemizedlist>
1194         </para>
1195       </sect3>
1196       <sect3 id="message-protocol-names-error">
1197         <title>Error names</title>
1198         <para>
1199           Error names have the same restrictions as interface names.
1200         </para>
1201       </sect3>
1202     </sect2>
1203
1204     <sect2 id="message-protocol-types">
1205       <title>Message Types</title>
1206       <para>
1207         Each of the message types (<literal>METHOD_CALL</literal>, <literal>METHOD_RETURN</literal>, <literal>ERROR</literal>, and
1208         <literal>SIGNAL</literal>) has its own expected usage conventions and header fields.
1209         This section describes these conventions.
1210       </para>
1211       <sect3 id="message-protocol-types-method">
1212         <title>Method Calls</title>
1213         <para>
1214           Some messages invoke an operation on a remote object.  These are
1215           called method call messages and have the type tag <literal>METHOD_CALL</literal>. Such
1216           messages map naturally to methods on objects in a typical program.
1217         </para>
1218         <para>
1219           A method call message is required to have a <literal>MEMBER</literal> header field
1220           indicating the name of the method. Optionally, the message has an
1221           <literal>INTERFACE</literal> field giving the interface the method is a part of. In the
1222           absence of an <literal>INTERFACE</literal> field, if two interfaces on the same object have
1223           a method with the same name, it is undefined which of the two methods
1224           will be invoked. Implementations may also choose to return an error in
1225           this ambiguous case. However, if a method name is unique
1226           implementations must not require an interface field.
1227         </para>
1228         <para>
1229           Method call messages also include a <literal>PATH</literal> field
1230           indicating the object to invoke the method on. If the call is passing
1231           through a message bus, the message will also have a
1232           <literal>DESTINATION</literal> field giving the name of the connection
1233           to receive the message.
1234         </para>
1235         <para>
1236           When an application handles a method call message, it is required to
1237           return a reply. The reply is identified by a <literal>REPLY_SERIAL</literal> header field
1238           indicating the serial number of the <literal>METHOD_CALL</literal> being replied to. The
1239           reply can have one of two types; either <literal>METHOD_RETURN</literal> or <literal>ERROR</literal>.
1240         </para>
1241         <para>
1242           If the reply has type <literal>METHOD_RETURN</literal>, the arguments to the reply message 
1243           are the return value(s) or "out parameters" of the method call. 
1244           If the reply has type <literal>ERROR</literal>, then an "exception" has been thrown, 
1245           and the call fails; no return value will be provided. It makes 
1246           no sense to send multiple replies to the same method call.
1247         </para>
1248         <para>
1249           Even if a method call has no return values, a <literal>METHOD_RETURN</literal> 
1250           reply is required, so the caller will know the method 
1251           was successfully processed.
1252         </para>
1253         <para>
1254           The <literal>METHOD_RETURN</literal> or <literal>ERROR</literal> reply message must have the <literal>REPLY_SERIAL</literal> 
1255           header field.
1256         </para>
1257         <para>
1258           If a <literal>METHOD_CALL</literal> message has the flag <literal>NO_REPLY_EXPECTED</literal>, 
1259           then as an optimization the application receiving the method 
1260           call may choose to omit the reply message (regardless of 
1261           whether the reply would have been <literal>METHOD_RETURN</literal> or <literal>ERROR</literal>). 
1262           However, it is also acceptable to ignore the <literal>NO_REPLY_EXPECTED</literal>
1263           flag and reply anyway.
1264         </para>
1265         <para>
1266           Unless a message has the flag <literal>NO_AUTO_START</literal>, if the
1267           destination name does not exist then a program to own the destination
1268           name will be started before the message is delivered.  The message
1269           will be held until the new program is successfully started or has
1270           failed to start; in case of failure, an error will be returned. This
1271           flag is only relevant in the context of a message bus, it is ignored
1272           during one-to-one communication with no intermediate bus.
1273         </para>
1274         <sect4 id="message-protocol-types-method-apis">
1275           <title>Mapping method calls to native APIs</title>
1276           <para>
1277             APIs for D-Bus may map method calls to a method call in a specific
1278             programming language, such as C++, or may map a method call written
1279             in an IDL to a D-Bus message.
1280           </para>
1281           <para>
1282             In APIs of this nature, arguments to a method are often termed "in"
1283             (which implies sent in the <literal>METHOD_CALL</literal>), or "out" (which implies
1284             returned in the <literal>METHOD_RETURN</literal>). Some APIs such as CORBA also have
1285             "inout" arguments, which are both sent and received, i.e. the caller
1286             passes in a value which is modified. Mapped to D-Bus, an "inout"
1287             argument is equivalent to an "in" argument, followed by an "out"
1288             argument. You can't pass things "by reference" over the wire, so
1289             "inout" is purely an illusion of the in-process API.
1290           </para>
1291           <para>
1292             Given a method with zero or one return values, followed by zero or more
1293             arguments, where each argument may be "in", "out", or "inout", the
1294             caller constructs a message by appending each "in" or "inout" argument,
1295             in order. "out" arguments are not represented in the caller's message.
1296           </para>
1297           <para>
1298             The recipient constructs a reply by appending first the return value 
1299             if any, then each "out" or "inout" argument, in order. 
1300             "in" arguments are not represented in the reply message.
1301           </para>
1302           <para>
1303             Error replies are normally mapped to exceptions in languages that have
1304             exceptions.
1305           </para>
1306           <para>
1307             In converting from native APIs to D-Bus, it is perhaps nice to 
1308             map D-Bus naming conventions ("FooBar") to native conventions 
1309             such as "fooBar" or "foo_bar" automatically. This is OK 
1310             as long as you can say that the native API is one that 
1311             was specifically written for D-Bus. It makes the most sense
1312             when writing object implementations that will be exported 
1313             over the bus. Object proxies used to invoke remote D-Bus 
1314             objects probably need the ability to call any D-Bus method,
1315             and thus a magic name mapping like this could be a problem.
1316           </para>
1317           <para>
1318             This specification doesn't require anything of native API bindings;
1319             the preceding is only a suggested convention for consistency 
1320             among bindings.
1321           </para>
1322         </sect4>
1323       </sect3>
1324
1325       <sect3 id="message-protocol-types-signal">
1326         <title>Signal Emission</title>
1327         <para>
1328           Unlike method calls, signal emissions have no replies. 
1329           A signal emission is simply a single message of type <literal>SIGNAL</literal>.
1330           It must have three header fields: <literal>PATH</literal> giving the object 
1331           the signal was emitted from, plus <literal>INTERFACE</literal> and <literal>MEMBER</literal> giving
1332           the fully-qualified name of the signal. The <literal>INTERFACE</literal> header is required
1333           for signals, though it is optional for method calls.
1334         </para>
1335       </sect3>
1336
1337       <sect3 id="message-protocol-types-errors">
1338         <title>Errors</title>
1339         <para>
1340           Messages of type <literal>ERROR</literal> are most commonly replies 
1341           to a <literal>METHOD_CALL</literal>, but may be returned in reply 
1342           to any kind of message. The message bus for example
1343           will return an <literal>ERROR</literal> in reply to a signal emission if 
1344           the bus does not have enough memory to send the signal.
1345         </para>
1346         <para>
1347           An <literal>ERROR</literal> may have any arguments, but if the first 
1348           argument is a <literal>STRING</literal>, it must be an error message.
1349           The error message may be logged or shown to the user
1350           in some way.
1351         </para>
1352       </sect3>
1353
1354       <sect3 id="message-protocol-types-notation">
1355         <title>Notation in this document</title>
1356         <para>
1357           This document uses a simple pseudo-IDL to describe particular method 
1358           calls and signals. Here is an example of a method call:
1359           <programlisting>
1360             org.freedesktop.DBus.StartServiceByName (in STRING name, in UINT32 flags,
1361                                                      out UINT32 resultcode)
1362           </programlisting>
1363           This means <literal>INTERFACE</literal> = org.freedesktop.DBus, <literal>MEMBER</literal> = StartServiceByName, 
1364           <literal>METHOD_CALL</literal> arguments are <literal>STRING</literal> and <literal>UINT32</literal>, <literal>METHOD_RETURN</literal> argument
1365           is <literal>UINT32</literal>. Remember that the <literal>MEMBER</literal> field can't contain any '.' (period)
1366           characters so it's known that the last part of the name in
1367           the "IDL" is the member name.
1368         </para>
1369         <para>
1370           In C++ that might end up looking like this:
1371           <programlisting>
1372             unsigned int org::freedesktop::DBus::StartServiceByName (const char  *name,
1373                                                                      unsigned int flags);
1374           </programlisting>
1375           or equally valid, the return value could be done as an argument:
1376           <programlisting>
1377             void org::freedesktop::DBus::StartServiceByName (const char   *name, 
1378                                                              unsigned int  flags,
1379                                                              unsigned int *resultcode);
1380           </programlisting>
1381           It's really up to the API designer how they want to make 
1382           this look. You could design an API where the namespace wasn't used 
1383           in C++, using STL or Qt, using varargs, or whatever you wanted.
1384         </para>
1385         <para>
1386           Signals are written as follows:
1387           <programlisting>
1388             org.freedesktop.DBus.NameLost (STRING name)
1389           </programlisting>
1390           Signals don't specify "in" vs. "out" because only 
1391           a single direction is possible.
1392         </para>
1393         <para>
1394           It isn't especially encouraged to use this lame pseudo-IDL in actual
1395           API implementations; you might use the native notation for the
1396           language you're using, or you might use COM or CORBA IDL, for example.
1397         </para>
1398       </sect3>
1399     </sect2>
1400
1401     <sect2 id="message-protocol-handling-invalid">
1402       <title>Invalid Protocol and Spec Extensions</title>
1403       
1404       <para>
1405         For security reasons, the D-Bus protocol should be strictly parsed and
1406         validated, with the exception of defined extension points. Any invalid
1407         protocol or spec violations should result in immediately dropping the
1408         connection without notice to the other end. Exceptions should be
1409         carefully considered, e.g. an exception may be warranted for a
1410         well-understood idiosyncrasy of a widely-deployed implementation.  In
1411         cases where the other end of a connection is 100% trusted and known to
1412         be friendly, skipping validation for performance reasons could also make
1413         sense in certain cases.
1414       </para>
1415
1416       <para>
1417         Generally speaking violations of the "must" requirements in this spec 
1418         should be considered possible attempts to exploit security, and violations 
1419         of the "should" suggestions should be considered legitimate (though perhaps
1420         they should generate an error in some cases).
1421       </para>
1422
1423       <para>
1424         The following extension points are built in to D-Bus on purpose and must
1425         not be treated as invalid protocol. The extension points are intended
1426         for use by future versions of this spec, they are not intended for third
1427         parties.  At the moment, the only way a third party could extend D-Bus
1428         without breaking interoperability would be to introduce a way to negotiate new
1429         feature support as part of the auth protocol, using EXTENSION_-prefixed
1430         commands. There is not yet a standard way to negotiate features.
1431         <itemizedlist>
1432           <listitem>
1433             <para>
1434               In the authentication protocol (see <xref linkend="auth-protocol"/>) unknown 
1435                 commands result in an ERROR rather than a disconnect. This enables 
1436                 future extensions to the protocol. Commands starting with EXTENSION_ are 
1437                 reserved for third parties.
1438             </para>
1439           </listitem>
1440           <listitem>
1441             <para>
1442               The authentication protocol supports pluggable auth mechanisms.
1443             </para>
1444           </listitem>
1445           <listitem>
1446             <para>
1447               The address format (see <xref linkend="addresses"/>) supports new
1448               kinds of transport.
1449             </para>
1450           </listitem>
1451           <listitem>
1452             <para>
1453               Messages with an unknown type (something other than
1454               <literal>METHOD_CALL</literal>, <literal>METHOD_RETURN</literal>,
1455               <literal>ERROR</literal>, <literal>SIGNAL</literal>) are ignored. 
1456               Unknown-type messages must still be well-formed in the same way 
1457               as the known messages, however. They still have the normal 
1458               header and body.
1459             </para>
1460           </listitem>
1461           <listitem>
1462             <para>
1463               Header fields with an unknown or unexpected field code must be ignored, 
1464               though again they must still be well-formed.
1465             </para>
1466           </listitem>
1467           <listitem>
1468             <para>
1469               New standard interfaces (with new methods and signals) can of course be added.
1470             </para>
1471           </listitem>
1472         </itemizedlist>
1473       </para>
1474
1475     </sect2>
1476
1477   </sect1>
1478
1479   <sect1 id="auth-protocol">
1480     <title>Authentication Protocol</title>
1481     <para>
1482       Before the flow of messages begins, two applications must
1483       authenticate. A simple plain-text protocol is used for
1484       authentication; this protocol is a SASL profile, and maps fairly
1485       directly from the SASL specification. The message encoding is
1486       NOT used here, only plain text messages.
1487     </para>
1488     <para>
1489       In examples, "C:" and "S:" indicate lines sent by the client and
1490       server respectively.
1491     </para>
1492     <sect2 id="auth-protocol-overview">
1493       <title>Protocol Overview</title>
1494       <para>
1495         The protocol is a line-based protocol, where each line ends with
1496         \r\n. Each line begins with an all-caps ASCII command name containing
1497         only the character range [A-Z_], a space, then any arguments for the
1498         command, then the \r\n ending the line. The protocol is
1499         case-sensitive. All bytes must be in the ASCII character set.
1500
1501         Commands from the client to the server are as follows:
1502
1503         <itemizedlist>
1504           <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
1505           <listitem><para>CANCEL</para></listitem>
1506           <listitem><para>BEGIN</para></listitem>
1507           <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
1508           <listitem><para>ERROR [human-readable error explanation]</para></listitem>
1509           <listitem><para>NEGOTIATE_UNIX_FD</para></listitem>
1510         </itemizedlist>
1511
1512         From server to client are as follows:
1513
1514         <itemizedlist>
1515           <listitem><para>REJECTED &lt;space-separated list of mechanism names&gt;</para></listitem>
1516           <listitem><para>OK &lt;GUID in hex&gt;</para></listitem>
1517           <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
1518           <listitem><para>ERROR</para></listitem>
1519           <listitem><para>AGREE_UNIX_FD</para></listitem>
1520         </itemizedlist>
1521       </para>
1522       <para>
1523         Unofficial extensions to the command set must begin with the letters 
1524         "EXTENSION_", to avoid conflicts with future official commands.
1525         For example, "EXTENSION_COM_MYDOMAIN_DO_STUFF".
1526       </para>
1527     </sect2>
1528     <sect2 id="auth-nul-byte">
1529       <title>Special credentials-passing nul byte</title>
1530       <para>
1531         Immediately after connecting to the server, the client must send a
1532         single nul byte. This byte may be accompanied by credentials
1533         information on some operating systems that use sendmsg() with
1534         SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
1535         sockets. However, the nul byte must be sent even on other kinds of
1536         socket, and even on operating systems that do not require a byte to be
1537         sent in order to transmit credentials. The text protocol described in
1538         this document begins after the single nul byte. If the first byte
1539         received from the client is not a nul byte, the server may disconnect 
1540         that client.
1541       </para>
1542       <para>
1543         A nul byte in any context other than the initial byte is an error; 
1544         the protocol is ASCII-only.
1545       </para>
1546       <para>
1547         The credentials sent along with the nul byte may be used with the 
1548         SASL mechanism EXTERNAL.
1549       </para>
1550     </sect2>
1551     <sect2 id="auth-command-auth">
1552       <title>AUTH command</title>
1553       <para>
1554         If an AUTH command has no arguments, it is a request to list
1555         available mechanisms. The server must respond with a REJECTED
1556         command listing the mechanisms it understands, or with an error.
1557       </para>
1558       <para>
1559         If an AUTH command specifies a mechanism, and the server supports
1560         said mechanism, the server should begin exchanging SASL
1561         challenge-response data with the client using DATA commands.
1562       </para>
1563       <para>
1564         If the server does not support the mechanism given in the AUTH
1565         command, it must send either a REJECTED command listing the mechanisms
1566         it does support, or an error.
1567       </para>
1568       <para>
1569         If the [initial-response] argument is provided, it is intended for use
1570         with mechanisms that have no initial challenge (or an empty initial
1571         challenge), as if it were the argument to an initial DATA command. If
1572         the selected mechanism has an initial challenge and [initial-response]
1573         was provided, the server should reject authentication by sending
1574         REJECTED.
1575       </para>
1576       <para>
1577         If authentication succeeds after exchanging DATA commands, 
1578         an OK command must be sent to the client.
1579       </para>
1580       <para>
1581         The first octet received by the server after the \r\n of the BEGIN
1582         command from the client must be the first octet of the
1583         authenticated/encrypted stream of D-Bus messages.
1584       </para>
1585       <para>
1586         If BEGIN is received by the server, the first octet received
1587         by the client after the \r\n of the OK command must be the
1588         first octet of the authenticated/encrypted stream of D-Bus
1589         messages.
1590       </para>
1591     </sect2>
1592     <sect2 id="auth-command-cancel">
1593       <title>CANCEL Command</title>
1594       <para>
1595         At any time up to sending the BEGIN command, the client may send a
1596         CANCEL command. On receiving the CANCEL command, the server must
1597         send a REJECTED command and abort the current authentication
1598         exchange.
1599       </para>
1600     </sect2>
1601     <sect2 id="auth-command-data">
1602       <title>DATA Command</title>
1603       <para>
1604         The DATA command may come from either client or server, and simply 
1605         contains a hex-encoded block of data to be interpreted 
1606         according to the SASL mechanism in use.
1607       </para>
1608       <para>
1609         Some SASL mechanisms support sending an "empty string"; 
1610         FIXME we need some way to do this.
1611       </para>
1612     </sect2>
1613     <sect2 id="auth-command-begin">
1614       <title>BEGIN Command</title>
1615       <para>
1616         The BEGIN command acknowledges that the client has received an 
1617         OK command from the server, and that the stream of messages
1618         is about to begin. 
1619       </para>
1620       <para>
1621         The first octet received by the server after the \r\n of the BEGIN
1622         command from the client must be the first octet of the
1623         authenticated/encrypted stream of D-Bus messages.
1624       </para>
1625     </sect2>
1626     <sect2 id="auth-command-rejected">
1627       <title>REJECTED Command</title>
1628       <para>
1629         The REJECTED command indicates that the current authentication
1630         exchange has failed, and further exchange of DATA is inappropriate.
1631         The client would normally try another mechanism, or try providing
1632         different responses to challenges.
1633       </para><para>
1634         Optionally, the REJECTED command has a space-separated list of
1635         available auth mechanisms as arguments. If a server ever provides
1636         a list of supported mechanisms, it must provide the same list 
1637         each time it sends a REJECTED message. Clients are free to 
1638         ignore all lists received after the first.
1639       </para>
1640     </sect2>
1641     <sect2 id="auth-command-ok">
1642       <title>OK Command</title>
1643       <para>
1644         The OK command indicates that the client has been
1645         authenticated. The client may now proceed with negotiating
1646         Unix file descriptor passing. To do that it shall send
1647         NEGOTIATE_UNIX_FD to the server.
1648       </para>
1649       <para>
1650         Otherwise, the client must respond to the OK command by
1651         sending a BEGIN command, followed by its stream of messages,
1652         or by disconnecting.  The server must not accept additional
1653         commands using this protocol after the BEGIN command has been
1654         received. Further communication will be a stream of D-Bus
1655         messages (optionally encrypted, as negotiated) rather than
1656         this protocol.
1657       </para>
1658       <para>
1659         If a client sends BEGIN the first octet received by the client
1660         after the \r\n of the OK command must be the first octet of
1661         the authenticated/encrypted stream of D-Bus messages.
1662       </para>
1663       <para>
1664         The OK command has one argument, which is the GUID of the server.
1665         See <xref linkend="addresses"/> for more on server GUIDs.
1666       </para>
1667     </sect2>
1668     <sect2 id="auth-command-error">
1669       <title>ERROR Command</title>
1670       <para>
1671         The ERROR command indicates that either server or client did not
1672         know a command, does not accept the given command in the current
1673         context, or did not understand the arguments to the command. This
1674         allows the protocol to be extended; a client or server can send a
1675         command present or permitted only in new protocol versions, and if
1676         an ERROR is received instead of an appropriate response, fall back
1677         to using some other technique.
1678       </para>
1679       <para>
1680         If an ERROR is sent, the server or client that sent the
1681         error must continue as if the command causing the ERROR had never been
1682         received. However, the the server or client receiving the error 
1683         should try something other than whatever caused the error; 
1684         if only canceling/rejecting the authentication.
1685       </para>
1686       <para>
1687         If the D-Bus protocol changes incompatibly at some future time,
1688         applications implementing the new protocol would probably be able to
1689         check for support of the new protocol by sending a new command and
1690         receiving an ERROR from applications that don't understand it. Thus the
1691         ERROR feature of the auth protocol is an escape hatch that lets us
1692         negotiate extensions or changes to the D-Bus protocol in the future.
1693       </para>
1694     </sect2>
1695     <sect2 id="auth-command-negotiate-unix-fd">
1696       <title>NEGOTIATE_UNIX_FD Command</title>
1697       <para>
1698         The NEGOTIATE_UNIX_FD command indicates that the client
1699         supports Unix file descriptor passing. This command may only
1700         be sent after the connection is authenticated, i.e. after OK
1701         was received by the client. This command may only be sent on
1702         transports that support Unix file descriptor passing.
1703       </para>
1704       <para>
1705         On receiving NEGOTIATE_UNIX_FD the server must respond with
1706         either AGREE_UNIX_FD or ERROR. It shall respond the former if
1707         the transport chosen supports Unix file descriptor passing and
1708         the server supports this feature. It shall respond the latter
1709         if the transport does not support Unix file descriptor
1710         passing, the server does not support this feature, or the
1711         server decides not to enable file descriptor passing due to
1712         security or other reasons.
1713       </para>
1714     </sect2>
1715     <sect2 id="auth-command-agree-unix-fd">
1716       <title>AGREE_UNIX_FD Command</title>
1717       <para>
1718         The AGREE_UNIX_FD command indicates that the server supports
1719         Unix file descriptor passing. This command may only be sent
1720         after the connection is authenticated, and the client sent
1721         NEGOTIATE_UNIX_FD to enable Unix file descriptor passing. This
1722         command may only be sent on transports that support Unix file
1723         descriptor passing.
1724       </para>
1725       <para>
1726         On receiving AGREE_UNIX_FD the client must respond with BEGIN,
1727         followed by its stream of messages, or by disconnecting.  The
1728         server must not accept additional commands using this protocol
1729         after the BEGIN command has been received. Further
1730         communication will be a stream of D-Bus messages (optionally
1731         encrypted, as negotiated) rather than this protocol.
1732       </para>
1733     </sect2>
1734     <sect2 id="auth-command-future">
1735       <title>Future Extensions</title>
1736       <para>
1737         Future extensions to the authentication and negotiation
1738         protocol are possible. For that new commands may be
1739         introduced. If a client or server receives an unknown command
1740         it shall respond with ERROR and not consider this fatal. New
1741         commands may be introduced both before, and after
1742         authentication, i.e. both before and after the OK command.
1743       </para>
1744     </sect2>
1745     <sect2 id="auth-examples">
1746       <title>Authentication examples</title>
1747       
1748       <para>
1749         <figure>
1750           <title>Example of successful magic cookie authentication</title>
1751           <programlisting>
1752             (MAGIC_COOKIE is a made up mechanism)
1753
1754             C: AUTH MAGIC_COOKIE 3138363935333137393635383634
1755             S: OK 1234deadbeef
1756             C: BEGIN
1757           </programlisting>
1758         </figure>
1759         <figure>
1760           <title>Example of finding out mechanisms then picking one</title>
1761           <programlisting>
1762             C: AUTH
1763             S: REJECTED KERBEROS_V4 SKEY
1764             C: AUTH SKEY 7ab83f32ee
1765             S: DATA 8799cabb2ea93e
1766             C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1767             S: OK 1234deadbeef
1768             C: BEGIN
1769           </programlisting>
1770         </figure>
1771         <figure>
1772           <title>Example of client sends unknown command then falls back to regular auth</title>
1773           <programlisting>
1774             C: FOOBAR
1775             S: ERROR
1776             C: AUTH MAGIC_COOKIE 3736343435313230333039
1777             S: OK 1234deadbeef
1778             C: BEGIN
1779           </programlisting>
1780         </figure>
1781         <figure>
1782           <title>Example of server doesn't support initial auth mechanism</title>
1783           <programlisting>
1784             C: AUTH MAGIC_COOKIE 3736343435313230333039
1785             S: REJECTED KERBEROS_V4 SKEY
1786             C: AUTH SKEY 7ab83f32ee
1787             S: DATA 8799cabb2ea93e
1788             C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1789             S: OK 1234deadbeef
1790             C: BEGIN
1791           </programlisting>
1792         </figure>
1793         <figure>
1794           <title>Example of wrong password or the like followed by successful retry</title>
1795           <programlisting>
1796             C: AUTH MAGIC_COOKIE 3736343435313230333039
1797             S: REJECTED KERBEROS_V4 SKEY
1798             C: AUTH SKEY 7ab83f32ee
1799             S: DATA 8799cabb2ea93e
1800             C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1801             S: REJECTED
1802             C: AUTH SKEY 7ab83f32ee
1803             S: DATA 8799cabb2ea93e
1804             C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1805             S: OK 1234deadbeef
1806             C: BEGIN
1807           </programlisting>
1808         </figure>
1809         <figure>
1810           <title>Example of skey cancelled and restarted</title>
1811           <programlisting>
1812             C: AUTH MAGIC_COOKIE 3736343435313230333039
1813             S: REJECTED KERBEROS_V4 SKEY
1814             C: AUTH SKEY 7ab83f32ee
1815             S: DATA 8799cabb2ea93e
1816             C: CANCEL
1817             S: REJECTED
1818             C: AUTH SKEY 7ab83f32ee
1819             S: DATA 8799cabb2ea93e
1820             C: DATA 8ac876e8f68ee9809bfa876e6f9876g8fa8e76e98f
1821             S: OK 1234deadbeef
1822             C: BEGIN
1823           </programlisting>
1824         </figure>
1825         <figure>
1826           <title>Example of successful magic cookie authentication with successful negotiation of Unix FD passing</title>
1827           <programlisting>
1828             (MAGIC_COOKIE is a made up mechanism)
1829
1830             C: AUTH MAGIC_COOKIE 3138363935333137393635383634
1831             S: OK 1234deadbeef
1832             C: NEGOTIATE_UNIX_FD
1833             S: AGREE_UNIX_FD
1834             C: BEGIN
1835           </programlisting>
1836         </figure>
1837         <figure>
1838           <title>Example of successful magic cookie authentication with unsuccessful negotiation of Unix FD passing</title>
1839           <programlisting>
1840             (MAGIC_COOKIE is a made up mechanism)
1841
1842             C: AUTH MAGIC_COOKIE 3138363935333137393635383634
1843             S: OK 1234deadbeef
1844             C: NEGOTIATE_UNIX_FD
1845             S: ERROR
1846             C: BEGIN
1847           </programlisting>
1848         </figure>
1849       </para>
1850     </sect2>
1851     <sect2 id="auth-states">
1852       <title>Authentication state diagrams</title>
1853       
1854       <para>
1855         This section documents the auth protocol in terms of 
1856         a state machine for the client and the server. This is 
1857         probably the most robust way to implement the protocol.
1858       </para>
1859
1860       <sect3 id="auth-states-client">
1861         <title>Client states</title>
1862         
1863         <para>
1864           To more precisely describe the interaction between the
1865           protocol state machine and the authentication mechanisms the
1866           following notation is used: MECH(CHALL) means that the
1867           server challenge CHALL was fed to the mechanism MECH, which
1868           returns one of
1869
1870           <itemizedlist>
1871             <listitem>
1872               <para>
1873                 CONTINUE(RESP) means continue the auth conversation
1874                 and send RESP as the response to the server;
1875               </para>
1876             </listitem>
1877
1878             <listitem>
1879               <para>
1880                 OK(RESP) means that after sending RESP to the server
1881                 the client side of the auth conversation is finished
1882                 and the server should return "OK";
1883               </para>
1884             </listitem>
1885
1886             <listitem>
1887               <para>
1888                 ERROR means that CHALL was invalid and could not be
1889                 processed.
1890               </para>
1891             </listitem>
1892           </itemizedlist>
1893           
1894           Both RESP and CHALL may be empty.
1895         </para>
1896         
1897         <para>
1898           The Client starts by getting an initial response from the
1899           default mechanism and sends AUTH MECH RESP, or AUTH MECH if
1900           the mechanism did not provide an initial response.  If the
1901           mechanism returns CONTINUE, the client starts in state
1902           <emphasis>WaitingForData</emphasis>, if the mechanism
1903           returns OK the client starts in state
1904           <emphasis>WaitingForOK</emphasis>.
1905         </para>
1906         
1907         <para>
1908           The client should keep track of available mechanisms and
1909           which it mechanisms it has already attempted. This list is
1910           used to decide which AUTH command to send. When the list is
1911           exhausted, the client should give up and close the
1912           connection.
1913         </para>
1914
1915         <formalpara>
1916           <title><emphasis>WaitingForData</emphasis></title>
1917           <para>
1918             <itemizedlist>
1919               <listitem>
1920                 <para>
1921                   Receive DATA CHALL
1922                   <simplelist>
1923                     <member>
1924                       MECH(CHALL) returns CONTINUE(RESP) &rarr; send
1925                       DATA RESP, goto
1926                       <emphasis>WaitingForData</emphasis>
1927                     </member>
1928
1929                     <member>
1930                       MECH(CHALL) returns OK(RESP) &rarr; send DATA
1931                       RESP, goto <emphasis>WaitingForOK</emphasis>
1932                     </member>
1933
1934                     <member>
1935                       MECH(CHALL) returns ERROR &rarr; send ERROR
1936                       [msg], goto <emphasis>WaitingForData</emphasis>
1937                     </member>
1938                   </simplelist>
1939                 </para>
1940               </listitem>
1941
1942               <listitem>
1943                 <para>
1944                   Receive REJECTED [mechs] &rarr;
1945                   send AUTH [next mech], goto
1946                   WaitingForData or <emphasis>WaitingForOK</emphasis>
1947                 </para>
1948               </listitem>
1949               <listitem>
1950                 <para>
1951                   Receive ERROR &rarr; send
1952                   CANCEL, goto
1953                   <emphasis>WaitingForReject</emphasis>
1954                 </para>
1955               </listitem>
1956               <listitem>
1957                 <para>
1958                   Receive OK &rarr; send
1959                   BEGIN, terminate auth
1960                   conversation, authenticated
1961                 </para>
1962               </listitem>
1963               <listitem>
1964                 <para>
1965                   Receive anything else &rarr; send
1966                   ERROR, goto
1967                   <emphasis>WaitingForData</emphasis>
1968                 </para>
1969               </listitem>
1970             </itemizedlist>
1971           </para>
1972         </formalpara>
1973
1974         <formalpara>
1975           <title><emphasis>WaitingForOK</emphasis></title>
1976           <para>
1977             <itemizedlist>
1978               <listitem>
1979                 <para>
1980                   Receive OK &rarr; send BEGIN, terminate auth
1981                   conversation, <emphasis>authenticated</emphasis>
1982                 </para>
1983               </listitem>
1984               <listitem>
1985                 <para>
1986                   Receive REJECT [mechs] &rarr; send AUTH [next mech],
1987                   goto <emphasis>WaitingForData</emphasis> or
1988                   <emphasis>WaitingForOK</emphasis>
1989                 </para>
1990               </listitem>
1991
1992               <listitem>
1993                 <para>
1994                   Receive DATA &rarr; send CANCEL, goto
1995                   <emphasis>WaitingForReject</emphasis>
1996                 </para>
1997               </listitem>
1998
1999               <listitem>
2000                 <para>
2001                   Receive ERROR &rarr; send CANCEL, goto
2002                   <emphasis>WaitingForReject</emphasis>
2003                 </para>
2004               </listitem>
2005
2006               <listitem>
2007                 <para>
2008                   Receive anything else &rarr; send ERROR, goto
2009                   <emphasis>WaitingForOK</emphasis>
2010                 </para>
2011               </listitem>
2012             </itemizedlist>
2013           </para>
2014         </formalpara>
2015
2016         <formalpara>
2017           <title><emphasis>WaitingForReject</emphasis></title>
2018           <para>
2019             <itemizedlist>
2020               <listitem>
2021                 <para>
2022                   Receive REJECT [mechs] &rarr; send AUTH [next mech],
2023                   goto <emphasis>WaitingForData</emphasis> or
2024                   <emphasis>WaitingForOK</emphasis>
2025                 </para>
2026               </listitem>
2027
2028               <listitem>
2029                 <para>
2030                   Receive anything else &rarr; terminate auth
2031                   conversation, disconnect
2032                 </para>
2033               </listitem>
2034             </itemizedlist>
2035           </para>
2036         </formalpara>
2037
2038       </sect3>
2039
2040       <sect3 id="auth-states-server">
2041         <title>Server states</title>
2042  
2043         <para>
2044           For the server MECH(RESP) means that the client response
2045           RESP was fed to the the mechanism MECH, which returns one of
2046
2047           <itemizedlist>
2048             <listitem>
2049               <para>
2050                 CONTINUE(CHALL) means continue the auth conversation and
2051                 send CHALL as the challenge to the client;
2052               </para>
2053             </listitem>
2054
2055             <listitem>
2056               <para>
2057                 OK means that the client has been successfully
2058                 authenticated;
2059               </para>
2060             </listitem>
2061
2062             <listitem>
2063               <para>
2064                 REJECT means that the client failed to authenticate or
2065                 there was an error in RESP.
2066               </para>
2067             </listitem>
2068           </itemizedlist>
2069
2070           The server starts out in state
2071           <emphasis>WaitingForAuth</emphasis>.  If the client is
2072           rejected too many times the server must disconnect the
2073           client.
2074         </para>
2075
2076         <formalpara>
2077           <title><emphasis>WaitingForAuth</emphasis></title>
2078           <para>
2079             <itemizedlist>
2080
2081               <listitem>
2082                 <para>
2083                   Receive AUTH &rarr; send REJECTED [mechs], goto
2084                   <emphasis>WaitingForAuth</emphasis>
2085                 </para>
2086               </listitem>
2087
2088               <listitem>
2089                 <para>
2090                   Receive AUTH MECH RESP
2091
2092                   <simplelist>
2093                     <member>
2094                       MECH not valid mechanism &rarr; send REJECTED
2095                       [mechs], goto
2096                       <emphasis>WaitingForAuth</emphasis>
2097                     </member>
2098
2099                     <member>
2100                       MECH(RESP) returns CONTINUE(CHALL) &rarr; send
2101                       DATA CHALL, goto
2102                       <emphasis>WaitingForData</emphasis>
2103                     </member>
2104
2105                     <member>
2106                       MECH(RESP) returns OK &rarr; send OK, goto
2107                       <emphasis>WaitingForBegin</emphasis>
2108                     </member>
2109
2110                     <member>
2111                       MECH(RESP) returns REJECT &rarr; send REJECTED
2112                       [mechs], goto
2113                       <emphasis>WaitingForAuth</emphasis>
2114                     </member>
2115                   </simplelist>
2116                 </para>
2117               </listitem>
2118
2119               <listitem>
2120                 <para>
2121                   Receive BEGIN &rarr; terminate
2122                   auth conversation, disconnect
2123                 </para>
2124               </listitem>
2125
2126               <listitem>
2127                 <para>
2128                   Receive ERROR &rarr; send REJECTED [mechs], goto
2129                   <emphasis>WaitingForAuth</emphasis>
2130                 </para>
2131               </listitem>
2132
2133               <listitem>
2134                 <para>
2135                   Receive anything else &rarr; send
2136                   ERROR, goto
2137                   <emphasis>WaitingForAuth</emphasis>
2138                 </para>
2139               </listitem>
2140             </itemizedlist>
2141           </para>
2142         </formalpara>
2143
2144        
2145         <formalpara>
2146           <title><emphasis>WaitingForData</emphasis></title>
2147           <para>
2148             <itemizedlist>
2149               <listitem>
2150                 <para>
2151                   Receive DATA RESP
2152                   <simplelist>
2153                     <member>
2154                       MECH(RESP) returns CONTINUE(CHALL) &rarr; send
2155                       DATA CHALL, goto
2156                       <emphasis>WaitingForData</emphasis>
2157                     </member>
2158
2159                     <member>
2160                       MECH(RESP) returns OK &rarr; send OK, goto
2161                       <emphasis>WaitingForBegin</emphasis>
2162                     </member>
2163
2164                     <member>
2165                       MECH(RESP) returns REJECT &rarr; send REJECTED
2166                       [mechs], goto
2167                       <emphasis>WaitingForAuth</emphasis>
2168                     </member>
2169                   </simplelist>
2170                 </para>
2171               </listitem>
2172
2173               <listitem>
2174                 <para>
2175                   Receive BEGIN &rarr; terminate auth conversation,
2176                   disconnect
2177                 </para>
2178               </listitem>
2179
2180               <listitem>
2181                 <para>
2182                   Receive CANCEL &rarr; send REJECTED [mechs], goto
2183                   <emphasis>WaitingForAuth</emphasis>
2184                 </para>
2185               </listitem>
2186
2187               <listitem>
2188                 <para>
2189                   Receive ERROR &rarr; send REJECTED [mechs], goto
2190                   <emphasis>WaitingForAuth</emphasis>
2191                 </para>
2192               </listitem>
2193
2194               <listitem>
2195                 <para>
2196                   Receive anything else &rarr; send ERROR, goto
2197                   <emphasis>WaitingForData</emphasis>
2198                 </para>
2199               </listitem>
2200             </itemizedlist>
2201           </para>
2202         </formalpara>
2203
2204         <formalpara>
2205           <title><emphasis>WaitingForBegin</emphasis></title>
2206           <para>
2207             <itemizedlist>
2208               <listitem>
2209                 <para>
2210                   Receive BEGIN &rarr; terminate auth conversation,
2211                   client authenticated
2212                 </para>
2213               </listitem>
2214
2215               <listitem>
2216                 <para>
2217                   Receive CANCEL &rarr; send REJECTED [mechs], goto
2218                   <emphasis>WaitingForAuth</emphasis>
2219                 </para>
2220               </listitem>
2221
2222               <listitem>
2223                 <para>
2224                   Receive ERROR &rarr; send REJECTED [mechs], goto
2225                   <emphasis>WaitingForAuth</emphasis>
2226                 </para>
2227               </listitem>
2228
2229               <listitem>
2230                 <para>
2231                   Receive anything else &rarr; send ERROR, goto
2232                   <emphasis>WaitingForBegin</emphasis>
2233                 </para>
2234               </listitem>
2235             </itemizedlist>
2236           </para>
2237         </formalpara>
2238
2239       </sect3>
2240       
2241     </sect2>
2242     <sect2 id="auth-mechanisms">
2243       <title>Authentication mechanisms</title>
2244       <para>
2245         This section describes some new authentication mechanisms.
2246         D-Bus also allows any standard SASL mechanism of course.
2247       </para>
2248       <sect3 id="auth-mechanisms-sha">
2249         <title>DBUS_COOKIE_SHA1</title>
2250         <para>
2251           The DBUS_COOKIE_SHA1 mechanism is designed to establish that a client
2252           has the ability to read a private file owned by the user being
2253           authenticated. If the client can prove that it has access to a secret
2254           cookie stored in this file, then the client is authenticated. 
2255           Thus the security of DBUS_COOKIE_SHA1 depends on a secure home 
2256           directory.
2257         </para>
2258         <para>
2259           Throughout this description, "hex encoding" must output the digits
2260           from a to f in lower-case; the digits A to F must not be used
2261           in the DBUS_COOKIE_SHA1 mechanism.
2262         </para>
2263         <para>
2264           Authentication proceeds as follows:
2265           <itemizedlist>
2266             <listitem>
2267               <para>
2268                 The client sends the username it would like to authenticate 
2269                 as, hex-encoded.
2270               </para>
2271             </listitem>
2272             <listitem>
2273               <para>
2274                 The server sends the name of its "cookie context" (see below); a
2275                 space character; the integer ID of the secret cookie the client
2276                 must demonstrate knowledge of; a space character; then a
2277                 randomly-generated challenge string, all of this hex-encoded into
2278                 one, single string.
2279               </para>
2280             </listitem>
2281             <listitem>
2282               <para>
2283                 The client locates the cookie and generates its own
2284                 randomly-generated challenge string. The client then concatenates
2285                 the server's decoded challenge, a ":" character, its own challenge,
2286                 another ":" character, and the cookie. It computes the SHA-1 hash
2287                 of this composite string as a hex digest. It concatenates the
2288                 client's challenge string, a space character, and the SHA-1 hex
2289                 digest, hex-encodes the result and sends it back to the server.
2290               </para>
2291             </listitem>
2292             <listitem>
2293               <para>
2294                 The server generates the same concatenated string used by the
2295                 client and computes its SHA-1 hash. It compares the hash with
2296                 the hash received from the client; if the two hashes match, the
2297                 client is authenticated.
2298               </para>
2299             </listitem>
2300           </itemizedlist>
2301         </para>
2302         <para>
2303           Each server has a "cookie context," which is a name that identifies a
2304           set of cookies that apply to that server. A sample context might be
2305           "org_freedesktop_session_bus". Context names must be valid ASCII,
2306           nonzero length, and may not contain the characters slash ("/"),
2307           backslash ("\"), space (" "), newline ("\n"), carriage return ("\r"),
2308           tab ("\t"), or period ("."). There is a default context,
2309           "org_freedesktop_general" that's used by servers that do not specify
2310           otherwise.
2311         </para>
2312         <para>
2313           Cookies are stored in a user's home directory, in the directory
2314           <filename>~/.dbus-keyrings/</filename>. This directory must 
2315           not be readable or writable by other users. If it is, 
2316           clients and servers must ignore it. The directory 
2317           contains cookie files named after the cookie context.
2318         </para>
2319         <para>
2320           A cookie file contains one cookie per line. Each line 
2321           has three space-separated fields:
2322           <itemizedlist>
2323             <listitem>
2324               <para>
2325                 The cookie ID number, which must be a non-negative integer and
2326                 may not be used twice in the same file.
2327               </para>
2328             </listitem>
2329             <listitem>
2330               <para>
2331                 The cookie's creation time, in UNIX seconds-since-the-epoch
2332                 format.
2333               </para>
2334             </listitem>
2335             <listitem>
2336               <para>
2337                 The cookie itself, a hex-encoded random block of bytes. The cookie
2338                 may be of any length, though obviously security increases 
2339                 as the length increases.
2340               </para>
2341             </listitem>
2342           </itemizedlist>
2343         </para>
2344         <para>
2345           Only server processes modify the cookie file.
2346           They must do so with this procedure:
2347           <itemizedlist>
2348             <listitem>
2349               <para>
2350                 Create a lockfile name by appending ".lock" to the name of the
2351                 cookie file.  The server should attempt to create this file
2352                 using <literal>O_CREAT | O_EXCL</literal>.  If file creation
2353                 fails, the lock fails. Servers should retry for a reasonable
2354                 period of time, then they may choose to delete an existing lock
2355                 to keep users from having to manually delete a stale
2356                 lock. <footnote><para>Lockfiles are used instead of real file
2357                 locking <literal>fcntl()</literal> because real locking
2358                 implementations are still flaky on network
2359                 filesystems.</para></footnote>
2360               </para>
2361             </listitem>
2362             <listitem>
2363               <para>
2364                 Once the lockfile has been created, the server loads the cookie
2365                 file. It should then delete any cookies that are old (the
2366                 timeout can be fairly short), or more than a reasonable
2367                 time in the future (so that cookies never accidentally 
2368                 become permanent, if the clock was set far into the future 
2369                 at some point). If no recent keys remain, the 
2370                 server may generate a new key.
2371               </para>
2372             </listitem>
2373             <listitem>
2374               <para>
2375                 The pruned and possibly added-to cookie file 
2376                 must be resaved atomically (using a temporary 
2377                 file which is rename()'d).
2378               </para>
2379             </listitem>
2380             <listitem>
2381               <para>
2382                 The lock must be dropped by deleting the lockfile.
2383               </para>
2384             </listitem>
2385           </itemizedlist>
2386         </para>
2387         <para>
2388           Clients need not lock the file in order to load it, 
2389           because servers are required to save the file atomically.          
2390         </para>
2391       </sect3>
2392     </sect2>
2393   </sect1>
2394   <sect1 id="addresses">
2395     <title>Server Addresses</title>
2396     <para>
2397       Server addresses consist of a transport name followed by a colon, and
2398       then an optional, comma-separated list of keys and values in the form key=value.
2399       Each value is escaped.
2400     </para>
2401     <para>
2402       For example: 
2403       <programlisting>unix:path=/tmp/dbus-test</programlisting>
2404       Which is the address to a unix socket with the path /tmp/dbus-test.
2405     </para>
2406     <para>
2407       Value escaping is similar to URI escaping but simpler.
2408       <itemizedlist>
2409         <listitem>
2410           <para>
2411             The set of optionally-escaped bytes is:
2412             <literal>[0-9A-Za-z_-/.\]</literal>. To escape, each
2413             <emphasis>byte</emphasis> (note, not character) which is not in the
2414             set of optionally-escaped bytes must be replaced with an ASCII
2415             percent (<literal>%</literal>) and the value of the byte in hex.
2416             The hex value must always be two digits, even if the first digit is
2417             zero. The optionally-escaped bytes may be escaped if desired.
2418           </para>
2419         </listitem>
2420         <listitem>
2421           <para>
2422             To unescape, append each byte in the value; if a byte is an ASCII
2423             percent (<literal>%</literal>) character then append the following
2424             hex value instead. It is an error if a <literal>%</literal> byte
2425             does not have two hex digits following. It is an error if a
2426             non-optionally-escaped byte is seen unescaped.
2427           </para>
2428         </listitem>
2429       </itemizedlist>
2430       The set of optionally-escaped bytes is intended to preserve address 
2431       readability and convenience.
2432     </para>
2433
2434     <para>
2435       A server may specify a key-value pair with the key <literal>guid</literal>
2436       and the value a hex-encoded 16-byte sequence. <xref linkend="uuids"/>
2437       describes the format of the <literal>guid</literal> field.  If present,
2438       this UUID may be used to distinguish one server address from another. A
2439       server should use a different UUID for each address it listens on. For
2440       example, if a message bus daemon offers both UNIX domain socket and TCP
2441       connections, but treats clients the same regardless of how they connect,
2442       those two connections are equivalent post-connection but should have
2443       distinct UUIDs to distinguish the kinds of connection.
2444     </para>
2445     
2446     <para>
2447       The intent of the address UUID feature is to allow a client to avoid
2448       opening multiple identical connections to the same server, by allowing the
2449       client to check whether an address corresponds to an already-existing
2450       connection.  Comparing two addresses is insufficient, because addresses
2451       can be recycled by distinct servers, and equivalent addresses may look
2452       different if simply compared as strings (for example, the host in a TCP
2453       address can be given as an IP address or as a hostname).
2454     </para>
2455
2456     <para>
2457       Note that the address key is <literal>guid</literal> even though the 
2458       rest of the API and documentation says "UUID," for historical reasons.
2459     </para>
2460
2461     <para>
2462       [FIXME clarify if attempting to connect to each is a requirement 
2463       or just a suggestion]
2464       When connecting to a server, multiple server addresses can be
2465       separated by a semi-colon. The library will then try to connect
2466       to the first address and if that fails, it'll try to connect to
2467       the next one specified, and so forth. For example
2468       <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
2469     </para>
2470
2471   </sect1>
2472   
2473   <sect1 id="transports">
2474     <title>Transports</title>
2475     <para>
2476       [FIXME we need to specify in detail each transport and its possible arguments]
2477     
2478       Current transports include: unix domain sockets (including 
2479       abstract namespace on linux), launchd, TCP/IP, and a debug/testing transport
2480       using in-process pipes. Future possible transports include one that
2481       tunnels over X11 protocol.
2482     </para>
2483   
2484     <sect2 id="transports-unix-domain-sockets">
2485       <title>Unix Domain Sockets</title>
2486       <para>
2487         Unix domain sockets can be either paths in the file system or on Linux 
2488         kernels, they can be abstract which are similar to paths but
2489         do not show up in the file system.  
2490       </para>
2491
2492       <para>
2493         When a socket is opened by the D-Bus library it truncates the path 
2494         name right before the first trailing Nul byte.  This is true for both
2495         normal paths and abstract paths.  Note that this is a departure from
2496         previous versions of D-Bus that would create sockets with a fixed 
2497         length path name.  Names which were shorter than the fixed length
2498         would be padded by Nul bytes.
2499       </para>
2500       <para>
2501         Unix domain sockets are not available on windows. 
2502       </para>
2503       <sect3 id="transports-unix-domain-sockets-addresses">
2504         <title>Server Address Format</title>
2505         <para> 
2506           Unix domain socket addresses are identified by the "unix:" prefix 
2507           and support the following key/value pairs:
2508         </para>
2509         <informaltable>
2510          <tgroup cols="3">
2511           <thead>
2512            <row>
2513             <entry>Name</entry>
2514             <entry>Values</entry>
2515             <entry>Description</entry>
2516            </row>
2517           </thead>
2518           <tbody>
2519            <row>
2520             <entry>path</entry>
2521             <entry>(path)</entry>
2522             <entry>path of the unix domain socket. If set, the "tmpdir" and "abstract" key must not be set.</entry>
2523           </row>
2524           <row>
2525             <entry>tmpdir</entry>
2526             <entry>(path)</entry>
2527             <entry>temporary directory in which a socket file with a random file name starting with 'dbus-' will be created by the server. This key can only be used in server addresses, not in client addresses. If set, the "path" and "abstract" key must not be set.</entry>
2528           </row>
2529           <row>
2530             <entry>abstract</entry>
2531             <entry>(string)</entry>
2532             <entry>unique string (path) in the abstract namespace. If set, the "path" or "tempdir" key must not be set.</entry>
2533           </row>
2534         </tbody>
2535         </tgroup>
2536        </informaltable>
2537       </sect3>
2538     </sect2>
2539     <sect2 id="transports-launchd">
2540       <title>launchd</title>
2541       <para>
2542         launchd is a open-source server management system that replaces init, inetd
2543         and cron on Apple Mac OS X versions 10.4 and above. It provides a common session
2544         bus address for each user and deprecates the X11-enabled D-Bus launcher on OSX.
2545       </para>
2546
2547       <para>
2548         launchd allocates a socket and provides it with the unix path through the
2549         DBUS_LAUNCHD_SESSION_BUS_SOCKET variable in launchd's environment. Every process
2550         spawned by launchd (or dbus-daemon, if it was started by launchd) can access
2551         it through its environment.
2552         Other processes can query for the launchd socket by executing:
2553         $ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET
2554         This is normally done by the D-Bus client library so doesn't have to be done
2555         manually.
2556       </para>
2557       <para>
2558         launchd is not available on Microsoft Windows.
2559       </para>
2560       <sect3 id="transports-launchd-addresses">
2561         <title>Server Address Format</title>
2562         <para>
2563           launchd addresses are identified by the "launchd:" prefix
2564           and support the following key/value pairs:
2565         </para>
2566         <informaltable>
2567          <tgroup cols="3">
2568           <thead>
2569            <row>
2570             <entry>Name</entry>
2571             <entry>Values</entry>
2572             <entry>Description</entry>
2573            </row>
2574           </thead>
2575           <tbody>
2576            <row>
2577             <entry>env</entry>
2578             <entry>(environment variable)</entry>
2579             <entry>path of the unix domain socket for the launchd created dbus-daemon.</entry>
2580           </row>
2581         </tbody>
2582         </tgroup>
2583        </informaltable>
2584       </sect3>
2585     </sect2>
2586     <sect2 id="transports-tcp-sockets">
2587       <title>TCP Sockets</title>
2588       <para>
2589         The tcp transport provides TCP/IP based connections between clients
2590         located on the same or different hosts. 
2591       </para>
2592       <para>
2593         Using tcp transport without any additional secure authentification mechanismus 
2594         over a network is unsecure. 
2595       </para>
2596       <para>  
2597         Windows notes: Because of the tcp stack on windows does not provide sending 
2598         credentials over a tcp connection, the EXTERNAL authentification 
2599         mechanismus does not work. 
2600       </para>
2601       <sect3 id="transports-tcp-sockets-addresses">
2602         <title>Server Address Format</title>
2603         <para> 
2604          TCP/IP socket addresses are identified by the "tcp:" prefix 
2605          and support the following key/value pairs:
2606         </para>
2607         <informaltable>
2608          <tgroup cols="3">
2609           <thead>
2610            <row>
2611             <entry>Name</entry>
2612             <entry>Values</entry>
2613             <entry>Description</entry>
2614            </row>
2615           </thead>
2616           <tbody>
2617            <row>
2618             <entry>host</entry>
2619             <entry>(string)</entry>
2620             <entry>dns name or ip address</entry>
2621           </row>
2622           <row>
2623            <entry>port</entry>
2624            <entry>(number)</entry>
2625            <entry>The tcp port the server will open. A zero value let the server 
2626             choose a free port provided from the underlaying operating system. 
2627             libdbus is able to retrieve the real used port from the server.  
2628            </entry>
2629           </row>
2630           <row>
2631            <entry>family</entry>
2632            <entry>(string)</entry>
2633            <entry>If set, provide the type of socket family either "ipv4" or "ipv6". If unset, the family is unspecified.</entry>
2634           </row>
2635          </tbody>
2636         </tgroup>
2637        </informaltable>
2638       </sect3>
2639     </sect2>
2640     <sect2 id="transports-nonce-tcp-sockets">
2641       <title>Nonce-secured TCP Sockets</title>
2642       <para>
2643         The nonce-tcp transport provides a secured TCP transport, using a
2644         simple authentication mechanism to ensure that only clients with read
2645         access to a certain location in the filesystem can connect to the server.
2646         The server writes a secret, the nonce, to a file and an incoming client
2647         connection is only accepted if the client sends the nonce right after
2648         the connect. The nonce mechanism requires no setup and is orthogonal to
2649         the higher-level authentication mechanisms described in the
2650         Authentication section.
2651       </para>
2652
2653       <para>
2654         On start, the server generates a random 16 byte nonce and writes it
2655         to a file in the user's temporary directory. The nonce file location
2656         is published as part of the server's D-Bus address using the
2657         "noncefile" key-value pair.
2658
2659         After an accept, the server reads 16 bytes from the socket. If the
2660         read bytes do not match the nonce stored in the nonce file, the
2661         server MUST immediately drop the connection.
2662         If the nonce match the received byte sequence, the client is accepted
2663         and the transport behaves like an unsecured tcp transport.
2664       </para>
2665       <para>
2666         After a successful connect to the server socket, the client MUST read
2667         the nonce from the file published by the server via the noncefile=
2668         key-value pair and send it over the socket. After that, the
2669         transport behaves like an unsecured tcp transport.
2670       </para>
2671       <sect3 id="transports-nonce-tcp-sockets-addresses">
2672         <title>Server Address Format</title>
2673         <para> 
2674          Nonce TCP/IP socket addresses uses the "nonce-tcp:" prefix 
2675          and support the following key/value pairs:
2676         </para>
2677         <informaltable>
2678          <tgroup cols="3">
2679           <thead>
2680            <row>
2681             <entry>Name</entry>
2682             <entry>Values</entry>
2683             <entry>Description</entry>
2684            </row>
2685           </thead>
2686           <tbody>
2687            <row>
2688             <entry>host</entry>
2689             <entry>(string)</entry>
2690             <entry>dns name or ip address</entry>
2691           </row>
2692           <row>
2693            <entry>port</entry>
2694            <entry>(number)</entry>
2695            <entry>The tcp port the server will open. A zero value let the server 
2696             choose a free port provided from the underlaying operating system. 
2697             libdbus is able to retrieve the real used port from the server.  
2698            </entry>
2699           </row>
2700           <row>
2701            <entry>family</entry>
2702            <entry>(string)</entry>
2703            <entry>If set, provide the type of socket family either "ipv4" or "ipv6". If unset, the family is unspecified.</entry>
2704           </row>
2705           <row>
2706            <entry>noncefile</entry>
2707            <entry>(path)</entry>
2708            <entry>file location containing the secret</entry>
2709           </row>
2710          </tbody>
2711         </tgroup>
2712        </informaltable>
2713       </sect3>
2714     </sect2>
2715    </sect1>
2716    <sect1 id="meta-transports">
2717     <title>Meta Transports</title>
2718     <para>
2719       Meta transports are a kind of transport with special enhancements or
2720       behavior. Currently available meta transports include: autolaunch
2721     </para>
2722
2723     <sect2 id="meta-transports-autolaunch">
2724      <title>Autolaunch</title>
2725      <para>The autolaunch transport provides a way for dbus clients to autodetect
2726        a running dbus session bus and to autolaunch a session bus if not present.
2727      </para>
2728      <sect3 id="meta-transports-autolaunch-addresses">
2729        <title>Server Address Format</title>
2730        <para>
2731          Autolaunch addresses uses the "autolaunch:" prefix and support the
2732          following key/value pairs:
2733        </para>
2734        <informaltable>
2735         <tgroup cols="3">
2736          <thead>
2737           <row>
2738            <entry>Name</entry>
2739            <entry>Values</entry>
2740            <entry>Description</entry>
2741           </row>
2742          </thead>
2743          <tbody>
2744           <row>
2745            <entry>scope</entry>
2746            <entry>(string)</entry>
2747            <entry>scope of autolaunch (Windows only)
2748             <itemizedlist>
2749              <listitem>
2750               <para>
2751                "*install-path" - limit session bus to dbus installation path.
2752                The dbus installation path is determined from the location of
2753                the shared dbus library. If the library is located in a 'bin'
2754                subdirectory the installation root is the directory above,
2755                otherwise the directory where the library lives is taken as
2756                installation root.
2757                <programlisting>
2758                    &lt;install-root&gt;/bin/[lib]dbus-1.dll
2759                    &lt;install-root&gt;/[lib]dbus-1.dll
2760                </programlisting>
2761               </para>
2762              </listitem>
2763              <listitem>
2764               <para>
2765                "*user" - limit session bus to the recent user.
2766               </para>
2767              </listitem>
2768              <listitem>
2769               <para>
2770                other values - specify dedicated session bus like "release",
2771                "debug" or other
2772               </para>
2773              </listitem>
2774             </itemizedlist>
2775            </entry>
2776          </row>
2777         </tbody>
2778        </tgroup>
2779       </informaltable>
2780      </sect3>
2781
2782      <sect3 id="meta-transports-autolaunch-windows-implementation">
2783       <title>Windows implementation</title>
2784       <para>
2785         On start, the server opens a platform specific transport, creates a mutex
2786         and a shared memory section containing the related session bus address.
2787         This mutex will be inspected by the dbus client library to detect a
2788         running dbus session bus. The access to the mutex and the shared memory
2789         section are protected by global locks.
2790       </para>
2791       <para>
2792        In the recent implementation the autolaunch transport uses a tcp transport
2793        on localhost with a port choosen from the operating system. This detail may
2794        change in the future.
2795       </para>
2796       <para>
2797         Disclaimer: The recent implementation is in an early state and may not
2798         work in all cirumstances and/or may have security issues. Because of this
2799         the implementation is not documentated yet.
2800       </para>
2801      </sect3>
2802     </sect2>
2803    </sect1>
2804    <sect1 id="naming-conventions">
2805     <title>Naming Conventions</title>
2806     
2807     <para>
2808       D-Bus namespaces are all lowercase and correspond to reversed domain
2809       names, as with Java. e.g. "org.freedesktop"
2810     </para>
2811     <para>
2812       Interface, signal, method, and property names are "WindowsStyleCaps", note
2813       that the first letter is capitalized, unlike Java.
2814     </para>
2815     <para>
2816       Object paths are normally all lowercase with underscores used rather than
2817       hyphens.
2818     </para>
2819   </sect1>
2820
2821   <sect1 id="uuids">
2822     <title>UUIDs</title>
2823     <para>
2824       A working D-Bus implementation uses universally-unique IDs in two places.
2825       First, each server address has a UUID identifying the address, 
2826       as described in <xref linkend="addresses"/>. Second, each operating
2827       system kernel instance running a D-Bus client or server has a UUID
2828       identifying that kernel, retrieved by invoking the method
2829       org.freedesktop.DBus.Peer.GetMachineId() (see <xref
2830       linkend="standard-interfaces-peer"/>).
2831     </para>
2832     <para>
2833       The term "UUID" in this document is intended literally, i.e. an
2834       identifier that is universally unique. It is not intended to refer to
2835       RFC4122, and in fact the D-Bus UUID is not compatible with that RFC.
2836     </para>
2837     <para>
2838       The UUID must contain 128 bits of data and be hex-encoded.  The
2839       hex-encoded string may not contain hyphens or other non-hex-digit
2840       characters, and it must be exactly 32 characters long.  To generate a
2841       UUID, the current reference implementation concatenates 96 bits of random
2842       data followed by the 32-bit time in seconds since the UNIX epoch (in big
2843       endian byte order).
2844     </para>
2845     <para>
2846       It would also be acceptable and probably better to simply generate 128
2847       bits of random data, as long as the random number generator is of high
2848       quality. The timestamp could conceivably help if the random bits are not
2849       very random. With a quality random number generator, collisions are
2850       extremely unlikely even with only 96 bits, so it's somewhat academic.
2851     </para>
2852     <para>
2853       Implementations should, however, stick to random data for the first 96 bits
2854       of the UUID.
2855     </para>
2856   </sect1>
2857     
2858   <sect1 id="standard-interfaces">
2859     <title>Standard Interfaces</title>
2860     <para>
2861       See <xref linkend="message-protocol-types-notation"/> for details on 
2862        the notation used in this section. There are some standard interfaces
2863       that may be useful across various D-Bus applications.
2864     </para>
2865     <sect2 id="standard-interfaces-peer">
2866       <title><literal>org.freedesktop.DBus.Peer</literal></title>
2867       <para>
2868         The <literal>org.freedesktop.DBus.Peer</literal> interface 
2869         has two methods:
2870         <programlisting>
2871           org.freedesktop.DBus.Peer.Ping ()
2872           org.freedesktop.DBus.Peer.GetMachineId (out STRING machine_uuid)
2873         </programlisting>
2874       </para>
2875       <para>
2876         On receipt of the <literal>METHOD_CALL</literal> message
2877         <literal>org.freedesktop.DBus.Peer.Ping</literal>, an application should do
2878         nothing other than reply with a <literal>METHOD_RETURN</literal> as
2879         usual.  It does not matter which object path a ping is sent to.  The
2880         reference implementation handles this method automatically.
2881       </para>
2882       <para>
2883         On receipt of the <literal>METHOD_CALL</literal> message
2884         <literal>org.freedesktop.DBus.Peer.GetMachineId</literal>, an application should 
2885         reply with a <literal>METHOD_RETURN</literal> containing a hex-encoded 
2886         UUID representing the identity of the machine the process is running on.
2887         This UUID must be the same for all processes on a single system at least
2888         until that system next reboots. It should be the same across reboots 
2889         if possible, but this is not always possible to implement and is not 
2890         guaranteed.
2891         It does not matter which object path a GetMachineId is sent to.  The
2892         reference implementation handles this method automatically.
2893       </para>
2894       <para>
2895         The UUID is intended to be per-instance-of-the-operating-system, so may represent
2896         a virtual machine running on a hypervisor, rather than a physical machine.
2897         Basically if two processes see the same UUID, they should also see the same
2898         shared memory, UNIX domain sockets, process IDs, and other features that require 
2899         a running OS kernel in common between the processes.
2900       </para>
2901       <para>
2902         The UUID is often used where other programs might use a hostname. Hostnames 
2903         can change without rebooting, however, or just be "localhost" - so the UUID
2904         is more robust.
2905       </para>
2906       <para>
2907         <xref linkend="uuids"/> explains the format of the UUID.
2908       </para>
2909     </sect2>
2910
2911     <sect2 id="standard-interfaces-introspectable">
2912       <title><literal>org.freedesktop.DBus.Introspectable</literal></title>
2913       <para>
2914         This interface has one method:
2915         <programlisting>
2916           org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)
2917         </programlisting>
2918       </para>
2919       <para>
2920         Objects instances may implement
2921         <literal>Introspect</literal> which returns an XML description of
2922         the object, including its interfaces (with signals and methods), objects
2923         below it in the object path tree, and its properties.
2924       </para>
2925       <para>
2926         <xref linkend="introspection-format"/> describes the format of this XML string.
2927       </para>
2928     </sect2>
2929     <sect2 id="standard-interfaces-properties">
2930       <title><literal>org.freedesktop.DBus.Properties</literal></title>
2931       <para>
2932         Many native APIs will have a concept of object <firstterm>properties</firstterm> 
2933         or <firstterm>attributes</firstterm>. These can be exposed via the 
2934         <literal>org.freedesktop.DBus.Properties</literal> interface.
2935       </para>
2936       <para>
2937         <programlisting>
2938               org.freedesktop.DBus.Properties.Get (in STRING interface_name,
2939                                                    in STRING property_name,
2940                                                    out VARIANT value);
2941               org.freedesktop.DBus.Properties.Set (in STRING interface_name,
2942                                                    in STRING property_name,
2943                                                    in VARIANT value);
2944               org.freedesktop.DBus.Properties.GetAll (in STRING interface_name,
2945                                                       out DICT&lt;STRING,VARIANT&gt; props);
2946         </programlisting>
2947       </para>
2948       <para>
2949         The available properties and whether they are writable can be determined
2950         by calling <literal>org.freedesktop.DBus.Introspectable.Introspect</literal>,
2951         see <xref linkend="standard-interfaces-introspectable"/>.
2952       </para>
2953       <para>
2954         An empty string may be provided for the interface name; in this case, 
2955         if there are multiple properties on an object with the same name, 
2956         the results are undefined (picking one by according to an arbitrary 
2957         deterministic rule, or returning an error, are the reasonable 
2958         possibilities).
2959       </para>
2960       <para>
2961         If one or more properties change on an object, the
2962         <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
2963         signal may be emitted (this signal was added in 0.14):
2964       </para>
2965       <para>
2966         <programlisting>
2967               org.freedesktop.DBus.Properties.PropertiesChanged (STRING interface_name,
2968                                                                  DICT&lt;STRING,VARIANT&gt; changed_properties,
2969                                                                  ARRAY&lt;STRING&gt; invalidated_properties);
2970         </programlisting>
2971       </para>
2972       <para>
2973         where <literal>changed_properties</literal> is a dictionary
2974         containing the changed properties with the new values and
2975         <literal>invalidated_properties</literal> is an array of
2976         properties that changed but the value is not conveyed.
2977       </para>
2978       <para>
2979         Whether the <literal>PropertiesChanged</literal> signal is
2980         supported can be determined by calling
2981         <literal>org.freedesktop.DBus.Introspectable.Introspect</literal>. Note
2982         that the signal may be supported for an object but it may
2983         differ how whether and how it is used on a per-property basis
2984         (for e.g. performance or security reasons). Each property (or
2985         the parent interface) must be annotated with the
2986         <literal>org.freedesktop.DBus.Property.EmitsChangedSignal</literal>
2987         annotation to convey this (usually the default value
2988         <literal>true</literal> is sufficient meaning that the
2989         annotation does not need to be used). See <xref
2990         linkend="introspection-format"/> for details on this
2991         annotation.
2992       </para>
2993     </sect2>
2994   </sect1>
2995
2996   <sect1 id="introspection-format">
2997     <title>Introspection Data Format</title>
2998     <para>
2999       As described in <xref linkend="standard-interfaces-introspectable"/>, 
3000       objects may be introspected at runtime, returning an XML string 
3001       that describes the object. The same XML format may be used in 
3002       other contexts as well, for example as an "IDL" for generating 
3003       static language bindings.
3004     </para>
3005     <para>
3006       Here is an example of introspection data:
3007       <programlisting>
3008         &lt;!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
3009          "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"&gt;
3010         &lt;node name="/org/freedesktop/sample_object"&gt;
3011           &lt;interface name="org.freedesktop.SampleInterface"&gt;
3012             &lt;method name="Frobate"&gt;
3013               &lt;arg name="foo" type="i" direction="in"/&gt;
3014               &lt;arg name="bar" type="s" direction="out"/&gt;
3015               &lt;arg name="baz" type="a{us}" direction="out"/&gt;
3016               &lt;annotation name="org.freedesktop.DBus.Deprecated" value="true"/&gt;
3017             &lt;/method&gt;
3018             &lt;method name="Bazify"&gt;
3019               &lt;arg name="bar" type="(iiu)" direction="in"/&gt;
3020               &lt;arg name="bar" type="v" direction="out"/&gt;
3021             &lt;/method&gt;
3022             &lt;method name="Mogrify"&gt;
3023               &lt;arg name="bar" type="(iiav)" direction="in"/&gt;
3024             &lt;/method&gt;
3025             &lt;signal name="Changed"&gt;
3026               &lt;arg name="new_value" type="b"/&gt;
3027             &lt;/signal&gt;
3028             &lt;property name="Bar" type="y" access="readwrite"/&gt;
3029           &lt;/interface&gt;
3030           &lt;node name="child_of_sample_object"/&gt;
3031           &lt;node name="another_child_of_sample_object"/&gt;
3032        &lt;/node&gt;
3033       </programlisting>
3034     </para>
3035     <para>
3036       A more formal DTD and spec needs writing, but here are some quick notes.
3037       <itemizedlist>
3038         <listitem>
3039           <para>
3040             Only the root &lt;node&gt; element can omit the node name, as it's
3041             known to be the object that was introspected.  If the root
3042             &lt;node&gt; does have a name attribute, it must be an absolute
3043             object path. If child &lt;node&gt; have object paths, they must be
3044             relative.
3045           </para>
3046         </listitem>
3047         <listitem>
3048           <para>
3049             If a child &lt;node&gt; has any sub-elements, then they 
3050             must represent a complete introspection of the child.
3051             If a child &lt;node&gt; is empty, then it may or may 
3052             not have sub-elements; the child must be introspected
3053             in order to find out. The intent is that if an object 
3054             knows that its children are "fast" to introspect
3055             it can go ahead and return their information, but 
3056             otherwise it can omit it.
3057           </para>
3058         </listitem>
3059         <listitem>
3060           <para>
3061             The direction element on &lt;arg&gt; may be omitted, 
3062             in which case it defaults to "in" for method calls 
3063             and "out" for signals. Signals only allow "out" 
3064             so while direction may be specified, it's pointless.
3065           </para>
3066         </listitem>
3067         <listitem>
3068           <para>
3069             The possible directions are "in" and "out", 
3070             unlike CORBA there is no "inout"
3071           </para>
3072         </listitem>
3073         <listitem>
3074           <para>
3075             The possible property access flags are 
3076             "readwrite", "read", and "write"
3077           </para>
3078         </listitem>
3079         <listitem>
3080           <para>
3081             Multiple interfaces can of course be listed for 
3082             one &lt;node&gt;.
3083           </para>
3084         </listitem>
3085         <listitem>
3086           <para>
3087             The "name" attribute on arguments is optional.
3088           </para>
3089         </listitem>
3090       </itemizedlist>
3091     </para>
3092     <para>
3093         Method, interface, property, and signal elements may have
3094         "annotations", which are generic key/value pairs of metadata.
3095         They are similar conceptually to Java's annotations and C# attributes.
3096         Well-known annotations:
3097      </para>
3098      <informaltable>
3099        <tgroup cols="3">
3100          <thead>
3101            <row>
3102              <entry>Name</entry>
3103              <entry>Values (separated by ,)</entry>
3104              <entry>Description</entry>
3105            </row>
3106          </thead>
3107          <tbody>
3108            <row>
3109              <entry>org.freedesktop.DBus.Deprecated</entry>
3110              <entry>true,false</entry>
3111              <entry>Whether or not the entity is deprecated; defaults to false</entry>
3112            </row>
3113            <row>
3114              <entry>org.freedesktop.DBus.GLib.CSymbol</entry>
3115              <entry>(string)</entry>
3116              <entry>The C symbol; may be used for methods and interfaces</entry>
3117            </row>
3118            <row>
3119              <entry>org.freedesktop.DBus.Method.NoReply</entry>
3120              <entry>true,false</entry>
3121              <entry>If set, don't expect a reply to the method call; defaults to false.</entry>
3122            </row>
3123            <row>
3124              <entry>org.freedesktop.DBus.Property.EmitsChangedSignal</entry>
3125              <entry>true,invalidates,false</entry>
3126              <entry>
3127                <para>
3128                  If set to <literal>false</literal>, the
3129                  <literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
3130                  signal, see <xref
3131                  linkend="standard-interfaces-properties"/> is not
3132                  guaranteed to be emitted if the property changes.
3133                </para>
3134                <para>
3135                  If set to <literal>invalidates</literal> the signal
3136                  is emitted but the value is not included in the
3137                  signal.
3138                </para>
3139                <para>
3140                  If set to <literal>true</literal> the signal is
3141                  emitted with the value included.
3142                </para>
3143                <para>
3144                  The value for the annotation defaults to
3145                  <literal>true</literal> if the enclosing interface
3146                  element does not specify the annotation. Otherwise it
3147                  defaults to the value specified in the enclosing
3148                  interface element.
3149                </para>
3150              </entry>
3151            </row>
3152          </tbody>
3153        </tgroup>
3154      </informaltable>
3155   </sect1>
3156   <sect1 id="message-bus">
3157     <title>Message Bus Specification</title>
3158     <sect2 id="message-bus-overview">
3159       <title>Message Bus Overview</title>
3160       <para>
3161         The message bus accepts connections from one or more applications. 
3162         Once connected, applications can exchange messages with other 
3163         applications that are also connected to the bus.
3164       </para>
3165       <para>
3166         In order to route messages among connections, the message bus keeps a
3167         mapping from names to connections. Each connection has one
3168         unique-for-the-lifetime-of-the-bus name automatically assigned.
3169         Applications may request additional names for a connection. Additional
3170         names are usually "well-known names" such as
3171         "org.freedesktop.TextEditor". When a name is bound to a connection,
3172         that connection is said to <firstterm>own</firstterm> the name.
3173       </para>
3174       <para>
3175         The bus itself owns a special name, <literal>org.freedesktop.DBus</literal>. 
3176         This name routes messages to the bus, allowing applications to make 
3177         administrative requests. For example, applications can ask the bus 
3178         to assign a name to a connection.
3179       </para>
3180       <para>
3181         Each name may have <firstterm>queued owners</firstterm>.  When an
3182         application requests a name for a connection and the name is already in
3183         use, the bus will optionally add the connection to a queue waiting for 
3184         the name. If the current owner of the name disconnects or releases
3185         the name, the next connection in the queue will become the new owner.
3186       </para>
3187
3188       <para>
3189         This feature causes the right thing to happen if you start two text
3190         editors for example; the first one may request "org.freedesktop.TextEditor", 
3191         and the second will be queued as a possible owner of that name. When 
3192         the first exits, the second will take over.
3193       </para>
3194
3195       <para>
3196         Messages may have a <literal>DESTINATION</literal> field (see <xref
3197         linkend="message-protocol-header-fields"/>).  If the
3198         <literal>DESTINATION</literal> field is present, it specifies a message
3199         recipient by name. Method calls and replies normally specify this field.
3200         The message bus must send messages (of any type) with the
3201         <literal>DESTINATION</literal> field set to the specified recipient,
3202         regardless of whether the recipient has set up a match rule matching
3203         the message.
3204       </para>
3205
3206       <para>
3207         Signals normally do not specify a destination; they are sent to all
3208         applications with <firstterm>message matching rules</firstterm> that
3209         match the message.
3210       </para>
3211
3212       <para>
3213         When the message bus receives a method call, if the
3214         <literal>DESTINATION</literal> field is absent, the call is taken to be
3215         a standard one-to-one message and interpreted by the message bus
3216         itself. For example, sending an
3217         <literal>org.freedesktop.DBus.Peer.Ping</literal> message with no
3218         <literal>DESTINATION</literal> will cause the message bus itself to
3219         reply to the ping immediately; the message bus will not make this
3220         message visible to other applications.
3221       </para>
3222
3223       <para>
3224         Continuing the <literal>org.freedesktop.DBus.Peer.Ping</literal> example, if
3225         the ping message were sent with a <literal>DESTINATION</literal> name of
3226         <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
3227         forwarded, and the Yoyodyne Corporation screensaver application would be
3228         expected to reply to the ping.
3229       </para>
3230     </sect2>
3231
3232     <sect2 id="message-bus-names">
3233       <title>Message Bus Names</title>
3234       <para>
3235         Each connection has at least one name, assigned at connection time and
3236         returned in response to the
3237         <literal>org.freedesktop.DBus.Hello</literal> method call.  This
3238         automatically-assigned name is called the connection's <firstterm>unique
3239         name</firstterm>.  Unique names are never reused for two different
3240         connections to the same bus.
3241       </para>
3242       <para>
3243         Ownership of a unique name is a prerequisite for interaction with 
3244         the message bus. It logically follows that the unique name is always 
3245         the first name that an application comes to own, and the last 
3246         one that it loses ownership of.
3247       </para>
3248       <para>
3249         Unique connection names must begin with the character ':' (ASCII colon
3250         character); bus names that are not unique names must not begin
3251         with this character. (The bus must reject any attempt by an application
3252         to manually request a name beginning with ':'.) This restriction
3253         categorically prevents "spoofing"; messages sent to a unique name
3254         will always go to the expected connection.
3255       </para>
3256       <para>
3257         When a connection is closed, all the names that it owns are deleted (or
3258         transferred to the next connection in the queue if any).
3259       </para>
3260       <para>
3261         A connection can request additional names to be associated with it using
3262         the <literal>org.freedesktop.DBus.RequestName</literal> message. <xref
3263         linkend="message-protocol-names-bus"/> describes the format of a valid
3264         name. These names can be released again using the
3265         <literal>org.freedesktop.DBus.ReleaseName</literal> message.
3266       </para>
3267
3268       <sect3 id="bus-messages-request-name">
3269         <title><literal>org.freedesktop.DBus.RequestName</literal></title>
3270         <para>
3271           As a method:
3272           <programlisting>
3273             UINT32 RequestName (in STRING name, in UINT32 flags)
3274           </programlisting>
3275           Message arguments:
3276           <informaltable>
3277             <tgroup cols="3">
3278               <thead>
3279                 <row>
3280                   <entry>Argument</entry>
3281                   <entry>Type</entry>
3282                   <entry>Description</entry>
3283                 </row>
3284               </thead>
3285               <tbody>
3286                 <row>
3287                   <entry>0</entry>
3288                   <entry>STRING</entry>
3289                   <entry>Name to request</entry>
3290                 </row>
3291                 <row>
3292                   <entry>1</entry>
3293                   <entry>UINT32</entry>
3294                   <entry>Flags</entry>
3295                 </row>
3296               </tbody>
3297             </tgroup>
3298           </informaltable>
3299           Reply arguments:
3300           <informaltable>
3301             <tgroup cols="3">
3302               <thead>
3303                 <row>
3304                   <entry>Argument</entry>
3305                   <entry>Type</entry>
3306                   <entry>Description</entry>
3307                 </row>
3308               </thead>
3309               <tbody>
3310                 <row>
3311                   <entry>0</entry>
3312                   <entry>UINT32</entry>
3313                   <entry>Return value</entry>
3314                 </row>
3315               </tbody>
3316             </tgroup>
3317           </informaltable>
3318         </para>
3319         <para>
3320           This method call should be sent to
3321           <literal>org.freedesktop.DBus</literal> and asks the message bus to
3322           assign the given name to the method caller. Each name maintains a
3323           queue of possible owners, where the head of the queue is the primary
3324           or current owner of the name. Each potential owner in the queue
3325           maintains the DBUS_NAME_FLAG_ALLOW_REPLACEMENT and
3326           DBUS_NAME_FLAG_DO_NOT_QUEUE settings from its latest RequestName
3327           call.  When RequestName is invoked the following occurs:
3328           <itemizedlist>
3329             <listitem>
3330               <para>
3331                 If the method caller is currently the primary owner of the name,
3332                 the DBUS_NAME_FLAG_ALLOW_REPLACEMENT and DBUS_NAME_FLAG_DO_NOT_QUEUE
3333                 values are updated with the values from the new RequestName call, 
3334                 and nothing further happens.
3335               </para>
3336             </listitem>
3337
3338             <listitem>
3339               <para>
3340                 If the current primary owner (head of the queue) has
3341                 DBUS_NAME_FLAG_ALLOW_REPLACEMENT set, and the RequestName
3342                 invocation has the DBUS_NAME_FLAG_REPLACE_EXISTING flag, then
3343                 the caller of RequestName replaces the current primary owner at
3344                 the head of the queue and the current primary owner moves to the
3345                 second position in the queue. If the caller of RequestName was 
3346                 in the queue previously its flags are updated with the values from 
3347                 the new RequestName in addition to moving it to the head of the queue.
3348               </para>
3349             </listitem>
3350
3351             <listitem>
3352               <para>
3353                 If replacement is not possible, and the method caller is
3354                 currently in the queue but not the primary owner, its flags are
3355                 updated with the values from the new RequestName call.
3356               </para>
3357             </listitem>
3358
3359             <listitem>
3360               <para>
3361                 If replacement is not possible, and the method caller is
3362                 currently not in the queue, the method caller is appended to the
3363                 queue.
3364               </para>
3365             </listitem>
3366
3367             <listitem>
3368               <para>
3369                 If any connection in the queue has DBUS_NAME_FLAG_DO_NOT_QUEUE
3370                 set and is not the primary owner, it is removed from the
3371                 queue. This can apply to the previous primary owner (if it
3372                 was replaced) or the method caller (if it updated the
3373                 DBUS_NAME_FLAG_DO_NOT_QUEUE flag while still stuck in the
3374                 queue, or if it was just added to the queue with that flag set).
3375               </para>
3376             </listitem>
3377           </itemizedlist>
3378         </para>
3379         <para>
3380           Note that DBUS_NAME_FLAG_REPLACE_EXISTING results in "jumping the
3381           queue," even if another application already in the queue had specified
3382           DBUS_NAME_FLAG_REPLACE_EXISTING.  This comes up if a primary owner
3383           that does not allow replacement goes away, and the next primary owner
3384           does allow replacement. In this case, queued items that specified
3385           DBUS_NAME_FLAG_REPLACE_EXISTING <emphasis>do not</emphasis>
3386           automatically replace the new primary owner. In other words,
3387           DBUS_NAME_FLAG_REPLACE_EXISTING is not saved, it is only used at the
3388           time RequestName is called. This is deliberate to avoid an infinite loop
3389           anytime two applications are both DBUS_NAME_FLAG_ALLOW_REPLACEMENT 
3390           and DBUS_NAME_FLAG_REPLACE_EXISTING.
3391         </para>
3392         <para>
3393           The flags argument contains any of the following values logically ORed
3394           together:
3395
3396           <informaltable>
3397             <tgroup cols="3">
3398               <thead>
3399                 <row>
3400                   <entry>Conventional Name</entry>
3401                   <entry>Value</entry>
3402                   <entry>Description</entry>
3403                 </row>
3404               </thead>
3405               <tbody>
3406                 <row>
3407                   <entry>DBUS_NAME_FLAG_ALLOW_REPLACEMENT</entry>
3408                   <entry>0x1</entry>
3409                   <entry>
3410
3411                     If an application A specifies this flag and succeeds in
3412                     becoming the owner of the name, and another application B
3413                     later calls RequestName with the
3414                     DBUS_NAME_FLAG_REPLACE_EXISTING flag, then application A
3415                     will lose ownership and receive a
3416                     <literal>org.freedesktop.DBus.NameLost</literal> signal, and
3417                     application B will become the new owner. If DBUS_NAME_FLAG_ALLOW_REPLACEMENT
3418                     is not specified by application A, or DBUS_NAME_FLAG_REPLACE_EXISTING
3419                     is not specified by application B, then application B will not replace
3420                     application A as the owner.
3421
3422                   </entry>
3423                 </row>
3424                 <row>
3425                   <entry>DBUS_NAME_FLAG_REPLACE_EXISTING</entry>
3426                   <entry>0x2</entry>
3427                   <entry>
3428
3429                     Try to replace the current owner if there is one. If this
3430                     flag is not set the application will only become the owner of
3431                     the name if there is no current owner. If this flag is set,
3432                     the application will replace the current owner if
3433                     the current owner specified DBUS_NAME_FLAG_ALLOW_REPLACEMENT.
3434
3435                   </entry>
3436                 </row>
3437                 <row>
3438                   <entry>DBUS_NAME_FLAG_DO_NOT_QUEUE</entry>
3439                   <entry>0x4</entry>
3440                   <entry>
3441
3442                     Without this flag, if an application requests a name that is
3443                     already owned, the application will be placed in a queue to
3444                     own the name when the current owner gives it up. If this
3445                     flag is given, the application will not be placed in the
3446                     queue, the request for the name will simply fail.  This flag
3447                     also affects behavior when an application is replaced as
3448                     name owner; by default the application moves back into the
3449                     waiting queue, unless this flag was provided when the application
3450                     became the name owner.
3451
3452                   </entry>
3453                 </row>
3454               </tbody>
3455             </tgroup>
3456           </informaltable>
3457
3458           The return code can be one of the following values:
3459
3460           <informaltable>
3461             <tgroup cols="3">
3462               <thead>
3463                 <row>
3464                   <entry>Conventional Name</entry>
3465                   <entry>Value</entry>
3466                   <entry>Description</entry>
3467                 </row>
3468               </thead>
3469               <tbody>
3470                 <row>
3471                   <entry>DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER</entry>
3472                   <entry>1</entry> <entry>The caller is now the primary owner of
3473                   the name, replacing any previous owner. Either the name had no
3474                   owner before, or the caller specified
3475                   DBUS_NAME_FLAG_REPLACE_EXISTING and the current owner specified
3476                   DBUS_NAME_FLAG_ALLOW_REPLACEMENT.</entry>
3477                 </row>
3478                 <row>
3479                   <entry>DBUS_REQUEST_NAME_REPLY_IN_QUEUE</entry>
3480                   <entry>2</entry>
3481
3482                   <entry>The name already had an owner,
3483                     DBUS_NAME_FLAG_DO_NOT_QUEUE was not specified, and either
3484                     the current owner did not specify
3485                     DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the requesting
3486                     application did not specify DBUS_NAME_FLAG_REPLACE_EXISTING.
3487                     </entry>
3488                 </row>
3489                 <row>
3490                   <entry>DBUS_REQUEST_NAME_REPLY_EXISTS</entry> <entry>3</entry>
3491                   <entry>The name already has an owner,
3492                   DBUS_NAME_FLAG_DO_NOT_QUEUE was specified, and either
3493                   DBUS_NAME_FLAG_ALLOW_REPLACEMENT was not specified by the
3494                   current owner, or DBUS_NAME_FLAG_REPLACE_EXISTING was not
3495                   specified by the requesting application.</entry>
3496                 </row>
3497                 <row>
3498                   <entry>DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER</entry>
3499                   <entry>4</entry>
3500                   <entry>The application trying to request ownership of a name is already the owner of it.</entry>
3501                 </row>
3502               </tbody>
3503             </tgroup>
3504           </informaltable>
3505         </para>
3506        </sect3>
3507
3508        <sect3 id="bus-messages-release-name">
3509         <title><literal>org.freedesktop.DBus.ReleaseName</literal></title>
3510         <para>
3511           As a method:
3512           <programlisting>
3513             UINT32 ReleaseName (in STRING name)
3514           </programlisting>
3515           Message arguments:
3516           <informaltable>
3517             <tgroup cols="3">
3518               <thead>
3519                 <row>
3520                   <entry>Argument</entry>
3521                   <entry>Type</entry>
3522                   <entry>Description</entry>
3523                 </row>
3524               </thead>
3525               <tbody>
3526                 <row>
3527                   <entry>0</entry>
3528                   <entry>STRING</entry>
3529                   <entry>Name to release</entry>
3530                 </row>
3531               </tbody>
3532             </tgroup>
3533           </informaltable>
3534           Reply arguments:
3535           <informaltable>
3536             <tgroup cols="3">
3537               <thead>
3538                 <row>
3539                   <entry>Argument</entry>
3540                   <entry>Type</entry>
3541                   <entry>Description</entry>
3542                 </row>
3543               </thead>
3544               <tbody>
3545                 <row>
3546                   <entry>0</entry>
3547                   <entry>UINT32</entry>
3548                   <entry>Return value</entry>
3549                 </row>
3550               </tbody>
3551             </tgroup>
3552           </informaltable>
3553         </para>
3554         <para>
3555           This method call should be sent to
3556           <literal>org.freedesktop.DBus</literal> and asks the message bus to
3557           release the method caller's claim to the given name. If the caller is
3558           the primary owner, a new primary owner will be selected from the
3559           queue if any other owners are waiting. If the caller is waiting in
3560           the queue for the name, the caller will removed from the queue and
3561           will not be made an owner of the name if it later becomes available.
3562           If there are no other owners in the queue for the name, it will be
3563           removed from the bus entirely.
3564
3565           The return code can be one of the following values:
3566
3567           <informaltable>
3568             <tgroup cols="3">
3569               <thead>
3570                 <row>
3571                   <entry>Conventional Name</entry>
3572                   <entry>Value</entry>
3573                   <entry>Description</entry>
3574                 </row>
3575               </thead>
3576               <tbody>
3577                 <row>
3578                   <entry>DBUS_RELEASE_NAME_REPLY_RELEASED</entry>
3579                   <entry>1</entry> <entry>The caller has released his claim on
3580                   the given name. Either the caller was the primary owner of
3581                   the name, and the name is now unused or taken by somebody
3582                   waiting in the queue for the name, or the caller was waiting
3583                   in the queue for the name and has now been removed from the
3584                   queue.</entry>
3585                 </row>
3586                 <row>
3587                   <entry>DBUS_RELEASE_NAME_REPLY_NON_EXISTENT</entry>
3588                   <entry>2</entry>
3589                   <entry>The given name does not exist on this bus.</entry>
3590                 </row>
3591                 <row>
3592                   <entry>DBUS_RELEASE_NAME_REPLY_NOT_OWNER</entry>
3593                   <entry>3</entry>
3594                   <entry>The caller was not the primary owner of this name,
3595                   and was also not waiting in the queue to own this name.</entry>
3596                 </row>
3597               </tbody>
3598             </tgroup>
3599           </informaltable>
3600         </para>
3601        </sect3>
3602
3603        <sect3 id="bus-messages-list-queued-owners">
3604         <title><literal>org.freedesktop.DBus.ListQueuedOwners</literal></title>
3605         <para>
3606           As a method:
3607           <programlisting>
3608             ARRAY of STRING ListQueuedOwners (in STRING name)
3609           </programlisting>
3610           Message arguments:
3611           <informaltable>
3612             <tgroup cols="3">
3613               <thead>
3614                 <row>
3615                   <entry>Argument</entry>
3616                   <entry>Type</entry>
3617                   <entry>Description</entry>
3618                 </row>
3619               </thead>
3620               <tbody>
3621                 <row>
3622                   <entry>0</entry>
3623                   <entry>STRING</entry>
3624                   <entry>The well-known bus name to query, such as
3625                     <literal>com.example.cappuccino</literal></entry>
3626                 </row>
3627               </tbody>
3628             </tgroup>
3629           </informaltable>
3630           Reply arguments:
3631           <informaltable>
3632             <tgroup cols="3">
3633               <thead>
3634                 <row>
3635                   <entry>Argument</entry>
3636                   <entry>Type</entry>
3637                   <entry>Description</entry>
3638                 </row>
3639               </thead>
3640               <tbody>
3641                 <row>
3642                   <entry>0</entry>
3643                   <entry>ARRAY of STRING</entry>
3644                   <entry>The unique bus names of connections currently queued
3645                     for the name</entry>
3646                 </row>
3647               </tbody>
3648             </tgroup>
3649           </informaltable>
3650         </para>
3651         <para>
3652           This method call should be sent to
3653           <literal>org.freedesktop.DBus</literal> and lists the connections
3654           currently queued for a bus name (see
3655           <xref linkend="term-queued-owner"/>).
3656         </para>
3657        </sect3>
3658     </sect2>
3659
3660     <sect2 id="message-bus-routing">
3661       <title>Message Bus Message Routing</title>
3662       <para>
3663         FIXME 
3664       </para>
3665       <sect3 id="message-bus-routing-match-rules">
3666         <title>Match Rules</title>
3667         <para>
3668           An important part of the message bus routing protocol is match  
3669           rules. Match rules describe what messages can be sent to a client
3670           based on the contents of the message.  When a message is routed
3671           through the bus it is compared to clients' match rules.  If any
3672           of the rules match, the message is dispatched to the client.
3673           If none of the rules match the message never leaves the bus.  This
3674           is an effective way to control traffic over the bus and to make sure
3675           only relevant message need to be processed by the client.
3676         </para>
3677         <para>
3678           Match rules are added using the AddMatch bus method 
3679           (see <xref linkend="bus-messages-add-match"/>).  Rules are
3680           specified as a string of comma separated key/value pairs. 
3681           Excluding a key from the rule indicates a wildcard match.  
3682           For instance excluding the the member from a match rule but 
3683           adding a sender would let all messages from that sender through.
3684           An example of a complete rule would be 
3685           "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='Foo',path='/bar/foo',destination=':452345.34',arg2='bar'"
3686         </para>
3687         <para>
3688           The following table describes the keys that can be used to create 
3689           a match rule:
3690           The following table summarizes the D-Bus types.
3691           <informaltable>
3692             <tgroup cols="3">
3693               <thead>
3694                 <row>
3695                   <entry>Key</entry>
3696                   <entry>Possible Values</entry>
3697                   <entry>Description</entry>
3698                 </row>
3699               </thead>
3700               <tbody>
3701                 <row>
3702                   <entry><literal>type</literal></entry>
3703                   <entry>'signal', 'method_call', 'method_return', 'error'</entry>
3704                   <entry>Match on the message type.  An example of a type match is type='signal'</entry>
3705                 </row>
3706                 <row>
3707                   <entry><literal>sender</literal></entry>
3708                   <entry>A bus or unique name (see <xref linkend="term-bus-name"/>
3709                   and <xref linkend="term-unique-name"/> respectively)
3710                   </entry>
3711                   <entry>Match messages sent by a particular sender.  An example of a sender match
3712                   is sender='org.freedesktop.Hal'</entry>
3713                 </row>
3714                 <row>
3715                   <entry><literal>interface</literal></entry>
3716                   <entry>An interface name (see <xref linkend="message-protocol-names-interface"/>)</entry>
3717                   <entry>Match messages sent over or to a particular interface.  An example of an
3718                   interface match is interface='org.freedesktop.Hal.Manager'.
3719                   If a message omits the interface header, it must not match any rule 
3720                   that specifies this key.</entry>
3721                 </row>
3722                 <row>
3723                   <entry><literal>member</literal></entry>
3724                   <entry>Any valid method or signal name</entry>
3725                   <entry>Matches messages which have the give method or signal name. An example of
3726                   a member match is member='NameOwnerChanged'</entry>
3727                 </row>
3728                 <row>
3729                   <entry><literal>path</literal></entry>
3730                   <entry>An object path (see <xref linkend="message-protocol-marshaling-object-path"/>)</entry>
3731                   <entry>Matches messages which are sent from or to the given object. An example of a
3732                   path match is path='/org/freedesktop/Hal/Manager'</entry>
3733                 </row>
3734                 <row>
3735                   <entry><literal>destination</literal></entry>
3736                   <entry>A unique name (see <xref linkend="term-unique-name"/>)</entry>
3737                   <entry>Matches messages which are being sent to the given unique name. An
3738                   example of a destination match is destination=':1.0'</entry>
3739                 </row>
3740                 <row>
3741                   <entry><literal>arg[0, 1, 2, 3, ...]</literal></entry>
3742                   <entry>Any string</entry>
3743                   <entry>Arg matches are special and are used for further restricting the 
3744                   match based on the arguments in the body of a message.  As of this time
3745                   only string arguments can be matched.  An example of an argument match 
3746                   would be arg3='Foo'. Only argument indexes from 0 to 63 should be 
3747                   accepted.</entry>
3748                 </row>
3749                 <row>
3750                   <entry><literal>arg[0, 1, 2, 3, ...]path</literal></entry>
3751                   <entry>Any string</entry>
3752                   <entry>Argument path matches provide a specialised form of wildcard
3753                   matching for path-like namespaces. As with normal argument matches,
3754                   if the argument is exactly equal to the string given in the match
3755                   rule then the rule is satisfied. Additionally, there is also a
3756                   match when either the string given in the match rule or the
3757                   appropriate message argument ends with '/' and is a prefix of the
3758                   other. An example argument path match is arg0path='/aa/bb/'. This
3759                   would match messages with first arguments of '/', '/aa/',
3760                   '/aa/bb/', '/aa/bb/cc/' and '/aa/bb/cc'. It would not match
3761                   messages with first arguments of '/aa/b', '/aa' or even '/aa/bb'.</entry>
3762                 </row>
3763               </tbody>
3764             </tgroup>
3765           </informaltable>
3766         </para>
3767       </sect3>
3768     </sect2>
3769     <sect2 id="message-bus-starting-services">
3770       <title>Message Bus Starting Services</title>
3771       <para>
3772         The message bus can start applications on behalf of other applications.
3773         In CORBA terms, this would be called <firstterm>activation</firstterm>.
3774         An application that can be started in this way is called a
3775         <firstterm>service</firstterm>.
3776       </para>
3777       <para>
3778         With D-Bus, starting a service is normally done by name. That is,
3779         applications ask the message bus to start some program that will own a
3780         well-known name, such as <literal>org.freedesktop.TextEditor</literal>.
3781         This implies a contract documented along with the name 
3782         <literal>org.freedesktop.TextEditor</literal> for which objects 
3783         the owner of that name will provide, and what interfaces those 
3784         objects will have.
3785       </para>
3786       <para>
3787         To find an executable corresponding to a particular name, the bus daemon
3788         looks for <firstterm>service description files</firstterm>.  Service
3789         description files define a mapping from names to executables. Different
3790         kinds of message bus will look for these files in different places, see
3791         <xref linkend="message-bus-types"/>.
3792       </para>
3793       <para>
3794         Service description files have the ".service" file
3795         extension. The message bus will only load service description files
3796         ending with .service; all other files will be ignored.  The file format
3797         is similar to that of <ulink
3798         url="http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html">desktop
3799         entries</ulink>. All service description files must be in UTF-8
3800         encoding. To ensure that there will be no name collisions, service files
3801         must be namespaced using the same mechanism as messages and service
3802         names.
3803       </para>
3804
3805       <para>
3806         [FIXME the file format should be much better specified than "similar to
3807         .desktop entries" esp. since desktop entries are already
3808         badly-specified. ;-)]
3809         These sections from the specification apply to service files as well:
3810
3811         <itemizedlist>
3812           <listitem><para>General syntax</para></listitem>
3813           <listitem><para>Comment format</para></listitem>
3814         </itemizedlist>
3815
3816         <figure>
3817           <title>Example service description file</title>
3818           <programlisting>
3819             # Sample service description file
3820             [D-BUS Service]
3821             Names=org.freedesktop.ConfigurationDatabase;org.gnome.GConf;
3822             Exec=/usr/libexec/gconfd-2
3823           </programlisting>
3824         </figure>
3825       </para>
3826       <para>
3827         When an application asks to start a service by name, the bus daemon tries to
3828         find a service that will own that name. It then tries to spawn the
3829         executable associated with it. If this fails, it will report an
3830         error. [FIXME what happens if two .service files offer the same service;
3831         what kind of error is reported, should we have a way for the client to
3832         choose one?]
3833       </para>
3834       <para>
3835         The executable launched will have the environment variable
3836         <literal>DBUS_STARTER_ADDRESS</literal> set to the address of the
3837         message bus so it can connect and request the appropriate names.
3838       </para>
3839       <para>
3840         The executable being launched may want to know whether the message bus
3841         starting it is one of the well-known message buses (see <xref
3842         linkend="message-bus-types"/>). To facilitate this, the bus must also set
3843         the <literal>DBUS_STARTER_BUS_TYPE</literal> environment variable if it is one
3844         of the well-known buses. The currently-defined values for this variable
3845         are <literal>system</literal> for the systemwide message bus,
3846         and <literal>session</literal> for the per-login-session message
3847         bus. The new executable must still connect to the address given
3848         in <literal>DBUS_STARTER_ADDRESS</literal>, but may assume that the
3849         resulting connection is to the well-known bus.
3850       </para>
3851       <para>
3852         [FIXME there should be a timeout somewhere, either specified
3853         in the .service file, by the client, or just a global value
3854         and if the client being activated fails to connect within that
3855         timeout, an error should be sent back.]
3856       </para>
3857
3858       <sect3 id="message-bus-starting-services-scope">
3859         <title>Message Bus Service Scope</title>
3860         <para>
3861           The "scope" of a service is its "per-", such as per-session,
3862           per-machine, per-home-directory, or per-display. The reference
3863           implementation doesn't yet support starting services in a different
3864           scope from the message bus itself. So e.g. if you start a service
3865           on the session bus its scope is per-session.
3866         </para>
3867         <para>
3868           We could add an optional scope to a bus name. For example, for
3869           per-(display,session pair), we could have a unique ID for each display
3870           generated automatically at login and set on screen 0 by executing a
3871           special "set display ID" binary. The ID would be stored in a
3872           <literal>_DBUS_DISPLAY_ID</literal> property and would be a string of
3873           random bytes. This ID would then be used to scope names.
3874           Starting/locating a service could be done by ID-name pair rather than
3875           only by name.
3876         </para>
3877         <para>
3878           Contrast this with a per-display scope. To achieve that, we would 
3879           want a single bus spanning all sessions using a given display.
3880           So we might set a <literal>_DBUS_DISPLAY_BUS_ADDRESS</literal> 
3881           property on screen 0 of the display, pointing to this bus.
3882         </para>
3883       </sect3>
3884     </sect2>
3885
3886     <sect2 id="message-bus-types">
3887       <title>Well-known Message Bus Instances</title>
3888       <para>
3889         Two standard message bus instances are defined here, along with how 
3890         to locate them and where their service files live.
3891       </para>
3892       <sect3 id="message-bus-types-login">
3893         <title>Login session message bus</title>
3894         <para>
3895           Each time a user logs in, a <firstterm>login session message
3896             bus</firstterm> may be started. All applications in the user's login
3897           session may interact with one another using this message bus.
3898         </para>
3899         <para>
3900           The address of the login session message bus is given 
3901           in the <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment 
3902           variable. If that variable is not set, applications may 
3903           also try to read the address from the X Window System root 
3904           window property <literal>_DBUS_SESSION_BUS_ADDRESS</literal>.
3905           The root window property must have type <literal>STRING</literal>.
3906           The environment variable should have precedence over the 
3907           root window property.
3908         </para>
3909         <para>The address of the login session message bus is given in the
3910         <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment variable. If
3911         DBUS_SESSION_BUS_ADDRESS is not set, or if it's set to the string
3912         "autolaunch:", the system should use platform-specific methods of
3913         locating a running D-Bus session server, or starting one if a running
3914         instance cannot be found. Note that this mechanism is not recommended
3915         for attempting to determine if a daemon is running. It is inherently
3916         racy to attempt to make this determination, since the bus daemon may
3917         be started just before or just after the determination is made.
3918         Therefore, it is recommended that applications do not try to make this
3919         determination for their functionality purposes, and instead they
3920         should attempt to start the server.</para>
3921
3922         <sect4 id="message-bus-types-login-x-windows">
3923           <title>X Windowing System</title>
3924           <para>
3925             For the X Windowing System, the application must locate the
3926             window owner of the selection represented by the atom formed by
3927             concatenating:
3928             <itemizedlist>
3929               <listitem>
3930                 <para>the literal string "_DBUS_SESSION_BUS_SELECTION_"</para>
3931               </listitem>
3932
3933               <listitem>
3934                 <para>the current user's username</para>
3935               </listitem>
3936
3937               <listitem>
3938                 <para>the literal character '_' (underscore)</para>
3939               </listitem>
3940
3941               <listitem>
3942                 <para>the machine's ID</para>
3943               </listitem>
3944             </itemizedlist>
3945           </para>
3946
3947           <para>
3948             The following properties are defined for the window that owns
3949             this X selection:
3950             <informaltable frame="all">
3951               <tgroup cols="2">
3952                 <tbody>
3953                   <row>
3954                     <entry>
3955                       <para>Atom</para>
3956                     </entry>
3957
3958                     <entry>
3959                       <para>meaning</para>
3960                     </entry>
3961                   </row>
3962
3963                   <row>
3964                     <entry>
3965                       <para>_DBUS_SESSION_BUS_ADDRESS</para>
3966                     </entry>
3967
3968                     <entry>
3969                       <para>the actual address of the server socket</para>
3970                     </entry>
3971                   </row>
3972
3973                   <row>
3974                     <entry>
3975                       <para>_DBUS_SESSION_BUS_PID</para>
3976                     </entry>
3977
3978                     <entry>
3979                       <para>the PID of the server process</para>
3980                     </entry>
3981                   </row>
3982                 </tbody>
3983               </tgroup>
3984             </informaltable>
3985           </para>
3986
3987           <para>
3988             At least the _DBUS_SESSION_BUS_ADDRESS property MUST be
3989             present in this window.
3990           </para>
3991
3992           <para>
3993             If the X selection cannot be located or if reading the
3994             properties from the window fails, the implementation MUST conclude
3995             that there is no D-Bus server running and proceed to start a new
3996             server. (See below on concurrency issues)
3997           </para>
3998
3999           <para>
4000             Failure to connect to the D-Bus server address thus obtained
4001             MUST be treated as a fatal connection error and should be reported
4002             to the application.
4003           </para>
4004
4005           <para>
4006             As an alternative, an implementation MAY find the information
4007             in the following file located in the current user's home directory,
4008             in subdirectory .dbus/session-bus/:
4009             <itemizedlist>
4010               <listitem>
4011                 <para>the machine's ID</para>
4012               </listitem>
4013
4014               <listitem>
4015                 <para>the literal character '-' (dash)</para>
4016               </listitem>
4017
4018               <listitem>
4019                 <para>the X display without the screen number, with the
4020                 following prefixes removed, if present: ":", "localhost:"
4021                 ."localhost.localdomain:". That is, a display of
4022                 "localhost:10.0" produces just the number "10"</para>
4023               </listitem>
4024             </itemizedlist>
4025           </para>
4026
4027           <para>
4028             The contents of this file NAME=value assignment pairs and
4029             lines starting with # are comments (no comments are allowed
4030             otherwise). The following variable names are defined:
4031             <informaltable
4032               frame="all">
4033               <tgroup cols="2">
4034                 <tbody>
4035                   <row>
4036                     <entry>
4037                       <para>Variable</para>
4038                     </entry>
4039
4040                     <entry>
4041                       <para>meaning</para>
4042                     </entry>
4043                   </row>
4044
4045                   <row>
4046                     <entry>
4047                       <para>DBUS_SESSION_BUS_ADDRESS</para>
4048                     </entry>
4049
4050                     <entry>
4051                       <para>the actual address of the server socket</para>
4052                     </entry>
4053                   </row>
4054
4055                   <row>
4056                     <entry>
4057                       <para>DBUS_SESSION_BUS_PID</para>
4058                     </entry>
4059
4060                     <entry>
4061                       <para>the PID of the server process</para>
4062                     </entry>
4063                   </row>
4064
4065                   <row>
4066                     <entry>
4067                       <para>DBUS_SESSION_BUS_WINDOWID</para>
4068                     </entry>
4069
4070                     <entry>
4071                       <para>the window ID</para>
4072                     </entry>
4073                   </row>
4074                 </tbody>
4075               </tgroup>
4076             </informaltable>
4077           </para>
4078
4079           <para>
4080             At least the DBUS_SESSION_BUS_ADDRESS variable MUST be present
4081             in this file.
4082           </para>
4083
4084           <para>
4085             Failure to open this file MUST be interpreted as absence of a
4086             running server. Therefore, the implementation MUST proceed to
4087             attempting to launch a new bus server if the file cannot be
4088             opened.
4089           </para>
4090
4091           <para>
4092             However, success in opening this file MUST NOT lead to the
4093             conclusion that the server is running. Thus, a failure to connect to
4094             the bus address obtained by the alternative method MUST NOT be
4095             considered a fatal error. If the connection cannot be established,
4096             the implementation MUST proceed to check the X selection settings or
4097             to start the server on its own.
4098           </para>
4099
4100           <para>
4101             If the implementation concludes that the D-Bus server is not
4102             running it MUST attempt to start a new server and it MUST also
4103             ensure that the daemon started as an effect of the "autolaunch"
4104             mechanism provides the lookup mechanisms described above, so
4105             subsequent calls can locate the newly started server. The
4106             implementation MUST also ensure that if two or more concurrent
4107             initiations happen, only one server remains running and all other
4108             initiations are able to obtain the address of this server and
4109             connect to it. In other words, the implementation MUST ensure that
4110             the X selection is not present when it attempts to set it, without
4111             allowing another process to set the selection between the
4112             verification and the setting (e.g., by using XGrabServer /
4113             XungrabServer).
4114           </para>
4115         </sect4>
4116         <sect4>
4117           <title></title>
4118           <para>
4119             [FIXME specify location of .service files, probably using
4120             DESKTOP_DIRS etc. from basedir specification, though login session
4121             bus is not really desktop-specific]
4122           </para>
4123         </sect4>
4124       </sect3>
4125       <sect3 id="message-bus-types-system">
4126         <title>System message bus</title>
4127         <para>
4128           A computer may have a <firstterm>system message bus</firstterm>,
4129           accessible to all applications on the system. This message bus may be
4130           used to broadcast system events, such as adding new hardware devices, 
4131           changes in the printer queue, and so forth.
4132         </para>
4133         <para>
4134           The address of the system message bus is given 
4135           in the <literal>DBUS_SYSTEM_BUS_ADDRESS</literal> environment 
4136           variable. If that variable is not set, applications should try 
4137           to connect to the well-known address
4138           <literal>unix:path=/var/run/dbus/system_bus_socket</literal>.
4139           <footnote>
4140             <para>
4141               The D-Bus reference implementation actually honors the 
4142               <literal>$(localstatedir)</literal> configure option 
4143               for this address, on both client and server side.
4144             </para>
4145           </footnote>
4146         </para>
4147         <para>
4148           [FIXME specify location of system bus .service files]
4149         </para>
4150       </sect3>
4151     </sect2>
4152
4153     <sect2 id="message-bus-messages">
4154       <title>Message Bus Messages</title>
4155       <para>
4156         The special message bus name <literal>org.freedesktop.DBus</literal>
4157         responds to a number of additional messages.
4158       </para>
4159
4160       <sect3 id="bus-messages-hello">
4161         <title><literal>org.freedesktop.DBus.Hello</literal></title>
4162         <para>
4163           As a method:
4164           <programlisting>
4165             STRING Hello ()
4166           </programlisting>
4167           Reply arguments:
4168           <informaltable>
4169             <tgroup cols="3">
4170               <thead>
4171                 <row>
4172                   <entry>Argument</entry>
4173                   <entry>Type</entry>
4174                   <entry>Description</entry>
4175                 </row>
4176               </thead>
4177               <tbody>
4178                 <row>
4179                   <entry>0</entry>
4180                   <entry>STRING</entry>
4181                   <entry>Unique name assigned to the connection</entry>
4182                 </row>
4183               </tbody>
4184             </tgroup>
4185           </informaltable>
4186         </para>
4187         <para>
4188           Before an application is able to send messages to other applications
4189           it must send the <literal>org.freedesktop.DBus.Hello</literal> message
4190           to the message bus to obtain a unique name. If an application without
4191           a unique name tries to send a message to another application, or a
4192           message to the message bus itself that isn't the
4193           <literal>org.freedesktop.DBus.Hello</literal> message, it will be
4194           disconnected from the bus.
4195         </para>
4196         <para>
4197           There is no corresponding "disconnect" request; if a client wishes to
4198           disconnect from the bus, it simply closes the socket (or other 
4199           communication channel).
4200         </para>
4201       </sect3>
4202       <sect3 id="bus-messages-list-names">
4203         <title><literal>org.freedesktop.DBus.ListNames</literal></title>
4204         <para>
4205           As a method:
4206           <programlisting>
4207             ARRAY of STRING ListNames ()
4208           </programlisting>
4209           Reply arguments:
4210           <informaltable>
4211             <tgroup cols="3">
4212               <thead>
4213                 <row>
4214                   <entry>Argument</entry>
4215                   <entry>Type</entry>
4216                   <entry>Description</entry>
4217                 </row>
4218               </thead>
4219               <tbody>
4220                 <row>
4221                   <entry>0</entry>
4222                   <entry>ARRAY of STRING</entry>
4223                   <entry>Array of strings where each string is a bus name</entry>
4224                 </row>
4225               </tbody>
4226             </tgroup>
4227           </informaltable>
4228         </para>
4229         <para>
4230           Returns a list of all currently-owned names on the bus.
4231         </para>
4232       </sect3>
4233       <sect3 id="bus-messages-list-activatable-names">
4234         <title><literal>org.freedesktop.DBus.ListActivatableNames</literal></title>
4235         <para>
4236           As a method:
4237           <programlisting>
4238             ARRAY of STRING ListActivatableNames ()
4239           </programlisting>
4240           Reply arguments:
4241           <informaltable>
4242             <tgroup cols="3">
4243               <thead>
4244                 <row>
4245                   <entry>Argument</entry>
4246                   <entry>Type</entry>
4247                   <entry>Description</entry>
4248                 </row>
4249               </thead>
4250               <tbody>
4251                 <row>
4252                   <entry>0</entry>
4253                   <entry>ARRAY of STRING</entry>
4254                   <entry>Array of strings where each string is a bus name</entry>
4255                 </row>
4256               </tbody>
4257             </tgroup>
4258           </informaltable>
4259         </para>
4260         <para>
4261           Returns a list of all names that can be activated on the bus.
4262         </para>
4263       </sect3>
4264       <sect3 id="bus-messages-name-exists">
4265         <title><literal>org.freedesktop.DBus.NameHasOwner</literal></title>
4266         <para>
4267           As a method:
4268           <programlisting>
4269             BOOLEAN NameHasOwner (in STRING name)
4270           </programlisting>
4271           Message arguments:
4272           <informaltable>
4273             <tgroup cols="3">
4274               <thead>
4275                 <row>
4276                   <entry>Argument</entry>
4277                   <entry>Type</entry>
4278                   <entry>Description</entry>
4279                 </row>
4280               </thead>
4281               <tbody>
4282                 <row>
4283                   <entry>0</entry>
4284                   <entry>STRING</entry>
4285                   <entry>Name to check</entry>
4286                 </row>
4287               </tbody>
4288             </tgroup>
4289           </informaltable>
4290           Reply arguments:
4291           <informaltable>
4292             <tgroup cols="3">
4293               <thead>
4294                 <row>
4295                   <entry>Argument</entry>
4296                   <entry>Type</entry>
4297                   <entry>Description</entry>
4298                 </row>
4299               </thead>
4300               <tbody>
4301                 <row>
4302                   <entry>0</entry>
4303                   <entry>BOOLEAN</entry>
4304                   <entry>Return value, true if the name exists</entry>
4305                 </row>
4306               </tbody>
4307             </tgroup>
4308           </informaltable>
4309         </para>
4310         <para>
4311           Checks if the specified name exists (currently has an owner).
4312         </para>
4313       </sect3>
4314
4315       <sect3 id="bus-messages-name-owner-changed">
4316         <title><literal>org.freedesktop.DBus.NameOwnerChanged</literal></title>
4317         <para>
4318           This is a signal:
4319           <programlisting>
4320             NameOwnerChanged (STRING name, STRING old_owner, STRING new_owner)
4321           </programlisting>
4322           Message arguments:
4323           <informaltable>
4324             <tgroup cols="3">
4325               <thead>
4326                 <row>
4327                   <entry>Argument</entry>
4328                   <entry>Type</entry>
4329                   <entry>Description</entry>
4330                 </row>
4331               </thead>
4332               <tbody>
4333                 <row>
4334                   <entry>0</entry>
4335                   <entry>STRING</entry>
4336                   <entry>Name with a new owner</entry>
4337                 </row>
4338                 <row>
4339                   <entry>1</entry>
4340                   <entry>STRING</entry>
4341                   <entry>Old owner or empty string if none</entry>
4342                 </row>
4343                 <row>
4344                   <entry>2</entry>
4345                   <entry>STRING</entry>
4346                   <entry>New owner or empty string if none</entry>
4347                 </row>
4348               </tbody>
4349             </tgroup>
4350           </informaltable>
4351         </para>
4352         <para>
4353           This signal indicates that the owner of a name has changed.
4354           It's also the signal to use to detect the appearance of 
4355           new names on the bus.
4356         </para>
4357       </sect3>
4358       <sect3 id="bus-messages-name-lost">
4359         <title><literal>org.freedesktop.DBus.NameLost</literal></title>
4360         <para>
4361           This is a signal:
4362           <programlisting>
4363             NameLost (STRING name)
4364           </programlisting>
4365           Message arguments:
4366           <informaltable>
4367             <tgroup cols="3">
4368               <thead>
4369                 <row>
4370                   <entry>Argument</entry>
4371                   <entry>Type</entry>
4372                   <entry>Description</entry>
4373                 </row>
4374               </thead>
4375               <tbody>
4376                 <row>
4377                   <entry>0</entry>
4378                   <entry>STRING</entry>
4379                   <entry>Name which was lost</entry>
4380                 </row>
4381               </tbody>
4382             </tgroup>
4383           </informaltable>
4384         </para>
4385         <para>
4386           This signal is sent to a specific application when it loses
4387           ownership of a name.
4388         </para>
4389       </sect3>
4390
4391       <sect3 id="bus-messages-name-acquired">
4392         <title><literal>org.freedesktop.DBus.NameAcquired</literal></title>
4393         <para>
4394           This is a signal:
4395           <programlisting>
4396             NameAcquired (STRING name)
4397           </programlisting>
4398           Message arguments:
4399           <informaltable>
4400             <tgroup cols="3">
4401               <thead>
4402                 <row>
4403                   <entry>Argument</entry>
4404                   <entry>Type</entry>
4405                   <entry>Description</entry>
4406                 </row>
4407               </thead>
4408               <tbody>
4409                 <row>
4410                   <entry>0</entry>
4411                   <entry>STRING</entry>
4412                   <entry>Name which was acquired</entry>
4413                 </row>
4414               </tbody>
4415             </tgroup>
4416           </informaltable>
4417         </para>
4418         <para>
4419           This signal is sent to a specific application when it gains
4420           ownership of a name.
4421         </para>
4422       </sect3>
4423
4424       <sect3 id="bus-messages-start-service-by-name">
4425         <title><literal>org.freedesktop.DBus.StartServiceByName</literal></title>
4426         <para>
4427           As a method:
4428           <programlisting>
4429             UINT32 StartServiceByName (in STRING name, in UINT32 flags)
4430           </programlisting>
4431           Message arguments:
4432           <informaltable>
4433             <tgroup cols="3">
4434               <thead>
4435                 <row>
4436                   <entry>Argument</entry>
4437                   <entry>Type</entry>
4438                   <entry>Description</entry>
4439                 </row>
4440               </thead>
4441               <tbody>
4442                 <row>
4443                   <entry>0</entry>
4444                   <entry>STRING</entry>
4445                   <entry>Name of the service to start</entry>
4446                 </row>
4447                 <row>
4448                   <entry>1</entry>
4449                   <entry>UINT32</entry>
4450                   <entry>Flags (currently not used)</entry>
4451                 </row>
4452               </tbody>
4453             </tgroup>
4454           </informaltable>
4455         Reply arguments:
4456         <informaltable>
4457           <tgroup cols="3">
4458             <thead>
4459               <row>
4460                 <entry>Argument</entry>
4461                 <entry>Type</entry>
4462                 <entry>Description</entry>
4463               </row>
4464             </thead>
4465             <tbody>
4466               <row>
4467                 <entry>0</entry>
4468                 <entry>UINT32</entry>
4469                 <entry>Return value</entry>
4470               </row>
4471             </tbody>
4472           </tgroup>
4473         </informaltable>
4474           Tries to launch the executable associated with a name. For more information, see <xref linkend="message-bus-starting-services"/>.
4475
4476         </para>
4477         <para>
4478           The return value can be one of the following values:
4479           <informaltable>
4480             <tgroup cols="3">
4481               <thead>
4482                 <row>
4483                   <entry>Identifier</entry>
4484                   <entry>Value</entry>
4485                   <entry>Description</entry>
4486                 </row>
4487               </thead>
4488               <tbody>
4489                 <row>
4490                   <entry>DBUS_START_REPLY_SUCCESS</entry>
4491                   <entry>1</entry>
4492                   <entry>The service was successfully started.</entry>
4493                 </row>
4494                 <row>
4495                   <entry>DBUS_START_REPLY_ALREADY_RUNNING</entry>
4496                   <entry>2</entry>
4497                   <entry>A connection already owns the given name.</entry>
4498                 </row>
4499               </tbody>
4500              </tgroup>
4501            </informaltable>
4502         </para>
4503
4504       </sect3>
4505
4506       <sect3 id="bus-messages-update-activation-environment">
4507         <title><literal>org.freedesktop.DBus.UpdateActivationEnvironment</literal></title>
4508         <para>
4509           As a method:
4510           <programlisting>
4511             UpdateActivationEnvironment (in ARRAY of DICT&lt;STRING,STRING&gt; environment)
4512           </programlisting>
4513           Message arguments:
4514           <informaltable>
4515             <tgroup cols="3">
4516               <thead>
4517                 <row>
4518                   <entry>Argument</entry>
4519                   <entry>Type</entry>
4520                   <entry>Description</entry>
4521                 </row>
4522               </thead>
4523               <tbody>
4524                 <row>
4525                   <entry>0</entry>
4526                   <entry>ARRAY of DICT&lt;STRING,STRING&gt;</entry>
4527                   <entry>Environment to add or update</entry>
4528                 </row>
4529               </tbody>
4530             </tgroup>
4531             </informaltable>
4532             Normally, session bus activated services inherit the environment of the bus daemon.  This method adds to or modifies that environment when activating services.
4533         </para>
4534         <para>
4535           Some bus instances, such as the standard system bus, may disable access to this method for some or all callers.
4536         </para>
4537         <para>
4538           Note, both the environment variable names and values must be valid UTF-8.  There's no way to update the activation environment with data that is invalid UTF-8.
4539         </para>
4540
4541       </sect3>
4542
4543       <sect3 id="bus-messages-get-name-owner">
4544         <title><literal>org.freedesktop.DBus.GetNameOwner</literal></title>
4545         <para>
4546           As a method:
4547           <programlisting>
4548             STRING GetNameOwner (in STRING name)
4549           </programlisting>
4550           Message arguments:
4551           <informaltable>
4552             <tgroup cols="3">
4553               <thead>
4554                 <row>
4555                   <entry>Argument</entry>
4556                   <entry>Type</entry>
4557                   <entry>Description</entry>
4558                 </row>
4559               </thead>
4560               <tbody>
4561                 <row>
4562                   <entry>0</entry>
4563                   <entry>STRING</entry>
4564                   <entry>Name to get the owner of</entry>
4565                 </row>
4566               </tbody>
4567             </tgroup>
4568           </informaltable>
4569         Reply arguments:
4570         <informaltable>
4571           <tgroup cols="3">
4572             <thead>
4573               <row>
4574                 <entry>Argument</entry>
4575                 <entry>Type</entry>
4576                 <entry>Description</entry>
4577               </row>
4578             </thead>
4579             <tbody>
4580               <row>
4581                 <entry>0</entry>
4582                 <entry>STRING</entry>
4583                 <entry>Return value, a unique connection name</entry>
4584               </row>
4585             </tbody>
4586           </tgroup>
4587         </informaltable>
4588         Returns the unique connection name of the primary owner of the name
4589         given. If the requested name doesn't have an owner, returns a
4590         <literal>org.freedesktop.DBus.Error.NameHasNoOwner</literal> error.
4591        </para>
4592       </sect3>
4593
4594       <sect3 id="bus-messages-get-connection-unix-user">
4595         <title><literal>org.freedesktop.DBus.GetConnectionUnixUser</literal></title>
4596         <para>
4597           As a method:
4598           <programlisting>
4599             UINT32 GetConnectionUnixUser (in STRING bus_name)
4600           </programlisting>
4601           Message arguments:
4602           <informaltable>
4603             <tgroup cols="3">
4604               <thead>
4605                 <row>
4606                   <entry>Argument</entry>
4607                   <entry>Type</entry>
4608                   <entry>Description</entry>
4609                 </row>
4610               </thead>
4611               <tbody>
4612                 <row>
4613                   <entry>0</entry>
4614                   <entry>STRING</entry>
4615                   <entry>Unique or well-known bus name of the connection to
4616                     query, such as <literal>:12.34</literal> or
4617                     <literal>com.example.tea</literal></entry>
4618                 </row>
4619               </tbody>
4620             </tgroup>
4621           </informaltable>
4622         Reply arguments:
4623         <informaltable>
4624           <tgroup cols="3">
4625             <thead>
4626               <row>
4627                 <entry>Argument</entry>
4628                 <entry>Type</entry>
4629                 <entry>Description</entry>
4630               </row>
4631             </thead>
4632             <tbody>
4633               <row>
4634                 <entry>0</entry>
4635                 <entry>UINT32</entry>
4636                 <entry>Unix user ID</entry>
4637               </row>
4638             </tbody>
4639           </tgroup>
4640         </informaltable>
4641         Returns the Unix user ID of the process connected to the server. If
4642         unable to determine it (for instance, because the process is not on the
4643         same machine as the bus daemon), an error is returned.
4644        </para>
4645       </sect3>
4646
4647       <sect3 id="bus-messages-get-connection-unix-process-id">
4648         <title><literal>org.freedesktop.DBus.GetConnectionUnixProcessID</literal></title>
4649         <para>
4650           As a method:
4651           <programlisting>
4652             UINT32 GetConnectionUnixProcessID (in STRING bus_name)
4653           </programlisting>
4654           Message arguments:
4655           <informaltable>
4656             <tgroup cols="3">
4657               <thead>
4658                 <row>
4659                   <entry>Argument</entry>
4660                   <entry>Type</entry>
4661                   <entry>Description</entry>
4662                 </row>
4663               </thead>
4664               <tbody>
4665                 <row>
4666                   <entry>0</entry>
4667                   <entry>STRING</entry>
4668                   <entry>Unique or well-known bus name of the connection to
4669                     query, such as <literal>:12.34</literal> or
4670                     <literal>com.example.tea</literal></entry>
4671                 </row>
4672               </tbody>
4673             </tgroup>
4674           </informaltable>
4675         Reply arguments:
4676         <informaltable>
4677           <tgroup cols="3">
4678             <thead>
4679               <row>
4680                 <entry>Argument</entry>
4681                 <entry>Type</entry>
4682                 <entry>Description</entry>
4683               </row>
4684             </thead>
4685             <tbody>
4686               <row>
4687                 <entry>0</entry>
4688                 <entry>UINT32</entry>
4689                 <entry>Unix process id</entry>
4690               </row>
4691             </tbody>
4692           </tgroup>
4693         </informaltable>
4694         Returns the Unix process ID of the process connected to the server. If
4695         unable to determine it (for instance, because the process is not on the
4696         same machine as the bus daemon), an error is returned.
4697        </para>
4698       </sect3>
4699
4700       <sect3 id="bus-messages-add-match">
4701         <title><literal>org.freedesktop.DBus.AddMatch</literal></title>
4702         <para>
4703           As a method:
4704           <programlisting>
4705             AddMatch (in STRING rule)
4706           </programlisting>
4707           Message arguments:
4708           <informaltable>
4709             <tgroup cols="3">
4710               <thead>
4711                 <row>
4712                   <entry>Argument</entry>
4713                   <entry>Type</entry>
4714                   <entry>Description</entry>
4715                 </row>
4716               </thead>
4717               <tbody>
4718                 <row>
4719                   <entry>0</entry>
4720                   <entry>STRING</entry>
4721                   <entry>Match rule to add to the connection</entry>
4722                 </row>
4723               </tbody>
4724             </tgroup>
4725           </informaltable>
4726         Adds a match rule to match messages going through the message bus (see <xref linkend='message-bus-routing-match-rules'/>). 
4727         If the bus does not have enough resources the <literal>org.freedesktop.DBus.Error.OOM</literal>
4728         error is returned.
4729        </para>
4730       </sect3>
4731       <sect3 id="bus-messages-remove-match">
4732         <title><literal>org.freedesktop.DBus.RemoveMatch</literal></title>
4733         <para>
4734           As a method:
4735           <programlisting>
4736             RemoveMatch (in STRING rule)
4737           </programlisting>
4738           Message arguments:
4739           <informaltable>
4740             <tgroup cols="3">
4741               <thead>
4742                 <row>
4743                   <entry>Argument</entry>
4744                   <entry>Type</entry>
4745                   <entry>Description</entry>
4746                 </row>
4747               </thead>
4748               <tbody>
4749                 <row>
4750                   <entry>0</entry>
4751                   <entry>STRING</entry>
4752                   <entry>Match rule to remove from the connection</entry>
4753                 </row>
4754               </tbody>
4755             </tgroup>
4756           </informaltable>
4757         Removes the first rule that matches (see <xref linkend='message-bus-routing-match-rules'/>). 
4758         If the rule is not found the <literal>org.freedesktop.DBus.Error.MatchRuleNotFound</literal>
4759         error is returned.
4760        </para>
4761       </sect3>
4762
4763       <sect3 id="bus-messages-get-id">
4764         <title><literal>org.freedesktop.DBus.GetId</literal></title>
4765         <para>
4766           As a method:
4767           <programlisting>
4768             GetId (out STRING id)
4769           </programlisting>
4770         Reply arguments:
4771         <informaltable>
4772           <tgroup cols="3">
4773             <thead>
4774               <row>
4775                 <entry>Argument</entry>
4776                 <entry>Type</entry>
4777                 <entry>Description</entry>
4778               </row>
4779             </thead>
4780             <tbody>
4781               <row>
4782                 <entry>0</entry>
4783                 <entry>STRING</entry>
4784                 <entry>Unique ID identifying the bus daemon</entry>
4785               </row>
4786             </tbody>
4787           </tgroup>
4788         </informaltable>
4789         Gets the unique ID of the bus. The unique ID here is shared among all addresses the 
4790         bus daemon is listening on (TCP, UNIX domain socket, etc.) and its format is described in 
4791         <xref linkend="uuids"/>. Each address the bus is listening on also has its own unique 
4792         ID, as described in <xref linkend="addresses"/>. The per-bus and per-address IDs are not related.
4793         There is also a per-machine ID, described in <xref linkend="standard-interfaces-peer"/> and returned
4794         by org.freedesktop.DBus.Peer.GetMachineId().
4795         For a desktop session bus, the bus ID can be used as a way to uniquely identify a user's session.
4796         </para>
4797       </sect3>
4798
4799     </sect2>
4800
4801   </sect1>
4802 <!--
4803   <appendix id="implementation-notes">
4804     <title>Implementation notes</title>
4805     <sect1 id="implementation-notes-subsection">
4806       <title></title>
4807       <para>
4808       </para>
4809     </sect1>
4810   </appendix>
4811 -->
4812
4813   <glossary><title>Glossary</title>
4814     <para>
4815       This glossary defines some of the terms used in this specification.
4816     </para>
4817
4818     <glossentry id="term-bus-name"><glossterm>Bus Name</glossterm>
4819       <glossdef>
4820         <para>
4821           The message bus maintains an association between names and
4822           connections. (Normally, there's one connection per application.)  A
4823           bus name is simply an identifier used to locate connections. For
4824           example, the hypothetical <literal>com.yoyodyne.Screensaver</literal>
4825           name might be used to send a message to a screensaver from Yoyodyne
4826           Corporation.  An application is said to <firstterm>own</firstterm> a
4827           name if the message bus has associated the application's connection
4828           with the name.  Names may also have <firstterm>queued
4829           owners</firstterm> (see <xref linkend="term-queued-owner"/>).
4830             The bus assigns a unique name to each connection, 
4831             see <xref linkend="term-unique-name"/>. Other names 
4832               can be thought of as "well-known names" and are 
4833               used to find applications that offer specific functionality.
4834         </para>
4835       </glossdef>
4836     </glossentry>
4837       
4838     <glossentry id="term-message"><glossterm>Message</glossterm>
4839       <glossdef>
4840         <para>
4841           A message is the atomic unit of communication via the D-Bus
4842           protocol. It consists of a <firstterm>header</firstterm> and a
4843           <firstterm>body</firstterm>; the body is made up of
4844           <firstterm>arguments</firstterm>.
4845         </para>
4846       </glossdef>
4847     </glossentry>
4848
4849     <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
4850       <glossdef>
4851         <para>
4852           The message bus is a special application that forwards 
4853           or routes messages between a group of applications
4854           connected to the message bus. It also manages 
4855           <firstterm>names</firstterm> used for routing
4856           messages.
4857         </para>
4858       </glossdef>
4859     </glossentry>
4860
4861     <glossentry id="term-name"><glossterm>Name</glossterm>
4862       <glossdef>
4863         <para>
4864           See <xref linkend="term-bus-name"/>. "Name" may 
4865             also be used to refer to some of the other names
4866             in D-Bus, such as interface names.
4867         </para>
4868       </glossdef>
4869     </glossentry>
4870
4871     <glossentry id="namespace"><glossterm>Namespace</glossterm>
4872       <glossdef>
4873         <para>
4874           Used to prevent collisions when defining new interfaces or bus
4875           names. The convention used is the same one Java uses for defining
4876           classes: a reversed domain name.
4877         </para>
4878       </glossdef>
4879     </glossentry>
4880
4881     <glossentry id="term-object"><glossterm>Object</glossterm>
4882       <glossdef>
4883         <para>
4884           Each application contains <firstterm>objects</firstterm>, which have
4885           <firstterm>interfaces</firstterm> and
4886           <firstterm>methods</firstterm>. Objects are referred to by a name,
4887           called a <firstterm>path</firstterm>.
4888         </para>
4889       </glossdef>
4890     </glossentry>
4891
4892     <glossentry id="one-to-one"><glossterm>One-to-One</glossterm>
4893       <glossdef>
4894         <para>
4895           An application talking directly to another application, without going
4896           through a message bus. One-to-one connections may be "peer to peer" or
4897           "client to server." The D-Bus protocol has no concept of client
4898           vs. server after a connection has authenticated; the flow of messages
4899           is symmetrical (full duplex).
4900         </para>
4901       </glossdef>
4902     </glossentry>
4903
4904     <glossentry id="term-path"><glossterm>Path</glossterm>
4905       <glossdef>
4906         <para>
4907           Object references (object names) in D-Bus are organized into a
4908           filesystem-style hierarchy, so each object is named by a path. As in
4909           LDAP, there's no difference between "files" and "directories"; a path
4910           can refer to an object, while still having child objects below it.
4911         </para>
4912       </glossdef>
4913     </glossentry>
4914
4915     <glossentry id="term-queued-owner"><glossterm>Queued Name Owner</glossterm>
4916       <glossdef>
4917         <para>
4918           Each bus name has a primary owner; messages sent to the name go to the
4919           primary owner. However, certain names also maintain a queue of
4920           secondary owners "waiting in the wings." If the primary owner releases
4921           the name, then the first secondary owner in the queue automatically
4922           becomes the new owner of the name.
4923         </para>
4924       </glossdef>
4925     </glossentry>
4926
4927     <glossentry id="term-service"><glossterm>Service</glossterm>
4928       <glossdef>
4929         <para>
4930           A service is an executable that can be launched by the bus daemon.
4931           Services normally guarantee some particular features, for example they
4932           may guarantee that they will request a specific name such as
4933           "org.freedesktop.Screensaver", have a singleton object
4934           "/org/freedesktop/Application", and that object will implement the
4935           interface "org.freedesktop.ScreensaverControl".
4936         </para>
4937       </glossdef>
4938     </glossentry>
4939
4940     <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
4941       <glossdef>
4942         <para>
4943           ".service files" tell the bus about service applications that can be
4944           launched (see <xref linkend="term-service"/>). Most importantly they
4945           provide a mapping from bus names to services that will request those
4946             names when they start up.
4947         </para>
4948       </glossdef>
4949     </glossentry>
4950
4951     <glossentry id="term-unique-name"><glossterm>Unique Connection Name</glossterm>
4952       <glossdef>
4953         <para>
4954           The special name automatically assigned to each connection by the
4955           message bus. This name will never change owner, and will be unique
4956           (never reused during the lifetime of the message bus).
4957           It will begin with a ':' character.
4958         </para>
4959       </glossdef>
4960     </glossentry>
4961
4962   </glossary>
4963 </article>