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