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
00129 static dbus_bool_t
00130 get_from_env (char **connection_p,
00131 const char *env_var)
00132 {
00133 const char *s;
00134
00135 _dbus_assert (*connection_p == NULL);
00136
00137 s = _dbus_getenv (env_var);
00138 if (s == NULL || *s == '\0')
00139 return TRUE;
00140 else
00141 {
00142 *connection_p = _dbus_strdup (s);
00143 return *connection_p != NULL;
00144 }
00145 }
00146
00147 static dbus_bool_t
00148 init_connections_unlocked (void)
00149 {
00150 if (!initialized)
00151 {
00152 const char *s;
00153 int i;
00154
00155 i = 0;
00156 while (i < N_BUS_TYPES)
00157 {
00158 bus_connections[i] = NULL;
00159 ++i;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00170 {
00171 _dbus_verbose ("Filling in system bus address...\n");
00172
00173 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SYSTEM],
00174 "DBUS_SYSTEM_BUS_ADDRESS"))
00175 return FALSE;
00176 }
00177
00178
00179 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00180 {
00181
00182 bus_connection_addresses[DBUS_BUS_SYSTEM] =
00183 _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
00184
00185 if (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00186 return FALSE;
00187
00188 _dbus_verbose (" used default system bus \"%s\"\n",
00189 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00190 }
00191 else
00192 _dbus_verbose (" used env var system bus \"%s\"\n",
00193 bus_connection_addresses[DBUS_BUS_SYSTEM]);
00194
00195 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00196 {
00197 _dbus_verbose ("Filling in session bus address...\n");
00198
00199 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION],
00200 "DBUS_SESSION_BUS_ADDRESS"))
00201 return FALSE;
00202
00203 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00204 bus_connection_addresses[DBUS_BUS_SESSION] =
00205 _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
00206
00207 if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00208 return FALSE;
00209
00210 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ?
00211 bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
00212 }
00213
00214 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00215 {
00216 _dbus_verbose ("Filling in activation bus address...\n");
00217
00218 if (!get_from_env (&bus_connection_addresses[DBUS_BUS_STARTER],
00219 "DBUS_STARTER_ADDRESS"))
00220 return FALSE;
00221
00222 _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_STARTER] ?
00223 bus_connection_addresses[DBUS_BUS_STARTER] : "none set");
00224 }
00225
00226
00227 if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL)
00228 {
00229 s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE");
00230
00231 if (s != NULL)
00232 {
00233 _dbus_verbose ("Bus activation type was set to \"%s\"\n", s);
00234
00235 if (strcmp (s, "system") == 0)
00236 activation_bus_type = DBUS_BUS_SYSTEM;
00237 else if (strcmp (s, "session") == 0)
00238 activation_bus_type = DBUS_BUS_SESSION;
00239 }
00240 }
00241 else
00242 {
00243
00244 if (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
00245 {
00246 bus_connection_addresses[DBUS_BUS_STARTER] =
00247 _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
00248 if (bus_connection_addresses[DBUS_BUS_STARTER] == NULL)
00249 return FALSE;
00250 }
00251 }
00252
00253
00254
00255
00256
00257 if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
00258 return FALSE;
00259
00260 if (!_dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
00261 return FALSE;
00262
00263 if (!_dbus_register_shutdown_func (addresses_shutdown_func,
00264 NULL))
00265 return FALSE;
00266
00267 initialized = TRUE;
00268 }
00269
00270 return initialized;
00271 }
00272
00273 static void
00274 bus_data_free (void *data)
00275 {
00276 BusData *bd = data;
00277
00278 if (bd->is_well_known)
00279 {
00280 int i;
00281 _DBUS_LOCK (bus);
00282
00283
00284
00285
00286
00287 i = 0;
00288 while (i < N_BUS_TYPES)
00289 {
00290 if (bus_connections[i] == bd->connection)
00291 bus_connections[i] = NULL;
00292
00293 ++i;
00294 }
00295 _DBUS_UNLOCK (bus);
00296 }
00297
00298 dbus_free (bd->unique_name);
00299 dbus_free (bd);
00300
00301 dbus_connection_free_data_slot (&bus_data_slot);
00302 }
00303
00304 static BusData*
00305 ensure_bus_data (DBusConnection *connection)
00306 {
00307 BusData *bd;
00308
00309 if (!dbus_connection_allocate_data_slot (&bus_data_slot))
00310 return NULL;
00311
00312 bd = dbus_connection_get_data (connection, bus_data_slot);
00313 if (bd == NULL)
00314 {
00315 bd = dbus_new0 (BusData, 1);
00316 if (bd == NULL)
00317 {
00318 dbus_connection_free_data_slot (&bus_data_slot);
00319 return NULL;
00320 }
00321
00322 bd->connection = connection;
00323
00324 if (!dbus_connection_set_data (connection, bus_data_slot, bd,
00325 bus_data_free))
00326 {
00327 dbus_free (bd);
00328 dbus_connection_free_data_slot (&bus_data_slot);
00329 return NULL;
00330 }
00331
00332
00333 }
00334 else
00335 {
00336 dbus_connection_free_data_slot (&bus_data_slot);
00337 }
00338
00339 return bd;
00340 }
00341
00348 void
00349 _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection)
00350 {
00351 int i;
00352
00353 _DBUS_LOCK (bus);
00354
00355
00356
00357
00358
00359
00360
00361 for (i = 0; i < N_BUS_TYPES; ++i)
00362 {
00363 if (bus_connections[i] == connection)
00364 {
00365 bus_connections[i] = NULL;
00366 }
00367 }
00368
00369 _DBUS_UNLOCK (bus);
00370 }
00371
00372 static DBusConnection *
00373 internal_bus_get (DBusBusType type,
00374 dbus_bool_t private,
00375 DBusError *error)
00376 {
00377 const char *address;
00378 DBusConnection *connection;
00379 BusData *bd;
00380 DBusBusType address_type;
00381
00382 _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL);
00383 _dbus_return_val_if_error_is_set (error, NULL);
00384
00385 _DBUS_LOCK (bus);
00386
00387 if (!init_connections_unlocked ())
00388 {
00389 _DBUS_UNLOCK (bus);
00390 _DBUS_SET_OOM (error);
00391 return NULL;
00392 }
00393
00394
00395
00396
00397
00398 address_type = type;
00399
00400
00401
00402
00403
00404
00405 if (type == DBUS_BUS_STARTER &&
00406 bus_connection_addresses[activation_bus_type] != NULL)
00407 type = activation_bus_type;
00408
00409 if (!private && bus_connections[type] != NULL)
00410 {
00411 connection = bus_connections[type];
00412 dbus_connection_ref (connection);
00413
00414 _DBUS_UNLOCK (bus);
00415 return connection;
00416 }
00417
00418 address = bus_connection_addresses[address_type];
00419 if (address == NULL)
00420 {
00421 dbus_set_error (error, DBUS_ERROR_FAILED,
00422 "Unable to determine the address of the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)");
00423 _DBUS_UNLOCK (bus);
00424 return NULL;
00425 }
00426
00427 if (private)
00428 connection = dbus_connection_open_private (address, error);
00429 else
00430 connection = dbus_connection_open (address, error);
00431
00432 if (!connection)
00433 {
00434 _DBUS_ASSERT_ERROR_IS_SET (error);
00435 _DBUS_UNLOCK (bus);
00436 return NULL;
00437 }
00438
00439
00440
00441
00442 dbus_connection_set_exit_on_disconnect (connection,
00443 TRUE);
00444
00445 if (!dbus_bus_register (connection, error))
00446 {
00447 _DBUS_ASSERT_ERROR_IS_SET (error);
00448 _dbus_connection_close_possibly_shared (connection);
00449 dbus_connection_unref (connection);
00450
00451 _DBUS_UNLOCK (bus);
00452 return NULL;
00453 }
00454
00455 if (!private)
00456 {
00457
00458
00459
00460
00461 bus_connections[type] = connection;
00462 }
00463
00464 _DBUS_LOCK (bus_datas);
00465 bd = ensure_bus_data (connection);
00466 _dbus_assert (bd != NULL);
00467
00468 bd->is_well_known = TRUE;
00469 _DBUS_UNLOCK (bus_datas);
00470
00471
00472 _DBUS_UNLOCK (bus);
00473
00474
00475 return connection;
00476 }
00477
00478
00480
00511 DBusConnection *
00512 dbus_bus_get (DBusBusType type,
00513 DBusError *error)
00514 {
00515 return internal_bus_get (type, FALSE, error);
00516 }
00517
00543 DBusConnection *
00544 dbus_bus_get_private (DBusBusType type,
00545 DBusError *error)
00546 {
00547 return internal_bus_get (type, TRUE, error);
00548 }
00549
00599 dbus_bool_t
00600 dbus_bus_register (DBusConnection *connection,
00601 DBusError *error)
00602 {
00603 DBusMessage *message, *reply;
00604 char *name;
00605 BusData *bd;
00606 dbus_bool_t retval;
00607
00608 _dbus_return_val_if_fail (connection != NULL, FALSE);
00609 _dbus_return_val_if_error_is_set (error, FALSE);
00610
00611 retval = FALSE;
00612
00613 _DBUS_LOCK (bus_datas);
00614
00615 bd = ensure_bus_data (connection);
00616 if (bd == NULL)
00617 {
00618 _DBUS_SET_OOM (error);
00619 _DBUS_UNLOCK (bus_datas);
00620 return FALSE;
00621 }
00622
00623 if (bd->unique_name != NULL)
00624 {
00625 _dbus_verbose ("Ignoring attempt to register the same DBusConnection %s with the message bus a second time.\n",
00626 bd->unique_name);
00627 _DBUS_UNLOCK (bus_datas);
00628
00629
00630 return TRUE;
00631 }
00632
00633 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00634 DBUS_PATH_DBUS,
00635 DBUS_INTERFACE_DBUS,
00636 "Hello");
00637
00638 if (!message)
00639 {
00640 _DBUS_SET_OOM (error);
00641
00642 _DBUS_UNLOCK (bus_datas);
00643 return FALSE;
00644 }
00645
00646 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
00647
00648 dbus_message_unref (message);
00649
00650 if (reply == NULL)
00651 goto out;
00652 else if (dbus_set_error_from_message (error, reply))
00653 goto out;
00654 else if (!dbus_message_get_args (reply, error,
00655 DBUS_TYPE_STRING, &name,
00656 DBUS_TYPE_INVALID))
00657 goto out;
00658
00659 bd->unique_name = _dbus_strdup (name);
00660 if (bd->unique_name == NULL)
00661 {
00662 _DBUS_SET_OOM (error);
00663 goto out;
00664 }
00665
00666 retval = TRUE;
00667
00668 out:
00669 if (reply)
00670 dbus_message_unref (reply);
00671
00672 if (!retval)
00673 _DBUS_ASSERT_ERROR_IS_SET (error);
00674
00675 _DBUS_UNLOCK (bus_datas);
00676
00677 return retval;
00678 }
00679
00680
00715 dbus_bool_t
00716 dbus_bus_set_unique_name (DBusConnection *connection,
00717 const char *unique_name)
00718 {
00719 BusData *bd;
00720 dbus_bool_t success;
00721
00722 _dbus_return_val_if_fail (connection != NULL, FALSE);
00723 _dbus_return_val_if_fail (unique_name != NULL, FALSE);
00724
00725 _DBUS_LOCK (bus_datas);
00726
00727 bd = ensure_bus_data (connection);
00728 if (bd == NULL)
00729 return FALSE;
00730
00731 _dbus_assert (bd->unique_name == NULL);
00732
00733 bd->unique_name = _dbus_strdup (unique_name);
00734 success = bd->unique_name != NULL;
00735
00736 _DBUS_UNLOCK (bus_datas);
00737
00738 return success;
00739 }
00740
00759 const char*
00760 dbus_bus_get_unique_name (DBusConnection *connection)
00761 {
00762 BusData *bd;
00763 const char *unique_name;
00764
00765 _dbus_return_val_if_fail (connection != NULL, NULL);
00766
00767 _DBUS_LOCK (bus_datas);
00768
00769 bd = ensure_bus_data (connection);
00770 if (bd == NULL)
00771 return NULL;
00772
00773 unique_name = bd->unique_name;
00774
00775 _DBUS_UNLOCK (bus_datas);
00776
00777 return unique_name;
00778 }
00779
00803 unsigned long
00804 dbus_bus_get_unix_user (DBusConnection *connection,
00805 const char *name,
00806 DBusError *error)
00807 {
00808 DBusMessage *message, *reply;
00809 dbus_uint32_t uid;
00810
00811 _dbus_return_val_if_fail (connection != NULL, DBUS_UID_UNSET);
00812 _dbus_return_val_if_fail (name != NULL, DBUS_UID_UNSET);
00813 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), DBUS_UID_UNSET);
00814 _dbus_return_val_if_error_is_set (error, DBUS_UID_UNSET);
00815
00816 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00817 DBUS_PATH_DBUS,
00818 DBUS_INTERFACE_DBUS,
00819 "GetConnectionUnixUser");
00820
00821 if (message == NULL)
00822 {
00823 _DBUS_SET_OOM (error);
00824 return DBUS_UID_UNSET;
00825 }
00826
00827 if (!dbus_message_append_args (message,
00828 DBUS_TYPE_STRING, &name,
00829 DBUS_TYPE_INVALID))
00830 {
00831 dbus_message_unref (message);
00832 _DBUS_SET_OOM (error);
00833 return DBUS_UID_UNSET;
00834 }
00835
00836 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00837 error);
00838
00839 dbus_message_unref (message);
00840
00841 if (reply == NULL)
00842 {
00843 _DBUS_ASSERT_ERROR_IS_SET (error);
00844 return DBUS_UID_UNSET;
00845 }
00846
00847 if (dbus_set_error_from_message (error, reply))
00848 {
00849 _DBUS_ASSERT_ERROR_IS_SET (error);
00850 dbus_message_unref (reply);
00851 return DBUS_UID_UNSET;
00852 }
00853
00854 if (!dbus_message_get_args (reply, error,
00855 DBUS_TYPE_UINT32, &uid,
00856 DBUS_TYPE_INVALID))
00857 {
00858 _DBUS_ASSERT_ERROR_IS_SET (error);
00859 dbus_message_unref (reply);
00860 return DBUS_UID_UNSET;
00861 }
00862
00863 dbus_message_unref (reply);
00864
00865 return (unsigned long) uid;
00866 }
00867
00886 char*
00887 dbus_bus_get_id (DBusConnection *connection,
00888 DBusError *error)
00889 {
00890 DBusMessage *message, *reply;
00891 char *id;
00892 const char *v_STRING;
00893
00894 _dbus_return_val_if_fail (connection != NULL, NULL);
00895 _dbus_return_val_if_error_is_set (error, NULL);
00896
00897 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
00898 DBUS_PATH_DBUS,
00899 DBUS_INTERFACE_DBUS,
00900 "GetId");
00901
00902 if (message == NULL)
00903 {
00904 _DBUS_SET_OOM (error);
00905 return NULL;
00906 }
00907
00908 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00909 error);
00910
00911 dbus_message_unref (message);
00912
00913 if (reply == NULL)
00914 {
00915 _DBUS_ASSERT_ERROR_IS_SET (error);
00916 return NULL;
00917 }
00918
00919 if (dbus_set_error_from_message (error, reply))
00920 {
00921 _DBUS_ASSERT_ERROR_IS_SET (error);
00922 dbus_message_unref (reply);
00923 return NULL;
00924 }
00925
00926 v_STRING = NULL;
00927 if (!dbus_message_get_args (reply, error,
00928 DBUS_TYPE_STRING, &v_STRING,
00929 DBUS_TYPE_INVALID))
00930 {
00931 _DBUS_ASSERT_ERROR_IS_SET (error);
00932 dbus_message_unref (reply);
00933 return NULL;
00934 }
00935
00936 id = _dbus_strdup (v_STRING);
00937
00938 dbus_message_unref (reply);
00939
00940 if (id == NULL)
00941 _DBUS_SET_OOM (error);
00942
00943
00944
00945 return id;
00946 }
00947
01050 int
01051 dbus_bus_request_name (DBusConnection *connection,
01052 const char *name,
01053 unsigned int flags,
01054 DBusError *error)
01055 {
01056 DBusMessage *message, *reply;
01057 dbus_uint32_t result;
01058
01059 _dbus_return_val_if_fail (connection != NULL, 0);
01060 _dbus_return_val_if_fail (name != NULL, 0);
01061 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01062 _dbus_return_val_if_error_is_set (error, 0);
01063
01064 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01065 DBUS_PATH_DBUS,
01066 DBUS_INTERFACE_DBUS,
01067 "RequestName");
01068
01069 if (message == NULL)
01070 {
01071 _DBUS_SET_OOM (error);
01072 return -1;
01073 }
01074
01075 if (!dbus_message_append_args (message,
01076 DBUS_TYPE_STRING, &name,
01077 DBUS_TYPE_UINT32, &flags,
01078 DBUS_TYPE_INVALID))
01079 {
01080 dbus_message_unref (message);
01081 _DBUS_SET_OOM (error);
01082 return -1;
01083 }
01084
01085 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01086 error);
01087
01088 dbus_message_unref (message);
01089
01090 if (reply == NULL)
01091 {
01092 _DBUS_ASSERT_ERROR_IS_SET (error);
01093 return -1;
01094 }
01095
01096 if (dbus_set_error_from_message (error, reply))
01097 {
01098 _DBUS_ASSERT_ERROR_IS_SET (error);
01099 dbus_message_unref (reply);
01100 return -1;
01101 }
01102
01103 if (!dbus_message_get_args (reply, error,
01104 DBUS_TYPE_UINT32, &result,
01105 DBUS_TYPE_INVALID))
01106 {
01107 _DBUS_ASSERT_ERROR_IS_SET (error);
01108 dbus_message_unref (reply);
01109 return -1;
01110 }
01111
01112 dbus_message_unref (reply);
01113
01114 return result;
01115 }
01116
01117
01136 int
01137 dbus_bus_release_name (DBusConnection *connection,
01138 const char *name,
01139 DBusError *error)
01140 {
01141 DBusMessage *message, *reply;
01142 dbus_uint32_t result;
01143
01144 _dbus_return_val_if_fail (connection != NULL, 0);
01145 _dbus_return_val_if_fail (name != NULL, 0);
01146 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
01147 _dbus_return_val_if_error_is_set (error, 0);
01148
01149 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01150 DBUS_PATH_DBUS,
01151 DBUS_INTERFACE_DBUS,
01152 "ReleaseName");
01153
01154 if (message == NULL)
01155 {
01156 _DBUS_SET_OOM (error);
01157 return -1;
01158 }
01159
01160 if (!dbus_message_append_args (message,
01161 DBUS_TYPE_STRING, &name,
01162 DBUS_TYPE_INVALID))
01163 {
01164 dbus_message_unref (message);
01165 _DBUS_SET_OOM (error);
01166 return -1;
01167 }
01168
01169 reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
01170 error);
01171
01172 dbus_message_unref (message);
01173
01174 if (reply == NULL)
01175 {
01176 _DBUS_ASSERT_ERROR_IS_SET (error);
01177 return -1;
01178 }
01179
01180 if (dbus_set_error_from_message (error, reply))
01181 {
01182 _DBUS_ASSERT_ERROR_IS_SET (error);
01183 dbus_message_unref (reply);
01184 return -1;
01185 }
01186
01187 if (!dbus_message_get_args (reply, error,
01188 DBUS_TYPE_UINT32, &result,
01189 DBUS_TYPE_INVALID))
01190 {
01191 _DBUS_ASSERT_ERROR_IS_SET (error);
01192 dbus_message_unref (reply);
01193 return -1;
01194 }
01195
01196 dbus_message_unref (reply);
01197
01198 return result;
01199 }
01200
01218 dbus_bool_t
01219 dbus_bus_name_has_owner (DBusConnection *connection,
01220 const char *name,
01221 DBusError *error)
01222 {
01223 DBusMessage *message, *reply;
01224 dbus_bool_t exists;
01225
01226 _dbus_return_val_if_fail (connection != NULL, FALSE);
01227 _dbus_return_val_if_fail (name != NULL, FALSE);
01228 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01229 _dbus_return_val_if_error_is_set (error, FALSE);
01230
01231 message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01232 DBUS_PATH_DBUS,
01233 DBUS_INTERFACE_DBUS,
01234 "NameHasOwner");
01235 if (message == NULL)
01236 {
01237 _DBUS_SET_OOM (error);
01238 return FALSE;
01239 }
01240
01241 if (!dbus_message_append_args (message,
01242 DBUS_TYPE_STRING, &name,
01243 DBUS_TYPE_INVALID))
01244 {
01245 dbus_message_unref (message);
01246 _DBUS_SET_OOM (error);
01247 return FALSE;
01248 }
01249
01250 reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
01251 dbus_message_unref (message);
01252
01253 if (reply == NULL)
01254 {
01255 _DBUS_ASSERT_ERROR_IS_SET (error);
01256 return FALSE;
01257 }
01258
01259 if (!dbus_message_get_args (reply, error,
01260 DBUS_TYPE_BOOLEAN, &exists,
01261 DBUS_TYPE_INVALID))
01262 {
01263 _DBUS_ASSERT_ERROR_IS_SET (error);
01264 dbus_message_unref (reply);
01265 return FALSE;
01266 }
01267
01268 dbus_message_unref (reply);
01269 return exists;
01270 }
01271
01294 dbus_bool_t
01295 dbus_bus_start_service_by_name (DBusConnection *connection,
01296 const char *name,
01297 dbus_uint32_t flags,
01298 dbus_uint32_t *result,
01299 DBusError *error)
01300 {
01301 DBusMessage *msg;
01302 DBusMessage *reply;
01303
01304 _dbus_return_val_if_fail (connection != NULL, FALSE);
01305 _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), FALSE);
01306
01307 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01308 DBUS_PATH_DBUS,
01309 DBUS_INTERFACE_DBUS,
01310 "StartServiceByName");
01311
01312 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &name,
01313 DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))
01314 {
01315 dbus_message_unref (msg);
01316 _DBUS_SET_OOM (error);
01317 return FALSE;
01318 }
01319
01320 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01321 -1, error);
01322 dbus_message_unref (msg);
01323
01324 if (reply == NULL)
01325 {
01326 _DBUS_ASSERT_ERROR_IS_SET (error);
01327 return FALSE;
01328 }
01329
01330 if (dbus_set_error_from_message (error, reply))
01331 {
01332 _DBUS_ASSERT_ERROR_IS_SET (error);
01333 dbus_message_unref (reply);
01334 return FALSE;
01335 }
01336
01337 if (result != NULL &&
01338 !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32,
01339 result, DBUS_TYPE_INVALID))
01340 {
01341 _DBUS_ASSERT_ERROR_IS_SET (error);
01342 dbus_message_unref (reply);
01343 return FALSE;
01344 }
01345
01346 dbus_message_unref (reply);
01347 return TRUE;
01348 }
01349
01350 static void
01351 send_no_return_values (DBusConnection *connection,
01352 DBusMessage *msg,
01353 DBusError *error)
01354 {
01355 if (error)
01356 {
01357
01358 DBusMessage *reply;
01359
01360 reply = dbus_connection_send_with_reply_and_block (connection, msg,
01361 -1, error);
01362
01363 if (reply == NULL)
01364 _DBUS_ASSERT_ERROR_IS_SET (error);
01365 else
01366 dbus_message_unref (reply);
01367 }
01368 else
01369 {
01370
01371 dbus_message_set_no_reply (msg, TRUE);
01372 dbus_connection_send (connection, msg, NULL);
01373 }
01374 }
01375
01451 void
01452 dbus_bus_add_match (DBusConnection *connection,
01453 const char *rule,
01454 DBusError *error)
01455 {
01456 DBusMessage *msg;
01457
01458 _dbus_return_if_fail (rule != NULL);
01459
01460 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01461 DBUS_PATH_DBUS,
01462 DBUS_INTERFACE_DBUS,
01463 "AddMatch");
01464
01465 if (msg == NULL)
01466 {
01467 _DBUS_SET_OOM (error);
01468 return;
01469 }
01470
01471 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
01472 DBUS_TYPE_INVALID))
01473 {
01474 dbus_message_unref (msg);
01475 _DBUS_SET_OOM (error);
01476 return;
01477 }
01478
01479 send_no_return_values (connection, msg, error);
01480
01481 dbus_message_unref (msg);
01482 }
01483
01501 void
01502 dbus_bus_remove_match (DBusConnection *connection,
01503 const char *rule,
01504 DBusError *error)
01505 {
01506 DBusMessage *msg;
01507
01508 _dbus_return_if_fail (rule != NULL);
01509
01510 msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
01511 DBUS_PATH_DBUS,
01512 DBUS_INTERFACE_DBUS,
01513 "RemoveMatch");
01514
01515 if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &rule,
01516 DBUS_TYPE_INVALID))
01517 {
01518 dbus_message_unref (msg);
01519 _DBUS_SET_OOM (error);
01520 return;
01521 }
01522
01523 send_no_return_values (connection, msg, error);
01524
01525 dbus_message_unref (msg);
01526 }
01527