summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-11-26 13:43:17 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-11-26 13:43:17 +0000
commit7e88afe4f8307c092172ff3c3b76c2f95ab00293 (patch)
treebdc418344c1e1f724421120bdeeeab0dd7fa3ce5 /network
parent4392fbd3d96e2eea0d91f0eb9fd059ab38255986 (diff)
Update services to new error codes and helper functions
Diffstat (limited to 'network')
-rw-r--r--network/Makefile.am2
-rw-r--r--network/connection.c20
-rw-r--r--network/error.c82
-rw-r--r--network/error.h35
-rw-r--r--network/manager.c60
-rw-r--r--network/server.c18
6 files changed, 52 insertions, 165 deletions
diff --git a/network/Makefile.am b/network/Makefile.am
index c8ca039e..2f8a7c3d 100644
--- a/network/Makefile.am
+++ b/network/Makefile.am
@@ -11,7 +11,7 @@ servicedir = $(libdir)/bluetooth
service_PROGRAMS = bluetoothd-service-network
bluetoothd_service_network_SOURCES = main.c \
- manager.h manager.c error.h error.c \
+ manager.h manager.c \
server.h server.c bridge.h bridge.c \
connection.h connection.c common.h common.c
diff --git a/network/connection.c b/network/connection.c
index 933cdd98..1628a038 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -181,7 +181,7 @@ static gboolean bnep_connect_cb(GIOChannel *chan, GIOCondition cond,
failed:
if (nc->state != DISCONNECTED) {
nc->state = DISCONNECTED;
- err_connection_failed(connection, nc->msg, "bnep failed");
+ error_connection_attempt_failed(connection, nc->msg, EIO);
g_io_channel_close(chan);
}
return FALSE;
@@ -254,7 +254,7 @@ static gboolean l2cap_connect_cb(GIOChannel *chan,
return FALSE;
failed:
nc->state = DISCONNECTED;
- err_connection_failed(connection, nc->msg, strerror(errno));
+ error_connection_attempt_failed(connection, nc->msg, errno);
g_io_channel_close(chan);
return FALSE;
}
@@ -383,7 +383,7 @@ static DBusHandlerResult get_name(DBusConnection *conn, DBusMessage *msg,
DBusMessage *reply;
if (!nc->name) {
- err_failed(conn, msg, "Cannot find service name");
+ error_failed(conn, msg, "Cannot find service name");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -405,7 +405,7 @@ static DBusHandlerResult get_description(DBusConnection *conn,
DBusMessage *reply;
if (!nc->desc) {
- err_failed(conn, msg, "Cannot find service description");
+ error_failed(conn, msg, "Cannot find service description");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -427,7 +427,7 @@ static DBusHandlerResult get_interface(DBusConnection *conn, DBusMessage *msg,
DBusMessage *reply;
if (nc->state != CONNECTED) {
- err_failed(conn, msg, "Device not connected");
+ error_failed(conn, msg, "Device not connected");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -449,14 +449,14 @@ static DBusHandlerResult connection_connect(DBusConnection *conn,
DBusError derr;
if (nc->state != DISCONNECTED) {
- err_failed(conn, msg, "Device already connected");
+ error_failed(conn, msg, "Device already connected");
return DBUS_HANDLER_RESULT_HANDLED;
}
dbus_error_init(&derr);
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -482,7 +482,7 @@ fail:
nc->msg = NULL;
}
nc->state = DISCONNECTED;
- err_connection_failed(conn, msg, strerror(errno));
+ error_connection_attempt_failed(conn, msg, errno);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -493,7 +493,7 @@ static DBusHandlerResult connection_cancel(DBusConnection *conn,
DBusMessage *reply;
if (nc->state != CONNECTING) {
- err_failed(conn, msg, "Device has no pending connect");
+ error_failed(conn, msg, "Device has no pending connect");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -512,7 +512,7 @@ static DBusHandlerResult connection_disconnect(DBusConnection *conn,
DBusMessage *reply;
if (nc->state != CONNECTED) {
- err_failed(conn, msg, "Device not connected");
+ error_failed(conn, msg, "Device not connected");
return DBUS_HANDLER_RESULT_HANDLED;
}
diff --git a/network/error.c b/network/error.c
deleted file mode 100644
index 24b3d124..00000000
--- a/network/error.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <dbus/dbus.h>
-
-#include "dbus.h"
-#include "error.h"
-
-#define NETWORK_ERROR_INTERFACE "org.bluez.network.Error"
-
-DBusHandlerResult err_does_not_exist(DBusConnection *conn, DBusMessage *msg,
- const char *str)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE ".DoesNotExist", str));
-}
-
-DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
- const char *str)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE ".Failed", str));
-}
-
-DBusHandlerResult err_connection_failed(DBusConnection *conn,
- DBusMessage *msg, const char *str)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE".ConnectionAttemptFailed",
- str));
-}
-
-DBusHandlerResult err_invalid_args(DBusConnection *conn,
- DBusMessage *msg, const char *str)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE ".InvalidArguments", str));
-}
-
-DBusHandlerResult err_not_supported(DBusConnection *conn, DBusMessage *msg)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE ".NotSupported",
- "The service is not supported by the remote device"));
-}
-
-DBusHandlerResult err_already_exists(DBusConnection *conn,
- DBusMessage *msg, const char *str)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- NETWORK_ERROR_INTERFACE ".AlreadyExists", str));
-}
diff --git a/network/error.h b/network/error.h
deleted file mode 100644
index d4162d5c..00000000
--- a/network/error.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-DBusHandlerResult err_does_not_exist(DBusConnection *conn,
- DBusMessage *msg, const char *str);
-DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
- const char *str);
-DBusHandlerResult err_connection_failed(DBusConnection *conn,
- DBusMessage *msg, const char *str);
-
-DBusHandlerResult err_invalid_args(DBusConnection *conn,
- DBusMessage *msg, const char *str);
-DBusHandlerResult err_not_supported(DBusConnection *conn, DBusMessage *msg);
-DBusHandlerResult err_already_exists(DBusConnection *conn,
- DBusMessage *msg, const char *str);
diff --git a/network/manager.c b/network/manager.c
index 6355f032..5855cf1f 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -171,19 +171,19 @@ static DBusHandlerResult remove_path(DBusConnection *conn,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &path,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
l = g_slist_find_custom(*list, path, (GCompareFunc) strcmp);
if (!l)
- return err_does_not_exist(conn, msg, "Path doesn't exist");
+ return error_does_not_exist(conn, msg, "Path doesn't exist");
/* Remove references from the storage */
if (*list == connection_paths) {
if (connection_has_pending(path))
- return err_failed(conn, msg, "Connection is Busy");
+ return error_failed(conn, msg, "Connection is Busy");
connection_remove_stored(path);
/* Reset default connection */
@@ -226,11 +226,13 @@ static void pan_record_reply(DBusPendingCall *call, void *data)
dbus_error_init(&derr);
if (dbus_set_error_from_message(&derr, reply)) {
+ /* FIXME: forward error as is */
if (dbus_error_has_name(&derr,
"org.bluez.Error.ConnectionAttemptFailed"))
- err_connection_failed(pr->conn, pr->msg, derr.message);
+ error_connection_attempt_failed(pr->conn, pr->msg,
+ EINVAL);
else
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
error("GetRemoteServiceRecord failed: %s(%s)", derr.name,
derr.message);
@@ -240,13 +242,13 @@ static void pan_record_reply(DBusPendingCall *call, void *data)
if (!dbus_message_get_args(reply, &derr,
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &rec_bin, &len,
DBUS_TYPE_INVALID)) {
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
error("%s: %s", derr.name, derr.message);
goto fail;
}
if (len == 0) {
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
error("Invalid PAN service record length");
goto fail;
}
@@ -276,7 +278,7 @@ static void pan_record_reply(DBusPendingCall *call, void *data)
if (connection_register(pr->path, &pr->src, &pr->dst, pr->id, name,
desc) < 0) {
- err_failed(pr->conn, pr->msg, "D-Bus path registration failed");
+ error_failed(pr->conn, pr->msg, "D-Bus path registration failed");
goto fail;
}
@@ -334,11 +336,13 @@ static void pan_handle_reply(DBusPendingCall *call, void *data)
dbus_error_init(&derr);
if (dbus_set_error_from_message(&derr, reply)) {
+ /* FIXME : forward error as is */
if (dbus_error_has_name(&derr,
"org.bluez.Error.ConnectionAttemptFailed"))
- err_connection_failed(pr->conn, pr->msg, derr.message);
+ error_connection_attempt_failed(pr->conn, pr->msg,
+ EINVAL);
else
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
error("GetRemoteServiceHandles: %s(%s)", derr.name,
derr.message);
@@ -348,18 +352,18 @@ static void pan_handle_reply(DBusPendingCall *call, void *data)
if (!dbus_message_get_args(reply, &derr,
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &phandle,
&len, DBUS_TYPE_INVALID)) {
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
error("%s: %s", derr.name, derr.message);
goto fail;
}
if (!len) {
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
goto fail;
}
if (get_record(pr, *phandle, pan_record_reply) < 0) {
- err_not_supported(pr->conn, pr->msg);
+ error_not_supported(pr->conn, pr->msg);
goto fail;
}
@@ -420,7 +424,7 @@ static DBusHandlerResult find_server(DBusConnection *conn,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -432,7 +436,7 @@ static DBusHandlerResult find_server(DBusConnection *conn,
}
if (list == NULL) {
- err_failed(conn, msg, "No such server");
+ error_does_not_exist(conn, msg, "No such server");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -483,7 +487,7 @@ static DBusHandlerResult find_connection(DBusConnection *conn,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -491,7 +495,7 @@ static DBusHandlerResult find_connection(DBusConnection *conn,
list = find_connection_pattern(conn, pattern);
if (list == NULL) {
- err_failed(conn, msg, "No such connection");
+ error_does_not_exist(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -579,21 +583,21 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
DBUS_TYPE_STRING, &addr,
DBUS_TYPE_STRING, &str,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
id = bnep_service_id(str);
if (id != BNEP_SVC_GN && id != BNEP_SVC_NAP && id != BNEP_SVC_PANU)
- return err_invalid_args(conn, msg, "Not supported");
+ return error_invalid_arguments(conn, msg, "Not supported");
snprintf(key, 32, "%s#%s", addr, bnep_name(id));
/* Checks if the connection was already been made */
for (l = connection_paths; l; l = l->next) {
if (connection_find_data(l->data, key) == 0) {
- err_already_exists(conn, msg,
+ error_already_exists(conn, msg,
"Connection Already exists");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -602,14 +606,14 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
bacpy(&src, BDADDR_ANY);
dev_id = hci_get_route(&src);
if (dev_id < 0 || hci_devba(dev_id, &src) < 0)
- return err_failed(conn, msg, "Adapter not available");
+ return error_failed(conn, msg, "Adapter not available");
pr = g_new0(struct pending_reply, 1);
pr->adapter_path = find_adapter(conn, &src);
if (!pr->adapter_path) {
pending_reply_free (pr);
- return err_failed(conn, msg, "Adapter not available");
+ return error_failed(conn, msg, "Adapter not available");
}
pr->conn = dbus_connection_ref(conn);
@@ -623,7 +627,7 @@ static DBusHandlerResult create_connection(DBusConnection *conn,
NETWORK_PATH"/connection%d", net_uid++);
if (get_handles(pr, pan_handle_reply) < 0)
- return err_not_supported(conn, msg);
+ return error_not_supported(conn, msg);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -642,7 +646,7 @@ static DBusHandlerResult last_connection(DBusConnection *conn,
if (connection_paths == NULL ||
g_slist_length (connection_paths) == 0) {
- err_does_not_exist(conn, msg, "No such connection");
+ error_does_not_exist(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -666,7 +670,7 @@ static DBusHandlerResult default_connection(DBusConnection *conn,
if (connection_paths == NULL ||
g_slist_length (connection_paths) == 0) {
- err_does_not_exist(conn, msg, "No such connection");
+ error_does_not_exist(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -700,14 +704,14 @@ static DBusHandlerResult change_default_connection(DBusConnection *conn,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
if (connection_paths == NULL ||
g_slist_length (connection_paths) == 0) {
- err_does_not_exist(conn, msg, "No such connection");
+ error_does_not_exist(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -718,7 +722,7 @@ static DBusHandlerResult change_default_connection(DBusConnection *conn,
list = find_connection_pattern(conn, pattern);
if (list == NULL) {
- err_failed(conn, msg, "No such connection");
+ error_does_not_exist(conn, msg, "No such connection");
return DBUS_HANDLER_RESULT_HANDLED;
}
else
diff --git a/network/server.c b/network/server.c
index 8c7bfb0d..a335569c 100644
--- a/network/server.c
+++ b/network/server.c
@@ -849,14 +849,14 @@ static DBusHandlerResult enable(DBusConnection *conn,
DBusMessage *reply;
if (ns->enable)
- return err_already_exists(conn, msg, "Server already enabled");
+ return error_already_exists(conn, msg, "Server already enabled");
if (bacmp(&ns->src, BDADDR_ANY) == 0) {
int dev_id;
dev_id = hci_get_route(&ns->src);
if ((dev_id < 0) || (hci_devba(dev_id, &ns->src) < 0))
- return err_failed(conn, msg, "Adapter not available");
+ return error_failed(conn, msg, "Adapter not available");
/* Store the server info */
server_store(ns->path);
@@ -870,7 +870,7 @@ static DBusHandlerResult enable(DBusConnection *conn,
ns->record_id = add_server_record(ns);
if (!ns->record_id) {
dbus_message_unref(reply);
- return err_failed(conn, msg,
+ return error_failed(conn, msg,
"service record registration failed");
}
@@ -904,7 +904,7 @@ static DBusHandlerResult disable(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (!ns->enable)
- return err_failed(conn, msg, "Not enabled");
+ return error_failed(conn, msg, "Not enabled");
/* Remove the service record */
if (ns->record_id) {
@@ -956,13 +956,13 @@ static DBusHandlerResult set_name(DBusConnection *conn,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
if (!name || (strlen(name) == 0))
- return err_invalid_args(conn, msg, "Invalid name");
+ return error_invalid_arguments(conn, msg, "Invalid name");
if (ns->name)
g_free(ns->name);
@@ -971,7 +971,7 @@ static DBusHandlerResult set_name(DBusConnection *conn,
if (ns->enable) {
if (update_server_record(ns) < 0) {
dbus_message_unref(reply);
- return err_failed(conn, msg,
+ return error_failed(conn, msg,
"Service record attribute update failed");
}
}
@@ -1022,14 +1022,14 @@ static DBusHandlerResult set_routing(DBusConnection *conn, DBusMessage *msg,
if (!dbus_message_get_args(msg, &derr,
DBUS_TYPE_STRING, &iface,
DBUS_TYPE_INVALID)) {
- err_invalid_args(conn, msg, derr.message);
+ error_invalid_arguments(conn, msg, derr.message);
dbus_error_free(&derr);
return DBUS_HANDLER_RESULT_HANDLED;
}
/* FIXME: Check if the interface is valid/UP */
if (!iface || (strlen(iface) == 0))
- return err_invalid_args(conn, msg, "Invalid interface");
+ return error_invalid_arguments(conn, msg, "Invalid interface");
if (ns->iface)
g_free(ns->iface);