00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <config.h>
00026 #include "dbus-bus.h"
00027 #include "dbus-protocol.h"
00028 #include "dbus-internals.h"
00029 #include "dbus-message.h"
00030 #include "dbus-marshal-validate.h"
00031 #include "dbus-misc.h"
00032 #include "dbus-threads-internal.h"
00033 #include "dbus-connection-internal.h"
00034 #include "dbus-string.h"
00035
00077 typedef struct
00078 {
00079 DBusConnection *connection;
00080 char *unique_name;
00082 unsigned int is_well_known : 1;
00083 } BusData;
00084
00087 static dbus_int32_t bus_data_slot = -1;
00088
00090 #define N_BUS_TYPES 3
00091
00092 static DBusConnection *bus_connections[N_BUS_TYPES];
00093 static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
00094
00095 static DBusBusType activation_bus_type = DBUS_BUS_STARTER;
00096
00097 static dbus_bool_t initialized = FALSE;
00098
00102 _DBUS_DEFINE_GLOBAL_LOCK (bus);
00103
00110 _DBUS_DEFINE_GLOBAL_LOCK (bus_datas);
00111
00112 static void
00113 addresses_shutdown_func (void *data)
00114 {
00115 int i;
00116
00117 i = 0;
00118 while (i < N_BUS_TYPES)
00119 {
00120 if (bus_connections[i] != NULL)
00121 _dbus_warn_check_failed ("dbus_shutdown() called but connections were still live. This probably means the application did not drop all its references to bus connections.\n");
00122
00123 dbus_free (bus_connection_addresses[i]);
00124 bus_connection_addresses[i] = NULL;
00125 ++i;
00126 }
00127
00128 activation_bus_type = DBUS_BUS_STARTER;
00129
00130 initialized = FALSE;
00131 }
00132
00133 static dbus_bool_t
00134 get_from_env (char **connection_p,
00135 const char *env_var)
00136 {
00137 const char *s;
00138
00139 _dbus_assert (*connection_p == NULL);
00140
00141 s = _dbus_getenv (env_var);
00142 if (s == NULL || *s == '\0')
00143 return TRUE;
00144 else
00145 {
00146 *connection_p = _dbus_strdup (s);
00147 return *connection_p != NULL;
00148 }
00149 }
00150
00151 static dbus_bool_t
00152 init_session_address (void)
00153 {
00154 dbus_bool_t retval;
00155
00156 retval = FALSE;
00157
00158
00159
00160 get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION],
00161 "DBUS_SESSION_BUS_ADDRESS");
00162 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00163 {
00164 dbus_bool_t supported;
00165 DBusString addr;
00166 DBusError error = DBUS_ERROR_INIT;
00167
00168 if (!_dbus_string_init (&addr))
00169 return FALSE;
00170
00171 supported = FALSE;
00172
00173
00174
00175
00176 retval = _dbus_lookup_session_address (&supported, &addr, &error);
00177 if (supported && retval)
00178 {
00179 retval =_dbus_string_steal_data (&addr, &bus_connection_addresses[DBUS_BUS_SESSION]);
00180 }
00181 else if (supported && !retval)
00182 {
00183 if (dbus_error_is_set(&error))
00184 _dbus_warn ("Dynamic session lookup supported but failed: %s\n", error.message);
00185 else
00186 _dbus_warn ("Dynamic session lookup supported but failed silently\n");
00187 }
00188 _dbus_string_free (&addr);
00189 }
00190 else
00191 retval = TRUE;
00192
00193 if (!retval)
00194 return FALSE;
00195
00196
00197
00198
00199 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00200 bus_connection_addresses[DBUS_BUS_SESSION] =
00201 _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
00202 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00203 return FALSE;
00204
00205 return TRUE;
00206 }
00207
00208 static dbus_bool_t
00209 init_connections_unlocked (void)
00210 {
00211 if (!initialized)
00212 {
00213 const char *s;
00214 int i;
00215
00216 i = 0;
00217 while (i < N_BUS_TYPES)
00218 {
00219 bus_connections[i] = NULL;
00220 ++i;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00231 {
00232 _dbus_verbose ("Filling in system bus address...\n");
00233
00234 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM],
00235 "DBUS_SYSTEM_BUS_ADDRESS"))
00236 return FALSE;
00237 }
00238
00239
00240 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00241 {
00242
00243 bus_connection_addresses[DBUS_BUS_SYSTEM] =
00244 _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
00245
00246 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00247 return FALSE;
00248
00249 _dbus_verbose (" used default system bus \"%s\"\n",
00250 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00251 }
00252 else
00253 _dbus_verbose (" used env var system bus \"%s\"\n",
00254 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00255
00256 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00257 {
00258 _dbus_verbose ("Filling in session bus address...\n");
00259
00260 if (!init_session_address ())
00261 return FALSE;
00262
00263 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ?
00264 bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
00265 }
00266
00267 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00268 {
00269 _dbus_verbose ("Filling in activation bus address...\n");
00270
00271 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER],
00272 "DBUS_STARTER_ADDRESS"))
00273 return FALSE;
00274
00275 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
00276 bus_connection_addresses[DBUS_BUS_STARTER] : "none set");
00277 }
00278
00279
00280 if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL)
00281 {
00282 s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE");
00283
00284 if (s != NULL)
00285 {
00286 _dbus_verbose ("Bus activation type was set to \"%s\"\n", s);
00287
00288 if (strcmp (s, "system") == 0)
00289 activation_bus_type = DBUS_BUS_SYSTEM;
00290 else if (strcmp (s, "session") == 0)
00291 activation_bus_type = DBUS_BUS_SESSION;
00292 }
00293 }
00294 else
00295 {
00296
00297 if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
00298 {
00299 bus_connection_addresses[DBUS_BUS_STARTER] =
00300 _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
00301 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00302 return FALSE;
00303 }
00304 }
00305
00306
00307
00308
00309
00310 if (!dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
00311 return FALSE;
00312
00313 if (!dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
00314 return FALSE;
00315
00316 if (!_dbus_register_shutdown_func (addresses_shutdown_func,
00317 NULL))
00318 return FALSE;
00319
00320 initialized = TRUE;
00321 }
00322
00323 return initialized;
00324 }
00325
00326 static void
00327 bus_data_free (void *data)
00328 {
00329 BusData *bd = data;
00330
00331 if (bd->is_well_known)
00332 {
00333 int i;
00334 _DBUS_LOCK (bus);
00335
00336
00337
00338
00339
00340 i = 0;
00341 while (i < N_BUS_TYPES)
00342 {
00343 if (bus_connections[i] == bd->connection)
00344 bus_connections[i] = NULL;
00345
00346 ++i;
00347 }
00348 _DBUS_UNLOCK (bus);
00349 }
00350
00351 dbus_free (bd->unique_name);
00352 dbus_free (bd);
00353
00354 dbus_connection_free_data_slot (&bus_data_slot);
00355 }
00356
00357 static BusData*
00358 ensure_bus_data (DBusConnection *connection)
00359 {
00360 BusData *bd;
00361
00362 if (!dbus_connection_allocate_data_slot (&bus_data_slot))
00363 return NULL;
00364
00365 bd = dbus_connection_get_data (connection, bus_data_slot);
00366 if (bd == NULL)
00367 {
00368 bd = dbus_new0 (BusData, 1);
00369 if (bd == NULL)
00370 {
00371 dbus_connection_free_data_slot (&bus_data_slot);
00372 return NULL;
00373 }
00374
00375 bd->connection = connection;
00376
00377 if (!dbus_connection_set_data (connection, bus_data_slot, bd,
00378 bus_data_free))
00379 {
00380 dbus_free (bd);
00381 dbus_connection_free_data_slot (&bus_data_slot);
00382 return NULL;
00383 }
00384
00385
00386 }
00387 else
00388 {
00389 dbus_connection_free_data_slot (&bus_data_slot);
00390 }
00391
00392 return bd;
00393 }
00394
00401 void
00402 _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection)
00403 {
00404 int i;
00405
00406 _DBUS_LOCK (bus);
00407
00408
00409
00410
00411
00412
00413
00414 for (i = 0; i < N_BUS_TYPES; ++i)
00415 {
00416 if (bus_connections[i] == connection)
00417 {
00418 bus_connections[i] = NULL;
00419 }
00420 }
00421
00422 _DBUS_UNLOCK (bus);
00423 }
00424
00425 static DBusConnection *
00426 internal_bus_get (DBusBusType type,
00427 dbus_bool_t private,
00428 DBusError *error)
00429 {
00430 const char *address;
00431 DBusConnection *connection;
00432 BusData *bd;
00433 DBusBusType address_type;
00434
00435 _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL);
00436 _dbus_return_val_if_error_is_set (error, NULL);
00437
00438 _DBUS_LOCK (bus);
00439
00440 if (!init_connections_unlocked ())
00441 {
00442 _DBUS_UNLOCK (bus);
00443 _DBUS_SET_OOM (error);
00444 return NULL;
00445 }
00446
00447
00448
00449
00450
00451 address_type = type;
00452
00453
00454
00455
00456
00457
00458 if (type == DBUS_BUS_STARTER &&
00459 bus_connection_addresses[activation_bus_type] != NULL)
00460 type = activation_bus_type;
00461
00462 if (!private && bus_connections[type] != NULL)
00463 {
00464 connection = bus_connections[type];
00465 dbus_connection_ref (connection);
00466
00467 _DBUS_UNLOCK (bus);
00468 return connection;
00469 }
00470
00471 address = bus_connection_addresses[address_type];
00472 if (address == NULL)
00473 {
00474 dbus_set_error (error, DBUS_ERROR_FAILED,
00475 "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
00476 _DBUS_UNLOCK (bus);
00477 return NULL;
00478 }
00479
00480 if (private)
00481 connection = dbus_connection_open_private (address, error);
00482 else
00483 connection = dbus_connection_open (address, error);
00484
00485 if (!connection)
00486 {
00487 _DBUS_ASSERT_ERROR_IS_SET (error);
00488 _DBUS_UNLOCK (bus);
00489 return NULL;
00490 }
00491
00492 if (!dbus_bus_register (connection, error))
00493 {
00494 _DBUS_ASSERT_ERROR_IS_SET (error);
00495 _dbus_connection_close_possibly_shared (connection);
00496 dbus_connection_unref (connection);
00497
00498 _DBUS_UNLOCK (bus);
00499 return NULL;
00500 }
00501
00502 if (!private)
00503 {
00504
00505
00506
00507
00508 bus_connections[type] = connection;
00509 }
00510
00511
00512
00513
00514 dbus_connection_set_exit_on_disconnect (connection,
00515 TRUE);
00516
00517 _DBUS_LOCK (bus_datas);
00518 bd = ensure_bus_data (connection);
00519 _dbus_assert (bd != NULL);
00520
00521 bd->is_well_known = TRUE;
00522 _DBUS_UNLOCK (bus_datas);
00523
00524
00525 _DBUS_UNLOCK (bus);
00526
00527
00528 return connection;
00529 }
00530
00531
00533
00564 DBusConnection *
00565 dbus_bus_get (DBusBusType type,
00566 DBusError *error)
00567 {
00568 return internal_bus_get (type, FALSE, error);
00569 }
00570
00596 DBusConnection *
00597 dbus_bus_get_private (DBusBusType type,
00598 DBusError *error)
00599 {
00600 return internal_bus_get (type, TRUE, error);
00601 }
00602
00652 dbus_bool_t
00653 dbus_bus_register (DBusConnection *connection,
00654 DBusError *error)
00655 {
00656 DBusMessage *message, *reply;
00657 char *name;
00658 BusData *bd;
00659 dbus_bool_t retval;
00660
00661 _dbus_return_val_if_fail (connection != NULL, FALSE);
00662 _dbus_return_val_if_error_is_set (error, FALSE);
00663
00664 retval = FALSE;
00665
00666 _DBUS_LOCK (bus_datas);
00667
00668 bd = ensure_bus_data (connection);
00669 if (bd == NULL)
00670 {
00671 _DBUS_SET_OOM (error);
00672 _DBUS_UNLOCK (bus_datas);
00673 return FALSE;
00674 }
00675
00676 if (bd->unique_name != NULL)
00677 {
00678 _dbus_verbose ("Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
00679 bd->unique_name);
00680 _DBUS_UNLOCK (bus_datas);
00681
00682
00683 return TRUE;
00684 }
00685
00686 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00687 DBUS_PATH_DBUS,
00688 DBUS_INTERFACE_DBUS,
00689 "Hello");
00690
00691 if (!message)
00692 {
00693 _DBUS_SET_OOM (error);
00694
00695 _DBUS_UNLOCK (bus_datas);
00696 return FALSE;
00697 }
00698
00699 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
00700
00701 dbus_message_unref (message);
00702
00703 if (reply == NULL)
00704 goto out;
00705 else if (dbus_set_error_from_message (error, reply))
00706 goto out;
00707 else if (!dbus_message_get_args (reply, error,
00708 DBUS_TYPE_STRING, &name,
00709 DBUS_TYPE_INVALID))
00710 goto out;
00711
00712 bd->unique_name = _dbus_strdup (name);
00713 if (bd->unique_name == NULL)
00714 {
00715 _DBUS_SET_OOM (error);
00716 goto out;
00717 }
00718
00719 retval = TRUE;
00720
00721 out:
00722 if (reply)
00723 dbus_message_unref (reply);
00724
00725 if (!retval)
00726 _DBUS_ASSERT_ERROR_IS_SET (error);
00727
00728 _DBUS_UNLOCK (bus_datas);
00729
00730 return retval;
00731 }
00732
00733
00768 dbus_bool_t
00769 dbus_bus_set_unique_name (DBusConnection *connection,
00770 const char *unique_name)
00771 {
00772 BusData *bd;
00773 dbus_bool_t success;
00774
00775 _dbus_return_val_if_fail (connection != NULL, FALSE);
00776 _dbus_return_val_if_fail (unique_name != NULL, FALSE);
00777
00778 _DBUS_LOCK (bus_datas);
00779
00780 bd = ensure_bus_data (connection);
00781 if (bd == NULL)
00782 return FALSE;
00783
00784 _dbus_assert (bd->unique_name == NULL);
00785
00786 bd->unique_name = _dbus_strdup (unique_name);
00787 success = bd->unique_name != NULL;
00788
00789 _DBUS_UNLOCK (bus_datas);
00790
00791 return success;
00792 }
00793
00812 const char*
00813 dbus_bus_get_unique_name (DBusConnection *connection)
00814 {
00815 BusData *bd;
00816 const char *unique_name;
00817
00818 _dbus_return_val_if_fail (connection != NULL, NULL);
00819
00820 _DBUS_LOCK (bus_datas);
00821
00822 bd = ensure_bus_data (connection);
00823 if (bd == NULL)
00824 return NULL;
00825
00826 unique_name = bd->unique_name;
00827
00828 _DBUS_UNLOCK (bus_datas);
00829
00830 return unique_name;
00831 }
00832
00856 unsigned long
00857 dbus_bus_get_unix_user (DBusConnection *connection,
00858 const char *name,
00859 DBusError *error)
00860 {
00861 DBusMessage *message, *reply;
00862 dbus_uint32_t uid;
00863
00864 _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET);
00865 _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET);
00866 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET);
00867 _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET);
00868
00869 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00870 DBUS_PATH_DBUS,
00871 DBUS_INTERFACE_DBUS,
00872 "GetConnectionUnixUser");
00873
00874 if (message == NULL)
00875 {
00876 _DBUS_SET_OOM (error);
00877 return DBUS_UID_UNSET;
00878 }
00879
00880 if (!dbus_message_append_args (message,
00881 DBUS_TYPE_STRING, &name,
00882 DBUS_TYPE_INVALID))
00883 {
00884 dbus_message_unref (message);
00885 _DBUS_SET_OOM (error);
00886 return DBUS_UID_UNSET;
00887 }
00888
00889 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00890 error);
00891
00892 dbus_message_unref (message);
00893
00894 if (reply == NULL)
00895 {
00896 _DBUS_ASSERT_ERROR_IS_SET (error);
00897 return DBUS_UID_UNSET;
00898 }
00899
00900 if (dbus_set_error_from_message (error, reply))
00901 {
00902 _DBUS_ASSERT_ERROR_IS_SET (error);
00903 dbus_message_unref (reply);
00904 return DBUS_UID_UNSET;
00905 }
00906
00907 if (!dbus_message_get_args (reply, error,
00908 DBUS_TYPE_UINT32, &uid,
00909 DBUS_TYPE_INVALID))
00910 {
00911 _DBUS_ASSERT_ERROR_IS_SET (error);
00912 dbus_message_unref (reply);
00913 return DBUS_UID_UNSET;
00914 }
00915
00916 dbus_message_unref (reply);
00917
00918 return (unsigned long) uid;
00919 }
00920
00939 char*
00940 dbus_bus_get_id (DBusConnection *connection,
00941 DBusError *error)
00942 {
00943 DBusMessage *message, *reply;
00944 char *id;
00945 const char *v_STRING;
00946
00947 _dbus_return_val_if_fail (connection != NULL, NULL);
00948 _dbus_return_val_if_error_is_set (error, NULL);
00949
00950 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00951 DBUS_PATH_DBUS,
00952 DBUS_INTERFACE_DBUS,
00953 "GetId");
00954
00955 if (message == NULL)
00956 {
00957 _DBUS_SET_OOM (error);
00958 return NULL;
00959 }
00960
00961 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00962 error);
00963
00964 dbus_message_unref (message);
00965
00966 if (reply == NULL)
00967 {
00968 _DBUS_ASSERT_ERROR_IS_SET (error);
00969 return NULL;
00970 }
00971
00972 if (dbus_set_error_from_message (error, reply))
00973 {
00974 _DBUS_ASSERT_ERROR_IS_SET (error);
00975 dbus_message_unref (reply);
00976 return NULL;
00977 }
00978
00979 v_STRING = NULL;
00980 if (!dbus_message_get_args (reply, error,
00981 DBUS_TYPE_STRING, &v_STRING,
00982 DBUS_TYPE_INVALID))
00983 {
00984 _DBUS_ASSERT_ERROR_IS_SET (error);
00985 dbus_message_unref (reply);
00986 return NULL;
00987 }
00988
00989 id = _dbus_strdup (v_STRING);
00990
00991 dbus_message_unref (reply);
00992
00993 if (id == NULL)
00994 _DBUS_SET_OOM (error);
00995
00996
00997
00998 return id;
00999 }
01000
01103 int
01104 dbus_bus_request_name (DBusConnection *connection,
01105 const char *name,
01106 unsigned int flags,
01107 DBusError *error)
01108 {
01109 DBusMessage *message, *reply;
01110 dbus_uint32_t result;
01111
01112 _dbus_return_val_if_fail (connection != NULL, 0);
01113 _dbus_return_val_if_fail (name != NULL, 0);
01114 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01115 _dbus_return_val_if_error_is_set (error, 0);
01116
01117 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01118 DBUS_PATH_DBUS,
01119 DBUS_INTERFACE_DBUS,
01120 "RequestName");
01121
01122 if (message == NULL)
01123 {
01124 _DBUS_SET_OOM (error);
01125 return -1;
01126 }
01127
01128 if (!dbus_message_append_args (message,
01129 DBUS_TYPE_STRING, &name,
01130 DBUS_TYPE_UINT32, &flags,
01131 DBUS_TYPE_INVALID))
01132 {
01133 dbus_message_unref (message);
01134 _DBUS_SET_OOM (error);
01135 return -1;
01136 }
01137
01138 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01139 error);
01140
01141 dbus_message_unref (message);
01142
01143 if (reply == NULL)
01144 {
01145 _DBUS_ASSERT_ERROR_IS_SET (error);
01146 return -1;
01147 }
01148
01149 if (dbus_set_error_from_message (error, reply))
01150 {
01151 _DBUS_ASSERT_ERROR_IS_SET (error);
01152 dbus_message_unref (reply);
01153 return -1;
01154 }
01155
01156 if (!dbus_message_get_args (reply, error,
01157 DBUS_TYPE_UINT32, &result,
01158 DBUS_TYPE_INVALID))
01159 {
01160 _DBUS_ASSERT_ERROR_IS_SET (error);
01161 dbus_message_unref (reply);
01162 return -1;
01163 }
01164
01165 dbus_message_unref (reply);
01166
01167 return result;
01168 }
01169
01170
01189 int
01190 dbus_bus_release_name (DBusConnection *connection,
01191 const char *name,
01192 DBusError *error)
01193 {
01194 DBusMessage *message, *reply;
01195 dbus_uint32_t result;
01196
01197 _dbus_return_val_if_fail (connection != NULL, 0);
01198 _dbus_return_val_if_fail (name != NULL, 0);
01199 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01200 _dbus_return_val_if_error_is_set (error, 0);
01201
01202 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01203 DBUS_PATH_DBUS,
01204 DBUS_INTERFACE_DBUS,
01205 "ReleaseName");
01206
01207 if (message == NULL)
01208 {
01209 _DBUS_SET_OOM (error);
01210 return -1;
01211 }
01212
01213 if (!dbus_message_append_args (message,
01214 DBUS_TYPE_STRING, &name,
01215 DBUS_TYPE_INVALID))
01216 {
01217 dbus_message_unref (message);
01218 _DBUS_SET_OOM (error);
01219 return -1;
01220 }
01221
01222 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01223 error);
01224
01225 dbus_message_unref (message);
01226
01227 if (reply == NULL)
01228 {
01229 _DBUS_ASSERT_ERROR_IS_SET (error);
01230 return -1;
01231 }
01232
01233 if (dbus_set_error_from_message (error, reply))
01234 {
01235 _DBUS_ASSERT_ERROR_IS_SET (error);
01236 dbus_message_unref (reply);
01237 return -1;
01238 }
01239
01240 if (!dbus_message_get_args (reply, error,
01241 DBUS_TYPE_UINT32, &result,
01242 DBUS_TYPE_INVALID))
01243 {
01244 _DBUS_ASSERT_ERROR_IS_SET (error);
01245 dbus_message_unref (reply);
01246 return -1;
01247 }
01248
01249 dbus_message_unref (reply);
01250
01251 return result;
01252 }
01253
01271 dbus_bool_t
01272 dbus_bus_name_has_owner (DBusConnection *connection,
01273 const char *name,
01274 DBusError *error)
01275 {
01276 DBusMessage *message, *reply;
01277 dbus_bool_t exists;
01278
01279 _dbus_return_val_if_fail (connection != NULL, FALSE);
01280 _dbus_return_val_if_fail (name != NULL, FALSE);
01281 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01282 _dbus_return_val_if_error_is_set (error, FALSE);
01283
01284 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01285 DBUS_PATH_DBUS,
01286 DBUS_INTERFACE_DBUS,
01287 "NameHasOwner");
01288 if (message == NULL)
01289 {
01290 _DBUS_SET_OOM (error);
01291 return FALSE;
01292 }
01293
01294 if (!dbus_message_append_args (message,
01295 DBUS_TYPE_STRING, &name,
01296 DBUS_TYPE_INVALID))
01297 {
01298 dbus_message_unref (message);
01299 _DBUS_SET_OOM (error);
01300 return FALSE;
01301 }
01302
01303 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
01304 dbus_message_unref (message);
01305
01306 if (reply == NULL)
01307 {
01308 _DBUS_ASSERT_ERROR_IS_SET (error);
01309 return FALSE;
01310 }
01311
01312 if (!dbus_message_get_args (reply, error,
01313 DBUS_TYPE_BOOLEAN, &exists,
01314 DBUS_TYPE_INVALID))
01315 {
01316 _DBUS_ASSERT_ERROR_IS_SET (error);
01317 dbus_message_unref (reply);
01318 return FALSE;
01319 }
01320
01321 dbus_message_unref (reply);
01322 return exists;
01323 }
01324
01347 dbus_bool_t
01348 dbus_bus_start_service_by_name (DBusConnection *connection,
01349 const char *name,
01350 dbus_uint32_t flags,
01351 dbus_uint32_t *result,
01352 DBusError *error)
01353 {
01354 DBusMessage *msg;
01355 DBusMessage *reply;
01356
01357 _dbus_return_val_if_fail (connection != NULL, FALSE);
01358 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01359
01360 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01361 DBUS_PATH_DBUS,
01362 DBUS_INTERFACE_DBUS,
01363 "StartServiceByName");
01364
01365 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name,
01366 DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
01367 {
01368 dbus_message_unref (msg);
01369 _DBUS_SET_OOM (error);
01370 return FALSE;
01371 }
01372
01373 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01374 -1, error);
01375 dbus_message_unref (msg);
01376
01377 if (reply == NULL)
01378 {
01379 _DBUS_ASSERT_ERROR_IS_SET (error);
01380 return FALSE;
01381 }
01382
01383 if (dbus_set_error_from_message (error, reply))
01384 {
01385 _DBUS_ASSERT_ERROR_IS_SET (error);
01386 dbus_message_unref (reply);
01387 return FALSE;
01388 }
01389
01390 if (result != NULL &&
01391 !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32,
01392 result, DBUS_TYPE_INVALID))
01393 {
01394 _DBUS_ASSERT_ERROR_IS_SET (error);
01395 dbus_message_unref (reply);
01396 return FALSE;
01397 }
01398
01399 dbus_message_unref (reply);
01400 return TRUE;
01401 }
01402
01403 static void
01404 send_no_return_values (DBusConnection *connection,
01405 DBusMessage *msg,
01406 DBusError *error)
01407 {
01408 if (error)
01409 {
01410
01411 DBusMessage *reply;
01412
01413 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01414 -1, error);
01415
01416 if (reply == NULL)
01417 _DBUS_ASSERT_ERROR_IS_SET (error);
01418 else
01419 dbus_message_unref (reply);
01420 }
01421 else
01422 {
01423
01424 dbus_message_set_no_reply (msg, TRUE);
01425 dbus_connection_send (connection, msg, NULL);
01426 }
01427 }
01428
01511 void
01512 dbus_bus_add_match (DBusConnection *connection,
01513 const char *rule,
01514 DBusError *error)
01515 {
01516 DBusMessage *msg;
01517
01518 _dbus_return_if_fail (rule != NULL);
01519
01520 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01521 DBUS_PATH_DBUS,
01522 DBUS_INTERFACE_DBUS,
01523 "AddMatch");
01524
01525 if (msg == NULL)
01526 {
01527 _DBUS_SET_OOM (error);
01528 return;
01529 }
01530
01531 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
01532 DBUS_TYPE_INVALID))
01533 {
01534 dbus_message_unref (msg);
01535 _DBUS_SET_OOM (error);
01536 return;
01537 }
01538
01539 send_no_return_values (connection, msg, error);
01540
01541 dbus_message_unref (msg);
01542 }
01543
01561 void
01562 dbus_bus_remove_match (DBusConnection *connection,
01563 const char *rule,
01564 DBusError *error)
01565 {
01566 DBusMessage *msg;
01567
01568 _dbus_return_if_fail (rule != NULL);
01569
01570 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01571 DBUS_PATH_DBUS,
01572 DBUS_INTERFACE_DBUS,
01573 "RemoveMatch");
01574
01575 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
01576 DBUS_TYPE_INVALID))
01577 {
01578 dbus_message_unref (msg);
01579 _DBUS_SET_OOM (error);
01580 return;
01581 }
01582
01583 send_no_return_values (connection, msg, error);
01584
01585 dbus_message_unref (msg);
01586 }
01587