- fixed dbus_bus_request_name
[platform/upstream/dbus.git] / dbus / dbus-transport-socket.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-transport-socket.c  Socket subclasses of DBusTransport
3  *
4  * Copyright (C) 2002, 2003, 2004, 2006  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <config.h>
25 #include "dbus-internals.h"
26 #include "dbus-connection-internal.h"
27 #include "dbus-nonce.h"
28 #include "dbus-transport-socket.h"
29 #include "dbus-transport-protected.h"
30 #include "dbus-watch.h"
31 #include "dbus-credentials.h"
32 #include <stdio.h>  //todo to remove
33
34 /**
35  * @defgroup DBusTransportSocket DBusTransport implementations for sockets
36  * @ingroup  DBusInternals
37  * @brief Implementation details of DBusTransport on sockets
38  *
39  * @{
40  */
41
42 /**
43  * Opaque object representing a socket file descriptor transport.
44  */
45 typedef struct DBusTransportSocket DBusTransportSocket;
46
47 /**
48  * Implementation details of DBusTransportSocket. All members are private.
49  */
50 struct DBusTransportSocket
51 {
52   DBusTransport base;                   /**< Parent instance */
53   int fd;                               /**< File descriptor. */
54   DBusWatch *read_watch;                /**< Watch for readability. */
55   DBusWatch *write_watch;               /**< Watch for writability. */
56
57   int max_bytes_read_per_iteration;     /**< To avoid blocking too long. */
58   int max_bytes_written_per_iteration;  /**< To avoid blocking too long. */
59
60   int message_bytes_written;            /**< Number of bytes of current
61                                          *   outgoing message that have
62                                          *   been written.
63                                          */
64   DBusString encoded_outgoing;          /**< Encoded version of current
65                                          *   outgoing message.
66                                          */
67   DBusString encoded_incoming;          /**< Encoded version of current
68                                          *   incoming data.
69                                          */
70 };
71
72 static void
73 free_watches (DBusTransport *transport)
74 {
75   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
76
77   _dbus_verbose ("start\n");
78   
79   if (socket_transport->read_watch)
80     {
81       if (transport->connection)
82         _dbus_connection_remove_watch_unlocked (transport->connection,
83                                                 socket_transport->read_watch);
84       _dbus_watch_invalidate (socket_transport->read_watch);
85       _dbus_watch_unref (socket_transport->read_watch);
86       socket_transport->read_watch = NULL;
87     }
88
89   if (socket_transport->write_watch)
90     {
91       if (transport->connection)
92         _dbus_connection_remove_watch_unlocked (transport->connection,
93                                                 socket_transport->write_watch);
94       _dbus_watch_invalidate (socket_transport->write_watch);
95       _dbus_watch_unref (socket_transport->write_watch);
96       socket_transport->write_watch = NULL;
97     }
98
99   _dbus_verbose ("end\n");
100 }
101
102 static void
103 socket_finalize (DBusTransport *transport)
104 {
105   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
106
107   _dbus_verbose ("\n");
108   
109   free_watches (transport);
110
111   _dbus_string_free (&socket_transport->encoded_outgoing);
112   _dbus_string_free (&socket_transport->encoded_incoming);
113   
114   _dbus_transport_finalize_base (transport);
115
116   _dbus_assert (socket_transport->read_watch == NULL);
117   _dbus_assert (socket_transport->write_watch == NULL);
118   
119   dbus_free (transport);
120 }
121
122 static void
123 check_write_watch (DBusTransport *transport)
124 {
125   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
126   dbus_bool_t needed;
127
128   if (transport->connection == NULL)
129     return;
130
131   if (transport->disconnected)
132     {
133       _dbus_assert (socket_transport->write_watch == NULL);
134       return;
135     }
136   
137   _dbus_transport_ref (transport);
138
139   if (_dbus_transport_get_is_authenticated (transport))
140     needed = _dbus_connection_has_messages_to_send_unlocked (transport->connection);
141   else
142     {
143       if (transport->send_credentials_pending)
144         needed = TRUE;
145       else
146         {
147           DBusAuthState auth_state;
148           
149           auth_state = _dbus_auth_do_work (transport->auth);
150           
151           /* If we need memory we install the write watch just in case,
152            * if there's no need for it, it will get de-installed
153            * next time we try reading.
154            */
155           if (auth_state == DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND ||
156               auth_state == DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
157             needed = TRUE;
158           else
159             needed = FALSE;
160         }
161     }
162
163   _dbus_verbose ("check_write_watch(): needed = %d on connection %p watch %p fd = %d outgoing messages exist %d\n",
164                  needed, transport->connection, socket_transport->write_watch,
165                  socket_transport->fd,
166                  _dbus_connection_has_messages_to_send_unlocked (transport->connection));
167
168   _dbus_connection_toggle_watch_unlocked (transport->connection,
169                                           socket_transport->write_watch,
170                                           needed);
171
172   _dbus_transport_unref (transport);
173 }
174
175 static void
176 check_read_watch (DBusTransport *transport)
177 {
178   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
179   dbus_bool_t need_read_watch;
180
181   _dbus_verbose ("fd = %d\n",socket_transport->fd);
182   
183   if (transport->connection == NULL)
184     return;
185
186   if (transport->disconnected)
187     {
188       _dbus_assert (socket_transport->read_watch == NULL);
189       return;
190     }
191   
192   _dbus_transport_ref (transport);
193
194   if (_dbus_transport_get_is_authenticated (transport))
195     need_read_watch =
196       (_dbus_counter_get_size_value (transport->live_messages) < transport->max_live_messages_size) &&
197       (_dbus_counter_get_unix_fd_value (transport->live_messages) < transport->max_live_messages_unix_fds);
198   else
199     {
200       if (transport->receive_credentials_pending)
201         need_read_watch = TRUE;
202       else
203         {
204           /* The reason to disable need_read_watch when not WAITING_FOR_INPUT
205            * is to avoid spinning on the file descriptor when we're waiting
206            * to write or for some other part of the auth process
207            */
208           DBusAuthState auth_state;
209           
210           auth_state = _dbus_auth_do_work (transport->auth);
211
212           /* If we need memory we install the read watch just in case,
213            * if there's no need for it, it will get de-installed
214            * next time we try reading. If we're authenticated we
215            * install it since we normally have it installed while
216            * authenticated.
217            */
218           if (auth_state == DBUS_AUTH_STATE_WAITING_FOR_INPUT ||
219               auth_state == DBUS_AUTH_STATE_WAITING_FOR_MEMORY ||
220               auth_state == DBUS_AUTH_STATE_AUTHENTICATED)
221             need_read_watch = TRUE;
222           else
223             need_read_watch = FALSE;
224         }
225     }
226
227   _dbus_verbose ("  setting read watch enabled = %d\n", need_read_watch);
228   _dbus_connection_toggle_watch_unlocked (transport->connection,
229                                           socket_transport->read_watch,
230                                           need_read_watch);
231
232   _dbus_transport_unref (transport);
233 }
234
235 static void
236 do_io_error (DBusTransport *transport)
237 {
238   _dbus_transport_ref (transport);
239   _dbus_transport_disconnect (transport);
240   _dbus_transport_unref (transport);
241 }
242
243 /* return value is whether we successfully read any new data. */
244 static dbus_bool_t
245 read_data_into_auth (DBusTransport *transport,
246                      dbus_bool_t   *oom)
247 {
248   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
249   DBusString *buffer;
250   int bytes_read;
251   
252   *oom = FALSE;
253
254   _dbus_auth_get_buffer (transport->auth, &buffer);
255   
256   bytes_read = _dbus_read_socket (socket_transport->fd,
257                                   buffer, socket_transport->max_bytes_read_per_iteration);
258
259   _dbus_auth_return_buffer (transport->auth, buffer,
260                             bytes_read > 0 ? bytes_read : 0);
261
262   if (bytes_read > 0)
263     {
264       _dbus_verbose (" read %d bytes in auth phase\n", bytes_read);
265
266       return TRUE;
267     }
268   else if (bytes_read < 0)
269     {
270       /* EINTR already handled for us */
271
272       if (_dbus_get_is_errno_enomem ())
273         {
274           *oom = TRUE;
275         }
276       else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
277         ; /* do nothing, just return FALSE below */
278       else
279         {
280           _dbus_verbose ("Error reading from remote app: %s\n",
281                          _dbus_strerror_from_errno ());
282           do_io_error (transport);
283         }
284
285       return FALSE;
286     }
287   else
288     {
289       _dbus_assert (bytes_read == 0);
290       
291       _dbus_verbose ("Disconnected from remote app\n");
292       do_io_error (transport);
293
294       return FALSE;
295     }
296 }
297
298 /* Return value is whether we successfully wrote any bytes */
299 static dbus_bool_t
300 write_data_from_auth (DBusTransport *transport)
301 {
302   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
303   int bytes_written;
304   const DBusString *buffer;
305
306   if (!_dbus_auth_get_bytes_to_send (transport->auth,
307                                      &buffer))
308     return FALSE;
309   
310   bytes_written = _dbus_write_socket (socket_transport->fd,
311                                       buffer,
312                                       0, _dbus_string_get_length (buffer));
313
314   if (bytes_written > 0)
315     {
316       _dbus_auth_bytes_sent (transport->auth, bytes_written);
317       return TRUE;
318     }
319   else if (bytes_written < 0)
320     {
321       /* EINTR already handled for us */
322       
323       if (_dbus_get_is_errno_eagain_or_ewouldblock ())
324         ;
325       else
326         {
327           _dbus_verbose ("Error writing to remote app: %s\n",
328                          _dbus_strerror_from_errno ());
329           do_io_error (transport);
330         }
331     }
332
333   return FALSE;
334 }
335
336 /* FALSE on OOM */
337 static dbus_bool_t
338 exchange_credentials (DBusTransport *transport,
339                       dbus_bool_t    do_reading,
340                       dbus_bool_t    do_writing)
341 {
342   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
343   DBusError error = DBUS_ERROR_INIT;
344
345   _dbus_verbose ("exchange_credentials: do_reading = %d, do_writing = %d\n",
346                   do_reading, do_writing);
347
348   if (do_writing && transport->send_credentials_pending)
349     {
350       if (_dbus_send_credentials_socket (socket_transport->fd,
351                                          &error))
352         {
353           transport->send_credentials_pending = FALSE;
354         }
355       else
356         {
357           _dbus_verbose ("Failed to write credentials: %s\n", error.message);
358           dbus_error_free (&error);
359           do_io_error (transport);
360         }
361     }
362   
363   if (do_reading && transport->receive_credentials_pending)
364     {
365       /* FIXME this can fail due to IO error _or_ OOM, broken
366        * (somewhat tricky to fix since the OOM error can be set after
367        * we already read the credentials byte, so basically we need to
368        * separate reading the byte and storing it in the
369        * transport->credentials). Does not really matter for now
370        * because storing in credentials never actually fails on unix.
371        */      
372       if (_dbus_read_credentials_socket (socket_transport->fd,
373                                          transport->credentials,
374                                          &error))
375         {
376           transport->receive_credentials_pending = FALSE;
377         }
378       else
379         {
380           _dbus_verbose ("Failed to read credentials %s\n", error.message);
381           dbus_error_free (&error);
382           do_io_error (transport);
383         }
384     }
385
386   if (!(transport->send_credentials_pending ||
387         transport->receive_credentials_pending))
388     {
389       if (!_dbus_auth_set_credentials (transport->auth,
390                                        transport->credentials))
391         return FALSE;
392     }
393
394   return TRUE;
395 }
396
397 static dbus_bool_t
398 do_authentication (DBusTransport *transport,
399                    dbus_bool_t    do_reading,
400                    dbus_bool_t    do_writing,
401                    dbus_bool_t   *auth_completed)
402 {
403   dbus_bool_t oom;
404   dbus_bool_t orig_auth_state;
405
406   oom = FALSE;
407   
408   orig_auth_state = _dbus_transport_get_is_authenticated (transport);
409
410   /* This is essential to avoid the check_write_watch() at the end,
411    * we don't want to add a write watch in do_iteration before
412    * we try writing and get EAGAIN
413    */
414   if (orig_auth_state)
415     {
416       if (auth_completed)
417         *auth_completed = FALSE;
418       return TRUE;
419     }
420   
421   _dbus_transport_ref (transport);
422   
423   while (!_dbus_transport_get_is_authenticated (transport) &&
424          _dbus_transport_get_is_connected (transport))
425     {      
426       if (!exchange_credentials (transport, do_reading, do_writing))
427         {
428           /* OOM */
429           oom = TRUE;
430           goto out;
431         }
432       
433       if (transport->send_credentials_pending ||
434           transport->receive_credentials_pending)
435         {
436           _dbus_verbose ("send_credentials_pending = %d receive_credentials_pending = %d\n",
437                          transport->send_credentials_pending,
438                          transport->receive_credentials_pending);
439           goto out;
440         }
441
442 #define TRANSPORT_SIDE(t) ((t)->is_server ? "server" : "client")
443       switch (_dbus_auth_do_work (transport->auth))
444         {
445         case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
446           _dbus_verbose (" %s auth state: waiting for input\n",
447                          TRANSPORT_SIDE (transport));
448           if (!do_reading || !read_data_into_auth (transport, &oom))
449             goto out;
450           break;
451       
452         case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
453           _dbus_verbose (" %s auth state: waiting for memory\n",
454                          TRANSPORT_SIDE (transport));
455           oom = TRUE;
456           goto out;
457           break;
458       
459         case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
460           _dbus_verbose (" %s auth state: bytes to send\n",
461                          TRANSPORT_SIDE (transport));
462           if (!do_writing || !write_data_from_auth (transport))
463             goto out;
464           break;
465       
466         case DBUS_AUTH_STATE_NEED_DISCONNECT:
467           _dbus_verbose (" %s auth state: need to disconnect\n",
468                          TRANSPORT_SIDE (transport));
469           do_io_error (transport);
470           break;
471       
472         case DBUS_AUTH_STATE_AUTHENTICATED:
473           _dbus_verbose (" %s auth state: authenticated\n",
474                          TRANSPORT_SIDE (transport));
475           break;
476         }
477     }
478
479  out:
480   if (auth_completed)
481     *auth_completed = (orig_auth_state != _dbus_transport_get_is_authenticated (transport));
482   
483   check_read_watch (transport);
484   check_write_watch (transport);
485   _dbus_transport_unref (transport);
486
487   if (oom)
488     return FALSE;
489   else
490     return TRUE;
491 }
492
493 /* returns false on oom */
494 static dbus_bool_t
495 do_writing (DBusTransport *transport)
496 {
497   int total;
498   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
499   dbus_bool_t oom;
500   
501   /* No messages without authentication! */
502   if (!_dbus_transport_get_is_authenticated (transport))
503     {
504       _dbus_verbose ("Not authenticated, not writing anything\n");
505       return TRUE;
506     }
507
508   if (transport->disconnected)
509     {
510       _dbus_verbose ("Not connected, not writing anything\n");
511       return TRUE;
512     }
513
514 #if 1
515   _dbus_verbose ("do_writing(), have_messages = %d, fd = %d\n",
516                  _dbus_connection_has_messages_to_send_unlocked (transport->connection),
517                  socket_transport->fd);
518 #endif
519   
520   oom = FALSE;
521   total = 0;
522
523   while (!transport->disconnected &&
524          _dbus_connection_has_messages_to_send_unlocked (transport->connection))
525     {
526       int bytes_written;
527       DBusMessage *message;
528       const DBusString *header;
529       const DBusString *body;
530       int header_len, body_len;
531       int total_bytes_to_write;
532       
533 //      int i;
534
535       if (total > socket_transport->max_bytes_written_per_iteration)
536         {
537           _dbus_verbose ("%d bytes exceeds %d bytes written per iteration, returning\n",
538                          total, socket_transport->max_bytes_written_per_iteration);
539           goto out;
540         }
541       
542       message = _dbus_connection_get_message_to_send (transport->connection);
543       _dbus_assert (message != NULL);
544       dbus_message_lock (message);
545
546 #if 0
547       _dbus_verbose ("writing message %p\n", message);
548 #endif
549       
550       _dbus_message_get_network_data (message,
551                                       &header, &body);
552
553       header_len = _dbus_string_get_length (header);
554       body_len = _dbus_string_get_length (body);
555
556   /*    fprintf (stderr, "\nheader:\n");  //todo for test - to remove together wit int i declaration above
557       for(i=0; i < header_len; i++)
558       {
559         fprintf (stderr, "%02x", _dbus_string_get_byte(header,i));
560       }
561       fprintf (stderr,"\n");
562       for(i=0; i < header_len; i++)
563       {
564         fprintf (stderr, "%c", _dbus_string_get_byte(header,i));
565       }
566       fprintf (stderr, "\nret size: %u, i: %u\n", header_len, i);
567
568
569       fprintf (stderr, "\nbody:\n");
570       for(i=0; i < body_len; i++)
571       {
572         fprintf (stderr, "%02x", _dbus_string_get_byte(body,i));
573       }
574       fprintf (stderr, "\nret size: %u, i: %u\n", body_len, i);
575       fprintf (stderr,"\n");
576       for(i=0; i < body_len; i++)
577       {
578         fprintf (stderr, "%c", _dbus_string_get_byte(body,i));
579       }
580       fprintf (stderr, "\nret size: %u, i: %u\n", body_len, i);*/
581
582       if (_dbus_auth_needs_encoding (transport->auth))
583         {
584           /* Does fd passing even make sense with encoded data? */
585           _dbus_assert(!DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport));
586
587           if (_dbus_string_get_length (&socket_transport->encoded_outgoing) == 0)
588             {
589               if (!_dbus_auth_encode_data (transport->auth,
590                                            header, &socket_transport->encoded_outgoing))
591                 {
592                   oom = TRUE;
593                   goto out;
594                 }
595               
596               if (!_dbus_auth_encode_data (transport->auth,
597                                            body, &socket_transport->encoded_outgoing))
598                 {
599                   _dbus_string_set_length (&socket_transport->encoded_outgoing, 0);
600                   oom = TRUE;
601                   goto out;
602                 }
603             }
604           
605           total_bytes_to_write = _dbus_string_get_length (&socket_transport->encoded_outgoing);
606
607 #if 0
608           _dbus_verbose ("encoded message is %d bytes\n",
609                          total_bytes_to_write);
610 #endif
611           
612           bytes_written =
613             _dbus_write_socket (socket_transport->fd,
614                                 &socket_transport->encoded_outgoing,
615                                 socket_transport->message_bytes_written,
616                                 total_bytes_to_write - socket_transport->message_bytes_written);
617         }
618       else
619         {
620           total_bytes_to_write = header_len + body_len;
621
622 #if 0
623           _dbus_verbose ("message is %d bytes\n",
624                          total_bytes_to_write);
625 #endif
626
627 #ifdef HAVE_UNIX_FD_PASSING
628           if (socket_transport->message_bytes_written <= 0 && DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport))
629             {
630               /* Send the fds along with the first byte of the message */
631               const int *unix_fds;
632               unsigned n;
633
634               _dbus_message_get_unix_fds(message, &unix_fds, &n);
635
636               bytes_written =
637                 _dbus_write_socket_with_unix_fds_two (socket_transport->fd,
638                                                       header,
639                                                       socket_transport->message_bytes_written,
640                                                       header_len - socket_transport->message_bytes_written,
641                                                       body,
642                                                       0, body_len,
643                                                       unix_fds,
644                                                       n);
645
646               if (bytes_written > 0 && n > 0)
647                 _dbus_verbose("Wrote %i unix fds\n", n);
648             }
649           else
650 #endif
651             {
652               if (socket_transport->message_bytes_written < header_len)
653                 {
654                   bytes_written =
655                     _dbus_write_socket_two (socket_transport->fd,
656                                             header,
657                                             socket_transport->message_bytes_written,
658                                             header_len - socket_transport->message_bytes_written,
659                                             body,
660                                             0, body_len);
661                 }
662               else
663                 {
664                   bytes_written =
665                     _dbus_write_socket (socket_transport->fd,
666                                         body,
667                                         (socket_transport->message_bytes_written - header_len),
668                                         body_len -
669                                         (socket_transport->message_bytes_written - header_len));
670                 }
671             }
672         }
673
674       if (bytes_written < 0)
675         {
676           /* EINTR already handled for us */
677           
678           /* For some discussion of why we also ignore EPIPE here, see
679            * http://lists.freedesktop.org/archives/dbus/2008-March/009526.html
680            */
681           
682           if (_dbus_get_is_errno_eagain_or_ewouldblock () || _dbus_get_is_errno_epipe ())
683             goto out;
684           else
685             {
686               _dbus_verbose ("Error writing to remote app: %s\n",
687                              _dbus_strerror_from_errno ());
688               do_io_error (transport);
689               goto out;
690             }
691         }
692       else
693         {
694           _dbus_verbose (" wrote %d bytes of %d\n", bytes_written,
695                          total_bytes_to_write);
696           
697           total += bytes_written;
698           socket_transport->message_bytes_written += bytes_written;
699
700           _dbus_assert (socket_transport->message_bytes_written <=
701                         total_bytes_to_write);
702           
703           if (socket_transport->message_bytes_written == total_bytes_to_write)
704             {
705               socket_transport->message_bytes_written = 0;
706               _dbus_string_set_length (&socket_transport->encoded_outgoing, 0);
707               _dbus_string_compact (&socket_transport->encoded_outgoing, 2048);
708
709               _dbus_connection_message_sent_unlocked (transport->connection,
710                                                       message);
711             }
712         }
713     }
714
715  out:
716   if (oom)
717     return FALSE;
718   else
719     return TRUE;
720 }
721
722 /* returns false on out-of-memory */
723 static dbus_bool_t
724 do_reading (DBusTransport *transport)
725 {
726   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
727   DBusString *buffer;
728   int bytes_read;
729   int total;
730   dbus_bool_t oom;
731
732   _dbus_verbose ("fd = %d\n",socket_transport->fd);
733   
734   /* No messages without authentication! */
735   if (!_dbus_transport_get_is_authenticated (transport))
736     return TRUE;
737
738   oom = FALSE;
739   
740   total = 0;
741
742  again:
743   
744   /* See if we've exceeded max messages and need to disable reading */
745   check_read_watch (transport);
746   
747   if (total > socket_transport->max_bytes_read_per_iteration)
748     {
749       _dbus_verbose ("%d bytes exceeds %d bytes read per iteration, returning\n",
750                      total, socket_transport->max_bytes_read_per_iteration);
751       goto out;
752     }
753
754   _dbus_assert (socket_transport->read_watch != NULL ||
755                 transport->disconnected);
756   
757   if (transport->disconnected)
758     goto out;
759
760   if (!dbus_watch_get_enabled (socket_transport->read_watch))
761     return TRUE;
762   
763   if (_dbus_auth_needs_decoding (transport->auth))
764     {
765       /* Does fd passing even make sense with encoded data? */
766       _dbus_assert(!DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport));
767
768       if (_dbus_string_get_length (&socket_transport->encoded_incoming) > 0)
769         bytes_read = _dbus_string_get_length (&socket_transport->encoded_incoming);
770       else
771         bytes_read = _dbus_read_socket (socket_transport->fd,
772                                         &socket_transport->encoded_incoming,
773                                         socket_transport->max_bytes_read_per_iteration);
774
775       _dbus_assert (_dbus_string_get_length (&socket_transport->encoded_incoming) ==
776                     bytes_read);
777       
778       if (bytes_read > 0)
779         {
780           int orig_len;
781           
782           _dbus_message_loader_get_buffer (transport->loader,
783                                            &buffer);
784
785           orig_len = _dbus_string_get_length (buffer);
786           
787           if (!_dbus_auth_decode_data (transport->auth,
788                                        &socket_transport->encoded_incoming,
789                                        buffer))
790             {
791               _dbus_verbose ("Out of memory decoding incoming data\n");
792               _dbus_message_loader_return_buffer (transport->loader,
793                                               buffer,
794                                               _dbus_string_get_length (buffer) - orig_len);
795
796               oom = TRUE;
797               goto out;
798             }
799
800           _dbus_message_loader_return_buffer (transport->loader,
801                                               buffer,
802                                               _dbus_string_get_length (buffer) - orig_len);
803
804           _dbus_string_set_length (&socket_transport->encoded_incoming, 0);
805           _dbus_string_compact (&socket_transport->encoded_incoming, 2048);
806         }
807     }
808   else
809     {
810       _dbus_message_loader_get_buffer (transport->loader,
811                                        &buffer);
812
813 #ifdef HAVE_UNIX_FD_PASSING
814       if (DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport))
815         {
816           int *fds, n_fds;
817
818           if (!_dbus_message_loader_get_unix_fds(transport->loader, &fds, &n_fds))
819             {
820               _dbus_verbose ("Out of memory reading file descriptors\n");
821               _dbus_message_loader_return_buffer (transport->loader, buffer, 0);
822               oom = TRUE;
823               goto out;
824             }
825
826           bytes_read = _dbus_read_socket_with_unix_fds(socket_transport->fd,
827                                                        buffer,
828                                                        socket_transport->max_bytes_read_per_iteration,
829                                                        fds, &n_fds);
830
831           if (bytes_read >= 0 && n_fds > 0)
832             _dbus_verbose("Read %i unix fds\n", n_fds);
833
834           _dbus_message_loader_return_unix_fds(transport->loader, fds, bytes_read < 0 ? 0 : n_fds);
835         }
836       else
837 #endif
838         {
839           bytes_read = _dbus_read_socket (socket_transport->fd,
840                                           buffer, socket_transport->max_bytes_read_per_iteration);
841         }
842
843       _dbus_message_loader_return_buffer (transport->loader,
844                                           buffer,
845                                           bytes_read < 0 ? 0 : bytes_read);
846     }
847
848   if (bytes_read < 0)
849     {
850       /* EINTR already handled for us */
851
852       if (_dbus_get_is_errno_enomem ())
853         {
854           _dbus_verbose ("Out of memory in read()/do_reading()\n");
855           oom = TRUE;
856           goto out;
857         }
858       else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
859         goto out;
860       else
861         {
862           _dbus_verbose ("Error reading from remote app: %s\n",
863                          _dbus_strerror_from_errno ());
864           do_io_error (transport);
865           goto out;
866         }
867     }
868   else if (bytes_read == 0)
869     {
870       _dbus_verbose ("Disconnected from remote app\n");
871       do_io_error (transport);
872       goto out;
873     }
874   else
875     {
876       _dbus_verbose (" read %d bytes\n", bytes_read);
877       
878       total += bytes_read;      
879
880       if (!_dbus_transport_queue_messages (transport))
881         {
882           oom = TRUE;
883           _dbus_verbose (" out of memory when queueing messages we just read in the transport\n");
884           goto out;
885         }
886       
887       /* Try reading more data until we get EAGAIN and return, or
888        * exceed max bytes per iteration.  If in blocking mode of
889        * course we'll block instead of returning.
890        */
891       goto again;
892     }
893
894  out:
895   if (oom)
896     return FALSE;
897   else
898     return TRUE;
899 }
900
901 static dbus_bool_t
902 unix_error_with_read_to_come (DBusTransport *itransport,
903                               DBusWatch     *watch,
904                               unsigned int   flags)
905 {
906   DBusTransportSocket *transport = (DBusTransportSocket *) itransport;
907
908   if (!(flags & DBUS_WATCH_HANGUP || flags & DBUS_WATCH_ERROR))
909     return FALSE;
910    
911   /* If we have a read watch enabled ...
912      we -might have data incoming ... => handle the HANGUP there */
913   if (watch != transport->read_watch &&
914       _dbus_watch_get_enabled (transport->read_watch))
915     return FALSE;
916       
917   return TRUE; 
918 }
919
920 static dbus_bool_t
921 socket_handle_watch (DBusTransport *transport,
922                    DBusWatch     *watch,
923                    unsigned int   flags)
924 {
925   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
926
927   _dbus_assert (watch == socket_transport->read_watch ||
928                 watch == socket_transport->write_watch);
929   _dbus_assert (watch != NULL);
930   
931   /* If we hit an error here on a write watch, don't disconnect the transport yet because data can
932    * still be in the buffer and do_reading may need several iteration to read
933    * it all (because of its max_bytes_read_per_iteration limit). 
934    */
935   if (!(flags & DBUS_WATCH_READABLE) && unix_error_with_read_to_come (transport, watch, flags))
936     {
937       _dbus_verbose ("Hang up or error on watch\n");
938       _dbus_transport_disconnect (transport);
939       return TRUE;
940     }
941   
942   if (watch == socket_transport->read_watch &&
943       (flags & DBUS_WATCH_READABLE))
944     {
945       dbus_bool_t auth_finished;
946 #if 1
947       _dbus_verbose ("handling read watch %p flags = %x\n",
948                      watch, flags);
949 #endif
950       if (!do_authentication (transport, TRUE, FALSE, &auth_finished))
951         return FALSE;
952
953       /* We don't want to do a read immediately following
954        * a successful authentication.  This is so we
955        * have a chance to propagate the authentication
956        * state further up.  Specifically, we need to
957        * process any pending data from the auth object.
958        */
959       if (!auth_finished)
960         {
961           if (!do_reading (transport))
962             {
963               _dbus_verbose ("no memory to read\n");
964               return FALSE;
965             }
966         }
967       else
968         {
969           _dbus_verbose ("Not reading anything since we just completed the authentication\n");
970         }
971     }
972   else if (watch == socket_transport->write_watch &&
973            (flags & DBUS_WATCH_WRITABLE))
974     {
975 #if 1
976       _dbus_verbose ("handling write watch, have_outgoing_messages = %d\n",
977                      _dbus_connection_has_messages_to_send_unlocked (transport->connection));
978 #endif
979       if (!do_authentication (transport, FALSE, TRUE, NULL))
980         return FALSE;
981       
982       if (!do_writing (transport))
983         {
984           _dbus_verbose ("no memory to write\n");
985           return FALSE;
986         }
987
988       /* See if we still need the write watch */
989       check_write_watch (transport);
990     }
991 #ifdef DBUS_ENABLE_VERBOSE_MODE
992   else
993     {
994       if (watch == socket_transport->read_watch)
995         _dbus_verbose ("asked to handle read watch with non-read condition 0x%x\n",
996                        flags);
997       else if (watch == socket_transport->write_watch)
998         _dbus_verbose ("asked to handle write watch with non-write condition 0x%x\n",
999                        flags);
1000       else
1001         _dbus_verbose ("asked to handle watch %p on fd %d that we don't recognize\n",
1002                        watch, dbus_watch_get_socket (watch));
1003     }
1004 #endif /* DBUS_ENABLE_VERBOSE_MODE */
1005
1006   return TRUE;
1007 }
1008
1009 static void
1010 socket_disconnect (DBusTransport *transport)
1011 {
1012   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
1013
1014   _dbus_verbose ("\n");
1015   
1016   free_watches (transport);
1017   
1018   _dbus_close_socket (socket_transport->fd, NULL);
1019   socket_transport->fd = -1;
1020 }
1021
1022 static dbus_bool_t
1023 socket_connection_set (DBusTransport *transport)
1024 {
1025   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
1026
1027   _dbus_watch_set_handler (socket_transport->write_watch,
1028                            _dbus_connection_handle_watch,
1029                            transport->connection, NULL);
1030
1031   _dbus_watch_set_handler (socket_transport->read_watch,
1032                            _dbus_connection_handle_watch,
1033                            transport->connection, NULL);
1034   
1035   if (!_dbus_connection_add_watch_unlocked (transport->connection,
1036                                             socket_transport->write_watch))
1037     return FALSE;
1038
1039   if (!_dbus_connection_add_watch_unlocked (transport->connection,
1040                                             socket_transport->read_watch))
1041     {
1042       _dbus_connection_remove_watch_unlocked (transport->connection,
1043                                               socket_transport->write_watch);
1044       return FALSE;
1045     }
1046
1047   check_read_watch (transport);
1048   check_write_watch (transport);
1049
1050   return TRUE;
1051 }
1052
1053 /**
1054  * @todo We need to have a way to wake up the select sleep if
1055  * a new iteration request comes in with a flag (read/write) that
1056  * we're not currently serving. Otherwise a call that just reads
1057  * could block a write call forever (if there are no incoming
1058  * messages).
1059  */
1060 static  void
1061 socket_do_iteration (DBusTransport *transport,
1062                    unsigned int   flags,
1063                    int            timeout_milliseconds)
1064 {
1065   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
1066   DBusPollFD poll_fd;
1067   int poll_res;
1068   int poll_timeout;
1069
1070   _dbus_verbose (" iteration flags = %s%s timeout = %d read_watch = %p write_watch = %p fd = %d\n",
1071                  flags & DBUS_ITERATION_DO_READING ? "read" : "",
1072                  flags & DBUS_ITERATION_DO_WRITING ? "write" : "",
1073                  timeout_milliseconds,
1074                  socket_transport->read_watch,
1075                  socket_transport->write_watch,
1076                  socket_transport->fd);
1077   
1078   /* the passed in DO_READING/DO_WRITING flags indicate whether to
1079    * read/write messages, but regardless of those we may need to block
1080    * for reading/writing to do auth.  But if we do reading for auth,
1081    * we don't want to read any messages yet if not given DO_READING.
1082    */
1083
1084   poll_fd.fd = socket_transport->fd;
1085   poll_fd.events = 0;
1086   
1087   if (_dbus_transport_get_is_authenticated (transport))
1088     {
1089       /* This is kind of a hack; if we have stuff to write, then try
1090        * to avoid the poll. This is probably about a 5% speedup on an
1091        * echo client/server.
1092        *
1093        * If both reading and writing were requested, we want to avoid this
1094        * since it could have funky effects:
1095        *   - both ends spinning waiting for the other one to read
1096        *     data so they can finish writing
1097        *   - prioritizing all writing ahead of reading
1098        */
1099       if ((flags & DBUS_ITERATION_DO_WRITING) &&
1100           !(flags & (DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK)) &&
1101           !transport->disconnected &&
1102           _dbus_connection_has_messages_to_send_unlocked (transport->connection))
1103         {
1104           do_writing (transport);
1105
1106           if (transport->disconnected ||
1107               !_dbus_connection_has_messages_to_send_unlocked (transport->connection))
1108             goto out;
1109         }
1110
1111       /* If we get here, we decided to do the poll() after all */
1112       _dbus_assert (socket_transport->read_watch);
1113       if (flags & DBUS_ITERATION_DO_READING)
1114         poll_fd.events |= _DBUS_POLLIN;
1115
1116       _dbus_assert (socket_transport->write_watch);
1117       if (flags & DBUS_ITERATION_DO_WRITING)
1118         poll_fd.events |= _DBUS_POLLOUT;
1119     }
1120   else
1121     {
1122       DBusAuthState auth_state;
1123       
1124       auth_state = _dbus_auth_do_work (transport->auth);
1125
1126       if (transport->receive_credentials_pending ||
1127           auth_state == DBUS_AUTH_STATE_WAITING_FOR_INPUT)
1128         poll_fd.events |= _DBUS_POLLIN;
1129
1130       if (transport->send_credentials_pending ||
1131           auth_state == DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
1132         poll_fd.events |= _DBUS_POLLOUT;
1133     }
1134
1135   if (poll_fd.events)
1136     {
1137       if (flags & DBUS_ITERATION_BLOCK)
1138         poll_timeout = timeout_milliseconds;
1139       else
1140         poll_timeout = 0;
1141
1142       /* For blocking selects we drop the connection lock here
1143        * to avoid blocking out connection access during a potentially
1144        * indefinite blocking call. The io path is still protected
1145        * by the io_path_cond condvar, so we won't reenter this.
1146        */
1147       if (flags & DBUS_ITERATION_BLOCK)
1148         {
1149           _dbus_verbose ("unlock pre poll\n");
1150           _dbus_connection_unlock (transport->connection);
1151         }
1152       
1153     again:
1154       poll_res = _dbus_poll (&poll_fd, 1, poll_timeout);
1155
1156       if (poll_res < 0 && _dbus_get_is_errno_eintr ())
1157         goto again;
1158
1159       if (flags & DBUS_ITERATION_BLOCK)
1160         {
1161           _dbus_verbose ("lock post poll\n");
1162           _dbus_connection_lock (transport->connection);
1163         }
1164       
1165       if (poll_res >= 0)
1166         {
1167           if (poll_res == 0)
1168             poll_fd.revents = 0; /* some concern that posix does not guarantee this;
1169                                   * valgrind flags it as an error. though it probably
1170                                   * is guaranteed on linux at least.
1171                                   */
1172           
1173           if (poll_fd.revents & _DBUS_POLLERR)
1174             do_io_error (transport);
1175           else
1176             {
1177               dbus_bool_t need_read = (poll_fd.revents & _DBUS_POLLIN) > 0;
1178               dbus_bool_t need_write = (poll_fd.revents & _DBUS_POLLOUT) > 0;
1179               dbus_bool_t authentication_completed;
1180
1181               _dbus_verbose ("in iteration, need_read=%d need_write=%d\n",
1182                              need_read, need_write);
1183               do_authentication (transport, need_read, need_write,
1184                                  &authentication_completed);
1185
1186               /* See comment in socket_handle_watch. */
1187               if (authentication_completed)
1188                 goto out;
1189                                  
1190               if (need_read && (flags & DBUS_ITERATION_DO_READING))
1191                 do_reading (transport);
1192               if (need_write && (flags & DBUS_ITERATION_DO_WRITING))
1193                 do_writing (transport);
1194             }
1195         }
1196       else
1197         {
1198           _dbus_verbose ("Error from _dbus_poll(): %s\n",
1199                          _dbus_strerror_from_errno ());
1200         }
1201     }
1202
1203
1204  out:
1205   /* We need to install the write watch only if we did not
1206    * successfully write everything. Note we need to be careful that we
1207    * don't call check_write_watch *before* do_writing, since it's
1208    * inefficient to add the write watch, and we can avoid it most of
1209    * the time since we can write immediately.
1210    * 
1211    * However, we MUST always call check_write_watch(); DBusConnection code
1212    * relies on the fact that running an iteration will notice that
1213    * messages are pending.
1214    */
1215   check_write_watch (transport);
1216
1217   _dbus_verbose (" ... leaving do_iteration()\n");
1218 }
1219
1220 static void
1221 socket_live_messages_changed (DBusTransport *transport)
1222 {
1223   /* See if we should look for incoming messages again */
1224   check_read_watch (transport);
1225 }
1226
1227
1228 static dbus_bool_t
1229 socket_get_socket_fd (DBusTransport *transport,
1230                       int           *fd_p)
1231 {
1232   DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
1233   
1234   *fd_p = socket_transport->fd;
1235   
1236   return TRUE;
1237 }
1238
1239 static const DBusTransportVTable socket_vtable = {
1240   socket_finalize,
1241   socket_handle_watch,
1242   socket_disconnect,
1243   socket_connection_set,
1244   socket_do_iteration,
1245   socket_live_messages_changed,
1246   socket_get_socket_fd
1247 };
1248
1249 /**
1250  * Creates a new transport for the given socket file descriptor.  The file
1251  * descriptor must be nonblocking (use _dbus_set_fd_nonblocking() to
1252  * make it so). This function is shared by various transports that
1253  * boil down to a full duplex file descriptor.
1254  *
1255  * @param fd the file descriptor.
1256  * @param server_guid non-#NULL if this transport is on the server side of a connection
1257  * @param address the transport's address
1258  * @returns the new transport, or #NULL if no memory.
1259  */
1260 DBusTransport*
1261 _dbus_transport_new_for_socket (int               fd,
1262                                 const DBusString *server_guid,
1263                                 const DBusString *address)
1264 {
1265   DBusTransportSocket *socket_transport;
1266   
1267   socket_transport = dbus_new0 (DBusTransportSocket, 1);
1268   if (socket_transport == NULL)
1269     return NULL;
1270
1271   if (!_dbus_string_init (&socket_transport->encoded_outgoing))
1272     goto failed_0;
1273
1274   if (!_dbus_string_init (&socket_transport->encoded_incoming))
1275     goto failed_1;
1276   
1277   socket_transport->write_watch = _dbus_watch_new (fd,
1278                                                  DBUS_WATCH_WRITABLE,
1279                                                  FALSE,
1280                                                  NULL, NULL, NULL);
1281   if (socket_transport->write_watch == NULL)
1282     goto failed_2;
1283   
1284   socket_transport->read_watch = _dbus_watch_new (fd,
1285                                                 DBUS_WATCH_READABLE,
1286                                                 FALSE,
1287                                                 NULL, NULL, NULL);
1288   if (socket_transport->read_watch == NULL)
1289     goto failed_3;
1290
1291   if (!_dbus_transport_init_base (&socket_transport->base,
1292                                   &socket_vtable,
1293                                   server_guid, address))
1294     goto failed_4;
1295
1296 #ifdef HAVE_UNIX_FD_PASSING
1297   _dbus_auth_set_unix_fd_possible(socket_transport->base.auth, _dbus_socket_can_pass_unix_fd(fd));
1298 #endif
1299
1300   socket_transport->fd = fd;
1301   socket_transport->message_bytes_written = 0;
1302   
1303   /* These values should probably be tunable or something. */     
1304   socket_transport->max_bytes_read_per_iteration = 2048;
1305   socket_transport->max_bytes_written_per_iteration = 2048;
1306   
1307   return (DBusTransport*) socket_transport;
1308
1309  failed_4:
1310   _dbus_watch_invalidate (socket_transport->read_watch);
1311   _dbus_watch_unref (socket_transport->read_watch);
1312  failed_3:
1313   _dbus_watch_invalidate (socket_transport->write_watch);
1314   _dbus_watch_unref (socket_transport->write_watch);
1315  failed_2:
1316   _dbus_string_free (&socket_transport->encoded_incoming);
1317  failed_1:
1318   _dbus_string_free (&socket_transport->encoded_outgoing);
1319  failed_0:
1320   dbus_free (socket_transport);
1321   return NULL;
1322 }
1323
1324 /**
1325  * Creates a new transport for the given hostname and port.
1326  * If host is NULL, it will default to localhost
1327  *
1328  * @param host the host to connect to
1329  * @param port the port to connect to
1330  * @param family the address family to connect to
1331  * @param path to nonce file
1332  * @param error location to store reason for failure.
1333  * @returns a new transport, or #NULL on failure.
1334  */
1335 DBusTransport*
1336 _dbus_transport_new_for_tcp_socket (const char     *host,
1337                                     const char     *port,
1338                                     const char     *family,
1339                                     const char     *noncefile,
1340                                     DBusError      *error)
1341 {
1342   int fd;
1343   DBusTransport *transport;
1344   DBusString address;
1345   
1346   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1347
1348   if (!_dbus_string_init (&address))
1349     {
1350       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
1351       return NULL;
1352     }
1353
1354   if (host == NULL)
1355     host = "localhost";
1356
1357   if (!_dbus_string_append (&address, noncefile ? "nonce-tcp:" : "tcp:"))
1358     goto error;
1359
1360   if (!_dbus_string_append (&address, "host=") ||
1361       !_dbus_string_append (&address, host))
1362     goto error;
1363
1364   if (!_dbus_string_append (&address, ",port=") ||
1365       !_dbus_string_append (&address, port))
1366     goto error;
1367
1368   if (family != NULL &&
1369       (!_dbus_string_append (&address, ",family=") ||
1370        !_dbus_string_append (&address, family)))
1371     goto error;
1372
1373   if (noncefile != NULL &&
1374       (!_dbus_string_append (&address, ",noncefile=") ||
1375        !_dbus_string_append (&address, noncefile)))
1376     goto error;
1377
1378   fd = _dbus_connect_tcp_socket_with_nonce (host, port, family, noncefile, error);
1379   if (fd < 0)
1380     {
1381       _DBUS_ASSERT_ERROR_IS_SET (error);
1382       _dbus_string_free (&address);
1383       return NULL;
1384     }
1385
1386   _dbus_verbose ("Successfully connected to tcp socket %s:%s\n",
1387                  host, port);
1388   
1389   transport = _dbus_transport_new_for_socket (fd, NULL, &address);
1390   _dbus_string_free (&address);
1391   if (transport == NULL)
1392     {
1393       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
1394       _dbus_close_socket (fd, NULL);
1395       fd = -1;
1396     }
1397
1398   return transport;
1399
1400 error:
1401   _dbus_string_free (&address);
1402   dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
1403   return NULL;
1404 }
1405
1406 /**
1407  * Opens a TCP socket transport.
1408  * 
1409  * @param entry the address entry to try opening as a tcp transport.
1410  * @param transport_p return location for the opened transport
1411  * @param error error to be set
1412  * @returns result of the attempt
1413  */
1414 DBusTransportOpenResult
1415 _dbus_transport_open_socket(DBusAddressEntry  *entry,
1416                             DBusTransport    **transport_p,                            
1417                             DBusError         *error)
1418 {
1419   const char *method;
1420   dbus_bool_t isTcp;
1421   dbus_bool_t isNonceTcp;
1422   
1423   method = dbus_address_entry_get_method (entry);
1424   _dbus_assert (method != NULL);
1425
1426   isTcp = strcmp (method, "tcp") == 0;
1427   isNonceTcp = strcmp (method, "nonce-tcp") == 0;
1428
1429   if (isTcp || isNonceTcp)
1430     {
1431       const char *host = dbus_address_entry_get_value (entry, "host");
1432       const char *port = dbus_address_entry_get_value (entry, "port");
1433       const char *family = dbus_address_entry_get_value (entry, "family");
1434       const char *noncefile = dbus_address_entry_get_value (entry, "noncefile");
1435
1436       if ((isNonceTcp == TRUE) != (noncefile != NULL)) {
1437           _dbus_set_bad_address (error, method, "noncefile", NULL);
1438           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
1439       }
1440
1441       if (port == NULL)
1442         {
1443           _dbus_set_bad_address (error, method, "port", NULL);
1444           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
1445         }
1446
1447       *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, noncefile, error);
1448       if (*transport_p == NULL)
1449         {
1450           _DBUS_ASSERT_ERROR_IS_SET (error);
1451           return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
1452         }
1453       else
1454         {
1455           _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1456           return DBUS_TRANSPORT_OPEN_OK;
1457         }
1458     }
1459   else
1460     {
1461       _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1462       return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
1463     }
1464 }
1465
1466 /** @} */
1467