Fix coding styling issues in src/error.c
PATCH 1/7 Fix coding styling issues in src/error.c
--- src/error.c | 26 +++++++++----------------- 1 files changed, 9 insertions(+), 17 deletions(-)
src/error.c +9 -17
@@ -51,8 +51,7 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,DBusMessage *btd_error_invalid_args (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".InvalidArguments" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" ,"Invalid arguments in method call" ); }
@@ -64,49 +63,42 @@ DBusMessage *btd_error_busy(DBusMessage *msg)DBusMessage *btd_error_already_exists (DBusMessage *msg) { -return g_dbus_create_error (msg, -ERROR_INTERFACE ".AlreadyExists" , -"Already Exists" ); +return g_dbus_create_error (msg,ERROR_INTERFACE ".AlreadyExists" , +"Already Exists" ); }DBusMessage *btd_error_not_supported (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotSupported" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".NotSupported" ,"Operation is not supported" ); }DBusMessage *btd_error_not_connected (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotConnected" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".NotConnected" ,"Not Connected" ); }DBusMessage *btd_error_in_progress (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".InProgress" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".InProgress" ,"In Progress" ); }DBusMessage *btd_error_not_available (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotAvailable" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAvailable" ,"Operation currently not available" ); }DBusMessage *btd_error_does_not_exist (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".DoesNotExist" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".DoesNotExist" ,"Does Not Exist" ); }DBusMessage *btd_error_not_authorized (DBusMessage *msg) { -return g_dbus_create_error (msg,ERROR_INTERFACE -".NotAuthorized" , +return g_dbus_create_error (msg,ERROR_INTERFACE ".NotAuthorized" ,"Operation Not Authorized" ); }
Signature · 1 line
1.7.3.2
PATCH 2/7 convert errors to btd_error_not_authorized()
--- audio/gateway.c | 3 +-- audio/transport.c | 8 ++++---- network/connection.c | 2 +- serial/port.c | 2 +- serial/proxy.c | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-)
audio/gateway.c +1 -2
@@ -514,8 +514,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn, goto done;if (strcmp (gw->agent->name,dbus_message_get_sender (msg)) !=0 ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Permission denied" ); +return btd_error_not_authorized (msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
audio/transport.c +4 -4
@@ -443,10 +443,10 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg, owner =media_transport_find_owner (transport, sender);if (owner !=NULL ) -return error_failed (msg,strerror (EPERM )); +return btd_error_not_authorized (msg);if (media_transport_acquire (transport, accesstype) == FALSE) -return error_failed (msg,strerror (EPERM )); +return btd_error_not_authorized (msg); owner =media_owner_create (transport, msg, accesstype); req = g_new0(struct acquire_request, 1);
@@ -476,7 +476,7 @@ static DBusMessage *release(DBusConnection *conn, DBusMessage *msg, owner =media_transport_find_owner (transport, sender);if (owner ==NULL ) -return error_failed (msg,strerror (EPERM )); +return btd_error_not_authorized (msg);if (g_strcmp0 (owner->accesstype, accesstype) ==0 )media_owner_remove (owner);
@@ -484,7 +484,7 @@ static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,media_transport_release (transport, accesstype);g_strdelimit (owner->accesstype, accesstype,' ' ); }else -return error_failed (msg,strerror (EPERM )); +return btd_error_not_authorized (msg);return g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); }
network/connection.c +1 -1
@@ -438,7 +438,7 @@ static DBusMessage *connection_cancel(DBusConnection *conn,const char *caller =dbus_message_get_sender (msg);if (!g_str_equal (owner, caller)) -return not_permited (msg); +return btd_error_not_authorized (msg);connection_destroy (conn, nc);
serial/port.c +1 -1
@@ -538,7 +538,7 @@ static DBusMessage *port_disconnect(DBusConnection *conn, owner =dbus_message_get_sender (port->msg); caller =dbus_message_get_sender (msg);if (!g_str_equal (owner, caller)) -return failed (msg,"Operation not permited" ); +return btd_error_not_authorized (msg);port_release (port);
serial/proxy.c +2 -2
@@ -728,7 +728,7 @@ static DBusMessage *proxy_set_serial_params(DBusConnection *conn,/* Don't allow change TTY settings if it is open */ if (prx->local) -return failed (msg,"Not allowed" ); +return btd_error_not_authorized (msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ratestr,
@@ -1112,7 +1112,7 @@ static DBusMessage *remove_proxy(DBusConnection *conn, sender =dbus_message_get_sender (msg);if (g_strcmp0 (prx->owner, sender) !=0 ) -return failed (msg,"Permission denied" ); +return btd_error_not_authorized (msg);unregister_proxy (prx);
Signature · 1 line
1.7.3.2
PATCH 3/7 convert errors to btd_error_does_not_exist()
--- audio/gateway.c | 4 +--- audio/media.c | 3 +-- plugins/service.c | 2 +- src/device.c | 4 +--- 4 files changed, 4 insertions(+), 9 deletions(-)
audio/gateway.c +1 -3
@@ -522,9 +522,7 @@ static DBusMessage *unregister_agent(DBusConnection *conn,return btd_error_invalid_args (msg);if (strcmp (gw->agent->path, path) !=0 ) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".Failed" , -"Unknown object path" ); +return btd_error_does_not_exist (msg);g_dbus_remove_watch (device->conn, gw->agent->watch);
audio/media.c +1 -2
@@ -351,8 +351,7 @@ static DBusMessage *unregister_endpoint(DBusConnection *conn, DBusMessage *msg, endpoint =media_adapter_find_endpoint (adapter, sender, path,NULL );if (endpoint ==NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Endpoint not registered" ); +return btd_error_does_not_exist (msg);media_endpoint_remove (endpoint);
plugins/service.c +1 -1
@@ -600,7 +600,7 @@ static DBusMessage *request_authorization(DBusConnection *conn, sender =dbus_message_get_sender (msg);if (find_pending_by_sender (serv_adapter, sender)) -return failed (msg); +return btd_error_does_not_exist (msg); user_record =find_record (serv_adapter, handle, sender);if (!user_record) {
src/device.c +1 -3
@@ -723,9 +723,7 @@ static DBusMessage *cancel_discover(DBusConnection *conn,const char *requestor;if (!device->browse) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".Failed" , -"No pending discovery" ); +return btd_error_does_not_exist (msg);if (!dbus_message_is_method_call (device->browse->msg,DEVICE_INTERFACE ,"DiscoverServices" ))
Signature · 1 line
1.7.3.2
PATCH 4/7 convert error to btd_error_busy()
--- audio/source.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
audio/source.c +1 -2
@@ -425,8 +425,7 @@ static DBusMessage *source_disconnect(DBusConnection *conn,return btd_error_not_connected (msg);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 ) {DBusMessage *reply =dbus_message_new_method_return (msg);
Signature · 1 line
1.7.3.2
PATCH 5/7 convert error to btd_error_not_connected()
--- network/connection.c | 8 +------- serial/port.c | 2 +- src/device.c | 4 +--- 3 files changed, 3 insertions(+), 11 deletions(-)
network/connection.c +1 -7
@@ -123,12 +123,6 @@ static inline DBusMessage *already_connected(DBusMessage *msg) "Device already connected"); } -static inline DBusMessage *not_connected (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Device not connected" ); -} -static inline DBusMessage *not_permited (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
@@ -460,7 +454,7 @@ static DBusMessage *connection_disconnect(DBusConnection *conn,return connection_cancel (conn, msg, nc); } -return not_connected (msg); +return btd_error_not_connected (msg); } static DBusMessage *connection_get_properties(DBusConnection *conn,
serial/port.c +1 -1
@@ -533,7 +533,7 @@ static DBusMessage *port_disconnect(DBusConnection *conn,return btd_error_does_not_exist (msg);if (!port->listener_id) -return failed (msg,"Not connected" ); +return btd_error_not_connected (msg); owner =dbus_message_get_sender (port->msg); caller =dbus_message_get_sender (msg);
src/device.c +1 -3
@@ -799,9 +799,7 @@ static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,struct btd_device *device = user_data;if (!device->handle) -return g_dbus_create_error (msg, -ERROR_INTERFACE ".NotConnected" , -"Device is not connected" ); +return btd_error_not_connected (msg);device_request_disconnect (device, msg);
Signature · 1 line
1.7.3.2
PATCH 6/7 convert error to btd_error_not_supported()
--- input/device.c | 8 +------- network/connection.c | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)
input/device.c +1 -7
@@ -315,12 +315,6 @@ failed:return FALSE; } -static inline DBusMessage *not_supported (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" , -"Not supported" ); -} -static inline DBusMessage *already_connected (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyConnected",
@@ -937,7 +931,7 @@ static DBusMessage *input_device_connect(DBusConnection *conn, iconn =find_connection (idev->connections,"HID" );if (!iconn) -return not_supported (msg); +return btd_error_not_supported (msg);if (iconn->pending_connect)return btd_error_in_progress (msg);
network/connection.c +1 -1
@@ -393,7 +393,7 @@ static DBusMessage *connection_connect(DBusConnection *conn, id =bnep_service_id (svc); nc =find_connection (peer->connections, id);if (!nc) -return not_supported (msg); +return btd_error_not_supported (msg);if (nc->state !=DISCONNECTED )return already_connected (msg);
Signature · 1 line
1.7.3.2
PATCH 7/7 Add btd_error_already_connected()
--- audio/device.c | 4 +--- audio/headset.c | 8 ++------ audio/sink.c | 4 +--- audio/source.c | 4 +--- input/device.c | 8 +------- network/connection.c | 2 +- src/error.c | 6 ++++++ src/error.h | 1 + 8 files changed, 14 insertions(+), 23 deletions(-)
audio/device.c +1 -3
@@ -521,9 +521,7 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,if (priv->state ==AUDIO_STATE_CONNECTING )return btd_error_in_progress (msg);else if (priv->state ==AUDIO_STATE_CONNECTED ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".AlreadyConnected" , -"Already Connected" ); +return btd_error_already_connected (msg); dev->auto_connect = TRUE;
audio/headset.c +2 -6
@@ -1697,9 +1697,7 @@ static DBusMessage *hs_connect(DBusConnection *conn, DBusMessage *msg,if (hs->state ==HEADSET_STATE_CONNECTING )return btd_error_in_progress (msg);else if (hs->state >HEADSET_STATE_CONNECTING ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".AlreadyConnected" , -"Already Connected" ); +return btd_error_already_connected (msg);if (hs->hfp_handle && !ag.telephony_ready) return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady",
@@ -1806,9 +1804,7 @@ static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg, }return btd_error_busy (msg);case HEADSET_STATE_PLAYING : -return g_dbus_create_error (msg,ERROR_INTERFACE -".AlreadyConnected" , -"Device Already Connected" ); +return btd_error_already_connected (msg);case HEADSET_STATE_CONNECTED :default :break ;
audio/sink.c +1 -3
@@ -442,9 +442,7 @@ static DBusMessage *sink_connect(DBusConnection *conn,return btd_error_busy (msg);if (sink->stream_state >=AVDTP_STATE_OPEN ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".AlreadyConnected" , -"Device Already Connected" ); +return btd_error_already_connected (msg);if (!sink_setup_stream (sink,NULL )) return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
audio/source.c +1 -3
@@ -393,9 +393,7 @@ static DBusMessage *source_connect(DBusConnection *conn,return btd_error_busy (msg);if (source->stream_state >=AVDTP_STATE_OPEN ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".AlreadyConnected" , -"Device Already Connected" ); +return btd_error_already_connected (msg);if (!source_setup_stream (source,NULL )) return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
input/device.c +1 -7
@@ -315,12 +315,6 @@ failed:return FALSE; } -static inline DBusMessage *already_connected (DBusMessage *msg) -{ -return g_dbus_create_error (msg,ERROR_INTERFACE ".AlreadyConnected" , -"Already connected to a device" ); -} -static inline DBusMessage *connection_attempt_failed (DBusMessage *msg,const char *err) {
@@ -937,7 +931,7 @@ static DBusMessage *input_device_connect(DBusConnection *conn,return btd_error_in_progress (msg);if (is_connected (iconn)) -return already_connected (msg); +return btd_error_already_connected (msg); iconn->pending_connect =dbus_message_ref (msg); fake = iconn->fake;
network/connection.c +1 -1
@@ -396,7 +396,7 @@ static DBusMessage *connection_connect(DBusConnection *conn,return btd_error_not_supported (msg);if (nc->state !=DISCONNECTED ) -return already_connected (msg); +return btd_error_already_connected (msg); nc->io = bt_io_connect(BT_IO_L2CAP, connect_cb, nc, NULL, &err,
src/error.c +6 -0
@@ -79,6 +79,12 @@ DBusMessage *btd_error_not_connected(DBusMessage *msg) "Not Connected"); } +DBusMessage *btd_error_already_connected (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE ".AlreadyConnected" , +"Already Connected" ); +} +DBusMessage *btd_error_in_progress (DBusMessage *msg) { return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
src/error.h +1 -0
@@ -35,6 +35,7 @@ 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); +DBusMessage *btd_error_already_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
Hi Gustavo,
Quoted 3 lines · Gustavo F. Padovan
--- src/error.c | 26 +++++++++----------------- 1 files changed, 9 insertions(+), 17 deletions(-)
Thanks! All seven patches have been pushed upstream.
Johan