From 49f96ab96e2f7a0fabbb1c863fbca43b12b127ec Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 18 Jan 2007 11:41:32 +0000 Subject: Add file skeleton for database interface --- hcid/dbus-database.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 hcid/dbus-database.c (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c new file mode 100644 index 00000000..cf4cbff8 --- /dev/null +++ b/hcid/dbus-database.c @@ -0,0 +1,28 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 Marcel Holtmann + * + * + * 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 +#endif + +#include "dbus-database.h" -- cgit From 9932d3f27fb04f03c560525f312c67b15aeeb85e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 19 Jan 2007 23:48:01 +0000 Subject: Add skeleton for database methods --- hcid/dbus-database.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index cf4cbff8..3421c5b3 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -25,4 +25,74 @@ #include #endif +#include + +#include "dbus.h" +#include "hcid.h" +#include "dbus-common.h" +#include "dbus-error.h" #include "dbus-database.h" + +static DBusHandlerResult add_service_record(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + dbus_uint32_t handle = 0x12345; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + dbus_uint32_t handle = 0x12345; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + DBUS_TYPE_INVALID); + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult remove_service_record(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + +static struct service_data database_services[] = { + { "AddServiceRecord", add_service_record }, + { "AddServiceRecordFromXML", add_service_record_from_xml }, + { "RemoveServiceRecord", remove_service_record }, + { NULL, NULL } +}; + +DBusHandlerResult handle_database_method(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + service_handler_func_t handler; + + handler = find_service_handler(database_services, msg); + + if (handler) + return handler(conn, msg, data); + + return error_unknown_method(conn, msg); +} -- cgit From d2ba2cd658a794fc1f81da892bb483123f86fe95 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 00:35:54 +0000 Subject: Implement methods for database interface --- hcid/dbus-database.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 4 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 3421c5b3..ac7e07d3 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -25,25 +25,99 @@ #include #endif +#include +#include +#include + +#include +#include +#include + #include #include "dbus.h" #include "hcid.h" +#include "sdpd.h" +#include "sdp-xml.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-database.h" +static GSList *records = NULL; + +struct record_data { + uint32_t handle; + char *sender; +}; + +static struct record_data *find_record(uint32_t handle, const char *sender) +{ + GSList *list; + + for (list = records; list; list = list->next) { + struct record_data *data = list->data; + if (handle == data->handle && !strcmp(sender, data->sender)) + return data; + } + + return NULL; +} + +static void exit_callback(const char *name, void *user_data) +{ + struct record_data *user_record = user_data; + + records = g_slist_remove(records, user_record); + + remove_record_from_server(user_record->handle); + + free(user_record); +} + static DBusHandlerResult add_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - dbus_uint32_t handle = 0x12345; + DBusMessageIter iter, array; + const char *sender; + struct record_data *user_record; + const uint8_t *record; + uint32_t size = 0; + int len = -1; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &array); + + dbus_message_iter_get_fixed_array(&array, &record, &len); + if (len <= 0) + return error_invalid_arguments(conn, msg); + + user_record = malloc(sizeof(*user_record)); + if (!user_record) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + size = len; + + if (register_sdp_record((uint8_t *) record, size, + &user_record->handle) < 0) { + error("Failed to register service record"); + free(user_record); + return error_failed(conn, msg, errno); + } + + sender = dbus_message_get_sender(msg); + + user_record->sender = strdup(sender); + + records = g_slist_append(records, user_record); + + name_listener_add(conn, sender, exit_callback, user_record); reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); @@ -53,13 +127,46 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; - dbus_uint32_t handle = 0x12345; + const char *sender, *record; + struct record_data *user_record; + sdp_record_t *sdp_record; + + if (dbus_message_get_args(msg, NULL, + DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + user_record = malloc(sizeof(*user_record)); + if (!user_record) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + sdp_record = sdp_xml_parse_record(record, strlen(record)); + if (!sdp_record) { + error("Parsing of XML service record failed"); + free(user_record); + return error_failed(conn, msg, EIO); + } + + if (add_record_to_server(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + + sender = dbus_message_get_sender(msg); + + user_record->handle = sdp_record->handle; + user_record->sender = strdup(sender); + + records = g_slist_append(records, user_record); + + name_listener_add(conn, sender, exit_callback, user_record); reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); @@ -69,6 +176,25 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; + dbus_uint32_t handle; + const char *sender; + struct record_data *user_record; + + if (dbus_message_get_args(msg, NULL, + DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + user_record = find_record(handle, sender); + if (!user_record) + return error_not_available(conn, msg); + + name_listener_remove(conn, sender, exit_callback, user_record); + + remove_record_from_server(handle); + + free(user_record); reply = dbus_message_new_method_return(msg); if (!reply) -- cgit From 173a8dc856d0820fc670b713b3d054647cbd2b4b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 00:40:25 +0000 Subject: Clear newly created structures --- hcid/dbus-database.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index ac7e07d3..f526b60e 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -96,6 +96,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (!user_record) return DBUS_HANDLER_RESULT_NEED_MEMORY; + memset(user_record, 0, sizeof(*user_record)); + size = len; if (register_sdp_record((uint8_t *) record, size, @@ -139,6 +141,8 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (!user_record) return DBUS_HANDLER_RESULT_NEED_MEMORY; + memset(user_record, 0, sizeof(*user_record)); + sdp_record = sdp_xml_parse_record(record, strlen(record)); if (!sdp_record) { error("Parsing of XML service record failed"); -- cgit From a38538129fe3e061ee324c6e05cf0eb62b020513 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 01:12:39 +0000 Subject: Support internal and external SDP servers --- hcid/dbus-database.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index f526b60e..5da84cfa 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -43,6 +43,8 @@ #include "dbus-error.h" #include "dbus-database.h" +static int sdp_server_enable = 0; + static GSList *records = NULL; struct record_data { @@ -69,7 +71,10 @@ static void exit_callback(const char *name, void *user_data) records = g_slist_remove(records, user_record); - remove_record_from_server(user_record->handle); + if (sdp_server_enable) + remove_record_from_server(user_record->handle); + else + unregister_sdp_record(user_record->handle); free(user_record); } @@ -82,7 +87,6 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, const char *sender; struct record_data *user_record; const uint8_t *record; - uint32_t size = 0; int len = -1; dbus_message_iter_init(msg, &iter); @@ -98,13 +102,17 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, memset(user_record, 0, sizeof(*user_record)); - size = len; + if (sdp_server_enable) { + return error_failed(conn, msg, EIO); + } else { + uint32_t size = len; - if (register_sdp_record((uint8_t *) record, size, + if (register_sdp_binary((uint8_t *) record, size, &user_record->handle) < 0) { - error("Failed to register service record"); - free(user_record); - return error_failed(conn, msg, errno); + error("Failed to register service record"); + free(user_record); + return error_failed(conn, msg, errno); + } } sender = dbus_message_get_sender(msg); @@ -150,11 +158,20 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, return error_failed(conn, msg, EIO); } - if (add_record_to_server(sdp_record) < 0) { - error("Failed to register service record"); - free(user_record); - sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + if (sdp_server_enable) { + if (add_record_to_server(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + } else { + if (register_sdp_record(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } } sender = dbus_message_get_sender(msg); @@ -196,7 +213,10 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, name_listener_remove(conn, sender, exit_callback, user_record); - remove_record_from_server(handle); + if (sdp_server_enable) + remove_record_from_server(handle); + else + unregister_sdp_record(handle); free(user_record); @@ -226,3 +246,8 @@ DBusHandlerResult handle_database_method(DBusConnection *conn, return error_unknown_method(conn, msg); } + +void set_sdp_server_enable(void) +{ + sdp_server_enable = 1; +} -- cgit From 8cc5595d9091b484b9a4abe314c0f3ec055e0581 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 05:26:15 +0000 Subject: Make it possible to support an embedded GLib --- hcid/dbus-database.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 5da84cfa..ea275b7a 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -33,6 +33,8 @@ #include #include +#include + #include #include "dbus.h" -- cgit From 73e0b1b5e832010192ec6d57e2afa36de2c96299 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 21:25:35 +0000 Subject: Fix memory leaks in record handling --- hcid/dbus-database.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index ea275b7a..d2268878 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -78,6 +78,9 @@ static void exit_callback(const char *name, void *user_data) else unregister_sdp_record(user_record->handle); + if (user_record->sender) + free(user_record->sender); + free(user_record); } @@ -174,6 +177,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } + sdp_record_free(sdp_record); } sender = dbus_message_get_sender(msg); @@ -215,11 +219,16 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, name_listener_remove(conn, sender, exit_callback, user_record); + records = g_slist_remove(records, user_record); + if (sdp_server_enable) remove_record_from_server(handle); else unregister_sdp_record(handle); + if (user_record->sender) + free(user_record->sender); + free(user_record); reply = dbus_message_new_method_return(msg); -- cgit From 493ec449cf22b725252c86863f801a191afdbde8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 22 Jan 2007 01:35:23 +0000 Subject: Update binary record handling for database interface --- hcid/dbus-database.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index d2268878..1e0cee3e 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -91,8 +91,9 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, DBusMessageIter iter, array; const char *sender; struct record_data *user_record; + sdp_record_t *sdp_record; const uint8_t *record; - int len = -1; + int scanned, len = -1; dbus_message_iter_init(msg, &iter); dbus_message_iter_recurse(&iter, &array); @@ -108,7 +109,28 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, memset(user_record, 0, sizeof(*user_record)); if (sdp_server_enable) { - return error_failed(conn, msg, EIO); + sdp_record = sdp_extract_pdu(record, &scanned); + if (!sdp_record) { + error("Parsing of service record failed"); + free(user_record); + return error_failed(conn, msg, EIO); + } + + if (scanned != len) { + error("Size mismatch of service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + + if (add_record_to_server(sdp_record) < 0) { + error("Failed to register service record"); + free(user_record); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + + user_record->handle = sdp_record->handle; } else { uint32_t size = len; @@ -170,6 +192,8 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } + + user_record->handle = sdp_record->handle; } else { if (register_sdp_record(sdp_record) < 0) { error("Failed to register service record"); @@ -177,12 +201,14 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } + + user_record->handle = sdp_record->handle; + sdp_record_free(sdp_record); } sender = dbus_message_get_sender(msg); - user_record->handle = sdp_record->handle; user_record->sender = strdup(sender); records = g_slist_append(records, user_record); -- cgit From 3021d8e125537fd3b14a5d50e0710bce17f8d198 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 24 Jan 2007 05:38:40 +0000 Subject: Add support for internal debug services --- hcid/dbus-database.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 1e0cee3e..f0b13abb 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -43,6 +43,8 @@ #include "sdp-xml.h" #include "dbus-common.h" #include "dbus-error.h" +#include "dbus-hci.h" +#include "dbus-service.h" #include "dbus-database.h" static int sdp_server_enable = 0; @@ -264,10 +266,38 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult register_service(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *ident, *name, *desc; + const char *sender; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, + DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, + DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + if (service_register(sender, ident, name, desc) < 0) + return error_failed(conn, msg, EIO); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + static struct service_data database_services[] = { { "AddServiceRecord", add_service_record }, { "AddServiceRecordFromXML", add_service_record_from_xml }, { "RemoveServiceRecord", remove_service_record }, + { "RegisterService", register_service }, { NULL, NULL } }; -- cgit From 48b5467e20216455a6b9683694cfd31968aa5543 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 24 Jan 2007 10:10:08 +0000 Subject: Move service registration to the manager interface --- hcid/dbus-database.c | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index f0b13abb..1e0cee3e 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -43,8 +43,6 @@ #include "sdp-xml.h" #include "dbus-common.h" #include "dbus-error.h" -#include "dbus-hci.h" -#include "dbus-service.h" #include "dbus-database.h" static int sdp_server_enable = 0; @@ -266,38 +264,10 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult register_service(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - DBusMessage *reply; - const char *ident, *name, *desc; - const char *sender; - - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, - DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, - DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); - - sender = dbus_message_get_sender(msg); - - if (service_register(sender, ident, name, desc) < 0) - return error_failed(conn, msg, EIO); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return send_message_and_unref(conn, reply); -} - static struct service_data database_services[] = { { "AddServiceRecord", add_service_record }, { "AddServiceRecordFromXML", add_service_record_from_xml }, { "RemoveServiceRecord", remove_service_record }, - { "RegisterService", register_service }, { NULL, NULL } }; -- cgit From 45d7f9ac3228a3b27ef3374e8cec13af1dd4f1fa Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 24 Jan 2007 14:18:50 +0000 Subject: Move service registration/authorization methods to database interface --- hcid/dbus-database.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 1e0cee3e..695970f8 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -41,8 +41,10 @@ #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" +#include "dbus-hci.h" #include "dbus-common.h" #include "dbus-error.h" +#include "dbus-service.h" #include "dbus-database.h" static int sdp_server_enable = 0; @@ -264,10 +266,106 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult register_service(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *sender, *ident, *name, *desc; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, + DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, + DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + if (service_register(sender, ident, name, desc) < 0) + return error_failed(conn, msg, EIO); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult unregister_service(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *sender, *ident; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, + DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult request_authorization(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *sender, *address, *path; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, + DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + +static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *sender, *address, *path; + + if (!hcid_dbus_use_experimental()) + return error_unknown_method(conn, msg); + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, + DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + sender = dbus_message_get_sender(msg); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); +} + static struct service_data database_services[] = { { "AddServiceRecord", add_service_record }, { "AddServiceRecordFromXML", add_service_record_from_xml }, { "RemoveServiceRecord", remove_service_record }, + { "RegisterService", register_service }, + { "UnregisterService", unregister_service }, + { "RequestAuthorization", request_authorization }, + { "CancelAuthorizationRequest", cancel_authorization_request }, { NULL, NULL } }; -- cgit From 138df419579f4a02b63f1055a436bc721b02ca2f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 24 Jan 2007 15:15:05 +0000 Subject: Fully implement Database.UnregisterService --- hcid/dbus-database.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 695970f8..423d117b 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -297,6 +297,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, { DBusMessage *reply; const char *sender, *ident; + struct service *service; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); @@ -307,6 +308,16 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, sender = dbus_message_get_sender(msg); + service = search_service(conn, ident); + if (!service) + return error_service_does_not_exist(conn, msg); + + if (!service->internal || strcmp(sender, service->bus_name)) + return error_not_authorized(conn, msg); + + if (service_unregister(service) < 0) + return error_failed(conn, msg, EIO); + reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; -- cgit From ab5967b2b95955accb3aad59f65e1eae6c6bd7ef Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 24 Jan 2007 15:19:19 +0000 Subject: s/internal/external/ with respect to services --- hcid/dbus-database.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 423d117b..fbd79c91 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -312,7 +312,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, if (!service) return error_service_does_not_exist(conn, msg); - if (!service->internal || strcmp(sender, service->bus_name)) + if (!service->external || strcmp(sender, service->bus_name)) return error_not_authorized(conn, msg); if (service_unregister(service) < 0) -- cgit From 6a57492f40729ceee156d7ff80cb2e99109e1082 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 24 Jan 2007 20:56:05 +0000 Subject: Remove incorrect g_io_channel_unref call --- hcid/dbus-database.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index fbd79c91..1d10be6e 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -45,6 +45,7 @@ #include "dbus-common.h" #include "dbus-error.h" #include "dbus-service.h" +#include "dbus-security.h" #include "dbus-database.h" static int sdp_server_enable = 0; @@ -328,8 +329,8 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, static DBusHandlerResult request_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *address, *path; + struct service *service; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); @@ -340,18 +341,29 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, sender = dbus_message_get_sender(msg); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + service = search_service(conn, sender); + if (!service) + return error_not_authorized(conn, msg); - return send_message_and_unref(conn, reply); + if (g_slist_find_custom(service->trusted_devices, address, + (GCompareFunc) strcasecmp)) { + DBusMessage *reply; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + return send_message_and_unref(conn, reply); + } + + return handle_authorize_request(conn, msg, service, address, path); } static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *address, *path; + struct service *service; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); @@ -362,11 +374,11 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, sender = dbus_message_get_sender(msg); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; + service = search_service(conn, sender); + if (!service) + return error_not_authorized(conn, msg); - return send_message_and_unref(conn, reply); + return cancel_authorize_request(conn, msg, service, address, path); } static struct service_data database_services[] = { -- cgit From 43d88387413875f41b491545372c3086e9659fbe Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 24 Jan 2007 23:17:17 +0000 Subject: Add some debug prints to the authorize process --- hcid/dbus-database.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 1d10be6e..90175592 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -332,6 +332,8 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, const char *sender, *address, *path; struct service *service; + debug("RequestAuthorization"); + if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); -- cgit From 695443f8d5e0da5fbff3b44279a0ed6abafdf3bb Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 26 Feb 2007 10:57:20 +0000 Subject: Use GLib memory allocation functions --- hcid/dbus-database.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 90175592..ab3a6938 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -82,7 +82,7 @@ static void exit_callback(const char *name, void *user_data) unregister_sdp_record(user_record->handle); if (user_record->sender) - free(user_record->sender); + g_free(user_record->sender); free(user_record); } @@ -105,11 +105,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (len <= 0) return error_invalid_arguments(conn, msg); - user_record = malloc(sizeof(*user_record)); - if (!user_record) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - memset(user_record, 0, sizeof(*user_record)); + user_record = g_new0(struct record_data, 1); if (sdp_server_enable) { sdp_record = sdp_extract_pdu(record, &scanned); @@ -147,7 +143,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, sender = dbus_message_get_sender(msg); - user_record->sender = strdup(sender); + user_record->sender = g_strdup(sender); records = g_slist_append(records, user_record); @@ -175,23 +171,19 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg); - user_record = malloc(sizeof(*user_record)); - if (!user_record) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - memset(user_record, 0, sizeof(*user_record)); + user_record = g_new0(struct record_data, 1); sdp_record = sdp_xml_parse_record(record, strlen(record)); if (!sdp_record) { error("Parsing of XML service record failed"); - free(user_record); + g_free(user_record); return error_failed(conn, msg, EIO); } if (sdp_server_enable) { if (add_record_to_server(sdp_record) < 0) { error("Failed to register service record"); - free(user_record); + g_free(user_record); sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } @@ -200,7 +192,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, } else { if (register_sdp_record(sdp_record) < 0) { error("Failed to register service record"); - free(user_record); + g_free(user_record); sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } @@ -212,7 +204,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sender = dbus_message_get_sender(msg); - user_record->sender = strdup(sender); + user_record->sender = g_strdup(sender); records = g_slist_append(records, user_record); @@ -256,7 +248,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, unregister_sdp_record(handle); if (user_record->sender) - free(user_record->sender); + g_free(user_record->sender); free(user_record); -- cgit From 3d16152fd30f2570ad8e9bb2427045e6fd317ce3 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 26 Feb 2007 13:44:45 +0000 Subject: More changes do use glib memory allocation --- hcid/dbus-database.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index ab3a6938..86053915 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -84,7 +84,7 @@ static void exit_callback(const char *name, void *user_data) if (user_record->sender) g_free(user_record->sender); - free(user_record); + g_free(user_record); } static DBusHandlerResult add_service_record(DBusConnection *conn, @@ -111,20 +111,20 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, sdp_record = sdp_extract_pdu(record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - free(user_record); + g_free(user_record); return error_failed(conn, msg, EIO); } if (scanned != len) { error("Size mismatch of service record"); - free(user_record); + g_free(user_record); sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } if (add_record_to_server(sdp_record) < 0) { error("Failed to register service record"); - free(user_record); + g_free(user_record); sdp_record_free(sdp_record); return error_failed(conn, msg, EIO); } @@ -136,7 +136,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (register_sdp_binary((uint8_t *) record, size, &user_record->handle) < 0) { error("Failed to register service record"); - free(user_record); + g_free(user_record); return error_failed(conn, msg, errno); } } @@ -250,7 +250,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, if (user_record->sender) g_free(user_record->sender); - free(user_record); + g_free(user_record); reply = dbus_message_new_method_return(msg); if (!reply) -- cgit From 04a18d65207a17e4005c0c7d71c7aa01be1659fb Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 26 Feb 2007 20:57:42 +0000 Subject: Implement the trust methods properly --- hcid/dbus-database.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 86053915..755de673 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -339,8 +339,7 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, if (!service) return error_not_authorized(conn, msg); - if (g_slist_find_custom(service->trusted_devices, address, - (GCompareFunc) strcasecmp)) { + if (read_trust(address, service->ident)) { DBusMessage *reply; reply = dbus_message_new_method_return(msg); -- cgit From c853057d20c7539d5214d0a126055baacb60887f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 10 Apr 2007 14:06:44 +0000 Subject: Implement global trust setting --- hcid/dbus-database.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 755de673..413fcffa 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include @@ -323,6 +325,9 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, { const char *sender, *address, *path; struct service *service; + bdaddr_t bdaddr; + gboolean trusted; + int adapter_id; debug("RequestAuthorization"); @@ -339,7 +344,18 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, if (!service) return error_not_authorized(conn, msg); - if (read_trust(address, service->ident)) { + str2ba(address, &bdaddr); + adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); + if (adapter_id < 0) + return error_not_connected(conn, msg); + + hci_devba(adapter_id, &bdaddr); + + trusted = read_trust(&bdaddr, address, GLOBAL_TRUST); + if (!trusted) + trusted = read_trust(BDADDR_ANY, address, service->ident); + + if (trusted) { DBusMessage *reply; reply = dbus_message_new_method_return(msg); -- cgit From 44847d5dfc0eebba1cebad1fbc89895901bfe09b Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 25 Apr 2007 22:14:22 +0000 Subject: Added UpdateServiceRecord --- hcid/dbus-database.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 413fcffa..3e65b02d 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -222,6 +222,67 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, return send_message_and_unref(conn, reply); } +static DBusHandlerResult update_service_record(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct record_data *user_record; + DBusMessage *reply; + DBusMessageIter iter, array; + sdp_record_t *sdp_record; + dbus_uint32_t handle; + const uint8_t *bin_record; + int err, scanned, size = -1; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_get_basic(&iter, &handle); + dbus_message_iter_next(&iter); + dbus_message_iter_recurse(&iter, &array); + + dbus_message_iter_get_fixed_array(&array, &bin_record, &size); + if (size <= 0) + return error_invalid_arguments(conn, msg); + + user_record = find_record(handle, dbus_message_get_sender(msg)); + if (!user_record) + return error_not_available(conn, msg); + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + sdp_record = sdp_extract_pdu(bin_record, &scanned); + if (!sdp_record) { + error("Parsing of service record failed"); + dbus_message_unref(reply); + return error_invalid_arguments(conn, msg); + } + + if (scanned != size) { + error("Size mismatch of service record"); + dbus_message_unref(reply); + sdp_record_free(sdp_record); + return error_invalid_arguments(conn, msg); + } + + if (sdp_server_enable) { + if (remove_record_from_server(handle) < 0) + return error_not_available(conn, msg); + + sdp_record->handle = handle; + err = add_record_to_server(sdp_record); + } else + err = update_sdp_record(handle, sdp_record); + + if (err < 0) { + error("Failed to update the service record"); + dbus_message_unref(reply); + sdp_record_free(sdp_record); + return error_failed(conn, msg, EIO); + } + + return send_message_and_unref(conn, reply); +} + static DBusHandlerResult remove_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -391,13 +452,14 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, } static struct service_data database_services[] = { - { "AddServiceRecord", add_service_record }, - { "AddServiceRecordFromXML", add_service_record_from_xml }, - { "RemoveServiceRecord", remove_service_record }, - { "RegisterService", register_service }, - { "UnregisterService", unregister_service }, - { "RequestAuthorization", request_authorization }, - { "CancelAuthorizationRequest", cancel_authorization_request }, + { "AddServiceRecord", add_service_record }, + { "AddServiceRecordFromXML", add_service_record_from_xml }, + { "UpdateServiceRecord", update_service_record }, + { "RemoveServiceRecord", remove_service_record }, + { "RegisterService", register_service }, + { "UnregisterService", unregister_service }, + { "RequestAuthorization", request_authorization }, + { "CancelAuthorizationRequest", cancel_authorization_request }, { NULL, NULL } }; -- cgit From 994212593598a7c176342e616bc99aae45991244 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 4 May 2007 15:32:26 +0000 Subject: Convert to using the generic D-Bus object handling --- hcid/dbus-database.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 3e65b02d..0e1d2f7b 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -40,6 +40,7 @@ #include #include "dbus.h" +#include "dbus-helper.h" #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" @@ -451,29 +452,24 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, return cancel_authorize_request(conn, msg, service, address, path); } -static struct service_data database_services[] = { - { "AddServiceRecord", add_service_record }, - { "AddServiceRecordFromXML", add_service_record_from_xml }, - { "UpdateServiceRecord", update_service_record }, - { "RemoveServiceRecord", remove_service_record }, - { "RegisterService", register_service }, - { "UnregisterService", unregister_service }, - { "RequestAuthorization", request_authorization }, - { "CancelAuthorizationRequest", cancel_authorization_request }, - { NULL, NULL } +static DBusMethodVTable database_methods[] = { + { "AddServiceRecord", add_service_record, "ay", "u" }, + { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, + { "UpdateServiceRecord", update_service_record, "uay", "" }, + { "RemoveServiceRecord", remove_service_record, "u", "" }, + { "RegisterService", register_service, "sss", "" }, + { "UnregisterService", unregister_service, "s", "" }, + { "RequestAuthorization", request_authorization, "ss", "" }, + { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, + { NULL, NULL, NULL, NULL } }; -DBusHandlerResult handle_database_method(DBusConnection *conn, - DBusMessage *msg, void *data) +dbus_bool_t database_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - - handler = find_service_handler(database_services, msg); - - if (handler) - return handler(conn, msg, data); - - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, + DATABASE_INTERFACE, + database_methods, + NULL, NULL); } void set_sdp_server_enable(void) -- cgit From 8cea4266a59e24df215febc4bfa4d98c4ad58e7c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 14 May 2007 11:56:39 +0000 Subject: Remove some experimental tags for stable methods --- hcid/dbus-database.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 0e1d2f7b..e4d8e4b3 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -329,9 +329,6 @@ static DBusHandlerResult register_service(DBusConnection *conn, DBusMessage *reply; const char *sender, *ident, *name, *desc; - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID) == FALSE) @@ -356,9 +353,6 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, const char *sender, *ident; struct service *service; - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg); @@ -393,9 +387,6 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, debug("RequestAuthorization"); - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg); @@ -436,9 +427,6 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, const char *sender, *address, *path; struct service *service; - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg); -- cgit From 12d3525ecefcc8ec1962572457cf49834a078b9a Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Tue, 12 Jun 2007 18:56:35 +0000 Subject: UpdateServiceRecord: removed mem leak(when sdpd is running) --- hcid/dbus-database.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index e4d8e4b3..0a6139a3 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -227,7 +227,6 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { struct record_data *user_record; - DBusMessage *reply; DBusMessageIter iter, array; sdp_record_t *sdp_record; dbus_uint32_t handle; @@ -247,20 +246,14 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, if (!user_record) return error_not_available(conn, msg); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - sdp_record = sdp_extract_pdu(bin_record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - dbus_message_unref(reply); return error_invalid_arguments(conn, msg); } if (scanned != size) { error("Size mismatch of service record"); - dbus_message_unref(reply); sdp_record_free(sdp_record); return error_invalid_arguments(conn, msg); } @@ -271,17 +264,22 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, sdp_record->handle = handle; err = add_record_to_server(sdp_record); - } else + if (err < 0) { + sdp_record_free(sdp_record); + error("Failed to update the service record"); + return error_failed(conn, msg, EIO); + } + } else { err = update_sdp_record(handle, sdp_record); - - if (err < 0) { - error("Failed to update the service record"); - dbus_message_unref(reply); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + if (err < 0) { + error("Failed to update the service record"); + return error_failed(conn, msg, EIO); + } } - return send_message_and_unref(conn, reply); + return send_message_and_unref(conn, + dbus_message_new_method_return(msg)); } static DBusHandlerResult remove_service_record(DBusConnection *conn, -- cgit From d2cbca4f4e0690c0a31ef6de1e0187e0f5bb5be9 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Tue, 12 Jun 2007 19:07:23 +0000 Subject: UpdateServiceRecord: add/replace the rec handle attr before update it(when sdpd is running) --- hcid/dbus-database.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 0a6139a3..8ee04c36 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -270,6 +270,9 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return error_failed(conn, msg, EIO); } } else { + sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); + sdp_attr_replace(sdp_record, SDP_ATTR_RECORD_HANDLE, d); + err = update_sdp_record(handle, sdp_record); sdp_record_free(sdp_record); if (err < 0) { -- cgit From b8020a613062f229b737174e934e75d96ba607d2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 22 Jun 2007 01:36:06 +0000 Subject: Improve local connection handling --- hcid/dbus-database.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 8ee04c36..2f904956 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -461,6 +461,27 @@ dbus_bool_t database_init(DBusConnection *conn, const char *path) NULL, NULL); } +DBusHandlerResult database_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMethodVTable *current; + + for (current = database_methods; + current->name && current->message_function; current++) { + if (!dbus_message_is_method_call(msg, DATABASE_INTERFACE, + current->name)) + continue; + + if (dbus_message_has_signature(msg, current->signature)) { + debug("%s: %s.%s()", dbus_message_get_path(msg), + DATABASE_INTERFACE, current->name); + return current->message_function(conn, msg, data); + } + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + void set_sdp_server_enable(void) { sdp_server_enable = 1; -- cgit From a7a78009cae0f94cff8d16430522a8901d1c4b90 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 22 Jun 2007 03:23:26 +0000 Subject: Handle local connection disconnects --- hcid/dbus-database.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 2f904956..8dd327d1 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -337,7 +337,7 @@ static DBusHandlerResult register_service(DBusConnection *conn, sender = dbus_message_get_sender(msg); - if (service_register(sender, ident, name, desc) < 0) + if (service_register(conn, sender, ident, name, desc) < 0) return error_failed(conn, msg, EIO); reply = dbus_message_new_method_return(msg); @@ -367,7 +367,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, if (!service->external || strcmp(sender, service->bus_name)) return error_not_authorized(conn, msg); - if (service_unregister(service) < 0) + if (service_unregister(conn, service) < 0) return error_failed(conn, msg, EIO); reply = dbus_message_new_method_return(msg); -- cgit From ab9d441d9df8c1e3bffb82cdfe53f1601a7ed883 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Mon, 25 Jun 2007 11:53:05 +0000 Subject: UpdateServiceRecord: fixed memory leak on failure --- hcid/dbus-database.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 8dd327d1..5b9effe7 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -259,8 +259,10 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, } if (sdp_server_enable) { - if (remove_record_from_server(handle) < 0) + if (remove_record_from_server(handle) < 0) { + sdp_record_free(sdp_record); return error_not_available(conn, msg); + } sdp_record->handle = handle; err = add_record_to_server(sdp_record); -- cgit From bd0bc214372e275311872d1585180ad4604adfe4 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Mon, 25 Jun 2007 19:29:08 +0000 Subject: database: Added new method UpdateServiceRecordFromXML --- hcid/dbus-database.c | 105 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 31 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 5b9effe7..69ade220 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -223,6 +223,41 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, return send_message_and_unref(conn, reply); } + +static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, + dbus_uint32_t handle, sdp_record_t *sdp_record) +{ + int err; + + if (sdp_server_enable) { + if (remove_record_from_server(handle) < 0) { + sdp_record_free(sdp_record); + return error_not_available(conn, msg); + } + + sdp_record->handle = handle; + err = add_record_to_server(sdp_record); + if (err < 0) { + sdp_record_free(sdp_record); + error("Failed to update the service record"); + return error_failed(conn, msg, EIO); + } + } else { + sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); + sdp_attr_replace(sdp_record, SDP_ATTR_RECORD_HANDLE, d); + + err = update_sdp_record(handle, sdp_record); + sdp_record_free(sdp_record); + if (err < 0) { + error("Failed to update the service record"); + return error_failed(conn, msg, EIO); + } + } + + return send_message_and_unref(conn, + dbus_message_new_method_return(msg)); +} + static DBusHandlerResult update_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -231,7 +266,7 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, sdp_record_t *sdp_record; dbus_uint32_t handle; const uint8_t *bin_record; - int err, scanned, size = -1; + int scanned, size = -1; dbus_message_iter_init(msg, &iter); dbus_message_iter_get_basic(&iter, &handle); @@ -258,33 +293,40 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return error_invalid_arguments(conn, msg); } - if (sdp_server_enable) { - if (remove_record_from_server(handle) < 0) { - sdp_record_free(sdp_record); - return error_not_available(conn, msg); - } + return update_record(conn, msg, handle, sdp_record); +} - sdp_record->handle = handle; - err = add_record_to_server(sdp_record); - if (err < 0) { - sdp_record_free(sdp_record); - error("Failed to update the service record"); - return error_failed(conn, msg, EIO); - } - } else { - sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); - sdp_attr_replace(sdp_record, SDP_ATTR_RECORD_HANDLE, d); +static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + const char *record; + struct record_data *user_record; + sdp_record_t *sdp_record; + dbus_uint32_t handle; + int len; - err = update_sdp_record(handle, sdp_record); + if (dbus_message_get_args(msg, NULL, + DBUS_TYPE_UINT32, &handle, + DBUS_TYPE_STRING, &record, + DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg); + + len = (record ? strlen(record) : 0); + if (len == 0) + return error_invalid_arguments(conn, msg); + + user_record = find_record(handle, dbus_message_get_sender(msg)); + if (!user_record) + return error_not_available(conn, msg); + + sdp_record = sdp_xml_parse_record(record, len); + if (!sdp_record) { + error("Parsing of XML service record failed"); sdp_record_free(sdp_record); - if (err < 0) { - error("Failed to update the service record"); - return error_failed(conn, msg, EIO); - } + return error_failed(conn, msg, EIO); } - return send_message_and_unref(conn, - dbus_message_new_method_return(msg)); + return update_record(conn, msg, handle, sdp_record); } static DBusHandlerResult remove_service_record(DBusConnection *conn, @@ -444,14 +486,15 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, } static DBusMethodVTable database_methods[] = { - { "AddServiceRecord", add_service_record, "ay", "u" }, - { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, - { "UpdateServiceRecord", update_service_record, "uay", "" }, - { "RemoveServiceRecord", remove_service_record, "u", "" }, - { "RegisterService", register_service, "sss", "" }, - { "UnregisterService", unregister_service, "s", "" }, - { "RequestAuthorization", request_authorization, "ss", "" }, - { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, + { "AddServiceRecord", add_service_record, "ay", "u" }, + { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, + { "UpdateServiceRecord", update_service_record, "uay", "" }, + { "UpdateServiceRecordFromXML", update_service_record_from_xml, "us", "" }, + { "RemoveServiceRecord", remove_service_record, "u", "" }, + { "RegisterService", register_service, "sss", "" }, + { "UnregisterService", unregister_service, "s", "" }, + { "RequestAuthorization", request_authorization, "ss", "" }, + { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, { NULL, NULL, NULL, NULL } }; -- cgit From 3b320a0355706a98f824f4d0abf2d14f820bbd81 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 15 Aug 2007 22:32:33 +0000 Subject: Rename files for adapter interface --- hcid/dbus-database.c | 1 + 1 file changed, 1 insertion(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 69ade220..1c770c83 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -44,6 +44,7 @@ #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" +#include "adapter.h" #include "dbus-hci.h" #include "dbus-common.h" #include "dbus-error.h" -- cgit From b22d297c0c679b400d7825367e31fed46c552a49 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 22 Aug 2007 01:50:41 +0000 Subject: First attempt for automatic setting of service classes value --- hcid/dbus-database.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 1c770c83..384df032 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -44,6 +44,7 @@ #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" +#include "manager.h" #include "adapter.h" #include "dbus-hci.h" #include "dbus-common.h" @@ -85,6 +86,8 @@ static void exit_callback(const char *name, void *user_data) else unregister_sdp_record(user_record->handle); + update_class_of_device(); + if (user_record->sender) g_free(user_record->sender); @@ -145,6 +148,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, } } + update_class_of_device(); + sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -206,6 +211,8 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); } + update_class_of_device(); + sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -255,6 +262,8 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, } } + update_class_of_device(); + return send_message_and_unref(conn, dbus_message_new_method_return(msg)); } @@ -357,6 +366,8 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, else unregister_sdp_record(handle); + update_class_of_device(); + if (user_record->sender) g_free(user_record->sender); -- cgit From 8af5664021b471e769b93a345f451f9a20b08ca8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 23 Aug 2007 10:12:37 +0000 Subject: Trigger the service classes update through a callback --- hcid/dbus-database.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 384df032..29e5b132 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -86,8 +86,6 @@ static void exit_callback(const char *name, void *user_data) else unregister_sdp_record(user_record->handle); - update_class_of_device(); - if (user_record->sender) g_free(user_record->sender); @@ -148,8 +146,6 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, } } - update_class_of_device(); - sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -211,8 +207,6 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); } - update_class_of_device(); - sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -262,8 +256,6 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, } } - update_class_of_device(); - return send_message_and_unref(conn, dbus_message_new_method_return(msg)); } @@ -366,8 +358,6 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, else unregister_sdp_record(handle); - update_class_of_device(); - if (user_record->sender) g_free(user_record->sender); -- cgit From 2646a19f46583a0a79b3933d4b2fb2dd3b156386 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 28 Aug 2007 11:26:05 +0000 Subject: Add some better debug logging for failed authoriztion requests --- hcid/dbus-database.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 29e5b132..16678fda 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -432,8 +432,6 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, gboolean trusted; int adapter_id; - debug("RequestAuthorization"); - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg); @@ -441,8 +439,11 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, sender = dbus_message_get_sender(msg); service = search_service(conn, sender); - if (!service) + if (!service) { + debug("Got RequestAuthorization from non-service owner %s", + sender); return error_not_authorized(conn, msg); + } str2ba(address, &bdaddr); adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); -- cgit From f1659f19cfb3ef0c0c09b5f5b7e2b06d90d079ab Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 23 Oct 2007 17:49:52 +0000 Subject: Update copyright information --- hcid/dbus-database.c | 1 + 1 file changed, 1 insertion(+) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 16678fda..7f2b2a99 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -2,6 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * + * Copyright (C) 2006-2007 Nokia Corporation * Copyright (C) 2004-2007 Marcel Holtmann * * -- cgit From 7e88afe4f8307c092172ff3c3b76c2f95ab00293 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 26 Nov 2007 13:43:17 +0000 Subject: Update services to new error codes and helper functions --- hcid/dbus-database.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 7f2b2a99..8b4060b4 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -50,6 +50,7 @@ #include "dbus-hci.h" #include "dbus-common.h" #include "dbus-error.h" +#include "error.h" #include "dbus-service.h" #include "dbus-security.h" #include "dbus-database.h" @@ -109,7 +110,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &record, &len); if (len <= 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = g_new0(struct record_data, 1); @@ -118,21 +119,21 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (!sdp_record) { error("Parsing of service record failed"); g_free(user_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (scanned != len) { error("Size mismatch of service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (add_record_to_server(sdp_record) < 0) { error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -143,7 +144,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, &user_record->handle) < 0) { error("Failed to register service record"); g_free(user_record); - return error_failed(conn, msg, errno); + return error_failed_errno(conn, msg, errno); } } @@ -175,7 +176,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = g_new0(struct record_data, 1); @@ -183,7 +184,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (!sdp_record) { error("Parsing of XML service record failed"); g_free(user_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (sdp_server_enable) { @@ -191,7 +192,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -200,7 +201,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -243,7 +244,7 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, if (err < 0) { sdp_record_free(sdp_record); error("Failed to update the service record"); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } } else { sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); @@ -253,7 +254,7 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, sdp_record_free(sdp_record); if (err < 0) { error("Failed to update the service record"); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } } @@ -278,7 +279,7 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &bin_record, &size); if (size <= 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) @@ -287,13 +288,13 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, sdp_record = sdp_extract_pdu(bin_record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (scanned != size) { error("Size mismatch of service record"); sdp_record_free(sdp_record); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } return update_record(conn, msg, handle, sdp_record); @@ -312,11 +313,11 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); len = (record ? strlen(record) : 0); if (len == 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) @@ -326,7 +327,7 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, if (!sdp_record) { error("Parsing of XML service record failed"); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } return update_record(conn, msg, handle, sdp_record); @@ -342,7 +343,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -380,12 +381,12 @@ static DBusHandlerResult register_service(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); if (service_register(conn, sender, ident, name, desc) < 0) - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); reply = dbus_message_new_method_return(msg); if (!reply) @@ -403,7 +404,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -415,7 +416,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, return error_not_authorized(conn, msg); if (service_unregister(conn, service) < 0) - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); reply = dbus_message_new_method_return(msg); if (!reply) @@ -435,7 +436,7 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -478,7 +479,7 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); -- cgit From ba255beb79afb9c00ae5b71821f84f911aa8d1fe Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 28 Jan 2008 10:38:40 +0000 Subject: Whitespace cleanup --- hcid/dbus-database.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 8b4060b4..a954d11f 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -491,7 +491,7 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, } static DBusMethodVTable database_methods[] = { - { "AddServiceRecord", add_service_record, "ay", "u" }, + { "AddServiceRecord", add_service_record, "ay", "u" }, { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, { "UpdateServiceRecord", update_service_record, "uay", "" }, { "UpdateServiceRecordFromXML", update_service_record_from_xml, "us", "" }, -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- hcid/dbus-database.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index a954d11f..44e4d4b6 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -3,7 +3,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2006-2007 Nokia Corporation - * Copyright (C) 2004-2007 Marcel Holtmann + * Copyright (C) 2004-2008 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify -- cgit From 45d1a411eecc9a09dc3bd81ab61de0b1649f5f20 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 7 Mar 2008 18:54:59 +0000 Subject: Rename some public agent functions to make way to the upcoming new agent API --- hcid/dbus-database.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 44e4d4b6..c5bcd6ae 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -468,7 +468,7 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, return send_message_and_unref(conn, reply); } - return handle_authorize_request(conn, msg, service, address, path); + return handle_authorize_request_old(conn, msg, service, address, path); } static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, @@ -487,7 +487,7 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, if (!service) return error_not_authorized(conn, msg); - return cancel_authorize_request(conn, msg, service, address, path); + return cancel_authorize_request_old(conn, msg, service, address, path); } static DBusMethodVTable database_methods[] = { -- cgit From 15884ba98a8ddec4b2ca7fb9fa21a1bc82faa3eb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 15 Mar 2008 02:23:02 +0000 Subject: Implement basic support for new service record registration --- hcid/dbus-database.c | 86 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 28 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index c5bcd6ae..aa8a7467 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -166,25 +166,19 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, - DBusMessage *msg, void *data) +int add_xml_record(DBusConnection *conn, const char *sender, + const char *record, dbus_uint32_t *handle) { - DBusMessage *reply; - const char *sender, *record; struct record_data *user_record; sdp_record_t *sdp_record; - if (dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - user_record = g_new0(struct record_data, 1); sdp_record = sdp_xml_parse_record(record, strlen(record)); if (!sdp_record) { error("Parsing of XML service record failed"); g_free(user_record); - return error_failed_errno(conn, msg, EIO); + return -EIO; } if (sdp_server_enable) { @@ -192,7 +186,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); + return -EIO; } user_record->handle = sdp_record->handle; @@ -201,7 +195,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); + return -EIO; } user_record->handle = sdp_record->handle; @@ -209,25 +203,45 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); } - sender = dbus_message_get_sender(msg); - user_record->sender = g_strdup(sender); records = g_slist_append(records, user_record); name_listener_add(conn, sender, exit_callback, user_record); + *handle = user_record->handle; + + return 0; +} + +static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + const char *sender, *record; + dbus_uint32_t handle; + int err; + + if (dbus_message_get_args(msg, NULL, + DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg, NULL); + + sender = dbus_message_get_sender(msg); + reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, - DBUS_TYPE_INVALID); + err = add_xml_record(conn, sender, record, &handle); + if (err < 0) + return error_failed_errno(conn, msg, err); + + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); } - static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, dbus_uint32_t handle, sdp_record_t *sdp_record) { @@ -300,6 +314,12 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return update_record(conn, msg, handle, sdp_record); } +int update_xml_record(DBusConnection *conn, const char *sender, + dbus_uint32_t handle, const char *record) +{ + return -EIO; +} + static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -333,23 +353,14 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, return update_record(conn, msg, handle, sdp_record); } -static DBusHandlerResult remove_service_record(DBusConnection *conn, - DBusMessage *msg, void *data) +int remove_record(DBusConnection *conn, const char *sender, + dbus_uint32_t handle) { - DBusMessage *reply; - dbus_uint32_t handle; - const char *sender; struct record_data *user_record; - if (dbus_message_get_args(msg, NULL, - DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - - sender = dbus_message_get_sender(msg); - user_record = find_record(handle, sender); if (!user_record) - return error_not_available(conn, msg); + return -1; name_listener_remove(conn, sender, exit_callback, user_record); @@ -365,6 +376,25 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, g_free(user_record); + return 0; +} + +static DBusHandlerResult remove_service_record(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + DBusMessage *reply; + dbus_uint32_t handle; + const char *sender; + + if (dbus_message_get_args(msg, NULL, + DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) + return error_invalid_arguments(conn, msg, NULL); + + sender = dbus_message_get_sender(msg); + + if (remove_record(conn, sender, handle) < 0) + return error_not_available(conn, msg); + reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; -- cgit From f511421ba10092ba32343a973e71f96ce4698f7b Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 20 Mar 2008 14:54:24 +0000 Subject: Added adapter UpdateServiceRecord implementation --- hcid/dbus-database.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index aa8a7467..a2330940 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -314,25 +314,19 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return update_record(conn, msg, handle, sdp_record); } -int update_xml_record(DBusConnection *conn, const char *sender, - dbus_uint32_t handle, const char *record) +DBusHandlerResult update_xml_record(DBusConnection *conn, + DBusMessage *msg, bdaddr_t *src) { - return -EIO; -} - -static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *record; struct record_data *user_record; sdp_record_t *sdp_record; + const char *record; dbus_uint32_t handle; int len; if (dbus_message_get_args(msg, NULL, - DBUS_TYPE_UINT32, &handle, - DBUS_TYPE_STRING, &record, - DBUS_TYPE_INVALID) == FALSE) + DBUS_TYPE_UINT32, &handle, + DBUS_TYPE_STRING, &record, + DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg, NULL); len = (record ? strlen(record) : 0); @@ -353,6 +347,12 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, return update_record(conn, msg, handle, sdp_record); } +static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + return update_xml_record(conn, msg, BDADDR_ANY); +} + int remove_record(DBusConnection *conn, const char *sender, dbus_uint32_t handle) { -- cgit From d504a0767e08b04f2af78c10db79d8e35f0c3e92 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 20 Mar 2008 20:10:49 +0000 Subject: Add records based on the adapter address --- hcid/dbus-database.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index a2330940..e6e1de06 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -129,7 +129,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, return error_failed_errno(conn, msg, EIO); } - if (add_record_to_server(sdp_record) < 0) { + if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) { error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); @@ -166,7 +166,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } -int add_xml_record(DBusConnection *conn, const char *sender, +int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, const char *record, dbus_uint32_t *handle) { struct record_data *user_record; @@ -182,7 +182,7 @@ int add_xml_record(DBusConnection *conn, const char *sender, } if (sdp_server_enable) { - if (add_record_to_server(sdp_record) < 0) { + if (add_record_to_server(src, sdp_record) < 0) { error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); @@ -191,7 +191,7 @@ int add_xml_record(DBusConnection *conn, const char *sender, user_record->handle = sdp_record->handle; } else { - if (register_sdp_record(sdp_record) < 0) { + if (register_sdp_record(src, sdp_record) < 0) { error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); @@ -232,7 +232,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - err = add_xml_record(conn, sender, record, &handle); + err = add_xml_record(conn, sender, BDADDR_ANY, record, &handle); if (err < 0) return error_failed_errno(conn, msg, err); @@ -243,7 +243,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, } static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, - dbus_uint32_t handle, sdp_record_t *sdp_record) + bdaddr_t *src, dbus_uint32_t handle, sdp_record_t *sdp_record) { int err; @@ -254,7 +254,7 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, } sdp_record->handle = handle; - err = add_record_to_server(sdp_record); + err = add_record_to_server(src, sdp_record); if (err < 0) { sdp_record_free(sdp_record); error("Failed to update the service record"); @@ -311,7 +311,7 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return error_invalid_arguments(conn, msg, NULL); } - return update_record(conn, msg, handle, sdp_record); + return update_record(conn, msg, BDADDR_ANY, handle, sdp_record); } DBusHandlerResult update_xml_record(DBusConnection *conn, @@ -344,7 +344,7 @@ DBusHandlerResult update_xml_record(DBusConnection *conn, return error_failed_errno(conn, msg, EIO); } - return update_record(conn, msg, handle, sdp_record); + return update_record(conn, msg, src, handle, sdp_record); } static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, -- cgit From 2fc88679b39c0d5db43973d1a3cfee7475c67538 Mon Sep 17 00:00:00 2001 From: Cidorvan Leite Date: Mon, 31 Mar 2008 20:09:27 +0000 Subject: Removed SDP conditional initialization --- hcid/dbus-database.c | 124 +++++++++++++++------------------------------------ 1 file changed, 35 insertions(+), 89 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index e6e1de06..f47df37d 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -55,8 +55,6 @@ #include "dbus-security.h" #include "dbus-database.h" -static int sdp_server_enable = 0; - static GSList *records = NULL; struct record_data { @@ -83,10 +81,7 @@ static void exit_callback(const char *name, void *user_data) records = g_slist_remove(records, user_record); - if (sdp_server_enable) - remove_record_from_server(user_record->handle); - else - unregister_sdp_record(user_record->handle); + remove_record_from_server(user_record->handle); if (user_record->sender) g_free(user_record->sender); @@ -112,41 +107,27 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (len <= 0) return error_invalid_arguments(conn, msg, NULL); - user_record = g_new0(struct record_data, 1); - - if (sdp_server_enable) { - sdp_record = sdp_extract_pdu(record, &scanned); - if (!sdp_record) { - error("Parsing of service record failed"); - g_free(user_record); - return error_failed_errno(conn, msg, EIO); - } + sdp_record = sdp_extract_pdu(record, &scanned); + if (!sdp_record) { + error("Parsing of service record failed"); + return error_failed_errno(conn, msg, EIO); + } - if (scanned != len) { - error("Size mismatch of service record"); - g_free(user_record); - sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); - } + if (scanned != len) { + error("Size mismatch of service record"); + sdp_record_free(sdp_record); + return error_failed_errno(conn, msg, EIO); + } - if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) { - error("Failed to register service record"); - g_free(user_record); - sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); - } + if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) { + error("Failed to register service record"); + sdp_record_free(sdp_record); + return error_failed_errno(conn, msg, EIO); + } - user_record->handle = sdp_record->handle; - } else { - uint32_t size = len; + user_record = g_new0(struct record_data, 1); - if (register_sdp_binary((uint8_t *) record, size, - &user_record->handle) < 0) { - error("Failed to register service record"); - g_free(user_record); - return error_failed_errno(conn, msg, errno); - } - } + user_record->handle = sdp_record->handle; sender = dbus_message_get_sender(msg); @@ -172,37 +153,22 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, struct record_data *user_record; sdp_record_t *sdp_record; - user_record = g_new0(struct record_data, 1); - sdp_record = sdp_xml_parse_record(record, strlen(record)); if (!sdp_record) { error("Parsing of XML service record failed"); - g_free(user_record); return -EIO; } - if (sdp_server_enable) { - if (add_record_to_server(src, sdp_record) < 0) { - error("Failed to register service record"); - g_free(user_record); - sdp_record_free(sdp_record); - return -EIO; - } - - user_record->handle = sdp_record->handle; - } else { - if (register_sdp_record(src, sdp_record) < 0) { - error("Failed to register service record"); - g_free(user_record); - sdp_record_free(sdp_record); - return -EIO; - } - - user_record->handle = sdp_record->handle; - + if (add_record_to_server(src, sdp_record) < 0) { + error("Failed to register service record"); sdp_record_free(sdp_record); + return -EIO; } + user_record = g_new0(struct record_data, 1); + + user_record->handle = sdp_record->handle; + user_record->sender = g_strdup(sender); records = g_slist_append(records, user_record); @@ -247,29 +213,17 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, { int err; - if (sdp_server_enable) { - if (remove_record_from_server(handle) < 0) { - sdp_record_free(sdp_record); - return error_not_available(conn, msg); - } - - sdp_record->handle = handle; - err = add_record_to_server(src, sdp_record); - if (err < 0) { - sdp_record_free(sdp_record); - error("Failed to update the service record"); - return error_failed_errno(conn, msg, EIO); - } - } else { - sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); - sdp_attr_replace(sdp_record, SDP_ATTR_RECORD_HANDLE, d); + if (remove_record_from_server(handle) < 0) { + sdp_record_free(sdp_record); + return error_not_available(conn, msg); + } - err = update_sdp_record(handle, sdp_record); + sdp_record->handle = handle; + err = add_record_to_server(src, sdp_record); + if (err < 0) { sdp_record_free(sdp_record); - if (err < 0) { - error("Failed to update the service record"); - return error_failed_errno(conn, msg, EIO); - } + error("Failed to update the service record"); + return error_failed_errno(conn, msg, EIO); } return send_message_and_unref(conn, @@ -366,10 +320,7 @@ int remove_record(DBusConnection *conn, const char *sender, records = g_slist_remove(records, user_record); - if (sdp_server_enable) - remove_record_from_server(handle); - else - unregister_sdp_record(handle); + remove_record_from_server(handle); if (user_record->sender) g_free(user_record->sender); @@ -561,8 +512,3 @@ DBusHandlerResult database_message(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - -void set_sdp_server_enable(void) -{ - sdp_server_enable = 1; -} -- cgit From 62acaff4f9dd436a453fb819c444f9abf7976327 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 3 Apr 2008 18:01:20 +0000 Subject: search_service cleanup --- hcid/dbus-database.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index f47df37d..93f37ad4 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -389,7 +389,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, sender = dbus_message_get_sender(msg); - service = search_service(conn, ident); + service = search_service(ident); if (!service) return error_service_does_not_exist(conn, msg); @@ -421,7 +421,7 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, sender = dbus_message_get_sender(msg); - service = search_service(conn, sender); + service = search_service(sender); if (!service) { debug("Got RequestAuthorization from non-service owner %s", sender); @@ -464,7 +464,7 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, sender = dbus_message_get_sender(msg); - service = search_service(conn, sender); + service = search_service(sender); if (!service) return error_not_authorized(conn, msg); -- cgit From a6bf5ec452e5426906fc9991d738e3a5ae27050c Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Tue, 8 Apr 2008 21:28:26 +0000 Subject: cleanup: connection status is verified twice for RequestAuthorization --- hcid/dbus-database.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 93f37ad4..4479f78c 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -409,14 +409,15 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, static DBusHandlerResult request_authorization(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *sender, *address, *path; + const char *sender, *address, *uuid; struct service *service; + char path[MAX_PATH_LENGTH]; bdaddr_t bdaddr; gboolean trusted; int adapter_id; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) + DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -449,7 +450,9 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, return send_message_and_unref(conn, reply); } - return handle_authorize_request_old(conn, msg, service, address, path); + snprintf(path, sizeof(path), "/org/bluez/hci%d", adapter_id); + return handle_authorize_request_old(conn, msg, + service, path, address, uuid); } static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, -- cgit From e17ea9f35ae810afd33b332978d5882953696cfd Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 9 Apr 2008 21:48:30 +0000 Subject: Added new function for plugin authorization --- hcid/dbus-database.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 4479f78c..a32bc810 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -406,7 +406,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult request_authorization(DBusConnection *conn, +static DBusHandlerResult request_authorization_old(DBusConnection *conn, DBusMessage *msg, void *data) { const char *sender, *address, *uuid; @@ -482,7 +482,7 @@ static DBusMethodVTable database_methods[] = { { "RemoveServiceRecord", remove_service_record, "u", "" }, { "RegisterService", register_service, "sss", "" }, { "UnregisterService", unregister_service, "s", "" }, - { "RequestAuthorization", request_authorization, "ss", "" }, + { "RequestAuthorization", request_authorization_old, "ss", "" }, { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, { NULL, NULL, NULL, NULL } }; -- cgit From 098cd10838193272c669348c5ffd0410218e1bcc Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 1 May 2008 01:05:46 +0000 Subject: fixed service authorization --- hcid/dbus-database.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index a32bc810..d37b4d97 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -422,7 +422,10 @@ static DBusHandlerResult request_authorization_old(DBusConnection *conn, sender = dbus_message_get_sender(msg); - service = search_service(sender); + service = search_service_by_uuid(uuid); + if (!service) + service = search_service(sender); + if (!service) { debug("Got RequestAuthorization from non-service owner %s", sender); @@ -458,20 +461,23 @@ static DBusHandlerResult request_authorization_old(DBusConnection *conn, static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *sender, *address, *path; + const char *sender, *address, *uuid; struct service *service; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) + DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); - service = search_service(sender); + service = search_service_by_uuid(uuid); + if (!service) + service = search_service(sender); + if (!service) return error_not_authorized(conn, msg); - return cancel_authorize_request_old(conn, msg, service, address, path); + return cancel_authorize_request_old(conn, msg, service, address, uuid); } static DBusMethodVTable database_methods[] = { -- cgit From 2af3c3a7ddc43577c067892cdfdc06dc4e63386c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 17:24:48 +0000 Subject: Remove service daemon activation handling --- hcid/dbus-database.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index d37b4d97..9519975e 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -353,57 +353,34 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult register_service(DBusConnection *conn, +static DBusHandlerResult register_service_old(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; - const char *sender, *ident, *name, *desc; + const char *ident, *name, *desc; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg, NULL); - sender = dbus_message_get_sender(msg); - - if (service_register(conn, sender, ident, name, desc) < 0) - return error_failed_errno(conn, msg, EIO); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return send_message_and_unref(conn, reply); + return error_failed_errno(conn, msg, EIO); } -static DBusHandlerResult unregister_service(DBusConnection *conn, +static DBusHandlerResult unregister_service_old(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; - const char *sender, *ident; struct service *service; + const char *ident; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_INVALID) == FALSE) return error_invalid_arguments(conn, msg, NULL); - sender = dbus_message_get_sender(msg); - service = search_service(ident); if (!service) return error_service_does_not_exist(conn, msg); - if (!service->external || strcmp(sender, service->bus_name)) - return error_not_authorized(conn, msg); - - if (service_unregister(conn, service) < 0) - return error_failed_errno(conn, msg, EIO); - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return send_message_and_unref(conn, reply); + return error_failed_errno(conn, msg, EIO); } static DBusHandlerResult request_authorization_old(DBusConnection *conn, @@ -486,8 +463,8 @@ static DBusMethodVTable database_methods[] = { { "UpdateServiceRecord", update_service_record, "uay", "" }, { "UpdateServiceRecordFromXML", update_service_record_from_xml, "us", "" }, { "RemoveServiceRecord", remove_service_record, "u", "" }, - { "RegisterService", register_service, "sss", "" }, - { "UnregisterService", unregister_service, "s", "" }, + { "RegisterService", register_service_old, "sss", "" }, + { "UnregisterService", unregister_service_old, "s", "" }, { "RequestAuthorization", request_authorization_old, "ss", "" }, { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, { NULL, NULL, NULL, NULL } -- cgit From e7d668ac9e813bc9922ee7d771848bd8822d5d1f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 20:23:45 +0000 Subject: Move D-Bus watch functions into libgdbus --- hcid/dbus-database.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 9519975e..370b7658 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -40,7 +40,8 @@ #include -#include "dbus.h" +#include + #include "dbus-helper.h" #include "hcid.h" #include "sdpd.h" -- cgit From 15ea15b3a752f0487bc50d0ea04925f1b9d33dcb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 8 May 2008 22:19:14 +0000 Subject: Move D-Bus object and interface helpers into libgdbus --- hcid/dbus-database.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 370b7658..acf5301c 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -37,12 +37,9 @@ #include #include - #include - #include -#include "dbus-helper.h" #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" -- cgit From 649448818704cd93136d55d33676ad80cb463224 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 27 May 2008 21:31:12 +0000 Subject: Use guint identifier for all name_listener operations --- hcid/dbus-database.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index acf5301c..cf2369b1 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -58,6 +58,7 @@ static GSList *records = NULL; struct record_data { uint32_t handle; char *sender; + guint listener_id; }; static struct record_data *find_record(uint32_t handle, const char *sender) @@ -133,7 +134,9 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, records = g_slist_append(records, user_record); - name_listener_add(conn, sender, exit_callback, user_record); + user_record->listener_id = name_listener_add(conn, sender, + exit_callback, + user_record); reply = dbus_message_new_method_return(msg); if (!reply) @@ -314,7 +317,7 @@ int remove_record(DBusConnection *conn, const char *sender, if (!user_record) return -1; - name_listener_remove(conn, sender, exit_callback, user_record); + name_listener_id_remove(user_record->listener_id); records = g_slist_remove(records, user_record); -- cgit From cc0f97ec2cb298bde87cd3753fd96f11ce41ff64 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 29 May 2008 14:43:27 +0000 Subject: Change name_listener API to libgdbus watch API --- hcid/dbus-database.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index cf2369b1..41702d9b 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -74,7 +74,7 @@ static struct record_data *find_record(uint32_t handle, const char *sender) return NULL; } -static void exit_callback(const char *name, void *user_data) +static void exit_callback(void *user_data) { struct record_data *user_record = user_data; @@ -134,9 +134,10 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, records = g_slist_append(records, user_record); - user_record->listener_id = name_listener_add(conn, sender, - exit_callback, - user_record); + user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender, + exit_callback, + user_record, + NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -174,7 +175,8 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, records = g_slist_append(records, user_record); - name_listener_add(conn, sender, exit_callback, user_record); + g_dbus_add_disconnect_watch(conn, sender, exit_callback, user_record, + NULL); *handle = user_record->handle; @@ -317,7 +319,7 @@ int remove_record(DBusConnection *conn, const char *sender, if (!user_record) return -1; - name_listener_id_remove(user_record->listener_id); + g_dbus_remove_watch(conn, user_record->listener_id); records = g_slist_remove(records, user_record); -- cgit From d6324969931f4b0202851443ad6ccb98a325f476 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Tue, 3 Jun 2008 10:50:00 +0000 Subject: Converted Adapter interface to use new GDBusMethodTable --- hcid/dbus-database.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 41702d9b..7dcc6b01 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -211,14 +211,16 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, +static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg, bdaddr_t *src, dbus_uint32_t handle, sdp_record_t *sdp_record) { int err; if (remove_record_from_server(handle) < 0) { sdp_record_free(sdp_record); - return error_not_available(conn, msg); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".NotAvailable", + "Not Available"); } sdp_record->handle = handle; @@ -226,11 +228,12 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, if (err < 0) { sdp_record_free(sdp_record); error("Failed to update the service record"); - return error_failed_errno(conn, msg, EIO); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".Failed", + strerror(EIO)); } - return send_message_and_unref(conn, - dbus_message_new_method_return(msg)); + return dbus_message_new_method_return(msg); } static DBusHandlerResult update_service_record(DBusConnection *conn, @@ -268,10 +271,11 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, return error_invalid_arguments(conn, msg, NULL); } - return update_record(conn, msg, BDADDR_ANY, handle, sdp_record); + return send_message_and_unref(conn, + update_record(conn, msg, BDADDR_ANY, handle, sdp_record)); } -DBusHandlerResult update_xml_record(DBusConnection *conn, +DBusMessage *update_xml_record(DBusConnection *conn, DBusMessage *msg, bdaddr_t *src) { struct record_data *user_record; @@ -284,21 +288,29 @@ DBusHandlerResult update_xml_record(DBusConnection *conn, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".InvalidArguments", + "Invalid arguments in method call"); len = (record ? strlen(record) : 0); if (len == 0) - return error_invalid_arguments(conn, msg, NULL); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".InvalidArguments", + "Invalid arguments in method call"); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) - return error_not_available(conn, msg); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".NotAvailable", + "Not Available"); sdp_record = sdp_xml_parse_record(record, len); if (!sdp_record) { error("Parsing of XML service record failed"); sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); + return g_dbus_create_error(msg, + ERROR_INTERFACE ".Failed", + strerror(EIO)); } return update_record(conn, msg, src, handle, sdp_record); @@ -307,7 +319,8 @@ DBusHandlerResult update_xml_record(DBusConnection *conn, static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, DBusMessage *msg, void *data) { - return update_xml_record(conn, msg, BDADDR_ANY); + return send_message_and_unref(conn, + update_xml_record(conn, msg, BDADDR_ANY)); } int remove_record(DBusConnection *conn, const char *sender, -- cgit From a853f0013160472751d39b68af8c40ce5e5d6336 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 3 Jun 2008 17:47:43 +0000 Subject: Change database interface to use gdbus API and remove broken methods --- hcid/dbus-database.c | 242 +++++++++++---------------------------------------- 1 file changed, 53 insertions(+), 189 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 7dcc6b01..c1ac2b97 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -36,8 +36,6 @@ #include #include -#include -#include #include #include "hcid.h" @@ -88,10 +86,26 @@ static void exit_callback(void *user_data) g_free(user_record); } -static DBusHandlerResult add_service_record(DBusConnection *conn, +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", + "Not Available"); +} + +static inline DBusMessage *failed(DBusMessage *msg) +{ + return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", "Failed"); +} + +static DBusMessage *add_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; DBusMessageIter iter, array; const char *sender; struct record_data *user_record; @@ -104,24 +118,24 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &record, &len); if (len <= 0) - return error_invalid_arguments(conn, msg, NULL); + return invalid_arguments(msg); sdp_record = sdp_extract_pdu(record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - return error_failed_errno(conn, msg, EIO); + return failed(msg); } if (scanned != len) { error("Size mismatch of service record"); sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); + return failed(msg); } if (add_record_to_server(BDADDR_ANY, sdp_record) < 0) { error("Failed to register service record"); sdp_record_free(sdp_record); - return error_failed_errno(conn, msg, EIO); + return failed(msg); } user_record = g_new0(struct record_data, 1); @@ -139,14 +153,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, user_record, NULL); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &user_record->handle, - DBUS_TYPE_INVALID); - - return send_message_and_unref(conn, reply); + return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &user_record->handle, + DBUS_TYPE_INVALID); } int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, @@ -183,32 +191,25 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, return 0; } -static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, +static DBusMessage *add_service_record_from_xml(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *record; dbus_uint32_t handle; int err; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); + return NULL; sender = dbus_message_get_sender(msg); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - err = add_xml_record(conn, sender, BDADDR_ANY, record, &handle); if (err < 0) - return error_failed_errno(conn, msg, err); + return failed(msg); - dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle, + return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID); - - return send_message_and_unref(conn, reply); } static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg, @@ -236,7 +237,7 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg, return dbus_message_new_method_return(msg); } -static DBusHandlerResult update_service_record(DBusConnection *conn, +static DBusMessage *update_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { struct record_data *user_record; @@ -253,26 +254,25 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &bin_record, &size); if (size <= 0) - return error_invalid_arguments(conn, msg, NULL); + return invalid_arguments(msg); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) - return error_not_available(conn, msg); + return not_available(msg); sdp_record = sdp_extract_pdu(bin_record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - return error_invalid_arguments(conn, msg, NULL); + return invalid_arguments(msg); } if (scanned != size) { error("Size mismatch of service record"); sdp_record_free(sdp_record); - return error_invalid_arguments(conn, msg, NULL); + return invalid_arguments(msg); } - return send_message_and_unref(conn, - update_record(conn, msg, BDADDR_ANY, handle, sdp_record)); + return update_record(conn, msg, BDADDR_ANY, handle, sdp_record); } DBusMessage *update_xml_record(DBusConnection *conn, @@ -288,15 +288,11 @@ DBusMessage *update_xml_record(DBusConnection *conn, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return g_dbus_create_error(msg, - ERROR_INTERFACE ".InvalidArguments", - "Invalid arguments in method call"); + return NULL; len = (record ? strlen(record) : 0); if (len == 0) - return g_dbus_create_error(msg, - ERROR_INTERFACE ".InvalidArguments", - "Invalid arguments in method call"); + return invalid_arguments(msg); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) @@ -316,11 +312,10 @@ DBusMessage *update_xml_record(DBusConnection *conn, return update_record(conn, msg, src, handle, sdp_record); } -static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, +static DBusMessage *update_service_record_from_xml(DBusConnection *conn, DBusMessage *msg, void *data) { - return send_message_and_unref(conn, - update_xml_record(conn, msg, BDADDR_ANY)); + return update_xml_record(conn, msg, BDADDR_ANY); } int remove_record(DBusConnection *conn, const char *sender, @@ -346,171 +341,40 @@ int remove_record(DBusConnection *conn, const char *sender, return 0; } -static DBusHandlerResult remove_service_record(DBusConnection *conn, +static DBusMessage *remove_service_record(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; dbus_uint32_t handle; const char *sender; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); + return NULL; sender = dbus_message_get_sender(msg); if (remove_record(conn, sender, handle) < 0) - return error_not_available(conn, msg); + return not_available(msg); - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return send_message_and_unref(conn, reply); -} - -static DBusHandlerResult register_service_old(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *ident, *name, *desc; - - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, - DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, - DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - - return error_failed_errno(conn, msg, EIO); + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -static DBusHandlerResult unregister_service_old(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - struct service *service; - const char *ident; - - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, - DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - - service = search_service(ident); - if (!service) - return error_service_does_not_exist(conn, msg); - - return error_failed_errno(conn, msg, EIO); -} - -static DBusHandlerResult request_authorization_old(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *sender, *address, *uuid; - struct service *service; - char path[MAX_PATH_LENGTH]; - bdaddr_t bdaddr; - gboolean trusted; - int adapter_id; - - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - - sender = dbus_message_get_sender(msg); - - service = search_service_by_uuid(uuid); - if (!service) - service = search_service(sender); - - if (!service) { - debug("Got RequestAuthorization from non-service owner %s", - sender); - return error_not_authorized(conn, msg); - } - - str2ba(address, &bdaddr); - adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); - if (adapter_id < 0) - return error_not_connected(conn, msg); - - hci_devba(adapter_id, &bdaddr); - - trusted = read_trust(&bdaddr, address, GLOBAL_TRUST); - if (!trusted) - trusted = read_trust(BDADDR_ANY, address, service->ident); - - if (trusted) { - DBusMessage *reply; - - reply = dbus_message_new_method_return(msg); - if (!reply) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - return send_message_and_unref(conn, reply); - } - - snprintf(path, sizeof(path), "/org/bluez/hci%d", adapter_id); - return handle_authorize_request_old(conn, msg, - service, path, address, uuid); -} - -static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - const char *sender, *address, *uuid; - struct service *service; - - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg, NULL); - - sender = dbus_message_get_sender(msg); - - service = search_service_by_uuid(uuid); - if (!service) - service = search_service(sender); - - if (!service) - return error_not_authorized(conn, msg); - - return cancel_authorize_request_old(conn, msg, service, address, uuid); -} - -static DBusMethodVTable database_methods[] = { - { "AddServiceRecord", add_service_record, "ay", "u" }, - { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, - { "UpdateServiceRecord", update_service_record, "uay", "" }, - { "UpdateServiceRecordFromXML", update_service_record_from_xml, "us", "" }, - { "RemoveServiceRecord", remove_service_record, "u", "" }, - { "RegisterService", register_service_old, "sss", "" }, - { "UnregisterService", unregister_service_old, "s", "" }, - { "RequestAuthorization", request_authorization_old, "ss", "" }, - { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, - { NULL, NULL, NULL, NULL } +static GDBusMethodTable database_methods[] = { + { "AddServiceRecord", "ay", "u", add_service_record }, + { "AddServiceRecordFromXML", "s", "u", add_service_record_from_xml }, + { "UpdateServiceRecord", "uay", "", update_service_record }, + { "UpdateServiceRecordFromXML", "us", "", update_service_record_from_xml }, + { "RemoveServiceRecord", "u", "", remove_service_record }, + { } }; dbus_bool_t database_init(DBusConnection *conn, const char *path) { - return dbus_connection_register_interface(conn, path, - DATABASE_INTERFACE, - database_methods, - NULL, NULL); + return g_dbus_register_interface(conn, path, DATABASE_INTERFACE, + database_methods, NULL, NULL, NULL, NULL); } -DBusHandlerResult database_message(DBusConnection *conn, - DBusMessage *msg, void *data) +void database_cleanup(DBusConnection *conn, const char *path) { - DBusMethodVTable *current; - - for (current = database_methods; - current->name && current->message_function; current++) { - if (!dbus_message_is_method_call(msg, DATABASE_INTERFACE, - current->name)) - continue; - - if (dbus_message_has_signature(msg, current->signature)) { - debug("%s: %s.%s()", dbus_message_get_path(msg), - DATABASE_INTERFACE, current->name); - return current->message_function(conn, msg, data); - } - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + g_dbus_unregister_interface(conn, path, DATABASE_INTERFACE); } -- cgit From 92faff9a094d5cbdfaa3c83f3fe17074a483ce55 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 7 Jun 2008 08:49:19 +0000 Subject: Cleanup errors and remove unused functions --- hcid/dbus-database.c | 1 - 1 file changed, 1 deletion(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index c1ac2b97..5924beb6 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -45,7 +45,6 @@ #include "adapter.h" #include "dbus-hci.h" #include "dbus-common.h" -#include "dbus-error.h" #include "error.h" #include "dbus-service.h" #include "dbus-security.h" -- cgit From b35ac6078fae8ff8d04d6fd7ea725fc8bf71ce3e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 13:27:28 +0000 Subject: Small optimization --- hcid/dbus-database.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 5924beb6..8c5880e7 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -332,9 +332,7 @@ int remove_record(DBusConnection *conn, const char *sender, remove_record_from_server(handle); - if (user_record->sender) - g_free(user_record->sender); - + g_free(user_record->sender); g_free(user_record); return 0; -- cgit From 8f1027f24f8b355d17d3197d17d1ccd38c9a64e5 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 13:29:47 +0000 Subject: One additional optimization --- hcid/dbus-database.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 8c5880e7..e9df79b0 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -79,9 +79,7 @@ static void exit_callback(void *user_data) remove_record_from_server(user_record->handle); - if (user_record->sender) - g_free(user_record->sender); - + g_free(user_record->sender); g_free(user_record); } -- cgit From c1f7605e7afb22c24f4b241afd36526e6181e7ef Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Jun 2008 13:49:39 +0000 Subject: Fix missing disconnect watch id handling --- hcid/dbus-database.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index e9df79b0..c6a689d2 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -75,6 +75,8 @@ static void exit_callback(void *user_data) { struct record_data *user_record = user_data; + debug("remove record"); + records = g_slist_remove(records, user_record); remove_record_from_server(user_record->handle); @@ -150,6 +152,8 @@ static DBusMessage *add_service_record(DBusConnection *conn, user_record, NULL); + debug("listener_id %d", user_record->listener_id); + return g_dbus_create_reply(msg, DBUS_TYPE_UINT32, &user_record->handle, DBUS_TYPE_INVALID); } @@ -180,8 +184,10 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, records = g_slist_append(records, user_record); - g_dbus_add_disconnect_watch(conn, sender, exit_callback, user_record, - NULL); + user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender, + exit_callback, user_record, NULL); + + debug("listener_id %d", user_record->listener_id); *handle = user_record->handle; @@ -320,18 +326,17 @@ int remove_record(DBusConnection *conn, const char *sender, { struct record_data *user_record; + debug("remove record 0x%x", handle); + user_record = find_record(handle, sender); if (!user_record) return -1; - g_dbus_remove_watch(conn, user_record->listener_id); + debug("listner_id %d", user_record->listener_id); - records = g_slist_remove(records, user_record); - - remove_record_from_server(handle); + g_dbus_remove_watch(conn, user_record->listener_id); - g_free(user_record->sender); - g_free(user_record); + exit_callback(user_record); return 0; } -- cgit From bf39ef3c93da52c445a181b840cbd45601979481 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 24 Jun 2008 00:24:08 +0000 Subject: Use safe PDU extract functions --- hcid/dbus-database.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hcid/dbus-database.c') diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index c6a689d2..ab88c8f5 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -119,7 +119,7 @@ static DBusMessage *add_service_record(DBusConnection *conn, if (len <= 0) return invalid_arguments(msg); - sdp_record = sdp_extract_pdu(record, &scanned); + sdp_record = sdp_extract_pdu_safe(record, len, &scanned); if (!sdp_record) { error("Parsing of service record failed"); return failed(msg); @@ -263,7 +263,7 @@ static DBusMessage *update_service_record(DBusConnection *conn, if (!user_record) return not_available(msg); - sdp_record = sdp_extract_pdu(bin_record, &scanned); + sdp_record = sdp_extract_pdu_safe(bin_record, size, &scanned); if (!sdp_record) { error("Parsing of service record failed"); return invalid_arguments(msg); -- cgit