00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "dbus-internals.h"
00025 #include "dbus-connection-internal.h"
00026 #include "dbus-transport-unix.h"
00027 #include "dbus-transport-socket.h"
00028 #include "dbus-transport-protected.h"
00029 #include "dbus-watch.h"
00030 #include "dbus-sysdeps-unix.h"
00031
00052 DBusTransport*
00053 _dbus_transport_new_for_domain_socket (const char *path,
00054 dbus_bool_t abstract,
00055 DBusError *error)
00056 {
00057 int fd;
00058 DBusTransport *transport;
00059 DBusString address;
00060
00061 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00062
00063 if (!_dbus_string_init (&address))
00064 {
00065 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00066 return NULL;
00067 }
00068
00069 fd = -1;
00070
00071 if ((abstract &&
00072 !_dbus_string_append (&address, "unix:abstract=")) ||
00073 (!abstract &&
00074 !_dbus_string_append (&address, "unix:path=")) ||
00075 !_dbus_string_append (&address, path))
00076 {
00077 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00078 goto failed_0;
00079 }
00080
00081 fd = _dbus_connect_unix_socket (path, abstract, error);
00082 if (fd < 0)
00083 {
00084 _DBUS_ASSERT_ERROR_IS_SET (error);
00085 goto failed_0;
00086 }
00087
00088 _dbus_fd_set_close_on_exec (fd);
00089
00090 _dbus_verbose ("Successfully connected to unix socket %s\n",
00091 path);
00092
00093 transport = _dbus_transport_new_for_socket (fd, NULL, &address);
00094 if (transport == NULL)
00095 {
00096 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00097 goto failed_1;
00098 }
00099
00100 _dbus_string_free (&address);
00101
00102 return transport;
00103
00104 failed_1:
00105 _dbus_close_socket (fd, NULL);
00106 failed_0:
00107 _dbus_string_free (&address);
00108 return NULL;
00109 }
00110
00119 DBusTransportOpenResult
00120 _dbus_transport_open_platform_specific (DBusAddressEntry *entry,
00121 DBusTransport **transport_p,
00122 DBusError *error)
00123 {
00124 const char *method;
00125
00126 method = dbus_address_entry_get_method (entry);
00127 _dbus_assert (method != NULL);
00128
00129 if (strcmp (method, "unix") == 0)
00130 {
00131 const char *path = dbus_address_entry_get_value (entry, "path");
00132 const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
00133 const char *abstract = dbus_address_entry_get_value (entry, "abstract");
00134
00135 if (tmpdir != NULL)
00136 {
00137 _dbus_set_bad_address (error, NULL, NULL,
00138 "cannot use the \"tmpdir\" option for an address to connect to, only in an address to listen on");
00139 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00140 }
00141
00142 if (path == NULL && abstract == NULL)
00143 {
00144 _dbus_set_bad_address (error, "unix",
00145 "path or abstract",
00146 NULL);
00147 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00148 }
00149
00150 if (path != NULL && abstract != NULL)
00151 {
00152 _dbus_set_bad_address (error, NULL, NULL,
00153 "can't specify both \"path\" and \"abstract\" options in an address");
00154 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
00155 }
00156
00157 if (path)
00158 *transport_p = _dbus_transport_new_for_domain_socket (path, FALSE,
00159 error);
00160 else
00161 *transport_p = _dbus_transport_new_for_domain_socket (abstract, TRUE,
00162 error);
00163 if (*transport_p == NULL)
00164 {
00165 _DBUS_ASSERT_ERROR_IS_SET (error);
00166 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
00167 }
00168 else
00169 {
00170 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00171 return DBUS_TRANSPORT_OPEN_OK;
00172 }
00173 }
00174 else
00175 {
00176 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00177 return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
00178 }
00179 }
00180