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 "dbus-bus.h"
00026 #include "dbus-protocol.h"
00027 #include "dbus-internals.h"
00028 #include "dbus-message.h"
00029 #include "dbus-marshal-validate.h"
00030 #include "dbus-threads-internal.h"
00031 #include "dbus-connection-internal.h"
00032 #include <string.h>
00033
00075 typedef struct
00076 {
00077 DBusConnection *connection;
00078 char *unique_name;
00080 unsigned int is_well_known : 1;
00081 } BusData;
00082
00085 static dbus_int32_t bus_data_slot = -1;
00086
00088 #define N_BUS_TYPES 3
00089
00090 static DBusConnection *bus_connections[N_BUS_TYPES];
00091 static char *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
00092
00093 static DBusBusType activation_bus_type = DBUS_BUS_STARTER;
00094
00095 static dbus_bool_t initialized = FALSE;
00096
00100 _DBUS_DEFINE_GLOBAL_LOCK (bus);
00101
00108 _DBUS_DEFINE_GLOBAL_LOCK (bus_datas);
00109
00110 static void
00111 addresses_shutdown_func (void *data)
00112 {
00113 int i;
00114
00115 i = 0;
00116 while (i < N_BUS_TYPES)
00117 {
00118 if (bus_connections[i] != NULL)
00119 _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");
00120
00121 dbus_free (bus_connection_addresses[i]);
00122 bus_connection_addresses[i] = NULL;
00123 ++i;
00124 }
00125
00126 activation_bus_type = DBUS_BUS_STARTER;
00127
00128 initialized = FALSE;
00129 }
00130
00131 static dbus_bool_t
00132 get_from_env (char **connection_p,
00133 const char *env_var)
00134 {
00135 const char *s;
00136
00137 _dbus_assert (*connection_p == NULL);
00138
00139 s = _dbus_getenv (env_var);
00140 if (s == NULL || *s == '\0')
00141 return TRUE;
00142 else
00143 {
00144 *connection_p = _dbus_strdup (s);
00145 return *connection_p != NULL;
00146 }
00147 }
00148
00149 static dbus_bool_t
00150 init_connections_unlocked (void)
00151 {
00152 if (!initialized)
00153 {
00154 const char *s;
00155 int i;
00156
00157 i = 0;
00158 while (i < N_BUS_TYPES)
00159 {
00160 bus_connections[i] = NULL;
00161 ++i;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00172 {
00173 _dbus_verbose ("Filling in system bus address...\n");
00174
00175 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM],
00176 "DBUS_SYSTEM_BUS_ADDRESS"))
00177 return FALSE;
00178 }
00179
00180
00181 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00182 {
00183
00184 bus_connection_addresses[DBUS_BUS_SYSTEM] =
00185 _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
00186
00187 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00188 return FALSE;
00189
00190 _dbus_verbose (" used default system bus \"%s\"\n",
00191 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00192 }
00193 else
00194 _dbus_verbose (" used env var system bus \"%s\"\n",
00195 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00196
00197 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00198 {
00199 _dbus_verbose ("Filling in session bus address...\n");
00200
00201 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION],
00202 "DBUS_SESSION_BUS_ADDRESS"))
00203 return FALSE;
00204
00205 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00206 bus_connection_addresses[DBUS_BUS_SESSION] =
00207 _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
00208
00209 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00210 return FALSE;
00211
00212 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ?
00213 bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
00214 }
00215
00216 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00217 {
00218 _dbus_verbose ("Filling in activation bus address...\n");
00219
00220 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER],
00221 "DBUS_STARTER_ADDRESS"))
00222 return FALSE;
00223
00224 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
00225 bus_connection_addresses[DBUS_BUS_STARTER] : "none set");
00226 }
00227
00228
00229 if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL)
00230 {
00231 s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE");
00232
00233 if (s != NULL)
00234 {
00235 _dbus_verbose ("Bus activation type was set to \"%s\"\n", s);
00236
00237 if (strcmp (s, "system") == 0)
00238 activation_bus_type = DBUS_BUS_SYSTEM;
00239 else if (strcmp (s, "session") == 0)
00240 activation_bus_type = DBUS_BUS_SESSION;
00241 }
00242 }
00243 else
00244 {
00245
00246 if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
00247 {
00248 bus_connection_addresses[DBUS_BUS_STARTER] =
00249 _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
00250 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00251 return FALSE;
00252 }
00253 }
00254
00255
00256
00257
00258
00259 if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
00260 return FALSE;
00261
00262 if (!_dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
00263 return FALSE;
00264
00265 if (!_dbus_register_shutdown_func (addresses_shutdown_func,
00266 NULL))
00267 return FALSE;
00268
00269 initialized = TRUE;
00270 }
00271
00272 return initialized;
00273 }
00274
00275 static void
00276 bus_data_free (void *data)
00277 {
00278 BusData *bd = data;
00279
00280 if (bd->is_well_known)
00281 {
00282 int i;
00283 _DBUS_LOCK (bus);
00284
00285
00286
00287
00288
00289 i = 0;
00290 while (i < N_BUS_TYPES)
00291 {
00292 if (bus_connections[i] == bd->connection)
00293 bus_connections[i] = NULL;
00294
00295 ++i;
00296 }
00297 _DBUS_UNLOCK (bus);
00298 }
00299
00300 dbus_free (bd->unique_name);
00301 dbus_free (bd);
00302
00303 dbus_connection_free_data_slot (&bus_data_slot);
00304 }
00305
00306 static BusData*
00307 ensure_bus_data (DBusConnection *connection)
00308 {
00309 BusData *bd;
00310
00311 if (!dbus_connection_allocate_data_slot (&bus_data_slot))
00312 return NULL;
00313
00314 bd = dbus_connection_get_data (connection, bus_data_slot);
00315 if (bd == NULL)
00316 {
00317 bd = dbus_new0 (BusData, 1);
00318 if (bd == NULL)
00319 {
00320 dbus_connection_free_data_slot (&bus_data_slot);
00321 return NULL;
00322 }
00323
00324 bd->connection = connection;
00325
00326 if (!dbus_connection_set_data (connection, bus_data_slot, bd,
00327 bus_data_free))
00328 {
00329 dbus_free (bd);
00330 dbus_connection_free_data_slot (&bus_data_slot);
00331 return NULL;
00332 }
00333
00334
00335 }
00336 else
00337 {
00338 dbus_connection_free_data_slot (&bus_data_slot);
00339 }
00340
00341 return bd;
00342 }
00343
00350 void
00351 _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection)
00352 {
00353 int i;
00354
00355 _DBUS_LOCK (bus);
00356
00357
00358
00359
00360
00361
00362
00363 for (i = 0; i < N_BUS_TYPES; ++i)
00364 {
00365 if (bus_connections[i] == connection)
00366 {
00367 bus_connections[i] = NULL;
00368 }
00369 }
00370
00371 _DBUS_UNLOCK (bus);
00372 }
00373
00374 static DBusConnection *
00375 internal_bus_get (DBusBusType type,
00376 dbus_bool_t private,
00377 DBusError *error)
00378 {
00379 const char *address;
00380 DBusConnection *connection;
00381 BusData *bd;
00382 DBusBusType address_type;
00383 char *s = NULL;
00384
00385 _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL);
00386 _dbus_return_val_if_error_is_set (error, NULL);
00387
00388 s = _dbus_getenv("DBUS_SESSION_BUS_ADDRESS");
00389 if ( (type == DBUS_BUS_SESSION) &&
00390 (s == NULL || *s == '\0') ) {
00391 return NULL;
00392 }
00393
00394 _DBUS_LOCK (bus);
00395
00396 if (!init_connections_unlocked ())
00397 {
00398 _DBUS_UNLOCK (bus);
00399 _DBUS_SET_OOM (error);
00400 return NULL;
00401 }
00402
00403
00404
00405
00406
00407 address_type = type;
00408
00409
00410
00411
00412
00413
00414 if (type == DBUS_BUS_STARTER &&
00415 bus_connection_addresses[activation_bus_type] != NULL)
00416 type = activation_bus_type;
00417
00418 if (!private && bus_connections[type] != NULL)
00419 {
00420 connection = bus_connections[type];
00421 dbus_connection_ref (connection);
00422
00423 _DBUS_UNLOCK (bus);
00424 return connection;
00425 }
00426
00427 address = bus_connection_addresses[address_type];
00428 if (address == NULL)
00429 {
00430 dbus_set_error (error, DBUS_ERROR_FAILED,
00431 "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
00432 _DBUS_UNLOCK (bus);
00433 return NULL;
00434 }
00435
00436 if (private)
00437 connection = dbus_connection_open_private (address, error);
00438 else
00439 connection = dbus_connection_open (address, error);
00440
00441 if (!connection)
00442 {
00443 _DBUS_ASSERT_ERROR_IS_SET (error);
00444 _DBUS_UNLOCK (bus);
00445 return NULL;
00446 }
00447
00448 if (!dbus_bus_register (connection, error))
00449 {
00450 _DBUS_ASSERT_ERROR_IS_SET (error);
00451 _dbus_connection_close_possibly_shared (connection);
00452 dbus_connection_unref (connection);
00453
00454 _DBUS_UNLOCK (bus);
00455 return NULL;
00456 }
00457
00458 if (!private)
00459 {
00460
00461
00462
00463
00464 bus_connections[type] = connection;
00465 }
00466
00467
00468
00469
00470 dbus_connection_set_exit_on_disconnect (connection,
00471 TRUE);
00472
00473 _DBUS_LOCK (bus_datas);
00474 bd = ensure_bus_data (connection);
00475 _dbus_assert (bd != NULL);
00476
00477 bd->is_well_known = TRUE;
00478 _DBUS_UNLOCK (bus_datas);
00479
00480
00481 _DBUS_UNLOCK (bus);
00482
00483
00484 return connection;
00485 }
00486
00487
00489
00520 DBusConnection *
00521 dbus_bus_get (DBusBusType type,
00522 DBusError *error)
00523 {
00524 return internal_bus_get (type, FALSE, error);
00525 }
00526
00552 DBusConnection *
00553 dbus_bus_get_private (DBusBusType type,
00554 DBusError *error)
00555 {
00556 return internal_bus_get (type, TRUE, error);
00557 }
00558
00608 dbus_bool_t
00609 dbus_bus_register (DBusConnection *connection,
00610 DBusError *error)
00611 {
00612 DBusMessage *message, *reply;
00613 char *name;
00614 BusData *bd;
00615 dbus_bool_t retval;
00616
00617 _dbus_return_val_if_fail (connection != NULL, FALSE);
00618 _dbus_return_val_if_error_is_set (error, FALSE);
00619
00620 retval = FALSE;
00621
00622 _DBUS_LOCK (bus_datas);
00623
00624 bd = ensure_bus_data (connection);
00625 if (bd == NULL)
00626 {
00627 _DBUS_SET_OOM (error);
00628 _DBUS_UNLOCK (bus_datas);
00629 return FALSE;
00630 }
00631
00632 if (bd->unique_name != NULL)
00633 {
00634 _dbus_verbose ("Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
00635 bd->unique_name);
00636 _DBUS_UNLOCK (bus_datas);
00637
00638
00639 return TRUE;
00640 }
00641
00642 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00643 DBUS_PATH_DBUS,
00644 DBUS_INTERFACE_DBUS,
00645 "Hello");
00646
00647 if (!message)
00648 {
00649 _DBUS_SET_OOM (error);
00650
00651 _DBUS_UNLOCK (bus_datas);
00652 return FALSE;
00653 }
00654
00655 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
00656
00657 dbus_message_unref (message);
00658
00659 if (reply == NULL)
00660 goto out;
00661 else if (dbus_set_error_from_message (error, reply))
00662 goto out;
00663 else if (!dbus_message_get_args (reply, error,
00664 DBUS_TYPE_STRING, &name,
00665 DBUS_TYPE_INVALID))
00666 goto out;
00667
00668 bd->unique_name = _dbus_strdup (name);
00669 if (bd->unique_name == NULL)
00670 {
00671 _DBUS_SET_OOM (error);
00672 goto out;
00673 }
00674
00675 retval = TRUE;
00676
00677 out:
00678 if (reply)
00679 dbus_message_unref (reply);
00680
00681 if (!retval)
00682 _DBUS_ASSERT_ERROR_IS_SET (error);
00683
00684 _DBUS_UNLOCK (bus_datas);
00685
00686 return retval;
00687 }
00688
00689
00724 dbus_bool_t
00725 dbus_bus_set_unique_name (DBusConnection *connection,
00726 const char *unique_name)
00727 {
00728 BusData *bd;
00729 dbus_bool_t success;
00730
00731 _dbus_return_val_if_fail (connection != NULL, FALSE);
00732 _dbus_return_val_if_fail (unique_name != NULL, FALSE);
00733
00734 _DBUS_LOCK (bus_datas);
00735
00736 bd = ensure_bus_data (connection);
00737 if (bd == NULL)
00738 return FALSE;
00739
00740 _dbus_assert (bd->unique_name == NULL);
00741
00742 bd->unique_name = _dbus_strdup (unique_name);
00743 success = bd->unique_name != NULL;
00744
00745 _DBUS_UNLOCK (bus_datas);
00746
00747 return success;
00748 }
00749
00768 const char*
00769 dbus_bus_get_unique_name (DBusConnection *connection)
00770 {
00771 BusData *bd;
00772 const char *unique_name;
00773
00774 _dbus_return_val_if_fail (connection != NULL, NULL);
00775
00776 _DBUS_LOCK (bus_datas);
00777
00778 bd = ensure_bus_data (connection);
00779 if (bd == NULL)
00780 return NULL;
00781
00782 unique_name = bd->unique_name;
00783
00784 _DBUS_UNLOCK (bus_datas);
00785
00786 return unique_name;
00787 }
00788
00812 unsigned long
00813 dbus_bus_get_unix_user (DBusConnection *connection,
00814 const char *name,
00815 DBusError *error)
00816 {
00817 DBusMessage *message, *reply;
00818 dbus_uint32_t uid;
00819
00820 _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET);
00821 _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET);
00822 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET);
00823 _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET);
00824
00825 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00826 DBUS_PATH_DBUS,
00827 DBUS_INTERFACE_DBUS,
00828 "GetConnectionUnixUser");
00829
00830 if (message == NULL)
00831 {
00832 _DBUS_SET_OOM (error);
00833 return DBUS_UID_UNSET;
00834 }
00835
00836 if (!dbus_message_append_args (message,
00837 DBUS_TYPE_STRING, &name,
00838 DBUS_TYPE_INVALID))
00839 {
00840 dbus_message_unref (message);
00841 _DBUS_SET_OOM (error);
00842 return DBUS_UID_UNSET;
00843 }
00844
00845 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00846 error);
00847
00848 dbus_message_unref (message);
00849
00850 if (reply == NULL)
00851 {
00852 _DBUS_ASSERT_ERROR_IS_SET (error);
00853 return DBUS_UID_UNSET;
00854 }
00855
00856 if (dbus_set_error_from_message (error, reply))
00857 {
00858 _DBUS_ASSERT_ERROR_IS_SET (error);
00859 dbus_message_unref (reply);
00860 return DBUS_UID_UNSET;
00861 }
00862
00863 if (!dbus_message_get_args (reply, error,
00864 DBUS_TYPE_UINT32, &uid,
00865 DBUS_TYPE_INVALID))
00866 {
00867 _DBUS_ASSERT_ERROR_IS_SET (error);
00868 dbus_message_unref (reply);
00869 return DBUS_UID_UNSET;
00870 }
00871
00872 dbus_message_unref (reply);
00873
00874 return (unsigned long) uid;
00875 }
00876
00895 char*
00896 dbus_bus_get_id (DBusConnection *connection,
00897 DBusError *error)
00898 {
00899 DBusMessage *message, *reply;
00900 char *id;
00901 const char *v_STRING;
00902
00903 _dbus_return_val_if_fail (connection != NULL, NULL);
00904 _dbus_return_val_if_error_is_set (error, NULL);
00905
00906 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00907 DBUS_PATH_DBUS,
00908 DBUS_INTERFACE_DBUS,
00909 "GetId");
00910
00911 if (message == NULL)
00912 {
00913 _DBUS_SET_OOM (error);
00914 return NULL;
00915 }
00916
00917 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00918 error);
00919
00920 dbus_message_unref (message);
00921
00922 if (reply == NULL)
00923 {
00924 _DBUS_ASSERT_ERROR_IS_SET (error);
00925 return NULL;
00926 }
00927
00928 if (dbus_set_error_from_message (error, reply))
00929 {
00930 _DBUS_ASSERT_ERROR_IS_SET (error);
00931 dbus_message_unref (reply);
00932 return NULL;
00933 }
00934
00935 v_STRING = NULL;
00936 if (!dbus_message_get_args (reply, error,
00937 DBUS_TYPE_STRING, &v_STRING,
00938 DBUS_TYPE_INVALID))
00939 {
00940 _DBUS_ASSERT_ERROR_IS_SET (error);
00941 dbus_message_unref (reply);
00942 return NULL;
00943 }
00944
00945 id = _dbus_strdup (v_STRING);
00946
00947 dbus_message_unref (reply);
00948
00949 if (id == NULL)
00950 _DBUS_SET_OOM (error);
00951
00952
00953
00954 return id;
00955 }
00956
01059 int
01060 dbus_bus_request_name (DBusConnection *connection,
01061 const char *name,
01062 unsigned int flags,
01063 DBusError *error)
01064 {
01065 DBusMessage *message, *reply;
01066 dbus_uint32_t result;
01067
01068 _dbus_return_val_if_fail (connection != NULL, 0);
01069 _dbus_return_val_if_fail (name != NULL, 0);
01070 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01071 _dbus_return_val_if_error_is_set (error, 0);
01072
01073 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01074 DBUS_PATH_DBUS,
01075 DBUS_INTERFACE_DBUS,
01076 "RequestName");
01077
01078 if (message == NULL)
01079 {
01080 _DBUS_SET_OOM (error);
01081 return -1;
01082 }
01083
01084 if (!dbus_message_append_args (message,
01085 DBUS_TYPE_STRING, &name,
01086 DBUS_TYPE_UINT32, &flags,
01087 DBUS_TYPE_INVALID))
01088 {
01089 dbus_message_unref (message);
01090 _DBUS_SET_OOM (error);
01091 return -1;
01092 }
01093
01094 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01095 error);
01096
01097 dbus_message_unref (message);
01098
01099 if (reply == NULL)
01100 {
01101 _DBUS_ASSERT_ERROR_IS_SET (error);
01102 return -1;
01103 }
01104
01105 if (dbus_set_error_from_message (error, reply))
01106 {
01107 _DBUS_ASSERT_ERROR_IS_SET (error);
01108 dbus_message_unref (reply);
01109 return -1;
01110 }
01111
01112 if (!dbus_message_get_args (reply, error,
01113 DBUS_TYPE_UINT32, &result,
01114 DBUS_TYPE_INVALID))
01115 {
01116 _DBUS_ASSERT_ERROR_IS_SET (error);
01117 dbus_message_unref (reply);
01118 return -1;
01119 }
01120
01121 dbus_message_unref (reply);
01122
01123 return result;
01124 }
01125
01126
01145 int
01146 dbus_bus_release_name (DBusConnection *connection,
01147 const char *name,
01148 DBusError *error)
01149 {
01150 DBusMessage *message, *reply;
01151 dbus_uint32_t result;
01152
01153 _dbus_return_val_if_fail (connection != NULL, 0);
01154 _dbus_return_val_if_fail (name != NULL, 0);
01155 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01156 _dbus_return_val_if_error_is_set (error, 0);
01157
01158 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01159 DBUS_PATH_DBUS,
01160 DBUS_INTERFACE_DBUS,
01161 "ReleaseName");
01162
01163 if (message == NULL)
01164 {
01165 _DBUS_SET_OOM (error);
01166 return -1;
01167 }
01168
01169 if (!dbus_message_append_args (message,
01170 DBUS_TYPE_STRING, &name,
01171 DBUS_TYPE_INVALID))
01172 {
01173 dbus_message_unref (message);
01174 _DBUS_SET_OOM (error);
01175 return -1;
01176 }
01177
01178 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01179 error);
01180
01181 dbus_message_unref (message);
01182
01183 if (reply == NULL)
01184 {
01185 _DBUS_ASSERT_ERROR_IS_SET (error);
01186 return -1;
01187 }
01188
01189 if (dbus_set_error_from_message (error, reply))
01190 {
01191 _DBUS_ASSERT_ERROR_IS_SET (error);
01192 dbus_message_unref (reply);
01193 return -1;
01194 }
01195
01196 if (!dbus_message_get_args (reply, error,
01197 DBUS_TYPE_UINT32, &result,
01198 DBUS_TYPE_INVALID))
01199 {
01200 _DBUS_ASSERT_ERROR_IS_SET (error);
01201 dbus_message_unref (reply);
01202 return -1;
01203 }
01204
01205 dbus_message_unref (reply);
01206
01207 return result;
01208 }
01209
01227 dbus_bool_t
01228 dbus_bus_name_has_owner (DBusConnection *connection,
01229 const char *name,
01230 DBusError *error)
01231 {
01232 DBusMessage *message, *reply;
01233 dbus_bool_t exists;
01234
01235 _dbus_return_val_if_fail (connection != NULL, FALSE);
01236 _dbus_return_val_if_fail (name != NULL, FALSE);
01237 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01238 _dbus_return_val_if_error_is_set (error, FALSE);
01239
01240 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01241 DBUS_PATH_DBUS,
01242 DBUS_INTERFACE_DBUS,
01243 "NameHasOwner");
01244 if (message == NULL)
01245 {
01246 _DBUS_SET_OOM (error);
01247 return FALSE;
01248 }
01249
01250 if (!dbus_message_append_args (message,
01251 DBUS_TYPE_STRING, &name,
01252 DBUS_TYPE_INVALID))
01253 {
01254 dbus_message_unref (message);
01255 _DBUS_SET_OOM (error);
01256 return FALSE;
01257 }
01258
01259 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
01260 dbus_message_unref (message);
01261
01262 if (reply == NULL)
01263 {
01264 _DBUS_ASSERT_ERROR_IS_SET (error);
01265 return FALSE;
01266 }
01267
01268 if (!dbus_message_get_args (reply, error,
01269 DBUS_TYPE_BOOLEAN, &exists,
01270 DBUS_TYPE_INVALID))
01271 {
01272 _DBUS_ASSERT_ERROR_IS_SET (error);
01273 dbus_message_unref (reply);
01274 return FALSE;
01275 }
01276
01277 dbus_message_unref (reply);
01278 return exists;
01279 }
01280
01303 dbus_bool_t
01304 dbus_bus_start_service_by_name (DBusConnection *connection,
01305 const char *name,
01306 dbus_uint32_t flags,
01307 dbus_uint32_t *result,
01308 DBusError *error)
01309 {
01310 DBusMessage *msg;
01311 DBusMessage *reply;
01312
01313 _dbus_return_val_if_fail (connection != NULL, FALSE);
01314 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01315
01316 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01317 DBUS_PATH_DBUS,
01318 DBUS_INTERFACE_DBUS,
01319 "StartServiceByName");
01320
01321 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name,
01322 DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
01323 {
01324 dbus_message_unref (msg);
01325 _DBUS_SET_OOM (error);
01326 return FALSE;
01327 }
01328
01329 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01330 -1, error);
01331 dbus_message_unref (msg);
01332
01333 if (reply == NULL)
01334 {
01335 _DBUS_ASSERT_ERROR_IS_SET (error);
01336 return FALSE;
01337 }
01338
01339 if (dbus_set_error_from_message (error, reply))
01340 {
01341 _DBUS_ASSERT_ERROR_IS_SET (error);
01342 dbus_message_unref (reply);
01343 return FALSE;
01344 }
01345
01346 if (result != NULL &&
01347 !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32,
01348 result, DBUS_TYPE_INVALID))
01349 {
01350 _DBUS_ASSERT_ERROR_IS_SET (error);
01351 dbus_message_unref (reply);
01352 return FALSE;
01353 }
01354
01355 dbus_message_unref (reply);
01356 return TRUE;
01357 }
01358
01359 static void
01360 send_no_return_values (DBusConnection *connection,
01361 DBusMessage *msg,
01362 DBusError *error)
01363 {
01364 if (error)
01365 {
01366
01367 DBusMessage *reply;
01368
01369 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01370 -1, error);
01371
01372 if (reply == NULL)
01373 _DBUS_ASSERT_ERROR_IS_SET (error);
01374 else
01375 dbus_message_unref (reply);
01376 }
01377 else
01378 {
01379
01380 dbus_message_set_no_reply (msg, TRUE);
01381 dbus_connection_send (connection, msg, NULL);
01382 }
01383 }
01384
01467 void
01468 dbus_bus_add_match (DBusConnection *connection,
01469 const char *rule,
01470 DBusError *error)
01471 {
01472 DBusMessage *msg;
01473
01474 _dbus_return_if_fail (rule != NULL);
01475
01476 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01477 DBUS_PATH_DBUS,
01478 DBUS_INTERFACE_DBUS,
01479 "AddMatch");
01480
01481 if (msg == NULL)
01482 {
01483 _DBUS_SET_OOM (error);
01484 return;
01485 }
01486
01487 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
01488 DBUS_TYPE_INVALID))
01489 {
01490 dbus_message_unref (msg);
01491 _DBUS_SET_OOM (error);
01492 return;
01493 }
01494
01495 send_no_return_values (connection, msg, error);
01496
01497 dbus_message_unref (msg);
01498 }
01499
01517 void
01518 dbus_bus_remove_match (DBusConnection *connection,
01519 const char *rule,
01520 DBusError *error)
01521 {
01522 DBusMessage *msg;
01523
01524 _dbus_return_if_fail (rule != NULL);
01525
01526 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01527 DBUS_PATH_DBUS,
01528 DBUS_INTERFACE_DBUS,
01529 "RemoveMatch");
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