| 159 | /** |
| 160 | * Opens launchd transport types. |
| 161 | * |
| 162 | * @param entry the address entry to try opening |
| 163 | * @param transport_p return location for the opened transport |
| 164 | * @param error error to be set |
| 165 | * @returns result of the attempt |
| 166 | */ |
| 167 | DBusTransportOpenResult |
| 168 | _dbus_transport_open_launchd (DBusAddressEntry *entry, |
| 169 | DBusTransport **transport_p, |
| 170 | DBusError *error) |
| 171 | { |
| 172 | const char *method, *path; |
| 173 | |
| 174 | method = dbus_address_entry_get_method (entry); |
| 175 | _dbus_assert (method != NULL); |
| 176 | |
| 177 | if (strcmp (method, "launchd") == 0) |
| 178 | { |
| 179 | const char *socket_key = dbus_address_entry_get_value (entry, "key"); |
| 180 | DBusString address, prefix; |
| 181 | dbus_bool_t supported, retval; |
| 182 | int prefixlen; |
| 183 | |
| 184 | _dbus_verbose ("Opening launchd transport\n"); |
| 185 | |
| 186 | if (socket_key == NULL) |
| 187 | { |
| 188 | _dbus_set_bad_address (error, "launchd", "key", NULL); |
| 189 | return DBUS_TRANSPORT_OPEN_BAD_ADDRESS; |
| 190 | } |
| 191 | |
| 192 | if (strcmp (socket_key, "session") != 0) |
| 193 | { |
| 194 | _dbus_set_bad_address (error, NULL, NULL, |
| 195 | "launchd key must be 'session'\n"); |
| 196 | return DBUS_TRANSPORT_OPEN_BAD_ADDRESS; |
| 197 | } |
| 198 | |
| 199 | if (!_dbus_string_init (&address)) |
| 200 | { |
| 201 | dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); |
| 202 | return DBUS_TRANSPORT_OPEN_BAD_ADDRESS; |
| 203 | } |
| 204 | |
| 205 | supported = FALSE; |
| 206 | retval = _dbus_lookup_session_address (&supported, &address, error); |
| 207 | _dbus_string_init_const (&prefix, "unix:path="); |
| 208 | prefixlen = _dbus_string_get_length(&prefix); |
| 209 | if ( !(supported && retval) || |
| 210 | !_dbus_string_equal_substring (&address, 0, prefixlen, &prefix, 0)) |
| 211 | { |
| 212 | if (!dbus_error_is_set(error)) |
| 213 | { |
| 214 | dbus_set_error(error, DBUS_ERROR_FAILED, |
| 215 | "Unable to get session socket address\n"); |
| 216 | } |
| 217 | goto l_failed_1; |
| 218 | } |
| 219 | path = _dbus_string_get_const_data_len ( &address, prefixlen, |
| 220 | _dbus_string_get_length( &address) - prefixlen ); |
| 221 | *transport_p = _dbus_transport_new_for_domain_socket ( path, FALSE, error ); |
| 222 | |
| 223 | if (*transport_p == NULL) |
| 224 | { |
| 225 | _DBUS_ASSERT_ERROR_IS_SET (error); |
| 226 | goto l_failed_1; |
| 227 | } |
| 228 | |
| 229 | _dbus_verbose ("Opened launchd socket at %s\n", path); |
| 230 | |
| 231 | _dbus_string_free (&address); |
| 232 | _dbus_string_free (&prefix); |
| 233 | |
| 234 | _DBUS_ASSERT_ERROR_IS_CLEAR (error); |
| 235 | return DBUS_TRANSPORT_OPEN_OK; |
| 236 | |
| 237 | |
| 238 | l_failed_1: |
| 239 | _dbus_string_free (&prefix); |
| 240 | |
| 241 | l_failed_0: |
| 242 | _dbus_string_free (&address); |
| 243 | |
| 244 | return DBUS_TRANSPORT_OPEN_BAD_ADDRESS; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | _DBUS_ASSERT_ERROR_IS_CLEAR (error); |
| 249 | return DBUS_TRANSPORT_OPEN_NOT_HANDLED; |
| 250 | } |
| 251 | } |
| 252 | |