• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List

dbus-transport-unix.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-transport-unix.c UNIX socket subclasses of DBusTransport
00003  *
00004  * Copyright (C) 2002, 2003, 2004  Red Hat Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 #include <config.h>
00025 #include "dbus-internals.h"
00026 #include "dbus-connection-internal.h"
00027 #include "dbus-transport-unix.h"
00028 #include "dbus-transport-socket.h"
00029 #include "dbus-transport-protected.h"
00030 #include "dbus-watch.h"
00031 #include "dbus-sysdeps-unix.h"
00032 
00053 DBusTransport*
00054 _dbus_transport_new_for_domain_socket (const char     *path,
00055                                        dbus_bool_t     abstract,
00056                                        DBusError      *error)
00057 {
00058   int fd;
00059   DBusTransport *transport;
00060   DBusString address;
00061   
00062   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00063 
00064   if (!_dbus_string_init (&address))
00065     {
00066       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00067       return NULL;
00068     }
00069 
00070   fd = -1;
00071 
00072   if ((abstract &&
00073        !_dbus_string_append (&address, "unix:abstract=")) ||
00074       (!abstract &&
00075        !_dbus_string_append (&address, "unix:path=")) ||
00076       !_dbus_string_append (&address, path))
00077     {
00078       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00079       goto failed_0;
00080     }
00081   
00082   fd = _dbus_connect_unix_socket (path, abstract, error);
00083   if (fd < 0)
00084     {
00085       _DBUS_ASSERT_ERROR_IS_SET (error);
00086       goto failed_0;
00087     }
00088 
00089   _dbus_verbose ("Successfully connected to unix socket %s\n",
00090                  path);
00091 
00092   transport = _dbus_transport_new_for_socket (fd, NULL, &address);
00093   if (transport == NULL)
00094     {
00095       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00096       goto failed_1;
00097     }
00098   
00099   _dbus_string_free (&address);
00100   
00101   return transport;
00102 
00103  failed_1:
00104   _dbus_close_socket (fd, NULL);
00105  failed_0:
00106   _dbus_string_free (&address);
00107   return NULL;
00108 }
00109 
00118 DBusTransportOpenResult
00119 _dbus_transport_open_platform_specific (DBusAddressEntry  *entry,
00120                                         DBusTransport    **transport_p,
00121                                         DBusError         *error)
00122 {
00123   const char *method;
00124   
00125   method = dbus_address_entry_get_method (entry);
00126   _dbus_assert (method != NULL);
00127 
00128   if (strcmp (method, "unix") == 0)
00129     {
00130       const char *path = dbus_address_entry_get_value (entry, "path");
00131       const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
00132       const char *abstract = dbus_address_entry_get_value (entry, "abstract");
00133           
00134       if (tmpdir != NULL)
00135         {
00136           _dbus_set_bad_address (error, NULL, NULL,
00137                                  "cannot use the \"tmpdir\" option for an address to connect to, only in an address to listen on");
00138           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00139         }
00140           
00141       if (path == NULL && abstract == NULL)
00142         {
00143           _dbus_set_bad_address (error, "unix",
00144                                  "path or abstract",
00145                                  NULL);
00146           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00147         }
00148 
00149       if (path != NULL && abstract != NULL)
00150         {
00151           _dbus_set_bad_address (error, NULL, NULL,
00152                                  "can't specify both \"path\" and \"abstract\" options in an address");
00153           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00154         }
00155 
00156       if (path)
00157         *transport_p = _dbus_transport_new_for_domain_socket (path, FALSE,
00158                                                            error);
00159       else
00160         *transport_p = _dbus_transport_new_for_domain_socket (abstract, TRUE,
00161                                                            error);
00162       if (*transport_p == NULL)
00163         {
00164           _DBUS_ASSERT_ERROR_IS_SET (error);
00165           return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
00166         }
00167       else
00168         {
00169           _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00170           return DBUS_TRANSPORT_OPEN_OK;
00171         }      
00172     }
00173   else
00174     {
00175       _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00176       return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
00177     }
00178 }
00179 

Generated on Tue Dec 21 2010 for D-Bus by  doxygen 1.7.1