Create btd_error_invalid_args()
PATCH 1/9 Create btd_error_invalid_args()
DBus error handling in BlueZ is a mess. This is the first patch to unify all DBus error handling like in ConnMan and oFono. This unifies all .InvalidArguments errors.
--- attrib/client.c | 20 ++++++----------- audio/gateway.c | 8 +----- audio/headset.c | 18 +++++---------- audio/media.c | 9 ++----- audio/telephony-dummy.c | 25 ++++++++------------ audio/telephony-maemo5.c | 11 ++------ audio/telephony-maemo6.c | 11 ++------ audio/transport.c | 14 +++-------- health/hdp.c | 54 ++++++++++++---------------------------------- network/server.c | 7 ------ plugins/service.c | 8 +------ serial/port.c | 8 ------ serial/proxy.c | 19 +++++----------- src/adapter.c | 52 +++++++++++++++++++------------------------ src/device.c | 22 ++++++------------ src/error.c | 7 ++++++ src/error.h | 2 + src/manager.c | 7 ------ 18 files changed, 99 insertions(+), 203 deletions(-)
attrib/client.c +7 -13
@@ -191,12 +191,6 @@ static int watcher_cmp(gconstpointer a, gconstpointer b)return g_strcmp0 (watcher->path, match->path); } -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static inline DBusMessage *not_authorized (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAuthorized",
@@ -466,7 +460,7 @@ static DBusMessage *register_watcher(DBusConnection *conn,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_OBJECT_PATH , &path,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (l2cap_connect (prim->gatt, &gerr, TRUE) <0 ) {DBusMessage *reply;
@@ -500,7 +494,7 @@ static DBusMessage *unregister_watcher(DBusConnection *conn,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_OBJECT_PATH , &path,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg); match = g_new0(struct watcher, 1); match->name =g_strdup (sender);
@@ -538,7 +532,7 @@ static DBusMessage *set_value(DBusConnection *conn, DBusMessage *msg,if (dbus_message_iter_get_arg_type (iter) !=DBUS_TYPE_ARRAY ||dbus_message_iter_get_element_type (iter) !=DBUS_TYPE_BYTE ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_recurse (iter, &sub);
@@ -587,23 +581,23 @@ static DBusMessage *set_property(DBusConnection *conn,const char *property;if (!dbus_message_iter_init (msg, &iter)) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&iter, &property);dbus_message_iter_next (&iter);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_recurse (&iter, &sub);if (g_str_equal ("Value" , property))return set_value (conn, msg, &sub, chr); -return invalid_args (msg); +return btd_error_invalid_args (msg); }static GDBusMethodTable char_methods[] = {
audio/gateway.c +2 -6
@@ -491,9 +491,7 @@ static DBusMessage *register_agent(DBusConnection *conn,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_OBJECT_PATH , &path,DBUS_TYPE_INVALID )) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".InvalidArguments" , -"Invalid argument" ); +return btd_error_invalid_args (msg); name =dbus_message_get_sender (msg); agent = g_new0(struct hf_agent, 1);
@@ -526,9 +524,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_OBJECT_PATH , &path,DBUS_TYPE_INVALID )) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".InvalidArguments" , -"Invalid argument" ); +return btd_error_invalid_args (msg);if (strcmp (gw->agent->path, path) !=0 ) return g_dbus_create_error(msg,
audio/headset.c +6 -12
@@ -176,12 +176,6 @@ struct event {static GSList *headset_callbacks =NULL ; -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static DBusHandlerResult error_not_supported (DBusConnection *conn,DBusMessage *msg) {
@@ -2022,35 +2016,35 @@ static DBusMessage *hs_set_property(DBusConnection *conn,uint16_t gain;if (!dbus_message_iter_init (msg, &iter)) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&iter, &property);dbus_message_iter_next (&iter);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_recurse (&iter, &sub);if (g_str_equal ("SpeakerGain" , property)) {if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_UINT16 ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&sub, &gain);return hs_set_gain (conn, msg, data, gain,HEADSET_GAIN_SPEAKER ); }else if (g_str_equal ("MicrophoneGain" , property)) {if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_UINT16 ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&sub, &gain);return hs_set_gain (conn, msg, data, gain,HEADSET_GAIN_MICROPHONE ); } -return invalid_args (msg); +return btd_error_invalid_args (msg); }static GDBusMethodTable headset_methods[] = { {"Connect" ,"" ,"" , hs_connect,
audio/media.c +3 -6
@@ -323,18 +323,15 @@ static DBusMessage *register_endpoint(DBusConnection *conn, DBusMessage *msg,dbus_message_iter_recurse (&args, &props);if (dbus_message_iter_get_arg_type (&props) !=DBUS_TYPE_DICT_ENTRY ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".Failed" ,"Invalid argument" ); +return btd_error_invalid_args (msg);if (parse_properties (&props, &uuid, &delay_reporting, &codec, &capabilities, &size) || uuid ==NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Invalid argument" ); +return btd_error_invalid_args (msg);if (media_endpoint_create (adapter, sender, path, uuid, delay_reporting, codec, capabilities, size) == FALSE) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Invalid argument" ); +return btd_error_invalid_args (msg);return g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); }
audio/telephony-dummy.c +10 -15
@@ -35,6 +35,7 @@#include "log.h" #include "telephony.h" +#include "error.h" #define TELEPHONY_DUMMY_IFACE "org.bluez.TelephonyTest"#define TELEPHONY_DUMMY_PATH "/org/bluez/test"
@@ -69,12 +70,6 @@ static struct indicator dummy_indicators[] = { NULL } }; -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,"org.bluez.Error.InvalidArguments" , -"Invalid arguments in method call" ); -} -void telephony_device_connected (void *telephony_device) {DBG ("telephony-dummy: device %p connected" , telephony_device);
@@ -236,7 +231,7 @@ static DBusMessage *outgoing_call(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &number,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);DBG ("telephony-dummy: outgoing call to %s" , number);
@@ -261,7 +256,7 @@ static DBusMessage *incoming_call(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &number,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);DBG ("telephony-dummy: incoming call to %s" , number);
@@ -307,10 +302,10 @@ static DBusMessage *signal_strength(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_UINT32 , &strength,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (strength >5 ) -return invalid_args (msg); +return btd_error_invalid_args (msg);telephony_update_indicator (dummy_indicators,"signal" , strength);
@@ -326,10 +321,10 @@ static DBusMessage *battery_level(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_UINT32 , &level,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (level >5 ) -return invalid_args (msg); +return btd_error_invalid_args (msg);telephony_update_indicator (dummy_indicators,"battchg" , level);
@@ -346,7 +341,7 @@ static DBusMessage *roaming_status(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_BOOLEAN , &roaming,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg); val = roaming ?EV_ROAM_ACTIVE :EV_ROAM_INACTIVE ;
@@ -365,7 +360,7 @@ static DBusMessage *registration_status(DBusConnection *conn, DBusMessage *msg,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_BOOLEAN , ®istration,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg); val = registration ?EV_SERVICE_PRESENT :EV_SERVICE_NONE ;
@@ -384,7 +379,7 @@ static DBusMessage *set_subscriber_number(DBusConnection *conn,if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &number,DBUS_TYPE_INVALID )) -return invalid_args (msg); +return btd_error_invalid_args (msg);g_free (subscriber_number); subscriber_number =g_strdup (number);
audio/telephony-maemo5.c +3 -8
@@ -38,6 +38,7 @@#include "log.h" #include "telephony.h" +#include "error.h" /* SSC D-Bus definitions */ #define SSC_DBUS_NAME "com.nokia.phone.SSC"
@@ -1880,12 +1881,6 @@ static void csd_init(void) } } -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,"org.bluez.Error.InvalidArguments" , -"Invalid arguments in method call" ); -} -static uint32_t get_callflag (const char *callerid_setting) {if (callerid_setting !=NULL ) {
@@ -1950,7 +1945,7 @@ static DBusMessage *set_callerid(DBusConnection *conn, DBusMessage *msg,if (dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &callerid_setting,DBUS_TYPE_INVALID ) == FALSE) -return invalid_args (msg); +return btd_error_invalid_args (msg); if (g_str_equal(callerid_setting, "allowed") || g_str_equal(callerid_setting, "restricted") ||
@@ -1964,7 +1959,7 @@ static DBusMessage *set_callerid(DBusConnection *conn, DBusMessage *msg,error ("telephony-maemo: invalid argument %s for method call" " SetCallerId" , callerid_setting); -return invalid_args (msg); +return btd_error_invalid_args (msg); }static GDBusMethodTable telephony_maemo_methods[] = {
audio/telephony-maemo6.c +3 -8
@@ -38,6 +38,7 @@#include "log.h" #include "telephony.h" +#include "error.h" /* SSC D-Bus definitions */ #define SSC_DBUS_NAME "com.nokia.phone.SSC"
@@ -1720,12 +1721,6 @@ static void csd_init(void) } } -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,"org.bluez.Error.InvalidArguments" , -"Invalid arguments in method call" ); -} -static uint32_t get_callflag (const char *callerid_setting) {if (callerid_setting !=NULL ) {
@@ -1790,7 +1785,7 @@ static DBusMessage *set_callerid(DBusConnection *conn, DBusMessage *msg,if (dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &callerid_setting,DBUS_TYPE_INVALID ) == FALSE) -return invalid_args (msg); +return btd_error_invalid_args (msg); if (g_str_equal(callerid_setting, "allowed") || g_str_equal(callerid_setting, "restricted") ||
@@ -1804,7 +1799,7 @@ static DBusMessage *set_callerid(DBusConnection *conn, DBusMessage *msg,error ("telephony-maemo6: invalid argument %s for method call" " SetCallerId" , callerid_setting); -return invalid_args (msg); +return btd_error_invalid_args (msg); } static DBusMessage *clear_lastnumber(DBusConnection *conn, DBusMessage *msg,
audio/transport.c +4 -10
@@ -93,12 +93,6 @@ struct media_transport { DBusMessageIter *value); }; -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static inline DBusMessage *error_failed (DBusMessage *msg,const char *desc) {return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" ,"%s" , desc);
@@ -549,16 +543,16 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,int err;if (!dbus_message_iter_init (msg, &iter)) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&iter, &property);dbus_message_iter_next (&iter);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_recurse (&iter, &value); sender =dbus_message_get_sender (msg);
@@ -577,7 +571,7 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,if (err <0 ) {if (err == -EINVAL ) -return invalid_args (msg); +return btd_error_invalid_args (msg);return error_failed (msg,strerror (-err)); }
health/hdp.c +14 -40
98 lines not on this page · raw message
network/server.c +0 -7
@@ -573,13 +573,6 @@ static inline DBusMessage *failed(DBusMessage *msg, const char *description) "%s", description); } -static inline DBusMessage *invalid_arguments (DBusMessage *msg, -const char *description) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"%s" , description); -} -static void server_disconnect (DBusConnection *conn,void *user_data) {struct network_server *ns = user_data;
plugins/service.c +1 -7
@@ -337,12 +337,6 @@ static void exit_callback(DBusConnection *conn, void *user_data)g_free (user_record); } -static inline DBusMessage *invalid_arguments (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static inline DBusMessage *not_available (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
@@ -464,7 +458,7 @@ static DBusMessage *update_xml_record(DBusConnection *conn, len = (record ?strlen (record) :0 );if (len ==0 ) -return invalid_arguments (msg); +return btd_error_invalid_args (msg); user_record =find_record (serv_adapter, handle,dbus_message_get_sender (msg));
serial/port.c +0 -8
@@ -57,7 +57,6 @@#include "port.h" #define SERIAL_PORT_INTERFACE "org.bluez.Serial" -#define ERROR_INVALID_ARGS "org.bluez.Error.InvalidArguments"#define ERROR_DOES_NOT_EXIST "org.bluez.Error.DoesNotExist"#define MAX_OPEN_TRIES 5
@@ -243,13 +242,6 @@ static inline DBusMessage *does_not_exist(DBusMessage *msg, "%s", description); } -static inline DBusMessage *invalid_arguments (DBusMessage *msg, -const char *description) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"%s" , description); -} -static inline DBusMessage *failed (DBusMessage *msg,const char *description) { return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
serial/proxy.c +6 -13
@@ -138,13 +138,6 @@ static inline DBusMessage *does_not_exist(DBusMessage *msg, "%s", description); } -static inline DBusMessage *invalid_arguments (DBusMessage *msg, -const char *description) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"%s" , description); -} -static inline DBusMessage *failed (DBusMessage *msg,const char *description) { return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
@@ -753,17 +746,17 @@ static DBusMessage *proxy_set_serial_params(DBusConnection *conn,return NULL ;if (str2speed (ratestr, &speed) ==B0 ) -return invalid_arguments (msg,"Invalid baud rate" ); +return btd_error_invalid_args (msg); ctrl = prx->proxy_ti.c_cflag;if (set_databits (databits, &ctrl) <0 ) -return invalid_arguments (msg,"Invalid data bits" ); +return btd_error_invalid_args (msg);if (set_stopbits (stopbits, &ctrl) <0 ) -return invalid_arguments (msg,"Invalid stop bits" ); +return btd_error_invalid_args (msg);if (set_parity (paritystr, &ctrl) <0 ) -return invalid_arguments (msg,"Invalid parity" ); +return btd_error_invalid_args (msg); prx->proxy_ti.c_cflag = ctrl; prx->proxy_ti.c_cflag |= (CLOCAL |CREAD );
@@ -1055,13 +1048,13 @@ static DBusMessage *create_proxy(DBusConnection *conn, uuid_str =bt_name2string (pattern);if (!uuid_str) -return invalid_arguments (msg,"Invalid UUID" ); +return btd_error_invalid_args (msg); err =register_proxy (adapter, uuid_str, address, &proxy);g_free (uuid_str);if (err == -EINVAL ) -return invalid_arguments (msg,"Invalid address" ); +return btd_error_invalid_args (msg);else if (err == -EALREADY )return g_dbus_create_error (msg,ERROR_INTERFACE ".AlreadyExist" ,"Proxy already exists" );
src/adapter.c +23 -29
176 lines not on this page · raw message
src/device.c +8 -14
@@ -547,12 +547,6 @@ static DBusMessage *set_blocked(DBusConnection *conn, DBusMessage *msg, } } -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static DBusMessage *set_property (DBusConnection *conn,DBusMessage *msg,void *data) {
@@ -561,22 +555,22 @@ static DBusMessage *set_property(DBusConnection *conn,const char *property;if (!dbus_message_iter_init (msg, &iter)) -return invalid_args (msg); +return btd_error_invalid_args (msg);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&iter, &property);dbus_message_iter_next (&iter);if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_recurse (&iter, &sub);if (g_str_equal ("Trusted" , property)) {dbus_bool_t value;if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_BOOLEAN ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&sub, &value);return set_trust (conn, msg, value, data);
@@ -584,7 +578,7 @@ static DBusMessage *set_property(DBusConnection *conn,const char *alias;if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_STRING ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&sub, &alias);return set_alias (conn, msg, alias, data);
@@ -592,14 +586,14 @@ static DBusMessage *set_property(DBusConnection *conn,dbus_bool_t value;if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_BOOLEAN ) -return invalid_args (msg); +return btd_error_invalid_args (msg);dbus_message_iter_get_basic (&sub, &value);return set_blocked (conn, msg, value, data); } -return invalid_args (msg); +return btd_error_invalid_args (msg); }static void discover_services_req_exit (DBusConnection *conn,void *user_data)
@@ -634,7 +628,7 @@ static DBusMessage *discover_services(DBusConnection *conn,uuid_t uuid;if (bt_string2uuid (&uuid, pattern) <0 ) -return invalid_args (msg); +return btd_error_invalid_args (msg);sdp_uuid128_to_uuid (&uuid);
src/error.c +7 -0
@@ -48,3 +48,10 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,return DBUS_HANDLER_RESULT_HANDLED ; } + +DBusMessage *btd_error_invalid_args (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".InvalidArguments" , +"Invalid arguments in method call" ); +}
src/error.h +2 -0
@@ -29,3 +29,5 @@DBusHandlerResult error_common_reply (DBusConnection *conn,DBusMessage *msg,const char *name,const char *descr); + +DBusMessage *btd_error_invalid_args (DBusMessage *msg);
src/manager.c +0 -7
@@ -64,13 +64,6 @@ void manager_update_svc(struct btd_adapter* adapter, uint8_t svc)adapter_set_service_classes (adapter, svc); } -static inline DBusMessage *invalid_args (DBusMessage *msg) -{ -return g_dbus_create_error (msg, -ERROR_INTERFACE ".InvalidArguments" , -"Invalid arguments in method call" ); -} -static inline DBusMessage *no_such_adapter (DBusMessage *msg) { return g_dbus_create_error(msg,
Signature · 1 line
1.7.3.2
PATCH 2/9 Add btd_error_already_exists()
--- audio/gateway.c | 4 +--- audio/media.c | 3 +-- network/server.c | 2 +- serial/proxy.c | 3 +-- src/adapter.c | 8 ++------ src/device.c | 4 +--- src/error.c | 7 +++++++ src/error.h | 1 + 8 files changed, 15 insertions(+), 17 deletions(-)
audio/gateway.c +1 -3
@@ -485,9 +485,7 @@ static DBusMessage *register_agent(DBusConnection *conn,const char *path, *name;if (gw->agent) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".AlreadyExists" , -"Agent already exists" ); +return btd_error_already_exists (msg);if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_OBJECT_PATH , &path,DBUS_TYPE_INVALID ))
audio/media.c +1 -2
@@ -318,8 +318,7 @@ static DBusMessage *register_endpoint(DBusConnection *conn, DBusMessage *msg,dbus_message_iter_next (&args);if (media_adapter_find_endpoint (adapter, sender, path,NULL ) !=NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Endpoint already registered" ); +return btd_error_already_exists (msg);dbus_message_iter_recurse (&args, &props);if (dbus_message_iter_get_arg_type (&props) !=DBUS_TYPE_DICT_ENTRY )
network/server.c +1 -1
@@ -603,7 +603,7 @@ static DBusMessage *register_server(DBusConnection *conn,return failed (msg,"Invalid UUID" );if (ns->record_id) -return failed (msg,"Already registered" ); +return btd_error_already_exists (msg); reply =dbus_message_new_method_return (msg);if (!reply)
serial/proxy.c +1 -2
@@ -1056,8 +1056,7 @@ static DBusMessage *create_proxy(DBusConnection *conn,if (err == -EINVAL )return btd_error_invalid_args (msg);else if (err == -EALREADY ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".AlreadyExist" , -"Proxy already exists" ); +return btd_error_already_exists (msg);else if (err <0 )return g_dbus_create_error (msg,ERROR_INTERFACE "Failed" ,"Proxy creation failed (%s)" ,strerror (-err));
src/adapter.c +2 -6
@@ -1698,9 +1698,7 @@ static DBusMessage *create_device(DBusConnection *conn,return btd_error_invalid_args (msg);if (adapter_find_device (adapter, address)) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".AlreadyExists" , -"Device already exists" ); +return btd_error_already_exists (msg);DBG ("%s" , address);
@@ -1871,9 +1869,7 @@ static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg,return NULL ;if (adapter->agent) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".AlreadyExists" , -"Agent already exists" ); +return btd_error_already_exists (msg); cap =parse_io_capability (capability);if (cap ==IO_CAPABILITY_INVALID )
src/device.c +1 -3
@@ -2002,9 +2002,7 @@ DBusMessage *device_create_bonding(struct btd_device *device, str =textfile_caseget (filename, dstaddr);if (str) {free (str); -return g_dbus_create_error (msg, -ERROR_INTERFACE ".AlreadyExists" , -"Bonding already exists" ); +return btd_error_already_exists (msg); }/* If our IO capability is NoInputNoOutput use medium security
src/error.c +7 -0
@@ -55,3 +55,10 @@ DBusMessage *btd_error_invalid_args(DBusMessage *msg)".InvalidArguments" , "Invalid arguments in method call"); } + +DBusMessage *btd_error_already_exists (DBusMessage *msg) +{ +return g_dbus_create_error (msg, +ERROR_INTERFACE ".AlreadyExists" , +"Already Exists" ); +}
src/error.h +1 -0
@@ -31,3 +31,4 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg, const char *name, const char *descr);DBusMessage *btd_error_invalid_args (DBusMessage *msg); +DBusMessage *btd_error_already_exists (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 3/9 Add btd_error_not_supported()
--- audio/control.c | 8 ++------ src/device.c | 4 +--- src/error.c | 7 +++++++ src/error.h | 1 + 4 files changed, 11 insertions(+), 9 deletions(-)
audio/control.c +2 -6
@@ -1019,9 +1019,7 @@ static DBusMessage *volume_up(DBusConnection *conn, DBusMessage *msg, "Device not Connected");if (!control->target) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotSupported" , -"AVRCP Target role not supported" ); +return btd_error_not_supported (msg); err =avctp_send_passthrough (control,VOL_UP_OP );if (err <0 )
@@ -1049,9 +1047,7 @@ static DBusMessage *volume_down(DBusConnection *conn, DBusMessage *msg, "Device not Connected");if (!control->target) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotSupported" , -"AVRCP Target role not supported" ); +return btd_error_not_supported (msg); err =avctp_send_passthrough (control,VOL_DOWN_OP );if (err <0 )
src/device.c +1 -3
@@ -538,9 +538,7 @@ static DBusMessage *set_blocked(DBusConnection *conn, DBusMessage *msg,case 0 :return dbus_message_new_method_return (msg);case EINVAL : -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotSupported" , -"Kernel lacks blacklist support" ); +return btd_error_not_supported (msg);default :return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" ,"%s" ,strerror (-err));
src/error.c +7 -0
@@ -62,3 +62,10 @@ DBusMessage *btd_error_already_exists(DBusMessage *msg)ERROR_INTERFACE ".AlreadyExists" , "Already Exists"); } + +DBusMessage *btd_error_not_supported (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".NotSupported" , +"Operation is not supported" ); +}
src/error.h +1 -0
@@ -32,3 +32,4 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,DBusMessage *btd_error_invalid_args (DBusMessage *msg);DBusMessage *btd_error_already_exists (DBusMessage *msg); +DBusMessage *btd_error_not_supported (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 4/9 Add btd_error_not_connected()
--- audio/control.c | 8 ++------ audio/device.c | 3 +-- audio/gateway.c | 4 +--- audio/headset.c | 24 ++++++------------------ audio/sink.c | 4 +--- audio/source.c | 4 +--- src/error.c | 7 +++++++ src/error.h | 1 + 8 files changed, 20 insertions(+), 35 deletions(-)
audio/control.c +2 -6
@@ -1014,9 +1014,7 @@ static DBusMessage *volume_up(DBusConnection *conn, DBusMessage *msg,return NULL ;if (control->state !=AVCTP_STATE_CONNECTED ) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);if (!control->target)return btd_error_not_supported (msg);
@@ -1042,9 +1040,7 @@ static DBusMessage *volume_down(DBusConnection *conn, DBusMessage *msg,return NULL ;if (control->state !=AVCTP_STATE_CONNECTED ) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);if (!control->target)return btd_error_not_supported (msg);
audio/device.c +1 -2
@@ -562,8 +562,7 @@ static DBusMessage *dev_disconnect(DBusConnection *conn, DBusMessage *msg,struct dev_priv *priv = dev->priv;if (priv->state ==AUDIO_STATE_DISCONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotConnected" , -"Not connected" ); +return btd_error_not_connected (msg);if (priv->dc_req)return dbus_message_new_method_return (msg);
audio/gateway.c +1 -3
@@ -423,9 +423,7 @@ static DBusMessage *ag_disconnect(DBusConnection *conn, DBusMessage *msg,return NULL ;if (!gw->rfcomm) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);gateway_close (device);ba2str (&device->dst, gw_addr);
audio/headset.c +6 -18
@@ -1618,9 +1618,7 @@ static DBusMessage *hs_stop(DBusConnection *conn, DBusMessage *msg,DBusMessage *reply =NULL ;if (hs->state <HEADSET_STATE_PLAY_IN_PROGRESS ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg); reply =dbus_message_new_method_return (msg);if (!reply)
@@ -1659,9 +1657,7 @@ static DBusMessage *hs_disconnect(DBusConnection *conn, DBusMessage *msg,char hs_address[18 ];if (hs->state ==HEADSET_STATE_DISCONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);headset_shutdown (device);ba2str (&device->dst, hs_address);
@@ -1737,9 +1733,7 @@ static DBusMessage *hs_ring(DBusConnection *conn, DBusMessage *msg,int err;if (hs->state <HEADSET_STATE_CONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg); reply =dbus_message_new_method_return (msg);if (!reply)
@@ -1774,9 +1768,7 @@ static DBusMessage *hs_cancel_call(DBusConnection *conn,DBusMessage *reply =NULL ;if (hs->state <HEADSET_STATE_CONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg); reply =dbus_message_new_method_return (msg);if (!reply)
@@ -1808,9 +1800,7 @@ static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg,switch (hs->state) {case HEADSET_STATE_DISCONNECTED :case HEADSET_STATE_CONNECTING : -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);case HEADSET_STATE_PLAY_IN_PROGRESS :if (hs->pending && hs->pending->msg ==NULL ) { hs->pending->msg =dbus_message_ref (msg);
@@ -1901,9 +1891,7 @@ static DBusMessage *hs_set_gain(DBusConnection *conn,int err;if (hs->state <HEADSET_STATE_CONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg); err =headset_set_gain (device, gain, type);if (err <0 )
audio/sink.c +1 -3
@@ -472,9 +472,7 @@ static DBusMessage *sink_disconnect(DBusConnection *conn,int err;if (!sink->session) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);if (sink->connect || sink->disconnect) return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
audio/source.c +1 -3
@@ -423,9 +423,7 @@ static DBusMessage *source_disconnect(DBusConnection *conn,int err;if (!source->session) -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , -"Device not Connected" ); +return btd_error_not_connected (msg);if (source->connect || source->disconnect) return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
src/error.c +7 -0
@@ -69,3 +69,10 @@ DBusMessage *btd_error_not_supported(DBusMessage *msg)".NotSupported" , "Operation is not supported"); } + +DBusMessage *btd_error_not_connected (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".NotConnected" , +"Not Connected" ); +}
src/error.h +1 -0
@@ -33,3 +33,4 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,DBusMessage *btd_error_invalid_args (DBusMessage *msg);DBusMessage *btd_error_already_exists (DBusMessage *msg);DBusMessage *btd_error_not_supported (DBusMessage *msg); +DBusMessage *btd_error_not_connected (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 5/9 Add btd_error_in_progress()
--- audio/device.c | 3 +-- audio/headset.c | 3 +-- input/device.c | 2 +- src/device.c | 11 ++--------- src/error.c | 7 +++++++ src/error.h | 1 + 6 files changed, 13 insertions(+), 14 deletions(-)
audio/device.c +1 -2
@@ -519,8 +519,7 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,struct dev_priv *priv = dev->priv;if (priv->state ==AUDIO_STATE_CONNECTING ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , -"Connect in Progress" ); +return btd_error_in_progress (msg);else if (priv->state ==AUDIO_STATE_CONNECTED ) return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyConnected",
audio/headset.c +1 -2
@@ -1695,8 +1695,7 @@ static DBusMessage *hs_connect(DBusConnection *conn, DBusMessage *msg,int err;if (hs->state ==HEADSET_STATE_CONNECTING ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , -"Connect in Progress" ); +return btd_error_in_progress (msg);else if (hs->state >HEADSET_STATE_CONNECTING ) return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyConnected",
input/device.c +1 -1
@@ -946,7 +946,7 @@ static DBusMessage *input_device_connect(DBusConnection *conn,return not_supported (msg);if (iconn->pending_connect) -return in_progress (msg); +return btd_error_in_progress (msg);if (is_connected (iconn))return already_connected (msg);
src/device.c +2 -9
@@ -177,12 +177,6 @@ static inline DBusMessage *no_such_adapter(DBusMessage *msg) "No such adapter"); } -static inline DBusMessage *in_progress (DBusMessage *msg,const char *str) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , -"%s" , str); -} -static void browse_request_free (struct browse_req *req) {if (req->listener_id)
@@ -611,8 +605,7 @@ static DBusMessage *discover_services(DBusConnection *conn,int err;if (device->browse) -return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , -"Discover in progress" ); +return btd_error_in_progress (msg);if (dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &pattern,DBUS_TYPE_INVALID ) == FALSE)
@@ -1991,7 +1984,7 @@ DBusMessage *device_create_bonding(struct btd_device *device,ba2str (&device->bdaddr, dstaddr);if (device->bonding) -return in_progress (msg,"Bonding in progress" ); +return btd_error_in_progress (msg);/* check if a link key already exists */ create_name(filename, PATH_MAX, STORAGEDIR, srcaddr,
src/error.c +7 -0
@@ -76,3 +76,10 @@ DBusMessage *btd_error_not_connected(DBusMessage *msg)".NotConnected" , "Not Connected"); } + +DBusMessage *btd_error_in_progress (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".InProgress" , +"In Progress" ); +}
src/error.h +1 -0
@@ -34,3 +34,4 @@ DBusMessage *btd_error_invalid_args(DBusMessage *msg);DBusMessage *btd_error_already_exists (DBusMessage *msg);DBusMessage *btd_error_not_supported (DBusMessage *msg);DBusMessage *btd_error_not_connected (DBusMessage *msg); +DBusMessage *btd_error_in_progress (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 6/9 Add btd_error_not_available()
--- audio/headset.c | 9 +++------ plugins/service.c | 16 +++------------- src/error.c | 7 +++++++ src/error.h | 1 + 4 files changed, 14 insertions(+), 19 deletions(-)
audio/headset.c +3 -6
@@ -1792,8 +1792,7 @@ static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg,if (sco_hci) {error ("Refusing Headset.Play() because SCO HCI routing " "is enabled" ); -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAvailable" , -"Operation not Available" ); +return btd_error_not_available (msg); }switch (hs->state) {
@@ -1838,8 +1837,7 @@ static DBusMessage *hs_get_speaker_gain(DBusConnection *conn,dbus_uint16_t gain;if (hs->state <HEADSET_STATE_CONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAvailable" , -"Operation not Available" ); +return btd_error_not_available (msg); reply =dbus_message_new_method_return (msg);if (!reply)
@@ -1864,8 +1862,7 @@ static DBusMessage *hs_get_mic_gain(DBusConnection *conn,dbus_uint16_t gain;if (hs->state <HEADSET_STATE_CONNECTED || slc ==NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAvailable" , -"Operation not Available" ); +return btd_error_not_available (msg); reply =dbus_message_new_method_return (msg);if (!reply)
plugins/service.c +3 -13
@@ -337,12 +337,6 @@ static void exit_callback(DBusConnection *conn, void *user_data)g_free (user_record); } -static inline DBusMessage *not_available (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAvailable" , -"Not Available" ); -} -static inline DBusMessage *failed (DBusMessage *msg) {return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" ,"Failed" );
@@ -417,9 +411,7 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,if (remove_record_from_server (handle) <0 ) {sdp_record_free (sdp_record); -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotAvailable" , -"Not Available" ); +return btd_error_not_available (msg); }if (serv_adapter->adapter)
@@ -463,9 +455,7 @@ static DBusMessage *update_xml_record(DBusConnection *conn, user_record =find_record (serv_adapter, handle,dbus_message_get_sender (msg));if (!user_record) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotAvailable" , -"Not Available" ); +return btd_error_not_available (msg); sdp_record =sdp_xml_parse_record (record, len);if (!sdp_record) {
@@ -550,7 +540,7 @@ static DBusMessage *remove_service_record(DBusConnection *conn, sender =dbus_message_get_sender (msg);if (remove_record (conn, sender, serv_adapter, handle) <0 ) -return not_available (msg); +return btd_error_not_available (msg);return dbus_message_new_method_return (msg); }
src/error.c +7 -0
@@ -83,3 +83,10 @@ DBusMessage *btd_error_in_progress(DBusMessage *msg)".InProgress" , "In Progress"); } + +DBusMessage *btd_error_not_available (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".NotAvailable" , +"Operation currently not available" ); +}
src/error.h +1 -0
@@ -34,4 +34,5 @@ DBusMessage *btd_error_invalid_args(DBusMessage *msg);DBusMessage *btd_error_already_exists (DBusMessage *msg);DBusMessage *btd_error_not_supported (DBusMessage *msg);DBusMessage *btd_error_not_connected (DBusMessage *msg); +DBusMessage *btd_error_not_available (DBusMessage *msg);DBusMessage *btd_error_in_progress (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 7/9 Add btd_error_busy()
--- audio/headset.c | 4 +--- audio/sink.c | 6 ++---- audio/source.c | 3 +-- input/device.c | 6 ------ src/error.c | 6 ++++++ src/error.h | 1 + 6 files changed, 11 insertions(+), 15 deletions(-)
audio/headset.c +1 -3
@@ -1804,9 +1804,7 @@ static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg, hs->pending->msg =dbus_message_ref (msg);return NULL ; } -return g_dbus_create_error (msg,ERROR_INTERFACE -".InProgress" , -"Play in Progress" ); +return btd_error_busy (msg);case HEADSET_STATE_PLAYING : return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyConnected",
audio/sink.c +2 -4
@@ -439,8 +439,7 @@ static DBusMessage *sink_connect(DBusConnection *conn, "Unable to get a session");if (sink->connect || sink->disconnect) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"%s" ,strerror (EBUSY )); +return btd_error_busy (msg);if (sink->stream_state >=AVDTP_STATE_OPEN ) return g_dbus_create_error(msg, ERROR_INTERFACE
@@ -475,8 +474,7 @@ static DBusMessage *sink_disconnect(DBusConnection *conn,return btd_error_not_connected (msg);if (sink->connect || sink->disconnect) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"%s" ,strerror (EBUSY )); +return btd_error_busy (msg);if (sink->stream_state <AVDTP_STATE_OPEN ) {DBusMessage *reply =dbus_message_new_method_return (msg);
audio/source.c +1 -2
@@ -390,8 +390,7 @@ static DBusMessage *source_connect(DBusConnection *conn, "Unable to get a session");if (source->connect || source->disconnect) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"%s" ,strerror (EBUSY )); +return btd_error_busy (msg);if (source->stream_state >=AVDTP_STATE_OPEN ) return g_dbus_create_error(msg, ERROR_INTERFACE
input/device.c +0 -6
@@ -321,12 +321,6 @@ static inline DBusMessage *not_supported(DBusMessage *msg) "Not supported"); } -static inline DBusMessage *in_progress (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , -"Device connection already in progress" ); -} -static inline DBusMessage *already_connected (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyConnected",
src/error.c +6 -0
@@ -56,6 +56,12 @@ DBusMessage *btd_error_invalid_args(DBusMessage *msg) "Invalid arguments in method call"); } +DBusMessage *btd_error_busy (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" , +"Operation already in progress" ); +} +DBusMessage *btd_error_already_exists (DBusMessage *msg) { return g_dbus_create_error(msg,
src/error.h +1 -0
@@ -31,6 +31,7 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg, const char *name, const char *descr);DBusMessage *btd_error_invalid_args (DBusMessage *msg); +DBusMessage *btd_error_busy (DBusMessage *msg);DBusMessage *btd_error_already_exists (DBusMessage *msg);DBusMessage *btd_error_not_supported (DBusMessage *msg);DBusMessage *btd_error_not_connected (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 8/9 Add btd_error_does_not_exist()
--- plugins/service.c | 10 ++-------- serial/port.c | 12 ++---------- serial/proxy.c | 9 +-------- src/adapter.c | 13 ++++--------- src/error.c | 7 +++++++ src/error.h | 1 + 6 files changed, 17 insertions(+), 35 deletions(-)
plugins/service.c +2 -8
@@ -354,12 +354,6 @@ static inline DBusMessage *not_authorized(DBusMessage *msg) "Not Authorized"); } -static inline DBusMessage *does_not_exist (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".DoesNotExist" , -"Does Not Exist" ); -} -static int add_xml_record (DBusConnection *conn,const char *sender,struct service_adapter *serv_adapter,const char *record,dbus_uint32_t *handle)
@@ -656,7 +650,7 @@ static DBusMessage *request_authorization(DBusConnection *conn, auth =next_pending (serv_adapter);if (auth ==NULL ) -return does_not_exist (msg); +return btd_error_does_not_exist (msg);if (serv_adapter->adapter)adapter_get_address (serv_adapter->adapter, &src);
@@ -687,7 +681,7 @@ static DBusMessage *cancel_authorization(DBusConnection *conn, auth =find_pending_by_sender (serv_adapter, sender);if (auth ==NULL ) -return does_not_exist (msg); +return btd_error_does_not_exist (msg);if (serv_adapter->adapter)adapter_get_address (serv_adapter->adapter, &src);
serial/port.c +2 -10
@@ -57,7 +57,6 @@#include "port.h" #define SERIAL_PORT_INTERFACE "org.bluez.Serial" -#define ERROR_DOES_NOT_EXIST "org.bluez.Error.DoesNotExist"#define MAX_OPEN_TRIES 5#define OPEN_WAIT 300/* ms. udev node creation retry wait */
@@ -235,13 +234,6 @@ void port_release_all(void)g_slist_free (devices); } -static inline DBusMessage *does_not_exist (DBusMessage *msg, -const char *description) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".DoesNotExist" , -"%s" , description); -} -static inline DBusMessage *failed (DBusMessage *msg,const char *description) { return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
@@ -497,7 +489,7 @@ static DBusMessage *port_connect(DBusConnection *conn, channel =strtol (pattern, &endptr,10 );if ((endptr && *endptr !='\0' ) || channel <1 || channel >30 ) -return does_not_exist (msg,"Does not match" ); +return btd_error_does_not_exist (msg); port =create_port (device,NULL , channel); }
@@ -538,7 +530,7 @@ static DBusMessage *port_disconnect(DBusConnection *conn, port =find_port (device->ports, dev);if (!port) -return does_not_exist (msg,"Port does not exist" ); +return btd_error_does_not_exist (msg);if (!port->listener_id)return failed (msg,"Not connected" );
serial/proxy.c +1 -8
@@ -131,13 +131,6 @@ static void proxy_free(struct serial_proxy *prx)g_free (prx); } -static inline DBusMessage *does_not_exist (DBusMessage *msg, -const char *description) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".DoesNotExist" , -"%s" , description); -} -static inline DBusMessage *failed (DBusMessage *msg,const char *description) { return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
@@ -1113,7 +1106,7 @@ static DBusMessage *remove_proxy(DBusConnection *conn, l =g_slist_find_custom (adapter->proxies, path, proxy_pathcmp);if (!l) -return does_not_exist (msg,"Invalid proxy path" ); +return btd_error_does_not_exist (msg); prx = l->data;
src/adapter.c +4 -9
@@ -1794,9 +1794,8 @@ static DBusMessage *remove_device(DBusConnection *conn, DBusMessage *msg, l =g_slist_find_custom (adapter->devices, path, (GCompareFunc ) device_path_cmp);if (!l) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".DoesNotExist" , -"Device does not exist" ); +return btd_error_does_not_exist (msg); + device = l->data;if (device_is_temporary (device) ||device_is_busy (device))
@@ -1832,9 +1831,7 @@ static DBusMessage *find_device(DBusConnection *conn, DBusMessage *msg, l =g_slist_find_custom (adapter->devices, address, (GCompareFunc ) device_address_cmp);if (!l) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".DoesNotExist" , -"Device does not exist" ); +return btd_error_does_not_exist (msg); device = l->data;
@@ -1905,9 +1902,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn, DBusMessage *msg, name =dbus_message_get_sender (msg);if (!adapter->agent || !agent_matches (adapter->agent, name, path)) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".DoesNotExist" , -"No such agent" ); +return btd_error_does_not_exist (msg);agent_free (adapter->agent); adapter->agent =NULL ;
src/error.c +7 -0
@@ -96,3 +96,10 @@ DBusMessage *btd_error_not_available(DBusMessage *msg)".NotAvailable" , "Operation currently not available"); } + +DBusMessage *btd_error_does_not_exist (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".DoesNotExist" , +"Does Not Exist" ); +}
src/error.h +1 -0
@@ -37,3 +37,4 @@ DBusMessage *btd_error_not_supported(DBusMessage *msg);DBusMessage *btd_error_not_connected (DBusMessage *msg);DBusMessage *btd_error_not_available (DBusMessage *msg);DBusMessage *btd_error_in_progress (DBusMessage *msg); +DBusMessage *btd_error_does_not_exist (DBusMessage *msg);
Signature · 1 line
1.7.3.2
PATCH 9/9 Add btd_error_not_authorized()
--- attrib/client.c | 8 +------- plugins/service.c | 22 ++++++++-------------- src/adapter.c | 8 +------- src/device.c | 8 ++------ src/error.c | 7 +++++++ src/error.h | 1 + 6 files changed, 20 insertions(+), 34 deletions(-)
attrib/client.c +1 -7
@@ -191,12 +191,6 @@ static int watcher_cmp(gconstpointer a, gconstpointer b)return g_strcmp0 (watcher->path, match->path); } -static inline DBusMessage *not_authorized (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAuthorized" , -"Not authorized" ); -} -static void append_char_dict (DBusMessageIter *iter,struct characteristic *chr) {DBusMessageIter dict;
@@ -502,7 +496,7 @@ static DBusMessage *unregister_watcher(DBusConnection *conn, l =g_slist_find_custom (prim->watchers, match, watcher_cmp);watcher_free (match);if (!l) -return not_authorized (msg); +return btd_error_not_authorized (msg); watcher = l->data;g_dbus_remove_watch (conn, watcher->id);
plugins/service.c +8 -14
@@ -348,12 +348,6 @@ static inline DBusMessage *failed_strerror(DBusMessage *msg, int err) "%s", strerror(err)); } -static inline DBusMessage *not_authorized (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAuthorized" , -"Not Authorized" ); -} -static int add_xml_record (DBusConnection *conn,const char *sender,struct service_adapter *serv_adapter,const char *record,dbus_uint32_t *handle)
@@ -555,7 +549,7 @@ static void auth_cb(DBusError *derr, void *user_data)if (derr) {error ("Access denied: %s" , derr->message); - reply =not_authorized (auth->msg); + reply =btd_error_not_authorized (auth->msg);dbus_message_unref (auth->msg);g_dbus_send_message (auth->conn, reply); goto done;
@@ -612,20 +606,20 @@ static DBusMessage *request_authorization(DBusConnection *conn,if (!user_record) { user_record =find_record (serv_adapter_any, handle, sender);if (!user_record) -return not_authorized (msg); +return btd_error_not_authorized (msg); } record =sdp_record_find (user_record->handle);if (record ==NULL ) -return not_authorized (msg); +return btd_error_not_authorized (msg);if (sdp_get_service_classes (record, &services) <0 ) {sdp_record_free (record); -return not_authorized (msg); +return btd_error_not_authorized (msg); }if (services ==NULL ) -return not_authorized (msg); +return btd_error_not_authorized (msg); uuid = services->data; uuid128 =sdp_uuid_to_uuid128 (uuid);
@@ -634,7 +628,7 @@ static DBusMessage *request_authorization(DBusConnection *conn,if (sdp_uuid2strn (uuid128, uuid_str,MAX_LEN_UUID_STR ) <0 ) {bt_free (uuid128); -return not_authorized (msg); +return btd_error_not_authorized (msg); }bt_free (uuid128);
@@ -662,7 +656,7 @@ static DBusMessage *request_authorization(DBusConnection *conn, serv_adapter->pending_list =g_slist_remove (serv_adapter->pending_list, auth);g_free (auth); -return not_authorized (msg); +return btd_error_not_authorized (msg); }return NULL ;
@@ -690,7 +684,7 @@ static DBusMessage *cancel_authorization(DBusConnection *conn,btd_cancel_authorization (&src, &auth->dst); - reply =not_authorized (auth->msg); + reply =btd_error_not_authorized (auth->msg);dbus_message_unref (auth->msg);g_dbus_send_message (auth->conn, reply);
src/adapter.c +1 -7
@@ -164,12 +164,6 @@ static inline DBusMessage *not_in_progress(DBusMessage *msg, const char *str) "%s", str); } -static inline DBusMessage *not_authorized (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAuthorized" , -"Not authorized" ); -} -static int found_device_cmp (const struct remote_dev_info *d1,const struct remote_dev_info *d2) {
@@ -1666,7 +1660,7 @@ static DBusMessage *cancel_device_creation(DBusConnection *conn,return not_in_progress (msg,"Device creation not in progress" );if (!device_is_creating (device, sender)) -return not_authorized (msg); +return btd_error_not_authorized (msg);device_set_temporary (device, TRUE);
src/device.c +2 -6
@@ -727,17 +727,13 @@ static DBusMessage *cancel_discover(DBusConnection *conn,if (!dbus_message_is_method_call (device->browse->msg,DEVICE_INTERFACE ,"DiscoverServices" )) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotAuthorized" , -"Not Authorized" ); +return btd_error_not_authorized (msg); requestor =browse_request_get_requestor (device->browse);/* only the discover requestor can cancel the inquiry process */ if (!requestor || !g_str_equal (requestor, sender)) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotAuthorized" , -"Not Authorized" ); +return btd_error_not_authorized (msg);discover_services_reply (device->browse, -ECANCELED ,NULL );
src/error.c +7 -0
@@ -103,3 +103,10 @@ DBusMessage *btd_error_does_not_exist(DBusMessage *msg)".DoesNotExist" , "Does Not Exist"); } + +DBusMessage *btd_error_not_authorized (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE +".NotAuthorized" , +"Operation Not Authorized" ); +}
src/error.h +1 -0
@@ -38,3 +38,4 @@ DBusMessage *btd_error_not_connected(DBusMessage *msg);DBusMessage *btd_error_not_available (DBusMessage *msg);DBusMessage *btd_error_in_progress (DBusMessage *msg);DBusMessage *btd_error_does_not_exist (DBusMessage *msg); +DBusMessage *btd_error_not_authorized (DBusMessage *msg);
Signature · 1 line
1.7.3.2
Re: [PATCH 3/9] Add btd_error_not_supported()
In reply to Gustavo F. PadovanHi Gustavo,
src/device.c static DBusMessage *set_blocked(DBusConnection *conn, DBusMessage *msg, · line 541
Quoted 4 lines · Gustavo F. Padovan
src/device.c +1
-3-return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotSupported" , -"Kernel lacks blacklist support" ); +return btd_error_not_supported (msg);
I'm not sure I agree with this. The specific error message would give hints to the user that he might need to update his kernel but the generic one doesn't give any such hints. Couldn't you have the btd_error_not_supported function take one extra cont char *msg parameter? I had a little bit similar feelings about the ALREADY_EXISTS patch (which I already pushed) but here the issue of loosing the specifics of the error is more obvious.
Johan
Hi Gustavo,
Quoted 15 lines · Gustavo F. Padovan
DBus error handling in BlueZ is a mess. This is the first patch to unify all DBus error handling like in ConnMan and oFono. This unifies all .InvalidArguments errors.
--- attrib/client.c | 20 ++++++----------- audio/gateway.c | 8 +----- audio/headset.c | 18 +++++---------- audio/media.c | 9 ++----- audio/telephony-dummy.c | 25 ++++++++------------ audio/telephony-maemo5.c | 11 ++------ audio/telephony-maemo6.c | 11 ++------ audio/transport.c | 14 +++-------- health/hdp.c | 54 ++++++++++++---------------------------------- network/server.c | 7 ------ plugins/service.c | 8 +------
Quoted 8 lines
serial/port.c | 8 ------ serial/proxy.c | 19 +++++----------- src/adapter.c | 52 +++++++++++++++++++------------------------ src/device.c | 22 ++++++------------ src/error.c | 7 ++++++ src/error.h | 2 + src/manager.c | 7 ------ 18 files changed, 99 insertions(+), 203 deletions(-)
This as well as the second patch (ERROR_NOT_SUPPORTED) have been pushed upstream.
Johan
Hi,
Quoted 2 lines · Johan Hedberg
This as well as the second patch (
ERROR_NOT_SUPPORTED) have been pushed upstream.
Actually I messed up with which patch is which and also pushed the one I didn't really like (the NOT_SUPPORTED one). So all nine patches are now upstream. However, as I pointed out in the other mail, please consider the drawback of making completely generic functions for all errors. In some cases it might make sense to att least be able to provide a context specific custom message (and I'd be glad to accept patches that do that).
Johan