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