200ef430fab3a722286a55d6798e7c976d2cdaa1
[platform/upstream/dbus.git] / doc / dbus-specification.sgml
1 <!doctype article PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
2 ]>
3 <article id="index">
4   <artheader>
5     <title>D-BUS Specification</title>
6     <releaseinfo>Version 0.7</releaseinfo>
7     <date>26 March 2003</date>
8     <authorgroup>
9       <author>
10         <firstname>Havoc</firstname>
11         <surname>Pennington</surname>
12         <affiliation>
13           <address>
14             <email>hp@pobox.com</email>
15           </address>
16         </affiliation>
17       </author>
18       <author>
19         <firstname>Anders</firstname>
20         <surname>Carlsson</surname>
21         <affiliation>
22           <orgname>CodeFactory AB</orgname>
23           <address>
24             <email>andersca@codefactory.se</email>
25           </address>
26         </affiliation>
27       </author>
28     </authorgroup>
29   </artheader>
30
31   <sect1 id="introduction">
32     <title>Introduction</title>
33     <para>
34       D-BUS is a system for low-latency, low-overhead, easy to use
35       interprocess communication (IPC). In more detail:
36       <itemizedlist>
37         <listitem>
38           <para>
39             D-BUS is <emphasis>low-latency</emphasis> because it is designed 
40             to avoid round trips and allow asynchronous operation, much like 
41             the X protocol.
42           </para>
43         </listitem>
44         <listitem>
45           <para>
46             D-BUS is <emphasis>low-overhead</emphasis> because it uses a
47             binary protocol, and does not have to convert to and from a text
48             format such as XML. Because D-BUS is intended for potentially
49             high-resolution same-machine IPC, not primarily for Internet IPC,
50             this is an interesting optimization.
51           </para>
52         </listitem>
53         <listitem>
54           <para>
55             D-BUS is <emphasis>easy to use</emphasis> because it works in terms
56             of <firstterm>messages</firstterm> rather than byte streams, and
57             does not require users to understand any complex concepts such as a
58             new type system or elaborate APIs. Libraries implementing D-BUS 
59             may choose to abstract messages as "method calls" (see 
60             <xref linkend="message-conventions-method">).
61           </para>
62         </listitem>
63       </itemizedlist>
64     </para>
65     <para>
66       The base D-BUS protocol is a peer-to-peer protocol, specified in <xref
67       linkend="message-protocol">. That is, it is a system for one application
68       to talk to a single other application. However, the primary intended
69       application of D-BUS is the D-BUS <firstterm>message bus</firstterm>,
70       specified in <xref linkend="message-bus">. The message bus is a special
71       application that accepts connections from multiple other applications, and
72       forwards messages among them.
73     </para>
74     <para>
75       Things that D-BUS can be used for is for example notification of
76       system changes (notification of when a camera is plugged in to a
77       computer, or a new version of some software has been installed),
78       or desktop interoperablity, for example a file monitoring
79       service or a configuration service.
80     </para>
81   </sect1>
82
83   <sect1 id="message-protocol">
84     <title>Message Protocol</title>
85     <para>
86       A <firstterm>message</firstterm> consists of a
87       <firstterm>header</firstterm> and a <firstterm>body</firstterm>. If you
88       think of a message as a package, the header is the address, and the body
89       contains the package contents. The message delivery system uses the header
90       information to figure out where to send the message and how to interpret
91       it; the recipient inteprets the body of the message.
92     </para>
93     
94     <para>
95       The body of the message is made up of zero or more
96       <firstterm>arguments</firstterm>, which are typed 
97       values, such as an integer or a byte array.
98     </para>
99
100     <sect2 id="message-protocol-header-encoding">
101       <title>Header Encoding</title>
102       <para>
103         Following the mandatory fields, there are zero or more named fields (see
104         <xref linkend="message-protocol-header-fields">), and then nul bytes
105         padding the header such that its total length in bytes is a multiple of
106         8.
107       </para>
108       <para>
109         The header MUST begin with the following mandatory fields in the following
110         order:
111         <informaltable>
112           <tgroup cols=2>
113             <thead>
114               <row>
115                 <entry>Size</entry>
116                 <entry>Description</entry>
117               </row>
118             </thead>
119             <tbody>
120               <row>
121                 <entry>1 byte</entry>
122                 <entry>Endianness flag; ASCII 'l' for little-endian 
123                   or ASCII 'B' for big-endian.</entry>
124               </row>
125               <row>
126                 <entry>1 byte</entry>
127                 <entry>Bitwise OR of flags. Unknown flags
128                   MUST be ignored. Currently-defined flags are described below.
129                 </entry>
130               </row>
131               <row>
132                 <entry>1 byte</entry>
133                 <entry>Major protocol version of the sending application.  If
134                 the major protocol version of the receiving application does not
135                 match, the applications will not be able to communicate and the
136                 D-BUS connection MUST be disconnected. The major protocol
137                 version for this version of the specification is 0.
138                 </entry>
139               </row>
140               <row>
141                 <entry>1 byte</entry>
142                 <entry>A nul byte, reserved for future use.
143                   Any value for this byte MUST be accepted.
144                 </entry>
145               </row>
146               <row>
147                 <entry>4 bytes</entry>
148                 <entry>An unsigned 32-bit integer in the
149                   message's byte order, indicating the total length in bytes of
150                   the header including named fields and any alignment padding.
151                   MUST be a multiple of 8.
152                 </entry>
153               </row>
154               <row>
155                 <entry>4 bytes</entry>
156                 <entry>An unsigned 32-bit integer in the
157                   message's byte order, indicating the total length in bytes of
158                   the message body.
159                 </entry>
160               </row>      
161               <row>
162                 <entry>4 bytes</entry>
163                 <entry>The message's serial number, a signed 32-bit integer in
164                   the message's byte order. Applications MUST NOT reuse the same
165                   serial number for different messages more often than 32-bit
166                   integer wraparound. Serial numbers must be greater than 
167                   zero.
168                 </entry>
169               </row>
170             </tbody>
171           </tgroup>
172         </informaltable>
173       </para>
174       <para>
175         Flags that can appear in the second byte of the header:
176         <informaltable>
177           <tgroup cols=2>
178             <thead>
179               <row>
180                 <entry>Hex value</entry>
181                 <entry>Description</entry>
182               </row>
183             </thead>
184             <tbody>
185               <row>
186                 <entry>0x1</entry>
187                 <entry>This message is an error reply. If the first argument exists and is a string, it is an error message.</entry>
188               </row>
189             </tbody>
190           </tgroup>
191         </informaltable>
192       </para>
193     </sect2>
194
195     <sect2 id="message-protocol-header-fields">
196       <title>Header Fields</title>
197       <para>
198         In addition to the required header information mentioned 
199         in <xref linkend="message-protocol-header-encoding">, 
200           the header may contain zero or more named 
201           header fields. These fields are named to allow 
202           future versions of this protocol specification to 
203           add new fields; implementations must ignore fields 
204           they do not understand. Implementations must not 
205           invent their own header fields; only changes to 
206           this specification may introduce new header fields.
207       </para>
208
209       <para>
210         Header field names MUST consist of 4 non-nul bytes.  The field name is
211         NOT nul terminated; it occupies exactly 4 bytes. Following the name, 
212         the field MUST have a type code, and then a properly-aligned value 
213         of that type. 
214         See <xref linkend="message-protocol-arguments"> for a description 
215           of how each type is encoded. If an implementation sees a header 
216           field name that it does not understand, it MUST ignore 
217           that field.
218       </para>
219
220       <para>
221         Here are the currently-defined named header fields:
222         <informaltable>
223           <tgroup cols=3>
224             <thead>
225               <row>
226                 <entry>Name</entry>
227                 <entry>Type</entry>
228                 <entry>Description</entry>
229               </row>
230             </thead>
231             <tbody>
232               <row>
233                 <entry>name</entry>
234                 <entry>STRING</entry>
235                 <entry>The name of the message, such as org.freedesktop.Peer.Ping</entry>
236               </row>
237               <row>
238                 <entry>rply</entry>
239                 <entry>INT32</entry>
240                 <entry>The serial number of the message this message is a reply
241                 to. (The serial number is one of the mandatory header fields,
242                 see <xref linkend="message-protocol-header-encoding">.)</entry>
243               </row>
244               <row>
245                 <entry>srvc</entry>
246                 <entry>STRING</entry>
247                 <entry>The name of the service this message should be routed to. 
248                 Only used in combination with the message bus, see 
249                 <xref linkend="message-bus">.</entry>
250               </row>
251               <row>
252                 <entry>sndr</entry>
253                 <entry>STRING</entry>
254                 <entry>The name of the base service that sent this message. 
255                 The message bus fills in this field; the field is 
256                 only meaningful in combination with the message bus.</entry>
257               </row>
258             </tbody>
259           </tgroup>
260         </informaltable>
261       </para>
262       
263     </sect2>
264     <sect2 id="message-protocol-header-padding">
265       <title>Header Alignment Padding</title>
266       <para>
267         To allow implementations to keep the header and the body in a single
268         buffer while keeping data types aligned, the total length of the header
269         must be a multiple of 8 bytes.  To achieve this, the header MUST be padded
270         with nul bytes to align its total length on an 8-byte boundary. 
271         The minimum number of padding bytes MUST be used. Because all possible 
272         named fields use at least 8 bytes, implementations can distinguish 
273         padding (which must be less than 8 bytes) from additional named fields
274         (which must be at least 8 bytes).
275       </para>
276     </sect2>
277
278     <sect2 id="message-protocol-arguments">
279       <title>Message Arguments</title>
280       <para>
281         The message body is made up of arguments. Each argument
282         is a type code, followed by the value of the argument 
283         in a type-dependent format.
284       </para>
285       <para>
286         [FIXME perhaps we should add type BYTE with the primary 
287         advantage being that it occupies 1 byte vs. 7 for UINT32,
288         or perhaps space savings aren't worth the complexity]
289         <informaltable>
290           <tgroup cols=3>
291             <thead>
292               <row>
293                 <entry>Type name</entry>
294                 <entry>Code</entry>
295                 <entry>Description</entry>
296               </row>
297             </thead>
298             <tbody>
299               <row>
300                 <entry>INVALID</entry>
301                 <entry>0</entry>
302                 <entry>Not a valid type code (error if it appears in a message)</entry>
303               </row><row>
304                 <entry>NIL</entry>
305                 <entry>1</entry>
306                 <entry>Marks an "unset" or "nonexistent" argument</entry>
307               </row><row>
308                 <entry>BYTE</entry>
309                 <entry>2</entry>
310                 <entry>8-bit unsigned integer.</entry>
311               </row><row>
312                 <entry>BOOLEAN</entry>
313                 <entry>3</entry>
314                 <entry>Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.</entry>
315               </row><row>
316                 <entry>INT32</entry>
317                 <entry>4</entry>
318                 <entry>32-bit signed integer</entry>
319               </row><row>
320                 <entry>UINT32</entry>
321                 <entry>5</entry>
322                 <entry>32-bit unsigned integer</entry>
323               </row><row>
324                 <entry>DOUBLE</entry>
325                 <entry>6</entry>
326                 <entry>IEEE 754 double</entry>
327               </row><row>
328                 <entry>STRING</entry>
329                 <entry>7</entry>
330                 <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be zero terminated. </entry>
331               </row><row>
332                 <entry>NAMED</entry>
333                 <entry>8</entry>
334                 <entry>A named byte array, used for custom types</entry>
335               </row><row>
336                 <entry>ARRAY</entry>
337                 <entry>9</entry>
338                 <entry>Array</entry>
339               </row><row>
340                 <entry>DICT</entry>
341                 <entry>10</entry>
342                 <entry>A dictionary of key/value pairs</entry>
343               </row>
344             </tbody>
345           </tgroup>
346         </informaltable>
347       </para>
348       <para>
349         The types are encoded as follows:
350         <informaltable>
351           <tgroup cols=2>
352             <thead>
353               <row>
354                 <entry>Type name</entry>
355                 <entry>Encoding</entry>
356               </row>
357             </thead>
358             <tbody>
359               <row>
360                 <entry>INVALID</entry>
361                 <entry>Not applicable; cannot be encoded.</entry>
362               </row><row>
363                 <entry>NIL</entry>
364                 <entry>No data is encoded; the type code is followed immediately 
365                 by the type code of the next argument.</entry>
366               </row><row>
367                 <entry>BYTE</entry>
368                 <entry>a byte.</entry>
369               </row><row>
370                 <entry>BOOLEAN</entry>
371                 <entry>a byte, with valid values 0 and 1.</entry>
372               </row><row>
373                 <entry>INT32</entry>
374                 <entry>32-bit signed integer in the message's byte order, aligned to 4-byte boundary.</entry>
375               </row><row>
376                 <entry>UINT32</entry>
377                 <entry>32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary.</entry>
378               </row><row>
379                 <entry>DOUBLE</entry>
380                 <entry>64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary.</entry>
381               </row><row>
382                 <entry>STRING</entry>
383                 <entry>UINT32 aligned to 4-byte boundary indicating the string's 
384                   length in bytes excluding its terminating nul, followed by 
385                   string data of the given length, followed by a terminating nul 
386                   byte.
387                 </entry>
388               </row><row>
389                 <entry>NAMED</entry>
390                 <entry>A string (encoded as the STRING type above) giving the
391                   name of the type followed by an UINT32 aligned to 4-byte boundary
392                   indicating the data length in bytes, followed by the data.
393                 </entry>
394               </row><row>
395                 <entry>ARRAY</entry>
396                 <entry>a byte giving the element type of the array followed
397                 by an UINT32 (aligned to 4 bytes) giving the length of the
398                 array data in bytes. This is then followed by a number of
399                 entires with the same type, encoded like that type normally
400                 would be encoded alone.
401                 </entry>
402               </row><row>
403                 <entry>DICT</entry>
404                 <entry>UINT32 giving the length of the dictionary data in bytes.
405                 This is followed by a number of keyname/value pairs, where the
406                 keyname is encoded as a STRING above, and the value is encoded
407                 as a byte with typecode and how that type normally would be encoded
408                 alone.
409                 </entry>
410               </row>
411             </tbody>
412           </tgroup>
413         </informaltable>
414       </para>
415     </sect2>
416   </sect1>
417
418   <sect1 id="auth-protocol">
419     <title>Authentication Protocol</title>
420     <para>
421       Before the flow of messages begins, two applications must
422       authenticate. A simple plain-text protocol is used for
423       authentication; this protocol is a SASL profile, and maps fairly
424       directly from the SASL specification. The message encoding is
425       NOT used here, only plain text messages.
426     </para>
427     <para>
428       In examples, "C:" and "S:" indicate lines sent by the client and
429       server respectively.
430     </para>
431     <sect2 id="auth-protocol-overview">
432       <title>Protocol Overview</title>
433       <para>
434         The protocol is a line-based protocol, where each line ends with
435         \r\n. Each line begins with an all-caps ASCII command name containing
436         only the character range [A-Z], a space, then any arguments for the
437         command, then the \r\n ending the line. The protocol is
438         case-sensitive. All bytes must be in the ASCII character set.
439
440         Commands from the client to the server are as follows:
441
442         <itemizedlist>
443           <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
444           <listitem><para>CANCEL</para></listitem
445                                           <listitem><para>BEGIN</para></listitem>
446                                           <listitem><para>DATA &lt;data in base 64 encoding&gt;</para></listitem>
447                                           <listitem><para>ERROR [human-readable error explanation]</para></listitem>
448         </itemizedlist>
449
450         From server to client are as follows:
451
452         <itemizedlist>
453           <listitem><para>REJECTED &lt;space-separated list of mechanism names&gt;</para></listitem>
454           <listitem><para>OK</para></listitem>
455           <listitem><para>DATA &lt;data in base 64 encoding&gt;</para></listitem>
456           <listitem><para>ERROR</para></listitem>
457         </itemizedlist>
458       </para>
459     </sect2>
460     <sect2 id="auth-nul-byte">
461       <title>Special credentials-passing nul byte</title>
462       <para>
463         Immediately after connecting to the server, the client must send a
464         single nul byte. This byte may be accompanied by credentials
465         information on some operating systems that use sendmsg() with
466         SCM_CREDS or SCM_CREDENTIALS to pass credentials over UNIX domain
467         sockets. However, the nul byte MUST be sent even on other kinds of
468         socket, and even on operating systems that do not require a byte to be
469         sent in order to transmit credentials. The text protocol described in
470         this document begins after the single nul byte. If the first byte
471         received from the client is not a nul byte, the server may disconnect 
472         that client.
473       </para>
474       <para>
475         A nul byte in any context other than the initial byte is an error; 
476         the protocol is ASCII-only.
477       </para>
478       <para>
479         The credentials sent along with the nul byte may be used with the 
480         SASL mechanism EXTERNAL.
481       </para>
482     </sect2>
483     <sect2 id="auth-command-auth">
484       <title>AUTH command</title>
485       <para>
486         If an AUTH command has no arguments, it is a request to list
487         available mechanisms. The server SHOULD respond with a REJECTED
488         command listing the mechanisms it understands.
489       </para>
490       <para>
491         If an AUTH command specifies a mechanism, and the server supports
492         said mechanism, the server SHOULD begin exchanging SASL
493         challenge-response data with the client using DATA commands.
494       </para>
495       <para>
496         If the server does not support the mechanism given in the AUTH
497         command, it SHOULD send a REJECTED command listing the mechanisms
498         it does support.
499       </para>
500       <para>
501         If the [initial-response] argument is provided, it is intended for
502         use with mechanisms that have no initial challenge (or an empty
503         initial challenge), as if it were the argument to an initial DATA
504         command. If the selected mechanism has an initial challenge, the
505         server should reject authentication by sending REJECTED.
506       </para>
507       <para>
508         If authentication succeeds after exchanging DATA commands, 
509         an OK command should be sent to the client. 
510       </para>
511       <para>
512         The first octet received by the client after the \r\n of the OK
513         command MUST be the first octet of the authenticated/encrypted 
514         stream of D-BUS messages.
515       </para>
516       <para>
517         The first octet received by the server after the \r\n of the BEGIN
518         command from the client MUST be the first octet of the
519         authenticated/encrypted stream of D-BUS messages.
520       </para>
521     </sect2>
522     <sect2 id="auth-command-cancel">
523       <title>CANCEL Command</title>
524       <para>
525         At any time up to sending the BEGIN command, the client may send a
526         CANCEL command. On receiving the CANCEL command, the server MUST
527         send a REJECTED command and abort the current authentication
528         exchange.
529       </para>
530     </sect2>
531     <sect2 id="auth-command-data">
532       <title>DATA Command</title>
533       <para>
534         The DATA command may come from either client or server, and simply 
535         contains a base64-encoded block of data to be interpreted 
536         according to the SASL mechanism in use.
537       </para>
538       <para>
539         Some SASL mechanisms support sending an "empty string"; 
540         FIXME we need some way to do this.
541       </para>
542     </sect2>
543     <sect2 id="auth-command-begin">
544       <title>BEGIN Command</title>
545       <para>
546         The BEGIN command acknowledges that the client has received an 
547         OK command from the server, and that the stream of messages
548         is about to begin. 
549       </para>
550       <para>
551         The first octet received by the server after the \r\n of the BEGIN
552         command from the client MUST be the first octet of the
553         authenticated/encrypted stream of D-BUS messages.
554       </para>
555     </sect2>
556     <sect2 id="auth-command-rejected">
557       <title>REJECTED Command</title>
558       <para>
559         The REJECTED command indicates that the current authentication
560         exchange has failed, and further exchange of DATA is inappropriate.
561         The client would normally try another mechanism, or try providing
562         different responses to challenges.
563       </para><para>
564         Optionally, the REJECTED command has a space-separated list of
565         available auth mechanisms as arguments. If a server ever provides
566         a list of supported mechanisms, it MUST provide the same list 
567         each time it sends a REJECTED message. Clients are free to 
568         ignore all lists received after the first.
569       </para>
570     </sect2>
571     <sect2 id="auth-command-ok">
572       <title>OK Command</title>
573       <para>
574         The OK command indicates that the client has been authenticated,
575         and that further communication will be a stream of D-BUS messages
576         (optionally encrypted, as negotiated) rather than this protocol.
577       </para>
578       <para>
579         The first octet received by the client after the \r\n of the OK
580         command MUST be the first octet of the authenticated/encrypted 
581         stream of D-BUS messages.
582       </para>
583       <para>
584         The client MUST respond to the OK command by sending a BEGIN
585         command, followed by its stream of messages, or by disconnecting.
586         The server MUST NOT accept additional commands using this protocol 
587         after the OK command has been sent.
588       </para>
589     </sect2>
590     <sect2 id="auth-command-error">
591       <title>ERROR Command</title>
592       <para>
593         The ERROR command indicates that either server or client did not
594         know a command, does not accept the given command in the current
595         context, or did not understand the arguments to the command. This
596         allows the protocol to be extended; a client or server can send a
597         command present or permitted only in new protocol versions, and if
598         an ERROR is received instead of an appropriate response, fall back
599         to using some other technique.
600       </para><para>
601         If an ERROR is sent, the server or client MUST continue as if the
602         command causing the ERROR had never been received.
603       </para>
604     </sect2>
605     <sect2 id="auth-examples">
606       <title>Authentication examples</title>
607       
608       <para>
609         <figure>
610           <title>Example of successful magic cookie authentication</title>
611           <programlisting>
612             (MAGIC_COOKIE is a made up mechanism)
613
614             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
615             S: OK
616             C: BEGIN
617           </programlisting>
618         </figure>
619         <figure>
620           <title>Example of finding out mechanisms then picking one</title>
621           <programlisting>
622             C: AUTH
623             S: REJECTED KERBEROS_V4 SKEY
624             C: AUTH SKEY bW9yZ2Fu
625             S: DATA OTUgUWE1ODMwOA==
626             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
627             S: OK
628             C: BEGIN
629           </programlisting>
630         </figure>
631         <figure>
632           <title>Example of client sends unknown command then falls back to regular auth</title>
633           <programlisting>
634             C: FOOBAR
635             S: ERROR
636             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
637             S: OK
638             C: BEGIN
639           </programlisting>
640         </figure>
641         <figure>
642           <title>Example of server doesn't support initial auth mechanism</title>
643           <programlisting>
644             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
645             S: REJECTED KERBEROS_V4 SKEY
646             C: AUTH SKEY bW9yZ2Fu
647             S: DATA OTUgUWE1ODMwOA==
648             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
649             S: OK
650             C: BEGIN
651           </programlisting>
652         </figure>
653         <figure>
654           <title>Example of wrong password or the like followed by successful retry</title>
655           <programlisting>
656             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
657             S: REJECTED KERBEROS_V4 SKEY
658             C: AUTH SKEY bW9yZ2Fu
659             S: DATA OTUgUWE1ODMwOA==
660             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
661             S: REJECTED
662             C: AUTH SKEY bW9yZ2Fu
663             S: DATA OTUgUWE1ODMwOA==
664             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
665             S: OK
666             C: BEGIN
667           </programlisting>
668         </figure>
669         <figure>
670           <title>Example of skey cancelled and restarted</title>
671           <programlisting>
672             C: AUTH MAGIC_COOKIE BsAY3g4gBNo=
673             S: REJECTED KERBEROS_V4 SKEY
674             C: AUTH SKEY bW9yZ2Fu
675             S: DATA OTUgUWE1ODMwOA==
676             C: CANCEL
677             S: REJECTED
678             C: AUTH SKEY bW9yZ2Fu
679             S: DATA OTUgUWE1ODMwOA==
680             C: DATA Rk9VUiBNQU5OIFNPT04gRklSIFZBUlkgTUFTSA==
681             S: OK
682             C: BEGIN
683           </programlisting>
684         </figure>
685       </para>
686     </sect2>
687     <sect2 id="auth-mechanisms">
688       <title>Authentication mechanisms</title>
689       <para>
690         This section describes some new authentication mechanisms.
691         D-BUS also allows any standard SASL mechanism of course.
692       </para>
693       <sect3 id="auth-mechanisms-sha">
694         <title>DBUS_COOKIE_SHA1</title>
695         <para>
696           The DBUS_COOKIE_SHA1 mechanism is designed to establish that a client
697           has the ability to read a private file owned by the user being
698           authenticated. If the client can prove that it has access to a secret
699           cookie stored in this file, then the client is authenticated. 
700           Thus the security of DBUS_COOKIE_SHA1 depends on a secure home 
701           directory.
702         </para>
703         <para>
704           Authentication proceeds as follows:
705           <itemizedlist>
706             <listitem>
707               <para>
708                 The client sends the username it would like to authenticate 
709                 as.
710               </para>
711             </listitem>
712             <listitem>
713               <para>
714                 The server sends the name of its "cookie context" (see below); a
715                 space character; the integer ID of the secret cookie the client
716                 must demonstrate knowledge of; a space character; then a
717                 hex-encoded randomly-generated challenge string.
718               </para>
719             </listitem>
720             <listitem>
721               <para>
722                 The client locates the cookie, and generates its own hex-encoded
723                 randomly-generated challenge string.  The client then
724                 concatentates the server's hex-encoded challenge, a ":"
725                 character, its own hex-encoded challenge, another ":" character,
726                 and the hex-encoded cookie.  It computes the SHA-1 hash of this
727                 composite string.  It sends back to the server the client's
728                 hex-encoded challenge string, a space character, and the SHA-1
729                 hash.
730               </para>
731             </listitem>
732             <listitem>
733               <para>
734                 The server generates the same concatenated string used by the
735                 client and computes its SHA-1 hash. It compares the hash with
736                 the hash received from the client; if the two hashes match, the
737                 client is authenticated.
738               </para>
739             </listitem>
740           </itemizedlist>
741         </para>
742         <para>
743           Each server has a "cookie context," which is a name that identifies a
744           set of cookies that apply to that server. A sample context might be
745           "org_freedesktop_session_bus". Context names must be valid ASCII,
746           nonzero length, and may not contain the characters slash ("/"),
747           backslash ("\"), space (" "), newline ("\n"), carriage return ("\r"),
748           tab ("\t"), or period ("."). There is a default context,
749           "org_freedesktop_global" that's used by servers that do not specify
750           otherwise.
751         </para>
752         <para>
753           Cookies are stored in a user's home directory, in the directory
754           <filename>~/.dbus-keyrings/</filename>. This directory must 
755           not be readable or writable by other users. If it is, 
756           clients and servers must ignore it. The directory 
757           contains cookie files named after the cookie context.
758         </para>
759         <para>
760           A cookie file contains one cookie per line. Each line 
761           has three space-separated fields:
762           <itemizedlist>
763             <listitem>
764               <para>
765                 The cookie ID number, which must be a non-negative integer and
766                 may not be used twice in the same file.
767               </para>
768             </listitem>
769             <listitem>
770               <para>
771                 The cookie's creation time, in UNIX seconds-since-the-epoch
772                 format.
773               </para>
774             </listitem>
775             <listitem>
776               <para>
777                 The cookie itself, a hex-encoded random block of bytes.
778               </para>
779             </listitem>
780           </itemizedlist>
781         </para>
782         <para>
783           Only server processes modify the cookie file. 
784           They must do so with this procedure:
785           <itemizedlist>
786             <listitem>
787               <para>
788                 Create a lockfile name by appending ".lock" to the name of the
789                 cookie file.  The server should attempt to create this file
790                 using <literal>O_CREAT | O_EXCL</literal>.  If file creation
791                 fails, the lock fails. Servers should retry for a reasonable
792                 period of time, then they may choose to delete an existing lock
793                 to keep users from having to manually delete a stale
794                 lock. <footnote><para>Lockfiles are used instead of real file
795                 locking <literal>fcntl()</literal> because real locking
796                 implementations are still flaky on network
797                 filesystems.</para></footnote>
798               </para>
799             </listitem>
800             <listitem>
801               <para>
802                 Once the lockfile has been created, the server loads the cookie
803                 file. It should then delete any cookies that are old (the
804                 timeout can be fairly short), or more than a reasonable
805                 time in the future (so that cookies never accidentally 
806                 become permanent, if the clock was set far into the future 
807                 at some point). If no recent keys remain, the 
808                 server may generate a new key.
809               </para>
810             </listitem>
811             <listitem>
812               <para>
813                 The pruned and possibly added-to cookie file 
814                 must be resaved atomically (using a temporary 
815                 file which is rename()'d).
816               </para>
817             </listitem>
818             <listitem>
819               <para>
820                 The lock must be dropped by deleting the lockfile.
821               </para>
822             </listitem>
823           </itemizedlist>
824         </para>
825         <para>
826           Clients need not lock the file in order to load it, 
827           because servers are required to save the file atomically.          
828         </para>
829       </sect3>
830     </sect2>
831   </sect1>
832   <sect1 id="addresses">
833     <title>Server Addresses</title>
834     <para>
835       Server addresses consist of a transport name followed by a colon, and
836       then an optional, comma-separated list of keys and values in the form key=value.
837       [FIXME how do you escape colon, comma, and semicolon in the values of the key=value pairs?]
838     </para>
839     <para>
840       For example: 
841       <programlisting>unix:path=/tmp/dbus-test</programlisting>
842       Which is the address to a unix socket with the path /tmp/dbus-test.
843     </para>
844     <para>
845       [FIXME clarify if attempting to connect to each is a requirement 
846       or just a suggestion]
847       When connecting to a server, multiple server addresses can be
848       separated by a semi-colon. The library will then try to connect
849       to the first address and if that fails, it'll try to connect to
850       the next one specified, and so forth. For example
851       <programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
852     </para>
853     <para>
854       [FIXME we need to specify in detail each transport and its possible arguments]
855       Currently, a transport over local UNIX sockets exists, a debug
856       transport that only works in-process and therefore can be used
857       for for unit testing also exists. It is possible that other
858       transports are added, such as a TCP/IP transport, and a
859       transport that works over X11.
860     </para>
861   </sect1>
862
863   <sect1 id="message-conventions">
864     <title>Message Conventions</title>
865     <para>
866       This section documents conventions that are not essential to D-BUS
867       functionality, but should generally be followed in order to simplify
868       programmer's lives.
869     </para>
870     <sect2 id="message-conventions-naming">
871       <title>Message Naming</title>
872       <para>
873         Messages are normally named in the form 
874         "org.freedesktop.Peer.Ping", which has three 
875         distinct components:
876         <variablelist>
877           <varlistentry>
878             <term>Namespace e.g. <literal>org.freedesktop</literal></term>
879             <listitem>
880               <para>
881                 Message names have a Java-style namespace: a reversed domain
882                 name. The components of the domain are normally lowercase.
883               </para>
884             </listitem>
885           </varlistentry>
886           <varlistentry>
887             <term>Package or object e.g. <literal>Peer</literal></term>
888             <listitem>
889               <para>
890                 The next part of the message name can be thought of as the name
891                 of a singleton object, or as the name of a package of related
892                 messages.  More than one dot-separated component might be used
893                 here. (Note that D-BUS does not define any idea of object
894                 instances or object references.)  The package or object name is
895                 capitalized LikeThis.
896               </para>
897             </listitem>
898           </varlistentry>
899           <varlistentry>
900             <term>Method or operation e.g. <literal>Ping</literal></term>
901             <listitem>
902               <para>
903                 The final part of the message name is the most specific, and
904                 should be a verb indicating an operation to be performed on the
905                 object.  The method or operation name is capitalized LikeThis.
906               </para>
907             </listitem>
908           </varlistentry>
909         </variablelist>
910       </para>
911       <para>
912         A reply to a message conventionally has the same name as the message
913         being replied to. When following method call conventions (see <xref
914                                                                          linkend="message-conventions-method">), this convention is mandatory, 
915           because a message with multiple possible replies can't be mapped
916           to method call semantics without special-case code.
917       </para>
918     </sect2>
919     <sect2 id="message-conventions-method">
920       <title>Method Call Mapping</title>
921       <para>
922         Some implementations of D-BUS may present an API that translates object
923         method calls into D-BUS messages. This document does not specify in
924         detail how such an API should look or work. However, it does specify how
925         message-based protocols should be designed to be friendly to such an
926         API.
927       </para>
928       <para>
929         Remember that D-BUS does not have object references or object instances.
930         So when one application sends the message
931         <literal>org.freedesktop.Peer.Ping</literal>, it sends it to another
932         application, not to any kind of sub-portion of that application.
933         However, a convenience API used within the recipient application may
934         route all messages that start with
935         <literal>org.freedesktop.Peer</literal> to a particular object instance,
936         and may invoke the <literal>Ping()</literal> method on said instance in
937         order to handle the message. This is a convenience API based on 
938         method calls.
939       </para>
940       <para>
941         A "method call" consists of a message and, optionally, a reply to that
942         message. The name of the "method" is the last component of the message,
943         for example, <literal>org.freedesktop.Peer.Ping</literal> would map to
944         the method <literal>Ping()</literal> on some object.
945       </para>
946       <para>
947         Arguments to a method may be considered "in" (processed by the
948         recipient of the message), or "out" (returned to the sender of the
949         message in the reply). "inout" arguments are both sent and received,
950         i.e. the caller passes in a value which is modified. An "inout" argument 
951         is equivalent to an "in" argument, followed by an "out" argument.
952       </para>
953       <para>
954         Given a method with zero or one return values, followed by zero or more
955         arguments, where each argument may be "in", "out", or "inout", the
956         caller constructs a message by appending each "in" or "inout" argument,
957         in order. "out" arguments are not represented in the caller's message.
958       </para>
959       <para>
960         The recipient constructs a reply by appending first the return value 
961         if any, then each "out" or "inout" argument, in order. 
962         "in" arguments are not represented in the reply message.
963       </para>
964       <para>
965         The standard reply message MUST have the same name as the message being 
966         replied to, and MUST set the "rply" header field to the serial 
967         number of the message being replied to.
968       </para>
969       <para>
970         If an error occurs, an error reply may be sent in place of the standard
971         reply. Error replies can be identified by a special header flag, see
972         <xref linkend="message-protocol-header-encoding">.  Error replies have a
973         name which reflects the type of error that occurred. Error replies would
974         generally be mapped to exceptions in a programming language.  If an
975         error reply has a first argument, and that argument has type STRING,
976         then the argument must be an error message.
977       </para>
978       <para>
979         [FIXME discuss mapping of broadcast messages + matching rules 
980         to signals and slots]
981       </para>
982     </sect2>
983   </sect1>
984
985   <sect1 id="standard-messages">
986     <title>Standard Peer-to-Peer Messages</title>
987     <para>
988       In the following message definitions, "method call notation" is presented
989       in addition to simply listing the message names and arguments. The special
990       type name ANY means any type other than NIL, and the special type name
991       ANY_OR_NIL means any valid type.
992       [FIXME the messages here are just made up to illustrate the 
993       format for defining them]
994     </para>
995     <sect2 id="standard-messages-ping">
996       <title><literal>org.freedesktop.Peer.Ping</literal></title>
997       <para>        
998         As a method:
999         <programlisting>
1000           void Ping ()
1001         </programlisting>
1002       </para>
1003       <para>
1004         On receipt of the message <literal>org.freedesktop.Peer.Ping</literal>,
1005         an application should reply with
1006         <literal>org.freedesktop.Peer.Ping</literal>. Neither the 
1007         message nor its reply have any arguments.
1008         [FIXME the messages here are just made up to illustrate the 
1009         format for defining them]
1010       </para>
1011     </sect2>
1012     <sect2 id="standard-messages-get-props">
1013       <title><literal>org.freedesktop.Props.Get</literal></title>
1014       <para>
1015         As a method:
1016         <programlisting>
1017           ANY_OR_NIL Get (in STRING property_name)
1018         </programlisting>
1019         Message arguments:
1020         <informaltable>
1021           <tgroup cols=3>
1022             <thead>
1023               <row>
1024                 <entry>Argument</entry>
1025                 <entry>Type</entry>
1026                 <entry>Description</entry>
1027               </row>
1028             </thead>
1029             <tbody>
1030               <row>
1031                 <entry>0</entry>
1032                 <entry>STRING</entry>
1033                 <entry>Name of the property to get</entry>
1034               </row>
1035             </tbody>
1036           </tgroup>
1037         </informaltable>
1038         Reply arguments:
1039         <informaltable>
1040           <tgroup cols=3>
1041             <thead>
1042               <row>
1043                 <entry>Argument</entry>
1044                 <entry>Type</entry>
1045                 <entry>Description</entry>
1046               </row>
1047             </thead>
1048             <tbody>
1049               <row>
1050                 <entry>0</entry>
1051                 <entry>ANY_OR_NIL</entry>
1052                 <entry>The value of the property. The type depends on the property.</entry>
1053               </row>
1054             </tbody>
1055           </tgroup>
1056         </informaltable>
1057       </para>
1058       <para>
1059         
1060         [FIXME the messages here are just made up to illustrate the 
1061         format for defining them]
1062       </para>
1063     </sect2>
1064   </sect1>
1065
1066   <sect1 id="message-bus">
1067     <title>Message Bus Specification</title>
1068     <sect2 id="message-bus-overview">
1069       <title>Message Bus Overview</title>
1070       <para>
1071         The message bus accepts connections from one or more applications. 
1072         Once connected, applications can send and receive messages from 
1073         the message bus, as in the peer-to-peer case.
1074       </para>
1075       <para>
1076         The message bus keeps track of a set of
1077         <firstterm>services</firstterm>. A service is simply a name, such 
1078         as <literal>com.yoyodyne.Screensaver</literal>, which can be 
1079         <firstterm>owned</firstterm> by one of the connected applications. 
1080         The message bus itself always owns the special service 
1081         <literal>org.freedesktop.DBus</literal>.
1082       </para>
1083       <para>
1084         Messages may have a <literal>srvc</literal> field (see <xref
1085                                                                   linkend="message-protocol-header-fields">).  When the message bus
1086           receives a message, if the <literal>srvc</literal> field is absent, the
1087           message is taken to be a standard peer-to-peer message and interpreted
1088           by the message bus itself. For example, sending
1089           an <literal>org.freedesktop.Peer.Ping</literal> message with no 
1090           <literal>srvc</literal> will cause the message bus itself to reply 
1091           to the ping immediately; the message bus would never make 
1092           this message visible to other applications.
1093       </para>
1094       <para>
1095         If the <literal>srvc</literal> field is present, then it indicates a
1096         request for the message bus to route the message. In the usual case,
1097         messages are routed to the owner of the named service.
1098         Messages may also be <firstterm>broadcast</firstterm>
1099         by sending them to the special service 
1100         <literal>org.freedesktop.Broadcast</literal>. Broadcast messages are
1101         sent to all applications with <firstterm>message matching
1102           rules</firstterm> that match the message.
1103       </para>
1104       <para>
1105         Continuing the <literal>org.freedesktop.Peer.Ping</literal> example, if
1106         the ping message were sent with a <literal>srvc</literal> name of
1107         <literal>com.yoyodyne.Screensaver</literal>, then the ping would be
1108         forwarded, and the Yoyodyne Corporation screensaver application would be
1109         expected to reply to the ping. If
1110         <literal>org.freedesktop.Peer.Ping</literal> were sent to
1111         <literal>org.freedesktop.Broadcast</literal>, then multiple applications
1112         might receive the ping, and all would normally reply to it.
1113       </para>
1114     </sect2>
1115
1116     <sect2 id="message-bus-services">
1117       <title>Message Bus Services</title>
1118       <para>
1119         A service is a name that identifies a certain application. Each
1120         application connected to the message bus has at least one service name
1121         assigned at connection time and returned in response to the
1122         <literal>org.freedesktop.DBus.Hello</literal> message.
1123         This automatically-assigned service name is called 
1124         the application's <firstterm>base service</firstterm>. 
1125         Base service names are unique and MUST never be reused for two different 
1126         applications.
1127       </para>
1128       <para>
1129         Ownership of the base service is a prerequisite for interaction with 
1130         the message bus. It logically follows that the base service is always 
1131         the first service that an application comes to own, and the last 
1132         service that it loses ownership of.
1133       </para>
1134       <para>
1135         Base service names must begin with the character ':' (ASCII colon
1136         character); service names that are not base service names must not begin
1137         with this character. (The bus must reject any attempt by an application
1138         to manually create a service name beginning with ':'.) This restriction
1139         categorically prevents "spoofing"; messages sent to a base service name
1140         will always go to a single application instance and that instance only.
1141       </para>
1142       <para>
1143         An application can request additional service names to be associated
1144         with it using the
1145         <literal>org.freedesktop.DBus.AcquireService</literal>
1146         message. [FIXME what service names are allowed; ASCII or unicode; 
1147         length limit; etc.]
1148       </para>
1149       <para>
1150         [FIXME this needs more detail, and should move the service-related message 
1151         descriptions up into this section perhaps]
1152         Service ownership handling can be specified in the flags part
1153         of the <literal>org.freedesktop.DBus.AcquireService</literal>
1154         message. If an application specifies the
1155         DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT flag, then all applications
1156         trying to acquire the service will be put in a queue. When the
1157         primary owner disconnects from the bus or removes ownership
1158         from the service, the next application in the queue will be the
1159         primary owner. If the DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT
1160         flag is not specified, then the primary owner will lose
1161         ownership whenever another application requests ownership of the
1162         service.
1163       </para>
1164       <para>
1165         When a client disconnects from the bus, all the services that
1166         the clients own are deleted, or in the case of a service that
1167         prohibits replacement, ownership is transferred to the next
1168         client in the queue, if any.
1169       </para>
1170     </sect2>
1171     <sect2 id="message-bus-routing">
1172       <title>Message Bus Message Routing</title>
1173       <para>
1174         When a message is received by the message bus, the message's 
1175         <literal>sndr</literal> header field MUST be set to the base service of
1176         the application which sent the message.  If the service already has
1177         a <literal>sndr</literal> field, the pre-existing field is replaced.
1178         This rule means that a replies are always sent to the base service name,
1179         i.e. to the same application that sent the message being replied to.
1180       </para>
1181       <para>
1182         [FIXME go into detail about broadcast, multicast, unicast, etc.]
1183       </para>
1184     </sect2>
1185     <sect2 id="message-bus-activation">
1186       <title>Message Bus Service Activation</title>
1187       <para>
1188         <firstterm>Activation</firstterm> means to locate a service 
1189         owner for a service that is currently unowned. For now, it 
1190         means to launch an executable that will take ownership of 
1191         a particular service.
1192       </para>
1193       <para>
1194         To find an executable corresponding to a particular service, the bus
1195         daemon looks for <firstterm>service description files</firstterm>.
1196         Service description files define a mapping from service names to
1197         executables. Different kinds of message bus will look for these files
1198         in different places, see <xref linkend="message-bus-types">.
1199       </para>
1200       <para>
1201         [FIXME the file format should be much better specified than
1202         "similar to .desktop entries" esp. since desktop entries are
1203         already badly-specified. ;-)] Service description files have
1204         the ".service" file extension. The message bus will only load
1205         service description files ending with .service; all other
1206         files will be ignored.  The file format is similar to that of
1207         <ulink
1208         url="http://www.freedesktop.org/standards/desktop-entry-spec/desktop-entry-spec.html">desktop
1209         entries</ulink>. All service description files must be in
1210         UTF-8 encoding. To ensure that there will be no name
1211         collisions, service files must be namespaced using the same
1212         mechanism as messages and service names.
1213
1214         <figure>
1215           <title>Example service description file</title>
1216           <programlisting>
1217             # Sample service description file
1218             [D-BUS Service]
1219             Name=org.gnome.ConfigurationDatabase
1220             Exec=/usr/libexec/gconfd-2
1221           </programlisting>
1222         </figure>
1223       </para>
1224       <para>
1225         When an application requests a service to be activated, the
1226         bus daemon tries to find it in the list of activation
1227         entries. It then tries to spawn the executable associated with
1228         it. If this fails, it will report an error. [FIXME what
1229         happens if two .service files offer the same service; what
1230         kind of error is reported, should we have a way for the client
1231         to choose one?]
1232       </para>
1233       <para>
1234         The executable launched will have the environment variable
1235         <literal>DBUS_ACTIVATION_ADDRESS</literal> set to the address of the
1236         message bus so it can connect and register the appropriate services.
1237       </para>
1238       <para>
1239         The executable being launched may want to know whether the message bus
1240         activating it is one of the well-known message buses (see <xref
1241         linkend="message-bus-types">). To facilitate this, the bus MUST also set
1242         the <literal>DBUS_ACTIVATION_BUS_TYPE</literal> environment variable if it is one
1243         of the well-known buses. The currently-defined values for this variable
1244         are <literal>system</literal> for the systemwide message bus,
1245         and <literal>session</literal> for the per-login-session message
1246         bus. The activated executable must still connect to the address given
1247         in <literal>DBUS_ACTIVATION_ADDRESS</literal>, but may assume that the
1248         resulting connection is to the well-known bus.
1249       </para>
1250       <para>
1251         [FIXME there should be a timeout somewhere, either specified
1252         in the .service file, by the client, or just a global value
1253         and if the client being activated fails to connect within that
1254         timeout, an error should be sent back.]
1255       </para>
1256     </sect2>
1257
1258     <sect2 id="message-bus-types">
1259       <title>Well-known Message Bus Instances</title>
1260       <para>
1261         Two standard message bus instances are defined here, along with how 
1262         to locate them and where their service files live.
1263       </para>
1264       <sect3 id="message-bus-types-login">
1265         <title>Login session message bus</title>
1266         <para>
1267           Each time a user logs in, a <firstterm>login session message
1268             bus</firstterm> may be started. All applications in the user's login
1269           session may interact with one another using this message bus.
1270         </para>
1271         <para>
1272           The address of the login session message bus is given 
1273           in the <literal>DBUS_SESSION_BUS_ADDRESS</literal> environment 
1274           variable. If that variable is not set, applications may 
1275           also try to read the address from the X Window System root 
1276           window property <literal>_DBUS_SESSION_BUS_ADDRESS</literal>.
1277           The root window property must have type <literal>STRING</literal>.
1278           The environment variable should have precedence over the 
1279           root window property.
1280         </para>
1281         <para>
1282           [FIXME specify location of .service files, probably using 
1283           DESKTOP_DIRS etc. from basedir specification, though login session 
1284           bus is not really desktop-specific]
1285         </para>
1286       </sect3>
1287       <sect3 id="message-bus-types-system">
1288         <title>System message bus</title>
1289         <para>
1290           A computer may have a <firstterm>system message bus</firstterm>,
1291           accessible to all applications on the system. This message bus may be
1292           used to broadcast system events, such as adding new hardware devices, 
1293           changes in the printer queue, and so forth.
1294         </para>
1295         <para>
1296           The address of the login session message bus is given 
1297           in the <literal>DBUS_SYSTEM_BUS_ADDRESS</literal> environment 
1298           variable. If that variable is not set, applications should try 
1299           to connect to the well-known address
1300           <literal>unix:path=/var/run/dbus/system_bus_socket</literal>.
1301           <footnote>
1302             <para>
1303               The D-BUS reference implementation actually honors the 
1304               <literal>$(localstatedir)</literal> configure option 
1305               for this address, on both client and server side.
1306             </para>
1307           </footnote>
1308         </para>
1309         <para>
1310           [FIXME specify location of system bus .service files]
1311         </para>
1312       </sect3>
1313     </sect2>
1314
1315     <sect2 id="message-bus-messages">
1316       <title>Message Bus Messages</title>
1317       <para>
1318         The special message bus service <literal>org.freedesktop.DBus</literal>
1319         responds to a number of messages, allowing applications to 
1320         interact with the message bus.
1321       </para>
1322
1323       <sect3 id="bus-messages-hello">
1324         <title><literal>org.freedesktop.DBus.Hello</literal></title>
1325         <para>
1326           As a method:
1327           <programlisting>
1328             STRING Hello ()
1329           </programlisting>
1330           Reply arguments:
1331           <informaltable>
1332             <tgroup cols=3>
1333               <thead>
1334                 <row>
1335                   <entry>Argument</entry>
1336                   <entry>Type</entry>
1337                   <entry>Description</entry>
1338                 </row>
1339               </thead>
1340               <tbody>
1341                 <row>
1342                   <entry>0</entry>
1343                   <entry>STRING</entry>
1344                   <entry>Name of the service assigned to the application</entry>
1345                 </row>
1346               </tbody>
1347             </tgroup>
1348           </informaltable>
1349         </para>
1350         <para>
1351           Before an application is able to send messages to other
1352           applications it must send the
1353           <literal>org.freedesktop.DBus.Hello</literal> message to the
1354           message bus service. If an application tries to send a
1355           message to another application, or a message to the message
1356           bus service that isn't the
1357           <literal>org.freedesktop.DBus.Hello</literal> message, it
1358           will be disconnected from the bus. If a client wishes to
1359           disconnect from the bus, it just has to disconnect from the
1360           transport used. No de-registration message is necessary.
1361         </para>
1362         <para>
1363           The reply message contains the name of the application's base service.
1364         </para>
1365       </sect3>
1366       <sect3 id="bus-messages-list-services">
1367         <title><literal>org.freedesktop.DBus.ListServices</literal></title>
1368         <para>
1369           As a method:
1370           <programlisting>
1371             STRING_ARRAY ListServices ()
1372           </programlisting>
1373           Reply arguments:
1374           <informaltable>
1375             <tgroup cols=3>
1376               <thead>
1377                 <row>
1378                   <entry>Argument</entry>
1379                   <entry>Type</entry>
1380                   <entry>Description</entry>
1381                 </row>
1382               </thead>
1383               <tbody>
1384                 <row>
1385                   <entry>0</entry>
1386                   <entry>STRING_ARRAY</entry>
1387                   <entry>Array of strings where each string is the name of a service</entry>
1388                 </row>
1389               </tbody>
1390             </tgroup>
1391           </informaltable>
1392         </para>
1393         <para>
1394           Returns a list of all existing services registered with the message bus. 
1395         </para>
1396       </sect3>
1397       <sect3 id="bus-messages-service-exists">
1398         <title><literal>org.freedesktop.DBus.ServiceExists</literal></title>
1399         <para>
1400           As a method:
1401           <programlisting>
1402             UINT32 ServiceExists (in STRING service_name)
1403           </programlisting>
1404           Message arguments:
1405           <informaltable>
1406             <tgroup cols=3>
1407               <thead>
1408                 <row>
1409                   <entry>Argument</entry>
1410                   <entry>Type</entry>
1411                   <entry>Description</entry>
1412                 </row>
1413               </thead>
1414               <tbody>
1415                 <row>
1416                   <entry>0</entry>
1417                   <entry>STRING</entry>
1418                   <entry>Name of the service</entry>
1419                 </row>
1420               </tbody>
1421             </tgroup>
1422           </informaltable>
1423           Reply arguments:
1424           <informaltable>
1425             <tgroup cols=3>
1426               <thead>
1427                 <row>
1428                   <entry>Argument</entry>
1429                   <entry>Type</entry>
1430                   <entry>Description</entry>
1431                 </row>
1432               </thead>
1433               <tbody>
1434                 <row>
1435                   <entry>0</entry>
1436                   <entry>UINT32</entry>
1437                   <entry>Return value, 1 if the service exists and 0 otherwise</entry>
1438                 </row>
1439               </tbody>
1440             </tgroup>
1441           </informaltable>
1442         </para>
1443         <para>
1444           Checks if a service with a specified name exists.
1445         </para>
1446       </sect3>
1447
1448       <sect3 id="bus-messages-acquire-service">
1449         <title><literal>org.freedesktop.DBus.AcquireService</literal></title>
1450         <para>
1451           As a method:
1452           <programlisting>
1453             UINT32 AcquireService (in STRING service_name)
1454           </programlisting>
1455           Message arguments:
1456           <informaltable>
1457             <tgroup cols=3>
1458               <thead>
1459                 <row>
1460                   <entry>Argument</entry>
1461                   <entry>Type</entry>
1462                   <entry>Description</entry>
1463                 </row>
1464               </thead>
1465               <tbody>
1466                 <row>
1467                   <entry>0</entry>
1468                   <entry>STRING</entry>
1469                   <entry>Name of the service</entry>
1470                 </row>
1471                 <row>
1472                   <entry>1</entry>
1473                   <entry>UINT32</entry>
1474                   <entry>Flags</entry>
1475                 </row>
1476               </tbody>
1477             </tgroup>
1478           </informaltable>
1479           Reply arguments:
1480           <informaltable>
1481             <tgroup cols=3>
1482               <thead>
1483                 <row>
1484                   <entry>Argument</entry>
1485                   <entry>Type</entry>
1486                   <entry>Description</entry>
1487                 </row>
1488               </thead>
1489               <tbody>
1490                 <row>
1491                   <entry>0</entry>
1492                   <entry>UINT32</entry>
1493                   <entry>Return value</entry>
1494                 </row>
1495               </tbody>
1496             </tgroup>
1497           </informaltable>
1498         </para>
1499         <para>
1500           Tries to become owner of a specific service. The flags
1501           specified can be the following values logically ORed together:
1502
1503           <informaltable>
1504             <tgroup cols=3>
1505               <thead>
1506                 <row>
1507                   <entry>Identifier</entry>
1508                   <entry>Value</entry>
1509                   <entry>Description</entry>
1510                 </row>
1511               </thead>
1512               <tbody>
1513                 <row>
1514                   <entry>DBUS_SERVICE_FLAGS_PROHIBIT_REPLACEMENT</entry>
1515                   <entry>0x1</entry>
1516                   <entry>
1517                     If the application succeeds in being the owner of the specified service,
1518                     then ownership of the service can't be transferred until the service
1519                     disconnects. If this flag is not set, then any application trying to become
1520                     the owner of the service will succeed and the previous owner will be
1521                     sent a <literal>org.freedesktop.DBus.ServiceLost</literal> message.
1522                   </entry>
1523                 </row>
1524                 <row>
1525                   <entry>DBUS_SERVICE_FLAGS_REPLACE_EXISTING</entry>
1526                   <entry>0x2</entry>
1527                   <entry>Only become the owner of the service if there is no current owner.</entry>
1528                 </row>
1529               </tbody>
1530             </tgroup>
1531           </informaltable>
1532
1533           [FIXME if it's one of the following values, why are the values
1534           done as flags instead of just 0, 1, 2, 3, 4]
1535           The return value can be one of the following values:
1536
1537           <informaltable>
1538             <tgroup cols=3>
1539               <thead>
1540                 <row>
1541                   <entry>Identifier</entry>
1542                   <entry>Value</entry>
1543                   <entry>Description</entry>
1544                 </row>
1545               </thead>
1546               <tbody>
1547                 <row>
1548                   <entry>DBUS_SERVICE_REPLY_PRIMARY_OWNER</entry>
1549                   <entry>0x1</entry>
1550                   <entry>The application is now the primary owner of the service.</entry>
1551                 </row>
1552                 <row>
1553                   <entry>DBUS_SERVICE_REPLY_IN_QUEUE</entry>
1554                   <entry>0x2</entry>
1555                   <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>
1556                 </row>
1557                 <row>
1558                   <entry>DBUS_SERVICE_REPLY_SERVICE_EXISTS</entry>
1559                   <entry>0x4</entry>
1560                   <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>
1561                 </row>
1562                 <row>
1563                   <entry>DBUS_SERVICE_REPLY_ALREADY_OWNER</entry>
1564                   <entry>0x8</entry>
1565                   <entry>The application trying to request ownership of the service is already the owner of it.</entry>
1566                 </row>
1567               </tbody>
1568             </tgroup>
1569           </informaltable>
1570         </para>
1571       </sect3>
1572       <sect3 id="bus-messages-service-acquired">
1573         <title><literal>org.freedesktop.DBus.ServiceAcquired</literal></title>
1574         <para>
1575           As a method:
1576           <programlisting>
1577             ServiceAcquired (in STRING service_name)
1578           </programlisting>
1579           Message arguments:
1580           <informaltable>
1581             <tgroup cols=3>
1582               <thead>
1583                 <row>
1584                   <entry>Argument</entry>
1585                   <entry>Type</entry>
1586                   <entry>Description</entry>
1587                 </row>
1588               </thead>
1589               <tbody>
1590                 <row>
1591                   <entry>0</entry>
1592                   <entry>STRING</entry>
1593                   <entry>Name of the service</entry>
1594                 </row>
1595                 <row>
1596                   <entry>1</entry>
1597                   <entry>UINT32</entry>
1598                   <entry>Flags</entry>
1599                 </row>
1600               </tbody>
1601             </tgroup>
1602           </informaltable>
1603         </para>
1604         <para>
1605           This message is sent to a specific application when it becomes the
1606           primary owner of a service.
1607         </para>
1608       </sect3>
1609       <sect3 id="bus-messages-service-lost">
1610         <title><literal>org.freedesktop.DBus.ServiceLost</literal></title>
1611         <para>
1612           As a method:
1613           <programlisting>
1614             ServiceLost (in STRING service_name)
1615           </programlisting>
1616           Message arguments:
1617           <informaltable>
1618             <tgroup cols=3>
1619               <thead>
1620                 <row>
1621                   <entry>Argument</entry>
1622                   <entry>Type</entry>
1623                   <entry>Description</entry>
1624                 </row>
1625               </thead>
1626               <tbody>
1627                 <row>
1628                   <entry>0</entry>
1629                   <entry>STRING</entry>
1630                   <entry>Name of the service</entry>
1631                 </row>
1632                 <row>
1633                   <entry>1</entry>
1634                   <entry>UINT32</entry>
1635                   <entry>Flags</entry>
1636                 </row>
1637               </tbody>
1638             </tgroup>
1639           </informaltable>
1640         </para>
1641         <para>
1642           This message is sent to a specific application when it loses primary
1643           ownership of a service.
1644
1645           [FIXME instead of ServiceLost/ServiceCreated going only to 
1646           a specific app, why not just OwnerChanged that covers both 
1647           lost and created and changed owner and deleted]
1648         </para>
1649       </sect3>
1650
1651       <sect3 id="bus-messages-service-created">
1652         <title><literal>org.freedesktop.DBus.ServiceCreated</literal></title>
1653         <para>
1654           As a method:
1655           <programlisting>
1656             ServiceCreated (in STRING service_name)
1657           </programlisting>
1658           Message arguments:
1659           <informaltable>
1660             <tgroup cols=3>
1661               <thead>
1662                 <row>
1663                   <entry>Argument</entry>
1664                   <entry>Type</entry>
1665                   <entry>Description</entry>
1666                 </row>
1667               </thead>
1668               <tbody>
1669                 <row>
1670                   <entry>0</entry>
1671                   <entry>STRING</entry>
1672                   <entry>Name of the service</entry>
1673                 </row>
1674                 <row>
1675                   <entry>1</entry>
1676                   <entry>UINT32</entry>
1677                   <entry>Flags</entry>
1678                 </row>
1679               </tbody>
1680             </tgroup>
1681           </informaltable>
1682         </para>
1683         <para>
1684           This message is broadcast to all applications when a service has been
1685           successfully registered on the message bus.
1686         </para>
1687       </sect3>
1688
1689       <sect3 id="bus-messages-service-deleted">
1690         <title><literal>org.freedesktop.DBus.ServiceDeleted</literal></title>
1691         <para>
1692           As a method:
1693           <programlisting>
1694             ServiceDeleted (in STRING service_name)
1695           </programlisting>
1696           Message arguments:
1697           <informaltable>
1698             <tgroup cols=3>
1699               <thead>
1700                 <row>
1701                   <entry>Argument</entry>
1702                   <entry>Type</entry>
1703                   <entry>Description</entry>
1704                 </row>
1705               </thead>
1706               <tbody>
1707                 <row>
1708                   <entry>0</entry>
1709                   <entry>STRING</entry>
1710                   <entry>Name of the service</entry>
1711                 </row>
1712                 <row>
1713                   <entry>1</entry>
1714                   <entry>UINT32</entry>
1715                   <entry>Flags</entry>
1716                 </row>
1717               </tbody>
1718             </tgroup>
1719           </informaltable>
1720         </para>
1721         <para>
1722           This message is broadcast to all applications when a service has been
1723           deleted from the message bus.
1724         </para>
1725       </sect3>
1726
1727       <sect3 id="bus-messages-activate-service">
1728         <title><literal>org.freedesktop.DBus.ActivateService</literal></title>
1729         <para>
1730           As a method:
1731           <programlisting>
1732             UINT32 ActivateService (in STRING service_name, in UINT32 flags)
1733           </programlisting>
1734           Message arguments:
1735           <informaltable>
1736             <tgroup cols=3>
1737               <thead>
1738                 <row>
1739                   <entry>Argument</entry>
1740                   <entry>Type</entry>
1741                   <entry>Description</entry>
1742                 </row>
1743               </thead>
1744               <tbody>
1745                 <row>
1746                   <entry>0</entry>
1747                   <entry>STRING</entry>
1748                   <entry>Name of the service to activate</entry>
1749                 </row>
1750                 <row>
1751                   <entry>1</entry>
1752                   <entry>UINT32</entry>
1753                   <entry>Flags (currently not used)</entry>
1754                 </row>
1755               </tbody>
1756             </tgroup>
1757           </informaltable>
1758         Reply arguments:
1759         <informaltable>
1760           <tgroup cols=3>
1761             <thead>
1762               <row>
1763                 <entry>Argument</entry>
1764                 <entry>Type</entry>
1765                 <entry>Description</entry>
1766               </row>
1767             </thead>
1768             <tbody>
1769               <row>
1770                 <entry>0</entry>
1771                 <entry>UINT32</entry>
1772                 <entry>Result code; DBUS_ACTIVATION_REPLY_ACTIVATED if
1773                 the service was activated successfully or
1774                 DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE if the service is
1775                 already active.</entry>
1776               </row>
1777             </tbody>
1778           </tgroup>
1779         </informaltable>
1780         </para>
1781         <para>
1782           Tries to launch the executable associated with a service. For more information, see <xref linkend="message-bus-activation">.
1783
1784             [FIXME need semantics in much more detail here; for example, 
1785             if I activate a service then send it a message, is the message 
1786             queued for the new service or is there a race]
1787         </para>
1788       </sect3>
1789
1790       <sect3 id="bus-messages-out-of-memory">
1791         <title><literal>org.freedesktop.DBus.Error.NoMemory</literal></title>
1792         <para>
1793           As a method:
1794           <programlisting>
1795             void NoMemory ()
1796           </programlisting>
1797         </para>
1798         <para>
1799           Sent by the message bus when it can't process a message due to an out of memory failure.
1800         </para>
1801       </sect3>
1802
1803       <sect3 id="bus-messages-service-does-not-exist">
1804         <title><literal>org.freedesktop.DBus.Error.ServiceDoesNotExist</literal></title>
1805         <para>
1806           As a method:
1807           <programlisting>
1808             void ServiceDoesNotExist (in STRING error)
1809           </programlisting>
1810         </para>
1811         <para>
1812           Sent by the message bus as a reply to a client that tried to send a message to a service that doesn't exist.
1813         </para>
1814       </sect3>
1815     </sect2>
1816
1817   </sect1>
1818 <!--
1819   <appendix id="implementation-notes">
1820     <title>Implementation notes</title>
1821     <sect1 id="implementation-notes-subsection">
1822       <title></title>
1823       <para>
1824       </para>
1825     </sect1>
1826   </appendix>
1827 -->
1828
1829   <glossary><title>Glossary</title>
1830     <para>
1831       This glossary defines some of the terms used in this specification.
1832     </para>
1833
1834     <glossentry id="term-activation"><glossterm>Activation</glossterm>
1835       <glossdef>
1836         <para>
1837           The process of creating an owner for a particular service, 
1838           typically by launching an executable.
1839         </para>
1840       </glossdef>
1841     </glossentry>
1842
1843     <glossentry id="term-base-service"><glossterm>Base Service</glossterm>
1844       <glossdef>
1845         <para>
1846           The special service automatically assigned to an application by the 
1847           message bus. This service may never change owner, and the service 
1848           name will be unique (never reused during the lifetime of the 
1849           message bus).
1850         </para>
1851       </glossdef>
1852     </glossentry>
1853
1854     <glossentry id="term-broadcast"><glossterm>Broadcast</glossterm>
1855       <glossdef>
1856         <para>
1857           A message sent to the special <literal>org.freedesktop.Broadcast</literal>
1858           service; the message bus will forward the broadcast message 
1859           to all applications that have expressed interest in it.
1860         </para>
1861       </glossdef>
1862     </glossentry>
1863       
1864     <glossentry id="term-message"><glossterm>Message</glossterm>
1865       <glossdef>
1866         <para>
1867           A message is the atomic unit of communication via the D-BUS
1868           protocol. It consists of a <firstterm>header</firstterm> and a
1869           <firstterm>body</firstterm>; the body is made up of
1870           <firstterm>arguments</firstterm>.
1871         </para>
1872       </glossdef>
1873     </glossentry>
1874
1875     <glossentry id="term-message-bus"><glossterm>Message Bus</glossterm>
1876       <glossdef>
1877         <para>
1878           The message bus is a special application that forwards 
1879           or broadcasts messages between a group of applications
1880           connected to the message bus. It also manages 
1881           <firstterm>services</firstterm>.
1882         </para>
1883       </glossdef>
1884     </glossentry>
1885
1886     <glossentry id="namespace"><glossterm>Namespace</glossterm>
1887       <glossdef>
1888         <para>
1889           Used to prevent collisions when defining message and service
1890           names. The convention used is the same as Java uses for
1891           defining classes: a reversed domain name.
1892         </para>
1893       </glossdef>
1894     </glossentry>
1895     <glossentry id="peer-to-peer"><glossterm>Peer-to-peer</glossterm>
1896       <glossdef>
1897         <para>
1898           An application talking directly to another application, without going through a message bus. 
1899         </para>
1900       </glossdef>
1901     </glossentry>
1902     <glossentry id="term-service"><glossterm>Service</glossterm>
1903       <glossdef>
1904         <para>
1905           A service is simply a named application that other 
1906           applications can refer to. For example, the 
1907           hypothetical <literal>com.yoyodyne.Screensaver</literal>
1908           service might accept messages that affect 
1909           a screensaver from Yoyodyne Corporation.
1910           An application is said to <firstterm>own</firstterm> 
1911           a service if the message bus has associated the 
1912           application with the service name.
1913         </para>
1914       </glossdef>
1915     </glossentry>
1916     <glossentry id="term-service-name"><glossterm>Service name</glossterm>
1917       <glossdef>
1918         <para>
1919           The name used when referring to a service. If the service is
1920           a base service it has a unique service name, for example
1921           ":1-20", and otherwise it should be namespaced.
1922         </para>
1923       </glossdef>
1924     </glossentry>
1925     <glossentry id="term-service-description-files"><glossterm>Service Description Files</glossterm>
1926       <glossdef>
1927         <para>
1928           ".service files" tell the bus how to activate a particular service.
1929           See <xref linkend="term-activation">
1930         </para>
1931       </glossdef>
1932     </glossentry>
1933
1934   </glossary>
1935 </article>
1936