1
1
/*
2
2
* BlueALSA - bluez.c
3
- * Copyright (c) 2016-2023 Arkadiusz Bokowy
3
+ * Copyright (c) 2016-2024 Arkadiusz Bokowy
4
4
*
5
5
* This file is a part of bluez-alsa.
6
6
*
@@ -91,20 +91,27 @@ struct bluez_adapter {
91
91
static pthread_mutex_t bluez_mutex = PTHREAD_MUTEX_INITIALIZER ;
92
92
static GHashTable * dbus_object_data_map = NULL ;
93
93
static struct bluez_adapter bluez_adapters [HCI_MAX_DEV ] = { 0 };
94
+ static char bluez_dbus_unique_name [64 ] = "" ;
94
95
95
96
static void bluez_register_a2dp_all (struct ba_adapter * );
96
97
97
98
static void bluez_register_media_application_finish (GObject * source ,
98
99
GAsyncResult * result , void * userdata ) {
99
100
(void )userdata ;
100
101
102
+ GDBusMessage * rep ;
101
103
GError * err = NULL ;
102
- GDBusMessage * rep = g_dbus_connection_send_message_with_reply_finish (
103
- G_DBUS_CONNECTION (source ), result , & err );
104
- if (rep != NULL &&
105
- g_dbus_message_get_message_type (rep ) == G_DBUS_MESSAGE_TYPE_ERROR )
106
- g_dbus_message_to_gerror (rep , & err );
107
104
105
+ if ((rep = g_dbus_connection_send_message_with_reply_finish (
106
+ G_DBUS_CONNECTION (source ), result , & err )) == NULL ||
107
+ g_dbus_message_to_gerror (rep , & err ))
108
+ goto fail ;
109
+
110
+ /* Save sender (BlueZ) unique name for calls filtering. */
111
+ const char * sender = g_dbus_message_get_sender (rep );
112
+ strncpy (bluez_dbus_unique_name , sender , sizeof (bluez_dbus_unique_name ) - 1 );
113
+
114
+ fail :
108
115
if (rep != NULL )
109
116
g_object_unref (rep );
110
117
if (err != NULL ) {
@@ -146,12 +153,12 @@ static void bluez_register_battery_provider_finish(GObject *source,
146
153
GAsyncResult * result , void * userdata ) {
147
154
(void )userdata ;
148
155
156
+ GDBusMessage * rep ;
149
157
GError * err = NULL ;
150
- GDBusMessage * rep = g_dbus_connection_send_message_with_reply_finish (
151
- G_DBUS_CONNECTION (source ), result , & err );
152
- if (rep != NULL &&
153
- g_dbus_message_get_message_type (rep ) == G_DBUS_MESSAGE_TYPE_ERROR ) {
154
- g_dbus_message_to_gerror (rep , & err );
158
+
159
+ if ((rep = g_dbus_connection_send_message_with_reply_finish (
160
+ G_DBUS_CONNECTION (source ), result , & err )) == NULL ||
161
+ g_dbus_message_to_gerror (rep , & err )) {
155
162
if (err -> code == G_DBUS_ERROR_UNKNOWN_METHOD ) {
156
163
/* Suppress warning message in case when BlueZ has no battery provider
157
164
* support enabled, because it's not a mandatory feature. */
@@ -658,12 +665,16 @@ static void bluez_export_a2dp(
658
665
659
666
static const GDBusMethodCallDispatcher dispatchers [] = {
660
667
{ .method = "SelectConfiguration" ,
668
+ .sender = bluez_dbus_unique_name ,
661
669
.handler = bluez_endpoint_select_configuration },
662
670
{ .method = "SetConfiguration" ,
671
+ .sender = bluez_dbus_unique_name ,
663
672
.handler = bluez_endpoint_set_configuration },
664
673
{ .method = "ClearConfiguration" ,
674
+ .sender = bluez_dbus_unique_name ,
665
675
.handler = bluez_endpoint_clear_configuration },
666
676
{ .method = "Release" ,
677
+ .sender = bluez_dbus_unique_name ,
667
678
.handler = bluez_endpoint_release },
668
679
{ 0 },
669
680
};
@@ -983,7 +994,7 @@ static int bluez_register_profile(
983
994
GError * * error ) {
984
995
985
996
GDBusMessage * msg = NULL , * rep = NULL ;
986
- int ret = 0 ;
997
+ int ret = -1 ;
987
998
988
999
debug ("Registering hands-free profile: %s" , dbus_obj -> path );
989
1000
@@ -1002,20 +1013,17 @@ static int bluez_register_profile(
1002
1013
g_variant_builder_clear (& options );
1003
1014
1004
1015
if ((rep = g_dbus_connection_send_message_with_reply_sync (config .dbus , msg ,
1005
- G_DBUS_SEND_MESSAGE_FLAGS_NONE , -1 , NULL , NULL , error )) == NULL )
1016
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE , -1 , NULL , NULL , error )) == NULL ||
1017
+ g_dbus_message_to_gerror (rep , error ))
1006
1018
goto fail ;
1007
1019
1008
- if (g_dbus_message_get_message_type (rep ) == G_DBUS_MESSAGE_TYPE_ERROR ) {
1009
- g_dbus_message_to_gerror (rep , error );
1010
- goto fail ;
1011
- }
1020
+ /* Save sender (BlueZ) unique name for calls filtering. */
1021
+ const char * sender = g_dbus_message_get_sender (rep );
1022
+ strncpy (bluez_dbus_unique_name , sender , sizeof (bluez_dbus_unique_name ) - 1 );
1012
1023
1013
- goto final ;
1024
+ ret = 0 ;
1014
1025
1015
1026
fail :
1016
- ret = -1 ;
1017
-
1018
- final :
1019
1027
if (msg != NULL )
1020
1028
g_object_unref (msg );
1021
1029
if (rep != NULL )
@@ -1034,10 +1042,13 @@ static void bluez_register_hfp(
1034
1042
1035
1043
static const GDBusMethodCallDispatcher dispatchers [] = {
1036
1044
{ .method = "NewConnection" ,
1045
+ .sender = bluez_dbus_unique_name ,
1037
1046
.handler = bluez_profile_new_connection },
1038
1047
{ .method = "RequestDisconnection" ,
1048
+ .sender = bluez_dbus_unique_name ,
1039
1049
.handler = bluez_profile_request_disconnection },
1040
1050
{ .method = "Release" ,
1051
+ .sender = bluez_dbus_unique_name ,
1041
1052
.handler = bluez_profile_release },
1042
1053
{ 0 },
1043
1054
};
@@ -1655,14 +1666,10 @@ bool bluez_a2dp_set_configuration(
1655
1666
pthread_mutex_unlock (& bluez_mutex );
1656
1667
1657
1668
if ((rep = g_dbus_connection_send_message_with_reply_sync (config .dbus , msg ,
1658
- G_DBUS_SEND_MESSAGE_FLAGS_NONE , -1 , NULL , NULL , error )) == NULL )
1669
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE , -1 , NULL , NULL , error )) == NULL ||
1670
+ g_dbus_message_to_gerror (rep , error ))
1659
1671
goto fail ;
1660
1672
1661
- if (g_dbus_message_get_message_type (rep ) == G_DBUS_MESSAGE_TYPE_ERROR ) {
1662
- g_dbus_message_to_gerror (rep , error );
1663
- goto fail ;
1664
- }
1665
-
1666
1673
rv = true;
1667
1674
1668
1675
fail :
0 commit comments