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