diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-06-25 19:29:08 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-06-25 19:29:08 +0000 |
commit | bd0bc214372e275311872d1585180ad4604adfe4 (patch) | |
tree | a0e3f4408f4a472023ce4e4d9d9dc73c55a61859 | |
parent | ab9d441d9df8c1e3bffb82cdfe53f1601a7ed883 (diff) |
database: Added new method UpdateServiceRecordFromXML
-rw-r--r-- | hcid/dbus-api.txt | 9 | ||||
-rw-r--r-- | hcid/dbus-database.c | 105 |
2 files changed, 83 insertions, 31 deletions
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index 87313c15..49031263 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -251,6 +251,15 @@ Methods void RegisterService(string identifier, string name, string description org.bluez.Error.NotAvailable org.bluez.Error.Failed + void UpdateServiceRecordFromXML(uint32 handle, string record) + + Updates a given service record provided in the + XML format. + + 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-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 } }; |