diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-02-26 16:24:07 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-02-26 16:24:07 +0000 |
commit | a7f1185d9a36357f9d32c23d2f27ac6031dc1b08 (patch) | |
tree | 67e3b1ff930af9546c9a47832ca7b7096d3bd0e7 /hcid | |
parent | eaf7c01776d820bad2b306ffefd93362b3194522 (diff) |
First update to new error messages
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-device.c | 175 | ||||
-rw-r--r-- | hcid/dbus-error.c | 19 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 37 | ||||
-rw-r--r-- | hcid/dbus.c | 44 | ||||
-rw-r--r-- | hcid/dbus.h | 4 |
5 files changed, 186 insertions, 93 deletions
diff --git a/hcid/dbus-device.c b/hcid/dbus-device.c index eb37deaf..7dc16b0e 100644 --- a/hcid/dbus-device.c +++ b/hcid/dbus-device.c @@ -79,10 +79,15 @@ static DBusMessage *handle_dev_get_address_req(DBusMessage *msg, void *data) struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[18], *str_ptr = str; + int err; - get_device_address(dbus_data->dev_id, str, sizeof(str)); + err = get_device_address(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -95,10 +100,15 @@ static DBusMessage *handle_dev_get_version_req(DBusMessage *msg, void *data) struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[20], *str_ptr = str; + int err; - get_device_version(dbus_data->dev_id, str, sizeof(str)); + err = get_device_version(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -111,10 +121,15 @@ static DBusMessage *handle_dev_get_revision_req(DBusMessage *msg, void *data) struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[64], *str_ptr = str; + int err; - get_device_revision(dbus_data->dev_id, str, sizeof(str)); + err = get_device_revision(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -127,10 +142,15 @@ static DBusMessage *handle_dev_get_manufacturer_req(DBusMessage *msg, void *data struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[64], *str_ptr = str; + int err; - get_device_manufacturer(dbus_data->dev_id, str, sizeof(str)); + err = get_device_manufacturer(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -143,10 +163,15 @@ static DBusMessage *handle_dev_get_company_req(DBusMessage *msg, void *data) struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[64], *str_ptr = str; + int err; - get_device_company(dbus_data->dev_id, str, sizeof(str)); + err = get_device_company(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -161,6 +186,8 @@ static DBusMessage *handle_dev_get_features_req(DBusMessage *msg, void *data) DBusMessageIter array_iter; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_iter_init_append(reply, &iter); @@ -197,6 +224,8 @@ static DBusMessage *handle_dev_get_mode_req(DBusMessage *msg, void *data) } reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &scan_mode, DBUS_TYPE_INVALID); @@ -207,7 +236,7 @@ static DBusMessage *handle_dev_get_mode_req(DBusMessage *msg, void *data) static DBusMessage *handle_dev_set_mode_req(DBusMessage *msg, void *data) { const struct hci_dbus_data *dbus_data = data; - DBusMessage *reply = NULL; + DBusMessage *reply; const char* scan_mode; uint8_t hci_mode; const uint8_t current_mode = dbus_data->mode; @@ -229,10 +258,8 @@ static DBusMessage *handle_dev_set_mode_req(DBusMessage *msg, void *data) return bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM); dd = hci_open_dev(dbus_data->dev_id); - if (dd < 0) { - syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV); - } + if (dd < 0) + return error_no_such_device(msg); /* Check if the new requested mode is different from the current */ if (current_mode != hci_mode) { @@ -250,21 +277,22 @@ static DBusMessage *handle_dev_set_mode_req(DBusMessage *msg, void *data) if (hci_send_req(dd, &rq, 100) < 0) { syslog(LOG_ERR, "Sending write scan enable command failed: %s (%d)", strerror(errno), errno); - reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno); - goto failed; + hci_close_dev(dd); + return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno); } if (status) { syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", status); - reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET | status); - goto failed; + hci_close_dev(dd); + return bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET | status); } } - reply = dbus_message_new_method_return(msg); + hci_close_dev(dd); -failed: - close(dd); + reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); return reply; } @@ -272,9 +300,11 @@ failed: static DBusMessage *handle_dev_get_discoverable_to_req(DBusMessage *msg, void *data) { const struct hci_dbus_data *dbus_data = data; - DBusMessage *reply = NULL; + DBusMessage *reply; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_UINT32, &dbus_data->discoverable_timeout, DBUS_TYPE_INVALID); @@ -285,7 +315,7 @@ static DBusMessage *handle_dev_get_discoverable_to_req(DBusMessage *msg, void *d static DBusMessage *handle_dev_set_discoverable_to_req(DBusMessage *msg, void *data) { struct hci_dbus_data *dbus_data = data; - DBusMessage *reply = NULL; + DBusMessage *reply; DBusMessageIter iter; uint32_t timeout; @@ -295,6 +325,8 @@ static DBusMessage *handle_dev_set_discoverable_to_req(DBusMessage *msg, void *d dbus_data->discoverable_timeout = timeout; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); return reply; } @@ -302,7 +334,7 @@ static DBusMessage *handle_dev_set_discoverable_to_req(DBusMessage *msg, void *d static DBusMessage *handle_dev_is_connectable_req(DBusMessage *msg, void *data) { const struct hci_dbus_data *dbus_data = data; - DBusMessage *reply = NULL; + DBusMessage *reply; const uint8_t hci_mode = dbus_data->mode; dbus_bool_t connectable = FALSE; @@ -310,6 +342,8 @@ static DBusMessage *handle_dev_is_connectable_req(DBusMessage *msg, void *data) connectable = TRUE; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &connectable, DBUS_TYPE_INVALID); @@ -320,7 +354,7 @@ static DBusMessage *handle_dev_is_connectable_req(DBusMessage *msg, void *data) static DBusMessage *handle_dev_is_discoverable_req(DBusMessage *msg, void *data) { const struct hci_dbus_data *dbus_data = data; - DBusMessage *reply = NULL; + DBusMessage *reply; const uint8_t hci_mode = dbus_data->mode; dbus_bool_t discoverable = FALSE; @@ -328,6 +362,8 @@ static DBusMessage *handle_dev_is_discoverable_req(DBusMessage *msg, void *data) discoverable = TRUE; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &discoverable, DBUS_TYPE_INVALID); @@ -341,6 +377,8 @@ static DBusMessage *handle_dev_get_major_class_req(DBusMessage *msg, void *data) const char *str_ptr = "computer"; reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); /*FIXME: Check the real device major class */ dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, @@ -359,19 +397,21 @@ static DBusMessage *handle_dev_get_minor_class_req(DBusMessage *msg, void *data) int dd; dd = hci_open_dev(dbus_data->dev_id); - if (dd < 0) { - syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV); - } + if (dd < 0) + return error_no_such_device(msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)", dbus_data->dev_id, strerror(errno), errno); hci_close_dev(dd); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno); + return error_generic(msg, -errno); } + hci_close_dev(dd); + reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); /* FIXME: Currently, only computer major class is supported */ if ((cls[1] & 0x1f) != 1) @@ -389,8 +429,6 @@ failed: dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); - hci_close_dev(dd); - return reply; } @@ -521,10 +559,15 @@ static DBusMessage *handle_dev_get_name_req(DBusMessage *msg, void *data) struct hci_dbus_data *dbus_data = data; DBusMessage *reply; char str[249], *str_ptr = str; + int err; - get_device_name(dbus_data->dev_id, str, sizeof(str)); + err = get_device_name(dbus_data->dev_id, str, sizeof(str)); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -539,6 +582,7 @@ static DBusMessage *handle_dev_set_name_req(DBusMessage *msg, void *data) DBusMessage *reply; bdaddr_t bdaddr; char *str_ptr; + int err; dbus_message_iter_init(msg, &iter); dbus_message_iter_get_basic(&iter, &str_ptr); @@ -552,9 +596,13 @@ static DBusMessage *handle_dev_set_name_req(DBusMessage *msg, void *data) write_local_name(&bdaddr, str_ptr); - set_device_name(dbus_data->dev_id, str_ptr); + err = set_device_name(dbus_data->dev_id, str_ptr); + if (err < 0) + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); return reply; } @@ -591,14 +639,16 @@ static DBusMessage *handle_dev_get_remote_manufacturer_req(DBusMessage *msg, voi if (!str) return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | ENXIO); - reply = dbus_message_new_method_return(msg); - compid = atoi(str); free(str); str = bt_compidtostr(compid); + reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); @@ -614,6 +664,7 @@ static DBusMessage *handle_dev_get_remote_company_req(DBusMessage *msg, void *da dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str_bdaddr, DBUS_TYPE_INVALID); + str2ba(str_bdaddr, &bdaddr); ba2oui(&bdaddr, oui); @@ -622,10 +673,15 @@ static DBusMessage *handle_dev_get_remote_company_req(DBusMessage *msg, void *da return bluez_new_failure_msg(msg, BLUEZ_EDBUS_RECORD_NOT_FOUND); reply = dbus_message_new_method_return(msg); + if (!reply) { + reply = error_out_of_memory(msg); + goto done; + } dbus_message_append_args(reply, DBUS_TYPE_STRING, &tmp, DBUS_TYPE_INVALID); +done: free(tmp); return reply; @@ -655,10 +711,15 @@ static DBusMessage *handle_dev_get_remote_name_req(DBusMessage *msg, void *data) return bluez_new_failure_msg(msg, BLUEZ_EDBUS_RECORD_NOT_FOUND); reply = dbus_message_new_method_return(msg); + if (!reply) { + reply = error_out_of_memory(msg); + goto done; + } dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); +done: free(name); return reply; @@ -680,9 +741,11 @@ static DBusMessage *handle_dev_get_remote_alias_req(DBusMessage *msg, void *data err = get_device_alias(dbus_data->dev_id, &bdaddr, str, sizeof(str)); if (err < 0) - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | -err); + return error_generic(msg, -err); reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); dbus_message_append_args(reply, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID); @@ -698,6 +761,7 @@ static DBusMessage *handle_dev_set_remote_alias_req(DBusMessage *msg, void *data DBusMessage *reply, *signal; char *str_ptr, *addr_ptr; bdaddr_t bdaddr; + int err; dbus_message_iter_init(msg, &iter); dbus_message_iter_get_basic(&iter, &addr_ptr); @@ -711,7 +775,9 @@ static DBusMessage *handle_dev_set_remote_alias_req(DBusMessage *msg, void *data str2ba(addr_ptr, &bdaddr); - set_device_alias(dbus_data->dev_id, &bdaddr, str_ptr); + err = set_device_alias(dbus_data->dev_id, &bdaddr, str_ptr); + if (err < 0) + return error_generic(msg, -err); signal = dev_signal_factory(dbus_data->dev_id, DEV_SIG_REMOTE_ALIAS_CHANGED, DBUS_TYPE_STRING, &addr_ptr, @@ -724,6 +790,8 @@ static DBusMessage *handle_dev_set_remote_alias_req(DBusMessage *msg, void *data } reply = dbus_message_new_method_return(msg); + if (!reply) + return error_out_of_memory(msg); return reply; } @@ -748,10 +816,15 @@ static DBusMessage *handle_dev_last_seen_req(DBusMessage *msg, void *data) return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | ENXIO); reply = dbus_message_new_method_return(msg); + if (!reply) { + reply = error_out_of_memory(msg); + goto done; + } dbus_message_append_args(reply, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); +done: free(str); return reply; @@ -777,10 +850,15 @@ static DBusMessage *handle_dev_last_used_req(DBusMessage *msg, void *data) return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | ENXIO); reply = dbus_message_new_method_return(msg); + if (!reply) { + reply = error_out_of_memory(msg); + goto done; + } dbus_message_append_args(reply, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); +done: free(str); return reply; @@ -798,9 +876,8 @@ static DBusMessage *handle_dev_create_bonding_req(DBusMessage *msg, void *data) bdaddr_t bdaddr; int dd, dev_id; - dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &str_bdaddr, - DBUS_TYPE_INVALID); + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str_bdaddr, + DBUS_TYPE_INVALID); str2ba(str_bdaddr, &bdaddr); @@ -814,7 +891,7 @@ static DBusMessage *handle_dev_create_bonding_req(DBusMessage *msg, void *data) dd = hci_open_dev(dev_id); if (dd < 0) - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV); + return error_no_such_device(msg); cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info)); if (!cr) { @@ -875,7 +952,7 @@ static DBusMessage *handle_dev_remove_bonding_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV); + return error_no_such_device(msg); get_device_address(dbus_data->dev_id, addr, sizeof(addr)); @@ -1075,11 +1152,8 @@ static DBusMessage *handle_dev_discover_req(DBusMessage *msg, void *data) int dd; dd = hci_open_dev(dbus_data->dev_id); - if (dd < 0) { - syslog(LOG_ERR, "Unable to open device %d: %s (%d)", - dbus_data->dev_id, strerror(errno), errno); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno); - } + if (dd < 0) + return error_no_such_device(msg); memset(&cp, 0, sizeof(cp)); cp.lap[0] = lap & 0xff; @@ -1121,11 +1195,8 @@ static DBusMessage *handle_dev_discover_cancel_req(DBusMessage *msg, void *data) int dd; dd = hci_open_dev(dbus_data->dev_id); - if (dd < 0) { - syslog(LOG_ERR, "Unable to open device %d: %s (%d)", - dbus_data->dev_id, strerror(errno), errno); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno); - } + if (dd < 0) + return error_no_such_device(msg); memset(&rq, 0, sizeof(rq)); rq.ogf = OGF_LINK_CTL; @@ -1226,7 +1297,8 @@ DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void * signature = dbus_message_get_signature(msg); iface = dbus_message_get_interface(msg); - syslog(LOG_INFO, "[%s,%d] path:%s, method:%s", __PRETTY_FUNCTION__, __LINE__, dbus_message_get_path(msg), method); + syslog(LOG_INFO, "Device path:%s method:%s", + dbus_message_get_path(msg), method); if (strcmp(DEVICE_INTERFACE, iface)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -1261,7 +1333,8 @@ failed: if (reply) { if (!dbus_connection_send (conn, reply, NULL)) - syslog(LOG_ERR, "Can't send reply message!"); + syslog(LOG_ERR, "Can't send reply message"); + dbus_message_unref(reply); } diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index df8913ad..88e5bd7f 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -156,3 +156,22 @@ DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint32_t ecode) return reply; } + +DBusMessage *error_generic(DBusMessage *msg, int err) +{ + const char *str = strerror(err); + + return dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownError", str); +} + +DBusMessage *error_out_of_memory(DBusMessage *msg) +{ + return dbus_message_new_error(msg, ERROR_INTERFACE ".OutOfMemory", + "Out of memory"); +} + +DBusMessage *error_no_such_device(DBusMessage *msg) +{ + return dbus_message_new_error(msg, ERROR_INTERFACE ".NoSuchDevice", + "No such device"); +} diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 47160b04..4e6b98c3 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -46,34 +46,31 @@ static DBusMessage *handle_mgr_list_devices_req(DBusMessage *msg, void *data) DBusMessage *reply; struct hci_dev_list_req *dl; struct hci_dev_req *dr; - int i, sk = -1; + int i, sk; sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); - if (sk < 0) { - syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno); - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno); - } + if (sk < 0) + return error_generic(msg, errno); dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl)); if (!dl) { - syslog(LOG_ERR, "Can't allocate memory"); close(sk); - return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM); + return error_out_of_memory(msg); } dl->dev_num = HCI_MAX_DEV; dr = dl->dev_req; if (ioctl(sk, HCIGETDEVLIST, dl) < 0) { - reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno); + reply = error_generic(msg, errno); goto failed; } dr = dl->dev_req; reply = dbus_message_new_method_return(msg); - if (reply == NULL) { - syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return"); + if (!reply) { + reply = error_out_of_memory(msg); goto failed; } @@ -115,13 +112,11 @@ static DBusMessage *handle_mgr_default_device_req(DBusMessage *msg, void *data) int default_dev = get_default_dev_id(); if (default_dev < 0) - return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV); + return error_no_such_device(msg); reply = dbus_message_new_method_return(msg); - if (!reply) { - syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return"); - return reply; - } + if (!reply) + return error_out_of_memory(msg); snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, default_dev); @@ -132,8 +127,8 @@ static DBusMessage *handle_mgr_default_device_req(DBusMessage *msg, void *data) } static const struct service_data mgr_services[] = { - { MGR_LIST_DEVICES, handle_mgr_list_devices_req, MGR_LIST_DEVICES_SIGNATURE }, - { MGR_DEFAULT_DEVICE, handle_mgr_default_device_req, MGR_DEFAULT_DEVICE_SIGNATURE }, + { MGR_LIST_DEVICES, handle_mgr_list_devices_req, MGR_LIST_DEVICES_SIGNATURE }, + { MGR_DEFAULT_DEVICE, handle_mgr_default_device_req, MGR_DEFAULT_DEVICE_SIGNATURE }, { NULL, NULL, NULL } }; @@ -151,9 +146,10 @@ DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void method = dbus_message_get_member(msg); signature = dbus_message_get_signature(msg); - syslog(LOG_INFO, "[%s,%d] path:%s, method:%s", __PRETTY_FUNCTION__, __LINE__, dbus_message_get_path(msg), method); + syslog(LOG_INFO, "Manager path:%s method:%s", + dbus_message_get_path(msg), method); - if (strcmp(iface, MANAGER_INTERFACE) != 0) + if (!strcmp(iface, MANAGER_INTERFACE)) return ret; for (handlers = mgr_services; handlers->name != NULL; handlers++) { @@ -175,7 +171,8 @@ DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void if (reply) { if (!dbus_connection_send (conn, reply, NULL)) - syslog(LOG_ERR, "Can't send reply message!"); + syslog(LOG_ERR, "Can't send reply message"); + dbus_message_unref(reply); } diff --git a/hcid/dbus.c b/hcid/dbus.c index d508bf76..fccac0b2 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -223,7 +223,7 @@ static gboolean register_dbus_path(const char *path, uint16_t path_id, uint16_t gboolean ret = FALSE; struct hci_dbus_data *data = NULL; - syslog(LOG_INFO, "[%s,%d] path:%s, fallback:%d", __PRETTY_FUNCTION__, __LINE__, path, fallback); + syslog(LOG_INFO, "Register path:%s fallback:%d", path, fallback); data = malloc(sizeof(struct hci_dbus_data)); if (data == NULL) { @@ -240,12 +240,12 @@ static gboolean register_dbus_path(const char *path, uint16_t path_id, uint16_t if (fallback) { if (!dbus_connection_register_fallback(connection, path, pvtable, data)) { - syslog(LOG_ERR, "DBUS failed to register %s fallback", path); + syslog(LOG_ERR, "D-Bus failed to register %s fallback", path); goto failed; } } else { if (!dbus_connection_register_object_path(connection, path, pvtable, data)) { - syslog(LOG_ERR, "DBUS failed to register %s object", path); + syslog(LOG_ERR, "D-Bus failed to register %s object", path); goto failed; } } @@ -263,13 +263,13 @@ static gboolean unregister_dbus_path(const char *path) { void *data; - syslog(LOG_INFO, "[%s,%d] path:%s", __PRETTY_FUNCTION__, __LINE__, path); + syslog(LOG_INFO, "Unregister path:%s", path); if (dbus_connection_get_object_path_data(connection, path, &data) && data) free(data); if (!dbus_connection_unregister_object_path (connection, path)) { - syslog(LOG_ERR, "DBUS failed to unregister %s object", path); + syslog(LOG_ERR, "D-Bus failed to unregister %s object", path); return FALSE; } @@ -375,7 +375,7 @@ gboolean hcid_dbus_unregister_device(uint16_t id) message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE, BLUEZ_MGR_DEV_REMOVED); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS remote name message"); + syslog(LOG_ERR, "Can't allocate D-Bus remote name message"); goto failed; } @@ -385,7 +385,7 @@ gboolean hcid_dbus_unregister_device(uint16_t id) DBUS_TYPE_INVALID); if (!dbus_connection_send(connection, message, NULL)) { - syslog(LOG_ERR, "Can't send D-BUS added device message"); + syslog(LOG_ERR, "Can't send D-Bus added device message"); goto failed; } @@ -419,7 +419,7 @@ void hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) message = dbus_message_new_method_call(PINAGENT_SERVICE_NAME, PINAGENT_PATH, PINAGENT_INTERFACE, PIN_REQUEST); if (message == NULL) { - syslog(LOG_ERR, "Couldn't allocate D-BUS message"); + syslog(LOG_ERR, "Couldn't allocate D-Bus message"); goto failed; } @@ -434,7 +434,7 @@ void hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) if (dbus_connection_send_with_reply(connection, message, &pending, TIMEOUT) == FALSE) { - syslog(LOG_ERR, "D-BUS send failed"); + syslog(LOG_ERR, "D-Bus send failed"); goto failed; } @@ -483,7 +483,7 @@ void hcid_dbus_bonding_created_complete(bdaddr_t *local, bdaddr_t *peer, const u message = dbus_message_new_signal(path, DEVICE_INTERFACE, name); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS remote name message"); + syslog(LOG_ERR, "Can't allocate D-Bus remote name message"); goto failed; } @@ -492,7 +492,7 @@ void hcid_dbus_bonding_created_complete(bdaddr_t *local, bdaddr_t *peer, const u DBUS_TYPE_INVALID); if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS remote name message"); + syslog(LOG_ERR, "Can't send D-Bus remote name message"); goto failed; } @@ -527,12 +527,12 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_SIG_DISCOVER_START); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message"); + syslog(LOG_ERR, "Can't allocate D-Bus inquiry start message"); goto failed; } if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS inquiry start message"); + syslog(LOG_ERR, "Can't send D-Bus inquiry start message"); goto failed; } @@ -564,12 +564,12 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_SIG_DISCOVER_COMPLETE); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message"); + syslog(LOG_ERR, "Can't allocate D-Bus inquiry complete message"); goto failed; } if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS inquiry complete message"); + syslog(LOG_ERR, "Can't send D-Bus inquiry complete message"); goto failed; } @@ -604,7 +604,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_SIG_DISCOVER_RESULT); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message"); + syslog(LOG_ERR, "Can't allocate D-Bus inquiry result message"); goto failed; } @@ -615,7 +615,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i DBUS_TYPE_INVALID); if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS inquiry result message"); + syslog(LOG_ERR, "Can't send D-Bus inquiry result message"); goto failed; } @@ -650,7 +650,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name) message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_SIG_REMOTE_NAME_CHANGED); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS remote name message"); + syslog(LOG_ERR, "Can't allocate D-Bus remote name message"); goto failed; } @@ -660,7 +660,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, char *name) DBUS_TYPE_INVALID); if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS remote name message"); + syslog(LOG_ERR, "Can't send D-Bus remote name message"); goto failed; } @@ -1108,7 +1108,7 @@ void hcid_dbus_setname_complete(bdaddr_t *local) signal = dev_signal_factory(id, DEV_SIG_NAME_CHANGED, DBUS_TYPE_STRING, &pname, DBUS_TYPE_INVALID); if (dbus_connection_send(connection, signal, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS %s signal", DEV_SIG_NAME_CHANGED); + syslog(LOG_ERR, "Can't send D-Bus %s signal", DEV_SIG_NAME_CHANGED); goto failed; } @@ -1204,7 +1204,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_SIG_MODE_CHANGED); if (message == NULL) { - syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message"); + syslog(LOG_ERR, "Can't allocate D-Bus inquiry complete message"); goto failed; } @@ -1213,7 +1213,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) DBUS_TYPE_INVALID); if (dbus_connection_send(connection, message, NULL) == FALSE) { - syslog(LOG_ERR, "Can't send D-BUS ModeChanged(%x) signal", rp.enable); + syslog(LOG_ERR, "Can't send D-Bus ModeChanged signal"); goto failed; } diff --git a/hcid/dbus.h b/hcid/dbus.h index 617d5006..c526e8e7 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -87,6 +87,10 @@ DBusConnection *get_dbus_connection(void); int get_default_dev_id(void); +DBusMessage *error_generic(DBusMessage *msg, int err); +DBusMessage *error_out_of_memory(DBusMessage *msg); +DBusMessage *error_no_such_device(DBusMessage *msg); + /*======================================================================== BlueZ D-Bus Manager service definitions "/org/bluez/Manager" *========================================================================*/ |