summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-25 22:14:22 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-04-25 22:14:22 +0000
commit44847d5dfc0eebba1cebad1fbc89895901bfe09b (patch)
tree8021bc6f212c44e978f1c08f84eb5f6b02a6f186
parenteefb64d927b48d2de2e100b1f7ee715bf86bbb57 (diff)
Added UpdateServiceRecord
-rw-r--r--hcid/dbus-api.txt8
-rw-r--r--hcid/dbus-common.c17
-rw-r--r--hcid/dbus-common.h1
-rw-r--r--hcid/dbus-database.c76
-rw-r--r--network/server.c64
-rw-r--r--sdpd/sdpd.h2
-rw-r--r--sdpd/service.c15
7 files changed, 156 insertions, 27 deletions
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt
index bca8a2c8..ea5a22d3 100644
--- a/hcid/dbus-api.txt
+++ b/hcid/dbus-api.txt
@@ -243,6 +243,14 @@ Methods void RegisterService(string identifier, string name, string description
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.Failed
+ void UpdateServiceRecord(uint32 handle, array{byte})
+
+ Updates a given service record.
+
+ Possible errors: org.bluez.Error.InvalidArguments
+ org.bluez.Error.NotAvailable
+ org.bluez.Error.Failed
+
void RemoveServiceRecord(uint32 handle)
Remove a service record identified by its handle.
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index 7ea19ba9..cccf8da4 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -451,6 +451,23 @@ int register_sdp_record(sdp_record_t *rec)
return err;
}
+int update_sdp_record(uint32_t handle, sdp_record_t *rec)
+{
+ if (!get_sdp_session())
+ return -1;
+
+ /* Update on the server */
+ rec->handle = handle;
+ if (sdp_device_record_update(sess, BDADDR_ANY, rec)) {
+ cleanup_sdp_session();
+ error("Service Record update failed: %s(%d).\n",
+ strerror(errno), errno);
+ return -1;
+ }
+
+ return 0;
+}
+
int unregister_sdp_record(uint32_t handle)
{
int err;
diff --git a/hcid/dbus-common.h b/hcid/dbus-common.h
index 54e7b58d..98513ea0 100644
--- a/hcid/dbus-common.h
+++ b/hcid/dbus-common.h
@@ -59,6 +59,7 @@ int hcid_dbus_init(void);
int register_sdp_binary(uint8_t *data, uint32_t size, uint32_t *handle);
int register_sdp_record(sdp_record_t *rec);
int unregister_sdp_record(uint32_t handle);
+int update_sdp_record(uint32_t handle, sdp_record_t *rec);
void cleanup_sdp_session(void);
#endif /* __BLUEZ_DBUS_COMMON_H */
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 }
};
diff --git a/network/server.c b/network/server.c
index 17534f9c..f50d1e06 100644
--- a/network/server.c
+++ b/network/server.c
@@ -658,6 +658,47 @@ static uint32_t add_server_record(struct network_server *ns)
return rec_id;
}
+static int update_server_record(struct network_server *ns)
+{
+ DBusMessage *msg, *reply;
+ DBusError derr;
+ sdp_buf_t buf;
+
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
+ "org.bluez.Database", "UpdateServiceRecord");
+ if (!msg) {
+ error("Can't allocate new method call");
+ return -ENOMEM;
+ }
+
+ if (create_server_record(&buf, ns->name, ns->id, ns->secure) < 0) {
+ error("Unable to allocate new service record");
+ dbus_message_unref(msg);
+ return -1;
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &ns->record_id,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &buf.data, buf.data_size, DBUS_TYPE_INVALID);
+
+ dbus_error_init(&derr);
+ reply = dbus_connection_send_with_reply_and_block(ns->conn, msg, -1, &derr);
+
+ free(buf.data);
+ dbus_message_unref(msg);
+
+ if (dbus_error_is_set(&derr) || dbus_set_error_from_message(&derr, reply)) {
+ error("Update service record failed: %s", derr.message);
+ dbus_error_free(&derr);
+ return -1;
+ }
+
+ dbus_message_unref(reply);
+
+ return 0;
+}
+
static int remove_server_record(DBusConnection *conn, uint32_t rec_id)
{
DBusMessage *msg, *reply;
@@ -818,12 +859,11 @@ static DBusHandlerResult set_name(DBusConnection *conn,
ns->name = g_strdup(name);
if (ns->io) {
- /* Server enabled - service record already registred
- * Workaround: Currently it is not possible update
- * one service record attribute using D-Bus methods
- */
- remove_server_record(ns->conn, ns->record_id);
- ns->record_id = add_server_record(ns);
+ if (update_server_record(ns) < 0) {
+ dbus_message_unref(reply);
+ return err_failed(conn, msg,
+ "Service record attribute update failed");
+ }
}
return send_message_and_unref(conn, reply);
@@ -908,14 +948,12 @@ static DBusHandlerResult set_security(DBusConnection *conn,
}
ns->secure = secure;
-
if (ns->io) {
- /* Server enabled - service record already registred
- * Workaround: Currently it is not possible update
- * one service record attribute using D-Bus methods
- */
- remove_server_record(ns->conn, ns->record_id);
- ns->record_id = add_server_record(ns);
+ if (update_server_record(ns) < 0) {
+ dbus_message_unref(reply);
+ return err_failed(conn, msg,
+ "Service record attribute update failed");
+ }
}
return send_message_and_unref(conn, reply);
diff --git a/sdpd/sdpd.h b/sdpd/sdpd.h
index 13aa2c74..31f3b645 100644
--- a/sdpd/sdpd.h
+++ b/sdpd/sdpd.h
@@ -86,4 +86,4 @@ int start_sdp_server(uint16_t mtu, const char *did, uint32_t flags);
void stop_sdp_server(void);
int add_record_to_server(sdp_record_t *rec);
-void remove_record_from_server(uint32_t handle);
+int remove_record_from_server(uint32_t handle);
diff --git a/sdpd/service.c b/sdpd/service.c
index 8c8c3a73..e469d841 100644
--- a/sdpd/service.c
+++ b/sdpd/service.c
@@ -297,19 +297,22 @@ int add_record_to_server(sdp_record_t *rec)
return 0;
}
-void remove_record_from_server(uint32_t handle)
+int remove_record_from_server(uint32_t handle)
{
sdp_record_t *rec;
debug("Removing record with handle 0x%05x", handle);
rec = sdp_record_find(handle);
- if (rec) {
- if (sdp_record_remove(handle) == 0)
- update_db_timestamp();
+ if (!rec)
+ return -ENOENT;
- sdp_record_free(rec);
- }
+ if (sdp_record_remove(handle) == 0)
+ update_db_timestamp();
+
+ sdp_record_free(rec);
+
+ return 0;
}
// FIXME: refactor for server-side